Page 3 of 3

Re: Read multiple keys from keyboard?

Posted: Mon Jun 03, 2024 12:10 pm
by unartic
If you restore A when done with your handler and chain the original handler, I recon GET will still work.

Re: Read multiple keys from keyboard?

Posted: Tue Jun 04, 2024 6:45 am
by voidstar
I do, or at least intended to.

The handler starts and ends like this:

Code: Select all

pha
phx
...
(some reg.A and X manipulations)
...
plx
pla

rts

When the BASIC program ends, I noticed the System ROM "pukes out" a bunch of buffered keystrokes. Not sure if that's a clue on what might be going wrong.

Re: Read multiple keys from keyboard?

Posted: Tue Jun 04, 2024 8:35 am
by unartic
That does make sence.

Normaly when a program is running any keypresses are buffered. As soon as the buffer is being read (GET) the buffered keys are retrieved and the buffer is emptied.

So in you isr you should set A to zero is you have 'used' the keypress (key is not stored into the buffer) or leave A as it is if you;ve not used the key (key is stored in buffer).

So you should use a flag indicating if you are using your multikey detection function (zero A) or not.

Or you can just set and restore the vector each time you want to check your multiple key input and always set A to zero.

Re: Read multiple keys from keyboard?

Posted: Tue Jun 04, 2024 4:31 pm
by Stefan
That's true.

The custom keycode handler is the simplest of constructions in the Kernal code, as shown below.

The last IBM key number is fetched from RAM where it's stored in ps2data_kbd. Near the end of the function, the code makes an indirect jump to the address pointed to by the keyhdl vector. By default that vector is pointing to the rts on the last line of the function.

When return from a custom keycode handler, the values of A, X, and Z will be interpreted according to the function description. Currently X is ignored as there are no two byte key codes. Maybe we should clear X not create future incompatibility problems.

Code: Select all

;*****************************************
; FETCH KEY CODE:
; out:  A: key code (0 = none)
;         bit 7=0 => key down, else key up
;         A = 127/255 => extended key code
;         X: Extended key code second byte
;         Z: 1 if no key
;*****************************************
fetch_key_code:
	lda ps2data_kbd_count
	beq receive_scancode_resume

	lda ps2data_kbd
	beq receive_scancode_resume

 	jmp (keyhdl) ;Jump to key event handler
receive_scancode_resume:
	rts

Re: Read multiple keys from keyboard?

Posted: Wed Jun 05, 2024 8:35 am
by voidstar
Got it. Actually no issue for me using GET inline with the rest of this processing, all good.

And here is a revised handler. Still not bit packed, but removes the need to bother about what key was actually pressed (works as long as we have under 256 keys! :) IBM set is only defining about half of them up to $7F, so all good there )

And it is much faster and cleaner this way. I'm not sure if the bit-packing would really be faster (exchanging the STA $0600,X with a bunch of shifts??). But if the end-user needs more golden RAM for themselves, then it might become a necessary approach.

This is just the new handler itself, the handler-installer remains the same. But the usage on this approach is different - instead of PEEKing in $0404 + user-defined key index (and in the order the user defined them), instead PEEK into $0600 + IBM key index (so now all keys can be queried, but maybe not in a preferred order). (see the VSynth/Audio Synth project as a usage example)
Those key codes are the left column here:
https://github.com/X16Community/x16-rom ... eycode.inc


Code: Select all

.org $0500
pha
phx

bmi key_fs_set    ; check NEGATIVE flag

key_fs_clear:
tax                ; will use reg.A as-is as offset into $0600
lda #1            ; let reg.A == 1, key was pressed
jmp key_store_1

key_fs_set:
and #$7F           ; clear the negative masks on the key
tax                  ; will use X as offset into $0600
lda #0              ; let reg.A == 0, key was released

key_store_1:
sta $0600,X     ; mem[$0600+x] = reg.A  (the flag state offset by the IBM key code)

plx
pla

rts

Re: Read multiple keys from keyboard?

Posted: Mon Aug 19, 2024 1:25 pm
by funkheld
hello, good day.

I'm looking for the finished cc65 compiler for windows.
where can I download it please?

thanks.
greetings