#18180 - bomberman - Mon Mar 22, 2004 10:22 am
Hello,
after solving my problems with graphic modes switch during a HBlank (see end of topic http://forum.gbadev.org/viewtopic.php?t=1303&start=0), I noticed a strange thing happening.
During splash screen and options menu screen, I do not need the interrupt to be triggered, so I disable this specific interruption, and only when I enter in my game loop, I enable it. And once out of ten approximately, just when I do this, my game resets on VBA and freezes on hardware. It seems I have "fixed" it by first waiting the beginning of the VBlank to enable/disable the HBlank interrupt. At least, I can not reproduce it any more... Is it "forbidden" to do it at any time ? Is there a reason to wait the VBlank interval ? I do not like bugs supposedly fixed because they don't happen any more :O)
Thanks !
#18200 - DekuTree64 - Mon Mar 22, 2004 4:37 pm
Are you only disabling it in IE, and not DISPSTAT? I haven't confirmed this personally, but I've heard that will sort of queue interrupts and trigger them as soon as you enable them again in IE. I don't know how that could cause a reset though, unless you haven't set the HBL function pointer yet, and just branch into nowhere when it's triggered.
But actually that doesn't make sense of why it would work properly during VBL, so I'm nt sure what the problem is.
If you're not disabling it in DISPSTAT already, do so and see what happens.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku
#18204 - bomberman - Mon Mar 22, 2004 4:58 pm
I always enable/disable the pair IE/DISPSTAT.
Having spoken with a pro, he told me that when modifying IE, IME should first be disabled. Then you should modify your IE (and other registers like DISPSTAT) and then reactivate your IME. Waiting to come back home tonight to test this without my VBlank wait.
In these conditions, it does not explain why it worked during VBL, you're right. On the other hand, I only could not reproduce it during VBL, it does not guarantee it worked fully. Tried it 50 consecutives times and did not crash, whereas before it would have crashed a few times.
Last thing, the reset was observed only in the emulator. The hardware just froze and I had to switch off and on.
Well, will let you know tomorrow the results of my tries tonight !
Thanks !
#18207 - poslundc - Mon Mar 22, 2004 5:05 pm
I don't think it matters if you enable DISPSTAT before IE or not, but you should disable DISPSTAT before IE in order to avoid queueing up an old interrupt that will launch immediately when next you enable IE.
Other than that, there could be plenty of potential mishaps occurring in code... interrupts are easy to get working, but tricky things to manage, unfortunately.
Dan.
#18217 - Miked0801 - Mon Mar 22, 2004 6:46 pm
Also a good idea to clear specific IF fields when playing with IE. Nothing like running 5 interrupts right on top of each other to cause unusual behavior.
#18242 - bomberman - Tue Mar 23, 2004 12:47 am
Well, here are the results of my experiments !
First of all, previously, the REG_IME was always on, and when activating HBlank interrupts, I was doing in this order:
1 - Modify IE
2 - Install the appropriate handler
3 - Modify DISPSTAT
So it would never jump in a non correctly setup function pointer. On the other hand, it's not only something which only happens on software (contrary to my previous problems), so we could suspect a software problem... Weird...
Anyway, after having listen to the advice I was given (disable REG_IME before any modifications of interrupts), it works fine, at any time. Not necessary to wait for the next VBlank. Or at least, I was not able to reproduce it...
So if you play with interrupts, try to remember this: DISABLE THE REG_IME :O)
#18245 - tepples - Tue Mar 23, 2004 1:06 am
If you get a problem on the emulator that doesn't show up on hardware (other than cycle inaccuracy or lack of serial support), then get a SourceForge.net account, make a minimal test case, and post it to the VisualBoyAdvance bug report site. Making the minimal test case will help you understand and explain the difference of behavior so that Forgotten, the maintainer of VBA, can better understand the behavior of the GBA hardware.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.