add assembly files

This commit is contained in:
Safyrus 2022-02-03 21:11:55 +01:00
parent 1f52d53afb
commit 52c5ce0de1
10 changed files with 923 additions and 0 deletions

View File

@ -0,0 +1,109 @@
;----------------------------------------
; FamiStudio Sound Engine configuration
;----------------------------------------
;----------------------------------------
; You don't need to edit this
;----------------------------------------
FAMISTUDIO_CFG_EXTERNAL=1
.ifdef C_CODE
FAMISTUDIO_CFG_C_BINDINGS = 1
.endif
;----------------------------------------
; Segments Configuration (You don't need to edit this too)
;----------------------------------------
.define FAMISTUDIO_CA65_ZP_SEGMENT ZEROPAGE
.define FAMISTUDIO_CA65_RAM_SEGMENT BSS
.define FAMISTUDIO_CA65_CODE_SEGMENT CODE
;----------------------------------------
; Audio Expansions (ONLY 0 OR 1 MUST BE ENABLE)
;----------------------------------------
; Konami VRC6 (2 extra square + saw)
FAMISTUDIO_EXP_VRC6 = 0
; Konami VRC7 (6 FM channels)
FAMISTUDIO_EXP_VRC7 = 0
; Nintendo MMC5 (2 extra squares, extra DPCM not supported)
FAMISTUDIO_EXP_MMC5 = 0
; Sunsoft S5B (2 extra squares, advanced features not supported.)
FAMISTUDIO_EXP_S5B = 0
; Famicom Disk System (extra wavetable channel)
FAMISTUDIO_EXP_FDS = 0
; Namco 163 (between 1 and 8 extra wavetable channels) + number of channels.
FAMISTUDIO_EXP_N163 = 0
FAMISTUDIO_EXP_N163_CHN_CNT = 4
;----------------------------------------
; Global Engine Configuration
;----------------------------------------
; One of these MUST be defined (PAL or NTSC playback).
; Note that only NTSC support is supported when using any of the audio expansions.
FAMISTUDIO_CFG_PAL_SUPPORT = 0
FAMISTUDIO_CFG_NTSC_SUPPORT = 1
; Support for sound effects playback + number of SFX that can play at once.
FAMISTUDIO_CFG_SFX_SUPPORT = 1
FAMISTUDIO_CFG_SFX_STREAMS = 2
; Blaarg's smooth vibrato technique. Eliminates phase resets ("pops") on
; square channels.
FAMISTUDIO_CFG_SMOOTH_VIBRATO = 0
; Enables DPCM playback support.
FAMISTUDIO_CFG_DPCM_SUPPORT = 1
; Must be enabled if you are calling sound effects from a different
; thread than the sound engine update.
FAMISTUDIO_CFG_THREAD = 1
;----------------------------------------
; Supported Features Configuration
;----------------------------------------
; Must be enabled if the songs you will be importing have been created using FamiTracker tempo mode.
; If you are using FamiStudio tempo mode, this must be undefined. You cannot mix and match tempo modes,
; the engine can only run in one mode or the other.
; More information at: https://famistudio.org/doc/song/#tempo-modes
; FAMISTUDIO_USE_FAMITRACKER_TEMPO = 1
; Must be enabled if the songs uses delayed notes or delayed cuts. This is obviously only available when using
; FamiTracker tempo mode as FamiStudio tempo mode does not need this.
; FAMISTUDIO_USE_FAMITRACKER_DELAYED_NOTES_OR_CUTS = 1
; Must be enabled if any song uses the volume track. The volume track allows manipulating the volume at the track
; level independently from instruments.
; More information at: https://famistudio.org/doc/pianoroll/#editing-volume-tracks-effects
FAMISTUDIO_USE_VOLUME_TRACK = 0
; Must be enabled if any song uses slides on the volume track. Volume track must be enabled too.
; More information at: https://famistudio.org/doc/pianoroll/#editing-volume-tracks-effects
FAMISTUDIO_USE_VOLUME_SLIDES = 0
; Must be enabled if any song uses the pitch track. The pitch track allows manipulating the pitch at the track
; level independently from instruments.
; More information at: https://famistudio.org/doc/pianoroll/#pitch
FAMISTUDIO_USE_PITCH_TRACK = 0
; Must be enabled if any song uses slide notes. Slide notes allows portamento and slide effects.
; More information at: https://famistudio.org/doc/pianoroll/#slide-notes
FAMISTUDIO_USE_SLIDE_NOTES = 0
; Must be enabled if any song uses slide notes on the noise channel too.
; More information at: https://famistudio.org/doc/pianoroll/#slide-notes
FAMISTUDIO_USE_NOISE_SLIDE_NOTES = 0
; Must be enabled if any song uses the vibrato speed/depth effect track.
; More information at: https://famistudio.org/doc/pianoroll/#vibrato-depth-speed
FAMISTUDIO_USE_VIBRATO = 0
; Must be enabled if any song uses arpeggios (not to be confused with instrument arpeggio envelopes, those
; are always supported).
; More information at: (TODO)
FAMISTUDIO_USE_ARPEGGIO = 0
; Must be enabled if any song uses the "Duty Cycle" effect (equivalent of FamiTracker Vxx, also called "Timbre").
FAMISTUDIO_USE_DUTYCYCLE_EFFECT = 0
;----------------------------------------

173
asm/audio/music/arpeggio.s Normal file
View File

@ -0,0 +1,173 @@
; This file for the FamiStudio Sound Engine and was generated by FamiStudio
.if FAMISTUDIO_CFG_C_BINDINGS
.export _music_data_arpeggio=music_data_arpeggio
.endif
music_data_arpeggio:
.byte 1
.word @instruments
.word @samples-4
.word @song0ch0,@song0ch1,@song0ch2,@song0ch3,@song0ch4
.byte .lobyte(@tempo_env_7_mid), .hibyte(@tempo_env_7_mid), 0, 0
.export music_data_arpeggio
.global FAMISTUDIO_DPCM_PTR
@instruments:
.word @env1,@env0,@env3,@env2
.word @env5,@env0,@env4,@env2
@samples:
@env0:
.byte $c0,$7f,$00,$00
@env1:
.byte $00,$cc,$c7,$c4,$c2,$c1,$c0,$00,$06
@env2:
.byte $00,$c0,$7f,$00,$01
@env3:
.byte $7f,$00,$00
@env4:
.byte $c2,$7f,$00,$00
@env5:
.byte $07,$c7,$c6,$c6,$c5,$00,$04,$c3,$c2,$c1,$c1,$00,$0a
@tempo_env_7_mid:
.byte $03,$05,$05,$06,$03,$06,$05,$05,$80
@song0ch0:
.byte $f7, $e7, $6b, $f7, $e7, $6b, $f7, $e7, $6b, $f7, $e7
@song0ch0loop:
.byte $6a, .lobyte(@tempo_env_7_mid), .hibyte(@tempo_env_7_mid), $f7, $e7, $6b, $f7, $e7, $6b, $f7, $e7, $6b, $f7, $e7, $6b
.byte $f7, $e7, $6b, $f7, $e7, $6b, $82
@song0ref35:
.byte $3d, $83, $00, $85, $41, $83, $00, $85, $42, $83, $00, $85, $44, $83, $00, $85, $3d, $83, $00, $85, $41, $83, $00, $85
.byte $42, $83, $00, $85, $44, $83, $00, $85
.byte $ff, $20
.word @song0ref35
@song0ref70:
.byte $6b
@song0ref71:
.byte $3a, $83, $00, $85, $3e, $83, $00, $85, $3f, $83, $00, $85, $41, $83, $00, $85, $3a, $83, $00, $85, $3e, $83, $00, $85
.byte $3f, $83, $00, $85, $41, $83, $00, $85
.byte $ff, $20
.word @song0ref71
.byte $6b
.byte $ff, $20
.word @song0ref35
.byte $ff, $20
.word @song0ref35
.byte $ff, $20
.word @song0ref70
.byte $ff, $20
.word @song0ref71
.byte $fd
.word @song0ch0loop
@song0ch1:
@song0ref122:
.byte $82
@song0ref123:
.byte $31, $83, $00, $85, $35, $83, $00, $85, $36, $83, $00, $85, $38, $83, $00, $85, $31, $83, $00, $85, $35, $83, $00, $85
.byte $36, $83, $00, $85, $38, $83, $00, $85
.byte $ff, $20
.word @song0ref123
@song0ref158:
.byte $2e, $83, $00, $85, $32, $83, $00, $85, $33, $83, $00, $85, $35, $83, $00, $85, $2e, $83, $00, $85, $32, $83, $00, $85
.byte $33, $83, $00, $85, $35, $83, $00, $85
.byte $ff, $20
.word @song0ref158
.byte $ff, $20
.word @song0ref123
.byte $ff, $20
.word @song0ref123
.byte $ff, $20
.word @song0ref158
.byte $ff, $20
.word @song0ref158
@song0ch1loop:
.byte $ff, $20
.word @song0ref122
.byte $ff, $20
.word @song0ref123
.byte $ff, $20
.word @song0ref158
.byte $ff, $20
.word @song0ref158
.byte $ff, $20
.word @song0ref123
.byte $ff, $20
.word @song0ref123
.byte $ff, $20
.word @song0ref158
.byte $ff, $20
.word @song0ref158
.byte $f7, $e7, $f7, $e7
.byte $ff, $20
.word @song0ref123
.byte $ff, $20
.word @song0ref123
.byte $ff, $20
.word @song0ref158
.byte $ff, $20
.word @song0ref158
.byte $ff, $20
.word @song0ref123
.byte $ff, $20
.word @song0ref123
.byte $ff, $20
.word @song0ref158
.byte $ff, $20
.word @song0ref158
.byte $fd
.word @song0ch1loop
@song0ch2:
.byte $f7, $e7, $f7, $e7
@song0ref265:
.byte $80
@song0ref266:
.byte $25, $8b, $29, $8b, $2a, $8b, $2c, $8b, $25, $8b, $29, $8b, $2a, $8b, $2c, $8b, $25, $8b, $29, $8b, $2a, $8b, $2c, $8b
.byte $25, $8b, $29, $8b, $2a, $8b, $2c, $8b, $22, $8b, $26, $8b, $27, $8b, $29, $8b, $22, $8b, $26, $8b, $27, $8b, $29, $8b
.byte $22, $8b, $26, $8b, $27, $8b, $29, $8b, $22, $8b, $26, $8b, $27, $8b, $29, $8b
@song0ch2loop:
.byte $ff, $40
.word @song0ref265
.byte $ff, $40
.word @song0ref266
.byte $ff, $40
.word @song0ref266
.byte $ff, $40
.word @song0ref266
.byte $ff, $40
.word @song0ref266
.byte $fd
.word @song0ch2loop
@song0ch3:
.byte $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7
@song0ch3loop:
.byte $80
@song0ref359:
.byte $1e, $8b, $00, $8b, $1e, $8b, $00, $8b, $1e, $8b, $1e, $8b, $1e, $8b, $00, $8b, $1e, $8b, $00, $8b, $1e, $8b, $00, $8b
.byte $1e, $8b, $00, $a7
.byte $ff, $1c
.word @song0ref359
.byte $ff, $1c
.word @song0ref359
.byte $ff, $1c
.word @song0ref359
.byte $ff, $1c
.word @song0ref359
.byte $ff, $1c
.word @song0ref359
.byte $ff, $1c
.word @song0ref359
.byte $ff, $1c
.word @song0ref359
.byte $ff, $1c
.word @song0ref359
.byte $ff, $1c
.word @song0ref359
.byte $fd
.word @song0ch3loop
@song0ch4:
.byte $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7
@song0ch4loop:
.byte $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $fd
.word @song0ch4loop

99
asm/constant.asm Normal file
View File

@ -0,0 +1,99 @@
;**********
; Constants
;**********
; Replace the value with the name of your CHR file
.define GAME_CHR "Boilerplate.chr"
;----------
; PPU
;----------
PPU_CTRL := $2000
PPU_MASK := $2001
PPU_STATUS := $2002
PPU_SCROLL := $2005
PPU_ADDR := $2006
PPU_DATA := $2007
; PPU MASK
PPU_MASK_GREY = %00000001
PPU_MASK_BKG8 = %00000010
PPU_MASK_SPR8 = %00000100
PPU_MASK_BKG = %00001000
PPU_MASK_SPR = %00010000
PPU_MASK_R = %00100000
PPU_MASK_G = %01000000
PPU_MASK_B = %10000000
; PPU CTRL
PPU_CTRL_NM_1 = %00000001
PPU_CTRL_NM_2 = %00000010
PPU_CTRL_INC = %00000100
PPU_CTRL_SPR = %00001000
PPU_CTRL_BKG = %00010000
PPU_CTRL_SPR_SIZE = %00100000
PPU_CTRL_SEL = %01000000
PPU_CTRL_NMI = %10000000
;----------
; APU
;----------
APU := $4000
APU_SQ1_VOL := $4000
APU_SQ1_SWEEP := $4001
APU_SQ1_LO := $4002
APU_SQ1_HI := $4003
APU_SQ2_VOL := $4004
APU_SQ2_SWEEP := $4005
APU_SQ2_LO := $4006
APU_SQ2_HI := $4007
APU_TRI_LINEAR := $4008
APU_TRI_LO := $400A
APU_TRI_HI := $400B
APU_NOISE_VOL := $400C
APU_NOISE_LO := $400E
APU_NOISE_HI := $400F
APU_DMC_FREQ := $4010
APU_DMC_RAW := $4011
APU_DMC_START := $4012
APU_DMC_LEN := $4013
APU_SND_CHN := $4015
APU_CTRL := $4015
APU_STATUS := $4015
APU_FRAME := $4017
;----------
; OAM
;----------
OAMDMA := $4014
;----------
; IO
;----------
IO_JOY1 := $4016
IO_JOY2 := $4017
;----------
; NMI
;----------
NMI_DONE = %10000000
NMI_SCRL = %00010000
NMI_PLT = %00001000
NMI_ATR = %00000100
NMI_SPR = %00000010
NMI_BKG = %00000001

63
asm/crt0.asm Normal file
View File

@ -0,0 +1,63 @@
;****************
; Author: Safyrus
;****************
.ifdef C_CODE
.export _exit,__STARTUP__:absolute=1
.import _main
.endif
; Header of the file (not part of the cartridge, used by the emulator)
.segment "HEADER"
.byte "NES", $1A; 0-3: Header
.byte $02 ; 4: PRG ROM
.byte $01 ; 5: CHR ROM
.byte $01 ; 6: Flags 6
.byte $00 ; 7: Flags 7
.byte $00 ; 8: Flags 8
.byte $00 ; 9: Flags 9
.byte $00 ; 10: Flags 10
.byte $00,$00,$00,$00,$00 ; Padding
.include "constant.asm"
.include "macro.asm"
.include "memory.asm"
.segment "STARTUP"
.ifdef C_CODE
_exit:
.endif
; 6502 vectors subrountines
.include "vector/rst.asm"
.include "vector/nmi.asm"
.include "vector/irq.asm"
.ifndef C_CODE
; main file
.include "main.asm"
.endif
.if FAMISTUDIO=1
; FamiStudio Sound Engine
.include "audio/famistudio_config.asm"
.include "audio/famistudio_ca65.s"
; Musics
.include "audio/music/arpeggio.s"
.endif
; 6502 vectors
.segment "VECTORS"
; 6502 vectors
.word NMI ; fffa nmi/vblank
.word RST ; fffc reset
.word IRQ ; fffe irq/brk
; CHR ROM data
.segment "CHARS"
.incbin GAME_CHR

20
asm/macro.asm Normal file
View File

@ -0,0 +1,20 @@
;**********
; Macros
;**********
.macro pushreg
PHA
TXA
PHA
TYA
PHA
.endmacro
.macro pullreg
PLA
TAY
PLA
TAX
PLA
.endmacro

83
asm/main.asm Normal file
View File

@ -0,0 +1,83 @@
;**********
; Main
;**********
MAIN:
.if FAMISTUDIO=1
LDX #<music_data_arpeggio ; music data (lo)
LDY #>music_data_arpeggio ; music data (hi)
LDA #$01 ; NTSC
JSR famistudio_init
LDA #$00 ; Song 0
JSR famistudio_music_play
.endif
@wait_vblank:
LDA nmi_flags
AND #NMI_DONE
BEQ @wait_vblank
.if FAMISTUDIO=1
; update sound engine
JSR famistudio_update
.endif
LDA #(PPU_MASK_BKG8+PPU_MASK_BKG+PPU_MASK_SPR8+PPU_MASK_SPR)
STA PPU_MASK
LDA #(NMI_ATR+NMI_PLT+NMI_SCRL+NMI_BKG+NMI_SPR)
STA nmi_flags
LDA #$23
STA atr_nametable
LDX #$00
LDA #$00
@loop_atr:
STA attributes, X
INX
CPX #$40
BNE @loop_atr
LDX #$00
@loop_plt:
TXA
STA palettes, X
INX
CPX #25
BNE @loop_plt
LDA #$40
STA OAM+0
LDA #$01
STA OAM+1
LDA #$00
STA OAM+2
LDA game_state
STA OAM+3
LDA #($05 + %00000000)
STA background+0
LDA #$20
STA background+1
LDA game_state
STA background+2
LDA #$04
STA background+3
LDA #$00
STA background+4
LDA #$01
STA background+5
LDA #$02
STA background+6
LDA #$03
STA background+7
LDA #$00
STA background+8
LDX game_state
INX
STX game_state
JMP @wait_vblank

87
asm/memory.asm Normal file
View File

@ -0,0 +1,87 @@
;**********
; Memory
;**********
.segment "ZEROPAGE"
; NMI Flags to activate graphical update
; Note: You cannot activate all updates.
; You need to have a execution time
; < ~2273 cycles (2000 to be sure)
; 7 bit 0
; ---- ----
; E..R PASB
; | | ||||
; | | |||+- Background tiles update
; | | ||| Execution time depend on data
; | | ||| (cycles ~= 16 + 38*p + for i:p do (14*p[i].n))
; | | ||| (p=packet number, p[i].n = packet data size)
; | | ||+-- Sprites update (513+ cycles)
; | | |+--- Nametables attributes update (821 cycles)
; | | +---- Palettes update (356 cycles)
; | +------ Scroll update (31 cycles)
; +--------- 1 when NMI has ended, should be set to 0 after reading.
; If let to 1, it means the NMI is disable
nmi_flags: .res 1
.export _nmi_flags=nmi_flags
; Scroll X position
scroll_x: .res 1
.export _scroll_x=scroll_x
; Scroll Y position
scroll_y: .res 1
.export _scroll_y=scroll_y
; Nametable high adress to update attributes for
; $23 = Nametable 1
; $27 = Nametable 2
; $2B = Nametable 3
; $2F = Nametable 4
atr_nametable: .res 1
.export _atr_nametable=atr_nametable
; value of the PPU_MASK (need to be refresh manually)
ppu_ctrl_val: .res 1
.export _ppu_ctrl_val=ppu_ctrl_val
; Attributes data to send to PPU during VBLANK
attributes: .res 64
.export _attributes=attributes
; Palettes data to send to PPU during VBLANK
; byte 0 = transparente color
; byte 1-3 = background palette 1
; byte 4-6 = background palette 2
; ...
; byte 13-16 = sprite palette 1
; ...
palettes: .res 25
.export _palettes=palettes
; Background data to send to PPU during VBLANK
; Packet structure:
; byte 0 = v.ssssss (v= vertical draw, s= size)
; byte 1-2 = ppu adress
; byte 3-s = tile data
; packet of size 0 means there is no more data to draw
background: .res 128
.export _background=background
;****************
; OAM SEGMENT
;****************
.segment "OAM"
OAM:
.export _OAM=OAM
;****************
; BSS SEGMENT
;****************
.segment "BSS"
game_state: .res 1
.export _game_state=game_state

16
asm/vector/irq.asm Normal file
View File

@ -0,0 +1,16 @@
;***********
; IRQ vector
;***********
IRQ:
; save register
PHA
; clear APU interrupt
LDA APU_STATUS
; restore register
PLA
; return
RTI

218
asm/vector/nmi.asm Normal file
View File

@ -0,0 +1,218 @@
;***********
; NMI vector
;***********
;--------------------
; Cycles notes
;--------------------
; 2273 cycles per VBLANK
; base (before @done) = 13+3+2+3+(2+3)*5
; @sprite = 513+ cycles
; @scroll = 31 cycles
; @attribute = 821 cycles
; @palette = 356 cycless
; @background ~= 16+(38*p+14*p[i].n)
;--------------------
NMI:
; save registers
pushreg
; do we need to do stuff ? (E flag)
BIT nmi_flags
BPL @start
JMP @end
@start:
; load NMI flags
LDA nmi_flags
; is the background flag on ? (B flag)
LSR
BCC @background_end
@background:
; save flags
PHA
LDX #$00
@background_loop:
; read size
LDA background, X
; if size = 0 then end
BEQ @background_loop_end
; save size to Y
AND #$3F
TAY
; is vertical flag off ?
LDA background, X
ASL
BCC @background_loop_hor
; tell the ppu to inc by 32
@background_loop_ver:
LDA ppu_ctrl_val
ORA #(PPU_CTRL_INC)
STA PPU_CTRL
JMP @background_loop_start
; tell the ppu to inc by 1
@background_loop_hor:
LDA ppu_ctrl_val
AND #($FF-PPU_CTRL_INC)
STA PPU_CTRL
@background_loop_start:
; reset latch
BIT PPU_STATUS
; set PPU adr
INX
LDA background, X
STA PPU_ADDR
INX
LDA background, X
STA PPU_ADDR
; send data
@background_loop_data:
; send 1 tile
INX
LDA background, X
STA PPU_DATA
; loop
DEY
BNE @background_loop_data
INX
JMP @background_loop
@background_loop_end:
; restore PPU_CTRL
LDA ppu_ctrl_val
STA PPU_CTRL
; restore flags
PLA
@background_end:
; is the sprite flag on ? (S flag)
LSR
BCC @sprite_end
@sprite:
; Update sprites
LDX #>OAM
STX OAMDMA
@sprite_end:
; is the attribute flag on ? (A flag)
LSR
BCC @attribute_end
@attribute:
; save flags
PHA
; reset latch
BIT PPU_STATUS
; set PPU address
LDA atr_nametable
STA PPU_ADDR
LDA #$C0
STA PPU_ADDR
; send data to PPU
LDX #$00
@attribute_loop:
; send 1 byte
INX
LDA attributes, X
STA PPU_DATA
; send another byte
INX
LDA attributes, X
STA PPU_DATA
; loop
CPX #$40
BNE @attribute_loop
; restore flags
PLA
@attribute_end:
; is the palette flag on ? (P flag)
LSR
BCC @palette_end
@palette:
; save flags
PHA
; reset latch
BIT PPU_STATUS
; set PPU address
LDA #$3F
STA PPU_ADDR
LDA #$00
STA PPU_ADDR
; send data to PPU
LDX #$00
; send transparent color
LDA palettes, X
TAY
INX
@palette_loop:
; send background
TYA
STA PPU_DATA
; send 3 colors
LDA palettes, X
STA PPU_DATA
INX
LDA palettes, X
STA PPU_DATA
INX
LDA palettes, X
STA PPU_DATA
INX
; loop
CPX #25
BNE @palette_loop
; restore flags
PLA
@palette_end:
; is the scroll flag on ? (R flag)
LSR
BCC @scroll_end
@scroll:
; reset latch
BIT PPU_STATUS
; set scrolling position to scroll_x, scroll_y
LDX scroll_x
STX PPU_SCROLL
LDX scroll_y
STX PPU_SCROLL
LDX #$00 ; set bit 15 of t in PPU to 0
STX PPU_ADDR ; (because, for unknown reason)
LDX #$00 ; to fix scrolling in the wrong nametable.
STX PPU_ADDR
@scroll_end:
@done:
; tell that we are done
LDA #NMI_DONE
ORA nmi_flags
STA nmi_flags
@end:
; restore registers
pullreg
; return
RTI

55
asm/vector/rst.asm Normal file
View File

@ -0,0 +1,55 @@
;***********
; RST vector
;***********
.ifdef C_CODE
.import _main
.endif
RST:
SEI ; Disable interrupt
CLD ; Clear/disable decimal
LDX #$FF ; Initialized stack
TXS
INX ; X=0
STX PPU_CTRL ; Disable NMI
STX PPU_MASK ; Disable Rendering
STX APU_DMC_FREQ ; Disable DMC IRQ
; Wait for the PPU to initialized
BIT PPU_STATUS ; Clear the VBL flag if it was set at reset time
@vwait1:
BIT PPU_STATUS
BPL @vwait1 ; At this point, about 27384 cycles have passed
@clrmem:
LDA #$00
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 @clrmem
@vwait2:
BIT PPU_STATUS
BPL @vwait2 ; At this point, about 57165 cycles have passed
LDA #%10010000 ; Enable NMI + set background table to $1000
STA PPU_CTRL
STA ppu_ctrl_val
CLI
.ifdef C_CODE
JMP _main
.else
JMP MAIN
.endif