Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Spin until power off
- game_loop:
- jsr play_music_engine
- jmp game_loop
- ; Play song data
- play_music_engine:
- ; If duration lower than 0 load next note and play it
- lda note_duration
- beq load_next_note
- ; If not then lower duration
- lda current_tempo
- beq reset_tempo
- dec current_tempo
- rts
- load_next_note:
- inc note_pointer ; Increment note pointer
- ldx note_pointer ; load note pointer into X
- lda songdata1, X ; load note
- sta note
- inc note_pointer ; Increment note pointer again
- ldx note_pointer ; load note pointer into X
- lda songdata1, X ; load note duration
- sta note_duration
- ; check for special opcodes
- lda note
- cmp #$FD
- beq handle_rest
- cmp #$FE
- beq handle_jump
- cmp #$FF
- beq handle_end
- ; if not special opcode, now sound the note
- jsr lookup_note ; jump to note lookup subroutine
- rts
- handle_rest:
- ldx note ; load note pointer into X
- lda #$00 ; load rest data
- sta $4002; play note
- lda #$00 ; load rest data
- sta $4003; play note
- rts ; go back to playing the note
- handle_jump:
- lda #$00
- sta note_pointer
- lda #$00
- sta current_tempo
- lda #$00
- sta note_duration
- ldx note_pointer ; load note pointer into X
- lda songdata1, X ; load tempo
- rts
- handle_end:
- lda #$01
- sta done_playing
- rts
- handle_done_playing:
- ldx note ; load note pointer into X
- lda #$00 ; load rest data
- sta $4002; play note
- lda #$00 ; load rest data
- sta $4003; play note
- lda #$FF
- sta note_duration
- rts
- lookup_note:
- ldx note ; load note pointer into X
- lda periodTableLo, X ; load actual note
- sta $4002; play note
- lda periodTableHi, X ; load actual note
- sta $4003; play note
- lda done_playing
- cmp #$01
- beq handle_done_playing
- rts ; go back to playing the note
- reset_tempo:
- lda tempo_duration
- sta current_tempo
- dec note_duration
- rts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement