STEP 1: Set up a file for look up tables if you haven't already.
A lot of my codes use look up tables, and I find it's sometimes easier to use one file for all the smaller tables I have. Create an asm file and put it somewhere in the GameEngineData folder (if you're not sure, just put it into GameEngineData\Routines\UserScripts\), and paste the following code into it:
Code: Select all
CheatCodeInputs: ;; Make sure the number of inputs here is the same number as the one in the beginning of the press start script .db %00010000, %00010000, %00100000, %00100000, %01000000, %10000000, %01000000, %10000000, %00000010, %00000001 ;; by the way, I'd highly recommend doing only one input at a time, the NES reads scripts VERY quickly and unless you have superhuman precision it'll be impossible to activate. ;; 7 6 5 4 3 2 1 0 <-- Gamepad Bits ;; | | | | | | | | ;; | | | | | | | +--- RIGHT ;; | | | | | | +----- LEFT ;; | | | | | +------- DOWN ;; | | | | +--------- UP ;; | | | +----------- START ;; | | +------------- SELECT ;; | +--------------- B BUTTON ;; +----------------- A BUTTON
Now that you have that settled, you'll want to go into your MainASM.asm file in GameEngineData and include your script. Make sure you put it down toward the end, after the include for "HUD_DEFINES.dat", but before "columnTableLo". Like this:
STEP 2: Download the scripts and import them into NESmaker
Now you'll want to import your scripts. You can either download the attachment, or copy the codes pasted below and insert them into asm files yourself. Whichever's easier. (I'll be loading the codes up to NESmakerfiles.com soon as well.)
Code: Select all
Komami_Code: LDA CodeTimer ;; Make sure you create this and the CodeIndex variable in Project Settings (under the User Variables, set both initial values to 0) BNE dontResetCodeIndex ;;If the code timer is zero, that means the player ran out of time, and we need to reset the code index, otherwise don't reset it. LDA #$00 STA CodeIndex ;;here's where we reset the code index dontResetCodeIndex: LDX CodeIndex LDA CheatCodeInputs,x ;;This takes the code index (now in the x register) and loads the value in the CheatCodeInputs look up table CMP gamepad ;; This takes the value we just loaded and compares it to the gamepad bits BNE WrongInputWasMade ;;If they aren't equal, that means the wrong input was made, otherwise move on. INC CodeIndex ;;CodeIndex increases by 1 LDA #40 ;; IMPORTANT! Change this number if you want to raise or lower the amount of time the player has to make the next input correctly. ;; 40 will allow the player about 40 frames (given that the NES runs at around 60fps for ntsc games, that's about 2/3rds of a second) STA CodeTimer ;;We reset the code timer so now it will tick down by 1 every frame. ;PlaySound #SFX_LOCKED_DOOR ;; You can put a sound here so that it will play whenever you enter a correct input. RTS WrongInputWasMade: ;; You could also play a discouraging or "error" sound here if you want to let the player know that they made an incorrect input LDA #$00 STA CodeIndex RTS
Code: Select all
Press_StartonStartScreen: LDA CodeIndex ;;Now that the player has pressed start, we'll check the code index to see if the player input all the codes correctly CMP #10 ;;IMPORTANT! If you changed the amount of inputs in your code, you will want to change this to match. BCC cheatCodeNotComplete ;;BCC branches when the carry flag is cleared, or in the case of a CMP, when the value in A is less than the value it's being compared to. ;; INSERT CODE YOU WANT TO RUN WHEN SUCCESSFULLY ENTERING CHEAT CODE HERE JMP StartTheGame cheatCodeNotComplete: ;; INSERT CODE YOU WANT TO RUN WHEN CHEAT CODE IS ENTERED INCORRECTLY (OPTIONAL) StartTheGame: LDA #$00 STA CodeIndex ;; These codes were added as a redundancy, just in case someone decided to try turbo mashing the start button after completing the code. STA CodeTimer ;; It also resets the index in case the player goes back to the start screen after this. LDA #STATE_START_GAME STA change_state LDA #%10000000 STA gameHandler ;; turn sprites on RTS
Once you import those codes into your input scripts, add them into your editor. With the start screen, you can simply set it up to when the player presses start. The KomamiCodeInputs script is a bit more... involved.
You can see here that I highlighted all the inputs that my code uses (Up, down, left, right, b, and a). I wouldn't recommend using the same button for the start screen and the input script, though, as you might run into trouble there.
STEP 3: Set up some custom variables!
Normally you'd have to dive into the code for this, but thankfully the newest version of NESmaker allows you to define your own custom variables. Just go to Project Settings>User Variables, and create the following:
Easy peasy! Now that we have that over with, it's time for the last step...
STEP 4: Modifying HandleGameTimer.asm
You can find this script by going into Project Settings>Script Settings, highlighting the "Handle Game Timer" script, and clicking the "Edit" button. From there, you'll want to enter the following code right after the line "dontUpdateGameTimer:"...
Code: Select all
LDA CodeTimer BEQ SkipCodeTimerCooldown DEC CodeTimer SkipCodeTimerCooldown:
Once that's done, you should have a fully functioning cheat code script!