-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathppmck.asm
252 lines (217 loc) · 3.95 KB
/
ppmck.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
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
; .list
.include "define.inc"
.include "effect.h"
MAKE_NES .equ 0
START_SONG .equ 0
.ifndef MAKE_NES
MAKE_NES .equ 0
.endif
.ifndef START_SONG
START_SONG .equ 1
.endif
.if MAKE_NES
; INES header setup
.inesprg 2 ; 16k PRG bank
.ineschr 1 ; 8k CHR bank
.inesmir 0 ; Vertical map mirroring
.inesmap 0 ; Mapper
.endif
;; .bank 0
;; .org $8000
.code
;NSF HEADER
db "NESM",$1A ;
db 1 ;Ver.
db TOTAL_SONGS ;Number of Songs
db START_SONG ;Start Song No.
dw LOAD ;Load
dw INIT ;Init
dw PLAY ;Play
;; .org $800E
TITLE
; db "Title",$0
;; .org $802E
COMPOSER
; db "Composer",$0
;; .org $804E
MAKER
; db "Maker",$0
;; .org $806E
dw 16666 ;1000000 / (freq of NTSC) sec
.if (ALLOW_BANK_SWITCH)
BANKSWITCH_INIT_MACRO
.else
db 0,0,0,0,0,0,0,0 ;Bankswitch Init Values
.endif
dw 20000 ;1000000 / (freq of PAL) sec
db %00
; ||
; |+-------------- PAL/NTSC
; +--------------- dual PAL/NTSC tune or not
; db $02
__VRC6 = %00000001
__VRC7 = %00000010
__FDS = %00000100
__MMC5 = %00001000
__N106 = %00010000
__FME7 = %00100000
db SOUND_GENERATOR
db 0,0,0,0
LOAD:
INIT:
jsr sound_init
rts
PLAY:
jsr sound_driver_start
rts
;-------------------------------------------------------------------------------
.include "ppmck/sounddrv.h"
.include "ppmck/internal.h"
;; .include "ppmck/dpcm.h"
.if SOUND_GENERATOR & __FDS
.include "ppmck/fds.h"
.endif
.if SOUND_GENERATOR & __VRC7
.include "ppmck/vrc7.h"
.endif
.if SOUND_GENERATOR & __VRC6
.include "ppmck/vrc6.h"
.endif
.if SOUND_GENERATOR & __N106
.include "ppmck/n106.h"
.endif
.if SOUND_GENERATOR & __MMC5
.include "ppmck/mmc5.h"
.endif
.if SOUND_GENERATOR & __FME7
.include "ppmck/fme7.h"
.endif
.include "ppmck/freqdata.h"
;-------------------------------------------------------------------------------
.if MAKE_NES
songno = $0100
pad_click = $0101
pad_press = $0102
nmi_flag = $0103 ;$ff when play needed
wantinit = $0104 ;$ff when init
.bank 0
NMI:
bit wantinit
bmi song_init_1
bit nmi_flag
bmi do_rti ; 処理落ち
dec nmi_flag
IRQ:
do_rti:
rti
song_init_1:
ldx #$ff
txs
inx
jmp song_init
RESET: ; このあたりのXレジスタの使い方はQuietustさんの方法を参考にしました
sei
cld
ldx #$00
stx $2000
stx $2001
stx pad_click
stx pad_press
inx
.wv: lda $2002
bpl .wv
dex
bpl .wv
txs ;#$ff
inx ;0
txa
.ram: sta <$0000,x
;sta $0100,x
sta $0200,x
sta $0300,x
sta $0400,x
sta $0500,x
sta $0600,x
sta $0700,x
inx
bne .ram
lda #START_SONG-1
sta songno
song_init:
ldx #$00 ; X = 0 indicates NTSC
stx $2000
stx nmi_flag
stx wantinit
stx $4015
lda songno
jsr INIT
;.wv: lda $2002 ; unneeded?
; bpl .wv
lda #$80 ; PPU NMI on
sta $2000
mainloop:
bit nmi_flag ; wait NMI
bpl mainloop
main_routine:
read_pad: ;NESAudioRipping.TXTを参考にしました
lda pad_press
sta pad_click
ldy #$08
ldx #$01
stx $4016
dex
stx $4016
.nextbit:
lda $4016 ; A B Select Start Up Down Left Right
ror a ; bit0 into C
txa ;
ror a ; C into bit7
tax ; X=A=C<<7|X>>1
dey
bne .nextbit
sta pad_press
eor pad_click ;このあたりはkz-sさんのsnddrv3を参考にしました
and pad_press
sta pad_click ;今押されたボタン
check_pad:
lda pad_click
tax ; X = pad_click
beq .check_pad_end
; Start
; txa
and #$08
bne .set_wantinit
; Left
txa
and #$40
beq .skipLeft
dec songno
bpl .set_wantinit
inc songno
bpl .check_pad_end
.set_wantinit:
dec wantinit
bmi .check_pad_end ;always
; Right
.skipLeft:
txa
and #$80
beq .skipRight
inc songno
lda #TOTAL_SONGS
cmp songno
bne .set_wantinit
dec songno
.skipRight:
.check_pad_end:
jsr PLAY
inc nmi_flag
jmp mainloop
.bank 3
.org $FFFA
dw NMI
dw RESET
dw IRQ
.bank 4
; NROM should have 8KB CHR-ROM
.endif