anotherlin/z80emu

halted state is not kept between emulation calls

vampirefrog opened this issue · 7 comments

Hello. If you run the cpu for N cycles, a HALT instruction occurs, then you run it for more cycles, the next run it will not recall that it is halted. This would not matter if you're interrupting it between two emulation calls, but if you're not, it needs to remember that it is halted. I fixed it by adding a halted flag in the state struct and that flag is set to 0 when the interrupt function is called. You might have a cleaner way of implementing it, so I won't submit a patch.

efa commented

please supply a link to your implementation so we can understand better
thank you

efa commented

404
The page you are trying to reach does not exist or you are not authorized to view it.

Gitea version: 1.18.0

You're right, I'm sorry, I've made the repo public, please try again.

efa commented

thank you.
To me your fix seems right.

Maybe in:
Z80NonMaskableInterrupt ()
you should reset
state->halted = 0;
too?

You might be right, but for my project it works fine as it is now, and you know better than me.

efa commented

at the end I preferred to use the status field of Z80_STATE setting and checking Z80_STATUS_FLAG_HALT from first enum in z80emu.h
This has the advantage of NMI HALT quit is already there, but mainly avoid increase the Z80_STATE size and so the snapshot file of my application remain the same format.
You can see my implementation at https://github.com/efa/Wilderland
Anyway thank you for discovering this