Page 1 of 1

FDC Implementation

Posted: Sat Feb 23, 2008 2:08 pm
by DeepOS
I've already read the OSdev wiki about it, and the links that the wiki gives, but I can't implement the source code examples, for examlpe, this code:

http://bos.asmhackers.net/docs/floppy/d ... torial.txt

Can anyone give me a source code or a guide that explain me how I code the FDC???

Thanks.

Posted: Sat Feb 23, 2008 5:50 pm
by xyjamepa
Why don't you try this?
just search the forum :wink:

Posted: Sat Feb 23, 2008 5:55 pm
by Jef
download the source code of my OS.
It contains a FDC driver, if this helps you.

Posted: Sat Feb 23, 2008 11:23 pm
by astrocrep
That Mystran tutorial looks awesome....

I have been eyeing that for quiet some time... just not ready to start fdc coding yet.

Posted: Sun Feb 24, 2008 10:16 am
by Dex
If anyone need code for a none bios floppy driver in ASM, i have written a simple OS, that does nothing but goes to pmode and sets up a pmode floppy driver.
If so let me know and i will find it and upload it.

Posted: Sun Feb 24, 2008 6:54 pm
by os.hacker64
Dex wrote:If anyone need code for a none bios floppy driver in ASM, i have written a simple OS, that does nothing but goes to pmode and sets up a pmode floppy driver.
If so let me know and i will find it and upload it.
Are you working on another OS? Or just improving DexOS. From my look at DexOS, I wonder what you could do writing a Desktop OS. :D

Posted: Sun Feb 24, 2008 9:28 pm
by xyjamepa
@Dex:
Yes would you please?

Posted: Sun Feb 24, 2008 9:36 pm
by Dex
Linux give me everything i need in a desktop OS, But i am alway building electronics projects and robots etc, and i used to use Dos, but i got tied of the 1 MB limit and segmention, plus the low graphics.
So i tried to find a modern pmode Dos like OS, and the only thing that came close was the Xbox, so i decided to code my own Xbox type OS, along with a team of coders. That what Dex stands for "Dos EXtreme".
Now all my robots are controled by DexOS and i even program pic's with it.

Posted: Mon Feb 25, 2008 3:18 am
by jal
Dex wrote:Now all my robots are controled by DexOS and i even program pic's with it.
That is rather cool.


JAL

Posted: Mon Feb 25, 2008 9:32 am
by Dex
abuashraf wrote:@Dex:
Yes would you please?
Sure, here is the demo that boots to Pmode and sets up a Pmode fdd. http://www.dex4u.com/demos/FddDemo.zip

Also here is just the fdd driver part (same as the one in the above), but it is much better commentated, also there notes to go with the per-do code from the "Intel floppy controller" PDF.
http://www.dex4u.com/demos/FloppyDriver.zip

PS: If you want the write to floppy code, let me know and i will post it, as that demo, demos read floppy only, it 95% the same code as the write floppy.

Posted: Mon Feb 25, 2008 11:57 am
by xyjamepa
Dex wrote: PS: If you want the write to floppy code, let me know and i will post it, as that demo, demos read floppy only, it 95% the same code as the write floppy.
That would be great,thanks Dex.

Posted: Mon Feb 25, 2008 12:45 pm
by Dex
Just add this code, under the FddRead function

Code: Select all

 ;----------------------------------------------------;
 ; FddWrite               ; Pmode write  function ;
 ;----------------------------------------------------;
 ;                                                    ;
 ;   Input:                                           ;
 ;          CH  = Track/cylinder                      ;
 ;          CL  = Sector                              ;
 ;          DH  = Head                                ;
 ;          DL  = Drive (only A: drive used 00 )      ;
 ;                                                    ;
 ;  Output:                                           ;
 ;          AH  = Status                              ;
 ;          AL  = Sector number read                  ;
 ;          CF  = 0 If successful                     ;
 ;              = 1 If error                          ;
 ;                                             (100%) ;
 ;....................................................;

FddWrite:
	pushad
	and   dh,00000001b
	mov   [Head],dh
	shl   dh,2
	mov   [DriveHead],dh
	mov   [FddErrorStatus],0x04
	cmp   ch,0x51
	jae   FddWriteErrorT
	mov   [cTrack],ch
	cmp   cl,0x13
	jae   FddWriteErrorT
	mov   [Sector],cl
	mov   [FddMTimer],0
	and   [FddMotorTimer0n],0
	test  [MotorOn],1
	jnz   @f
	call  FddMotorOn
@@:
	mov   dx,CcrReg
	mov   al,00000000b
	out   dx,al
	mov   [FddErrorStatus],0x80
	;call  FddRecalibrate
	;jc    FddWriteError
	xor    ecx,ecx
	mov    cx,3					
@@:
	call  FddReadWriteSeek				
	jnc   @f
	loop  @b
	jmp   FddWriteErrorT
@@:
	mov   dx,MsReg
	in    al,dx
	test  al,00100000b
	jnz   FddWriteErrorT
	Call  Setup_DMA2_Write
;******************************
; 1. Write Sector Command
;******************************
	call  FdcSendByteReady
	jc    FddWriteErrorT
	mov   dx,DtReg
	mov   al,0xe5
	out   dx,al
;******************************
; 2. Drive
;******************************
	call  FdcSendByteReady
	jc    FddWriteErrorT
	mov   dx,DtReg
	mov   al,[DriveHead]
	out   dx,al
;******************************
; 3. Cylinder
;******************************
	call  FdcSendByteReady
	jc    FddWriteErrorT
	mov   dx,DtReg
	mov   al,[cTrack]				 
	out   dx,al
;******************************
; 4. Head
;******************************
	call  FdcSendByteReady
	jc    FddWriteErrorT
	mov   dx,DtReg
	mov   al,[Head]
	out   dx,al
;******************************
; 5. Sector
;******************************
	call  FdcSendByteReady
	jc    FddWriteErrorT
	mov   dx,DtReg
	mov   al,[Sector]				
	out   dx,al
;******************************
; 6. Sector Size
;******************************
	call  FdcSendByteReady
	jc    FddWriteErrorT
	mov   dx,DtReg
	mov   al,0x02
	out   dx,al
;******************************
; 7. Sectors to a track
;******************************
	call  FdcSendByteReady
	jc    FddWriteErrorT
	mov   dx,DtReg
	mov   al,0x12
	out   dx,al
;******************************
; 8. Gap Length
;******************************
	call  FdcSendByteReady
	jc    FddWriteErrorT
	mov   dx,DtReg
	mov   al,0x1B				       
	out   dx,al
;******************************
; 9. Data Length
;******************************
	call  FdcSendByteReady
	jc    FddWriteErrorT
	mov   dx,DtReg
	mov   al,0xFF
	out   dx,al
;******************************
; Wait floppy int
;******************************
	mov   [done],0
	call  WaitDone
	jc    FddWriteErrorT
	call  FdcGetByteReady				
	jc    FddWriteErrorT
	mov   dx,DtReg					
	in    al,dx
	mov   [ResultST0],al				
	call  FdcGetByteReady
	jc    FddWriteErrorT
	mov   dx,DtReg
	in    al,dx
	mov   [ResultST1],al
	call  FdcGetByteReady
	jc    FddWriteErrorT
	mov   dx,DtReg
	in    al,dx
	mov   [ResultST2],al
	call  FdcGetByteReady
	jc    FddWriteErrorT
	mov   dx,DtReg
	in    al,dx
	cmp   [cTrack],al
	jne    @f
	mov   [ResultC],al
@@:
	call  FdcGetByteReady
	jc    FddWriteErrorT
	mov   dx,DtReg
	in    al,dx
	mov   [ResultH],al
	call  FdcGetByteReady
	jc    FddWriteErrorT
	mov   dx,DtReg
	in    al,dx
	mov   [ResultR],al
	call  FdcGetByteReady
	jc    FddWriteErrorT
	mov   dx,DtReg
	in    al,dx
	mov   [ResultN],al
	test  [ResultST0],11000000b			
	jnz   FddWriteErrorT
	mov   [FddErrorStatus],0x00			
FddWriteSuccsessT:
	popad
	mov   ah,[FddErrorStatus]
	mov   al,[ResultR]
	clc
	ret
FddWriteErrorT:
	popad
	mov   ah,[FddErrorStatus]
	stc
	ret