How bubio/bubix1turboz works
Purpose and Entry Point
BubiX1turboZ is a macOS/Linux/Windows emulator for the Sharp X1 turbo Z. It retains a C++ eX1turboZ-derived emulation core and supplies a Nim application shell. The executable entry point is src/nim/bubix1turboz.nim; its package/build definition is bubix1turboz.nimble.
Native Core and C ABI Boundary
The C++ core owns machine execution and host-facing emulation operations. src/core/emu.cpp and src/core/emu.h coordinate the emulator, while src/bridge/bubix1_api.cpp and src/bridge/bubix1_api.h expose a narrow API for Nim. This bridge is the primary language and ownership boundary: UI/application features should call core capabilities through it rather than couple directly to C++ internals.
Machine Emulation
The virtual Sharp X1 system is composed from CPU, event, memory, I/O, and device implementations. src/core/vm/x1/x1.cpp and src/core/vm/x1/x1.h define the X1 machine integration; src/core/vm/z80.cpp supplies CPU emulation; src/core/vm/x1/display.cpp handles the machine display path. The VM also includes floppy, disk, hard-disk/SCSI, keyboard/mouse, MIDI, and Yamaha/PSG audio devices under src/core/vm/.
SDL Host Adaptation
The C++ core uses SDL-oriented host services for screen output, audio, input, and platform OS support. src/core/sdl/osd.cpp is the host abstraction coordinator, with src/core/sdl/osd_screen.cpp and src/core/sdl/osd_sound.cpp driving rendering and sound. SDL2 is therefore a material runtime dependency across supported platforms.
Nim Application Orchestration
Nim translates user intent and persisted application state into bridge calls. src/nim/bubix1/core.nim manages core interaction; src/nim/bubix1/diskset.nim manages disk insertion workflows; src/nim/bubix1/savestate.nim implements quick save/load state. Supporting modules cover ROM/application paths, key mapping, recent files, archive handling, capture, localization, and configuration. Required ROMs reside in per-user application data directories, not the repository.
Platform UI Boundary
Shared UI contracts live in src/nim/bubix1/ui/types.nim, with platform-selected implementations for windowing, menus, dialogs, clipboard, and state/volume panels. Linux uses GTK3 integration in src/nim/bubix1/ui/linux/gtk3.nim; macOS wraps native Objective-C services such as src/nim/bubix1/ui/macos/nativemenu.m; Windows uses Win32 bindings in src/nim/bubix1/ui/windows/win32.nim. Stub modules permit unsupported or optional host features without leaking platform code into shared application logic.
Distribution and Build Pipeline
Build scripts compile the patched C++ core, link it with the Nim app, and package native artifacts: scripts/build_core.sh, scripts/build_nim_app.sh, and per-platform drivers such as scripts/build_macos.sh. Release CI is split by OS in .github/workflows/build-macos.yml, .github/workflows/build-linux.yml, and .github/workflows/build-windows.yml; release assets are published via .github/workflows/publish-release-assets.yml. Linux additionally depends on GTK3 and zlib; Windows scripts fetch MinGW-w64, SDL2, and zlib.
Main entry points: emu.cpp Emulator coordinator · core.nim Core orchestration · types.nim Shared UI contracts · build_nim_app.sh App build
Components 24
Nim application
- Application entry
src/nim/bubix1turboz.nim - Core orchestration · Translates application actions into bridge calls.
src/nim/bubix1/core.nim - Disk workflows
src/nim/bubix1/diskset.nim - Save states
src/nim/bubix1/savestate.nim - Shared UI contracts
src/nim/bubix1/ui/types.nim
Native emulation
- C ABI bridge · Primary ownership and language boundary for emulator operations.
src/bridge/bubix1_api.cpp - Bridge API contract
src/bridge/bubix1_api.h - Emulator coordinator
src/core/emu.cpp - Core contract
src/core/emu.h - Sharp X1 machine
src/core/vm/x1/x1.cpp - Z80 CPU
src/core/vm/z80.cpp - Machine display
src/core/vm/x1/display.cpp - SDL host services · Coordinates screen, audio, input, and OS services.
src/core/sdl/osd.cpp - SDL rendering
src/core/sdl/osd_screen.cpp - SDL audio
src/core/sdl/osd_sound.cpp
Platform UI
- Linux GTK3 UI
src/nim/bubix1/ui/linux/gtk3.nim - macOS native menu
src/nim/bubix1/ui/macos/nativemenu.m - Windows Win32 UI
src/nim/bubix1/ui/windows/win32.nim
Build and release
- Nim package definition
bubix1turboz.nimble - Core build
scripts/build_core.sh - App build
scripts/build_nim_app.sh - macOS packaging
scripts/build_macos.sh - OS build CI · Separate macOS, Linux, and Windows build workflows.
.github/workflows/build-macos.yml - Release publishing
.github/workflows/publish-release-assets.yml
Connections 24
- Application entry → Core orchestration: starts
- Application entry → Shared UI contracts: uses
- Core orchestration → Disk workflows: coordinates
- Core orchestration → Save states: coordinates
- Core orchestration → C ABI bridge: calls
- Shared UI contracts → Linux GTK3 UI: implemented by
- Shared UI contracts → macOS native menu: implemented by
- Shared UI contracts → Windows Win32 UI: implemented by
- C ABI bridge → Bridge API contract: declares
- C ABI bridge → Emulator coordinator: invokes
- Emulator coordinator → Core contract: declares
- Emulator coordinator → Sharp X1 machine: runs
- Sharp X1 machine → Z80 CPU: uses
- Sharp X1 machine → Machine display: drives
- Emulator coordinator → SDL host services: uses host services
- SDL host services → SDL rendering: renders through
- SDL host services → SDL audio: outputs through
- Nim package definition → App build: defines build
- Core build → Emulator coordinator: compiles
- App build → Application entry: builds and links
- App build → Core build: depends on
- macOS packaging → App build: packages
- OS build CI → macOS packaging: runs platform builds
- Release publishing → OS build CI: publishes artifacts from