UrForth: properly mark scattered colon words
[urasm.git] / libs / GetKey.zas
blobcbcc46aebf23c5dafbccde6a98f6c0e3f4e3bd02
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; wait for keypress; return char
3 ;; OUT:
4 ;;   A: key code
5 ;;   HL,DE,BC,F: dead
6 GetKey:
7   call InKey
8   jr   nc,GetKey
9   ret
11 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12 ;; don't wait for keypress; return char or carry reset
13 ;; OUT:
14 ;;   A: key code or trash
15 ;;   HL,DE,BC,F: dead
16 ;;   CARRY: set if key was decoded
17 ;; note:
18 ;;   30: CS
19 ;;   31: SS
20 InKey:
21   ld   hl,.keytab-1 ; Mascii values
22   ld   de,5
23   ld   c,#7F        ; 1st half row
24 .loop0:
25   ld   a,c
26   IN   a,(#FE)      ; Get half row
27   cpl
28   and  #1F
29   ld   b,a
30   jr   z,.nokey     ; No keys pressed
31   push hl
32 .loop1:
33   inc  hl           ; Find key within row
34   rra
35   jr   nc,.loop1    ; Wow - No key if carry
36   ld   a,(hl)       ; Get mazcii value from table
37   pop  hl
38   ;cp   31           ; SS
39   ;jr   z,.nokey
40   ;cp   30           ; CS
41   ;scf
42   ;ret  nz           ; Back with CARRY if valid key
43   scf
44   ret
45 .nokey:
46   add  hl,de
47   rrc  c            ; Next row on keyboard (carry=1)
48   jr   c,.loop0
49   ret               ; Go back with NO CARRY if no key pressed
51 .keytab: DEFM  ' ',31,'MNB',13,'LKJHPOIUY0987612345QWERTASDFG',30,'ZXCV'