-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmisc.asm
286 lines (245 loc) · 5.41 KB
/
misc.asm
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
*\ :ts=8 bk=0
*
* misc.asm: Helpful stuff.
*
* Leo L. Schwab 9305.20
*/
AREA misc, CODE
ALIGN
****************************************************************************
* resetlinebuf
*
* SYNOPSIS
* resetlinebuf (buf)
* r0
*
* int32 *buf;
*
* DESCRIPTION
* Sets the contents of buf to contain ~0 (all ones). The size of
* buf is assumed to be 40 bytes.
*
EXPORT resetlinebuf
resetlinebuf ROUT
mvn r1, #0
mvn r2, #0
mvn r3, #0
stmia r0!, {r1-r3}
stmia r0!, {r1-r3}
stmia r0!, {r1-r3}
str r1, [r0]
mov pc, lr ; RTS
****************************************************************************
* islinefull
*
* SYNOPSIS
* int islinefull (buf)
* r0
*
* int32 *buf;
*
* DESCRIPTION
* Tests the contents of buf. Returns TRUE if all zero; FALSE
* otherwise.
*
EXPORT islinefull
islinefull ROUT
ldmia r0!, {r1-r3} ; Check for any nonzero contents
orr r1, r1, r2
orrs r1, r1, r3
bne notfull
ldmia r0!, {r1-r3}
orr r1, r1, r2
orrs r1, r1, r3
bne notfull
ldmia r0!, {r1-r3}
orr r1, r1, r2
orrs r1, r1, r3
bne notfull
ldr r1, [r0]
cmp r1, #0
notfull movne r0, #0 ; FALSE if any bits nonzero
moveq r0, #1 ; TRUE if all zero
mov pc, lr ; RTS
****************************************************************************
* testmarklinebuf
*
* SYNOPSIS
* int testmarklinebuf (buf, lx, rx)
* r0 r1 r2
*
* int32 *buf;
* int32 lx, rx;
*
* DESCRIPTION
* Clears the bits in buf from lx to rx, inclusive, while testing them
* to see if any were set in the first place. Returns TRUE if any bits
* in the range were set, FALSE otherwise.
*
EXPORT testmarklinebuf
testmarklinebuf ROUT
stmdb sp, {r4-r6}
mov r6, #0 ; FALSE
;------ Are start and end indicies the same? If so, don't bother.
cmp r1, r2 ; if (lx == rx)
beq exitFALSE ; return (FALSE)
;------ Factor in MapCel() artifact.
;------ If left greater than right, swap values.
sub r2, r2, #1 ; rx--
cmp r1, r2 ; if (lx > rx)
eorgt r1, r1, r2 ; swap (lx, rx)
eorgt r2, r2, r1
eorgt r1, r1, r2
;------ If beyond edges of screen, don't bother.
cmp r1, #320 ; if (lx >= 320 ||
bge exitFALSE
cmp r2, #0 ; rx < 0)
blt exitFALSE ; return (FALSE)
;------ Truncate to edges of screen.
cmp r1, #0 ; if (lx < 0)
movlt r1, #0 ; lx = 0;
cmp r2, #320 ; if (rx >= 320)
movgt r2, #320 ; rx = 319;
subgt r2, r2, #1
;------ Get first and last longword masks.
mov r3, r1 ; lm = leftmasks[lx & 31];
mov r4, r2 ; rm = rightmasks[rx & 31];
and r3, r3, #31
and r4, r4, #31
ldr r5, =leftmasks
ldr r3, [r5, +r3, LSL #2]
ldr r5, =rightmasks
ldr r4, [r5, +r4, LSL #2]
;------ Shift down to get indicies.
mov r1, r1, ASR #5 ; lx >>= 5
mov r2, r2, ASR #5 ; rx >>= 5
cmp r1, r2
bne domany
;------ We begin and end within the same longword. Fold masks
;------ and test relevant longword.
and r3, r3, r4 ; lm &= rm;
ldr r5, [r0, +r1, LSL #2] ; tmp = buf[lx]
tst r5, r3 ; if (tmp & lm)
bicne r5, r5, r3 ; tmp &= ~lm
strne r5, [r0, +r1, LSL #2] ; buf[lx] = tmp
movne r6, #1 ; TRUE
exitFALSE mov r0, r6
ldmdb sp, {r4-r6}
mov pc, lr ; RTS
;------ We span multiple longwords. Scan and clear relevant bits.
domany ldr r5, [r0, +r1, LSL #2] ; tmp = buf[lx]
tst r5, r3 ; if (tmp & lm)
movne r6, #1
bic r5, r5, r3 ; tmp &= ~lm
str r5, [r0, +r1, LSL #2]
mvn r3, #0 ; lm = ~0
maskloop add r1, r1, #1 ; lx++
cmp r1, r2 ; if (lx == rx)
moveq r3, r4 ; lm = rm;
ldr r5, [r0, +r1, LSL #2]
tst r5, r3 ; if (tmp & lm)
movne r6, #1 ; result = TRUE;
bic r5, r5, r3
str r5, [r0, +r1, LSL #2]
cmp r1, r2
blt maskloop ; do { } while (lx < rx)
mov r0, r6
ldmdb sp, {r4-r6}
mov pc, lr ; RTS
;------ Masking data.
leftmasks
DCD &FFFFFFFF
DCD &7FFFFFFF
DCD &3FFFFFFF
DCD &1FFFFFFF
DCD &0FFFFFFF
DCD &07FFFFFF
DCD &03FFFFFF
DCD &01FFFFFF
DCD &00FFFFFF
DCD &007FFFFF
DCD &003FFFFF
DCD &001FFFFF
DCD &000FFFFF
DCD &0007FFFF
DCD &0003FFFF
DCD &0001FFFF
DCD &0000FFFF
DCD &00007FFF
DCD &00003FFF
DCD &00001FFF
DCD &00000FFF
DCD &000007FF
DCD &000003FF
DCD &000001FF
DCD &000000FF
DCD &0000007F
DCD &0000003F
DCD &0000001F
DCD &0000000F
DCD &00000007
DCD &00000003
DCD &00000001
rightmasks
DCD &80000000
DCD &C0000000
DCD &E0000000
DCD &F0000000
DCD &F8000000
DCD &FC000000
DCD &FE000000
DCD &FF000000
DCD &FF800000
DCD &FFC00000
DCD &FFE00000
DCD &FFF00000
DCD &FFF80000
DCD &FFFC0000
DCD &FFFE0000
DCD &FFFF0000
DCD &FFFF8000
DCD &FFFFC000
DCD &FFFFE000
DCD &FFFFF000
DCD &FFFFF800
DCD &FFFFFC00
DCD &FFFFFE00
DCD &FFFFFF00
DCD &FFFFFF80
DCD &FFFFFFC0
DCD &FFFFFFE0
DCD &FFFFFFF0
DCD &FFFFFFF8
DCD &FFFFFFFC
DCD &FFFFFFFE
DCD &FFFFFFFF
****************************************************************************
* mkVertPtrs
*
* SYNOPSIS
* mkVertPtrs (verts, ptrArry, idx0, idx1, idx2, idx3)
* r0 r1 r2 r3 [sp] [sp+4]
*
* Vertex *verts;
* Vertex **ptrArry;
* int32 idx0, idx1, idx2, idx3
*
* DESCRIPTION
* Convert the indicies into pointers to verticies.
*
EXPORT mkVertPtrs
mkVertPtrs ROUT
stmdb sp, {r4-r5}
ldmia sp, {r4, r5}
add r2, r2, r2, LSL #1 ; n *= 3
add r3, r3, r3, LSL #1
add r4, r4, r4, LSL #1
add r5, r5, r5, LSL #1
add r2, r0, r2, LSL #2 ; n = verts + (n * 4)
add r3, r0, r3, LSL #2
add r4, r0, r4, LSL #2
add r5, r0, r5, LSL #2
stmia r1, {r2-r5}
ldmdb sp, {r4-r5}
mov pc, lr ; RTS
END