Add support for different joysticks

This commit is contained in:
karri 2024-07-20 13:14:22 +03:00
parent 0541b65aa4
commit 19899022af

View File

@ -53,13 +53,20 @@ JOY_COUNT = 2 ; Number of joysticks we support
; Must return an JOY_ERR_xx code in a/x. ; Must return an JOY_ERR_xx code in a/x.
; ;
PB2 = $04 ; Joystick 0
PB4 = $10 ; Joystick 1
INSTALL: INSTALL:
; Assume 7800 2-button controller, can change ; Assume 7800 2-button controller, can change
; to 2600 1-button later ; to 2600 1-button later
lda #$14 lda #(PB2 | PB4)
sta CTLSWB ; enable 2-button 7800 controller 1: set pin 6 to output ; 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 ldy #$00
sty SWCHB ; enable 2-button 7800 controller 2: pull pin 6 (INPT4) high sty SWCHB
reset: reset:
lda #JOY_ERR_OK lda #JOY_ERR_OK
@ -88,6 +95,28 @@ COUNT:
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; READ: Read a particular joystick passed in A for 2 fire buttons. ; 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: readbuttons:
; Y has joystick of interest 0/1 ; Y has joystick of interest 0/1
; return value: ; return value:
@ -97,42 +126,48 @@ readbuttons:
; $03: both buttons ; $03: both buttons
; preserves X ; preserves X
tya tya
beq L5 beq readbuttons0
readbuttons1:
; Joystick 1 processing ; Joystick 1 processing
; 7800 joystick 1 buttons ; Start by checking for single button 2600 joystick
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
bit INPT5 bit INPT5
bmi L4 bpl singlebtn1detected
L3: iny ; .......1 jmp readdualbuttons1
lda #0 ; Fallback to 2600 joystick mode singlebtn1detected:
sta CTLSWB ; Single button joystick detected but could be dual
L4: tya ; ......21 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 rts
L5: ; Joystick 0 processing readbuttons0:
; 7800 joystick 0 buttons ; Joystick 0 processing
ldy #0 ; ........ ; Start by checking for single button 2600 joystick
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
bit INPT4 bit INPT4
bmi L4 bpl singlebtn0detected
bpl L3 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: READ:
tay ; Store joystick 0/1 in Y tay ; Store joystick 0/1 in Y