I'm hoping someone can give me a steer on implementing the HALT bug?
I have had a few attempts in my emulator at implementing this but based on the results of a halt_bug.gb test rom I found at https://github.com/retrio/gb-test-roms
I cannot get it passing.
The closest I have got has the results reversed from those that appear to be expected in the test rom when I run it with BGB, I don't understand why I would have them the other way round and believe I must be missing a condition that triggers the bug.
I have the simplest implementation based on the IME flag, is this all that should trigger the bug or is it also based on interrupts being enabled in IE?
My current attempt just has a haltBug flag that is set to !IME when HALT is called, and in my step proc if haltBug is set then it reads and executes the opcode without incrementing PC.
The test output also raised another question, when reading the value of IE/IF are the unused bits returned as 1 or 0? The test in BGB appears to suggest that they return as 1 where as I have been storing IF ANDed with 0x1F and returning that so zero in the upper 3 bits. Should I be ORing with 0xE0 before reading?