Log inGet started
Package

huc6280.module

Newest version

README.md

pcengine.huc6280

The Hudson HuC6280 CPU in Luau: the 65C02 instruction set plus the HuC6280's extras (SXY/SAX/SAY, CLA/CLX/CLY, ST0/ST1/ST2, TAM/TMA with eight 8 KB MMU pages over a 21-bit space, CSL/CSH, SET and the T flag, BSR, TST, block transfers TII/TDD/TIN/TIA/TAI, BBR/BBS/RMB/SMB), its on-die timer and its interrupt controller (IRQ2/BRK, IRQ1, timer). Cycles are counted in 7.16 MHz units; in low speed (CSL) each CPU cycle costs four.

local HuC6280 = require("pcengine.huc6280")
local cpu = HuC6280.new({
	read = function(phys) return 0xFF end,      -- 21-bit physical read (I/O, open bus)
	write = function(phys, v) end,             -- 21-bit physical write
	map = function(bank) return buf, off, writable end, -- fast path: a buffer for an 8 KB bank, or nil
})
cpu.reset()
local used = cpu.run(455)          -- run at least 455 cycles, returns cycles used
cpu.setIrq(HuC6280.IRQ1, true)     -- level-triggered IRQ1 / IRQ2 lines

The timer ($0C00-$0FFF) and interrupt controller ($1400-$17FF) are on the die: route those I/O-page addresses to cpu.timerRead/timerWrite/irqRead/irqWrite. cpu.getState()/setState() for save states, cpu.regs() for tests.