Minor changes: 1.0.1

This commit is contained in:
patrick_pluto 2024-08-22 19:29:21 +02:00
parent d83aef84a7
commit d77733d29f
2 changed files with 48 additions and 49 deletions

93
cpu.hpp
View file

@ -16,56 +16,55 @@ You should have received a copy of the GNU General Public License along with thi
#include <cstdlib> #include <cstdlib>
#include <cstdint> #include <cstdint>
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; cout << static_cast<int> ( rom[*pointer] ) << endl;
cout << static_cast<int>(*pointer) << endl; cout << static_cast<int> ( *pointer ) << endl;
switch ( rom[*pointer] ) { switch ( rom[*pointer] ) {
case 0x00: // GET case 0x00: // GET
registers[rom[*pointer + 1]] = rom[*pointer + 2]; registers[rom[*pointer + 1]] = rom[*pointer + 2];
*pointer += 3; *pointer += 3;
break; break;
case 0x01: // LOAD 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 0x02: // STORE 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 case 0x03: // ADD
registers[rom[*pointer + 1]] = registers[rom[*pointer + 2]] + registers[rom[*pointer + 3]]; registers[rom[*pointer + 1]] = registers[rom[*pointer + 2]] + registers[rom[*pointer + 3]];
*pointer += 4; *pointer += 4;
break; break;
case 0x04: // SUB case 0x04: // SUB
registers[rom[*pointer + 1]] = registers[rom[*pointer + 2]] - registers[rom[*pointer + 3]]; registers[rom[*pointer + 1]] = registers[rom[*pointer + 2]] - registers[rom[*pointer + 3]];
*pointer += 4; *pointer += 4;
break; break;
case 0x05: // JMP case 0x05: // JMP
*pointer = rom[*pointer + 1];
break;
case 0x06: // JEQ
if ( rom[*pointer + 2] == registers[rom[*pointer + 3]] ) {
*pointer = rom[*pointer + 1]; *pointer = rom[*pointer + 1];
break;
case 0x06: // JEQ
if ( rom[*pointer + 2] == registers[rom[*pointer + 3]] ) {
*pointer = rom[*pointer + 1];
}
break;
default:
cout << "Invalid Instruction, quitting." << endl;
exit ( 1 );
}
}
void cpuEmulation ( uint8_t *rom ) {
*pointer = 0;
while ( true ) {
cpuInstructions ( rom );
} }
break;
default:
cout << "Invalid Instruction, quitting." << endl;
exit ( 1 );
} }
} }
void cpuEmulation ( uint8_t *rom ) {
*pointer = 0;
while ( true ) {
cpuInstructions ( rom );
}
}

View file

@ -11,11 +11,11 @@ You should have received a copy of the GNU General Public License along with thi
#include "cpu.hpp" #include "cpu.hpp"
using namespace plutoisa; using namespace std;
int main ( int argc, char *argv[] ) { int main ( int argc, char *argv[] ) {
const char *filename = argv[1]; const char *filename = argv[1];
const int rom_size = 16; const int rom_size = 256;
ifstream file ( filename, ios::binary ); ifstream file ( filename, ios::binary );