I'm trying to implement game controls using kernel routines in Commodore 64.
Below code works with one exception. Each key stroke counted as single input. e.g.: There is no effect if you keep holding the button. You had to release and press again for each move. How can I change this behaviour? Simply I want to repat the action as long as the key held down.
GETIN = $FFE4
SCNKEY = $FF9F
keyScan:
jsr SCNKEY ;get key
jsr GETIN ;put key in A
cmp #65
beq left
cmp #68
beq right
jmp keyScan
SCNKEY
isn't suitable for games that require multiple simultaneous key input. It's stateless and simply returns 'the' key that is pressed now — i.e. if two are pressed, it'll tell you only one, and officially makes no guarantee as to which. The best you could do is consider a key still pressed untilSCNKEY
reports either that something else is pressed or that nothing is, but it'd be even odds as to whether a second simultaneous keypress is ignored or replaces the first.If your program doesn't fit the orthodoxy of there only ever being 'the' key that is pressed, you'll have to hit the hardware yourself. Codebase64 offers some example code; my summary version is (having set up the CIA correctly, though it'll likely be appropriately configured already):
A generic routine would need to test each row individually to avoid shadowing — suppose you asked to read rows 4 and 5 at the same time by storing 0s to DC00 in bits 3 and 4, and the result you got back had the top bit clear, you wouldn't know whether v or n or both were pressed, only that at least one of them is.
See the very bottom of the same link as above for a table of the rows and columns on an English-language keyboard; they're the result of the physical key layout so other languages will vary as much as their keyboards do. If you're writing a game and you're more interested in the layout of the keys than their symbols then you needn't worry about the language.