INT 13 problem writing sector 0

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
User avatar
Holus
Member
Member
Posts: 51
Joined: Thu Jan 27, 2011 5:57 pm

INT 13 problem writing sector 0

Post 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!
Computer says NOOOO
User avatar
andymc
Member
Member
Posts: 31
Joined: Tue Feb 01, 2011 6:18 pm
Location: London, UK
Contact:

Re: INT 13 problem writing sector 0

Post 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.
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: INT 13 problem writing sector 0

Post 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
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
User avatar
Holus
Member
Member
Posts: 51
Joined: Thu Jan 27, 2011 5:57 pm

Re: INT 13 problem writing sector 0

Post 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??
Computer says NOOOO
M2004
Member
Member
Posts: 65
Joined: Sun Mar 07, 2010 2:12 am

Re: INT 13 problem writing sector 0

Post by M2004 »

Holus: Are you setting up the es segment properly?


regards
mac2004
User avatar
Holus
Member
Member
Posts: 51
Joined: Thu Jan 27, 2011 5:57 pm

Re: INT 13 problem writing sector 0

Post by Holus »

I hope so,...

PUSH CS
POP ES

When I set "BILL GATES IS A SUCKER$" in MyFILE it display like it should.
Computer says NOOOO
User avatar
andymc
Member
Member
Posts: 31
Joined: Tue Feb 01, 2011 6:18 pm
Location: London, UK
Contact:

Re: INT 13 problem writing sector 0

Post 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.
guilherme
Member
Member
Posts: 35
Joined: Mon Jan 31, 2011 6:58 am
Location: Brasil

Re: INT 13 problem writing sector 0

Post 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.
guilherme
Member
Member
Posts: 35
Joined: Mon Jan 31, 2011 6:58 am
Location: Brasil

Re: INT 13 problem writing sector 0

Post 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.
Post Reply