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.SP = 0xFFFE;
cpu.state.PC = 0x100; cpu.state.PC = 0x100;
const std::chrono::milliseconds delay(1); const std::chrono::milliseconds delay(10);
while(!cpu.state.stopped) try {
{ while(!cpu.state.stopped)
std::cout {
<< "A:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.A std::cout
<< " F:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.getF() << "A:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.A
<< " B:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.B << " F:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.getF()
<< " C:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.C << " B:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.B
<< " D:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.D << " C:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.C
<< " E:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.E << " D:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.D
<< " H:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.H << " E:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.E
<< " L:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.L << " H:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.H
<< " SP:" << std::setfill('0') << std::setw(4) << std::hex << std::uppercase << (unsigned)cpu.state.SP << " L:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.L
<< " PC:" << std::setfill('0') << std::setw(4) << std::hex << std::uppercase << (unsigned)cpu.state.PC << " SP:" << std::setfill('0') << std::setw(4) << std::hex << std::uppercase << (unsigned)cpu.state.SP
<< " PCMEM:" << " PC:" << std::setfill('0') << std::setw(4) << std::hex << std::uppercase << (unsigned)cpu.state.PC
<< std::setw(2) << std::hex << std::uppercase << (unsigned)b.read8(cpu.state.PC) << "," << " PCMEM:"
<< 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) << ","
<< 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+1) << ","
<< std::setw(2) << std::hex << std::uppercase << (unsigned)b.read8(cpu.state.PC+3) << std::endl; << 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;
}
} }