-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwolfasm.s
440 lines (403 loc) · 7.64 KB
/
wolfasm.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
@ -*- tab-width: 8 -*-
.arch armv5te
.syntax unified
.macro CODE32_FN name
.section .text.\name, "ax", %progbits
.p2align 2
.code 32
.type \name, %function
.global \name
\name:
.endm
CODE32_FN ScaleLineAsm
push {r4-r11,lr}
ldr r5, =vbuf
ldr lr, =bufferPitch
ldr r5, [r5]
ldr lr, [lr]
ldr r6, [sp, #9 * 4] // linecmds
add r0, r5
3: ldrb r10, [r6], #6
ldrb r4, [r6, #-5]
orr r10, r10, r4, lsl #8
lsl r10, #16
asrs r10, #17 // end
beq 9f
ldrb r11, [r6, #-4]
ldrb r4, [r6, #-3]
ldrb r12, [r6, #-2]
ldrb r5, [r6, #-1]
orr r11, r11, r4, lsl #8
orr r12, r12, r5, lsl #8
lsl r11, #16
lsl r12, #16
asr r12, #17
mul r9, r2, r12
add r11, r3, r11, asr #16
// endpix = (frac >> FRACBITS) + toppix
add r8, r1, r9, asr #16
subs r12, r10
bge 3b
ldr r4, =viewheight
add r11, r10
ldr r10, [r4]
2: cmp r8, r10
bge 3b
add r9, r2 // frac += fracstep
bic r7, r8, r8, asr #31
// endpix = (frac >> FRACBITS) + toppix
adds r8, r1, r9, asr #16
bmi 5f
cmp r8, r10
movgt r8, r10
subs r5, r8, r7
ble 5f
mla r7, lr, r7, r0
ldrb r4, [r11, r12]
1: subs r5, #2
strb r4, [r7], lr
strbpl r4, [r7], lr
bhi 1b
5: adds r12, #1
bne 2b
b 3b
9: pop {r4-r11,pc}
CODE32_FN pal_update16_asm
push {r4,lr}
mov r12, #256
sub r1, #256 * 2
1: ldrb r2, [r0, #1]
ldrb r3, [r0, #2]
ldrb r4, [r0], #4
lsr r2, #2
lsr r3, #3
lsr r4, #3
orr r3, r3, r2, lsl #5
orr r3, r3, r4, lsl #11
strh r3, [r1], #2
subs r12, #1
bne 1b
pop {r4,pc}
CODE32_FN pal_update32_asm
push {r4,lr}
mov r12, #256
sub r1, #256 * 4
1: ldrb r2, [r0, #1]
ldrb r3, [r0, #2]
ldrb r4, [r0], #4
lsl r3, #11
orr r3, r3, r2, lsl #1
orr r3, r3, r4, lsl #22
str r3, [r1], #4
subs r12, #1
bne 1b
pop {r4,pc}
CODE32_FN scr_repeat_asm
push {r4-r5,lr}
mov r3, r1
mov r4, r1
mov r5, r1
1: stmia r0!, {r1,r3-r5}
subs r2, #8
bne 1b
pop {r4-r5,pc}
.macro UPDATE_COPY4 r6, r7, r8, r9
and \r6, r12, \r9, lsl #1
and \r7, r12, \r9, lsr #7
and \r8, r12, \r9, lsr #15
and \r9, r12, \r9, lsr #23
ldrh \r6, [r2, \r6]
ldrh \r7, [r2, \r7]
ldrh \r8, [r2, \r8]
ldrh \r9, [r2, \r9]
orr \r6, \r6, \r7, lsl #16
orr \r7, \r8, \r9, lsl #16
.endm
CODE32_FN scr_update_1d1_asm
push {r6-r11,lr}
ldr r12, =0x1fe
1: ldmia r1!, {r9,r11}
UPDATE_COPY4 r6, r7, r8, r9
UPDATE_COPY4 r8, r9, r10, r11
stmia r0!, {r6-r9}
subs r3, #8
bne 1b
pop {r6-r11,pc}
CODE32_FN scr_update_1d2_asm
push {r4-r11,lr}
ldr lr, =0x00400802
ldr r5, =0xf81f07e0
mov r4, #0x3fc
1: sub r3, #320 << 16
2: ldr r11, [r1, #320]
ldr r10, [r1], #4
and r8, r4, r11, lsl #2
and r9, r4, r11, lsr #6
and r6, r4, r10, lsl #2
and r7, r4, r10, lsr #6
ldr r6, [r2, r6]
ldr r7, [r2, r7]
ldr r8, [r2, r8]
ldr r9, [r2, r9]
add r6, r7
add r8, r9
add r6, r8
and r7, lr, r6, lsr #2
add r6, lr
add r6, r7
and r6, r5
and r8, r4, r11, lsr #14
and r9, r4, r11, lsr #22
orr r11, r6, r6, lsl #16
lsr r11, #16
and r6, r4, r10, lsr #14
and r7, r4, r10, lsr #22
ldr r6, [r2, r6]
ldr r7, [r2, r7]
ldr r8, [r2, r8]
ldr r9, [r2, r9]
add r6, r7
add r8, r9
add r6, r8
and r7, lr, r6, lsr #2
add r6, lr
add r6, r7
and r6, r5
orr r6, r6, r6, lsr #16
orr r6, r11, r6, lsl #16
str r6, [r0], #4
adds r3, #4 << 16
bmi 2b
add r1, #320
subs r3, #2
bhi 1b
pop {r4-r11,pc}
.macro READ2X2
mov r4, #0x3fc
ldrh r8, [r1, r12]
ldrh r6, [r1], #2
and r9, r4, r8, lsr #6
and r7, r4, r6, lsr #6
and r6, r4, r6, lsl #2
and r8, r4, r8, lsl #2
ldr r6, [r2, r6]
ldr r7, [r2, r7]
ldr r8, [r2, r8]
ldr r9, [r2, r9]
.endm
.macro SCALE15X_12 r6, r7, lsl, lsr
add r11, \r6, \r7
and r4, r11, lr, lsl #1
add r4, r4, r11, lsl #1
and r11, r10, \r6, lsl #2
orr r11, r11, r11, \lsl #16
and r4, r10
\lsr r11, #16
orr r4, r4, r4, \lsr #16
orr r11, r11, r4, \lsl #16
.endm
CODE32_FN scr_update_3d2_asm
push {r4-r11,lr}
sub r2, #256 * 4
mov r12, #480
ldr lr, =0x00400802
ldr r10, =0xf81f07e0
1: sub r3, #320 << 16
2:
READ2X2
SCALE15X_12 r6, r7, lsl, lsr
str r11, [r0], #4
and r5, r10, r7, lsl #2
orr r5, r5, r5, lsr #16
lsl r5, #16
add r7, r9
add r11, r6, r8
and r4, r11, lr, lsl #1
add r4, r4, r11, lsl #1
and r4, r10
orr r4, r4, r4, lsl #16
add r11, r7
and r6, lr, r11, lsr #2
add r11, r6
add r11, lr
and r11, r10
orr r11, r11, r11, lsr #16
lsl r11, #16
orr r11, r11, r4, lsr #16
str r11, [r0, #480 * 2 - 4]
and r4, r7, lr, lsl #1
add r4, r4, r7, lsl #1
and r4, r10
orr r4, r4, r4, lsl #16
orr r5, r5, r4, lsr #16
SCALE15X_12 r8, r9, lsl, lsr
str r11, [r0, #480 * 4 - 4]
and r4, r10, r9, lsl #2
orr r11, r4, r4, lsl #16
READ2X2
and r4, r10, r8, lsl #2
orr r4, r4, r4, lsr #16
lsl r4, #16
orr r4, r4, r11, lsr #16
str r4, [r0, #480 * 4]
and r4, r10, r6, lsl #2
orr r4, r4, r4, lsr #16
lsl r4, #16
orr r4, r4, r5, lsr #16
str r4, [r0], #4
lsl r5, #16
orr r5, r5, r11, lsr #16
SCALE15X_12 r7, r6, lsr, lsl
str r11, [r0], #4
add r11, r6, r8
and r4, r11, lr, lsl #1
add r4, r4, r11, lsl #1
and r4, r10
orr r4, r4, r4, lsr #16
lsl r4, #16
orr r4, r4, r5, lsr #16
str r4, [r0, #480 * 2 - 8]
add r7, r9
add r11, r7
and r4, lr, r11, lsr #2
add r11, r4
add r11, lr
and r11, r10
orr r11, r11, r11, lsl #16
lsr r11, #16
and r4, r7, lr, lsl #1
add r4, r4, r7, lsl #1
and r4, r10
orr r4, r4, r4, lsr #16
orr r11, r11, r4, lsl #16
str r11, [r0, #480 * 2 - 4]
SCALE15X_12 r9, r8, lsr, lsl
str r11, [r0, #480 * 4 - 4]
adds r3, #4 << 16
bmi 2b
add r1, #480 * 2 - 320
add r0, #480 * 4
subs r3, #2
bhi 1b
pop {r4-r11,pc}
.macro SCALE15X_121 r6, r7
and r11, r10, \r6, lsl #2
add r12, \r6, \r7
and r5, r12, lr, lsl #1
add r5, r5, r12, lsl #1
and r12, r10, \r7, lsl #2
and r5, r10
orr r11, r11, r11, lsr #16
orr r5, r5, r5, lsr #16
orr r12, r12, r12, lsr #16
.endm
CODE32_FN scr_update_25x24d20_asm
push {r4-r11,lr}
sub r2, #256 * 4
ldr lr, =0x00400802
ldr r10, =0xf81f07e0
1:
add r3, #(3 - 1) << 12
4: sub r3, #320 << 16
3: ldr r9, [r1], #4
mov r4, #0x3fc
and r6, r4, r9, lsl #2
and r7, r4, r9, lsr #6
and r8, r4, r9, lsr #14
and r9, r4, r9, lsr #22
ldr r6, [r2, r6]
ldr r7, [r2, r7]
ldr r8, [r2, r8]
ldr r9, [r2, r9]
SCALE15X_121 r7, r8
and r8, r10, r6, lsl #2
and r9, r10, r9, lsl #2
orr r8, r8, r8, lsr #16
orr r9, r9, r9, lsr #16
strh r8, [r0], #10
strh r11, [r0, #-8]
strh r5, [r0, #-6]
strh r12, [r0, #-4]
strh r9, [r0, #-2]
adds r3, #4 << 16
bmi 3b
add r1, #400 - 320
subs r3, #1 << 12
bhi 4b
add r3, #1 << 12
subs r3, #3
bls 9f
sub r3, #320 << 16
2: ldr r8, [r1, #400]
ldr r6, [r1], #4
mov r4, #0x3fc
// left
and r7, r4, r6, lsl #2
and r9, r4, r8, lsl #2
ldr r7, [r2, r7]
ldr r9, [r2, r9]
SCALE15X_121 r7, r9
add r7, r0, #400 * 2
add r9, r0, #400 * 4
strh r11, [r0], #10
strh r5, [r7]
strh r12, [r9]
// right
and r7, r4, r6, lsr #22
and r9, r4, r8, lsr #22
ldr r7, [r2, r7]
ldr r9, [r2, r9]
SCALE15X_121 r7, r9
add r7, r0, #400 * 2
add r9, r0, #400 * 4
strh r11, [r0, #-2]
strh r5, [r7, #-2]
strh r12, [r9, #-2]
and r9, r4, r8, lsr #14
and r7, r4, r6, lsr #14
and r6, r4, r6, lsr #6
and r8, r4, r8, lsr #6
ldr r6, [r2, r6]
ldr r7, [r2, r7]
ldr r8, [r2, r8]
ldr r9, [r2, r9]
// top
SCALE15X_121 r6, r7
strh r11, [r0, #-8]
strh r5, [r0, #-6]
strh r12, [r0, #-4]
add r0, #400 * 2
// center
add r6, r8
add r7, r9
add r5, r6, r7
and r12, lr, r5, lsr #2
add r5, lr
add r5, r12
and r11, r6, lr, lsl #1
and r12, r7, lr, lsl #1
add r6, r11, r6, lsl #1
add r7, r12, r7, lsl #1
and r6, r10
and r5, r10
and r7, r10
orr r6, r6, r6, lsr #16
orr r5, r5, r5, lsr #16
orr r7, r7, r7, lsr #16
strh r6, [r0, #-8]
strh r5, [r0, #-6]
strh r7, [r0, #-4]
add r0, #400 * 2
// bottom
SCALE15X_121 r8, r9
strh r11, [r0, #-8]
strh r5, [r0, #-6]
strh r12, [r0, #-4]
sub r0, #400 * 4
adds r3, #4 << 16
bmi 2b
add r1, #400 * 2 - 320
add r0, #400 * 4
subs r3, #2
bhi 1b
9: pop {r4-r11,pc}