From 93e2c279baacf40c0aa8b35e22cba47188c0d3a0 Mon Sep 17 00:00:00 2001 From: "Marat Zakiyanov (Mario79)" Date: Sun, 22 Jul 2007 20:52:21 +0000 Subject: [PATCH] The universal cache of IDE devices. Step 2: 1) Realized cache ATAPI device (CD\DVD). 2) Lock\Unlock ATAPI device for working with cache. 3) Eject (F70/10) and Load (F70/11) tray of ATAPI device. 4) Application CD_tray for control of tray ATAPI device. git-svn-id: svn://kolibrios.org@585 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/trunk/blkdev/cd_drv.inc | 802 +++++++++-------- kernel/trunk/blkdev/ide_cache.inc | 524 ++++++++--- kernel/trunk/data32.inc | 2 + kernel/trunk/detect/getcache.inc | 71 +- kernel/trunk/docs/sysfuncr.txt | 64 ++ kernel/trunk/docs/sysfuncs.txt | 62 ++ kernel/trunk/fs/fs_lfn.inc | 1291 ++++++++++++++------------- kernel/trunk/fs/iso9660.inc | 507 ++++++----- programs/system/cd_tray/CD_tray.ASM | 186 ++++ programs/system/cd_tray/MACROS.INC | 268 ++++++ programs/system/cd_tray/build.bat | 2 + 11 files changed, 2397 insertions(+), 1382 deletions(-) create mode 100644 programs/system/cd_tray/CD_tray.ASM create mode 100644 programs/system/cd_tray/MACROS.INC create mode 100644 programs/system/cd_tray/build.bat diff --git a/kernel/trunk/blkdev/cd_drv.inc b/kernel/trunk/blkdev/cd_drv.inc index d3b2f78a74..b303bdd19e 100644 --- a/kernel/trunk/blkdev/cd_drv.inc +++ b/kernel/trunk/blkdev/cd_drv.inc @@ -16,7 +16,6 @@ $Revision$ ; данных из сектора компакт-диска ; Автор текста программы Кулаков Владимир Геннадьевич. - ; Максимальное количество повторений операции чтения MaxRetr equ 10 ; Предельное время ожидания готовности к приему команды @@ -35,74 +34,138 @@ NoTickWaitTime equ 0xfffff ;* Данные считывается в массив CDDataBuf. * ;************************************************* ReadCD: - pusha + pusha ; Задать размер сектора - mov [CDBlockSize],2048 ;2352 + mov [CDBlockSize],2048 ;2352 ; Очистить буфер пакетной команды - call clear_packet_buffer + call clear_packet_buffer ; Сформировать пакетную команду для считывания ; сектора данных - ; Задать код команды Read CD - mov [PacketCommand],byte 0x28 ;0xBE - ; Задать адрес сектора - mov AX,word [CDSectorAddress+2] - xchg AL,AH - mov word [PacketCommand+2],AX - mov AX,word [CDSectorAddress] - xchg AL,AH - mov word [PacketCommand+4],AX + ; Задать код команды Read CD + mov [PacketCommand],byte 0x28 ;0xBE + ; Задать адрес сектора + mov AX,word [CDSectorAddress+2] + xchg AL,AH + mov word [PacketCommand+2],AX + mov AX,word [CDSectorAddress] + xchg AL,AH + mov word [PacketCommand+4],AX ; mov eax,[CDSectorAddress] ; mov [PacketCommand+2],eax - ; Задать количество считываемых секторов - mov [PacketCommand+8],byte 1 - ; Задать считывание данных в полном объеме + ; Задать количество считываемых секторов + mov [PacketCommand+8],byte 1 + ; Задать считывание данных в полном объеме ; mov [PacketCommand+9],byte 0xF8 ; Подать команду - call SendPacketDatCommand + call SendPacketDatCommand ; call test_mario79 - popa - ret + popa + ret ;******************************************** ;* ЧТЕНИЕ СЕКТОРА С ПОВТОРАМИ * ;* Многократное повторение чтения при сбоях * ;******************************************** ReadCDWRetr: - pushad - +;----------------------------------------------------------- +; input : eax = block to read +; ebx = destination +;----------------------------------------------------------- + pushad + mov eax,[CDSectorAddress] + mov ebx,[CDDataBuf_pointer] + call cd_calculate_cache + add esi,8 + mov edi,1 +.hdreadcache: +; push esi +; mov esi,[esi] +; call test_mario79 +; mov esi,eax +; call test_mario79 +; pop esi + +; cmp dword [esi+4],0 ; empty +; je .nohdcache + cmp [esi],eax ; correct sector + je .yeshdcache +.nohdcache: + add esi,8 + inc edi + dec ecx + jnz .hdreadcache + call find_empty_slot_CD_cache ; ret in edi + + push edi + push eax + call cd_calculate_cache_2 + shl edi,11 + add edi,eax + mov [CDDataBuf_pointer],edi + pop eax + pop edi + + call ReadCDWRetr_1 + mov [CDDataBuf_pointer],ebx + call cd_calculate_cache_1 + lea esi,[edi*8+esi] +; push esi +; call test_mario79 +; mov esi,eax +; call test_mario79 +; pop esi + mov [esi],eax ; sector number +; mov dword [esi+4],1 ; hd read - mark as same as in hd +.yeshdcache: + mov esi,edi + shl esi,11 ;9 + push eax + call cd_calculate_cache_2 + add esi,eax + pop eax + mov edi,ebx ;[CDDataBuf_pointer] + mov ecx,512 ;/4 + cld + rep movsd ; move data + popad + ret + +ReadCDWRetr_1: + pushad + ; Цикл, пока команда не выполнена успешно или не ; исчерпано количество попыток - mov ECX,MaxRetr + mov ECX,MaxRetr @@NextRetr: ; Подать команду - call ReadCD - cmp [DevErrorCode],0 - je @@End_4 - - or ecx,ecx ;{SPraid.simba} (for cd load) - jz @@End_4 - dec ecx - - cmp [timer_ticks_enable],0 - jne @f - mov eax,NoTickWaitTime + call ReadCD + cmp [DevErrorCode],0 + je @@End_4 + + or ecx,ecx ;{SPraid.simba} (for cd load) + jz @@End_4 + dec ecx + + cmp [timer_ticks_enable],0 + jne @f + mov eax,NoTickWaitTime .wait: - dec eax - cmp eax,0 - je @@NextRetr - jmp .wait + dec eax + cmp eax,0 + je @@NextRetr + jmp .wait @@: ; Задержка на 2,5 секунды - mov EAX,[timer_ticks] - add EAX,250 ;50 + mov EAX,[timer_ticks] + add EAX,250 ;50 @@Wait: - call change_task - cmp EAX,[timer_ticks] - ja @@Wait - loop @@NextRetr + call change_task + cmp EAX,[timer_ticks] + ja @@Wait + loop @@NextRetr @@End_4: - popad - ret + popad + ret ; Универсальные процедуры, обеспечивающие выполнение @@ -115,11 +178,11 @@ ReadCDWRetr: MaxCDWaitTime equ 1000 ;200 ;10 секунд ; Область памяти для формирования пакетной команды -PacketCommand: rb 12 ;DB 12 DUP (?) +PacketCommand: rb 12 ;DB 12 DUP (?) ; Область памяти для приема данных от дисковода ;CDDataBuf DB 4096 DUP (0) ; Размер принимаемого блока данных в байтах -CDBlockSize DW ? +CDBlockSize DW ? ; Адрес считываемого сектора данных CDSectorAddress: DD ? ; Время начала очередной операции с диском @@ -141,123 +204,123 @@ CDDataBuf_pointer dd 0 ;* CDBlockSize - размер принимаемого блока данных. * ;**************************************************** SendPacketDatCommand: - pushad + pushad ; Задать режим CHS - mov [ATAAddressMode],0 + mov [ATAAddressMode],0 ; Послать ATA-команду передачи пакетной команды - mov [ATAFeatures],0 - mov [ATASectorCount],0 - mov [ATASectorNumber],0 - ; Загрузить размер передаваемого блока - mov AX,[CDBlockSize] - mov [ATACylinder],AX - mov [ATAHead],0 - mov [ATACommand],0A0h - call SendCommandToHDD_1 - cmp [DevErrorCode],0 ;проверить код ошибки - jne @@End_8 ;закончить, сохранив код ошибки + mov [ATAFeatures],0 + mov [ATASectorCount],0 + mov [ATASectorNumber],0 + ; Загрузить размер передаваемого блока + mov AX,[CDBlockSize] + mov [ATACylinder],AX + mov [ATAHead],0 + mov [ATACommand],0A0h + call SendCommandToHDD_1 + cmp [DevErrorCode],0 ;проверить код ошибки + jne @@End_8 ;закончить, сохранив код ошибки ; Ожидание готовности дисковода к приему ; пакетной команды - mov DX,[ATABasePortAddr] - add DX,7 ;порт 1х7h - mov ecx,NoTickWaitTime + mov DX,[ATABasePortAddr] + add DX,7 ;порт 1х7h + mov ecx,NoTickWaitTime @@WaitDevice0: - cmp [timer_ticks_enable],0 - jne @f - dec ecx - cmp ecx,0 - je @@Err1_1 - jmp .test + cmp [timer_ticks_enable],0 + jne @f + dec ecx + cmp ecx,0 + je @@Err1_1 + jmp .test @@: - call change_task - ; Проверить время выполнения команды - mov EAX,[timer_ticks] - sub EAX,[TickCounter_1] - cmp EAX,BSYWaitTime - ja @@Err1_1 ;ошибка тайм-аута - ; Проверить готовность + call change_task + ; Проверить время выполнения команды + mov EAX,[timer_ticks] + sub EAX,[TickCounter_1] + cmp EAX,BSYWaitTime + ja @@Err1_1 ;ошибка тайм-аута + ; Проверить готовность .test: - in AL,DX - test AL,80h ;состояние сигнала BSY - jnz @@WaitDevice0 - test AL,08h ;состояние сигнала DRQ - jz @@WaitDevice0 - test AL,1 ;состояние сигнала ERR - jnz @@Err6 + in AL,DX + test AL,80h ;состояние сигнала BSY + jnz @@WaitDevice0 + test AL,08h ;состояние сигнала DRQ + jz @@WaitDevice0 + test AL,1 ;состояние сигнала ERR + jnz @@Err6 ; Послать пакетную команду - cli - mov DX,[ATABasePortAddr] - mov AX,[PacketCommand] - out DX,AX - mov AX,[PacketCommand+2] - out DX,AX - mov AX,[PacketCommand+4] - out DX,AX - mov AX,[PacketCommand+6] - out DX,AX - mov AX,[PacketCommand+8] - out DX,AX - mov AX,[PacketCommand+10] - out DX,AX - sti + cli + mov DX,[ATABasePortAddr] + mov AX,[PacketCommand] + out DX,AX + mov AX,[PacketCommand+2] + out DX,AX + mov AX,[PacketCommand+4] + out DX,AX + mov AX,[PacketCommand+6] + out DX,AX + mov AX,[PacketCommand+8] + out DX,AX + mov AX,[PacketCommand+10] + out DX,AX + sti ; Ожидание готовности данных - mov DX,[ATABasePortAddr] - add DX,7 ;порт 1х7h - mov ecx,NoTickWaitTime + mov DX,[ATABasePortAddr] + add DX,7 ;порт 1х7h + mov ecx,NoTickWaitTime @@WaitDevice1: - cmp [timer_ticks_enable],0 - jne @f - dec ecx - cmp ecx,0 - je @@Err1_1 - jmp .test_1 + cmp [timer_ticks_enable],0 + jne @f + dec ecx + cmp ecx,0 + je @@Err1_1 + jmp .test_1 @@: - call change_task - ; Проверить время выполнения команды - mov EAX,[timer_ticks] - sub EAX,[TickCounter_1] - cmp EAX,MaxCDWaitTime - ja @@Err1_1 ;ошибка тайм-аута - ; Проверить готовность + call change_task + ; Проверить время выполнения команды + mov EAX,[timer_ticks] + sub EAX,[TickCounter_1] + cmp EAX,MaxCDWaitTime + ja @@Err1_1 ;ошибка тайм-аута + ; Проверить готовность .test_1: - in AL,DX - test AL,80h ;состояние сигнала BSY - jnz @@WaitDevice1 - test AL,08h ;состояние сигнала DRQ - jz @@WaitDevice1 - test AL,1 ;состояние сигнала ERR - jnz @@Err6_temp + in AL,DX + test AL,80h ;состояние сигнала BSY + jnz @@WaitDevice1 + test AL,08h ;состояние сигнала DRQ + jz @@WaitDevice1 + test AL,1 ;состояние сигнала ERR + jnz @@Err6_temp ; Принять блок данных от контроллера - mov EDI,[CDDataBuf_pointer] ;0x7000 ;CDDataBuf - ; Загрузить адрес регистра данных контроллера - mov DX,[ATABasePortAddr] ;порт 1x0h - ; Загрузить в счетчик размер блока в байтах - xor ecx,ecx - mov CX,[CDBlockSize] - ; Вычислить размер блока в 16-разрядных словах - shr CX,1 ;разделить размер блока на 2 - ; Принять блок данных - cli - cld - rep insw - sti - ; Успешное завершение приема данных - jmp @@End_8 + mov EDI,[CDDataBuf_pointer] ;0x7000 ;CDDataBuf + ; Загрузить адрес регистра данных контроллера + mov DX,[ATABasePortAddr] ;порт 1x0h + ; Загрузить в счетчик размер блока в байтах + xor ecx,ecx + mov CX,[CDBlockSize] + ; Вычислить размер блока в 16-разрядных словах + shr CX,1 ;разделить размер блока на 2 + ; Принять блок данных + cli + cld + rep insw + sti + ; Успешное завершение приема данных + jmp @@End_8 ; Записать код ошибки @@Err1_1: - mov [DevErrorCode],1 - jmp @@End_8 + mov [DevErrorCode],1 + jmp @@End_8 @@Err6_temp: - mov [DevErrorCode],7 - jmp @@End_8 + mov [DevErrorCode],7 + jmp @@End_8 @@Err6: - mov [DevErrorCode],6 + mov [DevErrorCode],6 @@End_8: - popad - ret + popad + ret @@ -271,83 +334,83 @@ SendPacketDatCommand: ;* PacketCommand - 12-байтный командный пакет. * ;*********************************************** SendPacketNoDatCommand: - pushad + pushad ; Задать режим CHS - mov [ATAAddressMode],0 + mov [ATAAddressMode],0 ; Послать ATA-команду передачи пакетной команды - mov [ATAFeatures],0 - mov [ATASectorCount],0 - mov [ATASectorNumber],0 - mov [ATACylinder],0 - mov [ATAHead],0 - mov [ATACommand],0A0h - call SendCommandToHDD_1 - cmp [DevErrorCode],0 ;проверить код ошибки - jne @@End_9 ;закончить, сохранив код ошибки + mov [ATAFeatures],0 + mov [ATASectorCount],0 + mov [ATASectorNumber],0 + mov [ATACylinder],0 + mov [ATAHead],0 + mov [ATACommand],0A0h + call SendCommandToHDD_1 + cmp [DevErrorCode],0 ;проверить код ошибки + jne @@End_9 ;закончить, сохранив код ошибки ; Ожидание готовности дисковода к приему ; пакетной команды - mov DX,[ATABasePortAddr] - add DX,7 ;порт 1х7h + mov DX,[ATABasePortAddr] + add DX,7 ;порт 1х7h @@WaitDevice0_1: - call change_task - ; Проверить время ожидания - mov EAX,[timer_ticks] - sub EAX,[TickCounter_1] - cmp EAX,BSYWaitTime - ja @@Err1_3 ;ошибка тайм-аута - ; Проверить готовность - in AL,DX - test AL,80h ;состояние сигнала BSY - jnz @@WaitDevice0_1 - test AL,1 ;состояние сигнала ERR - jnz @@Err6_1 - test AL,08h ;состояние сигнала DRQ - jz @@WaitDevice0_1 + call change_task + ; Проверить время ожидания + mov EAX,[timer_ticks] + sub EAX,[TickCounter_1] + cmp EAX,BSYWaitTime + ja @@Err1_3 ;ошибка тайм-аута + ; Проверить готовность + in AL,DX + test AL,80h ;состояние сигнала BSY + jnz @@WaitDevice0_1 + test AL,1 ;состояние сигнала ERR + jnz @@Err6_1 + test AL,08h ;состояние сигнала DRQ + jz @@WaitDevice0_1 ; Послать пакетную команду ; cli - mov DX,[ATABasePortAddr] - mov AX,word [PacketCommand] - out DX,AX - mov AX,word [PacketCommand+2] - out DX,AX - mov AX,word [PacketCommand+4] - out DX,AX - mov AX,word [PacketCommand+6] - out DX,AX - mov AX,word [PacketCommand+8] - out DX,AX - mov AX,word [PacketCommand+10] - out DX,AX + mov DX,[ATABasePortAddr] + mov AX,word [PacketCommand] + out DX,AX + mov AX,word [PacketCommand+2] + out DX,AX + mov AX,word [PacketCommand+4] + out DX,AX + mov AX,word [PacketCommand+6] + out DX,AX + mov AX,word [PacketCommand+8] + out DX,AX + mov AX,word [PacketCommand+10] + out DX,AX ; sti ; Ожидание подтверждения приема команды - mov DX,[ATABasePortAddr] - add DX,7 ;порт 1х7h + mov DX,[ATABasePortAddr] + add DX,7 ;порт 1х7h @@WaitDevice1_1: - call change_task - ; Проверить время выполнения команды - mov EAX,[timer_ticks] - sub EAX,[TickCounter_1] - cmp EAX,MaxCDWaitTime - ja @@Err1_3 ;ошибка тайм-аута - ; Ожидать освобождения устройства - in AL,DX - test AL,80h ;состояние сигнала BSY - jnz @@WaitDevice1_1 - test AL,1 ;состояние сигнала ERR - jnz @@Err6_1 - test AL,40h ;состояние сигнала DRDY - jz @@WaitDevice1_1 - jmp @@End_9 + call change_task + ; Проверить время выполнения команды + mov EAX,[timer_ticks] + sub EAX,[TickCounter_1] + cmp EAX,MaxCDWaitTime + ja @@Err1_3 ;ошибка тайм-аута + ; Ожидать освобождения устройства + in AL,DX + test AL,80h ;состояние сигнала BSY + jnz @@WaitDevice1_1 + test AL,1 ;состояние сигнала ERR + jnz @@Err6_1 + test AL,40h ;состояние сигнала DRDY + jz @@WaitDevice1_1 + jmp @@End_9 ; Записать код ошибки @@Err1_3: - mov [DevErrorCode],1 - jmp @@End_9 + mov [DevErrorCode],1 + jmp @@End_9 @@Err6_1: - mov [DevErrorCode],6 + mov [DevErrorCode],6 @@End_9: - popad - ret + popad + ret ;**************************************************** ;* ПОСЛАТЬ КОМАНДУ ЗАДАННОМУ ДИСКУ * @@ -369,119 +432,119 @@ SendPacketNoDatCommand: ;* возвращен код ошибки. * ;**************************************************** SendCommandToHDD_1: - pushad + pushad ; Проверить значение кода режима - cmp [ATAAddressMode],1 - ja @@Err2_4 + cmp [ATAAddressMode],1 + ja @@Err2_4 ; Проверить корректность номера канала - mov BX,[ChannelNumber] - cmp BX,1 - jb @@Err3_4 - cmp BX,2 - ja @@Err3_4 + mov BX,[ChannelNumber] + cmp BX,1 + jb @@Err3_4 + cmp BX,2 + ja @@Err3_4 ; Установить базовый адрес - dec BX - shl BX,1 - movzx ebx,bx - mov AX,[ebx+StandardATABases] - mov [ATABasePortAddr],AX + dec BX + shl BX,1 + movzx ebx,bx + mov AX,[ebx+StandardATABases] + mov [ATABasePortAddr],AX ; Ожидание готовности HDD к приему команды - ; Выбрать нужный диск - mov DX,[ATABasePortAddr] - add DX,6 ;адрес регистра головок - mov AL,[DiskNumber] - cmp AL,1 ;проверить номера диска - ja @@Err4_4 - shl AL,4 - or AL,10100000b - out DX,AL - ; Ожидать, пока диск не будет готов - inc DX - mov eax,[timer_ticks] - mov [TickCounter_1],eax - mov ecx,NoTickWaitTime + ; Выбрать нужный диск + mov DX,[ATABasePortAddr] + add DX,6 ;адрес регистра головок + mov AL,[DiskNumber] + cmp AL,1 ;проверить номера диска + ja @@Err4_4 + shl AL,4 + or AL,10100000b + out DX,AL + ; Ожидать, пока диск не будет готов + inc DX + mov eax,[timer_ticks] + mov [TickCounter_1],eax + mov ecx,NoTickWaitTime @@WaitHDReady_2: - cmp [timer_ticks_enable],0 - jne @f - dec ecx - cmp ecx,0 - je @@Err1_4 - jmp .test + cmp [timer_ticks_enable],0 + jne @f + dec ecx + cmp ecx,0 + je @@Err1_4 + jmp .test @@: - call change_task - ; Проверить время ожидания - mov eax,[timer_ticks] - sub eax,[TickCounter_1] - cmp eax,BSYWaitTime ;300 ;ожидать 3 сек. - ja @@Err1_4 ;ошибка тайм-аута - ; Прочитать регистр состояния + call change_task + ; Проверить время ожидания + mov eax,[timer_ticks] + sub eax,[TickCounter_1] + cmp eax,BSYWaitTime ;300 ;ожидать 3 сек. + ja @@Err1_4 ;ошибка тайм-аута + ; Прочитать регистр состояния .test: - in AL,DX - ; Проверить состояние сигнала BSY - test AL,80h - jnz @@WaitHDReady_2 - ; Проверить состояние сигнала DRQ - test AL,08h - jnz @@WaitHDReady_2 + in AL,DX + ; Проверить состояние сигнала BSY + test AL,80h + jnz @@WaitHDReady_2 + ; Проверить состояние сигнала DRQ + test AL,08h + jnz @@WaitHDReady_2 ; Загрузить команду в регистры контроллера - cli - mov DX,[ATABasePortAddr] - inc DX ;регистр "особенностей" - mov AL,[ATAFeatures] - out DX,AL - inc DX ;счетчик секторов - mov AL,[ATASectorCount] - out DX,AL - inc DX ;регистр номера сектора - mov AL,[ATASectorNumber] - out DX,AL - inc DX ;номер цилиндра (младший байт) - mov AX,[ATACylinder] - out DX,AL - inc DX ;номер цилиндра (старший байт) - mov AL,AH - out DX,AL - inc DX ;номер головки/номер диска - mov AL,[DiskNumber] - shl AL,4 - cmp [ATAHead],0Fh ;проверить номер головки - ja @@Err5_4 - or AL,[ATAHead] - or AL,10100000b - mov AH,[ATAAddressMode] - shl AH,6 - or AL,AH - out DX,AL + cli + mov DX,[ATABasePortAddr] + inc DX ;регистр "особенностей" + mov AL,[ATAFeatures] + out DX,AL + inc DX ;счетчик секторов + mov AL,[ATASectorCount] + out DX,AL + inc DX ;регистр номера сектора + mov AL,[ATASectorNumber] + out DX,AL + inc DX ;номер цилиндра (младший байт) + mov AX,[ATACylinder] + out DX,AL + inc DX ;номер цилиндра (старший байт) + mov AL,AH + out DX,AL + inc DX ;номер головки/номер диска + mov AL,[DiskNumber] + shl AL,4 + cmp [ATAHead],0Fh ;проверить номер головки + ja @@Err5_4 + or AL,[ATAHead] + or AL,10100000b + mov AH,[ATAAddressMode] + shl AH,6 + or AL,AH + out DX,AL ; Послать команду - mov AL,[ATACommand] - inc DX ;регистр команд - out DX,AL - sti + mov AL,[ATACommand] + inc DX ;регистр команд + out DX,AL + sti ; Сбросить признак ошибки - mov [DevErrorCode],0 - jmp @@End_10 + mov [DevErrorCode],0 + jmp @@End_10 ; Записать код ошибки @@Err1_4: - mov [DevErrorCode],1 - jmp @@End_10 + mov [DevErrorCode],1 + jmp @@End_10 @@Err2_4: - mov [DevErrorCode],2 - jmp @@End_10 + mov [DevErrorCode],2 + jmp @@End_10 @@Err3_4: - mov [DevErrorCode],3 - jmp @@End_10 + mov [DevErrorCode],3 + jmp @@End_10 @@Err4_4: - mov [DevErrorCode],4 - jmp @@End_10 + mov [DevErrorCode],4 + jmp @@End_10 @@Err5_4: - mov [DevErrorCode],5 + mov [DevErrorCode],5 ; Завершение работы программы @@End_10: ; sti - popad - ret - + popad + ret + ;************************************************* ;* ОЖИДАНИЕ ГОТОВНОСТИ УСТРОЙСТВА К РАБОТЕ * ;* Входные параметры передаются через глобальные * @@ -490,34 +553,73 @@ SendCommandToHDD_1: ;* DiskNumber - номер диска на канале. * ;************************************************* WaitUnitReady: - pusha + pusha ; Запомнить время начала операции - mov EAX,[timer_ticks] - mov [WURStartTime],EAX + mov EAX,[timer_ticks] + mov [WURStartTime],EAX ; Очистить буфер пакетной команды - call clear_packet_buffer + call clear_packet_buffer ; Сформировать команду TEST UNIT READY - mov [PacketCommand],word 00h + mov [PacketCommand],word 00h ; ЦИКЛ ОЖИДАНИЯ ГОТОВНОСТИ УСТРОЙСТВА @@SendCommand: - ; Подать команду проверки готовности - call SendPacketNoDatCommand - call change_task - ; Проверить код ошибки - cmp [DevErrorCode],0 - je @@End_11 - ; Проверить время ожидания готовности - mov EAX,[timer_ticks] - sub EAX,[WURStartTime] - cmp EAX,MaxCDWaitTime - jb @@SendCommand - ; Ошибка тайм-аута - mov [DevErrorCode],1 + ; Подать команду проверки готовности + call SendPacketNoDatCommand + call change_task + ; Проверить код ошибки + cmp [DevErrorCode],0 + je @@End_11 + ; Проверить время ожидания готовности + mov EAX,[timer_ticks] + sub EAX,[WURStartTime] + cmp EAX,MaxCDWaitTime + jb @@SendCommand + ; Ошибка тайм-аута + mov [DevErrorCode],1 @@End_11: - popa - ret + popa + ret + +;************************************************* +;* ЗАПРЕТИТЬ СМЕНУ ДИСКА * +;* Входные параметры передаются через глобальные * +;* перменные: * +;* ChannelNumber - номер канала; * +;* DiskNumber - номер диска на канале. * +;************************************************* +prevent_medium_removal: + pusha +; Очистить буфер пакетной команды + call clear_packet_buffer +; Задать код команды + mov [PacketCommand],byte 0x1E +; Задать код запрета + mov [PacketCommand+4],byte 11b +; Подать команду + call SendPacketNoDatCommand + popa + ret + +;************************************************* +;* РАЗРЕШИТЬ СМЕНУ ДИСКА * +;* Входные параметры передаются через глобальные * +;* перменные: * +;* ChannelNumber - номер канала; * +;* DiskNumber - номер диска на канале. * +;************************************************* +allow_medium_removal: + pusha +; Очистить буфер пакетной команды + call clear_packet_buffer +; Задать код команды + mov [PacketCommand],byte 0x1E +; Задать код запрета + mov [PacketCommand+4],byte 00b +; Подать команду + call SendPacketNoDatCommand + popa + ret - ;************************************************* ;* ЗАГРУЗИТЬ НОСИТЕЛЬ В ДИСКОВОД * ;* Входные параметры передаются через глобальные * @@ -526,18 +628,18 @@ WaitUnitReady: ;* DiskNumber - номер диска на канале. * ;************************************************* LoadMedium: - pusha + pusha ; Очистить буфер пакетной команды - call clear_packet_buffer + call clear_packet_buffer ; Сформировать команду START/STOP UNIT - ; Задать код команды - mov [PacketCommand],word 1Bh - ; Задать операцию загрузки носителя - mov [PacketCommand+4],word 00000011b + ; Задать код команды + mov [PacketCommand],word 1Bh + ; Задать операцию загрузки носителя + mov [PacketCommand+4],word 00000011b ; Подать команду - call SendPacketNoDatCommand - popa - ret + call SendPacketNoDatCommand + popa + ret ;************************************************* ;* ИЗВЛЕЧЬ НОСИТЕЛЬ ИЗ ДИСКОВОДА * @@ -546,19 +648,19 @@ LoadMedium: ;* ChannelNumber - номер канала; * ;* DiskNumber - номер диска на канале. * ;************************************************* -UnloadMedium: - pusha +EjectMedium: + pusha ; Очистить буфер пакетной команды - call clear_packet_buffer + call clear_packet_buffer ; Сформировать команду START/STOP UNIT - ; Задать код команды - mov [PacketCommand],word 1Bh - ; Задать операцию извлечения носителя - mov [PacketCommand+4],word 00000010b + ; Задать код команды + mov [PacketCommand],word 1Bh + ; Задать операцию извлечения носителя + mov [PacketCommand+4],word 00000010b ; Подать команду - call SendPacketNoDatCommand - popa - ret + call SendPacketNoDatCommand + popa + ret ;************************************************* ;* ОПРЕДЕЛИТЬ ОБЩЕЕ КОЛИЧЕСТВО СЕКТОРОВ НА ДИСКЕ * @@ -568,22 +670,22 @@ UnloadMedium: ;* DiskNumber - номер диска на канале. * ;************************************************* ReadCapacity: - pusha + pusha ; Очистить буфер пакетной команды - call clear_packet_buffer + call clear_packet_buffer ; Задать размер буфера в байтах - mov [CDBlockSize],8 + mov [CDBlockSize],8 ; Сформировать команду READ CAPACITY - mov [PacketCommand],word 25h + mov [PacketCommand],word 25h ; Подать команду - call SendPacketDatCommand - popa - ret + call SendPacketDatCommand + popa + ret -clear_packet_buffer: +clear_packet_buffer: ; Очистить буфер пакетной команды - mov [PacketCommand],dword 0 - mov [PacketCommand+4],dword 0 - mov [PacketCommand+8],dword 0 - ret + mov [PacketCommand],dword 0 + mov [PacketCommand+4],dword 0 + mov [PacketCommand+8],dword 0 + ret diff --git a/kernel/trunk/blkdev/ide_cache.inc b/kernel/trunk/blkdev/ide_cache.inc index 760c658bde..a551a967f4 100644 --- a/kernel/trunk/blkdev/ide_cache.inc +++ b/kernel/trunk/blkdev/ide_cache.inc @@ -21,85 +21,73 @@ write_cache: push eax ecx edx esi edi ; write difference ( 2 ) from cache to hd - -; mov ecx,cache_max -; mov esi,HD_CACHE+8 call calculate_cache add esi,8 - mov edi,1 - - write_cache_more: - - cmp dword [esi+4],2 ; if cache slot is not different +write_cache_more: + cmp dword [esi+4],2 ; if cache slot is not different jne .write_chain - - mov dword [esi+4],1 ; same as in hd - mov eax,[esi] ; eax = sector to write - + mov dword [esi+4],1 ; same as in hd + mov eax,[esi] ; eax = sector to write cmp eax,[PARTITION_START] - jb danger + jb danger cmp eax,[PARTITION_END] - ja danger - + ja danger ; DMA write is permitted only if [allow_dma_access]=1 - cmp [allow_dma_access], 2 - jae .nodma - cmp [dma_hdd], 1 - jnz .nodma + cmp [allow_dma_access], 2 + jae .nodma + cmp [dma_hdd], 1 + jnz .nodma ; ЋЎкҐ¤Ё­пҐ¬ § ЇЁбм 楯®зЄЁ Ї®б«Ґ¤®ў вҐ«м­ле ᥪв®а®ў ў ®¤­® ®Ўа йҐ­ЁҐ Є ¤ЁбЄг - cmp ecx, 1 - jz .nonext - cmp dword [esi+8+4], 2 - jnz .nonext - push eax - inc eax - cmp eax, [esi+8] - pop eax - jnz .nonext - cmp [cache_chain_started], 1 - jz @f - mov [cache_chain_started], 1 - mov [cache_chain_size], 0 - mov [cache_chain_pos], edi - mov [cache_chain_ptr], esi + cmp ecx, 1 + jz .nonext + cmp dword [esi+8+4], 2 + jnz .nonext + push eax + inc eax + cmp eax, [esi+8] + pop eax + jnz .nonext + cmp [cache_chain_started], 1 + jz @f + mov [cache_chain_started], 1 + mov [cache_chain_size], 0 + mov [cache_chain_pos], edi + mov [cache_chain_ptr], esi @@: - inc [cache_chain_size] - cmp [cache_chain_size], 64 - jnz .continue - jmp .write_chain + inc [cache_chain_size] + cmp [cache_chain_size], 64 + jnz .continue + jmp .write_chain .nonext: - call flush_cache_chain - mov [cache_chain_size], 1 - mov [cache_chain_ptr], esi - call write_cache_sector - jmp .continue + call flush_cache_chain + mov [cache_chain_size], 1 + mov [cache_chain_ptr], esi + call write_cache_sector + jmp .continue .nodma: - call cache_write_pio + call cache_write_pio .write_chain: - call flush_cache_chain - + call flush_cache_chain .continue: - danger: - +danger: add esi,8 inc edi dec ecx jnz write_cache_more - call flush_cache_chain + call flush_cache_chain return_02: pop edi esi edx ecx eax ret flush_cache_chain: - cmp [cache_chain_started], 0 - jz @f - call write_cache_chain - mov [cache_chain_started], 0 + cmp [cache_chain_started], 0 + jz @f + call write_cache_chain + mov [cache_chain_started], 0 @@: - ret - - + ret +;-------------------------------------------------------------------- align 4 find_empty_slot: ;----------------------------------------------------------- @@ -108,68 +96,36 @@ find_empty_slot: ;----------------------------------------------------------- ; push ecx esi - search_again: - -; mov ecx,cache_max*10/100 -; mov edi,[cache_search_start] +search_again: call calculate_cache_3 -; push eax edx -; mov eax,ecx -; mov ecx,10 -; xor edx,edx -; div ecx -; mov ecx,eax -; pop edx eax - shr ecx,3 - search_for_empty: - + shr ecx,3 +search_for_empty: inc edi -; cmp edi,cache_max -; push eax call calculate_cache_4 -; cmp edi,eax -; pop eax jbe inside_cache mov edi,1 - - inside_cache: - -; cmp dword [edi*8+HD_CACHE+4],2 ; get cache slot info +inside_cache: push esi call calculate_cache_1 cmp dword [edi*8+esi+4],2 pop esi - jb found_slot ; it's empty or read + jb found_slot ; it's empty or read dec ecx jnz search_for_empty - - call write_cache ; no empty slots found, write all + call write_cache ; no empty slots found, write all cmp [hd_error],0 jne found_slot_access_denied - - jmp search_again ; and start again - - found_slot: - -; mov [cache_search_start],edi + jmp search_again ; and start again +found_slot: call calculate_cache_5 - found_slot_access_denied: +found_slot_access_denied: ret - +;-------------------------------------------------------------------- align 4 clear_hd_cache: -; push eax ecx edi -; mov edi, HD_CACHE -; mov ecx,16384 -; xor eax,eax -; cld -; rep stosd ; clear hd cache with 0 -; mov [cache_search_start],eax mov [fat_in_cache],-1 mov [fat_change],0 -; pop edi ecx eax ret - ;-------------------------------------------------------------------- align 4 calculate_cache: @@ -207,7 +163,7 @@ calculate_cache: cmp [hdd_appl_data],0 jne .ide2_appl_data mov ecx,[cache_ide2_system_sad_size] - mov esi,[cache_ide2_pointer] + mov esi,[cache_ide2_pointer] ret .ide2_appl_data: mov ecx,[cache_ide2_appl_sad_size] @@ -217,7 +173,7 @@ calculate_cache: cmp [hdd_appl_data],0 jne .ide3_appl_data mov ecx,[cache_ide3_system_sad_size] - mov esi,[cache_ide3_pointer] + mov esi,[cache_ide3_pointer] ret .ide3_appl_data: mov ecx,[cache_ide3_appl_sad_size] @@ -261,7 +217,7 @@ calculate_cache_1: .ide3: cmp [hdd_appl_data],0 jne .ide3_appl_data - mov esi,[cache_ide3_pointer] + mov esi,[cache_ide3_pointer] ret .ide3_appl_data: mov esi,[cache_ide3_data_pointer] @@ -276,7 +232,7 @@ calculate_cache_2: jne .ide1 cmp [hdd_appl_data],0 jne .ide0_appl_data - mov eax,[cache_ide0_system_data] + mov eax,[cache_ide0_system_data] ret .ide0_appl_data: mov eax,[cache_ide0_appl_data] @@ -304,7 +260,7 @@ calculate_cache_2: .ide3: cmp [hdd_appl_data],0 jne .ide3_appl_data - mov eax,[cache_ide3_system_data] + mov eax,[cache_ide3_system_data] ret .ide3_appl_data: mov eax,[cache_ide3_appl_data] @@ -346,7 +302,7 @@ calculate_cache_3: cmp [hdd_appl_data],0 jne .ide2_appl_data mov ecx,[cache_ide2_system_sad_size] - mov edi,[cache_ide2_search_start] + mov edi,[cache_ide2_search_start] ret .ide2_appl_data: mov ecx,[cache_ide2_appl_sad_size] @@ -356,7 +312,7 @@ calculate_cache_3: cmp [hdd_appl_data],0 jne .ide3_appl_data mov ecx,[cache_ide3_system_sad_size] - mov edi,[cache_ide3_search_start] + mov edi,[cache_ide3_search_start] ret .ide3_appl_data: mov ecx,[cache_ide3_appl_sad_size] @@ -415,7 +371,7 @@ calculate_cache_5: jne .ide1 cmp [hdd_appl_data],0 jne .ide0_appl_data - mov [cache_ide0_search_start],edi + mov [cache_ide0_search_start],edi ret .ide0_appl_data: mov [cache_ide0_appl_search_start],edi @@ -443,15 +399,357 @@ calculate_cache_5: .ide3: cmp [hdd_appl_data],0 jne .ide3_appl_data - mov [cache_ide3_search_start],edi + mov [cache_ide3_search_start],edi + ret +.ide3_appl_data: + mov [cache_ide3_appl_search_start],edi + ret + +;-------------------------------------------------------------------- +align 4 +find_empty_slot_CD_cache: +;----------------------------------------------------------- +; find empty or read slot, flush cache if next 10% is used by write +; output : edi = cache slot +;----------------------------------------------------------- +.search_again: + call cd_calculate_cache_3 +.search_for_empty: + inc edi + call cd_calculate_cache_4 + jbe .inside_cache + mov edi,1 +.inside_cache: + call cd_calculate_cache_5 + ret +;-------------------------------------------------------------------- +clear_CD_cache: + pusha +.ide0: + xor eax,eax + cmp [cdpos],1 + jne .ide1 + mov [cache_ide0_search_start],eax + mov ecx,[cache_ide0_system_sad_size] + mov edi,[cache_ide0_pointer] + call .clear + mov [cache_ide0_appl_search_start],eax + mov ecx,[cache_ide0_appl_sad_size] + mov edi,[cache_ide0_data_pointer] + jmp .continue +.ide1: + cmp [cdpos],2 + jne .ide2 + mov [cache_ide1_search_start],eax + mov ecx,[cache_ide1_system_sad_size] + mov edi,[cache_ide1_pointer] + call .clear + mov [cache_ide1_appl_search_start],eax + mov ecx,[cache_ide1_appl_sad_size] + mov edi,[cache_ide1_data_pointer] + jmp .continue +.ide2: + cmp [cdpos],3 + jne .ide3 + mov [cache_ide2_search_start],eax + mov ecx,[cache_ide2_system_sad_size] + mov edi,[cache_ide2_pointer] + call .clear + mov [cache_ide2_appl_search_start],eax + mov ecx,[cache_ide2_appl_sad_size] + mov edi,[cache_ide2_data_pointer] + jmp .continue +.ide3: + mov [cache_ide3_search_start],eax + mov ecx,[cache_ide3_system_sad_size] + mov edi,[cache_ide3_pointer] + call .clear + mov [cache_ide3_appl_search_start],eax + mov ecx,[cache_ide3_appl_sad_size] + mov edi,[cache_ide3_data_pointer] +.continue: + call .clear + popa + ret +.clear: + shl ecx,1 + cld + rep stosd + ret +;-------------------------------------------------------------------- +align 4 +cd_calculate_cache: +; mov ecx,cache_max ; entries in cache +; mov esi,HD_CACHE+8 + +; 1 - IDE0 ... 4 - IDE3 +.ide0: + cmp [cdpos],1 + jne .ide1 + cmp [cd_appl_data],0 + jne .ide0_appl_data + mov ecx,[cache_ide0_system_sad_size] + mov esi,[cache_ide0_pointer] + ret +.ide0_appl_data: + mov ecx,[cache_ide0_appl_sad_size] + mov esi,[cache_ide0_data_pointer] + ret +.ide1: + cmp [cdpos],2 + jne .ide2 + cmp [cd_appl_data],0 + jne .ide1_appl_data + mov ecx,[cache_ide1_system_sad_size] + mov esi,[cache_ide1_pointer] + ret +.ide1_appl_data: + mov ecx,[cache_ide1_appl_sad_size] + mov esi,[cache_ide1_data_pointer] + ret +.ide2: + cmp [cdpos],3 + jne .ide3 + cmp [cd_appl_data],0 + jne .ide2_appl_data + mov ecx,[cache_ide2_system_sad_size] + mov esi,[cache_ide2_pointer] + ret +.ide2_appl_data: + mov ecx,[cache_ide2_appl_sad_size] + mov esi,[cache_ide2_data_pointer] + ret +.ide3: + cmp [cd_appl_data],0 + jne .ide3_appl_data + mov ecx,[cache_ide3_system_sad_size] + mov esi,[cache_ide3_pointer] + ret +.ide3_appl_data: + mov ecx,[cache_ide3_appl_sad_size] + mov esi,[cache_ide3_data_pointer] + ret +;-------------------------------------------------------------------- +align 4 +cd_calculate_cache_1: +; lea esi,[edi*8+HD_CACHE] +; 1 - IDE0 ... 4 - IDE3 +.ide0: + cmp [cdpos],1 + jne .ide1 + cmp [cd_appl_data],0 + jne .ide0_appl_data + mov esi,[cache_ide0_pointer] + ret +.ide0_appl_data: + mov esi,[cache_ide0_data_pointer] + ret +.ide1: + cmp [cdpos],2 + jne .ide2 + cmp [cd_appl_data],0 + jne .ide1_appl_data + mov esi,[cache_ide1_pointer] + ret +.ide1_appl_data: + mov esi,[cache_ide1_data_pointer] + ret +.ide2: + cmp [cdpos],3 + jne .ide3 + cmp [cd_appl_data],0 + jne .ide2_appl_data + mov esi,[cache_ide2_pointer] + ret +.ide2_appl_data: + mov esi,[cache_ide2_data_pointer] + ret +.ide3: + cmp [cd_appl_data],0 + jne .ide3_appl_data + mov esi,[cache_ide3_pointer] + ret +.ide3_appl_data: + mov esi,[cache_ide3_data_pointer] + ret +;-------------------------------------------------------------------- +align 4 +cd_calculate_cache_2: +; add esi,HD_CACHE+65536 +; 1 - IDE0 ... 4 - IDE3 +.ide0: + cmp [cdpos],1 + jne .ide1 + cmp [cd_appl_data],0 + jne .ide0_appl_data + mov eax,[cache_ide0_system_data] + ret +.ide0_appl_data: + mov eax,[cache_ide0_appl_data] + ret +.ide1: + cmp [cdpos],2 + jne .ide2 + cmp [cd_appl_data],0 + jne .ide1_appl_data + mov eax,[cache_ide1_system_data] + ret +.ide1_appl_data: + mov eax,[cache_ide1_appl_data] + ret +.ide2: + cmp [cdpos],3 + jne .ide3 + cmp [cd_appl_data],0 + jne .ide2_appl_data + mov eax,[cache_ide2_system_data] + ret +.ide2_appl_data: + mov eax,[cache_ide2_appl_data] + ret +.ide3: + cmp [cd_appl_data],0 + jne .ide3_appl_data + mov eax,[cache_ide3_system_data] + ret +.ide3_appl_data: + mov eax,[cache_ide3_appl_data] + ret +;-------------------------------------------------------------------- +align 4 +cd_calculate_cache_3: +; mov ecx,cache_max*10/100 +; mov edi,[cache_search_start] + +; 1 - IDE0 ... 4 - IDE3 +.ide0: + cmp [cdpos],1 + jne .ide1 + cmp [cd_appl_data],0 + jne .ide0_appl_data + mov edi,[cache_ide0_search_start] + ret +.ide0_appl_data: + mov edi,[cache_ide0_appl_search_start] + ret +.ide1: + cmp [cdpos],2 + jne .ide2 + cmp [cd_appl_data],0 + jne .ide1_appl_data + mov edi,[cache_ide1_search_start] + ret +.ide1_appl_data: + mov edi,[cache_ide1_appl_search_start] + ret +.ide2: + cmp [cdpos],3 + jne .ide3 + cmp [cd_appl_data],0 + jne .ide2_appl_data + mov edi,[cache_ide2_search_start] + ret +.ide2_appl_data: + mov edi,[cache_ide2_appl_search_start] + ret +.ide3: + cmp [cd_appl_data],0 + jne .ide3_appl_data + mov edi,[cache_ide3_search_start] + ret +.ide3_appl_data: + mov edi,[cache_ide3_appl_search_start] + ret +;-------------------------------------------------------------------- +align 4 +cd_calculate_cache_4: +; cmp edi,cache_max +; 1 - IDE0 ... 4 - IDE3 +.ide0: + cmp [cdpos],1 + jne .ide1 + cmp [cd_appl_data],0 + jne .ide0_appl_data + cmp edi,[cache_ide0_system_sad_size] + ret +.ide0_appl_data: + cmp edi,[cache_ide0_appl_sad_size] + ret +.ide1: + cmp [cdpos],2 + jne .ide2 + cmp [cd_appl_data],0 + jne .ide1_appl_data + cmp edi,[cache_ide1_system_sad_size] + ret +.ide1_appl_data: + cmp edi,[cache_ide1_appl_sad_size] + ret +.ide2: + cmp [cdpos],3 + jne .ide3 + cmp [cd_appl_data],0 + jne .ide2_appl_data + cmp edi,[cache_ide2_system_sad_size] + ret +.ide2_appl_data: + cmp edi,[cache_ide2_appl_sad_size] + ret +.ide3: + cmp [cd_appl_data],0 + jne .ide3_appl_data + cmp edi,[cache_ide3_system_sad_size] + ret +.ide3_appl_data: + cmp edi,[cache_ide3_appl_sad_size] + ret +;-------------------------------------------------------------------- +align 4 +cd_calculate_cache_5: +; mov [cache_search_start],edi +; 1 - IDE0 ... 4 - IDE3 +.ide0: + cmp [cdpos],1 + jne .ide1 + cmp [cd_appl_data],0 + jne .ide0_appl_data + mov [cache_ide0_search_start],edi + ret +.ide0_appl_data: + mov [cache_ide0_appl_search_start],edi + ret +.ide1: + cmp [cdpos],2 + jne .ide2 + cmp [cd_appl_data],0 + jne .ide1_appl_data + mov [cache_ide1_search_start],edi + ret +.ide1_appl_data: + mov [cache_ide1_appl_search_start],edi + ret +.ide2: + cmp [cdpos],3 + jne .ide3 + cmp [cd_appl_data],0 + jne .ide2_appl_data + mov [cache_ide2_search_start],edi + ret +.ide2_appl_data: + mov [cache_ide2_appl_search_start],edi + ret +.ide3: + cmp [cd_appl_data],0 + jne .ide3_appl_data + mov [cache_ide3_search_start],edi ret .ide3_appl_data: mov [cache_ide3_appl_search_start],edi ret ;-------------------------------------------------------------------- -align 4 -calculate_linear_to_real: - shr eax, 12 - mov eax, [page_tabs+eax*4] - and eax, 0xFFFFF000 - ret +;align 4 +;calculate_linear_to_real: +; shr eax, 12 +; mov eax, [page_tabs+eax*4] +; and eax, 0xFFFFF000 +; ret diff --git a/kernel/trunk/data32.inc b/kernel/trunk/data32.inc index 389e8584d8..9319d8260b 100644 --- a/kernel/trunk/data32.inc +++ b/kernel/trunk/data32.inc @@ -306,6 +306,7 @@ hdbase rd 1 ; for boot 0x1f0 hdid rd 1 hdpos rd 1 ; for boot 0x1 fat32part rd 1 ; for boot 0x1 +cdpos rd 1 sb16 rd 1 @@ -387,6 +388,7 @@ cache_ide3_appl_search_start rd 1 debug_step_pointer rd 1 hdd_appl_data rb 1 ; 0 = system cache, 1 - application cache +cd_appl_data rb 1 ; 0 = system cache, 1 - application cache lba_read_enabled rd 1 ; 0 = disabled , 1 = enabled pci_access_enabled rd 1 ; 0 = disabled , 1 = enabled diff --git a/kernel/trunk/detect/getcache.inc b/kernel/trunk/detect/getcache.inc index bd5da5f8c9..ba9e19a540 100644 --- a/kernel/trunk/detect/getcache.inc +++ b/kernel/trunk/detect/getcache.inc @@ -18,13 +18,13 @@ shl eax,3 ; translate pages in butes *4096 shl eax,12 -; check a upper size of the cache, no more than 1 Mb on the physical device +; check a upper size of the cache, no more than 1 Mb on the physical device cmp eax,1024*1024 jbe @f mov eax,1024*1024 jmp .continue @@: -; check a lower size of the cache, not less than 128 Kb on the physical device +; check a lower size of the cache, not less than 128 Kb on the physical device cmp eax,128*1024 jae @f mov eax,128*1024 @@ -44,30 +44,31 @@ mov [cache_ide3_search_start],eax mov [cache_ide3_appl_search_start],eax mov [hdd_appl_data],1 ;al + mov [cd_appl_data],1 mov cl,[DRIVE_DATA+1] mov ch,cl and cl,11b cmp cl,0 - je .ide2 + je .ide2 call get_cache_ide3 .ide2: mov cl,ch and cl,1100b cmp cl,0 - je .ide1 + je .ide1 call get_cache_ide2 .ide1: mov cl,ch and cl,110000b cmp cl,0 - je .ide0 + je .ide0 call get_cache_ide1 .ide0: mov cl,ch and cl,11000000b cmp cl,0 - je end_get_cache + je end_get_cache call get_cache_ide0 jmp end_get_cache @@ -85,21 +86,21 @@ get_cache_ide0: mov [cache_ide0_appl_data_size],eax add ebx,edx mov [cache_ide0_data_pointer],ebx - + cmp cl,10000000b - je .cd + je .cd push ecx mov eax,[cache_ide0_system_data_size] call calculate_for_hd add eax,[cache_ide0_pointer] mov [cache_ide0_system_data],eax mov [cache_ide0_system_sad_size],ecx - + push edi mov edi,[cache_ide0_pointer] call clear_ide_cache pop edi - + mov eax,[cache_ide0_appl_data_size] call calculate_for_hd add eax,[cache_ide0_data_pointer] @@ -110,7 +111,7 @@ get_cache_ide0: mov edi,[cache_ide0_data_pointer] call clear_ide_cache pop edi - + pop ecx ret .cd: @@ -125,21 +126,21 @@ get_cache_ide0: mov edi,[cache_ide0_pointer] call clear_ide_cache pop edi - + mov eax,[cache_ide0_appl_data_size] call calculate_for_cd add eax,[cache_ide0_data_pointer] mov [cache_ide0_appl_data],eax mov [cache_ide0_appl_sad_size],ecx - + push edi mov edi,[cache_ide0_data_pointer] call clear_ide_cache pop edi - + pop ecx ret - + get_cache_ide1: push ecx stdcall kernel_alloc,[cache_ide1_size] @@ -154,9 +155,9 @@ get_cache_ide1: mov [cache_ide1_appl_data_size],eax add ebx,edx mov [cache_ide1_data_pointer],ebx - + cmp cl,100000b - je .cd + je .cd push ecx mov eax,[cache_ide1_system_data_size] call calculate_for_hd @@ -174,12 +175,12 @@ get_cache_ide1: add eax,[cache_ide1_data_pointer] mov [cache_ide1_appl_data],eax mov [cache_ide1_appl_sad_size],ecx - + push edi mov edi,[cache_ide1_data_pointer] call clear_ide_cache pop edi - + pop ecx ret .cd: @@ -200,12 +201,12 @@ get_cache_ide1: add eax,[cache_ide1_data_pointer] mov [cache_ide1_appl_data],eax mov [cache_ide1_appl_sad_size],ecx - + push edi mov edi,[cache_ide1_data_pointer] call clear_ide_cache pop edi - + pop ecx ret @@ -223,9 +224,9 @@ get_cache_ide2: mov [cache_ide2_appl_data_size],eax add ebx,edx mov [cache_ide2_data_pointer],ebx - + cmp cl,1000b - je .cd + je .cd push ecx mov eax,[cache_ide2_system_data_size] call calculate_for_hd @@ -243,12 +244,12 @@ get_cache_ide2: add eax,[cache_ide2_data_pointer] mov [cache_ide2_appl_data],eax mov [cache_ide2_appl_sad_size],ecx - + push edi mov edi,[cache_ide2_data_pointer] call clear_ide_cache pop edi - + pop ecx ret .cd: @@ -269,12 +270,12 @@ get_cache_ide2: add eax,[cache_ide2_data_pointer] mov [cache_ide2_appl_data],eax mov [cache_ide2_appl_sad_size],ecx - + push edi mov edi,[cache_ide2_data_pointer] call clear_ide_cache pop edi - + pop ecx ret @@ -292,9 +293,9 @@ get_cache_ide3: mov [cache_ide3_appl_data_size],eax add ebx,edx mov [cache_ide3_data_pointer],ebx - + cmp cl,10b - je .cd + je .cd push ecx mov eax,[cache_ide3_system_data_size] call calculate_for_hd @@ -312,12 +313,12 @@ get_cache_ide3: add eax,[cache_ide3_data_pointer] mov [cache_ide3_appl_data],eax mov [cache_ide3_appl_sad_size],ecx - + push edi mov edi,[cache_ide3_data_pointer] call clear_ide_cache pop edi - + pop ecx ret .cd: @@ -338,12 +339,12 @@ get_cache_ide3: add eax,[cache_ide3_data_pointer] mov [cache_ide3_appl_data],eax mov [cache_ide3_appl_sad_size],ecx - + push edi mov edi,[cache_ide3_data_pointer] call clear_ide_cache pop edi - + pop ecx ret @@ -374,7 +375,7 @@ calculate_for_cd: sub eax,ebx dec ecx ret - + clear_ide_cache: push eax shl ecx,1 @@ -383,7 +384,7 @@ clear_ide_cache: rep stosd pop eax ret - + end_get_cache: ; mov [cache_ide0_pointer],HD_CACHE ; mov [cache_ide0_system_data],HD_CACHE+65536 diff --git a/kernel/trunk/docs/sysfuncr.txt b/kernel/trunk/docs/sysfuncr.txt index 33d8041e6f..9a94e9cf68 100644 --- a/kernel/trunk/docs/sysfuncr.txt +++ b/kernel/trunk/docs/sysfuncr.txt @@ -4114,6 +4114,10 @@ Architecture Software Developer's Manual, Volume 3, Appendix B); „«п CD-ЇаЁў®¤®ў ў бўп§Ё б  ЇЇ а в­л¬Ё ®Ја ­ЁзҐ­Ёп¬Ё ¤®бвгЇ­л в®«мЄ® Ї®¤дг­ЄжЁЁ 0,1,5 Ё 7, ўл§®ў ¤агЈЁе Ї®¤дг­ЄжЁ© § ўҐаиЁвбп ®иЁЎЄ®© б Є®¤®¬ 2. +ЏаЁ ЇҐаў®¬ ®Ўа йҐ­ЁЁ Ї®¤дг­ЄжЁ© 0,1,5,7 Є гбва®©бвў ¬ ATAPI (CD Ё DVD) +Їа®Ё§ў®¤Ёвбп Ў«®ЄЁа®ўЄ  агз­®Ј® гЇа ў«Ґ­Ёп ¬Ґе ­Ё§¬®¬ «®вЄ . ќв® бўп§ ­® +б  «Ј®аЁв¬®¬ ЄниЁа®ў ­Ёп ¤ ­­ле Ї®«г祭­ле ®в ЇаЁў®¤ . ђ §Ў«®ЄЁа®ўЄ  +Їа®Ё§ў®¤Ёвбп ®Ўа йҐ­ЁҐ¬ Ї®¤дг­ЄжЁҐ© 10 Є ᮮ⢥вбвўго饬г гбва®©бвўг. ====================================================================== = ”г­ЄжЁп 70, Ї®¤дг­ЄжЁп 0 - з⥭ЁҐ д ©«  б Ї®¤¤Ґа¦Є®© ¤«Ё­­ле Ё¬с­. = @@ -4473,6 +4477,66 @@ Architecture Software Developer's Manual, Volume 3, Appendix B); * ђ®¤ЁвҐ«мбЄ п Ї ЇЄ  ¤®«¦­  㦥 бгйҐбвў®ў вм. * …б«Ё Ї ЇЄ  㦥 бгйҐбвўгҐв, дг­ЄжЁп § ўҐаиЁвбп гбЇҐи­® (eax=0). +====================================================================== +========== ”г­ЄжЁп 70, Ї®¤дг­ЄжЁп 10 - Ё§ў«Ґзм «®в®Є ЇаЁў®¤  ¤ЁбЄ . ============ +====================================================================== +Џ а ¬Ґвал: + * eax = 70 - ­®¬Ґа дг­ЄжЁЁ + * ebx = гЄ § вҐ«м ­  Ё­д®а¬ жЁ®­­го бвагЄвгаг +”®а¬ в Ё­д®а¬ жЁ®­­®© бвагЄвгал: + * +0: dword: 10 = ­®¬Ґа Ї®¤дг­ЄжЁЁ + * +4: dword: 0 (§ аҐ§ҐаўЁа®ў ­®) + * +8: dword: 0 (§ аҐ§ҐаўЁа®ў ­®) + * +12 = +0xC: dword: 0 (§ аҐ§ҐаўЁа®ў ­®) + * +16 = +0x10: dword: 0 (§ аҐ§ҐаўЁа®ў ­®) + * +20 = +0x14: ASCIIZ-Ё¬п Ї ЇЄЁ, Їа ўЁ«  д®а¬Ёа®ў ­Ёп Ё¬с­ гЄ § ­л ў + ®ЎйҐ¬ ®ЇЁб ­ЁЁ + Ё«Ё + * +20 = +0x14: db 0 + * +21 = +0x15: dd гЄ § вҐ«м ­  ASCIIZ-бва®Єг б Ё¬Ґ­Ґ¬ Ї ЇЄЁ +‚®§ўа й Ґ¬®Ґ §­ зҐ­ЁҐ: + * ЌЁзҐЈ® ­Ґ ў®§ўа й Ґвбп. +‡ ¬Ґз ­Ёп: + * ”г­ЄжЁп Ї®¤¤Ґа¦Ёў Ґвбп в®«мЄ® ¤«п ATAPI гбва®©бвў (CD Ё DVD). + * ЏаЁ Ё§ў«ҐзҐ­ЁЁ «®вЄ  Їа®Ё§ў®¤Ёвбп а §Ў«®ЄЁа®ўЄ  агз­®Ј® гЇа ў«Ґ­Ёп ¬Ґе ­Ё§¬®¬ «®вЄ . + * ЏаЁ Ё§ў«ҐзҐ­ЁЁ «®вЄ  Є®¤ Їа®Ё§ў®¤Ёв ®зЁбвЄг Єни  б®®вўҐвбвўго饣® гбва®©бвў . + * Џгвм ўў®¤Ёвбп ў бв ­¤ ав­®¬ ¤«п 70 дг­ЄжЁЁ ўЁ¤Ґ. „«п а Ў®в®бЇ®б®Ў­®бвЁ ¬®¦­® + ®Ја ­ЁзЁвмбп Їгвп¬Ё ўЁ¤ : + db '/cd0/1/',0 + db '/cd1/1/',0 + db '/cd2/1/',0 + db '/cd3/1/',0 + * ЏаЁ¬Ґа®¬ ЁбЇ®«м§®ў ­Ёп дг­ЄжЁЁ пў«пҐвбп ЇаЁ«®¦Ґ­ЁҐ CD_tray. + +====================================================================== +========== ”г­ЄжЁп 70, Ї®¤дг­ЄжЁп 11 - § Јаг§Ёвм «®в®Є ЇаЁў®¤  ¤ЁбЄ . =========== +====================================================================== +Џ а ¬Ґвал: + * eax = 70 - ­®¬Ґа дг­ЄжЁЁ + * ebx = гЄ § вҐ«м ­  Ё­д®а¬ жЁ®­­го бвагЄвгаг +”®а¬ в Ё­д®а¬ жЁ®­­®© бвагЄвгал: + * +0: dword: 11 = ­®¬Ґа Ї®¤дг­ЄжЁЁ + * +4: dword: 0 (§ аҐ§ҐаўЁа®ў ­®) + * +8: dword: 0 (§ аҐ§ҐаўЁа®ў ­®) + * +12 = +0xC: dword: 0 (§ аҐ§ҐаўЁа®ў ­®) + * +16 = +0x10: dword: 0 (§ аҐ§ҐаўЁа®ў ­®) + * +20 = +0x14: ASCIIZ-Ё¬п Ї ЇЄЁ, Їа ўЁ«  д®а¬Ёа®ў ­Ёп Ё¬с­ гЄ § ­л ў + ®ЎйҐ¬ ®ЇЁб ­ЁЁ + Ё«Ё + * +20 = +0x14: db 0 + * +21 = +0x15: dd гЄ § вҐ«м ­  ASCIIZ-бва®Єг б Ё¬Ґ­Ґ¬ Ї ЇЄЁ +‚®§ўа й Ґ¬®Ґ §­ зҐ­ЁҐ: + * ЌЁзҐЈ® ­Ґ ў®§ўа й Ґвбп. +‡ ¬Ґз ­Ёп: + * ”г­ЄжЁп Ї®¤¤Ґа¦Ёў Ґвбп в®«мЄ® ¤«п ATAPI гбва®©бвў (CD Ё DVD) + * Џгвм ўў®¤Ёвбп ў бв ­¤ ав­®¬ ¤«п 70 дг­ЄжЁЁ ўЁ¤Ґ. „«п а Ў®в®бЇ®б®Ў­®бвЁ ¬®¦­® + ®Ја ­ЁзЁвмбп Їгвп¬Ё ўЁ¤ : + db '/cd0/1/',0 + db '/cd1/1/',0 + db '/cd2/1/',0 + db '/cd3/1/',0 + * ЏаЁ¬Ґа®¬ ЁбЇ®«м§®ў ­Ёп дг­ЄжЁЁ пў«пҐвбп ЇаЁ«®¦Ґ­ЁҐ CD_tray. + ====================================================================== === ”г­ЄжЁп 71, Ї®¤дг­ЄжЁп 1 - гбв ­®ўЁвм § Ј®«®ў®Є ®Є­  Їа®Ја ¬¬л. == ====================================================================== diff --git a/kernel/trunk/docs/sysfuncs.txt b/kernel/trunk/docs/sysfuncs.txt index 9fa1906f56..9f33e0e7c0 100644 --- a/kernel/trunk/docs/sysfuncs.txt +++ b/kernel/trunk/docs/sysfuncs.txt @@ -4075,6 +4075,10 @@ Available subfunctions: For CD-drives due to hardware limitations only subfunctions 0,1,5 and 7 are available, other subfunctions return error with code 2. +At the first call subfunctions 0,1,5,7 to devices ATAPI (CD and DVD) the locking +of handle mechanism of a tray is made. It is connected to algorithm of caching +given obtained from a drive. Deblocking is made by call subfunction 10 +to the appropriate device. ====================================================================== === Function 70, subfunction 0 - read file with long names support. == @@ -4429,6 +4433,64 @@ Remarks: * The parent folder must already exist. * If target folder already exists, function returns success (eax=0). +====================================================================== +================ Function 70, subfunction 10 - eject tray of disk drive. ============== +====================================================================== +Parameters: + * eax = 70 - function number + * ebx = pointer to the information structure +Format of the information structure: + * +0: dword: 10 = subfunction number + * +4: dword: 0 (reserved) + * +8: dword: 0 (reserved) + * +12 = +0xC: dword: 0 (reserved) + * +16 = +0x10: dword: 0 (reserved) + * +20 = +0x14: ASCIIZ-name of folder, the rules of names forming are + given in the general description + or + * +20 = +0x14: db 0 + * +21 = +0x15: dd pointer to ASCIIZ-string with folder name +Returned value: + * Nothing comes back. +Remarks: + * The function is supported only for ATAPI devices (CD and DVD). + * At extract of a tray is made deblocking of handle mechanism of a tray. + * At extract of a tray the code makes clearing the cache of the appropriate device. + * The path is standard for 70 functions. For serviceability it is possible to be limited to paths: + db '/cd0/1/',0 + db '/cd1/1/',0 + db '/cd2/1/',0 + db '/cd3/1/',0 + * An example of usage of the function is the application CD_tray. + +====================================================================== +============== Function 70, subfunction 11 - load tray of disk drive. ================= +====================================================================== +Parameters: + * eax = 70 - function number + * ebx = pointer to the information structure +Format of the information structure: + * +0: dword: 11 = subfunction number + * +4: dword: 0 (reserved) + * +8: dword: 0 (reserved) + * +12 = +0xC: dword: 0 (reserved) + * +16 = +0x10: dword: 0 (reserved) + * +20 = +0x14: ASCIIZ-name of folder, the rules of names forming are + given in the general description + or + * +20 = +0x14: db 0 + * +21 = +0x15: dd pointer to ASCIIZ-string with folder name +Returned value: + * Nothing comes back. +Remarks: + * The function is supported only for ATAPI devices (CD and DVD). + * The path is standard for 70 functions. For serviceability it is possible to be limited to paths: + db '/cd0/1/',0 + db '/cd1/1/',0 + db '/cd2/1/',0 + db '/cd3/1/',0 + * An example of usage of the function is the application CD_tray. + ====================================================================== ========== Function 71, subfunction 1 - set window caption. ========== ====================================================================== diff --git a/kernel/trunk/fs/fs_lfn.inc b/kernel/trunk/fs/fs_lfn.inc index c069d432a8..56e3a328cd 100644 --- a/kernel/trunk/fs/fs_lfn.inc +++ b/kernel/trunk/fs/fs_lfn.inc @@ -15,71 +15,71 @@ image_of_ebx EQU esp+24 iglobal ; in this table names must be in lowercase rootdirs: - db 2,'rd' - dd fs_OnRamdisk - dd fs_NextRamdisk - db 7,'ramdisk' - dd fs_OnRamdisk - dd fs_NextRamdisk - db 2,'fd' - dd fs_OnFloppy - dd fs_NextFloppy - db 10,'floppydisk' - dd fs_OnFloppy - dd fs_NextFloppy - db 3,'hd0' - dd fs_OnHd0 - dd fs_NextHd0 - db 3,'hd1' - dd fs_OnHd1 - dd fs_NextHd1 - db 3,'hd2' - dd fs_OnHd2 - dd fs_NextHd2 - db 3,'hd3' - dd fs_OnHd3 - dd fs_NextHd3 + db 2,'rd' + dd fs_OnRamdisk + dd fs_NextRamdisk + db 7,'ramdisk' + dd fs_OnRamdisk + dd fs_NextRamdisk + db 2,'fd' + dd fs_OnFloppy + dd fs_NextFloppy + db 10,'floppydisk' + dd fs_OnFloppy + dd fs_NextFloppy + db 3,'hd0' + dd fs_OnHd0 + dd fs_NextHd0 + db 3,'hd1' + dd fs_OnHd1 + dd fs_NextHd1 + db 3,'hd2' + dd fs_OnHd2 + dd fs_NextHd2 + db 3,'hd3' + dd fs_OnHd3 + dd fs_NextHd3 ;********************************************** - db 3,'cd0' - dd fs_OnCd0 - dd fs_NextCd - db 3,'cd1' - dd fs_OnCd1 - dd fs_NextCd - db 3,'cd2' - dd fs_OnCd2 - dd fs_NextCd - db 3,'cd3' - dd fs_OnCd3 - dd fs_NextCd + db 3,'cd0' + dd fs_OnCd0 + dd fs_NextCd + db 3,'cd1' + dd fs_OnCd1 + dd fs_NextCd + db 3,'cd2' + dd fs_OnCd2 + dd fs_NextCd + db 3,'cd3' + dd fs_OnCd3 + dd fs_NextCd ;*********************************************** - db 0 + db 0 virtual_root_query: - dd fs_HasRamdisk - db 'rd',0 - dd fs_HasFloppy - db 'fd',0 - dd fs_HasHd0 - db 'hd0',0 - dd fs_HasHd1 - db 'hd1',0 - dd fs_HasHd2 - db 'hd2',0 - dd fs_HasHd3 - db 'hd3',0 + dd fs_HasRamdisk + db 'rd',0 + dd fs_HasFloppy + db 'fd',0 + dd fs_HasHd0 + db 'hd0',0 + dd fs_HasHd1 + db 'hd1',0 + dd fs_HasHd2 + db 'hd2',0 + dd fs_HasHd3 + db 'hd3',0 ;********************************************** - dd fs_HasCd0 - db 'cd0',0 - dd fs_HasCd1 - db 'cd1',0 - dd fs_HasCd2 - db 'cd2',0 - dd fs_HasCd3 - db 'cd3',0 + dd fs_HasCd0 + db 'cd0',0 + dd fs_HasCd1 + db 'cd1',0 + dd fs_HasCd2 + db 'cd2',0 + dd fs_HasCd3 + db 'cd3',0 ;********************************************** - dd 0 + dd 0 endg file_system_lfn: @@ -97,255 +97,255 @@ file_system_lfn: ; 9 : create directory ; parse file name - xchg ebx, eax - lea esi, [ebx+20] - lodsb - test al, al - jnz @f - mov esi, [esi] - lodsb + xchg ebx, eax + lea esi, [ebx+20] + lodsb + test al, al + jnz @f + mov esi, [esi] + lodsb @@: - cmp al, '/' - jz .notcurdir - dec esi - mov ebp, esi - test al, al - jnz @f - xor ebp, ebp + cmp al, '/' + jz .notcurdir + dec esi + mov ebp, esi + test al, al + jnz @f + xor ebp, ebp @@: - mov esi, [current_slot] - mov esi, [esi+APPDATA.cur_dir] - jmp .parse_normal + mov esi, [current_slot] + mov esi, [esi+APPDATA.cur_dir] + jmp .parse_normal .notcurdir: - cmp byte [esi], 0 - jz .rootdir - call process_replace_file_name + cmp byte [esi], 0 + jz .rootdir + call process_replace_file_name .parse_normal: - cmp dword [ebx], 7 - jne @F - mov edx, [ebx+4] - mov ebx, [ebx+8] - call fs_execute ; esi+ebp, ebx, edx - mov [image_of_eax], eax - ret + cmp dword [ebx], 7 + jne @F + mov edx, [ebx+4] + mov ebx, [ebx+8] + call fs_execute ; esi+ebp, ebx, edx + mov [image_of_eax], eax + ret @@: - mov edi, rootdirs-8 - xor ecx, ecx - push esi + mov edi, rootdirs-8 + xor ecx, ecx + push esi .scan1: - pop esi - add edi, ecx - scasd - scasd - mov cl, byte [edi] - test cl, cl - jz .notfound - inc edi - push esi + pop esi + add edi, ecx + scasd + scasd + mov cl, byte [edi] + test cl, cl + jz .notfound + inc edi + push esi @@: - lodsb - or al, 20h - scasb - loopz @b - jnz .scan1 - lodsb - cmp al, '/' - jz .found1 - test al, al - jnz .scan1 - pop eax + lodsb + or al, 20h + scasb + loopz @b + jnz .scan1 + lodsb + cmp al, '/' + jz .found1 + test al, al + jnz .scan1 + pop eax ; directory /xxx .maindir: - cmp dword [ebx], 1 - jnz .access_denied - xor eax, eax - mov ebp, [ebx+12] - mov edx, [ebx+16] + cmp dword [ebx], 1 + jnz .access_denied + xor eax, eax + mov ebp, [ebx+12] + mov edx, [ebx+16] ; add edx, std_application_base_address - push dword [ebx+4] ; first block - mov ebx, [ebx+8] ; flags - mov esi, [edi+4] + push dword [ebx+4] ; first block + mov ebx, [ebx+8] ; flags + mov esi, [edi+4] ; ebx=flags, [esp]=first block, ebp=number of blocks, edx=return area, esi='Next' handler - mov edi, edx - mov ecx, 32/4 - rep stosd - mov byte [edx], 1 ; version + mov edi, edx + mov ecx, 32/4 + rep stosd + mov byte [edx], 1 ; version .maindir_loop: - call esi - jc .maindir_done - inc dword [edx+8] - dec dword [esp] - jns .maindir_loop - dec ebp - js .maindir_loop - inc dword [edx+4] - mov dword [edi], 0x10 ; attributes: folder - mov dword [edi+4], 1 ; name type: UNICODE - push eax - xor eax, eax - add edi, 8 - mov ecx, 40/4-2 - rep stosd - pop eax - push eax edx + call esi + jc .maindir_done + inc dword [edx+8] + dec dword [esp] + jns .maindir_loop + dec ebp + js .maindir_loop + inc dword [edx+4] + mov dword [edi], 0x10 ; attributes: folder + mov dword [edi+4], 1 ; name type: UNICODE + push eax + xor eax, eax + add edi, 8 + mov ecx, 40/4-2 + rep stosd + pop eax + push eax edx ; convert number in eax to decimal UNICODE string - push edi - push -'0' - mov cl, 10 + push edi + push -'0' + mov cl, 10 @@: - xor edx, edx - div ecx - push edx - test eax, eax - jnz @b + xor edx, edx + div ecx + push edx + test eax, eax + jnz @b @@: - pop eax - add al, '0' - stosb - test bl, 1 ; UNICODE name? - jz .ansi2 - mov byte [edi], 0 - inc edi + pop eax + add al, '0' + stosb + test bl, 1 ; UNICODE name? + jz .ansi2 + mov byte [edi], 0 + inc edi .ansi2: - test al, al - jnz @b - mov byte [edi-1], 0 - pop edi + test al, al + jnz @b + mov byte [edi-1], 0 + pop edi ; UNICODE name length is 520 bytes, ANSI - 264 - add edi, 520 - test bl, 1 - jnz @f - sub edi, 520-264 + add edi, 520 + test bl, 1 + jnz @f + sub edi, 520-264 @@: - pop edx eax - jmp .maindir_loop + pop edx eax + jmp .maindir_loop .maindir_done: - pop eax - mov ebx, [edx+4] - xor eax, eax - dec ebp - js @f - mov al, ERROR_END_OF_FILE + pop eax + mov ebx, [edx+4] + xor eax, eax + dec ebp + js @f + mov al, ERROR_END_OF_FILE @@: - mov [image_of_eax], eax - mov [image_of_ebx], ebx - ret + mov [image_of_eax], eax + mov [image_of_ebx], ebx + ret ; directory / .rootdir: - cmp dword [ebx], 1 ; read folder? - jz .readroot + cmp dword [ebx], 1 ; read folder? + jz .readroot .access_denied: - mov dword [image_of_eax], 10 ; access denied - ret + mov dword [image_of_eax], 10 ; access denied + ret .readroot: ; virtual root folder - special handler - mov esi, virtual_root_query - mov ebp, [ebx+12] - mov edx, [ebx+16] + mov esi, virtual_root_query + mov ebp, [ebx+12] + mov edx, [ebx+16] ; add edx, std_application_base_address - push dword [ebx+4] ; first block - mov ebx, [ebx+8] ; flags - xor eax, eax + push dword [ebx+4] ; first block + mov ebx, [ebx+8] ; flags + xor eax, eax ; eax=0, [esp]=first block, ebx=flags, ebp=number of blocks, edx=return area - mov edi, edx - mov ecx, 32/4 - rep stosd - mov byte [edx], 1 ; version + mov edi, edx + mov ecx, 32/4 + rep stosd + mov byte [edx], 1 ; version .readroot_loop: - cmp dword [esi], eax - jz .readroot_done - call dword [esi] - add esi, 4 - test eax, eax - jnz @f + cmp dword [esi], eax + jz .readroot_done + call dword [esi] + add esi, 4 + test eax, eax + jnz @f .readroot_next: - or ecx, -1 - xchg esi, edi - repnz scasb - xchg esi, edi - jmp .readroot_loop + or ecx, -1 + xchg esi, edi + repnz scasb + xchg esi, edi + jmp .readroot_loop @@: - xor eax, eax - inc dword [edx+8] - dec dword [esp] - jns .readroot_next - dec ebp - js .readroot_next - inc dword [edx+4] - mov dword [edi], 0x10 ; attributes: folder - mov dword [edi+4], 1 ; name type: UNICODE - add edi, 8 - mov ecx, 40/4-2 - rep stosd - push edi + xor eax, eax + inc dword [edx+8] + dec dword [esp] + jns .readroot_next + dec ebp + js .readroot_next + inc dword [edx+4] + mov dword [edi], 0x10 ; attributes: folder + mov dword [edi+4], 1 ; name type: UNICODE + add edi, 8 + mov ecx, 40/4-2 + rep stosd + push edi @@: - lodsb - stosb - test bl, 1 - jz .ansi - mov byte [edi], 0 - inc edi + lodsb + stosb + test bl, 1 + jz .ansi + mov byte [edi], 0 + inc edi .ansi: - test eax, eax - jnz @b - pop edi - add edi, 520 - test bl, 1 - jnz .readroot_loop - sub edi, 520-264 - jmp .readroot_loop + test eax, eax + jnz @b + pop edi + add edi, 520 + test bl, 1 + jnz .readroot_loop + sub edi, 520-264 + jmp .readroot_loop .readroot_done: - pop eax - mov ebx, [edx+4] - xor eax, eax - dec ebp - js @f - mov al, ERROR_END_OF_FILE + pop eax + mov ebx, [edx+4] + xor eax, eax + dec ebp + js @f + mov al, ERROR_END_OF_FILE @@: - mov [image_of_eax], eax - mov [image_of_ebx], ebx - ret + mov [image_of_eax], eax + mov [image_of_ebx], ebx + ret .notfound: - mov dword [image_of_eax], ERROR_FILE_NOT_FOUND - and dword [image_of_ebx], 0 - ret + mov dword [image_of_eax], ERROR_FILE_NOT_FOUND + and dword [image_of_ebx], 0 + ret .found1: - pop eax - cmp byte [esi], 0 - jz .maindir + pop eax + cmp byte [esi], 0 + jz .maindir ; read partition number - xor ecx, ecx - xor eax, eax + xor ecx, ecx + xor eax, eax @@: - lodsb - cmp al, '/' - jz .done1 - test al, al - jz .done1 - sub al, '0' - cmp al, 9 - ja .notfound - lea ecx, [ecx*5] - lea ecx, [ecx*2+eax] - jmp @b + lodsb + cmp al, '/' + jz .done1 + test al, al + jz .done1 + sub al, '0' + cmp al, 9 + ja .notfound + lea ecx, [ecx*5] + lea ecx, [ecx*2+eax] + jmp @b .done1: - jecxz .notfound - test al, al - jnz @f - dec esi + jecxz .notfound + test al, al + jnz @f + dec esi @@: - cmp byte [esi], 0 - jnz @f - test ebp, ebp - jz @f - mov esi, ebp - xor ebp, ebp + cmp byte [esi], 0 + jnz @f + test ebp, ebp + jz @f + mov esi, ebp + xor ebp, ebp @@: ; now [edi] contains handler address, ecx - partition number, ; esi points to ASCIIZ string - rest of name - jmp dword [edi] + jmp dword [edi] ; handlers for devices ; in: ecx = 0 => query virtual directory /xxx @@ -356,279 +356,294 @@ file_system_lfn: ; out: [image_of_eax]=image of eax, [image_of_ebx]=image of ebx fs_OnRamdisk: - cmp ecx, 1 - jnz file_system_lfn.notfound - mov eax, [ebx] - cmp eax, fs_NumRamdiskServices - jae .not_impl - mov ecx, [ebx+12] - mov edx, [ebx+16] + cmp ecx, 1 + jnz file_system_lfn.notfound + mov eax, [ebx] + cmp eax, fs_NumRamdiskServices + jae .not_impl + mov ecx, [ebx+12] + mov edx, [ebx+16] ; add edx, std_application_base_address - add ebx, 4 - call dword [fs_RamdiskServices + eax*4] - mov [image_of_eax], eax - mov [image_of_ebx], ebx - ret + add ebx, 4 + call dword [fs_RamdiskServices + eax*4] + mov [image_of_eax], eax + mov [image_of_ebx], ebx + ret .not_impl: - mov dword [image_of_eax], 2 ; not implemented - ret + mov dword [image_of_eax], 2 ; not implemented + ret fs_NotImplemented: - mov eax, 2 - ret + mov eax, 2 + ret fs_RamdiskServices: - dd fs_RamdiskRead - dd fs_RamdiskReadFolder - dd fs_RamdiskRewrite - dd fs_RamdiskWrite - dd fs_RamdiskSetFileEnd - dd fs_RamdiskGetFileInfo - dd fs_RamdiskSetFileInfo - dd 0 - dd fs_RamdiskDelete - dd fs_RamdiskCreateFolder + dd fs_RamdiskRead + dd fs_RamdiskReadFolder + dd fs_RamdiskRewrite + dd fs_RamdiskWrite + dd fs_RamdiskSetFileEnd + dd fs_RamdiskGetFileInfo + dd fs_RamdiskSetFileInfo + dd 0 + dd fs_RamdiskDelete + dd fs_RamdiskCreateFolder + dd fs_NotImplemented + dd fs_NotImplemented fs_NumRamdiskServices = ($ - fs_RamdiskServices)/4 fs_OnFloppy: - cmp ecx, 2 - ja file_system_lfn.notfound - mov eax, [ebx] - cmp eax, fs_NumFloppyServices - jae fs_OnRamdisk.not_impl - call reserve_flp - mov [flp_number], cl - mov ecx, [ebx+12] - mov edx, [ebx+16] + cmp ecx, 2 + ja file_system_lfn.notfound + mov eax, [ebx] + cmp eax, fs_NumFloppyServices + jae fs_OnRamdisk.not_impl + call reserve_flp + mov [flp_number], cl + mov ecx, [ebx+12] + mov edx, [ebx+16] ; add edx, std_application_base_address - add ebx, 4 - call dword [fs_FloppyServices + eax*4] - and [flp_status], 0 - mov [image_of_eax], eax - mov [image_of_ebx], ebx - ret + add ebx, 4 + call dword [fs_FloppyServices + eax*4] + and [flp_status], 0 + mov [image_of_eax], eax + mov [image_of_ebx], ebx + ret fs_FloppyServices: - dd fs_FloppyRead - dd fs_FloppyReadFolder - dd fs_FloppyRewrite - dd fs_FloppyWrite - dd fs_FloppySetFileEnd - dd fs_FloppyGetFileInfo - dd fs_FloppySetFileInfo - dd 0 - dd fs_FloppyDelete - dd fs_FloppyCreateFolder + dd fs_FloppyRead + dd fs_FloppyReadFolder + dd fs_FloppyRewrite + dd fs_FloppyWrite + dd fs_FloppySetFileEnd + dd fs_FloppyGetFileInfo + dd fs_FloppySetFileInfo + dd 0 + dd fs_FloppyDelete + dd fs_FloppyCreateFolder + dd fs_NotImplemented + dd fs_NotImplemented fs_NumFloppyServices = ($ - fs_FloppyServices)/4 fs_OnHd0: - call reserve_hd1 - mov [hdbase], 0x1F0 - mov [hdid], 0 - push 1 - jmp fs_OnHd + call reserve_hd1 + mov [hdbase], 0x1F0 + mov [hdid], 0 + push 1 + jmp fs_OnHd fs_OnHd1: - call reserve_hd1 - mov [hdbase], 0x1F0 - mov [hdid], 0x10 - push 2 - jmp fs_OnHd + call reserve_hd1 + mov [hdbase], 0x1F0 + mov [hdid], 0x10 + push 2 + jmp fs_OnHd fs_OnHd2: - call reserve_hd1 - mov [hdbase], 0x170 - mov [hdid], 0 - push 3 - jmp fs_OnHd + call reserve_hd1 + mov [hdbase], 0x170 + mov [hdid], 0 + push 3 + jmp fs_OnHd fs_OnHd3: - call reserve_hd1 - mov [hdbase], 0x170 - mov [hdid], 0x10 - push 4 + call reserve_hd1 + mov [hdbase], 0x170 + mov [hdid], 0x10 + push 4 fs_OnHd: - call reserve_hd_channel - pop eax - mov [hdpos], eax - cmp ecx, 0x100 - jae .nf - cmp cl, [DRIVE_DATA+1+eax] - jbe @f + call reserve_hd_channel + pop eax + mov [hdpos], eax + cmp ecx, 0x100 + jae .nf + cmp cl, [DRIVE_DATA+1+eax] + jbe @f .nf: - call free_hd_channel - and [hd1_status], 0 - mov dword [image_of_eax], 5 ; not found - ret + call free_hd_channel + and [hd1_status], 0 + mov dword [image_of_eax], 5 ; not found + ret @@: - mov [fat32part], ecx - push ebx esi - call choice_necessity_partition_1 - pop esi ebx - mov ecx, [ebx+12] - mov edx, [ebx+16] + mov [fat32part], ecx + push ebx esi + call choice_necessity_partition_1 + pop esi ebx + mov ecx, [ebx+12] + mov edx, [ebx+16] ; add edx, std_application_base_address - mov eax, [ebx] - cmp eax, fs_NumHdServices - jae .not_impl - add ebx, 4 - call dword [fs_HdServices + eax*4] - call free_hd_channel - and [hd1_status], 0 - mov [image_of_eax], eax - mov [image_of_ebx], ebx - ret + mov eax, [ebx] + cmp eax, fs_NumHdServices + jae .not_impl + add ebx, 4 + call dword [fs_HdServices + eax*4] + call free_hd_channel + and [hd1_status], 0 + mov [image_of_eax], eax + mov [image_of_ebx], ebx + ret .not_impl: - call free_hd_channel - and [hd1_status], 0 - mov dword [image_of_eax], 2 ; not implemented - ret + call free_hd_channel + and [hd1_status], 0 + mov dword [image_of_eax], 2 ; not implemented + ret fs_HdServices: - dd fs_HdRead - dd fs_HdReadFolder - dd fs_HdRewrite - dd fs_HdWrite - dd fs_HdSetFileEnd - dd fs_HdGetFileInfo - dd fs_HdSetFileInfo - dd 0 - dd fs_HdDelete - dd fs_HdCreateFolder + dd fs_HdRead + dd fs_HdReadFolder + dd fs_HdRewrite + dd fs_HdWrite + dd fs_HdSetFileEnd + dd fs_HdGetFileInfo + dd fs_HdSetFileInfo + dd 0 + dd fs_HdDelete + dd fs_HdCreateFolder + dd fs_NotImplemented + dd fs_NotImplemented fs_NumHdServices = ($ - fs_HdServices)/4 ;******************************************************* fs_OnCd0: - call reserve_cd - mov [ChannelNumber],1 - mov [DiskNumber],0 - push 6 - jmp fs_OnCd + call reserve_cd + mov [ChannelNumber],1 + mov [DiskNumber],0 + push 6 + push 1 + jmp fs_OnCd fs_OnCd1: - call reserve_cd - mov [ChannelNumber],1 - mov [DiskNumber],1 - push 4 - jmp fs_OnCd + call reserve_cd + mov [ChannelNumber],1 + mov [DiskNumber],1 + push 4 + push 2 + jmp fs_OnCd fs_OnCd2: - call reserve_cd - mov [ChannelNumber],2 - mov [DiskNumber],0 - push 2 - jmp fs_OnCd + call reserve_cd + mov [ChannelNumber],2 + mov [DiskNumber],0 + push 2 + push 3 + jmp fs_OnCd fs_OnCd3: - call reserve_cd - mov [ChannelNumber],2 - mov [DiskNumber],1 - push 0 + call reserve_cd + mov [ChannelNumber],2 + mov [DiskNumber],1 + push 0 + push 4 fs_OnCd: - call reserve_cd_channel - pop eax - mov [hdpos], eax - cmp ecx, 0x100 - jae .nf - push ecx ebx - mov cl,al - mov bl,[DRIVE_DATA+1] - shr bl,cl - test bl,2 - pop ebx ecx + call reserve_cd_channel + pop eax + mov [cdpos], eax + pop eax + cmp ecx, 0x100 + jae .nf + push ecx ebx + mov cl,al + mov bl,[DRIVE_DATA+1] + shr bl,cl + test bl,2 + pop ebx ecx - jnz @f + jnz @f .nf: - call free_cd_channel - and [cd_status], 0 - mov dword [image_of_eax], 5 ; not found - ret + call free_cd_channel + and [cd_status], 0 + mov dword [image_of_eax], 5 ; not found + ret @@: - mov ecx, [ebx+12] - mov edx, [ebx+16] + mov ecx, [ebx+12] + mov edx, [ebx+16] ; add edx, std_application_base_address - mov eax, [ebx] - cmp eax,fs_NumCdServices - jae .not_impl - add ebx, 4 - call dword [fs_CdServices + eax*4] - call free_cd_channel - and [cd_status], 0 - mov [image_of_eax], eax - mov [image_of_ebx], ebx - ret + mov eax, [ebx] + cmp eax,fs_NumCdServices + jae .not_impl + add ebx, 4 + call dword [fs_CdServices + eax*4] + call free_cd_channel + and [cd_status], 0 + mov [image_of_eax], eax + mov [image_of_ebx], ebx + ret .not_impl: - call free_cd_channel - and [cd_status], 0 - mov dword [image_of_eax], 2 ; not implemented - ret + call free_cd_channel + and [cd_status], 0 + mov dword [image_of_eax], 2 ; not implemented + ret fs_CdServices: - dd fs_CdRead - dd fs_CdReadFolder - dd fs_NotImplemented - dd fs_NotImplemented - dd fs_NotImplemented - dd fs_CdGetFileInfo - dd fs_NotImplemented - dd 0 + dd fs_CdRead + dd fs_CdReadFolder + dd fs_NotImplemented + dd fs_NotImplemented + dd fs_NotImplemented + dd fs_CdGetFileInfo + dd fs_NotImplemented + dd 0 + dd fs_NotImplemented + dd fs_NotImplemented + dd fs_EjectDeviceTray + dd fs_LoadDeviceTray fs_NumCdServices = ($ - fs_CdServices)/4 ;******************************************************* fs_HasRamdisk: - mov al, 1 ; we always have ramdisk - ret + mov al, 1 ; we always have ramdisk + ret fs_HasFloppy: - cmp byte [DRIVE_DATA], 0 - setnz al - ret + cmp byte [DRIVE_DATA], 0 + setnz al + ret fs_HasHd0: - mov al, [DRIVE_DATA+1] - and al, 11000000b - cmp al, 01000000b - setz al - ret + mov al, [DRIVE_DATA+1] + and al, 11000000b + cmp al, 01000000b + setz al + ret fs_HasHd1: - mov al, [DRIVE_DATA+1] - and al, 00110000b - cmp al, 00010000b - setz al - ret + mov al, [DRIVE_DATA+1] + and al, 00110000b + cmp al, 00010000b + setz al + ret fs_HasHd2: - mov al, [DRIVE_DATA+1] - and al, 00001100b - cmp al, 00000100b - setz al - ret + mov al, [DRIVE_DATA+1] + and al, 00001100b + cmp al, 00000100b + setz al + ret fs_HasHd3: - mov al, [DRIVE_DATA+1] - and al, 00000011b - cmp al, 00000001b - setz al - ret + mov al, [DRIVE_DATA+1] + and al, 00000011b + cmp al, 00000001b + setz al + ret ;******************************************************* fs_HasCd0: - mov al, [DRIVE_DATA+1] - and al, 11000000b - cmp al, 10000000b - setz al - ret + mov al, [DRIVE_DATA+1] + and al, 11000000b + cmp al, 10000000b + setz al + ret fs_HasCd1: - mov al, [DRIVE_DATA+1] - and al, 00110000b - cmp al, 00100000b - setz al - ret + mov al, [DRIVE_DATA+1] + and al, 00110000b + cmp al, 00100000b + setz al + ret fs_HasCd2: - mov al, [DRIVE_DATA+1] - and al, 00001100b - cmp al, 00001000b - setz al - ret + mov al, [DRIVE_DATA+1] + and al, 00001100b + cmp al, 00001000b + setz al + ret fs_HasCd3: - mov al, [DRIVE_DATA+1] - and al, 00000011b - cmp al, 00000010b - setz al - ret + mov al, [DRIVE_DATA+1] + and al, 00000011b + cmp al, 00000010b + setz al + ret ;******************************************************* ; fs_NextXXX functions: @@ -638,217 +653,217 @@ fs_HasCd3: fs_NextRamdisk: ; we always have /rd/1 - test eax, eax - stc - jnz @f - mov al, 1 - clc + test eax, eax + stc + jnz @f + mov al, 1 + clc @@: - ret + ret fs_NextFloppy: ; we have /fd/1 iff (([DRIVE_DATA] and 0xF0) != 0) and /fd/2 iff (([DRIVE_DATA] and 0x0F) != 0) - test byte [DRIVE_DATA], 0xF0 - jz .no1 - test eax, eax - jnz .no1 - inc eax - ret ; CF cleared + test byte [DRIVE_DATA], 0xF0 + jz .no1 + test eax, eax + jnz .no1 + inc eax + ret ; CF cleared .no1: - test byte [DRIVE_DATA], 0x0F - jz .no2 - cmp al, 2 - jae .no2 - mov al, 2 - clc - ret + test byte [DRIVE_DATA], 0x0F + jz .no2 + cmp al, 2 + jae .no2 + mov al, 2 + clc + ret .no2: - stc - ret + stc + ret ; on hdx, we have partitions from 1 to [0x40002+x] fs_NextHd0: - push 0 - jmp fs_NextHd + push 0 + jmp fs_NextHd fs_NextHd1: - push 1 - jmp fs_NextHd + push 1 + jmp fs_NextHd fs_NextHd2: - push 2 - jmp fs_NextHd + push 2 + jmp fs_NextHd fs_NextHd3: - push 3 + push 3 fs_NextHd: - pop ecx - movzx ecx, byte [DRIVE_DATA+2+ecx] - cmp eax, ecx - jae fs_NextFloppy.no2 - inc eax - clc - ret + pop ecx + movzx ecx, byte [DRIVE_DATA+2+ecx] + cmp eax, ecx + jae fs_NextFloppy.no2 + inc eax + clc + ret ;******************************************************* fs_NextCd: ; we always have /cdX/1 - test eax, eax - stc - jnz @f - mov al, 1 - clc + test eax, eax + stc + jnz @f + mov al, 1 + clc @@: - ret + ret ;******************************************************* process_replace_file_name: - mov ebp, [full_file_name_table] - mov edi, [full_file_name_table.size] - dec edi - shl edi, 7 - add edi, ebp + mov ebp, [full_file_name_table] + mov edi, [full_file_name_table.size] + dec edi + shl edi, 7 + add edi, ebp .loop: - cmp edi, ebp - jb .notfound - push esi edi + cmp edi, ebp + jb .notfound + push esi edi @@: - cmp byte [edi], 0 - jz .dest_done - lodsb - test al, al - jz .cont - or al, 20h - scasb - jz @b - jmp .cont + cmp byte [edi], 0 + jz .dest_done + lodsb + test al, al + jz .cont + or al, 20h + scasb + jz @b + jmp .cont .dest_done: - cmp byte [esi], 0 - jz .found - cmp byte [esi], '/' - jnz .cont - inc esi - jmp .found + cmp byte [esi], 0 + jz .found + cmp byte [esi], '/' + jnz .cont + inc esi + jmp .found .cont: - pop edi esi - sub edi, 128 - jmp .loop + pop edi esi + sub edi, 128 + jmp .loop .found: - pop edi eax - mov ebp, esi - cmp byte [esi], 0 - lea esi, [edi+64] - jnz .ret + pop edi eax + mov ebp, esi + cmp byte [esi], 0 + lea esi, [edi+64] + jnz .ret .notfound: - xor ebp, ebp + xor ebp, ebp .ret: - ret + ret sys_current_directory: - mov esi, [current_slot] - mov esi, [esi+APPDATA.cur_dir] - mov edx, esi - dec eax - jz .set - dec eax - jz .get - ret + mov esi, [current_slot] + mov esi, [esi+APPDATA.cur_dir] + mov edx, esi + dec eax + jz .set + dec eax + jz .get + ret .get: ; sysfunction 30.2: [for app] eax=30,ebx=2,ecx->buffer,edx=len ; for our code: ebx->buffer,ecx=len @@: - lodsb - test al, al - jnz @b - sub esi, edx - inc esi - mov [esp+36], esi - cmp ecx, esi - jbe @f - mov ecx, esi + lodsb + test al, al + jnz @b + sub esi, edx + inc esi + mov [esp+36], esi + cmp ecx, esi + jbe @f + mov ecx, esi @@: - cmp ecx, 1 - jbe .ret - mov esi, edx - mov edi, ebx - mov al, '/' - stosb - dec ecx - dec ecx - rep movsb - mov byte [edi], 0 + cmp ecx, 1 + jbe .ret + mov esi, edx + mov edi, ebx + mov al, '/' + stosb + dec ecx + dec ecx + rep movsb + mov byte [edi], 0 .ret: - ret + ret .set: ; sysfunction 30.1: [for app] eax=30,ebx=1,ecx->string ; for our code: ebx->string to set @@: - inc esi - cmp byte [esi-1], 0 - jnz @b - dec esi - cmp byte [ebx], '/' - jz .set_absolute + inc esi + cmp byte [esi-1], 0 + jnz @b + dec esi + cmp byte [ebx], '/' + jz .set_absolute ; string gives relative path .relative: - cmp byte [ebx], 0 - jz .set_ok - cmp word [ebx], '.' - jz .set_ok - cmp word [ebx], './' - jnz @f - add ebx, 2 - jmp .relative + cmp byte [ebx], 0 + jz .set_ok + cmp word [ebx], '.' + jz .set_ok + cmp word [ebx], './' + jnz @f + add ebx, 2 + jmp .relative @@: - cmp word [ebx], '..' - jnz .doset_relative - cmp byte [ebx+2], 0 - jz @f - cmp byte [ebx+2], '/' - jnz .doset_relative + cmp word [ebx], '..' + jnz .doset_relative + cmp byte [ebx+2], 0 + jz @f + cmp byte [ebx+2], '/' + jnz .doset_relative @@: - dec esi - cmp byte [esi], '/' - jnz @b - mov byte [esi], 0 - add ebx, 3 - jmp .relative + dec esi + cmp byte [esi], '/' + jnz @b + mov byte [esi], 0 + add ebx, 3 + jmp .relative .doset_relative: - add edx, 0x1000 - mov byte [esi], '/' - inc esi - cmp esi, edx - jae .overflow_esi + add edx, 0x1000 + mov byte [esi], '/' + inc esi + cmp esi, edx + jae .overflow_esi @@: - mov al, [ebx] - inc ebx - mov [esi], al - inc esi - test al, al - jz .set_ok - cmp esi, edx - jb @b + mov al, [ebx] + inc ebx + mov [esi], al + inc esi + test al, al + jz .set_ok + cmp esi, edx + jb @b .overflow_esi: - mov byte [esi-1], 0 ; force null-terminated string + mov byte [esi-1], 0 ; force null-terminated string .set_ok: - ret + ret .set_absolute: - lea esi, [ebx+1] - call process_replace_file_name - mov edi, edx - add edx, 0x1000 + lea esi, [ebx+1] + call process_replace_file_name + mov edi, edx + add edx, 0x1000 .set_copy: - lodsb - stosb - test al, al - jz .set_part2 + lodsb + stosb + test al, al + jz .set_part2 .set_copy_cont: - cmp edi, edx - jb .set_copy + cmp edi, edx + jb .set_copy .overflow_edi: - mov byte [edi-1], 0 - ret + mov byte [edi-1], 0 + ret .set_part2: - mov esi, ebp - xor ebp, ebp - test esi, esi - jz .set_ok - mov byte [edi-1], '/' - jmp .set_copy_cont + mov esi, ebp + xor ebp, ebp + test esi, esi + jz .set_ok + mov byte [edi-1], '/' + jmp .set_copy_cont diff --git a/kernel/trunk/fs/iso9660.inc b/kernel/trunk/fs/iso9660.inc index 0167855d87..4ec4dc2099 100644 --- a/kernel/trunk/fs/iso9660.inc +++ b/kernel/trunk/fs/iso9660.inc @@ -9,17 +9,17 @@ $Revision$ uglobal cd_current_pointer_of_input dd 0 cd_current_pointer_of_input_2 dd 0 -cd_mem_location dd 0 -cd_counter_block dd 0 -IDE_Channel_1 db 0 -IDE_Channel_2 db 0 +cd_mem_location dd 0 +cd_counter_block dd 0 +IDE_Channel_1 db 0 +IDE_Channel_2 db 0 endg reserve_cd: cli cmp [cd_status],0 - je reserve_ok2 + je reserve_ok2 sti call change_task @@ -42,14 +42,14 @@ reserve_cd_channel: .IDE_Channel_1: cli cmp [IDE_Channel_1],0 - je .reserve_ok_1 + je .reserve_ok_1 sti call change_task jmp .IDE_Channel_1 .IDE_Channel_2: cli cmp [IDE_Channel_2],0 - je .reserve_ok_2 + je .reserve_ok_2 sti call change_task jmp .IDE_Channel_1 @@ -95,7 +95,7 @@ fs_CdRead: .noaccess: pop edi .noaccess_2: - or ebx, -1 + or ebx, -1 mov eax, ERROR_ACCESS_DENIED ret @@ -109,19 +109,19 @@ fs_CdRead: pop edi cmp [DevErrorCode],0 jne .noaccess_2 - or ebx, -1 + or ebx, -1 mov eax, ERROR_FILE_NOT_FOUND ret .found: mov edi,[cd_current_pointer_of_input] - test byte [edi+25],10b ; do not allow read directories + test byte [edi+25],10b ; do not allow read directories jnz .noaccess test ebx, ebx - jz .l1 + jz .l1 cmp dword [ebx+4], 0 - jz @f - xor ebx, ebx + jz @f + xor ebx, ebx .reteof: mov eax, 6 ; end of file pop edi @@ -129,31 +129,31 @@ fs_CdRead: @@: mov ebx, [ebx] .l1: - push ecx edx - push 0 - mov eax, [edi+10] ; реальный размер файловой секции - sub eax, ebx - jb .eof - cmp eax, ecx - jae @f - mov ecx, eax - mov byte [esp], 6 + push ecx edx + push 0 + mov eax, [edi+10] ; реальный размер файловой секции + sub eax, ebx + jb .eof + cmp eax, ecx + jae @f + mov ecx, eax + mov byte [esp], 6 @@: mov eax,[edi+2] mov [CDSectorAddress],eax ; now eax=cluster, ebx=position, ecx=count, edx=buffer for data .new_sector: test ecx, ecx - jz .done + jz .done sub ebx, 2048 jae .next add ebx, 2048 jnz .incomplete_sector cmp ecx, 2048 - jb .incomplete_sector + jb .incomplete_sector ; we may read and memmove complete sector mov [CDDataBuf_pointer],edx - call ReadCDWRetr ; читаем сектор файла + call ReadCDWRetr ; читаем сектор файла cmp [DevErrorCode],0 jne .noaccess_3 add edx, 2048 @@ -164,7 +164,7 @@ fs_CdRead: .incomplete_sector: ; we must read and memmove incomplete sector mov [CDDataBuf_pointer],CDDataBuf - call ReadCDWRetr ; читаем сектор файла + call ReadCDWRetr ; читаем сектор файла cmp [DevErrorCode],0 jne .noaccess_3 push ecx @@ -176,7 +176,7 @@ fs_CdRead: sub ecx, ebx push edi esi ecx mov edi,edx - lea esi, [CDDataBuf + ebx] + lea esi, [CDDataBuf + ebx] cld rep movsb pop ecx esi edi @@ -187,15 +187,15 @@ fs_CdRead: jmp .next .done: - mov ebx, edx - pop eax edx ecx edi - sub ebx, edx - ret + mov ebx, edx + pop eax edx ecx edi + sub ebx, edx + ret .eof: - mov ebx, edx - pop eax edx ecx - sub ebx, edx - jmp .reteof + mov ebx, edx + pop eax edx ecx + sub ebx, edx + jmp .reteof ;---------------------------------------------------------------- ; @@ -213,79 +213,79 @@ fs_CdRead: ; ;-------------------------------------------------------------- fs_CdReadFolder: - push edi - call cd_find_lfn - jnc .found - pop edi - cmp [DevErrorCode], 0 - jne .noaccess_1 - or ebx, -1 - mov eax, ERROR_FILE_NOT_FOUND - ret + push edi + call cd_find_lfn + jnc .found + pop edi + cmp [DevErrorCode], 0 + jne .noaccess_1 + or ebx, -1 + mov eax, ERROR_FILE_NOT_FOUND + ret .found: - mov edi, [cd_current_pointer_of_input] - test byte [edi+25], 10b ; do not allow read directories - jnz .found_dir - pop edi + mov edi, [cd_current_pointer_of_input] + test byte [edi+25], 10b ; do not allow read directories + jnz .found_dir + pop edi .noaccess_1: - or ebx, -1 - mov eax, ERROR_ACCESS_DENIED - ret + or ebx, -1 + mov eax, ERROR_ACCESS_DENIED + ret .found_dir: - mov eax, [edi+2] ; eax=cluster - mov [CDSectorAddress], eax - mov eax, [edi+10] ; размер директрории + mov eax, [edi+2] ; eax=cluster + mov [CDSectorAddress], eax + mov eax, [edi+10] ; размер директрории .doit: ; init header - push eax ecx - mov edi, edx - mov ecx, 32/4 - xor eax, eax - rep stosd - pop ecx eax - mov byte [edx], 1 ; version - mov [cd_mem_location], edx - add [cd_mem_location], 32 + push eax ecx + mov edi, edx + mov ecx, 32/4 + xor eax, eax + rep stosd + pop ecx eax + mov byte [edx], 1 ; version + mov [cd_mem_location], edx + add [cd_mem_location], 32 ; начинаем переброску БДВК в УСВК ;.mainloop: - mov [cd_counter_block], dword 0 - dec dword [CDSectorAddress] - push ecx + mov [cd_counter_block], dword 0 + dec dword [CDSectorAddress] + push ecx .read_to_buffer: - inc dword [CDSectorAddress] - mov [CDDataBuf_pointer], CDDataBuf - call ReadCDWRetr ; читаем сектор директории - cmp [DevErrorCode], 0 - jne .noaccess_1 - call .get_names_from_buffer - sub eax,2048 + inc dword [CDSectorAddress] + mov [CDDataBuf_pointer], CDDataBuf + call ReadCDWRetr ; читаем сектор директории + cmp [DevErrorCode], 0 + jne .noaccess_1 + call .get_names_from_buffer + sub eax,2048 ; директория закончилась? - ja .read_to_buffer - mov edi, [cd_counter_block] - mov [edx+8], edi - mov edi, [ebx] - sub [edx+4], edi - xor eax, eax - dec ecx - js @f - mov al, ERROR_END_OF_FILE + ja .read_to_buffer + mov edi, [cd_counter_block] + mov [edx+8], edi + mov edi, [ebx] + sub [edx+4], edi + xor eax, eax + dec ecx + js @f + mov al, ERROR_END_OF_FILE @@: - pop ecx edi - mov ebx, [edx+4] - ret + pop ecx edi + mov ebx, [edx+4] + ret .get_names_from_buffer: mov [cd_current_pointer_of_input_2],CDDataBuf push eax esi edi edx .get_names_from_buffer_1: call cd_get_name - jc .end_buffer + jc .end_buffer inc dword [cd_counter_block] mov eax,[cd_counter_block] cmp [ebx],eax jae .get_names_from_buffer_1 test ecx, ecx - jz .get_names_from_buffer_1 + jz .get_names_from_buffer_1 mov edi,[cd_counter_block] mov [edx+4],edi dec ecx @@ -307,18 +307,18 @@ fs_CdReadFolder: ; проверка конца файла mov ax,[esi] cmp ax,word 3B00h ; сепаратор конца файла ';' - je .cd_get_parameters_of_file_1 + je .cd_get_parameters_of_file_1 ; проверка для файлов не заканчивающихся сепаратором movzx eax,byte [ebp-33] add eax,ebp sub eax,34 cmp esi,eax - je .cd_get_parameters_of_file_1 + je .cd_get_parameters_of_file_1 ; проверка конца папки movzx eax,byte [ebp-1] add eax,ebp cmp esi,eax - jb .ansi + jb .ansi .cd_get_parameters_of_file_1: mov [edi],byte 0 call cd_get_parameters_of_file @@ -327,7 +327,7 @@ fs_CdReadFolder: .ansi_parent_directory: cmp [cd_counter_block],2 - je @f + je @f mov [edi],byte '.' inc edi jmp .cd_get_parameters_of_file_1 @@ -344,18 +344,18 @@ fs_CdReadFolder: ; проверка конца файла mov ax,[esi] cmp ax,word 3B00h ; сепаратор конца файла ';' - je .cd_get_parameters_of_file_2 + je .cd_get_parameters_of_file_2 ; проверка для файлов не заканчивающихся сепаратором movzx eax,byte [ebp-33] add eax,ebp sub eax,34 cmp esi,eax - je .cd_get_parameters_of_file_2 + je .cd_get_parameters_of_file_2 ; проверка конца папки movzx eax,byte [ebp-1] add eax,ebp cmp esi,eax - jb .unicode + jb .unicode .cd_get_parameters_of_file_2: mov [edi],word 0 call cd_get_parameters_of_file @@ -364,7 +364,7 @@ fs_CdReadFolder: .unicode_parent_directory: cmp [cd_counter_block],2 - je @f + je @f mov [edi],word 2E00h ; '.' add edi,2 jmp .cd_get_parameters_of_file_2 @@ -387,7 +387,7 @@ cd_get_parameters_of_file_1: shl eax,1 ; это каталог? test [ebp-8],byte 2 - jz .file + jz .file inc eax .file: ; метка тома не как в FAT, в этом виде отсутсвует @@ -395,7 +395,7 @@ cd_get_parameters_of_file_1: shl eax,3 ; файл является скрытым? (атрибут существование) test [ebp-8],byte 1 - jz .hidden + jz .hidden inc eax .hidden: shl eax,1 @@ -457,153 +457,168 @@ cd_get_parameters_of_file_1: ; ;---------------------------------------------------------------- fs_CdGetFileInfo: - cmp byte [esi], 0 - jnz @f - mov eax, 2 - ret + cmp byte [esi], 0 + jnz @f + mov eax, 2 + ret @@: - push edi - call cd_find_lfn - pushfd - cmp [DevErrorCode], 0 - jz @f - popfd - pop edi - mov eax, 11 - ret + push edi + call cd_find_lfn + pushfd + cmp [DevErrorCode], 0 + jz @f + popfd + pop edi + mov eax, 11 + ret @@: - popfd - jnc @f - pop edi - mov eax, ERROR_FILE_NOT_FOUND - ret + popfd + jnc @f + pop edi + mov eax, ERROR_FILE_NOT_FOUND + ret @@: - mov edi, edx - push ebp - mov ebp, [cd_current_pointer_of_input] - add ebp, 33 - call cd_get_parameters_of_file_1 - pop ebp - and dword [edi+4], 0 - pop edi - xor eax, eax - ret + mov edi, edx + push ebp + mov ebp, [cd_current_pointer_of_input] + add ebp, 33 + call cd_get_parameters_of_file_1 + pop ebp + and dword [edi+4], 0 + pop edi + xor eax, eax + ret +;---------------------------------------------------------------- +fs_EjectDeviceTray: + call clear_CD_cache + call allow_medium_removal + call EjectMedium + ret +;---------------------------------------------------------------- +fs_LoadDeviceTray: + call LoadMedium + ret +;---------------------------------------------------------------- cd_find_lfn: + mov [cd_appl_data],0 ; in: esi+ebp -> name ; out: CF=1 - file not found ; else CF=0 and [cd_current_pointer_of_input] direntry - push eax esi + push eax esi ; 16 сектор начало набора дескрипторов томов - mov [CDSectorAddress],dword 15 -.start: - inc dword [CDSectorAddress] + mov [CDSectorAddress],dword 15 mov [CDDataBuf_pointer],CDDataBuf - call ReadCDWRetr + call prevent_medium_removal +.start: + inc dword [CDSectorAddress] + call ReadCDWRetr ;_1 cmp [DevErrorCode],0 jne .access_denied ; проверка на вшивость - cmp [CDDataBuf+1],dword 'CD00' - jne .access_denied - cmp [CDDataBuf+5],byte '1' - jne .access_denied + cmp [CDDataBuf+1],dword 'CD00' + jne .access_denied + cmp [CDDataBuf+5],byte '1' + jne .access_denied ; сектор является терминатором набор дескрипторов томов? - cmp [CDDataBuf],byte 0xff - je .access_denied + cmp [CDDataBuf],byte 0xff + je .access_denied ; сектор является дополнительным и улучшенным дескриптором тома? - cmp [CDDataBuf],byte 0x2 - jne .start + cmp [CDDataBuf],byte 0x2 + jne .start ; сектор является дополнительным дескриптором тома? - cmp [CDDataBuf+6],byte 0x1 - jne .start + cmp [CDDataBuf+6],byte 0x1 + jne .start ; параметры root директрории - mov eax,[CDDataBuf+0x9c+2] ; начало root директрории - mov [CDSectorAddress],eax - mov eax,[CDDataBuf+0x9c+10] ; размер root директрории - cmp byte [esi], 0 - jnz @f - mov [cd_current_pointer_of_input],CDDataBuf+0x9c - jmp .done + mov eax,[CDDataBuf+0x9c+2] ; начало root директрории + mov [CDSectorAddress],eax + mov eax,[CDDataBuf+0x9c+10] ; размер root директрории + cmp byte [esi], 0 + jnz @f + mov [cd_current_pointer_of_input],CDDataBuf+0x9c + jmp .done @@: ; начинаем поиск .mainloop: - dec dword [CDSectorAddress] + dec dword [CDSectorAddress] .read_to_buffer: - inc dword [CDSectorAddress] - mov [CDDataBuf_pointer],CDDataBuf - call ReadCDWRetr ; читаем сектор директории - cmp [DevErrorCode],0 - jne .access_denied - push ebp - call cd_find_name_in_buffer - pop ebp - jnc .found - sub eax,2048 + inc dword [CDSectorAddress] + mov [CDDataBuf_pointer],CDDataBuf + call ReadCDWRetr ; читаем сектор директории + cmp [DevErrorCode],0 + jne .access_denied + push ebp + call cd_find_name_in_buffer + pop ebp + jnc .found + sub eax,2048 ; директория закончилась? - cmp eax,0 - ja .read_to_buffer + cmp eax,0 + ja .read_to_buffer ; нет искомого элемента цепочки .access_denied: - pop esi eax - stc - ret + pop esi eax + mov [cd_appl_data],1 + stc + ret ; искомый элемент цепочки найден .found: ; конец пути файла - cmp byte [esi-1], 0 - jz .done + cmp byte [esi-1], 0 + jz .done .nested: - mov eax,[cd_current_pointer_of_input] - push dword [eax+2] - pop dword [CDSectorAddress] ; начало директории - mov eax,[eax+2+8] ; размер директории - jmp .mainloop + mov eax,[cd_current_pointer_of_input] + push dword [eax+2] + pop dword [CDSectorAddress] ; начало директории + mov eax,[eax+2+8] ; размер директории + jmp .mainloop ; указатель файла найден .done: - test ebp, ebp - jz @f - mov esi, ebp - xor ebp, ebp - jmp .nested + test ebp, ebp + jz @f + mov esi, ebp + xor ebp, ebp + jmp .nested @@: - pop esi eax - clc - ret + pop esi eax + mov [cd_appl_data],1 + clc + ret cd_find_name_in_buffer: - mov [cd_current_pointer_of_input_2],CDDataBuf + mov [cd_current_pointer_of_input_2],CDDataBuf .start: - call cd_get_name - jc .not_found - call cd_compare_name - jc .start + call cd_get_name + jc .not_found + call cd_compare_name + jc .start .found: - clc - ret + clc + ret .not_found: - stc - ret + stc + ret cd_get_name: - push eax - mov ebp,[cd_current_pointer_of_input_2] - mov [cd_current_pointer_of_input],ebp - mov eax,[ebp] - cmp eax,0 ; входы закончились? - je .next_sector - cmp ebp,CDDataBuf+2048 ; буфер закончился? - jae .next_sector - movzx eax, byte [ebp] - add [cd_current_pointer_of_input_2],eax ; следующий вход каталога - add ebp,33 ; указатель установлен на начало имени - pop eax - clc - ret + push eax + mov ebp,[cd_current_pointer_of_input_2] + mov [cd_current_pointer_of_input],ebp + mov eax,[ebp] + cmp eax,0 ; входы закончились? + je .next_sector + cmp ebp,CDDataBuf+2048 ; буфер закончился? + jae .next_sector + movzx eax, byte [ebp] + add [cd_current_pointer_of_input_2],eax ; следующий вход каталога + add ebp,33 ; указатель установлен на начало имени + pop eax + clc + ret .next_sector: - pop eax - stc - ret + pop eax + stc + ret cd_compare_name: ; compares ASCIIZ-names, case-insensitive (cp866 encoding) @@ -622,7 +637,7 @@ cd_compare_name: xchg ah,al scasw pop eax - je .coincides + je .coincides call char_toupper call ansi2uni_char xchg ah,al @@ -631,9 +646,9 @@ cd_compare_name: jne .name_not_coincide .coincides: cmp [esi],byte '/' ; разделитель пути, конец имени текущего элемента - je .done - cmp [esi],byte 0 ; разделитель пути, конец имени текущего элемента - je .done + je .done + cmp [esi],byte 0 ; разделитель пути, конец имени текущего элемента + je .done jmp .loop .name_not_coincide: pop edi eax esi @@ -642,13 +657,13 @@ cd_compare_name: .done: ; проверка конца файла cmp [edi],word 3B00h ; сепаратор конца файла ';' - je .done_1 + je .done_1 ; проверка для файлов не заканчивающихся сепаратором movzx eax,byte [ebp-33] add eax,ebp sub eax,34 cmp edi,eax - je .done_1 + je .done_1 ; проверка конца папки movzx eax,byte [ebp-1] add eax,ebp @@ -665,58 +680,58 @@ char_todown: ; convert character to uppercase, using cp866 encoding ; in: al=symbol ; out: al=converted symbol - cmp al, 'A' - jb .ret - cmp al, 'Z' - jbe .az - cmp al, 'Ђ' - jb .ret - cmp al, 'ђ' - jb .rus1 - cmp al, 'џ' - ja .ret + cmp al, 'A' + jb .ret + cmp al, 'Z' + jbe .az + cmp al, 'Ђ' + jb .ret + cmp al, 'ђ' + jb .rus1 + cmp al, 'џ' + ja .ret ; 0x90-0x9F -> 0xE0-0xEF - add al, 'а'-'ђ' + add al, 'а'-'ђ' .ret: - ret + ret .rus1: ; 0x80-0x8F -> 0xA0-0xAF .az: - add al, 0x20 - ret + add al, 0x20 + ret uni2ansi_char: ; convert UNICODE character in al to ANSI character in ax, using cp866 encoding ; in: ax=UNICODE character ; out: al=converted ANSI character - cmp ax, 0x80 - jb .ascii - cmp ax, 0x401 - jz .yo1 - cmp ax, 0x451 - jz .yo2 - cmp ax, 0x410 - jb .unk - cmp ax, 0x440 - jb .rus1 - cmp ax, 0x450 - jb .rus2 + cmp ax, 0x80 + jb .ascii + cmp ax, 0x401 + jz .yo1 + cmp ax, 0x451 + jz .yo2 + cmp ax, 0x410 + jb .unk + cmp ax, 0x440 + jb .rus1 + cmp ax, 0x450 + jb .rus2 .unk: - mov al, '_' - jmp .doit + mov al, '_' + jmp .doit .yo1: - mov al, 'р' - jmp .doit + mov al, 'р' + jmp .doit .yo2: - mov al, 'с' - jmp .doit + mov al, 'с' + jmp .doit .rus1: ; 0x410-0x43F -> 0x80-0xAF - add al, 0x70 - jmp .doit + add al, 0x70 + jmp .doit .rus2: ; 0x440-0x44F -> 0xE0-0xEF - add al, 0xA0 + add al, 0xA0 .ascii: .doit: - ret + ret diff --git a/programs/system/cd_tray/CD_tray.ASM b/programs/system/cd_tray/CD_tray.ASM new file mode 100644 index 0000000000..0e700e7bb5 --- /dev/null +++ b/programs/system/cd_tray/CD_tray.ASM @@ -0,0 +1,186 @@ +; +; Управление лотками дисковых приводов ATAPI +; 22.07.2007 Mario79 исходный вариант +;--------------------------------------------------------------------- + + use32 ; включить 32-битный режим ассемблера + org 0x0 ; адресация с нуля + + db 'MENUET01' ; 8-байтный идентификатор MenuetOS + dd 0x01 ; версия заголовка (всегда 1) + dd START ; адрес первой команды + dd I_END ; размер программы + dd 0x11000 ; количество памяти + dd 0x11000 ; адрес вершины стэка + dd 0x0 ; адрес буфера для параметров (не используется) + dd 0x0 ; зарезервировано + +include 'MACROS.INC' ; макросы облегчают жизнь ассемблерщиков! + +;--------------------------------------------------------------------- +;--- НАЧАЛО ПРОГРАММЫ ---------------------------------------------- +;--------------------------------------------------------------------- + +START: + +red: ; перерисовать окно + call draw_window ; вызываем процедуру отрисовки окна + +;--------------------------------------------------------------------- +;--- ЦИКЛ ОБРАБОТКИ СОБЫТИЙ ---------------------------------------- +;--------------------------------------------------------------------- + +still: + mcall 10 ; функция 10 - ждать события + + cmp eax,1 ; перерисовать окно ? + je red ; если да - на метку red + cmp eax,2 ; нажата клавиша ? + je key ; если да - на key + cmp eax,3 ; нажата кнопка ? + je button ; если да - на button + + jmp still ; если другое событие - в начало цикла + + +;--------------------------------------------------------------------- + + + key: ; нажата клавиша на клавиатуре + mcall 2 ; функция 2 - считать код символа (в ah) + + jmp still ; вернуться к началу цикла + +;--------------------------------------------------------------------- + + button: + mcall 17 ; 17 - получить идентификатор нажатой кнопки + cmp ah,2 + jne b3 + mov dword [load_tray.name],cd0 + jmp b5.1 + b3: + cmp ah,3 + jne b4 + mov dword [load_tray.name],cd1 + jmp b5.1 + b4: + cmp ah,4 + jne b5 + mov dword [load_tray.name],cd2 + jmp b5.1 + b5: + cmp ah,5 + jne b6 + mov dword [load_tray.name],cd3 + .1: + mcall 70, load_tray + jmp red + b6: + cmp ah,6 + jne b7 + mov dword [eject_tray.name],cd0 + jmp b9.1 + b7: + cmp ah,7 + jne b8 + mov dword [eject_tray.name],cd1 + jmp b9.1 + b8: + cmp ah,8 + jne b9 + mov dword [eject_tray.name],cd2 + jmp b9.1 + b9: + cmp ah,9 + jne b1 + mov dword [eject_tray.name],cd3 + .1: + mcall 70, eject_tray + jmp red + b1: + cmp ah, 1 ; если НЕ нажата кнопка с номером 1, + jne still ; вернуться + + .exit: + mcall -1 ; иначе конец программы + + + +;--------------------------------------------------------------------- +;--- ОПРЕДЕЛЕНИЕ И ОТРИСОВКА ОКНА ---------------------------------- +;--------------------------------------------------------------------- + +draw_window: + mcall 12, 1 ; функция 12: сообщить ОС об отрисовке окна + ; 1 - начинаем рисовать + ; СОЗДАиМ ОКНО + + mcall 0, <100,230>, <100,110>, 0x03AABBCC, 0x805080D0, 0x005080D0 + mcall 71, 1 ,header + mcall 8,<15,42>,<40,20>,2,0xaaaaaa + call draw_buttons + mov edx,6 + add ecx,30 shl 16 + mcall + call draw_buttons + + mcall 4, <25,25>, 0x80ffffff,text1 + mov edx,text2 + + add ebx,3 shl 16+20 + mcall + mov edx,text3 + add ebx,30 + sub ebx,3 shl 16 + mcall + + mcall 12, 2 ; функция 12: сообщить ОС об отрисовке окна + ; 2, закончили рисовать + + ret ; выходим из процедуры + +draw_buttons: + pusha + add ebx,50 shl 16 + inc edx + mcall + add ebx,50 shl 16 + inc edx + mcall + add ebx,50 shl 16 + inc edx + mcall + popa + ret +;--------------------------------------------------------------------- +;--- ДАННЫЕ ПРОГРАММЫ ---------------------------------------------- +;--------------------------------------------------------------------- +header db ' ATAPI Device Tray Control',0 +text3 db 'eject eject eject eject',0 +text2 db 'load load load load',0 +text1 db '/cd0/ /cd1/ /cd2/ /cd3/',0 +cd0: db '/cd0/1/',0 +cd1: db '/cd1/1/',0 +cd2: db '/cd2/1/',0 +cd3: db '/cd3/1/',0 +;--------------------------------------------------------------------- +load_tray: + .subfunction dd 11 + .rezerv dd 0 + .rezerv1 dd 0 + .rezerv2 dd 0 + .rezerv3 dd 0 + db 0 + .name: dd cd0 + +eject_tray: + .subfunction dd 10 + .rezerv dd 0 + .rezerv1 dd 0 + .rezerv2 dd 0 + .rezerv3 dd 0 + db 0 + .name: dd cd0 + +I_END: ; метка конца программы diff --git a/programs/system/cd_tray/MACROS.INC b/programs/system/cd_tray/MACROS.INC new file mode 100644 index 0000000000..cd445840ed --- /dev/null +++ b/programs/system/cd_tray/MACROS.INC @@ -0,0 +1,268 @@ +; new application structure +macro meos_app_start + { + use32 + org 0x0 + + db 'MENUET01' + dd 0x01 + dd __start + dd __end + dd __memory + dd __stack + + if used __params & ~defined __params + dd __params + else + dd 0x0 + end if + + dd 0x0 + } +MEOS_APP_START fix meos_app_start + +macro code + { + __start: + } +CODE fix code + +macro data + { + __data: + } +DATA fix data + +macro udata + { + if used __params & ~defined __params + __params: + db 0 + __end: + rb 255 + else + __end: + end if + __udata: + } +UDATA fix udata + +macro meos_app_end + { + align 32 + rb 2048 + __stack: + __memory: + } +MEOS_APP_END fix meos_app_end + + +; macro for defining multiline text data +struc mstr [sstring] + { + forward + local ssize + virtual at 0 + db sstring + ssize = $ + end virtual + dd ssize + db sstring + common + dd -1 + } + + +; strings +macro sz name,[data] { ; from MFAR [mike.dld] + common + if used name + label name + end if + forward + if used name + db data + end if + common + if used name + .size = $-name + end if +} + +macro lsz name,[lng,data] { ; from MFAR [mike.dld] + common + if used name + label name + end if + forward + if (used name)&(lang eq lng) + db data + end if + common + if used name + .size = $-name + end if +} + + + +; easy system call macro +macro mpack dest, hsrc, lsrc +{ + if (hsrc eqtype 0) & (lsrc eqtype 0) + mov dest, (hsrc) shl 16 + lsrc + else + if (hsrc eqtype 0) & (~lsrc eqtype 0) + mov dest, (hsrc) shl 16 + add dest, lsrc + else + mov dest, hsrc + shl dest, 16 + add dest, lsrc + end if + end if +} + +macro __mov reg,a,b { ; mike.dld + if (~a eq)&(~b eq) + mpack reg,a,b + else if (~a eq)&(b eq) + mov reg,a + end if +} + +macro mcall a,b,c,d,e,f { ; mike.dld + __mov eax,a + __mov ebx,b + __mov ecx,c + __mov edx,d + __mov esi,e + __mov edi,f + int 0x40 +} + + + +; language for programs +lang fix ru ; ru en fr ge fi + + + +; optimize the code for size +__regs fix + +macro add arg1,arg2 + { + if (arg2 eqtype 0) + if (arg2) = 1 + inc arg1 + else + add arg1,arg2 + end if + else + add arg1,arg2 + end if + } + +macro sub arg1,arg2 + { + if (arg2 eqtype 0) + if (arg2) = 1 + dec arg1 + else + sub arg1,arg2 + end if + else + sub arg1,arg2 + end if + } + +macro mov arg1,arg2 + { + if (arg1 in __regs) & (arg2 eqtype 0) + if (arg2) = 0 + xor arg1,arg1 + else if (arg2) = 1 + xor arg1,arg1 + inc arg1 + else if (arg2) = -1 + or arg1,-1 + else if (arg2) > -128 & (arg2) < 128 + push arg2 + pop arg1 + else + mov arg1,arg2 + end if + else + mov arg1,arg2 + end if + } + + +macro struct name + { + virtual at 0 + name name + sizeof.#name = $ - name + end virtual + } + +; structures used in MeOS +struc process_information + { + .cpu_usage dd ? ; +0 + .window_stack_position dw ? ; +4 + .window_stack_value dw ? ; +6 + .not_used1 dw ? ; +8 + .process_name rb 12 ; +10 + .memory_start dd ? ; +22 + .used_memory dd ? ; +26 + .PID dd ? ; +30 + .x_start dd ? ; +34 + .y_start dd ? ; +38 + .x_size dd ? ; +42 + .y_size dd ? ; +46 + .slot_state dw ? ; +50 + rb (1024-52) + } +struct process_information + +struc system_colors + { + .frame dd ? + .grab dd ? + .grab_button dd ? + .grab_button_text dd ? + .grab_text dd ? + .work dd ? + .work_button dd ? + .work_button_text dd ? + .work_text dd ? + .work_graph dd ? + } +struct system_colors + + +; constants + +; events +EV_IDLE = 0 +EV_TIMER = 0 +EV_REDRAW = 1 +EV_KEY = 2 +EV_BUTTON = 3 +EV_EXIT = 4 +EV_BACKGROUND = 5 +EV_MOUSE = 6 +EV_IPC = 7 +EV_STACK = 8 + +; event mask bits for function 40 +EVM_REDRAW = 1b +EVM_KEY = 10b +EVM_BUTTON = 100b +EVM_EXIT = 1000b +EVM_BACKGROUND = 10000b +EVM_MOUSE = 100000b +EVM_IPC = 1000000b +EVM_STACK = 10000000b \ No newline at end of file diff --git a/programs/system/cd_tray/build.bat b/programs/system/cd_tray/build.bat new file mode 100644 index 0000000000..c4cc6c4b97 --- /dev/null +++ b/programs/system/cd_tray/build.bat @@ -0,0 +1,2 @@ +@fasm CD_tray.ASM CD_tray +@pause \ No newline at end of file