diff --git a/cpu.hpp b/cpu.hpp index 5c3a4ff..250fe5c 100644 --- a/cpu.hpp +++ b/cpu.hpp @@ -16,56 +16,55 @@ You should have received a copy of the GNU General Public License along with thi #include #include -namespace plutoisa { - using namespace std; +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 ) ); +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 ) { - cout << static_cast(rom[*pointer]) << endl; - cout << static_cast(*pointer) << endl; - switch ( rom[*pointer] ) { - case 0x00: // GET - registers[rom[*pointer + 1]] = rom[*pointer + 2]; - *pointer += 3; - break; - case 0x01: // LOAD - registers[rom[*pointer + 1]] = memory[rom[*pointer + 2]]; - *pointer += 3; - break; - case 0x02: // STORE - memory[rom[*pointer + 2]] = registers[rom[*pointer + 1]]; - *pointer += 3; - 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 +void cpuInstructions ( uint8_t *rom ) { + cout << static_cast ( rom[*pointer] ) << endl; + cout << static_cast ( *pointer ) << endl; + switch ( rom[*pointer] ) { + case 0x00: // GET + registers[rom[*pointer + 1]] = rom[*pointer + 2]; + *pointer += 3; + break; + case 0x01: // LOAD + registers[rom[*pointer + 1]] = memory[rom[*pointer + 2]]; + *pointer += 3; + break; + case 0x02: // STORE + memory[rom[*pointer + 2]] = registers[rom[*pointer + 1]]; + *pointer += 3; + 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; - 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 ); + } +} + diff --git a/main.cpp b/main.cpp index 6b52ab4..6170dcb 100644 --- a/main.cpp +++ b/main.cpp @@ -11,11 +11,11 @@ You should have received a copy of the GNU General Public License along with thi #include "cpu.hpp" -using namespace plutoisa; +using namespace std; int main ( int argc, char *argv[] ) { const char *filename = argv[1]; - const int rom_size = 16; + const int rom_size = 256; ifstream file ( filename, ios::binary );