Keyboard debouncing in ZX ROM ?

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

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.
0 x

Posts: 8
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
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.
1 x

User avatar
Manic Miner
Posts: 468
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.
0 x

Post Reply