home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff256.lzh / Stevie / dos.c < prev    next >
C/C++ Source or Header  |  1989-10-19  |  4KB  |  252 lines

  1. /*
  2.  * DOS System-dependent routines.
  3.  *
  4.  * System-specific code for MS-DOS. This has been tested with
  5.  * MSDOS 3.3 on an AT. Also, the console driver "nansi.sys" is
  6.  * required.
  7.  *
  8.  */
  9.  
  10. #include <dos.h>
  11. #include "stevie.h"
  12.  
  13. /*
  14.  * inchar() - get a character from the keyboard
  15.  */
  16. int
  17. inchar()
  18. {
  19.     int             c;
  20.  
  21.     for (;; beep()) {        /* loop until we get a valid character */
  22.  
  23.     flushbuf();        /* flush any pending output */
  24.  
  25.     switch (c = getch()) {
  26.       case 0x1e:
  27.         return K_CGRAVE;
  28.       case 0:        /* special key */
  29.         if (State != NORMAL) {
  30.         c = getch();    /* throw away next char */
  31.         continue;    /* and loop for another char */
  32.         }
  33.         switch (c = getch()) {
  34.           case 0x50:
  35.         return K_DARROW;
  36.           case 0x48:
  37.         return K_UARROW;
  38.           case 0x4b:
  39.         return K_LARROW;
  40.           case 0x4d:
  41.         return K_RARROW;
  42.           case 0x52:
  43.         return K_INSERT;
  44.           case 0x47:
  45.         stuffReadbuff("1G");
  46.         return -1;
  47.           case 0x4f:
  48.         stuffReadbuff("G");
  49.         return -1;
  50.           case 0x51:
  51.         stuffReadbuff(mkstr(CTRL('F')));
  52.         return -1;
  53.           case 0x49:
  54.         stuffReadbuff(mkstr(CTRL('B')));
  55.         return -1;
  56.         /*
  57.          * Hard-code some useful function key macros. 
  58.          */
  59.           case 0x3b:    /* F1 */
  60.         stuffReadbuff(":p\n");
  61.         return -1;
  62.           case 0x54:    /* SF1 */
  63.         stuffReadbuff(":p!\n");
  64.         return -1;
  65.           case 0x3c:    /* F2 */
  66.         stuffReadbuff(":n\n");
  67.         return -1;
  68.           case 0x55:    /* SF2 */
  69.         stuffReadbuff(":n!\n");
  70.         return -1;
  71.           case 0x3d:    /* F3 */
  72.         stuffReadbuff(":e #\n");
  73.         return -1;
  74.           case 0x3e:    /* F4 */
  75.         stuffReadbuff(":rew\n");
  76.         return -1;
  77.           case 0x57:    /* SF4 */
  78.         stuffReadbuff(":rew!\n");
  79.         return -1;
  80.           case 0x3f:    /* F5 */
  81.         stuffReadbuff("[[");
  82.         return -1;
  83.           case 0x40:    /* F6 */
  84.         stuffReadbuff("]]");
  85.         return -1;
  86.           case 0x41:    /* F7 */
  87.         stuffReadbuff("<<");
  88.         return -1;
  89.           case 0x42:    /* F8 */
  90.         stuffReadbuff(">>");
  91.         return -1;
  92.           case 0x43:    /* F9 */
  93.         stuffReadbuff(":x\n");
  94.         return -1;
  95.           case 0x44:    /* F10 */
  96.         stuffReadbuff(":help\n");
  97.         return -1;
  98.           default:
  99.         break;
  100.         }
  101.         break;
  102.  
  103.       default:
  104.         return c;
  105.     }
  106.     }
  107. }
  108.  
  109. #define BSIZE   2048
  110. static char     outbuf[BSIZE];
  111. static int      bpos = 0;
  112.  
  113. flushbuf()
  114. {
  115.     if (bpos != 0)
  116.     write(1, outbuf, bpos);
  117.     bpos = 0;
  118. }
  119.  
  120. /*
  121.  * Macro to output a character. Used within this file for speed.
  122.  */
  123. #define outone(c)       outbuf[bpos++] = c; if (bpos >= BSIZE) flushbuf()
  124.  
  125. /*
  126.  * Function version for use outside this file.
  127.  */
  128. void
  129. outchar(c)
  130.     register char   c;
  131. {
  132.     outbuf[bpos++] = c;
  133.     if (bpos >= BSIZE)
  134.     flushbuf();
  135. }
  136.  
  137.  
  138. /*
  139.  * outstr(s) - write a string to the console
  140.  */
  141. void
  142. outstr(s)
  143.     register char  *s;
  144. {
  145.     if (strcmp(s, T_DL) == 0) {    /* delete line */
  146.     union REGS      rr;
  147.  
  148.     flushbuf();
  149.     rr.x.ax = 0x0300;    /* get cursor position */
  150.     rr.x.bx = 0;
  151.     int86(0x10, &rr, &rr);
  152.     rr.h.ch = rr.h.dh;    /* scroll from current row to bot dn 1 */
  153.     rr.h.cl = rr.h.dl;
  154.     rr.h.dh = Rows - rr.h.ch;
  155.     rr.h.dl = Columns;
  156.     rr.x.bx = 07;
  157.     rr.x.ax = 0x0601;
  158.     int86(0x10, &rr, &rr);
  159.     return;
  160.     }
  161.     if (strcmp(s, T_IL) == 0) {    /* insert line */
  162.     union REGS      rr;
  163.  
  164.     flushbuf();
  165.     rr.x.ax = 0x0300;    /* get cursor position */
  166.     rr.x.bx = 0;
  167.     int86(0x10, &rr, &rr);
  168.     rr.h.ch = rr.h.dh;    /* scroll from current row to bot dn 1 */
  169.     rr.h.cl = rr.h.dl;
  170.     rr.h.dh = Rows - rr.h.ch;
  171.     rr.h.dl = Columns;
  172.     rr.x.bx = 07;
  173.     rr.x.ax = 0x0701;
  174.     int86(0x10, &rr, &rr);
  175.     return;
  176.     }
  177.     while (*s) {
  178.     outone(*s++);
  179.     }
  180. }
  181.  
  182. void
  183. beep()
  184. {
  185.     if (RedrawingDisabled)
  186.     return;
  187.  
  188.     outone('\007');
  189. }
  190.  
  191. void
  192. sleep(n)
  193.     int             n;
  194. {
  195.     /*
  196.      * Should do something reasonable here. 
  197.      */
  198. }
  199.  
  200. void
  201. delay()
  202. {
  203.     long            l;
  204.  
  205.     flushbuf();
  206.     /*
  207.      * Should do something better here... 
  208.      */
  209.     for (l = 0; l < 5000; l++);
  210. }
  211.  
  212. void
  213. windinit()
  214. {
  215.     Columns = 80;
  216.     P(P_LI) = Rows = 25;
  217. }
  218.  
  219. void
  220. windexit(r)
  221.     int             r;
  222. {
  223.     flushbuf();
  224.     exit(r);
  225. }
  226.  
  227. void
  228. windgoto(r, c)
  229.     register int    r, c;
  230. {
  231.     union REGS      rr;
  232.  
  233.     flushbuf();
  234.     rr.h.dh = r;
  235.     rr.h.dl = c;
  236.     rr.x.bx = 0;
  237.     rr.x.ax = 0x0200;
  238.     int86(0x10, &rr, &rr);
  239. }
  240.  
  241. FILE           *
  242. fopenb(fname, mode)
  243.     char           *fname;
  244.     char           *mode;
  245. {
  246.     FILE           *fopen();
  247.     char            modestr[16];
  248.  
  249.     sprintf(modestr, "%sb", mode);
  250.     return fopen(fname, modestr);
  251. }
  252.