A cycle-accurate Apple II and Apple IIgs emulator written in Zig, usable as both a program and a library.

give the 65816 its stack and its register transfers

228 encodings against 195: the seventeen register-to-register moves and register increments, and the sixteen that push and pull. Two things the recordings settled. The stack is two stacks, and which one an instruction gets depends on which machine it came from. Emulating, the pointer is held inside page one, so a pull from $01ff reads $000100 — that is the 6502's stack and a program written for that machine expects it. The instructions this processor added were never promised any such thing and step straight out of the page: PLD from $01ff reads $000200, and PHD from $0100 puts its second byte at $0000ff. So the confinement is per instruction rather than per access, and it is applied at the start of each instruction and when the register is read, never in between — which is how the pointer can leave page one during a push and still read back inside it afterwards. XBA takes two cycles of its own rather than one, and PER's internal cycle holds the last operand byte's address, which is the same rule REP, SEP and the direct page penalty all follow. The transfers are where the widths get particular: which flag governs is the destination's and not the source's, so TXA is as wide as M says and TAX as wide as X says, and the four that move whole sixteen-bit registers — TCD, TDC, TCS, TSC — ignore both because what they move was never eight bits wide. TXS and TCS set no flags; XBA sets its two from the low half after the swap, eight bits of it whatever M says. 4,560,000 cases, every register, every cycle count and every cycle of every bus trace. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FawbWzEu5hoLLZSMCehUGP


Author jcollie.dev
Co-author Claude Opus 5 Date Commit Parent 663d5dc6