Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user Sepa ! (Registered 2024-05-13) 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: 11136
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: 1628
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: 1628
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: 465
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
lft
Aomeba/Artline Desig..
iAN CooG/HVSC
Impetigo/Crescent
fegolhuzz
Mibri/ATL^MSL^PRX
Sepa
Sokrates
Doc Snyder/ONS
JackAsser/Booze Design
Thierry
Jammer
Raf/Vulture Design
psych
Exile/Anubis
Mr. SID
El Gato
Youth
Ghost/Quantum
Nith/TRIÉ…D
Guests online: 104
Top Demos
1 13:37  (9.8)
2 Next Level  (9.8)
3 Mojo  (9.7)
4 Coma Light 13  (9.7)
5 Edge of Disgrace  (9.6)
6 Comaland 100%  (9.6)
7 Uncensored  (9.6)
8 No Bounds  (9.6)
9 Wonderland XIV  (9.6)
10 Bromance  (9.5)
Top onefile Demos
1 Party Elk 2  (9.7)
2 It's More Fun to Com..  (9.6)
3 Cubic Dream  (9.6)
4 Layers  (9.6)
5 Copper Booze  (9.5)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Rainbow Connection  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Booze Design  (9.3)
3 Nostalgia  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Original Suppliers
1 Black Beard  (9.7)
2 Derbyshire Ram  (9.5)
3 hedning  (9.2)
4 Baracuda  (9.1)
5 Jazzcat  (8.6)

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