nothing held = load screen 0
While holding A = display screen 1
My code works! But I am fairly sure it is a bit (more likely a lot) hacky, and probably far from best practice. Is there a better way to do this?
Code: Select all
; controller reading subroutines start
readcontroller:
LDA newbuttons
STA oldbuttons
LDX #$00
LDA #$01 ; strobe joypad
STA $4016
LDA #$00
STA $4016
ConLoop:
LDA $4016 ; check the state of each button
LSR
ROR newbuttons
INX
CPX #$08
bne ConLoop
LDA oldbuttons ; invert bits
EOR #$FF
AND newbuttons
STA justpressed
LDA screennumber ; save old screen number for later compare
STA oldscreen
;button ( 0 0 0 0 0 0 0 0 )
;layout ( R L D U St Sl B A )
checkselect:
lda #0
sta screennumber
LDA #%00000100
AND oldbuttons
BEQ checkstart
lda #5
sta screennumber
checkstart:
LDA #%00001000
AND oldbuttons
BEQ checka
lda #6
sta screennumber
checka:
LDA #%00000010
AND oldbuttons
BEQ checkb
lda #7
sta screennumber
checkb:
LDA #%00000001
AND oldbuttons
BEQ checkup
lda #8
sta screennumber
checkup:
LDA #%00010000
AND oldbuttons
BEQ checkdown
lda #2
sta screennumber
checkdown:
LDA #%00100000
AND oldbuttons
BEQ checkleft
lda #4
sta screennumber
checkleft:
LDA #%01000000
AND oldbuttons
BEQ checkright
lda #1
sta screennumber
checkright:
LDA #%10000000
AND oldbuttons
BEQ checksdone
lda #3
sta screennumber
checksdone: