[A83] Re: Repetative keys.
[Prev][Next][Index][Thread]
[A83] Re: Repetative keys.
> Yeah,=20
> I 've thought of using direct input, but the disadvantage 
is that
> it would require quite a deal of code.
> 
Wrong. Unless you consider 20 lines a great deal. Here's a 
nice solution for you.
http://www.extra.hu/cobb/input.inc
How to use?
Simply call ReadKeyboard which fills the array at 
KeyPressed.
To verify a key (an example):
call ReadKeyboard         ; filling the array
ld a,(KeyPressed+1)       ; choosing the appropriate byte
and 64                    ; selecting the bit (bit 6)
jr z,Clear_is_being_pressed
You can also use this to handle multiple keypresses:
call ReadKeyboard         ; filling the array
ld a,(KeyPressed)
and 1                     ; bit 0
call z,Press_Down
ld a,(KeyPressed)
and 8                     ; bit 3
call z,Press_Up
ld a,(KeyPressed)
and 2                     ; bit 1
call z,Press_Left
ld a,(KeyPressed)
and 4                     ; bit 2
call z,Press_Right
In this case, all the Press_XXX subroutines will be called 
whose arrow was pressed. Note that the subroutines should 
not use ReadKeyboard, although it wouldn't cause much 
problem.
If you want non-repetitive keys with direct input:
call ReadKeyboard
call ValidateKeys
ld a,(ValidKey+1)         ; choosing the appropriate byte
and 64                    ; selecting the bit (bit 6)
jr z,Clear_was_once_pressed
note that you have to use ValidKey instead of KeyPressed; 
you can still use KeyPressed for repetitions.
if you put this in a loop like:
MAINLOOP:
call ReadKeyboard
call ValidateKeys
; ... doing the checks and calling the subroutines
jp MAINLOOP
you have to release the keys to be able to detect the next 
keypress in the ValidKey table.
PG
References: