Page 1 of 2

Floppy driver without DMA?

Posted: Sat Feb 24, 2007 3:48 am
by pcmattman
Hello all, I'm wanting to write a floppy driver but I don't want to use DMA (all the tutorials I've looked at have been so vague that I just give up on it).

Now the real question is, how can I read/write bytes to the floppy via IRQ 6?

Posted: Sat Feb 24, 2007 4:35 am
by inflater
IRQ 6 is INT 0Eh by BIOS.
You can access the primary floppy controller by ports 3F0-3F7 hexa, and if the PC is AT compatible, you can access the secondary FDC by ports 370-377 hexadecimal.
If you want these functions, ask me, i will try to translate these complicated functions to English language :lol:, but BIOS and INT 13 makes things a lot easier in real mode :D (you can access memory up to 4GB by unreal mode)

inflater

Posted: Sat Feb 24, 2007 4:53 am
by pcmattman
Hmmm... old version of OS was real mode, new version is PMode...

So I basically send a whole lot of commands to the floppy controller and it should do things for me?

Edit: not to sound like a google noob, but I can't find anything about programming the controller... help?

Posted: Sat Feb 24, 2007 5:31 am
by inflater
FDC should (if used right) process the commands, no? I don't see any problem... *if* you are using that FDC ports and not BIOS.

inflater

Posted: Sat Feb 24, 2007 5:36 am
by pcmattman
inflater wrote:FDC should (if used right) process the commands, no?
See, that's my problem at the moment... which commands do I send?

Posted: Sat Feb 24, 2007 5:58 am
by inflater
Translation:

//EDIT: Eww, the tables are corrupted... :(

3F2H Write: digital register input

┌7┬6┬5┬4┬3┬2┬1┬0┐
│D C B A│ │ │ │
└┬┴─┴─┴┬┴┬┴┬┴┬┴┬┘ bit
└──┬──┘ │ │ └─┴─ 0-1: disk (0-3, AT: 0-1)
│ │ └───── 2: 0 = FDC reset
│ └─────── 3: 1 = enable DMA and interrupts
└──────────── 4-7: spin up motor (AT: bits 6-7 not used)

3F4H Reading: main status register

┌7┬6┬5┬4┬3┬2┬1┬0┐
│ │ │ │ │D C B A│
└┬┴┬┴┬┴┬┴┬┴─┴─┴┬┘ bit
│ │ │ │ └─────┴─ 0: drive is busy (AT: bits 2-3 not used)
│ │ │ └───────── 4: 1 = FDC is busy (reading or writing in progr.)
│ │ └─────────── 5: 1 = non-DMA mode; 0 = DMA mode activated
│ └───────────── 6: direction of data transfer:
│ 1 = FDC ──► CPU
│ 0 = CPU ──► FDC
└─────────────── 7: status register:
1 = OK for data transfer

3F5H Reading/Writing: register of commands and data
0E6 h - Read data (sector) from diskette
──────────────────────────────────────────────────────
Command order:
0E6h
xxxx xHdd H - head ,d - drive
tttt tttt t - track
hhhh hhhh h - head
ssss ssss s - sector
xxxx xxll l - sector size ( 00 - 128B, 01 - 256B, 10 512B, 11 - 1KB )
eeee eeee e - Last sector on track
gggg gggg g - GAP size
vvvv vvvv v - transfer length ( 0ffh )
Returns:
1.Sb 0 Status byte 0
Bits :
7 6 5 4 3 2 1 0
┌──┬──┬──┬──┬──┬──┬──┬──┐
│Term │Se│Er│Nr│Hd│Drive│
└──┴──┴──┴──┴──┴──┴──┴──┘
Term - status of operation end 11 HW error ( unconnected )
10 bad command
01 cant finish
00 OK
Se - The "head standing up" is in progress
Er - Drive error
Nr - Not ready
Hd - Current selected head
Drive- Current drive

2.Sb 1 Status byte 1
Bity :
7 6 5 4 3 2 1 0
┌──┬──┬──┬──┬──┬──┬──┬──┐
│ET│0 │Tr│Or│0 │Se│Wp│Am│
└──┴──┴──┴──┴──┴──┴──┴──┘
ET - sector is above last sector ( EOT error)
Tr - data transfer error
Or - Too high transfer speed
Se - Error reading sector
Wp - Write-protected drive
Am - Address mark not found

3.Sb 2 Status byte 2
Bity :
7 6 5 4 3 2 1 0
┌──┬──┬──┬──┬──┬──┬──┬──┐
│0 │DD│CR│Tr│??│??│Bt│Am│
└──┴──┴──┴──┴──┴──┴──┴──┘
DD - DDAM found
CR - CRC error
Tr - Bad track identification
Bt - Bad track
Am - Address mark not found

4.Track
5.Head
6.Sector
7.Len

Posted: Sat Feb 24, 2007 6:01 am
by pcmattman
Where do you find these things?

Posted: Sat Feb 24, 2007 6:04 am
by inflater
AThelp, a little program I use in OS dev :D

But it is in czech language... If you want that program, just whistle and i will attach the program to this post. (phpBB atachments)

inflater

Posted: Sat Feb 24, 2007 6:06 am
by pcmattman
Hmmm... do you know of any pmode open-source floppy drivers that I could "borrow" code from.... I just really need to see how other people do it in pmode so that I can figure it out myself. So far my floppy driver code is:

Code: Select all

#include "mattise.h"

/**** revision 2 ****/

int floppy_flag = 1;

char* drive_types[6] =	{ "No floppy drive.",
				"360KB 5.25in floppy",
				"1.2MB 5.25in floppy",
				"720KB 3.5in floppy",
				"1.44MB 3.5in floppy",
				"2.88MB 3.5in floppy"
			};

void DetectFloppyDrives()
{
	unsigned char c;
	outportb( 0x70, 0x10 );
	c = inportb( 0x71 );

	unsigned char drive1;
	unsigned char drive2;
	drive1 = c >> 4;
	drive2 = c & 0xF;

	kputs( "Floppy 1: " ); kputs( drive_types[ drive1 ] );
	kputs( "\n" );
	kputs( "Floppy 2: " ); kputs( drive_types[ drive2 ] );
	kputs( "\n" );
}

// floppy IRQ handler
void FloppyHandler( struct regs* r )
{
	// reset the flag, say that we
	// have handled the interrupt
	// lets the initialization return
	floppy_flag = 0;
}

// reset the floppy disk
void ResetFloppy()
{
	// reset the drive
	outportb( 0x3F2, 0x00 );
	outportb( 0x3F7, 0x00 );
	outportb( 0x3F2, 0x0C );

	// set the flag
	floppy_flag = 1;

	// wait for the interrupt...
	while( floppy_flag == 1 );
}

// initializes the floppy
void InitFloppy()
{
	// install the handler
	irq_install_handler( 6, FloppyHandler );
}
But I really need to be able to read sectors in the least to be able to continue development.

Posted: Sat Feb 24, 2007 6:11 am
by inflater
Sorry, I dunno C++...
Maybe others will help you.

Anyway, I've posted AThelp. If you need help with it, just ask.

http://inflater.ic.cz/athelp.zip

inflater

Posted: Sat Feb 24, 2007 6:12 am
by pcmattman
It's actually C... you can't tell me you're writing your OS in asm... or is it in some other language?

Posted: Sat Feb 24, 2007 6:14 am
by inflater
Well, 50 percent 16-bit ASM (BIOS), my file system, boot sector and bootlader (sets up INT 30h, kernel functions), and 50 percent Borland Pascal 7.0 (16-bit too), the main kernel. My OS isnt pure unreal mode, it has just a special memory manager.

inflater

Posted: Sat Feb 24, 2007 6:17 am
by pcmattman
Um.. that's a dud zip.

Why must this be so difficult! (reading and writing to floppy, that is)

Posted: Sat Feb 24, 2007 6:19 am
by inflater
"dud zip" ? You mean dead zip? Well, try download again, it should be 902 kB long.
//EDIT: The zip works for me...

inflater

Posted: Sat Feb 24, 2007 6:20 am
by pcmattman
Well... that works now... I would say it's IE's fault, except that I'm using a web browser that I wrote so it sort of invalidates it... although it does use CHtmlView - so I can say it's Microsoft's fault.

Microsoft: the ultimate scapegoat!