Gekkio/mooneye-gb

In ie_push.s, cannot trigger "R3: unwanted cancel" failure ?

gurushida opened this issue · 2 comments

When I tried this test with my emulator, instead of failing or passing, the emulator just stopped after a while. As I was investigating why, it occurred to me that my implementation should have triggered the "R3: unwanted cancel" failure but that it didn't for some reason.

My understanding of the scenario that should lead to this failure is as follows:

  • from address PC=0x0235 with SP=0x0001, we trigger INTR_SERIAL with "ldh (<IF), a"
  • while processing this interrupt, if it is cancelled, PC is set to 0
  • because at the end of ie_push.s we have ".org $0000" followed by "jp hl", when executing the instruction at PC=0, we should jump to the address contained in HL

However, because we trigger the interrupt with SP=1, pushing PC as part of processing the interrupt not only puts 0x35 into IE but it also puts 0x02 at the address 0 which replaces the 0xE9 opcode of the jump instruction that should trigger the failure path.

Is my interpretation correct or did I miss something ?

It's been a while since I wrote that test, so unfortunately I can't remember exactly what is tested by that test ROM.

However, I can tell that your interpretation doesn't seem correct because ROM is not writable:

puts 0x02 at the address 0 which replaces the 0xE9 opcode of the jump instruction

Writing 0x02 to 0x0000 has no effect (other than a real/emulated MBC possibly disabling RAM access, which doesn't matter in this test), so the jump instruction won't be affected.

Ah, I completely forgot that this part of the addressable space was read-only. Thanks a lot !