main.cpp - Add try-catch for CpuException

This commit is contained in:
madmaurice 2023-09-01 23:44:06 +02:00
parent 243553acba
commit c38f0de994

View file

@ -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;
}
}