123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560 |
- #include "memmap.i65"
- #include "dma.i65"
- menu_init:
- sep #$20 : .as
- rep #$10 : .xl
- lda #^ROOT_DIR
- ldx #!ROOT_DIR
- sta dirptr_bank
- stx dirptr_addr
- sta dirstart_bank
- stx dirstart_addr
- stz menu_state
- stz dirend_onscreen
- lda #$04
- sta cursor_x
- lda #$09
- sta cursor_y
- ldx #$0000
- stx dirptr_idx
- stx menu_sel
- lda #$01
- sta menu_dirty
- rts
- menuloop:
- menuloop_s1
- sep #$20 : .as
- rep #$10 : .xl
- lda isr_done
- lsr
- bcc menuloop_s1
- stz isr_done
- jsr menu_cleanup ;update phase 2
- jsr menu_updates ;update stuff, check keys etc
- lda menu_dirty ;is there ANY reason to redraw the menu?
- cmp #$01
- beq menuloop_redraw ;then do
- bra menuloop_s1
- menuloop_redraw
- stz menu_dirty
- jsr menu_redraw
- bra menuloop_s1
- rts
- menu_cleanup:
- sep #$20 : .as
- rep #$10 : .xl
- lda dirend_onscreen
- beq menu_cleanup_out
- lda dirend_idx
- lsr
- lsr
- pha
- menu_cleanup_loop
- cmp listdisp
- beq +
- pha
- clc
- adc #$09
- sta print_y
- lda #^space64
- ldx #!space64
- sta print_bank
- stx print_src
- stz print_pal
- lda #64
- sta print_count
- jsr hiprint
- pla
- inc
- bra menu_cleanup_loop
- +
- pla
- cmp menu_sel
- beq menu_cleanup_out
- bpl menu_cleanup_out
- sta menu_sel
- menu_cleanup_out
- rts
-
- menu_updates:
- ;update selection, scroll etc
- lda menu_sel
- asl
- asl
- sta dirptr_idx
- lda menu_sel
- clc
- adc #$08
- sta bar_yl
- ;get input
- jsr read_pad
- lda #$04
- and pad1trig+1
- bne key_down
- lda #$08
- and pad1trig+1
- bne key_up
- lda #$01
- and pad1trig+1
- bne key_right
- lda #$02
- and pad1trig+1
- bne key_left
- lda #$80
- and pad1trig+1
- bne key_b
- lda #$20
- and pad1trig+1
- bne key_select
- lda #$80
- and pad1trig
- bne key_a
- bra menuupd_out
- key_down
- jsr menu_key_down
- bra menuupd_out
- key_up
- jsr menu_key_up
- bra menuupd_out
- key_right
- jsr menu_key_right
- bra menuupd_out
- key_left
- jsr menu_key_left
- bra menuupd_out
- key_b
- jsr menu_key_b
- bra menuupd_out
- key_a
- jsr menu_key_a
- bra menuupd_out
- key_select
- jsr menu_key_select
- bra menuupd_out
- menuupd_out
- lda #$09
- sta cursor_y
- rts
- menu_redraw:
- lda menu_state
- beq redraw_filelist
- ; cmp 1
- ; beq redraw_main
- menu_redraw_out
- rts
- redraw_filelist
- ldy #$0000
- sty dirptr_idx
- stz dirend_idx
- stz dirend_onscreen
- redraw_filelist_loop
- ldy dirptr_idx
- tya
- lsr
- lsr
- cmp listdisp
- beq redraw_filelist_last
- lda dirptr_bank
- phb
- pha
- plb
- rep #$20 : .al
- lda (dirptr_addr), y
- sta @dirent_addr
- iny
- iny
- sep #$20 : .as
- lda (dirptr_addr), y
- clc
- adc #$c0
- sta @dirent_bank
- cmp #$c0
- beq redraw_filelist_dirend
- iny
- lda (dirptr_addr), y
- iny
- sta @dirent_type
- plb
- sty dirptr_idx
- jsr print_direntry
- bra redraw_filelist_loop
- redraw_filelist_dirend
- plb
- dey
- dey
- dey
- dey
- dey
- dey
- sty dirend_idx
- lda #$01
- sta dirend_onscreen
- bra redraw_filelist_out
- redraw_filelist_last ;check if next offscreen item is end of dir
- lda dirptr_bank
- phb
- pha
- plb
- iny
- iny
- lda (dirptr_addr), y
- beq redraw_filelist_dirend
- plb
- redraw_filelist_out
- ldx #$0000
- stx dirptr_idx
- brl menu_redraw_out
- print_direntry:
- lda dirent_bank
- ldx dirent_addr
- phb
- pha
- plb
- lda @dirent_type
- cmp #$80
- rep #$20 : .al
- bne dirent_is_file
- dirent_is_dir
- lda #$04 ;skip dir tgt
- sta @fd_fnoff
- lda #$01 ;different color for dirs
- sta @print_pal
- bra dirent_type_cont
- dirent_is_file
- lda #$40 ;skip game header
- sta @fd_fnoff
- lda #$00
- sta @print_pal ;palette 0 (white)
- dirent_type_cont
- txa
- clc
- adc @fd_fnoff
- tax
- sep #$20 : .as
- lda !0, x ;load offset of leaf (file) name
- clc
- adc #1
- rep #$20 : .al
- and #$00ff ;kill hi byte
- sta @fd_fnoff
- txa
- adc @fd_fnoff
- sta @fd_fnoff
- plb
- lda cursor_y
- sta print_y
- inc
- sta cursor_y
- lda cursor_x
- sta print_x
- sep #$20 : .as
- ldx fd_fnoff
- lda #58
- sta print_count
- stx print_src
- lda dirent_bank
- sta print_bank
- jsr hiprint
- lda cursor_x
- clc
- adc print_done
- sta print_x
- lda #58
- sec
- sbc print_done
- sta print_count
- lda #^space64
- ldx #!space64
- sta print_bank
- stx print_src
- jsr hiprint
- rts
-
- menu_key_down:
- lda listdisp
- dec
- cmp menu_sel
- bne +
- lda #$01
- sta menu_dirty
- lda dirend_onscreen
- bne down_out
- rep #$20 : .al
- lda dirptr_addr
- clc
- adc #$04
- sta dirptr_addr
- sep #$20 : .as
- rts
- + lda menu_sel
- inc
- sta menu_sel
- down_out
- rts
- menu_key_up:
- lda menu_sel
- bne +
- lda #$01
- sta menu_dirty
- rep #$20 : .al
- lda dirptr_addr
- cmp dirstart_addr
- beq up_out
- sec
- sbc #$04
- sta dirptr_addr
- bra up_out
- + dec
- sta menu_sel
- up_out
- sep #$20 : .as
- rts
- menu_key_left:
- lda #$01
- sta menu_dirty
- rep #$20 : .al
- lda dirptr_addr
- beq +
- sec
- sbc listdisp
- sec
- sbc listdisp
- sec
- sbc listdisp
- sec
- sbc listdisp
- bcc +
- cmp dirstart_addr
- bcc +
- - sta dirptr_addr
- sep #$20 : .as
- rts
- + lda dirstart_addr
- sep #$20 : .as
- stz menu_sel
- rep #$20 : .al
- bra -
-
- menu_key_right:
- sep #$20 : .as
- lda dirend_onscreen
- bne menuupd_lastcursor
- lda #$01
- sta menu_dirty
- rep #$20 : .al
- lda listdisp
- asl
- asl
- clc
- adc dirptr_addr
- sta dirptr_addr
- sep #$20 : .as
- rts
- menuupd_lastcursor
- lda dirend_idx
- lsr
- lsr
- sta menu_sel
- rts
- menu_key_b:
- jsr select_item
- rts
- menu_key_select:
- lda barstep
- beq do_setup448
- do_setup224
- jsr setup_224
- rts
- do_setup448
- jsr setup_448
- rts
- menu_key_a:
- rep #$20 : .al
- lda dirstart_addr
- beq skip_key_a
- sta dirptr_addr
- lda #$0000
- sta menu_sel
- bra select_item
- skip_key_a
- sep #$20 : .as
- rts
- select_item:
- rep #$20 : .al
- lda menu_sel
- and #$00ff
- asl
- asl
- tay
- sep #$20 : .as
- lda dirptr_bank
- phb
- pha
- plb
- iny
- iny
- iny
- lda (dirptr_addr), y
- beq sel_is_file
- cmp #$80
- beq sel_is_dir
- select_item_cont
- plb
- rts
- sel_is_file
- jsr select_file
- bra select_item_cont
- sel_is_dir
- jsr select_dir
- bra select_item_cont
- select_file:
- ; have avr load the rom
- dey
- lda (dirptr_addr), y
- sta @AVR_PARAM+2
- rep #$20 : .al
- dey
- dey
- lda (dirptr_addr), y
- sta @AVR_PARAM
- sep #$20 : .as
- lda #$01
- sta @AVR_CMD
- lda #$00
- sta @$4200
- cli
- jsl @infloop
- rts
- select_dir: ; y = direntry ptr
- dey
- lda (dirptr_addr), y
- clc
- adc #$c0
- sta @dirent_bank
- dey
- dey
- rep #$20 : .al
- lda (dirptr_addr), y
- sta @dirent_addr
- tax
- sep #$20 : .as
- lda @dirent_bank
- phb
- pha
- plb
- lda !2, x ; load linked dir start bank
- clc
- adc #$c0
- sta @dirptr_bank
- sta @dirstart_bank
- rep #$20 : .al
- lda !0, x ; load linked dir start address
- sta @dirptr_addr
- sta @dirstart_addr
- lda #$0000
- sta @menu_sel
- sep #$20 : .as
- lda #$01
- sta @menu_dirty
- plb
- rts
- setup_224:
- php
- rep #$30 : .xl : .al
- lda #18
- sta listdisp
- dec
- cmp menu_sel
- bmi setup_228_adjsel
- bra +
- setup_228_adjsel
- sta menu_sel
- +
- lda #19*64
- sta textdmasize
- lda #$0007
- sta hdma_scroll+8
- sep #$20 : .as
- lda #$07
- sta $2110
- lda #$00
- sta $2110
- lda #$00
- sta barstep
- ora #$08
- sta $2133
- lda #$0a
- sta hdma_math+6
- lda #$01
- sta menu_dirty
- lda #^space64
- ldx #!space64
- sta print_bank
- stx print_src
- stz print_pal
- lda #64
- sta print_count
- lda #27
- sta print_y
- stz print_x
- jsr hiprint
- lda #28
- sta print_y
- jsr hiprint
- jsr hiprint
-
- plp
- rts
- setup_448:
- php
- rep #$30 : .xl : .al
- lda #36
- sta listdisp
- lda #38*64
- sta textdmasize
- lda #$ffc6
- sta hdma_scroll+8
- sep #$20 : .as
- lda #$c6
- sta $2110
- lda #$ff
- sta $2110
- lda #$01
- sta barstep
- ora #$08
- sta $2133
- lda #$06
- sta hdma_math+6
- lda #$01
- sta menu_dirty
- plp
- rts
|