Re: A83: wait 'til no key is pressed
[Prev][Next][Index][Thread]
Re: A83: wait 'til no key is pressed
In a message dated 2/20/00 5:06:30 AM Central Standard Time,
matthias.sauppe@gmx.de writes:
> Now I've written a new routine (code below). First, wait_clear waits for
> clear key, then it calls wait_no_keys_pressed. There is a small routine
that
> waits a few cycles, so I can ignore key 'bounces'. But it still won't work!
> And I don't know why. Could you tell me, please?
>
> Here's the code:
>
> wait_clear:
> ld a,0ffh
> out (1),a
> ld a,0fdh
> out (1),a
> in a,(1)
> cp 191
> jr nz,wait_clear
> call wait_no_keys_pressed
> ret
>
> wait_no_keys_pressed:
> call wait
> ld b,0feh
> call wait_for_row
> ld b,0fdh
> call wait_for_row
> ld b,0fbh
> call wait_for_row
> ld b,0f7h
> call wait_for_row
> ld b,0efh
> call wait_for_row
> ld b,0dfh
> call wait_for_row
> ld b,0bfh
> call wait_for_row
> call wait
> ret
>
> wait:
> ld a,255
> ld b,255
> wait_loop:
> nop
> nop
> nop
> nop
> dec a
> cp 0
> jp nz,wait_loop
> dec b
> ld a,b
> cp 0
> jp nz,wait_loop
> ret
>
> wait_for_row:
> ld a,0ffh
> out (1),a
> ld a,b
> out (1),a
> in a,(1)
> cp 255
> jp nz,wait_for_row
> ret
>
> Thanks for help!
>
>
> > Two things. Firstly the value read back is (as AsmGuru says) dependent on
> > which keys are pressed but your routine only works if that is the only
key
> > pressed in the appropriate "key row".
> ...
> > However, there is another issue. Keys "bounce". What this means is
> > when you press or release a key you get a short period where the
> > keys go on/off/on/off/on very fast (when the contacts are very close
I made a Direct Input Waitkey routine once and put it on the TCPA page,
however our webpage is down right now, so I'll past the code here, maybe it
will be of some use to you. If you wish to continue to use your routine, I
suggest just throwing some HALT commands in here 'n there, which should
detect the key-"up"s correct, alleviating any of the key bouncing. My code is
pasted below, cya...
Jason_K
;----------(Direct_Input_Waitkey v2.1)----------;
; Input: Nothing. Pauses until Any Key pressed. ;
; Output: C = Key Value, A and B = Port Value. ;
; Registers Destroyed: Only AF and BC Affected. ;
;-----------------------------------------------;
D_I_Waitkey:
ld a, 254
D_I_Loop1:
ld b, a
call Direct_Input
cp 255
jr nz, D_I_Waitkey
ld a, b
RLCA
cp 127
jr nz, D_I_Loop1
D_I_GetKey:
ld a, 254
D_I_Loop2:
ld b, a
ld c, a
call Direct_Input
cp 255
jr nz, D_I_Key_Pressed
ld a, c
RLCA
cp 127
jr z, D_I_Getkey
jr D_I_Loop2
D_I_Key_Pressed:
EI
ld c, a
D_I_Key_Loop:
halt
call Direct_Input
cp c
jr z, D_I_Key_Loop
ld a, b
ret
;----------(Direct_Input Routine v1.0)----------;
; Input: B = The Key Port Value to be Checked. ;
; Output: A = Key Value / State of the Keyport. ;
;-----------------------------------------------;
Direct_Input:
ld a, $FF
out (1), a
ld a, b
out (1), a
in a, (1)
ret