diff --git a/res/prefs.conf b/res/prefs.conf index 1a72fe311..74832d88e 100644 --- a/res/prefs.conf +++ b/res/prefs.conf @@ -1 +1 @@ -# Total Replay preferences file # Do not edit by hand. # Or do. I'm a comment, not a cop. # value=attract mode module listed in ATTRACT.CONF, or empty NEXTATTRACT= # value=transition effect listed in FX.CONF, or empty NEXTFX= # value=transition effect listed in DFX.CONF, or empty NEXTDFX= [eof] \ No newline at end of file +# Total Replay preferences file # Do not edit by hand. # Or do. I'm a comment, not a cop. # value=attract mode module listed in ATTRACT.CONF, or empty NEXTATTRACT= # value=transition effect listed in FX.CONF, or empty NEXTFX= # value=transition effect listed in DFX.CONF, or empty NEXTDFX= # value=0 or 1 CHEAT=0 [eof] \ No newline at end of file diff --git a/src/4cade.init.a b/src/4cade.init.a index ff9eb391d..5b3451b4a 100644 --- a/src/4cade.init.a +++ b/src/4cade.init.a @@ -216,11 +216,20 @@ OneTimeSetup sta GameCount sta SAVE - lda #$80 ; TODO make this a pref + jsr pref_get ; see if cheats are enabled by default + !word kCheat + !word 0 + +STAY PTR ; (PTR) -> cheat pref value as length-prefixed string '1' or '0' + ldy #1 + lda (PTR),y ; A = #$B1 or #$B0 + and #1 ; A = #$01 or #$00 + clc + ror + ror ; A = #$80 or #$00 sta gCheatsEnabled ; calculate and update visible game count (3-digit decimal number as ASCII string) - ldy #0 + dey ; Y = 0 @outer lda #0 pha diff --git a/src/parse.prefs.a b/src/parse.prefs.a index 5b0f0c238..5e567436a 100644 --- a/src/parse.prefs.a +++ b/src/parse.prefs.a @@ -29,11 +29,14 @@ kNextFX kNextDFX !byte 7 !raw "NEXTDFX" +kCheat + !byte 5 + !raw "CHEAT" ;------------------------------------------------------------------------------ ; pref_get -; get pref value by pref key, and validate that the pref value exists as a key -; in another OKVS +; get pref value by pref key, and optionally validate that the pref value +; exists as a key in another OKVS ; ; example usage: ; jsr pref_get @@ -47,10 +50,12 @@ kNextDFX ; ; in: stack contains 4 bytes of parameters: ; +1 [word] address of length-prefixed pref key -; +3 [word] address of OKVS +; +3 [word] address of OKVS, or 0 ; gGlobalPrefsStore must be initialized (this is done in 4cade.init) ; out: A/Y = address of pref value ; X = index of pref value in passed store +; (if OKVS parameter is 0, no validation occurs and X=0 and Z=1 on exit, +; some callers rely on this behavior, so don't change it!) ; PARAM clobbered ; PTR clobbered ; SRC clobbered @@ -68,6 +73,8 @@ pref_get !word gGlobalPrefsStore @prefkey !word $FDFD ; SMC bcs .useDefaultValue ; if pref key is not found, use default value + ldx @store2+1 + beq @done +STAY + +STAY PTR ldy #0 @@ -84,7 +91,7 @@ pref_get @store2 !word $FDFD ; SMC @n !byte $FD ; SMC ldx @n - rts +@done rts ;------------------------------------------------------------------------------ ; pref_set @@ -140,6 +147,11 @@ pref_set +LDADDR kNextDFX jsr @addStringFromStore + +LDADDR @kFluff4 + jsr @addString + +LDADDR kCheat + jsr @addStringFromStore + +LDADDR @kEOF jsr @addString @@ -194,9 +206,12 @@ pref_set @kFluff2 !byte @kFluff3-*-1 !byte $0D !raw "# value=transition effect listed in FX.CONF, or empty",$0D -@kFluff3 !byte @kEOF-*-1 +@kFluff3 !byte @kFluff4-*-1 !byte $0D !raw "# value=transition effect listed in DFX.CONF, or empty",$0D +@kFluff4 !byte @kEOF-*-1 + !byte $0D + !raw "# value=0 or 1",$0D @kEOF !byte @_-*-1 !byte $0D !raw "[eof]",$0D diff --git a/src/ui.browse.mode.a b/src/ui.browse.mode.a index f7a63c81f..f8ca802a1 100644 --- a/src/ui.browse.mode.a +++ b/src/ui.browse.mode.a @@ -81,17 +81,21 @@ GameCount = *+1 ldx BrowseSelectedIndex jsr PlayGameFromBrowse jsr BlankHGR - jmp + + jmp .ForceBrowseChanged + +.OnCheat + jsr ToggleCheat + beq .ForceBrowseChanged ; always branches because Z=1 on exit from ToggleCheat .OnTab ldx BrowseSelectedIndex jsr MiniAttractMode cmp #$8D beq .OnLaunch -+ bit CLEARKBD +.ForceBrowseChanged + bit CLEARKBD ldx BrowseSelectedIndex ; execution falls through here - .OnBrowseChanged stx @index jsr okvs_nth ; get the name of the new game @@ -146,6 +150,7 @@ kBrowseExitToSearch = 3 kBrowseTab = 4 kBrowseLaunch = 5 kBrowseCredits = 6 +kBrowseCheat = 7 .BrowseDispatchTableLo !byte <.OnSearch @@ -155,6 +160,7 @@ kBrowseCredits = 6 !byte <.OnTab !byte <.OnLaunch !byte .OnSearch !byte >.OnPrevious @@ -163,9 +169,11 @@ kBrowseCredits = 6 !byte >.OnTab !byte >.OnLaunch !byte >Credits + !byte >.OnCheat -kNumBrowseKeys = 10 ; number of entries in next 2 tables (each) +kNumBrowseKeys = 11 ; number of entries in next 2 tables (each) .BrowseKeys + !byte $83 ; Ctrl-C = toggle cheat mode !byte $AF ; '/' = credits !byte $BF ; '?' = credits !byte $A0 ; Space = mini attract mode @@ -177,6 +185,7 @@ kNumBrowseKeys = 10 ; number of entries in next 2 tables (each) !byte $8B ; up arrow = previous !byte $88 ; left arrow = previous .BrowseKeyDispatch + !byte kBrowseCheat !byte kBrowseCredits !byte kBrowseCredits !byte kBrowseTab diff --git a/src/ui.cheats.a b/src/ui.cheats.a index d8ae272e5..1f7159476 100644 --- a/src/ui.cheats.a +++ b/src/ui.cheats.a @@ -4,11 +4,31 @@ ; cheat-related UI functions ; ; Public functions: +; - ToggleCheat ; - BuildUILine1WithNoDots ; - BuildCheatLine1 ; - BuildCheatLine2 ; +ToggleCheat +; in: none +; out: all registers clobbered +; X = 0, Z = 1 (guaranteed by pref_set) + lda gCheatsEnabled + eor #$80 + sta gCheatsEnabled + beq + + lda #$B1 + +HIDE_NEXT_2_BYTES ++ lda #$B0 + sta @val + jsr pref_set + !word kCheat + !word @pref + rts +@pref !byte 1 +@val !byte $FD + BuildUILine1WithNoDots ; in: X = game index, or #$FF if no game selected ; out: all registers clobbered diff --git a/src/ui.search.mode.a b/src/ui.search.mode.a index 841495ef1..73836f6ba 100644 --- a/src/ui.search.mode.a +++ b/src/ui.search.mode.a @@ -107,6 +107,10 @@ SearchMode sec ; tell caller to redraw UI rts +.OnCheat + jsr ToggleCheat + beq .OnInputChanged ; always branches because Z=1 on exit from ToggleCheat + .OnSearch ldx InputLength cpx #MaxInputLength @@ -236,7 +240,8 @@ kInputBrowse = 3 kInputTab = 4 kInputLaunch = 5 kInputCredits = 6 -kInputError = 7 +kInputCheat = 7 +kInputError = 8 .InputDispatchTableLo !byte <.OnSearch @@ -246,6 +251,7 @@ kInputError = 7 !byte <.OnTab !byte <.OnLaunch !byte .OnSearch @@ -255,10 +261,12 @@ kInputError = 7 !byte >.OnTab !byte >.OnLaunch !byte >Credits + !byte >.OnCheat !byte >.OnError -kNumInputKeys = 8 ; number of entries in next 2 tables (each) +kNumInputKeys = 9 ; number of entries in next 2 tables (each) .InputKeys + !byte $83 ; Ctrl-C = toggle cheat mode !byte $AF ; '/' = credits !byte $BF ; '?' = credits !byte $A0 ; Space = mini attract mode @@ -270,6 +278,7 @@ kNumInputKeys = 8 ; number of entries in next 2 tables (each) !byte $9B ; Esc = clear input buffer (if any) ; or switch to mega attract mode .InputKeyDispatch + !byte kInputCheat !byte kInputCredits !byte kInputCredits !byte kInputTab