nesdev.com
http://forums.nesdev.com/

FDS disk eject/insert loop bug?
http://forums.nesdev.com/viewtopic.php?f=3&t=16923
Page 1 of 1

Author:  Sour [ Wed Jan 10, 2018 6:58 pm ]
Post subject:  FDS disk eject/insert loop bug?

I stumbled upon a couple of FDS games that do something that seems weird while waiting for a disk to be inserted:
Code:
loop:                   
  LDA $4032               
  AND #$01                 
  BEQ loop                 ;if a disk is currently inserted, loop (e.g wait for eject)
  LDA $4032               
  AND #$01                 
  BNE loop                 ;if no disk is currently inserted, loop (e.g wait for insert, but the loop goes back to the first check!)

And then others do this instead (which makes a lot more sense to me):
Code:
wait_eject_loop:         
  LDA $4032               
  AND #$01                 
  BEQ wait_eject_loop     
  LDY #$FF                 
  JSR Delayms             
wait_insert_loop:       
  LDA $4032               
  AND #$01                 
  BNE wait_insert_loop
As far as I can tell, the first version can fail to recognize the newly inserted disk pretty often (which would force the user to eject the disk and then reinsert it). This can happen if you the "drive is empty" bit gets cleared while the code is in the first part of the loop (which loops until the disk is ejected).

My 6502 assembly skills are pretty terrible, so I could be understanding this wrong, but I can actually get this behavior several times in a row in the games (Aspic, Ao no Senritsu) that use the first version (e.g doing eject disk -> wait -> insert disk causes the execution to go back to the first loop and the game doesn't react at all)

The only way the first version would "reliably" be able to exit its loop was if the value of the "drive is empty" bit quickly toggled between 0 and 1 a number of times when physically ejecting or inserting a disk?

Author:  *Spitfire_NES* [ Fri Jan 12, 2018 5:34 am ]
Post subject:  Re: FDS disk eject/insert loop bug?

Which games are these Sour? Would Aspic-Majaou no Noroi be one of them? This was something that was fixed in nestopia before by martin, under better disc drive emulation. It takes multiple times to get this game to load as a lot of the time ejecting/inserting the disk does nothing.

Author:  tepples [ Fri Jan 12, 2018 6:43 am ]
Post subject:  Re: FDS disk eject/insert loop bug?

Sour wrote:
The only way the first version would "reliably" be able to exit its loop was if the value of the "drive is empty" bit quickly toggled between 0 and 1 a number of times when physically ejecting or inserting a disk?

You mean like switch bounce?

Author:  Sour [ Fri Jan 12, 2018 2:46 pm ]
Post subject:  Re: FDS disk eject/insert loop bug?

*Spitfire_NES* wrote:
Would Aspic-Majaou no Noroi be one of them?
Yes, Aspic is one of the 2 games I found that have this problem. Thanks - I'll try to hunt down the change that was done in Nestopia's code for this.
tepples wrote:
You mean like switch bounce?
Exactly what I was hoping to hear! I expected this might be a thing, but my knowledge of electronics is rather limited. If this happens on the FDS, it would make a lot of sense.

Author:  lidnariq [ Fri Jan 12, 2018 2:48 pm ]
Post subject:  Re: FDS disk eject/insert loop bug?

Switch bounce usually only happens in one direction (the "making contact" direction)..

Author:  Sour [ Sat Jan 13, 2018 9:44 pm ]
Post subject:  Re: FDS disk eject/insert loop bug?

lidnariq wrote:
Switch bounce usually only happens in one direction (the "making contact" direction)..
It could probably still explain this, since the buggy loop occurs while waiting for the disk to be inserted, which would presumably push on a switch?

Also, I took a look at Nestopia's code, but it didn't look like anything special was being done for that flag. And Nestopia itself doesn't work properly with Aspic, either (need to switch the disk a bunch of times before it finally works)

Author:  rainwarrior [ Sat Jan 13, 2018 10:38 pm ]
Post subject:  Re: FDS disk eject/insert loop bug?

Sour wrote:
lidnariq wrote:
Switch bounce usually only happens in one direction (the "making contact" direction)..
It could probably still explain this, since the buggy loop occurs while waiting for the disk to be inserted, which would presumably push on a switch?

I think the switch could be either... push to connect or push to break (my gut says the latter), but there's trivial ways that could either be a high or low signal by the time you read it. The Wiki's pinout says it's low when "media set" at least when coming in to the RAM adapter.

Author:  lidnariq [ Sun Jan 14, 2018 1:36 am ]
Post subject:  Re: FDS disk eject/insert loop bug?

Briefly looking around for videos of people disassembling the drive itself, I think I see a big normally-closed switch on the side with yellow wires (that is opened by inserting a disk). But the people who uploaded the videos also comment on there being multiple switches inside (there's obviously also the limit switches for seeking to end and beginning), so I'm not certain if I'm both seeing that big one correctly and if it's also the one that detects insertion.

Author:  *Spitfire_NES* [ Sun Jan 14, 2018 4:58 pm ]
Post subject:  Re: FDS disk eject/insert loop bug?

Hey Sour, sorry i prob should have clarified, this fix was seemingly implemented into nestopia 1.33. I think in subsequent versions martin may have overwrote these fixes in fds since he obviously made many fixes to fds.cpp since then.

Here's a snippet from the changelog for that version:

* More accurate FDS disk drive emulation. Fixes "Aspic-Majaou no Noroi", "Hao Kun no Fushigina Tabi" and possibly others.

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/