How the floppy drive works?

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
thinklogic

How the floppy drive works?

Post by thinklogic »

Hi
i just join this forum
i wish to write my own OS and i guess i want to start it from creating a floppy disk boot copier like *(fdimage).

i can program in asm but i don't know how the floppy drive works

i already wrote the code but i heard loud sound when my program copy the data to floppy disk.

i put the data into floppy disk in this order
i copy the data into floppy disk SECTOR BY SECTOR.

eg. (*this is imaginary code for explanation purpose)

Code: Select all

; variable declaration
; ====================
$track???= 0 ;(accept value 0 to 79)
$head???= 0 ;(accept value 0 or 1)
$sector???= 1 ;(accept value from 1 to 18)

; convert submitted param into number and fill it into variables
; valid $track, $head and $sector values
; ==============================================================

; this is how i put the data into disk
; ====================================
for(!eof) {
???if($sector == 19) {
??????$head???+= 1;
??????$sector???= 0;
???} else $sector += 1;

???if($head == 2) {
??????$head???= 0;
??????$track???+= 1;
???}
???
???if($track == 80) exit();
???
???$floppyLocation = $track, $head, $sector;
???copy($floppyLocation, $currentBuffer512Byte); (interrupt 13h with function 3h)
}
i am using int 13h function 3h to write my buffer into floppy disk.
so CH (Track Number) will increase value from 0 to 79
CL (Sector Number) will increase value from 1 to 18 and
DH (Head Number) will have 0 or 1.

my code will put the data straight away to the floppy disk once it reads from
the provided file. i wonder, should i park the floppy writer arm somewhere before i use it or ... ? coz i heard loud sound when my code runs and i not really yet wish to burn my floppy drive.


care to tell me where is wrong?



sincerely,
ThinkLogic.
Therx

Re:How the floppy drive works?

Post by Therx »

Copying sector by sector will be slow and may be the cause of the noise. I think there is a int 13h function to write whole tracks at a time...

Pete
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:How the floppy drive works?

Post by Brendan »

Hi,

Just wondering if this is a typing error:
thinklogic wrote:

Code: Select all

for(!eof) {
???if($sector == 19) {
??????$head???+= 1;
??????$sector???= 0;
???} else $sector += 1;
It should be "$sector = 1;" in there...

This wouldn't explain your noise though - it'd give a "bad sector" error when the BIOS can't find sector 0.

Apart from this your imaginary code looks good :)
thinklogic wrote: care to tell me where is wrong?
I expect the problem would be in the real code, rather than in the imaginary code. I assume you've got a little bit of inline assembly that calls the BIOS - perhaps you could add some parameter checking before doing the "int 0x13"? Example:

Code: Select all

     cmpb $0,%%cl
L1:  je L1
     cmpb $18,%%cl
L2:  ja L2
     cmpb $80,%%ch
L3:  jb L3
     cmpb $1,%%dh
L4:  ja L4
     int $0x13
Other possibilities include using a floppy disk that isn't formatted or has bad sectors. That could account for 'normal' loud noises only though (not explosions that make your ears bleed or something that sounds like the earth splitting in two ;) )

It is possible (but not generally recommended) to remove the floppy disk drive from the computer, remove it's protective metal cover and watch the floppy writer arm to see what it's doing to make your noise. Make sure you follow anti-static precautions though (keep everything earthed and discharge yourself)..

Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
thinklogic

Re:How the floppy drive works?

Post by thinklogic »

the idea to copy sector by sector is to obtain the last Track Head and Sector values.

eg.
Let say i got a file named a.img sized 1,024 bytes and i wanna write it into floppy disk.

D:\my writer\writer.exe a.img 4 1 5
// so the track is 4, head is 1 and sector is 5
// and after finish it will tell the user the next THS to write
// eg
Writer Job Completed...
Next Begin Track -> Head -> Sector = 4 -> 1 -> 7

the idea is to copy OS file into the floppy disk separately

let say my OS have 4 assembled FASM file.
boot.com
error.com
inout.com
args.com

so i will copy the boot.com to T.H.S => 0.0.1
and error.com => 4.0.1
and inout.com => 6.0.1
and args.com => 8.0.1

and boot.com will then load the remain files (error,inout,args) separately into memory (coz i know where they are located in the OS * i hardcode them into boot.com)

em. if i combine them together in one file, i wonder how can i know what their (THS) values inside the floppy disk?

another reason why i wanna do it this way because i can update the file separately

let say i update inout.com, so i just need to write
D:\my writer\writer.exe inout.com 4 1 5


sincerely
ThinkLogic
thinklogic

Re:How the floppy drive works?

Post by thinklogic »

It should be "$sector = 1;" in there...
yup, ya are right, it is a typing error. :(

yup i do check the param value before using the int 13h
and assure the THS value is valid otherwise will send them to error notice.
Post Reply