https://github.com/brianpugh/game-and-watch-patch

CFW for the Nintendo Game and Watch

https://github.com/brianpugh/game-and-watch-patch

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.8%) to scientific vocabulary

Keywords

cfw custom firmware game-and-watch gnw hack mario mod nintendo retro-go reverse-engineering zelda
Last synced: 5 months ago · JSON representation

Repository

CFW for the Nintendo Game and Watch

Basic Info
  • Host: GitHub
  • Owner: BrianPugh
  • License: bsd-3-clause
  • Language: C
  • Default Branch: main
  • Homepage:
  • Size: 1.35 MB
Statistics
  • Stars: 162
  • Watchers: 12
  • Forks: 22
  • Open Issues: 3
  • Releases: 10
Topics
cfw custom firmware game-and-watch gnw hack mario mod nintendo retro-go reverse-engineering zelda
Created over 4 years ago · Last pushed 12 months ago
Metadata Files
Readme Funding License

README.md

Custom firmware for the newer Nintendo Game and Watch consoles.

Click to play demo

What is this?

This repo contains custom code as well as a patching utility to add additional functionality to the stock Game and Watch firmware. In short, this project allows you to run the firmware your game and watch came with along side retro-go.

Features

  • Works correctly with retro-go in internal flash bank 2.
  • Press button combination (LEFT + GAME) to launch retro-go from internal flash bank 2.
  • Run make help to see all configuration options.

Mario (PATCH_PARAMS="--device=mario")

  • Ability to store the entire firmware in internal flash! No external flash required!
    • Option to remove the "Mario Song" easter egg.
    • Option to remove the 5 sleeping illustrations.
    • LZMA compressed data.
    • Intelligently move as much data to internal firmware as possible.
  • Configurable timeouts.
  • Ability to play SMB1 ROM hacks via --smb1=path-to-patched-smb1-rom.nes
  • Ability to dynamically load SMB1 ROM hack sprites for the clock via --smb1-graphics=path-to-patch.ips
    • Can add up to 8 additional graphics sets.
    • Cycle through via the down button on the clock screen.
    • Add all your ips files to ips/ and have the patcher automatically discover them via the flag --smb1-graphics-glob
  • Dumps SMB1 and SMB2 ROMs that are playable by other emulators.
  • See the mario document for more information.

Zelda (PATCH_PARAMS="--device=zelda")

Usage

This repo uses the gnwmanager cli tool. See it's instructions on how to install.

Install game-and-watch-patch python dependencies (>=python3.6 required) via:

pip3 install -r requirements.txt

Place your internal_flash_backup_${DEVICE}.bin and flash_backup_${DEVICE}.bin in the root of this repo. To extract these from your gnw system, see the gnwmanager unlock tutorial. For example, if we are patching the mario game and watch, we need the files internal_flash_backup_mario.bin and flash_backup_mario.bin in the root directory of this project.

See the appropriate section below for your device model.

For additional configuration options, run make help.

Retro Go (Mario)

Since most people are going to be using this with retro-go, want the minimum amount of external storage used, and don't care about the sleeping images or the mario song easter egg, here are the recommend commands. Note that this uses an undocumented 128KB of internal Bank 1 and requires a patched version of openocd installed.

```

in this repo

make clean make PATCH_PARAMS="--device=mario --internal-only" flash

in the retro-go repo

make clean make -j8 INTFLASH_BANK=2 flash ```

Retro Go (Zelda)

This assumes you have upgraded the external flash to something larger than 4MB. See the zelda document for using retro-go with the stock 4MB flash chip.

```

in this repo

make clean make PATCH_PARAMS="--device=zelda" flash

in the retro-go repo

make clean

In this example, I'm assuming you have a 64MB flash chip (60 = 64 - 4)

make -j8 EXTFLASHSIZEMB=60 EXTFLASHOFFSET=4194304 INTFLASHBANK=2 flash ```

Build and flash using Docker

If you are familiar with Docker and prefer a solution where you don't have to manually install toolchains and so on, expand this section and read on. To reduce the number of potential pitfalls in installation of various software, a Dockerfile is provided containing everything needed to compile and flash Custom Firmware (CFW) to your Nintendo® Game & Watch™ system. This Dockerfile is written tageting an x86-64 machine running Linux. Steps to flash from a docker container (running on Linux, e.g. Archlinux or Ubuntu): ```bash # Go into the docker directory of this repo. cd docker/ # Pull the pre-built docker image. docker pull brianpugh/game-and-watch-patch:latest # When done, use the image to create a container with the attached docker-compose.yaml file. # You have to edit the compose file and set the path to the directory with your firmware backup (volumes section of the file). docker compose up -d # This will create and run a container game-and-watch-patch. # The firmware backup files will be mounted into /tmp/firmware of the container. # Now, go inside the container copy the backup files and proceed as described above in the Usage section. docker exec -it game-and-watch-patch /bin/bash ``` If you run into permission issues, [ensure that your user is in the docker group.](https://docs.docker.com/engine/install/linux-postinstall/)

Troubleshooting/FAQ:

Unable to install python dependency keystone-engine on rpi3

If you are unable to install keystone-engine on a raspberry pi 3, try: 1. Update the GPU RAM to 16MB from raspi-config 2. Build and install keystone-engine from source (should take ~15 minutes): git clone https://github.com/keystone-engine/keystone cd keystone/bindings/python/ python3 -m pip install .

Development

Main stages to developing a feature: 1. Find a place to take control in the stock rom (usually function calls). 2. Add the stock function and its address to Core/Inc/stock_firmware.h. 3. Implement your own function, possibly in Core/Src/main.c. There's a good chance your custom function will call the function in (2). You will also probably have to add -Wl,--undefined=my_custom_function to LDFLAGS in the Makefile so that it doesn't get optimized out as unreachable code. 4. Add a patch definition to patches/patches.py.

Protocols

We store information about how much external flash this firmware uses at internal-flash offset 0x01B8. This location is in the HDMI-CEC handler in the vector-table; this is unused for all game-and-watch purposes, so serves as a safe, standardized spot to put a bit of data. At this location we store the following data:

C struct { external_flash_size: 24; // This value * 4096 is the amount of external flash used by this firmware. must_be_4: 4; // "magic" value that would never be valid in any real hdmi-cec firmware. 0x4 is in the hardware perhipheral space. is_mario: 1; // This is the mario firmware. is_zelda: 1; // This is the zelda firmware. _unused: 2; // Reserved for future use. All 0 for now. }

Journal

This is my first time ever developing patches for a closed source binary. I documented my journey in hopes that it helps other people. If you have any recommendations, tips, tricks, or anything like that, please leave a github issue and I'll update the documentation!

Acknowledgement

Thanks to the community that made this possible! This repo was built with the help of others. Repos referenced during the development of this project:

I would also like to thank the stacksmashing discord for all the help (special shoutout to @cyanic)!

Owner

  • Name: Brian Pugh
  • Login: BrianPugh
  • Kind: user
  • Location: Washington D.C.

Deep Learning Scientist and blockchain enthusiast

GitHub Events

Total
  • Release event: 2
  • Watch event: 25
  • Delete event: 2
  • Issue comment event: 2
  • Push event: 6
  • Pull request event: 5
  • Create event: 5
Last Year
  • Release event: 2
  • Watch event: 25
  • Delete event: 2
  • Issue comment event: 2
  • Push event: 6
  • Pull request event: 5
  • Create event: 5

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 17
  • Total pull requests: 57
  • Average time to close issues: 13 days
  • Average time to close pull requests: about 5 hours
  • Total issue authors: 17
  • Total pull request authors: 7
  • Average comments per issue: 3.12
  • Average comments per pull request: 0.28
  • Merged pull requests: 55
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 3
  • Average time to close issues: N/A
  • Average time to close pull requests: 1 day
  • Issue authors: 0
  • Pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 0.67
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • Vendo232 (1)
  • gigaclood (1)
  • BrianPugh (1)
  • WellsWang (1)
  • igaspaly4 (1)
  • drandreas (1)
  • damonmo (1)
  • apple524 (1)
  • retrohead (1)
  • kolmogorovpavel (1)
  • hexiaotun (1)
  • rutdarkronin (1)
  • DSkywalk (1)
  • gmcpaul (1)
  • wesk1 (1)
Pull Request Authors
  • BrianPugh (48)
  • BenjaminSoelberg (4)
  • Takiiiiiiii (2)
  • luisfcorreia (1)
  • cHunter789 (1)
  • jzobac (1)
  • DSkywalk (1)
Top Labels
Issue Labels
enhancement (1)
Pull Request Labels

Dependencies

requirements.txt pypi
  • Pillow *
  • colorama *
  • keystone-engine *
  • numpy *
  • pycryptodome *
  • pyelftools *