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