Sly 1:Codes

Codes is the subsystem that handles watching for cheat code inputs and executing cheat callbacks. A nearly identical system is used in and.

Startup
During initialization, the game calls, which calls   nine times. This function takes a pointer to a cheat code sequence (an array of shorts) and registers the cheat code so it can be triggered later.

Update
The  game loop calls   every frame to check if a cheat code has been entered. It keeps track of how many consecutive button presses you have entered without pausing.

For each input you make that is the correct input on a particular cheat code, it increments the counter on the CHEAT struct related to that code. If it checks your input against a particular cheat code sequence and finds an incorrect input, it resets that CHEAT counter to 0.

Once you've entered an entire code correctly (meaning amount of inputs you entered is the same as the length of the cheat code, and all the inputs were correct), it reads the callback function from the CHEAT struct and schedules it to be called on the current frame. This is when it plays the click sound effect you hear when a cheat code is entered.