i have rewritten part of my loader and sometimes it loads file (fat12) ok, sometimes it doesn't.(when filesize is changed) the problem is, that sometimes loader cant recognize the end of cluster. so can anyone please, check my code?
thanks a lot
Code: Select all
initmodule3:
mov si, init3note
call print_string
MOV SI, fatload
CALL print_string
XOR AX, AX
xor dl, dl
INT 0x13
MOV AH, 2
MOV AL, 14
MOV CL, 2
MOV CH, 0
;XOR DX, DX ; rofl logical 19
MOV DH, 1
XOR DL, DL
push es
mov bx, 0x60
mov es, bx
xor bx, bx
INT 0x13
pop es
JC mountfailure
MOV AH, 2
MOV AL, 9
MOV CL, 2
XOR CH, CH
XOR DX, DX
push es
mov bx, 0x220
mov es, bx
xor bx, bx
INT 0x13
pop es
JC mountfailure
MOV CX, 0xE0
xor si, si
push ds
mov ax, 0x60
mov ds, ax
iter:
ADD SI, 0x20
MOV DI, image
PUSH SI
PUSH CX
MOV CX, 11
CLD
REPE CMPSB
POP CX
POP SI
LOOPNE iter
CMP CX, 0
JE noimage
pop ds
PUSH SI
MOV SI, found
CALL print_string
POP SI
push 0x60
pop ds
ADD SI, 0x1A
MOV AX, [ds:SI]
xor bx, bx
iter1:
PUSH AX
push 0x900
pop ds
CALL clstochs
MOV AH, 2
MOV AL, 1
MOV CH, [ds:fdd_cyld]
MOV CL, [ds:fdd_sect]
MOV DH, [ds:fdd_head]
XOR DL, DL
push 0xa00
pop es
INT 0x13
;xchg bx, bx
JC readfailure
push es
push 0x900
pop es
inc byte [es:counter]
mov al, byte [es:counter]
call printhex
pop es
ADD BX, 0x200
POP AX
PUSH AX
MOV CX, 3
MUL CX
SHR AX, 1
MOV SI, AX
push 0x220
pop ds
MOV CX, [ds:SI]
POP AX
AND AX, 1
CMP AX, 0
JE even
SHR CX, 4
JMP n1
even:
AND CX, 0x0FFF
n1:
MOV AX, CX
CMP AX, 0x0FF7 <=============== there is the problem
xchg bx, bx
JA loadok
JMP iter1
there is the cluster/chs routine:
clstochs:
convclustlba:
;clusterStart=rootStart+(rootEntries*32)/bytesPerSectors
;lba=clusterStart+(cluster-2)*sectPerCluster
PUSH BX
PUSH AX ; cluster
MOV AX, 7168
MOV BX, 0x200
DIV BX
ADD AX, 19
POP BX
PUSH AX ; clusterStart
SUB BX, 2
MOV AX, 1
MUL BX
MOV BX, AX
POP AX
ADD AX, BX
POP BX
convlbachs:
PUSHA
MOV BX, 18
XOR DX, DX
DIV BX ;
INC DX
MOV [ds:fdd_sect], DL
MOV BX, 2
XOR DX, DX
DIV BX
MOV [ds:fdd_cyld], AL
MOV [ds:fdd_head], DL
POPA
RET