$ show sarah-walker-pcem/pcem
PCem is a vintage IBM PC/XT/AT/386/486/Pentium emulator that prioritizes hardware-level accuracy over performance. It emulates a vast range of CPUs (8088 through Pentium II, K6, Cyrix), chipsets (Intel 430/440 series, VIA, SiS, OPTi, etc.), video cards (CGA, EGA, VGA, SVGA, Voodoo 1-3, ATI Mach64, S3 Virge, and many more), sound cards (AdLib, Sound Blaster, Gravis Ultrasound, AWE32, OPL, reSID, etc.), storage controllers (IDE, SCSI, MFM, floppy), and networking (NE2000, SLiRP). The emulator uses a dynamic recompiler (codegen) with host backends for x86, x86-64, ARM, and ARM64 to achieve usable performance on modern hardware. It provides two parallel GUI frontends (wxWidgets and Qt), both using SDL2 for video and input, and supports a plugin system for extending emulated hardware. The codebase is written primarily in C with some C++ components, built with CMake and Clang, and targets Windows, Linux, and macOS.
The LLM identified 4 files worth highlighting for reuse:
A self-contained C library for reading, writing, and creating Virtual Hard Disk (VHD) images in fixed, sparse, and differencing formats. It handles big-endian serialization, CRC32 checksums, CHS geometry calculation, parent locator resolution, and platform-specific file I/O. The library exposes a clean API (mvhd_open, mvhd_create_*, mvhd_read/write_sectors) and can be extracted and reused in any project requiring VHD support without modification.
A reusable emulation core for the AY-3-8910 / YM2149 programmable sound generator. It provides configurable clock and sample rates, panning, envelope shapes, and includes a FIR decimation filter and DC removal filter. The implementation is self-contained in a single .c file with a header, and can be integrated into any emulator or audio project requiring this classic sound chip.
A port of DOSBox's CGA composite color emulation, providing accurate rendering of the NTSC artifact colors produced by IBM CGA cards in composite mode. It includes calibration tables for hue, saturation, and contrast, and is implemented as a standalone module that can be reused in other emulators or retro-computing projects needing CGA composite output.
The intermediate representation (IR) layer of PCem's dynamic recompiler. It defines a set of uop (micro-operation) handlers (MOV, ADD, AND, etc.) and provides functions for compiling x86 instruction sequences into IR blocks, performing register allocation, loop unrolling, and code block management. While tightly integrated with the emulator's CPU state, the IR design and compilation pipeline could be extracted as a reusable JIT framework for other emulators or language runtimes.