Floppy images

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
PrzemekG_

Floppy images

Post by PrzemekG_ »

I have a problem with be bootloader when reading files larger than 8kb. Since this is on my fs, I know where the problem is. I have made some tools to manage FlopFS2 from dos. The problem is my LBA -> CHS in those tools or in bootsector.
This is the bootsectors's code to load a sector from LBA:
[code]
load_sect:   ; ES:BX = Location ; AX = Sector
mov si, 18 ; sector/track
div si ; divide logical sect by track size
inc dl ; sector # begins at 1
mov [d_tmp], dl ; sector to read
xor dx, dx ; logical track left in ax
div word [d_heads] ; (heads) leaves head in dl, cyl in ax
mov dh, [d_bootdrv] ;
xchg dl, dh ; head to dh, drive to dl
mov cx, ax ; cyl to cx
xchg cl, ch ; low 8 bits of cyl to ch, hi 2 bits
shl cl, 6 ; shifted to bits 6 and 7
or cl, byte [d_tmp] ; or with sector number
mov al, 1 ; number of sectors
mov ah, 2 ; use read function of int 0x13
int 0x13 ; read sector
jc .fail1
xor ax, ax
inc ax
ret ; return to caller
.fail1:
xor ax, ax
ret
[/code]
This is not my code, I only modified is a little.

I have found 2 algoritms LBA->CHS:
[code]
// method 1
t = sector / (drv->h * drv->s);
tmp = sector % (drv->h * drv->s);
h = tmp / drv->s;
s = tmp % drv->s + 1;
// method 2
t = (sector/drv->s)/drv->h;
h = (sector/drv->s) % drv->h;
s = (sector % drv->s) + 1;
// drv->s = sectors/track
// drv->h = heads
// drv->t
[/code]
Both of them seams to give the same result. In the image file I readed from the floppy, I sow something strage, some sectors where far from the begining. The last sector I was using was LBA 20, which should be at 0x2800, but is somewhere in 0x4c00.

How are saved floppy imaged from a floppy???
Or maybe I have wrong algoritm for LBA -> CHS, maybe a floppy have a diferant geometry from a hard disk, and LBA is diferant?
Post Reply