1 @ some color conversion and blitting routines
\r
3 @ (c) Copyright 2006, notaz
\r
4 @ All Rights Reserved
\r
7 @ Convert 0000bbb0 ggg0rrr0 0000bbb0 ggg0rrr0
\r
8 @ to 00000000 rrr00000 ggg00000 bbb00000 ...
\r
10 @ lr = 0x00e000e0, out: r3=lower_pix, r2=higher_pix; trashes rin
\r
11 @ if sh==2, r8=0x00404040 (sh!=0 destroys flags!)
\r
12 .macro convRGB32_2 rin sh=0
\r
13 and r2, lr, \rin, lsr #4 @ blue
\r
15 orr r2, r2, r3, lsl #8 @ g0b0g0b0
\r
17 mov r3, r2, lsl #16 @ g0b00000
\r
18 and \rin,lr, \rin, ror #12 @ 00r000r0 (reversed)
\r
19 orr r3, r3, \rin, lsr #16 @ g0b000r0
\r
21 mov r3, r3, ror #17 @ shadow mode
\r
23 adds r3, r3, #0x40000000 @ green
\r
24 orrcs r3, r3, #0xe0000000
\r
26 adds r3, r3, #0x40000000
\r
27 orrcs r3, r3, #0xe0000000
\r
29 adds r3, r3, #0x40000000
\r
30 orrcs r3, r3, #0xe0000000
\r
32 orr r3, r3, r3, lsr #3
\r
34 mov r3, r3, ror #16 @ r3=low
\r
35 orr r3, r3, r3, lsr #3
\r
41 orr r2, r2, \rin, lsl #16
\r
46 adds r2, r2, #0x40000000 @ blue
\r
47 orrcs r2, r2, #0xe0000000
\r
49 adds r2, r2, #0x40000000
\r
50 orrcs r2, r2, #0xe0000000
\r
52 adds r2, r2, #0x40000000
\r
53 orrcs r2, r2, #0xe0000000
\r
55 orr r2, r2, r2, lsr #3
\r
57 orr r2, r2, r2, lsr #3
\r
64 .global vidConvCpyRGB32 @ void *to, void *from, int pixels
\r
67 stmfd sp!, {r4-r7,lr}
\r
69 mov r12, r2, lsr #3 @ repeats
\r
84 ldmfd sp!, {r4-r7,lr}
\r
88 .global vidConvCpyRGB32sh @ void *to, void *from, int pixels
\r
91 stmfd sp!, {r4-r7,lr}
\r
93 mov r12, r2, lsr #3 @ repeats
\r
108 ldmfd sp!, {r4-r7,lr}
\r
112 .global vidConvCpyRGB32hi @ void *to, void *from, int pixels
\r
115 stmfd sp!, {r4-r7,lr}
\r
117 mov r12, r2, lsr #3 @ repeats
\r
118 mov lr, #0x00e00000
\r
119 orr lr, lr, #0x00e0
\r
131 ldmfd sp!, {r4-r7,lr}
\r
135 @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
\r
137 @ -------- M2 stuff ---------
\r
139 .global vidConvCpy_90 @ void *to, void *from, int width
\r
142 stmfd sp!, {r4-r10,lr}
\r
144 mov lr, #0x00F00000
\r
145 orr lr, lr, #0x00F0
\r
147 mov r12, #224/4 @ row counter
\r
148 mov r10, r2, lsl #2 @ we do 2 pixel wide copies
\r
150 add r8, r0, #256*4 @ parallel line
\r
151 add r1, r1, #0x23000
\r
152 add r1, r1, #0x00B80 @ r1+=328*223*2+8*2
\r
155 mov r4, #0 @ fill bottom border
\r
167 @ at first this loop was written differently: src pixels were fetched with ldm's and
\r
168 @ dest was not sequential. It ran nearly 2 times slower. It seems it is very important
\r
169 @ to do sequential memory access on those items, which we have more (to offload addressing bus?).
\r
171 ldr r4, [r1], #-328*2
\r
172 ldr r5, [r1], #-328*2
\r
173 ldr r6, [r1], #-328*2
\r
174 ldr r7, [r1], #-328*2
\r
186 bne .loopM2RGB32_90
\r
188 mov r4, #0 @ top border
\r
191 stmia r0!, {r4-r6,r12}
\r
192 stmia r0!, {r4-r6,r12}
\r
193 stmia r8!, {r4-r6,r12}
\r
194 stmia r8!, {r4-r6,r12}
\r
197 ldmeqfd sp!, {r4-r10,pc} @ return
\r
199 add r0, r8, #16*4 @ set new dst pointer
\r
201 add r9, r9, #2*2 @ fix src pointer
\r
204 stmia r0!, {r4-r6,r12} @ bottom border
\r
205 stmia r0!, {r4-r6,r12}
\r
206 stmia r8!, {r4-r6,r12}
\r
207 stmia r8!, {r4-r6,r12}
\r
209 mov r12, #224/4 @ restore row counter
\r
214 @ converter for vidConvCpy_270
\r
215 @ lr = 0x00F000F0, out: r3=lower_pix, r2=higher_pix; trashes rin
\r
216 .macro convRGB32_3 rin
\r
217 and r2, lr, \rin, lsr #4 @ blue
\r
219 orr r2, r2, r3, lsl #8 @ g0b0g0b0
\r
221 mov r3, r2, lsl #16 @ g0b00000
\r
222 and \rin,lr, \rin, ror #12 @ 00r000r0 (reversed)
\r
223 orr r3, r3, \rin, lsr #16 @ g0b000r0
\r
225 mov r2, r2, lsr #16
\r
226 orr r2, r2, \rin, lsl #16
\r
229 mov \rin,r3, ror #16 @ r3=low
\r
232 @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
\r
235 @ takes byte-sized pixels from r3-r6, fetches from pal and stores to r7,r8,r10,lr
\r
237 .macro mode2_4pix shift
\r
238 and r7, r11, r3, lsr #\shift
\r
239 ldr r7, [r2, r7, lsl #2]
\r
241 and r8, r11, r4, lsr #\shift
\r
242 ldr r8, [r2, r8, lsl #2]
\r
244 and r10,r11, r5, lsr #\shift
\r
245 ldr r10,[r2, r10,lsl #2]
\r
247 and lr, r11, r6, lsr #\shift
\r
248 ldr lr, [r2, lr, lsl #2]
\r
252 .macro mode2_4pix_getpix0 dreg sreg
\r
253 and \dreg, r11, \sreg
\r
254 ldr \dreg, [r2, \dreg, lsl #2]
\r
257 .macro mode2_4pix_getpix1 dreg sreg
\r
258 and \dreg, r11, \sreg, lsr #8
\r
259 ldr \dreg, [r2, \dreg, lsl #2]
\r
262 .macro mode2_4pix_getpix2 dreg sreg
\r
263 and \dreg, r11, \sreg, lsr #16
\r
264 ldr \dreg, [r2, \dreg, lsl #2]
\r
267 .macro mode2_4pix_getpix3 dreg sreg
\r
268 and \dreg, r11, \sreg, lsr #24
\r
269 ldr \dreg, [r2, \dreg, lsl #2]
\r
272 @ takes byte-sized pixels from reg, fetches from pal and stores to r3-r6
\r
274 .macro mode2_4pix2_0 reg
\r
275 mode2_4pix_getpix0 r3, \reg
\r
276 mode2_4pix_getpix1 r4, \reg
\r
277 mode2_4pix_getpix2 r5, \reg
\r
278 mode2_4pix_getpix3 r6, \reg
\r
282 .macro mode2_4pix2_180 reg
\r
283 mode2_4pix_getpix3 r3, \reg
\r
284 mode2_4pix_getpix2 r4, \reg
\r
285 mode2_4pix_getpix1 r5, \reg
\r
286 mode2_4pix_getpix0 r6, \reg
\r
289 @ takes byte-sized pixels from reg, fetches from pal and stores to r3-r5
\r
290 @ r11=0xFF, r2=pal, r10=0xfcfcfc, r6=tmp
\r
291 .macro mode2_4pix_to3 reg is180
\r
293 mode2_4pix_getpix3 r3, \reg
\r
294 mode2_4pix_getpix2 r4, \reg
\r
296 mode2_4pix_getpix0 r3, \reg @ gathering loads cause a weird-hang
\r
297 mode2_4pix_getpix1 r4, \reg
\r
300 sub r3, r3, r3, lsr #2 @ r3 *= 0.75
\r
301 add r3, r3, r4, lsr #2 @ r3 += r4 * 0.25
\r
305 mode2_4pix_getpix1 r5, \reg
\r
306 mode2_4pix_getpix0 r6, \reg
\r
308 mode2_4pix_getpix2 r5, \reg
\r
309 mode2_4pix_getpix3 r6, \reg
\r
313 add r4, r4, r5, lsr #1 @ r4 = (r4 + r5) / 2;
\r
315 sub r6, r6, r6, lsr #2 @ r6 *= 0.75
\r
316 add r5, r6, r5, lsr #2 @ r5 = r6 + r5 * 0.25
\r
321 @ void *to, void *from, void *pal, int width
\r
322 .macro vidConvCpyM2_landscape is270
\r
323 stmfd sp!, {r4-r11,lr}
\r
327 mov r12, #(224/4-1)<<16 @ row counter
\r
328 orr r12, r12, r3, lsl #1 @ we do 4 pixel wide copies (right to left)
\r
333 add r1, r1, #0x11c00
\r
334 add r1, r1, #0x00308 @ 328*224+8
\r
338 mov r3, #0 @ fill top border
\r
344 add r7, r0, #256*4-8*4
\r
347 add r7, r7, #256*4-8*4
\r
350 add r7, r7, #256*4-8*4
\r
354 0: @ .loopM2RGB32_270:
\r
355 subs r12, r12, #1<<16
\r
363 ldr r3, [r1, #-328]!
\r
364 ldr r4, [r1, #-328]!
\r
365 ldr r5, [r1, #-328]!
\r
366 ldr r6, [r1, #-328]!
\r
374 stmia r0, {r7,r8,r10,lr}
\r
382 stmia r0, {r7,r8,r10,lr}
\r
390 stmia r0, {r7,r8,r10,lr}
\r
398 stmia r0!,{r7,r8,r10,lr}
\r
399 sub r0, r0, #256*4*3
\r
401 bpl 0b @ .loopM2RGB32_270
\r
403 mov r3, #0 @ bottom border
\r
409 add r0, r0, #256*4-8*4
\r
412 add r0, r0, #256*4-8*4
\r
415 add r0, r0, #256*4-8*4
\r
417 nop @ phone crashes if this is commented out. Do I stress it too much?
\r
420 add r12, r12, #1<<16
\r
422 ldmeqfd sp!, {r4-r11,pc} @ return
\r
426 sub r9, r9, #4 @ fix src pointer
\r
432 stmia r0!, {r3-r6} @ top border
\r
434 add r7, r0, #256*4-8*4
\r
437 add r7, r7, #256*4-8*4
\r
440 add r7, r7, #256*4-8*4
\r
444 orr r12, r12, #(224/4-1)<<16 @ restore row counter
\r
445 b 0b @ .loopM2RGB32_270
\r
449 .global vidConvCpy_90 @ void *to, void *from, void *pal, int width
\r
452 vidConvCpyM2_landscape 0
\r
455 .global vidConvCpy_270 @ void *to, void *from, void *pal, int width
\r
458 vidConvCpyM2_landscape 1
\r
461 .global vidConvCpy_center_0 @ void *to, void *from, void *pal
\r
463 vidConvCpy_center_0:
\r
464 stmfd sp!, {r4-r6,r11,lr}
\r
467 add r1, r1, #8 @ not border (centering 32col here)
\r
469 mov r12, #(240/4-1)<<16
\r
474 subs r12, r12, #1<<16
\r
481 adds r12, r12, #1<<16
\r
482 ldmeqfd sp!, {r4-r6,r11,pc} @ return
\r
485 orr r12, #(240/4-1)<<16
\r
489 .global vidConvCpy_center_180 @ void *to, void *from, void *pal
\r
491 vidConvCpy_center_180:
\r
492 stmfd sp!, {r4-r6,r11,lr}
\r
495 add r1, r1, #0x11c00
\r
496 add r1, r1, #0x002B8 @ #328*224-72
\r
498 mov r12, #(240/4-1)<<16
\r
503 subs r12, r12, #1<<16
\r
507 bpl .loopRGB32_c180
\r
510 adds r12, r12, #1<<16
\r
511 ldmeqfd sp!, {r4-r6,r11,pc} @ return
\r
514 orr r12, #(240/4-1)<<16
\r
518 @ note: the following code assumes that (pal[x] & 0x030303) == 0
\r
520 .global vidConvCpy_center2_40c_0 @ void *to, void *from, void *pal, int lines
\r
522 vidConvCpy_center2_40c_0:
\r
523 stmfd sp!, {r4-r6,r10,r11,lr}
\r
527 orr r10, r10, lsl #8
\r
528 orr r10, r10, lsl #8
\r
529 add r1, r1, #8 @ border
\r
531 mov r12, #(240/3-1)<<16
\r
534 .loopRGB32_c2_40c_0:
\r
536 subs r12, r12, #1<<16
\r
538 mode2_4pix_to3 lr, 0
\r
541 bpl .loopRGB32_c2_40c_0
\r
544 adds r12, r12, #1<<16
\r
545 ldmeqfd sp!, {r4-r6,r10,r11,pc} @ return
\r
548 orr r12, #(240/3-1)<<16
\r
549 b .loopRGB32_c2_40c_0
\r
552 .global vidConvCpy_center2_40c_180 @ void *to, void *from, void *pal, int lines
\r
554 vidConvCpy_center2_40c_180:
\r
555 stmfd sp!, {r4-r6,r10,r11,lr}
\r
559 orr r10, r10, lsl #8
\r
560 orr r10, r10, lsl #8
\r
564 @ add r1, r1, #0x11000
\r
565 @ add r1, r1, #0x00f00 @ #328*224
\r
567 mov r12, #(240/3-1)<<16
\r
572 subs r12, r12, #1<<16
\r
574 mode2_4pix_to3 lr, 1
\r
577 bpl .loop_c2_40c_180
\r
580 adds r12, r12, #1<<16
\r
581 ldmeqfd sp!, {r4-r6,r10,r11,pc} @ return
\r
584 orr r12, #(240/3-1)<<16
\r
588 .global vidConvCpy_center2_32c_0 @ void *to, void *from, void *pal, int lines
\r
590 vidConvCpy_center2_32c_0:
\r
591 stmfd sp!, {r4-r11,lr}
\r
594 orr r10, r10, lsl #8
\r
595 orr r10, r10, lsl #8
\r
597 add r1, r1, #8 @ border
\r
599 mov r12, #(240/15-1)<<16
\r
603 ldmia r1!, {r7-r9,lr}
\r
604 subs r12, r12, #1<<16
\r
612 mode2_4pix_to3 lr, 0
\r
617 adds r12, r12, #1<<16
\r
618 ldmeqfd sp!, {r4-r11,pc} @ return
\r
621 orr r12, #(240/15-1)<<16
\r
625 .global vidConvCpy_center2_32c_180 @ void *to, void *from, void *pal, int lines
\r
627 vidConvCpy_center2_32c_180:
\r
628 stmfd sp!, {r4-r11,lr}
\r
631 orr r10, r10, lsl #8
\r
632 orr r10, r10, lsl #8
\r
637 @ add r1, r1, #0x11000
\r
638 @ add r1, r1, #0x00f00 @ #328*224
\r
640 mov r12, #(240/15-1)<<16
\r
644 ldmdb r1!, {r7-r9,lr}
\r
645 subs r12, r12, #1<<16
\r
653 mode2_4pix_to3 r7, 1
\r
655 bpl .loop_c2_32c_180
\r
658 adds r12, r12, #1<<16
\r
659 ldmeqfd sp!, {r4-r11,pc} @ return
\r
662 orr r12, #(240/15-1)<<16
\r
666 @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
\r
669 .global vidClear @ void *to, int lines
\r
674 orr r12, r1, r12, lsl #16
\r
681 subs r12, r12, #1<<16
\r
683 stmia r0!, {r1-r3,lr}
\r
684 stmia r0!, {r1-r3,lr}
\r
685 stmia r0!, {r1-r3,lr}
\r
686 stmia r0!, {r1-r3,lr}
\r
690 adds r12, r12, #1<<16
\r
691 ldmeqfd sp!, {pc} @ return
\r
693 orr r12, #(240/16-1)<<16
\r