reading file from floppy/fat12
Posted: Wed Oct 27, 2004 5:28 am
I have fighting alot with my damn bootsector thing... i have successfully loaded the rootdir and located the file (well at least I don't get any error doing this) but it fail reading it later..
I do as it say I should read the fat12 in the FAQ (if I got my assembly code right was a while since I coded assembly)
this is a pice of my code
;---( Read file )---
;
; Input
; AX - The first cluster entry value
; BX - FileBuffer (where to store the file)
ReadFile:
cmp ax, 0x0fff ; end of file?
jge EOF ; well if it is jump to EOF
call LBAtoCHS ; convert AX to CHS values
mov al, 1 ; sectors to read
call ReadChunk ; read the sector that this value is ( LBAtoCHS already set CHS values needed in correct registers and BX is the FILE_BUFF and al is sectors to read)
add bx, 0x200 ; increase bx with 512 bytes becouse we just read in that into it
push ax ; push AX onto stack
pop dx ; retrive AX from stack but into DX
add dx, dx ; multiply with 2 ( or actually dx + dx -> dx=5 5+5 )
add dx, ax ; multiply with 3 ( or actuallu dx + dx + ax -> AX=5 5+5+5 )
rcr dx, 1 ; this would divide with 2 (or multiply with 1.5)
; and it will also put a bit in carry flag if
pushf ; save carry flag for a while
mov ax, FAT_BUFF
add ax, dx ; now this would be the next value from the fat
popf
jc integer
shr ax, 4 ; it wasn't a whole integer
jmp ReadFile
integer:
and ax, 0x0fff
jmp ReadFile
Eof:
ret
bochs says I try to read a sector that is far beoyond the limit of the floppy size
I do as it say I should read the fat12 in the FAQ (if I got my assembly code right was a while since I coded assembly)
this is a pice of my code
;---( Read file )---
;
; Input
; AX - The first cluster entry value
; BX - FileBuffer (where to store the file)
ReadFile:
cmp ax, 0x0fff ; end of file?
jge EOF ; well if it is jump to EOF
call LBAtoCHS ; convert AX to CHS values
mov al, 1 ; sectors to read
call ReadChunk ; read the sector that this value is ( LBAtoCHS already set CHS values needed in correct registers and BX is the FILE_BUFF and al is sectors to read)
add bx, 0x200 ; increase bx with 512 bytes becouse we just read in that into it
push ax ; push AX onto stack
pop dx ; retrive AX from stack but into DX
add dx, dx ; multiply with 2 ( or actually dx + dx -> dx=5 5+5 )
add dx, ax ; multiply with 3 ( or actuallu dx + dx + ax -> AX=5 5+5+5 )
rcr dx, 1 ; this would divide with 2 (or multiply with 1.5)
; and it will also put a bit in carry flag if
pushf ; save carry flag for a while
mov ax, FAT_BUFF
add ax, dx ; now this would be the next value from the fat
popf
jc integer
shr ax, 4 ; it wasn't a whole integer
jmp ReadFile
integer:
and ax, 0x0fff
jmp ReadFile
Eof:
ret
bochs says I try to read a sector that is far beoyond the limit of the floppy size