home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 2.ddi / CLIBSRC3.ZIP / VRAM.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  5.3 KB  |  136 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - vram.cas
  3.  *
  4.  * function(s)
  5.  *        vptr   - returns a pointer to a screen position.
  6.  *        __vram - moves bytes of video RAM and checks for snow
  7.  *-----------------------------------------------------------------------*/
  8.  
  9. /*
  10.  *      C/C++ Run Time Library - Version 5.0
  11.  *
  12.  *      Copyright (c) 1987, 1992 by Borland International
  13.  *      All Rights Reserved.
  14.  *
  15.  */
  16.  
  17.  
  18. #pragma inline
  19. #include <_video.h>
  20. #include <dos.h>
  21.  
  22. /*-----------------------------------------------------------------------*
  23.  
  24. Name            vptr - returns a pointer to a screen position.
  25.  
  26. Usage           void far * pascal __vptr(int x, int y)
  27.  
  28. Prototype in    _video.h
  29.  
  30. Description     returns a pointer to the position (x, y) on the screen
  31.  
  32. *------------------------------------------------------------------------*/
  33. void far * pascal near __vptr(int x, int y)
  34. {
  35.   return MK_FP(_video.displayptr.u.seg,
  36.                (_video.displayptr.u.off+(y-1)*_video.screenwidth+(x-1))*2);
  37. }
  38.  
  39. /*-----------------------------------------------------------------------*
  40.  
  41. Name            __vram - moves bytes of video RAM and checks for snow
  42.  
  43. Usage           void pascal __vram(void far *dst, void far *src, int len)
  44.  
  45. Prototype in    _video.h
  46.  
  47. Description     moves len bytes of video RAM from src to dst and checks
  48.                 for snow.
  49.  
  50. *------------------------------------------------------------------------*/
  51. void pascal near __vram(void far *dst, void far *src, int len)
  52. {
  53. int snow;
  54.  
  55.         snow = _video.snow;
  56.  
  57.         asm     push    ds
  58.         asm     mov     cx, len         /* Length value into CX */
  59.         asm     jcxz    VRAMExit
  60.         asm     les     di, dst         /* Get pointers to data area */
  61.         asm     lds     si, src
  62.  
  63.         asm     cld                     /* Setup move direction */
  64.         asm     cmp     si, di          /* Check for move direction */
  65.         asm     jae     VRAMSnowTest    /* Moving down?, then forward move ok */
  66.         asm     mov     ax, cx          /* Nope, then start at other end */
  67.         asm     dec     ax
  68.         asm     shl     ax, 1
  69.         asm     add     si, ax
  70.         asm     add     di, ax
  71.         asm     std
  72.  
  73. VRAMSnowTest:
  74.         asm     cmp     word ptr snow, 0/* Does video card snow ? */
  75.         asm     jnz     VRAMStopSnow    /* Yes, wait for retrace */
  76.         asm     rep     movsw           /* Suppose to do both, do normal move */
  77.         asm     jmp     short VRAMExit  /* All done */
  78.  
  79. VRAMStopSnow:
  80.  
  81.         asm     mov     dx, 3DAh        /* Suppose to wait, Point DX to CGA status port */
  82.         asm     mov     ax, es          /* See if both are in video seg */
  83.         asm     mov     bx, ds
  84.         asm     cmp     ax, bx
  85.         asm     je      VIOStopSnow     /* Have to wait to and fro */
  86.  
  87. VRAMWait4HRetrace:
  88.         asm     cli                     /* No ints during critical section */
  89. VRAMSynchronize:
  90.         asm     in      al, dx          /* Get 6845 status */
  91.         asm     ror     al, 1           /* In horizontal retrace ? */
  92.         asm     jc      VRAMSynchronize /* If on, wait for cycle to end */
  93. VRAMWaitForNext:
  94.         asm     in      al, dx          /* Get 6845 status */
  95.         asm     ror     al, 1           /* In horizontal retrace ? */
  96.         asm     jnc     VRAMWaitForNext /* No, wait for it to begin */
  97.         asm     movsw                   /* Move video ram word */
  98.         asm     sti                     /* Allow interrupts */
  99.         asm     loop    VRAMWait4HRetrace/* Next byte */
  100.         asm     jmp     short VRAMExit
  101.  
  102. VIOStopSnow:
  103. VInWait4HRetrace:
  104.         asm     cli                     /* No ints during critical section */
  105. VInSynchronize:
  106.         asm     in      al, dx          /* Get 6845 status */
  107.         asm     ror     al, 1           /* In horizontal retrace ? */
  108.         asm     jc      VInSynchronize  /* If on, wait for cycle to end */
  109. VInWaitForNext:
  110.         asm     in      al, dx          /* Get 6845 status */
  111.         asm     ror     al, 1           /* In horizontal retrace ? */
  112.         asm     jnc     VInWaitForNext  /* No, wait for it to begin */
  113.         asm     lodsw                   /* Get word from video ram */
  114.         asm     sti                     /* Allow interrupts */
  115.         asm     mov     bx, ax          /* Save word
  116.         asm     cli                     /* No ints during critical section */
  117. VOutSynchronize:
  118.         asm     in      al, dx          /* Get 6845 status */
  119.         asm     ror     al, 1           /* In horizontal retrace ? */
  120.         asm     jc      VOutSynchronize /* If on, wait for cycle to end */
  121. VOutWaitForNext:
  122.         asm     in      al, dx          /* Get 6845 status */
  123.         asm     ror     al, 1           /* In horizontal retrace ? */
  124.         asm     jnc     VOutWaitForNext /* No, wait for it to begin */
  125.         asm     mov     ax, bx          /* Get word to store */
  126.         asm     stosw                   /* Put word in video ram */
  127.         asm     sti                     /* Allow interrupts */
  128.         asm     loop    VInWait4HRetrace/* Next byte */
  129.  
  130. VRAMExit:
  131.         asm     cld                     /* Restore Direction Flag */
  132.         asm     pop     ds
  133.  
  134.         return;
  135. }
  136.