Commit graph

67 commits

Author SHA1 Message Date
0xrsydn
4e4dde742d fix(memory): return the Game Pak address pattern beyond the ROM chip
CPU and DMA reads past the supplied image returned Unmapped and stopped the
machine; a second game's boot code reads 0x09fe20f8 past a 16 MiB image. The
Game Pak shares data lines with the low address lines, so where no chip drives
the bus a read returns the halfword address, (A >> 1) & 0xffff, per lane
(GBATEK; mGBA uses the same pattern).

The chip is the image size rounded up to a power of two. Bytes between a
trimmed image's end and that boundary are unknown and stay diagnostic, as do
host reads and instruction fetches. Two truncation fixtures move into that gap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HhfHfHEuzv2AUTd6erW1gU
2026-10-14 14:28:41 +07:00
0xrsydn
32eaffa0fe feat(cartridge): add 32 KiB SRAM save memory
Select it with --save-type sram (SaveDevice::Sram). The array is byte-wide,
starts erased, and repeats every 32 KiB through the 0x0e00xxxx save window.
A CPU byte store is staged and committed when its step completes, so failed
steps roll back and reads later in the step see the byte. Unlike Flash, SRAM
can be read from ROM code. Halfword/word access and DMA stay diagnostic until
the 8-bit bus behavior for those widths is verified.

SRAM shares the save-image API, host save files, and save states. Its device
code is new, so existing save states keep loading.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HhfHfHEuzv2AUTd6erW1gU
2026-10-14 14:28:41 +07:00
0xrsydn
20176716d9 fix(memory): ignore CPU and DMA writes to unused I/O addresses
Stores to I/O addresses with no register returned Unmapped and stopped the
machine. Hardware ignores them. Emulated writes there now pay their bus cost and
change nothing; host writes stay strict. The unmodeled internal memory control
register at 0x04xx0800 and all unused I/O reads remain diagnostics.

Rollback tests that used unused I/O as their failing word now run the block on
to a register that rejects the stored value: SIOMULTI2 outside multiplayer
mode, an RCNT GPIO serial IRQ, or 64-sample wave playback. Where no reachable
register can fail (JOYSTAT, POSTFLG/HALTCNT, IME, DMA3CNT), the test now checks
that the block commits and the unused word is ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HhfHfHEuzv2AUTd6erW1gU
2026-10-14 14:28:41 +07:00
0xrsydn
b535c08313 fix(cpu): accept ARM multiplies whose destination equals Rm
MUL/MLA with Rd=Rm and long multiplies with RdHi or RdLo equal to Rm returned
UnsupportedInstruction and stopped the machine. The ARM7TDMI reads every
operand before writing the result, so these forms execute normally. R15
operands and RdHi=RdLo remain diagnostics.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HhfHfHEuzv2AUTd6erW1gU
2026-10-14 14:28:41 +07:00
0xrsydn
0ef2719c6b fix(video): ignore enable bits for backgrounds a mode lacks
DISPCNT enable bits for BG3 in Mode 1, BG0/BG1 in Mode 2, and every background
but BG2 in Modes 3-5 failed the whole frame with UnsupportedLayers, and the
window turned that into a stopped session. Hardware has no such backgrounds and
ignores the bits, so the renderer now masks them. The error variant is removed.

Prohibited OBJ mode 3 and shape 3 stay diagnostics: their hardware output is
not established here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HhfHfHEuzv2AUTd6erW1gU
2026-10-14 14:28:41 +07:00
0xrsydn
258fbff2fa fix(memory): ignore CPU and DMA writes to the Game Pak ROM windows
Stores to 0x08-0x0c returned ReadOnly and stopped the machine. Hardware ignores
them, and a second game's boot code stores to a ROM mirror. Emulated writes now
pay their bus cost and change nothing. The 0x0d window stays a diagnostic until
EEPROM is modeled there, and host writes stay strict.

Tests that used a ROM store as their failing write now cross an ignored ROM
word into the 0x0d window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HhfHfHEuzv2AUTd6erW1gU
2026-10-14 14:28:41 +07:00
0xrsydn
66817c919d fix(desktop): persist the save when a ROM window ends on a diagnostic
A core, DMA, rendering, window, or audio error returned before the save was
written, so every completed in-game save since launch was lost. The window now
writes changed bytes on that path too. The diagnostic stays the session error;
a refused or failed write is reported as output. A failed state restore leaves
save memory undefined and is never written. Terminal runs keep the strict rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HhfHfHEuzv2AUTd6erW1gU
2026-10-14 14:28:41 +07:00
0xrsydn
fd73788735 feat(core): add whole-machine save states with F5/F9 window slots
Machine::save_state and load_state encode the CPU, every RAM, and every device
through Snapshot impls into a versioned, checksummed format. Rejected loads leave
the machine unchanged. The ROM window saves to and loads from one state file
with F5 and F9.
2026-10-14 14:28:41 +07:00
0xrsydn
d7de5f7121 fix(video): read BG maps and tiles through the 128 KiB VRAM mirror window 2026-10-07 10:11:51 +07:00
0xrsydn
7772a9d8eb fix(bios): return cleanly for empty LZ77 streams 2026-10-07 09:06:00 +07:00
0xrsydn
423d0ba120 feat(desktop): add muted accelerated ROM playback 2026-10-07 08:52:40 +07:00
0xrsydn
86f29018fd feat(desktop): add safe explicit Flash save-file persistence 2026-10-07 08:36:12 +07:00
0xrsydn
8ded9bc90e feat(cartridge): implement transactional Flash programming and erase 2026-10-07 08:36:12 +07:00
0xrsydn
2ea7164d9a feat(desktop): add opt-in Darwin audio output 2026-10-07 07:35:19 +07:00
0xrsydn
902c892d3f feat(audio): capture transactional fixed-rate stereo samples 2026-10-07 07:16:42 +07:00
0xrsydn
f496f12ea3 feat(audio): add single-bank wave channel playback 2026-10-07 06:58:46 +07:00
0xrsydn
7546d17630 feat(serial): support disconnected Joybus configuration and local registers 2026-10-07 06:38:04 +07:00
0xrsydn
8b3b7ae62d feat(cartridge): add explicit Flash identification and banked reads 2026-10-07 06:25:43 +07:00
0xrsydn
fce222eea2 feat(cartridge): implement RTC calendar transfers and clock updates 2026-10-07 05:59:29 +07:00
0xrsydn
692be36349 feat(cartridge): add explicit GPIO and RTC control support 2026-10-07 05:34:52 +07:00
0xrsydn
c5e19baed4 feat(serial): model disconnected multiplayer configuration 2026-10-07 05:06:49 +07:00
0xrsydn
0b36ef1e24 feat(serial): clock disconnected normal transfers and completion IRQs 2026-10-07 04:23:07 +07:00
0xrsydn
d329c76dc3 feat(serial): retain disconnected external-clock requests 2026-10-07 03:58:21 +07:00
0xrsydn
a0516de748 fix(memory): ignore emulated writes to mapped BIOS 2026-10-07 03:33:50 +07:00
0xrsydn
86f8663904 fix(serial): gate RCNT interrupt and Joybus controls by mode 2026-10-07 03:10:18 +07:00
0xrsydn
8ae7b3cf72 feat(audio): implement PSG noise channel 4 2026-10-07 02:54:57 +07:00
0xrsydn
ca2134f23c refactor(audio): share PSG length and envelope state 2026-10-07 02:40:09 +07:00
0xrsydn
aee3621513 feat(audio): implement PSG pulse channel 2 2026-10-07 02:33:41 +07:00
0xrsydn
9a646651da feat(audio): implement PSG pulse channel 1 2026-10-07 01:58:08 +07:00
0xrsydn
5888c4d292 feat(audio): implement nominal Direct Sound playback and FIFO DMA 2026-10-07 01:40:51 +07:00
0xrsydn
d6a47a3e12 feat(bios): support sound and serial register reset 2026-10-07 01:01:07 +07:00
0xrsydn
cb2772cef8 feat(io): model disabled sound and disconnected serial state 2026-10-07 01:01:07 +07:00
0xrsydn
1b39a7f33f fix(bios): initialize affine scales before cartridge boot 2026-10-06 22:35:27 +07:00
0xrsydn
bf2ab54fc2 feat(test-runner): add deterministic gameplay scenarios 2026-10-06 22:29:47 +07:00
0xrsydn
27806ccf9e fix(timers): retain shared free-running prescaler phase 2026-10-06 22:07:49 +07:00
0xrsydn
bfecc87e84 fix(timers): apply machine accesses at bus completion 2026-10-06 21:52:09 +07:00
0xrsydn
8930ea93b4 test(timing): compare prefetch cancellation with published observations 2026-10-06 21:05:30 +07:00
0xrsydn
8f22092e06 feat(timing): implement nominal Game Pak opcode prefetch 2026-10-06 20:45:16 +07:00
0xrsydn
7f3ebd3a5d refactor(cpu): account for timing in bus-access order 2026-10-06 17:17:54 +07:00
0xrsydn
86321f0071 feat(cpu): retain fetch access kinds across instruction execution 2026-10-06 16:58:17 +07:00
0xrsydn
2d7eb6e4eb feat(cpu): account for source fetches in branch and IRQ refills 2026-10-06 16:37:30 +07:00
0xrsydn
0650b60908 feat(cpu): charge non-refill code at pipeline fetch addresses 2026-10-06 15:35:10 +07:00
0xrsydn
0a696ea3e7 feat(cpu): use actual fetch regions for boundary bus snapshots 2026-10-06 15:14:34 +07:00
0xrsydn
f2c532f8f6 feat(cpu): retain IWRAM bus history across execution states 2026-10-06 14:31:14 +07:00
0xrsydn
e630d7a0ea refactor(cpu): share instruction fetch samples with bus history 2026-10-06 14:17:35 +07:00
0xrsydn
ea055270f4 feat(cpu): retain Thumb instruction pipeline halfwords 2026-10-06 04:14:56 +07:00
0xrsydn
47df9d05a7 feat(cpu): retain ARM instruction pipeline words
Buffer ARM sequential fetch results and refill target pairs after branches, PC writes, and machine exception entry. Stage advances transactionally, defer speculative fetch diagnostics, and preserve buffered words across CPU/DMA stores and host edits. Add explicit CPU pipeline invalidation for debugger repair and memory rebinding.

Add 15 original instruction-buffer regressions. Keep full-state rollback equality while distinguishing architectural comparisons in semantic tests. Update the display error test for an already buffered branch. Document evidence and separate remaining Thumb, bus-history, and timing work.

Validated on Darwin arm64: 967 workspace and 898 core/demo tests in each debug/release profile, 39 Python tests, native ROM windows, ten window smoke modes, fmt, clippy, and rustdoc. Public ARM/Thumb/memory/BIOS reports and nominal cycles remain unchanged.
2026-10-06 04:01:00 +07:00
0xrsydn
16286e0cbd feat(timing): break CPU sequential access after DMA
Retain one pending non-sequential resume after successful DMA. Apply it to the next nominal non-refill code access and consume it only on successful CPU or IRQ progress. Preserve failed-step atomicity, host and idle isolation, existing refill costs, and WAITCNT ordering.

Add 13 original regressions for ARM/Thumb widths, ROM wait settings, sources, preemption, retries, mixed APIs, idle states, and interrupt timing. Record pinned hardware-test source and emulator evidence without claiming physical-hardware or full-pipeline conformance.

Validated on Darwin arm64: 952 workspace and 883 core/demo tests per debug/release profile, 39 Python tests, native ROM windows, ten window smoke modes, fmt, clippy, and rustdoc. Public ARM/Thumb/memory/BIOS reports remain unchanged.
2026-10-06 03:16:52 +07:00
0xrsydn
663b25e5d1 feat(memory): retain IWRAM lane effects across DMA
Update existing Thumb IWRAM continuation lanes from successful DMA reads and writes before the resumed PC+4 snapshot. Keep channel halfword duplication separate from actual lane accesses. Preserve atomic errors, cold-entry diagnostics, IRQ invalidation, and nominal timing.

Add original DMA matrices and resume regressions; update prior invalidation expectations. Record pinned ares and jgenesis evidence and explicit limits for cross-state history, general open bus, and sub-instruction arbitration.

Validated on Darwin arm64: 939 workspace and 870 core/demo tests per debug/release profile, 39 Python tests, native ROM windows, ten window smoke modes, fmt, clippy, and rustdoc. Public ARM/Thumb/memory/BIOS reports remain identical to the previous results.
2026-10-06 02:39:17 +07:00
0xrsydn
e72c643640 feat(dma): retain per-channel transfer data
Retain independent known data across DMA blocks. Duplicate mapped halfword sources and select the destination lane for blocked sources below work RAM. Keep cold history diagnostic, commit only successful units, and preserve separate CPU/BIOS history rules.

Add 13 original regressions and pinned source research. CPU resume ownership, general DMA open bus, and IWRAM DMA lane effects remain explicit limits.

Validated on Darwin arm64: 930 workspace and 861 core/demo tests in debug and release, 39 Python tests, native ROM windows, ten window smoke modes, fmt, clippy, and rustdoc. Public ARM/Thumb/memory/BIOS reports match the previous results exactly.
2026-10-06 02:18:24 +07:00