diff --git a/main.cpp b/main.cpp index 45625a2..860efb8 100644 --- a/main.cpp +++ b/main.cpp @@ -64,30 +64,36 @@ int main(int argc, char** argv) cpu.state.SP = 0xFFFE; cpu.state.PC = 0x100; - const std::chrono::milliseconds delay(1); + const std::chrono::milliseconds delay(10); - while(!cpu.state.stopped) - { - std::cout - << "A:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.A - << " F:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.getF() - << " B:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.B - << " C:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.C - << " D:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.D - << " E:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.E - << " H:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.H - << " L:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.L - << " SP:" << std::setfill('0') << std::setw(4) << std::hex << std::uppercase << (unsigned)cpu.state.SP - << " PC:" << std::setfill('0') << std::setw(4) << std::hex << std::uppercase << (unsigned)cpu.state.PC - << " PCMEM:" - << std::setw(2) << std::hex << std::uppercase << (unsigned)b.read8(cpu.state.PC) << "," - << std::setw(2) << std::hex << std::uppercase << (unsigned)b.read8(cpu.state.PC+1) << "," - << std::setw(2) << std::hex << std::uppercase << (unsigned)b.read8(cpu.state.PC+2) << "," - << std::setw(2) << std::hex << std::uppercase << (unsigned)b.read8(cpu.state.PC+3) << std::endl; + try { + while(!cpu.state.stopped) + { + std::cout + << "A:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.A + << " F:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.getF() + << " B:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.B + << " C:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.C + << " D:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.D + << " E:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.E + << " H:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.H + << " L:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.L + << " SP:" << std::setfill('0') << std::setw(4) << std::hex << std::uppercase << (unsigned)cpu.state.SP + << " PC:" << std::setfill('0') << std::setw(4) << std::hex << std::uppercase << (unsigned)cpu.state.PC + << " PCMEM:" + << std::setw(2) << std::hex << std::uppercase << (unsigned)b.read8(cpu.state.PC) << "," + << std::setw(2) << std::hex << std::uppercase << (unsigned)b.read8(cpu.state.PC+1) << "," + << std::setw(2) << std::hex << std::uppercase << (unsigned)b.read8(cpu.state.PC+2) << "," + << std::setw(2) << std::hex << std::uppercase << (unsigned)b.read8(cpu.state.PC+3) << std::endl; - cpu.step(); + cpu.step(); - std::this_thread::sleep_for(delay); - } + + if(cpu.state.halted) + std::this_thread::sleep_for(delay); + } + } catch(CpuException& e) { + std::cerr << e.what() << std::endl; + } }