2.8 KiB
emulator
A simple emulator built in C++17 using SDL2 for video/audio. It loads a ROM file from disk, maps it into memory, and runs a fetch/decode/execute loop rendered to an SDL window.
Prerequisites
- C++17 compiler — MSVC (Visual Studio 2019 or 2022 Build Tools) on Windows. The project is currently configured for the MSVC toolchain.
- CMake 3.21 or newer (required for the CMake Presets feature).
- Ninja — used as the build generator.
- vcpkg — dependencies are declared in
vcpkg.json(manifest mode), so vcpkg fetches them automatically on first configure. A working vcpkg installation must be available on the system. - Git — for cloning and for vcpkg to fetch package sources.
Project layout
.
├── CMakeLists.txt # build definition
├── CMakePresets.json # configure/build presets (vcpkg + MSVC + Ninja)
├── vcpkg.json # dependency manifest (sdl2, sdl2-image)
├── .vscode/ # editor / IntelliSense config
├── src/
│ ├── main.cpp # entry point: parses argv, runs the emulator
│ ├── emulator.hpp # Emulator class declaration
│ └── emulator.cpp # Emulator class implementation
└── build/ # generated after configure (gitignored)
Installation
-
Clone the repository
git clone <repo-url> emulator cd emulator -
Ensure vcpkg is installed
If you do not already have vcpkg, clone and bootstrap it:
git clone https://github.com/microsoft/vcpkg.git cd vcpkg .\bootstrap-vcpkg.batNote its root path — you will reference it in the next step.
-
Point CMake at the vcpkg toolchain
CMakePresets.jsonsetsCMAKE_TOOLCHAIN_FILEto:C:/Program Files (x86)/Microsoft Visual Studio/18/BuildTools/VC/vcpkg/scripts/buildsystems/vcpkg.cmakeIf your vcpkg lives elsewhere, edit the
defaultconfigure preset (or create aCMakeUserPresets.jsonnext toCMakePresets.json) so theCMAKE_TOOLCHAIN_FILEvalue matches your vcpkg install.
Setup & build
Configure and build with the bundled preset (uses vcpkg manifest mode, so
sdl2 and sdl2-image are installed automatically on first configure):
cmake --preset default
cmake --build --preset default
The resulting executable is placed in build/ (e.g. build/emulator.exe).
Running
Pass a ROM file as the only argument:
.\build\emulator.exe <rom-file>
Press Esc or close the window to quit.
Editor / IntelliSense
VS Code IntelliSense is configured in .vscode/c_cpp_properties.json to read
build/compile_commands.json (generated by the default preset). Configure
the project once with cmake --preset default so the compile database exists;
IntelliSense will then resolve SDL.h and the project headers correctly.