It is currently Sun Nov 19, 2017 11:11 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: HALT Bug
PostPosted: Thu Jul 28, 2016 6:12 am 
Offline

Joined: Thu Jul 29, 2010 4:39 am
Posts: 24
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 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?

Thanks


Top
 Profile  
 
 Post subject: Re: HALT Bug
PostPosted: Mon Aug 01, 2016 7:37 am 
Offline

Joined: Thu Jul 29, 2010 4:39 am
Posts: 24
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 halt_bug.gb and still passes the individual instructions tests from Blargg.

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

Cheers


Top
 Profile  
 
 Post subject: Re: HALT Bug
PostPosted: Thu Aug 04, 2016 9:22 pm 
Offline

Joined: Thu Jun 16, 2016 11:53 am
Posts: 10
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 :)


Top
 Profile  
 
 Post subject: Re: HALT Bug
PostPosted: Fri Aug 05, 2016 12:47 am 
Offline

Joined: Thu Jul 29, 2010 4:39 am
Posts: 24
Oooh, new documentation.

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group