Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Add Game Genie Support for NES #186

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

martaaay
Copy link

@martaaay martaaay commented Jan 14, 2022

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 kbeckmann/retro-go-stm32#17

@martaaay
Copy link
Author

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...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants