-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeebtrk3.6502
514 lines (382 loc) · 13 KB
/
beebtrk3.6502
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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
\ ******************************************************************
\ * Beeb Tracker
\ * Volume 3 - Sonic the Hedgehog Edition
\ * Music player & visualiser in MODE 7
\ * Kieran Connell & Simon Morris
\ * A Bitshifters Production
\ ******************************************************************
\\ Common global defines
INCLUDE "lib/bbc.h.6502"
\ ******************************************************************
\ * Define compilation flags
\ ******************************************************************
CODE_ORIGIN = &1100 ; assuming standard BBC Micro DFS this is safe!
_DEBUG = FALSE ; include extra stuff for debugging
COMPILE_OPTION_EXIT = FALSE ; enable "Exit" in selection menu
\ ******************************************************************
\ * Define global constants
\ ******************************************************************
\ ******************************************************************
\ * Define app constants
\ ******************************************************************
\\ Number of entries in our file table
NUM_vgm_files = 28
\ ******************************************************************
\ * Define fast (zero page) runtime variables
\ ******************************************************************
\\ Our own app variables
ORG &00
GUARD &9F ; user ZP + econet ZP
\\ Any includes here can declare ZP vars from the pool using SKIP
INCLUDE "lib/exomiser.h.6502"
INCLUDE "lib/vgmplayer.h.6502"
INCLUDE "lib/beebtracker.h.6502"
\ ******************************************************************
\ * Start address to be saved
\ ******************************************************************
LARGEST_VGM_SIZE = 13249 - 266 ; less size of splash screen "loader_volume2.bin.exo"
ORG CODE_ORIGIN ; code origin - assume standard BBC Micro
GUARD MODE7_base_addr-LARGEST_VGM_SIZE ; ensure code size plus size of largest VGM file doesn't hit start of screen memory
.start
\ ******************************************************************
\ * Code entry
\ ******************************************************************
INCLUDE "lib/exomiser.s.6502"
INCLUDE "lib/vgmplayer.s.6502"
INCLUDE "lib/beebtracker.s.6502"
\ ******************************************************************
\ * Main loop including high-level state machine
\ ******************************************************************
.main
{
\\ ***** System initialise ***** \\
\\ *FX 200,3 - clear memory on break as we use OS memory areas and can cause nasty effects
LDA #200
LDX #3
JSR osbyte
JSR clear_vram
\\ Set MODE 1
LDA #22: JSR oswrch
LDA #2: JSR oswrch
\\ Turn off cursor by directly poking crtc
SEI
LDA #10: STA &FE00
LDA #32: STA &FE01
CLI
\\ Present intro screen
JSR show_title
\\ Set MODE 7
LDA #22: JSR oswrch
LDA #7: JSR oswrch
\\ Turn off cursor by directly poking crtc
SEI
LDA #10: STA &FE00
LDA #32: STA &FE01
CLI
\\ Present intro screen
JSR show_intro
\\ Run the tracker demo
JSR tracker_main
\\ ***** Exit app entirely ***** \\
\\ Credits / Outro screen goes here \\
\\ Exit cleanly - tidy up anything else here!
LDA #12: JSR oswrch
\\ Would be nice to clear escape state and issue BASIC NEW to avoid "Bad Program" error
.return
RTS
}
\\ *** Show loading screen ***
.show_intro
{
LDA#&81:LDX#100:LDY#0:JSR osbyte
LDA #19:LDX #0:JSR osbyte
SEI:LDA #6:STA &FE00:LDA #0:STA &FE01:CLI
\\ Initialize compressed data stream
\\ the title screen is an included binary at the VGM_stream_data memory address
\\ (later overwritten by loaded VGMs)
LDX #LO(VGM_stream_data)
LDY #HI(VGM_stream_data)
JSR exo_init_decruncher
\\ unpack to screen
LDX #&00
LDY #&7c
JSR exo_unpack
LDA #19:LDX #0:JSR osbyte
LDA #6:STA &FE00:LDA #25:STA &FE01
\\ wait for keypress within 2 secs
LDA#&81:LDX#200:LDY#0:JSR osbyte
RTS
}
TITLE_LOAD_ADDRESS = &8000 - 3022 ; length of compressed title screen
.show_title
{
\\ conceal vram while we load & unpack
SEI
LDA #6:STA &FE00:LDA #0:STA &FE01
CLI
\\ Set osfile param block
LDA #LO(title_data_filename)
STA osfile_params + 0
LDA #HI(title_data_filename)
STA osfile_params + 1
LDA #LO(TITLE_LOAD_ADDRESS)
STA osfile_params + 2
LDA #HI(TITLE_LOAD_ADDRESS)
STA osfile_params + 3
LDA #0
STA osfile_params + 6
\\ Issue osfile call
LDX #LO(osfile_params)
LDY #HI(osfile_params)
LDA #&FF
JSR osfile
\\ Initialize compressed data stream
LDX #LO(TITLE_LOAD_ADDRESS)
LDY #HI(TITLE_LOAD_ADDRESS)
JSR exo_init_decruncher
\\ unpack to screen
LDX #&00
LDY #&30
JSR fancy_exo_unpack ;exo_unpack
\\ wait for keypress within 5 secs
LDA#&81:LDX#0:LDY#2:JSR osbyte
LDA #19:LDX #0:JSR osbyte
LDA #6:STA &FE00:LDA #0:STA &FE01
JSR clear_vram
RTS
}
; -------------------------------------------------------------------
.fancy_exo_unpack
{
STX write_chr+1
STY write_chr+2
LDA #0:STA linereveal
.next_chr
INC bytecounter+0
BNE skiphi
INC bytecounter+1
.skiphi
LDA bytecounter+1
CMP #HI(640)
BNE notyet
LDA bytecounter+0
CMP #LO(640)
BNE notyet
INC linereveal
LDA #19:JSR osbyte
LDA #6:STA &FE00:LDA linereveal:STA &FE01
LDA #0:STA bytecounter:STA bytecounter+1
.notyet
JSR exo_get_decrunched_byte
BCS all_done
.write_chr STA &ffff ; **SELF-MODIFIED**
INC write_chr+1
BNE next_chr
INC write_chr+2
BNE next_chr
.all_done
LDA #6:STA &FE00:LDA #32:STA &FE01
RTS
.linereveal EQUB 0
.bytecounter EQUW 0
}
\\ reset all memory from &3000 to &8000 to zero
\\ hides unsightly mode switches
.clear_vram
{
sei
lda #&30
sta loop2+2
lda #0
ldy #&50
.loop
ldx #0
.loop2
sta &3000,x
inx
bne loop2
inc loop2+2
dey
bne loop
cli
rts
}
.code_end
\ ******************************************************************
\ * Stored data
\ ******************************************************************
.data_start
.menu_data_filename EQUS "BeebDat", 13
.title_data_filename EQUS "Title", 13
\\ Need to put this macro last as I don't know how to undo the character map!
\\
SET_TELETEXT_FONT_CHAR_MAP
\\ Scrolltext messages stored as font glyph byte offsets
.scrolltext_start
.demo_message
EQUS " Welcome to the Bitshifters Sonic The Hedgehog and Sonic Chaos BeebTracker Demo... 28 awesome VGM chiptune music files ported from Sega Master System to your BBC"
EQUS " Micro. Released at the RISC OS London Show on 29 October 2016. Big hellos to jbnbeeb.. Tricky.. and lazarusr.. representing the ABug Collective at the show! Press Escape"
EQUS " to bring up the menu. Use the up and down arrow keys and return to select a new track. They have been retuned to 4Mhz and resampled at 50Hz so can be played back on your"
EQUS " SN76489 sound chip. This production was brought to you by Kieran and Henley. Find the full source to this demo and more at bitshifters.github.io. Enjoy the soundtrack! "
EQUB 0
.load_message
EQUS "Loading... ", 0
\\ ** ANY EQUS LINES AFTER THIS POINT WILL STILL CONTAIN REMAPPED CHARACTERS ** \\
.scrolltext_end
\\ Clear character mappings
RESET_MAPCHAR
\ ******************************************************************
\ * EXO VGM data file
\ * This must be compressed using the following flags:
\ * exomizer.exe raw -c -m 1024 <file.raw> -o <file.exo>
\ ******************************************************************
.VGM_stream_data
INCBIN "data/loader_volume3.bin.exo"
\ ******************************************************************
\ * End address to be saved
\ ******************************************************************
.end
ORG &0900
GUARD &0D00
.menu_data_start
\\ No longer require loading_table but each entry must be exactly 4 bytes
\\ Does not have to be aligned but entries have to be fixed size
\\ This isn't actually any smaller than using pointer tables but fewer things to type I suppose :)
\\ V.B is an invalid filename for some reason with BeebASM
.vgm_filenames
EQUS "V.0", 13
EQUS "V.2", 13
EQUS "V.3", 13
EQUS "V.4", 13
EQUS "V.6", 13
EQUS "V.7", 13
EQUS "V.8", 13
EQUS "V.9", 13
EQUS "V.C", 13
EQUS "V.D", 13
EQUS "V.E", 13
EQUS "V.F", 13
EQUS "V.G", 13
EQUS "V.H", 13
EQUS "C.0", 13
EQUS "C.1", 13
EQUS "C.2", 13
EQUS "C.3", 13
EQUS "C.4", 13
EQUS "C.5", 13
EQUS "C.6", 13
EQUS "C.7", 13
EQUS "C.8", 13
EQUS "C.9", 13
EQUS "C.A", 13
EQUS "C.C", 13
EQUS "C.D", 13
EQUS "C.E", 13
\\ No longer require pointer table but each entry must be exactly 32 bytes
\\ Does not have to be aligned but entries have to be fixed size
\\ Code to multiple by 32 probably takes up as much space as the previous pointer tables!
.menu_entries
EQUS " 1. Title Screen "
EQUS " 3. Green Hill Zone "
EQUS " 4. Invincible "
EQUS " 5. Bridge Zone "
EQUS " 7. Jungle Zone "
EQUS " 8. Bonus Zone "
EQUS " 9. Labyrinth Zone "
EQUS "10. Act Complete "
EQUS "11. Scrap Brain Zone "
EQUS "12. Sky Base Zone "
EQUS "13. Boss Theme "
EQUS "14. Death "
EQUS "15. Ending "
EQUS "16. Marble Zone (Bonus) "
EQUS "17. Sonic Chaos Intro "
EQUS "18. Sonic Chaos Title Screen "
EQUS "19. Sonic Chaos Select Player "
EQUS "20. Sonic Chaos Turquoise Hill "
EQUS "21. Sonic Chaos Boss "
EQUS "22. Sonic Chaos Gigalopolis Zone"
EQUS "23. Sonic Chaos Sleeping Egg Zn "
EQUS "24. Sonic Chaos Special Stage "
EQUS "25. Sonic Chaos Mecha Green Hill"
EQUS "26. Sonic Chaos Aqua Planet Zone"
EQUS "27. Sonic Chaos Special Stage 2 "
EQUS "28. Sonic Chaos Electric Egg Zn "
EQUS "29. Sonic Chaos Final Boss "
EQUS "30. Sonic Chaos Ending "
IF COMPILE_OPTION_EXIT
EQUS "Exit "
ENDIF
.menu_entries_end
.menu_data_end
\ ******************************************************************
\ * Print out code & data metrics
\ ******************************************************************
D_MENU_SIZE = menu_data_end-menu_data_start
D_LOOKUP_SIZE = lookup_tables_end-lookup_tables_start
D_NOTES_SIZE = note_tables_end-note_tables_start
D_SCROLLTEXT_SIZE = scrolltext_end-scrolltext_start
D_SCREENS_SIZE = mode7_data_end-mode7_data_start
D_EXO_CODE_SIZE = exo_end-exo_start
D_VGM_PLAYER_CODE_SIZE = vgm_player_end-vgm_player_start
D_MENU_ENTRIES_SIZE = menu_entries_end-menu_entries
PRINT "------------------------------------------------------------"
PRINT "Code origin = ", ~CODE_ORIGIN
PRINT "Code size =", end-start-D_MENU_SIZE-D_LOOKUP_SIZE-D_NOTES_SIZE-D_SCROLLTEXT_SIZE-D_SCREENS_SIZE
PRINT " menu data size =",D_MENU_SIZE
PRINT " menu entries size =",D_MENU_ENTRIES_SIZE
PRINT " lookup tables size =",D_LOOKUP_SIZE
PRINT " note tables size =",D_NOTES_SIZE
PRINT " scrolltext size =",D_SCROLLTEXT_SIZE
PRINT " MODE 7 screen size =", D_SCREENS_SIZE
PRINT " VGM Player code size = ", D_VGM_PLAYER_CODE_SIZE
PRINT " EXO code size = ", D_EXO_CODE_SIZE
PRINT "Run-time vars (above origin) =", VGM_stream_data-end
PRINT "------------------------------------------------------------"
PRINT "Total size (disk) =", end-start
PRINT "Total size (code + data + vars above origin) =", VGM_stream_data-start
PRINT "Available memory (above origin) =", &7C00 - CODE_ORIGIN
PRINT "Max song size =", &7C00 - VGM_stream_data
PRINT "------------------------------------------------------------"
\ ******************************************************************
\ * Save the code
\ ******************************************************************
SAVE "!Boot", start, end, main
SAVE "BeebDat", menu_data_start, menu_data_end
PUTFILE "vgm_sonic/sonic1.raw.exo", "V.0", 0
PUTFILE "vgm_sonic/sonic3.raw.exo", "V.2", 0
PUTFILE "vgm_sonic/sonic4.raw.exo", "V.3", 0
PUTFILE "vgm_sonic/sonic5.raw.exo", "V.4", 0
PUTFILE "vgm_sonic/sonic7.raw.exo", "V.6", 0
PUTFILE "vgm_sonic/sonic8.raw.exo", "V.7", 0
PUTFILE "vgm_sonic/sonic9.raw.exo", "V.8", 0
PUTFILE "vgm_sonic/sonic10.raw.exo", "V.9", 0
PUTFILE "vgm_sonic/sonic11.raw.exo", "V.C", 0
PUTFILE "vgm_sonic/sonic12.raw.exo", "V.D", 0
PUTFILE "vgm_sonic/sonic13.raw.exo", "V.E", 0
PUTFILE "vgm_sonic/sonic14.raw.exo", "V.F", 0
PUTFILE "vgm_sonic/sonic15.raw.exo", "V.G", 0
PUTFILE "vgm_sonic/sonic16.raw.exo", "V.H", 0
PUTFILE "vgm_sonic/chaos1.raw.exo", "C.0", 0
PUTFILE "vgm_sonic/chaos3.raw.exo", "C.1", 0
PUTFILE "vgm_sonic/chaos4.raw.exo", "C.2", 0
PUTFILE "vgm_sonic/chaos7.raw.exo", "C.3", 0
PUTFILE "vgm_sonic/chaos10.raw.exo", "C.4", 0
PUTFILE "vgm_sonic/chaos12.raw.exo", "C.5", 0
PUTFILE "vgm_sonic/chaos14.raw.exo", "C.6", 0
PUTFILE "vgm_sonic/chaos16.raw.exo", "C.7", 0
PUTFILE "vgm_sonic/chaos19.raw.exo", "C.8", 0
PUTFILE "vgm_sonic/chaos20.raw.exo", "C.9", 0
PUTFILE "vgm_sonic/chaos22.raw.exo", "C.A", 0
PUTFILE "vgm_sonic/chaos23.raw.exo", "C.C", 0
PUTFILE "vgm_sonic/chaos24.raw.exo", "C.D", 0
PUTFILE "vgm_sonic/chaos25.raw.exo", "C.E", 0
PUTFILE "data/sonic.bin.exo", "Title", 0
; No room for readme!
;PUTFILE "beebtrk3.md", "README", 0
IF _DEBUG ; only needed for debug purposes
PUTFILE "data/screen3.mode7", "screen", &7C00
PUTFILE "data/font_5x5.mode7", "font", &7C00
PUTFILE "data/font_5x5_shifted.mode7", "font2", &7C00
PUTFILE "data/menu_overlay.mode7", "menu", &7C00
ENDIF