FDS IRQ reload flag/value

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Sour
Posts: 736
Joined: Sun Feb 07, 2016 6:16 pm

FDS IRQ reload flag/value

Post by Sour » Sun Sep 17, 2017 3:49 pm

It seems like no emulator is able to run all 4 of these games at once without some sort of issue:
-Druid Kyoufu no Tobira (status bar flickers every other frame)
-Kaettekita Mario Bros (graphical glitches in disk insert prompt screen)
-Lutter (freezes after pressing any button once in game)
-Putt Putt Golf (no sound, buggy scrolling in-game)

Of all the emulators I've tested, there is always at least 1 game that fails (I may have missed some):
Bizhawk - Kaettekita Mario Bros
FCEUX - Druid Kyoufu no Tobira
Mesen - Putt Putt Golf
Nestopia UE - Druid Kyoufu No Tobira, Lutter
Nintaco - Kaettekita Mario Bros
Nintendulator - Kaettekita Mario Bros
puNES - Lutter, Putt Putt Golf

I haven't been able to find any way to keep all 4 games working at once.
All of these seem to be linked to the behavior of the IRQ reload value ($4020 & $4021) when the IRQ reload flag is disabled (bit 0 in $4022). When & under what conditions the reload value gets reset to 0 has an impact on these games - some appear to expect the reload value to be preserved after writes to $4022 or after an IRQ is triggered, while others expect the reload value to reset to 0 in similar conditions. I haven't managed to find any pattern that makes sense between all 4 games.

The Wiki doesn't seem to mention the reload flag in $4022, and I am not really aware of any other FDS documentation that does (other than emulator sources) - the other FDS documents listed in the old nesdev homepage don't mention the irq reload flag either. There is an older thread by FHorse about Kaettekita Mario Bros on here, but I haven't really been able to find any other information beyond that.

So... any ideas?

zxbdragon
Posts: 474
Joined: Mon Dec 12, 2011 8:15 pm

Re: FDS IRQ reload flag/value

Post by zxbdragon » Sun Sep 17, 2017 8:20 pm

my build nestopia,
-Druid Kyoufu no Tobira OK
-Kaettekita Mario Bros OK
-Lutter OK
-Putt Putt Golf no sound

zxbdragon
Posts: 474
Joined: Mon Dec 12, 2011 8:15 pm

Re: FDS IRQ reload flag/value

Post by zxbdragon » Mon Sep 18, 2017 7:21 am

if(_irqEnabled && !_irqReloadEnabled) {
//Needed by Kaettekita Mario Bros
//If done when _irqEnabled is false, Lutter breaks
if(_irqReloadValue & 0x0F)
_irqReloadValue = 0;
}

Sour
Posts: 736
Joined: Sun Feb 07, 2016 6:16 pm

Re: FDS IRQ reload flag/value

Post by Sour » Mon Sep 18, 2017 1:53 pm

While that works (Kaettekita sets $6302 as the reload value, Putt Putt Golf uses $5400), it's essentially a patch on top of another patch (I'm fairly sure that the condition in Mesen's code that you modified here is incorrect, hardware-wise).

I'm mostly hoping to figure out how the FDS itself resets the value, since patches could just end up breaking any other FDS game.

zxbdragon
Posts: 474
Joined: Mon Dec 12, 2011 8:15 pm

Re: FDS IRQ reload flag/value

Post by zxbdragon » Mon Sep 18, 2017 3:26 pm

working nestopia for all irq fds.

User avatar
Zepper
Formerly Fx3
Posts: 3190
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Re: FDS IRQ reload flag/value

Post by Zepper » Mon Sep 18, 2017 3:33 pm

Sour wrote:Of all the emulators I've tested, there is always at least 1 game that fails (I may have missed some):
(...)
So... any ideas?
Try my emulator RockNES and let me know.

Sour
Posts: 736
Joined: Sun Feb 07, 2016 6:16 pm

Re: FDS IRQ reload flag/value

Post by Sour » Mon Sep 18, 2017 5:42 pm

Zepper wrote:Try my emulator RockNES and let me know.
Same as Bizhawk, Nintendulator & Nintaco - 2 of the 3 random intro sequences to Kaettekita Mario Bros end with a glitchy disk switch message.

This is the behavior you get when you never reset the reload value to 0.
I guess only Kaettekita Mario Bros expects this to happen - maybe the actual issue is elsewhere.

User avatar
Zepper
Formerly Fx3
Posts: 3190
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Re: FDS IRQ reload flag/value

Post by Zepper » Mon Sep 18, 2017 6:35 pm

Sour wrote:
Zepper wrote:Try my emulator RockNES and let me know.
Same as Bizhawk, Nintendulator & Nintaco - 2 of the 3 random intro sequences to Kaettekita Mario Bros end with a glitchy disk switch message.

This is the behavior you get when you never reset the reload value to 0.
I guess only Kaettekita Mario Bros expects this to happen - maybe the actual issue is elsewhere.
I don't know such game. Is it original or... an hack of the FDS SMB?

Sour
Posts: 736
Joined: Sun Feb 07, 2016 6:16 pm

Re: FDS IRQ reload flag/value

Post by Sour » Mon Sep 18, 2017 6:47 pm

It's a game made by Nintendo themselves: https://www.mariowiki.com/Kaettekita_Mario_Bros.

zxbdragon
Posts: 474
Joined: Mon Dec 12, 2011 8:15 pm

Re: FDS IRQ reload flag/value

Post by zxbdragon » Mon Sep 18, 2017 8:34 pm

Sour wrote:
Zepper wrote:Try my emulator RockNES and let me know.
Same as Bizhawk, Nintendulator & Nintaco - 2 of the 3 random intro sequences to Kaettekita Mario Bros end with a glitchy disk switch message.

This is the behavior you get when you never reset the reload value to 0.
I guess only Kaettekita Mario Bros expects this to happen - maybe the actual issue is elsewhere.
Hardware not this bug.

zxbdragon
Posts: 474
Joined: Mon Dec 12, 2011 8:15 pm

Re: FDS IRQ reload flag/value

Post by zxbdragon » Mon Sep 18, 2017 8:39 pm

Zepper wrote:
Sour wrote:Of all the emulators I've tested, there is always at least 1 game that fails (I may have missed some):
(...)
So... any ideas?
Try my emulator RockNES and let me know.
20170919113841.png
20170919113841.png (7.89 KiB) Viewed 10361 times

Pokun
Posts: 1237
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: FDS IRQ reload flag/value

Post by Pokun » Tue Sep 19, 2017 1:12 am

The wiki page about FDS is lacking some information from Enri's page. Enri's page doesn't mention $4022.0 either though.
$4022:(出力) [output]
 Bit2:1=IRQタイマカウント開始、0=IRQタイマカウント停止 [1=IRQ Timer Count Start, 0=IRQ Timer Count Stop]
Enri's page differs from the wiki on this matter: $4022.2 controls timer state according to Enri. I guess Enri is wrong in this case?

Sour
Posts: 736
Joined: Sun Feb 07, 2016 6:16 pm

Re: FDS IRQ reload flag/value

Post by Sour » Tue Sep 19, 2017 4:58 am

Pokun wrote:Enri's page differs from the wiki on this matter: $4022.2 controls timer state according to Enri. I guess Enri is wrong in this case?
I'm guessing this is probably a typo and meant to say Bit 1 (as in the 2nd bit).

On the other hand, this reminded me that I hadn't checked another Japanese source of information - VirtuaNES. And after checking, it actually plays all 4 games properly :)
Its source code implies that bit 0 of $4022 is not an irq reload flag, it's an irq repeat flag.
If bit 0 is not set, the IRQ is supposed to trigger a single time, and then the irqEnabled flag is set to false (but its reload value is not altered). The IRQ's timer is always reloaded with the reload value once it triggers.
Using this logic makes all 4 games work *if* you also add logic to disable the "irqEnabled" flag when the game writes to $4023 with bit 0 (disk registers enabled) cleared (this is also from VirtuaNES' code). Otherwise Kaettekita Mario Bros crashes with an illegal opcode.

At the very least, this logic fixes the issues in Mesen too, and seems to make sense. (still need to try running other games to make sure this works properly, though)

Pokun
Posts: 1237
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: FDS IRQ reload flag/value

Post by Pokun » Tue Sep 19, 2017 8:22 am

I see, all these emulators got it wrong because there's little accurate information of the FDS (at least in English). I think a mending of the wiki is in order. And proper test disk images so the behaviour can be verified on real hardware and emulators alike.

User avatar
rainwarrior
Posts: 7642
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: FDS IRQ reload flag/value

Post by rainwarrior » Tue Sep 19, 2017 2:01 pm

I'm assuming you've verified the behaviour of these 4 games against an actual FDS, but in case the hardware is scarce if you've got an FDS file you'd like tested I can do it.

Post Reply