home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / GRAPHICS / MISC / STK100.ZIP / STKSRC.COM / SPR_LOW.DEF < prev    next >
Encoding:
Text File  |  1990-10-20  |  5.0 KB  |  164 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. * shape   The address of the combined shape/mask data
  42. * dest    The destination address in the frame buffer
  43. * save    The address of the save buffer
  44. * w       The width of the shape in bytes
  45. * h       The height of the shape in pixels
  46. **********************************************************************/
  47. void PUT(BYTE far *shape, BYTE far *dest, BYTE far *save, WORD w, WORD h)
  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. /**********************************************************************
  104. * ERASE
  105. * Erase the sprite from screen by putting the saved data back
  106. * dest    The destination address in the frame buffer
  107. * save    The address of the save buffer
  108. * w       The width of the shape in bytes
  109. * h       The height of the shape in pixels
  110. **********************************************************************/
  111. void ERASE(BYTE far *dest, BYTE far *save, WORD w, WORD h)
  112. {
  113. #ifdef C_VER
  114.     WORD i;
  115.  
  116.     while (h-- > 0) {
  117.         for (i=0; i<w; i++, dest++, save++)
  118.             *dest = *save;
  119.         NEXT_SCAN_LINE(dest, w);
  120.     }
  121. #else
  122. /***** Assembler version is about 2 to 3 times faster *****/
  123. asm push ds
  124. asm push es
  125. asm cld
  126.     /** fetch parameters **/
  127. asm mov  ax, w
  128. asm mov  dl, al         /** use only low byte of width! **/
  129. asm mov  ax, h
  130. asm mov  dh, al         /** use only low byte of height! **/
  131. asm les  di, dest
  132. asm lds  si, save
  133.     /** dh=height, dl=width, es:di=dest, ds:si=shape, ds:bx=save **/
  134. HEIGHT_LOOP:
  135. asm mov  cl, dl
  136. asm mov  ch, 0
  137. asm push di
  138. WIDTH_LOOP:
  139. asm rep movsb          /** restore one scanline **/
  140. asm pop  di
  141.     /** advance to next scanline **/
  142. ASM_NEXT_SCAN_LINE(di)
  143. asm dec  dh          /** decrement height counter and jump back if not zero */
  144. asm jnz  HEIGHT_LOOP
  145. asm pop  es
  146. asm pop  ds
  147.  
  148. #endif
  149. }
  150.  
  151. /** Undefine hardware dependent macros to make later redefinition easier **/
  152.  
  153. #undef ADDR
  154. #undef PUT
  155. #undef ERASE
  156. #undef NEXT_SCAN_LINE
  157. #undef ASM_NEXT_SCAN_LINE
  158. #undef SCR_OFS
  159. #undef SCR_SEG
  160. #undef SCR_PAGE_2_SEG
  161.