2010-10-01 13:21:55 +04:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;; ;;
|
2015-06-01 22:18:07 +03:00
|
|
|
|
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
|
;; ;;
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
|
$Revision$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;**********************************************************
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Непосредственная работа с контроллером гибкого диска
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;**********************************************************
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Автор исходного текста Кулаков Владимир Геннадьевич.
|
|
|
|
|
; Адаптация и доработка Mario79
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
|
;give_back_application_data: ; переслать приложению
|
2010-10-01 13:21:55 +04:00
|
|
|
|
; mov edi,[TASK_BASE]
|
|
|
|
|
; mov edi,[edi+TASKDATA.mem_start]
|
|
|
|
|
; add edi,ecx
|
|
|
|
|
give_back_application_data_1:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov esi, FDD_BUFF;FDD_DataBuffer ;0x40000
|
2013-11-24 11:02:55 +04:00
|
|
|
|
mov ecx, 128
|
2013-05-28 23:09:31 +04:00
|
|
|
|
cld
|
|
|
|
|
rep movsd
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
|
;take_data_from_application: ; взять из приложени
|
2010-10-01 13:21:55 +04:00
|
|
|
|
; mov esi,[TASK_BASE]
|
|
|
|
|
; mov esi,[esi+TASKDATA.mem_start]
|
|
|
|
|
; add esi,ecx
|
|
|
|
|
take_data_from_application_1:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov edi, FDD_BUFF;FDD_DataBuffer ;0x40000
|
2013-11-24 11:02:55 +04:00
|
|
|
|
mov ecx, 128
|
2013-05-28 23:09:31 +04:00
|
|
|
|
cld
|
|
|
|
|
rep movsd
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Коды завершения операции с контроллером (FDC_Status)
|
|
|
|
|
FDC_Normal equ 0 ;нормальное завершение
|
|
|
|
|
FDC_TimeOut equ 1 ;ошибка тайм-аута
|
|
|
|
|
FDC_DiskNotFound equ 2 ;в дисководе нет диска
|
|
|
|
|
FDC_TrackNotFound equ 3 ;дорожка не найдена
|
|
|
|
|
FDC_SectorNotFound equ 4 ;сектор не найден
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Максимальные значения координат сектора (заданные
|
|
|
|
|
; значения соответствуют параметрам стандартного
|
|
|
|
|
; трехдюймового гибкого диска объемом 1,44 Мб)
|
2010-10-01 13:21:55 +04:00
|
|
|
|
MAX_Track equ 79
|
|
|
|
|
MAX_Head equ 1
|
|
|
|
|
MAX_Sector equ 18
|
|
|
|
|
|
|
|
|
|
uglobal
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Счетчик тиков таймера
|
2010-10-01 13:21:55 +04:00
|
|
|
|
TickCounter dd ?
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Код завершения операции с контроллером НГМД
|
2010-10-01 13:21:55 +04:00
|
|
|
|
FDC_Status DB ?
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Флаг прерывания от НГМД
|
2010-10-01 13:21:55 +04:00
|
|
|
|
FDD_IntFlag DB ?
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Момент начала последней операции с НГМД
|
2010-10-01 13:21:55 +04:00
|
|
|
|
FDD_Time DD ?
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Номер дисковода
|
2010-10-01 13:21:55 +04:00
|
|
|
|
FDD_Type db 0
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Координаты сектора
|
2010-10-01 13:21:55 +04:00
|
|
|
|
FDD_Track DB ?
|
|
|
|
|
FDD_Head DB ?
|
|
|
|
|
FDD_Sector DB ?
|
|
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Блок результата операции
|
2010-10-01 13:21:55 +04:00
|
|
|
|
FDC_ST0 DB ?
|
|
|
|
|
FDC_ST1 DB ?
|
|
|
|
|
FDC_ST2 DB ?
|
|
|
|
|
FDC_C DB ?
|
|
|
|
|
FDC_H DB ?
|
|
|
|
|
FDC_R DB ?
|
|
|
|
|
FDC_N DB ?
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Счетчик повторения операции чтени
|
2010-10-01 13:21:55 +04:00
|
|
|
|
ReadRepCounter DB ?
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Счетчик повторения операции рекалибровки
|
2010-10-01 13:21:55 +04:00
|
|
|
|
RecalRepCounter DB ?
|
|
|
|
|
endg
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Область памяти для хранения прочитанного сектора
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;FDD_DataBuffer: times 512 db 0 ;DB 512 DUP (?)
|
|
|
|
|
fdd_motor_status db 0
|
|
|
|
|
timer_fdd_motor dd 0
|
|
|
|
|
|
|
|
|
|
;*************************************
|
2013-05-28 23:09:31 +04:00
|
|
|
|
;* ИНИЦИАЛИЗАЦИЯ РЕЖИМА ПДП ДЛЯ НГМД *
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;*************************************
|
|
|
|
|
Init_FDC_DMA:
|
|
|
|
|
pushad
|
2012-03-08 12:33:38 +04:00
|
|
|
|
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)
|
2013-05-28 23:09:31 +04:00
|
|
|
|
out 0x5, al
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov al, 0x1;[dmasize] ;(0x1ff = 511 / 0x23ff =9215)
|
|
|
|
|
out 0x5, al
|
|
|
|
|
mov al, 2
|
|
|
|
|
out 0xa, al
|
2010-10-01 13:21:55 +04:00
|
|
|
|
popad
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;***********************************
|
2013-05-28 23:09:31 +04:00
|
|
|
|
;* ЗАПИСАТЬ БАЙТ В ПОРТ ДАННЫХ FDC *
|
|
|
|
|
;* Параметры: *
|
|
|
|
|
;* AL - выводимый байт. *
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;***********************************
|
|
|
|
|
FDCDataOutput:
|
2013-11-24 11:02:55 +04:00
|
|
|
|
; DEBUGF 1,'K : FDCDataOutput(%x)',al
|
2010-10-01 13:21:55 +04:00
|
|
|
|
; pusha
|
2013-05-28 23:09:31 +04:00
|
|
|
|
push eax ecx edx
|
|
|
|
|
mov AH, AL ;запомнить байт в AH
|
|
|
|
|
; Сбросить переменную состояния контроллера
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [FDC_Status], FDC_Normal
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Проверить готовность контроллера к приему данных
|
|
|
|
|
mov DX, 3F4h ;(порт состояния FDC)
|
|
|
|
|
mov ecx, 0x10000 ;установить счетчик тайм-аута
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@TestRS:
|
2013-05-28 23:09:31 +04:00
|
|
|
|
in AL, DX ;прочитать регистр RS
|
|
|
|
|
and AL, 0C0h ;выделить разряды 6 и 7
|
|
|
|
|
cmp AL, 80h ;проверить разряды 6 и 7
|
2010-10-01 13:21:55 +04:00
|
|
|
|
je @@OutByteToFDC
|
|
|
|
|
loop @@TestRS
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Ошибка тайм-аута
|
2013-11-24 11:02:55 +04:00
|
|
|
|
; DEBUGF 1,' timeout\n'
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [FDC_Status], FDC_TimeOut
|
2013-05-28 23:09:31 +04:00
|
|
|
|
jmp @@End_5
|
|
|
|
|
; Вывести байт в порт данных
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@OutByteToFDC:
|
|
|
|
|
inc DX
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov AL, AH
|
|
|
|
|
out DX, AL
|
2013-11-24 11:02:55 +04:00
|
|
|
|
; DEBUGF 1,' ok\n'
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@End_5:
|
|
|
|
|
; popa
|
2013-05-28 23:09:31 +04:00
|
|
|
|
pop edx ecx eax
|
2010-10-01 13:21:55 +04:00
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;******************************************
|
2013-05-28 23:09:31 +04:00
|
|
|
|
;* ПРОЧИТАТЬ БАЙТ ИЗ ПОРТА ДАННЫХ FDC *
|
|
|
|
|
;* Процедура не имеет входных параметров. *
|
|
|
|
|
;* Выходные данные: *
|
|
|
|
|
;* AL - считанный байт. *
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;******************************************
|
|
|
|
|
FDCDataInput:
|
|
|
|
|
push ECX
|
|
|
|
|
push DX
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Сбросить переменную состояния контроллера
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [FDC_Status], FDC_Normal
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Проверить готовность контроллера к передаче данных
|
|
|
|
|
mov DX, 3F4h ;(порт состояния FDC)
|
2013-11-21 06:42:12 +04:00
|
|
|
|
mov ecx, 0x10000 ;установить счетчик тайм-аута
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@TestRS_1:
|
2013-05-28 23:09:31 +04:00
|
|
|
|
in AL, DX ;прочитать регистр RS
|
|
|
|
|
and AL, 0C0h ;выдлить разряды 6 и 7
|
|
|
|
|
cmp AL, 0C0h ;проверить разряды 6 и 7
|
2010-10-01 13:21:55 +04:00
|
|
|
|
je @@GetByteFromFDC
|
|
|
|
|
loop @@TestRS_1
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Ошибка тайм-аута
|
2013-11-24 11:02:55 +04:00
|
|
|
|
; DEBUGF 1,'K : FDCDataInput: timeout\n'
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [FDC_Status], FDC_TimeOut
|
2013-05-28 23:09:31 +04:00
|
|
|
|
jmp @@End_6
|
|
|
|
|
; Ввести байт из порта данных
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@GetByteFromFDC:
|
|
|
|
|
inc DX
|
2012-03-08 12:33:38 +04:00
|
|
|
|
in AL, DX
|
2013-11-24 11:02:55 +04:00
|
|
|
|
; DEBUGF 1,'K : FDCDataInput: %x\n',al
|
2012-03-08 12:33:38 +04:00
|
|
|
|
@@End_6:
|
|
|
|
|
pop DX
|
2010-10-01 13:21:55 +04:00
|
|
|
|
pop ECX
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;*********************************************
|
2013-05-28 23:09:31 +04:00
|
|
|
|
;* ОБРАБОТЧИК ПРЕРЫВАНИЯ ОТ КОНТРОЛЛЕРА НГМД *
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;*********************************************
|
|
|
|
|
FDCInterrupt:
|
2013-11-24 11:02:55 +04:00
|
|
|
|
; dbgstr 'FDCInterrupt'
|
2013-09-14 22:55:13 +04:00
|
|
|
|
; Установить флаг прерывания
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [FDD_IntFlag], 1
|
2013-09-14 22:55:13 +04:00
|
|
|
|
mov al, 1
|
2013-05-28 23:09:31 +04:00
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
|
|
;*******************************************
|
2013-05-28 23:09:31 +04:00
|
|
|
|
;* ОЖИДАНИЕ ПРЕРЫВАНИЯ ОТ КОНТРОЛЛЕРА НГМД *
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;*******************************************
|
|
|
|
|
WaitFDCInterrupt:
|
|
|
|
|
pusha
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Сбросить байт состояния операции
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [FDC_Status], FDC_Normal
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Обнулить счетчик тиков
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov eax, [timer_ticks]
|
|
|
|
|
mov [TickCounter], eax
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Ожидать установки флага прерывания НГМД
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@TestRS_2:
|
2013-09-14 22:55:13 +04:00
|
|
|
|
call change_task
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp [FDD_IntFlag], 0
|
2013-05-28 23:09:31 +04:00
|
|
|
|
jnz @@End_7 ;прерывание произошло
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov eax, [timer_ticks]
|
|
|
|
|
sub eax, [TickCounter]
|
2013-11-24 11:02:55 +04:00
|
|
|
|
cmp eax, 200;50 ;25 ;5 ;ожидать 5 тиков
|
2010-10-01 13:21:55 +04:00
|
|
|
|
jb @@TestRS_2
|
|
|
|
|
; jl @@TestRS_2
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Ошибка тайм-аута
|
2013-11-24 11:02:55 +04:00
|
|
|
|
; dbgstr 'WaitFDCInterrupt: timeout'
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [FDC_Status], FDC_TimeOut
|
|
|
|
|
@@End_7:
|
|
|
|
|
popa
|
2010-10-01 13:21:55 +04:00
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;*********************************
|
2013-05-28 23:09:31 +04:00
|
|
|
|
;* ВКЛЮЧИТЬ МОТОР ДИСКОВОДА "A:" *
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;*********************************
|
|
|
|
|
FDDMotorON:
|
2013-11-24 11:02:55 +04:00
|
|
|
|
; dbgstr 'FDDMotorON'
|
2010-10-01 13:21:55 +04:00
|
|
|
|
pusha
|
|
|
|
|
; cmp [fdd_motor_status],1
|
|
|
|
|
; je fdd_motor_on
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov al, [flp_number]
|
|
|
|
|
cmp [fdd_motor_status], al
|
2010-10-01 13:21:55 +04:00
|
|
|
|
je fdd_motor_on
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Произвести сброс контроллера НГМД
|
|
|
|
|
mov DX, 3F2h;порт управления двигателями
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov AL, 0
|
|
|
|
|
out DX, AL
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Выбрать и включить мотор дисковода
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp [flp_number], 1
|
2010-10-01 13:21:55 +04:00
|
|
|
|
jne FDDMotorON_B
|
|
|
|
|
; call FDDMotorOFF_B
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov AL, 1Ch ; Floppy A
|
2010-10-01 13:21:55 +04:00
|
|
|
|
jmp FDDMotorON_1
|
|
|
|
|
FDDMotorON_B:
|
|
|
|
|
; call FDDMotorOFF_A
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov AL, 2Dh ; Floppy B
|
2010-10-01 13:21:55 +04:00
|
|
|
|
FDDMotorON_1:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
out DX, AL
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Обнулить счетчик тиков
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov eax, [timer_ticks]
|
|
|
|
|
mov [TickCounter], eax
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Ожидать 0,5 с
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@dT:
|
|
|
|
|
call change_task
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov eax, [timer_ticks]
|
|
|
|
|
sub eax, [TickCounter]
|
|
|
|
|
cmp eax, 50 ;10
|
2010-10-01 13:21:55 +04:00
|
|
|
|
jb @@dT
|
2013-11-24 11:02:55 +04:00
|
|
|
|
; Read results of RESET command
|
|
|
|
|
push 4
|
|
|
|
|
; DEBUGF 1,'K : floppy reset results:'
|
|
|
|
|
@@:
|
|
|
|
|
mov al, 8
|
|
|
|
|
call FDCDataOutput
|
|
|
|
|
call FDCDataInput
|
|
|
|
|
; DEBUGF 1,' %x',al
|
|
|
|
|
call FDCDataInput
|
|
|
|
|
; DEBUGF 1,' %x',al
|
|
|
|
|
dec dword [esp]
|
|
|
|
|
jnz @b
|
|
|
|
|
; DEBUGF 1,'\n'
|
|
|
|
|
pop eax
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp [flp_number], 1
|
2010-10-01 13:21:55 +04:00
|
|
|
|
jne fdd_motor_on_B
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [fdd_motor_status], 1
|
2010-10-01 13:21:55 +04:00
|
|
|
|
jmp fdd_motor_on
|
|
|
|
|
fdd_motor_on_B:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [fdd_motor_status], 2
|
2010-10-01 13:21:55 +04:00
|
|
|
|
fdd_motor_on:
|
|
|
|
|
call save_timer_fdd_motor
|
|
|
|
|
popa
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;*****************************************
|
2013-05-28 23:09:31 +04:00
|
|
|
|
;* СОХРАНЕНИЕ УКАЗАТЕЛЯ ВРЕМЕНИ *
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;*****************************************
|
|
|
|
|
save_timer_fdd_motor:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov eax, [timer_ticks]
|
|
|
|
|
mov [timer_fdd_motor], eax
|
2010-10-01 13:21:55 +04:00
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;*****************************************
|
2013-05-28 23:09:31 +04:00
|
|
|
|
;* ПРОВЕРКА ЗАДЕРЖКИ ВЫКЛЮЧЕНИЯ МОТОРА *
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;*****************************************
|
2013-05-28 23:09:31 +04:00
|
|
|
|
proc check_fdd_motor_status_has_work?
|
|
|
|
|
cmp [fdd_motor_status], 0
|
|
|
|
|
jz .no
|
|
|
|
|
mov eax, [timer_ticks]
|
|
|
|
|
sub eax, [timer_fdd_motor]
|
|
|
|
|
cmp eax, 500
|
|
|
|
|
jb .no
|
|
|
|
|
.yes:
|
|
|
|
|
xor eax, eax
|
|
|
|
|
inc eax
|
|
|
|
|
ret
|
|
|
|
|
.no:
|
|
|
|
|
xor eax, eax
|
|
|
|
|
ret
|
|
|
|
|
endp
|
|
|
|
|
|
2010-10-01 13:21:55 +04:00
|
|
|
|
align 4
|
|
|
|
|
check_fdd_motor_status:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp [fdd_motor_status], 0
|
2010-10-01 13:21:55 +04:00
|
|
|
|
je end_check_fdd_motor_status_1
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov eax, [timer_ticks]
|
|
|
|
|
sub eax, [timer_fdd_motor]
|
|
|
|
|
cmp eax, 500
|
2010-10-01 13:21:55 +04:00
|
|
|
|
jb end_check_fdd_motor_status
|
|
|
|
|
call FDDMotorOFF
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [fdd_motor_status], 0
|
2010-10-01 13:21:55 +04:00
|
|
|
|
end_check_fdd_motor_status_1:
|
|
|
|
|
end_check_fdd_motor_status:
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;**********************************
|
2013-05-28 23:09:31 +04:00
|
|
|
|
;* ВЫКЛЮЧИТЬ МОТОР ДИСКОВОДА *
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;**********************************
|
|
|
|
|
FDDMotorOFF:
|
2013-11-24 11:02:55 +04:00
|
|
|
|
; dbgstr 'FDDMotorOFF'
|
2010-10-01 13:21:55 +04:00
|
|
|
|
push AX
|
|
|
|
|
push DX
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp [flp_number], 1
|
2010-10-01 13:21:55 +04:00
|
|
|
|
jne FDDMotorOFF_1
|
|
|
|
|
call FDDMotorOFF_A
|
|
|
|
|
jmp FDDMotorOFF_2
|
|
|
|
|
FDDMotorOFF_1:
|
|
|
|
|
call FDDMotorOFF_B
|
|
|
|
|
FDDMotorOFF_2:
|
|
|
|
|
pop DX
|
|
|
|
|
pop AX
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; сброс флагов кеширования в связи с устареванием информации
|
2013-11-24 11:02:55 +04:00
|
|
|
|
or [floppy_media_flags+0], FLOPPY_MEDIA_NEED_RESCAN
|
|
|
|
|
or [floppy_media_flags+1], FLOPPY_MEDIA_NEED_RESCAN
|
2010-10-01 13:21:55 +04:00
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
FDDMotorOFF_A:
|
2013-05-28 23:09:31 +04:00
|
|
|
|
mov DX, 3F2h;порт управления двигателями
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov AL, 0Ch ; Floppy A
|
|
|
|
|
out DX, AL
|
2010-10-01 13:21:55 +04:00
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
FDDMotorOFF_B:
|
2013-05-28 23:09:31 +04:00
|
|
|
|
mov DX, 3F2h;порт управления двигателями
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov AL, 5h ; Floppy B
|
|
|
|
|
out DX, AL
|
2010-10-01 13:21:55 +04:00
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;*******************************
|
2013-05-28 23:09:31 +04:00
|
|
|
|
;* РЕКАЛИБРОВКА ДИСКОВОДА "A:" *
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;*******************************
|
|
|
|
|
RecalibrateFDD:
|
2013-11-24 11:02:55 +04:00
|
|
|
|
; dbgstr 'RecalibrateFDD'
|
2010-10-01 13:21:55 +04:00
|
|
|
|
pusha
|
|
|
|
|
call save_timer_fdd_motor
|
2013-11-24 11:02:55 +04:00
|
|
|
|
; Сбросить флаг прерывания
|
|
|
|
|
mov [FDD_IntFlag], 0
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Подать команду "Рекалибровка"
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov AL, 07h
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov AL, 00h
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Ожидать завершения операции
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call WaitFDCInterrupt
|
2013-11-24 11:02:55 +04:00
|
|
|
|
cmp [FDC_Status], 0
|
|
|
|
|
jne .fail
|
|
|
|
|
; Read results of RECALIBRATE command
|
|
|
|
|
; DEBUGF 1,'K : floppy recalibrate results:'
|
|
|
|
|
mov al, 8
|
|
|
|
|
call FDCDataOutput
|
|
|
|
|
call FDCDataInput
|
2014-12-01 06:51:07 +03:00
|
|
|
|
push eax
|
2013-11-24 11:02:55 +04:00
|
|
|
|
; DEBUGF 1,' %x',al
|
|
|
|
|
call FDCDataInput
|
|
|
|
|
; DEBUGF 1,' %x',al
|
|
|
|
|
; DEBUGF 1,'\n'
|
2014-12-01 06:51:07 +03:00
|
|
|
|
pop eax
|
|
|
|
|
test al, 0xC0
|
|
|
|
|
jz @f
|
|
|
|
|
mov [FDC_Status], FDC_DiskNotFound
|
|
|
|
|
@@:
|
2013-11-24 11:02:55 +04:00
|
|
|
|
.fail:
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call save_timer_fdd_motor
|
|
|
|
|
popa
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;*****************************************************
|
2013-05-28 23:09:31 +04:00
|
|
|
|
;* ПОИСК ДОРОЖКИ *
|
|
|
|
|
;* Параметры передаются через глобальные переменные: *
|
|
|
|
|
;* FDD_Track - номер дорожки (0-79); *
|
|
|
|
|
;* FDD_Head - номер головки (0-1). *
|
|
|
|
|
;* Результат операции заносится в FDC_Status. *
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;*****************************************************
|
|
|
|
|
SeekTrack:
|
2013-11-24 11:02:55 +04:00
|
|
|
|
; dbgstr 'SeekTrack'
|
2010-10-01 13:21:55 +04:00
|
|
|
|
pusha
|
|
|
|
|
call save_timer_fdd_motor
|
2013-11-21 06:42:12 +04:00
|
|
|
|
; Сбросить флаг прерывания
|
|
|
|
|
mov [FDD_IntFlag], 0
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Подать команду "Поиск"
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov AL, 0Fh
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Передать байт номера головки/накопител
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov AL, [FDD_Head]
|
|
|
|
|
shl AL, 2
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Передать байт номера дорожки
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov AL, [FDD_Track]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Ожидать завершения операции
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call WaitFDCInterrupt
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp [FDC_Status], FDC_Normal
|
2010-10-01 13:21:55 +04:00
|
|
|
|
jne @@Exit
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Сохранить результат поиска
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov AL, 08h
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
|
|
|
|
call FDCDataInput
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [FDC_ST0], AL
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataInput
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [FDC_C], AL
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Проверить результат поиска
|
|
|
|
|
; Поиск завершен?
|
2012-03-08 12:33:38 +04:00
|
|
|
|
test [FDC_ST0], 100000b
|
2010-10-01 13:21:55 +04:00
|
|
|
|
je @@Err
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Заданный трек найден?
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov AL, [FDC_C]
|
|
|
|
|
cmp AL, [FDD_Track]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
jne @@Err
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Номер головки совпадает с заданным?
|
2013-11-24 11:02:55 +04:00
|
|
|
|
; The H bit (Head Address) in ST0 will always return a "0" (c) 82077AA datasheet,
|
|
|
|
|
; description of SEEK command. So we can not verify the proper head.
|
|
|
|
|
; mov AL, [FDC_ST0]
|
|
|
|
|
; and AL, 100b
|
|
|
|
|
; shr AL, 2
|
|
|
|
|
; cmp AL, [FDD_Head]
|
|
|
|
|
; jne @@Err
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Операция завершена успешно
|
2013-11-24 11:02:55 +04:00
|
|
|
|
; dbgstr 'SeekTrack: FDC_Normal'
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [FDC_Status], FDC_Normal
|
2013-05-28 23:09:31 +04:00
|
|
|
|
jmp @@Exit
|
|
|
|
|
@@Err: ; Трек не найден
|
2013-11-24 11:02:55 +04:00
|
|
|
|
; dbgstr 'SeekTrack: FDC_TrackNotFound'
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [FDC_Status], FDC_TrackNotFound
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@Exit:
|
|
|
|
|
call save_timer_fdd_motor
|
|
|
|
|
popa
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;*******************************************************
|
2013-05-28 23:09:31 +04:00
|
|
|
|
;* ЧТЕНИЕ СЕКТОРА ДАННЫХ *
|
|
|
|
|
;* Параметры передаются через глобальные переменные: *
|
|
|
|
|
;* FDD_Track - номер дорожки (0-79); *
|
|
|
|
|
;* FDD_Head - номер головки (0-1); *
|
|
|
|
|
;* FDD_Sector - номер сектора (1-18). *
|
|
|
|
|
;* Результат операции заносится в FDC_Status. *
|
|
|
|
|
;* В случае успешного выполнения операции чтения *
|
|
|
|
|
;* содержимое сектора будет занесено в FDD_DataBuffer. *
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;*******************************************************
|
|
|
|
|
ReadSector:
|
2013-11-24 11:02:55 +04:00
|
|
|
|
; dbgstr 'ReadSector'
|
2010-10-01 13:21:55 +04:00
|
|
|
|
pushad
|
|
|
|
|
call save_timer_fdd_motor
|
2013-11-21 06:42:12 +04:00
|
|
|
|
; Сбросить флаг прерывания
|
|
|
|
|
mov [FDD_IntFlag], 0
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Установить скорость передачи 500 Кбайт/с
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov AX, 0
|
|
|
|
|
mov DX, 03F7h
|
|
|
|
|
out DX, AL
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Инициализировать канал прямого доступа к памяти
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [dmamode], 0x46
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call Init_FDC_DMA
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Подать команду "Чтение данных"
|
|
|
|
|
mov AL, 0E6h ;чтение в мультитрековом режиме
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov AL, [FDD_Head]
|
|
|
|
|
shl AL, 2
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov AL, [FDD_Track]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov AL, [FDD_Head]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov AL, [FDD_Sector]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
2013-05-28 23:09:31 +04:00
|
|
|
|
mov AL, 2 ;код размера сектора (512 байт)
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
2013-05-28 23:09:31 +04:00
|
|
|
|
mov AL, 18 ;+1; 3Fh ;число секторов на дорожке
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
2013-05-28 23:09:31 +04:00
|
|
|
|
mov AL, 1Bh ;значение GPL
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
2013-05-28 23:09:31 +04:00
|
|
|
|
mov AL, 0FFh;значение DTL
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Ожидаем прерывание по завершении операции
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call WaitFDCInterrupt
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp [FDC_Status], FDC_Normal
|
2010-10-01 13:21:55 +04:00
|
|
|
|
jne @@Exit_1
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Считываем статус завершения операции
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call GetStatusInfo
|
2012-03-08 12:33:38 +04:00
|
|
|
|
test [FDC_ST0], 11011000b
|
2010-10-01 13:21:55 +04:00
|
|
|
|
jnz @@Err_1
|
2013-11-24 11:02:55 +04:00
|
|
|
|
; dbgstr 'ReadSector: FDC_Normal'
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [FDC_Status], FDC_Normal
|
2013-05-28 23:09:31 +04:00
|
|
|
|
jmp @@Exit_1
|
2012-03-08 12:33:38 +04:00
|
|
|
|
@@Err_1:
|
2013-11-24 11:02:55 +04:00
|
|
|
|
; dbgstr 'ReadSector: FDC_SectorNotFound'
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [FDC_Status], FDC_SectorNotFound
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@Exit_1:
|
|
|
|
|
call save_timer_fdd_motor
|
|
|
|
|
popad
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;*******************************************************
|
2013-05-28 23:09:31 +04:00
|
|
|
|
;* ЧТЕНИЕ СЕКТОРА (С ПОВТОРЕНИЕМ ОПЕРАЦИИ ПРИ СБОЕ) *
|
|
|
|
|
;* Параметры передаются через глобальные переменные: *
|
|
|
|
|
;* FDD_Track - номер дорожки (0-79); *
|
|
|
|
|
;* FDD_Head - номер головки (0-1); *
|
|
|
|
|
;* FDD_Sector - номер сектора (1-18). *
|
|
|
|
|
;* Результат операции заносится в FDC_Status. *
|
|
|
|
|
;* В случае успешного выполнения операции чтения *
|
|
|
|
|
;* содержимое сектора будет занесено в FDD_DataBuffer. *
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;*******************************************************
|
|
|
|
|
ReadSectWithRetr:
|
|
|
|
|
pusha
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Обнулить счетчик повторения операции рекалибровки
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [RecalRepCounter], 0
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@TryAgain:
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Обнулить счетчик повторения операции чтени
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [ReadRepCounter], 0
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@ReadSector_1:
|
|
|
|
|
call ReadSector
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp [FDC_Status], 0
|
2010-10-01 13:21:55 +04:00
|
|
|
|
je @@Exit_2
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp [FDC_Status], 1
|
2010-10-01 13:21:55 +04:00
|
|
|
|
je @@Err_3
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Троекратное повторение чтени
|
2010-10-01 13:21:55 +04:00
|
|
|
|
inc [ReadRepCounter]
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp [ReadRepCounter], 3
|
2010-10-01 13:21:55 +04:00
|
|
|
|
jb @@ReadSector_1
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Троекратное повторение рекалибровки
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call RecalibrateFDD
|
|
|
|
|
call SeekTrack
|
|
|
|
|
inc [RecalRepCounter]
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp [RecalRepCounter], 3
|
2010-10-01 13:21:55 +04:00
|
|
|
|
jb @@TryAgain
|
|
|
|
|
@@Exit_2:
|
|
|
|
|
popa
|
|
|
|
|
ret
|
|
|
|
|
@@Err_3:
|
|
|
|
|
popa
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;*******************************************************
|
2013-05-28 23:09:31 +04:00
|
|
|
|
;* ЗАПИСЬ СЕКТОРА ДАННЫХ *
|
|
|
|
|
;* Параметры передаются через глобальные переменные: *
|
|
|
|
|
;* FDD_Track - номер дорожки (0-79); *
|
|
|
|
|
;* FDD_Head - номер головки (0-1); *
|
|
|
|
|
;* FDD_Sector - номер сектора (1-18). *
|
|
|
|
|
;* Результат операции заносится в FDC_Status. *
|
|
|
|
|
;* В случае успешного выполнения операции записи *
|
|
|
|
|
;* содержимое FDD_DataBuffer будет занесено в сектор. *
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;*******************************************************
|
|
|
|
|
WriteSector:
|
2013-11-24 11:02:55 +04:00
|
|
|
|
; dbgstr 'WriteSector'
|
2010-10-01 13:21:55 +04:00
|
|
|
|
pushad
|
|
|
|
|
call save_timer_fdd_motor
|
2013-11-21 06:42:12 +04:00
|
|
|
|
; Сбросить флаг прерывания
|
|
|
|
|
mov [FDD_IntFlag], 0
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Установить скорость передачи 500 Кбайт/с
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov AX, 0
|
|
|
|
|
mov DX, 03F7h
|
|
|
|
|
out DX, AL
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Инициализировать канал прямого доступа к памяти
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [dmamode], 0x4A
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call Init_FDC_DMA
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Подать команду "Запись данных"
|
|
|
|
|
mov AL, 0xC5 ;0x45 ;запись в мультитрековом режиме
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov AL, [FDD_Head]
|
|
|
|
|
shl AL, 2
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov AL, [FDD_Track]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov AL, [FDD_Head]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov AL, [FDD_Sector]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
2013-05-28 23:09:31 +04:00
|
|
|
|
mov AL, 2 ;код размера сектора (512 байт)
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
2013-05-28 23:09:31 +04:00
|
|
|
|
mov AL, 18; 3Fh ;число секторов на дорожке
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
2013-05-28 23:09:31 +04:00
|
|
|
|
mov AL, 1Bh ;значение GPL
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
2013-05-28 23:09:31 +04:00
|
|
|
|
mov AL, 0FFh;значение DTL
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataOutput
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Ожидаем прерывание по завершении операции
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call WaitFDCInterrupt
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp [FDC_Status], FDC_Normal
|
2010-10-01 13:21:55 +04:00
|
|
|
|
jne @@Exit_3
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Считываем статус завершения операции
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call GetStatusInfo
|
2012-03-08 12:33:38 +04:00
|
|
|
|
test [FDC_ST0], 11000000b ;11011000b
|
2010-10-01 13:21:55 +04:00
|
|
|
|
jnz @@Err_2
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [FDC_Status], FDC_Normal
|
2013-05-28 23:09:31 +04:00
|
|
|
|
jmp @@Exit_3
|
2012-03-08 12:33:38 +04:00
|
|
|
|
@@Err_2:
|
|
|
|
|
mov [FDC_Status], FDC_SectorNotFound
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@Exit_3:
|
|
|
|
|
call save_timer_fdd_motor
|
|
|
|
|
popad
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;*******************************************************
|
2013-05-28 23:09:31 +04:00
|
|
|
|
;* ЗАПИСЬ СЕКТОРА (С ПОВТОРЕНИЕМ ОПЕРАЦИИ ПРИ СБОЕ) *
|
|
|
|
|
;* Параметры передаются через глобальные переменные: *
|
|
|
|
|
;* FDD_Track - номер дорожки (0-79); *
|
|
|
|
|
;* FDD_Head - номер головки (0-1); *
|
|
|
|
|
;* FDD_Sector - номер сектора (1-18). *
|
|
|
|
|
;* Результат операции заносится в FDC_Status. *
|
|
|
|
|
;* В случае успешного выполнения операции записи *
|
|
|
|
|
;* содержимое FDD_DataBuffer будет занесено в сектор. *
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;*******************************************************
|
|
|
|
|
WriteSectWithRetr:
|
|
|
|
|
pusha
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Обнулить счетчик повторения операции рекалибровки
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [RecalRepCounter], 0
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@TryAgain_1:
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Обнулить счетчик повторения операции чтени
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [ReadRepCounter], 0
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@WriteSector_1:
|
|
|
|
|
call WriteSector
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp [FDC_Status], 0
|
2010-10-01 13:21:55 +04:00
|
|
|
|
je @@Exit_4
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp [FDC_Status], 1
|
2010-10-01 13:21:55 +04:00
|
|
|
|
je @@Err_4
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Троекратное повторение чтени
|
2010-10-01 13:21:55 +04:00
|
|
|
|
inc [ReadRepCounter]
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp [ReadRepCounter], 3
|
2010-10-01 13:21:55 +04:00
|
|
|
|
jb @@WriteSector_1
|
2013-05-28 23:09:31 +04:00
|
|
|
|
; Троекратное повторение рекалибровки
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call RecalibrateFDD
|
|
|
|
|
call SeekTrack
|
|
|
|
|
inc [RecalRepCounter]
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp [RecalRepCounter], 3
|
2010-10-01 13:21:55 +04:00
|
|
|
|
jb @@TryAgain_1
|
|
|
|
|
@@Exit_4:
|
|
|
|
|
popa
|
|
|
|
|
ret
|
|
|
|
|
@@Err_4:
|
|
|
|
|
popa
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;*********************************************
|
2013-05-28 23:09:31 +04:00
|
|
|
|
;* ПОЛУЧИТЬ ИНФОРМАЦИЮ О РЕЗУЛЬТАТЕ ОПЕРАЦИИ *
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;*********************************************
|
|
|
|
|
GetStatusInfo:
|
|
|
|
|
push AX
|
|
|
|
|
call FDCDataInput
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [FDC_ST0], AL
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataInput
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [FDC_ST1], AL
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataInput
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [FDC_ST2], AL
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataInput
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [FDC_C], AL
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataInput
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [FDC_H], AL
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataInput
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [FDC_R], AL
|
2010-10-01 13:21:55 +04:00
|
|
|
|
call FDCDataInput
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [FDC_N], AL
|
2010-10-01 13:21:55 +04:00
|
|
|
|
pop AX
|
|
|
|
|
ret
|
|
|
|
|
|
2013-11-24 11:02:55 +04:00
|
|
|
|
; Interface for disk subsystem.
|
|
|
|
|
; Assume fixed capacity for 1.44M.
|
|
|
|
|
FLOPPY_CAPACITY = 2880 ; in sectors
|
|
|
|
|
|
|
|
|
|
iglobal
|
|
|
|
|
align 4
|
|
|
|
|
floppy_functions:
|
|
|
|
|
dd .size
|
|
|
|
|
dd 0 ; no close() function
|
|
|
|
|
dd 0 ; no closemedia() function
|
|
|
|
|
dd floppy_querymedia
|
|
|
|
|
dd floppy_read
|
|
|
|
|
dd floppy_write
|
|
|
|
|
dd 0 ; no flush() function
|
|
|
|
|
dd 0 ; no adjust_cache_size() function
|
|
|
|
|
.size = $ - floppy_functions
|
|
|
|
|
endg
|
|
|
|
|
|
|
|
|
|
uglobal
|
|
|
|
|
floppy_media_flags rb 2
|
|
|
|
|
n_sector dd 0 ; temporary save for sector value
|
|
|
|
|
flp_number db 0 ; 1- Floppy A, 2-Floppy B
|
|
|
|
|
old_track db 0 ; old value track
|
|
|
|
|
flp_label rb 15*2 ; Label and ID of inserted floppy disk
|
|
|
|
|
align 4
|
|
|
|
|
; Hardware does not allow to work with two floppies in parallel,
|
|
|
|
|
; so there is one mutex guarding access to any floppy.
|
|
|
|
|
floppy_mutex MUTEX
|
|
|
|
|
endg
|
|
|
|
|
; Meaning of bits in floppy_media_flags
|
|
|
|
|
FLOPPY_MEDIA_PRESENT = 1 ; media was present when last asked
|
|
|
|
|
FLOPPY_MEDIA_NEED_RESCAN = 2 ; media was possibly changed, need to rescan
|
|
|
|
|
FLOPPY_MEDIA_LABEL_CHANGED = 4 ; temporary state
|
|
|
|
|
|
|
|
|
|
iglobal
|
|
|
|
|
floppy1_name db 'fd',0
|
|
|
|
|
floppy2_name db 'fd2',0
|
|
|
|
|
endg
|
|
|
|
|
|
|
|
|
|
; This function is called in boot process.
|
|
|
|
|
; It creates filesystems /fd and/or /fd2, if the system has one/two floppy drives.
|
|
|
|
|
proc floppy_init
|
|
|
|
|
mov ecx, floppy_mutex
|
|
|
|
|
call mutex_init
|
|
|
|
|
; First floppy is present if [DRIVE_DATA] and 0xF0 is nonzero.
|
|
|
|
|
test byte [DRIVE_DATA], 0xF0
|
|
|
|
|
jz .no1
|
|
|
|
|
stdcall disk_add, floppy_functions, floppy1_name, 1, DISK_NO_INSERT_NOTIFICATION
|
|
|
|
|
.no1:
|
|
|
|
|
; Second floppy is present if [DRIVE_DATA] and 0x0F is nonzero.
|
|
|
|
|
test byte [DRIVE_DATA], 0x0F
|
|
|
|
|
jz .no2
|
|
|
|
|
stdcall disk_add, floppy_functions, floppy2_name, 2, DISK_NO_INSERT_NOTIFICATION
|
|
|
|
|
.no2:
|
|
|
|
|
ret
|
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
; Returns information about disk media.
|
|
|
|
|
; Floppy drives do not support insert notifications,
|
|
|
|
|
; DISK_NO_INSERT_NOTIFICATION is set,
|
|
|
|
|
; the disk subsystem calls this function before each filesystem operation.
|
|
|
|
|
; If the media has changed, return error for the first call as signal
|
|
|
|
|
; to finalize work with old media and the true geometry for the second call.
|
|
|
|
|
; Assume that media is (possibly) changed anytime when motor is off.
|
|
|
|
|
proc floppy_querymedia
|
|
|
|
|
virtual at esp+4
|
|
|
|
|
.userdata dd ?
|
|
|
|
|
.info dd ?
|
|
|
|
|
end virtual
|
|
|
|
|
; 1. Acquire the global lock.
|
|
|
|
|
mov ecx, floppy_mutex
|
|
|
|
|
call mutex_lock
|
|
|
|
|
mov edx, [.userdata] ; 1 for /fd, 2 for /fd2
|
|
|
|
|
; 2. If the media was reported and has been changed, forget it and report an error.
|
|
|
|
|
mov al, [floppy_media_flags+edx-1]
|
|
|
|
|
and al, FLOPPY_MEDIA_PRESENT + FLOPPY_MEDIA_NEED_RESCAN
|
|
|
|
|
cmp al, FLOPPY_MEDIA_PRESENT + FLOPPY_MEDIA_NEED_RESCAN
|
|
|
|
|
jnz .not_reported
|
|
|
|
|
.no_media:
|
|
|
|
|
mov [floppy_media_flags+edx-1], 0
|
|
|
|
|
.return_no_media:
|
|
|
|
|
mov ecx, floppy_mutex
|
|
|
|
|
call mutex_unlock
|
|
|
|
|
mov eax, DISK_STATUS_NO_MEDIA
|
|
|
|
|
retn 8
|
|
|
|
|
.not_reported:
|
|
|
|
|
; 3. If we are in the temporary state LABEL_CHANGED, this is the second call
|
|
|
|
|
; after intermediate DISK_STATUS_NO_MEDIA due to media change;
|
|
|
|
|
; clear the flag and return the current geometry without rereading the bootsector.
|
|
|
|
|
cmp [floppy_media_flags+edx-1], FLOPPY_MEDIA_LABEL_CHANGED
|
|
|
|
|
jz .report_geometry
|
|
|
|
|
; 4. Try to read the bootsector.
|
|
|
|
|
mov [flp_number], dl
|
|
|
|
|
mov [FDC_Status], 0
|
|
|
|
|
call floppy_read_bootsector
|
|
|
|
|
; 5. If reading bootsector failed, assume that media is not present.
|
|
|
|
|
mov edx, [.userdata]
|
|
|
|
|
cmp [FDC_Status], 0
|
|
|
|
|
jnz .no_media
|
|
|
|
|
; 6. Check whether the previous status is "present". If not, go to 10.
|
|
|
|
|
push esi edi
|
|
|
|
|
imul edi, edx, 15
|
|
|
|
|
add edi, flp_label-15
|
|
|
|
|
mov esi, FDD_BUFF+39
|
|
|
|
|
mov ecx, 15
|
|
|
|
|
test [floppy_media_flags+edx-1], FLOPPY_MEDIA_PRESENT
|
|
|
|
|
jz .set_label
|
|
|
|
|
; 7. Compare the old label with the current one.
|
|
|
|
|
rep cmpsb
|
|
|
|
|
; 8. If the label has not changed, go to 11.
|
|
|
|
|
jz .ok
|
|
|
|
|
; 9. If the label has changed, store it, enter temporary state LABEL_CHANGED
|
|
|
|
|
; and report DISK_STATUS_NO_MEDIA.
|
|
|
|
|
; dbgstr 'floppy label changed'
|
|
|
|
|
add esi, ecx
|
|
|
|
|
add edi, ecx
|
|
|
|
|
mov ecx, 15
|
|
|
|
|
sub esi, ecx
|
|
|
|
|
sub edi, ecx
|
|
|
|
|
rep movsb
|
|
|
|
|
mov [floppy_media_flags+edx-1], FLOPPY_MEDIA_LABEL_CHANGED
|
|
|
|
|
pop edi esi
|
|
|
|
|
jmp .return_no_media
|
|
|
|
|
.set_label:
|
|
|
|
|
; 10. The previous state was "not present". Copy the label.
|
|
|
|
|
rep movsb
|
|
|
|
|
.ok:
|
|
|
|
|
pop edi esi
|
|
|
|
|
.report_geometry:
|
|
|
|
|
; 11. Fill DISKMEDIAINFO structure.
|
|
|
|
|
mov ecx, [.info]
|
|
|
|
|
and [ecx+DISKMEDIAINFO.Flags], 0
|
|
|
|
|
mov [ecx+DISKMEDIAINFO.SectorSize], 512
|
|
|
|
|
mov dword [ecx+DISKMEDIAINFO.Capacity], FLOPPY_CAPACITY
|
|
|
|
|
and dword [ecx+DISKMEDIAINFO.Capacity+4], 0
|
|
|
|
|
; 12. Update state: media is present, data are actual.
|
|
|
|
|
mov [floppy_media_flags+edx-1], FLOPPY_MEDIA_PRESENT
|
|
|
|
|
; 13. Release the global lock and return successful status.
|
|
|
|
|
mov ecx, floppy_mutex
|
|
|
|
|
call mutex_unlock
|
|
|
|
|
xor eax, eax
|
|
|
|
|
retn 8
|
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
proc floppy_read_bootsector
|
|
|
|
|
pushad
|
|
|
|
|
mov [FDD_Track], 0; Цилиндр
|
|
|
|
|
mov [FDD_Head], 0; Сторона
|
|
|
|
|
mov [FDD_Sector], 1; Сектор
|
|
|
|
|
call FDDMotorON
|
|
|
|
|
call RecalibrateFDD
|
|
|
|
|
cmp [FDC_Status], 0
|
|
|
|
|
jne .nothing
|
|
|
|
|
call SeekTrack
|
|
|
|
|
cmp [FDC_Status], 0
|
|
|
|
|
jne .nothing
|
|
|
|
|
call ReadSectWithRetr
|
|
|
|
|
.nothing:
|
|
|
|
|
popad
|
|
|
|
|
ret
|
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
read_chs_sector:
|
|
|
|
|
call calculate_chs
|
|
|
|
|
call ReadSectWithRetr
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
save_chs_sector:
|
|
|
|
|
call calculate_chs
|
|
|
|
|
call WriteSectWithRetr
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
calculate_chs:
|
|
|
|
|
mov bl, [FDD_Track]
|
|
|
|
|
mov [old_track], bl
|
|
|
|
|
mov ebx, 18
|
|
|
|
|
xor edx, edx
|
|
|
|
|
div ebx
|
|
|
|
|
inc edx
|
|
|
|
|
mov [FDD_Sector], dl
|
|
|
|
|
mov edx, eax
|
|
|
|
|
shr eax, 1
|
|
|
|
|
and edx, 1
|
|
|
|
|
mov [FDD_Track], al
|
|
|
|
|
mov [FDD_Head], dl
|
|
|
|
|
mov dl, [old_track]
|
|
|
|
|
cmp dl, [FDD_Track]
|
|
|
|
|
je no_seek_track_1
|
|
|
|
|
call SeekTrack
|
|
|
|
|
no_seek_track_1:
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
; Writes one or more sectors to the device.
|
|
|
|
|
proc floppy_write
|
|
|
|
|
mov dl, 1
|
|
|
|
|
jmp floppy_read_write
|
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
; Reads one or more sectors from the device.
|
|
|
|
|
proc floppy_read
|
|
|
|
|
mov dl, 0
|
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
; Common part of floppy_read and floppy_write.
|
|
|
|
|
proc floppy_read_write userdata:dword, buffer:dword, start_sector:qword, numsectors_ptr:dword
|
|
|
|
|
virtual at ebp-8
|
|
|
|
|
.sectors_todo dd ?
|
|
|
|
|
.operation db ?
|
|
|
|
|
end virtual
|
|
|
|
|
push edx ; save operation code to [.operation]
|
|
|
|
|
; 1. Get number of sectors to read/write
|
|
|
|
|
; and zero number of sectors that were actually read/written.
|
|
|
|
|
mov eax, [numsectors_ptr]
|
|
|
|
|
push dword [eax] ; initialize [.sectors_todo]
|
|
|
|
|
and dword [eax], 0
|
|
|
|
|
push ebx esi edi ; save used registers to be stdcall
|
|
|
|
|
; 2. Acquire the global lock.
|
|
|
|
|
mov ecx, floppy_mutex
|
|
|
|
|
call mutex_lock
|
|
|
|
|
; 3. Set floppy number for this operation.
|
|
|
|
|
mov edx, [userdata]
|
|
|
|
|
mov [flp_number], dl
|
|
|
|
|
; 4. Read/write sector-by-sector.
|
|
|
|
|
.operation_loop:
|
|
|
|
|
; 4a. Check that the sector is inside the media.
|
|
|
|
|
cmp dword [start_sector+4], 0
|
|
|
|
|
jnz .end_of_media
|
|
|
|
|
mov eax, dword [start_sector]
|
|
|
|
|
cmp eax, FLOPPY_CAPACITY
|
|
|
|
|
jae .end_of_media
|
|
|
|
|
; 4b. For read operation, call read_chs_sector and then move data from FDD_BUFF to [buffer].
|
|
|
|
|
; For write operation, move data from [buffer] to FDD_BUFF and then call save_chs_sector.
|
|
|
|
|
cmp [.operation], 0
|
|
|
|
|
jz .read
|
|
|
|
|
mov esi, [buffer]
|
|
|
|
|
mov edi, FDD_BUFF
|
|
|
|
|
mov ecx, 512/4
|
|
|
|
|
rep movsd
|
|
|
|
|
mov [buffer], esi
|
|
|
|
|
call save_chs_sector
|
|
|
|
|
jmp @f
|
|
|
|
|
.read:
|
|
|
|
|
call read_chs_sector
|
|
|
|
|
mov esi, FDD_BUFF
|
|
|
|
|
mov edi, [buffer]
|
|
|
|
|
mov ecx, 512/4
|
|
|
|
|
rep movsd
|
|
|
|
|
mov [buffer], edi
|
|
|
|
|
@@:
|
|
|
|
|
; 4c. If there was an error, propagate it to the caller.
|
|
|
|
|
cmp [FDC_Status], 0
|
|
|
|
|
jnz .fail
|
|
|
|
|
; 4d. Otherwise, increment number of sectors processed and continue the loop.
|
|
|
|
|
mov eax, [numsectors_ptr]
|
|
|
|
|
inc dword [eax]
|
|
|
|
|
inc dword [start_sector]
|
|
|
|
|
dec [.sectors_todo]
|
|
|
|
|
jnz .operation_loop
|
|
|
|
|
; 5. Release the global lock and return with the correct status.
|
|
|
|
|
push 0
|
|
|
|
|
.return:
|
|
|
|
|
mov ecx, floppy_mutex
|
|
|
|
|
call mutex_unlock
|
|
|
|
|
pop eax
|
|
|
|
|
pop edi esi ebx ; restore used registers to be stdcall
|
|
|
|
|
ret ; this translates to leave/retn N and purges local variables
|
|
|
|
|
.fail:
|
|
|
|
|
push -1
|
|
|
|
|
jmp .return
|
|
|
|
|
.end_of_media:
|
|
|
|
|
push DISK_STATUS_END_OF_MEDIA
|
|
|
|
|
jmp .return
|
|
|
|
|
endp
|