From 3109cc0e75e66137e79a4b3ecc44a53fb0fab9ff Mon Sep 17 00:00:00 2001 From: Patrick_Pluto Date: Thu, 22 Aug 2024 14:55:49 +0200 Subject: [PATCH] Adding previous work. --- .gitignore | 2 ++ cpu.hpp | 42 ++++++++++++++++++++++++++++++++++++++++++ main.cpp | 13 +++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 .gitignore create mode 100644 cpu.hpp create mode 100644 main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..662f6d5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vscode/ +bin/ diff --git a/cpu.hpp b/cpu.hpp new file mode 100644 index 0000000..9508c24 --- /dev/null +++ b/cpu.hpp @@ -0,0 +1,42 @@ +#include +#include + +namespace plutoisa +{ + using namespace std; + + uint8_t *registers = (uint8_t *)malloc(8 * sizeof(uint8_t)); + uint8_t *memory = (uint8_t *)malloc(128 * sizeof(uint8_t)); + uint8_t *pointer = (uint8_t *)malloc(sizeof(uint8_t)); + + void cpuInstructions(uint8_t *rom) + { + switch (rom[*pointer]) + { + case 0x00: // LOAD R0 M0 + registers[rom[*pointer + 1]] = memory[rom[*pointer + 2]]; + *pointer += 3; + break; + case 0x01: // STORE R0 M0 + memory[rom[*pointer + 2]] = registers[rom[*pointer + 1]]; + *pointer += 3; + break; + default: + cout << "Invalid Instruction, expect broken behavior" << endl; + exit(1); + } + } + + void cpuEmulation(uint8_t *rom) + { + *pointer = 0; + + memory[0] = 0x12; + + while (true) + { + cout << static_cast(registers[0]) << endl; + cpuInstructions(rom); + } + } +} \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..f93369e --- /dev/null +++ b/main.cpp @@ -0,0 +1,13 @@ +#include "cpu.hpp" + +using namespace plutoisa; + +int main() +{ + uint8_t *rom = (uint8_t *)malloc(16 * sizeof(uint8_t)); + rom[0] = 0x00; + rom[1] = 0x00; + rom[2] = 0x00; + rom[3] = 0xFF; + cpuEmulation(rom); +} \ No newline at end of file