GameShark, cheat devices, and PlayStation runtime function patching
How GameShark and cheat devices worked on the PlayStation 1.
I’ve spent hundreds of hours trying to escape 3d worlds through map glitches and bugs. For some players, bending and breaking the rules of a game is part of the fun. It’s fascinating to make games do things their developers never intended.
Exploring the boundaries of a game – and perhaps improving it on the way – brought us modding and homebrew video games. Modding and reverse engineering go hand in hand; modifying a game without any understanding of it’s data structures or architecture is a dire effort.
In the past, a tiny fraction of players possessed the skills and determination to produce mods, while a large majority of players would have happily played modified games. This division is where Datel struck gold in the 1990’s.
Datel was a UK-based company that specialized in game enhancing hardware and software. Together with their American partner InterAct they released GameShark in 19961. It was a small bootable cartridge that connects to the parallel port of the PlayStation. With the GameShark, players could activate “cheats” before booting up a game.
The cheats could grant the player infinite ammo, health or unlock characters and levels that weren’t available through traditional cheat codes.
The GameShark was a massive hit, selling millions of units2. In Europe, the device was marketed under the Action Replay brand. If you’re interested in the marketing side, Defunct Games has a great collection of GameShark print advertisements.
Datel continued their research and improved GameShark over the years. Among other things, they developed two CD versions of the GameShark, which don’t require a cartridge. That in itself is a remarkable thing, but that’s another story.
How GameShark codes work
Every game has a built-in table of functions that modify the game’s state. The game state consists of player position, current health etc. and these are stored in main RAM.
During gameplay, when the player takes a hit, the health value in RAM is decreased. GameShark could prevent the loss of health, either by constantly overwriting the health value, or modifying the function that decreases the value. This advanced technique, called runtime function patching, requires understanding of low-level programming and the hardware.
The genius of GameShark was to package these complex memory operations as something players were already familiar with: cheat codes3. For the majority, GameShark provided universal cheat codes that could be looked up in magazines or on the web.
Upon a closer look though, GameShark codes are memory patch instructions encoded in hexadecimal4,5. They follow a system. An interactive listing of GameShark PS1 codes is shown in figure 2.
For example the code 80XXXXXX YYYY writes the value specified by YYYY to address XXXXXX, every frame.
The address could be the player’s health, and the value would be the desired value.
Let’s see how we’d go about that.
Take this example code for a game’s hit logic in c:
struct Player {
short hp; // player.hp lives at 0x800A1240
} player;
void player_hit(int damage) {
player.hp -= damage;
if (player.hp <= 0)
player_die();
}
A Player struct stores the players health.
It’s allocated somewhere in the RAM as a level starts.
The GameShark cartridge contained a code generator tool, essentially a memory scanner, which was used to discover new codes6. We won’t go into debuggers and memory scanners in this article, but this tutorial VHS has got you covered.
Let’s assume, for now, that hp is always stored at a known memory address 0x800A1240.
The most trivial memory patch is to overwrite the player.hp value every frame.
We know the address (0x800 + offset A1240) and our desired value is 100 (64h), so the corresponding GameShark code is:
80A1240 0064 // player.hp = 100, every frame
Every frame, the health is reset to 100. We’ve now got an infinite health cheat.
But what makes the write happen every frame? How do we use this cheat code?
The cheat engine
GameShark codes are applied by the cheat engine, a program that is loaded to unused RAM prior to starting the game. The engine is loaded to RAM by the GameShark cartridge or CD, as they take on the role of a bootloader.
The outline is:
-
The console is first booted into the GameShark menu using the cartridge or the CD. In the menu, you have the option to activate cheats as well as start the actual game.
-
As the game boots, the cheat engine (along with the active cheat list) is injected to an unused region in kernel RAM. An additional hook to call the cheat engine is added to the vblank routine7, which runs every frame.
-
The cheat engine is executed every frame and it performs the operations as programmed by the active cheat codes; like a tiny virtual machine.

It’s quite remarkable to see it all work. But as I’ve hinted, the cheat engine is not limited to a single cheat code. Let’s dive into more memory patching.
A deeper dive in memory patching
Our first patch only had one single instruction to overwrite a value. With multiple codes, it’s possible to patch memory to any wanted configuration.
Recall our earlier example program.
The player_hit() is called when the player takes damage.
struct Player {
short hp; // player.hp lives at 0x800A1240
} player;
void player_hit(int damage) {
player.hp -= damage;
if (player.hp <= 0)
player_die();
}
Below is the same program compiled to R3000 machine code.
Following the PlayStation calling conventions,
The compiler translates the function to a stack allocation for function arguments (a0-a3) and a store instruction for the return address.
The damage is passed in the first argument register a0.
This is followed by the actual function body, which is what we’re interested in.
Here’s the R3000 machine code for the player_hit() function body:
| Address | Machine code | Assembly | Meaning |
|---|---|---|---|
| Function body | |||
80010000 |
3C03800A |
lui v1, 0x800A |
v1 = 0x800A0000 |
80010004 |
84621240 |
lh v0, 0x1240(v1) |
v0 = player.hp |
80010008 |
00000000 |
nop |
(load delay slot) |
8001000C |
00441023 |
subu v0, v0, a0 |
v0 -= damage |
80010010 |
A4621240 |
sh v0, 0x1240(v1) |
player.hp = v0 |
80010014 |
00021400 |
sll v0, v0, 16 |
sign-extend the short… |
80010018 |
00021403 |
sra v0, v0, 16 |
…to a full int |
8001001C |
1C400003 |
bgtz v0, 0x8001002C |
if hp > 0, return |
80010020 |
00000000 |
nop |
(branch delay slot) |
80010024 |
0C004040 |
jal player_die |
call player_die() |
80010028 |
00000000 |
nop |
(jump delay slot) |
Don’t worry if it looks overwhelming. You might be more comfortable reading the “Meaning” column.
We’re interested in the instruction that subtracts the damage from our health:
subu v0, v0, a0
The subu stands for “subtract unsigned”8 and, as mentioned previously, a0 is the zeroth function argument, i.e. damage.
To stop the damage, we can replace the instruction with a nop for “No operation”.
| Address | Patched code | Assembly | Meaning |
|---|---|---|---|
8001000C |
|
|
do nothing |
To get that nop we need to patch the machine instruction to 00000000.
That’s a 32-bit number or four bytes.
The PS1 GameShark doesn’t support 32-bit writes, so we need to do two 16-bit writes:
801000C 0000 // write low half
801000E 0000 // write high half
This works, but there are more elegant solutions.
By replacing the argument a0 in the original instruction with a constant zero value, we essentially get a no-op:
| Address | Patched code | Assembly | Meaning |
|---|---|---|---|
8001000C |
|
subu v0, v0, |
v0 -= 0 |
This is useful because the patched machine code differs only by one digit in the high half. Therefore a single 16-bit patch operation is enough. The GameShark code is:
801000E 0040 // write high half
It’s perfect! That is until your game crashes on startup.
The memory address 8001000C might be used for something else before your character appears on screen.
Poking random memory addresses seldom results in good things, so a guard is needed.
Here’s where the D0 and D1 GameShark codes come in handy.
The D0 works like a conditional.
Using it, we can check that the instruction at the address is subu.
D001000C 1023 // if the low half at 8001000C is 1023
8001000E 0040 // write high half
This patch only changes the high half when the instruction is the right one. We can finally launch the game without crashing and enjoy our invincible character.
Phew!
Epilogue
Most modern consoles are locked and cheat devices are a thing of the past. On the bright side, most emulators support GameShark cheat codes.
It’s also possible to do binary patching instead of patching a running game. In fact, ROM patches are how most PlayStation mods and translations are distributed today.
ROM patching works for emulation, but booting custom code on the PlayStation hardware is far from trivial. See my article on compiling and running Hello world on the original PlayStation hardware.
Hence, GameShark is still relevant and fun today. There are still dozens of sites with GameShark codes. Go try them out!
-
Cheating comes to 32-bit systems, Electronic Gaming Monthly, Issue 78, 1996 (archived). ↩
-
Press release in Nintendo World Report, 2002 (archived). ↩
-
And Action Replay, and probably others before that. ↩
-
How To Hack Like A Pro VHS by InterAct. ↩
-
Some games use the vblank routine themselves and overwrite the GameShark handler as they boot. For these games, GameShark’s CD versions provided customized addresses for injecting handler routines. ↩
-
LSI Logic LR33300 and LR33310 Self-Embedding Processors User’s Manual, Chapter 3. ↩