Page 1 of 6

FDS IRQ reload flag/value

Posted: Sun Sep 17, 2017 3:49 pm
by Sour
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?

Re: FDS IRQ reload flag/value

Posted: Sun Sep 17, 2017 8:20 pm
by zxbdragon
my build nestopia,
-Druid Kyoufu no Tobira OK
-Kaettekita Mario Bros OK
-Lutter OK
-Putt Putt Golf no sound

Re: FDS IRQ reload flag/value

Posted: Mon Sep 18, 2017 7:21 am
by zxbdragon
if(_irqEnabled && !_irqReloadEnabled) {
//Needed by Kaettekita Mario Bros
//If done when _irqEnabled is false, Lutter breaks
if(_irqReloadValue & 0x0F)
_irqReloadValue = 0;
}

Re: FDS IRQ reload flag/value

Posted: Mon Sep 18, 2017 1:53 pm
by Sour
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.

Re: FDS IRQ reload flag/value

Posted: Mon Sep 18, 2017 3:26 pm
by zxbdragon
working nestopia for all irq fds.

Re: FDS IRQ reload flag/value

Posted: Mon Sep 18, 2017 3:33 pm
by Zepper
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.

Re: FDS IRQ reload flag/value

Posted: Mon Sep 18, 2017 5:42 pm
by Sour
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.

Re: FDS IRQ reload flag/value

Posted: Mon Sep 18, 2017 6:35 pm
by Zepper
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?

Re: FDS IRQ reload flag/value

Posted: Mon Sep 18, 2017 6:47 pm
by Sour
It's a game made by Nintendo themselves: https://www.mariowiki.com/Kaettekita_Mario_Bros.

Re: FDS IRQ reload flag/value

Posted: Mon Sep 18, 2017 8:34 pm
by zxbdragon
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.

Re: FDS IRQ reload flag/value

Posted: Mon Sep 18, 2017 8:39 pm
by zxbdragon
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 10315 times

Re: FDS IRQ reload flag/value

Posted: Tue Sep 19, 2017 1:12 am
by Pokun
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?

Re: FDS IRQ reload flag/value

Posted: Tue Sep 19, 2017 4:58 am
by Sour
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)

Re: FDS IRQ reload flag/value

Posted: Tue Sep 19, 2017 8:22 am
by Pokun
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.

Re: FDS IRQ reload flag/value

Posted: Tue Sep 19, 2017 2:01 pm
by rainwarrior
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.