kosarev / z80

Fast and flexible Z80/i8080 emulator with C++ and Python APIs
MIT License
63 stars 10 forks source link

Request CPU reset function #26

Closed simonowen closed 3 years ago

simonowen commented 3 years ago

Many use cases are likely to want to perform a soft reset of the CPU core. Should there be a reset function to do the appropriate register/state initialisation?

I've been debugging a strange issue that caused the first reset to fail but a second one to succeed. I tracked it down to the CPU being halted (using di;halt) at the point of the reset. This was fixed by manually clearing the halted state in my own reset code.

I'm now using:

        cpu.set_is_halted(false);
        cpu.set_iff1(false);
        cpu.set_pc(0);
        cpu.set_ir(0);

Do you think that's enough to cover a reset, and could it be something I could call instead?

kosarev commented 3 years ago
        cpu.set_is_halted(false);
        cpu.set_iff1(false);
        cpu.set_pc(0);
        cpu.set_ir(0);

I think this misses resetting the decoder, so might run the first instruction as if it was DD/FD-prefixed. #29 hopefully nails it.

kosarev commented 3 years ago

@simonowen Are we done with this?

simonowen commented 3 years ago

Yes, I'm using it and it's working well -- thanks!