kolibrios/kernel/trunk/blkdev/flp_drv.inc
msu-se d5c0fed779 moving to kernel directory
git-svn-id: svn://kolibrios.org@2 a494cfbc-eb01-0410-851d-a64ba20cac60
2005-10-07 04:39:30 +00:00

686 lines
21 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;**********************************************************
; <EFBFBD>¥¯®á।á⢥­­ ï à ¡®â  á ª®­â஫«¥à®¬ £¨¡ª®£® ¤¨áª 
;**********************************************************
; €¢â®à ¨á室­®£® ⥪áâ  Šã« ª®¢ ‚« ¤¨¬¨à ƒ¥­­ ¤ì¥¢¨ç.
; €¤ ¯â æ¨ï ¨ ¤®à ¡®âª  Mario79
fdd_read_and_write:
pusha
read_sector:
cmp eax,1
jne write_sector
call save_HTS_values
call flp_readsector
call give_back_application_data
jmp fdd_read_end
write_sector:
cmp eax,2
jne fdd_read_end
call save_HTS_values
call take_data_from_application
call flp_writesector
fdd_read_end:
popa
ret
save_HTS_values:
mov [FDD_Sector],bl
mov [FDD_Head],bh
shr ebx,16
mov [FDD_Track],bl
mov [FDD_Type],bh
ret
give_back_application_data: ; ¯¥à¥á« âì ¯à¨«®¦¥­¨î
mov edi,[3010h]
mov edi,[edi+10h]
add edi,ecx
give_back_application_data_1:
mov esi,0xD000 ;FDD_DataBuffer ;0x40000
xor ecx,ecx
mov cx,128
cld
rep movsd
ret
take_data_from_application: ; ¢§ïâì ¨§ ¯à¨«®¦¥­¨ï
mov esi,[3010h]
mov esi,[esi+10h]
add esi,ecx
take_data_from_application_1:
mov edi,0xD000 ;FDD_DataBuffer ;0x40000
xor ecx,ecx
mov cx,128
cld
rep movsd
ret
flp_initialization:
; “áâ ­®¢¨âì ­®¢ë© ®¡à ¡®â稪 ¯à¥à뢠­¨ï <EFBFBD>ƒŒ„
call SetUserInterrupts
; ‚ª«îç¨âì ¬®â®à ¤¨áª®¢®¤ 
call FDDMotorON
; ˆ­¨æ¨ «¨§¨à®¢ âì ¯¥à¥¬¥­­ë¥
; mov [FDD_Track],0
; mov [FDD_Head],0
; mov [FDD_Sector],1
; <EFBFBD>஢¥á⨠४ «¨¡à®¢ªã ¨ ¯®¨áª ­ã«¥¢®© ¤®à®¦ª¨
call RecalibrateFDD
call SeekTrack
ret
flp_readsector:
call flp_initialization
; <EFBFBD>à®ç¨â âì ᥪâ®à
call ReadSectWithRetr
; call ReadSector
; cmp [FDC_Status],0
; jne @@SectorNotFound
mov [fdc_irq_func],fdc_null
; call FDDMotorOFF
ret
flp_writesector:
call flp_initialization
; ‡ ¯¨á âì ᥪâ®à
call WriteSectWithRetr
; call WriteSector
; cmp [FDC_Status],0
; jne @@SectorNotFound
mov [fdc_irq_func],fdc_null
; call FDDMotorOFF
ret
@@DiskNotFound:
ret
@@SectorNotFound:
ret
; Š®¤ë § ¢¥à襭¨ï ®¯¥à æ¨¨ á ª®­â஫«¥à®¬ (FDC_Status)
FDC_Normal equ 0 ;­®à¬ «ì­®¥ § ¢¥à襭¨¥
FDC_TimeOut equ 1 ;®è¨¡ª  â ©¬- ãâ 
FDC_DiskNotFound equ 2 ;¢ ¤¨áª®¢®¤¥ ­¥â ¤¨áª 
FDC_TrackNotFound equ 3 ;¤®à®¦ª  ­¥ ­ ©¤¥­ 
FDC_SectorNotFound equ 4 ;ᥪâ®à ­¥ ­ ©¤¥­
; Œ ªá¨¬ «ì­ë¥ §­ ç¥­¨ï ª®®à¤¨­ â ᥪâ®à  (§ ¤ ­­ë¥
; §­ ç¥­¨ï ᮮ⢥âáâ¢ãîâ ¯ à ¬¥âà ¬ áâ ­¤ àâ­®£®
; âà¥å¤î©¬®¢®£® £¨¡ª®£® ¤¨áª  ®¡ê¥¬®¬ 1,44 Œ¡)
MAX_Track equ 79
MAX_Head equ 1
MAX_Sector equ 18
; ‘ç¥â稪 ⨪®¢ â ©¬¥à 
TickCounter dd ?
; Š®¤ § ¢¥à襭¨ï ®¯¥à æ¨¨ á ª®­â஫«¥à®¬ <EFBFBD>ƒŒ„
FDC_Status DB ?
; ”« £ ¯à¥à뢠­¨ï ®â <EFBFBD>ƒŒ„
FDD_IntFlag DB ?
; Œ®¬¥­â ­ ç «  ¯®á«¥¤­¥© ®¯¥à æ¨¨ á <EFBFBD>ƒŒ„
FDD_Time DD ?
; <EFBFBD>®¬¥à ¤¨áª®¢®¤ 
FDD_Type db 0
; Š®®à¤¨­ âë ᥪâ®à 
FDD_Track DB ?
FDD_Head DB ?
FDD_Sector DB ?
; <EFBFBD>«®ª १ã«ìâ â  ®¯¥à æ¨¨
FDC_ST0 DB ?
FDC_ST1 DB ?
FDC_ST2 DB ?
FDC_C DB ?
FDC_H DB ?
FDC_R DB ?
FDC_N DB ?
; ‘ç¥â稪 ¯®¢â®à¥­¨ï ®¯¥à æ¨¨ ç⥭¨ï
ReadRepCounter DB ?
; ‘ç¥â稪 ¯®¢â®à¥­¨ï ®¯¥à æ¨¨ ४ «¨¡à®¢ª¨
RecalRepCounter DB ?
; Ž¡« áâì ¯ ¬ï⨠¤«ï åà ­¥­¨ï ¯à®ç¨â ­­®£® ᥪâ®à 
;FDD_DataBuffer: times 512 db 0 ;DB 512 DUP (?)
fdd_motor_status db 0
timer_fdd_motor dd 0
;*************************************
;* ˆ<EFBFBD>ˆˆˆ‡€ˆŸ <EFBFBD>…†ˆŒ€ <EFBFBD><EFBFBD> „‹Ÿ <EFBFBD>ƒŒ„ *
;*************************************
Init_FDC_DMA:
pushad
mov al,0
out 0x0c,al ; reset the flip-flop to a known state.
mov al,6 ; mask channel 2 so we can reprogram it.
out 0x0a,al
mov al,[dmamode] ; 0x46 -> Read from floppy - 0x4A Write to floppy
out 0x0b,al
mov al,0
out 0x0c,al ; reset the flip-flop to a known state.
mov eax,0xD000
out 0x04,al ; set the channel 2 starting address to 0
shr eax,8
out 0x04,al
shr eax,8
out 0x81,al
mov al,0
out 0x0c, al ; reset flip-flop
mov al, 0xff ;set count (actual size -1)
out 0x5, al
mov al,0x1 ;[dmasize] ;(0x1ff = 511 / 0x23ff =9215)
out 0x5,al
mov al,2
out 0xa,al
popad
ret
;***********************************
;* ‡€<EFBFBD>ˆœ <EFBFBD>€‰ <EFBFBD>Ž<EFBFBD> „€<EFBFBD><EFBFBD> FDC *
;* <EFBFBD> à ¬¥âàë: *
;* AL - ¢ë¢®¤¨¬ë© ¡ ©â. *
;***********************************
FDCDataOutput:
; pusha
push ax cx dx
mov AH,AL ;§ ¯®¬­¨âì ¡ ©â ¢ AH
; ‘¡à®á¨âì ¯¥à¥¬¥­­ãî á®áâ®ï­¨ï ª®­â஫«¥à 
mov [FDC_Status],FDC_Normal
; <EFBFBD>஢¥à¨âì £®â®¢­®áâì ª®­â஫«¥à  ª ¯à¨¥¬ã ¤ ­­ëå
mov DX,3F4h ;(¯®àâ á®áâ®ï­¨ï FDC)
xor CX,CX ;ãáâ ­®¢¨âì áç¥â稪 â ©¬- ãâ 
@@TestRS:
in AL,DX ;¯à®ç¨â âì ॣ¨áâà RS
and AL,0C0h ;¢ë¤¥«¨âì à §àï¤ë 6 ¨ 7
cmp AL,80h ;¯à®¢¥à¨âì à §àï¤ë 6 ¨ 7
je @@OutByteToFDC
loop @@TestRS
; Žè¨¡ª  â ©¬- ãâ 
mov [FDC_Status],FDC_TimeOut
jmp @@End_5
; ‚뢥á⨠¡ ©â ¢ ¯®àâ ¤ ­­ëå
@@OutByteToFDC:
inc DX
mov AL,AH
out DX,AL
@@End_5:
; popa
pop dx cx ax
ret
;******************************************
;* <EFBFBD><EFBFBD>Ž—ˆœ <EFBFBD>€‰ ˆ‡ <EFBFBD>Ž<EFBFBD> „€<EFBFBD><EFBFBD> FDC *
;* <EFBFBD>à®æ¥¤ãà  ­¥ ¨¬¥¥â ¢å®¤­ëå ¯ à ¬¥â஢. *
;* ‚ë室­ë¥ ¤ ­­ë¥: *
;* AL - áç¨â ­­ë© ¡ ©â. *
;******************************************
FDCDataInput:
push ECX
push DX
; ‘¡à®á¨âì ¯¥à¥¬¥­­ãî á®áâ®ï­¨ï ª®­â஫«¥à 
mov [FDC_Status],FDC_Normal
; <EFBFBD>஢¥à¨âì £®â®¢­®áâì ª®­â஫«¥à  ª ¯¥à¥¤ ç¥ ¤ ­­ëå
mov DX,3F4h ;(¯®àâ á®áâ®ï­¨ï FDC)
xor CX,CX ;ãáâ ­®¢¨âì áç¥â稪 â ©¬- ãâ 
@@TestRS_1:
in AL,DX ;¯à®ç¨â âì ॣ¨áâà RS
and AL,0C0h ;¢ë¤«¨âì à §àï¤ë 6 ¨ 7
cmp AL,0C0h ;¯à®¢¥à¨âì à §àï¤ë 6 ¨ 7
je @@GetByteFromFDC
loop @@TestRS_1
; Žè¨¡ª  â ©¬- ãâ 
mov [FDC_Status],FDC_TimeOut
jmp @@End_6
; ‚¢¥á⨠¡ ©â ¨§ ¯®àâ  ¤ ­­ëå
@@GetByteFromFDC:
inc DX
in AL,DX
@@End_6: pop DX
pop ECX
ret
;*********************************************
;* Ž<EFBFBD><EFBFBD><EFBFBD>ŽˆŠ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˆŸ Ž’ ŠŽ<EFBFBD><EFBFBD>Ž<EFBFBD> <EFBFBD>ƒŒ„ *
;*********************************************
FDCInterrupt:
; <EFBFBD> §à¥è¨âì ¯à¥à뢠­¨ï
; sti
; push AX
; “áâ ­®¢¨âì ä« £ ¯à¥à뢠­¨ï
mov [FDD_IntFlag],1
; <EFBFBD>®á« âì ª®¬ ­¤ã EOI ª®­â஫«¥àã ¯à¥à뢠­¨©
; mov AL,20h
; out 20h,AL
; pop AX
ret
;******************************************
;* <EFBFBD>Žˆœ <EFBFBD>Ž Ž<EFBFBD><EFBFBD><EFBFBD>ŽˆŠ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˆ *
;* <EFBFBD>ƒŒ„ *
;******************************************
SetUserInterrupts:
mov [fdc_irq_func],FDCInterrupt
ret
;*******************************************
;* Ž†ˆ„€<EFBFBD>ˆ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˆŸ Ž’ ŠŽ<EFBFBD><EFBFBD>Ž<EFBFBD> <EFBFBD>ƒŒ„ *
;*******************************************
WaitFDCInterrupt:
pusha
; ‘¡à®á¨âì ¡ ©â á®áâ®ï­¨ï ®¯¥à æ¨¨
mov [FDC_Status],FDC_Normal
; ‘¡à®á¨âì ä« £ ¯à¥à뢠­¨ï
mov [FDD_IntFlag],0
; Ž¡­ã«¨âì áç¥â稪 ⨪®¢
mov eax,[timer_ticks]
mov [TickCounter],eax
; Ž¦¨¤ âì ãáâ ­®¢ª¨ ä« £  ¯à¥à뢠­¨ï <EFBFBD>ƒŒ„
@@TestRS_2:
cmp [FDD_IntFlag],0
jnz @@End_7 ;¯à¥à뢠­¨¥ ¯à®¨§®è«®
mov eax,[timer_ticks]
sub eax,[TickCounter]
cmp eax,50 ;25 ;5 ;®¦¨¤ âì 5 ⨪®¢
jb @@TestRS_2
; jl @@TestRS_2
; Žè¨¡ª  â ©¬- ãâ 
mov [FDC_Status],FDC_TimeOut
; mov [flp_status],0
@@End_7: popa
ret
;*********************************
;* ‚Š‹ž—ˆ’œ ŒŽŽ<EFBFBD> „ˆ‘ŠŽ‚Ž„€ "A:" *
;*********************************
FDDMotorON:
pusha
; cmp [fdd_motor_status],1
; je fdd_motor_on
mov al,[flp_number]
cmp [fdd_motor_status],al
je fdd_motor_on
; <EFBFBD>ந§¢¥á⨠á¡à®á ª®­â஫«¥à  <EFBFBD>ƒŒ„
mov DX,3F2h ;¯®àâ ã¯à ¢«¥­¨ï ¤¢¨£ â¥«ï¬¨
mov AL,0
out DX,AL
; ‚ë¡à âì ¨ ¢ª«îç¨âì ¬®â®à ¤¨áª®¢®¤ 
cmp [flp_number],1
jne FDDMotorON_B
; call FDDMotorOFF_B
mov AL,1Ch ; Floppy A
jmp FDDMotorON_1
FDDMotorON_B:
; call FDDMotorOFF_A
mov AL,2Dh ; Floppy B
FDDMotorON_1:
out DX,AL
; Ž¡­ã«¨âì áç¥â稪 ⨪®¢
mov eax,[timer_ticks]
mov [TickCounter],eax
; Ž¦¨¤ âì 0,5 á
@@dT:
mov eax,[timer_ticks]
sub eax,[TickCounter]
cmp eax,50 ;10
jb @@dT
cmp [flp_number],1
jne fdd_motor_on_B
mov [fdd_motor_status],1
jmp fdd_motor_on
fdd_motor_on_B:
mov [fdd_motor_status],2
fdd_motor_on:
call save_timer_fdd_motor
popa
ret
;*****************************************
;* Ž•<EFBFBD><EFBFBD><EFBFBD>ˆ “Š€‡€’…‹Ÿ <EFBFBD>…Œ…<EFBFBD>ˆ *
;*****************************************
save_timer_fdd_motor:
mov eax,[timer_ticks]
mov [timer_fdd_motor],eax
ret
;*****************************************
;* <EFBFBD><EFBFBD>Ž<EFBFBD>Š€ ‡€„…<EFBFBD>†Šˆ Šž—…<EFBFBD>ˆŸ ŒŽŽ<EFBFBD> *
;*****************************************
check_fdd_motor_status:
cmp [fdd_motor_status],0
je end_check_fdd_motor_status
mov eax,[timer_ticks]
sub eax,[timer_fdd_motor]
cmp eax,500
jb end_check_fdd_motor_status
call FDDMotorOFF
mov [fdd_motor_status],0
end_check_fdd_motor_status:
ret
;**********************************
;* ‚›Š‹ž—ˆ’œ ŒŽŽ<EFBFBD> „ˆ‘ŠŽ‚Ž„€ *
;**********************************
FDDMotorOFF:
push AX
push DX
cmp [flp_number],1
jne FDDMotorOFF_1
call FDDMotorOFF_A
jmp FDDMotorOFF_2
FDDMotorOFF_1:
call FDDMotorOFF_B
FDDMotorOFF_2:
pop DX
pop AX
; á¡à®á ä« £®¢ ª¥è¨à®¢ ­¨ï ¢ á¢ï§¨ á ãáâ à¥¢ ­¨¥¬ ¨­ä®à¬ æ¨¨
mov [root_read],0
mov [flp_fat],0
ret
FDDMotorOFF_A:
mov DX,3F2h ;¯®àâ ã¯à ¢«¥­¨ï ¤¢¨£ â¥«ï¬¨
mov AL,0Ch ; Floppy A
out DX,AL
ret
FDDMotorOFF_B:
mov DX,3F2h ;¯®àâ ã¯à ¢«¥­¨ï ¤¢¨£ â¥«ï¬¨
mov AL,5h ; Floppy B
out DX,AL
ret
;*******************************
;* <EFBFBD>…Š€ˆ<EFBFBD><EFBFBD>ŽŠ€ „ˆ‘ŠŽ‚Ž„€ "A:" *
;*******************************
RecalibrateFDD:
pusha
call save_timer_fdd_motor
; <EFBFBD>®¤ âì ª®¬ ­¤ã "<EFBFBD>¥ª «¨¡à®¢ª "
mov AL,07h
call FDCDataOutput
mov AL,00h
call FDCDataOutput
; Ž¦¨¤ âì § ¢¥à襭¨ï ®¯¥à æ¨¨
call WaitFDCInterrupt
; cmp [FDC_Status],0
; je no_fdc_status_error
; mov [flp_status],0
;no_fdc_status_error:
call save_timer_fdd_motor
popa
ret
;*****************************************************
;* <EFBFBD>ŽˆŠ „Ž<EFBFBD>Ž†Šˆ *
;* <EFBFBD> à ¬¥âàë ¯¥à¥¤ îâáï ç¥à¥§ £«®¡ «ì­ë¥ ¯¥à¥¬¥­­ë¥: *
;* FDD_Track - ­®¬¥à ¤®à®¦ª¨ (0-79); *
;* FDD_Head - ­®¬¥à £®«®¢ª¨ (0-1). *
;* <EFBFBD>¥§ã«ìâ â ®¯¥à æ¨¨ § ­®á¨âáï ¢ FDC_Status. *
;*****************************************************
SeekTrack:
pusha
call save_timer_fdd_motor
; <EFBFBD>®¤ âì ª®¬ ­¤ã "<EFBFBD>®¨áª"
mov AL,0Fh
call FDCDataOutput
; <EFBFBD>¥à¥¤ âì ¡ ©â ­®¬¥à  £®«®¢ª¨/­ ª®¯¨â¥«ï
mov AL,[FDD_Head]
shl AL,2
call FDCDataOutput
; <EFBFBD>¥à¥¤ âì ¡ ©â ­®¬¥à  ¤®à®¦ª¨
mov AL,[FDD_Track]
call FDCDataOutput
; Ž¦¨¤ âì § ¢¥à襭¨ï ®¯¥à æ¨¨
call WaitFDCInterrupt
cmp [FDC_Status],FDC_Normal
jne @@Exit
; ‘®åà ­¨âì १ã«ìâ â ¯®¨áª 
mov AL,08h
call FDCDataOutput
call FDCDataInput
mov [FDC_ST0],AL
call FDCDataInput
mov [FDC_C],AL
; <EFBFBD>஢¥à¨âì १ã«ìâ â ¯®¨áª 
; <EFBFBD>®¨áª § ¢¥à襭?
test [FDC_ST0],100000b
je @@Err
; ‡ ¤ ­­ë© â४ ­ ©¤¥­?
mov AL,[FDC_C]
cmp AL,[FDD_Track]
jne @@Err
; <EFBFBD>®¬¥à £®«®¢ª¨ ᮢ¯ ¤ ¥â á § ¤ ­­ë¬?
mov AL,[FDC_ST0]
and AL,100b
shr AL,2
cmp AL,[FDD_Head]
jne @@Err
; Ž¯¥à æ¨ï § ¢¥à襭  ãᯥ譮
mov [FDC_Status],FDC_Normal
jmp @@Exit
@@Err: ; ’४ ­¥ ­ ©¤¥­
mov [FDC_Status],FDC_TrackNotFound
; mov [flp_status],0
@@Exit:
call save_timer_fdd_motor
popa
ret
;*******************************************************
;* <EFBFBD>ˆ …ŠŽ<EFBFBD> „€<EFBFBD><EFBFBD> *
;* <EFBFBD> à ¬¥âàë ¯¥à¥¤ îâáï ç¥à¥§ £«®¡ «ì­ë¥ ¯¥à¥¬¥­­ë¥: *
;* FDD_Track - ­®¬¥à ¤®à®¦ª¨ (0-79); *
;* FDD_Head - ­®¬¥à £®«®¢ª¨ (0-1); *
;* FDD_Sector - ­®¬¥à ᥪâ®à  (1-18). *
;* <EFBFBD>¥§ã«ìâ â ®¯¥à æ¨¨ § ­®á¨âáï ¢ FDC_Status. *
;* á«ãç ¥ ãᯥ譮£® ¢ë¯®«­¥­¨ï ®¯¥à æ¨¨ ç⥭¨ï *
;* ᮤ¥à¦¨¬®¥ ᥪâ®à  ¡ã¤¥â § ­¥á¥­® ¢ FDD_DataBuffer. *
;*******************************************************
ReadSector:
pushad
call save_timer_fdd_motor
; “áâ ­®¢¨âì ᪮à®áâì ¯¥à¥¤ ç¨ 500 Š¡ ©â/á
mov AX,0
mov DX,03F7h
out DX,AL
; ˆ­¨æ¨ «¨§¨à®¢ âì ª ­ « ¯àאַ£® ¤®áâ㯠 ª ¯ ¬ïâ¨
mov [dmamode],0x46
call Init_FDC_DMA
; <EFBFBD>®¤ âì ª®¬ ­¤ã "—⥭¨¥ ¤ ­­ëå"
mov AL,0E6h ;ç⥭¨¥ ¢ ¬ã«ìâ¨â४®¢®¬ ०¨¬¥
call FDCDataOutput
mov AL,[FDD_Head]
shl AL,2
call FDCDataOutput
mov AL,[FDD_Track]
call FDCDataOutput
mov AL,[FDD_Head]
call FDCDataOutput
mov AL,[FDD_Sector]
call FDCDataOutput
mov AL,2 ;ª®¤ à §¬¥à  ᥪâ®à  (512 ¡ ©â)
call FDCDataOutput
mov AL,18 ;+1; 3Fh ;ç¨á«® ᥪâ®à®¢ ­  ¤®à®¦ª¥
call FDCDataOutput
mov AL,1Bh ;§­ ç¥­¨¥ GPL
call FDCDataOutput
mov AL,0FFh ;§­ ç¥­¨¥ DTL
call FDCDataOutput
; Ž¦¨¤ ¥¬ ¯à¥à뢠­¨¥ ¯® § ¢¥à襭¨¨ ®¯¥à æ¨¨
call WaitFDCInterrupt
cmp [FDC_Status],FDC_Normal
jne @@Exit_1
; ‘ç¨â뢠¥¬ áâ âãá § ¢¥à襭¨ï ®¯¥à æ¨¨
call GetStatusInfo
test [FDC_ST0],11011000b
jnz @@Err_1
mov [FDC_Status],FDC_Normal
jmp @@Exit_1
@@Err_1: mov [FDC_Status],FDC_SectorNotFound
; mov [flp_status],0
@@Exit_1:
call save_timer_fdd_motor
popad
ret
;*******************************************************
;* <EFBFBD>ˆ …ŠŽ<EFBFBD> ( <EFBFBD>ŽŽ<EFBFBD><EFBFBD>ˆ…Œ Ž<EFBFBD><EFBFBD>ˆˆ <EFBFBD><EFBFBD>ˆ <EFBFBD>Ž…) *
;* <EFBFBD> à ¬¥âàë ¯¥à¥¤ îâáï ç¥à¥§ £«®¡ «ì­ë¥ ¯¥à¥¬¥­­ë¥: *
;* FDD_Track - ­®¬¥à ¤®à®¦ª¨ (0-79); *
;* FDD_Head - ­®¬¥à £®«®¢ª¨ (0-1); *
;* FDD_Sector - ­®¬¥à ᥪâ®à  (1-18). *
;* <EFBFBD>¥§ã«ìâ â ®¯¥à æ¨¨ § ­®á¨âáï ¢ FDC_Status. *
;* á«ãç ¥ ãᯥ譮£® ¢ë¯®«­¥­¨ï ®¯¥à æ¨¨ ç⥭¨ï *
;* ᮤ¥à¦¨¬®¥ ᥪâ®à  ¡ã¤¥â § ­¥á¥­® ¢ FDD_DataBuffer. *
;*******************************************************
ReadSectWithRetr:
pusha
; Ž¡­ã«¨âì áç¥â稪 ¯®¢â®à¥­¨ï ®¯¥à æ¨¨ ४ «¨¡à®¢ª¨
mov [RecalRepCounter],0
@@TryAgain:
; Ž¡­ã«¨âì áç¥â稪 ¯®¢â®à¥­¨ï ®¯¥à æ¨¨ ç⥭¨ï
mov [ReadRepCounter],0
@@ReadSector_1:
call ReadSector
cmp [FDC_Status],0
je @@Exit_2
cmp [FDC_Status],1
je @@Err_3
; ’஥ªà â­®¥ ¯®¢â®à¥­¨¥ ç⥭¨ï
inc [ReadRepCounter]
cmp [ReadRepCounter],3
jb @@ReadSector_1
; ’஥ªà â­®¥ ¯®¢â®à¥­¨¥ ४ «¨¡à®¢ª¨
call RecalibrateFDD
call SeekTrack
inc [RecalRepCounter]
cmp [RecalRepCounter],3
jb @@TryAgain
; mov [flp_status],0
@@Exit_2:
popa
ret
@@Err_3:
mov [flp_status],0
popa
ret
;*******************************************************
;* ‡€<EFBFBD>ˆœ …ŠŽ<EFBFBD> „€<EFBFBD><EFBFBD> *
;* <EFBFBD> à ¬¥âàë ¯¥à¥¤ îâáï ç¥à¥§ £«®¡ «ì­ë¥ ¯¥à¥¬¥­­ë¥: *
;* FDD_Track - ­®¬¥à ¤®à®¦ª¨ (0-79); *
;* FDD_Head - ­®¬¥à £®«®¢ª¨ (0-1); *
;* FDD_Sector - ­®¬¥à ᥪâ®à  (1-18). *
;* <EFBFBD>¥§ã«ìâ â ®¯¥à æ¨¨ § ­®á¨âáï ¢ FDC_Status. *
;* á«ãç ¥ ãᯥ譮£® ¢ë¯®«­¥­¨ï ®¯¥à æ¨¨ § ¯¨á¨ *
;* ᮤ¥à¦¨¬®¥ FDD_DataBuffer ¡ã¤¥â § ­¥á¥­® ¢ ᥪâ®à. *
;*******************************************************
WriteSector:
pushad
call save_timer_fdd_motor
; “áâ ­®¢¨âì ᪮à®áâì ¯¥à¥¤ ç¨ 500 Š¡ ©â/á
mov AX,0
mov DX,03F7h
out DX,AL
; ˆ­¨æ¨ «¨§¨à®¢ âì ª ­ « ¯àאַ£® ¤®áâ㯠 ª ¯ ¬ïâ¨
mov [dmamode],0x4A
call Init_FDC_DMA
; <EFBFBD>®¤ âì ª®¬ ­¤ã "‡ ¯¨áì ¤ ­­ëå"
mov AL,0xC5 ;0x45 ;§ ¯¨áì ¢ ¬ã«ìâ¨â४®¢®¬ ०¨¬¥
call FDCDataOutput
mov AL,[FDD_Head]
shl AL,2
call FDCDataOutput
mov AL,[FDD_Track]
call FDCDataOutput
mov AL,[FDD_Head]
call FDCDataOutput
mov AL,[FDD_Sector]
call FDCDataOutput
mov AL,2 ;ª®¤ à §¬¥à  ᥪâ®à  (512 ¡ ©â)
call FDCDataOutput
mov AL,18; 3Fh ;ç¨á«® ᥪâ®à®¢ ­  ¤®à®¦ª¥
call FDCDataOutput
mov AL,1Bh ;§­ ç¥­¨¥ GPL
call FDCDataOutput
mov AL,0FFh ;§­ ç¥­¨¥ DTL
call FDCDataOutput
; Ž¦¨¤ ¥¬ ¯à¥à뢠­¨¥ ¯® § ¢¥à襭¨¨ ®¯¥à æ¨¨
call WaitFDCInterrupt
cmp [FDC_Status],FDC_Normal
jne @@Exit_3
; ‘ç¨â뢠¥¬ áâ âãá § ¢¥à襭¨ï ®¯¥à æ¨¨
call GetStatusInfo
test [FDC_ST0],11000000b ;11011000b
jnz @@Err_2
mov [FDC_Status],FDC_Normal
jmp @@Exit_3
@@Err_2: mov [FDC_Status],FDC_SectorNotFound
@@Exit_3:
call save_timer_fdd_motor
popad
ret
;*******************************************************
;* ‡€<EFBFBD>ˆœ …ŠŽ<EFBFBD> ( <EFBFBD>ŽŽ<EFBFBD><EFBFBD>ˆ…Œ Ž<EFBFBD><EFBFBD>ˆˆ <EFBFBD><EFBFBD>ˆ <EFBFBD>Ž…) *
;* <EFBFBD> à ¬¥âàë ¯¥à¥¤ îâáï ç¥à¥§ £«®¡ «ì­ë¥ ¯¥à¥¬¥­­ë¥: *
;* FDD_Track - ­®¬¥à ¤®à®¦ª¨ (0-79); *
;* FDD_Head - ­®¬¥à £®«®¢ª¨ (0-1); *
;* FDD_Sector - ­®¬¥à ᥪâ®à  (1-18). *
;* <EFBFBD>¥§ã«ìâ â ®¯¥à æ¨¨ § ­®á¨âáï ¢ FDC_Status. *
;* á«ãç ¥ ãᯥ譮£® ¢ë¯®«­¥­¨ï ®¯¥à æ¨¨ § ¯¨á¨ *
;* ᮤ¥à¦¨¬®¥ FDD_DataBuffer ¡ã¤¥â § ­¥á¥­® ¢ ᥪâ®à. *
;*******************************************************
WriteSectWithRetr:
pusha
; Ž¡­ã«¨âì áç¥â稪 ¯®¢â®à¥­¨ï ®¯¥à æ¨¨ ४ «¨¡à®¢ª¨
mov [RecalRepCounter],0
@@TryAgain_1:
; Ž¡­ã«¨âì áç¥â稪 ¯®¢â®à¥­¨ï ®¯¥à æ¨¨ ç⥭¨ï
mov [ReadRepCounter],0
@@WriteSector_1:
call WriteSector
cmp [FDC_Status],0
je @@Exit_4
cmp [FDC_Status],1
je @@Err_4
; ’஥ªà â­®¥ ¯®¢â®à¥­¨¥ ç⥭¨ï
inc [ReadRepCounter]
cmp [ReadRepCounter],3
jb @@WriteSector_1
; ’஥ªà â­®¥ ¯®¢â®à¥­¨¥ ४ «¨¡à®¢ª¨
call RecalibrateFDD
call SeekTrack
inc [RecalRepCounter]
cmp [RecalRepCounter],3
jb @@TryAgain_1
@@Exit_4:
popa
ret
@@Err_4:
mov [flp_status],0
popa
ret
;*********************************************
;* <EFBFBD>Ž“—ˆœ ˆ<EFBFBD>”Ž<EFBFBD>Œ€ˆž Ž <EFBFBD>…‡“œ Ž<EFBFBD><EFBFBD>ˆˆ *
;*********************************************
GetStatusInfo:
push AX
call FDCDataInput
mov [FDC_ST0],AL
call FDCDataInput
mov [FDC_ST1],AL
call FDCDataInput
mov [FDC_ST2],AL
call FDCDataInput
mov [FDC_C],AL
call FDCDataInput
mov [FDC_H],AL
call FDCDataInput
mov [FDC_R],AL
call FDCDataInput
mov [FDC_N],AL
pop AX
ret