This commit is contained in:
2026-07-02 15:32:34 -04:00
commit 693216fb46
8 changed files with 266 additions and 0 deletions

45
.gitignore vendored Normal file
View File

@@ -0,0 +1,45 @@
# --- Build directories ---
build/
out/
# --- vcpkg installed artifacts (restored from vcpkg.json on configure) ---
vcpkg_installed/
build/vcpkg_installed/
# --- CMake generated / cache files ---
CMakeCache.txt
CMakeFiles/
cmake_install.cmake
compile_commands.json
*.cmake
!CMakeLists.txt
!CMakePresets.json
!CMakeUserPresets.json
# --- Ninja ---
build.ninja
.ninja_deps
.ninja_log
# --- vcpkg logs ---
vcpkg-manifest-install.log
# --- Compiled objects & executables ---
*.obj
*.o
*.a
*.lib
*.exe
*.pdb
*.ilk
*.exp
# --- IDE / editor ---
.vs/
.vscode/
*.user
# --- OS junk ---
Thumbs.db
desktop.ini
.DS_Store

40
CMakeLists.txt Normal file
View File

@@ -0,0 +1,40 @@
cmake_minimum_required(VERSION 3.16)
project(emulator LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()
option(EMULATOR_BUILD_TESTS "Build unit tests" OFF)
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
add_executable(emulator
src/main.cpp
src/emulator.cpp
)
target_include_directories(emulator PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)
target_link_libraries(emulator PRIVATE
SDL2::SDL2
SDL2_image::SDL2_image
)
if(MSVC)
target_compile_options(emulator PRIVATE /W4 /permissive-)
else()
target_compile_options(emulator PRIVATE -Wall -Wextra -Wpedantic)
endif()
if(EMULATOR_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()

37
CMakePresets.json Normal file
View File

@@ -0,0 +1,37 @@
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 21,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"displayName": "Default (vcpkg + MSVC)",
"description": "Configure with vcpkg manifest mode and generate compile_commands.json for IntelliSense",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": {
"type": "BOOL",
"value": "ON"
},
"CMAKE_TOOLCHAIN_FILE": {
"type": "FILEPATH",
"value": "C:/Program Files (x86)/Microsoft Visual Studio/18/BuildTools/VC/vcpkg/scripts/buildsystems/vcpkg.cmake"
},
"VCPKG_TARGET_TRIPLET": {
"type": "STRING",
"value": "x64-windows"
}
},
"generator": "Ninja"
}
],
"buildPresets": [
{
"name": "default",
"configurePreset": "default"
}
]
}

93
README.md Normal file
View File

@@ -0,0 +1,93 @@
# 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
1. **Clone the repository**
```sh
git clone <repo-url> emulator
cd emulator
```
2. **Ensure vcpkg is installed**
If you do not already have vcpkg, clone and bootstrap it:
```sh
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat
```
Note its root path — you will reference it in the next step.
3. **Point CMake at the vcpkg toolchain**
`CMakePresets.json` sets `CMAKE_TOOLCHAIN_FILE` to:
```
C:/Program Files (x86)/Microsoft Visual Studio/18/BuildTools/VC/vcpkg/scripts/buildsystems/vcpkg.cmake
```
If your vcpkg lives elsewhere, edit the `default` configure preset
(or create a `CMakeUserPresets.json` next to `CMakePresets.json`) so the
`CMAKE_TOOLCHAIN_FILE` value 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):
```sh
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:
```sh
.\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.

13
src/emulator.cpp Normal file
View File

@@ -0,0 +1,13 @@
#include "emulator.hpp"
namespace emu {
Emulator::Emulator(std::string rom_path)
: rom_path_(std::move(rom_path)) {}
int Emulator::run() {
// TODO: load ROM from rom_path_ and run the emulator loop
return 0;
}
} // namespace emu

16
src/emulator.hpp Normal file
View File

@@ -0,0 +1,16 @@
#pragma once
#include <string>
namespace emu {
class Emulator {
public:
explicit Emulator(std::string rom_path);
int run();
private:
std::string rom_path_;
};
} // namespace emu

13
src/main.cpp Normal file
View File

@@ -0,0 +1,13 @@
#include <iostream>
#include "emulator.hpp"
int main(int argc, char** argv) {
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " <rom-file>\n";
return 1;
}
emu::Emulator emulator(argv[1]);
return emulator.run();
}

9
vcpkg.json Normal file
View File

@@ -0,0 +1,9 @@
{
"name": "emulator",
"version-string": "0.1.0",
"dependencies": [
"sdl2",
"sdl2-image"
],
"builtin-baseline": "544a4c5c297e60e4ac4a5a1810df66748d908869"
}