home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / sozobon / scsrc20 / szadb / window.c < prev   
C/C++ Source or Header  |  1990-02-24  |  4KB  |  302 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. char scrbuf[0x80ff];
  15. char *screen;
  16. long oscreen;
  17. int mywindow;
  18. int ucolor0, ucolor1;
  19.  
  20. winopen()
  21. {
  22.     long xbios();
  23.  
  24.  
  25.     screen = scrbuf;
  26.     screen += 0xff;
  27.     screen = (char *)((long)screen & ~0xffL);
  28.     
  29.     oscreen = xbios(2);
  30.     xbios(5, -1L, screen, -1);
  31.     ucolor0 = xbios(7, 0, 0);
  32.     ucolor1 = xbios(7, 1, 0x777);
  33.     w_init();
  34.     mywindow = 1;
  35. }
  36.  
  37. winswtch()
  38. {
  39.     long xbios();
  40.  
  41.     if (mywindow) {
  42.         xbios(5, -1L, oscreen, -1);
  43.         xbios(7, 0, ucolor0);
  44.         xbios(7, 1, ucolor1);
  45.     } else {
  46.         oscreen = xbios(2);
  47.         xbios(5, -1L, screen, -1);
  48.         ucolor0 = xbios(7, 0, 0);
  49.         ucolor1 = xbios(7, 1, 0x777);
  50.     }
  51.     mywindow = !mywindow;
  52. }
  53.  
  54. winclose()
  55. {
  56.     if (mywindow)
  57.         winswtch();
  58. }
  59.  
  60. puts(s)
  61. char *s;
  62. {
  63.     while (*s)
  64.         putchar(*s++);
  65. }
  66.  
  67. putchar(c)
  68. char c;
  69. {
  70.     w_curs(0);
  71.     c &= 0x7f;
  72.     switch (c) {
  73.     case '\b':
  74.         w_bs();
  75.         break;
  76.     case '\t':
  77.         w_tab();
  78.         break;
  79.     case '\n':
  80.         w_nl();
  81.         break;
  82.     default:
  83.         w_put(c);
  84.         break;
  85.     }
  86.     w_curs(1);
  87. }
  88.  
  89. struct window {
  90.     short cols, lines;
  91.     short curc, curl;
  92.     short res;
  93.     short fontsz;
  94.     short csz, lsz, fsz;
  95.     char *font;
  96. } w;
  97.  
  98. char *bw_font;
  99. char *c_font;
  100.  
  101. w_init()
  102. {
  103.     int w_res;
  104.     long fontsp, getfonts();
  105.     long t;
  106.  
  107.     fontsp = getfonts();
  108.  
  109.     t = fontsp + 4;
  110.     t = *(long *)t;
  111.     t += 0x4c;
  112.     c_font = *(char **)t;
  113.  
  114.     t = fontsp + 8;
  115.     t = *(long *)t;
  116.     t += 0x4c;
  117.     bw_font = *(char **)t;
  118.  
  119.     w.curc = w.curl = 0;
  120.  
  121.     w.res = xbios(4);
  122.     switch (w.res) {
  123.     case 0:
  124.         w.cols = 40;
  125.         w.lines = 25;
  126.         w.csz = 8;
  127.         w.lsz = 4*40*8;
  128.         w.fsz = 4*40;
  129.         w.fontsz = 8;
  130.         w.font = c_font;
  131.         break;
  132.     case 1:
  133.         w.cols = 80;
  134.         w.lines = 25;
  135.         w.csz = 4;
  136.         w.lsz = 2*80*8;
  137.         w.fsz = 2*80;
  138.         w.fontsz = 8;
  139.         w.font = c_font;
  140.         break;
  141.     case 2:
  142.         w.cols = 80;
  143.         w.lines = 25;
  144.         w.csz = 2;
  145.         w.lsz = 1*80*16;
  146.         w.fsz = 1*80;
  147.         w.fontsz = 16;
  148.         w.font = bw_font;
  149.         break;
  150.     }
  151.     w_curs(1);
  152. }
  153.  
  154. w_put(c)
  155. char c;
  156. {
  157.     int i;
  158.     char *fp;
  159.     char *tp;
  160.     int woff, horl;
  161.  
  162.     tp = screen;
  163.     horl = w.curc & 1;
  164.     woff = w.curc >> 1;
  165.     tp += woff*w.csz + horl;
  166.     tp += w.curl*w.lsz;
  167.  
  168.     fp = &w.font[c];
  169.     for (i=0; i<w.fontsz; i++) {
  170.         *tp = *fp;
  171.         tp += w.fsz;
  172.         fp += 256;
  173.     }
  174.     w.curc++;
  175.     if (w.curc >= w.cols)
  176.         w_nl();
  177. }
  178.  
  179. w_curs(flg)
  180. {
  181.     int i;
  182.     char *tp;
  183.     int woff, horl;
  184.     char val;
  185.  
  186.     tp = screen;
  187.     horl = w.curc & 1;
  188.     woff = w.curc >> 1;
  189.     tp += woff*w.csz + horl;
  190.     tp += w.curl*w.lsz;
  191.  
  192.     val = flg ? 0xff : 0;
  193.  
  194.     for (i=0; i<w.fontsz; i++) {
  195.         *tp = val;
  196.         tp += w.fsz;
  197.     }
  198. }
  199.  
  200. w_bs()
  201. {
  202.     if (w.curc)
  203.         w.curc--;
  204. }
  205.  
  206. optnl()
  207. {
  208.     if (w.curc) {
  209.         w_curs(0);
  210.         w_nl();
  211.         w_curs(1);
  212.     }
  213. }
  214.  
  215. align(n)
  216. {
  217.     w_curs(0);
  218.     if (w.curc > n)
  219.         w_nl();
  220.     w.curc = n;
  221.     w_curs(1);
  222. }
  223.  
  224. tab(n)
  225. {
  226.     w_curs(0);
  227.     w.curc += n;
  228.     w.curc -= (w.curc % n);
  229.     if (w.curc >= w.cols)
  230.         w_nl();
  231.     w_curs(1);
  232. }
  233.  
  234. w_tab()
  235. {
  236.     w.curc += 10;
  237.     w.curc -= (w.curc % 10);
  238.     if (w.curc >= w.cols)
  239.         w_nl();
  240. }
  241.  
  242. w_nl()
  243. {
  244.     w.curc = 0;
  245.     w.curl++;
  246.     if (w.curl >= w.lines) {
  247.         w_scrup();
  248.         w.curl = w.lines-1;
  249.     }
  250. }
  251.  
  252. w_scrup()
  253. {
  254.     register char *fr, *to, *clr;
  255.     register cnt;
  256.  
  257.     clr = fr = to = screen;
  258.     fr += w.lsz;
  259.     cnt = w.lsz * (w.lines-1);
  260.     clr += cnt;
  261.     wcopy(fr, to, cnt/2);
  262.     cnt = w.lsz;
  263.     while (cnt--)
  264.         *clr++ = 0;
  265. }
  266.  
  267. char linesv[80*16];
  268.  
  269. w_help(flag)
  270. {
  271.     static int svcol;
  272.     char *tp;
  273.  
  274.     if (flag == 0) {
  275.         w_curs(0);
  276.         tp = screen;
  277.         tp += w.curl*w.lsz;
  278.         wcopy(tp, linesv, w.lsz/2);
  279.         svcol = w.curc;
  280.         w.curc = w.cols - 40;
  281.     } else {
  282.         w.curl = w.lines-1;
  283.         tp = screen;
  284.         tp += w.curl*w.lsz;
  285.         wcopy(linesv, tp, w.lsz/2);
  286.         w.curc = svcol;
  287.         w_curs(1);
  288.     }
  289. }
  290.  
  291. w_hline(n)
  292. {
  293.     w.curl = n;
  294.     w.curc = w.cols - 40;
  295. }
  296.  
  297. w_hchr(c)
  298. char c;
  299. {
  300.     w_put(c);
  301. }
  302.