Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)
You are not logged in.
Howdy fellas ! I've got a programming issue. Now, before striking the WRONG BOARD hammer, please read the rest. Thank you
Basically, the LCD interrupt is requested when it shouldn't every time I write to STAT. Below is a more precise description of the context in which it happens.
All of the following description has been done using BGB 1.5.3, but the behavior is the same on console.
This happens on a game flagged as GBC-only, and in DMG / SGB mode.
Here's my situation : right after my game's init, I have only the VBlank and LCD bits set in IE, and bits 3-6 of STAT are reset. IME is reset, and only the VBlank bit is set in IF.
So far, so good.
Then, IME is set, but the VBlank handler discards itself because it's not starting on scanline $90 (it's a failsafe).
On the next VBlank, though, the handler runs its full code, which includes setting bit 5 of STAT (this is used for music operations).
First thing I'm confused about is, the bit is set during scanline $93, yet IF bit 1 (LCD interrupt request) gets set immediately. We're still in Mode 1, so why ?
If I continue to trace execution, right as the VBlank handler exits, execution jumps to the STAT interrupt vector. However, the procedure runs a "res 5, [hl]" while hl = $FF41 to clear the Mode 2 interrupt flag. The flag is reset, but for some reason, this also sets the LCD bit in IF !
So the cycle repeats, with the LCD bit getting set each time precisely at the "res 5, [hl]".
[EDIT]
I tried replacing ith "ld a, [hl] / res 5, [hl] / ld [hl], a", I tried replacing the [hl] with [$FF41], I tried using ldh instead, but the bit in IF always gets set right after writing back to $FF41.
So now, why is this in the hardware board ? Because this behavior does NOT occur on the GBC. Someone suggested me it could be a hardware difference between DMG and GBC (I guess it would make sense, the LCD differs between these consoles), so I'm asking to the hardware pros : do you know why this occurs ?
If you are interested, I can attach the ROM of my game where this occurs. Just let me know.
Big thanks to anyone who will answer, this is really puzzling me.
Last edited by ISSOtm (2017-05-08 04:51:07)
Offline
You're probably hitting the STAT bug: http://www.devrs.com/gb/files/faqs.html#GBBugs
Offline
Thanks ! I confirm I am hitting that bug, which I worked around by removing the STAT handler in GB mode.
That info isn't present in the wiki, I'll add it.
Last edited by ISSOtm (2017-05-08 16:04:22)
Offline
That's true, it's not in the wiki, and it took me quite a long time to find a web in which it was described. And well, the description is really crappy, but that's because the bug is quite weird (I did some research about it some time ago and gave up).
Offline
Well, I can't add it to the wiki because my session timed out, and my password is said to be incorrect.
Said password works on the forums.
Offline
I am confused why when I asked for help I don't get a answer at all. While if another person does they get it fast
Offline
Because I have been polite, asked for something reasonable, and did not harass anyone.S
Offline
I don't harass and I am polite. I asked for reasonable stuff like needing help on things relating to the game-boy. I get it that I am not entitled to getting a reply but still kinda cruel.
BTW that new avatar is me but compressed because the max was 130x130
Last edited by npzman (2018-01-29 09:55:46)
Offline