Repository navigation
The theme of this release: the machine runs the way the hardware does, and the debugger finds the variable behind a feature.
0.8.0 taught the debugger to read a program the way its source does. This release turns to what runs underneath it. The emulator counted one cycle per instruction, played the simple sound channels two octaves high and emulated no flash chip. Now it runs the GBA's timing, CPU, video, sound and BIOS against hardware test suites. On top of that machine, a new Memory diff panel finds the variable behind something you can see on screen.
GBA Debugger for VS Code is updated with this release.
All nine packages and the extension move to 0.9.0 together.
⚠️ Timing changed
A game now runs as much code per frame as it does on hardware, where before it ran one instruction per cycle. Anything that measured or replayed by instruction count sees different numbers: the inspector's cycle is in CPU cycles now.
Older save states still load. Every new piece of state has a documented default when a snapshot predates it, so a state restores and keeps running, but from then on it runs on the new timing. A replay of an old state can drift from what the old emulator would have done.
The emulator, measured against the hardware
Every jsmolka gba-tests ROM passes: arm, thumb, memory, bios, nes, unsafe, and the SRAM, 64 KB flash and 128 KB flash save tests. In the mGBA test suite, Memory, I/O read, Timing, Timer IRQ, Shifter, Carry, Multiply long, BIOS math, DMA and SIO register tests all pass in full. Its video tests match the hardware captures, with Layer toggle 2 the one exception. Before this release, Timing passed 4 of 2020 checks and Timer IRQ none.
| mGBA suite | 0.8.0 | 0.9.0 |
|---|---|---|
| Timing | 4 / 2020 | 2020 / 2020 |
| Timer IRQ | 0 / 90 | 90 / 90 |
| I/O read | 36 / 130 | 130 / 130 |
| BIOS math | 308 / 615 | 615 / 615 |
| Memory | 1336 / 1552 | 1552 / 1552 |
| Video tests matching | 2 / 7 | 6 / 7 |
The emulator is also faster: about 480 frames per second headless on Klonoa: Empire of Dreams, against about 355 before.
- Time is counted in ARM7TDMI cycles.
- Each instruction costs its N, S and I cycles plus the wait states of the memory it touches, priced from WAITCNT and the game pak prefetch buffer.
- A DMA takes its own cycles and holds the bus, channel by priority, and an interrupt reaches the CPU 7 cycles after it is raised.
- Timers, DMA, sound and the PPU read one clock, and it stays exact in the middle of an instruction.
- The CPU runs through its two-stage pipeline.
- Self-modifying code sees the opcodes already fetched, and so does a debugger: a write over the instruction at the stopped PC is what runs next.
- The ARMv4 rules for misaligned, banked and block loads and stores, MSR privilege and condition NV apply.
- Multiplies set the carry flag the way the ARM7TDMI's multiplier does.
- I/O has one register path for every access width. Each register reads through its own mask, write-only and unused registers read open bus, and the BIOS reads back its last fetched opcode from outside.
- The PPU draws each line at the start of HBlank, so raster effects land on their own line.
- All six video modes share one compositor, so the bitmap modes get sprites, windows, blending and the affine transform.
- The OBJ window, sprite priority, mosaic, 5-bit blending, the OBJ cycle budget and Green Swap all follow the hardware.
- Sound plays at the right pitch. The simple sound channels ran four times too fast. Each sound register byte acts on its own, channel 3 has both wave banks, and Direct Sound keeps time through DMA.
- The BIOS functions return what the real BIOS returns.
- Math, affine, copy and decompression functions are bit-exact and take the real BIOS's cycles.
- Halt, Stop, IntrWait, VBlankIntrWait and SoftReset run as BIOS code, so an interrupt is serviced inside them as on hardware.
- A flash cartridge has its flash chip, with its command protocol, chip ID, erase and the bank switch of a 128 KB chip. Flash
.savfiles now import and export like SRAM and EEPROM ones; 0.8.0 refused them. - The serial port answers a transfer with nothing connected, the way the hardware does.
Memory diff: find the variable behind a feature
The Memory search tab becomes Memory diff, at the same panel id.
How you use it:
- Capture RAM with a menu on item A, move to item B, capture again, move back to A, capture a third time.
- Draw on the graph what the value did between the captures:
changed,same,went uporwent down. Each new capture arrives joined to the one before it.
What it returns: the same arrow back to the first capture is what separates the variable from everything that merely churns. The answer is a handful of rows out of all 294,912 bytes of RAM, with the value each capture held.
What a row offers: Add as a label, Watch and Break on write. A data breakpoint on the variable names the function that writes it.
- Background noise is muted by address range, never by name.
- An idle run marks whatever moves on its own.
- The DMA watched in that run marks every shadow buffer.
- The stack pointer marks how deep the abandoned call frames reach.
- Every mute is a listed, reversible row.
- Each address is placed in one of four tiers the panel keeps visually distinct:
- an object the program declares, with its typed member path;
- memory a pointer reaches (
gMenu->cursor), read from the pointers the program declares; - the nearest symbol below, shown only as a landmark;
- an address nothing names.
- Watches set from the panel are listed in the panel, since VS Code's Breakpoints view lists no data breakpoints.
- A capture can be taken while the game runs, and a save state can be adopted as a capture.
In the Play page
- Games run at the GBA's 59.73 frames per second on every display. On a 120 Hz screen they used to run twice as fast.
- "Play Balatro GBA" downloads the latest release again, through a keyed proxy. When the download fails, the page links the file on GitHub to drop onto the loader.
For code that drives the emulator directly
Breaking:
MemoryBus(arm-emulator) has opcode fetches of its own (fetch16,fetch32) and prices accesses (accessCycles,fetchCycles,dataCycles,idle).ArmCpu.step()returns the cycles it took, andArmCpu.refusedsays when a debugger stop refused the instruction.Gbasets the post-BIOS boot state itself, so hosts no longer set the stack pointers, CPSR and PC afterloadRom.BiosEnvis gone.- The APU follows the scheduler's clock, so hosts stop ticking it and only read samples.
New exports:
- In
@gba-kit/gba-emulator:BIOS_SWI_HANDLER,SerialPort,DISPCNT_LATCH_CYCLEandHBLANK_START_CYCLE. - In
@gba-kit/gba-browser:FrameClock,FRAME_MSandMAX_FRAMES_PER_CALLBACK. - In
@gba-kit/debug-info:placementAt,pathToandPointerIndex, and the'service'frame method for a call stack that runs through a BIOS call.
New memory diff requests: gba-kit/captures, capture, retagCapture, reorderCaptures, forgetCapture, discoverNoise, mutes, setMute, diffFilter, breakOnWrite, watchpoints and unwatch. gba-kit/searchMemory and gba-kit/filterMemory are unchanged.