draw_arm.S 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029
  1. /*
  2. * assembly optimized versions of most funtions from draw.c
  3. * (C) notaz, 2006-2010
  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. .extern Pico
  11. .extern PicoOpt
  12. .extern HighCol
  13. .extern DrawScanline
  14. .extern HighSprZ
  15. .extern rendstatus
  16. .extern HighPreSpr
  17. .extern DrawLineDest
  18. .extern DrawStripInterlace
  19. .extern HighCacheS_ptr
  20. .equiv OVERRIDE_HIGHCOL, 1
  21. .equ PDRAW_SPRITES_MOVED, (1<<0)
  22. .equ PDRAW_WND_DIFF_PRIO, (1<<1)
  23. .equ PDRAW_ACC_SPRITES, (1<<2)
  24. .equ PDRAW_DIRTY_SPRITES, (1<<4)
  25. .equ PDRAW_PLANE_HI_PRIO, (1<<6)
  26. .equ PDRAW_SHHI_DONE, (1<<7)
  27. @ helper
  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 plane_sh, int *hcache, int cellskip, int maxcells);
  263. .global DrawLayer
  264. DrawLayer:
  265. stmfd sp!, {r4-r11,lr}
  266. ldr r11, =(Pico+0x22228) @ Pico.video
  267. mov r8, #1
  268. ldrb r7, [r11, #16] @ ??vv??hh
  269. mov r6, r1 @ hcache
  270. orr r9, r3, r0, lsl #30
  271. orr r9, r9, r2, lsl #8 @ r9=sh[31]|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. bicgt r1, r1, #0xff00 @ r1=ymask=(height<<8)|0xff; ...; // Y Mask in pixels
  279. add r10, r10, #5
  280. cmp r10, #7
  281. subge r10, r10, #1 @ r10=shift[width] (5,6,6,7)
  282. @ calculate xmask:
  283. mov r5, r8, lsl r10
  284. sub r5, r5, #1 @ r5=xmask
  285. @ Find name table:
  286. ands r0, r0, #1
  287. ldreqb r12, [r11, #2]
  288. ldrneb r12, [r11, #4]
  289. ldr r2, =DrawScanline @ trying to make good use of pipeline here
  290. ldr lr, =(Pico+0x10000) @ lr=Pico.vram
  291. moveq r12, r12, lsl #10
  292. movne r12, r12, lsl #13
  293. and r12, r12, #(7<<13) @ r12=(ts->nametab<<1) (halfword compliant)
  294. ldrh r8, [r11, #12]
  295. ldrb r7, [r11, #11]
  296. ldr r2, [r2]
  297. mov r4, r8, lsr #8 @ pvid->reg[13]
  298. mov r4, r4, lsl #10 @ htab=pvid->reg[13]<<9; (halfwords)
  299. tst r7, #2
  300. addne r4, r4, r2, lsl #2 @ htab+=DrawScanline<<1; // Offset by line
  301. tst r7, #1
  302. biceq r4, r4, #0x1f @ htab&=~0xf; // Offset by tile
  303. add r4, r4, r0, lsl #1 @ htab+=plane
  304. bic r4, r4, #0x00ff0000 @ just in case
  305. ldrh r3, [lr, r4] @ r3=hscroll
  306. tst r7, #4
  307. bne .DrawStrip_vsscroll
  308. @ Get vertical scroll value:
  309. add r7, lr, #0x012000
  310. add r7, r7, #0x000180 @ r7=Pico.vsram (Pico+0x22180)
  311. ldr r7, [r7]
  312. tst r8, #2
  313. tstne r8, #4
  314. bne .DrawStrip_interlace
  315. tst r0, r0
  316. movne r7, r7, lsr #16
  317. @ Find the line in the name table
  318. add r2, r2, r7
  319. and r2, r2, r1
  320. mov r4, r2, lsr #3
  321. add r10, r10, #1 @ shift[width]++
  322. add r12, r12, r4, lsl r10 @ nametab+=(ts.line>>3)<<shift[width];
  323. @ ldmia r0, {r1,r2,r3,r5,r6,r9} @ r2=line, r3=ts->hscroll, r5=ts->xmask, r6=ts->hc, r9=ts->cells
  324. and r10,r2, #7
  325. mov r10,r10, lsl #1 @ r10=ty=(ts->line&7)<<1;
  326. orr r10,r10, r9, lsl #24
  327. rsb r8, r3, #0
  328. mov r8, r8, lsr #3 @ r8=tilex=(-ts->hscroll)>>3
  329. sub r1, r3, #1
  330. and r1, r1, #7
  331. add r7, r1, #1 @ r7=dx=((ts->hscroll-1)&7)+1
  332. tst r9, #1<<31
  333. mov r3, #0
  334. orrne r10,r10, #1<<23 @ r10=(cells<<24|sh<<23|hi_not_empty<<22|had_output<<21|ty)
  335. movne r3, #0x40 @ default to shadowed pal on sh mode
  336. cmp r7, #8
  337. addne r10,r10, #0x01000000 @ we will loop cells+1 times if there is scroll
  338. and r9, r9, #0xff00
  339. add r8, r8, r9, lsr #8 @ tilex+=cellskip
  340. add r7, r7, r9, lsr #5 @ dx+=cellskip<<3;
  341. sub r10,r10,r9, lsl #16 @ cells-=cellskip
  342. @ cache some stuff to avoid mem access
  343. .if OVERRIDE_HIGHCOL
  344. ldr r11,=HighCol
  345. mov r0, #0xf
  346. ldr r11,[r11]
  347. .else
  348. ldr r11,=HighCol
  349. mov r0, #0xf
  350. .endif
  351. mvn r9, #0 @ r9=prevcode=-1
  352. add r1, r11, r7 @ r1=pdest
  353. @ r4 & r7 are scratch in this loop
  354. .dsloop_subr1:
  355. sub r1, r1, #8
  356. .dsloop: @ 40-41 times
  357. subs r10,r10, #0x01000000
  358. bmi .dsloop_exit
  359. .dsloop_enter:
  360. and r7, r5, r8
  361. add r7, lr, r7, lsl #1 @ Pico.vram+((tilex&ts->xmask) as halfwords)
  362. ldrh r7, [r7, r12] @ r7=code (int, but from unsigned, no sign extend)
  363. add r1, r1, #8
  364. add r8, r8, #1
  365. tst r7, #0x8000
  366. bne .DrawStrip_hiprio
  367. cmp r7, r9
  368. beq .DrawStrip_samecode @ we know stuff about this tile already
  369. mov r9, r7 @ remember code
  370. orr r10, r10, #1<<21 @ seen non hi-prio tile
  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. bic r7, r3, #0x3f
  378. and r3, r9, #0x6000
  379. add r3, r7, r3, lsr #9 @ r3=pal=((code&0x6000)>>9);
  380. .DrawStrip_samecode:
  381. tst r2, r2
  382. beq .dsloop @ tileline blank
  383. cmp r2, r2, ror #4
  384. beq .DrawStrip_SingleColor @ tileline singlecolor
  385. tst r9, #0x0800
  386. bne .DrawStrip_TileFlip
  387. @ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r0: helper pattern
  388. .DrawStrip_TileNorm:
  389. TileNorm r0
  390. b .dsloop
  391. .DrawStrip_TileFlip:
  392. TileFlip r0
  393. b .dsloop
  394. .DrawStrip_SingleColor:
  395. and r4, r2, #0xf
  396. orr r4, r3, r4
  397. orr r4, r4, r4, lsl #8
  398. tst r1, #1 @ not aligned?
  399. strneb r4, [r1], #1
  400. streqh r4, [r1], #2
  401. strh r4, [r1], #2
  402. strh r4, [r1], #2
  403. strh r4, [r1], #2
  404. strneb r4, [r1], #1 @ have a remaining unaligned pixel?
  405. b .dsloop_subr1
  406. .DrawStrip_hiprio_maybempt:
  407. cmp r7, r9
  408. beq .dsloop @ must've been empty, otherwise we wouldn't get here
  409. movs r2, r7, lsl #20 @ if (code&0x1000)
  410. mov r2, r2, lsl #1
  411. add r2, r2, r10, lsl #17
  412. mov r2, r2, lsr #17
  413. eorcs r2, r2, #0x0e @ if (code&0x1000) addr^=0xe;
  414. ldr r2, [lr, r2, lsl #1] @ pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
  415. mov r9, r7 @ remember code
  416. tst r2, r2
  417. beq .dsloop
  418. orr r10, r10, #1<<22
  419. .DrawStrip_hiprio:
  420. tst r10, #0x00c00000
  421. beq .DrawStrip_hiprio_maybempt
  422. sub r0, r1, r11
  423. orr r7, r7, r0, lsl #16
  424. orr r7, r7, r10, lsl #25 @ (ty<<25)
  425. tst r7, #0x1000
  426. eorne r7, r7, #7<<26 @ if(code&0x1000) cval^=7<<26;
  427. str r7, [r6], #4 @ cache hi priority tile
  428. mov r0, #0xf
  429. b .dsloop
  430. .dsloop_exit:
  431. tst r10, #1<<21 @ seen non hi-prio tile
  432. ldreq r1, =rendstatus
  433. mov r0, #0
  434. ldreq r2, [r1]
  435. str r0, [r6] @ terminate the cache list
  436. orreq r2, r2, #PDRAW_PLANE_HI_PRIO @ had a layer with all hi-prio tiles
  437. streq r2, [r1]
  438. ldmfd sp!, {r4-r11,lr}
  439. bx lr
  440. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  441. .DrawStrip_vsscroll:
  442. rsb r8, r3, #0
  443. mov r8, r8, lsr #3 @ r8=tilex=(-ts->hscroll)>>3
  444. bic r8, r8, #0x3fc00000
  445. orr r8, r8, r5, lsl #25 @ r8=(xmask[31:25]|had_output[24]|tilex[21:0])
  446. ldr r4, =DrawScanline
  447. orr r5, r1, r10, lsl #24
  448. ldr r4, [r4]
  449. sub r1, r3, #1
  450. orr r5, r5, r4, lsl #16 @ r5=(shift_width[31:24]|scanline[23:16]|ymask[15:0])
  451. and r1, r1, #7
  452. add r7, r1, #1 @ r7=dx=((ts->hscroll-1)&7)+1
  453. mov r10,r9, lsl #16
  454. tst r0, #1
  455. orrne r10,r10, #0x8000
  456. tst r9, #1<<31
  457. mov r3, #0
  458. orr r10,r10, #0xff000000 @ will be adjusted on entering loop
  459. orrne r10,r10, #1<<23 @ r10=(cell[31:24]|sh[23]|hi_not_empty[22]|cells_max[21:16]|plane[15]|ty[14:0])
  460. movne r3, #0x40 @ default to shadowed pal on sh mode
  461. cmp r7, #8
  462. subne r10,r10, #0x01000000 @ have hscroll, start with negative cell
  463. and r9, r9, #0xff00
  464. add r8, r8, r9, lsr #8 @ tilex+=cellskip
  465. add r7, r7, r9, lsr #5 @ dx+=cellskip<<3;
  466. add r10,r10,r9, lsl #16 @ cell+=cellskip
  467. @ cache some stuff to avoid mem access
  468. .if OVERRIDE_HIGHCOL
  469. ldr r11,=HighCol
  470. mov r0, #0xf
  471. ldr r11,[r11]
  472. .else
  473. ldr r11,=HighCol
  474. mov r0, #0xf
  475. .endif
  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 r7, lr, #0x012000
  488. add r7, r7, #0x000180 @ r7=Pico.vsram (Pico+0x22180)
  489. add r7, r7, r10,asr #23 @ vsram + ((cell&~1)<<1)
  490. bic r7, r7, #3
  491. tst r10,#0x8000 @ plane1?
  492. addne r7, r7, #2
  493. ldrh r7, [r7] @ r7=vscroll
  494. bic r10,r10,#0xff @ clear old ty
  495. and r4, r5, #0xff0000 @ scanline
  496. add r4, r4, r7, lsl #16 @ ... += vscroll
  497. and r4, r4, r5, lsl #16 @ ... &= ymask
  498. and r7, r4, #0x70000
  499. orr r10,r10,r7, lsr #15 @ new ty
  500. mov r4, r4, lsr #19
  501. mov r7, r5, lsr #24
  502. mov r4, r4, lsl r7 @ nametabadd
  503. and r7, r8, r8, lsr #25
  504. add r7, lr, r7, lsl #1 @ Pico.vram+((tilex&ts->xmask) as halfwords)
  505. add r7, r7, r4, lsl #1
  506. ldrh r7, [r7, r12] @ r7=code (int, but from unsigned, no sign extend)
  507. add r1, r1, #8
  508. add r8, r8, #1
  509. tst r7, #0x8000
  510. bne .DrawStrip_vs_hiprio
  511. cmp r7, r9
  512. beq .DrawStrip_vs_samecode @ we know stuff about this tile already
  513. mov r9, r7 @ remember code
  514. orr r8, r8, #(1<<24)@ seen non hi-prio tile
  515. movs r2, r9, lsl #20 @ if (code&0x1000)
  516. mov r2, r2, lsl #1
  517. add r2, r2, r10, lsl #17
  518. mov r2, r2, lsr #17
  519. eorcs r2, r2, #0x0e @ if (code&0x1000) addr^=0xe;
  520. ldr r2, [lr, r2, lsl #1] @ pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
  521. bic r7, r3, #0x3f
  522. and r3, r9, #0x6000
  523. add r3, r7, r3, lsr #9 @ r3=pal=((code&0x6000)>>9);
  524. .DrawStrip_vs_samecode:
  525. tst r2, r2
  526. beq .dsloop_vs @ tileline blank
  527. cmp r2, r2, ror #4
  528. beq .DrawStrip_vs_SingleColor @ tileline singlecolor
  529. tst r9, #0x0800
  530. bne .DrawStrip_vs_TileFlip
  531. @ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r0: helper pattern
  532. .DrawStrip_vs_TileNorm:
  533. TileNorm r0
  534. b .dsloop_vs
  535. .DrawStrip_vs_TileFlip:
  536. TileFlip r0
  537. b .dsloop_vs
  538. .DrawStrip_vs_SingleColor:
  539. and r4, r2, #0xf
  540. orr r4, r3, r4
  541. orr r4, r4, r4, lsl #8
  542. tst r1, #1 @ not aligned?
  543. strneb r4, [r1], #1
  544. streqh r4, [r1], #2
  545. strh r4, [r1], #2
  546. strh r4, [r1], #2
  547. strh r4, [r1], #2
  548. strneb r4, [r1], #1 @ have a remaining unaligned pixel?
  549. b .dsloop_vs_subr1
  550. .DrawStrip_vs_hiprio:
  551. tst r10, #0x00c00000
  552. beq .DrawStrip_vs_hiprio_maybempt
  553. sub r0, r1, r11
  554. orr r7, r7, r0, lsl #16
  555. orr r7, r7, r10, lsl #25 @ (ty<<25)
  556. tst r7, #0x1000
  557. eorne r7, r7, #7<<26 @ if(code&0x1000) cval^=7<<26;
  558. str r7, [r6], #4 @ cache hi priority tile
  559. mov r0, #0xf
  560. b .dsloop_vs
  561. .DrawStrip_vs_hiprio_maybempt:
  562. cmp r7, r9
  563. beq .dsloop_vs @ must've been empty, otherwise we wouldn't get here
  564. movs r2, r7, lsl #20 @ if (code&0x1000)
  565. mov r2, r2, lsl #1
  566. add r2, r2, r10, lsl #17
  567. mov r2, r2, lsr #17
  568. eorcs r2, r2, #0x0e @ if (code&0x1000) addr^=0xe;
  569. ldr r2, [lr, r2, lsl #1] @ pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
  570. mov r9, r7 @ remember code
  571. tst r2, r2
  572. orrne r10, r10, #1<<22
  573. bne .DrawStrip_vs_hiprio
  574. b .dsloop_vs
  575. .dsloop_vs_exit:
  576. tst r8, #(1<<24) @ seen non hi-prio tile
  577. ldreq r1, =rendstatus
  578. mov r0, #0
  579. ldreq r2, [r1]
  580. str r0, [r6] @ terminate the cache list
  581. orreq r2, r2, #PDRAW_PLANE_HI_PRIO @ had a layer with all hi-prio tiles
  582. streq r2, [r1]
  583. ldmfd sp!, {r4-r11,lr}
  584. bx lr
  585. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  586. @ interlace mode 2? Sonic 2?
  587. .DrawStrip_interlace:
  588. tst r0, r0
  589. moveq r7, r7, lsl #21
  590. movne r7, r7, lsl #5
  591. @ Find the line in the name table
  592. add r2, r7, r2, lsl #22 @ r2=(vscroll+(DrawScanline<<1))<<21 (11 bits);
  593. orr r1, r1, #0x80000000
  594. and r2, r2, r1, ror #10 @ &((ymask<<1)|1)<<21;
  595. mov r2, r2, lsr #21
  596. mov r4, r2, lsr #4
  597. mov r12, r12, lsr #1 @ halfwords
  598. add r0, r12, r4, lsl r10 @ nametab+=(ts.line>>4)<<shift[width];
  599. and r9, r9, #0xff
  600. sub sp, sp, #6*4
  601. stmia sp, {r0,r2,r3,r5,r6,r9}
  602. mov r0, sp
  603. bl DrawStripInterlace @ struct TileStrip *ts
  604. add sp, sp, #6*4
  605. ldmfd sp!, {r4-r11,lr}
  606. bx lr
  607. .pool
  608. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  609. .global BackFill @ int reg7, int sh
  610. BackFill:
  611. stmfd sp!, {r4-r9,lr}
  612. .if OVERRIDE_HIGHCOL
  613. ldr lr, =HighCol
  614. mov r0, r0, lsl #26
  615. ldr lr, [lr]
  616. mov r0, r0, lsr #26
  617. add lr, lr, #8
  618. .else
  619. ldr lr, =(HighCol+8)
  620. mov r0, r0, lsl #26
  621. mov r0, r0, lsr #26
  622. .endif
  623. orr r0, r0, r1, lsl #6
  624. orr r0, r0, r0, lsl #8
  625. orr r0, r0, r0, lsl #16
  626. mov r1, r0
  627. mov r2, r0
  628. mov r3, r0
  629. mov r4, r0
  630. mov r5, r0
  631. mov r6, r0
  632. mov r7, r0
  633. @ go go go!
  634. stmia lr!, {r0-r7} @ 10*8*4
  635. stmia lr!, {r0-r7}
  636. stmia lr!, {r0-r7}
  637. stmia lr!, {r0-r7}
  638. stmia lr!, {r0-r7}
  639. stmia lr!, {r0-r7}
  640. stmia lr!, {r0-r7}
  641. stmia lr!, {r0-r7}
  642. stmia lr!, {r0-r7}
  643. stmia lr!, {r0-r7}
  644. ldmfd sp!, {r4-r9,r12}
  645. bx r12
  646. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  647. .global DrawTilesFromCache @ int *hc, int sh, int rlim
  648. DrawTilesFromCache:
  649. stmfd sp!, {r4-r8,r11,lr}
  650. @ cache some stuff to avoid mem access
  651. .if OVERRIDE_HIGHCOL
  652. ldr r11,=HighCol
  653. mov r12,#0xf
  654. ldr r11,[r11]
  655. .else
  656. ldr r11,=HighCol
  657. mov r12,#0xf
  658. .endif
  659. ldr lr, =(Pico+0x10000) @ lr=Pico.vram
  660. mvn r5, #0 @ r5=prevcode=-1
  661. ands r8, r1, #1
  662. orr r8, r8, r2, lsl #1
  663. bne .dtfc_check_rendflags
  664. @ scratch: r4, r7
  665. .dtfc_loop:
  666. ldr r6, [r0], #4 @ read code
  667. movs r1, r6, lsr #16 @ r1=dx;
  668. ldmeqfd sp!, {r4-r8,r11,pc} @ dx is never zero, this must be a terminator, return
  669. bic r4, r1, #0xfe00
  670. add r1, r11, r4 @ r1=pdest
  671. mov r7, r6, lsl #16
  672. cmp r5, r7, lsr #16
  673. beq .dtfc_samecode @ if (code==prevcode)
  674. mov r5, r7, lsr #16
  675. mov r2, r5, lsl #21
  676. mov r2, r2, lsr #17 @ r2=addr=(code&0x7ff)<<4;
  677. add r2, r2, r6, lsr #25 @ addr+=ty
  678. and r3, r5, #0x6000
  679. mov r3, r3, lsr #9 @ r3=pal=((code&0x6000)>>9);
  680. ldr r2, [lr, r2, lsl #1] @ pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
  681. .dtfc_samecode:
  682. rsbs r4, r4, r8, lsr #1
  683. bmi .dtfc_cut_tile
  684. tst r8, #1
  685. bne .dtfc_shadow
  686. tst r2, r2
  687. beq .dtfc_loop
  688. cmp r2, r2, ror #4
  689. beq .dtfc_SingleColor @ tileline singlecolor
  690. tst r5, #0x0800
  691. bne .dtfc_TileFlip
  692. @ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r12: helper pattern
  693. .dtfc_TileNorm:
  694. TileNorm r12
  695. b .dtfc_loop
  696. .dtfc_TileFlip:
  697. TileFlip r12
  698. b .dtfc_loop
  699. .dtfc_SingleColor:
  700. and r4, r2, #0xf
  701. orr r4, r3, r4
  702. orr r4, r4, r4, lsl #8
  703. tst r1, #1 @ not aligned?
  704. strneb r4, [r1], #1
  705. streqh r4, [r1], #2
  706. strh r4, [r1], #2
  707. strh r4, [r1], #2
  708. strh r4, [r1], #2
  709. strneb r4, [r1], #1 @ have a remaining unaligned pixel?
  710. b .dtfc_loop
  711. .dtfc_shadow:
  712. tst r2, r2
  713. beq .dtfc_shadow_blank
  714. cmp r2, r2, ror #4
  715. beq .dtfc_SingleColor @ tileline singlecolor
  716. tst r5, #0x0800
  717. bne .dtfc_TileFlipShHP
  718. @ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r12: helper pattern
  719. .dtfc_TileNormShHP:
  720. TileNormShHP
  721. b .dtfc_loop
  722. .dtfc_TileFlipShHP:
  723. TileFlipShHP
  724. b .dtfc_loop
  725. .dtfc_shadow_blank:
  726. tst r1, #1
  727. ldrneb r4, [r1]
  728. mov r6, #0xbf
  729. and r4, r4, #0xbf
  730. strneb r4, [r1], #1
  731. ldrh r4, [r1]
  732. orr r6, r6, r6, lsl #8
  733. and r4, r4, r6
  734. strh r4, [r1], #2
  735. ldrh r4, [r1]
  736. and r4, r4, r6
  737. strh r4, [r1], #2
  738. ldrh r4, [r1]
  739. and r4, r4, r6
  740. strh r4, [r1], #2
  741. ldrh r4, [r1]
  742. and r4, r4, r6
  743. streqh r4, [r1]
  744. strneb r4, [r1]
  745. b .dtfc_loop
  746. .dtfc_cut_tile:
  747. add r4, r4, #7 @ 0-6
  748. mov r4, r4, lsl #2
  749. mov r12,#0xf<<28
  750. mov r12,r12,asr r4
  751. mov r2, r2, ror #16
  752. tst r5, #0x0800 @ flipped?
  753. mvnne r12,r12
  754. and r2, r2, r12
  755. mov r2, r2, ror #16
  756. mov r12,#0xf
  757. tst r8, #1
  758. bne .dtfc_shadow
  759. tst r2, r2
  760. beq .dtfc_loop
  761. tst r5, #0x0800
  762. beq .dtfc_TileNorm
  763. b .dtfc_TileFlip
  764. @ check if we have detected layer covered with hi-prio tiles:
  765. .dtfc_check_rendflags:
  766. ldr r1, =rendstatus
  767. ldr r2, [r1]
  768. tst r2, #(PDRAW_PLANE_HI_PRIO|PDRAW_SHHI_DONE)
  769. beq .dtfc_loop
  770. bic r8, r8, #1 @ sh/hi mode off
  771. tst r2, #PDRAW_SHHI_DONE
  772. bne .dtfc_loop @ already processed
  773. orr r2, r2, #PDRAW_SHHI_DONE
  774. str r2, [r1]
  775. add r1, r11,#8
  776. mov r3, #320/4/4
  777. mov r6, #0xbf
  778. orr r6, r6, r6, lsl #8
  779. orr r6, r6, r6, lsl #16
  780. .dtfc_loop_shprep:
  781. ldmia r1, {r2,r4,r5,r7}
  782. subs r3, r3, #1
  783. and r2, r2, r6
  784. and r4, r4, r6
  785. and r5, r5, r6
  786. and r7, r7, r6
  787. stmia r1!,{r2,r4,r5,r7}
  788. bne .dtfc_loop_shprep
  789. mvn r5, #0 @ r5=prevcode=-1
  790. b .dtfc_loop
  791. .pool
  792. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  793. .global DrawSpritesSHi @ unsigned char *sprited
  794. DrawSpritesSHi:
  795. ldr r3, [r0]
  796. mov r12,#0xff
  797. ands r3, r3, #0x7f
  798. bxeq lr
  799. stmfd sp!, {r4-r11,lr}
  800. strb r12,[r0,#2] @ set end marker
  801. add r10,r0, #3 @ r10=HighLnSpr end
  802. add r10,r10,r3 @ r10=HighLnSpr end
  803. .if OVERRIDE_HIGHCOL
  804. ldr r11,=HighCol
  805. mov r12,#0xf
  806. ldr r11,[r11]
  807. .else
  808. ldr r11,=HighCol
  809. mov r12,#0xf
  810. .endif
  811. ldr lr, =(Pico+0x10000) @ lr=Pico.vram
  812. DrawSpriteSHi:
  813. @ draw next sprite
  814. ldrb r0, [r10,#-1]!
  815. ldr r1, =HighPreSpr
  816. @ ldr r8, [sp, #-4]
  817. cmp r0, #0xff
  818. ldmeqfd sp!, {r4-r11,pc} @ end of list
  819. and r0, r0, #0x7f
  820. add r0, r1, r0, lsl #3
  821. ldr r9, [r0, #4] @ sprite[1]
  822. mov r2, r9, asr #16 @ r2=sx
  823. mov r9, r9, lsl #16
  824. mov r3, r9, lsr #31 @ priority
  825. mov r9, r9, lsr #16
  826. @ orr r9, r9, r8, lsl #31 @ r9=code|sh[31] @@ sh is always on here now
  827. and r4, r9, #0x6000
  828. orr r9, r9, r4, lsl #16
  829. orr r9, r9, #0x90000000 @ r9=scc1 ???? ... <code> (s=shadow/hilight, cc=pal)
  830. cmp r12,r9, lsr #28 @ sh/hi with pal3?
  831. cmpne r3, #1 @ if not, is it hi prio?
  832. bne DrawSpriteSHi @ non-operator low sprite, already drawn
  833. ldr r3, [r0] @ sprite[0]
  834. ldr r7, =DrawScanline
  835. mov r6, r3, lsr #28
  836. sub r6, r6, #1 @ r6=width-1 (inc later)
  837. mov r5, r3, lsr #24
  838. and r5, r5, #7 @ r5=height
  839. mov r0, r3, lsl #16 @ r4=sy<<16 (tmp)
  840. ldr r7, [r7]
  841. sub r7, r7, r0, asr #16 @ r7=row=DrawScanline-sy
  842. tst r9, #0x1000
  843. movne r0, r5, lsl #3
  844. subne r0, r0, #1
  845. subne r7, r0, r7 @ if (code&0x1000) row=(height<<3)-1-row; // Flip Y
  846. add r8, r9, r7, lsr #3 @ tile+=row>>3; // Tile number increases going down
  847. tst r9, #0x0800
  848. mlane r8, r5, r6, r8 @ if (code&0x0800) { tile+=delta*(width-1);
  849. rsbne r5, r5, #0 @ delta=-delta; } // r5=delta now
  850. mov r8, r8, lsl #21
  851. mov r8, r8, lsr #17
  852. and r7, r7, #7
  853. add r8, r8, r7, lsl #1 @ tile+=(row&7)<<1; // Tile address
  854. mov r5, r5, lsl #4 @ delta<<=4; // Delta of address
  855. mov r3, r4, lsr #9 @ r3=pal=((code>>9)&0x30);
  856. add r6, r6, #1 @ inc now
  857. adds r0, r2, #0 @ mov sx to r0 and set ZV flags
  858. b .dsprShi_loop_enter
  859. .dsprShi_loop:
  860. subs r6, r6, #1 @ width--
  861. beq DrawSpriteSHi
  862. adds r0, r0, #8 @ sx+=8
  863. add r8, r8, r5 @ tile+=delta
  864. .dsprShi_loop_enter:
  865. ble .dsprShi_loop @ sx <= 0
  866. cmp r0, #328
  867. bge DrawSpriteSHi
  868. mov r8, r8, lsl #17
  869. mov r8, r8, lsr #17 @ tile&=0x7fff; // Clip tile address
  870. ldr r2, [lr, r8, lsl #1] @ pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
  871. add r1, r11, r0 @ r1=pdest
  872. tst r2, r2
  873. beq .dsprShi_loop
  874. cmp r12, r9, lsr #28
  875. beq .dsprShi_shadow
  876. cmp r2, r2, ror #4
  877. beq .dsprShi_SingleColor @ tileline singlecolor
  878. tst r9, #0x0800
  879. bne .dsprShi_TileFlip
  880. @ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r12: helper pattern
  881. @ scratch: r4, r7
  882. .dsprShi_TileNorm:
  883. TileNorm r12
  884. b .dsprShi_loop
  885. .dsprShi_TileFlip:
  886. TileFlip r12
  887. b .dsprShi_loop
  888. .dsprShi_SingleColor:
  889. and r4, r2, #0xf
  890. orr r4, r3, r4
  891. orr r4, r4, r4, lsl #8
  892. tst r0, #1 @ not aligned?
  893. strneb r4, [r1], #1
  894. streqh r4, [r1], #2
  895. strh r4, [r1], #2
  896. strh r4, [r1], #2
  897. strh r4, [r1], #2
  898. strneb r4, [r1], #1
  899. b .dsprShi_loop
  900. .dsprShi_shadow:
  901. tst r9, #0x8000
  902. beq .dsprShi_shadow_lowpri
  903. cmp r2, r2, ror #4
  904. beq .dsprShi_singlec_sh
  905. tst r9, #0x0800
  906. bne .dsprShi_TileFlip_sh
  907. @ (r1=pdest, r2=pixels8, r3=pal) r4, r7: scratch, r12: helper pattern
  908. .dsprShi_TileNorm_sh:
  909. TileNormSh
  910. b .dsprShi_loop
  911. .dsprShi_TileFlip_sh:
  912. TileFlipSh
  913. b .dsprShi_loop
  914. .dsprShi_singlec_sh:
  915. cmp r2, #0xe0000000
  916. bcc .dsprShi_SingleColor @ normal singlecolor tileline (carry inverted in ARM)
  917. tst r2, #0x10000000
  918. bne .dsprShi_sh_sh
  919. TileSingleHi
  920. b .dsprShi_loop
  921. .dsprShi_sh_sh:
  922. TileSingleSh
  923. b .dsprShi_loop
  924. .dsprShi_shadow_lowpri:
  925. tst r9, #0x800
  926. bne .dsprShi_TileFlip_sh_lp
  927. .dsprShi_TileNorm_sh_lp:
  928. TileNormSh_onlyop_lp
  929. b .dsprShi_loop
  930. .dsprShi_TileFlip_sh_lp:
  931. TileFlipSh_onlyop_lp
  932. b .dsprShi_loop
  933. .pool
  934. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  935. .global DrawAllSprites @ unsigned char *sprited, int prio, int sh
  936. DrawAllSprites:
  937. ldr r3, =rendstatus
  938. orr r1, r2, r1, lsl #1
  939. ldr r12,[r3]
  940. tst r12,#(PDRAW_DIRTY_SPRITES|PDRAW_SPRITES_MOVED)
  941. beq das_no_prep
  942. stmfd sp!, {r0,r1,lr}
  943. and r0, r12,#PDRAW_DIRTY_SPRITES
  944. bic r12,r12,#(PDRAW_DIRTY_SPRITES|PDRAW_SPRITES_MOVED)
  945. str r12,[r3]
  946. bl PrepareSprites
  947. ldmfd sp!, {r0,r1,lr}
  948. das_no_prep:
  949. ldr r3, [r0]
  950. ands r3, r3, #0x7f
  951. bxeq lr
  952. @ time to do some real work
  953. stmfd sp!, {r4-r11,lr}
  954. mov r12,#0xff
  955. strb r12,[r0,#2] @ set end marker
  956. add r10,r0, #3
  957. add r10,r10,r3 @ r10=HighLnSpr end
  958. str r1, [sp, #-4] @ no calls after this point
  959. .if OVERRIDE_HIGHCOL
  960. ldr r11,=HighCol
  961. mov r12,#0xf
  962. ldr r11,[r11]
  963. .else
  964. ldr r11,=HighCol
  965. mov r12,#0xf
  966. .endif
  967. ldr lr, =(Pico+0x10000) @ lr=Pico.vram
  968. @ + 0 : hhhhvvvv ----hhvv yyyyyyyy yyyyyyyy // v, h: horiz. size
  969. @ + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8
  970. DrawSprite: @ was: unsigned int *sprite, int sh, int acc_sprites
  971. @ draw next sprite
  972. ldrb r0, [r10,#-1]!
  973. ldr r1, =HighPreSpr
  974. ldr r8, [sp, #-4]
  975. mov r2, r0, lsr #7
  976. cmp r0, #0xff
  977. ldmeqfd sp!, {r4-r11,pc} @ end of list
  978. cmp r2, r8, lsr #1
  979. bne DrawSprite @ wrong priority
  980. and r0, r0, #0x7f
  981. add r0, r1, r0, lsl #3
  982. @ stmfd sp!, {r4-r9,r11,lr}
  983. @ orr r8, r2, r1, lsl #4
  984. ldr r3, [r0] @ sprite[0]
  985. ldr r7, =DrawScanline
  986. mov r6, r3, lsr #28
  987. sub r6, r6, #1 @ r6=width-1 (inc later)
  988. mov r5, r3, lsr #24
  989. and r5, r5, #7 @ r5=height
  990. mov r4, r3, lsl #16 @ r4=sy<<16 (tmp)
  991. ldr r7, [r7]
  992. ldr r9, [r0, #4]
  993. sub r7, r7, r4, asr #16 @ r7=row=DrawScanline-sy
  994. mov r2, r9, asr #16 @ r2=sx
  995. mov r9, r9, lsl #16
  996. mov r9, r9, lsr #16
  997. orr r9, r9, r8, lsl #31 @ r9=code|sh[31]
  998. tst r9, #0x1000
  999. movne r4, r5, lsl #3
  1000. subne r4, r4, #1
  1001. subne r7, r4, r7 @ if (code&0x1000) row=(height<<3)-1-row; // Flip Y
  1002. add r8, r9, r7, lsr #3 @ tile+=row>>3; // Tile number increases going down
  1003. tst r9, #0x0800
  1004. mlane r8, r5, r6, r8 @ if (code&0x0800) { tile+=delta*(width-1);
  1005. rsbne r5, r5, #0 @ delta=-delta; } // r5=delta now
  1006. mov r8, r8, lsl #21
  1007. mov r8, r8, lsr #17
  1008. and r7, r7, #7
  1009. add r8, r8, r7, lsl #1 @ tile+=(row&7)<<1; // Tile address
  1010. .dspr_continue:
  1011. @ cache some stuff to avoid mem access
  1012. mov r5, r5, lsl #4 @ delta<<=4; // Delta of address
  1013. and r4, r9, #0x6000
  1014. orr r9, r9, r4, lsl #16
  1015. orrs r9, r9, #0x10000000 @ r9=scc1 ???? ... <code> (s=shadow/hilight, cc=pal)
  1016. mov r3, r4, lsr #9 @ r3=pal=((code>>9)&0x30);
  1017. orrmi r3, r3, #0x40 @ for sh/hi
  1018. add r6, r6, #1 @ inc now
  1019. adds r0, r2, #0 @ mov sx to r0 and set ZV flags
  1020. b .dspr_loop_enter
  1021. .dspr_loop:
  1022. subs r6, r6, #1 @ width--
  1023. beq DrawSprite
  1024. adds r0, r0, #8 @ sx+=8
  1025. add r8, r8, r5 @ tile+=delta
  1026. .dspr_loop_enter:
  1027. ble .dspr_loop @ sx <= 0
  1028. cmp r0, #328
  1029. bge DrawSprite
  1030. mov r8, r8, lsl #17
  1031. mov r8, r8, lsr #17 @ tile&=0x7fff; // Clip tile address
  1032. ldr r2, [lr, r8, lsl #1] @ pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
  1033. add r1, r11, r0 @ r1=pdest
  1034. tst r2, r2
  1035. beq .dspr_loop
  1036. cmp r12, r9, lsr #28
  1037. beq .dspr_shadow
  1038. cmp r2, r2, ror #4
  1039. beq .dspr_SingleColor @ tileline singlecolor
  1040. tst r9, #0x0800
  1041. bne .dspr_TileFlip
  1042. @ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r12: helper pattern
  1043. @ scratch: r4, r7
  1044. .dspr_TileNorm:
  1045. TileNorm r12
  1046. b .dspr_loop
  1047. .dspr_TileFlip:
  1048. TileFlip r12
  1049. b .dspr_loop
  1050. .dspr_singlec_sh:
  1051. cmp r2, #0xe0000000
  1052. bcs .dspr_TileNorm_sh @ op. tileline, markop. XXX: maybe add a spec. handler?
  1053. .dspr_SingleColor:
  1054. and r4, r2, #0xf
  1055. orr r4, r3, r4
  1056. orr r4, r4, r4, lsl #8
  1057. tst r0, #1 @ not aligned?
  1058. strneb r4, [r1], #1
  1059. streqh r4, [r1], #2
  1060. strh r4, [r1], #2
  1061. strh r4, [r1], #2
  1062. strh r4, [r1], #2
  1063. strneb r4, [r1], #1
  1064. b .dspr_loop
  1065. .dspr_shadow:
  1066. cmp r2, r2, ror #4
  1067. beq .dspr_singlec_sh
  1068. tst r9, #0x0800
  1069. bne .dspr_TileFlip_sh
  1070. @ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r12: helper pattern
  1071. .dspr_TileNorm_sh:
  1072. TileNormSh_markop
  1073. b .dspr_loop
  1074. .dspr_TileFlip_sh:
  1075. TileFlipSh_markop
  1076. b .dspr_loop
  1077. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  1078. .global DrawWindow @ int tstart, int tend, int prio, int sh // int *hcache
  1079. DrawWindow:
  1080. stmfd sp!, {r4-r11,lr}
  1081. ldr r11, =(Pico+0x22228) @ Pico.video
  1082. ldr r10, =DrawScanline
  1083. ldrb r12, [r11, #3] @ pvid->reg[3]
  1084. ldr r10, [r10]
  1085. ldr r4, [r11, #12]
  1086. mov r5, r10, lsr #3
  1087. and r10, r10, #7
  1088. mov r10, r10, lsl #1 @ r10=ty
  1089. mov r12, r12, lsl #10
  1090. tst r4, #1 @ 40 cell mode?
  1091. andne r12, r12, #0xf000 @ 0x3c<<10
  1092. andeq r12, r12, #0xf800
  1093. addne r12, r12, r5, lsl #7
  1094. addeq r12, r12, r5, lsl #6 @ nametab
  1095. add r12, r12, r0, lsl #2 @ +starttile
  1096. ldr r6, =rendstatus
  1097. ldr lr, =(Pico+0x10000) @ lr=Pico.vram
  1098. ldr r6, [r6]
  1099. @ fetch the first code now
  1100. ldrh r7, [lr, r12]
  1101. ands r6, r6, #PDRAW_WND_DIFF_PRIO
  1102. orr r6, r6, r2
  1103. eoreq r8, r2, r7, lsr #15 @ do prio bits differ?
  1104. cmpeq r8, #1
  1105. ldmeqfd sp!, {r4-r11,pc} @ yes, assume that whole window uses same priority
  1106. orr r6, r6, r3, lsl #8 @ shadow mode
  1107. sub r8, r1, r0
  1108. @ cache some stuff to avoid mem access
  1109. .if OVERRIDE_HIGHCOL
  1110. ldr r11,=HighCol
  1111. mov r8, r8, lsl #1 @ cells
  1112. ldr r11,[r11]
  1113. mvn r9, #0 @ r9=prevcode=-1
  1114. add r11,r11,#8
  1115. .else
  1116. ldr r11,=(HighCol+8)
  1117. mov r8, r8, lsl #1 @ cells
  1118. mvn r9, #0 @ r9=prevcode=-1
  1119. .endif
  1120. add r1, r11, r0, lsl #4 @ r1=pdest
  1121. mov r0, #0xf
  1122. b .dwloop_enter
  1123. @ r4,r5 are scratch in this loop
  1124. .dwloop:
  1125. add r1, r1, #8
  1126. .dwloop_nor1:
  1127. add r12, r12, #2 @ halfwords
  1128. ldrh r7, [lr, r12] @ r7=code (int, but from unsigned, no sign extend)
  1129. subs r8, r8, #1
  1130. beq .dwloop_end @ done
  1131. eor r5, r6, r7, lsr #15
  1132. tst r5, #1
  1133. orrne r6, r6, #2 @ wrong pri
  1134. bne .dwloop
  1135. cmp r7, r9
  1136. beq .dw_samecode @ we know stuff about this tile already
  1137. .dwloop_enter:
  1138. mov r9, r7 @ remember code
  1139. movs r2, r9, lsl #20 @ if (code&0x1000)
  1140. mov r2, r2, lsl #1
  1141. add r2, r10, r2, lsr #17 @ r2=addr=(code&0x7ff)<<4; addr+=ty
  1142. eorcs r2, r2, #0x0e @ if (code&0x1000) addr^=0xe;
  1143. and r3, r9, #0x6000
  1144. mov r3, r3, lsr #9 @ r3=pal=((code&0x6000)>>9);
  1145. ldr r2, [lr, r2, lsl #1] @ pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
  1146. .dw_samecode:
  1147. tst r6, #0x100
  1148. bne .dw_shadow
  1149. .dw_shadow_done:
  1150. tst r2, r2
  1151. beq .dwloop @ tileline blank
  1152. cmp r2, r2, ror #4
  1153. beq .dw_SingleColor @ tileline singlecolor
  1154. tst r9, #0x0800
  1155. bne .dw_TileFlip
  1156. @ (r1=pdest, r2=pixels8, r3=pal) r4: scratch, r0: helper pattern
  1157. .dw_TileNorm:
  1158. TileNorm r0
  1159. b .dwloop
  1160. .dw_TileFlip:
  1161. TileFlip r0
  1162. b .dwloop
  1163. .dw_SingleColor:
  1164. and r4, r0, r2 @ #0x0000000f
  1165. orr r4, r3, r4
  1166. orr r4, r4, r4, lsl #8
  1167. orr r4, r4, r4, lsl #16
  1168. mov r5, r4
  1169. stmia r1!, {r4,r5}
  1170. b .dwloop_nor1 @ we incremeted r1 ourselves
  1171. .dw_shadow:
  1172. tst r6, #1 @ hi pri?
  1173. orreq r3, r3, #0x40
  1174. beq .dw_shadow_done
  1175. ldr r4, [r1]
  1176. mov r5, #0x3f
  1177. orr r5, r5, r5, lsl #8
  1178. orr r5, r5, r5, lsl #16
  1179. and r4, r4, r5
  1180. str r4, [r1]
  1181. ldr r4, [r1,#4]
  1182. and r4, r4, r5
  1183. str r4, [r1,#4]
  1184. b .dw_shadow_done
  1185. .dwloop_end:
  1186. ldr r0, =rendstatus
  1187. ldr r1, [r0]
  1188. and r6, r6, #PDRAW_WND_DIFF_PRIO
  1189. orr r1, r1, r6
  1190. str r1, [r0]
  1191. ldmfd sp!, {r4-r11,r12}
  1192. bx r12
  1193. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  1194. @ hilights 2 pixels in RGB444/BGR444 format
  1195. .macro TileDoShHi2Pixels444 reg
  1196. mov \reg, \reg, ror #12
  1197. adds \reg, \reg, #0x40000000
  1198. orrcs \reg, \reg, #0xf0000000
  1199. mov \reg, \reg, ror #28
  1200. adds \reg, \reg, #0x40000000
  1201. orrcs \reg, \reg, #0xf0000000
  1202. mov \reg, \reg, ror #28
  1203. adds \reg, \reg, #0x40000000
  1204. orrcs \reg, \reg, #0xf0000000
  1205. mov \reg, \reg, ror #24
  1206. adds \reg, \reg, #0x40000000
  1207. orrcs \reg, \reg, #0xf0000000
  1208. mov \reg, \reg, ror #28
  1209. adds \reg, \reg, #0x40000000
  1210. orrcs \reg, \reg, #0xf0000000
  1211. mov \reg, \reg, ror #28
  1212. adds \reg, \reg, #0x40000000
  1213. orrcs \reg, \reg, #0xf0000000
  1214. mov \reg, \reg, ror #12
  1215. .endm
  1216. .global FinalizeLineBGR444 @ int sh
  1217. FinalizeLineBGR444:
  1218. stmfd sp!, {r4-r6,lr}
  1219. mov r6, r0
  1220. ldr lr, =(Pico+0x22228) @ Pico.video
  1221. ldr r0, =DrawLineDest
  1222. ldrb r12, [lr, #12]
  1223. ldr r0, [r0]
  1224. sub r3, lr, #0x128 @ r3=Pico.cram
  1225. tst r12, #1
  1226. movne r2, #320/4 @ len
  1227. bne .fl_no32colBGR444
  1228. ldr r4, =PicoOpt
  1229. mov r2, #256/4
  1230. ldr r4, [r4]
  1231. tst r4, #0x100
  1232. addeq r0, r0, #32*2
  1233. .fl_no32colBGR444:
  1234. tst r6, r6
  1235. beq .fl_noshBGR444
  1236. ldr r4, =HighPal
  1237. ldrb r12, [lr, #-0x1a] @ 0x2220e ~ dirtyPal
  1238. tst r12, r12
  1239. moveq r3, r4
  1240. beq .fl_noshBGR444
  1241. mov r12, #0
  1242. strb r12, [lr, #-0x1a]
  1243. mov lr, #0x40/8
  1244. @ copy pal:
  1245. .fl_loopcpBGR444:
  1246. ldmia r3!, {r1,r5,r6,r12}
  1247. subs lr, lr, #1
  1248. stmia r4!, {r1,r5,r6,r12}
  1249. bne .fl_loopcpBGR444
  1250. @ shadowed pixels:
  1251. mov r12, #0x0077
  1252. orr r12,r12,#0x0700
  1253. orr r12,r12,r12,lsl #16
  1254. sub r3, r3, #0x40*2
  1255. add r5, r4, #0x80*2
  1256. mov lr, #0x40/4
  1257. .fl_loopcpBGR444_sh:
  1258. ldmia r3!, {r1,r6}
  1259. subs lr, lr, #1
  1260. and r1, r12, r1, lsr #1
  1261. and r6, r12, r6, lsr #1
  1262. stmia r4!, {r1,r6}
  1263. stmia r5!, {r1,r6}
  1264. bne .fl_loopcpBGR444_sh
  1265. @ hilighted pixels:
  1266. sub r3, r3, #0x40*2
  1267. mov lr, #0x40/2
  1268. .fl_loopcpBGR444_hi:
  1269. ldr r1, [r3], #4
  1270. TileDoShHi2Pixels444 r1
  1271. str r1, [r4], #4
  1272. subs lr, lr, #1
  1273. bne .fl_loopcpBGR444_hi
  1274. sub r3, r4, #0x40*3*2
  1275. mov r6, #1
  1276. .fl_noshBGR444:
  1277. ldr r12,=rendstatus
  1278. eors r6, r6, #1 @ sh is 0
  1279. ldr r12,[r12]
  1280. mov lr, #0xff
  1281. tstne r12,#PDRAW_ACC_SPRITES
  1282. .if OVERRIDE_HIGHCOL
  1283. ldr r1, =HighCol
  1284. movne lr, #0x3f
  1285. ldr r1, [r1]
  1286. mov lr, lr, lsl #1
  1287. add r1, r1, #8
  1288. .else
  1289. ldr r1, =(HighCol+8)
  1290. movne lr, #0x3f
  1291. mov lr, lr, lsl #1
  1292. .endif
  1293. .fl_loopBGR444:
  1294. ldr r12, [r1], #4
  1295. subs r2, r2, #1
  1296. and r4, lr, r12, lsl #1
  1297. ldrh r4, [r3, r4]
  1298. and r5, lr, r12, lsr #7
  1299. ldrh r5, [r3, r5]
  1300. and r6, lr, r12, lsr #15
  1301. ldrh r6, [r3, r6]
  1302. and r12,lr, r12, lsr #23
  1303. ldrh r12,[r3, r12] @ 1c.i.
  1304. orr r4, r4, r5, lsl #16
  1305. orr r5, r6, r12,lsl #16
  1306. stmia r0!, {r4,r5}
  1307. bne .fl_loopBGR444
  1308. ldmfd sp!, {r4-r6,lr}
  1309. bx lr
  1310. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  1311. @ Convert 0000bbb0 ggg0rrr0
  1312. @ to rrrrrggg gggbbbbb
  1313. @ r2,r3 - scratch, lr = 0x001c001c, r8 = 0x08610861
  1314. .macro convRGB565 reg
  1315. and r2, lr, \reg,lsr #7 @ b
  1316. and r3, lr, \reg,lsr #3 @ g
  1317. and \reg, lr, \reg,lsl #1 @ r
  1318. orr r2, r2, r3, lsl #6
  1319. orr \reg, r2, \reg,lsl #11
  1320. and r2, r8, \reg,lsr #4
  1321. orr \reg, \reg, r2
  1322. .endm
  1323. @ trashes: r2-r8,r12,lr; r8 = 0x08610861; r0,r1 are advanced
  1324. .macro vidConvCpyRGB565_local
  1325. mov r12, r2, lsr #3 @ repeats
  1326. mov lr, #0x001c0000
  1327. orr lr, lr, #0x01c @ lr == pattern 0x001c001c
  1328. 0:
  1329. ldmia r1!, {r4-r7}
  1330. subs r12, r12, #1
  1331. convRGB565 r4
  1332. str r4, [r0], #4
  1333. convRGB565 r5
  1334. str r5, [r0], #4
  1335. convRGB565 r6
  1336. str r6, [r0], #4
  1337. convRGB565 r7
  1338. str r7, [r0], #4
  1339. bgt 0b
  1340. .endm
  1341. .global vidConvCpyRGB565
  1342. vidConvCpyRGB565: @ void *to, void *from, int pixels
  1343. stmfd sp!, {r4-r9,lr}
  1344. mov r8, #0x0061
  1345. orr r8, r8, #0x0800
  1346. orr r8, r8, r8, lsl #16
  1347. vidConvCpyRGB565_local
  1348. ldmfd sp!, {r4-r9,lr}
  1349. bx lr
  1350. .global PicoDoHighPal555 @ int sh
  1351. PicoDoHighPal555:
  1352. stmfd sp!, {r4-r9,lr}
  1353. mov r1, #0
  1354. ldr r8, =(Pico+0x22228) @ Pico.video
  1355. PicoDoHighPal555_nopush:
  1356. orr r9, r1, r0, lsl #31 @ 0:called from FinalizeLine555, 31: s/h
  1357. ldr r0, =HighPal
  1358. mov r1, #0
  1359. strb r1, [r8, #-0x1a] @ 0x2220e ~ dirtyPal
  1360. sub r1, r8, #0x128 @ r1=Pico.cram
  1361. mov r2, #0x40
  1362. mov r8, #0x0061
  1363. orr r8, r8, #0x0800
  1364. orr r8, r8, r8, lsl #16
  1365. vidConvCpyRGB565_local
  1366. tst r9, #(1<<31)
  1367. beq PicoDoHighPal555_end
  1368. ldr r3, =HighPal
  1369. @ shadowed pixels:
  1370. mov r12, #0x008e
  1371. add r4, r3, #0x40*2
  1372. orr r12,r12,#0x7300
  1373. add r5, r3, #0xc0*2
  1374. orr r12,r12,r12,lsl #16
  1375. mov lr, #0x40/4
  1376. .fl_loopcpRGB555_sh:
  1377. ldmia r3!, {r1,r6}
  1378. subs lr, lr, #1
  1379. and r1, r12, r1, lsr #1
  1380. and r6, r12, r6, lsr #1
  1381. stmia r4!, {r1,r6}
  1382. stmia r5!, {r1,r6}
  1383. bne .fl_loopcpRGB555_sh
  1384. @ hilighted pixels:
  1385. @ t = ((dpal[i] >> 1) & 0x738e738e) + 0x738e738e;
  1386. @ t |= (t >> 4) & 0x08610861;
  1387. @ r8=0x08610861
  1388. sub r3, r3, #0x40*2
  1389. mov lr, #0x40/4
  1390. .fl_loopcpRGB555_hi:
  1391. ldmia r3!, {r1,r6}
  1392. and r1, r12, r1, lsr #1
  1393. and r6, r12, r6, lsr #1
  1394. add r1, r12, r1
  1395. add r6, r12, r6
  1396. and r5, r8, r1, lsr #4
  1397. and r7, r8, r6, lsr #4
  1398. orr r1, r1, r5
  1399. orr r6, r6, r7
  1400. stmia r4!, {r1,r6}
  1401. subs lr, lr, #1
  1402. bne .fl_loopcpRGB555_hi
  1403. mov r0, #1
  1404. PicoDoHighPal555_end:
  1405. tst r9, #1
  1406. ldmeqfd sp!, {r4-r9,pc}
  1407. ldr r8, =(Pico+0x22228) @ Pico.video
  1408. b FinalizeLineRGB555_pal_done
  1409. .global FinalizeLine555 @ int sh
  1410. FinalizeLine555:
  1411. stmfd sp!, {r4-r9,lr}
  1412. ldr r8, =(Pico+0x22228) @ Pico.video
  1413. ldrb r2, [r8, #-0x1a] @ 0x2220e ~ dirtyPal
  1414. mov r1, #1
  1415. tst r2, r2
  1416. bne PicoDoHighPal555_nopush
  1417. FinalizeLineRGB555_pal_done:
  1418. ldr r3, =HighPal
  1419. ldr r12,=rendstatus
  1420. eors r0, r0, #1 @ sh is 0
  1421. ldr r12,[r12]
  1422. mov lr, #0xff
  1423. tstne r12,#PDRAW_ACC_SPRITES
  1424. movne lr, #0x3f
  1425. .if OVERRIDE_HIGHCOL
  1426. ldr r1, =HighCol
  1427. ldr r0, =DrawLineDest
  1428. ldr r1, [r1]
  1429. ldr r0, [r0]
  1430. add r1, r1, #8
  1431. .else
  1432. ldr r0, =DrawLineDest
  1433. ldr r1, =(HighCol+8)
  1434. ldr r0, [r0]
  1435. .endif
  1436. ldrb r12, [r8, #12]
  1437. mov lr, lr, lsl #1
  1438. tst r12, #1
  1439. movne r2, #320/8 @ len
  1440. bne .fl_no32colRGB555
  1441. ldr r4, =PicoOpt
  1442. mov r2, #256/8
  1443. ldr r4, [r4]
  1444. tst r4, #0x4000
  1445. bne .fl_32scale_RGB555
  1446. tst r4, #0x0100
  1447. addeq r0, r0, #32*2
  1448. .fl_no32colRGB555:
  1449. #ifdef UNALIGNED_DRAWLINEDEST
  1450. @ this is basically for Gizmondo, which has unaligned odd lines in the framebuffer
  1451. tst r0, #2
  1452. bne .fl_RGB555u
  1453. #endif
  1454. .fl_loopRGB555:
  1455. ldr r12, [r1], #4
  1456. ldr r7, [r1], #4
  1457. and r4, lr, r12, lsl #1
  1458. ldrh r4, [r3, r4]
  1459. and r5, lr, r12, lsr #7
  1460. ldrh r5, [r3, r5]
  1461. and r6, lr, r12, lsr #15
  1462. ldrh r6, [r3, r6]
  1463. orr r4, r4, r5, lsl #16
  1464. and r5, lr, r12, lsr #23
  1465. ldrh r5, [r3, r5]
  1466. and r8, lr, r7, lsl #1
  1467. ldrh r8, [r3, r8]
  1468. orr r5, r6, r5, lsl #16
  1469. and r6, lr, r7, lsr #7
  1470. ldrh r6, [r3, r6]
  1471. and r12,lr, r7, lsr #15
  1472. ldrh r12,[r3, r12]
  1473. and r7, lr, r7, lsr #23
  1474. ldrh r7, [r3, r7]
  1475. orr r8, r8, r6, lsl #16
  1476. subs r2, r2, #1
  1477. orr r12,r12, r7, lsl #16
  1478. stmia r0!, {r4,r5,r8,r12}
  1479. bne .fl_loopRGB555
  1480. ldmfd sp!, {r4-r9,lr}
  1481. bx lr
  1482. .fl_32scale_RGB555:
  1483. stmfd sp!, {r10}
  1484. mov r9, #0x3900 @ f800 07e0 001f | e000 0780 001c | 3800 01e0 0007
  1485. orr r9, r9, #0x00e7
  1486. #ifdef UNALIGNED_DRAWLINEDEST
  1487. tst r0, #2
  1488. bne .fl_32scale_RGB555u
  1489. #endif
  1490. .fl_loop32scale_RGB555:
  1491. ldr r12, [r1], #4
  1492. ldr r7, [r1], #4
  1493. and r4, lr, r12,lsl #1
  1494. ldrh r4, [r3, r4]
  1495. and r5, lr, r12,lsr #7
  1496. ldrh r5, [r3, r5]
  1497. and r4, r4, r9, lsl #2
  1498. orr r4, r4, r4, lsl #14 @ r4[31:16] = 1/4 pix_s 0
  1499. and r5, r5, r9, lsl #2
  1500. sub r6, r5, r5, lsr #2 @ r6 = 3/4 pix_s 1
  1501. add r4, r4, r6, lsl #16 @ pix_d 0, 1
  1502. and r6, lr, r12,lsr #15
  1503. ldrh r6, [r3, r6]
  1504. and r12,lr, r12,lsr #23
  1505. ldrh r12,[r3, r12]
  1506. and r6, r6, r9, lsl #2
  1507. add r5, r5, r6
  1508. mov r5, r5, lsr #1
  1509. sub r6, r6, r6, lsr #2 @ r6 = 3/4 pix_s 2
  1510. orr r5, r5, r6, lsl #16
  1511. and r6, lr, r7, lsl #1
  1512. ldrh r6, [r3, r6]
  1513. and r12,r12,r9, lsl #2
  1514. add r5, r5, r12,lsl #14 @ pix_d 2, 3
  1515. and r6, r6, r9, lsl #2
  1516. orr r6, r12,r6, lsl #16 @ pix_d 4, 5
  1517. and r12,lr, r7, lsr #7
  1518. ldrh r12,[r3, r12]
  1519. and r10,lr, r7, lsr #15
  1520. ldrh r10,[r3, r10]
  1521. and r12,r12,r9, lsl #2
  1522. sub r8, r12,r12,lsr #2 @ r8 = 3/4 pix_s 1
  1523. add r8, r8, r6, lsr #18
  1524. and r7, lr, r7, lsr #23
  1525. ldrh r7, [r3, r7]
  1526. and r10,r10,r9, lsl #2
  1527. orr r8, r8, r10,lsl #15
  1528. add r8, r8, r12,lsl #15 @ pix_d 6, 7
  1529. sub r10,r10,r10,lsr #2 @ r10= 3/4 pix_s 2
  1530. and r7, r7, r9, lsl #2
  1531. add r10,r10,r7, lsr #2 @ += 1/4 pix_s 3
  1532. orr r10,r10,r7, lsl #16 @ pix_d 8, 9
  1533. subs r2, r2, #1
  1534. stmia r0!, {r4,r5,r6,r8,r10}
  1535. bne .fl_loop32scale_RGB555
  1536. ldmfd sp!, {r10}
  1537. ldmfd sp!, {r4-r9,lr}
  1538. bx lr
  1539. #ifdef UNALIGNED_DRAWLINEDEST
  1540. @ unaligned versions of loops
  1541. @ warning: starts drawing 2bytes before dst
  1542. .fl_RGB555u:
  1543. sub r0, r0, #2 @ initial adjustment
  1544. mov r8, #0
  1545. .fl_loopRGB555u:
  1546. ldr r12, [r1], #4
  1547. ldr r7, [r1], #4
  1548. and r6, lr, r12,lsl #1
  1549. ldrh r6, [r3, r6]
  1550. and r5, lr, r12,lsr #7
  1551. ldrh r5, [r3, r5]
  1552. orr r4, r8, r6, lsl #16
  1553. and r6, lr, r12,lsr #15
  1554. ldrh r6, [r3, r6]
  1555. and r8, lr, r12,lsr #23
  1556. ldrh r8, [r3, r8]
  1557. orr r5, r5, r6, lsl #16
  1558. and r6, lr, r7, lsl #1
  1559. ldrh r6, [r3, r6]
  1560. and r12,lr, r7, lsr #7
  1561. ldrh r12,[r3, r12]
  1562. orr r6, r8, r6, lsl #16
  1563. and r8, lr, r7, lsr #15
  1564. ldrh r8, [r3, r8]
  1565. and r7, lr, r7, lsr #23
  1566. subs r2, r2, #1
  1567. orr r12,r12,r8, lsl #16
  1568. ldrh r8, [r3, r7]
  1569. stmia r0!, {r4,r5,r6,r12}
  1570. bne .fl_loopRGB555u
  1571. strh r8, [r0], #2
  1572. ldmfd sp!, {r4-r9,lr}
  1573. bx lr
  1574. .fl_32scale_RGB555u:
  1575. sub r0, r0, #2 @ initial adjustment
  1576. mov r4, #0
  1577. @ r9 f800 07e0 001f | e000 0780 001c | 3800 01e0 0007
  1578. .fl_loop32scale_RGB555u:
  1579. ldr r12, [r1], #4
  1580. ldr r7, [r1], #4
  1581. and r6, lr, r12,lsl #1
  1582. ldrh r6, [r3, r6]
  1583. and r5, lr, r12,lsr #7
  1584. ldrh r5, [r3, r5]
  1585. and r6, r6, r9, lsl #2
  1586. orr r4, r4, r6, lsl #16 @ r4 = pix_d -1, 0
  1587. and r5, r5, r9, lsl #2
  1588. sub r8, r5, r5, lsr #2 @ r8 = 3/4 pix_s 1
  1589. add r6, r8, r6, lsr #2 @ r6 = (1/4 pix_s 0) + (3/4 pix_s 1)
  1590. orr r5, r6, r5, lsl #15
  1591. and r6, lr, r12,lsr #15
  1592. ldrh r6, [r3, r6]
  1593. and r12,lr, r12,lsr #23
  1594. ldrh r12,[r3, r12]
  1595. and r6, r6, r9, lsl #2
  1596. add r5, r5, r6, lsl #15 @ r5 = pix_d 1, 2
  1597. and r8, lr, r7, lsl #1
  1598. ldrh r8, [r3, r8]
  1599. and r10,lr, r7, lsr #7
  1600. ldrh r10,[r3, r10]
  1601. and r12,r12,r9, lsl #2
  1602. sub r6, r6, r6, lsr #2 @ r6 = 3/4 pix_s 2
  1603. add r6, r6, r12,lsr #2
  1604. orr r6, r6, r12,lsl #16 @ r6 = pix_d 3, 4
  1605. and r8, r8, r9, lsl #2
  1606. and r10,r10,r9, lsl #2
  1607. sub r12,r10,r10,lsr #2 @ r12 = 3/4 pix_s 5
  1608. orr r8, r8, r8, lsl #14
  1609. add r8, r8, r12,lsl #16 @ r8 = pix_d 5, 6
  1610. and r12,lr, r7, lsr #15
  1611. ldrh r12,[r3, r12]
  1612. and r7, lr, r7, lsr #23
  1613. ldrh r7, [r3, r7]
  1614. and r12,r12,r9, lsl #2
  1615. add r10,r10,r12
  1616. mov r10,r10, lsr #1
  1617. sub r12,r12,r12,lsr #2 @ r12 = 3/4 pix_s 6
  1618. orr r10,r10,r12,lsl #16
  1619. and r7, r7, r9, lsl #2
  1620. add r10,r10,r7, lsl #14 @ r10 = pix_d 7, 8
  1621. subs r2, r2, #1
  1622. stmia r0!, {r4,r5,r6,r8,r10}
  1623. mov r4, r7
  1624. bne .fl_loop32scale_RGB555u
  1625. strh r4, [r0], #2
  1626. ldmfd sp!, {r10}
  1627. ldmfd sp!, {r4-r9,lr}
  1628. bx lr
  1629. #endif /* UNALIGNED_DRAWLINEDEST */
  1630. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  1631. @ utility
  1632. .global blockcpy @ void *dst, void *src, size_t n
  1633. blockcpy:
  1634. stmfd sp!, {r4,r5}
  1635. mov r2, r2, lsr #4
  1636. blockcpy_loop:
  1637. ldmia r1!, {r3-r5,r12}
  1638. subs r2, r2, #1
  1639. stmia r0!, {r3-r5,r12}
  1640. bne blockcpy_loop
  1641. ldmfd sp!, {r4,r5}
  1642. bx lr
  1643. .global blockcpy_or @ void *dst, void *src, size_t n, int pat
  1644. blockcpy_or:
  1645. stmfd sp!, {r4-r6}
  1646. orr r3, r3, r3, lsl #8
  1647. orr r3, r3, r3, lsl #16
  1648. mov r2, r2, lsr #4
  1649. blockcpy_loop_or:
  1650. ldmia r1!, {r4-r6,r12}
  1651. subs r2, r2, #1
  1652. orr r4, r4, r3
  1653. orr r5, r5, r3
  1654. orr r6, r6, r3
  1655. orr r12,r12,r3
  1656. stmia r0!, {r4-r6,r12}
  1657. bne blockcpy_loop_or
  1658. ldmfd sp!, {r4-r6}
  1659. bx lr
  1660. @ vim:filetype=armasm