Floppy driver without DMA?

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.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Floppy driver without DMA?

Post 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?
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Post 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
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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?
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Post 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
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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?
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Post 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
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Where do you find these things?
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Post 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
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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.
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Post 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
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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?
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Post 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
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Um.. that's a dud zip.

Why must this be so difficult! (reading and writing to floppy, that is)
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Post 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
Last edited by inflater on Sat Feb 24, 2007 6:20 am, edited 1 time in total.
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

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