Page 1 of 1

Author:  DParrott [ Thu Jul 28, 2016 6:12 am ]
Post subject:  HALT Bug

Hi all,

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 test rom I found at 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?


Author:  DParrott [ Mon Aug 01, 2016 7:37 am ]
Post subject:  Re: HALT Bug

Forgive the self post but I thought I'd follow up.

I wonder is this another of those GameBoy issues where a few people have worked it out but it's not documented anywhere?

I have consulted some other emulators and the behaviour seems to be that if interrupts are disabled and there is a pending interrupt when the HALT instruction executes then the bug is triggered. From what I could find the docs only mention interrupts being disabled.

Implementing the above behaviour passes the and still passes the individual instructions tests from Blargg.

Hopefully this helps if others are trying to implement the same issue.


Author:  binji [ Thu Aug 04, 2016 9:22 pm ]
Post subject:  Re: HALT Bug

The correct behavior is actually documented in AntonioND's cycle accurate gameboy docs. It's funny, I didn't even notice that there was a test for this (strangely without source). Tried it on my emulator, and I realized I had it implemented completely wrong... but now it's fixed! Thanks for mentioning this :)

Author:  DParrott [ Fri Aug 05, 2016 12:47 am ]
Post subject:  Re: HALT Bug

Oooh, new documentation.

Thanks for pointing that out, a quick look shows I have come across it before but forgot about it. Excellent resource.

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group