input.z80 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. #define CUR_COUNT_RESET 23
  2. _IsA2ByteTok = 42A3h
  3. keyflags = 35
  4. shift = 0
  5. alpha = 1
  6. shiftprev = 2
  7. alphaprev = 3
  8. holdmod = 4
  9. cursorblink = 7
  10. curcount = scrap+8
  11. penTemp = curcount+1
  12. textRow_base= penTemp+2
  13. input_end_text = textRow_base+2
  14. input_head = input_end_text+2
  15. input_top = input_head+2
  16. input_curptr= input_top+2
  17. input:
  18. ;Inputs: DE points to the ending string
  19. ;Save the location of the ending string
  20. ld (input_end_text),de
  21. ;Save the text pointer for when we clear input.
  22. ld hl,(textRow)
  23. ld (textRow_base),hl
  24. ;set up the input buffer
  25. ld hl,(input_base)
  26. ld (input_head),hl
  27. ld (input_curptr),hl
  28. xor a
  29. ld (hl),a
  30. ld bc,(input_size)
  31. add hl,bc
  32. dec hl ;make room for ending NULL
  33. ld (input_top),hl
  34. ;Clear the input
  35. call input_clear
  36. ;clear input mode
  37. xor a
  38. ld (flags+keyflags),a
  39. ;Set text mode to overwrite, but save original settings
  40. ld a,(OutputLogic)
  41. push af
  42. xor a
  43. ld (OutputLogic),a
  44. ;Clear out any keypresses
  45. out (1),a
  46. _:
  47. in a,(1)
  48. inc a
  49. jr nz,-_
  50. ;write 0xFF to the key port to flush
  51. ; dec a
  52. ; out (1),a
  53. ; ;Save the user flags since we'll be modifying them for text
  54. ; ld a,(flags+UserFlags)
  55. ; push af
  56. ;Print the current input
  57. call inp_dispstr
  58. ; ;Restore the user flags
  59. ; pop af
  60. ; ld (flags+UserFlags),a
  61. ;Restore text coords
  62. ld hl,(penTemp)
  63. ld (textRow),hl
  64. ;Get input
  65. call inputloop
  66. ;Restore text logic
  67. pop af
  68. ld (OutputLogic),a
  69. ;redraw the screen to show cursor removed and modebox removed
  70. call inp_disp
  71. ;append a null byte to end the input string.
  72. ld hl,(input_head)
  73. ; ld (hl),0
  74. ld (hl),$3F ;Grammer needs a newline token
  75. ld hl,(input_base)
  76. ret
  77. inputloop:
  78. ld hl,(textRow)
  79. ld (penTemp),hl
  80. res cursorblink,(iy+keyflags)
  81. ld a,CUR_COUNT_RESET>>1
  82. ld (curcount),a
  83. input_key_loop:
  84. in a,(4)
  85. and 8
  86. jp z,input_ON
  87. ;blink the cursor
  88. ld hl,curcount
  89. dec (hl)
  90. jr nz,+_
  91. ld (hl),CUR_COUNT_RESET
  92. ld a,(flags+keyflags)
  93. xor 1<<cursorblink
  94. ld (flags+keyflags),a
  95. and 1<<cursorblink
  96. ld a,' '
  97. call nz,getcursorchar
  98. call inp_VPutMap
  99. ; res InvertTextFlag,(iy+UserFlags)
  100. call inp_disp
  101. ld hl,(penTemp)
  102. ld (textRow),hl
  103. _:
  104. ld hl,getKeyDebounce
  105. ld (prev_page_call_address),hl
  106. call prev_page_call
  107. or a
  108. jr z,input_key_loop
  109. push af
  110. ld a,' '
  111. call inp_VPutMap
  112. ld hl,(penTemp)
  113. ld (textRow),hl
  114. pop af
  115. cp 9
  116. ret z
  117. call +_
  118. jr inputloop
  119. _:
  120. ; dec a
  121. ; jr z,input_cursor_down
  122. ; dec a
  123. ; jr z,input_cursor_left
  124. ; dec a
  125. ; jr z,input_cursor_right
  126. ; dec a
  127. ; jr z,input_cursor_up
  128. ; add a,4
  129. cp 15
  130. jr z,input_clear
  131. cp 56
  132. jr z,input_del
  133. call getKeyTok
  134. ret c
  135. ld a,d
  136. ld c,e
  137. sub 1
  138. inc a
  139. ccf
  140. ld de,(input_head)
  141. ld hl,(input_top)
  142. sbc hl,de
  143. ret z
  144. ret c
  145. ex de,hl
  146. or a
  147. jr z,+_
  148. ld (hl),a
  149. inc hl
  150. _:
  151. ld (hl),c
  152. inc hl
  153. ld (hl),0
  154. ld (input_head),hl
  155. call inp_dispstr
  156. call inp_disp
  157. ;Restore text coords
  158. ld hl,(penTemp)
  159. ld (textRow),hl
  160. ret
  161. ; input_cursor_down:
  162. ; ret
  163. ; input_cursor_up:
  164. ; ret
  165. ; input_cursor_left:
  166. ; ret
  167. ; input_cursor_right:
  168. ; ;make sure we aren't at the end of input
  169. ; ld hl,(input_curptr)
  170. ; ld a,(hl)
  171. ; or a
  172. ; ret z
  173. ;
  174. ; ;Advance to the next tokem
  175. ; call VPutTok ;advances text, sets HL to point to the next token
  176. ; ld (input_curptr),hl
  177. ;
  178. ; ;Save the new text coordinates
  179. ; ld hl(textRow)
  180. ; ld (penTemp),hl
  181. ; ret
  182. input_clear:
  183. call +_
  184. jr c,input_clear
  185. jp inp_disp
  186. input_del:
  187. call +_
  188. jp inp_disp
  189. _:
  190. ld de,(input_head)
  191. ld hl,(input_base)
  192. or a
  193. sbc hl,de
  194. ret z
  195. ;jp nc,fatal_error
  196. ex de,hl
  197. dec hl
  198. ld (input_head),hl
  199. ld e,(hl)
  200. ld d,0
  201. dec hl
  202. ld a,(hl)
  203. bcall(_IsA2ByteTok)
  204. jr nz,+_
  205. ld d,a
  206. ld (input_head),hl
  207. .db $FE ;start of `cp *`, skips the `inc hl`
  208. _:
  209. inc hl
  210. ld (hl),0
  211. ;DE is the token to erase
  212. ;redraw the input so that we know where to start drawing spaces!
  213. push de
  214. call inp_dispstr
  215. pop de
  216. ld hl,OP3
  217. ld a,d
  218. or a
  219. jr z,+_
  220. ld (hl),d
  221. inc hl
  222. _:
  223. ld (hl),e
  224. ld l,OP3&255
  225. bcall(_Get_Tok_Strng)
  226. ;BC is the length of the string
  227. ld a,b
  228. or c
  229. jr z,input_del_finish
  230. ;Now draw spaces for each char
  231. ld hl,OP3
  232. _:
  233. push bc
  234. push hl
  235. ld a,(hl)
  236. call vput_space_p1
  237. pop hl
  238. pop bc
  239. cpi
  240. jp pe,-_
  241. input_del_finish:
  242. ld hl,(penTemp)
  243. ld (textRow),hl
  244. scf
  245. ret
  246. inp_disp = p1_GraphToLCD
  247. input_ON:
  248. ld hl,ONErr
  249. ld (prev_page_call_address),hl
  250. call prev_page_call
  251. jp inp_disp
  252. inp_dispstr:
  253. ;Reset text coords
  254. ld hl,(textRow_base)
  255. ld (textRow),hl
  256. ;Draw the current input
  257. ld hl,(input_base)
  258. call inp_VPutTokS
  259. ;Save the text coordinate
  260. ld hl,(textRow)
  261. ld (penTemp),hl
  262. ;Draw a blank space:
  263. ; xor a ;already zero from VPutS
  264. call inp_VPutMap
  265. ;Draw the end text
  266. ld hl,(input_end_text)
  267. call inp_VPutS
  268. ;Draw another blank space:
  269. ; xor a
  270. jp inp_VPutMap
  271. _:
  272. push hl
  273. bcall(_IsA2ByteTok)
  274. push af
  275. bcall(_Get_Tok_Strng)
  276. ; ld hl,OP3+1
  277. ; add hl,bc
  278. ; ld (hl),0
  279. ld hl,OP3
  280. call inp_VPutS
  281. pop af
  282. pop hl
  283. inc hl
  284. jr nz,$+3
  285. inc hl
  286. inp_VPutTokS:
  287. ld a,(hl)
  288. or a
  289. jr nz,-_
  290. ret
  291. inp_VPutS:
  292. push hl
  293. ld hl,GPutS
  294. ld (prev_page_call_address),hl
  295. pop hl
  296. jp prev_page_call
  297. inp_VPutMap:
  298. push hl
  299. ld hl,PutSC
  300. ld (prev_page_call_address),hl
  301. pop hl
  302. jp prev_page_call
  303. vput_space_p1:
  304. ld hl,vput_space
  305. ld (prev_page_call_address),hl
  306. jp prev_page_call
  307. input_mode_LUT:
  308. .db $E0,$1E,"Aa"
  309. getcursorchar:
  310. ; set InvertTextFlag,(iy+UserFlags)
  311. ld a,(flags+keyflags)
  312. ld hl,input_mode_LUT
  313. and 3
  314. add a,l
  315. ld l,a
  316. #if input_mode_LUT&255>252
  317. jr nc,+_
  318. inc h
  319. _:
  320. #endif
  321. ld a,(hl)
  322. ret