Skip to content

Commit

Permalink
[KERNAL] change controller polling timing in hopes of improving compa…
Browse files Browse the repository at this point in the history
…tibility
  • Loading branch information
mooinglemur committed Mar 7, 2024
1 parent 9122a2f commit 8e37083
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions kernal/drivers/x16/joystick.s
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ joystick_scan:
pha
pla
stz nes_data
pha
pla
pha
pla

; read 3x 8 bits
ldx #bit_jclk
ldy #8
l1: stz nes_data ; Drive NES clock low (NES controller doesn't change when low)
nop ; Delay for slow SNES controllers
lda nes_data ; Read all controller bits
l1: lda nes_data ; Read all controller bits
stx nes_data ; Drive NES clock high

; process while NES clock is high (bits change)
Expand All @@ -85,6 +87,7 @@ l1: stz nes_data ; Drive NES clock low (NES controller doesn't change when low)
rol ; Move bit 6 into C
rol joy2 ; Roll C into joy2
rol ; Roll bit 5 into C
stz nes_data ; Drive NES clock low (NES controller doesn't change when low)
rol joy3 ; Roll C into joy3
rol ; Roll bit 4 into C
rol joy4 ; Roll C into joy4
Expand All @@ -93,9 +96,7 @@ l1: stz nes_data ; Drive NES clock low (NES controller doesn't change when low)
bne l1

ldy #8
l2: stz nes_data ; Drive NES clock low (NES controller doesn't change when low)

lda nes_data ; Read all controller bits
l2: lda nes_data ; Read all controller bits
stx nes_data ; Drive NES clock high

; process while NES clock is high (bits change)
Expand All @@ -104,6 +105,7 @@ l2: stz nes_data ; Drive NES clock low (NES controller doesn't change when low)
rol ; Move bit 6 into C
rol joy2+1 ; Roll C into joy2
rol ; Roll bit 5 into C
stz nes_data ; Drive NES clock low (NES controller doesn't change when low)
rol joy3+1 ; Roll C into joy3
rol ; Roll bit 4 into C
rol joy4+1 ; Roll C into joy4
Expand All @@ -112,17 +114,15 @@ l2: stz nes_data ; Drive NES clock low (NES controller doesn't change when low)
bne l2

ldy #8
l3: stz nes_data ; Drive NES clock low (NES controller doesn't change when low)

lda nes_data ; Read all controller bits
l3: lda nes_data ; Read all controller bits
stx nes_data ; Drive NES clock high

; process while NES clock is high (bits change)
rol ; Move bit 7 into C
rol joy1+2 ; Roll C into joy1
rol ; Move bit 6 into C
rol joy2+2 ; Roll C into joy2
rol ; Roll bit 5 into C
stz nes_data ; Drive NES clock low (NES controller doesn't change when low)
rol joy3+2 ; Roll C into joy3
rol ; Roll bit 4 into C
rol joy4+2 ; Roll C into joy4
Expand All @@ -131,7 +131,7 @@ l3: stz nes_data ; Drive NES clock low (NES controller doesn't change when low)
bne l3

; force present if controller ID (bits 8-11) is not 15

lda joy1+1
and #%00001111
cmp #15
Expand Down

0 comments on commit 8e37083

Please sign in to comment.