The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => 16 bit DOS Programming => Topic started by: AeroASM on May 05, 2005, 11:23:28 AM

Title: Extended int 13h
Post by: AeroASM on May 05, 2005, 11:23:28 AM
Is this code snippet right?


;LBA in esi, destination address in di, number of sectors in cx
ReadSectors:
mov [DiskAddressPacket+2h],cx
mov [DiskAddressPacket+4h],di
mov [DiskAddressPacket+8h],esi
mov ah,42h
mov dl,[bBootDrive]
mov si,DiskAddressPacket
int 13h
ret
DiskAddressPacket:
db 10h
db 0h
dw 0h
dd 0h
dq 0h


The reason I have not tested it myself is that my computer takes ages to reboot and I am also in the middle of typing a coursework essay.
Title: Re: Extended int 13h
Post by: MichaelW on May 05, 2005, 05:52:02 PM
It looks OK as far as it goes, but it does not check the carry flag on return (CF set on error). And to reliably access a diskette (or other drive that may not be spinning when the call is made) you should make several tries, resetting the disk between tries, before you accept an error return.
Title: Re: Extended int 13h
Post by: AeroASM on May 05, 2005, 06:02:51 PM
Is three tries enough for floppy and one try for HDD? Also the bit I really wanted to check was that when writing a far pointer ds:di you first write di, then ds.

Thanks
Title: Re: Extended int 13h
Post by: MichaelW on May 05, 2005, 07:15:53 PM
I code for four tries and use the same code for all disks. I differentiate between HDD and floppy only for the code that resets the disk. You need to check the error return for a HDD anyway, so using the same code for both does not slow anything down. The function expects a far pointer to the disk address packet in DS:SI so the proper order of the address components in memory does not matter here. For storage in memory the segment should be in the high-order word, so if you were passing a far pointer on the stack you would push the segment first, followed by the offset.