r_surf8.s 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. //
  2. // surf8.s
  3. // x86 assembly-language 8 bpp surface block drawing code.
  4. //
  5. #include "qasm.h"
  6. #if id386
  7. .data
  8. sb_v: .long 0
  9. .text
  10. .align 4
  11. .globl C(R_Surf8Start)
  12. C(R_Surf8Start):
  13. //----------------------------------------------------------------------
  14. // Surface block drawer for mip level 0
  15. //----------------------------------------------------------------------
  16. .align 4
  17. .globl C(R_DrawSurfaceBlock8_mip0)
  18. C(R_DrawSurfaceBlock8_mip0):
  19. pushl %ebp // preserve caller's stack frame
  20. pushl %edi
  21. pushl %esi // preserve register variables
  22. pushl %ebx
  23. // for (v=0 ; v<numvblocks ; v++)
  24. // {
  25. movl C(r_lightptr),%ebx
  26. movl C(r_numvblocks),%eax
  27. movl %eax,sb_v
  28. movl C(prowdestbase),%edi
  29. movl C(pbasesource),%esi
  30. Lv_loop_mip0:
  31. // lightleft = lightptr[0];
  32. // lightright = lightptr[1];
  33. // lightdelta = (lightleft - lightright) & 0xFFFFF;
  34. movl (%ebx),%eax // lightleft
  35. movl 4(%ebx),%edx // lightright
  36. movl %eax,%ebp
  37. movl C(r_lightwidth),%ecx
  38. movl %edx,C(lightright)
  39. subl %edx,%ebp
  40. andl $0xFFFFF,%ebp
  41. leal (%ebx,%ecx,4),%ebx
  42. // lightptr += lightwidth;
  43. movl %ebx,C(r_lightptr)
  44. // lightleftstep = (lightptr[0] - lightleft) >> blockdivshift;
  45. // lightrightstep = (lightptr[1] - lightright) >> blockdivshift;
  46. // lightdeltastep = ((lightleftstep - lightrightstep) & 0xFFFFF) |
  47. // 0xF0000000;
  48. movl 4(%ebx),%ecx // lightptr[1]
  49. movl (%ebx),%ebx // lightptr[0]
  50. subl %eax,%ebx
  51. subl %edx,%ecx
  52. sarl $4,%ecx
  53. orl $0xF0000000,%ebp
  54. sarl $4,%ebx
  55. movl %ecx,C(lightrightstep)
  56. subl %ecx,%ebx
  57. andl $0xFFFFF,%ebx
  58. orl $0xF0000000,%ebx
  59. subl %ecx,%ecx // high word must be 0 in loop for addressing
  60. movl %ebx,C(lightdeltastep)
  61. subl %ebx,%ebx // high word must be 0 in loop for addressing
  62. Lblockloop8_mip0:
  63. movl %ebp,C(lightdelta)
  64. movb 14(%esi),%cl
  65. sarl $4,%ebp
  66. movb %dh,%bh
  67. movb 15(%esi),%bl
  68. addl %ebp,%edx
  69. movb %dh,%ch
  70. addl %ebp,%edx
  71. movb 0x12345678(%ebx),%ah
  72. LBPatch0:
  73. movb 13(%esi),%bl
  74. movb 0x12345678(%ecx),%al
  75. LBPatch1:
  76. movb 12(%esi),%cl
  77. movb %dh,%bh
  78. addl %ebp,%edx
  79. rorl $16,%eax
  80. movb %dh,%ch
  81. addl %ebp,%edx
  82. movb 0x12345678(%ebx),%ah
  83. LBPatch2:
  84. movb 11(%esi),%bl
  85. movb 0x12345678(%ecx),%al
  86. LBPatch3:
  87. movb 10(%esi),%cl
  88. movl %eax,12(%edi)
  89. movb %dh,%bh
  90. addl %ebp,%edx
  91. movb %dh,%ch
  92. addl %ebp,%edx
  93. movb 0x12345678(%ebx),%ah
  94. LBPatch4:
  95. movb 9(%esi),%bl
  96. movb 0x12345678(%ecx),%al
  97. LBPatch5:
  98. movb 8(%esi),%cl
  99. movb %dh,%bh
  100. addl %ebp,%edx
  101. rorl $16,%eax
  102. movb %dh,%ch
  103. addl %ebp,%edx
  104. movb 0x12345678(%ebx),%ah
  105. LBPatch6:
  106. movb 7(%esi),%bl
  107. movb 0x12345678(%ecx),%al
  108. LBPatch7:
  109. movb 6(%esi),%cl
  110. movl %eax,8(%edi)
  111. movb %dh,%bh
  112. addl %ebp,%edx
  113. movb %dh,%ch
  114. addl %ebp,%edx
  115. movb 0x12345678(%ebx),%ah
  116. LBPatch8:
  117. movb 5(%esi),%bl
  118. movb 0x12345678(%ecx),%al
  119. LBPatch9:
  120. movb 4(%esi),%cl
  121. movb %dh,%bh
  122. addl %ebp,%edx
  123. rorl $16,%eax
  124. movb %dh,%ch
  125. addl %ebp,%edx
  126. movb 0x12345678(%ebx),%ah
  127. LBPatch10:
  128. movb 3(%esi),%bl
  129. movb 0x12345678(%ecx),%al
  130. LBPatch11:
  131. movb 2(%esi),%cl
  132. movl %eax,4(%edi)
  133. movb %dh,%bh
  134. addl %ebp,%edx
  135. movb %dh,%ch
  136. addl %ebp,%edx
  137. movb 0x12345678(%ebx),%ah
  138. LBPatch12:
  139. movb 1(%esi),%bl
  140. movb 0x12345678(%ecx),%al
  141. LBPatch13:
  142. movb (%esi),%cl
  143. movb %dh,%bh
  144. addl %ebp,%edx
  145. rorl $16,%eax
  146. movb %dh,%ch
  147. movb 0x12345678(%ebx),%ah
  148. LBPatch14:
  149. movl C(lightright),%edx
  150. movb 0x12345678(%ecx),%al
  151. LBPatch15:
  152. movl C(lightdelta),%ebp
  153. movl %eax,(%edi)
  154. addl C(sourcetstep),%esi
  155. addl C(surfrowbytes),%edi
  156. addl C(lightrightstep),%edx
  157. addl C(lightdeltastep),%ebp
  158. movl %edx,C(lightright)
  159. jc Lblockloop8_mip0
  160. // if (pbasesource >= r_sourcemax)
  161. // pbasesource -= stepback;
  162. cmpl C(r_sourcemax),%esi
  163. jb LSkip_mip0
  164. subl C(r_stepback),%esi
  165. LSkip_mip0:
  166. movl C(r_lightptr),%ebx
  167. decl sb_v
  168. jnz Lv_loop_mip0
  169. popl %ebx // restore register variables
  170. popl %esi
  171. popl %edi
  172. popl %ebp // restore the caller's stack frame
  173. ret
  174. //----------------------------------------------------------------------
  175. // Surface block drawer for mip level 1
  176. //----------------------------------------------------------------------
  177. .align 4
  178. .globl C(R_DrawSurfaceBlock8_mip1)
  179. C(R_DrawSurfaceBlock8_mip1):
  180. pushl %ebp // preserve caller's stack frame
  181. pushl %edi
  182. pushl %esi // preserve register variables
  183. pushl %ebx
  184. // for (v=0 ; v<numvblocks ; v++)
  185. // {
  186. movl C(r_lightptr),%ebx
  187. movl C(r_numvblocks),%eax
  188. movl %eax,sb_v
  189. movl C(prowdestbase),%edi
  190. movl C(pbasesource),%esi
  191. Lv_loop_mip1:
  192. // lightleft = lightptr[0];
  193. // lightright = lightptr[1];
  194. // lightdelta = (lightleft - lightright) & 0xFFFFF;
  195. movl (%ebx),%eax // lightleft
  196. movl 4(%ebx),%edx // lightright
  197. movl %eax,%ebp
  198. movl C(r_lightwidth),%ecx
  199. movl %edx,C(lightright)
  200. subl %edx,%ebp
  201. andl $0xFFFFF,%ebp
  202. leal (%ebx,%ecx,4),%ebx
  203. // lightptr += lightwidth;
  204. movl %ebx,C(r_lightptr)
  205. // lightleftstep = (lightptr[0] - lightleft) >> blockdivshift;
  206. // lightrightstep = (lightptr[1] - lightright) >> blockdivshift;
  207. // lightdeltastep = ((lightleftstep - lightrightstep) & 0xFFFFF) |
  208. // 0xF0000000;
  209. movl 4(%ebx),%ecx // lightptr[1]
  210. movl (%ebx),%ebx // lightptr[0]
  211. subl %eax,%ebx
  212. subl %edx,%ecx
  213. sarl $3,%ecx
  214. orl $0x70000000,%ebp
  215. sarl $3,%ebx
  216. movl %ecx,C(lightrightstep)
  217. subl %ecx,%ebx
  218. andl $0xFFFFF,%ebx
  219. orl $0xF0000000,%ebx
  220. subl %ecx,%ecx // high word must be 0 in loop for addressing
  221. movl %ebx,C(lightdeltastep)
  222. subl %ebx,%ebx // high word must be 0 in loop for addressing
  223. Lblockloop8_mip1:
  224. movl %ebp,C(lightdelta)
  225. movb 6(%esi),%cl
  226. sarl $3,%ebp
  227. movb %dh,%bh
  228. movb 7(%esi),%bl
  229. addl %ebp,%edx
  230. movb %dh,%ch
  231. addl %ebp,%edx
  232. movb 0x12345678(%ebx),%ah
  233. LBPatch22:
  234. movb 5(%esi),%bl
  235. movb 0x12345678(%ecx),%al
  236. LBPatch23:
  237. movb 4(%esi),%cl
  238. movb %dh,%bh
  239. addl %ebp,%edx
  240. rorl $16,%eax
  241. movb %dh,%ch
  242. addl %ebp,%edx
  243. movb 0x12345678(%ebx),%ah
  244. LBPatch24:
  245. movb 3(%esi),%bl
  246. movb 0x12345678(%ecx),%al
  247. LBPatch25:
  248. movb 2(%esi),%cl
  249. movl %eax,4(%edi)
  250. movb %dh,%bh
  251. addl %ebp,%edx
  252. movb %dh,%ch
  253. addl %ebp,%edx
  254. movb 0x12345678(%ebx),%ah
  255. LBPatch26:
  256. movb 1(%esi),%bl
  257. movb 0x12345678(%ecx),%al
  258. LBPatch27:
  259. movb (%esi),%cl
  260. movb %dh,%bh
  261. addl %ebp,%edx
  262. rorl $16,%eax
  263. movb %dh,%ch
  264. movb 0x12345678(%ebx),%ah
  265. LBPatch28:
  266. movl C(lightright),%edx
  267. movb 0x12345678(%ecx),%al
  268. LBPatch29:
  269. movl C(lightdelta),%ebp
  270. movl %eax,(%edi)
  271. movl C(sourcetstep),%eax
  272. addl %eax,%esi
  273. movl C(surfrowbytes),%eax
  274. addl %eax,%edi
  275. movl C(lightrightstep),%eax
  276. addl %eax,%edx
  277. movl C(lightdeltastep),%eax
  278. addl %eax,%ebp
  279. movl %edx,C(lightright)
  280. jc Lblockloop8_mip1
  281. // if (pbasesource >= r_sourcemax)
  282. // pbasesource -= stepback;
  283. cmpl C(r_sourcemax),%esi
  284. jb LSkip_mip1
  285. subl C(r_stepback),%esi
  286. LSkip_mip1:
  287. movl C(r_lightptr),%ebx
  288. decl sb_v
  289. jnz Lv_loop_mip1
  290. popl %ebx // restore register variables
  291. popl %esi
  292. popl %edi
  293. popl %ebp // restore the caller's stack frame
  294. ret
  295. //----------------------------------------------------------------------
  296. // Surface block drawer for mip level 2
  297. //----------------------------------------------------------------------
  298. .align 4
  299. .globl C(R_DrawSurfaceBlock8_mip2)
  300. C(R_DrawSurfaceBlock8_mip2):
  301. pushl %ebp // preserve caller's stack frame
  302. pushl %edi
  303. pushl %esi // preserve register variables
  304. pushl %ebx
  305. // for (v=0 ; v<numvblocks ; v++)
  306. // {
  307. movl C(r_lightptr),%ebx
  308. movl C(r_numvblocks),%eax
  309. movl %eax,sb_v
  310. movl C(prowdestbase),%edi
  311. movl C(pbasesource),%esi
  312. Lv_loop_mip2:
  313. // lightleft = lightptr[0];
  314. // lightright = lightptr[1];
  315. // lightdelta = (lightleft - lightright) & 0xFFFFF;
  316. movl (%ebx),%eax // lightleft
  317. movl 4(%ebx),%edx // lightright
  318. movl %eax,%ebp
  319. movl C(r_lightwidth),%ecx
  320. movl %edx,C(lightright)
  321. subl %edx,%ebp
  322. andl $0xFFFFF,%ebp
  323. leal (%ebx,%ecx,4),%ebx
  324. // lightptr += lightwidth;
  325. movl %ebx,C(r_lightptr)
  326. // lightleftstep = (lightptr[0] - lightleft) >> blockdivshift;
  327. // lightrightstep = (lightptr[1] - lightright) >> blockdivshift;
  328. // lightdeltastep = ((lightleftstep - lightrightstep) & 0xFFFFF) |
  329. // 0xF0000000;
  330. movl 4(%ebx),%ecx // lightptr[1]
  331. movl (%ebx),%ebx // lightptr[0]
  332. subl %eax,%ebx
  333. subl %edx,%ecx
  334. sarl $2,%ecx
  335. orl $0x30000000,%ebp
  336. sarl $2,%ebx
  337. movl %ecx,C(lightrightstep)
  338. subl %ecx,%ebx
  339. andl $0xFFFFF,%ebx
  340. orl $0xF0000000,%ebx
  341. subl %ecx,%ecx // high word must be 0 in loop for addressing
  342. movl %ebx,C(lightdeltastep)
  343. subl %ebx,%ebx // high word must be 0 in loop for addressing
  344. Lblockloop8_mip2:
  345. movl %ebp,C(lightdelta)
  346. movb 2(%esi),%cl
  347. sarl $2,%ebp
  348. movb %dh,%bh
  349. movb 3(%esi),%bl
  350. addl %ebp,%edx
  351. movb %dh,%ch
  352. addl %ebp,%edx
  353. movb 0x12345678(%ebx),%ah
  354. LBPatch18:
  355. movb 1(%esi),%bl
  356. movb 0x12345678(%ecx),%al
  357. LBPatch19:
  358. movb (%esi),%cl
  359. movb %dh,%bh
  360. addl %ebp,%edx
  361. rorl $16,%eax
  362. movb %dh,%ch
  363. movb 0x12345678(%ebx),%ah
  364. LBPatch20:
  365. movl C(lightright),%edx
  366. movb 0x12345678(%ecx),%al
  367. LBPatch21:
  368. movl C(lightdelta),%ebp
  369. movl %eax,(%edi)
  370. movl C(sourcetstep),%eax
  371. addl %eax,%esi
  372. movl C(surfrowbytes),%eax
  373. addl %eax,%edi
  374. movl C(lightrightstep),%eax
  375. addl %eax,%edx
  376. movl C(lightdeltastep),%eax
  377. addl %eax,%ebp
  378. movl %edx,C(lightright)
  379. jc Lblockloop8_mip2
  380. // if (pbasesource >= r_sourcemax)
  381. // pbasesource -= stepback;
  382. cmpl C(r_sourcemax),%esi
  383. jb LSkip_mip2
  384. subl C(r_stepback),%esi
  385. LSkip_mip2:
  386. movl C(r_lightptr),%ebx
  387. decl sb_v
  388. jnz Lv_loop_mip2
  389. popl %ebx // restore register variables
  390. popl %esi
  391. popl %edi
  392. popl %ebp // restore the caller's stack frame
  393. ret
  394. //----------------------------------------------------------------------
  395. // Surface block drawer for mip level 3
  396. //----------------------------------------------------------------------
  397. .align 4
  398. .globl C(R_DrawSurfaceBlock8_mip3)
  399. C(R_DrawSurfaceBlock8_mip3):
  400. pushl %ebp // preserve caller's stack frame
  401. pushl %edi
  402. pushl %esi // preserve register variables
  403. pushl %ebx
  404. // for (v=0 ; v<numvblocks ; v++)
  405. // {
  406. movl C(r_lightptr),%ebx
  407. movl C(r_numvblocks),%eax
  408. movl %eax,sb_v
  409. movl C(prowdestbase),%edi
  410. movl C(pbasesource),%esi
  411. Lv_loop_mip3:
  412. // lightleft = lightptr[0];
  413. // lightright = lightptr[1];
  414. // lightdelta = (lightleft - lightright) & 0xFFFFF;
  415. movl (%ebx),%eax // lightleft
  416. movl 4(%ebx),%edx // lightright
  417. movl %eax,%ebp
  418. movl C(r_lightwidth),%ecx
  419. movl %edx,C(lightright)
  420. subl %edx,%ebp
  421. andl $0xFFFFF,%ebp
  422. leal (%ebx,%ecx,4),%ebx
  423. movl %ebp,C(lightdelta)
  424. // lightptr += lightwidth;
  425. movl %ebx,C(r_lightptr)
  426. // lightleftstep = (lightptr[0] - lightleft) >> blockdivshift;
  427. // lightrightstep = (lightptr[1] - lightright) >> blockdivshift;
  428. // lightdeltastep = ((lightleftstep - lightrightstep) & 0xFFFFF) |
  429. // 0xF0000000;
  430. movl 4(%ebx),%ecx // lightptr[1]
  431. movl (%ebx),%ebx // lightptr[0]
  432. subl %eax,%ebx
  433. subl %edx,%ecx
  434. sarl $1,%ecx
  435. sarl $1,%ebx
  436. movl %ecx,C(lightrightstep)
  437. subl %ecx,%ebx
  438. andl $0xFFFFF,%ebx
  439. sarl $1,%ebp
  440. orl $0xF0000000,%ebx
  441. movl %ebx,C(lightdeltastep)
  442. subl %ebx,%ebx // high word must be 0 in loop for addressing
  443. movb 1(%esi),%bl
  444. subl %ecx,%ecx // high word must be 0 in loop for addressing
  445. movb %dh,%bh
  446. movb (%esi),%cl
  447. addl %ebp,%edx
  448. movb %dh,%ch
  449. movb 0x12345678(%ebx),%al
  450. LBPatch16:
  451. movl C(lightright),%edx
  452. movb %al,1(%edi)
  453. movb 0x12345678(%ecx),%al
  454. LBPatch17:
  455. movb %al,(%edi)
  456. movl C(sourcetstep),%eax
  457. addl %eax,%esi
  458. movl C(surfrowbytes),%eax
  459. addl %eax,%edi
  460. movl C(lightdeltastep),%eax
  461. movl C(lightdelta),%ebp
  462. movb (%esi),%cl
  463. addl %eax,%ebp
  464. movl C(lightrightstep),%eax
  465. sarl $1,%ebp
  466. addl %eax,%edx
  467. movb %dh,%bh
  468. movb 1(%esi),%bl
  469. addl %ebp,%edx
  470. movb %dh,%ch
  471. movb 0x12345678(%ebx),%al
  472. LBPatch30:
  473. movl C(sourcetstep),%edx
  474. movb %al,1(%edi)
  475. movb 0x12345678(%ecx),%al
  476. LBPatch31:
  477. movb %al,(%edi)
  478. movl C(surfrowbytes),%ebp
  479. addl %edx,%esi
  480. addl %ebp,%edi
  481. // if (pbasesource >= r_sourcemax)
  482. // pbasesource -= stepback;
  483. cmpl C(r_sourcemax),%esi
  484. jb LSkip_mip3
  485. subl C(r_stepback),%esi
  486. LSkip_mip3:
  487. movl C(r_lightptr),%ebx
  488. decl sb_v
  489. jnz Lv_loop_mip3
  490. popl %ebx // restore register variables
  491. popl %esi
  492. popl %edi
  493. popl %ebp // restore the caller's stack frame
  494. ret
  495. .globl C(R_Surf8End)
  496. C(R_Surf8End):
  497. //----------------------------------------------------------------------
  498. // Code patching routines
  499. //----------------------------------------------------------------------
  500. .data
  501. .align 4
  502. LPatchTable8:
  503. .long LBPatch0-4
  504. .long LBPatch1-4
  505. .long LBPatch2-4
  506. .long LBPatch3-4
  507. .long LBPatch4-4
  508. .long LBPatch5-4
  509. .long LBPatch6-4
  510. .long LBPatch7-4
  511. .long LBPatch8-4
  512. .long LBPatch9-4
  513. .long LBPatch10-4
  514. .long LBPatch11-4
  515. .long LBPatch12-4
  516. .long LBPatch13-4
  517. .long LBPatch14-4
  518. .long LBPatch15-4
  519. .long LBPatch16-4
  520. .long LBPatch17-4
  521. .long LBPatch18-4
  522. .long LBPatch19-4
  523. .long LBPatch20-4
  524. .long LBPatch21-4
  525. .long LBPatch22-4
  526. .long LBPatch23-4
  527. .long LBPatch24-4
  528. .long LBPatch25-4
  529. .long LBPatch26-4
  530. .long LBPatch27-4
  531. .long LBPatch28-4
  532. .long LBPatch29-4
  533. .long LBPatch30-4
  534. .long LBPatch31-4
  535. .text
  536. .align 4
  537. .globl C(R_Surf8Patch)
  538. C(R_Surf8Patch):
  539. pushl %ebx
  540. movl C(colormap),%eax
  541. movl $LPatchTable8,%ebx
  542. movl $32,%ecx
  543. LPatchLoop8:
  544. movl (%ebx),%edx
  545. addl $4,%ebx
  546. movl %eax,(%edx)
  547. decl %ecx
  548. jnz LPatchLoop8
  549. popl %ebx
  550. ret
  551. #endif // id386