home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 361_02 / vpeek.ca < prev    next >
Text File  |  1991-09-16  |  2KB  |  98 lines

  1.  
  2. /* Vpeek.c ---> Direct Video RAM Access w/ Snow Control.
  3.  *
  4.  * Author: J.Ekwall                    13 September 91
  5.  *
  6.  * Copyrighted to the Public Domain.  Unlimited Distribution Authorized.
  7.  *
  8.  * User Assumes All Risks/Liabilities.
  9.  *
  10.  * Last Update: 13 September 91/EK
  11.  */
  12.  
  13. #pragma inline                /* TCC -B -c -ms vpeek.ca */
  14. #include <dos.h>
  15. #include <stdek.h>
  16. #include <gadgets.h>
  17.  
  18. #define VSEG        0xB800
  19.  
  20. static int SnowStop;
  21.  
  22. void CgaSnowFence(void) { SnowStop++; }
  23.  
  24. void Vpoke(unsigned adr, unsigned chr)
  25. {
  26.     if (!SnowStop) poke(VSEG, adr, chr);
  27.     else    {
  28.        _DI = adr;              /* offset of video character */
  29.        _ES = VSEG;             /* video segment */
  30.        asm cld;
  31.        _BX = chr;              /* the attribute and character */
  32.        _DX = 986;              /* video status port */
  33.        
  34.        /* ------ wait for video retrace to start ----- */
  35.        do
  36.           asm in  al,dx;
  37.        while (_AL & 1);
  38.        
  39.        /* ------ wait for video retrace to stop ----- */
  40.        do
  41.           asm in  al,dx;
  42.        while (!(_AL & 1));
  43.        _AL = _BL;
  44.        asm stosb;              /* store character */
  45.        
  46.        /* ------ wait for video retrace to start ----- */
  47.        do
  48.           asm in  al,dx;
  49.        while (_AL & 1);
  50.        
  51.        /* ------ wait for video retrace to stop ----- */
  52.        do
  53.           asm in  al,dx;
  54.        while (!(_AL & 1));
  55.        _AL = _BH;
  56.        asm stosb;              /* store attribute */
  57.     }
  58. }
  59.  
  60. int Vpeek(unsigned adr)
  61. /* read a character and attribute from video RAM */
  62. {
  63.     if (!SnowStop) return peek(VSEG, adr);
  64.     asm push ds;
  65.     _DX = 986;                      /* video status port */
  66.     _DS = VSEG;                     /* video segment address */
  67.     _SI = adr;                      /* video character offset */
  68.     asm cld;
  69.     
  70.     /* wait for video retrace to start ----- */
  71.     do
  72.        asm in  al,dx;
  73.     while (_AL & 1);
  74.     
  75.     /* wait for video retrace to stop */
  76.     do
  77.        asm in  al,dx;
  78.     while (!(_AL & 1));
  79.     asm lodsb;                      /* get the character */
  80.     _BL = _AL;
  81.     
  82.     /* wait for video retrace to start */
  83.     do
  84.        asm in  al,dx;
  85.     while (_AL & 1);
  86.     
  87.     /* ait for video retrace to stop */
  88.     do
  89.        asm in  al,dx;
  90.     while (!(_AL & 1));
  91.     asm lodsb;                      /* get the attribute */
  92.     _BH = _AL;
  93.     _AX = _BX;
  94.     asm pop ds;
  95.     return _AX;
  96. }
  97.  
  98.