| 1 |
; |
| 2 |
; In most cases where the SID file is known this might work: |
| 3 |
; |
| 4 |
.comment |
| 5 |
*= $1000 |
| 6 |
music .binary "music.sid", $7e; skip header and load |
| 7 |
|
| 8 |
*= $0801 ; C64 BASIC header |
| 9 |
.word (+), 2021 |
| 10 |
.null $9e, format("%4d", start) |
| 11 |
+ .word 0 |
| 12 |
|
| 13 |
start lda #0 |
| 14 |
jsr music ; initialize |
| 15 |
|
| 16 |
lp bit $d011 |
| 17 |
bpl lp |
| 18 |
- bit $d011 |
| 19 |
bmi - |
| 20 |
jsr music+3 ; call play every frame |
| 21 |
jmp lp |
| 22 |
.endc |
| 23 |
; |
| 24 |
; However SID files can have all sorts of load/init/play addresses |
| 25 |
; and might not always have the same length of header either. |
| 26 |
; |
| 27 |
; So the following function tries to figure these details out. |
| 28 |
|
| 29 |
loadsid .function _data : binary; use binary() for this parameter |
| 30 |
_data_at := _data[[$7,$6]] ; data offset (big endian) |
| 31 |
_load := _data[[$9,$8]] ; load address (big endian) |
| 32 |
_init := _data[[$b,$a]] ; init address (big endian) |
| 33 |
_play := _data[[$d,$c]] ; play address (big endian) |
| 34 |
|
| 35 |
; dump music data after the header (and the optional loading address) |
| 36 |
_sid .text _data[_data_at + (_load != 0 ? 0 : 2):] |
| 37 |
|
| 38 |
; if load address is zero then it's the first 2 bytes of music data |
| 39 |
_sid.load = _load != 0 ? _load : _data[_data_at + [0, 1]] |
| 40 |
_sid.init = _init != 0 ? _init : _load |
| 41 |
_sid.play = _play ; put results into constants |
| 42 |
.endf _sid ; and return them |
| 43 |
|
| 44 |
; There's a lot more information in the header, however that would make |
| 45 |
; this example unnecessary complicated so it's left as an exercise |
| 46 |
; to the reader. |
| 47 |
; |
| 48 |
*= music.load ; set PC to load address |
| 49 |
music #loadsid "music.sid" ; load this file as music |
| 50 |
|
| 51 |
* = $0801 ; C64 BASIC header |
| 52 |
.word (+), 2021 |
| 53 |
.null $9e, format("%4d", start) |
| 54 |
+ .word 0 |
| 55 |
|
| 56 |
start lda #0 |
| 57 |
jsr music.init ; initialize |
| 58 |
|
| 59 |
lp bit $d011 |
| 60 |
bpl lp |
| 61 |
- bit $d011 |
| 62 |
bmi - |
| 63 |
jsr music.play ; call play every frame |
| 64 |
jmp lp |