-
Notifications
You must be signed in to change notification settings - Fork 0
/
guntner.dasm
419 lines (337 loc) · 9.72 KB
/
guntner.dasm
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
include "nesdefs.dasm"
include "zp_vars.asm"
;;;;; RAM NOTES
; $000 zero page
; $100 6502 stack
; $200 PPU OAM sprite data
; $300 entity data
; $400-7ff sine scale tables
phase_spawn_table = $0150
spare_stack = $170
top_of_stack = $1e0
end_of_ram = $800
sprite_0_y EQM $b6 ; 182
sprite_0_y_diff EQM $4a ; 74
;;;;; NES CARTRIDGE HEADER
NES_HEADER 0,1,1,NES_MIRR_VERT ; mapper 0, 1 PRGs, 1 CHR
;;;;; START OF CODE
cart_start: subroutine
NES_INIT ; set up stack pointer, turn off PPU
; CLEAR CPU RAM
jsr ClearRAM ; clear RAM
jsr WHOOPS
; MY SETUP
; setup rng
lda #$01
sta rng0
sta rng1
lda #$ff
sta rng2
sta dashboard_message
lda #232
sta scroll_y ; just seems right
jsr sine_init
lda #>arctang_velocity_tables
sta arctang_velocity_hi
lda #$c0
sta scroll_to_counter
lda #1
sta game_difficulty
lda #$01
sta player_speed
; set default player colors
lda #$14
sta player_color0
lda #$21
sta player_color1
lda #$37
sta player_color2
jsr player_update_colors
; bookbinder colors
ldx #81
ldy #6
jsr palette_load
;============================== M O D E I N I T H E R E
lda #$0f
sta pal_uni_bg
;jsr game_init
jsr menu_screens_init
;jsr attract_init
;jsr cut_scene_intro_init
;jsr cut_scene_outro_init
;jsr options_screen_init
;jsr sandbox_init
;jsr sandbox2_init
.endless
jmp .endless ; endless loop
;;;;; INTERRUPT HANDLERS
nmi_handler: subroutine
; ~2250 cycles for PPU access (PAL is 7450 cycles)
; "On NTSC, count on being able to copy 160 bytes
; to nametables or the palette using a moderately
; unrolled loop"
; write 64 tiles?
; write all palettes
; oam dma
SAVE_REGS ; 13 cycles
; enable NMI lockout
lda nmi_lockout
cmp #$00
beq .no_lock
jmp .nmi_end
.no_lock
inc nmi_lockout
; PPU vBLANK STUFF
; RENDER va cycles
lda state_render_addr
jmp jump_to_subroutine
state_render_done:
; OAM DMA 513 cycles
lda #$02
sta PPU_OAM_DMA
; PALETTE 236 cycles
jsr palette_render
; SCROLL POS 17 cycles
bit PPU_STATUS
lda scroll_x_hi
sta PPU_SCROLL
lda scroll_y
sta PPU_SCROLL
; NAMETABLE++ 9 cycles
lda scroll_page
and #$01
ora #CTRL_NMI|CTRL_BG_1000
sta PPU_CTRL
lda ppu_mask_emph
eor #MASK_BG|MASK_SPR
sta PPU_MASK
; hope everything above was under
; ~2250 cycles!
; main state logic
lda state_update_addr
jmp jump_to_subroutine
state_update_done:
sprite0_wait:
lda state_sprite0
beq sprite0_off
; wait for Sprite 0; SPRITE 0 WAIT TIME!!!
.wait0 bit PPU_STATUS
bvs .wait0
lda #$c0
.wait1 bit PPU_STATUS
beq .wait1
; HUD POSITIONING
; Horizontal Scroll Solution
bit PPU_STATUS
lda #$00
sta PPU_SCROLL
sta PPU_SCROLL
; Vertical Scroll Solution
;lda #$26
;sta PPU_ADDR
;lda #$c0
;sta PPU_ADDR
;lda #$00
;sta PPU_SCROLL
;sta PPU_SCROLL
; set bg pos to page 2 for dashboard
lda #$01|#CTRL_NMI|CTRL_BG_1000
sta PPU_CTRL
lda ppu_mask_emph
eor #MASK_BG
sta PPU_MASK
; must be game mode
jsr player_bullets_update
jsr starfield_update
; HUD prepare for next draw
; stop updating HUD if game over
lda player_death_flag
bne skip_dash_update
jsr dashboard_update
skip_dash_update:
sprite0_off:
; debug in lifebar space
;lda phase_spawn_counter
;jsr get_char_hi
;sta $109
;lda phase_spawn_counter
;jsr get_char_lo
;sta $10a
;lda phase_kill_counter
;jsr get_char_hi
;sta $10c
;lda phase_kill_counter
;jsr get_char_lo
;sta $10d
jsr song_update
jsr apu_update
jsr player_controls_read
jsr powerup_bomb_update
jsr powerup_mushroom_update
jsr palette_update
inc wtf ; frame counter lo
bne .skip_ftw
inc ftw ; frame counter hi
.skip_ftw
jsr timer_update ; update global time
lda rng0 ; rng updates
jsr NextRandom
sta rng0
lda rng1
jsr PrevRandom
sta rng1
lda rng2
jsr NextRandom
sta rng2
; disable NMI lockout
lda #$00
sta nmi_lockout
.nmi_end
RESTORE_REGS ; 16 cycles
rti
; all includes
include "ppu_lib_and_tables.asm"
;nop ; how much prg space we using?
include "state__handler.asm"
;nop ; how much prg space we using?
include "state_menu_screens.asm"
;nop ; how much prg space we using?
include "state_cutscenes.asm"
;nop ; how much prg space we using?
include "state_attract.asm"
;nop ; how much prg space we using?
include "state_game.asm"
;nop ; how much prg space we using?
sandbox_init
sandbox_update
; include "state_sandbox.asm"
;nop ; how much prg space we using?
;include "state_sandbox2.asm"
;nop ; how much prg space we using?
include "arctang.asm"
;nop ; how much prg space we using?
include "collision_detection.dasm"
;nop ; how much prg space we using?
include "dashboard.asm"
;nop ; how much prg space we using?
include "palette.asm"
;nop ; how much prg space we using?
include "powerups.asm"
;nop ; how much prg space we using?
include "sine.dasm"
;nop ; how much prg space we using?
;include "starfield.dasm"
;nop ; how much prg space we using?
include "starfield_simple.asm"
;nop ; how much prg space we using?
include "timer_global.dasm"
;nop ; how much prg space we using?
include "phase_handler.asm"
;nop ; how much prg space we using?
include "phase_table.asm"
;nop ; how much prg space we using?
include "enemy_handler.dasm"
;nop ; how much prg space we using?
include "enemy_tables.dasm"
;nop ; how much prg space we using?
include "enemy_death.asm"
include "enemy_boss_moufs.asm"
;nop
include "enemy_boss_vamp.asm"
;nop ; how much prg space we using?
include "enemy_boss_scarab.asm"
;nop ; how much prg space we using?
include "enemy_boss_swordtner.asm"
;nop
include "enemy_boss_eyes.asm"
include "enemy_ant.asm"
;nop ; how much prg space we using?
;include "enemy_bat.asm"
;nop ; how much prg space we using?
include "enemy_birb.asm"
;nop ; how much prg space we using?
include "enemy_chomps.asm"
;nop ; how much prg space we using?
include "enemy_dart.asm"
;nop ; how much prg space we using?
include "enemy_dumbface.asm"
;nop
include "enemy_galger.asm"
;nop
include "enemy_ikes_mom.asm"
;nop
include "enemy_lasso.asm"
;nop ; how much prg space we using?
include "enemy_maggs.asm"
;nop ; how much prg space we using?
include "enemy_muya.asm"
;nop
include "enemy_skeet.asm"
;nop ; how much prg space we using
include "enemy_skully.asm"
;nop ; how much prg space we using?
include "enemy_spark.asm"
;nop ; how much prg space we using?
include "enemy_starglasses.asm"
;nop ; how much prg space we using?
include "enemy_throber.asm"
;nop ; how much prg space we using?
include "enemy_uzi.asm"
;nop ; how much prg space we using?
include "enemy_zigzag.asm"
;nop ; how much prg space we using?
include "player_main.dasm"
;nop ; how much prg space we using?
include "player_bullets.dasm"
;nop ; how much prg space we using?
include "player_controls.dasm"
;nop ; how much prg space we using?
include "player_movement.dasm"
;nop ; how much prg space we using?
include "player_demo.asm"
;nop ; how much prg space we using?
include "apu_engine.asm"
;nop ; how much prg space we using?
include "apu_sfx.asm"
;nop ; how much prg space we using?
include "apu_song.asm"
;nop ; how much prg space we using?
;fd13 - bosses have 2 spawn assistants
;fd0c - boss spawn fade from white
;fcd9 - removed score system
;fd4e - conglomerated all jump tables
;fd82 - refactored scarab sprite handlings
;fdc6 - nop's used for size gauges commented out
;fdf5 - all 4 bosses and game play able
;f953 - moar optimized 1197 bytes left! \:U/
;f9ea - optimized enemy code / using arctang more
;fbb8 - all audio done
;fa5d - phase engine and all text and distress alien
;f535 - super secret code / a new song
;f3c0 - gutted superfluous enemy handling code
;f4d9 - gutted fancy starfield/msg feature
;fa82 - 1st level playable
;f7e3 - scarab boss
;f6e3 - ant/lasso/throber/uzi
;f37d - new audio engine and powerup sfx
;f162 - rewrote player movement
;f258 - powerups done except sfx
;f267 - vampire done?
;f14c - with arctang now
;e7be
;e8b6 newnewnew
;ea9f bookmark new
;e666 bookmark old
; LOOKUP TABLES AT TOP OF ROM
org $fe00
include "tables_at_top_of_rom.asm"
lda #13 ; super secret operation
;;;;; CPU VECTORS
seg Vectors ; segment "Vectors"
org $fffa ; start at address $fffa
.word nmi_handler ; $fffa vblank nmi
.word cart_start ; $fffc reset
.word nmi_handler ; $fffe irq / brk
;;;;; GRAPHX
org $010000
incbin "guntner.chr"