(For lists of codes, see under NES at the Galoob web site. I have a few custom codes on my pages for Legend of Zelda, Final Fantasy, Final Fantasy II, Final Fantasy 3, The Bard's Tale, Mother (Earthbound Zero), Ninja Gaiden, Willow, and Kid Icarus.)
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:
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.
FECADB or FECADBHG
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.
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.