XL1200-EMU Symbolics XL1200 Emulator

C11 Emulator Peripherals & Host Backends

This document describes the from-scratch ISO C11 implementation of the Symbolics XL1200 / Merlin-II motherboard peripherals, host I/O backends, firmware loaders, and disk/tape tooling in emu/.


1. Core vs. Shell Boundary

To keep libivory_core.so hot-reloadable and portable across Linux, macOS, and Windows (MinGW-w64), the peripheral stack enforces a strict split between pure ISO C11 core devices (compiled into libivory_core.so) and OS-specific host backends & loaders (compiled into the ivory-xl1200 shell and wired via callback structs):

LayerSource FilesResponsibility
Core Devices (libivory_core.so)merlin.c, nvram_mk48t02.c, scsi_wd33c93.c, eth_82586.c, console_hw.cBus decode, 82C54 PIT, MK48T02 NVRAM/TOD, WD33C93A SCSI state machine + streaming 64-bit disk/CD/tape I/O, Intel 82586 DMA/descriptor engine, DUSCC + 8237A + VRAM + SLB protocol. Zero platform networking or GUI headers.
Host Backends & Loader (ivory-xl1200 shell)eth_slirp.c, eth_tap_linux.c, serial_host.c, loader.cUser-mode libslirp NAT, Linux /dev/net/tun TAP & AF_PACKET raw Ethernet, portable 2-channel serial transports (TCP listen/connect, POSIX AF_UNIX / Win32 Named Pipe, TX capture file), and IFEP promJ split/combined Boot PROM loading.
Standalone Media Toolfep_convert.c (ivory_fep_tools.h)ivory-fep-convert CLI & shared library functions for MacIvory→XL1200 FEPFS conversion, blank/FEPFS disk creation, SIMH .tap creation, and image inspection.

2. Merlin-II Motherboard Hub (emu/src/merlin.c)

MerlinBoard (declared in emu/include/ivory_emu.h) owns the C-Bus core registers, 82C54 PIT, MK48T02 NVRAM, I/O Board 0 64-KWord DMA SRAM, WD33C93A SCSI controller, Intel 82586 Ethernet controller, DP8466 ESDI stub, and VIC068/VMEbus register storage, and dispatches console/serial/VRAM traffic to Xl1200Console.

2.1 Bus Dispatch & Lifecycle API

  • merlin_init / merlin_reset: Resets all sub-devices, initializes MERLIN_CACHE_CTRL_PMA (0x0A000004) to 2 (enabled), MERLIN_VME_TIMEOUT_PMA (0x0A000008, board->vme_timeout, VME Timeout / Board ECO register) to MERLIN_ECO_DEFAULT (0x0FF4FF11), builds the 32-byte I/O Board 0 ID ROM (with rotated-byte checksum), populates MK48T02 cookies & MAC, and clears pending interrupts.
  • merlin_set_identity(MerlinBoard *, const MerlinIdentityConfig *): Configures board serial number, Ethernet MAC address, monitor type (0 = Philips, 1 = Sony), manufacturing date (days since 1982-01-01), and Main/IO0 ECO nibbles, automatically regenerating the I/O Board 0 ID ROM checksum, MK48T02 MAC copy (+0x20), and eth.ia_addr.
  • merlin_io_read / merlin_io_write: Routes all Merlin-II PMAs (0x08000000 PIT, 0x09000000 MK48T02, 0x0A000000..0x0A00000F C-Bus core, 0x40000000..0x4000FFFF IO0 SRAM, 0x44014000..0x4402D001 IO0 MMIO, 0x48000000..0x4807FFFF VRAM, 0x80000000..0x8FF8000F VME/VIC068). Returns IVORY_ERR_BUS_FAULT for unpopulated I/O Board 1 (0x50000000..0x5FFFFFFF) and unmapped MMIO addresses.

2.2 Performance & Idle-Sleep Optimizations

  • Event-Driven DMA (dma_service_pending): merlin_tick() skips SCSI and console 8237A DMA scans on ticks where neither controller has armed transfers, keeping hot-path tick overhead minimal.
  • Cached Interrupt State (irq_active_cached): Recomputed only when int_pending or int_enable changes, making merlin_irq_asserted() a single boolean check in the CPU loop.
  • Idle Timer Prediction (merlin_us_until_next_timer_irq): Computes the exact microsecond horizon until the next enabled 82C54 Counter 2 (10 MHz), cascaded Counter 1→0 (1 MHz), or C-Bus interval timer IRQ, allowing the shell to sleep cleanly during Genera idle loops instead of busy-spinning.
  • Run-Light Activity Latch: Tracks MERLIN_LEDS_PMA (0x0A000000) specifically on U1 bit 0x02 (process activity, ignoring the 2 Hz U0 heartbeat bit 0x01) for accurate GUI status-bar activity indication.

3. Mostek MK48T02 NVRAM & BCD TOD Clock (emu/src/nvram_mk48t02.c)

Mk48t02Nvram emulates the 2,048-byte battery-backed Timekeeper at 0x09000000..0x090007FF:

  • NVRAM Persistence: nvram_mk48t02_load_file() and nvram_mk48t02_save_file() load/persist the exact 2,048-byte image (MK48T02_SIZE_BYTES). nvram_mk48t02_init() seeds Merlin cookies 0x55, 0xAA, 1, 16 at +1..+4 and the 6-byte Symbolics MAC (08:00:05:00:00:01 default) at +0x20..+0x25.
  • BCD TOD Latching (0x7F8..0x7FF): Implements the full READ<6> freeze latch (read_latch[8]) and WRITE<7> commit latch (write_latch[8]), STOP<7> oscillator halt in Seconds, START<7> in Hours, and a C11-portable civil_utc_to_epoch() converter (avoiding non-standard timegm()) that maintains time_offset_sec relative to the host UTC clock so guest clock adjustments persist smoothly.

4. WD33C93A SCSI Controller & Streaming Media (emu/src/scsi_wd33c93.c)

Wd33c93Scsi implements a multi-target SCSI bus (targets 0..6, initiator ID 7) without ever loading whole disk images into RAM:

4.1 64-Bit Streaming I/O & Fast Ring DMA

  • 64-Bit Positional I/O: Uses emu/include/emu_io.h (pread/pwrite on POSIX; 64-bit OVERLAPPED ReadFile/WriteFile or _fseeki64 on Windows) so multi-gigabyte FEPFS images (>4 GiB) work cleanly across Linux, macOS, and Windows.
  • 4-KWord Segment-Contiguous 32-Bit DMA Fast Loops: Transfers pack/unpack 4 bytes per DTP-FIXNUM word in bulk across contiguous segments of the 32-KiB I/O Board 0 SRAM ring (0x40005000..0x40006FFF), checking wrap, trigger (0x4401B000), and overrun (0x4401A800) boundaries at segment granularity.

4.2 Target Attachment & Multi-Chunk Phase 0x45 Continuation

  • Target APIs:
    • scsi_wd33c93_attach_disk(scsi, target_id, path, read_only) — 1,280-byte sector FEPFS/LMFS hard disks.
    • scsi_wd33c93_attach_cdrom(scsi, target_id, path) — 2,048-byte sector read-only ISO-9660 images.
    • scsi_wd33c93_attach_tape(scsi, target_id, path, read_only) — Variable-record SIMH .tap sequential tape drives.
    • scsi_wd33c93_detach_target(scsi, target_id) — Live media detach/swap support.
  • Multi-Chunk DMA Continuation: Transfers exceeding 32 KiB pause with CMD_PHASE = 0x45 and SCSI_STATUS = 0x19 (Data-In) or 0x18 (Data-Out). The active SCSI target ID is latched in WD_REG_INT_ACTIVE_TARGET (0x1D, isolated from guest register writes). On reconnect, wd_try_continue_dma_phase() runs before DEST_ID target lookup, handling Genera's scsi-transfer-reconnect zeroing of DEST_ID<2:0>.

5. Intel 82586 Ethernet & Host Networking Backends

5.1 Core Controller (emu/src/eth_82586.c)

Eth82586 is a pure ISO C11 implementation (zero OS headers, zero mutable statics) driven by 0x44016000 <7:5> and sharing MerlinBoard.io0_sram:

  • Full Descriptor Pipeline: Parses SCP (default byte address 0x01FFF4) → ISCP → SCB → CBL (NOP, IA-SETUP, CONFIGURE, MC-SETUP, TRANSMIT with chained TBDs, TDR, DUMP 170B, DIAGNOSE) and RFA (RFD/RBD chains).
  • Address Filtering & Loopback: Implements unicast (IA), broadcast, 64-bit Ethernet CRC-32 multicast hash filtering, promiscuous mode, and internal/external loopback (ETH_82586_CTRL_INHIBIT_LOOPBACK + CONFIGURE byte 3).
  • Host Callback Bridge (EthHostCallbacks): All wire TX/RX goes exclusively through on_tx_frame(ctx, frame, len) and poll_rx_frame(ctx, dst, cap).

5.2 User-Mode NAT Backend (emu/src/eth_slirp.c)

  • Wraps libslirp inside the shell (compiled when HAVE_LIBSLIRP is enabled), providing zero-privilege TCP/UDP/ICMP NAT networking for Genera (e.g., Chaos-over-IP, Telnet, FTP, DNS) without root or TAP configuration.
  • Portable across POSIX (poll) and Windows/MinGW-w64 (Winsock2 + WSAPoll, omitting POLLPRI which triggers WSAEINVAL on Windows).
  • Uses an EmuMutex-guarded 64-slot RX ring (2,048 bytes/frame) and up to 16 libslirp monotonic timers backed by emu_mono_ns().

5.3 Linux TAP & Raw AF_PACKET Backend (emu/src/eth_tap_linux.c)

  • eth_tap_linux_open_tap(ifname, ...): Opens /dev/net/tun with IFF_TAP | IFF_NO_PI in non-blocking mode for bridged L2 host networking (ideal for native Chaosnet or local LAN access).
  • eth_tap_linux_open_packet(ifname, ...): Opens a raw AF_PACKET / SOCK_RAW (ETH_P_ALL) socket bound to a host NIC, filtering out PACKET_OUTGOING echoes on RX.
  • Compiled only on Linux (#ifdef __linux__); cleanly stubbed on non-Linux hosts so libivory_core remains 100% portable.

6. Console, DUSCC/8237A Serial & Host Serial Backends

6.1 Console Hardware (emu/src/console_hw.c)

Xl1200Console implements:

  • Monochrome VRAM (0x48000000..0x4807FFFF): 512 KWords (1152×896 visible, 64-word stride, LSB-leftmost), VIDEO_VPOS (0x44024000), VIDEO_CTRL (0x4402C000, BOW/WOB polarity, enable, forced black, speaker bit), and Am8158 timing (0x4402D000..1). Default GUI overscan crop trims to 1084×812 at (34, 34).
  • Signetics SCN26562/68562 DUSCC (0x44017000/7100) and Intel 8237A 4-Channel DMAC (0x44017200/7300), plus MERLIN_SERIAL_CTRL_PMA (0x44014800).
  • SLB Keyboard/Mouse Serializer: slb_enqueue_wire_bytes() encodes 16-bit SLB logical events into authentic 1-byte (MOUSE-SWITCH, MOUSE-MOVE, SERIAL-WINDOW) and 2-byte (KEY-DOWN, KEY-UP, ALL-KEYS-UP, STATUS, SERIAL-IN) wire frames onto DUSCC Channel A RX / DMAC Channel 0.
  • Serial Host Callback Interface: Routes Channel A/B TX bytes, RX polling, and live modem status (ICTSR<3:0>: DCD/CTS/DSR) through Xl1200SerialCallbacks (console_hw_set_serial_callbacks()).

6.2 Portable 2-Channel Host Serial Backend (emu/include/ivory_serial_host.h, emu/src/serial_host.c)

Xl1200SerialHost bridges console_hw.c's Xl1200SerialCallbacks (called from emu_thread) to Main-Thread non-blocking host I/O via lock-free 4,096-byte SPSC rings (Xl1200SerialRing tx_ring/rx_ring) and emu_ipc.h. Channel 0 (DUSCC Ch.A) and Channel 1 (DUSCC Ch.B) are configured independently via --serial-a <spec> / --serial-b <spec> or s7 :serial-a / :serial-b:

SpecMode (Xl1200SerialMode)Platform Support & Behavior
noneSERIAL_MODE_NONEChannel disconnected (default; Ch.A remains driven by GUI/SLB console).
tcp-listen:<[a]:port>SERIAL_MODE_TCP_LISTENDual-stack IPv4/IPv6 non-blocking single-client TCP listener (auto-reaccepts on disconnect); portable across POSIX and Win32 Winsock2.
tcp:<[a]:port>SERIAL_MODE_TCP_CONNECTNon-blocking outbound TCP client with automatic reconnect inside serial_host_poll().
pipe:<name_or_path>SERIAL_MODE_PIPENative Win32 Named Pipe (\\.\pipe\...) on Windows or POSIX AF_UNIX local server socket on Linux/macOS.
file:<path>SERIAL_MODE_FILEAppend-only TX capture file for logging guest serial output.

Live modem status (XL1200_SERIAL_MODEM_DCD, CTS, DSR in atomic modem_bits) reflects active peer connection state. Public Main-Thread API: serial_host_init(), serial_host_destroy(), serial_host_configure(), serial_host_poll(), serial_host_fill_callbacks(), and serial_host_get_status() (covered by emu/tests/test_serial_host.c).


7. Firmware Boot PROM Loader (emu/src/loader.c)

loader.c loads authentic IFEP promJ / FEP Boot PROM binary images into IfepImage and installs them into IvoryMem without injecting synthetic guest code:

  • Split or Combined Boot PROM (ifep_load_rom_files, ifep_load_file, ifep_load_buffer):
    • Accepts either a combined 128-KiB rom.dump (ifep_load_file) or the two raw 64-KiB EPROM chip dumps (115988 low ‖ 115989 high via ifep_load_rom_files).
    • ifep_guess_rom_hi_path() automatically pairs a lone --rom 115988-*.bin path with its sibling 115989-*.bin file.
    • Parses the 30-byte "IFEP prom<ver>" header, unpacks each 5-byte-word LE section into its declared Zone 31 vma_base (e.g., 0xF8001000..0xF80071F2), reads the (entry_vma, 0xFFFFFFFF) footer, and installs sections via ifep_install() (setting cold-boot entry 0xF8007162 for FEP 3.30).
    • ifep_lookup_vma() supports ROM inspection/disassembly; ifep_free() releases loaded section buffers.

8. Disk & Tape Media Tooling (emu/src/fep_convert.c, emu/include/ivory_fep_tools.h)

Compiled both as the standalone CLI ivory-fep-convert and linked into the emulator shell (ivory_fep_tools.h) for GUI/s7/debug-IPC media creation without spawning subprocesses:

CLI Mode / C APIFunction
ivory-fep-convert <in_macivory_or_mister_vhd> <out_xl1200.raw> [--volume <idx|name>]
(fep_tools_convert_macivory / fep_tools_convert_macivory_ex)
Converts MiSTer FPGA 1,536-byte padded .vhd images (stripping the 256-byte tail per page to packed 1,280-byte .raw), raw MacIvory (LBAL, with or without 0x400 prefix), Apple Partition Map (APM) disks, or Classic HFS volumes (automatically discovering hidden fInvisible=0x4000 'IVRY' files across both Catalog and Extents Overflow B-trees, as well as raw APM FEP partitions). When multiple FEP volumes are found and no --volume filter is given (including from the GUI Convert Mac/VHD... dialog), converts and saves all discovered volumes as <base>_<vol><ext> (e.g., xl1200_fep0.raw, xl1200_fep1.raw, xl1200_fep2.raw). (Note: scsi_wd33c93.c also mounts MiSTer 1,536-byte .vhd images directly without conversion, including read-only, read-write, and sparse .ovl overlay + commit.)
ivory-fep-convert --to-mister-vhd <in_xl1200.raw> <out_mister.vhd>
(fep_tools_to_mister_vhd)
Exports a packed 1,280-byte XL1200 .raw disk image to a MiSTer FPGA 1,536-byte padded .vhd image (1,280-byte FEP page + 256-byte 0x44 tail per 3×512B SD sector slot).
ivory-fep-convert --convert-all <in_apm_or_hfs.img> <out_prefix>
(fep_tools_convert_macivory_all)
Streams and converts every discovered hidden/visible MacIvory FEPFS volume inside an APM or Classic HFS disk image to <out_prefix>_<vol>.raw (e.g., _fep0.raw, _fep1.raw, _fep2.raw).
ivory-fep-convert --create-blank <out.raw> --size-mb <N>
(fep_tools_create_blank)
Creates a sparse, 1,280-byte-aligned blank SCSI disk image (1..16384 MiB) ready for FEP Initialize Disk.
ivory-fep-convert --create-fepfs <out.raw> --size-mb <N>
(fep_tools_create_fepfs)
Formats a ready-to-mount Little-Endian XL1200 FEPFS volume with 64 redundant LABL pages, FEPF/FEPD root directory headers, allocation bitmap, and Genera Universal Time (1900-01-01 epoch) timestamps.
ivory-fep-convert --create-tape <out.tap>
(fep_tools_create_tape)
Creates an empty SIMH .tap image terminated with an EOM (0xFFFFFFFF) marker.
ivory-fep-convert --info <path>
(fep_tools_probe / fep_tools_list_macivory_volumes)
Auto-detects FEP_IMG_XL1200_FEPFS, FEP_IMG_MISTER_VHD (1,536B padded stride), FEP_IMG_MACIVORY_FEPFS, FEP_IMG_MACIVORY_APM, FEP_IMG_MACIVORY_HFS, FEP_IMG_SIMH_TAP, or FEP_IMG_BLANK_1280B, printing APM/HFS hidden MacIvory volume inventories or FEPFS geometry and directory entries.
ivory-fep-convert --inject / --extract
(fep_tools_inject_file / fep_tools_extract_file)
Offline FEPFS file injection (allocating FEPB extents, writing FEPF headers, updating FEPD directory blocks) and extraction (e.g., for custom .flod overlays).
Related Chip Datasheets (11)All Component Datasheets →