Fix menu navigation: restore original up/down behavior

- Keep loop counters in FindNextItem/FindPrevItem (prevents infinite recursion)
- Restore FindNextDownItem/FindNextUpItem to original logic:
  - Move ONE row, then delegate to FindNextItem if slot empty
- Fix boundary check in FindNextUpItem: use BEQ/BPL for signed comparison
  (CMP #$01 : BCS was wrong - unsigned comparison treats $FE as 254 >= 1)

The original design: Up/Down navigate rows, delegate to horizontal scan
if target slot is empty. The loop counters in horizontal navigation
prevent infinite loops when all items are empty.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
scawful
2025-12-06 23:25:16 -05:00
parent 841ef2d017
commit 791ebaf552

View File

@@ -83,14 +83,22 @@ Menu_ItemCursorPositions:
Menu_FindNextItem: Menu_FindNextItem:
{ {
LDY.w $0202 : INY PHX ; Save X for counter
CPY.b #$19 : BCC .no_reset LDX.b #$18 ; Max 24 items
LDY.b #$01 .loop
.no_reset LDY.w $0202 : INY
STY.w $0202 CPY.b #$19 : BCC .no_reset
LDX.w Menu_AddressIndex-1, Y LDY.b #$01
LDA.l $7EF300, X .no_reset
BEQ Menu_FindNextItem STY.w $0202
PHX
LDX.w Menu_AddressIndex-1, Y
LDA.l $7EF300, X
PLX
BNE .found ; Item exists, done
DEX : BNE .loop ; Keep searching
.found
PLX
RTS RTS
} }
@@ -98,13 +106,21 @@ Menu_FindNextItem:
Menu_FindPrevItem: Menu_FindPrevItem:
{ {
LDY.w $0202 : DEY : BNE .no_reset PHX ; Save X for counter
LDY.b #$18 LDX.b #$18 ; Max 24 items
.no_reset .loop
STY.w $0202 LDY.w $0202 : DEY : BNE .no_reset
LDX.w Menu_AddressIndex-1, Y LDY.b #$18
LDA.l $7EF300, X .no_reset
BEQ Menu_FindPrevItem STY.w $0202
PHX
LDX.w Menu_AddressIndex-1, Y
LDA.l $7EF300, X
PLX
BNE .found ; Item exists, done
DEX : BNE .loop ; Keep searching
.found
PLX
RTS RTS
} }
@@ -116,10 +132,10 @@ Menu_FindNextDownItem:
CMP.b #$19 : BCC .no_reset CMP.b #$19 : BCC .no_reset
SBC.b #$18 SBC.b #$18
.no_reset .no_reset
TAY : STY.w $0202 TAY : STY.w $0202
LDX.w Menu_AddressIndex-1, Y LDX.w Menu_AddressIndex-1, Y
LDA.l $7EF300, X LDA.l $7EF300, X
BEQ Menu_FindNextItem BEQ Menu_FindNextItem ; If empty, scan horizontally (now safe)
RTS RTS
} }
@@ -128,21 +144,15 @@ Menu_FindNextDownItem:
Menu_FindNextUpItem: Menu_FindNextUpItem:
{ {
LDA.w $0202 : SEC : SBC.b #$06 LDA.w $0202 : SEC : SBC.b #$06
BPL .no_reset : BNE .no_reset BEQ .wrap ; If zero, wrap
CLC : ADC.b #$18 BPL .no_reset ; If positive (1+), valid
.wrap
CLC : ADC.b #$18 ; Wrap to bottom row
.no_reset .no_reset
TAY : STY.w $0202 TAY : STY.w $0202
CPY.b #$19 : BCS .reset_up
LDX.w Menu_AddressIndex-1, Y
LDA.l $7EF300, X
BEQ Menu_FindNextItem
RTS
.reset_up
LDY.b #$01
STY.w $0202
LDX.w Menu_AddressIndex-1, Y LDX.w Menu_AddressIndex-1, Y
LDA.l $7EF300, X LDA.l $7EF300, X
BEQ Menu_FindNextItem BEQ Menu_FindNextItem ; If empty, scan horizontally (now safe)
RTS RTS
} }