draw_arm.S 53 KB

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