home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / szadb21b / source / src / window.c < prev   
C/C++ Source or Header  |  1991-07-07  |  7KB  |  321 lines

  1. /* Copyright (c) 1990 by Sozobon, Limited.  Authors: Johann Ruegg, Don Dugger
  2.  *
  3.  * Permission is granted to anyone to use this software for any purpose
  4.  * on any computer system, and to redistribute it freely, with the
  5.  * following restrictions:
  6.  * 1) No charge may be made other than reasonable charges for reproduction.
  7.  * 2) Modified versions must be clearly marked as such.
  8.  * 3) The authors are not responsible for any harmful consequences
  9.  *    of using this software, even if they result from defects in it.
  10.  *
  11.  *    window.c
  12.  */
  13. /*
  14.  * Modifications:
  15.  *  - w_nl rewritten to allow recording of display lines in a transcript
  16.  *    file
  17.  *  - small mods to speedup scrolling
  18.  *     Michal Jaegermann, May 1990
  19.  *  - TT modifications - startup code computes now most of fields
  20.  *    in 'window' structure, since it depends on a machine and resolution
  21.  *    and we would like to avoid using calls to malloc() to reserve
  22.  *    screen area (and linesv buffer if help is compiled in).
  23.  *    Changes in types of window structure. Functions putting
  24.  *    bits on a debugger screen more streamlined.
  25.  *     Michal Jaegermann, July 1991
  26.  */
  27. #include "adb.h"
  28. #include "lang.h"
  29.  
  30. /*
  31.  * Size of a needed buffer for a screen and a value for 'screen'
  32.  * are computed by a startup code, since we would not to hardwire
  33.  * screen size into this program, but we also want to avoid
  34.  * using malloc()
  35.  */
  36. char           *screen;  /* initialized and space reserved in a startup
  37.                 code - depends on a monitor and resolution */
  38. long            oscreen;
  39. int             mywindow;
  40. int             ucolor0, ucolor1;
  41. int             opcode_pos = ALIGN_A;
  42. char           *linbuf; /* initialized and space reserved in a startup
  43.                code - wider by two then a current screen width;
  44.                function cleanlb() from assist.s has to be
  45.                aware about this sizes */
  46.  
  47. extern int      trid;
  48. extern char    *trname;
  49. extern w_buf   *trbuf;
  50. extern void     cleanlb ();
  51. extern int      l_restart, w_restart, lb_fill;
  52. extern char    *lbuf, *cnbuf;
  53.  
  54. winopen ()
  55. {
  56.     long            xbios ();
  57.  
  58.  
  59. /***  this code moved to start.s
  60.  
  61.     screen = scrbuf;
  62.     screen += 0xff;
  63.     screen = (char *) ((long) screen & ~0xffL);
  64.  
  65. ***/
  66.  
  67.     oscreen = xbios (2);
  68.     xbios (5, -1L, screen, -1);
  69.     ucolor0 = xbios (7, 0, 0);
  70.     ucolor1 = xbios (7, 1, 0x777);
  71.     w_init ();
  72.     mywindow = 1;
  73. }
  74.  
  75. winswtch ()
  76. {
  77.     long            xbios ();
  78.  
  79.     if (mywindow) {
  80.     xbios (5, -1L, oscreen, -1);
  81.     xbios (7, 0, ucolor0);
  82.     xbios (7, 1, ucolor1);
  83.     }
  84.     else {
  85.     oscreen = xbios (2);
  86.     xbios (5, -1L, screen, -1);
  87.     ucolor0 = xbios (7, 0, 0);
  88.     ucolor1 = xbios (7, 1, 0x777);
  89.     }
  90.     mywindow = !mywindow;
  91. }
  92.  
  93. winclose ()
  94. {
  95.     if (mywindow)
  96.     winswtch ();
  97. }
  98.  
  99.  
  100. putchr (c)
  101.     char            c;
  102. {
  103.     w_curs (0);
  104.     /* c &= 0x7f;  */
  105.     switch (c) {
  106.     case '\b':
  107.     w_bs ();
  108.     break;
  109.     case '\t':
  110.     w_tab ();
  111.     break;
  112.     case '\n':
  113.     w_nl ();
  114.     break;
  115.     default:
  116.     w_put (c);
  117.     break;
  118.     }
  119.     w_curs (1);
  120. }
  121.  
  122. /*
  123.  * This is the single instance of this structure and its fields
  124.  * are initialized in a startup code
  125.  */
  126.  
  127. struct window w;
  128.  
  129. unsigned long   wcurl_max;
  130. static char    skips[8] = {  /* 2 to this power gives a number of
  131.                                  words to skip to the next alpha cell */
  132.         3,    /* 0 - ST low */            
  133.         2,    /* 1 - ST medium */
  134.         1,    /* 2 - ST high */
  135.         0,    /* 3 - nobody */
  136.         3,    /* 4 - TT medium */
  137.         0,    /* 5 - nobody */
  138.         1,    /* 6 - TT high */
  139.         4     /* 7 - TT low */
  140.         };
  141.  
  142. w_init ()
  143. {
  144.     int             w_res;
  145.     char           *fontsp;
  146.  
  147. /***
  148.     fields of w, with an exception of w.csz, initialized already in start.s
  149. ***/
  150.     fontsp = w.font;
  151.     if ( 2 > (w_res = w.res))     /* ST low and medium */
  152.     fontsp += 4;
  153.     else
  154.     fontsp += 8;        /* ST high and all TT resolutions */
  155.  
  156.     fontsp = *(char **) fontsp;
  157.     fontsp += 0x4c;
  158.     w.font = *(char **) fontsp;
  159.  
  160.     if (0 == w_res || 7 == w_res) /* low, 40 columns, ST or TT */ 
  161.     opcode_pos = 4;        /* print in the next line with an indent */
  162.     w.csz = skips[w_res];
  163.     wcurl_max = (unsigned long)(w.lines - 1) * w.lsz;
  164.     w_curs (1);
  165. }
  166.  
  167. w_put (c)
  168.     char            c;
  169. {
  170.     register int    i;
  171.     register char  *fp;
  172.     register char  *tp;
  173.     register unsigned int    woff;
  174.     register long  width;
  175.  
  176.     woff = w.curc;
  177.     linbuf[woff] = c;
  178.     tp = screen;
  179.     tp += woff & 1;
  180.     woff >>= 1;            /* loose the lowest bit */
  181.     tp += (woff << w.csz);
  182.     tp += w.curl;
  183.  
  184.     fp = &w.font[c];
  185.     i = w.fontsz;
  186.     width = w.fsz;
  187.     do {
  188.     *tp = *fp;
  189.     tp += width;
  190.     fp += 256;
  191.     } while (--i > 0);
  192.     w.curc++;
  193.     if (w.curc >= w.cols)
  194.     force_nl ();
  195. }
  196.  
  197. w_curs (flg)
  198. {
  199.     register int    i;
  200.     register char *tp;
  201.     register unsigned int woff;
  202.     register long   width;
  203.     char            val;
  204.  
  205.     tp = screen;
  206.     woff = w.curc;
  207.     tp += (woff &1);
  208.     woff >>= 1;            /* loose the lowest bit */
  209.     tp += (woff << w.csz);
  210.     tp += w.curl;
  211.  
  212.     val = flg ? 0xff : 0;
  213.  
  214.     i = w.fontsz;
  215.     width = w.fsz;
  216.     do {
  217.     *tp = val;
  218.     tp += width;
  219.     } while (--i > 0);
  220. }
  221.  
  222. w_bs ()
  223. {
  224.     if (w.curc > w_restart) {
  225.     --w.curc;
  226.     w_put (' ');
  227.     }
  228.     w.curc = w_restart;
  229.     prt (&lbuf[l_restart]);
  230. }
  231.  
  232. optnl ()
  233. {
  234.     if (w.curc) {
  235.     w_curs (0);
  236.     w_nl ();
  237.     w_curs (1);
  238.     }
  239. }
  240.  
  241. align (n)
  242. {
  243.     w_curs (0);
  244.     if (n >= w.cols) {
  245.     n = (n % w.cols);
  246.     force_nl ();
  247.     }
  248.     else if (w.curc > n) {
  249.     force_nl ();
  250.     }
  251.     w.curc = n;
  252.     w_curs (1);
  253. }
  254.  
  255. tab (n)
  256. {
  257.     w_curs (0);
  258.     w.curc += n;
  259.     w.curc -= (w.curc % n);
  260.     if (w.curc >= w.cols)
  261.     force_nl ();
  262.     w_curs (1);
  263. }
  264.  
  265. w_tab ()
  266. {
  267.     w.curc += 10;
  268.     w.curc -= (w.curc % 10);
  269.     if (w.curc >= w.cols)
  270.     force_nl ();
  271. }
  272.  
  273. w_nl ()
  274. {
  275.     extern void     trclose ();
  276.     extern int      (*trout) ();
  277.  
  278.     if (trid != NO_TRANS) {    /* send a current screen line to transcript */
  279.     linbuf[w.curc] = '\r';
  280.     linbuf[w.curc + 1] = '\n';
  281.     if (0 > (*trout) (trid, linbuf, (w.curc + 2))) {
  282.         if ((w_buf *) 0 == trbuf)
  283.         /* prtf("\nerror on write to %s\n", trname); */
  284.         prtf (MW, trname);
  285.         trclose ();
  286.     }
  287.     }
  288.     w.curc = 0;
  289.     if (w.curl >= wcurl_max)
  290.     w_scrup ();
  291.     else
  292.     w.curl += w.lsz;
  293.     cleanlb ();
  294. }
  295.  
  296. force_nl ()
  297. {
  298.     w_restart = 0;
  299.     l_restart = lb_fill;
  300.     w_nl ();
  301. }
  302.  
  303. /*
  304.  * Watch out - this function will work as long as (wcurl_max / 16)
  305.  * fits into 16 bits!  For huge screens lcopy has to be modified.
  306.  */
  307. w_scrup ()
  308. {
  309.     register char        *clr;
  310.     register int         cnt;
  311.     register unsigned long     offset = wcurl_max;
  312.  
  313.     clr = screen;
  314.     cnt = w.lsz;
  315.     lcopy (clr + cnt, clr, (unsigned int) (offset / 16));
  316.     clr += offset;
  317.     do {
  318.     *clr++ = 0;
  319.     } while (--cnt);
  320. }
  321.