getKeyChar.z80 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. getKeyChar:
  2. ;converts a key press to a char
  3. ;returns c flag set if not a valid key
  4. cp 54 \ jr nz,+_
  5. ;If previous state was [2nd], set normal, else set [2nd]
  6. ld a,(keyflags+flags)
  7. res shift,(iy+keyflags)
  8. res alpha,(iy+keyflags)
  9. and 3
  10. dec a
  11. scf
  12. ret z
  13. set shift,(iy+keyflags)
  14. ret
  15. _:
  16. cp 48 \ jr z,mod_alpha
  17. sub 1
  18. ret c
  19. bit alpha,(iy+keyflags)
  20. jr nz,chkalphakey
  21. cp 47
  22. ccf
  23. ret c
  24. bit shift,(iy+keyflags)
  25. res shift,(iy+keyflags)
  26. ld hl,shiftkeyLUT
  27. jr nz,+_
  28. ld hl,regkeyLUT
  29. _:
  30. add a,l
  31. ld l,a
  32. jr nc,+_
  33. inc h
  34. _:
  35. ld a,(hl)
  36. sub 1
  37. ret
  38. chkalphakey:
  39. ;either uppercase or lowercase
  40. call toAlpha
  41. ret c
  42. bit shift,(iy+keyflags)
  43. jp z,mod_reset
  44. call mod_reset
  45. cp 'Z'+1
  46. ret z
  47. cp 22h \ jr nz,+_ \ ld a,27h \ ret
  48. _:
  49. cp '?' \ jr nz,+_ \ ld a,'!' \ ret
  50. _:
  51. cp ' ' \ jr nz,+_ \ ld a,$EE \ ret ;EE is triple space
  52. _:
  53. cp ':' \ jr nz,+_ \ ld a,';' \ ret
  54. _:
  55. add a,20h
  56. ret
  57. mod_alpha:
  58. ld a,(keyflags+flags)
  59. ;if previous state was [ALPHA], switch to [alpha]
  60. ;If previous state was [alpha], switch to normal
  61. ;If previous state was [2nd], set the holdmod bit and set [ALPHA]
  62. and $FC
  63. ld b,a
  64. ld a,(keyflags+flags)
  65. and 3
  66. jr nz,+_
  67. set alpha,b
  68. _:
  69. dec a
  70. jr nz,+_
  71. set holdmod,b
  72. set alpha,b
  73. _:
  74. dec a
  75. jr nz,+_
  76. set shift,b
  77. set alpha,b
  78. _:
  79. ld a,b
  80. ld (flags+keyflags),a
  81. scf
  82. ret
  83. toAlpha:
  84. cp 9
  85. ret c
  86. jr nz,+_
  87. ld a,22h
  88. ret
  89. _:
  90. cp 47
  91. ccf
  92. ret c
  93. ld c,a
  94. cpl
  95. and 7
  96. ld b,a
  97. rla
  98. rla
  99. add a,b
  100. srl c
  101. srl c
  102. srl c
  103. sub c
  104. cp 3
  105. jr c,+_
  106. cp 5
  107. ret c
  108. sub 2
  109. _:
  110. cp 27
  111. ret z
  112. jr nc,+_
  113. add a,'A'
  114. ret
  115. _:
  116. sub 29
  117. jr nz,+_
  118. ld a,' '
  119. ret
  120. _:
  121. dec a
  122. jr nz,+_
  123. ld a,':'
  124. ret
  125. _:
  126. ld a,'?'
  127. ret
  128. mod_reset:
  129. bit holdmod,(iy+keyflags)
  130. ret nz
  131. res shift,(iy+keyflags)
  132. res alpha,(iy+keyflags)
  133. ret
  134. regKeyLUT:
  135. .db $20,0,0,$1F ;down,left,right,up
  136. .db 0,0,0,0,$D7
  137. .db $2C,$2E,$2B,$30,$5F ;+-*/^
  138. .db 0,0
  139. .db $1B,$34,$37,$3A,$2A ;neg369)
  140. .db 0,0,0
  141. .db $2F,$33,$36,$39,$29 ;.258(
  142. .db 0,0,0
  143. .db $31,$32,$35,$38,$2D ;0147,
  144. .db 0,0,0,0
  145. .db $1D ;sto
  146. .db 0,0
  147. .db $13,$12 ;sqrd, inv
  148. shiftKeyLUT:
  149. .db $08,$D0,$06,$07
  150. .db 0,0,0,0,0,$61
  151. .db $5E,$C2,$DC,$C5
  152. .db 0,0,0,0,0
  153. .db $05,$7D
  154. .db 0,0,0
  155. .db $D8,0,0,$04,$7C
  156. .db 0,0,$DD
  157. .db $60,0,0,$03,$1C,0,$14,0
  158. .db 0,0,0,$1E,$11,$17