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

Last change on this file since 592 was 592, checked in by krille_n_, 6 years ago

Changes:

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