# SPDX-License-Identifier: MIT """The HG51B169 core: registers, reset, the clocked state machine, the cache, DMA and bus port. The chip sits between the S-CPU and the cartridge ROM (start-here.md). The board gives it its ROM/SRAM bus as two callables taking the chip's own 24-bit SNES-style addresses (handoff decision 7) and advances it in chip clocks (``run``); the S-CPU side (``read``/``write``, ``irq``, ``owns_rom_bus``, ``vector``) is in :mod:`hg51b_python.host`. **Time.** One instruction is one clock, a taken jump 2 more, a taken skip 1 more (U1). Everything that uses the ROM bus advances **one byte at a time** (handoff decision 5; byuu's model steps per byte too, ares ``hg51b.cpp`` ``cache``/``dma`` l.72-113): a cache page load is 512 byte reads, a DMA one read and one write per byte, each costing its region's wait (``1 + wait`` on ROM/SRAM, ``INTERNAL_ACCESS_COST`` inside the chip: C8). So an S-CPU access that the board makes between two :meth:`HG51B.run` calls can land mid-load and see the busy bit and ``owns_rom_bus``. A unit (an instruction, a byte, a clock of idling) is atomic: its effect happens when it starts and its clocks are charged then; a run that ends inside a unit owes the difference to the next run. **The main loop** (byuu's model, ares ``hg51b.cpp`` l.26-33 ``HG51B::main``, ISC): locked, suspended, a cache load, a DMA, halted, else one instruction. An instruction first looks its page up in the cache (U2): the current cache page, then the other, then a load into an unlocked page (both locked: halt). Then the word is fetched, PC advances (wrapping from FFh to cache page 1 with PB = P, or halting on page 1), one clock passes, and the operation runs. **Contested behaviours** are class attributes, set on a subclass or an instance to compare (decision 4): C1 ``SHIFT_LIMIT``, C6 ``MUL_LATENCY`` (``_alu``); C4 ``STACK_MODEL``, C17 ``FAR_SELECT`` (``_flow``); C13 ``STATUS_MIRROR``, C18 ``IRQ_DISABLE_SETS_FLAG`` (``host``); C7 ``BUS_DELAY_EXTRA``, C8 ``INTERNAL_ACCESS_COST``, C10 ``CLEAR_IS_NOP``, C11 ``LD_P_SOURCE``, C16 ``OPERAND_00_READS_A`` (here). Every non-default position is a closed-box Mesen2 observation (OBSERVED, ``scripts/cx4_probe.py``) or a document's reading; C2, C3 and C9 have no switch (Wave 2, docs/provenance.md). C12 is the board's; C14 is ``CLOCK_HZ``; C15 is :meth:`HG51B.reset`. """ from __future__ import annotations from collections.abc import Callable, Sequence from hg51b_python._alu import MASK, ALUMixin from hg51b_python._decode import CONSTANTS, OPS from hg51b_python._flow import STACK_DEPTH, FlowMixin from hg51b_python.data_rom import WORDS from hg51b_python.data_rom import data_rom as computed_data_rom from hg51b_python.host import HostMixin from hg51b_python.state import CPUState DATA_RAM_SIZE = 3072 NO_PAGE = -1 # a cache page that holds nothing (after reset: U20 "cache empty") # The chip's bus regions (byuu's glue, ares ``hitachidsp/memory.cpp`` ``address*``, Mapping = 0, the LoROM # boards SHVC-1DC0N/2DC0N). REGION_NONE, REGION_ROM, REGION_SRAM, REGION_DATA_RAM, REGION_IO = range(5) def region(address: int) -> int: """Which part of the chip's 24-bit bus ``address`` selects (ares ``hitachidsp/memory.cpp``).""" if address & 0x408000 == 0x008000 or address & 0xC00000 == 0xC00000: return REGION_ROM # 00-3F/80-BF:8000-FFFF, C0-FF:0000-FFFF (/ROM1, /ROM2) if address & 0xF88000 == 0x700000: return REGION_SRAM # 70-77:0000-7FFF (/SRAM) if address & 0x40E000 == 0x006000: if address & 0x0C00 != 0x0C00: return REGION_DATA_RAM # 00-3F/80-BF:6000-6BFF, 7000-7BFF return REGION_IO # 00-3F/80-BF:6C00-6FFF, 7C00-7FFF return REGION_NONE class HG51B(ALUMixin, FlowMixin, HostMixin): """A Hitachi HG51B169 (the SNES Capcom Cx4). ``bus_read(address) -> byte`` and ``bus_write(address, value)`` are the chip's ROM/SRAM bus with 24-bit addresses; the board decodes them (LoROM, one or two ROMs, SRAM). The core calls them only for the ROM and SRAM regions; its own data RAM ($6000-$6BFF) and I/O block are inside. ``data_rom``: ``None`` computes the 1,024 words (U21), or pass the words of a BYOR image (``load_data_rom``). A new core is in the power-on state. """ #: C14. The crystal: 20 MHz, one chip clock per cycle (fullsnes "External Oscillators"; ares). The #: board converts master clocks (NTSC: 176/189 chip clocks per master clock). CLOCK_HZ = 20_000_000 #: C3 (no switch): a DMA byte whose source and target are both ROM, or both SRAM, #: locks the chip until $7F53 (byuu's model, ares ``hg51b.cpp`` l.104-105). Here the #: DMA then ends (ares leaves it pending, to lock again after $7F53). Closed-box Mesen2 #: runs lock in more cases (C3, OBSERVED); they are recorded, not modelled. #: C7. Clocks a bus access (operand 2Eh/2Fh) takes beyond the wait state: 0 (default; #: byuu's model, ares ``registers.cpp`` l.15, 21 ``pending = wait``), 1 (a closed-box #: Mesen2 run: WAIT after a ROM read with wait 4 lasts 5 clocks; OBSERVED, #: ``scripts/cx4_probe.py bus``). BUS_DELAY_EXTRA = 0 #: C8. What a cache-load or DMA byte inside the chip (data RAM, I/O) costs: 0 (default; #: byuu's model, ares ``hg51b.cpp`` l.20-24 ``wait()`` returns 0) or 1 (closed-box #: Mesen2 runs: a 1,024-byte ROM-to-data-RAM DMA stays busy for 32 S-CPU polls with ROM #: wait 0 and 141 with wait 7, the ratio of 2 to 9 clocks a byte; OBSERVED, #: ``scripts/cx4_probe.py dma-cost-w0 dma-cost-w7``). INTERNAL_ACCESS_COST = 0 #: C10. False (default; byuu's model, ares ``instructions.cpp`` l.143-148): F800h-FBFFh #: is CLEAR (A, P, the RAM buffer and DPR = 0). True: a NOP, as a closed-box Mesen2 run #: shows (A, P and DPR unchanged after F800h, F9FFh, FB00h; OBSERVED, #: ``scripts/cx4_probe.py clear``). Unused by the program. CLEAR_IS_NOP = False #: C11. "ares" (default; byuu's model, ares ``instructions.cpp`` l.193 ``r.gpr[reg]``): #: ``LD P,reg`` takes R(word & 15). "operand-observed": the operand code is read like #: any other register operand (00h A, 06h 0, 51h FFFFFFh, 66h/76h/E6h R6) and masked #: to 15 bits, as a closed-box Mesen2 run shows (OBSERVED, ``scripts/cx4_probe.py #: ldp``). Unused by the program. LD_P_SOURCE = "ares" #: C16. True (default; fullsnes' register table; a closed-box Mesen2 run reads A for #: 00h too, OBSERVED ``scripts/cx4_probe.py ldp``): operand 00h reads A. #: False: byuu's model, ares ``readRegister`` (``registers.cpp`` l.1-63), reads 0. Writes to 00h do #: nothing in both emulators. The program never names 00h as an operand (survey). OPERAND_00_READS_A = True def __init__( self, bus_read: Callable[[int], int], bus_write: Callable[[int, int], None] | None = None, data_rom: Sequence[int] | None = None, ) -> None: self._bus_read = bus_read self._bus_write = bus_write or (lambda address, value: None) if data_rom is None: self.data_rom = computed_data_rom() else: words = [int(word) for word in data_rom] if len(words) != WORDS or any(not 0 <= word <= MASK for word in words): raise ValueError(f"data_rom must be {WORDS} words of 24 bits") self.data_rom = words self.data_ram = bytearray(DATA_RAM_SIZE) self.program_ram = [[0] * 256, [0] * 256] # the instruction cache, 2 pages self.r = [0] * 16 self.stack = [0] * STACK_DEPTH self.cache_lock = [False, False] self.cache_address = [NO_PAGE, NO_PAGE] self.vectors = bytearray(32) # The dispatch table: one bound handler per high byte (``_decode.OPS``). self._ops = [getattr(self, f"_op_{key}") for key, _ in OPS] self.clock = 0 # chip clocks since construction self.instructions = 0 # instructions executed since construction self._debt = 0 # clocks the last run went past its budget self.reset() # ----- reset (U20, C15) -------------------------------------------------------------- def reset(self) -> None: """Power-on state (U20: ares ``hg51b.cpp`` l.125 ``power``): halted, cache empty, waits ROM 3 / RAM 3, every register 0, IRQ enabled. C15: the console's reset is assumed to be the same, so this keeps the data RAM (and the cache contents, which are marked empty); a new core's data RAM is zero.""" self.pb = 0 self.pc = 0 self.a = 0 self.p = 0 self.mul = 0 self.mdr = 0 self.rom = 0 self.ram = 0 self.mar = 0 self.dpr = 0 self.r[:] = [0] * 16 self.n = self.z = self.c = self.v = False self.stack[:] = [0] * STACK_DEPTH self.sp = 0 self.irq_flag = False self.irq_line = False self.lock = False self.halted = True self.irq_disabled = False self.single_rom = True self.vectors[:] = bytes(32) self.wait_rom = 3 self.wait_ram = 3 self.suspend_enabled = False self.suspend_duration = 0 self.cache_enabled = False self.cache_page = 0 self.cache_preload = False self.cache_lock[:] = [False, False] self.cache_address[:] = [NO_PAGE, NO_PAGE] self.cache_base = 0 self.cache_pb = 0 self.cache_pc = 0 self._cache_pos = -1 # bytes of the page load done; -1: not started self._cache_target = 0 # the cache page being loaded self._cache_from = 0 # its ROM address self.dma_enabled = False self.dma_source = 0 self.dma_target = 0 self.dma_length = 0 self._dma_pos = 0 self.bus_enabled = False self.bus_reading = False self.bus_writing = False self.bus_pending = 0 self.bus_address = 0 self._mul_pending = -1 # C6: a product not yet visible # ----- time ---------------------------------------------------------------------------- def run(self, clocks: int) -> int: """Advance by ``clocks`` chip clocks (less what the last call overran); returns the instructions executed. Halted, locked or suspended time passes in one go.""" budget = clocks - self._debt start = self.instructions step = self.step while budget > 0: idle = self.halted and not (self.cache_enabled or self.dma_enabled) if self.lock or (idle and not self.suspend_enabled): self._tick(budget) # nothing happens but the bus port finishing budget = 0 break if self.suspend_enabled: if self.suspend_duration == 0: self._tick(budget) # suspended until $7F5D budget = 0 break spent = min(budget, self.suspend_duration) self._tick(spent) self.suspend_duration -= spent if self.suspend_duration == 0: self.suspend_enabled = False budget -= spent continue budget -= step() self._debt = -budget return self.instructions - start def step(self) -> int: """One unit of the main loop; returns its clocks (0 when it only decided something, e.g. that a cache load must start).""" if self.lock: self._tick(1) return 1 if self.suspend_enabled: self._tick(1) if self.suspend_duration: self.suspend_duration -= 1 if self.suspend_duration == 0: self.suspend_enabled = False return 1 if self.cache_enabled: return self._cache_byte() if self.dma_enabled: return self._dma_byte() if self.halted: self._tick(1) return 1 return self._execute() def _tick(self, clocks: int) -> None: """Let ``clocks`` pass: the bus port counts down and completes (ares ``hg51b.cpp`` l.35 ``step``).""" self.clock += clocks if self.bus_enabled: if self.bus_pending > clocks: self.bus_pending -= clocks else: self.bus_enabled = False self.bus_pending = 0 if self.bus_reading: self.bus_reading = False self.mdr = self._read(self.bus_address) # the byte, zero-extended if self.bus_writing: self.bus_writing = False self._write(self.bus_address, self.mdr & 0xFF) # ----- instructions -------------------------------------------------------------------- def _execute(self) -> int: start = self.clock found = self._lookup() if found < 0: self._halt() # both cache pages locked and the page is not cached return 0 if found == 0: return 0 # a page load has started; it runs as its own units word = self.program_ram[self.cache_page][self.pc] self._advance() self._tick(1) pending = self._mul_pending self._mul_pending = -1 self._ops[word >> 8](word) if pending >= 0: # C6: the previous instruction's product appears now self.mul = pending self.instructions += 1 return self.clock - start def _advance(self) -> None: """PC + 1; past FFh execution moves to cache page 1 with PB = P (U2; ares ``hg51b.cpp`` l.55-63 ``advance``). On page 1 it halts.""" pc = (self.pc + 1) & 0xFF self.pc = pc if pc: return if self.cache_page == 1: self._halt() return self.cache_page = 1 if self.cache_lock[1]: self._halt() return self.pb = self.p if self._lookup() < 0: self._halt() # ----- the cache (U2) ------------------------------------------------------------------ def _lookup(self) -> int: """Find PB's page: 1 cached (and selected), 0 a load has started, -1 both cache pages locked. Tries the current page, then the other, then loads into an unlocked one (ares ``hg51b.cpp`` l.72-96 ``cache``).""" address = (self.cache_base + (self.pb << 9)) & MASK page = self.cache_page if self.cache_address[page] == address: return 1 page ^= 1 self.cache_page = page if self.cache_address[page] == address: return 1 if self.cache_lock[page]: page ^= 1 self.cache_page = page if self.cache_lock[page]: return -1 self._start_load(page, address) return 0 def _start_load(self, page: int, address: int) -> None: self.cache_enabled = True self.cache_preload = False self._cache_pos = 0 self._cache_target = page self._cache_from = address def _cache_byte(self) -> int: """One byte of a page load (256 little-endian words, 512 bytes).""" if self._cache_pos < 0: # started by $7F48: decide what to load now (C9) if self.cache_preload: address = (self.cache_base + (self.pb << 9)) & MASK self._start_load(self.cache_page, address) else: found = self._lookup() if found: # cached already, or both pages locked: nothing to load self.cache_enabled = False return 0 offset = self._cache_pos address = (self._cache_from + offset) & MASK cost = self._wait(address) self._tick(cost) value = self._read(address) words = self.program_ram[self._cache_target] if offset & 1: words[offset >> 1] = words[offset >> 1] & 0x00FF | value << 8 else: words[offset >> 1] = value offset += 1 if offset == 512: self.cache_address[self._cache_target] = self._cache_from self.cache_enabled = False offset = -1 self._cache_pos = offset return cost # ----- DMA (U15, C3) ------------------------------------------------------------------- def _dma_byte(self) -> int: position = self._dma_pos if position >= self.dma_length: # also a length of 0: nothing to copy self.dma_enabled = False self._dma_pos = 0 return 0 source = (self.dma_source + position) & MASK target = (self.dma_target + position) & MASK if self._dma_locks(region(source), region(target)): self.lock = True self.dma_enabled = False self._dma_pos = 0 return 0 start = self.clock self._tick(self._wait(source)) value = self._read(source) self._tick(self._wait(target)) self._write(target, value) position += 1 if position >= self.dma_length: self.dma_enabled = False position = 0 self._dma_pos = position return self.clock - start @staticmethod def _dma_locks(source: int, target: int) -> bool: """C3: both ends ROM, or both SRAM (ares ``hg51b.cpp`` l.104-105).""" return source == target and source in (REGION_ROM, REGION_SRAM) # ----- the chip's own bus -------------------------------------------------------------- def _wait(self, address: int) -> int: kind = region(address) if kind == REGION_ROM: return 1 + self.wait_rom if kind == REGION_SRAM: return 1 + self.wait_ram return self.INTERNAL_ACCESS_COST def _read(self, address: int) -> int: kind = region(address) if kind in (REGION_ROM, REGION_SRAM): return self._bus_read(address) & 0xFF if kind == REGION_DATA_RAM: return self.data_ram[address & 0xFFF] if kind == REGION_IO: return self._read_io(address & 0x3FF) return 0 # nothing selected: 00h (ares ``hitachidsp/memory.cpp`` ``read``) def _write(self, address: int, value: int) -> None: kind = region(address) if kind == REGION_SRAM: self._bus_write(address, value) elif kind == REGION_DATA_RAM: self.data_ram[address & 0xFFF] = value elif kind == REGION_IO: self._write_io(address & 0x3FF, value) # ROM writes go nowhere (ares ``writeROM`` does nothing) # ----- the register operands (start-here.md "Registers"; U5, U6, U10) ----------------- def _get(self, word: int) -> int: """Read the operand named by the word's low 7 bits (bit 7 is ignored).""" code = word & 0x7F if code >= 0x60: return self.r[code & 0xF] # R0-R15, mirrored at 70h-7Fh if code >= 0x50: return CONSTANTS[code & 0xF] if code == 0x00: return self.a if self.OPERAND_00_READS_A else 0 # C16 if code == 0x01: return self.mul >> 24 if code == 0x02: return self.mul & MASK if code == 0x03: return self.mdr if code == 0x08: return self.rom if code == 0x0C: return self.ram if code == 0x13: return self.mar if code == 0x1C: return self.dpr if code == 0x20: return self.pc if code == 0x28: return self.p if code == 0x2E or code == 0x2F: # start a bus read at MAR; the operand reads 0 self._start_bus(code, reading=True) return 0 # undefined codes read 0 (ares ``registers.cpp`` l.62; provisional, U5) def _put(self, code: int, value: int) -> None: """Write ``value`` to the register named by ``code`` (bit 7 ignored).""" code &= 0x7F value &= MASK if code >= 0x60: self.r[code & 0xF] = value elif code == 0x01: self.mul = self.mul & MASK | value << 24 elif code == 0x02: self.mul = self.mul & ~MASK | value elif code == 0x03: self.mdr = value elif code == 0x08: self.rom = value elif code == 0x0C: self.ram = value elif code == 0x13: self.mar = value elif code == 0x1C: self.dpr = value elif code == 0x20: self.pc = value & 0xFF elif code == 0x28: self.p = value & 0x7FFF elif code == 0x2E or code == 0x2F: # start a bus write of MDR at MAR self._start_bus(code, reading=False) # constants, 00h and undefined codes: nothing def _start_bus(self, code: int, *, reading: bool) -> None: """Operand 2Eh uses the ROM wait, 2Fh the RAM wait (U10, C7).""" self.bus_enabled = True self.bus_reading = reading self.bus_writing = not reading wait = self.wait_rom if code == 0x2E else self.wait_ram self.bus_pending = wait + self.BUS_DELAY_EXTRA self.bus_address = self.mar # ----- moves, loads and stores --------------------------------------------------------- def _op_nop(self, word: int) -> None: pass def _op_wait(self, word: int) -> None: """Stall until the bus access completes (U10).""" if self.bus_enabled: self._tick(self.bus_pending) def _op_inc_mar(self, word: int) -> None: self.mar = (self.mar + 1) & MASK def _op_ld_reg(self, word: int) -> None: value = self._get(word) sub = word >> 8 & 3 if sub == 0: self.a = value elif sub == 1: self.mdr = value else: self.mar = value def _op_ld_p_reg(self, word: int) -> None: if self.LD_P_SOURCE == "ares": self.p = self.r[word & 0xF] & 0x7FFF # C11 else: # "operand-observed" self.p = self._get(word) & 0x7FFF def _op_ld_imm(self, word: int) -> None: value = word & 0xFF # zero-extended sub = word >> 8 & 3 if sub == 0: self.a = value elif sub == 1: self.mdr = value elif sub == 2: self.mar = value else: self.p = value def _op_ld_pl(self, word: int) -> None: self.p = self.p & 0x7F00 | word & 0xFF def _op_ld_ph(self, word: int) -> None: self.p = self.p & 0x00FF | (word & 0x7F) << 8 def _op_st(self, word: int) -> None: self._put(word, self.mdr if word & 0x100 else self.a) def _op_swap(self, word: int) -> None: index = word & 0xF self.a, self.r[index] = self.r[index], self.a def _op_clear(self, word: int) -> None: if self.CLEAR_IS_NOP: return self.a = self.p = self.ram = self.dpr = 0 # U17 (ares instructionCLEAR) # ----- data RAM and data ROM (U3, U4, U18) -------------------------------------------- @staticmethod def _fold(address: int) -> int: """12-bit data RAM address; C00h-FFFh fold onto 800h-BFFh (U3).""" address &= 0xFFF return address - 0x400 if address >= 0xC00 else address def _op_rdram_a(self, word: int) -> None: shift = 8 * (word >> 8 & 3) value = self.data_ram[self._fold(self.a)] self.ram = self.ram & ~(0xFF << shift) & MASK | value << shift def _op_rdram_imm(self, word: int) -> None: shift = 8 * (word >> 8 & 3) value = self.data_ram[self._fold(self.dpr + (word & 0xFF))] self.ram = self.ram & ~(0xFF << shift) & MASK | value << shift def _op_wrram_a(self, word: int) -> None: self.data_ram[self._fold(self.a)] = self.ram >> (8 * (word >> 8 & 3)) & 0xFF def _op_wrram_imm(self, word: int) -> None: address = self._fold(self.dpr + (word & 0xFF)) self.data_ram[address] = self.ram >> (8 * (word >> 8 & 3)) & 0xFF def _op_rdrom_a(self, word: int) -> None: self.rom = self.data_rom[self.a & 0x3FF] def _op_rdrom_imm(self, word: int) -> None: self.rom = self.data_rom[word & 0x3FF] # ----- state ----------------------------------------------------------------------------- def capture_state(self, *, memory: bool = True) -> CPUState: """Every register, the I/O state and (unless ``memory=False``) the data RAM and the instruction cache: a save state. ``memory=False`` is the cheap per-instruction form traces and the debugger use.""" return CPUState( pb=self.pb, pc=self.pc, a=self.a, p=self.p, mul=self.mul, mdr=self.mdr, rom=self.rom, ram=self.ram, mar=self.mar, dpr=self.dpr, r=tuple(self.r), n=self.n, z=self.z, c=self.c, v=self.v, stack=tuple(self.stack), sp=self.sp, irq_flag=self.irq_flag, irq_line=self.irq_line, lock=self.lock, halted=self.halted, irq_disabled=self.irq_disabled, single_rom=self.single_rom, vectors=bytes(self.vectors), wait_rom=self.wait_rom, wait_ram=self.wait_ram, suspend_enabled=self.suspend_enabled, suspend_duration=self.suspend_duration, cache_enabled=self.cache_enabled, cache_page=self.cache_page, cache_preload=self.cache_preload, cache_lock=tuple(self.cache_lock), cache_address=tuple(self.cache_address), cache_base=self.cache_base, cache_pb=self.cache_pb, cache_pc=self.cache_pc, cache_pos=self._cache_pos, cache_target=self._cache_target, cache_from=self._cache_from, dma_enabled=self.dma_enabled, dma_source=self.dma_source, dma_target=self.dma_target, dma_length=self.dma_length, dma_pos=self._dma_pos, bus_enabled=self.bus_enabled, bus_reading=self.bus_reading, bus_writing=self.bus_writing, bus_pending=self.bus_pending, bus_address=self.bus_address, mul_pending=self._mul_pending, clock=self.clock, instructions=self.instructions, debt=self._debt, data_ram=bytes(self.data_ram) if memory else None, program_ram=(tuple(self.program_ram[0]), tuple(self.program_ram[1])) if memory else None, ) def restore_state(self, state: CPUState) -> None: """Replace everything the state carries (a registers-only state leaves the data RAM and the cache contents alone).""" if type(state) is not CPUState: raise TypeError("state must be a CPUState") for name in ( "pb", "pc", "a", "p", "mul", "mdr", "rom", "ram", "mar", "dpr", "n", "z", "c", "v", "sp", "irq_flag", "irq_line", "lock", "halted", "irq_disabled", "single_rom", "wait_rom", "wait_ram", "suspend_enabled", "suspend_duration", "cache_enabled", "cache_page", "cache_preload", "cache_base", "cache_pb", "cache_pc", "dma_enabled", "dma_source", "dma_target", "dma_length", "bus_enabled", "bus_reading", "bus_writing", "bus_pending", "bus_address", "clock", "instructions", ): # fmt: skip setattr(self, name, getattr(state, name)) self.r[:] = state.r self.stack[:] = state.stack self.vectors[:] = state.vectors self.cache_lock[:] = state.cache_lock self.cache_address[:] = state.cache_address self._cache_pos = state.cache_pos self._cache_target = state.cache_target self._cache_from = state.cache_from self._dma_pos = state.dma_pos self._mul_pending = state.mul_pending self._debt = state.debt if state.data_ram is not None: self.data_ram[:] = state.data_ram if state.program_ram is not None: self.program_ram[0][:] = state.program_ram[0] self.program_ram[1][:] = state.program_ram[1] __all__ = [ "DATA_RAM_SIZE", "HG51B", "NO_PAGE", "REGION_DATA_RAM", "REGION_IO", "REGION_NONE", "REGION_ROM", "REGION_SRAM", "region", ]