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

Last change on this file since 595 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
Line 
1; Project name : Assembly Library
2; Description : Displays file dialog.
3
4;
5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
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.
12;
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
16; GNU General Public License for more details.
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
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:
34; AX, BX, CX, DX, DI
35;--------------------------------------------------------------------
36ALIGN JUMP_ALIGN
37DialogFile_GetFileNameWithIoInDSSI:
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
44 mov bx, FileEventHandler
45 mov BYTE [si+FILE_DIALOG_IO.bUserCancellation], TRUE
46 call Dialog_DisplayWithDialogInputInDSSIandHandlerInBX
47
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
53
54
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
74 call Registers_CopyESDItoDSSI
75 call ItemLineSplitter_GetLineToDSSIandLengthToCXfromStringInDSSIwithIndexInCX
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
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
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
126 at MENUEVENT.ExitMenu, dw Dialog_EventExitMenu
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
133 at MENUEVENT.RefreshItemFromCX, dw .RefreshItemFromCX
134iend
135
136
137;--------------------------------------------------------------------
138; ReInitializeMenuinitFromSSBP
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
148ReInitializeMenuinitFromSSBP:
149 call DisplayLoadingMessageInInformationArea
150InitializeMenuinitFromSSBP:
151 call LoadItemStringBufferToESDI
152 call CreateStringFromCurrentDirectoryContentsToESDI
153 call LoadItemStringBufferToESDI
154 call SortDirectoryContentsStringFromESDIwithCountInCX
155 call RemoveLastLFandTerminateESDIwithNull
156
157 call Registers_CopySSBPtoDSSI
158 xor ax, ax
159 call Dialog_EventInitializeMenuinitFromDSSIwithHighlightedItemInAX
160 call GetInfoLinesToCXandDialogFlagsToAX
161 mov [bp+MENUINIT.bInfoLines], cl
162 CALL_DISPLAY_LIBRARY GetColumnsToALandRowsToAH
163 mov [bp+MENUINIT.bHeight], ah ; Always max height
164 mov WORD [bp+MENU.wFirstVisibleItem], 0
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:
190; CX: Number of files or directories found
191; Corrupts registers:
192; AX, BX, DX, SI, DI, DS
193;--------------------------------------------------------------------
194ALIGN JUMP_ALIGN
195CreateStringFromCurrentDirectoryContentsToESDI:
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
201 lds si, [bp+DIALOG.fpDialogIO]
202 eMOVZX cx, [si+FILE_DIALOG_IO.bFileAttributes]
203 lds si, [si+FILE_DIALOG_IO.fpFileFilterString]
204 call Directory_UpdateDTAForFirstMatchForDSSIwithAttributesInCX
205
206 call .ClearDLifInRootDirectory
207 call Directory_GetDiskTransferAreaAddressToDSSI
208 xor cx, cx ; Clear file/directory count
209 call .FindMatchingFilesAndPrintThemToOffScreenBuffer
210
211 JMP_DISPLAY_LIBRARY PopDisplayContext
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:
226 call Registers_CopyESDItoDSSI
227 call Directory_WriteCurrentPathToDSSI
228 mov dl, [si]
229 ret
230
231;--------------------------------------------------------------------
232; .FindMatchingFilesAndPrintThemToOffScreenBuffer
233; Parameters:
234; CX: Initial directory count
235; DL: Zero if root directory selected
236; DS:SI: Ptr to DTA with first matching file
237; Returns:
238; CX: Incremented by number of files/directories found
239; Corrupts registers:
240; AX, BX, DX, DI, DS
241;--------------------------------------------------------------------
242ALIGN JUMP_ALIGN
243.FindMatchingFilesAndPrintThemToOffScreenBuffer:
244 call AppendFileFromDTAinDSSItoOffScreenBuffer
245 call Directory_UpdateDTAForNextMatchUsingPreviousParameters
246 jnc SHORT .FindMatchingFilesAndPrintThemToOffScreenBuffer
247 ret
248
249
250;--------------------------------------------------------------------
251; AppendFileFromDTAinDSSItoOffScreenBuffer
252; Parameters:
253; CX: Files/directories found
254; DL: Zero if root directory selected
255; DS:SI: Ptr to DTA containing file information
256; Returns:
257; CX: Incremented by number of files/directories found
258; Corrupts registers:
259; AX, BX
260;--------------------------------------------------------------------
261ALIGN JUMP_ALIGN
262AppendFileFromDTAinDSSItoOffScreenBuffer:
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:
270 inc cx ; Nothing filtered so increment files/directories
271
272 push bp
273 push si
274 push dx
275 push cx
276 call .FormatFileOrDirectoryToBufferFromDTAinDSSI
277 pop cx
278 pop dx
279 pop si
280 pop bp
281.Return:
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
300 ; Fall to .FormatFile
301
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:
311; AX, BX, CX, DX, SI, DI
312;--------------------------------------------------------------------
313.FormatFile:
314 xchg si, ax
315 call String_ConvertDSSItoLowerCase
316 xchg ax, si
317
318 ; Push parameters for file name
319 push ax ; Push file name offset
320 push ds ; Push file name segment
321
322 ; Push parameters for file size
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
334
335 ; Format to buffer
336 mov si, g_szFileFormat
337 jmp SHORT .FormatStringInCSSIandReturn
338
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:
348; AX, SI, DI
349;--------------------------------------------------------------------
350ALIGN JUMP_ALIGN
351.FormatDirectory:
352 push ax ; Push directory name offset
353 push ds ; Push directory name segment
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:
361 JMP_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
362
363
364;--------------------------------------------------------------------
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:
371; ES:DI: Ptr to end of directory contents string
372; Corrupts registers:
373; AX, BX, CX, DX, SI, DS
374;--------------------------------------------------------------------
375ALIGN JUMP_ALIGN
376SortDirectoryContentsStringFromESDIwithCountInCX:
377 call Registers_CopyESDItoDSSI
378
379 ; Add directory contents string length to DI
380 mov ax, FILE_STRING_LENGTH
381 push ax
382 mul cx
383 add di, ax
384
385 mov dx, cx
386 pop cx
387 mov bx, .FileStringComparator
388 jmp Sort_ItemsFromDSSIwithCountInDXsizeInCXandComparatorInBX
389
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:
397; FLAGS: Signed comparison between first and second item
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;--------------------------------------------------------------------
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;--------------------------------------------------------------------
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:
463 ePUSH_T ax, Bit_GetSetCountToCXfromAX
464 xor ah, ah
465 ; Fall to GetDialogFlagsToAL
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:
495 mov ax, [si]
496 cmp ax, UPDIR_CHARACTERS
497 je SHORT .ChangeToUpdir
498 call Char_IsUpperCaseLetterInAL
499 jc SHORT .ParseAndChangeToSubdirInDSSI
500 call Char_IsDecimalDigitInAL
501 jc SHORT .ParseAndChangeToSubdirInDSSI ; Assume subdir and check for errors
502 ; Fall to .ParseAndSelectFileFromDSSI
503
504;--------------------------------------------------------------------
505; .ParseAndSelectFileFromDSSI
506; Parameters:
507; DS:SI: NULL terminated string selected from dialog
508; SS:BP: Ptr to DIALOG
509; Returns:
510; Nothing (exits dialog)
511; Corrupts registers:
512; All, except BP
513;--------------------------------------------------------------------
514.ParseAndSelectFileFromDSSI:
515 les di, [bp+DIALOG.fpDialogIO]
516 add di, BYTE FILE_DIALOG_IO.szFile
517 mov cx, FILENAME_BUFFER_SIZE-1
518 call Memory_CopyCXbytesFromDSSItoESDI
519 xor ax, ax
520 stosb ; Terminate with NULL
521 jmp SHORT CloseFileDialogAfterSuccessfulSelection
522
523;--------------------------------------------------------------------
524; .ChangeToUpdir
525; Parameters:
526; SS:BP: Ptr to DIALOG
527; Returns:
528; Nothing
529; Corrupts registers:
530; All, except BP
531;--------------------------------------------------------------------
532ALIGN JUMP_ALIGN
533.ChangeToUpdir:
534 push cs
535 pop ds
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:
553 call Directory_ChangeToPathFromDSSI
554 jc SHORT .ParseAndSelectFileFromDSSI ; Must have been a file starting with number
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:
568 call ReInitializeMenuinitFromSSBP
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
614;;; InitializeStringDialogIoInDSSIforInputtingFileName
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
623;;;
624
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
631
632
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
647 ; Fall to CloseFileDialogAfterSuccessfulSelection
648
649;--------------------------------------------------------------------
650; CloseFileDialogAfterSuccessfulSelection
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
659CloseFileDialogAfterSuccessfulSelection:
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
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
686.UserCancelledDriveChange:
687 ret
688
689;--------------------------------------------------------------------
690; .DisplayDriveSelectionDialogWithIoInDSSI
691; Parameters:
692; DS:SI: Ptr to uninitialized DRIVE_DIALOG_IO
693; SS:BP: Ptr to DIALOG
694; Returns:
695; DS:SI: Ptr to DRIVE_DIALOG_IO
696; Corrupts registers:
697; AX, DI
698;--------------------------------------------------------------------
699ALIGN JUMP_ALIGN
700.DisplayDriveSelectionDialogWithIoInDSSI:
701 call InitializeNullStringsToDialogInputInDSSI
702 mov WORD [si+DIALOG_INPUT.fszTitle], g_szSelectNewDrive
703 JMP_MENU_LIBRARY GetDriveWithIoInDSSI
704
705;--------------------------------------------------------------------
706; .ChangeDriveToUserSelectionFromIoInDSSI
707; Parameters:
708; DS:SI: Ptr to DRIVE_DIALOG_IO
709; SS:BP: Ptr to DIALOG
710; Returns:
711; Nothing
712; Corrupts registers:
713; All, except BP
714;--------------------------------------------------------------------
715ALIGN JUMP_ALIGN
716.ChangeDriveToUserSelectionFromIoInDSSI:
717 cmp BYTE [si+DRIVE_DIALOG_IO.bUserCancellation], FALSE
718 jne SHORT .UserCancelledDriveChange
719
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
733 mov dl, [si+DRIVE_DIALOG_IO.bReturnDriveNumber]
734 call Drive_SetDefaultFromDL
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
763 jmp RefreshFilesToDisplay
764
765
766;--------------------------------------------------------------------
767; DisplayLoadingMessageInInformationArea
768; Parameters:
769; SS:BP: Ptr to DIALOG
770; Returns:
771; Nothing
772; Corrupts registers:
773; AX, BX, CX, DX, SI, DI
774;--------------------------------------------------------------------
775ALIGN JUMP_ALIGN
776DisplayLoadingMessageInInformationArea:
777 call MenuText_ClearInformationArea
778 call MenuText_PrepareToDrawInformationArea
779 mov si, g_szLoadingPleaseWait
780 JMP_DISPLAY_LIBRARY PrintNullTerminatedStringFromCSSI
781
782
783;--------------------------------------------------------------------
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.