Page 1 of 1

[SOLVED] Floppy read problems (with fdc) on different...

Posted: Sat Aug 05, 2023 11:07 am
by LoveProgramming
I already have an ATA drive, so I thought why not make a floppy?

The problem occurs when trying to read from a floppy with another size than a 1.44Mb floppy.
If this was real hardware, I would expect all sorts of issues, but I'm having this same problem on both QEMU and Virtualbox
E.g. on VirtualBox if I change the attached floppy to anything else than 1.44Mb it will cause an error
In this post I have omitted my initialization code as it is fairly long.

However, during initialization I:
1 Reset controller
2 Send sense interrupts
3 Set transfer speed
4 spin up drives
5 Configure
6 Recalibrate (which should seek to 0)

Then finally I first select and then read with this code:

Code: Select all

  push 20
  call allocate_mem
  mov eax, esi
  
  push word 0x46
  push dword 0x20000
  push word 512 ;The dma should stop it right?
  call initialize_dma_floppy
      
  mov byte [es:0x8006], 0
      
  ;Send read
       
  mov byte [es:esi], 01000000b | 0x6
  mov byte [es:esi+1], 0 ;Head number+drive
  mov byte [es:esi+2], 0 ;C
  mov byte [es:esi+3], 0 ;H
  mov byte [es:esi+4], 1 ;S
  mov byte [es:esi+5], 2 ;Size
  mov byte [es:esi+6], 8 ;Eot
  mov byte [es:esi+7], 0x1B ;Gap lenght
  mov byte [es:esi+8], 0xFF ;DTL
      
  push word 0x3F0
  push esi
  push word 9
  call write_entire_command_floppy
      
  ;Wait for interrupt
  read_test_wait_irq:
    cmp byte [es:0x8006], 0
    je read_test_wait_irq
  
  push word 0x3F0
  push esi
  push word 7
  call read_entire_data_floppy
        
  movzx eax, byte [es:esi]
  push eax
  push word 0x09
  call write_uint
  
  movzx eax, byte [es:esi+1]
  push eax
  push word 0x09
  call write_uint
On anything other than 1.44Mb the 6th bit in st0 is set (decimal 64) which according to:
https://www.ardent-tool.com/floppy/Flop ... mming.html
is an error
The value in st1 is also 1 which according to the same site is a "no address mark error"

I'm really stuck, have not idea why it doesn't work and would appreciate help greatly!

Re: Floppy read problems (with fdc) on different sizes of me

Posted: Sat Aug 05, 2023 1:06 pm
by Octocontrabass
What changes did you make to your initialization code to handle the different disk/drive combination?

Re: Floppy read problems (with fdc) on different sizes of me

Posted: Sun Aug 06, 2023 3:30 am
by LoveProgramming
I'm not sure if I fully understand your question.
As I'm testing, I only use one floppy (I boot from CD-ROM) so I wouldn't need to change the floppy number.

As for setting the transfer speed, I wouldn't expect problems on VMs, besides I set it to zero (lowest)
which accordingly to Osdev "DSR and CCR default to 0, and can always be set to zero safely".

As for specify values, I also use long delay values which should be safe for different medias. Again I doubt this
would cause problems on a Vm

Is there anything other that would need to be changed that I'm not aware of?

Re: Floppy read problems (with fdc) on different sizes of me

Posted: Sun Aug 06, 2023 3:43 pm
by Octocontrabass
LoveProgramming wrote:accordingly to Osdev "DSR and CCR default to 0, and can always be set to zero safely".
"The upper 6 bits on both DSR and CCR default to 0, and can always be set to zero safely." The lower two bits must be set to the correct data rate for the disk/drive combination you're using. Setting the lower two bits to 0 selects 500kbps, but that's not the correct rate for any disk with 8 sectors per track.

Re: Floppy read problems (with fdc) on different sizes of me

Posted: Mon Aug 07, 2023 4:14 am
by LoveProgramming
First of all, thank you!

Now it at least doesn't error out imidiately.

Still, the "tutorial" I followed used reads to get the media type.
Clearly, that won't work, because I can't set the CCR before knowing the type
Using bios values seems unreliable. Will I have to try to read multiple
times with different CCR values to get the type or is there a better way?

Re: Floppy read problems (with fdc) on different sizes of me

Posted: Mon Aug 07, 2023 10:28 am
by Octocontrabass
LoveProgramming wrote:Using bios values seems unreliable.
The BIOS can tell you the drive type, but not the disk type.
LoveProgramming wrote:Will I have to try to read multiple times with different CCR values to get the type or is there a better way?
As far as I know, that's the only way. The drive can't tell you what type of disk is inserted.