Keyboard debouncing in ZX ROM ?

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
catmeows
Manic Miner
Posts: 711
Joined: Tue May 28, 2019 12:02 pm
Location: Prague

Keyboard debouncing in ZX ROM ?

Post 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.
Proud owner of Didaktik M
pobtastic
Drutt
Posts: 29
Joined: Fri May 29, 2020 8:21 pm
Location: United Kingdom

Re: Keyboard debouncing in ZX ROM ?

Post 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.
User avatar
RMartins
Manic Miner
Posts: 776
Joined: Thu Nov 16, 2017 3:26 pm

Re: Keyboard debouncing in ZX ROM ?

Post 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.
Post Reply