This repository has been archived on 2024-08-24. You can view files and clone it, but cannot push or open issues or pull requests.
PlutoISA/cpu.hpp
2024-08-22 14:55:49 +02:00

42 lines
No EOL
1 KiB
C++

#include <iostream>
#include <cstdint>
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<int>(registers[0]) << endl;
cpuInstructions(rom);
}
}
}