Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Reading the Keyboard - no roms/kernal
2007-07-23 22:35
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
2007-07-23 22:56
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
2007-07-24 07:29
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..
2007-07-24 09:29
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.
2007-07-24 10:44
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.
2007-07-24 11:36
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
2007-07-24 20:15
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.
2007-07-24 21:45
Iapetus/Algarbi/Wood

Registered: Dec 2004
Posts: 71
Thank you Stryyker
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Peacemaker/CENSOR/Hi..
REBEL 1/HF
marley
rexbeng
Shogoon/Elysium/MSL
Guests online: 118
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.3)
Top Coders
1 Axis  (9.8)
2 Graham  (9.8)
3 Lft  (9.8)
4 Crossbow  (9.8)
5 HCL  (9.8)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.063 sec.