mirror of
https://github.com/D-Modem/courier-emu.git
synced 2026-11-28 20:38:07 -08:00
The ROM parked at 0x80444 waiting for timer 2's MAX COUNT because the harness modelled the peripheral control block as plain memory. The timers are now modelled from the instruction clock: the enable gate that only takes a new ENABLE when INHIBIT is set with it, the zero-compare-is-full-range rule that self-test depends on, single-shot against continuous, and the sticky max-count bit. The instruction-to-tick ratio comes from the 5 MHz timer clock and the 1,111 instructions per millisecond the ring qualification window pins down, and lands timer 0's programmed compare at one interrupt per 5,600 instructions against the 4,096 the harness had been using as a hand-tuned constant. The mask side of the interrupt controller is modelled too, because it has to be: the boot table writes IMASK = 0x0079, masking the timers, and delivering a timer interrupt through that mask lands in a handler that is only consistent later in the sequence. Running the ROM at all needed the rest of a boot: it is mapped where its own chip select puts it, entered at the reset vector, and its software interrupts are dispatched in real mode so the boot block can enter through the vector table it installs at physical zero. `run` detects which kind of image it was given. Past the self-test the ROM reaches a tick wait, and this firmware calibrates that tick from an external INT1 edge rather than a timer period: timer 1 runs as a stopwatch, and the INT1 handler at 9ea4:0722 sets timer 2's compare to one and a half times what it measured. --int1-after supplies that edge as a harness stimulus. What drives it on hardware is not established, and two things still stop the tick short - the analysis file records both. The XMF path keeps its calibrated delay helpers: an update image is entered past the boot block that programs the control block, and answering its timer reads from the model puts its own timer interrupt handler on a path it does not return from. Its writes are still tracked, so a run now reports the compares it programs. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
140 lines
5.7 KiB
Python
140 lines
5.7 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import unittest
|
|
|
|
from courier_emu.rom import (
|
|
LCS_START,
|
|
RESET_VECTOR,
|
|
ROM_SIZE,
|
|
UCS_START,
|
|
CourierRom,
|
|
RomFormatError,
|
|
)
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
IMAGE = ROOT / "IDSDL302.ROM"
|
|
|
|
|
|
@unittest.skipUnless(IMAGE.exists(), "no Courier ROM image available")
|
|
class CourierRomTests(unittest.TestCase):
|
|
def setUp(self) -> None:
|
|
self.rom = CourierRom.load(IMAGE)
|
|
|
|
def test_the_reset_stub_places_the_rom(self) -> None:
|
|
# An XMF carries only an update payload, so its address is a modelling
|
|
# choice. A ROM ends with the 80186 reset vector, and the stub there
|
|
# programs the chip select that decodes the ROM before it jumps, so the
|
|
# image says where it lives.
|
|
self.assertEqual(self.rom.base, 0x80000)
|
|
self.assertEqual(self.rom.base + ROM_SIZE, 0x100000)
|
|
self.assertEqual(self.rom.reset.chip_select_register, UCS_START)
|
|
self.assertEqual(self.rom.reset.boot_physical, 0xFDA21)
|
|
|
|
def test_the_setup_table_gives_the_flash_and_ram_map(self) -> None:
|
|
selects = self.rom.chip_selects()
|
|
self.assertEqual(selects["flash"]["start"], 0x80000)
|
|
self.assertEqual(selects["ram"]["start"], 0x00000)
|
|
self.assertEqual(selects["ram"]["stop"], 0x20000)
|
|
|
|
def test_the_peripheral_control_block_is_mapped_where_the_harness_hooks_it(
|
|
self,
|
|
) -> None:
|
|
# The relocation register moves the control block into memory space at
|
|
# 0x0ff00, which is the window the 80186 harness already watches.
|
|
block = self.rom.chip_selects()["peripheral_control_block"]
|
|
self.assertEqual(block["address"], 0x0FF00)
|
|
self.assertEqual(block["memory_mapped"], 1)
|
|
|
|
def test_the_setup_tables_are_recovered_whole(self) -> None:
|
|
writes = self.rom.peripheral_writes()
|
|
self.assertEqual(len(writes["word_writes"]), 36)
|
|
self.assertEqual(len(writes["byte_writes"]), 9)
|
|
ports = dict(writes["word_writes"])
|
|
self.assertIn(UCS_START, ports)
|
|
self.assertIn(LCS_START, ports)
|
|
# The byte table seeds the board latches, and it seeds two of them with
|
|
# exactly the values the 2002 firmware's own boot writes.
|
|
latches = dict(writes["byte_writes"])
|
|
self.assertEqual(latches[0x12], 0x7F)
|
|
self.assertEqual(latches[0x14], 0xF5)
|
|
|
|
def test_the_parameter_region_is_where_the_search_looks(self) -> None:
|
|
# The search at 0x7e07c walks four sectors from 0xf8000. On a part that
|
|
# has never been configured they read erased, which is why an image
|
|
# alone cannot supply one.
|
|
sectors = self.rom.parameter_sectors
|
|
self.assertEqual(sectors[0]["physical"], 0xF8000)
|
|
self.assertTrue(all(sector["erased"] for sector in sectors[:3]))
|
|
self.assertFalse(any(sector["checksum_matches"] for sector in sectors))
|
|
|
|
def test_the_application_image_starts_at_the_bottom_of_the_rom(self) -> None:
|
|
self.assertEqual(self.rom.at(0x80000, 4), b"\xbd\x0b\x00\xe9")
|
|
|
|
def test_reading_outside_the_rom_is_refused(self) -> None:
|
|
with self.assertRaises(ValueError):
|
|
self.rom.at(0x7FFFF, 1)
|
|
with self.assertRaises(ValueError):
|
|
self.rom.at(0xFFFF0, 32)
|
|
|
|
def test_describe_reports_the_recovered_map(self) -> None:
|
|
described = self.rom.describe()
|
|
self.assertEqual(described["base"], "0x80000")
|
|
self.assertEqual(described["reset_vector"], f"{RESET_VECTOR:#07x}")
|
|
self.assertEqual(described["boot_entry"], "fc00:1a21")
|
|
|
|
|
|
@unittest.skipUnless(IMAGE.exists(), "no Courier ROM image available")
|
|
class RomBootTests(unittest.TestCase):
|
|
def test_the_rom_boots_past_its_timer_self_test(self) -> None:
|
|
# 0x80432 enables timer 2 and 0x80444 spins until MAX COUNT. With the
|
|
# control block modelled as plain memory that bit never sets, and the
|
|
# ROM parks there for the rest of the run.
|
|
from courier_emu.machine import CourierMachine
|
|
|
|
machine = CourierMachine(CourierRom.load(IMAGE))
|
|
result = machine.run(40_000_000)
|
|
self.assertNotEqual(result.registers["ip"], 0x0444)
|
|
self.assertGreaterEqual(result.timers["timers"][2]["max_counts"], 1)
|
|
# The boot block ran: it programmed the chip selects through I/O space,
|
|
# relocated itself, and entered through its own vector table.
|
|
self.assertEqual(result.timers["timers"][0]["compare_a"], 25_200)
|
|
self.assertGreater(result.timers["controller"]["writes"], 0)
|
|
|
|
def test_the_boot_block_reads_the_settings_eeprom(self) -> None:
|
|
# An XMF update carries no boot block, which is why no boot-time NVRAM
|
|
# access shows up there. The ROM has one.
|
|
from courier_emu.machine import CourierMachine
|
|
from courier_emu.nvram import CourierNvram
|
|
|
|
nvram = CourierNvram()
|
|
machine = CourierMachine(CourierRom.load(IMAGE), nvram=nvram)
|
|
machine.run(6_000_000)
|
|
self.assertGreaterEqual(nvram.reads, 1)
|
|
|
|
def test_the_dsp_bridge_is_refused_for_a_rom(self) -> None:
|
|
from courier_emu.machine import CourierMachine
|
|
|
|
with self.assertRaises(ValueError):
|
|
CourierMachine(CourierRom.load(IMAGE), with_dsp=True)
|
|
|
|
|
|
class RomFormatTests(unittest.TestCase):
|
|
def test_an_update_payload_is_not_a_rom(self) -> None:
|
|
with self.assertRaises(RomFormatError):
|
|
CourierRom.load(ROOT / "main211.xmf")
|
|
|
|
def test_a_rom_without_a_reset_stub_is_refused(self) -> None:
|
|
import tempfile
|
|
|
|
with tempfile.NamedTemporaryFile(suffix=".ROM") as handle:
|
|
handle.write(b"\x00" * ROM_SIZE)
|
|
handle.flush()
|
|
with self.assertRaises(RomFormatError):
|
|
CourierRom.load(handle.name)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|