LBITBLT.ASM 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. ;THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  2. ;SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
  3. ;END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  4. ;ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  5. ;IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  6. ;SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  7. ;FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  8. ;CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
  9. ;AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  10. ;COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  11. ;
  12. ; $Source: f:/miner/source/2d/rcs/lbitblt.asm $
  13. ; $Revision: 1.7 $
  14. ; $Author: mike $
  15. ; $Date: 1994/08/12 17:38:28 $
  16. ;
  17. ; Bitblt from linear to linear
  18. ;
  19. ; $Log: lbitblt.asm $
  20. ; Revision 1.7 1994/08/12 17:38:28 mike
  21. ; Fix bug.
  22. ;
  23. ; Revision 1.6 1994/08/11 17:59:33 mike
  24. ; Assembler versions for 3 rotations of merge functions.
  25. ;
  26. ; Revision 1.5 1994/01/22 14:35:16 john
  27. ; Added transparency as color index 255.
  28. ;
  29. ; Revision 1.4 1994/01/18 21:42:41 john
  30. ; unrolled loops in gr_merge_textures...
  31. ;
  32. ; Revision 1.3 1994/01/18 10:56:04 john
  33. ; Added code to merge two ttextures.
  34. ;
  35. ; Revision 1.2 1993/12/28 12:07:26 john
  36. ; initial version
  37. ;
  38. ; Revision 1.1 1993/12/22 11:05:46 john
  39. ; Initial revision
  40. ;
  41. ;
  42. .386
  43. option oldstructs
  44. .nolist
  45. include types.inc
  46. include psmacros.inc
  47. include gr.inc
  48. .list
  49. assume cs:_TEXT, ds:_DATA
  50. _DATA segment dword public USE32 'DATA'
  51. rcsid db "$Id: lbitblt.asm 1.7 1994/08/12 17:38:28 mike Exp $"
  52. align 4
  53. JumpTable dd RowAligned0, RowAligned1, RowAligned2, RowAligned3
  54. row_count dd ?
  55. _DATA ends
  56. _TEXT segment dword public USE32 'CODE'
  57. ; C-calling:
  58. ; void gr_lbitblt( grs_bitmap * source, grs_bitmap * dest, int height, int width )
  59. PUBLIC gr_lbitblt_
  60. gr_lbitblt_:
  61. ; EAX = grs_bitmap * source
  62. ; EDX = grs_bitmap * dest
  63. ; EBX = height
  64. ; ECX = width
  65. push esi
  66. push edi
  67. push ebp
  68. dec ebx
  69. js Done
  70. mov esi, [eax].bm_data
  71. mov edi, [edx].bm_data
  72. movzx eax, [eax].bm_rowsize
  73. sub eax, ecx
  74. movzx edx, [edx].bm_rowsize
  75. sub edx, ecx
  76. ; Can use ebp, eax, edx, ecx
  77. mov ebp, ecx
  78. cmp ebp, 16
  79. jb RowAligned0 ; If not 16 pixels wide, don't worry about alignment
  80. mov ecx, edi
  81. and ecx, 011b
  82. jmp NEAR32 PTR JumpTable[ecx*4]
  83. RowAligned0:
  84. NextRowAligned0:
  85. mov ecx, ebp
  86. shr ecx, 2
  87. rep movsd
  88. mov ecx, ebp
  89. and ecx, 11b
  90. rep movsb
  91. add esi, eax
  92. add edi, edx
  93. dec ebx
  94. jns NextRowAligned0
  95. pop ebp
  96. pop edi
  97. pop esi
  98. ret
  99. RowAligned1:
  100. sub ebp, 3
  101. NextRowAligned1:
  102. movsw
  103. movsb
  104. mov ecx, ebp
  105. shr ecx, 2
  106. rep movsd
  107. mov ecx, ebp
  108. and ecx, 11b
  109. rep movsb
  110. add esi, eax
  111. add edi, edx
  112. dec ebx
  113. jns NextRowAligned1
  114. pop ebp
  115. pop edi
  116. pop esi
  117. ret
  118. RowAligned2:
  119. sub ebp, 2
  120. NextRowAligned2:
  121. movsw
  122. mov ecx, ebp
  123. shr ecx, 2
  124. rep movsd
  125. mov ecx, ebp
  126. and ecx, 11b
  127. rep movsb
  128. add esi, eax
  129. add edi, edx
  130. dec ebx
  131. jns NextRowAligned2
  132. pop ebp
  133. pop edi
  134. pop esi
  135. ret
  136. RowAligned3:
  137. dec ebp
  138. NextRowAligned3:
  139. movsb
  140. mov ecx, ebp
  141. shr ecx, 2
  142. rep movsd
  143. mov ecx, ebp
  144. and ecx, 11b
  145. rep movsb
  146. add esi, eax
  147. add edi, edx
  148. dec ebx
  149. jns NextRowAligned3
  150. Done: pop ebp
  151. pop edi
  152. pop esi
  153. ret
  154. ; C-calling:
  155. ; void gr_merge_textures( ubyte * lower, ubyte * upper, ubyte * dest )
  156. PUBLIC gr_merge_textures_, gr_merge_textures_1_, gr_merge_textures_2_, gr_merge_textures_3_
  157. ; case 1:
  158. ; //
  159. ; for (y=0; y<64; y++ )
  160. ; for (x=0; x<64; x++ ) {
  161. ; c = top_data[ 64*x+(63-y) ];
  162. ; if (c==255)
  163. ; c = bottom_data[ 64*y+x ];
  164. ; *dest_data++ = c;
  165. ; }
  166. ; break;
  167. ; case 2:
  168. ; // Normal
  169. ; for (y=0; y<64; y++ )
  170. ; for (x=0; x<64; x++ ) {
  171. ; c = top_data[ 64*(63-y)+(63-x) ];
  172. ; if (c==255)
  173. ; c = bottom_data[ 64*y+x ];
  174. ; *dest_data++ = c;
  175. ; }
  176. ; break;
  177. ; case 3:
  178. ; // Normal
  179. ; for (y=0; y<64; y++ )
  180. ; for (x=0; x<64; x++ ) {
  181. ; c = top_data[ 64*(63-x)+y ];
  182. ; if (c==255)
  183. ; c = bottom_data[ 64*y+x ];
  184. ; *dest_data++ = c;
  185. ; }
  186. ; break;
  187. gr_merge_textures_:
  188. ; EAX = lower data
  189. ; EDX = upper data
  190. ; EBX = dest data
  191. push ebp
  192. push edi
  193. push ecx
  194. push esi
  195. mov ebp, edx
  196. mov edi, ebx
  197. mov bl, 255
  198. mov bh, bl
  199. and ebx, 0ffffh
  200. and edx, 0ffffh
  201. mov esi, eax
  202. mov ecx, (64*64)/2
  203. jmp gmt1
  204. second_must_be_not_trans:
  205. mov ah, dh
  206. mov [edi],ax
  207. add edi,2
  208. dec ecx
  209. je donegmt
  210. gmt1: mov dx, [ebp]
  211. add ebp, 2
  212. cmp edx, ebx
  213. jne not_transparent
  214. ; both transparent
  215. movsw
  216. dec ecx
  217. jne gmt1
  218. jmp donegmt
  219. ; DH OR DL ARE INVISIBLE
  220. not_transparent:
  221. mov ax,[esi]
  222. add esi,2
  223. cmp dl, bl
  224. je second_must_be_not_trans
  225. mov al, dl
  226. cmp dh, bh
  227. je @f
  228. mov ah, dh
  229. @@: mov [edi],ax
  230. add edi,2
  231. dec ecx
  232. jne gmt1
  233. donegmt:
  234. pop esi
  235. pop ecx
  236. pop edi
  237. pop ebp
  238. ret
  239. ; -----------------------------------------------------------------------------------------
  240. ; case 1, normal in x, flip in y
  241. gr_merge_textures_1_:
  242. ; eax = background data
  243. ; edx = foreground data
  244. ; ebx = destination address
  245. push ebp
  246. push edi
  247. push ecx
  248. push esi
  249. push ebx
  250. mov ch, 255 ; transparent color, stick in a register, is this faster?
  251. mov esi, 63 ; esi will be the offset to the current pixel
  252. mov row_count, esi
  253. mov ebp, 64 ; do for 64 pixels
  254. align 4
  255. gmt1_1: mov cl, [edx + esi] ; get foreground pixel
  256. add esi, 64 ; point at next row
  257. cmp cl, ch ; see if transparent
  258. jne not_transparent_1 ; dl contains a solid color, just write it
  259. mov cl,[eax] ; get background pixel
  260. not_transparent_1: mov [ebx], cl ; write pixel
  261. inc ebx ; point at next destination address
  262. inc eax
  263. dec ebp ; see if done a whole row
  264. jne gmt1_1 ; no, so do next pixel
  265. mov ebp, 64 ; do for 64 pixels
  266. dec row_count ; advance to next row
  267. mov esi, row_count ; doing next row, get offset, DANGER: DOESN'T SET FLAGS, BEWARE ON 68000, POWERPC!!
  268. jns gmt1_1 ; no (going down to 0)
  269. pop ebx
  270. pop esi
  271. pop ecx
  272. pop edi
  273. pop ebp
  274. ret
  275. ; -----------------------------------------------------------------------------------------
  276. ; case 1, normal in x, flip in y
  277. gr_merge_textures_2_:
  278. ; eax = background data
  279. ; edx = foreground data
  280. ; ebx = destination address
  281. push ebp
  282. push edi
  283. push ecx
  284. push esi
  285. push ebx
  286. mov ch, 255 ; transparent color, stick in a register, is this faster?
  287. mov esi, 63 + 64*63 ; esi will be the offset to the current pixel
  288. align 4
  289. gmt1_2: mov cl, [edx + esi] ; get foreground pixel
  290. cmp cl, ch ; see if transparent
  291. jne not_transparent_2 ; dl contains a solid color, just write it
  292. mov cl,[eax] ; get background pixel
  293. not_transparent_2: mov [ebx], cl ; write pixel
  294. inc ebx ; point at next destination address
  295. inc eax
  296. dec esi ; advance to next row
  297. jns gmt1_2 ; no (going down to 0)
  298. pop ebx
  299. pop esi
  300. pop ecx
  301. pop edi
  302. pop ebp
  303. ret
  304. ; -----------------------------------------------------------------------------------------
  305. ; case 1, normal in x, flip in y
  306. gr_merge_textures_3_:
  307. ; eax = background data
  308. ; edx = foreground data
  309. ; ebx = destination address
  310. push ebp
  311. push edi
  312. push ecx
  313. push esi
  314. push ebx
  315. mov ch, 255 ; transparent color, stick in a register, is this faster?
  316. mov esi, 64*63 ; esi will be the offset to the current pixel
  317. mov row_count, 64
  318. mov ebp, 32 ; do for 64 pixels (2x loop)
  319. ; first copy of loop
  320. align 4
  321. gmt1_3: mov cl, [edx + esi] ; get foreground pixel
  322. sub esi, 64 ; point at next row
  323. cmp cl, ch ; see if transparent
  324. jne not_transparent_3 ; dl contains a solid color, just write it
  325. mov cl,[eax] ; get background pixel
  326. not_transparent_3: inc eax
  327. mov [ebx], cl ; write pixel
  328. inc ebx ; point at next destination address
  329. ; second copy of loop
  330. mov cl, [edx + esi] ; get foreground pixel
  331. sub esi, 64 ; point at next row
  332. cmp cl, ch ; see if transparent
  333. jne nt_3a ; dl contains a solid color, just write it
  334. mov cl,[eax] ; get background pixel
  335. nt_3a: inc eax
  336. mov [ebx], cl ; write pixel
  337. inc ebx ; point at next destination address
  338. dec ebp ; see if done a whole row
  339. jne gmt1_3 ; no, so do next pixel
  340. mov ebp, 32 ; do for 64 pixels
  341. add esi, 64*64+1 ; doing next row, get offset, DANGER: DOESN'T SET FLAGS, BEWARE ON 68000, POWERPC!!
  342. dec row_count ; advance to next row
  343. jne gmt1_3 ; no (going down to 0)
  344. pop ebx
  345. pop esi
  346. pop ecx
  347. pop edi
  348. pop ebp
  349. ret
  350. _TEXT ends
  351. end