# A Note on Game Genie Codes for the NES

Last revised 2011-03-20.

(For lists of codes, see under NES at the Galoob web site. I have some homemade codes here.)

The current reference on Game Genie Codes for the Nintendo Entertainment System (N.E.S.) is the NES Game Genie Code Format DOC, version 0.71, by Benzene of Digital Emutations. It is short and to the point. Unfortunately its algorithm manipulates single bits to encipher and decipher the Game Genie Codes. This complicates the programming needlessly. Essentially the same method appears on pages by WyrmCorp and The Mighty Mike Master.

Here is an efficient algorithm:

Game Genie codes are made up from 16 letters, divided into two groups: [APZLGITY] and [EOXUKSVN]. Benzene, following others, treats these as low values (0–7) and high values (8–15). The correct coding assigns even values to the first group and odd values to the second:

 A=0 P=2 Z=4 L=6 G=8 I=10 T=12 Y=14 E=1 O=3 X=5 U=7 K=9 S=11 V=13 N=15

This coding preserves the nybble structure of the codes. The other does not and so requires bits to be rearranged.

Game Genie Codes for NES may be conditional or unconditional.

Unconditional: 16-bit ROM address, 8-bit replacement value.

Conditional: 16-bit ROM address, 8-bit replacement value, 8-bit compare value.

The conditional form is more common, because the NES maps ROM banks. An unconditional replacement would affect any ROM bank mapped in at the specified location. The original value at that location usually suffices to distinguish the desired bank. Unconditional substitution is good enough for a location with a fixed mapping.

## Enciphering

Define a nybble as half a byte, a byte's first or last 4 bits, high-order bit first. Let ABCD be the nybbles of the address, EF be those of the replacement value, and GH be those of the compare value if any. The high bit of the address is always 1 to the CPU, or 0 relative to the start of the ROM bank. Set it to 0 if the code is unconditional, 1 if conditional. Then rearrange the groups of 4 bits thus:

Rotate the bits one position leftward, then translate each nybble into its letter code.

Example: for infinite lives in Bomberman, replace the value at address \$c498 with \$a5. The address nybbles ABCD are 1100-0100-1001-1000; the value nybbles EF are 1010-0101. Clear the high bit of A and rearrange the nybbles according to the scheme FECADB; this gives 0101-1010-1001-0100-1000-0100. Rotating left gives 1011-0101-0010-1001-0000-1000, or SXPKAG.

 C 4 9 8 A 5 4 4 9 8 A 5 5 A 9 4 8 4 0101 1010 1001 0100 1000 0100 1011 0101 0010 1001 0000 1000 B 5 2 9 0 8 S X P K A G

## Deciphering

Reverse the process to decipher a code. That is, translate each letter to a nybble, rotate the bits one position rightward, and interpret the resulting nybbles as FECADB or FECADBHG, depending on the high bit of A. Finally, set the high bit of ABCD to get the CPU address.

Example: for infinite lives in Castlevania, the Game Genie code is OXNGLZVK. Translating to nybbles gives 0011-0101-1111-1000-0110-0100-1101-1001. Rotating one bit rightward gives 1001-1010-1111-1100-0011-0010-0110-1100, or \$9afc326c. Interpret these nybbles as FECADBHG; this gives an address ABCD of \$c2f3, a replacement value EF of \$a9, and a compare value GH of \$c6. (On a 6502, \$c6 is the opcode for decrementing a zero-page address, and \$a9 is a load immediate.)

Here is a Perl script that enciphers and deciphers Game Genie codes for the N.E.S.

“Game Genie” is a registered trademark of Lewis Galoob Toys, Inc.

Back to Crude ASCII Maps
Col. G. L. Sicherman [ HOME | MAIL ]