From ede9da49ff7a04d785cbd0867de281fab9fb0eb2 Mon Sep 17 00:00:00 2001 From: 4am Date: Wed, 10 Jul 2024 15:33:04 -0400 Subject: [PATCH] press asterisk to select random game closes #226 --- src/ui.browse.mode.a | 77 ++++++++++++++++++++++++++++++++++++++++++-- src/ui.common.a | 14 ++++---- src/ui.search.mode.a | 7 ++-- 3 files changed, 85 insertions(+), 13 deletions(-) diff --git a/src/ui.browse.mode.a b/src/ui.browse.mode.a index d97c6f1a3..03db00fab 100644 --- a/src/ui.browse.mode.a +++ b/src/ui.browse.mode.a @@ -37,6 +37,7 @@ kSoftBell = 9 ; must match kInputError kBrowseJoystick = 10 kBrowseQuit = 11 kBrowseSHR = 12 +kBrowseRandom = 13 ldy #kNumBrowseKeys - dey @@ -94,6 +95,18 @@ notLastGame +STX16 gGameToLaunch jmp OnBrowseChanged +OnBrowseRandom + bit $ff58 + +LD16 RNDSEED + +ST16 .rnd + jsr n_mod_m +.rnd !word 0 +GameCount + !word 0 + stx gGameToLaunch + sta gGameToLaunch+1 + jmp OnBrowseChanged + ReloadIndexAndLaunch jsr ReloadSearchIndex OnBrowseLaunch @@ -144,6 +157,7 @@ BrowseDispatchTableLo !byte OnBrowseSearch !byte >OnBrowsePrevious @@ -158,8 +172,9 @@ BrowseDispatchTableHi !byte >Joystick !byte >OnQuit !byte >AllSHRSlideshow + !byte >OnBrowseRandom -kNumBrowseKeys = 15 +kNumBrowseKeys = 16 ; number of entries in next 2 tables (each) BrowseKeys !byte $80 ; Ctrl-@ = SHR-only slideshow @@ -177,6 +192,7 @@ BrowseKeys !byte $8A ; down arrow = next !byte $88 ; left arrow = previous !byte $95 ; right arrow = next + !byte $AA ; '*' = select random BrowseKeyDispatch !byte kBrowseSHR !byte kBrowseCheat @@ -193,6 +209,61 @@ BrowseKeyDispatch !byte kBrowseNext !byte kBrowsePrevious !byte kBrowseNext + !byte kBrowseRandom -GameCount - !word 0 +;------------------------------------------------------------------------------ +; n_mod_m +; Calculate remainder of dividing two 16-bit numbers (often written in modern +; programming languages as 'n % m') +; +; in: stack contains 4 bytes of parameters: +; +1 [word] n +; +3 [word] m +; out: 16-bit value returned in X (high) and A (lo) +; clobbers Y +; clobbers zp$00..$05 +;------------------------------------------------------------------------------ +;out: X (low), A (high) +;trashes Y, and $0-5 +n_mod_m + pla + tay + pla + tax + iny + bne + + inx ++ sty $0 + stx $1 + ldy #3 + clc + tya + adc $0 + sta $2 + bcc + + inx ++ txa + pha + lda $2 + pha +- lda ($0),y + sta $2,y + dey + bpl - + sec +- lda $2 + sbc $4 + tax + lda $3 + sbc $5 + bcc + + stx $2 + sta $3 + bcs - ; always branches ++ tay + txa + adc $4 + tax + tya + adc $5 + rts diff --git a/src/ui.common.a b/src/ui.common.a index d9cae2121..58f8d3e97 100755 --- a/src/ui.common.a +++ b/src/ui.common.a @@ -8,7 +8,7 @@ ; - BlankDHGR ; - DHGRMode ; - IsSearchKey -; - IsUpDownOrRightArrow +; - IsKeyThatSwitchesToBrowseMode ; ;------------------------------------------------------------------------------ @@ -137,19 +137,21 @@ IsSearchKey rts ;------------------------------------------------------------------------------ -; IsUpDownOrRightArrow -; test whether accumulator contains ASCII code for up, down, or right arrow -; search +; IsKeyThatSwitchesToBrowseMode +; test whether accumulator contains ASCII code for up, down, or right arrow, +; or asterisk ; ; in: A = key ; out: all registers preserved -; Z = 1 if accumulator was one of those 3 keys +; Z = 1 if accumulator was one of those keys ; Z = 0 otherwise ;------------------------------------------------------------------------------ -IsUpDownOrRightArrow +IsKeyThatSwitchesToBrowseMode cmp #$8B ; up arrow beq @done cmp #$95 ; right arrow beq @done cmp #$8A ; down arrow + beq @done + cmp #$AA ; '*' @done rts diff --git a/src/ui.search.mode.a b/src/ui.search.mode.a index c6f5c1703..4a0dbe5d1 100644 --- a/src/ui.search.mode.a +++ b/src/ui.search.mode.a @@ -132,12 +132,11 @@ SearchMode .SearchModeInputLoop jsr WaitForKeyFor30Seconds - ; Don't clear keyboard strobe yet. If the user pressed an arrow key, - ; we want to switch to Browse Mode with the keyboard still hot so - ; that mode finds and dispatches the arrow key. + ; Don't clear keyboard strobe yet. Certain keys switch to Browse Mode + ; with the keyboard still hot so that mode dispatches it ldx #kInputBrowse - jsr IsUpDownOrRightArrow + jsr IsKeyThatSwitchesToBrowseMode beq .InputDispatch bit CLEARKBD