My last question wasn't specific enough so I'll rephrase it. I've been having trouble with programming game consoles/computers like Commodore 64 that have active-low joysticks, where the bits are all packed into one or more bytes that is read from the joystick port. (I'm used to the NES where you have to strobe the keys and read it active-high). I'd like to convert the routine below to active-high, by flipping the bits of
joypad1, removing the
CMP #$FF, and changing each
BEQ. I thought that would have been enough, but this ends up making none of the controls work. (Each direction is set up to move a hardware sprite around the screen.) How do I correctly alter the code below to read the input active-high?
JOYSTICK_FIRE equ #%00010000 JOYSTICK_RIGHT equ #%00001000 JOYSTICK_LEFT equ #%00000100 JOYSTICK_DOWN equ #%00000010 JOYSTICK_UP equ #%00000001 handle_input: lda joypad1 cmp #$FF ; if all bits are 1, no buttons pressed. bne continueReadingInput jmp doneReadingInput ;don't bother checking if no keys pressed continueReadingInput: lda joypad1 and #JOYSTICK_FIRE bne JoyNotFire ;YOUR CODE FOR WHAT HAPPENS WHEN YOU PRESS FIRE GOES HERE. JoyNotFire: lda joypad1 and #JOYSTICK_RIGHT bne JoyNotRight ;YOUR CODE FOR WHAT HAPPENS WHEN YOU PRESS LEFT GOES HERE. JoyNotRight: lda joypad1 and #JOYSTICK_LEFT bne JoyNotLeft ;YOUR CODE FOR WHAT HAPPENS WHEN YOU PRESS LEFT GOES HERE. JoyNotLeft: lda joypad1 and #JOYSTICK_DOWN bne JoyNotDown ;YOUR CODE FOR WHAT HAPPENS WHEN YOU PRESS DOWN GOES HERE. JoyNotDown: lda joypad1_held and #JOYSTICK_UP bne doneReadingInput ;YOUR CODE FOR WHAT HAPPENS WHEN YOU PRESS UP GOES HERE. doneReadingInput: rts
EOR #$FFafter each
LDA joypad1and see what happens. I'd rather just do it once when the joypad1 variable is created but it causes problems.
EOR #$FFmethod after each instance of
LDA JOYPAD1works, unless I try comparing anything other than
JOYPAD1_PRESSEDetc.) Flipping the bits read from the joystick and saving them to the variable crashes the game but only when pressing Down or Left. Very strange
LDA $DC01 EOR #$FF STA JOYPAD1where
JOYPAD1is a zero page address. Then do all my controller reading this frame from