home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / progrmng / stk110.lzh / STKSRC.COM / SPR_LOW.DEF < prev    next >
Encoding:
Text File  |  1991-02-25  |  4.5 KB  |  146 lines

  1. /**********************************************************************
  2. * The hardware INdependent skeletons for the hardware dependent
  3. * low level routines. This file is included by the file spr_low.c
  4. * once for each different graphics card.
  5. **********************************************************************
  6.                     This file is part of
  7.  
  8.           STK -- The sprite toolkit -- version 1.1
  9.  
  10.               Copyright (C) Jari Karjala 1991
  11.  
  12. The sprite toolkit (STK) is a FreeWare toolkit for creating high
  13. resolution sprite graphics with PCompatible hardware. This toolkit 
  14. is provided as is without any warranty or such thing. See the file
  15. COPYING for further information.
  16.  
  17. **********************************************************************/
  18.  
  19. /**********************************************************************
  20. * PUT
  21. * Put the given shape into the given address using the given mask and
  22. * saving the old contents into the given buffer. The shape and mask
  23. * data must be combined as described in the file sprP.h and they
  24. * must reside in the same segment as save buffer.
  25. * w       The width of the shape in bytes
  26. * h       The height of the shape in pixels
  27. * dest    The destination address in the frame buffer
  28. * shape   The address of the combined shape/mask data
  29. * save    The address of the save buffer
  30. **********************************************************************/
  31. void PUT(WORD w, WORD h, BYTE far *dest, BYTE far *shape, BYTE far *save)
  32. {
  33. #ifdef C_VER
  34.     
  35.     WORD i;
  36.     BYTE tmp;
  37.  
  38.     while (h-- > 0) {
  39.         for (i=0; i<w; i++, shape++, shape++, dest++, save++) {
  40.             tmp = *dest;
  41.             *dest = (tmp & *(shape+1)) | *shape;
  42.             *save = tmp;
  43.         }
  44.         NEXT_SCAN_LINE(dest, w);
  45.     }
  46.     
  47. #else
  48. /***** Assembler version is about 2 to 3 times faster *****/
  49. asm push ds
  50. asm push es
  51. asm cld
  52.     /** fetch parameters **/
  53. asm mov  ax, w
  54. asm mov  dl, al         /** use only low byte of width! **/
  55. asm mov  ax, h
  56. asm mov  dh, al         /** use only low byte of height! **/
  57. asm les  di, dest
  58. asm lds  si, shape      /** shape and save must point into same segment **/
  59. asm lds  bx, save
  60.     /** dh=height, dl=width, es:di=dest, ds:si=shape, ds:bx=save **/
  61. HEIGHT_LOOP:
  62. asm mov  cl, dl
  63. asm push di
  64. WIDTH_LOOP:
  65. asm lodsw            /** now we have shape byte in al and mask byte in ah **/
  66. asm mov  ch, es:[di] /** take byte from screen **/
  67. asm mov  [bx], ch    /**  save it **/
  68. asm and  ch, ah      /**  and it with mask **/
  69. asm or   al, ch      /**  or the shape **/
  70. asm stosb            /**  and store back **/
  71. asm inc  bx          /** next byte in save buffer **/
  72. asm dec  cl          /** decrement width counter and jump back if not zero **/
  73. asm jnz  WIDTH_LOOP
  74. asm pop  di
  75.     /** advance to next scanline **/
  76. ASM_NEXT_SCAN_LINE(di)
  77. asm dec  dh          /** decrement height counter and jump back if not zero */
  78. asm jnz  HEIGHT_LOOP
  79. asm pop  es
  80. asm pop  ds
  81.  
  82. #endif
  83.  
  84. }
  85.  
  86.  
  87. /**********************************************************************
  88. * ERASE
  89. * Erase the sprite from screen by putting the saved data back
  90. * w       The width of the shape in bytes
  91. * h       The height of the shape in pixels
  92. * dest    The destination address in the frame buffer
  93. * save    The address of the save buffer
  94. **********************************************************************/
  95. void ERASE(WORD w, WORD h, BYTE far *dest, BYTE far *save)
  96. {
  97. #ifdef C_VER
  98.     WORD i;
  99.  
  100.     while (h-- > 0) {
  101.         for (i=0; i<w; i++, dest++, save++)
  102.             *dest = *save;
  103.         NEXT_SCAN_LINE(dest, w);
  104.     }
  105. #else
  106. /***** Assembler version is about 2 to 3 times faster *****/
  107. asm push ds
  108. asm push es
  109. asm cld
  110.     /** fetch parameters **/
  111. asm mov  ax, w
  112. asm mov  dl, al         /** use only low byte of width! **/
  113. asm mov  ax, h
  114. asm mov  dh, al         /** use only low byte of height! **/
  115. asm les  di, dest
  116. asm lds  si, save
  117.     /** dh=height, dl=width, es:di=dest, ds:si=shape, ds:bx=save **/
  118. HEIGHT_LOOP:
  119. asm mov  cl, dl
  120. asm mov  ch, 0
  121. asm push di
  122. WIDTH_LOOP:
  123. asm rep movsb          /** restore one scanline **/
  124. asm pop  di
  125.     /** advance to next scanline **/
  126. ASM_NEXT_SCAN_LINE(di)
  127. asm dec  dh          /** decrement height counter and jump back if not zero */
  128. asm jnz  HEIGHT_LOOP
  129. asm pop  es
  130. asm pop  ds
  131.  
  132. #endif
  133. }
  134.  
  135. /** Undefine hardware dependent macros to make later redefinition easier **/
  136.  
  137. #undef PUT
  138. #undef ERASE
  139. #undef NEXT_SCAN_LINE
  140. #undef ASM_NEXT_SCAN_LINE
  141. #undef SCR_OFS
  142. #undef SCR_SEG
  143. #undef SCR_PAGE_2_SEG
  144.