1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-16 18:08:04 +00:00

Merge pull request #2468 from karrika/fix-joystick

Fixed #2459
This commit is contained in:
Bob Andrews 2024-07-28 15:49:42 +02:00 committed by GitHub
commit 91f908f55a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -53,13 +53,20 @@ JOY_COUNT = 2 ; Number of joysticks we support
; Must return an JOY_ERR_xx code in a/x.
;
PB2 = $04 ; Joystick 0
PB4 = $10 ; Joystick 1
INSTALL:
; Assume 7800 2-button controller, can change
; to 2600 1-button later
lda #$14
sta CTLSWB ; enable 2-button 7800 controller 1: set pin 6 to output
lda #(PB2 | PB4)
; enable 2-button 7800 controllers on both ports
; by setting PB2 and PB4 to output
sta CTLSWB
; enable 2-button 7800 controllers by setting
; the outputs to 0; (INPT4 and INPT5) high
ldy #$00
sty SWCHB ; enable 2-button 7800 controller 2: pull pin 6 (INPT4) high
sty SWCHB
reset:
lda #JOY_ERR_OK
@ -88,6 +95,28 @@ COUNT:
; ------------------------------------------------------------------------
; READ: Read a particular joystick passed in A for 2 fire buttons.
readdualbuttons0:
ldy #0 ; ........
bit INPT0 ; Check for right button
bpl L1
ldy #2 ; ......2.
L1: bit INPT1 ; Check for left button
bpl L2
iny ; ......21
L2: tya
rts
readdualbuttons1:
ldy #0 ; ........
bit INPT2 ; Check for right button
bpl L1
ldy #2 ; ......2.
L3: bit INPT3 ; Check for left button
bpl L2
iny ; ......21
L4: tya
rts
readbuttons:
; Y has joystick of interest 0/1
; return value:
@ -97,42 +126,48 @@ readbuttons:
; $03: both buttons
; preserves X
tya
beq L5
beq readbuttons0
readbuttons1:
; Joystick 1 processing
; 7800 joystick 1 buttons
ldy #0 ; ........
bit INPT2 ; Check for right button
bpl L1
ldy #2 ; ......2.
L1: bit INPT3 ;Check for left button
bpl L2
iny ; ......21
L2: tya
bne L4 ; 7800 mode joystick worked
; 2600 Joystick 1
; Start by checking for single button 2600 joystick
bit INPT5
bmi L4
L3: iny ; .......1
lda #0 ; Fallback to 2600 joystick mode
sta CTLSWB
L4: tya ; ......21
bpl singlebtn1detected
jmp readdualbuttons1
singlebtn1detected:
; Single button joystick detected but could be dual
jsr readdualbuttons1
bne L5 ; It was a dual button press
; It was a single button press
bit INPT5
bmi L5
iny ; .......1
lda #PB4 ; Joystick 1 is a single button unit
clc
adc SWCHB
sta SWCHB ; Cut power from the dual button circuit
L5: tya ; ......21
rts
L5: ; Joystick 0 processing
; 7800 joystick 0 buttons
ldy #0 ; ........
bit INPT0 ; Check for right button
bpl L6
ldy #2 ; ......2.
L6: bit INPT1 ;Check for left button
bpl L7
iny ; ......21
L7: tya
bne L4 ; 7800 mode joystick worked
; 2600 Joystick 0
readbuttons0:
; Joystick 0 processing
; Start by checking for single button 2600 joystick
bit INPT4
bmi L4
bpl L3
bpl singlebtn0detected
jmp readdualbuttons0
singlebtn0detected:
; Single button joystick detected but could be dual
jsr readdualbuttons0
bne L6 ; It was a dual button press
; It was a single button press
bit INPT4
bmi L6
iny ; .......1
lda #PB2 ; Joystick 0 is a single button unit
clc
adc SWCHB
sta SWCHB ; Cut power from the dual button circuit
L6: tya ; ......21
rts
READ:
tay ; Store joystick 0/1 in Y