Files
courier-emu/tools/imodem_x2_map.py
T
Cryan209andClaude Opus 5 7886201886 Identify the four V.90 bits in ffd9
All four live in image 6 of the 3.00.02 overlay set, which is why joining only
5/11/10 finds five of thirty-five references. Bit 5 is set when 039f bit 7 -
the digital-server role - is set, and its reader self-clears it after latching
a five-bit field; bit 6 is cleared when a convergence counter reaches 4, so it
marks a phase rather than a mode; bits 4 and 7 steer message assembly and one
extra per-frame call, and have no bitwise writer.

Tag 72's payload goes to ffdf with only its top bit reaching ffd9, as bit 14.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-11 11:54:27 +12:00

83 lines
3.1 KiB
Python

#!/usr/bin/env python3
"""Rebuild the first-x2 I-modem (IM020104) address spaces and disassemble them.
Two spaces share one flash image:
* the 8086 supervisor, flat-addressed from the NAC's own 0x40000 load base;
* the joined C5x program the DSP runs, images 5/11/10 laid down at 8000,
9194 and d000 as the build's overlay table names them.
Usage (addresses are hex, end exclusive):
python tools/imodem_x2_map.py dsp e172 e186
python tools/imodem_x2_map.py sup addca ade12
"""
from __future__ import annotations
import struct
import sys
import zipfile
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
from courier_emu.nac import NacImage # noqa: E402
from tools.c5x_disasm import disassemble # noqa: E402
ARCHIVE = ROOT / "docs/x2/im020104.zip"
MEMBER = "IM020104.NAC"
# The V.90-era 3.00.02 image's own overlay map, as blob offsets. Images 8 and
# 11 both load at 9260 and are alternatives; 6 and 10 overlap likewise, so a
# joined program has to pick one of each pair.
V90_IMAGES = {5: (0xA8690, 4670, 0x8000), 6: (0x90D60, 13909, 0xA000),
7: (0x97A10, 5173, 0xB800), 8: (0x9A280, 2436, 0x9260),
9: (0x9B590, 3215, 0xB000), 10: (0x9CEB0, 7536, 0xD100),
11: (0xA0990, 15997, 0x9260)}
# Overlay rows of the first-x2 build: source segment, byte count, C5x load word.
# Segments are physical/16, and the flat image starts at the NAC's load base.
DSP_IMAGES = ((0xE005, 0x2322, 0x8000), # image 5, resident-class
(0xD84C, 0x7B86, 0x9194), # image 11
(0xD4EF, 0x35C2, 0xD000)) # image 10, the new x2 engine
def flat(path: Path | None = None) -> tuple[int, bytes]:
"""The whole flash as one array, with the physical address it starts at."""
if path is not None:
return NacImage.load(path).flatten()
with zipfile.ZipFile(ARCHIVE) as archive, archive.open(MEMBER) as handle:
scratch = ROOT / "build" / MEMBER
scratch.parent.mkdir(exist_ok=True)
scratch.write_bytes(handle.read())
return NacImage.load(scratch).flatten()
def dsp_memory(blob: bytes, base: int) -> list[int]:
memory = [0] * 0x10000
for segment, length, load in DSP_IMAGES:
start = segment * 16 - base
for index in range(length // 2):
memory[load + index] = struct.unpack_from("<H", blob, start + 2 * index)[0]
return memory
def main() -> None:
space, first, last = sys.argv[1], int(sys.argv[2], 16), int(sys.argv[3], 16)
base, blob = flat()
if space == "dsp":
for instruction in disassemble(dsp_memory(blob, base), first, last):
words = " ".join(f"{word:04x}" for word in instruction.words)
print(f"{instruction.pc:04x}: {words:<10} {instruction.text}")
return
from capstone import CS_ARCH_X86, CS_MODE_16, Cs
for instruction in Cs(CS_ARCH_X86, CS_MODE_16).disasm(
blob[first - base:last - base], first):
print(f"{instruction.address:05x}: {instruction.bytes.hex():<14} "
f"{instruction.mnemonic} {instruction.op_str}")
if __name__ == "__main__":
main()