Rendered from docs/AR_ENGINE.md in the repository.
Worked out offline from Datel's firmware 1.06 (your own copy; addresses only, no code reproduced) with
tools/probes/fw_regscan.py, fw_map.py and disassembly, and checked against what sessions 32-37
measured. Confidence: from the code, except where a session number says measured. Not yet seen
running on hardware (see LIVE_VIEW_PLAN.md, stage B), but Datel's real trampoline and
engine run correctly on this model in emulation (tools/probes/ar_engine_sim.py).
The pieces
| Piece | Where | What it is |
|---|---|---|
| The code list | built by Datel's menu, passed to 0x0800C5F8 | Decrypted codes, 8 bytes each (address word, value word), up to 200 (0x640 bytes) |
| The master code | found in the list by 0x0800C548 | Gives the hook address in the game (saved at IWRAM 0x03002238) and the hook type (0x0300223C, 0-4) |
| The engine | 0x5B4 bytes, stored in Datel's image at 0x0802E510 (copied to IWRAM 0x03002244 by the start-up code) | Linked to run at 0x09FE0400: a few NOPs, then the code interpreter at 0x09FE0408 |
| The trampolines | Datel's image at 0x0800D168-0x0800D200 | "Write 0x0067 to the mapping register, call 0x09FE0401, write 0x0007, return", one per hook type |
| The 8 KB block | DUO flash 0x08020000-0x08021FFF | Rebuilt and rewritten every time a game is started with codes: +0x020 the trampoline, +0x400 the engine, +0x9C0 the code list |
| The ROM patch | control registers 0x09FE0000/0x0020/0x0040 and 0x0080/0x00A0/0x00C0 | Two halfword patches at the hook address: a Thumb BL to 0x08000020 (computed by 0x0800C4F0) |
The 8 KB block reads as zeros on this DUO today (session 34's flash map: pages 0x08020000-0x08021FFF are "0"), consistent with no game having been started with codes since it was last cleared.
Starting a game with codes (0x0800C5F8)
- Every patch-address register (0x09FE0000, 0x0020, 0x0080, 0x00A0, 0x0100, 0x0120, 0x0200, 0x0220, 0x0280, 0x02A0, 0x02C0, 0x02E0) is set to 0xFFFF (no patch) and 0x0180/0x01A0 to 0.
- 0x0800C548 scans the code list for the master code: hook address, hook type.
- The 8 KB block is read from flash, the trampoline for the hook type copied to +0x020, the engine to +0x400 and the code list to +0x9C0, and the block written back with Datel's sector erase-and-write routine (0x0800B928).
- The hook is patched: slot one gets (hook address >> 1) and the BL's first half, slot two the next halfword and the BL's second half.
- The game is started (0x0800CA7C, then the ARM start routine at 0x0800CFA4) with mapping 0x0007.
While the game runs
- Mapping 0x0007 shows the game's ROM, except the header overlay 0x08000020-0x0800009F, which now shows the block's +0x020: the trampoline. (Measured, sessions 33-34: the overlay reads zeros under 0x0007, as the block is zero today.)
- When the game reaches the hook address, the Actel substitutes the BL: the game calls 0x08000020.
- The trampoline writes 0x0067: the Actel now maps the block at 0x09FE0000, so 0x09FE0400 is the engine and 0x09FE09C0 the code list. It calls the engine (Thumb, 0x09FE0401) with the return address inside the overlay (0x08000031/33/41/45 depending on the hook type).
- The engine walks the code list. It keeps its place and flags in the control registers 0x09FE0180 (index) and 0x09FE01A0 (flags; bit 7 and a count), which are therefore visible in mode 0x0067, and dispatches on each code's type (bits 27-31 of the value word) through a 17-entry table at 0x09FE04C0; a second table at 0x09FE07xx handles conditional types.
- It returns to the trampoline, which writes 0x0007 again and returns to the game.
Details worth knowing
- The trampoline has two
mov r8, r8placeholders: Datel copies the game's two original halfwords at the hook into them (it reads them through its read-from-game helper), so the replaced instructions are still executed. A hook therefore needs two halfwords that don't depend on where they run. - 0x09FE0180 keeps the engine's place in the code list between calls and 0x09FE01A0 its flags (bit 7) and how many codes to run per call (bits 0-6): long lists are spread over several frames.
- Codes use Action Replay V3's raw layout: in the address word, bits 0-19 and 20-23 encode the address (0x02000100 is 0x00200100), bits 25-26 the size, 27-29 the type and 30-31 the subtype.
Why this matters for a live view
The engine runs inside the game, every time the hook is reached (once a frame for a typical master code), with the DUO's registers in reach. The control registers 0x0180/0x01A0 work in mode 0x0067, so very likely LINK_IN/LINK_OUT do too: a replacement engine could answer the PC over USB while the game plays - reading the party, the RNG state or the save buffer and sending it, a few bytes per frame.