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

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
LoveProgramming
Posts: 5
Joined: Sun Jun 11, 2023 11:02 am

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

Post 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!
Last edited by LoveProgramming on Mon Aug 07, 2023 10:52 am, edited 1 time in total.
Octocontrabass
Member
Member
Posts: 5218
Joined: Mon Mar 25, 2013 7:01 pm

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

Post by Octocontrabass »

What changes did you make to your initialization code to handle the different disk/drive combination?
User avatar
LoveProgramming
Posts: 5
Joined: Sun Jun 11, 2023 11:02 am

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

Post 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?
Octocontrabass
Member
Member
Posts: 5218
Joined: Mon Mar 25, 2013 7:01 pm

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

Post 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.
User avatar
LoveProgramming
Posts: 5
Joined: Sun Jun 11, 2023 11:02 am

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

Post 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?
Octocontrabass
Member
Member
Posts: 5218
Joined: Mon Mar 25, 2013 7:01 pm

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

Post 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.
Post Reply