diff --git a/cpu.hpp b/cpu.hpp index 250fe5c..8e38c46 100644 --- a/cpu.hpp +++ b/cpu.hpp @@ -15,6 +15,9 @@ You should have received a copy of the GNU General Public License along with thi #include #include #include +#include +#include +#include "tpu.hpp" using namespace std; @@ -61,10 +64,22 @@ void cpuInstructions ( uint8_t *rom ) { } void cpuEmulation ( uint8_t *rom ) { + const int targetFPS = 20; + const int frameDuration = 1000 / targetFPS; *pointer = 0; while ( true ) { + auto start = chrono::high_resolution_clock::now(); + cpuInstructions ( rom ); + textProcessing ( registers[7] ); + + auto end = chrono::high_resolution_clock::now(); + chrono::duration elapsed = end - start; + + if ( elapsed.count() < frameDuration ) { + this_thread::sleep_for ( chrono::milliseconds ( frameDuration ) - elapsed ); + } } } diff --git a/tpu.hpp b/tpu.hpp new file mode 100644 index 0000000..d6d7f13 --- /dev/null +++ b/tpu.hpp @@ -0,0 +1,125 @@ +#pragma once + +#include +#include +#include + +using namespace std; + +void textProcessing ( uint8_t ch ) { + switch ( ch ) { + case 0x01: + cout << "0"; + break; + case 0x02: + cout << "1"; + break; + case 0x03: + cout << "2"; + break; + case 0x04: + cout << "3"; + break; + case 0x05: + cout << "4"; + break; + case 0x06: + cout << "5"; + break; + case 0x07: + cout << "6"; + break; + case 0x08: + cout << "7"; + break; + case 0x09: + cout << "8"; + break; + case 0x0A: + cout << "9"; + break; + case 0x0B: + cout << "A"; + break; + case 0x0C: + cout << "B"; + break; + case 0x0D: + cout << "C"; + break; + case 0x0E: + cout << "D"; + break; + case 0x0F: + cout << "E"; + break; + case 0x10: + cout << "F"; + break; + case 0x11: + cout << "G"; + break; + case 0x12: + cout << "H"; + break; + case 0x13: + cout << "I"; + break; + case 0x14: + cout << "J"; + break; + case 0x15: + cout << "K"; + break; + case 0x16: + cout << "L"; + break; + case 0x17: + cout << "M"; + break; + case 0x18: + cout << "N"; + break; + case 0x19: + cout << "O"; + break; + case 0x1A: + cout << "P"; + break; + case 0x1B: + cout << "Q"; + break; + case 0x1C: + cout << "R"; + break; + case 0x1D: + cout << "S"; + break; + case 0x1E: + cout << "T"; + break; + case 0x1F: + cout << "U"; + break; + case 0x20: + cout << "V"; + break; + case 0x21: + cout << "W"; + break; + case 0x22: + cout << "X"; + break; + case 0x23: + cout << "Y"; + break; + case 0x24: + cout << "Z"; + break; + case 0x25: + cout << endl; + break; + default: + break; + } +}