.include "testing.s"
.include "joysticks.s"
.include "minimal_ppu.s"

reset:
	sei
	cld
	ldx #$FF
	txs

	lda #$01
	sta SNDCHN
	lda #$AF ; Duty 2, LC halted, evelope enabled, volume = F
	sta PULSE_CH1_DLCV
	lda #$7F ; 
	sta PULSE_CH1_SWEEP
	lda #$6F
	sta PULSE_CH1_TLOW
	sta TIMER_LOW
	lda #$F0
	sta PULSE_CH1_LCTH
; PULSE_CH1_DLCV = $4000
; PULSE_CH1_SWEEP = $4001
; PULSE_CH1_TLOW = $4002
; PULSE_CH1_LCTH = $4003

	jmp init_ppu_and_wait

; zp_res 
zp_res TIMER_LOW
update_audio:
	adc TIMER_LOW
	sta PULSE_CH1_TLOW
	sta TIMER_LOW

	rts

zp_res PRESSED_A
zp_res PRESSED_B

nmi:
	nmi_start
	jsr read_joy1

	and #$80
	beq not_a
	lda #$08
	jsr update_audio
not_a:
	lda JOYTEMP
	and #$40
	beq not_b
	lda #$01
	jsr update_audio
not_b:
	nmi_end


irq:
	rti
