How to check key pressed (positive transition)

Door albs_br

Champion (499)

afbeelding van albs_br

21-05-2023, 17:46

Hi guys,

I'm trying to get a key press, but it is triggering multiple times.
The way I think it would solve is by checking if on OLDKEYS it was released before.

This way I should get only one trigger, on positive transition (key pressed).


    ld      a, (BIOS_NEWKEY + 8)
    bit     7, a
    jp      z, .keyPressed


    ; check if key was previously released
    ld      a, (BIOS_OLDKEY + 8)
    bit     7, a
    ret     z

    ; execute key pressed code here
    call    BIOS_BEEP


But is not working. Any ideas?

Aangemeld of registreer om reacties te plaatsen

Van MsxKun

Paragon (1134)

afbeelding van MsxKun

21-05-2023, 18:27

Don't trust OLDKEY. Save the old key values into RAM by yourself, to be sure.

Try something like this... Returns 0 if not pressed or if at past check the key was also already pressed.

   call    .CHK
   or      a
   ret     z
   jp      BEEP

   ld	a,(PRESSED)		   ; saved value before current check, so = old status
   ld	b,a
   ld	a,(BIOS_NEWKEY + 8)	; Value stored by BIOS
   and	10000000b	   ; Keep only bit 7
   ld	(PRESSED),a		   ; Saves press status

   ld	c,a			           ; readed value again
   and	b			   ; old value
   xor	c			                        

Van aoineko

Paragon (1138)

afbeelding van aoineko

22-05-2023, 07:51

OLDKEYS is reset by the BIOS in the interrupt handler so, unfortunately, you can't use it.

Van albs_br

Champion (499)

afbeelding van albs_br

22-05-2023, 13:44

Thanks for all help guys.

@MsxKun sugestion solved the problem.