SG

How SawGod works

SawGod is not an emulator running the cartridge. Every routine of the 2002 WonderSwan Color game was decompiled into C++, and that code now runs natively, on a small model of the WonderSwan that keeps its memory and timing exact. One game runs underneath; Game Boy, WonderSwan Color and Enhanced are three ways of presenting it, and the menus, music, saves and mods are built around it.

From your cartridge to the screen

1What you bring

Your ROM

Checked on first run, then unpacked on your machine into two archives: wsc.sgz (data tables, Japanese text, maps, art) and gb.sgz (the Game Boy look).

No game data ships with SawGod.

Mods

Folders or .sgz files that replace tables, text or graphics, file by file. .sgz files are just zipped resource packs.

Controls

Keyboard and gamepad, mapped onto the WonderSwan's buttons.

2The game

The decompiled game

All 1,300 routines of the original, as readable C++. Same rules, numbers and random numbers as the cartridge.

src/game/

The seams

Where SawGod and mods reach into the game:

  • Textevery line by key
  • Data tablesitems, monsters, shops
  • Hooksevents and values
  • Savesnine slots and autosave
src/game/

The WonderSwan model

The CPU's registers and memory, interrupts, and the video and sound chips the game expects.

src/emu/

One tick per WonderSwan frame: 75.47 a second

3What you see and hear

Picture

  • GBGame Boy art, drawn from the same game state
  • WSCthe original WonderSwan Color picture
  • EnhancedGPU effects: Mode 7, lighting, bloom, depth of field

Then the redesigned menus and text are drawn on top, and the picture is paced to your display.

Sound

  • GBGame Boy sound chip
  • WSCWonderSwan sound chip
  • Enhancednew arrangements, played through FluidSynth

Saves

Human-readable TOML files beside your options. You can edit your save, I won't tell.

Around it all: the app (src/app/) runs the loop, and port services (src/engine/) handle options, input, archives, mods and the GPU renderer. Picture and sound modes switch at any time, independently.

One tick

75.47 times a second, the same four steps:

  1. Read input

    Keys and pads become WonderSwan buttons. While Options is open, the game waits.

  2. Run the game

    The decompiled routines run until the game waits for the next frame, just as it did on the hardware.

  3. Sound and saves

    The chosen music path gets its samples; any save the game made is written to disk.

  4. Draw

    GB, WSC or Enhanced, plus the menus, presented at your display's own refresh rate.

  5. Routine by routine

    Each decompiled routine is run side by side with the original machine code on the same inputs, and every register and byte of memory must match.

Where mods plug in

A mod is a folder or .sgz file laid out like the game's own archives. Each file replaces only what it lists; when two mods change the same thing, the later one wins.

Put this in your modTo change
tables/*.csvGame data by row: items, shops, monsters, encounters, formations, meat.
text/en.csv, text/ja.csvAny line of text by key: dialogue, battle messages, menu labels.
gfx/, maps/, gb/Graphics and maps, by path, in any of the three modes.
C++ hooksGame events and values (a battle starting, gold won, a random encounter), in a source build.

The mod format may change in 1.x releases. Start modding.

Read the code

Everything is on GitHub under the MIT license.