menu.a65 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  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 #$02
  15. sta cursor_x
  16. lda #$09
  17. sta cursor_y
  18. lda #$01
  19. sta bar_xl
  20. lda #$3e
  21. sta bar_wl
  22. ldx #$0000
  23. stx dirptr_idx
  24. stx menu_sel
  25. lda #$01
  26. sta menu_dirty
  27. rts
  28. menuloop:
  29. menuloop_s1
  30. sep #$20 : .as
  31. rep #$10 : .xl
  32. lda isr_done
  33. lsr
  34. bcc menuloop_s1
  35. stz isr_done
  36. jsr printtime
  37. jsr menu_updates ;update stuff, check keys etc
  38. lda menu_dirty ;is there ANY reason to redraw the menu?
  39. cmp #$01
  40. beq menuloop_redraw ;then do
  41. bra menuloop_s1
  42. menuloop_redraw
  43. stz menu_dirty
  44. jsr menu_statusbar
  45. jsr menu_redraw
  46. jsr menu_cleanup ;update phase 2
  47. bra menuloop_s1
  48. rts
  49. menu_cleanup:
  50. sep #$20 : .as
  51. rep #$10 : .xl
  52. lda dirend_onscreen ;end of file list on screen?
  53. beq menu_cleanup_out ;
  54. lda dirend_idx
  55. lsr
  56. lsr
  57. pha
  58. menu_cleanup_loop ;pad rest of screen with empty lines
  59. cmp listdisp ;end of screen reached?
  60. beq + ;then leave
  61. pha
  62. clc
  63. adc #$09 ;first line in text area
  64. inc
  65. sta print_y
  66. stz print_x
  67. lda #^space64
  68. ldx #!space64
  69. sta print_bank
  70. stx print_src
  71. stz print_pal
  72. lda #64
  73. sta print_count
  74. jsr hiprint
  75. pla
  76. inc
  77. bra menu_cleanup_loop
  78. +
  79. pla
  80. cmp menu_sel
  81. beq menu_cleanup_out
  82. bpl menu_cleanup_out
  83. sta menu_sel
  84. menu_cleanup_out
  85. rts
  86. menu_updates:
  87. ;update selection, scroll etc
  88. lda menu_sel
  89. asl
  90. asl
  91. sta dirptr_idx
  92. lda menu_sel
  93. clc
  94. adc #$08
  95. sta bar_yl
  96. lda #$3e
  97. sta bar_wl
  98. lda #$01
  99. sta bar_xl
  100. ;get input
  101. jsr read_pad
  102. lda #$04
  103. and pad1trig+1
  104. bne key_down
  105. lda #$08
  106. and pad1trig+1
  107. bne key_up
  108. lda #$01
  109. and pad1trig+1
  110. bne key_right
  111. lda #$02
  112. and pad1trig+1
  113. bne key_left
  114. lda #$80
  115. and pad1trig+1
  116. bne key_b
  117. lda #$20
  118. and pad1trig+1
  119. bne key_select
  120. lda #$80
  121. and pad1trig
  122. bne key_a
  123. lda #$40
  124. and pad1trig
  125. bne key_x
  126. bra menuupd_out
  127. key_down
  128. jsr menu_key_down
  129. bra menuupd_out
  130. key_up
  131. jsr menu_key_up
  132. bra menuupd_out
  133. key_right
  134. jsr menu_key_right
  135. bra menuupd_out
  136. key_left
  137. jsr menu_key_left
  138. bra menuupd_out
  139. key_b
  140. jsr menu_key_b
  141. bra menuupd_out
  142. key_a
  143. jsr menu_key_a
  144. bra menuupd_out
  145. key_x
  146. jsr menu_key_x
  147. bra menuupd_out
  148. key_select
  149. jsr menu_key_select
  150. bra menuupd_out
  151. menuupd_out
  152. lda #$09
  153. sta cursor_y
  154. rts
  155. menu_redraw:
  156. lda menu_state
  157. beq redraw_filelist
  158. ; cmp 1
  159. ; beq redraw_main
  160. menu_redraw_out
  161. rts
  162. redraw_filelist
  163. ldy #$0000
  164. sty dirptr_idx
  165. stz dirend_idx
  166. stz dirend_onscreen
  167. redraw_filelist_loop
  168. ldy dirptr_idx
  169. tya
  170. lsr
  171. lsr
  172. cmp listdisp
  173. beq redraw_filelist_last
  174. lda dirptr_bank
  175. phb
  176. pha
  177. plb
  178. rep #$20 : .al
  179. lda (dirptr_addr), y
  180. sta @dirent_addr
  181. iny
  182. iny
  183. sep #$20 : .as
  184. lda (dirptr_addr), y ; load fileinfo bank
  185. clc
  186. adc #$c0 ; add $C0 for memory map
  187. sta @dirent_bank ; store as current bank
  188. cmp #$c0 ; if bank was 0 -> dirend entry in DB
  189. beq redraw_filelist_dirend ; handle dirend
  190. iny
  191. lda (dirptr_addr), y
  192. iny
  193. sta @dirent_type
  194. plb
  195. sty dirptr_idx
  196. jsr print_direntry
  197. bra redraw_filelist_loop
  198. redraw_filelist_dirend
  199. plb
  200. dey ; recover last valid direntry number
  201. dey ; (we had 2x iny of the direntry pointer above,
  202. dey ; so account for those too)
  203. dey
  204. dey
  205. dey
  206. sty dirend_idx ; dirend_idx <- last valid directory entry.
  207. lda #$01 ; encountered during redraw, so must be on screen
  208. sta dirend_onscreen
  209. bra redraw_filelist_out
  210. redraw_filelist_last ;check if next offscreen item is end of dir
  211. lda dirptr_bank
  212. phb
  213. pha
  214. plb
  215. iny
  216. iny
  217. lda (dirptr_addr), y
  218. beq redraw_filelist_dirend
  219. plb
  220. redraw_filelist_out
  221. ldx #$0000
  222. stx dirptr_idx
  223. brl menu_redraw_out
  224. print_direntry:
  225. lda cursor_y
  226. sta print_y
  227. inc
  228. sta cursor_y
  229. lda dirent_bank
  230. ldx dirent_addr
  231. phb
  232. pha
  233. plb
  234. lda @dirent_type
  235. cmp #$80
  236. rep #$20 : .al
  237. bne dirent_is_file
  238. dirent_is_dir
  239. lda #$04 ;skip dir tgt
  240. sta @fd_fnoff
  241. lda #$01 ;different color for dirs
  242. bra dirent_type_cont
  243. dirent_is_file
  244. lda #$06 ;skip size string
  245. sta @fd_fnoff
  246. lda @dirent_type
  247. and #$00ff
  248. cmp #$0001 ;SMC -> palette 0 (white)
  249. bne +
  250. lda #$0000
  251. bra dirent_type_cont
  252. +
  253. cmp #$0004 ;IPS -> palette 2 (green)
  254. bne +
  255. lda #$0002
  256. bra dirent_type_cont
  257. +
  258. lda #$0000 ;default -> palette 0
  259. dirent_type_cont
  260. sta @print_pal
  261. rep #$20 : .al
  262. txa
  263. clc
  264. adc @fd_fnoff
  265. tax
  266. sep #$20 : .as
  267. lda !0, x ;load offset of leaf (file) name
  268. inc
  269. rep #$20 : .al
  270. and #$00ff ;kill hi byte
  271. sta @fd_fnoff
  272. txa
  273. clc
  274. adc @fd_fnoff
  275. sta @fd_fnoff
  276. plb
  277. lda cursor_x
  278. sta print_x
  279. sep #$20 : .as
  280. ldx fd_fnoff
  281. lda #54
  282. sta print_count
  283. stx print_src
  284. lda dirent_bank
  285. sta print_bank
  286. jsr hiprint
  287. lda cursor_x
  288. clc
  289. adc print_done
  290. sta print_x
  291. lda #54
  292. sec
  293. sbc print_done
  294. sta print_count
  295. lda #^space64
  296. ldx #!space64
  297. sta print_bank
  298. stx print_src
  299. jsr hiprint
  300. sep #$20 : .as
  301. lda dirent_type
  302. cmp #$80
  303. bne dirent_is_file_2
  304. lda #^text_dirmark
  305. ldx #!text_dirmark
  306. sta print_bank
  307. stx print_src
  308. bra dirent_type_cont_2
  309. dirent_is_file_2
  310. lda dirent_bank
  311. ldx dirent_addr
  312. sta print_bank
  313. stx print_src
  314. dirent_type_cont_2
  315. lda #56
  316. sta print_x
  317. lda #6
  318. sta print_count
  319. jsr hiprint
  320. rts
  321. menu_key_down:
  322. lda listdisp
  323. dec
  324. cmp menu_sel
  325. bne +
  326. lda #$01
  327. sta menu_dirty
  328. lda dirend_onscreen
  329. bne down_out
  330. rep #$20 : .al
  331. lda dirptr_addr
  332. clc
  333. adc #$04
  334. sta dirptr_addr
  335. sep #$20 : .as
  336. rts
  337. + lda dirend_onscreen
  338. beq +
  339. lda dirend_idx
  340. lsr
  341. lsr
  342. cmp menu_sel
  343. beq menuupd_lastcursor
  344. bcc menuupd_lastcursor
  345. + lda menu_sel
  346. inc
  347. sta menu_sel
  348. down_out
  349. rts
  350. menu_key_up:
  351. lda menu_sel
  352. bne +
  353. lda #$01
  354. sta menu_dirty
  355. rep #$20 : .al
  356. lda dirptr_addr
  357. cmp dirstart_addr
  358. beq up_out
  359. sec
  360. sbc #$04
  361. sta dirptr_addr
  362. bra up_out
  363. + dec
  364. sta menu_sel
  365. up_out
  366. sep #$20 : .as
  367. rts
  368. menuupd_lastcursor
  369. lda dirend_idx
  370. lsr
  371. lsr
  372. sta menu_sel
  373. rts
  374. ; go back one page
  375. menu_key_left:
  376. lda #$01 ; must redraw afterwards
  377. sta menu_dirty
  378. rep #$20 : .al
  379. lda dirptr_addr ; get current direntry pointer
  380. beq + ; special case: if 0, we are at the first entry in memory
  381. lsr
  382. lsr ; make comparable to listdisp
  383. cmp listdisp ; if there's less or equal previous entries...
  384. beq + ; ...than display lines, reset to directory start
  385. bcc +
  386. sec
  387. sbc listdisp ; subtract one screen page's worth of entries
  388. asl
  389. asl ; make comparable to dirstart_addr again
  390. cmp dirstart_addr ; check whether calculated offset is before...
  391. bcc + ; ...start of directory
  392. - sta dirptr_addr ; store new selected entry
  393. sep #$20 : .as
  394. rts
  395. + lda dirstart_addr ; reset pointer to start of directory
  396. stz menu_sel ; reset the selection cursor too
  397. bra -
  398. ; go forth one page
  399. menu_key_right:
  400. sep #$20 : .as
  401. lda dirend_onscreen
  402. bne menuupd_lastcursor
  403. lda #$01
  404. sta menu_dirty
  405. rep #$20 : .al
  406. lda listdisp
  407. asl
  408. asl
  409. clc
  410. adc dirptr_addr
  411. sta dirptr_addr
  412. sep #$20 : .as
  413. rts
  414. menu_key_b:
  415. jsr select_item
  416. rts
  417. menu_key_select:
  418. lda barstep
  419. beq do_setup448
  420. do_setup224
  421. jsr setup_224
  422. rts
  423. do_setup448
  424. jsr setup_448
  425. rts
  426. menu_key_a:
  427. rep #$20 : .al
  428. lda dirstart_addr
  429. beq skip_key_a
  430. sta dirptr_addr
  431. lda #$0000
  432. sta menu_sel
  433. bra select_item
  434. skip_key_a
  435. sep #$20 : .as
  436. rts
  437. select_item:
  438. rep #$20 : .al
  439. lda menu_sel
  440. and #$00ff
  441. asl
  442. asl
  443. tay
  444. sep #$20 : .as
  445. lda dirptr_bank
  446. phb
  447. pha
  448. plb
  449. iny
  450. iny
  451. iny
  452. lda (dirptr_addr), y
  453. cmp #$01
  454. beq sel_is_file
  455. cmp #$04
  456. beq sel_is_file
  457. cmp #$80
  458. beq sel_is_dir
  459. select_item_cont
  460. plb
  461. rts
  462. sel_is_file
  463. jsr select_file
  464. bra select_item_cont
  465. sel_is_dir
  466. jsr select_dir
  467. bra select_item_cont
  468. select_file:
  469. ; have avr load the rom
  470. dey
  471. rep #$20 : .al
  472. lda (dirptr_addr), y
  473. and #$00ff
  474. sta @AVR_PARAM+2
  475. dey
  476. dey
  477. lda (dirptr_addr), y
  478. sta @AVR_PARAM
  479. sep #$20 : .as
  480. lda #$01
  481. sta @AVR_CMD
  482. lda #$00
  483. sta @$4200
  484. sei
  485. jsl @wram_fadeloop
  486. rts
  487. select_dir: ; y = direntry ptr
  488. dey
  489. lda (dirptr_addr), y
  490. clc
  491. adc #$c0
  492. sta @dirent_bank
  493. dey
  494. dey
  495. rep #$20 : .al
  496. lda (dirptr_addr), y
  497. sta @dirent_addr
  498. tax
  499. sep #$20 : .as
  500. lda @dirent_bank
  501. phb
  502. pha
  503. plb
  504. lda !2, x ; load linked dir start bank
  505. clc
  506. adc #$c0
  507. sta @dirptr_bank
  508. sta @dirstart_bank
  509. rep #$20 : .al
  510. lda !0, x ; load linked dir start address
  511. sta @dirptr_addr
  512. sta @dirstart_addr
  513. lda #$0000
  514. sta @menu_sel
  515. sep #$20 : .as
  516. lda #$01
  517. sta @menu_dirty
  518. plb
  519. rts
  520. menu_key_x:
  521. jsr mainmenu
  522. rts
  523. setup_224:
  524. php
  525. rep #$30 : .xl : .al
  526. lda #18
  527. sta listdisp
  528. dec
  529. cmp menu_sel
  530. bmi setup_224_adjsel
  531. bra +
  532. setup_224_adjsel
  533. sta menu_sel
  534. +
  535. lda #18*64
  536. sta textdmasize
  537. lda #$0007
  538. sta hdma_scroll+8
  539. sep #$20 : .as
  540. lda #$07
  541. sta $2110
  542. lda #$00
  543. sta $2110
  544. lda #$00
  545. sta barstep
  546. ora #$08
  547. sta $2133
  548. lda #$08
  549. sta hdma_math_selection
  550. stz vidmode
  551. lda #$01
  552. sta menu_dirty
  553. lda #^space64
  554. ldx #!space64
  555. sta print_bank
  556. stx print_src
  557. stz print_pal
  558. lda #64
  559. sta print_count
  560. lda #27
  561. sta print_y
  562. stz print_x
  563. jsr hiprint
  564. lda #28
  565. sta print_y
  566. jsr hiprint
  567. jsr hiprint
  568. plp
  569. rts
  570. setup_448:
  571. php
  572. rep #$30 : .xl : .al
  573. lda #36
  574. sta listdisp
  575. lda #36*64
  576. sta textdmasize
  577. lda #$ffc6
  578. sta hdma_scroll+8
  579. sep #$20 : .as
  580. lda #$c6
  581. sta $2110
  582. lda #$ff
  583. sta $2110
  584. lda #$01
  585. sta barstep
  586. ora #$08
  587. sta $2133
  588. lda #$04
  589. sta hdma_math_selection
  590. lda #$01
  591. sta vidmode
  592. sta menu_dirty
  593. plp
  594. rts
  595. menu_statusbar
  596. pha
  597. phx
  598. php
  599. sep #$20 : .as
  600. rep #$10 : .xl
  601. lda #^text_statusbar_keys
  602. sta @print_bank
  603. rep #$20 : .al
  604. lda #!text_statusbar_keys
  605. sta @print_src
  606. sep #$20 : .as
  607. lda #$00
  608. sta @print_pal
  609. lda #$02
  610. sta @print_x
  611. lda #$40
  612. sta @print_count
  613. lda listdisp
  614. clc
  615. adc #$0a
  616. clc
  617. adc vidmode
  618. sta @print_y
  619. jsr hiprint
  620. plp
  621. plx
  622. pla
  623. rts