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