forked from KolibriOS/kolibrios
d5c0fed779
git-svn-id: svn://kolibrios.org@2 a494cfbc-eb01-0410-851d-a64ba20cac60
686 lines
21 KiB
PHP
686 lines
21 KiB
PHP
;**********************************************************
|
||
; <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
|
||
|