Page 1 of 1

a few questions on floppy drive initialization

Posted: Mon Oct 19, 2020 2:46 am
by ITchimp
I was trying to initialize the floppy, following the instructions in the wiki...
after I send the lock command (0x94), I am reading back the result and
according to wiki it is supposed to be 1<<4, but I am getting 0x90... is it that the
documentation is wrong or I am doing it wrong?

Code: Select all

  char c = (1<<6)| (1<<5)|(1<<4)|8; //polling mode off, FIFO on, implied seek on, threadhold =8
   floppy_write_cmd(0);
   
   // now lock the configuration
   floppy_write_cmd(0x94); // MT bit set + 0x14 for lock; 0x14 is unlock with lock bit turned off
   result = floppy_read_data();
   if (result !=(1<<4)){
        print(" lock command failed \n");
        print(" floppy initialization aborted \n");
        return;
   }
        

Re: a few questions on floppy drive initialization

Posted: Mon Oct 19, 2020 6:28 pm
by BenLunt
ITchimp wrote:I was trying to initialize the floppy, following the instructions in the wiki...
after I send the lock command (0x94), I am reading back the result and
according to wiki it is supposed to be 1<<4, but I am getting 0x90... is it that the
documentation is wrong or I am doing it wrong?

Code: Select all

  char c = (1<<6)| (1<<5)|(1<<4)|8; //polling mode off, FIFO on, implied seek on, threadhold =8
   floppy_write_cmd(0);
You set 'c' to the values you wish to send to the controller, yet you still send '0'. Is this just a typo? i.e.:

Code: Select all

  char c = (1<<6)| (1<<5)|(1<<4)|8; //polling mode off, FIFO on, implied seek on, threadhold =8
   floppy_write_cmd(c);
Also, using the LOCK command isn't very common. If you are going to reset the controller, you are most likely going to run through the process of initializing it anyway, including setting the FIFO.

I would ignore the LOCK command, but that is just my opinion.

Ben
- http://www.fysnet.net/media_storage_devices.htm

Re: a few questions on floppy drive initialization

Posted: Wed Oct 21, 2020 1:29 am
by ITchimp
Thanks that was my bad for not send the c value to output port...

I have another question regarding the DOR definition

the lower 2 bits select the drive number for next access..
the top 4 bits turns the motor on...

so if I want to access the second floppy for a seeking
should I simply set the top 4 bits as 0x20, and then set lower 2 bits to 0x1
as well? can you clarify the definition of "next" in the "next access"?

another way of saying this is: if we can use the lower 2 bits to select the drive,,
then we only need 1 bit to turn it on, what is the point of having top 4 bits redundantly
select the motor????

Re: a few questions on floppy drive initialization

Posted: Wed Oct 21, 2020 12:09 pm
by Octocontrabass
ITchimp wrote:if we can use the lower 2 bits to select the drive,,
then we only need 1 bit to turn it on, what is the point of having top 4 bits redundantly
select the motor????
It's faster to copy data between two floppy drives if you leave both motors enabled, since you don't need to wait for each drive to spin up when you switch between them.

Re: a few questions on floppy drive initialization

Posted: Wed Oct 21, 2020 5:51 pm
by BenLunt
As Octocontrabass states, this allows you to keep a disk spinning even though you may be accessing another drive. It was quite common back in the day for a computer to have at least two drives. (Just for fun, I happen to still have one here on one of my desks that has a 3 1/2" as well as a 5 1/4")

With all of this in mind, you will need to create a thread (or task) to watch the motors and turn them off after a couple of seconds. This is done in real mode via the Legacy BIOS. A value is decremented once per interrupt and if it reaches zero, the motor is turned off.

Once you move to protected mode (or even long mode), this service is no longer available, so you will need to do this yourself. It is actually quite simple. Take the time you wish to have a motor run after no more access, calculate the hertz a timer would be called, and decrement a value until zero. Just like the Legacy BIOS does it.

One more note about the floppy drive. If you happen to be booting from the floppy drive and move to protected mode before the BIOS has time to turn off the motor, the drive will continue to spin indefinitely. A really easy trick to make sure this doesn't happen is to set the value the BIOS uses (a byte at 0x00440) to 1 just before you move to protected mode. If it is already zero, skip the check. Here is some code I use.

Ben