| |
Iapetus/Algarbi/Wood
Registered: Dec 2004 Posts: 71 |
Reading the Keyboard - no roms/kernal
Hey guys,
I need to read the key presses without using the kernal routines, can someone post a routine or write how to do it? Thank you |
|
| |
chatGPZ
Registered: Dec 2001 Posts: 11386 |
look here: http://unusedino.de/ec64/technical/aay/c64/keybmatr.htm
the standard way to do it is programming cia1/port a ($dc00) as output and port b ($dc01) as input.
then you output a bit in port a, and read port b. depending what you have read you can determine which key in the matrix has been set.
mmh that said, if i recall correctly the whole thing is low active, so you actually output all but one bit set, and in port b each zero bit means a pressed key in that column.
now for an actual keyboard scanner....it pretty much depends on what you need :) it can be dead easy (but slow, and only one key, and no shift states) to quite tricky (but fast, and handling more than one key at once). i recommend playing with it, its a good exercise =P |
| |
Frantic
Registered: Mar 2003 Posts: 1648 |
There is an article in one of the C=Hacking issues about a keyboard routine. This routine is maybe a little bit more fancy than a routine that you might have had in mind, but the code there there should still give you a very good hint on how to read the keyboard in a good and stable way (it has some key debouncing code for example, which might be useful in many kinds of programs).
Here:
http://codebase64.org/doku.php?id=magazines:chacking6#three-key..
|
| |
Iapetus/Algarbi/Wood
Registered: Dec 2004 Posts: 71 |
Thank you guys I will check those links.
I think I will need to read two or three keys together tho in one place........ that makes it sound more complicated from what you said Groepaz. |
| |
Frantic
Registered: Mar 2003 Posts: 1648 |
Nah.. not so complicated. The approach used by the routine I posted a link to simply scans the keys until it finds one that is pressed (unless that is a shifkey; it will continue scanning), but you could equally well just scan through all possible keys if you want/need to. |
| |
Iapetus/Algarbi/Wood
Registered: Dec 2004 Posts: 71 |
I have looked at those routines Frantic and I decided to use the "slow" one but I couldn't figure out how it works. I was reading from teh scan table but I was getting just two number for each row of keys alternating, for example if I pressed S I would get 32 then if I press D I get 2 or 4 I don't remember but if I press F I will get again 32 and so forth....
I must be doing something wrong |
| |
Stryyker
Registered: Dec 2001 Posts: 468 |
Check the link Groepaz linked to. You will need to write to $DC00 and read from $DC01 8 times to check for each keypress. As someone mentioned it uses active low for a keypress. A simple EOR #$FF should make it friendlier result where you expect keypresses to be a 1 and not a 0. 8 bit registers. With 8 different bits to set in $DC00 and 8 bits read from $DC01 gives you 64 keys.
In the 8x8 grid if you press 3 keys a
XX
X-
pattern (or a combination) similarly rotated the - will read as a keypress. Some places call it ghost keys.
From the Groepaz map I think it works like lda #$7f (bit 7 clear reading the left column in the table), sta $dc00, lda $dc01, if bit 5 is not set then the Commodore key is pressed.
Basically you clear the bit for the row to test for and any key presses clear the bit in row.
lda #$ef, sta $dc00 clears bit 4 which allows
|Bit 4| N | O | K | M | 0 | J | I | 9 |
to be tested for.
lda $dc01. If bit 7 is clear then N is pressed.
It is up to you on how you decode the result. From what Groepaz linked to you would expect S to be 32 and D be 2. 8 bits can only detect 8 keys at a time.
|
| |
Iapetus/Algarbi/Wood
Registered: Dec 2004 Posts: 71 |
Thank you Stryyker |