;libmbr.asm ;written by, Soni .MODEL small .DOSSEG EXTERN _cyl:word EXTERN _head:word .STACK 0000h .DATA .CODE _readSector PROC near push bp mov bp, sp push bx push es ;register set ES:BX should have the address of buffer ;which is atleast 0x0200 bytes long. push ds pop es mov bx, word ptr [bp + 04h] ;get head number, so the max head could be 0xFF. mov dh, byte ptr [bp + 06h] ;get drive number. mov dl, byte ptr [bp + 07h] ;get the sector number, bits[0-5] = sector(max 63) ;bits[6-7] = the bits[8-9] of 10 bit cylinder number. mov cl, byte ptr [bp + 08h] ;get cylinder number, bits[0-7] of 10 bits cylinder number, ;max could be 0x03FF. mov ch, byte ptr [bp + 09h] ;get number of sectors to read, so the max sectors read colud be ;0xFF mov al, byte ptr [bp + 0Ah] ;BE VERY CAREFULL THE VALUE SHOULD BE 02H NOT 03H. mov ah, 02h int 13h jc fail mov ax, 0000h fail: pop es pop bx pop bp retn _readSector ENDP _writeSector PROC near push bp mov bp, sp push bx push es ;register set ES:BX should have the address of buffer ;which is atleast 0x0200 bytes long. push ds pop es mov bx, word ptr [bp + 04h] ;get head number, so the max head could be 0xFF. mov dh, byte ptr [bp + 06h] ;get drive number. mov dl, byte ptr [bp + 07h] ;get the sector number, bits[0-5] = sector(max 63) ;bits[6-7] = the bits[8-9] of 10 bit cylinder number. mov cl, byte ptr [bp + 08h] ;get cylinder number, bits[0-7] of 10 bits cylinder number, ;max could be 0x03FF. mov ch, byte ptr [bp + 09h] ;get number of sectors to read, so the max sectors written colud be ;0xFF mov al, byte ptr [bp + 0Ah] ;BE VERY CAREFULL THE VALUE SHOULD BE 03H NOT 02H. mov ah, 03h int 13h jc fail mov ax, 0000h fail: pop es pop bx pop bp retn _writeSector ENDP _getCHS PROC near push bp mov bp, sp xor ax, ax push cx mov ax, [bp + 04h] mov dx, 0000h div word ptr [bp + 06h] ;cylinders mov cl, 08h rcl ax, cl mov cl, 06h shl al, cl mov cx, ax xchg ax, dx div byte ptr [bp + 08h] ;al = head, ah = sectors(0-origin) cmp ah, 00h jz A1 jmp A2 A1: inc ah A2: or cl, ah mov _cyl, cx and ax, 00ffh mov _head, ax pop cx mov sp, bp pop bp retn _getCHS ENDP END PUBLIC _readSector PUBLIC _writeSector PUBLIC _getCHS