42 lines
1 KiB
C++
42 lines
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);
|
||
|
}
|
||
|
}
|
||
|
}
|