diff --git a/src/spider/runtime/Runtime.cpp b/src/spider/runtime/Runtime.cpp index 7188517..b8a85ef 100644 --- a/src/spider/runtime/Runtime.cpp +++ b/src/spider/runtime/Runtime.cpp @@ -1,5 +1,7 @@ #include "Runtime.hpp" +#include + namespace spider { // Constructors & Destructors // @@ -17,14 +19,17 @@ namespace spider { // Stepping/Running the Machine // void Runtime::step() { - // fetchInstr() decodes the opcode, addressing mode and type siz + // fetchInstr() decodes the opcode, + // addressing mode and type size cpu.fetchInstr(); - // execute() completes the fetch-decode-execute cycle by calling the correct instruction method based on the opcode. + // execute() completes the fetch-decode-execute + // cycle by calling the correct instruction + // method based on the opcode. cpu.execute(); } void Runtime::step(u64 n) { - while(n >= 4) { + while (n >= 4) { step(); step(); step(); @@ -34,9 +39,34 @@ namespace spider { while (n--) step(); } - void Runtime::run() {} + u64 Runtime::run() { + // TODO: Must use the flag register + // for the enabled bit. + return 0; + } - //void Runtime::run(u64 n) {} + u64 Runtime::run(u64 n) { + using namespace std::chrono; + u64 total_steps = 0; + auto start_time = high_resolution_clock::now(); + + // TODO: Must use the flag register + // for the enabled bit. + while (true) { + step(); + step(); + step(); + step(); + total_steps += 4; + + // measure time! + auto current_time = high_resolution_clock::now(); + auto elapsed = duration_cast(current_time - start_time).count(); + if (static_cast(elapsed) >= n) break; + } + + return total_steps; + } // Misc // @@ -50,7 +80,7 @@ namespace spider { void Runtime::hookReel(InstrReel* newReel, bool own) { delete this->reel; cpu.hookInstrReel(newReel); - if(own) this->reel = newReel; + if (own) this->reel = newReel; } } diff --git a/src/spider/runtime/Runtime.hpp b/src/spider/runtime/Runtime.hpp index 905041b..b91209a 100644 --- a/src/spider/runtime/Runtime.hpp +++ b/src/spider/runtime/Runtime.hpp @@ -55,14 +55,18 @@ namespace spider { * Sets the machine to run continously. * If interrupts occur, they will be handled * automatically. + * + * Returns the amount of cycles ran. */ - void run(); + u64 run(); /** * Runs this machine for a set amount of * milliseconds. + * + * Returns the amount of cycles ran. */ - void run(u64 ms); + u64 run(u64 ms); public: