Skip to content

feat: restore last game folder/rom position on reset-to-menu (#87) - #293

Open
Xeroxxx wants to merge 4 commits into
mrehkopf:masterfrom
Xeroxxx:feat/resettolastentry
Open

feat: restore last game folder/rom position on reset-to-menu (#87)#293
Xeroxxx wants to merge 4 commits into
mrehkopf:masterfrom
Xeroxxx:feat/resettolastentry

Conversation

@Xeroxxx

@Xeroxxx Xeroxxx commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

May close: #87

Reset to menu got extended with two more options: Rom and Folder

  • Rom drops back to last folder and the cursor is on the rom previously launched.
  • Folder drops back to the folder where the last rom was launched from.
  • On/Off unchanged
  • Only on Warmboot/Reset
  • Coldboot behavior stays unchanged.

https://www.youtube.com/watch?v=pQI8CDfdafI

@spend-cloud-tom

Copy link
Copy Markdown

Reset-to-menu in Folder/Rom mode lands one folder short for paths a few levels deep

Repro: put a ROM at /A/B/C/D/E/Game.smc, set Reset to menu = Folder, run it, short-reset. The menu opens in /A/B/C/D/ instead of /A/B/C/D/E/.

Cause

The outer loop in filesel_nav_last uses X as the cursor into LAST_GAME_DIR, but jsr fnl_enter_subdir clobbers X:

  • fnl_cmp_subdir reuses X as its compare index (it only happens to leave it at testvar+2 on a successful match — that's incidental, not by contract);
  • fnl_append_cwd uses X as the FILESEL_CWD write index;
  • filesel_request_filelist calls WRAM_WAIT_MCU, hide_cursor, pop_window, none of which preserve X.

So the inx after fnl_enter_subdir increments whatever X ended up as — usually not the slash position the loop expects. The cursor drifts each iteration; whether the loop happens to terminate one component early depends on path content (which is why short paths sometimes appear to work).

The fnl_got_comp_eos branch is unaffected because it falls through to fnl_find_file/fnl_out and never re-reads from X.

Fix

 fnl_got_comp_slash:
   stx testvar+2           ; fnl_comp_end = x (exclusive, '/' position)
   jsr fnl_enter_subdir
   bcc fnl_out             ; not found — bail out
+  ldx testvar+2           ; restore x (clobbered inside fnl_enter_subdir)
   inx                     ; skip '/'
   bra fnl_comp_loop

Verified locally: with the patch the menu returns to the deepest folder for a 5-deep path. Haven't done an exhaustive sweep of Rom-mode edge cases.

@Xeroxxx

Xeroxxx commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

@spend-cloud-tom Thanks for testing. The proposed fix is spot on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Continue in previous directory instead of dropping to root directory on reset to menu

2 participants