| |
Monte Carlos
Registered: Jun 2004 Posts: 330 |
Short routine to check if 1,2 or 3 is pressed
I remember i often checked for space using
lda #$10
bit $dc01
rts
Space was pressed if the code returned with a cleared zero flag. Also, I remember some other codes like #$02 for left arrow or #$20 for cbm (???). Other codes I don't remember.
Now, I'm in search for a short routine to check if 1,2 or 3 is pressed and return 0,1,2 respectively.
Do you have any idea how to set/read the CIA regs in this case?
I'm working with this keyboard matrix: https://sta.c64.org/cbm64kbdlay.html |
|
| |
tlr
Registered: Sep 2003 Posts: 1628 |
Quote: I remember i often checked for space using
lda #$10
bit $dc01
rts
Space was pressed if the code returned with a cleared zero flag. Also, I remember some other codes like #$02 for left arrow or #$20 for cbm (???). Other codes I don't remember.
Now, I'm in search for a short routine to check if 1,2 or 3 is pressed and return 0,1,2 respectively.
Do you have any idea how to set/read the CIA regs in this case?
I'm working with this keyboard matrix: https://sta.c64.org/cbm64kbdlay.html
How about:
.C:c000 78 SEI
.C:c001 A2 00 LDX #$00
.C:c003 A9 7F LDA #$7F
.C:c005 8D 00 DC STA $DC00
.C:c008 AD 01 DC LDA $DC01
.C:c00b 4A LSR A
.C:c00c 90 12 BCC $C020
.C:c00e 4A LSR A
.C:c00f 4A LSR A
.C:c010 4A LSR A
.C:c011 90 0C BCC $C01F
.C:c013 A9 FD LDA #$FD
.C:c015 8D 00 DC STA $DC00
.C:c018 AD 01 DC LDA $DC01
.C:c01b 4A LSR A
.C:c01c B0 E5 BCS $C003
.C:c01e E8 INX
.C:c01f E8 INX
.C:c020 8E 00 04 STX $0400
.C:c023 90 DC BCC $C001 |
| |
Monte Carlos
Registered: Jun 2004 Posts: 330 |
Thank you! However, meanwhile I made it up myself.
Here is my code:
lda #%11111101
sta CIA1_PRA
lda CIA1_PRB
cmp #%11111110
beq is3
lda #%01111111
sta CIA1_PRA
lda CIA1_PRB
cmp #%11111110
beq is1
cmp #%11110111
beq is2
lda #$FF
rts
is1:
lda #0
rts
is2:
lda #1
rts
is3:
lda #2
rts
|
| |
ws
Registered: Apr 2012 Posts: 110 |
You already solved it for your case, but maybe for future reference:
i found Shift key + one other key by Oswald to be pretty useful.
(Note: for some reason, "minikey" never worked reliably for me, reasons might be found below.)
Also this article is of general interest if one encounters problems : https://codebase64.org/doku.php?id=base:scanning_the_keyboard_t.. |
| |
tlr
Registered: Sep 2003 Posts: 1628 |
Quote: Thank you! However, meanwhile I made it up myself.
Here is my code:
lda #%11111101
sta CIA1_PRA
lda CIA1_PRB
cmp #%11111110
beq is3
lda #%01111111
sta CIA1_PRA
lda CIA1_PRB
cmp #%11111110
beq is1
cmp #%11110111
beq is2
lda #$FF
rts
is1:
lda #0
rts
is2:
lda #1
rts
is3:
lda #2
rts
a bit longer, but you leave $7f in $dc00 which is cleaner I suppose. |
| |
Krill
Registered: Apr 2002 Posts: 2534 |
How sensible is it to compare the keyboard matrix row bytes ($dc01) with literal values, rather than checking for individual bits to be clear?
This mostly depends on desired tolerance of key rollovers, i guess, and 1 vs 2 (same matrix column) would have to have a preferred default when both are pressed. |
| |
tlr
Registered: Sep 2003 Posts: 1628 |
Quote: How sensible is it to compare the keyboard matrix row bytes ($dc01) with literal values, rather than checking for individual bits to be clear?
This mostly depends on desired tolerance of key rollovers, i guess, and 1 vs 2 (same matrix column) would have to have a preferred default when both are pressed.
I guess for a key check with immediate action as opposed to keyboard input this is ok. If you hold 1 and 2 when the routine is entered nothing happens, but if repeatedly called then as soon as only one of them is pressed it will trigger. |
| |
Monte Carlos
Registered: Jun 2004 Posts: 330 |
There should only be reaction on non mistakable input. So it would be ok.
I think the cases structure in my code could be optimized away using ldx #0 and then inx on every unmatched condition. This would make it a little shorter. However, I needed it fast. So I didn't mind. |
| |
Silver Dream !
Registered: Nov 2005 Posts: 106 |
If you have system vars intact then even w/o IRQs:
: JSR $FF9F ; SCNKEY
JSR $FFE4 ; GETIN
BEQ :-
CMP #$34 ; >= code for '4'?
BCS :-
CMP #$31 ; < code for '1'?
BCC :-
AND #$0F ; optional
|
| |
TheRyk
Registered: Mar 2009 Posts: 1716 |
Quoting Monte Carlos...
I'm working with this keyboard matrix: https://sta.c64.org/cbm64kbdlay.html
Especially as you're German, I've always found this one useful:
https://www.c64-wiki.de/wiki/Tastatur#Schaltung
much clearer imho than the English equivalent
https://www.c64-wiki.com/wiki/Keyboard#Keyboard_Matrix
@Silver-Dream: KERNAL stuff of course often does it as well (i.e. if you can and want to use ROM in your situation), but I thought TS really wanted to remember how to do it properly by reading CIA regs without accessing ROMs |
| |
TWW
Registered: Jul 2009 Posts: 514 |
Quoting Monte CarlosThere should only be reaction on non mistakable input. So it would be ok.
Only way to ensure there is no shadowing (wrongfully reported keys due to 3 keys or more being pressed simultaneously), is to check the entire matrix. Kernal will not help wth this. |