1.0.0
This commit is contained in:
parent
3109cc0e75
commit
d83aef84a7
5 changed files with 91 additions and 31 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,4 @@
|
||||||
.vscode/
|
.vscode/
|
||||||
bin/
|
bin/
|
||||||
|
*.kdev4
|
||||||
|
.kdev4/
|
||||||
|
|
14
Makefile
Normal file
14
Makefile
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
# Compiler
|
||||||
|
CXX = g++
|
||||||
|
# Source file
|
||||||
|
SRC = main.cpp
|
||||||
|
# Executable name
|
||||||
|
EXEC = pluto_isa_emu
|
||||||
|
|
||||||
|
# Default target
|
||||||
|
all:
|
||||||
|
mkdir -p bin/
|
||||||
|
$(CXX) $(SRC) -o bin/$(EXEC)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm bin/$(EXEC)
|
|
@ -1,2 +1,3 @@
|
||||||
# PlutoISA
|
# PlutoISA
|
||||||
|
|
||||||
|
This is an emulator for the custom made PlutoISA.
|
||||||
|
|
61
cpu.hpp
61
cpu.hpp
|
@ -1,41 +1,70 @@
|
||||||
|
/*
|
||||||
|
PlutoISA
|
||||||
|
Copyright (C) 2024 Patrick_Pluto
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <cstdlib>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace plutoisa
|
namespace plutoisa {
|
||||||
{
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
uint8_t *registers = ( uint8_t * ) malloc ( 8 * sizeof ( uint8_t ) );
|
uint8_t *registers = ( uint8_t * ) malloc ( 8 * sizeof ( uint8_t ) );
|
||||||
uint8_t *memory = ( uint8_t * ) malloc ( 128 * sizeof ( uint8_t ) );
|
uint8_t *memory = ( uint8_t * ) malloc ( 128 * sizeof ( uint8_t ) );
|
||||||
uint8_t *pointer = ( uint8_t * ) malloc ( sizeof ( uint8_t ) );
|
uint8_t *pointer = ( uint8_t * ) malloc ( sizeof ( uint8_t ) );
|
||||||
|
|
||||||
void cpuInstructions(uint8_t *rom)
|
void cpuInstructions ( uint8_t *rom ) {
|
||||||
{
|
cout << static_cast<int>(rom[*pointer]) << endl;
|
||||||
switch (rom[*pointer])
|
cout << static_cast<int>(*pointer) << endl;
|
||||||
{
|
switch ( rom[*pointer] ) {
|
||||||
case 0x00: // LOAD R0 M0
|
case 0x00: // GET
|
||||||
|
registers[rom[*pointer + 1]] = rom[*pointer + 2];
|
||||||
|
*pointer += 3;
|
||||||
|
break;
|
||||||
|
case 0x01: // LOAD
|
||||||
registers[rom[*pointer + 1]] = memory[rom[*pointer + 2]];
|
registers[rom[*pointer + 1]] = memory[rom[*pointer + 2]];
|
||||||
*pointer += 3;
|
*pointer += 3;
|
||||||
break;
|
break;
|
||||||
case 0x01: // STORE R0 M0
|
case 0x02: // STORE
|
||||||
memory[rom[*pointer + 2]] = registers[rom[*pointer + 1]];
|
memory[rom[*pointer + 2]] = registers[rom[*pointer + 1]];
|
||||||
*pointer += 3;
|
*pointer += 3;
|
||||||
break;
|
break;
|
||||||
|
case 0x03: // ADD
|
||||||
|
registers[rom[*pointer + 1]] = registers[rom[*pointer + 2]] + registers[rom[*pointer + 3]];
|
||||||
|
*pointer += 4;
|
||||||
|
break;
|
||||||
|
case 0x04: // SUB
|
||||||
|
registers[rom[*pointer + 1]] = registers[rom[*pointer + 2]] - registers[rom[*pointer + 3]];
|
||||||
|
*pointer += 4;
|
||||||
|
break;
|
||||||
|
case 0x05: // JMP
|
||||||
|
*pointer = rom[*pointer + 1];
|
||||||
|
break;
|
||||||
|
case 0x06: // JEQ
|
||||||
|
if ( rom[*pointer + 2] == registers[rom[*pointer + 3]] ) {
|
||||||
|
*pointer = rom[*pointer + 1];
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
cout << "Invalid Instruction, expect broken behavior" << endl;
|
cout << "Invalid Instruction, quitting." << endl;
|
||||||
exit ( 1 );
|
exit ( 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cpuEmulation(uint8_t *rom)
|
void cpuEmulation ( uint8_t *rom ) {
|
||||||
{
|
|
||||||
*pointer = 0;
|
*pointer = 0;
|
||||||
|
|
||||||
memory[0] = 0x12;
|
while ( true ) {
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
cout << static_cast<int>(registers[0]) << endl;
|
|
||||||
cpuInstructions ( rom );
|
cpuInstructions ( rom );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
28
main.cpp
28
main.cpp
|
@ -1,13 +1,27 @@
|
||||||
|
/*
|
||||||
|
PlutoISA
|
||||||
|
Copyright (C) 2024 Patrick_Pluto
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "cpu.hpp"
|
#include "cpu.hpp"
|
||||||
|
|
||||||
using namespace plutoisa;
|
using namespace plutoisa;
|
||||||
|
|
||||||
int main()
|
int main ( int argc, char *argv[] ) {
|
||||||
{
|
const char *filename = argv[1];
|
||||||
uint8_t *rom = (uint8_t *)malloc(16 * sizeof(uint8_t));
|
const int rom_size = 16;
|
||||||
rom[0] = 0x00;
|
|
||||||
rom[1] = 0x00;
|
ifstream file ( filename, ios::binary );
|
||||||
rom[2] = 0x00;
|
|
||||||
rom[3] = 0xFF;
|
uint8_t *rom = ( uint8_t * ) malloc ( rom_size * sizeof ( uint8_t ) );
|
||||||
|
|
||||||
|
file.read ( reinterpret_cast<char*> ( rom ), rom_size );
|
||||||
|
|
||||||
cpuEmulation ( rom );
|
cpuEmulation ( rom );
|
||||||
}
|
}
|
Reference in a new issue