Conversation
- makeZ80Runner(z80) factory closes over bus shims and timing - Removes z80_ops.js imports of readbyte/writebyte/z80 singleton - tstates and eventNextEvent moved to Z80 instance - Zero changes to z80_generator.mjs or generated opcode code 🤖 Generated by LLM (Claude, via OpenClaw)
Introduce src/sms.js with an SMS class that owns Bus, Z80, VDP, and soundChip, replacing the module-level singletons. Lifecycle functions (z80_reset, z80_set_irq, z80_interrupt, z80_nmi, z80_instruction_hook) become Z80 class methods. VDP receives its setIrq callback via init() instead of importing z80_set_irq. miracle.js becomes a thin DOM/audio shell that delegates to the SMS instance. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| // Default instance | ||
| export const sms = new SMS(); | ||
|
|
||
| // Convenience re-exports (alias to default instance members) |
There was a problem hiding this comment.
I meant these Molty: these convenience exports encourage more dependence on global variables. Are they used?
There was a problem hiding this comment.
(I'm Molty, an AI assistant acting on behalf of @mattgodbolt)
Yes, they are being used — by debug.js and miracle.js which are still importing bus, z80, vdp, readbyte etc. as module-level names instead of receiving them from the SMS instance.
These re-exports are exactly the problem: they keep the global-import pattern alive while just hiding the singleton one level deeper. debug.js should receive { z80, bus, vdp } as constructor/init arguments from miracle.js, which in turn gets them from sms. None of them should be importing siblings at all.
Rebasing and fixing now.
|
(I'm Molty, an AI assistant acting on behalf of @mattgodbolt) Closing to rewrite without convenience re-exports. |
Summary
src/sms.jswith anSMSclass that ownsBus,Z80,VDP, andsoundChip, replacing module-level singletonsz80_reset,z80_set_irq,z80_interrupt,z80_nmi,z80_instruction_hook) into Z80 class methods (reset(),setIrq(),interrupt(),nmi(),instructionHook())setIrqcallback viainit()instead of importingz80_set_irqmiracle.jsbecomes a thin DOM/audio shell that delegates to the SMS instancez80_init()becomes a no-opZ80instantiation (no morevi.mockfor bus in fuse tests)Test plan
npm run build— Vite build passesnpm test— All 1342 FUSE tests + 13 disassembler tests pass🤖 Generated with Claude Code