It is currently Sat Dec 16, 2017 11:28 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Tue Aug 16, 2016 9:57 am 
Offline

Joined: Sun Feb 07, 2016 6:16 pm
Posts: 301
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:
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:
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!


Top
 Profile  
 
PostPosted: Tue Aug 16, 2016 9:59 am 
Offline
User avatar

Joined: Fri May 21, 2010 4:10 pm
Posts: 279
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


Top
 Profile  
 
PostPosted: Tue Aug 16, 2016 10:08 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19353
Location: NE Indiana, USA (NTSC)
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.


Top
 Profile  
 
PostPosted: Tue Aug 16, 2016 10:38 am 
Offline

Joined: Sun Feb 07, 2016 6:16 pm
Posts: 301
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?


Top
 Profile  
 
PostPosted: Tue Aug 16, 2016 11:08 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19353
Location: NE Indiana, USA (NTSC)
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.


Top
 Profile  
 
PostPosted: Tue Aug 16, 2016 1:28 pm 
Offline

Joined: Sun Feb 07, 2016 6:16 pm
Posts: 301
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group