Write to certain sectors of floppy

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
hazardoxide
Member
Member
Posts: 26
Joined: Thu Dec 13, 2007 12:31 pm

Write to certain sectors of floppy

Post 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
If bill gates had a dollar for everytime windows crashed...oh wait... he does.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post 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.. 8)

(If you want to know how to actually write bytes to a floppy image.. use your favourite programming languages file I/O routines..)
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
hazardoxide
Member
Member
Posts: 26
Joined: Thu Dec 13, 2007 12:31 pm

Post by hazardoxide »

but how do you write to the boot sector?
If bill gates had a dollar for everytime windows crashed...oh wait... he does.
User avatar
Red Shaya
Posts: 15
Joined: Wed Oct 03, 2007 4:21 pm
Contact:

Post 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 
The Bina OS - More of a challenge then an OS
The Eddie OS - OS for kids and for fun loving adults
Post Reply