; Keyboard Routines for GABasic
; Hey, finally i found a good txt explaining
; keyboard ints
; GF 2000

; --- Inkey, ret last key
; This one doesn't support extended keys

Inkey:
 XOR EAX, EAX
 Mov AH,06h
 Mov DL,0FFh
 Int 21h
 Jz NoKey
 Xor AH,AH
Ret
NoKey:
 Xor  EAX, EAX
Ret

; --- INKEY$
; - EAX, dest
INKEY$:
  MOV edi, eax
  mov ebx, edi
  mov ecx, [eax]
  add ebx, ecx
  add ebx, 4

  Mov AH, 06
  Mov DL, 0FFh
  Int 21h
  Jz empty
  mov [ebx], al
  inc ecx
  mov [edi], ecx
  cmp al, 0
  JE extended
    RET
extended:
  Mov AH,06h
  Mov DL,0FFh
  Int 21h
  inc ebx
  mov [ebx], al
  inc ecx
  mov [edi], ecx
empty:   ; Don't fill the string
RET

; -- Clears the key buffer
; Function by Solus
ClearKeyBuffer:
    mov esi, 1050
    mov al, [esi]
    add esi, 2
    mov [esi], al
ret