Gameboy Development Forum

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.

Ads

#1 2017-05-08 04:50:08

ISSOtm
Member
From: Somewhere in Echo RAM
Registered: 2017-04-18
Posts: 160
Website

Retriggering interrupts

Howdy fellas ! I've got a programming issue. Now, before striking the WRONG BOARD hammer, please read the rest. Thank you smile
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)


The French Lord Of Laziness.
Legend of Zelda and Undertale fan, I also tend to break Pokémon R/B/Y a little too much.

Twitter | Me on GCL | Discord : ISSOtm#9015 | Skype : isso.tm (I don't login anymore)

Offline

 

#2 2017-05-08 14:55:35

AntonioND
Member
Registered: 2014-06-17
Posts: 134
Website

Re: Retriggering interrupts

You're probably hitting the STAT bug: http://www.devrs.com/gb/files/faqs.html#GBBugs

Offline

 

#3 2017-05-08 16:04:04

ISSOtm
Member
From: Somewhere in Echo RAM
Registered: 2017-04-18
Posts: 160
Website

Re: Retriggering interrupts

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)


The French Lord Of Laziness.
Legend of Zelda and Undertale fan, I also tend to break Pokémon R/B/Y a little too much.

Twitter | Me on GCL | Discord : ISSOtm#9015 | Skype : isso.tm (I don't login anymore)

Offline

 

#4 2017-05-08 16:45:27

AntonioND
Member
Registered: 2014-06-17
Posts: 134
Website

Re: Retriggering interrupts

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

 

#5 2017-05-08 17:43:00

ISSOtm
Member
From: Somewhere in Echo RAM
Registered: 2017-04-18
Posts: 160
Website

Re: Retriggering interrupts

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.


The French Lord Of Laziness.
Legend of Zelda and Undertale fan, I also tend to break Pokémon R/B/Y a little too much.

Twitter | Me on GCL | Discord : ISSOtm#9015 | Skype : isso.tm (I don't login anymore)

Offline

 

#6 2018-01-29 05:00:32

npzman
Banned
From:
Registered: 2014-11-19
Posts: 197

Re: Retriggering interrupts

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


Twitter : @Sfeedman please follow
Join : sfeed.club my website please join

Offline

 

#7 2018-01-29 08:04:44

ISSOtm
Member
From: Somewhere in Echo RAM
Registered: 2017-04-18
Posts: 160
Website

Re: Retriggering interrupts

Because I have been polite, asked for something reasonable, and did not harass anyone.S


The French Lord Of Laziness.
Legend of Zelda and Undertale fan, I also tend to break Pokémon R/B/Y a little too much.

Twitter | Me on GCL | Discord : ISSOtm#9015 | Skype : isso.tm (I don't login anymore)

Offline

 

#8 2018-01-29 09:54:45

npzman
Banned
From:
Registered: 2014-11-19
Posts: 197

Re: Retriggering interrupts

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)


Twitter : @Sfeedman please follow
Join : sfeed.club my website please join

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson