Page 1 of 1
Write to certain sectors of floppy
Posted: Tue Dec 25, 2007 9:00 pm
by hazardoxide
how do i write files to certain sectors of a floppy? like grub and the kernel and stuff? I know bootloaders must go on cyl 0 head 0 sec 1, how do i write a file to that? like the prog in emu8086, only to a real floppy.
thanks
Posted: Tue Dec 25, 2007 11:26 pm
by Brynet-Inc
Let's think this though...
A sector is 512 bytes, 1 sector is used... so you have 2879 sectors available...
Instead of troubling yourself with such basic math.. consider a file system..
(
If you want to know how to actually write bytes to a floppy image.. use your favourite programming languages file I/O routines..)
Posted: Tue Dec 25, 2007 11:35 pm
by hazardoxide
but how do you write to the boot sector?
Posted: Wed Dec 26, 2007 5:46 am
by Red Shaya
here is a sample "read disk" code.
Just replace INT 13 AH=02 with INT 13 AH=03 to make it a "Write disk" code.
Also consider the following page for reference
http://www.ctyme.com/intr/rb-0608.htm
Code: Select all
PUSH CS
POP DS
MOV CX,5
XOR AH,AH
.Reset_disk
INT 13
JNC .Read_disk
LOOP .Reset_disk ; retry for 5 times
; Print a reset error message
MOV SI, ResetErrorMsg
CALL PrintStr ; print the error message
JMP .Stop
.Read_disk
MOV AH,02
MOV AL,SectNumber
MOV BX,Stage2Address
MOV CX,0001 ; read from cylinder #1
XOR DX,DX ; Read from floppy (Disk 0)
INT 13
JNC .RunStage2
MOV SI,ReadFailMsg
CALL PrintStr ; Print the read error message
.Stop
HLT
.RunStage2
JMP Stage2Address
.PrintStr
PUSH BX
PUSH AX
MOV AH,0E
MOV BX,0007
LODSB
.RdChr
JZ .EndStr
INT 10
JMP .RdChr
.EndStr
POP AX
POP BX
RET