Hi, having a bit of trouble converting LBA to CHS for use with int 0x13, read sectors. I'm attempting to do this in my loader.

mov cx, 18
xor dx, dx
div cx
mov cx, dx
inc cx
xor dx, dx
shr ax, 1
rcl dh, 1
mov ch, al
shl ah, 6
or cl, ah

then in my read sector routine:

mov ah, 0x02
mov al, 0x12
mov cl, 1

        jc .readError

        int 0x13

The above code works for images on floppy that can be found on sector 1. But, I have another image at 1:0-5, and when I attempt to read that image into memory, I receive a read error. I have tried changing my code a few ways, but I just can not figure out what needs to be done. Any ideas?
Posted on 2010-06-06 17:31:33 by DaveT

First chunk of code looks fine (though somewhat eclectic: you've hardcoded 18 SPT yet calculating 10-bit cylinder; 1024-cylinder floppy? ;)). Perhaps something sets CF before second chunk?

Error code from int 0x13 can provide pointers too (most current BIOSes handle DMA-across-64k and multitrack I/O themselves, yet those can be an issue).
Posted on 2010-06-07 05:58:11 by baldr
Yep, this is for the floppy. Sorry I didn't mention that in my original post.

I checked the AH register after the error and I was receiving 0x04, which is to say that the sector not found/read error had occurred.

My LBA2CHS routine seems to muck up the cl register. Because if I print out those registers before the read takes place, I see that the cl register is always either 1 or 0, so I attempt to force the correct sector number (i.e. 5) and I get the error code 0x04.

So, is it a bad idea to try to read multiple sectors at once, should I read only one at a time?

I should mention that this routine and related code did work when I was loading an image whose sector was 1, so 4:0:1, etc. And, I was forcing it to one then as well.
Posted on 2010-06-07 14:44:35 by DaveT

Could you provide more substantial (and continuous) chunk of code, especially from call LBA2CHS to the corresponding int 0x13? jc .readError looks like being misplaced.

The function LBA2CHS alone seems to be alright (if it consists of the code in the first chunk and ret).

It's OK (in most cases) to read arbitrary number of sectors to an arbitrary placed buffer, but you may read sector-wise to 512-byte-aligned just to be safe, for a while.

Try to hardcode C:H:S, would int 0x13 succeed? Can that sector be read using other means (disk editor, debug)?
Posted on 2010-06-07 15:40:22 by baldr