home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / 1989 / 12 / mixed / screen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-18  |  6.0 KB  |  225 lines

  1. /* ------------------------------------------------------ */
  2. /*                     SCREEN.C                           */
  3. /*        erste Veröffentlichung: Ausgabe 2'88            */
  4. /*     (c) 1988 G.Rühwald  &  PASCAL International        */
  5. /* ------------------------------------------------------ */
  6. #include <stdlib.h>
  7. #include <dos.h>
  8. #include "screen.h"
  9.  
  10.  
  11. /* Attribut für normale Schrift ins Highbyte ------------ */
  12.  
  13.   int attribut = ATT_NORMAL << 8;
  14.  
  15. /* Zeiger auf Bildschirmspeicher einrichten ------------- */
  16.  
  17. #define MK_FP(Seg,Offs) \
  18.         ((void far *)(((unsigned long)(Seg)<<16)|(Offs)))
  19. int far *screenpointer = ((int far *)
  20.                          MK_FP(SCREEN_SEGMENT,0x0000));
  21.  
  22. /* In dieser Struktur werden die Fenster gespeichert ---- */
  23.  
  24. struct windows { int xa, ya, xe, ye;
  25.                  int *screen_zeig;
  26.                };
  27.  
  28. struct windows window[MAX_WINDOWS];
  29. int window_num = NOWIN;
  30.  
  31. /* ------------------------------------------------------ */
  32. void set_attribut(att)
  33.   unsigned char att;
  34. {
  35.   attribut = att << 8;
  36. }
  37.  
  38. /* ------------------------------------------------------ */
  39. void make_relativ(x,y)
  40.   int *x, *y;
  41. {
  42.   *x += window[window_num].xa;
  43.   *y += window[window_num].ya;
  44. }
  45.  
  46. /* ------------------------------------------------------ */
  47. void set_cursor(x,y)
  48.   int x, y;
  49. { union REGS regs;
  50.  
  51.   if (window_num != NOWIN) make_relativ(&x, &y);
  52.   regs.h.ah = 2;
  53.   regs.h.dh = y-1;
  54.   regs.h.dl = x-1;
  55.   regs.h.bh = 0;
  56.   int86(0x10, ®s, ®s);
  57. }
  58.  
  59. /* ------------------------------------------------------ */
  60. void cursor(mode)
  61.   int mode;
  62. { union REGS regs;
  63.  
  64.   switch(mode)
  65.   {
  66.     case 0 : { regs.h.cl = 0x00; regs.h.ch = 0x0F; break; }
  67.     case 1 : { regs.h.cl = 0x07; regs.h.ch = 0x07; break; }
  68.     case 2 : { regs.h.cl = 0x07; regs.h.ch = 0x06; break; }
  69.     case 8 : { regs.h.cl = 0x08; regs.h.ch = 0x00; break; }
  70.   }
  71.   regs.h.ah = 1;
  72.   int86(0x10, ®s, ®s);
  73. }
  74.  
  75. /* ------------------------------------------------------ */
  76. void printxy(x,y,c)
  77.   int x, y;
  78.   unsigned char c;
  79. {
  80.   if (window_num != NOWIN) make_relativ(&x, &y);
  81.   *(screenpointer + SCREEN_OFFSET(x,y)) =
  82.                                  (((int) c) | attribut);
  83. }
  84.  
  85. /* ------------------------------------------------------ */
  86. void printsxy(x, y, str)
  87.   int x, y;
  88.   char *str;
  89. {
  90.   for (; *str != '\0'; x++, str++)
  91.     printxy(x, y, (unsigned)*str);
  92. }
  93.  
  94. /* ------------------------------------------------------ */
  95. unsigned char readxy(x, y)
  96.   int x, y;
  97. {
  98.   if (window_num != NOWIN) make_relativ(&x, &y);
  99.   return((unsigned char)*(screenpointer +
  100.                           SCREEN_OFFSET(x,y)));
  101. }
  102.  
  103. /* ------------------------------------------------------ */
  104. void readsxy(x, y, length, str)
  105.   int x, y, length;
  106.   char *str;
  107. {
  108.   int i;
  109.  
  110.   for(i = 0; i<= length; i++, str++, x++)
  111.     *str = (signed) readxy(x, y);
  112.   *str = '\0';
  113. }
  114.  
  115. /* ------------------------------------------------------ */
  116. void clrscr(xanf, yanf, xend, yend)
  117.   int xanf, yanf, xend, yend;
  118. {
  119.   register x, y;
  120.   int alt_attribut;
  121.  
  122.   alt_attribut = attribut;
  123.   attribut = 7*256;
  124.   for(x = xanf; x <= xend; x++)
  125.     for(y = yanf; y <= yend; y++)
  126.       printxy(x,y,' ');
  127.   attribut = alt_attribut;
  128. }
  129.  
  130. /* ------------------------------------------------------ */
  131. void open_window(xa, ya, xe, ye, rahmen)
  132.   int xa, ya, xe, ye, rahmen;
  133. {
  134.   unsigned char oben_links, oben_rechts, unten_links,
  135.                 unten_rechts, oben_unten, seite;
  136.   register x, y;
  137.   int *zeiger;
  138.   int screen_length, alt_window_num;
  139.   char buffer[81];
  140.   char *bufp = buffer;
  141.  
  142.   switch (rahmen)
  143.   {
  144.                                            /* ohne Rahmen */
  145.     case 0 : {   oben_links = oben_rechts
  146.                = unten_links = unten_rechts
  147.                = oben_unten = seite = ' ';
  148.                break;
  149.              }
  150.                                         /* einfache Linie */
  151.     case 1 : { oben_links  = 218;  oben_rechts  = 191;
  152.                unten_links = 192;  unten_rechts = 217;
  153.                oben_unten  = 196;  seite        = 179;
  154.                break;
  155.              }
  156.                                         /* doppelte Linie */
  157.     case 2 : { oben_links  = 201;  oben_rechts  = 187;
  158.                unten_links = 200;  unten_rechts = 188;
  159.                oben_unten  = 205;  seite        = 186;
  160.                break;
  161.              }
  162.   }
  163.   window_num++;
  164.   window[window_num].xa = xa;
  165.   window[window_num].ya = ya;
  166.   window[window_num].xe = xe;
  167.   window[window_num].ye = ye;
  168.                  /* Speicherplatz auf dem Heap allokieren */
  169.   screen_length = (xe-xa+1) * (ye-ya+1);
  170.   zeiger = window[window_num].screen_zeig
  171.          = calloc(screen_length,2);
  172.  
  173.   alt_window_num = window_num;
  174.   window_num = NOWIN;
  175.   for(x = xa; x <= xe; x++)
  176.     for (y = ya; y <= ye; y++)
  177.       *(zeiger++) = readxy(x, y);
  178.  
  179.       /* String für Ober-/Unterkante-Fenster fertigmachen */
  180.   for (x =xa; x < xe; x++, bufp++) *bufp = oben_unten;
  181.   *bufp = '\0';
  182.   clrscr(xa+1,ya+1,xe-1,ye-1);
  183.  
  184.                                        /* Rahmen zeichnen */
  185.   printxy(xa, ya, oben_links);
  186.   printsxy(xa+1, ya, buffer);
  187.   printxy(xe, ya, oben_rechts);
  188.   for(x = ya+1; x < ye; x++)
  189.     { printxy(xa,x,seite);
  190.       printxy(xe,x,seite);
  191.     }
  192.   printxy(xa,ye,unten_links);
  193.   printsxy(xa+1,ye,buffer);
  194.   printxy(xe,ye,unten_rechts);
  195.  
  196.   window_num = alt_window_num;
  197. }
  198.  
  199. /* ------------------------------------------------------ */
  200. void close_window()
  201. {
  202.   int *zeiger;
  203.   register x, y;
  204.   int xa,ya,xe,ye,alt_window_num;
  205.  
  206.   xa=window[window_num].xa;
  207.   ya=window[window_num].ya;
  208.   xe=window[window_num].xe;
  209.   ye=window[window_num].ye;
  210.   zeiger=window[window_num].screen_zeig;
  211.  
  212.   alt_window_num = window_num;
  213.   window_num = NOWIN;
  214.  
  215.   for(x = xa; x <= xe; x++)
  216.     for(y = ya; y <= ye; y++)
  217.       printxy(x,y,*(zeiger++));
  218.  
  219.   window_num = alt_window_num;
  220.   free(window[window_num].screen_zeig);
  221.   window_num--;
  222. }
  223. /* ------------------------------------------------------ */
  224. /*                  Ende von SCREEN.C                     */
  225.