Re: A83: Simple Routine Help


[Prev][Next][Index][Thread]

Re: A83: Simple Routine Help




On 02-Jun-99, you wrote:

> Hey All, this simple routine has been frustrating me for like a week because 
> it looks like it should work, could somebody look through it and help me 
> figure out why it wont...?  The routine first goes into a loop checking all 
> the keyports of Port 1, and seeing if they are not 255, noting that a key has 
> been pressed. I'm pretty sure that works fine (although the SCF may not be 
> necessary), but the problem is in the next part.  After it jumps out of that 
> first loop, B contains the current Keyport of the key that was pressed, and A 
> contains the Key Value of the key. I then load the Key Value into C, continue 
> to check A at the Keyport in B, and see how it compares to C. My purpose in 
> this part is that it should keep cycling in the second loop until that key is 
> Released. This is intended so that there wont be repeated functions occuring 
> later on if the key is held down. However, the routine will just not stop and 
> wait for it to be releasedt, and continues to exit after any key has been 
> pressed. Can someone help me figure out why? Here's the routine...

> ;-------------(Direct_Input_Waitkey)------------;
> ; 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_Loop: ld b, a \ ld c, a
>     call Direct_Input
>     cp 255 \ jr nz, D_I_Key
>     ld a, c \ SCF \ RLCA
>     cp 127 \ jr z, D_I_Waitkey
>     jr D_I_Loop
> D_I_Key:
>     push af \ ld c, a \ push bc
> D_I_Key_Loop:
>     call Direct_Input
>     cp c \ jr z, D_I_Key_Loop
>     pop bc \ pop af \ ld a, b
>     ret
> Direct_Input:    ;Input: Keyport Value in B, Output: Key Value in A.
>     ld a, 0FFh
>     out (1), a
>     ld a, b
>     out (1), a
>     in a, (1)
>     ret

> Thanks Alot, 
> Jason_K  =)


The keys will bounce. This hardware problem can be worked around by for
example waiting a couple of milliseconds before D_I_Key_Loop.

Linus
-- 
                                                           wwww 
                                                          (o)(O)
.-->                                           .-------mm--(__)--mm--------.
| Linus Akesson                                | http://linusworld.cjb.net |
`---------------^-- ----- --- --  -- -  -   -  `---------ooO--Ooo----------'
  Love your enemies: they'll go crazy trying to figure out what you're up
  to.



References: