startmenu.z80 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. setup_parserhook:
  2. call SetUpData
  3. call FindGVarData
  4. call readbyte
  5. ;D is the flags
  6. bit tokenhook_optout,d
  7. call z,p0_tokenhook_on
  8. in a,(6)
  9. ld hl,GrammerHook
  10. bcall(_SetParserHook)
  11. ret
  12. p0_tokenhook_on:
  13. ld hl,tokenhook_on
  14. ld (next_page_call_address),hl
  15. ld hl,tokenHookPtr+2
  16. dec b
  17. ld a,b
  18. jp next_page_call
  19. StartMenu:
  20. call setup_parserhook
  21. startmenu__:
  22. ;need to add in the options at the bottom
  23. ;add title at the top
  24. ;Need to set the filter flags
  25. ;Need to draw the menu box
  26. ;Need to show <status><name><type>
  27. ;Show 7 programs at a time
  28. ;First we set up the initial data and pointers
  29. call SetUpData
  30. ;Delete temp programs (archived progs are copied to temp programs)
  31. bcall(_DeleteTempPrograms)
  32. ;Sort the VAT, but put the calc in 15MHz mode if possible in order to speed it up
  33. ld c,1
  34. call SetSpeed
  35. ;Set up some pointers for VAT traversal
  36. ld hl,sortVAT
  37. ld (next_page_call_address),hl
  38. call next_page_call
  39. ;Set the default gbuf to appBackUpScreen and clear it
  40. ld hl,appBackUpScreen
  41. ld (gbuf_temp),hl
  42. ld (BufPtr),hl
  43. ld (GrayBufPtr),hl
  44. call ZeroMem768
  45. ;Set speed to 6MHz, take advantage of A=0 fom ZeroMem768
  46. out (20h),a
  47. ;now we are going to draw the top and bottom fields
  48. ;Top line
  49. ;ld a,-1
  50. dec a ;A is zero from ZeroMem768
  51. ld hl,appBackUpScreen+672
  52. ld b,12
  53. call SetSmallMem
  54. ;bottom line
  55. ld hl,appBackUpScreen+96
  56. ld b,12
  57. call SetSmallMem
  58. ;Header text (version number)
  59. ld hl,StrVersion
  60. ld bc,$0301
  61. call GPutSS
  62. ;Options
  63. ld hl,58
  64. ld (TextRow),hl
  65. call GPutSI
  66. .db "Gram AppV Asm Exit More",0
  67. ;draw the bars between the options
  68. ld de,$0111
  69. _:
  70. ld bc,0838h
  71. push de
  72. ld a,d
  73. call DrawRectToGraph
  74. pop de
  75. ld a,e
  76. add a,20
  77. ld e,a
  78. cp 96
  79. jr c,-_
  80. ;highlight the 'Grammer' filter option
  81. call highlight_Gram
  82. ;Need to set the filter flags.
  83. ld (iy+34),8
  84. ;Draw the menu box
  85. call DrawRectToGraphI \ .db 16,10,44,64,1
  86. call DrawRectToGraphI \ .db 15,11,42,66,2
  87. redraw_menu:
  88. ; Erase contents of the menu box
  89. call DrawRectToGraphI \ .db 16,11,42,64,0
  90. ;Reset the menu data
  91. ld hl,(progPtr)
  92. ld (VATptr),hl
  93. ; ld (VATptr_next),hl
  94. call VATPtrToOP1
  95. ld hl,0
  96. ld (main_menu_cursor),hl ;L=cursor, h=cursor_max
  97. ld (main_menu_index),hl
  98. ;Load the first seven entries (if possible)
  99. _:
  100. call isStartMenu_valid
  101. jr nz,+_
  102. ld hl,(VATPtr)
  103. ld (VATPtr_next),hl ;just a safe place to store it
  104. call NextVAT_valid_draw_advance_stepin
  105. jr startVATloop
  106. _:
  107. call NextVAT_valid_draw
  108. jr c,main_menu_loop
  109. ld hl,(VATPtr)
  110. ld (VATPtr_next),hl ;just a safe place to store it
  111. startVATloop:
  112. call NextVAT_valid_draw
  113. jr c,+_
  114. ld a,(main_menu_cursor_max)
  115. cp 7
  116. jr nz,startVATloop
  117. _:
  118. ld de,(VATPtr_next)
  119. ld hl,(VATPtr)
  120. ld (VATPtr_next),hl
  121. ld (VATPtr),de
  122. main_menu_loop:
  123. ;here we need to draw the cursor highlight
  124. ld a,(main_menu_cursor)
  125. ld l,a
  126. add a,a
  127. add a,l
  128. add a,a
  129. add a,11 ;y coord
  130. ld b,6
  131. ld c,a
  132. ld de,$4010
  133. push bc
  134. ld a,2
  135. call DrawRectToGraph
  136. call GraphToLCD
  137. pop bc
  138. ld de,$4010
  139. ld a,2
  140. call DrawRectToGraph
  141. main_menu_ui_loop:
  142. in a,(4)
  143. and 8
  144. ret z
  145. call GetKeyDebounce
  146. or a
  147. jr z,main_menu_ui_loop
  148. cp 15 \ ret z ;clear
  149. cp 50 \ ret z ;F4 (Exit)
  150. cp 49
  151. jr z,$+6
  152. cp 55
  153. jr nz,+_
  154. ld hl,modemenu
  155. ld (next_page_call_address),hl
  156. call next_page_call
  157. jp startmenu__
  158. _:
  159. cp 53 \ jr nz,+_ ;F1 (Gram)
  160. ld a,(flags+34)
  161. xor 8
  162. ld (flags+34),a
  163. ld de,$1100
  164. jr highlight_option
  165. _:
  166. cp 52 \ jr nz,+_ ;F2 (AppV)
  167. ld a,(flags+34)
  168. xor 64
  169. ld (flags+34),a
  170. ld de,1312h
  171. highlight_option:
  172. call highlight
  173. jp redraw_menu
  174. _:
  175. cp 51 \ jr nz,+_ ;F3
  176. ld a,(flags+34)
  177. xor 4
  178. ld (flags+34),a
  179. ld de,1326h
  180. jr highlight_option
  181. _:
  182. ld hl,main_menu_cursor
  183. cp 54 ;[2nd]
  184. jr z,+_
  185. cp 12 ;[*]
  186. jp z,main_menu_archunarch
  187. dec a \ jr z,cur_dn ;down
  188. sub 3 \ jp z,cur_up ;up
  189. cp 5 ;[Enter]-4
  190. jp nz,main_menu_ui_loop
  191. _:
  192. ;here ENTER is pressed
  193. ;need to load the variable name into OP1
  194. call main_menu_get_var_name
  195. call isStartMenu_valid
  196. call z,SelectedProgOP1
  197. jp startmenu__
  198. main_menu_get_var_name:
  199. ld a,(hl)
  200. or a
  201. jr z,selected_entry
  202. _:
  203. push af
  204. call NextVAT_valid
  205. pop af
  206. dec a
  207. jr nz,-_
  208. selected_entry:
  209. ld hl,(VATPtr)
  210. jp VATPtrToOP1
  211. cur_dn:
  212. ld a,(hl)
  213. inc a
  214. inc hl
  215. cp (hl)
  216. jr nc,+_
  217. dec hl
  218. ld (hl),a
  219. jp main_menu_loop
  220. _:
  221. cp 7
  222. jp nz,main_menu_ui_loop
  223. ;here we need to scroll down.
  224. ;This means we need to advance VATPtr and VATPtr_next
  225. ;draw VATPtr_next
  226. ;first, advance VATPtr_next
  227. ld hl,(VATPtr)
  228. push hl
  229. ld hl,(VATPtr_next)
  230. ld (VATPtr),hl
  231. call NextVAT_valid
  232. pop hl
  233. ld de,(VATPtr)
  234. ld (VATPtr),hl
  235. jp c,main_menu_ui_loop
  236. _:
  237. ld (VATPtr_next),de
  238. ;now we know there are more entries
  239. ;shift the menu up, then draw the entry, then advance VATPtr
  240. ld de,appBackUpScreen+134
  241. ld hl,appBackUpScreen+206
  242. ld a,36
  243. _:
  244. call mov8
  245. inc l \ inc hl
  246. inc l \ inc hl
  247. inc e \ inc de
  248. inc e \ inc de
  249. dec a
  250. jr nz,-_
  251. ;We need to clear the bottom 6 rows of pixels
  252. call DrawRectToGraphI \ .db 16,47,6,64,0
  253. ld a,6
  254. call draw_var_name
  255. call NextVAT_valid
  256. ld hl,(main_menu_index)
  257. inc hl
  258. ld (main_menu_index),hl
  259. jp main_menu_loop
  260. cur_up:
  261. ld a,(hl)
  262. or a
  263. jr z,+_
  264. dec (hl)
  265. jp main_menu_loop
  266. _:
  267. ;now we need to scroll up. Verify that main_menu_index!=0
  268. ld hl,(main_menu_index)
  269. ld a,h
  270. or l
  271. jp z,main_menu_ui_loop
  272. dec hl
  273. ld (main_menu_index),hl
  274. ld hl,(VATPtr)
  275. push hl
  276. ld de,(VATPtr_next)
  277. call PrevVAT_valid_with_start
  278. ; call PrevVAT_with_start
  279. ld hl,(VATPtr)
  280. ld (VATPtr_next),hl
  281. pop hl
  282. ld (VATPtr),hl
  283. call PrevVAT_valid
  284. ;need to shift the screen up
  285. ld hl,appBackUpScreen+561
  286. ld de,appBackUpScreen+633
  287. ld a,36
  288. _:
  289. ldd \ ldd \ ldd \ ldd
  290. ldd \ ldd \ ldd \ ldd
  291. dec l \ dec hl
  292. dec l \ dec hl
  293. dec e \ dec de
  294. dec e \ dec de
  295. dec a
  296. jr nz,-_
  297. call DrawRectToGraphI \ .db 16,11,6,64,0
  298. call draw_var_name
  299. jp main_menu_loop
  300. highlight_Gram:
  301. ld de,$1100
  302. highlight:
  303. ld bc,0739h
  304. ld a,2
  305. jp DrawRectToGraph
  306. NextVAT_valid_draw:
  307. call NextVAT_valid
  308. ret c
  309. NextVAT_valid_draw_advance_stepin:
  310. ld hl,main_menu_cursor_max
  311. ld a,(hl)
  312. inc (hl)
  313. call draw_var_name
  314. or a
  315. ret
  316. NextVAT_valid:
  317. ld hl,(VATPtr)
  318. push hl
  319. call +_
  320. pop hl
  321. ret nc
  322. ld (VATPtr),hl
  323. ret
  324. _:
  325. call NextVAT
  326. ret c
  327. call isStartMenu_valid
  328. jr nz,-_
  329. or a
  330. ret
  331. draw_var_name:
  332. push af
  333. bcall(_ChkFindSym)
  334. pop af
  335. ld h,b
  336. call calculate_text_coord
  337. xor a
  338. ld (OP1+9),a
  339. or h
  340. ld a,' '
  341. jr z,+_
  342. ld a,'*'
  343. _:
  344. call PutSC
  345. ld hl,OP1+1
  346. call GPutS
  347. ld a,16
  348. ld (textCol),a
  349. ld a,(OP1)
  350. cp 15h
  351. ld hl,s_appv
  352. jr z,+_
  353. ld hl,s_prog
  354. _:
  355. jp GPutS
  356. main_menu_archunarch:
  357. ; Calculate the text text coord for the archive status symbol
  358. ld a,(hl)
  359. push af
  360. call calculate_text_coord
  361. pop af
  362. call main_menu_get_var_name
  363. call isStartMenu_valid
  364. jp nz,main_menu_loop
  365. ; ld a,(OP1)
  366. ; push af
  367. bcall(_Arc_Unarc)
  368. ; Need to fix the RAM code after archiving/unarchiving.
  369. call setup_readarc
  370. ; pop af
  371. ; ld (OP1),a
  372. ;
  373. ; ; Need to overwrite the archive status symbol
  374. ; bcall(_ChkFindSym)
  375. ; inc b
  376. ; dec b
  377. ; ld a,' '
  378. ; jr z,+_
  379. ; ld a,'*'
  380. ; _:
  381. ; call PutSC
  382. jp redraw_menu
  383. calculate_text_coord:
  384. ld c,a
  385. add a,a
  386. add a,c
  387. add a,a
  388. add a,11 ;y coord
  389. ld c,a
  390. ld b,4
  391. ld (textRow),bc
  392. ret