• Stars
    star
    138
  • Rank 263,084 (Top 6 %)
  • Language
    C
  • License
    BSD 3-Clause "New...
  • Created about 3 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CFW for the Nintendo Game and Watch

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

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 game and watch backup repo. 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.

Install python dependencies (>=python3.6 required) via:

pip3 install -r requirements.txt

Download STM32 Driver files:

make download_sdk

The default programmer interface is stlink, you can chose a different interface via the ADAPTER variable. For example, ADAPTER=rpi.

NOTE: if you are flashing a 64MB chip, add LARGE_FLASH=1 to your make command!

I recommend pressing the power button at the same time you press enter. Note that the same configuration parameters have to be passed to each make command.

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_patched

# 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
# Note: only set the LARGE_FLASH=1 if you have a >=64MB chip!
make PATCH_PARAMS="--device=zelda" LARGE_FLASH=1 flash_patched

# in the retro-go repo
make clean
# In this example, I'm assuming you have a 64MB flash chip (60 = 64 - 4)
make -j8 EXTFLASH_SIZE_MB=60 EXTFLASH_OFFSET=4194304 INTFLASH_BANK=2 flash

Troubleshooting/FAQ:

Error: FSIZE in DCR(1) doesn't match actual capacity. while flashing.

If you receive this error, you can safely ignore it. It doesn't impact flashing or the final device at all.

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.

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)!

More Repositories

1

cyclopts

Intuitive, easy CLIs based on python type hints.
Python
278
star
2

python-template

Python project and library template for clean, reliable, open-source projects.
Python
257
star
3

belay

Belay is a python library that enables the rapid development of projects that interact with hardware via a micropython-compatible board.
Python
236
star
4

lox

Threading and Multiprocessing made easy.
Python
90
star
5

autoregistry

Automatic registry design-pattern library for mapping names to functionality.
Python
38
star
6

tamp

Tamp is a low-memory, DEFLATE-inspired lossless compression library.
Python
24
star
7

gnwmanager

C
15
star
8

cookiecutter-esp32-webserver

Cookiecutter template to get you quickly started with an ESP32-based webserver project.
C
13
star
9

cookiecutter-esp-idf-component

Cookiecutter template for an ESP-IDF component
C
5
star
10

pugh_torch

Functions, losses, and module blocks to share between experiments.
Python
4
star
11

micropython-libs

Python
4
star
12

install-micropython

Github Action to install micropython.
JavaScript
4
star
13

python-rai-rpc

Rai_node rpc commands wrapped for python
Python
3
star
14

RaiBlocks-Live-TPS

A simple python script that will display the transactions per second (TPS) of the incoming transactions on a rai_node/rai_wallet.
Python
3
star
15

magnetometer

CLI Magnetometer using a CircuitPython board + Belay
Python
3
star
16

micropython-fnv1a32

Micropython native module for the FNV1a hashing algorithm.
Python
3
star
17

raiblocks-docker

Docker for RaiBlocks
Dockerfile
2
star
18

esp-tamp-demo

C
2
star
19

makerdiary-m60-config

Lightweight repo to be directly used on the 8MB partition of the MakerDiary M60 keyboard
Python
2
star
20

micropython-native-module-template

Template for creating Micropython native module libraries with pre-built binaries
Python
2
star
21

dotfiles

Shell
1
star
22

pytorch-lightning-template

Python
1
star
23

monerod-docker

Dockerfile
1
star
24

esp32_unit_tester

ESP32 Unit Test App for ESP-IDF
C
1
star