everything works until I call the int13h 43h extended write which actually returns NC flag with AL=0,1 with AL=2 (write verify on) it rejects with AH=1, CF=1 just according to spec.
Now I read back with int13h 42h the same sector 0, but old data is still there. Which means the function returned OK but write did not take place.
The code below might have some convoluted jumps and redundant labels but that is because I removed all debugging macros and other stuff to make it easier to read. Anyone catch anything wrong? Thanks!
Code: Select all
data segment para public 'data'
fileName db "boot.bin$"
dosHdrBuffer db 512 dup (?)
mbrBuffer db 512 dup (?)
filePointer dw ?
readSize dw ?
data ends
; open bootstrap file.
mainLab1:
mov ah, 3dh ; (AH) = file open int 21h code.
sub al, al ; (AL) = RO mode.
mov dx, DATA
mov ds, dx
lea dx, fileName ; (DS:DX) = pointer to filename string.
int 21h ; (AX) = file handle.
jnc mainLab2
jmp mainExit
; read till the end or up to 1024 into buffer if FF pointer is successful.
mainLab2:
mov filePointer, ax ; save file pointer.
mov ah, 3fh ; (AH) = file read int 21h code.
mov bx, filePointer ; (BX) = file pointer.
mov cx, 400h ; (CX) = maximum of 1024 bytes.
mov dx, DATA
mov ds, dx
lea dx, dosHdrBuffer ; (DS:DX) = 16:16 buffer to read into.
int 21h ; (AX) = No. of bytes read if success.
jnc mainLab3
jmp mainExit
; copy to disk 80h sector 0. Since the first 200h bytes of read is dosheader
; we point the DS:SI to right after dosHeaderBuffer which is mbrBuffer
; which itself is 512 bytes.
mainLab3:
mov readSize, ax ; save read size.
mov dl, 80h ; disk 0
mov si, DATA
mov ds, si
lea si, dap ; (DS:SI) = SEG:OFF pointer to dap.
mov cx, 1 ; (CX) = No. of sectors.
mov di, DATA
mov es, di
lea di, mbrBuffer ; (DS:SI) = SEG:OFF pointer to dap.
M_PRINTF "\nData to write: "
M_PRINTSTR_1616_NL es, di, 0, 040h
mov byte ptr ds:[si+DAP_OFFSET_SIZE], 10h
mov byte ptr ds:[si+DAP_OFFSET_UNUSED], 00h
mov word ptr ds:[si+DAP_OFFSET_NO_SECTORS], cx
mov word ptr ds:[si+DAP_OFFSET_BUFFER_PTR], di
mov word ptr ds:[si+DAP_OFFSET_BUFFER_PTR+2], es
mov dword ptr ds:[si+DAP_OFFSET_SECTOR_START], eax
mov dword ptr ds:[si+DAP_OFFSET_SECTOR_START+4], 0h ; set starting sector No for upper 48 lba.
mov ah, 43h ; (AH) = fcn No. for extended disk write.
sub al, al ; (AL) = close write check. Not sure what it means.
int 13h ; (AH) = return code if error writing.
jnc mainLab4
jmp mainExit
; open loading file.
mainLab4:
; perform a sector 0 readback:
mov dl, 80h ; disk 0
mov si, DATA
mov ds, si
lea si, dap ; (DS:SI) = SEG:OFF pointer to dap.
; prepare DAP area.
mov cx, 1 ; (CX) = No. of sectors.
mov di, DATA
mov es, di
lea di, mbrBuffer ; (DS:SI) = SEG:OFF pointer to dap.
mov byte ptr ds:[si+DAP_OFFSET_SIZE], 10h
mov byte ptr ds:[si+DAP_OFFSET_UNUSED], 00h
mov word ptr ds:[si+DAP_OFFSET_NO_SECTORS], cx
mov word ptr ds:[si+DAP_OFFSET_BUFFER_PTR], di
mov word ptr ds:[si+DAP_OFFSET_BUFFER_PTR+2], es
mov dword ptr ds:[si+DAP_OFFSET_SECTOR_START], eax
mov dword ptr ds:[si+DAP_OFFSET_SECTOR_START+4], 0h ; set starting sector No for upper 48 lba.
mov ah, 42h ; (AH) = fcn No. for extended disk read.
int 13h ; (AH) = return code if error writing.
jnc mainLab5
mainLab5:
M_PRINTF "\nReadback success. "
M_PRINTSTR_1616_NL es, di, 0, 040h
jmp mainExit
Here is the return output, i putout first 40h bytes of the blob to be written (first hex printout) and after that read back the same sector (second hex printout). Like I said earlier, none of the INT call returned CF and worked OK, except the int 13h 43h write just did not take place.
Code: Select all
Success opening file (fileHandle), reading: 0005
Read success (No. of bytes): 0238
Data to write:
0701:0209: B2 80 BE 00 7E 8E DE 2B : F6 C6 04 10 C6 44 01 00
0701:0219: C7 44 02 00 00 C7 44 04 : 00 80 C7 44 06 00 00 66
0701:0229: 89 44 08 66 C7 44 0C 00 : 00 00 00 B4 42 CD 13 2B
0701:0239: F6 8E DE BE 00 80 FF 24 : 00 00 00 00 00 00 00 00
Success writing sector 0. Readback test:
Readback success.
0701:0209: 33 C0 8E D0 BC 00 7C 8E : C0 8E D8 BE 00 7C BF 00
0701:0219: 06 B9 00 02 FC F3 A4 50 : 68 1C 06 CB FB B9 04 00
0701:0229: BD BE 07 80 7E 00 00 7C : 0B 0F 85 0E 01 83 C5 10
0701:0239: E2 F1 CD 18 88 56 00 55 : C6 46 11 05 C6 46 10 00