$ show felixrieseberg/macintosh.js
macintosh.js is a desktop application that emulates a 1991 Macintosh Quadra running Mac OS 8 using Electron and a WebAssembly port of the Basilisk II emulator. The architecture consists of three main components: the Electron main process handling application lifecycle and system IPC, the renderer process managing the UI and user input via canvas, and a WebWorker running the emulator core. Communication between threads uses SharedArrayBuffers and Atomics for synchronized access to video, audio, input, and ethernet data. The application provides virtual disk storage through a host folder mapping and basic ethernet networking via UDP broadcast for local AppleTalk communication.
The LLM identified 4 files worth highlighting for reuse:
Implements thread-safe locking mechanisms using JavaScript Atomics for communication between the main thread and WebWorker. Provides acquireLock and releaseLock functions that use Atomics.compareExchange and Atomics.store for synchronization on SharedArrayBuffers. This pattern is reusable in any scenario requiring coordination between threads using shared memory.
Implements a robust audio streaming system using the Web Audio API with double-buffering to prevent underruns. Manages audio chunks in SharedArrayBuffer, handles timing compensation for browser jitter, and maintains a queue of pre-buffered audio segments. Demonstrates advanced understanding of real-time audio constraints in web environments.
Implements a lock-free ring buffer in SharedArrayBuffer for Ethernet frame communication between the emulator worker and main process. Uses atomic operations to manage read/write pointers and handles length-prefixed frame encapsulation. Provides efficient, low-latency networking without locks or blocking operations.
Defines the SharedArrayBuffer memory layout and communication protocol used between the renderer, main process, and emulator worker. Specifies exact byte offsets for input controls, video mode, audio data, and ethernet buffers, along with lock state constants. This clean protocol definition enables safe, high-performance shared memory communication.