Code: Select all
;----------------------------------------------------;
; Fdd seek ;
;----------------------------------------------------;
; ;
; Input: ;
; none. ;
; Output: ;
; ;
; (100%) ;
;....................................................;
FddReadWriteSeek:
pushad
mov al,[ResultC] ; put what track/cylinder we are at in al
cmp [cTrack],al ; is it the same,as we want
je FddSeekControllerSuccsess ; yes leave.
call FdcSendByteReady ; can we send a byte ?.
jc FddSeekControllerError ; Is CF 1, if so timeout error.
mov [Timer],1 ; 5 = 250us
mov [TimerOn],1 ; start couting
call WaitTimer ; wait for timer
; **** ISSUE A SEEK COMMAND ****
mov dx,DtReg ; DtReg = 0x3f5
mov al,0x0F ; Seek Command
out dx,al
call FdcSendByteReady ; can we send a byte ?.
jc FddSeekControllerError ; Is CF 1, if so timeout error.
mov [Timer],1 ; 5 = 250us
mov [TimerOn],1 ; start couting
call WaitTimer ; wait for timer
mov dx,DtReg ; DtReg = 0x3f5
mov al,[DriveHead] ; Drive # (00 = A)
out dx,al
call FdcSendByteReady ; can we send a byte ?.
jc FddSeekControllerError ; Is CF 1, if so timeout error.
mov [Timer],1 ; 5 = 250us
mov [TimerOn],1 ; start couting
call WaitTimer ; wait for timer
mov dx,DtReg ; DtReg = 0x3f5
mov al,[cTrack] ; Cylinder #
out dx,al
; **** WAIT FOR INTERRUPT ****
mov [done],0 ; we need to wait
call WaitDone ; for floppy int.
jc FddSeekControllerError ; jump to error exit,if timeout.
; **** ISSUE SENSE INTERRUPT STATUS COMMAND ****
call FdcSendByteReady ; can we send a byte ?.
jc FddSeekControllerError ; Is CF 1, if so timeout error.
mov [Timer],1 ; 5 = 250us
mov [TimerOn],1 ; start couting
call WaitTimer ; wait for timer
mov dx,DtReg ; DtReg = 0x3f5
mov al,0x08 ; Sense Interrupt Status Command
out dx,al
call FdcGetByteReady ; can we get a byte ?.
jc FddSeekControllerError ; Is CF 1, if so timeout error.
mov dx,DtReg ; Should read ST0 ,(DtReg = 0x3f5 )
in al,dx
mov ah,al ; save ST0 in ah
call FdcGetByteReady ; can we get a byte ?.
jc FddSeekControllerError ; Is CF 1, if so timeout error.
mov dx,DtReg ; Should read PCN ,(DtReg = 0x3f5 )
in al,dx
; mov al,FddErrorSeekFail
test ah,00100000b ; test sr0 is 0x20
jz FddSeekControllerError ; if not we have a error :-(.
test ah,10000000b ; test sr0 is 0x80
jnz FddSeekControllerError ; if not we have a error :-(.
FddSeekControllerSuccsess: ; succsess we hope :-)
popad
clc
ret
FddSeekControllerError: ; we have a error (blame M$)
popad
stc
ret
;----------------------------------------------------;
; FdcSendByteReady ;floppy control sendbyte ready ;
;----------------------------------------------------;
FdcSendByteReady:
push eax
push edx
mov [Timer],30 ; 20 = about 1 second,we use (1.5 seconds).
mov [TimerOn],1 ; start counting.
FdcSendByteReadyLoop:
mov al,[TimerOn] ; we test if
or al,al ; timeout is up yet?.
jz FdcSendByteReadyError ; if it is we exit,with error.
mov dx,MsReg ; check status reg
in al,dx
and al,11000000b
cmp al,10000000b ; are we ok to write
jnz FdcSendByteReadyLoop ; if not do another loop.
pop edx
pop eax
clc ; we end here if we write:-)
ret
FdcSendByteReadyError: ; we end up here if we run out of time:-(.
pop edx
pop eax
stc
ret
;----------------------------------------------------;
; FdcGetByteReady ;floppy control getbyte ready ;
;----------------------------------------------------;
FdcGetByteReady:
push eax
push edx
mov [Timer],30 ; 20 = about 1 second,we use (1.5 seconds).
mov [TimerOn],1 ; start couting.
FdcGetByteReadyLoop:
mov al,[TimerOn] ; we test if
or al,al ; timeout is up yet?.
jz FdcGetByteReadyError ; if it is we exit,with error.
mov dx,MsReg ; check status reg
in al,dx
and al,11000000b
cmp al,11000000b ; are we ok to read
jnz FdcGetByteReadyLoop ; if not do another loop.
pop edx
pop eax
clc ; we end here if we can getbyte:-)
ret
FdcGetByteReadyError: ; we end up here if we run out of time:-(.
pop edx
pop eax
stc
ret
;----------------------------------------------------;
; Fdd motor off ;TURNS MOTOR OFF WITH DELAY. ;
;----------------------------------------------------;
Fdd_motor_off:
mov dx,DorReg ; DorReg = 0x3F2
mov al,0
out dx,al
mov [MotorOn],0 ; mov the on bit 0,this means motor off.
ret
;----------------------------------------------------;
; Fdd Motor On ;TURNS MOTOR ON WITH DELAY. ;
;----------------------------------------------------;
FddMotorOn:
mov dx,DorReg ; DorReg = 0x3F2
mov al,00011100b ; motor 0 on, DMA enabled, no reset, drive A:(00011100b)
out dx,al
mov [Timer],20 ; 5 = 250us
mov [TimerOn],1 ; start couting
call WaitTimer ; wait for timer
mov [MotorOn],1 ; mov the on bit 1
ret
It may help you to fix yours, note the comments go with the intel floppy controler pdf perdo code.
Also note its hook into the fdd int.
And motor needs spin up time.