mirror of
https://git.k-space.ee/arti/vt1200.git
synced 2026-10-30 12:03:54 +02:00
66 lines
2.2 KiB
Python
66 lines
2.2 KiB
Python
"""Tests for reconstruct.py — the VT1200 EPROM de-interleaver.
|
|
|
|
The firmware's addresses are now known (see MEMORY_MAP.md): the ROM is
|
|
top-aligned at physical byte 0x07E40000 and the EPROM *bank* order is the
|
|
reverse of part-number order. `reconstruct(..., linear=True)` must therefore
|
|
emit an image where file offset == physical byte - 0x07E40000.
|
|
"""
|
|
import os
|
|
import struct
|
|
import unittest
|
|
|
|
import reconstruct
|
|
|
|
ROM_SIZE = 0x1C0000
|
|
ROM_BASE = 0x07E40000
|
|
RESET_VECTOR = 0x3F200040 # bit address the reset entry holds
|
|
POST_BYTES = bytes.fromhex("6003500540070056")
|
|
# In part-number order bank0 (210/211) is first, so its reset vector -- the last
|
|
# entry of the vector page -- lands at file offset 0x3FFFC.
|
|
RESET_VECTOR_OFFSET_PART_ORDER = 0x3FFFC
|
|
|
|
|
|
def _load(dirname, linear):
|
|
return reconstruct.reconstruct(dirname, linear=linear)[1]
|
|
|
|
|
|
class LinearImageTest(unittest.TestCase):
|
|
"""linear=True yields an image whose offsets are CPU-address ordered."""
|
|
|
|
def test_size(self):
|
|
self.assertEqual(len(_load("v2.1", linear=True)), ROM_SIZE)
|
|
|
|
def test_reset_vector_is_at_top_of_rom(self):
|
|
img = _load("v2.1", linear=True)
|
|
self.assertEqual(struct.unpack_from("<I", img, len(img) - 4)[0], RESET_VECTOR)
|
|
|
|
def test_reset_target_holds_post_code(self):
|
|
# 0x3F200040 >> 3 == 0x07E40008 == ROM_BASE + 8
|
|
img = _load("v2.1", linear=True)
|
|
self.assertEqual(img[8:8 + len(POST_BYTES)], POST_BYTES)
|
|
|
|
def test_vector_page_is_at_top(self):
|
|
linear = _load("v2.1", linear=True)
|
|
part = _load("v2.1", linear=False)
|
|
self.assertEqual(linear[-0x80:], part[0x3FF80:0x40000])
|
|
|
|
def test_known_string_pointer_resolves(self):
|
|
# Stored pointer 0x3F816ED8 >> 3 == ROM_BASE + 0xC2DDB
|
|
img = _load("v2.1", linear=True)
|
|
self.assertEqual(img[0xC2DDB:0xC2DDB + 15], b"Messages re-xmt")
|
|
|
|
|
|
class PartOrderImageTest(unittest.TestCase):
|
|
"""linear=False preserves the legacy part-number-ordered layout."""
|
|
|
|
def test_reset_vector_location(self):
|
|
img = _load("v2.1", linear=False)
|
|
self.assertEqual(
|
|
struct.unpack_from("<I", img, RESET_VECTOR_OFFSET_PART_ORDER)[0],
|
|
RESET_VECTOR,
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|