FDS IRQ reload flag/value

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

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

Re: FDS IRQ reload flag/value

Post by Sour »

I'm actually in the process of rewriting the whole thing using the test you made instead, much easier to understand with actual numbers on the screen.

Also improving a lot of stuff code-wise - slowly getting the hang of how to deal with IRQs in general, using macros and etc.

Also trying to assume as little as possible about the FDS' behavior in each test - e.g the last test you ran implies that writing $02 to $4022 when the reload value is set to 0 actually triggers an IRQ. If true, this invalidates some of the other tests.

I'll probably be done with that at some point tonight, so you might as well ignore the old code for now.
Sour
Posts: 891
Joined: Sun Feb 07, 2016 6:16 pm

Re: FDS IRQ reload flag/value

Post by Sour »

Ok, here we go again.
Completely re-written from scratch based on your test (thanks for that, btw!), with an output that's actually readable.
I've tried this on virtually all the emulators I had (FCEUX, Mesen, Nestopia, Nintendulator, RockNES, Nintaco, puNES, VirtuaNES) and it displays the result screen properly in all cases - so at least that's a start.

First column is test #, 2nd is pass/fail (X or O), 3rd is the number of irqs triggered during the test, the rest is a short description of what the test is trying to validate.
output.png
The code is included along with the FDS file.
Edit: Pass/Fail column is obviously not really relevant until the test is validated on an FDS and updated to match.
Attachments
FdsIrqTestsV6.zip
(8.34 KiB) Downloaded 285 times
Last edited by Sour on Thu Sep 21, 2017 8:06 pm, edited 1 time in total.
User avatar
Zepper
Formerly Fx3
Posts: 3262
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Re: FDS IRQ reload flag/value

Post by Zepper »

Any chance of testing Disk IRQs?
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: FDS IRQ reload flag/value

Post by rainwarrior »

V6 result::

Code: Select all

01 O 00
02 O 01
03 X 01
04 O 02
05 O 00
06 O 00
07 O 20
08 O 20
09 O 01
0A O 20
0B O 01
0C O 20
0D O 01
0E O 00
0F O 01
10 O 00
11 O 01
12 O 04
13 O 04
Did not see any power-on variations over ~15 tests.
Sour
Posts: 891
Joined: Sun Feb 07, 2016 6:16 pm

Re: FDS IRQ reload flag/value

Post by Sour »

Awesome - finally some conclusive results! Thanks for taking the time to do all these tests!

Test 3 failing in this case is fine, since it was just me assuming the FDS' behavior.
Apparently writing $02 to $4022 will trigger an IRQ immediately if the reload value is $00 - so I guess the IRQ triggers whenever the timer is at 0, rather than when it reaches 0. One thing left to test might be checking if turning on the irq repeat flag when the reload is 0 makes the irq fire in an infinite loop (I'm assuming it would)

@Zepper I could be wrong, but I'm under the impression the FDSStick(?) is probably emulation the disk drive and its IRQs? (i.e the disk irqs probably can't be properly validated without actually writing the test rom to a FDS disk and loading that?)
I only have a vague understanding of how the disk loading & its irqs work, to be honest, so I probably couldn't write a test for it even if I wanted to.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: FDS IRQ reload flag/value

Post by rainwarrior »

I don't have a disk drive. (I used to, but I couldn't get it to work, so I gave it to someone else.)

I don't know much about the hardware, though. Does the disk drive itself generate IRQs or is that done internally? Is there actually any feasible way to differentiate FDSstick from a real disk?
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: FDS IRQ reload flag/value

Post by lidnariq »

The Disk Drive cable itself is just three digital signals from the base station (written to via $4025), three signals from the base station (read via $4032), the battery voltage (read via $4033), the serial transmit and receive streams, ground, +5V, and the twelfth pin is unused.
User avatar
loopy
Posts: 405
Joined: Sun Sep 19, 2004 10:52 pm
Location: UT

Re: FDS IRQ reload flag/value

Post by loopy »

No, the drive itself doesn't generate IRQs. There should be no difference between using a FDSStick and a real drive for IRQ testing. You MIGHT want to load only your test rom onto fdsstick, removing any other games. This will bypass the boot menu and load your rom directly.

I'll leave this here, it seems relevant.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: FDS IRQ reload flag/value

Post by rainwarrior »

I didn't realize there was a bootloader now! I was still using the original release. :) I'll have to try that out.

I forgot about that thing with $4023, so my "spurious IRQ" test wouldn't have picked up on that since it doesn't mess with $4023. I should try again with it intentionally cleared...
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: FDS IRQ reload flag/value

Post by rainwarrior »

Hm! Very curious. I tried modifying my IRQ logging program, in particular to skip calling the BIOS reset to start the program (which normally writes to $4023). I found if I wrote $00 or $83 to $4023 once, nothing unusual happened, but if I skipped writing to it altogether, I got a variety of things happening (sirq2_no_reset.fds):

1. Loads and runs normally.
2. Loads and runs, but disk activity never seems to stop. No IRQ, but the FDSstick keeps turning on the green light over and over. (Or in the plugged into USB mode, the progress bar keeps repeating from 0 to 100%.)
3. Hangs on black screen, disk activity never stops.

One time I even caught one IRQ in the log but I accidentally reset and I haven't been able to reproduce it. Not sure if I caused it accidentally by pressing buttons or moving my Famicom around too much etc.


So, at least one write to $4023 after the license bypass NMI seems to be needed to reliably stop the disk access, but sometimes it stopped normally anyway? I didn't managed to get any good leads on whether this can make an IRQ...

Anyhow, sorry this post isn't very good information but it feels like the function of $4023 is more complicated than just disable/enable? Does the BIOS really only write it twice on reset? And even then it makes a point of writing $00 before $83... is that more like a reset sequence?
Attachments
sirq2.zip
(6.76 KiB) Downloaded 282 times
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: FDS IRQ reload flag/value

Post by Pokun »

I got identical results with FdsIrqTestsV6 as Rainwarrior as usual. But I only tested once, power cycling made the disk image corrupt somehow and it wouldn't start anymore (error 22).

I should mention that I also haven't updated my FDSStick so it's also not using the bootloader. Good to know that you can get around the bootloader by only writing one disk image though, I guess it's time for me to update it. :)
rainwarrior wrote:(The alignment of those diagrams is off, for me, I think that heart isn't properly monospaced, but it should be clear from context where the columns lie.)
Yeah sorry about that, I failed to produce monospaced hearts somehow, lacking love I guess.
Sour
Posts: 891
Joined: Sun Feb 07, 2016 6:16 pm

Re: FDS IRQ reload flag/value

Post by Sour »

That could actually explain the difference with the old version of the test - each test writes $83 to $4023 before starting to reset any changes I make to the disk enabled register in some of the tests. Maybe that's why this one doesn't freeze up - the I flag doesn't get cleared until after that $83 write, so any disk irqs would essentially be ignored.

I made one final version to fix the expected result for the failed test, and add 2 more tests related to the behavior when the reload value is 0. I'm expecting these to pass on the FDS - if they do, this will probably be the last version of this for now. Disk IRQs can be in their own separate test, if I ever get around to looking at those.

I'll try to update the FDS page on the wiki with the information that was confirmed by these tests once I get a chance.
Attachments
FdsIrqTestsV7.zip
(8.54 KiB) Downloaded 1015 times
User avatar
Zepper
Formerly Fx3
Posts: 3262
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Re: FDS IRQ reload flag/value

Post by Zepper »

Care to explain each test with a "X", please?
Attachments
fdsirqtestsv7 000.png
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: FDS IRQ reload flag/value

Post by rainwarrior »

Code: Select all

01 O 00
02 O 01
03 O 01
04 O 02
05 O 00
06 O 00
07 O 20
08 O 20
09 O 01
0A O 20
0B O 01
0C O 20
0D O 01
0E O 00
0F O 01
10 O 00
11 O 01
12 O 04
13 O 04
14 O 04
15 O 40
I did a few power tests to see if there were variations (didn't see any) but a strange thing, though: after running sometimes a red light comes on for the FDSStick and never shuts off. If I power cycle while this is happening I think I end up corrupting the disk sometimes, and get an "err 32" trying to load after that.
Sour
Posts: 891
Joined: Sun Feb 07, 2016 6:16 pm

Re: FDS IRQ reload flag/value

Post by Sour »

rainwarrior wrote:I did a few power tests to see if there were variations (didn't see any) but a strange thing, though: after running sometimes a red light comes on for the FDSStick and never shuts off. If I power cycle while this is happening I think I end up corrupting the disk sometimes, and get an "err 32" trying to load after that.
That sounds oddly similar to what Pokun mentioned, too. But I can't really see how the test could be causing it - it does absolutely nothing after displaying the results. Maybe a bug with the FDSStick itself?
Zepper wrote:Care to explain each test with a "X", please?
All 3 should be caused by essentially the same thing: unlike what the wiki implies, the FDS's irq triggers whenever the counter is at 0 - not just when it reaches 0. So setting reload value to 0 and writing to $4022 to start the IRQ will trigger one immediately. If the repeat flag is enabled, this will cause a never-ending loop of IRQs.
Post Reply