menu.a65 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. #include "memmap.i65"
  2. #include "dma.i65"
  3. menu_init:
  4. sep #$20 : .as
  5. rep #$10 : .xl
  6. lda #^ROOT_DIR
  7. ldx #!ROOT_DIR
  8. sta dirptr_bank
  9. stx dirptr_addr
  10. sta dirstart_bank
  11. stx dirstart_addr
  12. stz menu_state
  13. stz dirend_onscreen
  14. lda #$04
  15. sta cursor_x
  16. lda #$09
  17. sta cursor_y
  18. ldx #$0000
  19. stx dirptr_idx
  20. stx menu_sel
  21. lda #$01
  22. sta menu_dirty
  23. rts
  24. menuloop:
  25. menuloop_s1
  26. sep #$20 : .as
  27. rep #$10 : .xl
  28. lda isr_done
  29. lsr
  30. bcc menuloop_s1
  31. stz isr_done
  32. jsr menu_cleanup ;update phase 2
  33. jsr menu_updates ;update stuff, check keys etc
  34. lda menu_dirty ;is there ANY reason to redraw the menu?
  35. cmp #$01
  36. beq menuloop_redraw ;then do
  37. bra menuloop_s1
  38. menuloop_redraw
  39. stz menu_dirty
  40. jsr menu_redraw
  41. bra menuloop_s1
  42. rts
  43. menu_cleanup:
  44. sep #$20 : .as
  45. rep #$10 : .xl
  46. lda dirend_onscreen
  47. beq menu_cleanup_out
  48. lda dirend_idx
  49. lsr
  50. lsr
  51. pha
  52. menu_cleanup_loop
  53. cmp listdisp
  54. beq +
  55. pha
  56. clc
  57. adc #$09
  58. sta print_y
  59. lda #^space64
  60. ldx #!space64
  61. sta print_bank
  62. stx print_src
  63. stz print_pal
  64. lda #64
  65. sta print_count
  66. jsr hiprint
  67. pla
  68. inc
  69. bra menu_cleanup_loop
  70. +
  71. pla
  72. cmp menu_sel
  73. beq menu_cleanup_out
  74. bpl menu_cleanup_out
  75. sta menu_sel
  76. menu_cleanup_out
  77. rts
  78. menu_updates:
  79. ;update selection, scroll etc
  80. lda menu_sel
  81. asl
  82. asl
  83. sta dirptr_idx
  84. lda menu_sel
  85. clc
  86. adc #$08
  87. sta bar_yl
  88. ;get input
  89. jsr read_pad
  90. lda #$04
  91. and pad1trig+1
  92. bne key_down
  93. lda #$08
  94. and pad1trig+1
  95. bne key_up
  96. lda #$01
  97. and pad1trig+1
  98. bne key_right
  99. lda #$02
  100. and pad1trig+1
  101. bne key_left
  102. lda #$80
  103. and pad1trig+1
  104. bne key_b
  105. lda #$20
  106. and pad1trig+1
  107. bne key_select
  108. lda #$80
  109. and pad1trig
  110. bne key_a
  111. bra menuupd_out
  112. key_down
  113. jsr menu_key_down
  114. bra menuupd_out
  115. key_up
  116. jsr menu_key_up
  117. bra menuupd_out
  118. key_right
  119. jsr menu_key_right
  120. bra menuupd_out
  121. key_left
  122. jsr menu_key_left
  123. bra menuupd_out
  124. key_b
  125. jsr menu_key_b
  126. bra menuupd_out
  127. key_a
  128. jsr menu_key_a
  129. bra menuupd_out
  130. key_select
  131. jsr menu_key_select
  132. bra menuupd_out
  133. menuupd_out
  134. lda #$09
  135. sta cursor_y
  136. rts
  137. menu_redraw:
  138. lda menu_state
  139. beq redraw_filelist
  140. ; cmp 1
  141. ; beq redraw_main
  142. menu_redraw_out
  143. rts
  144. redraw_filelist
  145. ldy #$0000
  146. sty dirptr_idx
  147. stz dirend_idx
  148. stz dirend_onscreen
  149. redraw_filelist_loop
  150. ldy dirptr_idx
  151. tya
  152. lsr
  153. lsr
  154. cmp listdisp
  155. beq redraw_filelist_last
  156. lda dirptr_bank
  157. phb
  158. pha
  159. plb
  160. rep #$20 : .al
  161. lda (dirptr_addr), y
  162. sta @dirent_addr
  163. iny
  164. iny
  165. sep #$20 : .as
  166. lda (dirptr_addr), y
  167. clc
  168. adc #$c0
  169. sta @dirent_bank
  170. cmp #$c0
  171. beq redraw_filelist_dirend
  172. iny
  173. lda (dirptr_addr), y
  174. iny
  175. sta @dirent_type
  176. plb
  177. sty dirptr_idx
  178. jsr print_direntry
  179. bra redraw_filelist_loop
  180. redraw_filelist_dirend
  181. plb
  182. dey
  183. dey
  184. dey
  185. dey
  186. dey
  187. dey
  188. sty dirend_idx
  189. lda #$01
  190. sta dirend_onscreen
  191. bra redraw_filelist_out
  192. redraw_filelist_last ;check if next offscreen item is end of dir
  193. lda dirptr_bank
  194. phb
  195. pha
  196. plb
  197. iny
  198. iny
  199. lda (dirptr_addr), y
  200. beq redraw_filelist_dirend
  201. plb
  202. redraw_filelist_out
  203. ldx #$0000
  204. stx dirptr_idx
  205. brl menu_redraw_out
  206. print_direntry:
  207. lda dirent_bank
  208. ldx dirent_addr
  209. phb
  210. pha
  211. plb
  212. lda @dirent_type
  213. cmp #$80
  214. rep #$20 : .al
  215. bne dirent_is_file
  216. dirent_is_dir
  217. lda #$04 ;skip dir tgt
  218. sta @fd_fnoff
  219. lda #$01 ;different color for dirs
  220. sta @print_pal
  221. bra dirent_type_cont
  222. dirent_is_file
  223. lda #$40 ;skip game header
  224. sta @fd_fnoff
  225. lda #$00
  226. sta @print_pal ;palette 0 (white)
  227. dirent_type_cont
  228. txa
  229. clc
  230. adc @fd_fnoff
  231. tax
  232. sep #$20 : .as
  233. lda !0, x ;load offset of leaf (file) name
  234. clc
  235. adc #1
  236. rep #$20 : .al
  237. and #$00ff ;kill hi byte
  238. sta @fd_fnoff
  239. txa
  240. adc @fd_fnoff
  241. sta @fd_fnoff
  242. plb
  243. lda cursor_y
  244. sta print_y
  245. inc
  246. sta cursor_y
  247. lda cursor_x
  248. sta print_x
  249. sep #$20 : .as
  250. ldx fd_fnoff
  251. lda #58
  252. sta print_count
  253. stx print_src
  254. lda dirent_bank
  255. sta print_bank
  256. jsr hiprint
  257. lda cursor_x
  258. clc
  259. adc print_done
  260. sta print_x
  261. lda #58
  262. sec
  263. sbc print_done
  264. sta print_count
  265. lda #^space64
  266. ldx #!space64
  267. sta print_bank
  268. stx print_src
  269. jsr hiprint
  270. rts
  271. menu_key_down:
  272. lda listdisp
  273. dec
  274. cmp menu_sel
  275. bne +
  276. lda #$01
  277. sta menu_dirty
  278. lda dirend_onscreen
  279. bne down_out
  280. rep #$20 : .al
  281. lda dirptr_addr
  282. clc
  283. adc #$04
  284. sta dirptr_addr
  285. sep #$20 : .as
  286. rts
  287. + lda menu_sel
  288. inc
  289. sta menu_sel
  290. down_out
  291. rts
  292. menu_key_up:
  293. lda menu_sel
  294. bne +
  295. lda #$01
  296. sta menu_dirty
  297. rep #$20 : .al
  298. lda dirptr_addr
  299. cmp dirstart_addr
  300. beq up_out
  301. sec
  302. sbc #$04
  303. sta dirptr_addr
  304. bra up_out
  305. + dec
  306. sta menu_sel
  307. up_out
  308. sep #$20 : .as
  309. rts
  310. menu_key_left:
  311. lda #$01
  312. sta menu_dirty
  313. rep #$20 : .al
  314. lda dirptr_addr
  315. beq +
  316. sec
  317. sbc listdisp
  318. sec
  319. sbc listdisp
  320. sec
  321. sbc listdisp
  322. sec
  323. sbc listdisp
  324. bcc +
  325. cmp dirstart_addr
  326. bcc +
  327. - sta dirptr_addr
  328. sep #$20 : .as
  329. rts
  330. + lda dirstart_addr
  331. sep #$20 : .as
  332. stz menu_sel
  333. rep #$20 : .al
  334. bra -
  335. menu_key_right:
  336. sep #$20 : .as
  337. lda dirend_onscreen
  338. bne menuupd_lastcursor
  339. lda #$01
  340. sta menu_dirty
  341. rep #$20 : .al
  342. lda listdisp
  343. asl
  344. asl
  345. clc
  346. adc dirptr_addr
  347. sta dirptr_addr
  348. sep #$20 : .as
  349. rts
  350. menuupd_lastcursor
  351. lda dirend_idx
  352. lsr
  353. lsr
  354. sta menu_sel
  355. rts
  356. menu_key_b:
  357. jsr select_item
  358. rts
  359. menu_key_select:
  360. lda barstep
  361. beq do_setup448
  362. do_setup224
  363. jsr setup_224
  364. rts
  365. do_setup448
  366. jsr setup_448
  367. rts
  368. menu_key_a:
  369. rep #$20 : .al
  370. lda dirstart_addr
  371. beq skip_key_a
  372. sta dirptr_addr
  373. lda #$0000
  374. sta menu_sel
  375. bra select_item
  376. skip_key_a
  377. sep #$20 : .as
  378. rts
  379. select_item:
  380. rep #$20 : .al
  381. lda menu_sel
  382. and #$00ff
  383. asl
  384. asl
  385. tay
  386. sep #$20 : .as
  387. lda dirptr_bank
  388. phb
  389. pha
  390. plb
  391. iny
  392. iny
  393. iny
  394. lda (dirptr_addr), y
  395. beq sel_is_file
  396. cmp #$80
  397. beq sel_is_dir
  398. select_item_cont
  399. plb
  400. rts
  401. sel_is_file
  402. jsr select_file
  403. bra select_item_cont
  404. sel_is_dir
  405. jsr select_dir
  406. bra select_item_cont
  407. select_file:
  408. ; have avr load the rom
  409. dey
  410. lda (dirptr_addr), y
  411. sta @AVR_PARAM+2
  412. rep #$20 : .al
  413. dey
  414. dey
  415. lda (dirptr_addr), y
  416. sta @AVR_PARAM
  417. sep #$20 : .as
  418. lda #$01
  419. sta @AVR_CMD
  420. lda #$00
  421. sta @$4200
  422. cli
  423. jsl @infloop
  424. rts
  425. select_dir: ; y = direntry ptr
  426. dey
  427. lda (dirptr_addr), y
  428. clc
  429. adc #$c0
  430. sta @dirent_bank
  431. dey
  432. dey
  433. rep #$20 : .al
  434. lda (dirptr_addr), y
  435. sta @dirent_addr
  436. tax
  437. sep #$20 : .as
  438. lda @dirent_bank
  439. phb
  440. pha
  441. plb
  442. lda !2, x ; load linked dir start bank
  443. clc
  444. adc #$c0
  445. sta @dirptr_bank
  446. sta @dirstart_bank
  447. rep #$20 : .al
  448. lda !0, x ; load linked dir start address
  449. sta @dirptr_addr
  450. sta @dirstart_addr
  451. lda #$0000
  452. sta @menu_sel
  453. sep #$20 : .as
  454. lda #$01
  455. sta @menu_dirty
  456. plb
  457. rts
  458. setup_224:
  459. php
  460. rep #$30 : .xl : .al
  461. lda #18
  462. sta listdisp
  463. dec
  464. cmp menu_sel
  465. bmi setup_228_adjsel
  466. bra +
  467. setup_228_adjsel
  468. sta menu_sel
  469. +
  470. lda #19*64
  471. sta textdmasize
  472. lda #$0007
  473. sta hdma_scroll+8
  474. sep #$20 : .as
  475. lda #$07
  476. sta $2110
  477. lda #$00
  478. sta $2110
  479. lda #$00
  480. sta barstep
  481. ora #$08
  482. sta $2133
  483. lda #$0a
  484. sta hdma_math+6
  485. lda #$01
  486. sta menu_dirty
  487. lda #^space64
  488. ldx #!space64
  489. sta print_bank
  490. stx print_src
  491. stz print_pal
  492. lda #64
  493. sta print_count
  494. lda #27
  495. sta print_y
  496. stz print_x
  497. jsr hiprint
  498. lda #28
  499. sta print_y
  500. jsr hiprint
  501. jsr hiprint
  502. plp
  503. rts
  504. setup_448:
  505. php
  506. rep #$30 : .xl : .al
  507. lda #36
  508. sta listdisp
  509. lda #38*64
  510. sta textdmasize
  511. lda #$ffc6
  512. sta hdma_scroll+8
  513. sep #$20 : .as
  514. lda #$c6
  515. sta $2110
  516. lda #$ff
  517. sta $2110
  518. lda #$01
  519. sta barstep
  520. ora #$08
  521. sta $2133
  522. lda #$06
  523. sta hdma_math+6
  524. lda #$01
  525. sta menu_dirty
  526. plp
  527. rts