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

Last change on this file was 625, checked in by krille_n_, 14 months ago

Changes:

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