A86: keyboard input problem/question [reposted]


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

A86: keyboard input problem/question [reposted]





I am trying to make an input routine which can determine the current status
of the keyboard without pausing the keyboard. This is necessary in the
program I am making -- I want there to be a blinking cursor (not the default
system one.)

The algorithm I made so far works pretty well (except for the repetition of
characters -- I think I can fix that pretty easily, though,) however, when
you press Y it will show "YZYZYZYZYYZZYZ" etc and if you press Z, it shows
"Z Z ZZZ  Z  Z    Z" etc. Does anyone know how to fix this?

Here's my code. Thanks!!

----------------------------------------------------------------------------
-----------------------------------------------------------------------

Input_Loop:
; ld a,(CursorTime)
; inc a
; ld (CursorTime),a
; cp 0
; jr z, CursorBlink

  ld c,0
Input_PortLoop:             ;Get keys
ld hl,PortMasks
ld d,0
ld e,c
add hl,de
ld a,(hl)
out (1),a
in a,(1)
call CheckAllBits
inc c
ld a,5
cp c
jr nz, Input_PortLoop

ld a,%00111111                 ; Check for Exit because I don't want to get
stuck in the loop
out (1),a
in a,(1)
bit 6,a
jr nz, Input_Loop
ret

CheckAllBits:
ld b,0                                    ; I don't know a better way to do
this :-(
bit 5,a
jr z, GotKey

ld b,1
bit 4,a
jr z, GotKey

ld b,2
bit 3,a
jr z, GotKey

ld b,3
bit 2,a
jr z, GotKey

ld b,4
bit 1,a
jr z, GotKey

ld b,5
bit 0,a
jr z, GotKey


ret
GotKey:
ld hl,KeyMatrixU
ld d,0
ld e,5
xor a
cp b
jr z, GotKey_GotY
GotKey_MatrixYLoop:
add hl,de
djnz GotKey_MatrixYLoop
GotKey_GotY:
ld e,c
add hl,de
ld a,(Hl)
call _putc
ret


PortMasks:
.db %01011111
.db %01101111
.db %01110111
.db %01111011
.db %01111101


KeyMatrixU:
.db "ABCDE"
.db "FGHIJ"
.db "KLMNO"
.db "PQRST"
.db "'UVWX"
.db " YZ  "