I need a suggestion about an ML keyboard routine in my tetris game as I'm completely lost.
My main issue is that the GETIN kernel routine seems inadequate because keys are subject to "repeat delay" and "repeat speed", resulting in a slower motion than I want (this happens when e.g. the left key is kept pressed).
I tried with SCNKEY reading locations 197 and 653 but game became too fast and unable to identify when key is "released". For example pressing the key to drop the piece it will drop several pieces at once.
I think I will have the same problem when I'll implement joystick support.
To make things more complicate, I'm trying to make it work with cursor keys, so to be able to play the game in Vice, but looks like Vice has a bug with cursor up and left because they are "shifted".
I need a suggestion... how do you do keyboard and joystick in your games?
thank you
Suggestion for a keyboard routine
Moderator: Moderators
I'm always using $C5 (197) for keyboard input, you have to have some sort of delay.
My main loop looks like that:
Regarding cursor keys and VICE: That's no bug as on the real VIC keyboard cursor left and cursor up are shifted keys! So you get the same scancode for cursor left and cursor right and have to check additionally for shift key. (That's what I ahve done in LCE, works pretty good on VICE and real VIC).
My main loop looks like that:
Code: Select all
lda #1
sta Delay
Main: lda $9004
bne Main
jsr GetKey
jsr GetJoy
; handle Keyboard and Joystick
jmp Main
; Decrease delay counter, when zero check for key
; if key pressed (ScanCode<>64) set Delay counter
; this leads to fast reaction on keypress but some sort
; of delay after each keypress
GetKey:
lda Delay
beq CheckKey
dec Delay
lda #0
rts
CheckKey:
lda $C5
pha
cmp #64
beq NoKey
lda #6
sta Delay
NoKey:
pla
rts
; something similar for Joystick
Regarding cursor keys and VICE: That's no bug as on the real VIC keyboard cursor left and cursor up are shifted keys! So you get the same scancode for cursor left and cursor right and have to check additionally for shift key. (That's what I ahve done in LCE, works pretty good on VICE and real VIC).
thank you for the code snippet, it clears all the confusion in my mind 
As for the Vice bug I mentioned before, I was referring to the fact that sometimes left arrow on pc keyboard produces "cursor right" on the vic20 emulated screen. This weird behaviour is annoying me because occurs very often. I don't know if it's just me, but in the list of Vice "known bugs" it's reported that shifted keys (like f2 or cursor left/up) are sometimes wrongly interpreted by the keyboard routine because both "shift" and "key" are triggered on the same cpu cycle.

As for the Vice bug I mentioned before, I was referring to the fact that sometimes left arrow on pc keyboard produces "cursor right" on the vic20 emulated screen. This weird behaviour is annoying me because occurs very often. I don't know if it's just me, but in the list of Vice "known bugs" it's reported that shifted keys (like f2 or cursor left/up) are sometimes wrongly interpreted by the keyboard routine because both "shift" and "key" are triggered on the same cpu cycle.
I usually don't use the Kernal routines, but initially store apropriate value in $9121 to be able to read certain columns of the keyboard from $9120 (or is it the other way round? I always forget...) This is useful if you only need to check a limited number of keys, not the whole keyboard.
This way you can check for key-combinations aswell, since each key has its own bit in the register. Don't remember which bits each key is mapped to, but if [cursor right] has the value of (255-) 8 and [shift] has the value of (255-) 4, then "cursor left" keypress will have the value (255-) 12.
(Subtracting from 255 because a pressed key makes the bit go zero.)
I simply assign each key combination which has a meaning in my program to a label, whether it's in fact a single key or a combination of several keys. Like this:
crsr_left = 12
crsr_rght = 8
return = 2
shift_ret = 6
...and so on
If I set the output register to enable more than one column on the keyboard, more than one key will give the same value. But this does not matter as long as each key actually used has a unique number.
If I want a keypress to be interpreted only once, I store its value and compare with that the next time. If it's equal, the subroutine returns "no key". If I want a repeat delay, I reset a counter each time a new key is pressed, and when the counter reaches zero, the routine returns the key number each time.
This way you can check for key-combinations aswell, since each key has its own bit in the register. Don't remember which bits each key is mapped to, but if [cursor right] has the value of (255-) 8 and [shift] has the value of (255-) 4, then "cursor left" keypress will have the value (255-) 12.
(Subtracting from 255 because a pressed key makes the bit go zero.)
I simply assign each key combination which has a meaning in my program to a label, whether it's in fact a single key or a combination of several keys. Like this:
crsr_left = 12
crsr_rght = 8
return = 2
shift_ret = 6
...and so on
If I set the output register to enable more than one column on the keyboard, more than one key will give the same value. But this does not matter as long as each key actually used has a unique number.
If I want a keypress to be interpreted only once, I store its value and compare with that the next time. If it's equal, the subroutine returns "no key". If I want a repeat delay, I reset a counter each time a new key is pressed, and when the counter reaches zero, the routine returns the key number each time.
- Schema
- factor
- Posts: 1440
- Joined: Tue Mar 23, 2004 7:07 am
- Website: http://www.jammingsignal.com
- Location: Toronto, Ontario
Are you using the VICE monitor? I find that VICE sometimes 'remembers' the state of the SHIFT key if I happen to be holding it when I break into the monitor. Then when you return to the emulated VIC, the keys act funny until you reset.nippur72 wrote: As for the Vice bug I mentioned before, I was referring to the fact that sometimes left arrow on pc keyboard produces "cursor right" on the vic20 emulated screen.
I've investigated more on the Vice shift-key bug. It appears to be more evident with the left cursor key. Indeed, if you quickly press on the pc keyboard the sequence left, up, left, up, ... the cursor on the emulated screen describes instead a right-up diagonal.
I should mention that I use an italian keyboard, so perhaps it's a problem with that.
Anyway the bug doesn't manifest in emulated plus/4, or c-128 which have different keymappings.
I've partially solved by changing the keyboard file "win_pos.vkm"
from
into
I should mention that I use an italian keyboard, so perhaps it's a problem with that.
Anyway the bug doesn't manifest in emulated plus/4, or c-128 which have different keymappings.
I've partially solved by changing the keyboard file "win_pos.vkm"
from
Code: Select all
92 7 2 1 /* Left -> CRSR LEFT */
Code: Select all
92 7 2 6 /* Left -> CRSR LEFT */