-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnesPlayer.ah
207 lines (189 loc) · 3.79 KB
/
nesPlayer.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
;;;;;;;;;;;;;;;;
; [definition]
;;;;;;;;;;;;;;;;
@02 :BUTTONWAIT
;;;;;;;;;;;;;;;;
; [zeropage]
;;;;;;;;;;;;;;;;
@C0
1:WALLCLOCK
1:CONTROLLER1 1:BUTTONWAITTO 1:BUTTONSAMPLE 1:BUTTONSTATE0 1:BUTTONSTATE1
|00D0
;;;;;;;;;;;;;;;;
; [memory]
;;;;;;;;;;;;;;;;
@0200
|0800
;;;;;;;;;;;;;;;;
; [const]
;;;;;;;;;;;;;;;;
@E000
256:INITOAMBUFFER
@E100
144:KEYSPY0
64:BGATTRIBUTE
32:MSGKB0
16:HEX2C
@E200
144:KEYSPY1
32:MSGKB1
32:MSGKB2
32:MSGKB3
16:DEC2C1
@E300
144:KEYSPCHAR0
32:MSGLED
32:MSGUNDERLINE
8:MSGTITLE 24:TITLE
16:DEC2C0
@E400
144:KEYSPX
8:MSGARTIST 24:ARTIST
8:MSGVERSION 24:VERSION
8:MSGCOMMENT 24:COMMENT
@E500
32:MSGTUNING
32:MSGTEMPO
32:MSGSONG
20:CPUINITREG
|E580
@E580
64:DIVNOTELO
@E5C0
64:DIVNOTEHI
@E600
128:FX16NOTELO
@E680
128:FX16NOTEMID
@E700
128:FX16NOTEHI
@E780
128:FX32NOTELO
@E800
128:FX32NOTEMID
@E880
128:FX32NOTEHI
@E900
256:STARTBANK
;;;;;;;;;;;;;;;;
; [linked_code]
;;;;;;;;;;;;;;;;
\include ./nesPlayer/graphics.ah
\include ./nesPlayer/sound.ah
;;;;;;;;;;;;;;;;
; [code]
;;;;;;;;;;;;;;;;
:RESETHANDLER {
CALL &STOP
LI $00 ST &PPUCTRL
ST &PPUMASK
BIT &PPUSTATUS
{ :_LOOP BIT &PPUSTATUS BPZ !_LOOP }
ST %WALLCLOCK
ST %BUTTONSTATE0
ST %BUTTONSTATE1
CALL &G_INITMEM
{ :_LOOP BIT &PPUSTATUS BPZ !_LOOP }
CALL &G_INITPPU
{ :_LOOP
LI $01 ST %CONTROLLER1
ST &OUT LSRA ST &OUT
{ :_LOOP
LD &IN1 LSRA RCL %CONTROLLER1
:_CON BCC !_LOOP :_BRK }
{ LD %BUTTONSTATE0 { BNZ !_ELSE
{ LD %BUTTONSTATE1 { BNZ !_ELSE
{ LD %CONTROLLER1 BZE !_ENDIF
ST %BUTTONSAMPLE
LI $80 ST %BUTTONSTATE0
LD %WALLCLOCK CLC ADCI %BUTTONWAIT ST %BUTTONWAITTO
:_ENDIF }
JMP &_ENDIF :_ELSE } LD %BUTTONSTATE1 AND %CONTROLLER1 BNZ !_ENDIF
ST %BUTTONSAMPLE
LI $80 ST %BUTTONSTATE0
LD %WALLCLOCK CLC ADCI %BUTTONWAIT ST %BUTTONWAITTO
:_ENDIF }
JMP &_ENDIF :_ELSE } LD %BUTTONWAITTO CLC SBC %WALLCLOCK { BMI !_ELSE
{ LD %BUTTONSAMPLE { BZE !_ELSE
{ AND %CONTROLLER1 { BZE !_ELSE
ST %BUTTONSAMPLE
JMP &_ENDIF :_ELSE }
ST %BUTTONSTATE0
ST %BUTTONSTATE1
:_ENDIF }
JMP &_ENDIF :_ELSE } LD %BUTTONSTATE1 AND %CONTROLLER1 BZE !_ENDIF
LI $00 ST %BUTTONSTATE0
:_ENDIF }
JMP &_ENDIF :_ELSE }
LD %BUTTONSAMPLE XORI $FF SEC ADCI $00 AND %BUTTONSAMPLE ST %BUTTONSAMPLE
{ CMPI %BTN_RIGHT BNE #3 JMP &_CASE_BTN_RIGHT CMPI %BTN_LEFT BNE #3 JMP &_CASE_BTN_LEFT CMPI %BTN_DOWN BNE #3 JMP &_CASE_BTN_DOWN CMPI %BTN_UP BNE #3 JMP &_CASE_BTN_UP CMPI %BTN_START BNE #3 JMP &_CASE_BTN_START CMPI %BTN_SELECT BNE #3 JMP &_CASE_BTN_SELECT CMPI %BTN_B BNE #3 JMP &_CASE_BTN_B CMPI %BTN_A BNE #3 JMP &_CASE_BTN_A BEQ #3
;default
JMP &_BRK
:_CASE_BTN_RIGHT
{ INC %NEXTSONG LD %NEXTSONG CMPI %SONGS BLO !_ENDIF
LI $00 ST %NEXTSONG
:_ENDIF }
JMP &_BRK
:_CASE_BTN_LEFT
{ LD %NEXTSONG { BZE !_ELSE
DEC %NEXTSONG
JMP &_ENDIF :_ELSE }
LI %SONGS SEC SBCI #1 ST %NEXTSONG
:_ENDIF }
JMP &_BRK
:_CASE_BTN_DOWN
{ LIX $10 :_LOOP BZE !_BRK
{ LD %NEXTSONG { BZE !_ELSE
DEC %NEXTSONG
JMP &_ENDIF :_ELSE }
LI %SONGS SEC SBCI #1 ST %NEXTSONG
:_ENDIF }
:_CON DECX JMP &_LOOP :_BRK }
JMP &_BRK
:_CASE_BTN_UP
{ LIX $10 :_LOOP BZE !_BRK
{ INC %NEXTSONG LD %NEXTSONG CMPI %SONGS BLO !_ENDIF
LI $00 ST %NEXTSONG
:_ENDIF }
:_CON DECX JMP &_LOOP :_BRK }
JMP &_BRK
:_CASE_BTN_START
JMP &_BRK
:_CASE_BTN_SELECT
JMP &_BRK
:_CASE_BTN_B
CALL &STOP
JMP &_BRK
:_CASE_BTN_A
LD %NEXTSONG CALL &INIT
JMP &_BRK
:_BRK }
LI $00 ST %BUTTONSTATE0
LD %BUTTONSAMPLE ST %BUTTONSTATE1
:_ENDIF }
JMP &_LOOP }
}
:NMIHANDLER {
PUSH
TXA PUSH
TYA PUSH
CALL &G_REFRESH
CALL &PLAY
CALL &G_NEXT
INC %WALLCLOCK
POP TAY
POP TAX
POP
RTI }
:IRQHANDLER {
RTI }
;;;;;;;;;;;;;;;;
; [vector]
;;;;;;;;;;;;;;;;
|FFFA
@FFFA
&NMIHANDLER
@FFFC
&RESETHANDLER
@FFFE
&IRQHANDLER