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 > cursor-control.
2003-04-04 07:16
Testicle
Account closed

Registered: Sep 2002
Posts: 131
cursor-control.

well, for a diskmag-system i want the user to be able to use both joystick and/or cursor-keys to choose chapters.

joystick is no problem, but then i tried to implement the cursor-function:

.keyboard lda $c5
cmp #7
beq .leftright
cmp #2
beq .updown
cmp #1
beq .jfire
rts
.leftright lda $028d
and #1
bne .jleft
jmp .jright
.updown lda $028d
and #1
bne .jup
jmp .jdown


first i used this function during the irq, but it didn't work. now i use this function beside my irq-routines, but nothing happens.

do i have to set special registers to get access to the cursor-keys or something like that?!?
2003-04-04 07:34
Oswald

Registered: Apr 2002
Posts: 5017
I always used the kernal to read the keyboard for such stuff.. there are 2 routines for that

- scnkey: you must call this one from your irq routine, this one scans the keyboard for pressed keys

- getin: and this one gives you the petscii codes of the pressed keys

so it will look like this

irq:
blah
...
jsr scnkey
...
blah

main prog:

jsr getin
cmp #"<crsr left>"
beq left
cmp #"<crsr up>"
beq up
...
etc

its the same as in basic :) you dont have to check for shift seperately.
2003-04-04 10:27
yago

Registered: May 2002
Posts: 332
The getin method is new to me (and a good Idea).

If you want to use the commodore keyboard read,
you need to end one of your irqs with
JMP $EA31

The other irqs should be ended with
JMP $EA81

Please note that the kernel must be switched in, so you need to change irq-vector at $314 instead of $fffe.

Have Fun,
Zed Yago
PS: Please correct me, if sth is wrong, written out of my head!
2003-04-04 11:12
Krill

Registered: Apr 2002
Posts: 2839
If i have to only check some keys for cursor control, i never use the kernel. Direct access of the key matrix is faster and it doesnt interfere with joy 1 input like the kernel input routine does due to poor coding. There is a way to have keyboard, joy 1 and joy 2 input simultaneously, if you use the data direction registers wisely (basically, put the negated $dc00 value to $dc02) to prevent joy 1 from interfering with the keyboard input.
2003-04-04 15:20
Testicle
Account closed

Registered: Sep 2002
Posts: 131
ah, jmp $ea31 solves my problem! :-)


usually i use either $ea7e or $ea81 to end my raster-irq, but i actually never knew the differences.

can somebody tell me?


and: when is it useful to use $fffe/$ffff as irq-vectors?
2003-04-04 15:37
cadaver

Registered: Feb 2002
Posts: 1153
When you want to use RAM behind Kernal, or want to save CPU cycles.
2003-04-04 16:11
Krill

Registered: Apr 2002
Posts: 2839
Quote: ah, jmp $ea31 solves my problem! :-)


usually i use either $ea7e or $ea81 to end my raster-irq, but i actually never knew the differences.

can somebody tell me?


and: when is it useful to use $fffe/$ffff as irq-vectors?


A look into the kernel using a monitor usually helps answering those questions... :b and the kernel is for weenies... *states* ;)
2003-04-05 15:21
yago

Registered: May 2002
Posts: 332
Quote: A look into the kernel using a monitor usually helps answering those questions... :b and the kernel is for weenies... *states* ;)

There are also some excellent Books about the cbm-kernel, which explain the routines and zp-addresses.
I agree, IMHO nowaday PC-Demos are not "real" Demos, because they use DirectX etc.
2003-04-07 06:00
Seven

Registered: Jan 2002
Posts: 201
yeah! and they use C instead of assembly! damn them!
2003-04-07 07:58
Oswald

Registered: Apr 2002
Posts: 5017
krill: oh well, then Im a weenie :)) but why would I sit down and code a keyboard scan routine, if its just about 2 jsr ? :)

$ea31 will call several kernal routines, cursor blinking, scnkey and the likes..

$ea81 is just: pla tay pla tax pla rti
$ea7e is a bit better with lda $dc0d in front of the earlier :)
2003-04-07 08:17
Testicle
Account closed

Registered: Sep 2002
Posts: 131
@Oswald: yes, i looked at the kernel and saw the differences. now i've got another question: is it necessary to end a raster-irq-routine with jmp $ea7e (or whatever) or can i directly use "rti" instead? i'm not sure, if the three missing pla's (from jmp $ea7e/81) would do any harm?

well, ofcourse i could give it (the "rti" i mean) a try, but then i would probably not know, if it really works or if it was just pure chance that nothing went wrong...
2003-04-07 09:07
MagerValp

Registered: Dec 2001
Posts: 1055
It'd just crash with a bare RTI, as in the beginning of the IRQ routine you have PHA TXA PHA TYA PHA. You have to restore them before exiting.
2003-04-07 10:50
Ninja

Registered: Jan 2002
Posts: 404
Krill: Well, I think some troubles are unavoidable using Joy1 and Keyboard even with data-direction registers. If the joy is pressed up and so the line is low, how can you check if e.g. "DEL" is pressed at the same time?
2003-04-07 11:51
Testicle
Account closed

Registered: Sep 2002
Posts: 131
@MagerValp: ah, understand! thanks! :-)
2003-04-07 13:41
Oswald

Registered: Apr 2002
Posts: 5017
testicle:
the kernal irq at its start pushes a,x,y regs to the stack on top of the return address, if you dont pull those values out, the code will continue to run un some random location, instead of the correct return addy...

ofcourse you can have your own irq routine, just
turn back the kernal when you want to use it, and jsr it..

(when not in irq we have $35 in $01, using fffe/ffff as vectors)

irq pha
txa
pha
tya
pha
...

lda #$36
sta $01
jsr kernal
lda #$35
sta $01
pla
tay
pla
tax
pla
rti

sorry, if this is was too straightforward 2 you :)
2020-04-26 23:23
Digger

Registered: Mar 2005
Posts: 421
@Oswald: Hmmm, I've tried your last example with JSR $ffe4 but it just returns $00 all the time, what am I doing wrong? Cheers!
2020-04-26 23:31
JackAsser

Registered: Jun 2002
Posts: 1989
@digger: necro-poster of the year! Congrats! :)

For custom keyscan I recommend Codebase and TLR’s routine.
2020-04-27 09:08
Oswald

Registered: Apr 2002
Posts: 5017
Quote: @Oswald: Hmmm, I've tried your last example with JSR $ffe4 but it just returns $00 all the time, what am I doing wrong? Cheers!

ffe4 is getin, reads a character from the input buffer.

but you also need to call SCNKEY (ff9f) from a raster irq (or with similar frequency), SCNKEY does scan the keyboard and fills up the input buffer.

(2nd post in here I explain same thing :P )
2020-04-27 10:59
Digger

Registered: Mar 2005
Posts: 421
@Oswald: Ahhh makes sense, thx!

@JackAsser: Hehe, still within this millennium though. I wanted to avoid any foreign code to save some bytes, since I don't need to read all the keys. Will give it a go. Kernal's SCNKEY seems to take a lot of rastertime actually.
2020-04-27 12:43
Fresh

Registered: Jan 2005
Posts: 101
For sure not the most accurate and possibly fast implementation, but it's a bit more reliable than C64 kernal version.
Moreover, I'm far to be a CIA guru, but I'm with ninja: I'm not sure you can 100% avoid joy1/keyboard collisions.
But I'd love to be proved wrong! :)

Here's the code, part of my 1541U2 Mod Player: routine GetKeyJoy, (set GKJtemp to any free location).

https://bitbucket.org/freshness79/mod-player/src/master/keyboar..
2020-04-27 16:48
Krill

Registered: Apr 2002
Posts: 2839
Quoting Fresh
I'm with ninja: I'm not sure you can 100% avoid joy1/keyboard collisions.
If simultaneous JOY1 and keyboard input isn't required, then i guess this can be done.

$DC00 (output) selects keyboard matrix column, then $DC01 (input, also JOY1) reflects pressed keys in the bits corresponding with the keybard matrix row.

Now, if no column is selected ($DC00 set to $ff) and $DC01 reads $ff, then JOY1 isn't active.
Do the required keyboard scans, then re-check if JOY1 still isn't active. Use the scanned keys if so, discard if JOY1 was active.

Oh, and you can also scan keys on the top 3 matrix rows without having to worry about JOY1 interference, as it isn't connected to bits 7..5 of $DC01. =)
2020-04-27 17:34
chatGPZ

Registered: Dec 2001
Posts: 11114
You can also do more fun stuff by scanning the keyboard in different ways than the standard way - see https://sourceforge.net/p/vice-emu/code/HEAD/tree/testprogs/CIA.. (this doesnt work very well in any emulator)
2020-04-27 20:26
Fresh

Registered: Jan 2005
Posts: 101
Quoting Krill
If simultaneous JOY1 and keyboard input isn't required, then i guess this can be done.

$DC00 (output) selects keyboard matrix column, then $DC01 (input, also JOY1) reflects pressed keys in the bits corresponding with the keybard matrix row.

Now, if no column is selected ($DC00 set to $ff) and $DC01 reads $ff, then JOY1 isn't active.
Do the required keyboard scans, then re-check if JOY1 still isn't active. Use the scanned keys if so, discard if JOY1 was active.

That's exactly the approach I used in the code I linked in my previous post: I read CIA 1 port B before and after checking keyboard, if both reads are $ff I can consider reliable the keyboard data.
This indeed works but if you use both keyboard and joystick simultaneously, only the status of the latter will be read.
Yes, you can scan a limited number of rows but again, it won't be the 100% I mentioned before either.
2020-04-27 23:28
Krill

Registered: Apr 2002
Posts: 2839
Yes yes, the disclaimers remain valid.

Quoting Fresh
That's exactly the approach I used in the code I linked in my previous post
Which... wasn't quite so obvious from the barely-commented code, to be honest. =) So apologies for stating in prose what your code does in... code. :D
2020-04-28 13:45
Fresh

Registered: Jan 2005
Posts: 101
Quoting Krill
Which... wasn't quite so obvious from the barely-commented code, to be honest.

Ehm... Touchez :D
2020-04-28 14:39
Frantic

Registered: Mar 2003
Posts: 1627
Quote: @digger: necro-poster of the year! Congrats! :)

For custom keyscan I recommend Codebase and TLR’s routine.


@Jackasser: What article do you refer to here?
2020-04-28 14:51
JackAsser

Registered: Jun 2002
Posts: 1989
Quote: @Jackasser: What article do you refer to here?

TWW/CTR ffs. Sorry. :D https://codebase64.org/doku.php?id=base:scanning_the_keyboard_t..
2020-04-28 15:40
Oswald

Registered: Apr 2002
Posts: 5017
3 key rollover is an overkill in most cases. usually you need this for menus or simple navigation, not for a text editor for fast typers :)
2020-04-28 18:25
JackAsser

Registered: Jun 2002
Posts: 1989
Quote: 3 key rollover is an overkill in most cases. usually you need this for menus or simple navigation, not for a text editor for fast typers :)

Indeed. I use that routine in EotB but extended to support c128 keyboard also.
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
icon/The Silents, Sp..
Endurion
Grue/Extend
Alias Medron/Padua
YPS
Airwolf/F4CG
csio/monarchy c+4
Guests online: 119
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Bromance  (9.6)
10 Memento Mori  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Rainbow Connection  (9.5)
7 Onscreen 5k  (9.5)
8 Wafer Demo  (9.5)
9 Dawnfall V1.1  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Logo Graphicians
1 Sander  (10)
2 Facet  (9.7)
3 Mermaid  (9.4)
4 Pal  (9.4)
5 Shine  (9.3)

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