home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / PROCWRKB.ZIP / BENCH1.ZIP / WIN / DOS / SCREEN.C < prev   
Encoding:
C/C++ Source or Header  |  1990-08-16  |  5.7 KB  |  271 lines

  1. /* ==( dos/screen.c )== */
  2. /* ----------------------------------------------- */
  3. /* Pro-C - Copyright (C) 1988, 1989 Vestronix Inc. */
  4. /* Modification to this source is not supported    */
  5. /* by Vestronix Inc.                               */
  6. /*            All Rights Reserved                  */
  7. /* ----------------------------------------------- */
  8. /* Written   Geo  26-Aug-88                        */
  9. /* Modified  Geo   1-May-90  See comments below    */
  10. /* ----------------------------------------------- */
  11. /* %W%  (%H% %T%) */
  12.  
  13. /*
  14.  *  Modifications
  15.  *
  16.  *   1-May-90  Geo - Fix for Herc cards byte is bios area
  17.  *  not being set, default any values less than 24x80 to 24x80
  18.  *   1-Mar-90  SBF - ttykeys[] initialization
  19.  *  25-Oct-89  Geo - 1.32 Merge
  20.  *
  21.  *
  22. */
  23.  
  24. # include <stdio.h>
  25. # include <bench.h>
  26.  
  27. # include "pregs.h"
  28.  
  29. char _page = 0;
  30.  
  31. /* Bios data */
  32. char far *videoscreen = (char far *)0xb8000000L; /* Assume colour */
  33. char far *videorows = (char far *)0x00400084L;
  34. char far *videocols = (char far *)0x0040004aL;
  35.  
  36. /* EXTERNs in bench.c */
  37. extern char snowwait; /* get_term() & procenv.exe */
  38.  
  39. /* Original cursor setting */
  40. int _cursorg = 0x0607;
  41. int resetcurs = -999;
  42.  
  43. extern short ttykeys[];
  44.  
  45. /* Settings used by cursor() */
  46. static int _curson  = 0x010D; /* 0x0607; */
  47. static int _cursoff = 0x2000;
  48.  
  49. /* System rows & cols, Range 0..n-1 */
  50. static short _sysrows = 24;
  51. static short _syscols = 79;
  52. static short _sysrc = 0x184f; /* (25-1) rows (80-1) cols */
  53.  
  54. /*
  55.  * Cursor is off or big
  56.  * returns previous setting 
  57.  *  to allow cursor setting to be changed
  58.  *  without affecting the calling routine's
  59.  *  cursor setting
  60. */
  61. int cursor(flag)
  62. int flag;
  63. {
  64. static int lastv = -999;
  65. RegStorage;
  66.  
  67.     if (flag == lastv)
  68.         return(flag);
  69.  
  70.     if (flag == -1)
  71.         Regs_cx = _cursorg;
  72.     else
  73.     Regs_cx = (flag == ON) ? _curson : _cursoff;
  74.     Regs_ah = 0x01;
  75.     Video();    /* Set cursor type */
  76.  
  77.     /* Set latest state, return previous */
  78.     lswap(int, lastv, flag);
  79.     return(flag);
  80. }
  81.  
  82. /* Should not be called directly */
  83. void _cls()
  84. {
  85. RegStorage;
  86.  
  87.     Regs_bh = 0x07;
  88.     Regs_cx = 0x0000;
  89.     Regs_dx = _sysrc;
  90.     Regs_ax = 0x0700;
  91.  
  92.     Video();    /* Initialise window */
  93. }
  94.  
  95. /*
  96.  * Clear all display cells to DOS normal
  97.  * and reset the cursor style
  98. */
  99. void resetscr()
  100. {
  101.     flushscr();
  102.  
  103.     _cls();
  104.  
  105.     /* Reset cursor shape with original */
  106.     resetcurs = cursor(-1);
  107.     moveto(1, 1); /* Looks nicer at the top */
  108. }
  109.  
  110. void moveto(row, col)
  111. int    row, col;
  112. {
  113. RegStorage;
  114.  
  115.     Regs_bh = _page;
  116.     Regs_dh = (unsigned char)row;
  117.     Regs_dl = (unsigned char)col;
  118.     Regs_ah = 0x02;
  119.  
  120.     Video();    /* Set cursor position */
  121. }
  122.  
  123. /* System default tables */
  124. /* Colour is used by the system */
  125. static unsigned char _colcrt[] =
  126. { 0x00, 0x17, 0x30, 0x47, 0x17, 0x1f, 0x30, 0x4f,
  127.   0x1f, 0x1e, 0x1f, 0x2f, 0x3f, 0x71, 0x5f, 0x6f};
  128. /* Mono is available when swapped */
  129. static unsigned char _monochrome[] =
  130. { 0x00, 0x07, 0x70, 0x01, 0x87, 0x0f, 0xf0, 0x09,
  131.   0x8f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07};
  132.  
  133. extern unsigned char mono[]; /* bench.c */
  134.  
  135. /* Called from create_w() on init */
  136. get_term()
  137. {
  138. extern char xmonitor; /* mip/wdata.c */
  139. int i;
  140. unsigned char mode;
  141. RegStorage;
  142.  
  143.     /* First get current active page */
  144.     Regs_cx = 0x00;  /* trying the status bits */
  145.     Regs_ah = 0x0f; 
  146.     Video();    /* Get current display mode */
  147.  
  148.     mode = Regs_al; /* Mashes al next statement */
  149.     _syscols = Regs_ah;
  150.     _syscols--; /* Keep range 0 .. n-1 */
  151.  
  152.     _page = Regs_bh;
  153.  
  154.     /* Set up colour or direct video */
  155.     if (mode != 7)
  156.     {
  157.         Regs_cx = 0;
  158.         Regs_bl = 0x10;
  159.         Regs_ah = 0x12;
  160.         Video();
  161.  
  162.     /* Trial ega setup */
  163. /* _sysrows = 42; */
  164.  
  165.         if (Regs_cx == 0)
  166.             snowwait = TRUE;    /* CGA */
  167.         else
  168.             /* Far system addreses - take care (~bitmask dangerous) */
  169.             snowwait =  FALSE;
  170.  
  171. # ifdef WDEBUGII
  172.         fprintf(stderr, "\nMonitor is %s\n",(snowwait?"CGA":"EGA"));
  173. # endif
  174.  
  175.         /* Colour */
  176.         _curson = 0x010D; /* 0x0607; */ /*  6,  7 */
  177.   }
  178.   else
  179.   {
  180.         snowwait = FALSE;
  181.         videoscreen = (char far *)0xB0000000L; /* Monochrome */
  182.         _curson = 0x0b0c; /* 11, 12 */
  183.   }
  184.  
  185.     xmonitor = (char)((mode == 3)? CGA : MONO);
  186.  
  187.     /* Set up default colour table */
  188.     bytecpy(colour, (mode == 3)? _colcrt : _monochrome, sizeof(_colcrt));
  189.  
  190.     /* Set up default mono table */
  191.     bytecpy(mono,   (mode != 3)? _colcrt : _monochrome, sizeof(_colcrt));
  192.  
  193.    /* Current cursor setting */
  194.    Regs_bh = _page; 
  195.    Regs_ah = 0x03; 
  196.     Video();        /* Read cursor position (also cursor setting) */
  197.    _cursorg = Regs_cx;
  198.  
  199. # ifdef WDEBUGII
  200.    fprintf(stderr, "Cursor setting %04x", _cursorg);
  201. # endif
  202.   
  203.   /* Confirm cursor is off */
  204.   cursor(OFF);
  205.  
  206.     /* Sysrc used for single value in resetting screen */
  207.     _sysrc = (_sysrows << 8) | _syscols; 
  208. /* Hack for larger video */
  209.     w_nrows = *videorows;
  210.     if (w_nrows < 24)
  211.         w_nrows = 24;
  212.     w_ncols = *videocols;
  213.     if (w_ncols < 80)
  214.         w_ncols = 80;
  215.     _sysrc = (w_nrows << 8) | w_ncols; 
  216.  
  217.     for (i = 1; i < MAX_TTYKEYS; i++)
  218.         ttykeys[i] = _K_Base(i);
  219.  
  220.   return(TRUE);
  221. }
  222.  
  223. /* Swaps in 2nd set of attributes */
  224. /* Recommend a redraws after this */
  225. swap_attr()
  226. {
  227. register int i;
  228.  
  229.     for (i = 0; i < sizeof(_colcrt); i++)
  230.         lswap(unsigned char, colour[i], mono[i]);
  231. }
  232.  
  233. void init_w(row, col)
  234. int row, col;
  235. {
  236. extern int _wsystart;
  237.  
  238. row; col; /* to get used */
  239.     get_term();
  240.     _wstartup();
  241.     _wsystart = 1;
  242.  
  243.     create_w(1, 1, w_nrows, w_ncols);
  244. }
  245.  
  246. void end_w(flag)
  247. int flag;
  248. {
  249. extern int _wsystart; /* wdata.c */
  250.  
  251.     if (_wsystart == 0)
  252.     {
  253. # ifdef WDEBUGI
  254.         fprintf(stderr, "\nend_w() : No windowing to end\n");
  255. # endif
  256.         return;
  257.     }
  258.  
  259.     if (flag == TRUE)
  260.         resetscr();
  261.     else
  262.     {
  263.         flushscr(); /* Update highlight menus */
  264.         cursor(-1);
  265.     }
  266.     _wshutdown();
  267. }
  268.  
  269. void flushcurs() {}
  270.  
  271.