i had a friend of mine beta testing my Pitfall! clone and his skills are terrible. i decided to put a cheat code in to help him out and this i what i came up with:
i think it works nicely. has anyone else ever implemented a cheat system in their projects? i'd like to know how mine stacks up.
edit: should proabably describe it
so each frame of the title screen it checks the currently pressed buttons against a sequence of button presses.
1. if the sequence index(cheatIndex) is greater then the sequence size (8), the cheat is enabled.
2. else if the current pressed button matches the next button in sequence, the sequence index is incremented and then wait for another loop
3. if #2 fails, then the current pressed button is compared to the previous button in sequence. if it matches the, the code hangs for another loop.
4. else it resets the sequence index and we repeat.
if the whole process takes too long, then the cheat is no longer available
Code:
ldx cheatIndex ; if button_index >= cheat_length
cpx #08
bcs _cheat_Activate ; branch to set cheat == ACTIVE
lda P1Joypad ; if cur_pressed == cur_button
cmp cheatCodeData, X
beq _cheat_gotoNextButton ; branch to check next button on next loop
_cheat_checkPrevButton: dex ; else button didn't match
cpx #$FF
beq _cheat_resetIndex
cmp cheatCodeData, X ; so check if cur_pressed == prev_button
beq _cheat_HangOnPrevButton ; branch to wait for another frame
_cheat_resetIndex: ldx #00 ; else reset button index
stx cheatIndex
jmp _cheat_ExitCheck
_cheat_gotoNextButton: inx ; button matched so move on to next
stx cheatIndex
jmp _cheat_ExitCheck
_cheat_Activate: lda #01 ; all 8 buttons matched so set cheat==true
sta cheatActive
_cheat_HangOnPrevButton:
_cheat_ExitCheck:
cpx #08
bcs _cheat_Activate ; branch to set cheat == ACTIVE
lda P1Joypad ; if cur_pressed == cur_button
cmp cheatCodeData, X
beq _cheat_gotoNextButton ; branch to check next button on next loop
_cheat_checkPrevButton: dex ; else button didn't match
cpx #$FF
beq _cheat_resetIndex
cmp cheatCodeData, X ; so check if cur_pressed == prev_button
beq _cheat_HangOnPrevButton ; branch to wait for another frame
_cheat_resetIndex: ldx #00 ; else reset button index
stx cheatIndex
jmp _cheat_ExitCheck
_cheat_gotoNextButton: inx ; button matched so move on to next
stx cheatIndex
jmp _cheat_ExitCheck
_cheat_Activate: lda #01 ; all 8 buttons matched so set cheat==true
sta cheatActive
_cheat_HangOnPrevButton:
_cheat_ExitCheck:
i think it works nicely. has anyone else ever implemented a cheat system in their projects? i'd like to know how mine stacks up.
edit: should proabably describe it
so each frame of the title screen it checks the currently pressed buttons against a sequence of button presses.
1. if the sequence index(cheatIndex) is greater then the sequence size (8), the cheat is enabled.
2. else if the current pressed button matches the next button in sequence, the sequence index is incremented and then wait for another loop
3. if #2 fails, then the current pressed button is compared to the previous button in sequence. if it matches the, the code hangs for another loop.
4. else it resets the sequence index and we repeat.
if the whole process takes too long, then the cheat is no longer available