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 > Scan the keyboard
2006-07-25 15:03
stunt
Account closed

Registered: Jul 2006
Posts: 48
Scan the keyboard

Guys,

Right now i'm still using kernal routine $ffe4 to scan the keyboard, but ofcourse I'd rather avoid using kernal routines. So Scout suggested me inastead to scan the keyboard matrix ($dc00 and $dc01) directly.

Now i have:
keyscanloop
      lda $dc00 ; row
      and #%00100000
      bne continu
      lda $dc01 ; collumn
      and #%00000001
      bne continu
      jmp keyispressed
continu 
      jmp keyscanloop
keyispressed 
      ...


But this doesnt seem to be working.
What am i doin wrong?

Stunt
2006-07-25 15:49
Soren

Registered: Dec 2001
Posts: 547
you store a value in one of the adresses
and read from the other and do a compare.

To put it short :)

2006-07-25 15:50
Soren

Registered: Dec 2001
Posts: 547
example

lda #$xx
sta $dc00

lda $dc01
cmp #$yy

more or less..

2006-07-25 16:13
stunt
Account closed

Registered: Jul 2006
Posts: 48
ok, thanks jeff,
now i tried:

scankey
     lda #%00010000 ; row for character '0'
     sta $dc00

     lda $dc01
     cmp #%00001000 '; collumn for character '0'

     bne scankey

     lda #07
     sta 53280


So I want to change border colour to yellow when key '0' is pressed. But still it doenst work.

(For the values i used the matrix on http://sta.c64.org/cbm64kbdlay.html (very handy link that scout gave me).Did i pick the right values for key '0'?)

Stunt

2006-07-25 16:19
enthusi

Registered: May 2004
Posts: 675
no, you either mixed row/column or got the bit-order wrong
bit 0 = #%00000001
2006-07-25 16:30
Soren

Registered: Dec 2001
Posts: 547
the bits of the key(s) to check for has to be off.

so to check for 0 (zero)
do this:

loop lda #%11101111
sta $dc00
lda $dc01
cmp #%11110111
bne loop
rts
2006-07-25 16:33
stunt
Account closed

Registered: Jul 2006
Posts: 48
yes it's working now!!!!!!
thx!
O and another 1 question, what if i want to scan for 2 keys pressed at same time, for example scan for 'f8', which is f7+shift?

thx

Stunt
2006-07-25 16:40
Soren

Registered: Dec 2001
Posts: 547
That gets a bit tricky, as there is both left shift and right shift/shiftlock.
But there is a neat adress, $028d which can be used to check for shift/CTRL/Commodore
when it has value 01, a shift key is pressed, 02 -> commodore key is pressed. 04 -> ctrl is pressed.
And you can combine those values.
so possible you could first check for f7 by using dc00 and dc01, and then check if shift is pressed by using address $028d.

2006-07-25 16:52
stunt
Account closed

Registered: Jul 2006
Posts: 48
@ jeff: u rock. f8 is now working also :))
2006-07-25 16:54
enthusi

Registered: May 2004
Posts: 675
well 028d aint very helpful when you code the KB-scan to get rid of the kernal. sorry for being all negative and of little use.
2006-07-25 17:05
stunt
Account closed

Registered: Jul 2006
Posts: 48
@ enthusi:

Please explain.

And please also tell me what is your solution then to read shift+key?

Stunt

2006-07-25 17:11
stunt
Account closed

Registered: Jul 2006
Posts: 48
What about scanning for both left and right shift?
U experts tell me what is the fastest option?
Maybe the fastest option is not to use shift/key combinations at all?

The thing is that i have to be careful, i have so many things to do per frame and yet so little rastertime:

Lots of sidparamters are updated realtime (at least 4 times per frame but if possible some parameters have to be updated like 8 or more times per frame), midi implementation still has to fit in (but i will probably rely on hardware a lot for the midipart) and also more than 1 sidchips are going to be adressed and updated in the future (right now pimping c64 by adding extrasidchip for 3+ voice polyphony) so i have to be very efficient with time.
2006-07-25 17:15
enthusi

Registered: May 2004
Posts: 675
$028d is set (only) by kernal. Actually by the very same code more or less you want to avoid. And since Im in destructive mode I deliver no solution ;)
But no magic needed. Same concept. Only some combinations are tough or if you want to check shift OR shift-lock. A mere 2-keys at once can be sone the same way as you do it now. Just AND the values or check this forum in coding. I recall at least one thread about detecting 3 keys etc...
good luck
2006-07-25 17:15
tlr

Registered: Sep 2003
Posts: 1728
How about this?

scan:
        lda     #$ff
        sta     $dc02
        lda     #$00
        sta     $dc03

        ldy     #0
        lda     #$fe
sc_lp1:
        pha
        sta     $dc00
        lda     $dc01
        sta     tab,y
        iny
        pla
        sec
        rol
        bcs     sc_lp1
        sta     $dc00   ; =$ff
        rts
tab:
        ds.b    8

It will test each row, and store the result in tab.
Now you will have one '0' bit for each key in tab (row 0 -> 7).
Due to how the matrix works, not all combinations of keys can be detected properly.

Complete scanner program for the C64 (and DTV):
http://www.kahlin.net/daniel/dtv/keyjoy.php
2006-07-25 17:28
Soren

Registered: Dec 2001
Posts: 547
using tables is a good idea. There must be several ways to do
that, depending on your needs.

But just thought about the F8-thing.. you could do a check for right shift+f7
and a check for left shift+f7....
just to be sure.

;)
2006-07-25 17:30
enthusi

Registered: May 2004
Posts: 675
and if you need a table, dont generate it :)
copy it:
http://www.tkk.fi/Misc/cbm/docs/c64-diss.html#EB79
2006-07-25 18:32
stunt
Account closed

Registered: Jul 2006
Posts: 48
Quote: and if you need a table, dont generate it :)
copy it:
http://www.tkk.fi/Misc/cbm/docs/c64-diss.html#EB79


Hey guys all this help is great.

I wish one of you coders would show the same dedication to the question that is formulated in the last post of in my other recent thread here about modulation: --> How to players and trackers usually deal with these modulation issues? --> Bit-scaling? (sid related, but not nescesarily, not a question related to the battlestar galactica music btw;-)

(scroll down to the last post)

Stunt
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
csabanw
Thunder.Bird/HF/MYD!..
iceout/Avatar/HF
psenough
sebalozlepsi
Guests online: 111
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.7)
5 Edge of Disgrace  (9.6)
6 No Bounds  (9.6)
7 Aliens in Wonderland  (9.6)
8 Comaland 100%  (9.6)
9 Uncensored  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Happy Birthday Dr.J  (9.7)
2 Layers  (9.6)
3 It's More Fun to Com..  (9.6)
4 Cubic Dream  (9.6)
5 Party Elk 2  (9.6)
6 Copper Booze  (9.6)
7 TRSAC, Gabber & Pebe..  (9.5)
8 Rainbow Connection  (9.5)
9 Dawnfall V1.1  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Nostalgia  (9.4)
2 Oxyron  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 SHAPE  (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.043 sec.