home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_12 / 8n12056a < prev    next >
Text File  |  1990-10-15  |  7KB  |  233 lines

  1. /*
  2.  *  CHAR.H
  3.  *
  4.  *  common references for character device driver
  5.  */
  6.  
  7.  
  8. /*  This is used for the escape buffer.  This is how many
  9.  *  bytes of parameters the escape() routine can save in one
  10.  *  sequence.  Tune it as you see fit.  It needs to be at
  11.  *  least long enough to hold the two bytes of an extended
  12.  *  key (such as F1), plus the replacement string:  */
  13.  
  14. #define BUF_LEN     80
  15.  
  16. /* length of the definition field; tune as you see fit.
  17.  * How long a string do you want? */
  18.  
  19. #define KEY_BUFLEN  21
  20.  
  21. /* number of re-assignments you can define;
  22.  * tune as you see fit.  Don't use it much?
  23.  * make it less. Redefining the entire keyboard?
  24.  * then make it more */
  25.  
  26. #define NKEYS       20
  27.  
  28. /*
  29.  *  parameters for the ring buffer.  If you want to
  30.  *  change the size, just change RLOG - the math demands
  31.  *  that the size of the buffer be a power of 2.  Makes
  32.  *  things nice and efficient that way.
  33.  */
  34.  
  35. #define RLOG    6
  36. #define RLEN    (2 << (RLOG - 1))
  37. #define RLIMIT  (RLEN - 1)
  38.  
  39. /*
  40.  *  macros for reading the system RAM where these neat
  41.  *  things are stored
  42.  */
  43.  
  44. #define CURRENT_MODE    (*(char far *)0x0449)
  45. #define SCREEN_WIDTH    (*(char far *)0x044A)
  46. #define SCREEN_OFFSET   (*(unsigned far *)0x044E)
  47. #define PAGE_TABLE  ((POSITION far *)0x0450)
  48. #define CURRENT_PAGE    (*(char far *)0x0462)
  49.  
  50. /*
  51.  *  base addresses for the video memory for the mono-
  52.  *  chrome adaptor (MONOCHROME) and the CGA (GRAPHIC)
  53.  */
  54.  
  55. #define MONOCHROME  ((char far *) 0x000B0000)
  56. #define GRAPHIC     ((char far *) 0x000B8000)
  57.  
  58. /*
  59.  *  status bits for the return code
  60.  */
  61.  
  62. #define UNKNOWN_COMMAND 03
  63. #define ERROR       0x8000
  64. #define DONE        0x0100
  65. #define BUSY        0x0200
  66.  
  67. /*
  68.  *  the states of the escape sequence:
  69.  *
  70.  *  RAW:        no escape sequence begun yet, or previous
  71.  *              sequence has been terminated
  72.  *
  73.  *  HAVE_ESC:   an escape has been received; now awaiting
  74.  *              the left bracket
  75.  *
  76.  *  HAVE_LBRACE:    an escape followed by a left bracket
  77.  *                  have been received; now waiting for a
  78.  *                  parameter or terminating character
  79.  *
  80.  *  IN_STRING:  a parameter beginning with a delimiter has
  81.  *              been started; until the same delimiter is
  82.  *              received, characters will be placed in the
  83.  *              escape buffer as is
  84.  *
  85.  *  IN_NUMBER:  a numeric parameter has been started; each
  86.  *              subsequent digit is 'added' to the number
  87.  *              in the escape buffer
  88.  */
  89.  
  90. #define RAW     0
  91. #define HAVE_ESC    1
  92. #define HAVE_LBRACE 2
  93. #define IN_STRING   3
  94. #define IN_NUMBER   4
  95.  
  96. /* typedef for cursor positioning; this union reflects the way
  97.  * that they are stored internally.  At the assembly language
  98.  * level, 16-bit registers can be loaded directly with the
  99.  * 16-bit position so that the high and low halves are
  100.  * correctly loaded for BIOS calls
  101.  */
  102.  
  103. typedef union
  104.     {
  105.     short   position;
  106.     struct
  107.         {
  108.         char    col;
  109.         char    line;
  110.         } loc;
  111.     } POSITION;
  112.  
  113. /*
  114.  * typedef for the reassignment buffer.  keystroke is the key
  115.  * being replaced; length is the number of bytes that the
  116.  * keystroke 'generates'; buffer holds the data that replaces
  117.  * the keystroke.
  118.  */
  119.  
  120. typedef struct
  121.     {
  122.     int keystroke;
  123.     char    length;
  124.     char    buffer  [ KEY_BUFLEN ];
  125.     } KEY;
  126.  
  127. /*----------- global variables ----------*/
  128.  
  129.                     /* the current character being output */
  130. extern char outchar;
  131.                     /* the current video mode */
  132. extern char video_mode;
  133.                     /* the current screen attribute */
  134. extern char attrib;
  135.                     /* a count of how many parameter bytes
  136.                      * have been read into the escape buffer
  137.                      */
  138. extern char char_cnt;
  139.                     /* the code being checked for in
  140.                      * reassignment routines; if null, it is
  141.                      * used to find an ununsed buffer; if
  142.                      * the value is non zero and positive,
  143.                      * it is used to look up a regular key;
  144.                      * if non-zero and negative, it is used
  145.                      * to look up an extended key */
  146. extern int  keycheck;
  147.                     /* the parameter buffer for ansi escape
  148.                      * sequences */
  149. extern char esc_buf [ BUF_LEN ];
  150.                     /* the current position */
  151. extern POSITION curr;
  152.                     /* the maximum position.  Actually, the
  153.                      * maximum line number is not used as
  154.                      * a maximum, but is used simply to
  155.                      * tell the clear-screen and clear-to-
  156.                      * end-of-line code how much screen to
  157.                      * clear */
  158. extern POSITION max;
  159.                     /* the current video page number */
  160. extern char cur_page;
  161.                     /* the current video address.  this is
  162.                      * the base address plus the offset to
  163.                      * the current page */
  164. extern char far *video_address;
  165.                     /* the transfer address specified in the
  166.                      * request header */
  167. extern char far *transfer;
  168.                     /* the count specified in the request
  169.                      * header */
  170. extern int  count;
  171.  
  172. /*
  173.  * pointer to the request header
  174.  */
  175.  
  176. extern  struct
  177.     {
  178.     char        rlength;
  179.     char        units;
  180.     char        command;
  181.     unsigned    status;
  182.     char        reserved    [ 8 ];
  183.     char        data;
  184.     char far    *transfer;
  185.     unsigned    count;
  186.     } far   *rh;
  187.  
  188. extern int  k;          /* generic int */
  189.  
  190.                         /* pointer to the length field
  191.                          * for the selected buffer */
  192. extern char *len;
  193.                         /* pointer to the definition
  194.                          * field for the selected buffer */
  195. extern char *ptr;
  196.  
  197. extern KEY kbuffer[NKEYS];  /* the buffers */
  198.  
  199. extern KEY  *kp;        /* pointer to a buffer */
  200.  
  201.                         /* r_buf[ r_index ] is the
  202.                          * next byte to be read */
  203. extern unsigned r_index;
  204.  
  205.                         /* r_buf[ w_index ] is where 
  206.                          * the next byte can be written */
  207. extern unsigned w_index;
  208.  
  209. extern char r_buf   [ RLEN ];   /* ring buffer */
  210.  
  211. /* 
  212.  * a temporary variable for storing either the delimiter while
  213.  * the escape sequence is in the IN_STRING state, or the value
  214.  * being computed if the escape sequence is in the IN_NUMBER
  215.  * state.  a convenient way of doubling the utility of a byte
  216.  * of storage while keeping track of just what we're doing
  217.  * with it.
  218.  */
  219.  
  220. extern union
  221.     {
  222.     char    delim;
  223.     char    value;
  224.     }       tmp;
  225. extern char     state;      /* the escape sequence state */
  226. extern POSITION     saved;  /* the saved cursor position */
  227. extern char     wrap;       /* wrap flag: wrap on if set */
  228. extern char     *cur_val;   /* line or column parameter being
  229.                                manipulated by w_cursor() */
  230. extern char     delta;      /* incr/decr to cur_val */
  231. extern char     limit;      /* limit of *cur_val */
  232.  
  233.