home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / IDD.ZIP / MONO.ARC / mono.c < prev   
C/C++ Source or Header  |  1989-02-13  |  3KB  |  201 lines

  1. /*
  2.  *    monochrome device driver
  3.  */
  4.  
  5. #include "driver.h"
  6.  
  7. #define    VidSeg    0xB0000000    /*  addr of monochrome video RAM    */
  8. #define    Attr    0x0700        /*  video attribute mask        */
  9. #define    Blank    (Attr + ' ')    /*  a blank                */
  10.  
  11. static BYTE    row,        /*  current row number            */
  12.         col;        /*  current column number        */
  13.  
  14. static WORD far *VidAddr;    /*  -> current display character    */
  15.  
  16.  
  17. /********************************
  18.  *    local routines        *
  19.  *******************************/
  20.  
  21. /*
  22.  *    set() ->    set WORDs
  23.  */
  24. static void set(addr, len, val)
  25.     WORD far    *addr;
  26.     int         len;
  27.     WORD         val;
  28.     {
  29.     while (len--)
  30.         *addr++ = val;
  31.     }
  32.  
  33.  
  34. /*
  35.  *    copy() ->    copy WORDs
  36.  */
  37. static void copy(src, dst, len)
  38.     WORD far    *src;
  39.     WORD far    *dst;
  40.     int         len;
  41.     {
  42.     while (len--)
  43.         *dst++ = *src++;
  44.     }
  45.  
  46.  
  47. /*
  48.  *    cls() ->    clear the screen
  49.  */
  50. static void cls()
  51.     {
  52.     set(VidSeg, 2000, Blank);    /*  clear the screen  */
  53.  
  54.     row = col = 0;            /*  reset  */
  55.     VidAddr = (WORD far *)VidSeg;
  56.     }
  57.  
  58.  
  59. /*
  60.  *    ScrollUp() ->    scroll screen upwards
  61.  */
  62. static void ScrollUp()
  63.     {
  64.     copy(VidSeg + 160, VidSeg, 1920);    /*  move up  */
  65.  
  66.     set(VidSeg + 3840, 80, Blank);        /*  clear last line  */
  67.  
  68.     VidAddr -= 80;
  69.     row = 24;
  70.     }
  71.  
  72.  
  73. /*
  74.  *    LineFeed() ->    perform line-feed
  75.  */
  76. static void LineFeed()
  77.     {
  78.     VidAddr += 80;
  79.     if (++row > 24)
  80.         ScrollUp();
  81.     }
  82.  
  83.  
  84. /*
  85.  *    Put() ->    write character to screen
  86.  */
  87. static void Put(c)
  88.     BYTE    c;
  89.     {
  90.     *VidAddr++ = (Attr + c);
  91.  
  92.     if (++col > 79)
  93.         {
  94.         col = 0;
  95.         LineFeed();
  96.         }
  97.     }
  98.  
  99.  
  100. /********************************
  101.  *    public routines        *
  102.  *******************************/
  103.  
  104. /*
  105.  *    Init() ->    initialize driver
  106.  */
  107. void Init()
  108.     {
  109.     cls();
  110.  
  111.     ((InitParms *)&ReqHdr)->EndAddr = EndAddr();
  112.     ReqHdr.Status = Done;
  113.     }
  114.  
  115.  
  116. /*
  117.  *    Output() ->    write bytes
  118.  */
  119. void Output()
  120.     {
  121.     InOutParms    *iop;    /*  our pointer        */
  122.     BYTE far    *ta;    /*  -> transfer addr    */
  123.     WORD        ctr;    /*  byte count        */
  124.     BYTE        c;
  125.  
  126.     iop = (InOutParms *)&ReqHdr;
  127.     ta = (BYTE far *)iop->Transfer;
  128.     ctr = iop->Count;
  129.  
  130.     while (ctr--)
  131.         {
  132.         switch (c = *ta++)
  133.             {
  134.             case '\r' :
  135.                 VidAddr -= col;    /*  move ptr  */
  136.                 col = 0;
  137.                 break;
  138.  
  139.             case '\n' :
  140.                 LineFeed();
  141.                 break;
  142.  
  143.             case '\b' :
  144.                 if (col)
  145.                     {
  146.                     col--;
  147.                     VidAddr--;
  148.                     }
  149.                 break;
  150.  
  151.             case '\t' :
  152.                 do
  153.                     Put(' ');
  154.                 while (col & 7);
  155.                 break;
  156.  
  157.             case '\f' :
  158.                 cls();
  159.                 break;
  160.  
  161.             default :
  162.                 Put(c);
  163.                 break;
  164.             }
  165.         }
  166.  
  167.     ReqHdr.Status = Done;
  168.     }
  169.  
  170.  
  171. /*
  172.  *    OutVerify() ->    output with verfiy
  173.  */
  174. void OutVerify()
  175.     {
  176.     Output();    /*  what can go wrong ??  */
  177.     }
  178.  
  179.  
  180. /*
  181.  *    OutStatus() ->    return output status
  182.  */
  183. void OutStatus()
  184.     {
  185.     ReqHdr.Status = Done;    /*  always ready  */
  186.     }
  187.  
  188.  
  189. /*
  190.  *    OutFlush() ->    flush output
  191.  */
  192. void OutFlush()
  193.     {
  194.     ReqHdr.Status = Done;    /*  always flushed  */
  195.     }
  196.  
  197.  
  198. /*
  199.  *    END of mono.c
  200.  */
  201.