#define   _INTRPT_      0x7f

/* This structure is used to hold status information
   on a process */

struct   _statusT
   {
      int                   kill_flag :2;
      int                   wait_flag :2;
      int                   fill_flag :12;
   };



/* This structure holds all of the information that
   defines a processes context */

struct   _simprocessT
   {
      struct _simprocessT   *next;
      struct _simprocessT   *prev;
      int                   init;
      int                   proc_id;
      struct _statusT       status;
      unsigned   long          start_time;
      void                  *waitpost;
      int                   reg_ax;
      int                   reg_bx;
      int                   reg_cx;
      int                   reg_dx;
      int                   reg_es;
      int                   reg_ds;
      int                   reg_si;
      int                   reg_di;
      int                   reg_bp;
      int                   reg_sp;
      int                   reg_ss;
      int                   reg_cs;
      int                   reg_ip;
      int                   reg_flag;
   };

typedef   struct   _simprocessT * pprocess;

/* this is the interprocess communications structure, for
   communications and synchronization */

struct   _postT
   {
      struct _postT         *next;
      struct _postT         *prev;
      char                   name[30];
      int                   handle;
      void                  *value;
      pprocess               *waiting;
   };


/*      Process header block list, which is circular */

struct   _simprocessT   *processlist;


/*      This process responds to the keyboard */

struct   _simprocessT   *kbprocess;
int                      set_kb_process = 0;

/*      Total number of process */

int                      totalprocs = 1;


/*      List of all current posts   */

struct   _postT         *postlist;

/*      Total number of posts in the system */

int      unsigned          totalposts;


/*      Storage for the original interrupt vector,
      which is replaced by task_handler*/

void      interrupt  (*old_vector)();


/*      Globals used by setup_task  */

int                   _sim_init_val = 2;
int                   glbl_sp;
int                   glbl_ss;
int                   glbl_bp;
void                 (*glbl_fc)(void) = NULL;


/*      Quick way to the system timer   */

long      unsigned      *systimer = MK_FP(0x0040,0x006c);


/*      Simulation Time used by system */

long   unsigned          _sim_system_time;

long   unsigned          _last_update_time;


/*      Simulation Time ratio used by system */

float                   _sim_time_ratio = 0;


/*      Hidden routines handle installation of task
      switcher, and actual task switching */

int               install_handler   (void);
void   interrupt   task_handler      (unsigned bp,unsigned di,
                                     unsigned si,unsigned ds,
                                     unsigned es,unsigned dx,
                                     unsigned cx,unsigned bx,
                                     unsigned ax,unsigned ip,
                                     unsigned cs,unsigned flags);
void               sim_start         (void);


/*      Simulation time available to programmer */

long   unsigned          CurrentTime;    /* Visible to programs */


/*      Visible routine for process control   */

int               start_kb_process   (void   (*func)(void),int stacksize);
int               start_process      (void   (*func)(void),int stacksize);
void               stop_process      (int process_id);
int               my_process_id      (void);


/*      Visible routines for control of process time utilivation */

int               wait_until_time   (long unsigned   starttime);
int               wait_for_time      (float   delaytime);


/*      Sets the sim time to real time ratio - maximum running speed.
      If this is set to 0.0, the system will run as fast as possible */

int               set_time_ratio      (float ratio);


/*      Visible routines for the handling of posts */

int               init_post         (char   *postname);
int               set_post          (int    posthandle,void   *pointer);
void              *get_post            (int    posthandle);
void              *wait_post         (int    posthandle);


/*      Exiting the system, and cleaning up the interrupts
      reports the value of the exit condition before
      exiting, useful for signalling certain errors */

void               exit_processing   (int condition);
