game-and-watch-retro-go
game-and-watch-retro-go copied to clipboard
Add Game Genie Support for NES
Add Game Genie support for NES
To add Game Genie codes, create a .ggcodes file next to the .nes you want to add game genie codes for. The file is a simple CSV with each line containing "code(s), comment", like this example for Super Mario Bros 1:
SXIOPO, Inf lives APZLGG+APZLTG+GAZUAG, Mega jump YAZULG+YAZUIG+YAZUYG, Moon Gravity OZTLLX+AATLGZ+SZLIVO, Always fire YSAOPE+YEAOZA+YEAPYA, World 8-1 YSAOPE+YEAOZA+AOAPYA, World H-1 YSAOPE+YEAOZA+LXAPYA, World -1 TVVOAE, Circus music PIGPOG, All sorts of fun GOZSXX, Invincibility NPEPNY, Bullet bills 1-1 PINAOO, Cool colors
You can also comment out a line by putting // or # in front of a line.
These codes are collected by parse_roms and put in a static array in nes_roms.c. You can have a max of 16 codes (triple codes, like the World 8-1 code above, count as 1). Each rom is assigned a unique monotonically increasing id which references a rom structure in persistent_config_ram containing a 16 bit variable, each bit identifying which codes is currently active.
Before loading a rom, the user can select which game genie codes are active. When the rom is started, the set of game genie codes are converted into a list of addresses, values, and compares stored statically in game_genie.c. When a new PRG ROM bank is loaded into memory (in mmc_bankrom), the memory in that space is patched by calling into gameGeniePatchRom. A special function was added in nes_mem.c to allow writes to PRG memory.
To compile with game-genie support, add GAME_GENIE=1 to your make line.
Depends on https://github.com/kbeckmann/retro-go-stm32/pull/17
One issue I'm finding is with a fully loaded suite of ROMs filling a 64 megabyte chip is I blow out .rodata: "region `FLASH' overflowed by 40680 bytes" One option would be to reduce the description size. Another would be to not store the 8 character game genie code, but rather to encode that down to the raw 16-bit addr + 8-bit value + 8-bit comparison, which would get us down to 4 bytes instead of 8 per code, but it might be challenging to do in a static initialized way...