-
Notifications
You must be signed in to change notification settings - Fork 1
/
CSCROLL.a99
453 lines (428 loc) · 10.9 KB
/
CSCROLL.a99
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
DEF RUNTST
REF VMBW,VWTR
REF VDPWA,VDPWD
REF MAKETX
*
REF MP01HD ; Map Header
*
REF FIXDCL,FIXDCD,FIXDCG ; Colors
REF FIXDPT,FIXDPD,FIXDPG ; Patterns
REF FIXDHD
REF FIXDRW,FIXDRD,FIXDRG ; Screen Image
* A program to test shifting the screen left and right
* This scroll method involves defining grops of 8 characters
* Each character in the group is pixel-shifted by one
* relative to the earlier character.
*
* Use this file together with HSCROLLDAT and FIXEDDAT
* Addresses
USRISR EQU >83C4 Address defining address of interupt routine
*
SPRTBL EQU >1800 Address of Sprite Pattern Table
CLRTBL EQU >380 Address of Color Table
PTNPG1 EQU >800 Address of Character Pattern Table 1
PTNPG2 EQU >1000 Address of Character Pattern Table 2
SCNPG1 EQU >0 Address of Page 1 of the screen image table
SCNPG2 EQU >400 Address of Page 2 of the screen image table
*
* Data used for page flips
*
VDPRG2 DATA >0200 Current value of VDP register 2
ADDRG2 DATA 1 Add this to Reg 2 to flip screen image page
VDPRG4 DATA >0401 Current value of VDP register 4
ADDRG4 EQU ADDRG2 Add this to Reg 4 to flip the patter page
VDPRG5 DATA >0506 Current value of VDP register 5
ADDRG5 DATA >E Add this to Reg 5 to flip sprite attribute page
MAPWD DATA 0 Width of current map
MAPXT DATA 0 Width of current map - >20 (screen width)
* Timer stuff
TIMER DATA >FFFF Decrements once every 349.2 ms.
DATA >FFFC Leftmost 14-bits decrement once every 21.3 microseconds.
MIDTIM DATA >FFFF Decrements once every 1.363 ms.
* Holds the same value as the word at TIMER+1.
*
SCRLTM DATA >FFF0 When MIDTIM <= this value, scroll left or right
WAITTM DATA 500 Amount of time to wait between scrolls (value of 1 ~= 2 ms)
TIMTXT BSS 4 ASCII characters representing timer value
EIGHT BYTE 8
MINSCL BYTE >80 Minimum scrollable character
EVEN
RUNTST
* Initialize Game
BL @INTGAM
* Draw fixed portion of image
BL @DRWFXD
* Initialize Scrollable map
LI R10,MP01HD
BL @INTMAP
* Initialize scroll position data
BL @INTPOS
* Wait to scroll horizontally
WAITLP LIMI 2
LIMI 0
BL @TRCKTM
MOV @MIDTIM,R0
S @SCRLTM,R0
JGT WAITLP
* Set next timer
S @WAITTM,@SCRLTM
* Display timer
MOV @TIMER,R0
LI R1,TIMTXT
BLWP @MAKETX
LI R0,>001A+SCNPG1
LI R1,TIMTXT
LI R2,4
BLWP @VMBW
LI R0,>001A+SCNPG2
BLWP @VMBW
* Update left or right scroll position
BL @SCROLL
* Store map address
LI R10,MP01HD
* If scroll direction > 0 && pixel scroll amount > 1 skip drawing screen image table
* If scroll direction < 0 && pixel scroll amount < 6 skip drawing screen image table
MOV R5,R5
JLT IFLBL1
CI R3,>01FF
JH PATSTP
JMP MAPSTP
IFLBL1 CI R3,>0600
JL PATSTP
* Copy map to VDP with scrolling
MAPSTP LI R0,>60
BL @DRWMAP
* Copy patterns to VDP with scrolling
PATSTP BL @DRWPAT
BL @FLIPPG
* Start over
JMP WAITLP
*
* Initialize game
*
INTGAM
* Define the interupt routine
* LI R0,TIMINT
* MOV R0,@USRISR
* Move Sprite Descriptor Table to >1000
LI R0,>0602
BLWP @VWTR
* Set background color
LI R0,>0701
BLWP @VWTR
* Initialize Timer
CLR R12 CRU base of the TMS9901
SBO 0 Enter timer mode
LI R1,>3FFF Maximum value
INCT R12 Address of bit 1
LDCR R1,14 Load value
DECT R12 There is a faster way (see below)
SBZ 0 Exit clock mode, start decrementer
RT
*
* Draw fixed portion of screen
*
DRWFXD MOV R11,@FXDRT
* Write character patterns for non-scrolling characters
LI R0,PTNPG1
LI R1,FIXDPT
LI R2,FIXDPG
BLWP @VMBW
LI R0,PTNPG2
BLWP @VMBW
* Write color definitions
LI R0,CLRTBL
LI R1,FIXDCL
LI R2,FIXDCG
BLWP @VMBW
* Write non-scrolling characters to both pages
BL @WRSCRN
NEG @ADDRG2
BL @WRSCRN
NEG @ADDRG2
*
MOV @FXDRT,R11
RT
FXDRT DATA 0
* Write non-scrolling characters to screen
WRSCRN
CLR R0
MOV @ADDRG2,@ADDRG2
JLT SCRN0
LI R0,SCNPG2
SCRN0 LI R1,FIXDRW
LI R2,FIXDRG
BLWP @VMBW
RT
*
* Initialize Map
*
* R10 - Address of map header
MAPCOL EQU 0
MAPROW EQU 2
MAPCHR EQU 4
COLORB EQU 6
COLORD EQU 8
COLORG EQU 10
PATRNB EQU 12
PATRND EQU 14
PATRNG EQU 16
TRANSB EQU 18
TRANSD EQU 20
TRANSG EQU 22
SPRITB EQU 24
SPRITD EQU 26
SPRITG EQU 28
SCRENB EQU 30
SCREND EQU 32
SCRENG EQU 34
INTMAP
* Record map width values
MOV *R10,R0
MOV R0,@MAPWD
AI R0,-32
MOV R0,@MAPXT
* Save minimum character
MOV @MAPCHR(10),R0
SWPB R0
MOVB R0,@MINSCL
* Write color definitions
CLR R0
MOVB @MINSCL,R0
SRL R0,11 Find value of minimum scrollable character / 8
AI R0,CLRTBL
MOV @COLORB(10),R1
MOV @COLORG(10),R2
BLWP @VMBW
* Write sprite pattern definitions
* LI R0,SPRTBL
* MOV @SPRITB(10),R1
* MOV @SPRITG(10),R2
* BLWP @VMBW
* Write 16-pixel character patterns
* R0 - Address within transition data
* R1 - End of Transition Data
* R2 - Address within 8-bit pattern data
* R3 - Address within 8-bit pattern data
* R4 - Address within pattern buffer
MOV @TRANSB(10),R0
MOV @TRANSD(10),R1
LI R4,PATBUF
* Set R2 and R3 to (character code in transition data) minus (minimum character code in map)
XPDLP CLR R2
MOVB @MINSCL,R2
NEG R2
MOVB R2,R3
AB *R0+,R2
AB *R0+,R3
* Make R2 and R3 word based.
SRL R2,8
SRL R3,8
* Multiply R2 and R3 by 8. That is, give them offset in pattern data.
SLA R2,3
SLA R3,3
* Set R2 and R3 to positions in pattern data.
A @PATRNB(10),R2
A @PATRNB(10),R3
* Move 16 bytes to the pattern buffer
MOVB *R2+,*R4+
MOVB *R3+,*R4+
MOVB *R2+,*R4+
MOVB *R3+,*R4+
*
MOVB *R2+,*R4+
MOVB *R3+,*R4+
MOVB *R2+,*R4+
MOVB *R3+,*R4+
*
MOVB *R2+,*R4+
MOVB *R3+,*R4+
MOVB *R2+,*R4+
MOVB *R3+,*R4+
*
MOVB *R2+,*R4+
MOVB *R3+,*R4+
MOVB *R2+,*R4+
MOVB *R3+,*R4+
* Loop to copy the next 16-pixel pattern
C R0,R1
JL XPDLP
RT
*
* Initialize Scroll Position values
*
INTPOS
* Store column scroll amount in R6
CLR R6
* Store pixel scroll amount in R3 (left-most byte)
LI R3,>FF00
* Store scroll direction in R4 and R5
* always either positive or negative 1.
LI R4,>0100
LI R5,>0001
RT
*
* Track Time
*
TRCKTM CLR R12
SBO 0 Enter timer mode
STCR R2,15 Read current value (plus mode bit)
SBZ 0
SRL R2,1 Get rid of mode bit
SLA R2,2
C R2,@TIMER+2
JL TRCK1
DEC @TIMER
TRCK1 MOV R2,@TIMER+2
MOVB @TIMER+1,@MIDTIM
MOVB @TIMER+2,@MIDTIM+1
RT
*
* Update scroll positions
*
SCROLL MOV R5,R5
JLT SLEFT
* R4 and R5 are expected to hold +1
SRIGHT AB R4,R3
CB R3,@EIGHT
JL PAINT
CLR R3
A R5,R6
C R6,@MAPXT
JL PAINT
DEC R6
LI R3,>0700
NEG R4
NEG R5
JMP PAINT
* R4 and R5 are expected to hold -1
SLEFT AB R4,R3
JGT PAINT
JEQ PAINT
LI R3,>0700
A R5,R6
JGT PAINT
JEQ PAINT
CLR R6
CLR R3
NEG R4
NEG R5
PAINT RT
*
* Draw the scrollable map
*
* R0 - Screen location to write to
* R3 - Pixel Scroll Amount
* R4 - left-most byte is scroll direction
* R5 - right-most scroll position
* R6 - Column Scroll Amount
* R10 - Address of map header
DRWMAP MOV R11,@DRWRT
BL @INTCHR
* Store end of map in R8
MOV @SCREND(10),R8
* Store position in map in R9
MOV @SCRENB(10),R9
A R6,R9
HSCRL LI R7,>20
HSCRL1 MOVB *R9,R1
AB @MINSCL,R1
MOVB R1,@VDPWD
INC R9
DEC R7
JNE HSCRL1
*
A @MAPXT,R9 Increase R9 to equal address of next row
C R9,R8
JL HSCRL
*
MOV @DRWRT,R11
RT
DRWRT DATA 0
*
* Define patterns for the scrollable map
*
* R3 - Pixel Scroll Amount
* R4 - left-most byte is scroll direction
* R5 - right-most scroll position
* R6 - Column Scroll Amount
* R10 - Address of map header
DRWPAT MOV R11,@DRWRT
* Define starting position for VDP RAM
MOVB @MINSCL,R0
SRL R0,8
BL @INTPAT
* Store position of 16-pixel pattern buffer in R9
LI R9,PATBUF
* Store end of pattern buffer in R8 (length of transition buffer * 8 + PATBUF )
MOV @TRANSG(10),R8
SLA R8,3
A R9,R8
* Copy pixel-shifted character to pattern buffer
MOV R3,R0
SWPB R0
PSCRL MOV *R9+,R1
MOV R0,R0
JEQ PSCRL1
SLA R1,0
PSCRL1 MOVB R1,@VDPWD
C R9,R8
JL PSCRL
*
MOV @DRWRT,R11
RT
*
* Specify the initial screen position to write to.
*
* R0 should already contain a screen position
INTCHR MOV @ADDRG2,@ADDRG2
JLT ITCHR0
AI R0,SCNPG2
ITCHR0 ORI R0,>4000 Set write bit to true
SWPB R0
MOVB R0,@VDPWA
SWPB R0
MOVB R0,@VDPWA
RT
*
* Specify the initial pattern address to write to.
*
* R0 should already contain an ASCII code
INTPAT SLA R0,3
MOV @ADDRG4,@ADDRG4
JLT ITPAT1
AI R0,PTNPG2
JMP ITPAT2
ITPAT1 AI R0,PTNPG1
ITPAT2 ORI R0,>4000 Set write bit to true
SWPB R0
MOVB R0,@VDPWA
SWPB R0
MOVB R0,@VDPWA
RT
*
* Flip Page
*
FLIPPG
* Flip page for screen image table and pattern table
A @ADDRG2,@VDPRG2
A @ADDRG4,@VDPRG4
NEG @ADDRG2
MOV @VDPRG2,R0
BLWP @VWTR
MOV @VDPRG4,R0
BLWP @VWTR
* Flip page for sprite attribute list
* A @ADDRG5,@VDPRG5
* NEG @ADDRG5
* MOV @VDPRG5,R0
* BLWP @VWTR
RT
TIMINT INC @TIMER
RT
TEXT 'SEE 16-PIXEL CHAR HERE'
EVEN
* 16-bit character patterns
PATBUF BSS >1000
PATEND
END