draw_arm.S 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870
  1. /*
  2. * assembly optimized versions of most funtions from draw.c
  3. * (C) notaz, 2006-2010,2017
  4. *
  5. * This work is licensed under the terms of MAME license.
  6. * See COPYING file in the top-level directory.
  7. *
  8. * this is highly specialized, be careful if changing related C code!
  9. */
  10. #include "pico_int_o32.h"
  11. .extern DrawStripInterlace
  12. .equ PDRAW_SPRITES_MOVED, (1<<0)
  13. .equ PDRAW_WND_DIFF_PRIO, (1<<1)
  14. .equ PDRAW_ACC_SPRITES, (1<<2)
  15. .equ PDRAW_DIRTY_SPRITES, (1<<4)
  16. .equ PDRAW_PLANE_HI_PRIO, (1<<6)
  17. .equ PDRAW_SHHI_DONE, (1<<7)
  18. @ helpers
  19. .macro add_c24 d s c
  20. add \d, \s, #(\c & 0x00ff00)
  21. .if \c & 0x0000ff
  22. add \d, \d, #(\c & 0x0000ff)
  23. .endif
  24. .if \c & 0xff0000
  25. add \d, \d, #(\c & 0xff0000)
  26. .endif
  27. .endm
  28. .macro TilePixel pat lsrr offs
  29. .if !\lsrr
  30. ands r4, \pat, r2
  31. .else
  32. ands r4, \pat, r2, lsr #\lsrr
  33. .endif
  34. orrne r4, r3, r4
  35. strneb r4, [r1,#\offs]
  36. .endm
  37. @ TileNorm (r1=pdest, r2=pixels8, r3=pal) r4: scratch, pat: register with helper pattern 0xf
  38. .macro TileNorm pat
  39. TilePixel \pat, 12, 0 @ #0x0000f000
  40. TilePixel \pat, 8, 1 @ #0x00000f00
  41. TilePixel \pat, 4, 2 @ #0x000000f0
  42. TilePixel \pat, 0, 3 @ #0x0000000f
  43. TilePixel \pat, 28, 4 @ #0xf0000000
  44. TilePixel \pat, 24, 5 @ #0x0f000000
  45. TilePixel \pat, 20, 6 @ #0x00f00000
  46. TilePixel \pat, 16, 7 @ #0x000f0000
  47. .endm
  48. @ TileFlip (r1=pdest, r2=pixels8, r3=pal) r4: scratch, pat: register with helper pattern 0xf
  49. .macro TileFlip pat
  50. TilePixel \pat, 16, 0 @ #0x000f0000
  51. TilePixel \pat, 20, 1 @ #0x00f00000
  52. TilePixel \pat, 24, 2 @ #0x0f000000
  53. TilePixel \pat, 28, 3 @ #0xf0000000
  54. TilePixel \pat, 0, 4 @ #0x0000000f
  55. TilePixel \pat, 4, 5 @ #0x000000f0
  56. TilePixel \pat, 8, 6 @ #0x00000f00
  57. TilePixel \pat, 12, 7 @ #0x0000f000
  58. .endm
  59. @ shadow/hilight mode
  60. @ this one is for hi priority layer
  61. .macro TilePixelShHP lsrr offs
  62. .if !\lsrr
  63. ands r4, r12, r2
  64. .else
  65. ands r4, r12, r2, lsr #\lsrr
  66. .endif
  67. ldreqb r4, [r1,#\offs]
  68. orrne r4, r3, r4
  69. andeq r4, r4, #0xbf
  70. strb r4, [r1,#\offs]
  71. .endm
  72. @ TileNormShHP (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r12: register with helper pattern 0xf, touches r3 high bits
  73. .macro TileNormShHP
  74. TilePixelShHP 12, 0 @ #0x0000f000
  75. TilePixelShHP 8, 1 @ #0x00000f00
  76. TilePixelShHP 4, 2 @ #0x000000f0
  77. TilePixelShHP 0, 3 @ #0x0000000f
  78. TilePixelShHP 28, 4 @ #0xf0000000
  79. TilePixelShHP 24, 5 @ #0x0f000000
  80. TilePixelShHP 20, 6 @ #0x00f00000
  81. TilePixelShHP 16, 7 @ #0x000f0000
  82. .endm
  83. @ TileFlipShHP (r1=pdest, r2=pixels8, r3=pal) r4: scratch, pat: register with helper pattern 0xf
  84. .macro TileFlipShHP
  85. TilePixelShHP 16, 0 @ #0x000f0000
  86. TilePixelShHP 20, 1 @ #0x00f00000
  87. TilePixelShHP 24, 2 @ #0x0f000000
  88. TilePixelShHP 28, 3 @ #0xf0000000
  89. TilePixelShHP 0, 4 @ #0x0000000f
  90. TilePixelShHP 4, 5 @ #0x000000f0
  91. TilePixelShHP 8, 6 @ #0x00000f00
  92. TilePixelShHP 12, 7 @ #0x0000f000
  93. .endm
  94. @ TileSingleSh (r1=pdest, r2=pixels8, r3=pal) r4,r7: scratch, r0=sx; r12: helper pattern 0xf
  95. .macro TileSingleSh
  96. tst r0, #1 @ not aligned?
  97. mov r7, #0x00c000
  98. orr r7, r7, #0xc0
  99. ldrneb r4, [r1]
  100. ldreqh r4, [r1]
  101. orr r4, r4, r7
  102. strneb r4, [r1], #1
  103. streqh r4, [r1], #2
  104. ldrh r4, [r1]
  105. orr r4, r4, r7
  106. strh r4, [r1], #2
  107. ldrh r4, [r1]
  108. orr r4, r4, r7
  109. strh r4, [r1], #2
  110. ldrh r4, [r1]
  111. orr r4, r4, r7
  112. strh r4, [r1], #2
  113. ldrneb r4, [r1]
  114. orr r4, r4, r7
  115. strneb r4, [r1], #1
  116. .endm
  117. @ TileSingleHi (r1=pdest, r2=pixels8, r3=pal) r4,r7: scratch, r0=sx, r12: register with helper pattern 0xf
  118. .macro TileSingleHi
  119. tst r1, #1 @ not aligned?
  120. mov r7, #0x008000
  121. orr r7, r7, #0x80
  122. ldrneb r4, [r1], #1
  123. ldreqh r4, [r1], #2 @ 1ci
  124. ldrh r12, [r1], #2
  125. bic r4, r4, r7, lsr #1
  126. orr r4, r4, r7
  127. strneb r4, [r1, #-3]
  128. streqh r4, [r1, #-4]
  129. ldrh r4, [r1], #2
  130. bic r12, r12, r7, lsr #1
  131. orr r12, r12, r7
  132. strh r12, [r1, #-4]
  133. ldrh r12, [r1], #2
  134. bic r4, r4, r7, lsr #1
  135. orr r4, r4, r7
  136. strh r4, [r1, #-4]
  137. ldrneb r4, [r1]
  138. bic r12, r12, r7, lsr #1
  139. orr r12, r12, r7
  140. strh r12, [r1, #-2]
  141. bicne r4, r4, r7, lsr #1
  142. orrne r4, r4, r7
  143. strneb r4, [r1], #1
  144. mov r12, #0xf
  145. .endm
  146. .macro TileDoShGenPixel shift ofs
  147. .if \shift
  148. ands r4, r12, r2, lsr #\shift
  149. .else
  150. ands r4, r12, r2
  151. .endif
  152. beq 0f
  153. cmp r4, #0xe
  154. ldrgeb r7, [r1,#\ofs]
  155. orrlt r7, r3, r4 @ normal
  156. bicge r7, r7, #0xc0
  157. orrge r7, r7, r4, lsl #6
  158. strb r7, [r1,#\ofs]
  159. 0:
  160. .endm
  161. @ TileFlipSh (r1=pdest, r2=pixels8, r3=pal) r4,r7: scratch, r0=sx, r12: register with helper pattern 0xf
  162. .macro TileFlipSh
  163. TileDoShGenPixel 16, 0 @ #0x000f0000
  164. TileDoShGenPixel 20, 1 @ #0x00f00000
  165. TileDoShGenPixel 24, 2 @ #0x0f000000
  166. TileDoShGenPixel 28, 3 @ #0xf0000000
  167. TileDoShGenPixel 0, 4 @ #0x0000000f
  168. TileDoShGenPixel 4, 5 @ #0x000000f0
  169. TileDoShGenPixel 8, 6 @ #0x00000f00
  170. TileDoShGenPixel 12, 7 @ #0x0000f000
  171. .endm
  172. @ TileNormSh (r1=pdest, r2=pixels8, r3=pal) r4,r7: scratch, r0=sx, r12: register with helper pattern 0xf
  173. .macro TileNormSh
  174. TileDoShGenPixel 12, 0 @ #0x0000f000
  175. TileDoShGenPixel 8, 1 @ #0x00000f00
  176. TileDoShGenPixel 4, 2 @ #0x000000f0
  177. TileDoShGenPixel 0, 3 @ #0x0000000f
  178. TileDoShGenPixel 28, 4 @ #0xf0000000
  179. TileDoShGenPixel 24, 5 @ #0x0f000000
  180. TileDoShGenPixel 20, 6 @ #0x00f00000
  181. TileDoShGenPixel 16, 7 @ #0x000f0000
  182. .endm
  183. .macro TileDoShGenPixel_markop shift ofs
  184. .if \shift
  185. ands r4, r12, r2, lsr #\shift
  186. .else
  187. ands r4, r12, r2
  188. .endif
  189. beq 0f
  190. cmp r4, #0xe
  191. ldrgeb r4, [r1,#\ofs]
  192. orrlt r4, r3, r4
  193. orrge r4, r4, #0x80
  194. strb r4, [r1,#\ofs]
  195. 0:
  196. .endm
  197. .macro TileFlipSh_markop
  198. TileDoShGenPixel_markop 16, 0 @ #0x000f0000
  199. TileDoShGenPixel_markop 20, 1 @ #0x00f00000
  200. TileDoShGenPixel_markop 24, 2 @ #0x0f000000
  201. TileDoShGenPixel_markop 28, 3 @ #0xf0000000
  202. TileDoShGenPixel_markop 0, 4 @ #0x0000000f
  203. TileDoShGenPixel_markop 4, 5 @ #0x000000f0
  204. TileDoShGenPixel_markop 8, 6 @ #0x00000f00
  205. TileDoShGenPixel_markop 12, 7 @ #0x0000f000
  206. .endm
  207. .macro TileNormSh_markop
  208. TileDoShGenPixel_markop 12, 0 @ #0x0000f000
  209. TileDoShGenPixel_markop 8, 1 @ #0x00000f00
  210. TileDoShGenPixel_markop 4, 2 @ #0x000000f0
  211. TileDoShGenPixel_markop 0, 3 @ #0x0000000f
  212. TileDoShGenPixel_markop 28, 4 @ #0xf0000000
  213. TileDoShGenPixel_markop 24, 5 @ #0x0f000000
  214. TileDoShGenPixel_markop 20, 6 @ #0x00f00000
  215. TileDoShGenPixel_markop 16, 7 @ #0x000f0000
  216. .endm
  217. .macro TileDoShGenPixel_onlyop_lp shift ofs
  218. .if \shift
  219. ands r7, r12, r2, lsr #\shift
  220. .else
  221. ands r7, r12, r2
  222. .endif
  223. ldrneb r4, [r1,#\ofs]
  224. cmp r7, #0xe
  225. blt 0f
  226. tst r4, #0xc0
  227. bicne r4, r4, #0xc0
  228. orrne r4, r4, r7, lsl #6
  229. strneb r4, [r1,#\ofs]
  230. 0:
  231. .endm
  232. .macro TileFlipSh_onlyop_lp
  233. TileDoShGenPixel_onlyop_lp 16, 0 @ #0x000f0000
  234. TileDoShGenPixel_onlyop_lp 20, 1 @ #0x00f00000
  235. TileDoShGenPixel_onlyop_lp 24, 2 @ #0x0f000000
  236. TileDoShGenPixel_onlyop_lp 28, 3 @ #0xf0000000
  237. TileDoShGenPixel_onlyop_lp 0, 4 @ #0x0000000f
  238. TileDoShGenPixel_onlyop_lp 4, 5 @ #0x000000f0
  239. TileDoShGenPixel_onlyop_lp 8, 6 @ #0x00000f00
  240. TileDoShGenPixel_onlyop_lp 12, 7 @ #0x0000f000
  241. .endm
  242. .macro TileNormSh_onlyop_lp
  243. TileDoShGenPixel_onlyop_lp 12, 0 @ #0x0000f000
  244. TileDoShGenPixel_onlyop_lp 8, 1 @ #0x00000f00
  245. TileDoShGenPixel_onlyop_lp 4, 2 @ #0x000000f0
  246. TileDoShGenPixel_onlyop_lp 0, 3 @ #0x0000000f
  247. TileDoShGenPixel_onlyop_lp 28, 4 @ #0xf0000000
  248. TileDoShGenPixel_onlyop_lp 24, 5 @ #0x0f000000
  249. TileDoShGenPixel_onlyop_lp 20, 6 @ #0x00f00000
  250. TileDoShGenPixel_onlyop_lp 16, 7 @ #0x000f0000
  251. .endm
  252. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  253. @ struct TileStrip
  254. @ {
  255. @ int nametab; // 0x00
  256. @ int line; // 0x04
  257. @ int hscroll; // 0x08
  258. @ int xmask; // 0x0C
  259. @ int *hc; // 0x10 (pointer to cache buffer)
  260. @ int cells; // 0x14
  261. @ };
  262. @ void DrawLayer(int lflags, int *hcache, int cellskip, int maxcells,
  263. @ struct PicoEState *est)
  264. .global DrawLayer
  265. DrawLayer:
  266. ldr r12, [sp] @ est
  267. stmfd sp!, {r4-r11,lr}
  268. ldr r11, [r12, #OFS_EST_Pico]
  269. mov r8, #1
  270. ldrb r7, [r11, #OFS_Pico_video_reg+16] @ ??vv??hh
  271. mov r6, r1 @ hcache
  272. orr r9, r3, r0, lsl #29 @ r9=force[31]|sh[30]|plane[29]
  273. orr r9, r9, r2, lsl #8 @ |cellskip[15:8]|maxcells[7:0] (tmp)
  274. mov r1, r7, lsl #4
  275. orr r1, r1, #0x00ff
  276. and r10, r7, #3
  277. cmp r10, #1
  278. biclt r1, r1, #0xfc00
  279. biceq r1, r1, #0xfe00
  280. cmp r10, #2
  281. moveq r1, #0x0007
  282. movgt r1, #0x00ff @ r1=ymask=(height<<8)|0xff; ...; // Y Mask in pixels
  283. add r10, r10, #5
  284. cmp r10, #7
  285. subge r10, r10, #1 @ r10=shift[width] (5,6,6,7)
  286. ldr r2, [r12, #OFS_EST_DrawScanline]
  287. ldr lr, [r12, #OFS_EST_PicoMem_vram]
  288. @ Find name table:
  289. ands r0, r0, #1
  290. ldreqb r12, [r11, #OFS_Pico_video_reg+2]
  291. ldrneb r12, [r11, #OFS_Pico_video_reg+4]
  292. @ calculate xmask:
  293. mov r5, r8, lsl r10
  294. sub r5, r5, #1 @ r5=xmask
  295. moveq r12, r12, lsl #10
  296. movne r12, r12, lsl #13
  297. and r12, r12, #(7<<13) @ r12=(ts->nametab<<1) (halfword compliant)
  298. ldrh r8, [r11, #OFS_Pico_video_reg+12]
  299. ldrb r7, [r11, #OFS_Pico_video_reg+11]
  300. mov r4, r8, lsr #8 @ pvid->reg[13]
  301. mov r4, r4, lsl #10 @ htab=pvid->reg[13]<<9; (halfwords)
  302. tst r7, #2
  303. addne r4, r4, r2, lsl #2 @ htab+=DrawScanline<<1; // Offset by line
  304. tst r7, #1
  305. biceq r4, r4, #0x1f @ htab&=~0xf; // Offset by tile
  306. add r4, r4, r0, lsl #1 @ htab+=plane
  307. bic r4, r4, #0x00ff0000 @ just in case
  308. ldrh r3, [lr, r4] @ r3=hscroll
  309. tst r7, #4
  310. bne .DrawStrip_vsscroll
  311. @ Get vertical scroll value:
  312. add_c24 r7, lr, (OFS_PMEM_vsram-OFS_PMEM_vram)
  313. ldr r7, [r7]
  314. tst r8, #2
  315. tstne r8, #4
  316. bne .DrawStrip_interlace
  317. tst r0, r0
  318. movne r7, r7, lsr #16
  319. @ Find the line in the name table
  320. add r2, r2, r7
  321. and r2, r2, r1
  322. mov r4, r2, lsr #3
  323. add r10, r10, #1 @ shift[width]++
  324. add r12, r12, r4, lsl r10 @ nametab+=(ts.line>>3)<<shift[width];
  325. @ ldmia r0, {r1,r2,r3,r5,r6,r9} @ r2=line, r3=ts->hscroll, r5=ts->xmask, r6=ts->hc, r9=ts->cells
  326. and r10,r2, #7
  327. mov r10,r10, lsl #1 @ r10=ty=(ts->line&7)<<1;
  328. orr r10,r10, r9, lsl #24
  329. rsb r8, r3, #0
  330. mov r8, r8, lsr #3 @ r8=tilex=(-ts->hscroll)>>3
  331. sub r1, r3, #1
  332. and r1, r1, #7
  333. add r7, r1, #1 @ r7=dx=((ts->hscroll-1)&7)+1
  334. movs r3, r9, lsl #1 @ (force[31]|sh[30]) << 1
  335. mov r3, #0
  336. orrmi r10,r10, #1<<23 @ r10=cells[31:24]|sh[23]|hi_not_empty[22]
  337. orrcs r10,r10, #1<<20 @ |had_output[21]|force[20]|ty[15:0]
  338. movmi r3, #0x40 @ default to shadowed pal on sh mode
  339. cmp r7, #8
  340. addne r10,r10, #0x01000000 @ we will loop cells+1 times if there is scroll
  341. and r9, r9, #0xff00
  342. add r8, r8, r9, lsr #8 @ tilex+=cellskip
  343. add r7, r7, r9, lsr #5 @ dx+=cellskip<<3;
  344. sub r10,r10,r9, lsl #16 @ cells-=cellskip
  345. @ cache some stuff to avoid mem access
  346. ldr r11,[sp, #9*4] @ est
  347. mov r0, #0xf
  348. ldr r11,[r11, #OFS_EST_HighCol]
  349. mvn r9, #0 @ r9=prevcode=-1
  350. add r1, r11, r7 @ r1=pdest
  351. @ r4 & r7 are scratch in this loop
  352. .dsloop_subr1:
  353. sub r1, r1, #8
  354. .dsloop: @ 40-41 times
  355. subs r10,r10, #0x01000000
  356. bmi .dsloop_exit
  357. .dsloop_enter:
  358. and r7, r5, r8
  359. add r7, lr, r7, lsl #1 @ Pico.vram+((tilex&ts->xmask) as halfwords)
  360. ldrh r7, [r7, r12] @ r7=code (int, but from unsigned, no sign extend)
  361. add r1, r1, #8
  362. add r8, r8, #1
  363. tst r7, #0x8000
  364. tsteq r10, #1<<20 @ force?
  365. bne .DrawStrip_hiprio
  366. cmp r7, r9
  367. beq .DrawStrip_samecode @ we know stuff about this tile already
  368. mov r9, r7 @ remember code
  369. orr r10, r10, #1<<21 @ seen non hi-prio tile
  370. movs r2, r9, lsl #20 @ if (code&0x1000)
  371. mov r2, r2, lsl #1
  372. add r2, r2, r10, lsl #17
  373. mov r2, r2, lsr #17
  374. eorcs r2, r2, #0x0e @ if (code&0x1000) addr^=0xe;
  375. ldr r2, [lr, r2, lsl #1] @ pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
  376. bic r7, r3, #0x3f
  377. and r3, r9, #0x6000
  378. add r3, r7, r3, lsr #9 @ r3=pal=((code&0x6000)>>9);
  379. .DrawStrip_samecode:
  380. tst r2, r2
  381. beq .dsloop @ tileline blank
  382. cmp r2, r2, ror #4
  383. beq .DrawStrip_SingleColor @ tileline singlecolor
  384. tst r9, #0x0800
  385. bne .DrawStrip_TileFlip
  386. @ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r0: helper pattern
  387. .DrawStrip_TileNorm:
  388. TileNorm r0
  389. b .dsloop
  390. .DrawStrip_TileFlip:
  391. TileFlip r0
  392. b .dsloop
  393. .DrawStrip_SingleColor:
  394. and r4, r2, #0xf
  395. orr r4, r3, r4
  396. orr r4, r4, r4, lsl #8
  397. tst r1, #1 @ not aligned?
  398. strneb r4, [r1], #1
  399. streqh r4, [r1], #2
  400. strh r4, [r1], #2
  401. strh r4, [r1], #2
  402. strh r4, [r1], #2
  403. strneb r4, [r1], #1 @ have a remaining unaligned pixel?
  404. b .dsloop_subr1
  405. .DrawStrip_hiprio_maybempt:
  406. cmp r7, r9
  407. beq .dsloop @ must've been empty, otherwise we wouldn't get here
  408. movs r2, r7, lsl #20 @ if (code&0x1000)
  409. mov r2, r2, lsl #1
  410. add r2, r2, r10, lsl #17
  411. mov r2, r2, lsr #17
  412. eorcs r2, r2, #0x0e @ if (code&0x1000) addr^=0xe;
  413. ldr r2, [lr, r2, lsl #1] @ pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
  414. mov r9, r7 @ remember code
  415. tst r2, r2
  416. beq .dsloop
  417. orr r10, r10, #1<<22
  418. .DrawStrip_hiprio:
  419. tst r10, #0x00d00000 @ sh[23]|hi_not_empty[22]|force[20]
  420. beq .DrawStrip_hiprio_maybempt
  421. sub r0, r1, r11
  422. orr r7, r7, r0, lsl #16
  423. orr r7, r7, r10, lsl #25 @ (ty<<25)
  424. tst r7, #0x1000
  425. eorne r7, r7, #7<<26 @ if(code&0x1000) cval^=7<<26;
  426. str r7, [r6], #4 @ cache hi priority tile
  427. mov r0, #0xf
  428. b .dsloop
  429. .dsloop_exit:
  430. tst r10, #1<<21 @ seen non hi-prio tile
  431. ldr r1, [sp, #9*4] @ est
  432. mov r0, #0
  433. ldreq r2, [r1, #OFS_EST_rendstatus]
  434. str r0, [r6] @ terminate the cache list
  435. orreq r2, r2, #PDRAW_PLANE_HI_PRIO @ had a layer with all hi-prio tiles
  436. streq r2, [r1, #OFS_EST_rendstatus]
  437. ldmfd sp!, {r4-r11,lr}
  438. bx lr
  439. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  440. .DrawStrip_vsscroll:
  441. rsb r8, r3, #0
  442. mov r8, r8, lsr #3 @ r8=tilex=(-ts->hscroll)>>3
  443. bic r8, r8, #0x3fc00000
  444. orr r8, r8, r5, lsl #25 @ r8=(xmask[31:25]|had_output[24]|tilex[21:0])
  445. ldr r11, [sp, #9*4] @ est
  446. orr r5, r1, r10, lsl #24
  447. ldr r4, [r11, #OFS_EST_DrawScanline]
  448. sub r1, r3, #1
  449. orr r5, r5, r4, lsl #16 @ r5=(shift_width[31:24]|scanline[23:16]|ymask[15:0])
  450. and r1, r1, #7
  451. add r7, r1, #1 @ r7=dx=((ts->hscroll-1)&7)+1
  452. mov r10,r9, lsl #16
  453. orr r10,r10, #0xff000000 @ will be adjusted on entering loop
  454. tst r0, #1
  455. orrne r10,r10, #0x8000
  456. tst r3, #0x0f @ hscroll & 0x0f?
  457. beq 0f
  458. eor r3, r3, r7
  459. sub r10,r10, #1<<24 @ cell-- // start from negative for hscroll
  460. tst r3, #0x08
  461. subne r10,r10, #1<<16 @ cells--
  462. subne r10,r10, #1<<24 @ cell-- // even more negative
  463. 0:
  464. tst r9, #1<<31
  465. mov r3, #0
  466. orrne r10,r10, #1<<23 @ r10=(cell[31:24]|sh[23]|hi_not_empty[22]|cells_max[21:16]|plane[15]|ty[14:0])
  467. movne r3, #0x40 @ default to shadowed pal on sh mode
  468. and r9, r9, #0xff00
  469. add r8, r8, r9, lsr #8 @ tilex+=cellskip
  470. add r7, r7, r9, lsr #5 @ dx+=cellskip<<3;
  471. add r10,r10,r9, lsl #16 @ cell+=cellskip
  472. @ cache some stuff to avoid mem access
  473. ldr r11,[sp, #9*4] @ est
  474. mov r0, #0xf
  475. ldr r11,[r11, #OFS_EST_HighCol]
  476. mvn r9, #0 @ r9=prevcode=-1
  477. add r1, r11, r7 @ r1=pdest
  478. @ r4 & r7 are scratch in this loop
  479. .dsloop_vs_subr1:
  480. sub r1, r1, #8
  481. .dsloop_vs: @ 40-41 times
  482. add r10,r10, #0x01000000
  483. and r4, r10, #0x003f0000
  484. cmp r4, r10, asr #8
  485. ble .dsloop_vs_exit
  486. @ calc offset and read tileline code to r7, also calc ty
  487. add_c24 r7, lr, (OFS_PMEM_vsram-OFS_PMEM_vram)
  488. add r7, r7, r10,asr #23 @ vsram + ((cell&~1)<<1)
  489. bic r7, r7, #3
  490. tst r10,#0x8000 @ plane1?
  491. addne r7, r7, #2
  492. ldrh r7, [r7] @ r7=vscroll
  493. bic r10,r10,#0xff @ clear old ty
  494. and r4, r5, #0xff0000 @ scanline
  495. add r4, r4, r7, lsl #16 @ ... += vscroll
  496. and r4, r4, r5, lsl #16 @ ... &= ymask
  497. and r7, r4, #0x70000
  498. orr r10,r10,r7, lsr #15 @ new ty
  499. mov r4, r4, lsr #19
  500. mov r7, r5, lsr #24
  501. mov r4, r4, lsl r7 @ nametabadd
  502. and r7, r8, r8, lsr #25
  503. add r7, lr, r7, lsl #1 @ PicoMem.vram+((tilex&ts->xmask) as halfwords)
  504. add r7, r7, r4, lsl #1
  505. ldrh r7, [r7, r12] @ r7=code (int, but from unsigned, no sign extend)
  506. add r1, r1, #8
  507. add r8, r8, #1
  508. tst r7, #0x8000
  509. bne .DrawStrip_vs_hiprio
  510. cmp r7, r9
  511. beq .DrawStrip_vs_samecode @ we know stuff about this tile already
  512. mov r9, r7 @ remember code
  513. orr r8, r8, #(1<<24)@ seen non hi-prio tile
  514. movs r2, r9, lsl #20 @ if (code&0x1000)
  515. mov r2, r2, lsl #1
  516. add r2, r2, r10, lsl #17
  517. mov r2, r2, lsr #17
  518. eorcs r2, r2, #0x0e @ if (code&0x1000) addr^=0xe;
  519. ldr r2, [lr, r2, lsl #1] @ pack=*(unsigned int *)(PicoMem.vram+addr); // Get 8 pixels
  520. bic r7, r3, #0x3f
  521. and r3, r9, #0x6000
  522. add r3, r7, r3, lsr #9 @ r3=pal=((code&0x6000)>>9);
  523. .DrawStrip_vs_samecode:
  524. tst r2, r2
  525. beq .dsloop_vs @ tileline blank
  526. cmp r2, r2, ror #4
  527. beq .DrawStrip_vs_SingleColor @ tileline singlecolor
  528. tst r9, #0x0800
  529. bne .DrawStrip_vs_TileFlip
  530. @ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r0: helper pattern
  531. .DrawStrip_vs_TileNorm:
  532. TileNorm r0
  533. b .dsloop_vs
  534. .DrawStrip_vs_TileFlip:
  535. TileFlip r0
  536. b .dsloop_vs
  537. .DrawStrip_vs_SingleColor:
  538. and r4, r2, #0xf
  539. orr r4, r3, r4
  540. orr r4, r4, r4, lsl #8
  541. tst r1, #1 @ not aligned?
  542. strneb r4, [r1], #1
  543. streqh r4, [r1], #2
  544. strh r4, [r1], #2
  545. strh r4, [r1], #2
  546. strh r4, [r1], #2
  547. strneb r4, [r1], #1 @ have a remaining unaligned pixel?
  548. b .dsloop_vs_subr1
  549. .DrawStrip_vs_hiprio:
  550. tst r10, #0x00c00000
  551. beq .DrawStrip_vs_hiprio_maybempt
  552. sub r0, r1, r11
  553. orr r7, r7, r0, lsl #16
  554. orr r7, r7, r10, lsl #25 @ (ty<<25)
  555. tst r7, #0x1000
  556. eorne r7, r7, #7<<26 @ if(code&0x1000) cval^=7<<26;
  557. str r7, [r6], #4 @ cache hi priority tile
  558. mov r0, #0xf
  559. b .dsloop_vs
  560. .DrawStrip_vs_hiprio_maybempt:
  561. cmp r7, r9
  562. beq .dsloop_vs @ must've been empty, otherwise we wouldn't get here
  563. movs r2, r7, lsl #20 @ if (code&0x1000)
  564. mov r2, r2, lsl #1
  565. add r2, r2, r10, lsl #17
  566. mov r2, r2, lsr #17
  567. eorcs r2, r2, #0x0e @ if (code&0x1000) addr^=0xe;
  568. ldr r2, [lr, r2, lsl #1] @ pack=*(unsigned int *)(PicoMem.vram+addr); // Get 8 pixels
  569. mov r9, r7 @ remember code
  570. tst r2, r2
  571. orrne r10, r10, #1<<22
  572. bne .DrawStrip_vs_hiprio
  573. b .dsloop_vs
  574. .dsloop_vs_exit:
  575. tst r8, #(1<<24) @ seen non hi-prio tile
  576. ldr r1, [sp, #9*4] @ est
  577. mov r0, #0
  578. ldreq r2, [r1, #OFS_EST_rendstatus]
  579. str r0, [r6] @ terminate the cache list
  580. orreq r2, r2, #PDRAW_PLANE_HI_PRIO @ had a layer with all hi-prio tiles
  581. streq r2, [r1, #OFS_EST_rendstatus]
  582. ldmfd sp!, {r4-r11,lr}
  583. bx lr
  584. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  585. @ interlace mode 2? Sonic 2?
  586. .DrawStrip_interlace:
  587. tst r0, r0
  588. moveq r7, r7, lsl #21
  589. movne r7, r7, lsl #5
  590. @ Find the line in the name table
  591. add r2, r7, r2, lsl #22 @ r2=(vscroll+(DrawScanline<<1))<<21 (11 bits);
  592. orr r1, r1, #0x80000000
  593. and r2, r2, r1, ror #10 @ &((ymask<<1)|1)<<21;
  594. mov r2, r2, lsr #21
  595. mov r4, r2, lsr #4
  596. mov r12, r12, lsr #1 @ halfwords
  597. add r0, r12, r4, lsl r10 @ nametab+=(ts.line>>4)<<shift[width];
  598. and r9, r9, #0xff
  599. sub sp, sp, #6*4
  600. stmia sp, {r0,r2,r3,r5,r6,r9}
  601. mov r0, sp
  602. bl DrawStripInterlace @ struct TileStrip *ts
  603. add sp, sp, #6*4
  604. ldmfd sp!, {r4-r11,lr}
  605. bx lr
  606. .pool
  607. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  608. @ void BackFill(int reg7, int sh, struct PicoEState *est)
  609. .global BackFill
  610. BackFill:
  611. stmfd sp!, {r4-r9,lr}
  612. mov r0, r0, lsl #26
  613. ldr lr, [r2, #OFS_EST_HighCol]
  614. mov r0, r0, lsr #26
  615. add lr, lr, #8
  616. orr r0, r0, r1, lsl #6
  617. orr r0, r0, r0, lsl #8
  618. orr r0, r0, r0, lsl #16
  619. mov r1, r0
  620. mov r2, r0
  621. mov r3, r0
  622. mov r4, r0
  623. mov r5, r0
  624. mov r6, r0
  625. mov r7, r0
  626. @ go go go!
  627. stmia lr!, {r0-r7} @ 10*8*4
  628. stmia lr!, {r0-r7}
  629. stmia lr!, {r0-r7}
  630. stmia lr!, {r0-r7}
  631. stmia lr!, {r0-r7}
  632. stmia lr!, {r0-r7}
  633. stmia lr!, {r0-r7}
  634. stmia lr!, {r0-r7}
  635. stmia lr!, {r0-r7}
  636. stmia lr!, {r0-r7}
  637. ldmfd sp!, {r4-r9,lr}
  638. bx lr
  639. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  640. @ void DrawTilesFromCache(int *hc, int sh, int rlim, struct PicoEState *est)
  641. .global DrawTilesFromCache
  642. DrawTilesFromCache:
  643. stmfd sp!, {r4-r9,r11,lr}
  644. @ cache some stuff to avoid mem access
  645. ldr r11,[r3, #OFS_EST_HighCol]
  646. mov r12,#0xf
  647. ldr lr, [r3, #OFS_EST_PicoMem_vram]
  648. mov r9, r3 @ est
  649. mvn r5, #0 @ r5=prevcode=-1
  650. ands r8, r1, #1
  651. orr r8, r8, r2, lsl #1
  652. bne .dtfc_check_rendflags
  653. @ scratch: r4, r7
  654. .dtfc_loop:
  655. ldr r6, [r0], #4 @ read code
  656. movs r1, r6, lsr #16 @ r1=dx;
  657. ldmeqfd sp!, {r4-r9,r11,pc} @ dx is never zero, this must be a terminator, return
  658. bic r4, r1, #0xfe00
  659. add r1, r11, r4 @ r1=pdest
  660. movs r7, r6, lsl #16
  661. bpl .dtfc_loop @ !(code & 0x8000)
  662. cmp r5, r7, lsr #16
  663. beq .dtfc_samecode @ if (code==prevcode)
  664. mov r5, r7, lsr #16
  665. mov r2, r5, lsl #21
  666. mov r2, r2, lsr #17 @ r2=addr=(code&0x7ff)<<4;
  667. add r2, r2, r6, lsr #25 @ addr+=ty
  668. and r3, r5, #0x6000
  669. mov r3, r3, lsr #9 @ r3=pal=((code&0x6000)>>9);
  670. ldr r2, [lr, r2, lsl #1] @ pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
  671. .dtfc_samecode:
  672. rsbs r4, r4, r8, lsr #1
  673. bmi .dtfc_cut_tile
  674. tst r8, #1
  675. bne .dtfc_shadow
  676. tst r2, r2
  677. beq .dtfc_loop
  678. cmp r2, r2, ror #4
  679. beq .dtfc_SingleColor @ tileline singlecolor
  680. tst r5, #0x0800
  681. bne .dtfc_TileFlip
  682. @ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r12: helper pattern
  683. .dtfc_TileNorm:
  684. TileNorm r12
  685. b .dtfc_loop
  686. .dtfc_TileFlip:
  687. TileFlip r12
  688. b .dtfc_loop
  689. .dtfc_SingleColor:
  690. and r4, r2, #0xf
  691. orr r4, r3, r4
  692. orr r4, r4, r4, lsl #8
  693. tst r1, #1 @ not aligned?
  694. strneb r4, [r1], #1
  695. streqh r4, [r1], #2
  696. strh r4, [r1], #2
  697. strh r4, [r1], #2
  698. strh r4, [r1], #2
  699. strneb r4, [r1], #1 @ have a remaining unaligned pixel?
  700. b .dtfc_loop
  701. .dtfc_shadow:
  702. tst r2, r2
  703. beq .dtfc_shadow_blank
  704. cmp r2, r2, ror #4
  705. beq .dtfc_SingleColor @ tileline singlecolor
  706. tst r5, #0x0800
  707. bne .dtfc_TileFlipShHP
  708. @ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r12: helper pattern
  709. .dtfc_TileNormShHP:
  710. TileNormShHP
  711. b .dtfc_loop
  712. .dtfc_TileFlipShHP:
  713. TileFlipShHP
  714. b .dtfc_loop
  715. .dtfc_shadow_blank:
  716. tst r1, #1
  717. ldrneb r4, [r1]
  718. mov r6, #0xbf
  719. and r4, r4, #0xbf
  720. strneb r4, [r1], #1
  721. ldrh r4, [r1]
  722. orr r6, r6, r6, lsl #8
  723. and r4, r4, r6
  724. strh r4, [r1], #2
  725. ldrh r4, [r1]
  726. and r4, r4, r6
  727. strh r4, [r1], #2
  728. ldrh r4, [r1]
  729. and r4, r4, r6
  730. strh r4, [r1], #2
  731. ldrh r4, [r1]
  732. and r4, r4, r6
  733. streqh r4, [r1]
  734. strneb r4, [r1]
  735. b .dtfc_loop
  736. .dtfc_cut_tile:
  737. add r4, r4, #7 @ 0-6
  738. mov r4, r4, lsl #2
  739. mov r12,#0xf<<28
  740. mov r12,r12,asr r4
  741. mov r2, r2, ror #16
  742. tst r5, #0x0800 @ flipped?
  743. mvnne r12,r12
  744. and r2, r2, r12
  745. mov r2, r2, ror #16
  746. mov r12,#0xf
  747. tst r8, #1
  748. bne .dtfc_shadow
  749. tst r2, r2
  750. beq .dtfc_loop
  751. tst r5, #0x0800
  752. beq .dtfc_TileNorm
  753. b .dtfc_TileFlip
  754. @ check if we have detected layer covered with hi-prio tiles:
  755. .dtfc_check_rendflags:
  756. ldr r2, [r9, #OFS_EST_rendstatus]
  757. tst r2, #(PDRAW_PLANE_HI_PRIO|PDRAW_SHHI_DONE)
  758. beq .dtfc_loop
  759. bic r8, r8, #1 @ sh/hi mode off
  760. tst r2, #PDRAW_SHHI_DONE
  761. bne .dtfc_loop @ already processed
  762. orr r2, r2, #PDRAW_SHHI_DONE
  763. str r2, [r9, #OFS_EST_rendstatus]
  764. add r1, r11,#8
  765. mov r3, #320/4/4
  766. mov r6, #0xbf
  767. orr r6, r6, r6, lsl #8
  768. orr r6, r6, r6, lsl #16
  769. .dtfc_loop_shprep:
  770. ldmia r1, {r2,r4,r5,r7}
  771. subs r3, r3, #1
  772. and r2, r2, r6
  773. and r4, r4, r6
  774. and r5, r5, r6
  775. and r7, r7, r6
  776. stmia r1!,{r2,r4,r5,r7}
  777. bne .dtfc_loop_shprep
  778. mvn r5, #0 @ r5=prevcode=-1
  779. b .dtfc_loop
  780. .pool
  781. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  782. @ void DrawSpritesSHi(unsigned char *sprited, struct PicoEState *est)
  783. .global DrawSpritesSHi
  784. DrawSpritesSHi:
  785. ldr r3, [r0]
  786. mov r12,#0xff
  787. ands r3, r3, #0x7f
  788. bxeq lr
  789. stmfd sp!, {r1,r4-r11,lr} @ +est
  790. strb r12,[r0,#2] @ set end marker
  791. add r10,r0, #3 @ r10=HighLnSpr end
  792. add r10,r10,r3 @ r10=HighLnSpr end
  793. ldr r11,[r1, #OFS_EST_HighCol]
  794. mov r12,#0xf
  795. ldr lr, [r1, #OFS_EST_PicoMem_vram]
  796. DrawSpriteSHi:
  797. @ draw next sprite
  798. ldrb r0, [r10,#-1]!
  799. ldr r7, [sp] @ est
  800. ldr r1, [r7, #OFS_EST_HighPreSpr]
  801. cmp r0, #0xff
  802. ldmeqfd sp!, {r1,r4-r11,pc} @ end of list
  803. and r0, r0, #0x7f
  804. add r0, r1, r0, lsl #3
  805. ldr r9, [r0, #4] @ sprite[1]
  806. mov r2, r9, asr #16 @ r2=sx
  807. mov r9, r9, lsl #16
  808. mov r3, r9, lsr #31 @ priority
  809. mov r9, r9, lsr #16
  810. @ orr r9, r9, r8, lsl #31 @ r9=code|sh[31] @@ sh is always on here now
  811. and r4, r9, #0x6000
  812. orr r9, r9, r4, lsl #16
  813. orr r9, r9, #0x90000000 @ r9=scc1 ???? ... <code> (s=shadow/hilight, cc=pal)
  814. cmp r12,r9, lsr #28 @ sh/hi with pal3?
  815. cmpne r3, #1 @ if not, is it hi prio?
  816. bne DrawSpriteSHi @ non-operator low sprite, already drawn
  817. ldr r3, [r0] @ sprite[0]
  818. mov r6, r3, lsr #28
  819. sub r6, r6, #1 @ r6=width-1 (inc later)
  820. mov r5, r3, lsr #24
  821. and r5, r5, #7 @ r5=height
  822. ldr r7, [r7, #OFS_EST_DrawScanline]
  823. mov r0, r3, lsl #16 @ r4=sy<<16 (tmp)
  824. sub r7, r7, r0, asr #16 @ r7=row=DrawScanline-sy
  825. tst r9, #0x1000
  826. movne r0, r5, lsl #3
  827. subne r0, r0, #1
  828. subne r7, r0, r7 @ if (code&0x1000) row=(height<<3)-1-row; // Flip Y
  829. add r8, r9, r7, lsr #3 @ tile+=row>>3; // Tile number increases going down
  830. tst r9, #0x0800
  831. mlane r8, r5, r6, r8 @ if (code&0x0800) { tile+=delta*(width-1);
  832. rsbne r5, r5, #0 @ delta=-delta; } // r5=delta now
  833. mov r8, r8, lsl #21
  834. mov r8, r8, lsr #17
  835. and r7, r7, #7
  836. add r8, r8, r7, lsl #1 @ tile+=(row&7)<<1; // Tile address
  837. mov r5, r5, lsl #4 @ delta<<=4; // Delta of address
  838. mov r3, r4, lsr #9 @ r3=pal=((code>>9)&0x30);
  839. add r6, r6, #1 @ inc now
  840. adds r0, r2, #0 @ mov sx to r0 and set ZV flags
  841. b .dsprShi_loop_enter
  842. .dsprShi_loop:
  843. subs r6, r6, #1 @ width--
  844. beq DrawSpriteSHi
  845. adds r0, r0, #8 @ sx+=8
  846. add r8, r8, r5 @ tile+=delta
  847. .dsprShi_loop_enter:
  848. ble .dsprShi_loop @ sx <= 0
  849. cmp r0, #328
  850. bge DrawSpriteSHi
  851. mov r8, r8, lsl #17
  852. mov r8, r8, lsr #17 @ tile&=0x7fff; // Clip tile address
  853. ldr r2, [lr, r8, lsl #1] @ pack=*(unsigned int *)(PicoMem.vram+addr); // Get 8 pixels
  854. add r1, r11, r0 @ r1=pdest
  855. tst r2, r2
  856. beq .dsprShi_loop
  857. cmp r12, r9, lsr #28
  858. beq .dsprShi_shadow
  859. cmp r2, r2, ror #4
  860. beq .dsprShi_SingleColor @ tileline singlecolor
  861. tst r9, #0x0800
  862. bne .dsprShi_TileFlip
  863. @ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r12: helper pattern
  864. @ scratch: r4, r7
  865. .dsprShi_TileNorm:
  866. TileNorm r12
  867. b .dsprShi_loop
  868. .dsprShi_TileFlip:
  869. TileFlip r12
  870. b .dsprShi_loop
  871. .dsprShi_SingleColor:
  872. and r4, r2, #0xf
  873. orr r4, r3, r4
  874. orr r4, r4, r4, lsl #8
  875. tst r0, #1 @ not aligned?
  876. strneb r4, [r1], #1
  877. streqh r4, [r1], #2
  878. strh r4, [r1], #2
  879. strh r4, [r1], #2
  880. strh r4, [r1], #2
  881. strneb r4, [r1], #1
  882. b .dsprShi_loop
  883. .dsprShi_shadow:
  884. tst r9, #0x8000
  885. beq .dsprShi_shadow_lowpri
  886. cmp r2, r2, ror #4
  887. beq .dsprShi_singlec_sh
  888. tst r9, #0x0800
  889. bne .dsprShi_TileFlip_sh
  890. @ (r1=pdest, r2=pixels8, r3=pal) r4, r7: scratch, r12: helper pattern
  891. .dsprShi_TileNorm_sh:
  892. TileNormSh
  893. b .dsprShi_loop
  894. .dsprShi_TileFlip_sh:
  895. TileFlipSh
  896. b .dsprShi_loop
  897. .dsprShi_singlec_sh:
  898. cmp r2, #0xe0000000
  899. bcc .dsprShi_SingleColor @ normal singlecolor tileline (carry inverted in ARM)
  900. tst r2, #0x10000000
  901. bne .dsprShi_sh_sh
  902. TileSingleHi
  903. b .dsprShi_loop
  904. .dsprShi_sh_sh:
  905. TileSingleSh
  906. b .dsprShi_loop
  907. .dsprShi_shadow_lowpri:
  908. tst r9, #0x800
  909. bne .dsprShi_TileFlip_sh_lp
  910. .dsprShi_TileNorm_sh_lp:
  911. TileNormSh_onlyop_lp
  912. b .dsprShi_loop
  913. .dsprShi_TileFlip_sh_lp:
  914. TileFlipSh_onlyop_lp
  915. b .dsprShi_loop
  916. .pool
  917. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  918. @ void DrawAllSprites(unsigned char *sprited, int prio, int sh,
  919. @ struct PicoEState *est)
  920. .global DrawAllSprites
  921. DrawAllSprites:
  922. orr r1, r2, r1, lsl #1
  923. ldr r2, [r0]
  924. ands r2, r2, #0x7f
  925. bxeq lr
  926. @ time to do some real work
  927. stmfd sp!, {r1,r3-r11,lr} @ +sh|prio<<1 +est
  928. mov r12,#0xff
  929. strb r12,[r0,#2] @ set end marker
  930. add r10,r0, #3
  931. add r10,r10,r2 @ r10=HighLnSpr end
  932. ldr r11,[r3, #OFS_EST_HighCol]
  933. mov r12,#0xf
  934. ldr lr, [r3, #OFS_EST_PicoMem_vram]
  935. @ + 0 : hhhhvvvv ----hhvv yyyyyyyy yyyyyyyy // v, h: horiz. size
  936. @ + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8
  937. DrawSprite:
  938. @ draw next sprite
  939. ldrb r0, [r10,#-1]!
  940. ldr r8, [sp] @ sh|prio<<1
  941. ldr r7, [sp, #4] @ est
  942. mov r2, r0, lsr #7
  943. cmp r0, #0xff
  944. ldmeqfd sp!, {r1,r3-r11,pc} @ end of list
  945. cmp r2, r8, lsr #1
  946. bne DrawSprite @ wrong priority
  947. ldr r1, [r7, #OFS_EST_HighPreSpr]
  948. and r0, r0, #0x7f
  949. add r0, r1, r0, lsl #3
  950. ldr r3, [r0] @ sprite[0]
  951. ldr r7, [r7, #OFS_EST_DrawScanline]
  952. mov r6, r3, lsr #28
  953. sub r6, r6, #1 @ r6=width-1 (inc later)
  954. mov r5, r3, lsr #24
  955. and r5, r5, #7 @ r5=height
  956. mov r4, r3, lsl #16 @ r4=sy<<16 (tmp)
  957. ldr r9, [r0, #4]
  958. sub r7, r7, r4, asr #16 @ r7=row=DrawScanline-sy
  959. mov r2, r9, asr #16 @ r2=sx
  960. mov r9, r9, lsl #16
  961. mov r9, r9, lsr #16
  962. orr r9, r9, r8, lsl #31 @ r9=code|sh[31]
  963. tst r9, #0x1000
  964. movne r4, r5, lsl #3
  965. subne r4, r4, #1
  966. subne r7, r4, r7 @ if (code&0x1000) row=(height<<3)-1-row; // Flip Y
  967. add r8, r9, r7, lsr #3 @ tile+=row>>3; // Tile number increases going down
  968. tst r9, #0x0800
  969. mlane r8, r5, r6, r8 @ if (code&0x0800) { tile+=delta*(width-1);
  970. rsbne r5, r5, #0 @ delta=-delta; } // r5=delta now
  971. mov r8, r8, lsl #21
  972. mov r8, r8, lsr #17
  973. and r7, r7, #7
  974. add r8, r8, r7, lsl #1 @ tile+=(row&7)<<1; // Tile address
  975. .dspr_continue:
  976. @ cache some stuff to avoid mem access
  977. mov r5, r5, lsl #4 @ delta<<=4; // Delta of address
  978. and r4, r9, #0x6000
  979. orr r9, r9, r4, lsl #16
  980. orrs r9, r9, #0x10000000 @ r9=scc1 ???? ... <code> (s=shadow/hilight, cc=pal)
  981. mov r3, r4, lsr #9 @ r3=pal=((code>>9)&0x30);
  982. orrmi r3, r3, #0x40 @ for sh/hi
  983. add r6, r6, #1 @ inc now
  984. adds r0, r2, #0 @ mov sx to r0 and set ZV flags
  985. b .dspr_loop_enter
  986. .dspr_loop:
  987. subs r6, r6, #1 @ width--
  988. beq DrawSprite
  989. adds r0, r0, #8 @ sx+=8
  990. add r8, r8, r5 @ tile+=delta
  991. .dspr_loop_enter:
  992. ble .dspr_loop @ sx <= 0
  993. cmp r0, #328
  994. bge DrawSprite
  995. mov r8, r8, lsl #17
  996. mov r8, r8, lsr #17 @ tile&=0x7fff; // Clip tile address
  997. ldr r2, [lr, r8, lsl #1] @ pack=*(unsigned int *)(PicoMem.vram+addr); // Get 8 pixels
  998. add r1, r11, r0 @ r1=pdest
  999. tst r2, r2
  1000. beq .dspr_loop
  1001. cmp r12, r9, lsr #28
  1002. beq .dspr_shadow
  1003. cmp r2, r2, ror #4
  1004. beq .dspr_SingleColor @ tileline singlecolor
  1005. tst r9, #0x0800
  1006. bne .dspr_TileFlip
  1007. @ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r12: helper pattern
  1008. @ scratch: r4, r7
  1009. .dspr_TileNorm:
  1010. TileNorm r12
  1011. b .dspr_loop
  1012. .dspr_TileFlip:
  1013. TileFlip r12
  1014. b .dspr_loop
  1015. .dspr_singlec_sh:
  1016. cmp r2, #0xe0000000
  1017. bcs .dspr_TileNorm_sh @ op. tileline, markop. XXX: maybe add a spec. handler?
  1018. .dspr_SingleColor:
  1019. and r4, r2, #0xf
  1020. orr r4, r3, r4
  1021. orr r4, r4, r4, lsl #8
  1022. tst r0, #1 @ not aligned?
  1023. strneb r4, [r1], #1
  1024. streqh r4, [r1], #2
  1025. strh r4, [r1], #2
  1026. strh r4, [r1], #2
  1027. strh r4, [r1], #2
  1028. strneb r4, [r1], #1
  1029. b .dspr_loop
  1030. .dspr_shadow:
  1031. cmp r2, r2, ror #4
  1032. beq .dspr_singlec_sh
  1033. tst r9, #0x0800
  1034. bne .dspr_TileFlip_sh
  1035. @ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r12: helper pattern
  1036. .dspr_TileNorm_sh:
  1037. TileNormSh_markop
  1038. b .dspr_loop
  1039. .dspr_TileFlip_sh:
  1040. TileFlipSh_markop
  1041. b .dspr_loop
  1042. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  1043. @ void DrawWindow(int tstart, int tend, int prio, int sh
  1044. @ struct PicoEState *est)
  1045. .global DrawWindow
  1046. DrawWindow:
  1047. ldr r12, [sp] @ est
  1048. stmfd sp!, {r4-r11,lr}
  1049. ldr r6, [r12, #OFS_EST_Pico]
  1050. ldr r10, [r12, #OFS_EST_DrawScanline]
  1051. mov r11, r12 @ est
  1052. ldrb r12, [r6, #OFS_Pico_video_reg+3] @ pvid->reg[3]
  1053. ldr r4, [r6, #OFS_Pico_video_reg+12]
  1054. mov r5, r10, lsr #3
  1055. and r10, r10, #7
  1056. mov r10, r10, lsl #1 @ r10=ty
  1057. mov r12, r12, lsl #10
  1058. tst r4, #1 @ 40 cell mode?
  1059. andne r12, r12, #0xf000 @ 0x3c<<10
  1060. andeq r12, r12, #0xf800
  1061. addne r12, r12, r5, lsl #7
  1062. addeq r12, r12, r5, lsl #6 @ nametab
  1063. add r12, r12, r0, lsl #2 @ +starttile
  1064. ldr lr, [r11, #OFS_EST_PicoMem_vram]
  1065. ldr r6, [r11, #OFS_EST_rendstatus]
  1066. @ fetch the first code now
  1067. ldrh r7, [lr, r12]
  1068. ands r6, r6, #PDRAW_WND_DIFF_PRIO
  1069. orr r6, r6, r2
  1070. eoreq r8, r2, r7, lsr #15 @ do prio bits differ?
  1071. cmpeq r8, #1
  1072. ldmeqfd sp!, {r4-r11,pc} @ yes, assume that whole window uses same priority
  1073. orr r6, r6, r3, lsl #8 @ shadow mode
  1074. sub r8, r1, r0
  1075. @ cache some stuff to avoid mem access
  1076. ldr r11, [r11, #OFS_EST_HighCol]
  1077. mov r8, r8, lsl #1 @ cells
  1078. add r11,r11,#8
  1079. mvn r9, #0 @ r9=prevcode=-1
  1080. add r1, r11, r0, lsl #4 @ r1=pdest
  1081. mov r0, #0xf
  1082. b .dwloop_enter
  1083. @ r4,r5 are scratch in this loop
  1084. .dwloop:
  1085. add r1, r1, #8
  1086. .dwloop_nor1:
  1087. add r12, r12, #2 @ halfwords
  1088. ldrh r7, [lr, r12] @ r7=code (int, but from unsigned, no sign extend)
  1089. subs r8, r8, #1
  1090. beq .dwloop_end @ done
  1091. eor r5, r6, r7, lsr #15
  1092. tst r5, #1
  1093. orrne r6, r6, #2 @ wrong pri
  1094. bne .dwloop
  1095. cmp r7, r9
  1096. beq .dw_samecode @ we know stuff about this tile already
  1097. .dwloop_enter:
  1098. mov r9, r7 @ remember code
  1099. movs r2, r9, lsl #20 @ if (code&0x1000)
  1100. mov r2, r2, lsl #1
  1101. add r2, r10, r2, lsr #17 @ r2=addr=(code&0x7ff)<<4; addr+=ty
  1102. eorcs r2, r2, #0x0e @ if (code&0x1000) addr^=0xe;
  1103. and r3, r9, #0x6000
  1104. mov r3, r3, lsr #9 @ r3=pal=((code&0x6000)>>9);
  1105. ldr r2, [lr, r2, lsl #1] @ pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
  1106. .dw_samecode:
  1107. tst r6, #0x100
  1108. bne .dw_shadow
  1109. .dw_shadow_done:
  1110. tst r2, r2
  1111. beq .dwloop @ tileline blank
  1112. cmp r2, r2, ror #4
  1113. beq .dw_SingleColor @ tileline singlecolor
  1114. tst r9, #0x0800
  1115. bne .dw_TileFlip
  1116. @ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r0: helper pattern
  1117. .dw_TileNorm:
  1118. TileNorm r0
  1119. b .dwloop
  1120. .dw_TileFlip:
  1121. TileFlip r0
  1122. b .dwloop
  1123. .dw_SingleColor:
  1124. and r4, r0, r2 @ #0x0000000f
  1125. orr r4, r3, r4
  1126. orr r4, r4, r4, lsl #8
  1127. orr r4, r4, r4, lsl #16
  1128. mov r5, r4
  1129. stmia r1!, {r4,r5}
  1130. b .dwloop_nor1 @ we incremeted r1 ourselves
  1131. .dw_shadow:
  1132. tst r6, #1 @ hi pri?
  1133. orreq r3, r3, #0x40
  1134. beq .dw_shadow_done
  1135. ldr r4, [r1]
  1136. mov r5, #0x3f
  1137. orr r5, r5, r5, lsl #8
  1138. orr r5, r5, r5, lsl #16
  1139. and r4, r4, r5
  1140. str r4, [r1]
  1141. ldr r4, [r1,#4]
  1142. and r4, r4, r5
  1143. str r4, [r1,#4]
  1144. b .dw_shadow_done
  1145. .dwloop_end:
  1146. and r2, r6, #PDRAW_WND_DIFF_PRIO
  1147. ldmfd sp!, {r4-r11,lr}
  1148. ldr r0, [sp]
  1149. ldr r1, [r0, #OFS_EST_rendstatus]
  1150. orr r1, r1, r2
  1151. str r1, [r0, #OFS_EST_rendstatus]
  1152. bx lr
  1153. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  1154. @ hilights 2 pixels in RGB444/BGR444 format
  1155. .macro TileDoShHi2Pixels444 reg
  1156. mov \reg, \reg, ror #12
  1157. adds \reg, \reg, #0x40000000
  1158. orrcs \reg, \reg, #0xf0000000
  1159. mov \reg, \reg, ror #28
  1160. adds \reg, \reg, #0x40000000
  1161. orrcs \reg, \reg, #0xf0000000
  1162. mov \reg, \reg, ror #28
  1163. adds \reg, \reg, #0x40000000
  1164. orrcs \reg, \reg, #0xf0000000
  1165. mov \reg, \reg, ror #24
  1166. adds \reg, \reg, #0x40000000
  1167. orrcs \reg, \reg, #0xf0000000
  1168. mov \reg, \reg, ror #28
  1169. adds \reg, \reg, #0x40000000
  1170. orrcs \reg, \reg, #0xf0000000
  1171. mov \reg, \reg, ror #28
  1172. adds \reg, \reg, #0x40000000
  1173. orrcs \reg, \reg, #0xf0000000
  1174. mov \reg, \reg, ror #12
  1175. .endm
  1176. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  1177. @ Convert 0000bbb0 ggg0rrr0
  1178. @ to rrrrrggg gggbbbbb
  1179. @ r2,r3 - scratch, lr = 0x001c001c, r8 = 0x08610861
  1180. .macro convRGB565 reg
  1181. and r2, lr, \reg,lsr #7 @ b
  1182. and r3, lr, \reg,lsr #3 @ g
  1183. and \reg, lr, \reg,lsl #1 @ r
  1184. orr r2, r2, r3, lsl #6
  1185. orr \reg, r2, \reg,lsl #11
  1186. and r2, r8, \reg,lsr #4
  1187. orr \reg, \reg, r2
  1188. .endm
  1189. @ trashes: r2-r8,r12,lr; r8 = 0x08610861; r0,r1 are advanced
  1190. .macro vidConvCpyRGB565_local
  1191. mov r12, r2, lsr #3 @ repeats
  1192. mov lr, #0x001c0000
  1193. orr lr, lr, #0x01c @ lr == pattern 0x001c001c
  1194. 0:
  1195. ldmia r1!, {r4-r7}
  1196. subs r12, r12, #1
  1197. convRGB565 r4
  1198. str r4, [r0], #4
  1199. convRGB565 r5
  1200. str r5, [r0], #4
  1201. convRGB565 r6
  1202. str r6, [r0], #4
  1203. convRGB565 r7
  1204. str r7, [r0], #4
  1205. bgt 0b
  1206. .endm
  1207. .global vidConvCpyRGB565
  1208. vidConvCpyRGB565: @ void *to, void *from, int pixels
  1209. stmfd sp!, {r4-r9,lr}
  1210. mov r8, #0x0061
  1211. orr r8, r8, #0x0800
  1212. orr r8, r8, r8, lsl #16
  1213. vidConvCpyRGB565_local
  1214. ldmfd sp!, {r4-r9,lr}
  1215. bx lr
  1216. @ void PicoDoHighPal555(int sh, int line, struct PicoEState *est)
  1217. .global PicoDoHighPal555
  1218. PicoDoHighPal555:
  1219. stmfd sp!, {r4-r10,lr}
  1220. mov r10,r2 @ est
  1221. mov r1, #0
  1222. ldr r8, [r10, #OFS_EST_Pico]
  1223. PicoDoHighPal555_nopush:
  1224. orr r9, r1, r0, lsl #31 @ 0:called from FinalizeLine555, 31: s/h
  1225. add r0, r10, #OFS_EST_HighPal
  1226. mov r1, #0
  1227. strb r1, [r8, #OFS_Pico_m_dirtyPal]
  1228. ldr r1, [r10, #OFS_EST_PicoMem_cram]
  1229. mov r2, #0x40
  1230. mov r8, #0x0061
  1231. orr r8, r8, #0x0800
  1232. orr r8, r8, r8, lsl #16
  1233. vidConvCpyRGB565_local
  1234. tst r9, #(1<<31)
  1235. beq PicoDoHighPal555_end
  1236. add r3, r10, #OFS_EST_HighPal
  1237. @ shadowed pixels:
  1238. mov r12, #0x008e
  1239. add r4, r3, #0x40*2
  1240. orr r12,r12,#0x7300
  1241. add r5, r3, #0xc0*2
  1242. orr r12,r12,r12,lsl #16
  1243. mov lr, #0x40/4
  1244. .fl_loopcpRGB555_sh:
  1245. ldmia r3!, {r1,r6}
  1246. subs lr, lr, #1
  1247. and r1, r12, r1, lsr #1
  1248. and r6, r12, r6, lsr #1
  1249. stmia r4!, {r1,r6}
  1250. stmia r5!, {r1,r6}
  1251. bne .fl_loopcpRGB555_sh
  1252. @ hilighted pixels:
  1253. @ t = ((dpal[i] >> 1) & 0x738e738e) + 0x738e738e;
  1254. @ t |= (t >> 4) & 0x08610861;
  1255. @ r8=0x08610861
  1256. sub r3, r3, #0x40*2
  1257. mov lr, #0x40/4
  1258. .fl_loopcpRGB555_hi:
  1259. ldmia r3!, {r1,r6}
  1260. and r1, r12, r1, lsr #1
  1261. and r6, r12, r6, lsr #1
  1262. add r1, r12, r1
  1263. add r6, r12, r6
  1264. and r5, r8, r1, lsr #4
  1265. and r7, r8, r6, lsr #4
  1266. orr r1, r1, r5
  1267. orr r6, r6, r7
  1268. stmia r4!, {r1,r6}
  1269. subs lr, lr, #1
  1270. bne .fl_loopcpRGB555_hi
  1271. mov r0, #1
  1272. PicoDoHighPal555_end:
  1273. tst r9, #1
  1274. ldmeqfd sp!, {r4-r10,pc}
  1275. ldr r8, [r10, #OFS_EST_Pico]
  1276. b FinalizeLineRGB555_pal_done
  1277. @ void FinalizeLine555(int sh, int line, struct PicoEState *est)
  1278. .global FinalizeLine555
  1279. FinalizeLine555:
  1280. stmfd sp!, {r4-r10,lr}
  1281. mov r10,r2 @ est
  1282. ldr r8, [r10, #OFS_EST_Pico]
  1283. ldrb r2, [r8, #OFS_Pico_m_dirtyPal]
  1284. mov r1, #1
  1285. tst r2, r2
  1286. bne PicoDoHighPal555_nopush
  1287. FinalizeLineRGB555_pal_done:
  1288. add r3, r10, #OFS_EST_HighPal
  1289. ldr r12, [r10, #OFS_EST_rendstatus]
  1290. eors r0, r0, #1 @ sh is 0
  1291. mov lr, #0xff
  1292. tstne r12,#PDRAW_ACC_SPRITES
  1293. movne lr, #0x3f
  1294. ldr r1, [r10, #OFS_EST_HighCol]
  1295. ldr r0, [r10, #OFS_EST_DrawLineDest]
  1296. add r1, r1, #8
  1297. ldrb r12, [r8, #OFS_Pico_video_reg+12]
  1298. mov lr, lr, lsl #1
  1299. tst r12, #1
  1300. movne r2, #320/8 @ len
  1301. bne .fl_no32colRGB555
  1302. ldr r4, [r10, #OFS_EST_PicoOpt]
  1303. mov r2, #256/8
  1304. ldr r4, [r4]
  1305. tst r4, #0x4000
  1306. bne .fl_32scale_RGB555
  1307. tst r4, #0x0100
  1308. addeq r0, r0, #32*2
  1309. .fl_no32colRGB555:
  1310. #ifdef UNALIGNED_DRAWLINEDEST
  1311. @ this is basically for Gizmondo, which has unaligned odd lines in the framebuffer
  1312. tst r0, #2
  1313. bne .fl_RGB555u
  1314. #endif
  1315. .fl_loopRGB555:
  1316. ldr r12, [r1], #4
  1317. ldr r7, [r1], #4
  1318. and r4, lr, r12, lsl #1
  1319. ldrh r4, [r3, r4]
  1320. and r5, lr, r12, lsr #7
  1321. ldrh r5, [r3, r5]
  1322. and r6, lr, r12, lsr #15
  1323. ldrh r6, [r3, r6]
  1324. orr r4, r4, r5, lsl #16
  1325. and r5, lr, r12, lsr #23
  1326. ldrh r5, [r3, r5]
  1327. and r8, lr, r7, lsl #1
  1328. ldrh r8, [r3, r8]
  1329. orr r5, r6, r5, lsl #16
  1330. and r6, lr, r7, lsr #7
  1331. ldrh r6, [r3, r6]
  1332. and r12,lr, r7, lsr #15
  1333. ldrh r12,[r3, r12]
  1334. and r7, lr, r7, lsr #23
  1335. ldrh r7, [r3, r7]
  1336. orr r8, r8, r6, lsl #16
  1337. subs r2, r2, #1
  1338. orr r12,r12, r7, lsl #16
  1339. stmia r0!, {r4,r5,r8,r12}
  1340. bne .fl_loopRGB555
  1341. ldmfd sp!, {r4-r10,lr}
  1342. bx lr
  1343. .fl_32scale_RGB555:
  1344. mov r9, #0x3900 @ f800 07e0 001f | e000 0780 001c | 3800 01e0 0007
  1345. orr r9, r9, #0x00e7
  1346. #ifdef UNALIGNED_DRAWLINEDEST
  1347. tst r0, #2
  1348. bne .fl_32scale_RGB555u
  1349. #endif
  1350. .fl_loop32scale_RGB555:
  1351. ldr r12, [r1], #4
  1352. ldr r7, [r1], #4
  1353. and r4, lr, r12,lsl #1
  1354. ldrh r4, [r3, r4]
  1355. and r5, lr, r12,lsr #7
  1356. ldrh r5, [r3, r5]
  1357. and r4, r4, r9, lsl #2
  1358. orr r4, r4, r4, lsl #14 @ r4[31:16] = 1/4 pix_s 0
  1359. and r5, r5, r9, lsl #2
  1360. sub r6, r5, r5, lsr #2 @ r6 = 3/4 pix_s 1
  1361. add r4, r4, r6, lsl #16 @ pix_d 0, 1
  1362. and r6, lr, r12,lsr #15
  1363. ldrh r6, [r3, r6]
  1364. and r12,lr, r12,lsr #23
  1365. ldrh r12,[r3, r12]
  1366. and r6, r6, r9, lsl #2
  1367. add r5, r5, r6
  1368. mov r5, r5, lsr #1
  1369. sub r6, r6, r6, lsr #2 @ r6 = 3/4 pix_s 2
  1370. orr r5, r5, r6, lsl #16
  1371. and r6, lr, r7, lsl #1
  1372. ldrh r6, [r3, r6]
  1373. and r12,r12,r9, lsl #2
  1374. add r5, r5, r12,lsl #14 @ pix_d 2, 3
  1375. and r6, r6, r9, lsl #2
  1376. orr r6, r12,r6, lsl #16 @ pix_d 4, 5
  1377. and r12,lr, r7, lsr #7
  1378. ldrh r12,[r3, r12]
  1379. and r10,lr, r7, lsr #15
  1380. ldrh r10,[r3, r10]
  1381. and r12,r12,r9, lsl #2
  1382. sub r8, r12,r12,lsr #2 @ r8 = 3/4 pix_s 1
  1383. add r8, r8, r6, lsr #18
  1384. and r7, lr, r7, lsr #23
  1385. ldrh r7, [r3, r7]
  1386. and r10,r10,r9, lsl #2
  1387. orr r8, r8, r10,lsl #15
  1388. add r8, r8, r12,lsl #15 @ pix_d 6, 7
  1389. sub r10,r10,r10,lsr #2 @ r10= 3/4 pix_s 2
  1390. and r7, r7, r9, lsl #2
  1391. add r10,r10,r7, lsr #2 @ += 1/4 pix_s 3
  1392. orr r10,r10,r7, lsl #16 @ pix_d 8, 9
  1393. subs r2, r2, #1
  1394. stmia r0!, {r4,r5,r6,r8,r10}
  1395. bne .fl_loop32scale_RGB555
  1396. ldmfd sp!, {r4-r10,lr}
  1397. bx lr
  1398. #ifdef UNALIGNED_DRAWLINEDEST
  1399. @ unaligned versions of loops
  1400. @ warning: starts drawing 2bytes before dst
  1401. .fl_RGB555u:
  1402. sub r0, r0, #2 @ initial adjustment
  1403. mov r8, #0
  1404. .fl_loopRGB555u:
  1405. ldr r12, [r1], #4
  1406. ldr r7, [r1], #4
  1407. and r6, lr, r12,lsl #1
  1408. ldrh r6, [r3, r6]
  1409. and r5, lr, r12,lsr #7
  1410. ldrh r5, [r3, r5]
  1411. orr r4, r8, r6, lsl #16
  1412. and r6, lr, r12,lsr #15
  1413. ldrh r6, [r3, r6]
  1414. and r8, lr, r12,lsr #23
  1415. ldrh r8, [r3, r8]
  1416. orr r5, r5, r6, lsl #16
  1417. and r6, lr, r7, lsl #1
  1418. ldrh r6, [r3, r6]
  1419. and r12,lr, r7, lsr #7
  1420. ldrh r12,[r3, r12]
  1421. orr r6, r8, r6, lsl #16
  1422. and r8, lr, r7, lsr #15
  1423. ldrh r8, [r3, r8]
  1424. and r7, lr, r7, lsr #23
  1425. subs r2, r2, #1
  1426. orr r12,r12,r8, lsl #16
  1427. ldrh r8, [r3, r7]
  1428. stmia r0!, {r4,r5,r6,r12}
  1429. bne .fl_loopRGB555u
  1430. strh r8, [r0], #2
  1431. ldmfd sp!, {r4-r10,lr}
  1432. bx lr
  1433. .fl_32scale_RGB555u:
  1434. sub r0, r0, #2 @ initial adjustment
  1435. mov r4, #0
  1436. @ r9 f800 07e0 001f | e000 0780 001c | 3800 01e0 0007
  1437. .fl_loop32scale_RGB555u:
  1438. ldr r12, [r1], #4
  1439. ldr r7, [r1], #4
  1440. and r6, lr, r12,lsl #1
  1441. ldrh r6, [r3, r6]
  1442. and r5, lr, r12,lsr #7
  1443. ldrh r5, [r3, r5]
  1444. and r6, r6, r9, lsl #2
  1445. orr r4, r4, r6, lsl #16 @ r4 = pix_d -1, 0
  1446. and r5, r5, r9, lsl #2
  1447. sub r8, r5, r5, lsr #2 @ r8 = 3/4 pix_s 1
  1448. add r6, r8, r6, lsr #2 @ r6 = (1/4 pix_s 0) + (3/4 pix_s 1)
  1449. orr r5, r6, r5, lsl #15
  1450. and r6, lr, r12,lsr #15
  1451. ldrh r6, [r3, r6]
  1452. and r12,lr, r12,lsr #23
  1453. ldrh r12,[r3, r12]
  1454. and r6, r6, r9, lsl #2
  1455. add r5, r5, r6, lsl #15 @ r5 = pix_d 1, 2
  1456. and r8, lr, r7, lsl #1
  1457. ldrh r8, [r3, r8]
  1458. and r10,lr, r7, lsr #7
  1459. ldrh r10,[r3, r10]
  1460. and r12,r12,r9, lsl #2
  1461. sub r6, r6, r6, lsr #2 @ r6 = 3/4 pix_s 2
  1462. add r6, r6, r12,lsr #2
  1463. orr r6, r6, r12,lsl #16 @ r6 = pix_d 3, 4
  1464. and r8, r8, r9, lsl #2
  1465. and r10,r10,r9, lsl #2
  1466. sub r12,r10,r10,lsr #2 @ r12 = 3/4 pix_s 5
  1467. orr r8, r8, r8, lsl #14
  1468. add r8, r8, r12,lsl #16 @ r8 = pix_d 5, 6
  1469. and r12,lr, r7, lsr #15
  1470. ldrh r12,[r3, r12]
  1471. and r7, lr, r7, lsr #23
  1472. ldrh r7, [r3, r7]
  1473. and r12,r12,r9, lsl #2
  1474. add r10,r10,r12
  1475. mov r10,r10, lsr #1
  1476. sub r12,r12,r12,lsr #2 @ r12 = 3/4 pix_s 6
  1477. orr r10,r10,r12,lsl #16
  1478. and r7, r7, r9, lsl #2
  1479. add r10,r10,r7, lsl #14 @ r10 = pix_d 7, 8
  1480. subs r2, r2, #1
  1481. stmia r0!, {r4,r5,r6,r8,r10}
  1482. mov r4, r7
  1483. bne .fl_loop32scale_RGB555u
  1484. strh r4, [r0], #2
  1485. ldmfd sp!, {r4-r10,lr}
  1486. bx lr
  1487. #endif /* UNALIGNED_DRAWLINEDEST */
  1488. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  1489. @ utility
  1490. .global blockcpy @ void *dst, void *src, size_t n
  1491. blockcpy:
  1492. stmfd sp!, {r4,r5}
  1493. mov r2, r2, lsr #4
  1494. blockcpy_loop:
  1495. ldmia r1!, {r3-r5,r12}
  1496. subs r2, r2, #1
  1497. stmia r0!, {r3-r5,r12}
  1498. bne blockcpy_loop
  1499. ldmfd sp!, {r4,r5}
  1500. bx lr
  1501. .global blockcpy_or @ void *dst, void *src, size_t n, int pat
  1502. blockcpy_or:
  1503. stmfd sp!, {r4-r6}
  1504. orr r3, r3, r3, lsl #8
  1505. orr r3, r3, r3, lsl #16
  1506. mov r2, r2, lsr #4
  1507. blockcpy_loop_or:
  1508. ldmia r1!, {r4-r6,r12}
  1509. subs r2, r2, #1
  1510. orr r4, r4, r3
  1511. orr r5, r5, r3
  1512. orr r6, r6, r3
  1513. orr r12,r12,r3
  1514. stmia r0!, {r4-r6,r12}
  1515. bne blockcpy_loop_or
  1516. ldmfd sp!, {r4-r6}
  1517. bx lr
  1518. @ vim:filetype=armasm