FME7 IRQs - Holy Diver Batman test vs Wiki info

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
Sour
Posts: 891
Joined: Sun Feb 07, 2016 6:16 pm

FME7 IRQs - Holy Diver Batman test vs Wiki info

Post by Sour »

Disclaimer: I have not written a single line of assembly for the 6502 in my life!

Mesen currently does not pass the IRQ tests found in Holy Diver Batman's test roms for the FME-7 (i.e: M69_P128K_C64K_S8K or M69_P128K_C64K_W8K)

I am following the information found on the wiki, but from what I can tell, this leads to the IRQ being triggered 2 cpu cycles too late for the test rom's code.
My code triggers the IRQ when the counter goes from $0 to $FFFF - so setting a value of 256 (like the test does), will trigger the IRQ flag 257 cycles later.
But the test contains the following comment:
"; Schedule an IRQ 256 cycles from now"
and then sets a value of 256 in the counter, which would cause the IRQ to be 257 cycles later.

This is how the IRQ test's code currently runs in Mesen:

Code: Select all

STA $A000  ;write cycle at cycle 0                IRQ Counter = $100
LDY #$E5   ;cycle 1 & 2                           IRQ Counter = $FF
INY        ;cycle 3 & 4
[...]
INY        ;cycle 253 & 254
BEQ $559   ;Y = $FF, cycle 255, 256               IRQ Counter = $1 -> $0 
CMP $FE    ;cycle 257 & 258                       IRQ Counter = $FFFF on before-last cycle, trigger IRQ next
[IRQ]
INC $FE    ;cycle 266
[...]
RTI
BEQ $54E
INY        ;Y = 0
BEQ $559   ;takes the branch and..
LDA #$10   ;test failed!
For the test rom to pass, the following needs to happen:

Code: Select all

STA $A000  ;write cycle at cycle 0
LDY #$E5   ;cycle 1
INY        ;cycle 3
[...]
INY        ;cycle 253, 254
BEQ $559   ;cycle 255, 256         IRQ Counter needs to get to $FFFF on the first cycle of BEQ to run on next instruction (i.e 255 cycles after enabling IRQs)
[IRQ]
INC $FE
[...]
RTI
CMP $FE    ;pass
BEQ $559   ;doesn't branch, Y = $FF
CPY #FE
BCS $55D   ;$FF > $FE, branches
[...] next irq test
puNES does pass this test, but it does not respect the information found in the Wiki (it triggers the IRQ when the counter hits 0 instead of $FFFF).
However, puNES' behavior causes a minor graphical glitch in "Gimmick! (J)" (pixels at the bottom right flash from time to time)
FCEUX also passes this test, and has no graphical glitch, but also triggers the IRQ when the counter hits 0.
Nestopia/Nintendulator both fail it.

Since tepples wrote this, I guess this is mostly a question he could answer:
Has the Holy Diver Batman rom been run on an actual FME-7 cart? My assumption would be yes, but I figure I would ask to make sure.
In which case, is the information on the Wiki wrong? If the IRQ is triggered when the counter hits 0, that would still leave me with a 1 cycle gap to a working solution, though.
Or is there something wrong with my analysis?

Sorry for the wall of text!
User avatar
*Spitfire_NES*
Posts: 306
Joined: Fri May 21, 2010 4:10 pm

Re: FME7 IRQs - Holy Diver Batman test vs Wiki info

Post by *Spitfire_NES* »

thanks for sharing this. IIRC, I thought nestopia was fixed to pass FME-7 IRQs from lidnariq?

EDIT**

relevant thread here:

viewtopic.php?f=2&t=12436
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: FME7 IRQs - Holy Diver Batman test vs Wiki info

Post by tepples »

The test in the FME-7 IRQ topic is authoritative. The FME-7 IRQ test in Holy Diver Batman was made based on outdated information. I have not yet updated it for two reasons: 1. The Curse of Possum Hollow has not yet gone gold, and 2. I have not yet received a patch to correct the FME-7 IRQ test in Holy Diver Batman.
Sour
Posts: 891
Joined: Sun Feb 07, 2016 6:16 pm

Re: FME7 IRQs - Holy Diver Batman test vs Wiki info

Post by Sour »

Thanks for the replies.

Mesen doesn't have any issues with any of the roms in the other thread (and I get the same result as the one shown by l_oliveira)
The fme7acktest-r1 test is already in my automatic tests for Mesen, but I was under the impression this only tested the behavior of writing to certain registers vs acknowledging IRQs, not the timing of IRQs in terms of CPU cycles (e.g whether the IRQ triggers at $0 or $FFFF)?

Also, my version of Nestopia UE does pass fme7acktest as well (so it includes the fix for it), but gives the same result as Mesen for the HDB test.

The other thread does say the IRQ triggers at $FFFF though, which probably means the Holy Diver Batman test would fail on a real cart?
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: FME7 IRQs - Holy Diver Batman test vs Wiki info

Post by tepples »

Holy Diver Batman was commissioned by a cartridge manufacturer as a quick test for assembled cartridge boards before a game is programmed onto the flash memory. Its name reflects this origin, as it was introduced when the manufacturer began to offer clones of the Holy Diver board and JxROM (the Batman: Return of the Joker board, with an FME-7). Thus it's designed to test whether things are connected at all rather than the precise behavior of the CPLD, such as what specific writes with what timing acknowledge the IRQ. That's more a matter for mapper-specific tests where you know everything is soldered down correctly. Because CPU A14-A12 are among the things that can be connected wrong, I have to fit a lot of the initial program into 4K and thus can't include tests for every mapper under the sun.

And you're correct that fme7acktest isn't intended to measure whether an emulator or CPLD's implementation of the FME-7's timer is dead-on cycle accurate. It's focused for a specific behavior I saw that differed from one emulator to another.
Sour
Posts: 891
Joined: Sun Feb 07, 2016 6:16 pm

Re: FME7 IRQs - Holy Diver Batman test vs Wiki info

Post by Sour »

Alright, thanks for the help and all the info!
I'll leave my implementation as it is now since it appears to be working properly in the games I've tested.
Post Reply