-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnsfDriver.ah
222 lines (195 loc) · 4.36 KB
/
nsfDriver.ah
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
;;;;;;;;;;;;;;;;
; [linked_data]
;;;;;;;;;;;;;;;;
@9900
64:W64NOTELO
64:W64NOTEHI
64:SAWNOTELO
64:SAWNOTEHI
@9A00
64:SQRNOTELO
64:SQRNOTEHI
64:DIVNOTELO
64:DIVNOTEHI
@9B00
128:FMNOTE
128:FMOCT
@9C00
128:FX16NOTELO
128:FX16NOTEMID
@9D00
128:FX16NOTEHI
128:FX32NOTELO
@9E00
128:FX32NOTEMID
128:FX32NOTEHI
@9F00
:STARTBANK
$00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
$00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
$00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
$00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
$00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
$00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
$00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
$00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
$00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
$00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
$00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
$00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
$00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
$00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
$00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
$00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00 $00
;;;;;;;;;;;;;;;;
; [zeropage]
;;;;;;;;;;;;;;;;
@F0
1:APU 1:SONGNUM 1:STATE 1:COUNT 1:TEMPOMUL 1:TEMPODIV 1:RALO 1:RAHI 1:BANK 1:LOOPBANK 1:LOOPRALO 1:LOOPRAHI
|0100
;;;;;;;;;;;;;;;;
; [const]
;;;;;;;;;;;;;;;;
@9004
:FDSINITREG
$80 $00 $00 $C0
$80 $00 $00 $80
|9010
@9014
:CPUINITREG
$30 $00 $00 $07
$30 $00 $00 $07
$00 $00 $00 $00
$30 $00 $00 $00
$0F $40 $40 $00
:MMC5INITREG
$30 $00 $00 $00
$30 $00 $00 $00
|9030
;;;;;;;;;;;;;;;;
; [linked_code]
;;;;;;;;;;;;;;;;
@9031
\include ./nsfDriver/CPU.ah
\include ./nsfDriver/MMC5.ah
\include ./nsfDriver/VRC6.ah
\include ./nsfDriver/FDS.ah
\include ./nsfDriver/S5B.ah
\include ./nsfDriver/VRC7.ah
\include ./nsfDriver/N163.ah
;;;;;;;;;;;;;;;;
; [code]
;;;;;;;;;;;;;;;;
\nsf_:init {
STX %APU
ST %SONGNUM
LIY $00 STY &APUSTATUS
STY &MMC5STATUS
STY &REC5HIPERIOD STY &REC6HIPERIOD
STY &SAWHIPERIOD
LI $03 ST &FDSSTATUS
LI $C0 ST &W64HIFREQ
LI $3F LADX %S5BSTATE STX &S5BADDR ST &S5BDATA
LADX %FX8VOL STX &N163ADDR STY &N163DATA
{ LADX %FM9OCT :_LOOP CPXI %FM1OCT BLT !_BRK
STX &VRC7ADDR STY &VRC7DATA
:_CON DECX JMP &_LOOP :_BRK }
{ LIX $13 :_LOOP BMI !_BRK
LD,X &CPUINITREG ST,X &REC1VOL
:_CON DECX JMP &_LOOP :_BRK }
LI $0F ST &APUSTATUS
LI $C0 ST &APUIRQ
STY &NOISELEN
{ LIX $07 :_LOOP BMI !_BRK
LD,X &MMC5INITREG ST,X &REC3VOL
:_CON DECX JMP &_LOOP :_BRK }
LI $03 ST &MMC5STATUS
STY &VRC6TEST
STY &REC5LOPERIOD STY &REC6LOPERIOD
STY &REC5VOL STY &REC6VOL
STY &SAWLOPERIOD
STY &SAWVOL
STY &W64ENVSPD
{ LIX $07 :_LOOP BMI !_BRK
LD,X &FDSINITREG ST,X &W64VOL
:_CON DECX JMP &_LOOP :_BRK }
ST &W64EN
TYA
{ LIX $3F :_LOOP BMI !_BRK
ST,X &W64WAVE
:_CON DECX JMP &_LOOP :_BRK }
STY &W64EN
{ LIX $1F :_LOOP BMI !_BRK
STY &WMODWAVE
:_CON DECX JMP &_LOOP :_BRK }
{ LADX %SENVWAVE :_LOOP CPXI %SQR1VOL BLT !_BRK
STX &S5BADDR STY &S5BDATA
:_CON DECX JMP &_LOOP :_BRK }
{ DECX :_LOOP BMI !_BRK
STX &S5BADDR STY &S5BDATA
:_CON DECX JMP &_LOOP :_BRK }
{ LADX %FM9FREQ :_LOOP BMI !_BRK
STX &VRC7ADDR STY &VRC7DATA
:_CON DECX JMP &_LOOP :_BRK }
LI $0F
{ LADX %FM9VOL :_LOOP CPXI %FM1VOL BLT !_BRK
STX &VRC7ADDR ST &VRC7DATA
:_CON DECX JMP &_LOOP :_BRK }
LADX %FXWAVEI STX &N163ADDR
{ LIX $7E :_LOOP BMI !_BRK
STY &N163DATA
:_CON DECX JMP &_LOOP :_BRK }
LI #4 ST %COUNT
LI #-1 ST %STATE
LI #1 ST %TEMPOMUL ST %TEMPODIV
LDX %SONGNUM LD,X &STARTBANK
{ BNZ !_ENDIF
STY %STATE
:_ENDIF }
ST %BANK ST &NSFBANK8
LI $FF ST %RALO
LI $7F ST %RAHI
RET }
\nsf_:play {
LD %STATE BNZ #1 RET
{ BPZ !_ENDIF
{ LD %COUNT BZE !_ENDIF
DEC %COUNT
RET
:_ENDIF }
LI $01 ST %STATE
:_ENDIF }
LD %COUNT SEC SBC %TEMPOMUL ST %COUNT BCC #1 RET
ADC %TEMPODIV ST %COUNT
LD %RAHI PUSH
LD %RALO PUSH
RET }
:SETLOOP {
LD %BANK ST %LOOPBANK
POP ST %LOOPRALO
POP ST %LOOPRAHI
PUSH
LD %LOOPRALO PUSH
RET }
:NEXTLOOP {
LD %LOOPBANK ST %BANK ST &NSFBANK8
LD %LOOPRALO ST %RALO
LD %LOOPRAHI ST %RAHI
POP
POP
RET }
:NEXTPAGE {
INC %BANK LD %BANK ST &NSFBANK8
LI $FF ST %RALO
LI $7F ST %RAHI
POP
POP
RET }
:ENDSONG {
LI $00 ST %STATE
}
:ENDROW {
POP ST %RALO
POP ST %RAHI
RET }
|9900