draw_arm.S 52 KB

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