-
Notifications
You must be signed in to change notification settings - Fork 2
/
music.asm
106 lines (93 loc) · 1.57 KB
/
music.asm
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
.ifndef MUSIC_INC
MUSIC_INC = 1
.include "x16.inc"
.include "ym2151.inc"
.include "globals.asm"
__music_delay: .byte 0
__music_playing: .byte 1
__music_looping: .byte 1
music_bank: .byte GAME_MUSIC_BANK
.macro INC_MUSIC_PTR
clc
lda MUSIC_PTR
adc #2
sta MUSIC_PTR
lda MUSIC_PTR+1
adc #0
sta MUSIC_PTR+1
.endmacro
init_music:
stz __music_delay
lda #<RAM_WIN
sta MUSIC_PTR
lda #>RAM_WIN
sta MUSIC_PTR+1
rts
stop_music:
stz __music_playing
YM_SET_REG YM_KEY_ON, YM_CH_1
YM_SET_REG YM_KEY_ON, YM_CH_2
YM_SET_REG YM_KEY_ON, YM_CH_3
YM_SET_REG YM_KEY_ON, YM_CH_4
YM_SET_REG YM_KEY_ON, YM_CH_5
YM_SET_REG YM_KEY_ON, YM_CH_6
YM_SET_REG YM_KEY_ON, YM_CH_7
YM_SET_REG YM_KEY_ON, YM_CH_8
jsr init_music
rts
stop_music_loop:
stz __music_looping
rts
enable_music_loop:
lda #1
sta __music_looping
rts
start_music:
lda #1
sta __music_playing
rts
music_tick:
lda __music_playing
bne @check_delay
jmp @return
@check_delay:
lda __music_delay
beq @load
dec __music_delay
bra @return
@load:
lda music_bank
sta RAM_BANK
@loop:
ldy #0
lda (MUSIC_PTR),y
iny
cmp #OPM_DELAY_REG
beq @delay
cmp #OPM_DONE_REG
beq @done
bra @write
@delay:
lda (MUSIC_PTR),y
sta __music_delay
INC_MUSIC_PTR
bra @return
@done:
lda __music_looping
bne @reinit
jsr stop_music
bra @return
@reinit:
jsr init_music
bra @return
@write:
bit YM_data
bmi @write
sta YM_reg
lda (MUSIC_PTR),y
sta YM_data
INC_MUSIC_PTR
bra @loop
@return:
rts
.endif