FDS IRQ reload flag/value

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

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 »

I just removed a check of the irq latch value on 4022 write (non-zero only). I got a pass in all tests.
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 »

Sour wrote:
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?
I feel like writing repeatedly to $4023 has consequences for disk activity, like it's causing the RAM adapter to send signals to the drive in some way. Maybe not important in terms of nailing this IRQ behaviour down but relevant to disk behaviour? It's weird how inconsistent it is, though.

Trying to check what the corruption was, I tried to read the "corrupted" disk back using the FDSStick program, and it was only 16 bytes long. (FDS,$1A header + 12 x $00) So... that's strange. Maybe it's just from powering off while it's trying to write?

I don't know what the held red light on the FDSstick means. Actively writing? Usually it turns on whenever I press the button, and the green one turns on any time the disk is being read, I think. (Similarly on my other test a few posts back, I'd get a repeating held green light on that one where it just never stops reading?


I do notice that in my example I zeroed out RAM, even though I was masking the value from $FA ($4025 write mirror) when applying mirroring to $4025. Maybe this put the disk into write mode? (There's also bit 5 that the wiki says "always set to 1", which is a direction this violates but I don't know if that's meaningful.) The default value for $FA should be $2E, which is the last thing the BIOS set it to on reset.

I should fix my example not to clobber those BIOS variables. I thought I tried to avoid that, but I missed the ZP ones. :(
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 »

Yeah, I patched V7 to fix that write to $4025 and now there's no more "weird" behaviour from the FDSstick. I can power cycle it with no problems at all.

So, yeah, I think the disk activity weirdness was my fault, a bug in my example (now fixed). Sorry.

I still think weird stuff can happen with the drive when writing to $4023, but seems well behaved/quiet as long as $4025 is properly set back to $2E beforehand? Anyhow, probably not relevant to the IRQ testing.

I also tried patching V5 to see if this affected that it hangs with only 1 heart displayed, but it's the same, so at least THAT wasn't my fault. ;)
Attachments
fdsirqtestsV7_patched.fds
(63.98 KiB) Downloaded 317 times
Sour
Posts: 891
Joined: Sun Feb 07, 2016 6:16 pm

Re: FDS IRQ reload flag/value

Post by Sour »

I guess it didn't like write mode being turned on? Odd that this would matter since it also meant the motor was turned off - hard to see how the FDS could corrupt a disk while the motor is disabled..

I'm guessing there is probably a reason for the BIOS to be writing $83 to $4023 instead of $03, but there is no mention of bit 7 in $4023 anywhere, from what I can see.

I updated the wiki with the information that was confirmed from these IRQ tests.
I might try writing another set of tests for the drive itself (though that will be trickier I'd imagine) - it would be nice to get a solid understanding of all the flags in in $4030/$4032 as well as the behavior of the disk IRQs.
I'm guessing the actual timing of the disk read/write operations can't really be tested with the FDSStick, though?
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: FDS IRQ reload flag/value

Post by Pokun »

I guess there is still a possibility that the FDSStick behaves differently from the real disk drive and ignores the motor state. Maybe Loopy could answer that.

I tried googling in Japanese for more information about $4023 but found nothing that tells us more than the wiki or Enri. I guess information of the FDS is really scarce overall.
Alyosha_TAS
Posts: 173
Joined: Wed Jun 15, 2016 11:49 am

Re: FDS IRQ reload flag/value

Post by Alyosha_TAS »

Hi all, I am trying to get these tests to work on BizHawk. The first problem I ran into is that the .FDS file indicates that there are 6 files on the disk, but looking over the file in hex editor I only see files 0-4. (Also, two files are both named FILE2, but that's not relevent to anything.)

I added in a blank file 5 to get it to run, but then it just repeatedly fires IRQ's and doesn't do anything else.

Am I missing something here?
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 »

Alyosha_TAS wrote:Hi all, I am trying to get these tests to work on BizHawk. The first problem I ran into is that the .FDS file indicates that there are 6 files on the disk, but looking over the file in hex editor I only see files 0-4. (Also, two files are both named FILE2, but that's not relevent to anything.)
The high file count is intentional, used to skip the BIOS' license screen. The technique is described here:
viewtopic.php?p=194826#p194826

The extra FILE2 is just a typo, should have been FILE1. (I need to fix that in my example template...)

You shouldn't need to add an extra file to get it to run... but a modified or high level replacement for the BIOS might break the license-skip technique?
Alyosha_TAS
Posts: 173
Joined: Wed Jun 15, 2016 11:49 am

Re: FDS IRQ reload flag/value

Post by Alyosha_TAS »

Ah ok thanks for the info.

I went back and tried V3 which still had the copyright screen and I still just get a blank screen, so it looks like I have a bit of work to do here.

EDIT: Actually that wasn't so bad, got everything working.

Thanks for the valuable research Sour, rainwarrior, et al. !
User avatar
*Spitfire_NES*
Posts: 306
Joined: Fri May 21, 2010 4:10 pm

Re: FDS IRQ reload flag/value

Post by *Spitfire_NES* »

Thanks for posting this up Sour! I would like to try to implement this fix into nestopia as well. I am taking the hot spot snippet from the Nestopia plus! SVN here. This was the last commit which fixed the freeze in Lutter but now makes the game putter have no sound.

Code: Select all

bool enabled = (data & 0x02) == 0x02;  
 			bool reload = (data & 0x01) == 0x01;  
  
 			if (enabled && !reload)  
  			{  
  				unit.timer.latch = 0;  
 				//ClearIRQ();  
 			}  
   
 			if (!unit.status)  
 			{  
 				//unit.timer.latch = 0;  
  				ClearIRQ();  
  			}  
With this current code.

Putt Putt golf has NO sound but

Druid works as expected
Lutter does not freeze when starting a new game
Kaettekita Mario Bros works as expected on ALL 3 loading screens.

Anyone see anything I might can try?

Also the FDS game Aspic-Majaou no Noroi has issues sometimes when loading side b the system is unresponsive. IS this issue related to this?

After looking through the changelogs I found this:

"More accurate FDS disk drive emulation. Fixes "Aspic-Majaou no Noroi", But Apparently this got borked again somehow.

Anyways, this is awesome work guys. Hopefully this is fix of the trivial matter. :)
User avatar
*Spitfire_NES*
Posts: 306
Joined: Fri May 21, 2010 4:10 pm

Re: FDS IRQ reload flag/value

Post by *Spitfire_NES* »

It's hard for me to get a screenshot so i will post the results. I ran the V7 FDS test against the FDS fixes from Nestopia plus! and got these results:

01 0
02 0
03 X
04 X
05 X
06 X
07 0
08 0
09 0
0A X
0B X
0C O
0D X
OE X
0F O
10 O
11 X
12 X
13 O
14 O
15 X

Can someone help me decipher what exactly is the issue. X meaning fail i am assuming right?
zxbdragon
Posts: 498
Joined: Mon Dec 12, 2011 8:15 pm

Re: FDS IRQ reload flag/value

Post by zxbdragon »

Nestopia Plus!Is dead, please use Nestopia UE or Mesen!
2017-10-28_10-28-09.jpg
User avatar
*Spitfire_NES*
Posts: 306
Joined: Fri May 21, 2010 4:10 pm

Re: FDS IRQ reload flag/value

Post by *Spitfire_NES* »

Zxbdragon, can you share these fixes please? If Nestopia plus! is dead, then how do you explain everything passing on your build? WTF.
Sour
Posts: 891
Joined: Sun Feb 07, 2016 6:16 pm

Re: FDS IRQ reload flag/value

Post by Sour »

The text next to each test is essentially a summary of what the emulator should do.

As far as I remember:
03 Starting irq counter when reload value is 0 should still cause an irq
04 The irq reload value should never get reset (by anything other than $4020/$4021 writes)
05 Disabling disk registers while waiting for an irq should cancel that irq (it should never be triggered)
06 Starting an irq when disk registers are disabled should be impossible
0A Writing to $4022 with bit 1 set ($02) should not acknowledge the irq
0B Writing to $4023 with bit 0 set ($01) should not acknowledge the irq
0D Writing to $4022 to start the irq counter while the irq counter was already running resets the counter and delays the irq.
0E Writing to $4022 to start an irq while disk regs are disabled, and then enabling disk registers should not cause an irq
11 Writing $00 to $4022 should not reset the irq reload value
12 Writing $02 to $4022 4 times in a row (with a small delay between each write) when reload value is 0 should cause 4 irqs
15 Starting the irq counter with the repeat flag & a reload value of 0 should cause an infinite never-ending loop of IRQs

Some of these tests are a bit redundant since I was trying to test for every possible edge case I could think of.
User avatar
*Spitfire_NES*
Posts: 306
Joined: Fri May 21, 2010 4:10 pm

Re: FDS IRQ reload flag/value

Post by *Spitfire_NES* »

Thank you for the clarification Sour. It's a little confusing but i see someone has it working in Nestopia.

Obviously ZxbDragon wants to throw it in my face that he has it working in his private modified build of Nestopia plus! so maybe he can help share this information, since he shared his other FDS fixes. So what do you say dragon, do you mind sharing your findings please? Since you already obviously have this working.
zxbdragon
Posts: 498
Joined: Mon Dec 12, 2011 8:15 pm

Re: FDS IRQ reload flag/value

Post by zxbdragon »

*Spitfire_NES* wrote:Zxbdragon, can you share these fixes please? If Nestopia plus! is dead, then how do you explain everything passing on your build? WTF.
I not fixed! this test code,I didn't save on the computer~! Wait UE solution
Post Reply