source: xtideuniversalbios/trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm@ 594

Last change on this file since 594 was 593, checked in by Tomi Tilli, 6 years ago

Flashing now works again.
Hack to get Windows 95 to work properly (MODULE_WIN95_CMOS_HACK included for 386 builds by default).
Edited makefile to produce large 386 build.
Fixed recovery time for QDI Vision VLB-IDE controllers.
No more warnings with Nasm 2.13.xx and later.
File dialog now properly restores default drive when file selection is cancelled.

File size: 23.9 KB
RevLine 
[41]1; Project name : Assembly Library
2; Description : Displays file dialog.
3
[376]4;
[505]5; XTIDE Universal BIOS and Associated Tools
[526]6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
[376]7;
8; This program is free software; you can redistribute it and/or modify
9; it under the terms of the GNU General Public License as published by
10; the Free Software Foundation; either version 2 of the License, or
11; (at your option) any later version.
[505]12;
[376]13; This program is distributed in the hope that it will be useful,
14; but WITHOUT ANY WARRANTY; without even the implied warranty of
15; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
[505]16; GNU General Public License for more details.
[376]17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
[41]19
20CURRENTDIR_CHARACTERS EQU 002Eh
21UPDIR_CHARACTERS EQU 2E2Eh
22
23; Section containing code
24SECTION .text
25
26;--------------------------------------------------------------------
27; DialogFile_GetFileNameWithIoInDSSI
28; Parameters:
29; DS:SI: Ptr to FILE_DIALOG_IO
30; SS:BP: Ptr to parent MENU
31; Returns:
32; Nothing
33; Corrupts registers:
[593]34; AX, BX, CX, DX, DI
[41]35;--------------------------------------------------------------------
36ALIGN JUMP_ALIGN
37DialogFile_GetFileNameWithIoInDSSI:
[593]38 ; We need to store default drive because user might change drive but
39 ; then cancel the file selection. In that case the original default directory
40 ; must be restored.
41 call Drive_GetDefaultToAL
42 push ax
43
[41]44 mov bx, FileEventHandler
45 mov BYTE [si+FILE_DIALOG_IO.bUserCancellation], TRUE
[593]46 call Dialog_DisplayWithDialogInputInDSSIandHandlerInBX
[41]47
[593]48 ; Now restore the default drive if user cancellation
49 pop dx
50 cmp BYTE [si+FILE_DIALOG_IO.bUserCancellation], TRUE
51 je Drive_SetDefaultFromDL
52 ret
[41]53
[593]54
[41]55;--------------------------------------------------------------------
56; FileEventHandler
57; Common parameters for all events:
58; BX: Menu event (anything from MENUEVENT struct)
59; SS:BP: Ptr to DIALOG
60; Common return values for all events:
61; CF: Set if event processed
62; Cleared if event not processed
63; Corrupts registers:
64; All
65;--------------------------------------------------------------------
66ALIGN JUMP_ALIGN
67FileEventHandler:
68 jmp [cs:bx+.rgfnEventHandlers]
69
70
71ALIGN JUMP_ALIGN
72.ItemSelectedFromCX:
73 call LoadItemStringBufferToESDI
[106]74 call Registers_CopyESDItoDSSI
[52]75 call ItemLineSplitter_GetLineToDSSIandLengthToCXfromStringInDSSIwithIndexInCX
[41]76 jmp ParseSelectionFromItemLineInDSSI
77
78
79ALIGN JUMP_ALIGN
80.RefreshInformation:
81 call GetInfoLinesToCXandDialogFlagsToAX
82 mov si, [cs:.rgszInfoStringLookup]
83 xor bx, bx
84 xchg dx, ax
85ALIGN JUMP_ALIGN
86.InfoLineLoop:
87 shr dl, 1
88 jnc SHORT .CheckNextFlag
89 mov si, [cs:bx+.rgszInfoStringLookup]
90 push bx
91 CALL_DISPLAY_LIBRARY PrintNullTerminatedStringFromCSSI
92 pop bx
93ALIGN JUMP_ALIGN
94.CheckNextFlag:
95 inc bx
96 inc bx
97 loop .InfoLineLoop
98 stc ; Event processed
99 ret
100
101
[53]102ALIGN JUMP_ALIGN
103.RefreshItemFromCX:
104 call LoadItemStringBufferToESDI
105 mov ax, FILE_STRING_LENGTH
106 xchg ax, cx
107 mul cx
108 add di, ax
109 mov si, di
110 mov bx, es
111 dec cx ; Do not print LF at the end of file string
112 CALL_DISPLAY_LIBRARY PrintCharBufferFromBXSIwithLengthInCX
113 stc
114 ret
115
116
[41]117ALIGN WORD_ALIGN
118.rgszInfoStringLookup:
119 dw g_szChangeDrive
120 dw g_szSelectDirectory
121 dw g_szCreateNew
122
123.rgfnEventHandlers:
124istruc MENUEVENT
125 at MENUEVENT.InitializeMenuinitFromDSSI, dw InitializeMenuinitFromSSBP
[58]126 at MENUEVENT.ExitMenu, dw Dialog_EventExitMenu
[41]127 at MENUEVENT.IdleProcessing, dw Dialog_EventNotHandled
128 at MENUEVENT.ItemHighlightedFromCX, dw Dialog_EventNotHandled
129 at MENUEVENT.ItemSelectedFromCX, dw .ItemSelectedFromCX
130 at MENUEVENT.KeyStrokeInAX, dw HandleFunctionKeyFromAH
131 at MENUEVENT.RefreshTitle, dw Dialog_EventRefreshTitle
132 at MENUEVENT.RefreshInformation, dw .RefreshInformation
[53]133 at MENUEVENT.RefreshItemFromCX, dw .RefreshItemFromCX
[41]134iend
135
136
137;--------------------------------------------------------------------
[54]138; ReInitializeMenuinitFromSSBP
[41]139; InitializeMenuinitFromSSBP
140; Parameters:
141; SS:BP: Ptr to DIALOG
142; Returns:
143; Nothing
144; Corrupts registers:
145; All, except BP
146;--------------------------------------------------------------------
147ALIGN JUMP_ALIGN
[54]148ReInitializeMenuinitFromSSBP:
149 call DisplayLoadingMessageInInformationArea
[41]150InitializeMenuinitFromSSBP:
151 call LoadItemStringBufferToESDI
152 call CreateStringFromCurrentDirectoryContentsToESDI
[46]153 call LoadItemStringBufferToESDI
154 call SortDirectoryContentsStringFromESDIwithCountInCX
[53]155 call RemoveLastLFandTerminateESDIwithNull
[54]156
[106]157 call Registers_CopySSBPtoDSSI
[52]158 xor ax, ax
159 call Dialog_EventInitializeMenuinitFromDSSIwithHighlightedItemInAX
[41]160 call GetInfoLinesToCXandDialogFlagsToAX
161 mov [bp+MENUINIT.bInfoLines], cl
162 CALL_DISPLAY_LIBRARY GetColumnsToALandRowsToAH
163 mov [bp+MENUINIT.bHeight], ah ; Always max height
[52]164 mov WORD [bp+MENU.wFirstVisibleItem], 0
[41]165 ret
166
167
168;--------------------------------------------------------------------
169; LoadItemStringBufferToESDI
170; Parameters:
171; SS:BP: Ptr to DIALOG
172; Returns:
173; ES:DI: Ptr to item string buffer
174; Corrupts registers:
175; Nothing
176;--------------------------------------------------------------------
177ALIGN JUMP_ALIGN
178LoadItemStringBufferToESDI:
179 les di, [bp+DIALOG.fpDialogIO]
180 les di, [es:di+FILE_DIALOG_IO.fszItemBuffer]
181 ret
182
183
184;--------------------------------------------------------------------
185; CreateStringFromCurrentDirectoryContentsToESDI
186; Parameters:
187; ES:DI: Buffer where to create item string
188; SS:BP: Ptr to DIALOG
189; Returns:
[46]190; CX: Number of files or directories found
[41]191; Corrupts registers:
[53]192; AX, BX, DX, SI, DI, DS
[41]193;--------------------------------------------------------------------
194ALIGN JUMP_ALIGN
195CreateStringFromCurrentDirectoryContentsToESDI:
[53]196 mov bx, di
197 CALL_DISPLAY_LIBRARY PushDisplayContext
198 mov cx, -1
199 CALL_DISPLAY_LIBRARY PrepareOffScreenBufferInESBXwithLengthInCX ; ES:DI now points to buffer
200
[41]201 lds si, [bp+DIALOG.fpDialogIO]
[293]202 eMOVZX cx, [si+FILE_DIALOG_IO.bFileAttributes]
[41]203 lds si, [si+FILE_DIALOG_IO.fpFileFilterString]
204 call Directory_UpdateDTAForFirstMatchForDSSIwithAttributesInCX
[53]205
[41]206 call .ClearDLifInRootDirectory
207 call Directory_GetDiskTransferAreaAddressToDSSI
[46]208 xor cx, cx ; Clear file/directory count
[53]209 call .FindMatchingFilesAndPrintThemToOffScreenBuffer
[41]210
[505]211 JMP_DISPLAY_LIBRARY PopDisplayContext
[41]212
213;--------------------------------------------------------------------
214; .ClearDLifInRootDirectory
215; Parameters:
216; SS:BP: Ptr to DIALOG
217; ES:DI: Ptr to destination string buffer
218; Returns:
219; DL: Cleared if in root directory
220; Set if in any other directory
221; Corrupts registers:
222; AX, SI, DS
223;--------------------------------------------------------------------
224ALIGN JUMP_ALIGN
225.ClearDLifInRootDirectory:
[106]226 call Registers_CopyESDItoDSSI
[41]227 call Directory_WriteCurrentPathToDSSI
228 mov dl, [si]
229 ret
230
231;--------------------------------------------------------------------
[53]232; .FindMatchingFilesAndPrintThemToOffScreenBuffer
[41]233; Parameters:
[53]234; CX: Initial directory count
235; DL: Zero if root directory selected
236; DS:SI: Ptr to DTA with first matching file
[41]237; Returns:
[53]238; CX: Incremented by number of files/directories found
[41]239; Corrupts registers:
[53]240; AX, BX, DX, DI, DS
[41]241;--------------------------------------------------------------------
242ALIGN JUMP_ALIGN
[53]243.FindMatchingFilesAndPrintThemToOffScreenBuffer:
244 call AppendFileFromDTAinDSSItoOffScreenBuffer
245 call Directory_UpdateDTAForNextMatchUsingPreviousParameters
246 jnc SHORT .FindMatchingFilesAndPrintThemToOffScreenBuffer
[41]247 ret
248
[46]249
[41]250;--------------------------------------------------------------------
[53]251; AppendFileFromDTAinDSSItoOffScreenBuffer
[41]252; Parameters:
[589]253; CX: Files/directories found
[41]254; DL: Zero if root directory selected
255; DS:SI: Ptr to DTA containing file information
256; Returns:
[46]257; CX: Incremented by number of files/directories found
[41]258; Corrupts registers:
[53]259; AX, BX
[41]260;--------------------------------------------------------------------
261ALIGN JUMP_ALIGN
[53]262AppendFileFromDTAinDSSItoOffScreenBuffer:
[592]263 cmp WORD [si+DTA.szFile], CURRENTDIR_CHARACTERS
264 je SHORT .Return ; We never want "."
265 test dl, dl
266 jnz SHORT .NotInRootDirectory
267 cmp WORD [si+DTA.szFile], UPDIR_CHARACTERS
268 je SHORT .Return ; No ".." when in root directory
269.NotInRootDirectory:
[46]270 inc cx ; Nothing filtered so increment files/directories
[41]271
272 push bp
273 push si
[53]274 push dx
[46]275 push cx
[41]276 call .FormatFileOrDirectoryToBufferFromDTAinDSSI
[46]277 pop cx
[53]278 pop dx
[41]279 pop si
280 pop bp
[592]281.Return:
[41]282 ret
283
284;--------------------------------------------------------------------
285; .FormatFileOrDirectoryToBufferFromDTAinDSSI
286; Parameters:
287; DS:SI: Ptr to DTA containing file information
288; Returns:
289; Nothing
290; Corrupts registers:
291; AX, BX, CX, DX, SI, DI, BP
292;--------------------------------------------------------------------
293ALIGN JUMP_ALIGN
294.FormatFileOrDirectoryToBufferFromDTAinDSSI:
295 mov bp, sp
296 lea ax, [si+DTA.szFile]
297
298 test BYTE [si+DTA.bFileAttributes], FLG_FILEATTR_DIRECTORY
299 jnz SHORT .FormatDirectory
[46]300 ; Fall to .FormatFile
[41]301
[46]302;--------------------------------------------------------------------
303; .FormatFile
304; Parameters:
305; BP: SP before pushing formatting parameters
306; DS:AX: Far pointer to file name
307; DS:SI: Ptr to DTA containing file information
308; Returns:
309; Nothing
310; Corrupts registers:
[53]311; AX, BX, CX, DX, SI, DI
[46]312;--------------------------------------------------------------------
313.FormatFile:
314 xchg si, ax
[53]315 call String_ConvertDSSItoLowerCase
[46]316 xchg ax, si
[52]317
318 ; Push parameters for file name
[53]319 push ax ; Push file name offset
320 push ds ; Push file name segment
[46]321
322 ; Push parameters for file size
[41]323 mov ax, [si+DTA.dwFileSize]
324 mov dx, [si+DTA.dwFileSize+2]
325 xor bx, bx
326 xor cx, cx
327 call Size_GetSizeToAXAndCharToDLfromBXDXAXwithMagnitudeInCX
328 mov cl, 'i'
329 cmp dl, ' '
330 eCMOVE cl, dl
331 push ax
332 push dx
333 push cx
[46]334
335 ; Format to buffer
[41]336 mov si, g_szFileFormat
337 jmp SHORT .FormatStringInCSSIandReturn
338
[46]339;--------------------------------------------------------------------
340; .FormatDirectory
341; Parameters:
342; BP: SP before pushing formatting parameters
343; DS:AX: Far pointer to directory name
344; DS:SI: Ptr to DTA containing file information
345; Returns:
346; Nothing
347; Corrupts registers:
[53]348; AX, SI, DI
[46]349;--------------------------------------------------------------------
[41]350ALIGN JUMP_ALIGN
351.FormatDirectory:
[46]352 push ax ; Push directory name offset
353 push ds ; Push directory name segment
[41]354 mov ax, g_szSub
355 cmp WORD [si+DTA.szFile], UPDIR_CHARACTERS
356 eCMOVE ax, g_szUp
357 push ax
358 mov si, g_szDirectoryFormat
359ALIGN JUMP_ALIGN
360.FormatStringInCSSIandReturn:
[505]361 JMP_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
[41]362
363
364;--------------------------------------------------------------------
[46]365; SortDirectoryContentsStringFromESDIwithCountInCX
366; Parameters:
367; CX: Number of files and directories
368; ES:DI: Buffer containing directory contents string
369; SS:BP: Ptr to DIALOG
370; Returns:
[53]371; ES:DI: Ptr to end of directory contents string
[46]372; Corrupts registers:
[53]373; AX, BX, CX, DX, SI, DS
[46]374;--------------------------------------------------------------------
375ALIGN JUMP_ALIGN
376SortDirectoryContentsStringFromESDIwithCountInCX:
[106]377 call Registers_CopyESDItoDSSI
[46]378
[181]379 ; Add directory contents string length to DI
[53]380 mov ax, FILE_STRING_LENGTH
[181]381 push ax
[53]382 mul cx
383 add di, ax
384
[181]385 mov dx, cx
386 pop cx
387 mov bx, .FileStringComparator
388 jmp Sort_ItemsFromDSSIwithCountInDXsizeInCXandComparatorInBX
389
[46]390;--------------------------------------------------------------------
391; .FileStringComparator
392; Parameters:
393; CX: Item size in bytes
394; DS:SI: Ptr to first item to compare
395; ES:DI: Ptr to second item to compare
396; Returns:
[181]397; FLAGS: Signed comparison between first and second item
[46]398; Corrupts registers:
399; Nothing
400;--------------------------------------------------------------------
401ALIGN JUMP_ALIGN
402.FileStringComparator:
403 push di
404 push si
405 push cx
406 push bx
407
408 mov bx, FILE_STRING_LENGTH-2 ; Zero BH
409 cmp WORD [si], UPDIR_CHARACTERS
410 je SHORT .ForceValueFromDSSItoBeLess
411 mov bl, [si+bx]
412 cmp bl, [es:di+FILE_STRING_LENGTH-2] ; 'B' for files, 'R' for directories
413 jne SHORT .ForceValueFromDSSItoBeMoreOrLess
414 repe cmpsb ; Two directories or two files
415
416ALIGN JUMP_ALIGN
417.ReturnFromComparison:
418 pop bx
419 pop cx
420 pop si
421 pop di
422 ret
423ALIGN JUMP_ALIGN
424.ForceValueFromDSSItoBeMoreOrLess:
425 ja SHORT .ForceValueFromDSSItoBeLess ; Directory in SI, file in DI
426 xchg bl, bh
427 ; Fall to ForceValueFromDSSItoBeLess
428ALIGN JUMP_ALIGN
429.ForceValueFromDSSItoBeLess:
430 cmp bh, bl
431 jmp SHORT .ReturnFromComparison
432
433
434;--------------------------------------------------------------------
[54]435; RemoveLastLFandTerminateESDIwithNull
436; Parameters:
437; ES:DI: Ptr to end of buffer to terminate
438; Returns:
439; Nothing
440; Corrupts registers:
441; AX
442;--------------------------------------------------------------------
443ALIGN JUMP_ALIGN
444RemoveLastLFandTerminateESDIwithNull:
445 dec di
446 xor ax, ax
447 stosb
448 ret
449
450
451;--------------------------------------------------------------------
[41]452; GetInfoLinesToCXandDialogFlagsToAX
453; Parameters:
454; SS:BP: Ptr to DIALOG
455; Returns:
456; AX: Dialog flags
457; CX: Number of info lines to be displayed
458; Corrupts registers:
459; SI, DS
460;--------------------------------------------------------------------
461ALIGN JUMP_ALIGN
462GetInfoLinesToCXandDialogFlagsToAX:
[592]463 ePUSH_T ax, Bit_GetSetCountToCXfromAX
464 xor ah, ah
465 ; Fall to GetDialogFlagsToAL
[41]466
467;--------------------------------------------------------------------
468; GetDialogFlagsToAL
469; Parameters:
470; SS:BP: Ptr to DIALOG
471; Returns:
472; AL: Dialog flags
473; Corrupts registers:
474; SI, DS
475;--------------------------------------------------------------------
476ALIGN JUMP_ALIGN
477GetDialogFlagsToAL:
478 lds si, [bp+DIALOG.fpDialogIO]
479 mov al, [si+FILE_DIALOG_IO.bDialogFlags]
480 ret
481
482
483;--------------------------------------------------------------------
484; ParseSelectionFromItemLineInDSSI
485; Parameters:
486; DS:SI: Ptr to char buffer containing file or directory to be selected
487; SS:BP: Ptr to DIALOG
488; Returns:
489; Nothing
490; Corrupts registers:
491; All, except BP
492;--------------------------------------------------------------------
493ALIGN JUMP_ALIGN
494ParseSelectionFromItemLineInDSSI:
[46]495 mov ax, [si]
496 cmp ax, UPDIR_CHARACTERS
497 je SHORT .ChangeToUpdir
498 call Char_IsUpperCaseLetterInAL
499 jc SHORT .ParseAndChangeToSubdirInDSSI
[141]500 call Char_IsDecimalDigitInAL
501 jc SHORT .ParseAndChangeToSubdirInDSSI ; Assume subdir and check for errors
[46]502 ; Fall to .ParseAndSelectFileFromDSSI
[41]503
504;--------------------------------------------------------------------
[46]505; .ParseAndSelectFileFromDSSI
[41]506; Parameters:
[46]507; DS:SI: NULL terminated string selected from dialog
[41]508; SS:BP: Ptr to DIALOG
509; Returns:
510; Nothing (exits dialog)
511; Corrupts registers:
512; All, except BP
513;--------------------------------------------------------------------
[46]514.ParseAndSelectFileFromDSSI:
[41]515 les di, [bp+DIALOG.fpDialogIO]
516 add di, BYTE FILE_DIALOG_IO.szFile
517 mov cx, FILENAME_BUFFER_SIZE-1
[50]518 call Memory_CopyCXbytesFromDSSItoESDI
[41]519 xor ax, ax
520 stosb ; Terminate with NULL
[293]521 jmp SHORT CloseFileDialogAfterSuccessfulSelection
[41]522
523;--------------------------------------------------------------------
[46]524; .ChangeToUpdir
[41]525; Parameters:
526; SS:BP: Ptr to DIALOG
527; Returns:
528; Nothing
529; Corrupts registers:
530; All, except BP
531;--------------------------------------------------------------------
532ALIGN JUMP_ALIGN
[46]533.ChangeToUpdir:
[51]534 push cs
535 pop ds
[46]536 mov si, g_szUpdir
537 jmp SHORT .ChangeDirectoryToDSSI
538
539;--------------------------------------------------------------------
540; .ParseAndChangeToSubdirInDSSI
541; Parameters:
542; DS:SI: NULL terminated string selected from dialog
543; SS:BP: Ptr to DIALOG
544; Returns:
545; Nothing
546; Corrupts registers:
547; All, except BP
548;--------------------------------------------------------------------
549ALIGN JUMP_ALIGN
550.ParseAndChangeToSubdirInDSSI:
551 mov BYTE [si+12], NULL ; Terminate with NULL (unnecessary spaces do not matter)
552.ChangeDirectoryToDSSI:
[41]553 call Directory_ChangeToPathFromDSSI
[141]554 jc SHORT .ParseAndSelectFileFromDSSI ; Must have been a file starting with number
[41]555 ; Fall to RefreshFilesToDisplay
556
557;--------------------------------------------------------------------
558; RefreshFilesToDisplay
559; Parameters:
560; SS:BP: Ptr to DIALOG
561; Returns:
562; Nothing
563; Corrupts registers:
564; All, except BP
565;--------------------------------------------------------------------
566ALIGN JUMP_ALIGN
567RefreshFilesToDisplay:
[54]568 call ReInitializeMenuinitFromSSBP
[41]569 jmp MenuInit_RefreshMenuWindow
570
571
572;--------------------------------------------------------------------
573; HandleFunctionKeyFromAH
574; Parameters:
575; AH: Scancode for function key
576; SS:BP: Ptr to DIALOG
577; Returns:
578; Nothing
579; Corrupts registers:
580; AX, SI, DI, BP
581;--------------------------------------------------------------------
582ALIGN JUMP_ALIGN
583HandleFunctionKeyFromAH:
584 call GetDialogFlagsToAL
585 cmp ah, KEY_FILEDIALOG_NEW_FILE_OR_DIR
586 je SHORT HandleFunctionKeyForCreatingNewFileOrDirectory
587 cmp ah, KEY_FILEDIALOG_SELECT_DIRECTORY
588 je SHORT HandleFunctionKeyForSelectingDirectoryInsteadOfFile
589 cmp ah, KEY_FILEDIALOG_CHANGE_DRIVE
590 je SHORT HandleFunctionKeyForDriveChange
591ReturnWithoutHandlingKeystroke:
592 clc ; Event not processed
593 ret
594
595
596;--------------------------------------------------------------------
597; HandleFunctionKeyForCreatingNewFileOrDirectory
598; Parameters:
599; AL: File dialog flags
600; SS:BP: Ptr to DIALOG
601; Returns:
602; Closes file dialog
603; Corrupts registers:
604; All, except BP
605;--------------------------------------------------------------------
606ALIGN JUMP_ALIGN
607HandleFunctionKeyForCreatingNewFileOrDirectory:
608 test al, FLG_FILEDIALOG_NEW
609 jz SHORT ReturnWithoutHandlingKeystroke
610
611 mov cx, STRING_DIALOG_IO_size
612 call Memory_ReserveCXbytesFromStackToDSSI
613
[568]614;;; InitializeStringDialogIoInDSSIforInputtingFileName
[41]615 call InitializeNullStringsToDialogInputInDSSI
616 mov WORD [si+DIALOG_INPUT.fszTitle], g_szEnterNewFileOrDirectory
617 mov WORD [si+STRING_DIALOG_IO.fnCharFilter], NULL
618 mov WORD [si+STRING_DIALOG_IO.wBufferSize], FILENAME_BUFFER_SIZE
619 les ax, [bp+DIALOG.fpDialogIO]
620 add ax, BYTE FILE_DIALOG_IO.szFile
621 mov [si+STRING_DIALOG_IO.fpReturnBuffer], ax
622 mov [si+STRING_DIALOG_IO.fpReturnBuffer+2], es
[568]623;;;
[41]624
[568]625 CALL_MENU_LIBRARY GetStringWithIoInDSSI
626 mov al, [si+STRING_DIALOG_IO.bUserCancellation]
627 add sp, BYTE STRING_DIALOG_IO_size
628 test al, al ; User cancellation?
629 jnz SHORT ReturnWithoutHandlingKeystroke
630 jmp CloseFileDialogAfterSuccessfulSelection
[41]631
[568]632
[41]633;--------------------------------------------------------------------
634; HandleFunctionKeyForSelectingDirectoryInsteadOfFile
635; Parameters:
636; AL: File dialog flags
637; SS:BP: Ptr to DIALOG
638; Returns:
639; Closes file dialog
640; Corrupts registers:
641; All, except BP
642;--------------------------------------------------------------------
643ALIGN JUMP_ALIGN
644HandleFunctionKeyForSelectingDirectoryInsteadOfFile:
645 test al, FLG_FILEDIALOG_DIRECTORY
646 jz SHORT ReturnWithoutHandlingKeystroke
[293]647 ; Fall to CloseFileDialogAfterSuccessfulSelection
[41]648
649;--------------------------------------------------------------------
[293]650; CloseFileDialogAfterSuccessfulSelection
[41]651; Parameters:
652; SS:BP: Ptr to DIALOG
653; Returns:
654; Nothing (exits dialog)
655; Corrupts registers:
656; All, except BP
657;--------------------------------------------------------------------
658ALIGN JUMP_ALIGN
[293]659CloseFileDialogAfterSuccessfulSelection:
[41]660 lds di, [bp+DIALOG.fpDialogIO]
661 mov BYTE [di+FILE_DIALOG_IO.bUserCancellation], FALSE
662 jmp MenuInit_CloseMenuWindow
663
664
665;--------------------------------------------------------------------
666; HandleFunctionKeyForDriveChange
667; Parameters:
668; AL: File dialog flags
669; SS:BP: Ptr to DIALOG
670; Returns:
671; Nothing
672; Corrupts registers:
673; All, except BP
674;--------------------------------------------------------------------
675ALIGN JUMP_ALIGN
676HandleFunctionKeyForDriveChange:
677 test al, FLG_FILEDIALOG_DRIVES
678 jz SHORT ReturnWithoutHandlingKeystroke
679
[54]680 call DisplayLoadingMessageInInformationArea
681 mov cx, DRIVE_DIALOG_IO_size
682 call Memory_ReserveCXbytesFromStackToDSSI
683 call .DisplayDriveSelectionDialogWithIoInDSSI
684 call .ChangeDriveToUserSelectionFromIoInDSSI
685 add sp, BYTE DRIVE_DIALOG_IO_size
[592]686.UserCancelledDriveChange:
[54]687 ret
[41]688
689;--------------------------------------------------------------------
[54]690; .DisplayDriveSelectionDialogWithIoInDSSI
[41]691; Parameters:
[54]692; DS:SI: Ptr to uninitialized DRIVE_DIALOG_IO
[41]693; SS:BP: Ptr to DIALOG
694; Returns:
[54]695; DS:SI: Ptr to DRIVE_DIALOG_IO
[41]696; Corrupts registers:
[54]697; AX, DI
[41]698;--------------------------------------------------------------------
699ALIGN JUMP_ALIGN
[54]700.DisplayDriveSelectionDialogWithIoInDSSI:
[41]701 call InitializeNullStringsToDialogInputInDSSI
702 mov WORD [si+DIALOG_INPUT.fszTitle], g_szSelectNewDrive
[525]703 JMP_MENU_LIBRARY GetDriveWithIoInDSSI
[41]704
705;--------------------------------------------------------------------
[54]706; .ChangeDriveToUserSelectionFromIoInDSSI
[41]707; Parameters:
[54]708; DS:SI: Ptr to DRIVE_DIALOG_IO
[41]709; SS:BP: Ptr to DIALOG
710; Returns:
711; Nothing
712; Corrupts registers:
[54]713; All, except BP
[41]714;--------------------------------------------------------------------
715ALIGN JUMP_ALIGN
[54]716.ChangeDriveToUserSelectionFromIoInDSSI:
717 cmp BYTE [si+DRIVE_DIALOG_IO.bUserCancellation], FALSE
718 jne SHORT .UserCancelledDriveChange
[41]719
[592]720 ; Install our Custom Critical Error Handler to catch "Drive Not Ready" errors. This handler only works on DOS 3.0+ systems
721 ; but that should be OK because only DOS 3.1+ will trigger it. Under older DOS versions drives are enumerated using
722 ; GET_DOS_DRIVE_PARAMETER_BLOCK_FOR_SPECIFIC_DRIVE which will access the drive so we know it is available at this point.
723 mov dx, DosCritical_CustomHandler
724 call DosCritical_InstallNewHandlerFromCSDX
725
726 ; Save the current drive on stack in case the selected drive is not ready and the user decides to cancel the change.
727 call Drive_GetDefaultToAL
728 xchg dx, ax
729
730.RetryDrive:
731 push dx ; Save the previous current drive to stack
732
[54]733 mov dl, [si+DRIVE_DIALOG_IO.bReturnDriveNumber]
734 call Drive_SetDefaultFromDL
[592]735
736 ; Now we must try to force a media access to catch "Drive Not Ready".
737 push ds
738 push ss
739 pop ds
740 ePUSH_T ax, CURRENTDIR_CHARACTERS
741 mov cx, FLG_FILEATTR_DIRECTORY
742 mov dx, sp
743 mov ax, FIND_FIRST_MATCHING_FILE<<8
744 int DOS_INTERRUPT_21h
745 pop ax
746 pop ds
747
748 pop dx ; Restore the previous current drive from stack
749
750 xchg ah, [cs:bLastCriticalError] ; Zero bLastCriticalError and fetch error code to AH
751 cmp ah, ERR_DOS_DRIVE_NOT_READY
752 jne SHORT .DriveIsReady
753
754 mov bx, g_szDlgDriveNotReady
755 call Dialogs_DisplayYesNoResponseDialogWithTitleStringInBX
756 jz SHORT .RetryDrive
757 ; The user cancelled the drive change. Restore current drive to what it was previously.
758 call Drive_SetDefaultFromDL
759 jmp DosCritical_RestoreDosHandler
760
761.DriveIsReady:
762 call DosCritical_RestoreDosHandler
[54]763 jmp RefreshFilesToDisplay
[41]764
765
766;--------------------------------------------------------------------
[54]767; DisplayLoadingMessageInInformationArea
[53]768; Parameters:
[54]769; SS:BP: Ptr to DIALOG
[53]770; Returns:
771; Nothing
772; Corrupts registers:
[54]773; AX, BX, CX, DX, SI, DI
[53]774;--------------------------------------------------------------------
775ALIGN JUMP_ALIGN
[54]776DisplayLoadingMessageInInformationArea:
777 call MenuText_ClearInformationArea
778 call MenuText_PrepareToDrawInformationArea
779 mov si, g_szLoadingPleaseWait
[505]780 JMP_DISPLAY_LIBRARY PrintNullTerminatedStringFromCSSI
[53]781
782
783;--------------------------------------------------------------------
[41]784; InitializeNullStringsToDialogInputInDSSI
785; Parameters:
786; DS:SI: Ptr to DIALOG_INPUT
787; SS:BP: Ptr to DIALOG
788; Returns:
789; Nothing
790; Corrupts registers:
791; AX
792;--------------------------------------------------------------------
793ALIGN JUMP_ALIGN
794InitializeNullStringsToDialogInputInDSSI:
795 mov ax, g_szNull
796 mov [si+DIALOG_INPUT.fszTitle], ax
797 mov [si+DIALOG_INPUT.fszTitle+2], cs
798 mov [si+DIALOG_INPUT.fszItems], ax
799 mov [si+DIALOG_INPUT.fszItems+2], cs
800 mov [si+DIALOG_INPUT.fszInfo], ax
801 mov [si+DIALOG_INPUT.fszInfo+2], cs
802 ret
Note: See TracBrowser for help on using the repository browser.