Page 1 of 1

Keyboard debouncing in ZX ROM ?

Posted: Tue Sep 15, 2020 6:53 am
by catmeows
Hi, does any one understand how is KEYBOARD (02BFh) routine working ? Why it uses two KSTATE sets ?
I generally understand how debouncing in software should work but ZX ROM seems overcomplicated to me.

Re: Keyboard debouncing in ZX ROM ?

Posted: Tue Sep 15, 2020 4:59 pm
by pobtastic
It's explained in very nice detail here https://skoolkit.ca/disassemblies/rom/hex/asm/02BF.html
A double system of 'KSTATE system variables' (KSTATE0-KSTATE3 and KSTATE4-KSTATE7) is used from now on.
The two sets allow for the detection of a new key being pressed (using one set) whilst still within the 'repeat period' of the previous key to have been pressed (details in the other set).
A set will only become free to handle a new key if the key is held down for about 1/10th. of a second, i.e. five calls to KEYBOARD.

Re: Keyboard debouncing in ZX ROM ?

Posted: Thu Sep 17, 2020 12:38 am
by RMartins
Well, it's not actually doing debouncing, but key repeat management.

If you are reading a key once, every frame, you don't actually need to debounce it, since bouncing takes place in a lot less than 20ms.