Floppy Disc Driver Problem

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
Ferrarius
Member
Member
Posts: 69
Joined: Sun Oct 28, 2007 4:10 pm

Floppy Disc Driver Problem

Post by Ferrarius »

Hello,

I'm trying to get a basic floppy driver operational to allow me to read my Command Line from disk into memory. Now most parts of the driver work (recalibrate, seek, Activating/Deactivating motor), yet the actual read seems to fail. I have tried to fix the problem but I can't seem to find the problem. Maybe someone else does?

DMA code:

Code: Select all

.INIT:
mov	al,0x06		;DMA channel 2 Mask

out	0x0A,al		;Mask the Bastard



mov	al,0xFF

out	0xD8,al		;Set Master Flip-Flop



mov	eax,ebx

out	0x04,al		;low address of buffer

mov	al,ah

out	0x04,al		;high address of buffer



mov	al,0xFF

out	0xD8,al		;Length Master Flip-Flop


out	0x05,al		;Low count of Sector - 1



mov	al,0x01

out	0x05,al		;high count of sector - 1



mov	al,dl

mov	al,0x01

out	0x81,al		;Page Register number



mov	al,0x02

out	0x0a,al		;unmask the bastard

ret			;return to calling procedure


.READFLOPPY:
mov	al,0x06		;DMA channel 2 Mask

out	0x0A,al		;Mask the Bastard



mov	al,0x46		;Single Transfer, To Mem, CH2

out	0x0b,al		;output to port



mov	al,0x02

out	0x0a,al		;unmask the bastard

ret			;return to calling procedure
EBX is 0, so if I'm right this should put the buffer at 0x10000?

Floppy Read Function:

Code: Select all

.READ:
push	eax

push	ebx

push	ecx

push	edx

mov	al,'N'

call	[0x20028]



mov	dx,FD.FIFO	;Port Address

call	.CHREADY	;Check if FIFO is ready



mov	al,'9'

call	[0x20028]



mov	al,0x46		;Read Sector Command

out	dx,al



mov	al,0x00		;Disk 0

out	dx,al

out	dx,al		;Cylinder

out	dx,al		;Head



mov	al,bl		;Sector Number

out	dx,al



mov	al,0x02		;Sector = 512 bytes

out	dx,al		;SectorSize

mov al,bl
inc	al

out	dx,al		;Last Sector Of Track

mov	al,0x1B

out	dx,al		;Gap Length

mov	al,0xFF

out	dx,al		;Obsolete Hardware Requirement



call	.RSN

mov	ecx,0x07

.READFIN:

call	.RECEIVED

loop	.READFIN

mov	al,'M'

call	[0x20028]



pop	edx

pop	ecx

pop	ebx

pop	eax

ret
and the RSN and RECEIVED subs:

Code: Select all

.RSN:

mov	al,[FINT]

cmp	al,0xFF

jne	.SNI

mov	ax,FD.FIFO

mov	dx,ax

mov	al,'8'

call	[0x20028]

mov	al,0x08

call	.CHREADY

out	dx,al

mov	al,'Z'

call	[0x20028]

xor	al,al

mov	[FINT],al

ret

.CHREADY:

push	eax

push	edx

mov	dx,FD.DRIVE_CONTROLLER_STATUS

.CH:

in	al,dx

and	al,0xC0

cmp	al,0x80

jne	.CH



pop	edx

pop	eax

ret


.RECEIVED:

push	eax

push	edx

mov	dx,FD.DRIVE_CONTROLLER_STATUS

.RC:

in	al,dx

and	al,0xC0

cmp	al,0xC0

jne	.RC

mov	dx,FD.FIFO

in	al,dx

pop	edx

pop	eax

ret
Thanks in advance for any help

(call [0x20028] is a a system call)
Modular Interface Kernel With a lot of bugs ;)
System123
Member
Member
Posts: 196
Joined: Mon Jul 07, 2008 1:25 am

Re: Floppy Disc Driver Problem

Post by System123 »

Hi

I have not had an in depth look at your code yet, just a brief glance. So far it looks and sounds like your DMA set up might be wrong. Attached is my floppy driver code which I am busy finishing. The read works but the write is still buggy. It is coded in Pascal and I hope it is useful. I will see what I can put together in assembler.

[The extension pas has been deactivated and can no longer be displayed.]

Cheers
Gizmic OS
Currently - Busy with FAT12 driver and VFS
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: Floppy Disc Driver Problem

Post by Dex »

You can also take a look at mine http://dex4u.com/demos/FloppyDriver.zip
Its written with fasm.
Ferrarius
Member
Member
Posts: 69
Joined: Sun Oct 28, 2007 4:10 pm

Re: Floppy Disc Driver Problem

Post by Ferrarius »

Hello everyone. Thanks for the suggestions, after looking at your codes and extensively using the Bochs debugger I was able to fix the FDD, my screen now happily displays "Hello Floppy User" :). I don't know what was exactly wrong, probably a combination of something in the DMA Set up and in the function call.
Modular Interface Kernel With a lot of bugs ;)
Post Reply