bugfixes in cd/Memory.s, poll loop detection
[picodrive.git] / platform / gp2x / asmutils.s
... / ...
CommitLineData
1@ some color conversion and blitting routines\r
2\r
3@ (c) Copyright 2006, notaz\r
4@ All Rights Reserved\r
5\r
6@ vim:filetype=armasm\r
7\r
8@ Convert 0000bbb0 ggg0rrr0 0000bbb0 ggg0rrr0\r
9@ to 00000000 rrr00000 ggg00000 bbb00000 ...\r
10\r
11@ lr = 0x00e000e0, out: r3=lower_pix, r2=higher_pix; trashes rin\r
12@ if sh==2, r8=0x00404040 (sh!=0 destroys flags!)\r
13.macro convRGB32_2 rin sh=0\r
14 and r2, lr, \rin, lsr #4 @ blue\r
15 and r3, \rin, lr\r
16 orr r2, r2, r3, lsl #8 @ g0b0g0b0\r
17\r
18 mov r3, r2, lsl #16 @ g0b00000\r
19 and \rin,lr, \rin, ror #12 @ 00r000r0 (reversed)\r
20 orr r3, r3, \rin, lsr #16 @ g0b000r0\r
21.if \sh == 1\r
22 mov r3, r3, ror #17 @ shadow mode\r
23.elseif \sh == 2\r
24 adds r3, r3, #0x40000000 @ green\r
25 orrcs r3, r3, #0xe0000000\r
26 mov r3, r3, ror #8\r
27 adds r3, r3, #0x40000000\r
28 orrcs r3, r3, #0xe0000000\r
29 mov r3, r3, ror #16\r
30 adds r3, r3, #0x40000000\r
31 orrcs r3, r3, #0xe0000000\r
32 mov r3, r3, ror #24\r
33.else\r
34 mov r3, r3, ror #16 @ r3=low\r
35.endif\r
36\r
37 orr r3, r3, r3, lsr #3\r
38 str r3, [r0], #4\r
39\r
40 mov r2, r2, lsr #16\r
41 orr r2, r2, \rin, lsl #16\r
42.if \sh == 1\r
43 mov r2, r2, lsr #1\r
44.elseif \sh == 2\r
45 mov r2, r2, ror #8\r
46 adds r2, r2, #0x40000000 @ blue\r
47 orrcs r2, r2, #0xe0000000\r
48 mov r2, r2, ror #8\r
49 adds r2, r2, #0x40000000\r
50 orrcs r2, r2, #0xe0000000\r
51 mov r2, r2, ror #8\r
52 adds r2, r2, #0x40000000\r
53 orrcs r2, r2, #0xe0000000\r
54 mov r2, r2, ror #8\r
55.endif\r
56\r
57 orr r2, r2, r2, lsr #3\r
58 str r2, [r0], #4\r
59.endm\r
60\r
61\r
62.global vidConvCpyRGB32 @ void *to, void *from, int pixels\r
63\r
64vidConvCpyRGB32:\r
65 stmfd sp!, {r4-r7,lr}\r
66\r
67 mov r12, r2, lsr #3 @ repeats\r
68 mov lr, #0x00e00000\r
69 orr lr, lr, #0x00e0\r
70\r
71.loopRGB32:\r
72 subs r12, r12, #1\r
73\r
74 ldmia r1!, {r4-r7}\r
75 convRGB32_2 r4\r
76 convRGB32_2 r5\r
77 convRGB32_2 r6\r
78 convRGB32_2 r7\r
79\r
80 bgt .loopRGB32\r
81\r
82 ldmfd sp!, {r4-r7,lr}\r
83 bx lr\r
84\r
85\r
86.global vidConvCpyRGB32sh @ void *to, void *from, int pixels\r
87\r
88vidConvCpyRGB32sh:\r
89 stmfd sp!, {r4-r7,lr}\r
90\r
91 mov r12, r2, lsr #3 @ repeats\r
92 mov lr, #0x00e00000\r
93 orr lr, lr, #0x00e0\r
94\r
95.loopRGB32sh:\r
96 subs r12, r12, #1\r
97\r
98 ldmia r1!, {r4-r7}\r
99 convRGB32_2 r4, 1\r
100 convRGB32_2 r5, 1\r
101 convRGB32_2 r6, 1\r
102 convRGB32_2 r7, 1\r
103\r
104 bgt .loopRGB32sh\r
105\r
106 ldmfd sp!, {r4-r7,lr}\r
107 bx lr\r
108\r
109\r
110.global vidConvCpyRGB32hi @ void *to, void *from, int pixels\r
111\r
112vidConvCpyRGB32hi:\r
113 stmfd sp!, {r4-r7,lr}\r
114\r
115 mov r12, r2, lsr #3 @ repeats\r
116 mov lr, #0x00e00000\r
117 orr lr, lr, #0x00e0\r
118\r
119.loopRGB32hi:\r
120 ldmia r1!, {r4-r7}\r
121 convRGB32_2 r4, 2\r
122 convRGB32_2 r5, 2\r
123 convRGB32_2 r6, 2\r
124 convRGB32_2 r7, 2\r
125\r
126 subs r12, r12, #1\r
127 bgt .loopRGB32hi\r
128\r
129 ldmfd sp!, {r4-r7,lr}\r
130 bx lr\r
131\r
132\r
133@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r
134\r
135\r
136@ mode2 blitter for 40 cols\r
137.global vidCpyM2_40col @ void *dest, void *src\r
138\r
139vidCpyM2_40col:\r
140 stmfd sp!, {r4-r6,lr}\r
141\r
142 mov r12, #224 @ lines\r
143 add r1, r1, #8\r
144\r
145vidCpyM2_40_loop_out:\r
146 mov r6, #10\r
147vidCpyM2_40_loop:\r
148 subs r6, r6, #1\r
149 ldmia r1!, {r2-r5}\r
150 stmia r0!, {r2-r5}\r
151 ldmia r1!, {r2-r5}\r
152 stmia r0!, {r2-r5}\r
153 bne vidCpyM2_40_loop\r
154 subs r12,r12,#1\r
155 add r1, r1, #8\r
156 bne vidCpyM2_40_loop_out\r
157\r
158 ldmfd sp!, {r4-r6,lr}\r
159 bx lr\r
160\r
161\r
162@ mode2 blitter for 32 cols\r
163.global vidCpyM2_32col @ void *dest, void *src\r
164\r
165vidCpyM2_32col:\r
166 stmfd sp!, {r4-r6,lr}\r
167\r
168 mov r12, #224 @ lines\r
169 add r1, r1, #8\r
170 add r0, r0, #32\r
171\r
172vidCpyM2_32_loop_out:\r
173 mov r6, #8\r
174vidCpyM2_32_loop:\r
175 subs r6, r6, #1\r
176 ldmia r1!, {r2-r5}\r
177 stmia r0!, {r2-r5}\r
178 ldmia r1!, {r2-r5}\r
179 stmia r0!, {r2-r5}\r
180 bne vidCpyM2_32_loop\r
181 subs r12,r12,#1\r
182 add r0, r0, #64\r
183 add r1, r1, #8+64\r
184 bne vidCpyM2_32_loop_out\r
185\r
186 ldmfd sp!, {r4-r6,lr}\r
187 bx lr\r
188\r
189\r
190@ mode2 blitter for 32 cols with no borders\r
191.global vidCpyM2_32col_nobord @ void *dest, void *src\r
192\r
193vidCpyM2_32col_nobord:\r
194 stmfd sp!, {r4-r6,lr}\r
195\r
196 mov r12, #224 @ lines\r
197 add r1, r1, #8\r
198 b vidCpyM2_32_loop_out\r
199\r
200\r
201.global spend_cycles @ c\r
202\r
203spend_cycles:\r
204 mov r0, r0, lsr #2 @ 4 cycles/iteration\r
205 sub r0, r0, #2 @ entry/exit/init\r
206.sc_loop:\r
207 subs r0, r0, #1\r
208 bpl .sc_loop\r
209\r
210 bx lr\r
211\r
212\r
213@ test\r
214.global flushcache\r
215\r
216flushcache:\r
217 swi #0x9f0002\r
218 mov pc, lr\r
219\r