home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / progrmng / stk110.lzh / STKSRC.COM / XSPR_LOW.DEF < prev   
Encoding:
Text File  |  1991-02-25  |  6.8 KB  |  225 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.0
  9.  
  10.               Copyright (C) Jari Karjala 1990
  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. /**********************************************************************
  21. * ADDR
  22. * Return the address of the given (x,y) coordinate pair in the
  23. * given graphics page.
  24. * x,y     X,Y coordinates
  25. * page    The graphics page (0/1)
  26. *
  27. * Return: far pointer into the screen.
  28. **********************************************************************/
  29. BYTE far *ADDR(WORD x, WORD y, BYTE page)
  30. {
  31.     return (BYTE far *)MK_FP(SCR_SEG+page*SCR_PAGE_2_SEG, SCR_OFS(x,y));
  32. }
  33.  
  34.  
  35. /**********************************************************************
  36. * PUT
  37. * Put the given shape into the given address using the given mask and
  38. * saving the old contents into the given buffer. The shape and mask
  39. * data must be combined as described in the file sprP.h and they
  40. * must reside in the same segment as save buffer.
  41. * w       The width of the shape in bytes
  42. * h       The height of the shape in pixels
  43. * dest    The destination address in the frame buffer
  44. * shape   The address of the combined shape/mask data
  45. * save    The address of the save buffer
  46. **********************************************************************/
  47. void PUT(WORD w, WORD h, BYTE far *dest, BYTE far *shape, BYTE far *save)
  48. {
  49. #ifdef C_VER
  50.     
  51.     WORD i;
  52.     BYTE tmp;
  53.  
  54.     while (h-- > 0) {
  55.         for (i=0; i<w; i++, shape++, shape++, dest++, save++) {
  56.             tmp = *dest;
  57.             *dest = (tmp & *(shape+1)) | *shape;
  58.             *save = tmp;
  59.         }
  60.         NEXT_SCAN_LINE(dest, w);
  61.     }
  62.     
  63. #else
  64. /***** Assembler version is about 2 to 3 times faster *****/
  65. asm push ds
  66. asm push es
  67. asm cld
  68.     /** fetch parameters **/
  69. asm mov  ax, w
  70. asm mov  dl, al         /** use only low byte of width! **/
  71. asm mov  ax, h
  72. asm mov  dh, al         /** use only low byte of height! **/
  73. asm les  di, dest
  74. asm lds  si, shape      /** shape and save must point into same segment **/
  75. asm lds  bx, save
  76.     /** dh=height, dl=width, es:di=dest, ds:si=shape, ds:bx=save **/
  77. HEIGHT_LOOP:
  78. asm mov  cl, dl
  79. asm push di
  80. WIDTH_LOOP:
  81. asm lodsw            /** now we have shape byte in al and mask byte in ah **/
  82. asm mov  ch, es:[di] /** take byte from screen **/
  83. asm mov  [bx], ch    /**  save it **/
  84. asm and  ch, ah      /**  and it with mask **/
  85. asm or   al, ch      /**  or the shape **/
  86. asm stosb            /**  and store back **/
  87. asm inc  bx          /** next byte in save buffer **/
  88. asm dec  cl          /** decrement width counter and jump back if not zero **/
  89. asm jnz  WIDTH_LOOP
  90. asm pop  di
  91.     /** advance to next scanline **/
  92. ASM_NEXT_SCAN_LINE(di)
  93. asm dec  dh          /** decrement height counter and jump back if not zero */
  94. asm jnz  HEIGHT_LOOP
  95. asm pop  es
  96. asm pop  ds
  97.  
  98. #endif
  99.  
  100. }
  101.  
  102. /**********************************************************************
  103. * XOR_PUT
  104. * Put the given shape into the given address using the XOR method.
  105. * The shape and mask
  106. * data must be combined as described in the file sprP.h and they
  107. * must reside in the same segment as save buffer.
  108. * w       The width of the shape in bytes
  109. * h       The height of the shape in pixels
  110. * dest    The destination address in the frame buffer
  111. * shape   The address of the combined shape/mask data
  112. * save    The address of the save buffer    (NOT USED)
  113. **********************************************************************/
  114. void XOR_PUT(WORD w, WORD h, BYTE far *dest, BYTE far *shape, BYTE far *save)
  115. {
  116. #ifdef C_VER
  117.     
  118.     WORD i;
  119.     BYTE tmp;
  120.  
  121.     while (h-- > 0) {
  122.         for (i=0; i<w; i++, shape++, shape++, dest++)
  123.             *dest ^= *shape;
  124.         NEXT_SCAN_LINE(dest, w);
  125.     }
  126.     
  127. #else
  128. /***** Assembler version is about 2 to 3 times faster *****/
  129. asm push ds
  130. asm push es
  131. asm cld
  132.     /** fetch parameters **/
  133. asm mov  ax, w
  134. asm mov  dl, al         /** use only low byte of width! **/
  135. asm mov  ax, h
  136. asm mov  dh, al         /** use only low byte of height! **/
  137. asm les  di, dest
  138. asm lds  si, shape
  139.     /** dh=height, dl=width, es:di=dest, ds:si=shape **/
  140. HEIGHT_LOOP:
  141. asm mov  cl, dl
  142. asm push di
  143. WIDTH_LOOP:
  144. asm lodsw            /** now we have shape byte in al and mask byte in ah **/
  145. asm xor  es:[di], al /** take byte from screen **/
  146. asm inc  di          /** next byte in screen **/
  147. asm dec  cl          /** decrement width counter and jump back if not zero **/
  148. asm jnz  WIDTH_LOOP
  149. asm pop  di
  150.     /** advance to next scanline **/
  151. ASM_NEXT_SCAN_LINE(di)
  152. asm dec  dh          /** decrement height counter and jump back if not zero */
  153. asm jnz  HEIGHT_LOOP
  154. asm pop  es
  155. asm pop  ds
  156.  
  157. #endif
  158.  
  159. }
  160.  
  161.  
  162. /**********************************************************************
  163. * ERASE
  164. * Erase the sprite from screen by putting the saved data back
  165. * dest    The destination address in the frame buffer
  166. * save    The address of the save buffer
  167. * w       The width of the shape in bytes
  168. * h       The height of the shape in pixels
  169. **********************************************************************/
  170. void ERASE(WORD w, WORD h, BYTE far *dest, BYTE far *save)
  171. {
  172. #ifdef C_VER
  173.     WORD i;
  174.  
  175.     while (h-- > 0) {
  176.         for (i=0; i<w; i++, dest++, save++)
  177.             *dest = *save;
  178.         NEXT_SCAN_LINE(dest, w);
  179.     }
  180. #else
  181. /***** Assembler version is about 2 to 3 times faster *****/
  182. asm push ds
  183. asm push es
  184. asm cld
  185.     /** fetch parameters **/
  186. asm mov  ax, w
  187. asm mov  dl, al         /** use only low byte of width! **/
  188. asm mov  ax, h
  189. asm mov  dh, al         /** use only low byte of height! **/
  190. asm les  di, dest
  191. asm lds  si, save
  192.     /** dh=height, dl=width, es:di=dest, ds:si=shape, ds:bx=save **/
  193. HEIGHT_LOOP:
  194. asm mov  cl, dl
  195. asm mov  ch, 0
  196. asm push di
  197. WIDTH_LOOP:
  198. asm rep movsb          /** restore one scanline **/
  199. asm pop  di
  200.     /** advance to next scanline **/
  201. ASM_NEXT_SCAN_LINE(di)
  202. asm dec  dh          /** decrement height counter and jump back if not zero */
  203. asm jnz  HEIGHT_LOOP
  204. asm pop  es
  205. asm pop  ds
  206.  
  207. #endif
  208. }
  209.  
  210. /** Undefine hardware dependent macros to make later redefinition easier **/
  211.  
  212. #undef ADDR
  213. #undef PUT
  214. #undef XOR_PUT
  215. #undef ERASE
  216. #undef NEXT_SCAN_LINE
  217. #undef ASM_NEXT_SCAN_LINE
  218. #undef SCR_OFS
  219. #undef SCR_SEG
  220. #undef SCR_PAGE_2_SEG
  221.