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
; Copyright 1996 Acorn Computers Ltd
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
; http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
; routines in this file are responsible for tiling the backdrops of
; windows.
[ windowsprite
; this is a 'signed' division macro
MACRO
$lab DivRemS $ra,$rb,$rc,$tmp
$lab CMP $rb,#0
BLT %FT2
DivRem $ra,$rb,$rc,$tmp
B %FT4
2 RSB $rb,$rb,#0
DivRem $ra,$rb,$rc,$tmp
RSB $rb,$rb,#0
; modulus should be -ve if divisor is -ve
4
MEND
plotsprite_tile1 DCB "tile_1",0,0
plotsprite_tile1_ DCB "tile_1-",0
ALIGN
plotspritebackground
Push "R0-R5,lr"
; first find sprite tile_1, look in window area, then wimp area
LDR R1,plotsprCB
TEQ R1,#0
BEQ %FT2
wsaddr R5,tile_sc_block
wsaddr R4,clipx0
MOV R14,PC
MOV PC,R1
NOP
NOP
Pull "R0-R5,PC"
2
TEQ R0,#1 ; colour 1
SWINE XOS_WriteI+16 ; just clear the area
Pull "R0-R5,PC",NE
LDR R1,[handle,#w_areaCBptr]
CMP R1,#2
BLT %FT3
MOV R0,#24
ORR R0,R0,#256
ADR R2,plotsprite_tile1
SWI XOS_SpriteOp
BVS %FT3
ADRL R14,tile_sc_block ; need to save global tile info as
; a local tile will overwrite this
LDMIA R14!,{R0,R3-R5}
Push "R0,R3-R5"
LDMIA R14,{R0,R3-R5}
Push "R0,R3-R5"
STR R1,thisCBptr
STR R2,spritename
MOV R0,#0
STR R0,lengthflags ; spritename is a pointer
BL cachespritedata
LDR R0,pixtable_at
STR R0,tile_temptab
LDR R0,sprite_log2px
STR R0,tile_log2px
LDR R0,sprite_log2py
STR R0,tile_log2py
LDR R14,needsfactors
TEQ R14,#0
ADRNE R14,factors
Push R3
LDMNEIA R14,{R0-R3}
MOVEQ R0,#0
ADRL R14,tile_sc_block
STMIA R14,{R0-R3}
Pull R3
LDR R1,needsfactors ; needs preserving
Push R1
B %FT6
3
LDR R2,tiling_sprite
CMP R2,#0
BEQ %FT4
LDRGT R1,baseofsprites
BGT %FT5
BLLT findwimptilesprite
LDRVC R1,baseofsprites
BVC %FT5
CLRV
4
SWI XOS_WriteI+16
Pull "R0-R5,PC" ; can't find it? don't bother
5
ADRL R14,tile_sc_block ; need to save global tile info as
; a local tile will overwrite this
LDMIA R14!,{R0,R3-R5}
Push "R0,R3-R5"
LDMIA R14,{R0,R3-R5}
Push "R0,R3-R5"
STR R1,thisCBptr
STR R2,spritename
MOV R0,#0
STR R0,lengthflags ; spritename is a pointer
LDR R0,tile_pixtable
LDR R1,needsfactors ; needs preserving
Push R1
STR R0,tile_temptab
LDR R0,tile_sc_block
STR R0,needsfactors
LDR R3,tile_width
LDR R4,tile_height
6
Push "x0-y1"
LDR R0,tile_log2px
MOV R3,R3, LSL R0
LDR R0,tile_log2py
MOV R4,R4, LSL R0
Push "R3,R4" ; width and height now on stack
LDR y1,[handle,#w_way1]
LDR x0,[handle,#w_wax0]
LDR R0,[handle,#w_scx]
DivRemS x1,R0,R3,R5 ; need to start 1 sprite left/below origin
SUB x0,x0,R0
LDR R0,[handle,#w_scy]
DivRemS x1,R0,R4,R5
LDR R4,[sp,#4]
SUB y1,y1,R0
7
ADR R14,clipx0
LDMIA R14,{R0,y0,x1,R14}
ADD x1,x1,#1 ; boundary condition
SUB y0,y0,#1 ; bc
RSB y0,R4,y0
ADD R14,R14,#1 ; boundary conditions
8
; get y1 within graphics window bounds
CMP y1,R14
SUBGT y1,y1,R4
BGT %BT8
SUB R0,R0,#1 ; boundary conditions
9
; get x0 within bounds
CMP x0,R0
ADDLT x0,x0,R3
BLT %BT9
SUB x0,x0,R3 ; get it back to left of window
MOV R4,y1
10
MOV R3,x0
20
MOV R5,#8
BL tile_putsprite
LDR R5,[sp]
ADD R3,R3,R5
CMP R3,x1
BLT %BT20
LDR R5,[sp,#4]
SUB R4,R4,R5
CMP R4,y0
BGT %BT10
err
ADD SP,SP,#8
err2
Pull "x0-y1"
Pull R0
STR R0,needsfactors
ADRL R14,tile_log2px ; restore global tile info
Pull "R0-R3"
STMIA R14,{R0-R3}
SUB R14,R14,#16
Pull "R0-R3"
STMIA R14,{R0-R3}
Pull "R0-R5,PC"
LTORG
;; Routine to stash tile_1 from wimp area
;; returns R2-> tile_1 or VS
findwimptilesprite ENTRY "R0-R1"
; is tiling disabled by CMOS ?
MOV R0,#161
MOV R1,#&8c
SWI XOS_Byte
TST R2,#128
SETV NE
MOVVS R2,#0
STRVS R2,tiling_sprite
EXIT VS
LDR R14,log2bpp
MOV R0,#1
MOV R14,R0,LSL R14
MOV R0,#0
CMP R14,#9
MOVGT R0,#"6"
CMP R14,#16
MOVGT R0,#"2"
Push "R0" ; now got "2",0 or "6",0 on stack
ADR R2,plotsprite_tile1_
LDMIA R2,{R0-R1}
Push "R0-R1" ; now have "tile_1-?#",0 on stack
CMP R14,#9
ADDLT R0,R14,#"0"
MOVGT R0,#"1"
CMPGT R14,#16
MOVGT R0,#"3"
STRB R0,[sp,#7]
BL findwimpspritefordepth
; try again.
ADRVS R14,plotsprite_tile1
LDMVSIA R14,{R0-R1}
Push "R0-R2",VS ; routine expects 12 bytes
BLVS findwimpspritefordepth
EXIT VS
LDR R1,baseofsprites
STR R1,thisCBptr
STR R2,spritename
MOV R0,#0
STR R0,lengthflags
BL cachespritedata
STR R3,tile_width
STR R4,tile_height
LDR R1,needsfactors
Push "R2-R3"
LDR R2,tile_pixtable
BIC R2,R2,#&80000000 ; incase cache invalidated before mode change
CMP R2,#0
MOVGT R0,#ModHandReason_Free
BLGT XROS_Module
TEQ R1,#0
ADRNE R14,factors
LDMNEIA R14,{R0-R3}
MOVEQ R0,#0
ADRL R14,tile_sc_block
STMIA R14,{R0-R3}
LDR R0,pixtable_at
STR R0,tile_pixtable
MOV R0,#0
STR R0,pixtable_at ; mark as used
LDR R0,sprite_log2px
STR R0,tile_log2px
LDR R0,sprite_log2py
STR R0,tile_log2py
Pull "R2-R3"
CLRV
EXIT
findwimpspritefordepth
; Sprite name to find (tile_1 or tile_1-##) is on stack
Push "lr"
LDR R2,list_at
CMP R2,#0
BNE %FT05
MOV R0,#24
ORR R0,R0,#256
[ SpritePriority
LDR R1,baseofhisprites
|
LDR R1,baseofsprites
]
ADD R2,SP,#4
SWI XOS_SpriteOp
BVC %FT07
MOV R0,#24
ORR R0,R0,#256
[ SpritePriority
LDR R1,baseoflosprites
|
LDR R1,baseofromsprites
]
ADD R2,SP,#4
SWI XOS_SpriteOp
B %FT07
05
; do it the quick way.
ADD R2,SP,#4
STR R2,spritename
BL getspriteaddr
07
MOVVS R2,#0
STR R2,tiling_sprite
Pull "R14"
ADD SP,SP,#12 ; skip name
MOV PC,lr
tile_putsprite
Push "R1-R7,LR"
;
LDR R0,needsfactors
TEQ R0,#0 ; do I need to translate
;
MOVNE R0,#SpriteReason_PutSpriteScaled
ADRNEL R6,tile_sc_block
MOVEQ R0,#SpriteReason_PutSpriteUserCoords
LDRNE R7,tile_temptab ; -> translation table
TSTNE R7,#&80000000
BLNE get_new_pixtable
;
LDR R1,thisCBptr
LDR R2,spritename
ORR R0,R0,#&200
SWI XOS_SpriteOp
SWIVS XOS_WriteI+16
Pull "R1-R7,PC",,^
get_new_pixtable ENTRY "R0-R6"
BIC R7,R7,#&80000000 ; now an address again
MOV R0,#0
STR R0,lengthflags
BL cachespritedata
LDR R0,tile_pixtable
TEQ R0,R7
BNE %FT05
MOV R2,R7
CMP R2,#0
MOVGT R0,#ModHandReason_Free
BLGT XROS_Module
LDR R7,pixtable_at
MOV R6,#0
STR R6,pixtable_at
STR R7,tile_pixtable
STR R7,tile_temptab
EXITS
05
; if tile_temptab and tile_pixtable were different then we must have been
; tiling a window with a custom tile. Can't free it either. However, the
; genereic table is probably stuffed as well.
LDR R7,tile_pixtable
ORR R7,R7,#&80000000
STR R7,tile_pixtable
LDR R7,pixtable_at
STR R7,tile_temptab
EXITS
LTORG
]
END