Mmmkaaay... This is not as easy as I would've hoped.
PS/2 is LSB first, 6522 Shift register is MSB first - from mode 010, that I missed before:
Quote:
Data is shifted first into bit 0 and is then shifted into the next higher
order bit of the shift register on the trailing edge of each clock pulse.
I noticed because I tried the SR IRQ route instead and got confused if I should use ROL or ROR for shifting in the last bit. ROL it is.
The best idea to get this approach working is to bit juggle the bits to the correct order - inline for speed.
So this is my current attempt ISR for the shift register:
Code:
lda SR1
sta $0B
getlastbit:
lda SR1
cmp $0b
beq getlastbit
LDA #%01000000 ; Let's disable the shift register after the last bit and reenable in main loop after half a second (for debugging)
STA ACR ; T1 continuous - disable T2 and Shift register
and #1
beq notset
sec
bcs rotatelastbit ; BRA
notset:
clc
rotatelastbit:
lda $0b
rol
sta $0b ; LSB is in MSB :/
; I could probably do this bit shuffling in the main loop I guess
rol $0b ; MSB to C
ror $0c ; C to MSB
rol $0b ; MSB to C
ror $0c ; C to MSB
rol $0b ; MSB to C
ror $0c ; C to MSB
rol $0b ; MSB to C
ror $0c ; C to MSB
rol $0b ; MSB to C
ror $0c ; C to MSB
rol $0b ; MSB to C
ror $0c ; C to MSB
rol $0b ; MSB to C
ror $0c ; C to MSB
rol $0b ; MSB to C
ror $0c ; C to MSB
pla
rti
It actually kind of works... Sometimes... I'm getting $44 half the time, but also a lot of $22 and $24. Other scan codes seem to confirm that it's kind of working.. The dreaded 011 mode bug is looming though. Was really hoping I didn't have to bring out extra hardware, but of course I have a '74 somewhere..
Currently I'm re-enabling the shift register when my cursor is blinking
Edit:
Since I had the MSB/LSB error before, I'll go back to the PB6 counting method again - reversing the shift register mig be what was missing.
Edit2: I finally did the sensible thing and used an output pin for debugging and connected my scope to that and the clock.. It's certainly not sampling the SR at the right time. It's basically rotating right every time I press a key.
Edit3: This actually seems to work. My debug pin tells me it's sampling SR right before the 10th rising edge. (Which is later than what I would expect with PB6 count being set to 9 and not 10)
Code:
t2_irq:
lda kbbit
cmp #2
beq count10 ; If we only counted to 2 then reset counter to 9
lda SR1 ; If we counted to 10 then fall through and save SR and reset counter to 2
; T1 continuous - disable Shift register
sta $0b ; LSB is in MSB :/
lda #$81
sta $5000 ; Ouput only register debug
LDA #%01100000
STA ACR
rol $0b ; MSB to C
ror $0c ; C to MSB
rol $0b ; MSB to C
ror $0c ; C to MSB
rol $0b ; MSB to C
ror $0c ; C to MSB
rol $0b ; MSB to C
ror $0c ; C to MSB
rol $0b ; MSB to C
ror $0c ; C to MSB
rol $0b ; MSB to C
ror $0c ; C to MSB
rol $0b ; MSB to C
ror $0c ; C to MSB
rol $0b ; MSB to C
ror $0c ; C to MSB
lda #2
sta kbbit
sta T2CL
lda #0
sta T2CH
lda #1
sta $5000 ; OOR debug
beq newcount ; BRA
count10:
LDA #%01101100
STA ACR ; T1+T2, reenable Shift register
lda #9
sta kbbit
sta T2CL
lda #0
sta T2CH
; bit SR1 ; Superfluous?
newcount:
pla
rti
In the main loop I reset the T2 counter every half second to kill the creeping framing errors.
Time to try a 74'74.