getKeyTok.z80 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. getKeyTok:
  2. ;converts a key press to a token
  3. ;Takes key value in A
  4. ;returns DE as token, c flag set if not a valid key else nc.
  5. ;Check mod tokens
  6. ;Check [2nd]
  7. cp 54 \ jr nz,+_
  8. ;If previous state was [2nd], set normal, else set [2nd]
  9. ld a,(keyflags+flags)
  10. res shift,(iy+keyflags)
  11. res alpha,(iy+keyflags)
  12. and 3
  13. dec a
  14. scf
  15. ret z
  16. set shift,(iy+keyflags)
  17. ret
  18. _:
  19. ;Check [Alpha]
  20. cp 48 \ jp z,mod_alpha
  21. ;Any other keys bigger should return c
  22. ccf
  23. ret c
  24. ;Check for no key pressed, or arrows
  25. sub 9
  26. ret c
  27. ;If [ALPHA] or [alpha] mode, check those LUTs
  28. bit alpha,(iy+keyflags)
  29. jr nz,chkalphakey_tok
  30. ;Else we have normal or [shift] mode
  31. ;Check if shift or normal, reset either way
  32. bit shift,(iy+keyflags)
  33. res shift,(iy+keyflags)
  34. ;get the LUT pointer for the mode
  35. ld hl,shiftkeytokLUT
  36. jr nz,+_
  37. ld hl,regkeytokLUT
  38. _:
  39. ;Now get the offset into the LUT
  40. add a,a
  41. add a,l
  42. ld l,a
  43. jr nc,+_
  44. inc h
  45. _:
  46. ;Load the value into DE
  47. ld e,(hl)
  48. inc hl
  49. ld d,(hl)
  50. ;Return c if output is null
  51. ld a,d
  52. or e
  53. sub 1
  54. ret
  55. chkalphakey_tok:
  56. ;either uppercase or lowercase
  57. call toAlpha_tok
  58. ld e,a
  59. ld d,0
  60. ret c
  61. ;Get [ALPHA] or [alpha] mode
  62. bit shift,(iy+keyflags)
  63. ;Do mod_reset. If [ALPHA], no need to modify further so exit
  64. jp z,mod_reset
  65. call mod_reset
  66. cp 'Z'+1
  67. ret nc
  68. cp 2Ah \ jr nz,+_ \ ld e,$AE \ ret ;Quote --> apostrophe
  69. _:
  70. cp $AF \ jr nz,+_ \ ld e,$2D \ ret ;? --> !
  71. _:
  72. cp $3E \ jr nz,+_ \ ld de,$BBD6 \ ret ;: --> ;
  73. _:
  74. cp $29 \ jr nz,+_ \ ld de,$BBD9 \ ret ;space --> underscore
  75. _:
  76. cp 'A'
  77. ccf
  78. ret nc
  79. ld d,$BB
  80. cp 'L'
  81. ccf
  82. adc a,$B0-'A'
  83. ld e,a
  84. ret
  85. toAlpha_tok:
  86. or a
  87. jr nz,+_
  88. ld a,$3F ;newline
  89. ret
  90. _:
  91. cp 1
  92. jr nz,+_
  93. ld a,2Ah ;Quote
  94. ret
  95. _:
  96. ;38 -> 0 30->1 22->2
  97. ;37 -> 5 29->6 21->7
  98. ;36 -> 10
  99. ;35 -> 15
  100. ;34 -> 20
  101. ;33 -> 25
  102. ;32 -> 30
  103. ;y=5*((-x-1)&7)-(x>>3) - 1
  104. ; =5*((~x)&7)-(x>>3) - 1
  105. ld c,a
  106. cpl
  107. and 7
  108. ld b,a
  109. add a,a
  110. add a,a
  111. add a,b
  112. srl c
  113. srl c
  114. srl c
  115. sub c
  116. dec a
  117. cp 3
  118. jr c,+_
  119. sub 2
  120. _:
  121. cp 27
  122. jr nc,+_
  123. add a,'A'
  124. ret
  125. _:
  126. sub 29
  127. jr nz,+_
  128. ld a,29h ;space token
  129. ret
  130. _:
  131. dec a
  132. jr nz,+_
  133. ld a,$3E ;Colon token
  134. ret
  135. _:
  136. ld a,$AF
  137. ret
  138. regKeyTokLUT:
  139. ;.dw 0,0,0,0,0,0,0,0 ;down,left,right,up
  140. .dw $3F,$70,$71,$82,$83,$F0,0,0 ;Enter,+-*/^
  141. .dw $B0,$33,$36,$39,$11,$C6,0,0 ;neg369)
  142. .dw $3A,$32,$35,$38,$10,$C4,0,0 ;.258(
  143. .dw $30,$31,$34,$37,$2B,$C2,0,0 ;0147,
  144. .dw $00,$04,$BE,$C0,$0D,$0C,0,0 ;sto
  145. shiftKeyTokLUT:
  146. ;.dw 0,0,0,0,0,0,0,0 ;down,left,right,up
  147. .dw $00,$00,$07,$06,$BB31,$AC,0,0 ;Enter,+-*/^
  148. .dw $72,$5D02,$5D05,$5E82,$09,$C7,0,0 ;neg369)
  149. .dw $2C,$5D01,$5D04,$5E81,$08,$C5,0,0 ;.258(
  150. .dw $00,$5D00,$5D03,$5E80,$3B,$C3,0,0 ;0147,
  151. .dw $00,$00,$BF,$C1,$BC,$00,0,0 ;sto