inkey.asm 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. ; INKEY Function
  2. ; Returns a string allocated in dynamic memory
  3. ; containing the string.
  4. ; An empty string otherwise.
  5. ;
  6. #include once <alloc.asm>
  7. ;
  8. INKEY:
  9. PROC
  10. LOCAL __EMPTY_INKEY
  11. LOCAL KEY_SCAN
  12. LOCAL KEY_TEST
  13. LOCAL KEY_CODE
  14. ;- ld bc,3 ; 1 char length string
  15. jsr __MEM_ALLOC ;- call __MEM_ALLOC
  16. lda z80_h ;- ld a,h
  17. sta z80_a
  18. ora z80_l ;- or l
  19. bne *+3 ;- ret z ; Return if NULL (No memory)
  20. rts
  21. lda z80_l ;- push hl ; Saves memory pointer
  22. pha
  23. lda z80_h
  24. pha
  25. jsr KEY_SCAN ;- call KEY_SCAN
  26. jne __EMPTY_INKEY ;- jp nz, __EMPTY_INKEY
  27. jsr KEY_TEST ;- call KEY_TEST
  28. jcs __EMPTY_INKEY ;- jp nc, __EMPTY_INKEY
  29. ;- dec d ; D is expected to be FLAGS so set bit 3 $FF
  30. ; 'L' Mode so no keywords.
  31. lda z80_a ;- ld e,a ; main key to A
  32. sta z80_e
  33. ; C is MODE 0 'KLC' from above still.
  34. jsr KEY_CODE ;- call KEY_CODE ; routine K-DECODE
  35. pla ;- pop hl
  36. sta z80_h
  37. pla
  38. sta z80_l
  39. lda #1 ;- ld (hl),1
  40. ldy #$00
  41. sta (z80_hl),y
  42. inc z80_l ;- inc hl
  43. bne *+4
  44. inc z80_h
  45. lda #0 ;- ld (hl),0
  46. ldy #$00
  47. sta (z80_hl),y
  48. inc z80_l ;- inc hl
  49. bne *+4
  50. inc z80_h
  51. lda z80_a ;- ld (hl),a
  52. ldy #$00
  53. sta (z80_hl),y
  54. ;- dec hl
  55. ;- dec hl ; HL Points to string result
  56. rts ;- ret
  57. __EMPTY_INKEY:
  58. pla ;- pop hl
  59. sta z80_h
  60. pla
  61. sta z80_l
  62. eor z80_a ;- xor a
  63. lda z80_a ;- ld (hl),a
  64. ldy #$00
  65. sta (z80_hl),y
  66. inc z80_l ;- inc hl
  67. bne *+4
  68. inc z80_h
  69. lda z80_a ;- ld (hl),a
  70. ldy #$00
  71. sta (z80_hl),y
  72. ;- dec hl
  73. rts ;- ret
  74. ;
  75. KEY_SCAN EQU 028Eh
  76. KEY_TEST EQU 031Eh
  77. KEY_CODE EQU 0333h
  78. ENDP