2018-08-13 22:17:36 +00:00
|
|
|
|
2018-08-03 18:06:08 +00:00
|
|
|
;;;;; SUBROUTINES
|
|
|
|
|
|
|
|
ClearRAM: subroutine
|
2019-03-15 01:55:16 +00:00
|
|
|
lda #0 ; A = 0
|
|
|
|
tax ; X = 0
|
2018-08-03 18:06:08 +00:00
|
|
|
.clearRAM
|
2019-03-15 01:55:16 +00:00
|
|
|
sta $0,x ; clear $0-$ff
|
|
|
|
cpx #$fe ; last 2 bytes of stack?
|
|
|
|
bcs .skipStack ; don't clear it
|
|
|
|
sta $100,x ; clear $100-$1fd
|
2018-08-03 18:06:08 +00:00
|
|
|
.skipStack
|
2019-03-15 01:55:16 +00:00
|
|
|
sta $200,x ; clear $200-$2ff
|
|
|
|
sta $300,x ; clear $300-$3ff
|
|
|
|
sta $400,x ; clear $400-$4ff
|
|
|
|
sta $500,x ; clear $500-$5ff
|
|
|
|
sta $600,x ; clear $600-$6ff
|
|
|
|
sta $700,x ; clear $700-$7ff
|
|
|
|
inx ; X = X + 1
|
|
|
|
bne .clearRAM ; loop 256 times
|
2018-08-03 18:06:08 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
; wait for VSYNC to start
|
|
|
|
WaitSync:
|
|
|
|
bit PPU_STATUS
|
|
|
|
bpl WaitSync
|
|
|
|
rts
|
|
|
|
|
|
|
|
;;;;; RANDOM NUMBERS
|
|
|
|
|
|
|
|
NextRandom subroutine
|
|
|
|
lsr
|
|
|
|
bcc .NoEor
|
|
|
|
eor #$d4
|
|
|
|
.NoEor:
|
|
|
|
rts
|
|
|
|
; Get previous random value
|
|
|
|
PrevRandom subroutine
|
|
|
|
asl
|
|
|
|
bcc .NoEor
|
|
|
|
eor #$a9
|
|
|
|
.NoEor:
|
|
|
|
rts
|
|
|
|
|
2019-02-21 19:19:29 +00:00
|
|
|
;;;;; CONTROLLER READING
|
|
|
|
|
2019-03-10 16:17:12 +00:00
|
|
|
ReadJoypad0 subroutine
|
|
|
|
ldy #0
|
|
|
|
ReadJoypadY
|
2019-02-21 19:19:29 +00:00
|
|
|
lda #$01
|
2019-03-10 16:17:12 +00:00
|
|
|
sta JOYPAD1,y ; set strobe bit
|
2019-02-21 19:19:29 +00:00
|
|
|
lsr ; now A is 0
|
2019-03-10 16:17:12 +00:00
|
|
|
sta JOYPAD1,y ; clear strobe bit
|
|
|
|
ldx #8 ; read 8 bits
|
2019-02-21 19:19:29 +00:00
|
|
|
.loop:
|
2019-03-10 16:17:12 +00:00
|
|
|
pha ; save A (result)
|
|
|
|
lda JOYPAD1,y ; load controller state
|
2019-02-21 19:19:29 +00:00
|
|
|
lsr ; bit 0 -> carry
|
2019-03-10 16:17:12 +00:00
|
|
|
pla ; restore A (result)
|
|
|
|
rol ; carry -> bit 0 of result
|
|
|
|
dex ; X = X - 1
|
|
|
|
bne .loop ; repeat if X is 0
|
2019-02-21 19:19:29 +00:00
|
|
|
rts ; controller bits returned in A
|
|
|
|
|