-
Notifications
You must be signed in to change notification settings - Fork 1
/
tms9918_demo.spin2
324 lines (268 loc) · 10.8 KB
/
tms9918_demo.spin2
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
{
TMS9918 Animation Demo
Written by Marco Maccaferri <[email protected]>
Based on Z80 code by J.B. Langston: https://github.com/jblang/TMS9918A.git
Nyan Cat images from Passan Kiskat by Dromedaar Vision: http://www.dromedaar.com/
}
CON
_clkfreq = 160_000_000
cvbs_pin = 32+7*3 addpins 1
vga_pin_base = 8
' color constants
TMSTRANSPARENT = $00
TMSBLACK = $01
TMSMEDGREEN = $02
TMSLIGHTGREEN = $03
TMSDARKBLUE = $04
TMSLIGHTBLUE = $05
TMSDARKRED = $06
TMSCYAN = $07
TMSMEDRED = $08
TMSLIGHTRED = $09
TMSDARKYELLOW = $0A
TMSLIGHTYELLOW = $0B
TMSDARKGREEN = $0C
TMSMAGENTA = $0D
TMSGRAY = $0E
TMSWHITE = $0F
FRAMETICKS = 6 ' number of interrupts per animation frame
FRAMECOUNT = 8 ' number of frames in animation
VAR
byte tms_regs[8]
byte tms_vram[16384]
byte tms_bitmap[256 * 192]
OBJ
tms : "tms9918_cvbs"
'tms : "tms9918_vga"
PUB main()
YDELTA := XDELTA := 1
TICKCOUNTER := FRAMETICKS
CURRFRAME := 0
tms.start(0, @tms_regs, @tms_vram, @tms_bitmap, cvbs_pin) ' NTSC
'tms.start(1, @tms_regs, @tms_vram, @tms_bitmap, cvbs_pin) ' PAL
'tms.start(@tms_regs, @tms_vram, @tms_bitmap, vga_pin_base) ' VGA
repeat
slide()
nyan()
sprite()
PUB nyan() | addr, ri, ra
' initialize registers for multicolor mode
bytemove(@tms_regs, @TMSMCREG, 8)
bytefill(@tms_vram, 0, 16384)
' initialize nametable
addr := $800
ri := 0
repeat 6
repeat ra from ri to ri+31
tms_vram[addr++] := ra
repeat ra from ri to ri+31
tms_vram[addr++] := ra
repeat ra from ri to ri+31
tms_vram[addr++] := ra
repeat ra from ri to ri+31
tms_vram[addr++] := ra
ri += 32
' animation loop
addr := @ANIMATION
repeat 15 * 10
waitatn() ' wait for frame update, adjust for speed
waitatn()
waitatn()
waitatn()
bytemove(@tms_vram + $0000, addr, $600)
addr += $600
if addr >= @ANIMATION_END
addr := @ANIMATION
DAT orgh
' register values for multicolor mode
TMSMCREG
byte %00000000 ' external video disabled
byte %11001000 ' 16KB, display enabled, multicolor mode
byte $02 ' name table at $8000
byte $00 ' color table not used
byte $00 ' pattern table at $0000
byte $76 ' sprite attribute table at $3B00
byte $03 ' sprite pattern table at $1800
byte $04 ' black background
ANIMATION
file "nyan.bin" ' animations, choose one
'file "nyands.bin"
'file "nyanfi.bin"
'file "nyangb.bin"
'file "nyanlb.bin"
'file "nyann1.bin"
'file "nyann2.bin"
'file "nyanus.bin"
'file "nyanxx.bin"
ANIMATION_END
VAR
byte TICKCOUNTER ' interrupt down counter
byte CURRFRAME ' current frame of animation
byte XDELTA ' direction of x axis motion
byte YDELTA ' directino of y axis motion
PUB sprite()
' initialize registers for graphics mode
bytemove(@tms_regs, @TMSBITMAPREG, 8)
bytefill(@tms_vram, 0, 16384)
' upload sprites
bytemove(@tms_vram + $1800, @WORLD0, $200)
'SPRITE1Y := SPRITE2Y := 88
'SPRITE1X := SPRITE2X := 0
'YDELTA := XDELTA := 1
'TICKCOUNTER := FRAMETICKS
'CURRFRAME := 0
' animation loop
repeat 60 * 10
waitatn() ' wait for frame update
SPRITE1X += XDELTA
if SPRITE1X == 240 or SPRITE1X == 0
XDELTA := -XDELTA
SPRITE2X := SPRITE1X
SPRITE1Y += YDELTA
if SPRITE1Y == 176 or SPRITE1Y == 0
YDELTA := -YDELTA
SPRITE2Y := SPRITE1Y
if TICKCOUNTER == 0
SPRITE1NAME := CURRFRAME * 8
SPRITE2NAME := CURRFRAME * 8 + 4
CURRFRAME++
if CURRFRAME >= FRAMECOUNT
CURRFRAME := 0
TICKCOUNTER := FRAMETICKS
bytemove(@tms_vram + $3B00, @SPRITE1Y, 12)
TICKCOUNTER--
DAT orgh
' register values for multicolor mode
TMSBITMAPREG
byte %00000010 ' bitmap mode, no external video
byte %11000010 ' 16KB ram; enable display
byte $0E ' name table at 3800H
byte $0FF ' color table at 2000H
byte $03 ' pattern table at 0000H
byte $76 ' sprite attribute table at 3B00H
byte $03 ' sprite pattern table at 1800H
byte $01 ' black background
' Sprite Attributes
SPRITE1Y byte 88
SPRITE1X byte 0
SPRITE1NAME byte 0
SPRITE1COLOR byte TMSDARKBLUE
SPRITE2Y byte 88
SPRITE2X byte 0
SPRITE2NAME byte 4
SPRITE2COLOR byte TMSLIGHTGREEN
byte $D0, $00, $00, $00 ' end of sprites processing
' planet sprites from TI VDP Programmer's guide
' Sprite world0 pattern 1
WORLD0 byte 007, 028, 056, 112, 120, 092, 014, 015
byte 015, 031, 127, 099, 115, 061, 031, 007
byte 224, 248, 124, 102, 242, 190, 220, 252
byte 248, 160, 192, 192, 226, 244, 248, 224
' Sprite world0 pattern 2
byte 000, 003, 007, 015, 007, 163, 241, 240
byte 240, 224, 128, 028, 012, 002, 000, 000
byte 000, 000, 128, 152, 012, 065, 035, 003
byte 007, 095, 063, 062, 028, 008, 000, 000
' Sprite world1 pattern 1
WORLD1 byte 003, 031, 062, 124, 126, 151, 003, 003
byte 003, 007, 031, 120, 124, 063, 031, 007
byte 224, 056, 028, 024, 060, 047, 183, 255
byte 254, 232, 240, 240, 248, 124, 248, 224
' Sprite world1 pattern 2
byte 000, 000, 001, 003, 001, 104, 252, 252
byte 252, 248, 224, 007, 003, 000, 000, 000
byte 000, 192, 224, 230, 194, 208, 072, 000
byte 001, 023, 015, 014, 006, 128, 000, 000
' Sprite world2 pattern 1
WORLD2 byte 007, 031, 063, 127, 063, 229, 192, 192
byte 128, 001, 007, 030, 063, 063, 031, 007
byte 224, 200, 132, 006, 142, 203, 237, 255
byte 255, 250, 252, 060, 062, 220, 248, 224
' Sprite world2 pattern 2
byte 000, 000, 000, 000, 064, 026, 063, 063
byte 127, 254, 248, 097, 064, 000, 000, 000
byte 000, 048, 120, 248, 112, 052, 018, 000
byte 000, 005, 003, 194, 192, 032, 000, 000
' Sprite world3 pattern 1
WORLD3 byte 007, 031, 063, 031, 079, 249, 112, 240
byte 224, 128, 001, 007, 015, 031, 031, 007
byte 224, 240, 224, 194, 226, 114, 059, 063
byte 063, 126, 255, 142, 206, 244, 248, 224
' Sprite world3 pattern 2
byte 000, 000, 000, 096, 048, 006, 143, 015
byte 031, 127, 254, 120, 112, 032, 000, 000
byte 000, 008, 028, 060, 028, 141, 196, 192
byte 192, 129, 000, 112, 048, 008, 000, 000
' Sprite world4 pattern 1
WORLD4 byte 007, 031, 063, 103, 115, 190, 220, 252
byte 248, 160, 192, 065, 099, 055, 031, 007
byte 224, 248, 248, 240, 248, 092, 014, 015
byte 015, 031, 127, 226, 242, 252, 248, 224
' Sprite world4 pattern 2
byte 000, 000, 000, 024, 012, 065, 035, 003
byte 007, 095, 063, 062, 028, 008, 000, 000
byte 000, 000, 004, 014, 006, 163, 241, 240
byte 240, 224, 128, 028, 012, 000, 000, 000
' Sprite world5 pattern 1
WORLD5 byte 007, 031, 031, 025, 060, 047, 183, 255
byte 254, 232, 240, 112, 120, 061, 031, 007
byte 224, 248, 252, 252, 254, 151, 003, 003
byte 003, 007, 031, 120, 252, 252, 248, 224
' Sprite world5 pattern 2
byte 000, 000, 032, 102, 067, 208, 072, 000
byte 001, 023, 015, 015, 007, 002, 000, 000
byte 000, 000, 000, 002, 000, 104, 252, 252
byte 252, 248, 224, 134, 002, 000, 000, 000
' Sprite world6 pattern 1
WORLD6 byte 007, 015, 007, 006, 015, 203, 237, 255
byte 255, 250, 252, 060, 062, 031, 031, 007
byte 224, 248, 252, 126, 062, 229, 192, 192
byte 128, 001, 007, 030, 062, 124, 248, 224
' Sprite world6 pattern 2
byte 000, 016, 056, 121, 112, 052, 018, 000
byte 000, 005, 003, 067, 065, 032, 000, 000
byte 000, 000, 000, 128, 192, 026, 063, 063
byte 127, 254, 248, 224, 192, 128, 000, 000
' Sprite world7 pattern 1
WORLD7 byte 007, 019, 033, 065, 099, 114, 059, 063
byte 063, 126, 255, 015, 079, 055, 031, 007
byte 224, 248, 252, 158, 206, 249, 112, 240
byte 224, 128, 001, 006, 142, 220, 248, 224
' Sprite world7 pattern 2
byte 000, 012, 030, 062, 028, 141, 196, 192
byte 192, 129, 000, 112, 048, 008, 000, 000
byte 000, 000, 000, 096, 048, 006, 143, 015
byte 031, 127, 254, 248, 112, 032, 000, 000
PUB slide() | regsp, vramp
regsp := @tms9918_regs
vramp := @tms9918_vram
waitatn()
waitatn()
bytemove(@tms_regs, regsp, 8)
bytemove(@tms_vram, vramp, 16384)
regsp += 8
vramp += 16384
waitms(10_000)
waitatn()
waitatn()
bytemove(@tms_regs, regsp, 8)
bytemove(@tms_vram, vramp, 16384)
regsp += 8
vramp += 16384
waitms(10_000)
waitatn()
waitatn()
bytemove(@tms_regs, regsp, 8)
bytemove(@tms_vram, vramp, 16384)
regsp += 8
vramp += 16384
waitms(10_000)
DAT orgh
tms9918_regs
file "tms9918_ascii.regs"
file "tms9918_mandel.regs"
file "tms9918_bombjack.regs"
tms9918_vram
file "tms9918_ascii.vram"
file "tms9918_mandel.vram"
file "tms9918_bombjack.vram"