-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathnestest.mfk
261 lines (235 loc) · 8.51 KB
/
nestest.mfk
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
253
254
255
256
257
258
259
260
261
// Based upon the example code from NES 101 tutorial by Michael Martin
// compile with -t nes_small
import nes_joy1_default
volatile byte initialized
void main() {
init_graphics()
init_input()
init_sound()
ppu_ctrl = %10001000
ppu_mask = %00011110
initialized = 1
while(true){}
}
void nmi() {
if initialized != 1 { return }
scroll_screen()
update_sprite()
react_to_input()
}
void irq() {
}
array oam_buffer [256] @$200
byte scroll
byte a // debouncing
sbyte dx
void init_graphics() {
init_sprites()
load_palette()
load_name_tables()
init_scrolling()
}
void init_input() {
a = 0
}
void init_sound() {
apu_status = 1
apu_pulse1_sweep = 0
apu_frame_counter = $40
}
void init_sprites() {
byte i
for i,255,downto,0 {
oam_buffer[i] = 0
}
oam_buffer[0] = $70
oam_buffer[1] = 1
oam_buffer[3] = 1
dx = 1
}
void load_palette() {
byte i
ppu_set_addr($3f00)
for i,0,until,palette.length {
ppu_write_data(palette[i])
}
}
void load_name_tables() {
pointer p
byte page_count
byte b
read_ppu_status()
p = bg.addr
ppu_set_addr($2400)
for page_count,0,until,4 {
for b,0,to,255 {
ppu_write_data(p[b])
}
p.hi += 1
}
for page_count,0,until,4 {
for b,0,to,255 {
ppu_write_data(0)
}
}
}
void init_scrolling() {
scroll = 240
}
void update_sprite() {
ppu_oam_dma_write(oam_buffer.addr.hi)
if oam_buffer[3] == 0 {
dx = 1
high_c()
} else if oam_buffer[3] == 255-8 {
dx = -1
high_c()
}
oam_buffer[3] += dx
}
void react_to_input() {
read_joy()
if input_a != 0 { // A button
if a == 0 {
reverse_dx()
}
}
a = input_a
if input_dy < 0 { // Up button
if oam_buffer[0] > 7 { oam_buffer[0] -= 1}
}
if input_dy > 0 { // Down button
if oam_buffer[0] < 223 { oam_buffer[0] += 1}
}
}
void reverse_dx() {
dx = 0 - dx
low_c()
}
void low_c() {
apu_pulse1_ctrl = $84
apu_pulse1_period = $9AA
}
void high_c() {
apu_pulse1_ctrl = $86
apu_pulse1_period = $869
}
void scroll_screen() {
ppu_write_data(0)
if scroll != 0 {
scroll -= 1
ppu_set_scroll(0, scroll)
}
}
const array bg = [
" " ascii,
"12345678901234567890123456789012" ascii,
" " ascii,
" " ascii,
" PRESENTING NES 101 " ascii,
" A GUIDE FOR OTHERWISE " ascii,
" EXPERIENCED PROGRAMMERS " ascii,
" " ascii,
" TUTORIAL FILE BY " ascii,
" MICHAEL MARTIN " ascii,
" " ascii,
" " ascii,
" " ascii,
" PRESS UP AND DOWN TO SHIFT " ascii,
" THE SPRITE " ascii,
" " ascii,
" PRESS A TO REVERSE DIRECTION" ascii,
" " ascii,
" " ascii,
" " ascii,
" " ascii,
" " ascii,
" " ascii,
"CHARACTER SET HIJACKED FROM " ascii,
"COMMODORE BUSINESS MACHINES " ascii,
" (C64'S CHARACTER ROM)" ascii,
" " ascii,
"READY. " ascii,
" " ascii,
" " ascii,
$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,$F0,$F0,$F0,$F0,$F0,$F0,$F0,$F0,
$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F
]
const array palette = [
$0E,$00,$0E,$19,$00,$00,$00,$00,$00,$00,$00,$00,$01,$00,$01,$21,
$0E,$20,$22,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
]
segment(chrrom)
const array charset @$0200 = [
$00,$00,$00,$00,$00,$00,$00,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$18,$18,$18,$18,$00,$00,$18,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$66,$66,$66,$00,$00,$00,$00,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$66,$66,$FF,$66,$FF,$66,$66,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$18,$3E,$60,$3C,$06,$7C,$18,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$62,$66,$0C,$18,$30,$66,$46,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$3C,$66,$3C,$38,$67,$66,$3F,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$06,$0C,$18,$00,$00,$00,$00,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$0C,$18,$30,$30,$30,$18,$0C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$30,$18,$0C,$0C,$0C,$18,$30,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$00,$66,$3C,$FF,$3C,$66,$00,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$00,$18,$18,$7E,$18,$18,$00,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$00,$00,$00,$00,$00,$18,$18,$30,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$00,$00,$00,$7E,$00,$00,$00,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$00,$00,$00,$00,$00,$18,$18,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$00,$03,$06,$0C,$18,$30,$60,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$3C,$66,$6E,$76,$66,$66,$3C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$18,$18,$38,$18,$18,$18,$7E,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$3C,$66,$06,$0C,$30,$60,$7E,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$3C,$66,$06,$1C,$06,$66,$3C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$06,$0E,$1E,$66,$7F,$06,$06,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$7E,$60,$7C,$06,$06,$66,$3C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$3C,$66,$60,$7C,$66,$66,$3C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$7E,$66,$0C,$18,$18,$18,$18,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$3C,$66,$66,$3C,$66,$66,$3C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$3C,$66,$66,$3E,$06,$66,$3C,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$00,$00,$18,$00,$00,$18,$00,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$00,$00,$18,$00,$00,$18,$18,$30,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$0E,$18,$30,$60,$30,$18,$0E,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,
$00,$00,$7E,$00,$7E,$00,$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FF,$FF
]
segment(chrrom)
const array sprites @$1000 = [
$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,
$18,$24,$66,$99,$99,$66,$24,$18,$00,$18,$18,$66,$66,$18,$18,$00
]