Page 1 of 1

INT 13 problem writing sector 0

Posted: Fri Feb 04, 2011 11:33 am
by Holus
I have a problem with INT 13 (or int 13 with me)
I want to format a disk just my writing Sector 0 and Sector 1 of a disk.

But it doesn't work like I want.
It doesn't work at all!!

First i fill the [MyFILE] array and that works fine.
But when i use the code below it doesn't write Sector 0 and 1.

This test is a little bit simpler and just Write it to the disk that's inserted.
SO DON'T TRY THIS AT HOME,... Just look at the code.

Code: Select all

	MOV AX,0301h
	MOV BX,MyFILE
	MOV CX,2
	MOV DX,0h   (or 80h)
	INT 13h
	JC ERROR
I see the disk flashing but that is it.

I wanted it to do like in DEBUG.EXE
w 0 2 0 2
does!

Re: INT 13 problem writing sector 0

Posted: Fri Feb 04, 2011 3:41 pm
by andymc
Holus wrote:I have a problem with INT 13 (or int 13 with me)

Code: Select all

	MOV AX,0301h
	MOV BX,MyFILE
	MOV CX,2
	MOV DX,0h   (or 80h)
	INT 13h
	JC ERROR
AH = 03
AL = number of sectors to write (1-128 dec.)
CH = track/cylinder number (0-1023 dec.)
CL = sector number (1-17 dec., see below)
DH = head number (0-15 dec.)
DL = drive number (0=A:, 1=2nd floppy, 80h=drive 0, 81h=drive 1)
ES:BX = pointer to buffer

Looks like you're actually writing the second sector in this code example.

In any case, remember the sector number is 1-based, so CX should contain 1 to write the first sector.

Re: INT 13 problem writing sector 0

Posted: Fri Feb 04, 2011 8:48 pm
by Chandra
Holus wrote:I have a problem with INT 13 (or int 13 with me)
I want to format a disk just my writing Sector 0 and Sector 1 of a disk.

But it doesn't work like I want.
It doesn't work at all!!

First i fill the [MyFILE] array and that works fine.
But when i use the code below it doesn't write Sector 0 and 1.

This test is a little bit simpler and just Write it to the disk that's inserted.
SO DON'T TRY THIS AT HOME,... Just look at the code.

Code: Select all

	MOV AX,0301h
	MOV BX,MyFILE
	MOV CX,2
	MOV DX,0h   (or 80h)
	INT 13h
	JC ERROR
I see the disk flashing but that is it.

I wanted it to do like in DEBUG.EXE
w 0 2 0 2
does!
There's nothing like 'Sector 0' while you are addressing the disk in 'CHS' mode.In this case, sector no. Starts from 1 and not 0.

In addition to this, you cannot format the disk by simply erasing the first two sectors.This will create a RAW disk. Therefore based on the filesystem you want to initialize on the disk, you may need to re-initialize the 'Root Directory' and/ or the 'Directory Table'.

Other things told by Andy.

Best Regards,
Chandra

Re: INT 13 problem writing sector 0

Posted: Sat Feb 05, 2011 5:43 am
by Holus
I use this code (the USB light flashing)
Then I check the disk after this operation by using debug.exe

L 0 2 0 1
L 0 2 0 2
or
L 0 2 0 3

Nothing seems to be changed.

Do I have to do something after using int 13h function 3h?
Resetting the drive or give some other instruction to actually write the sectors??

Re: INT 13 problem writing sector 0

Posted: Sat Feb 05, 2011 7:08 am
by M2004
Holus: Are you setting up the es segment properly?


regards
mac2004

Re: INT 13 problem writing sector 0

Posted: Sat Feb 05, 2011 8:01 am
by Holus
I hope so,...

PUSH CS
POP ES

When I set "BILL GATES IS A SUCKER$" in MyFILE it display like it should.

Re: INT 13 problem writing sector 0

Posted: Sat Feb 05, 2011 9:21 am
by andymc
Holus wrote:I hope so,...

PUSH CS
POP ES

When I set "BILL GATES IS A SUCKER$" in MyFILE it display like it should.
That might not be right. How have you declared your segments?

However, even if your ES isn't quite right, something should get written. It just might not be what you expect. If the light goes on, though, that suggests that something is getting written somewhere.

Re: INT 13 problem writing sector 0

Posted: Sat Feb 05, 2011 9:40 pm
by guilherme
Ok (starting phrases with Ok is my personal mark...), there's two basical things:
1: the buffer used by int 13h, both for reading and writing is located at es:bx (the absolute address of ES:BX is ES*010h+BX, in other words, if ES is 01001h and BX 01010h, the addressed memory is 011020h = 10010h + 1010h.)
2: in the CHS disk addressing, cl = 1 is the first sector, so the first sector of the entire disk (boot secotr) is dh = 0, ch = 0, cl = 1.

And only for remember, to erase the disk with no chances of recovering the previous data, you must set ALL sectors to zero (pointing to a buffer with 512 zeroes).

Use ralf's brown interrupt list to find out more about int 13h, for me it's the most confiable source of interrupt data, because this have data collected from old 16-bit computer to the modern 64-bit computers.

Re: INT 13 problem writing sector 0

Posted: Sun Feb 06, 2011 3:04 pm
by guilherme
The data won't be recoverable using the original drive of the disk if you has done a zero-fill on it. The only way to recover the data in a disk that has been "zero-filled" is using a analogic analysis, analysing the magnetic value of each bit, comparing it with the ideal magnetic intensity: the difference between ideal magnetic intensity and the current one is increased, and may reveal the previous bit value.
In that case, you must do something like writing random values to each sector of the disk, and then zero-fill it.