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

Last change on this file since 52 was 52, checked in by aitotat, 14 years ago

Changes to Assembly Library:
Completely rewritten line splitting (slower but no need to modify string).
Some changes to string processing functions.
Saved few bytes from CGA detection.

File size: 23.3 KB
Line 
1; File name     :   DialogFile.asm
2; Project name  :   Assembly Library
3; Created date  :   6.9.2010
4; Last update   :   12.10.2010
5; Author        :   Tomi Tilli
6; Description   :   Displays file dialog.
7
8
9CURRENTDIR_CHARACTERS   EQU     002Eh
10UPDIR_CHARACTERS        EQU     2E2Eh
11
12; Section containing code
13SECTION .text
14
15;--------------------------------------------------------------------
16; DialogFile_GetFileNameWithIoInDSSI
17;   Parameters:
18;       DS:SI:  Ptr to FILE_DIALOG_IO
19;       SS:BP:  Ptr to parent MENU
20;   Returns:
21;       Nothing
22;   Corrupts registers:
23;       AX, BX, CX, DX, SI, DI
24;--------------------------------------------------------------------
25ALIGN JUMP_ALIGN
26DialogFile_GetFileNameWithIoInDSSI:
27    mov     bx, FileEventHandler
28    mov     BYTE [si+FILE_DIALOG_IO.bUserCancellation], TRUE
29    jmp     Dialog_DisplayWithDialogInputInDSSIandHandlerInBX
30
31
32;--------------------------------------------------------------------
33; FileEventHandler
34;   Common parameters for all events:
35;       BX:         Menu event (anything from MENUEVENT struct)
36;       SS:BP:      Ptr to DIALOG
37;   Common return values for all events:
38;       CF:         Set if event processed
39;                   Cleared if event not processed
40;   Corrupts registers:
41;       All
42;--------------------------------------------------------------------
43ALIGN JUMP_ALIGN
44FileEventHandler:
45    jmp     [cs:bx+.rgfnEventHandlers]
46
47
48ALIGN JUMP_ALIGN
49.ItemSelectedFromCX:
50    call    LoadItemStringBufferToESDI
51    call    Memory_CopyESDItoDSSI
52    call    ItemLineSplitter_GetLineToDSSIandLengthToCXfromStringInDSSIwithIndexInCX
53    jmp     ParseSelectionFromItemLineInDSSI
54
55
56ALIGN JUMP_ALIGN
57.RefreshInformation:
58    call    GetInfoLinesToCXandDialogFlagsToAX
59    mov     si, [cs:.rgszInfoStringLookup]
60    xor     bx, bx
61    xchg    dx, ax
62ALIGN JUMP_ALIGN
63.InfoLineLoop:
64    shr     dl, 1
65    jnc     SHORT .CheckNextFlag
66    mov     si, [cs:bx+.rgszInfoStringLookup]
67    push    bx
68    CALL_DISPLAY_LIBRARY PrintNullTerminatedStringFromCSSI
69    pop     bx
70ALIGN JUMP_ALIGN
71.CheckNextFlag:
72    inc     bx
73    inc     bx
74    loop    .InfoLineLoop
75    stc                     ; Event processed
76    ret
77
78
79ALIGN WORD_ALIGN
80.rgszInfoStringLookup:
81    dw      g_szChangeDrive
82    dw      g_szSelectDirectory
83    dw      g_szCreateNew
84
85.rgfnEventHandlers:
86istruc MENUEVENT
87    at  MENUEVENT.InitializeMenuinitFromDSSI,   dw  InitializeMenuinitFromSSBP
88    at  MENUEVENT.ExitMenu,                     dw  Dialog_EventNotHandled
89    at  MENUEVENT.IdleProcessing,               dw  Dialog_EventNotHandled
90    at  MENUEVENT.ItemHighlightedFromCX,        dw  Dialog_EventNotHandled
91    at  MENUEVENT.ItemSelectedFromCX,           dw  .ItemSelectedFromCX
92    at  MENUEVENT.KeyStrokeInAX,                dw  HandleFunctionKeyFromAH
93    at  MENUEVENT.RefreshTitle,                 dw  Dialog_EventRefreshTitle
94    at  MENUEVENT.RefreshInformation,           dw  .RefreshInformation
95    at  MENUEVENT.RefreshItemFromCX,            dw  Dialog_EventRefreshItemFromCX
96iend
97
98
99;--------------------------------------------------------------------
100; InitializeMenuinitFromSSBP
101;   Parameters:
102;       DS:SI:      Ptr to MENUINIT to initialize (also points to DIALOG)
103;       SS:BP:      Ptr to DIALOG
104;   Returns:
105;       Nothing
106;   Corrupts registers:
107;       All, except BP
108;--------------------------------------------------------------------
109ALIGN JUMP_ALIGN
110InitializeMenuinitFromSSBP:
111    call    LoadItemStringBufferToESDI
112    call    CreateStringFromCurrentDirectoryContentsToESDI
113    call    LoadItemStringBufferToESDI
114    call    SortDirectoryContentsStringFromESDIwithCountInCX
115    call    Memory_CopySSBPtoDSSI
116    xor     ax, ax
117    call    Dialog_EventInitializeMenuinitFromDSSIwithHighlightedItemInAX
118    call    GetInfoLinesToCXandDialogFlagsToAX
119    mov     [bp+MENUINIT.bInfoLines], cl
120    CALL_DISPLAY_LIBRARY GetColumnsToALandRowsToAH
121    mov     [bp+MENUINIT.bHeight], ah               ; Always max height
122    mov     WORD [bp+MENU.wFirstVisibleItem], 0
123    ret
124
125
126;--------------------------------------------------------------------
127; LoadItemStringBufferToESDI
128;   Parameters:
129;       SS:BP:  Ptr to DIALOG
130;   Returns:
131;       ES:DI:  Ptr to item string buffer
132;   Corrupts registers:
133;       Nothing
134;--------------------------------------------------------------------
135ALIGN JUMP_ALIGN
136LoadItemStringBufferToESDI:
137    les     di, [bp+DIALOG.fpDialogIO]
138    les     di, [es:di+FILE_DIALOG_IO.fszItemBuffer]
139    ret
140
141
142;--------------------------------------------------------------------
143; CreateStringFromCurrentDirectoryContentsToESDI
144;   Parameters:
145;       ES:DI:  Buffer where to create item string
146;       SS:BP:  Ptr to DIALOG
147;   Returns:
148;       CX:     Number of files or directories found
149;   Corrupts registers:
150;       AX, DX, SI, DI, DS, ES
151;--------------------------------------------------------------------
152ALIGN JUMP_ALIGN
153CreateStringFromCurrentDirectoryContentsToESDI:
154    lds     si, [bp+DIALOG.fpDialogIO]
155    eMOVZX  cx, BYTE [si+FILE_DIALOG_IO.bFileAttributes]
156    lds     si, [si+FILE_DIALOG_IO.fpFileFilterString]
157    call    Directory_UpdateDTAForFirstMatchForDSSIwithAttributesInCX
158    rcr     cx, 1           ; Store CF
159    call    .ClearDLifInRootDirectory
160    call    Directory_GetDiskTransferAreaAddressToDSSI
161    rcl     cx, 1           ; Restore CF
162    xor     cx, cx          ; Clear file/directory count
163    ; Fall to .FindMatchingFilesAndWriteThemToESDI
164
165;--------------------------------------------------------------------
166; .FindMatchingFilesAndWriteThemToESDI
167;   Parameters:
168;       CX:     Initial directory count
169;       DL:     Zero if root directory selected
170;       DS:SI:  Ptr to DTA with first matching file
171;       ES:DI:  Ptr to destination string buffer
172;   Returns:
173;       CX:     Incremented by number of files/directories found
174;   Corrupts registers:
175;       AX, DX, DI
176;--------------------------------------------------------------------
177;ALIGN JUMP_ALIGN
178.FindMatchingFilesAndWriteThemToESDI:
179    jc      SHORT TerminateESDIwithNull
180    call    AppendFileToBufferInESDIfromDtaInDSSI
181    call    Directory_UpdateDTAForNextMatchUsingPreviousParameters
182    jmp     SHORT .FindMatchingFilesAndWriteThemToESDI
183
184;--------------------------------------------------------------------
185; .ClearDLifInRootDirectory
186;   Parameters:
187;       SS:BP:  Ptr to DIALOG
188;       ES:DI:  Ptr to destination string buffer
189;   Returns:
190;       DL:     Cleared if in root directory
191;               Set if in any other directory
192;   Corrupts registers:
193;       AX, SI, DS
194;--------------------------------------------------------------------
195ALIGN JUMP_ALIGN
196.ClearDLifInRootDirectory:
197    call    Memory_CopyESDItoDSSI
198    call    Directory_WriteCurrentPathToDSSI
199    mov     dl, [si]
200    ret
201
202
203;--------------------------------------------------------------------
204; TerminateESDIwithNull
205;   Parameters:
206;       ES:DI:  Ptr to destination string buffer
207;   Returns:
208;       Nothing
209;   Corrupts registers:
210;       AX
211;--------------------------------------------------------------------
212ALIGN JUMP_ALIGN
213TerminateESDIwithNull:
214    xor     ax, ax
215    stosb
216    ret
217
218
219;--------------------------------------------------------------------
220; AppendFileToBufferInESDIfromDtaInDSSI
221;   Parameters:
222;       CX:     Files/directores found
223;       DL:     Zero if root directory selected
224;       DS:SI:  Ptr to DTA containing file information
225;       ES:DI:  Ptr to destination string buffer
226;   Returns:
227;       CX:     Incremented by number of files/directories found
228;       DI:     Updated for next file
229;   Corrupts registers:
230;       AX, BX, DX
231;--------------------------------------------------------------------
232ALIGN JUMP_ALIGN
233AppendFileToBufferInESDIfromDtaInDSSI:
234    call    .FilterCurrentDirectory         ; We never want "."
235    call    .FilterUpDirectoryWhenInRoot    ; No ".." when in root directory
236    inc     cx                              ; Nothing filtered so increment files/directories
237    ; Fall to .PrepareBufferFormattingAndFormatFromDTAinDSSI
238
239;--------------------------------------------------------------------
240; .PrepareBufferFormattingAndFormatFromDTAinDSSI
241;   Parameters:
242;       DS:SI:  Ptr to DTA containing file information
243;       ES:DI:  Ptr to destination string buffer
244;   Returns:
245;       DI:     Updated for next file
246;   Corrupts registers:
247;       AX, BX, DX
248;--------------------------------------------------------------------
249;ALIGN JUMP_ALIGN
250.PrepareBufferFormattingAndFormatFromDTAinDSSI:
251    push    bp
252    push    si
253    push    cx
254    mov     bx, di
255    CALL_DISPLAY_LIBRARY PushDisplayContext
256    mov     cx, -1
257    CALL_DISPLAY_LIBRARY PrepareOffScreenBufferInESBXwithLengthInCX
258
259    call    .FormatFileOrDirectoryToBufferFromDTAinDSSI
260
261    CALL_DISPLAY_LIBRARY GetCharacterPointerToBXAX
262    xchg    bx, ax
263    CALL_DISPLAY_LIBRARY PopDisplayContext
264    mov     di, bx
265    pop     cx
266    pop     si
267    pop     bp
268    ret
269
270;--------------------------------------------------------------------
271; .FormatFileOrDirectoryToBufferFromDTAinDSSI
272;   Parameters:
273;       DS:SI:  Ptr to DTA containing file information
274;   Returns:
275;       Nothing
276;   Corrupts registers:
277;       AX, BX, CX, DX, SI, DI, BP
278;--------------------------------------------------------------------
279ALIGN JUMP_ALIGN
280.FormatFileOrDirectoryToBufferFromDTAinDSSI:
281    mov     bp, sp
282    lea     ax, [si+DTA.szFile]
283
284    test    BYTE [si+DTA.bFileAttributes], FLG_FILEATTR_DIRECTORY
285    jnz     SHORT .FormatDirectory
286    ; Fall to .FormatFile
287
288;--------------------------------------------------------------------
289; .FormatFile
290;   Parameters:
291;       BP:     SP before pushing formatting parameters
292;       DS:AX:  Far pointer to file name
293;       DS:SI:  Ptr to DTA containing file information
294;   Returns:
295;       Nothing
296;   Corrupts registers:
297;       AX, BX, CX, DX, SI, DI, BP
298;--------------------------------------------------------------------
299.FormatFile:
300    ; Convert file name to lower case
301    xchg    si, ax
302    mov     dx, StringProcess_ConvertToLowerCase
303    call    StringProcess_DSSIwithFunctionInDX
304    xchg    ax, si
305
306    ; Push parameters for file name
307    push    ax              ; Push directory name offset
308    push    ds              ; Push directory 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, BX, CX, DX, SI, DI, BP
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    CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
350    ret
351
352;--------------------------------------------------------------------
353; .FilterCurrentDirectory
354; .FilterUpDirectoryWhenInRoot
355;   Parameters:
356;       DL:     Zero if root directory selected
357;       DS:SI:  Ptr to DTA containing file information
358;   Returns:
359;       Nothing
360;       Returns from AppendFileToBufferInESDIfromDtaInDSSI when filtering
361;   Corrupts registers:
362;       AX
363;--------------------------------------------------------------------
364ALIGN JUMP_ALIGN
365.FilterCurrentDirectory:
366    cmp     WORD [si+DTA.szFile], CURRENTDIR_CHARACTERS
367    jne     SHORT .ReturnWithoutFiltering
368    add     sp, BYTE 2      ; Remove return address from stack
369    ret
370
371ALIGN JUMP_ALIGN
372.FilterUpDirectoryWhenInRoot:
373    test    dl, dl          ; Set ZF if root directory selected
374    jnz     SHORT .ReturnWithoutFiltering
375    cmp     WORD [si+DTA.szFile], UPDIR_CHARACTERS
376    jne     SHORT .ReturnWithoutFiltering
377    add     sp, BYTE 2      ; Remove return address from stack
378ALIGN JUMP_ALIGN, ret
379.ReturnWithoutFiltering:
380    ret
381
382
383;--------------------------------------------------------------------
384; SortDirectoryContentsStringFromESDIwithCountInCX
385;   Parameters:
386;       CX:     Number of files and directories
387;       ES:DI:  Buffer containing directory contents string
388;       SS:BP:  Ptr to DIALOG
389;   Returns:
390;       Nothing
391;   Corrupts registers:
392;       AX, BX, CX, DX, SI, DI, DS, ES
393;--------------------------------------------------------------------
394ALIGN JUMP_ALIGN
395SortDirectoryContentsStringFromESDIwithCountInCX:
396    call    Memory_ExchangeDSSIwithESDI
397    mov     bx, .FileStringComparator
398    xchg    dx, cx
399    mov     cx, FILE_STRING_LENGTH
400    jmp     Sort_ItemsFromDSSIwithCountInDXsizeInCXandComparatorInBX
401
402;--------------------------------------------------------------------
403; .FileStringComparator
404;   Parameters:
405;       CX:     Item size in bytes
406;       DS:SI:  Ptr to first item to compare
407;       ES:DI:  Ptr to second item to compare
408;   Returns:
409;       FLAGS:  Signed comparition between first and second item
410;   Corrupts registers:
411;       Nothing
412;--------------------------------------------------------------------
413ALIGN JUMP_ALIGN
414.FileStringComparator:
415    push    di
416    push    si
417    push    cx
418    push    bx
419
420    mov     bx, FILE_STRING_LENGTH-2            ; Zero BH
421    cmp     WORD [si], UPDIR_CHARACTERS
422    je      SHORT .ForceValueFromDSSItoBeLess
423    mov     bl, [si+bx]
424    cmp     bl, [es:di+FILE_STRING_LENGTH-2]    ; 'B' for files, 'R' for directories
425    jne     SHORT .ForceValueFromDSSItoBeMoreOrLess
426    repe cmpsb                                  ; Two directories or two files
427
428ALIGN JUMP_ALIGN
429.ReturnFromComparison:
430    pop     bx
431    pop     cx
432    pop     si
433    pop     di
434    ret
435ALIGN JUMP_ALIGN
436.ForceValueFromDSSItoBeMoreOrLess:
437    ja      SHORT .ForceValueFromDSSItoBeLess   ; Directory in SI, file in DI
438    xchg    bl, bh
439    ; Fall to ForceValueFromDSSItoBeLess
440ALIGN JUMP_ALIGN
441.ForceValueFromDSSItoBeLess:
442    cmp     bh, bl
443    jmp     SHORT .ReturnFromComparison
444
445
446;--------------------------------------------------------------------
447; GetInfoLinesToCXandDialogFlagsToAX
448;   Parameters:
449;       SS:BP:  Ptr to DIALOG
450;   Returns:
451;       AX:     Dialog flags
452;       CX:     Number of info lines to be displayed
453;   Corrupts registers:
454;       SI, DS
455;--------------------------------------------------------------------
456ALIGN JUMP_ALIGN
457GetInfoLinesToCXandDialogFlagsToAX:
458    xor     ax, ax
459    call    GetDialogFlagsToAL
460    jmp     Bit_GetSetCountToCXfromAX
461
462;--------------------------------------------------------------------
463; GetDialogFlagsToAL
464;   Parameters:
465;       SS:BP:  Ptr to DIALOG
466;   Returns:
467;       AL:     Dialog flags
468;   Corrupts registers:
469;       SI, DS
470;--------------------------------------------------------------------
471ALIGN JUMP_ALIGN
472GetDialogFlagsToAL:
473    lds     si, [bp+DIALOG.fpDialogIO]
474    mov     al, [si+FILE_DIALOG_IO.bDialogFlags]
475    ret
476
477
478;--------------------------------------------------------------------
479; ParseSelectionFromItemLineInDSSI
480;   Parameters:
481;       DS:SI:  Ptr to char buffer containing file or directory to be selected
482;       SS:BP:  Ptr to DIALOG
483;   Returns:
484;       Nothing
485;   Corrupts registers:
486;       All, except BP
487;--------------------------------------------------------------------
488ALIGN JUMP_ALIGN
489ParseSelectionFromItemLineInDSSI:
490    mov     ax, [si]
491    cmp     ax, UPDIR_CHARACTERS
492    je      SHORT .ChangeToUpdir
493    call    Char_IsUpperCaseLetterInAL
494    jc      SHORT .ParseAndChangeToSubdirInDSSI
495    ; Fall to .ParseAndSelectFileFromDSSI
496
497;--------------------------------------------------------------------
498; .ParseAndSelectFileFromDSSI
499;   Parameters:
500;       DS:SI:  NULL terminated string selected from dialog
501;       SS:BP:  Ptr to DIALOG
502;   Returns:
503;       Nothing (exits dialog)
504;   Corrupts registers:
505;       All, except BP
506;--------------------------------------------------------------------
507.ParseAndSelectFileFromDSSI:
508    les     di, [bp+DIALOG.fpDialogIO]
509    add     di, BYTE FILE_DIALOG_IO.szFile
510    mov     cx, FILENAME_BUFFER_SIZE-1
511    call    Memory_CopyCXbytesFromDSSItoESDI
512    xor     ax, ax
513    stosb                       ; Terminate with NULL
514    jmp     SHORT CloseFileDialogAfterSuccessfullSelection
515
516;--------------------------------------------------------------------
517; .ChangeToUpdir
518;   Parameters:
519;       SS:BP:  Ptr to DIALOG
520;   Returns:
521;       Nothing
522;   Corrupts registers:
523;       All, except BP
524;--------------------------------------------------------------------
525ALIGN JUMP_ALIGN
526.ChangeToUpdir:
527    push    cs
528    pop     ds
529    mov     si, g_szUpdir
530    jmp     SHORT .ChangeDirectoryToDSSI
531
532;--------------------------------------------------------------------
533; .ParseAndChangeToSubdirInDSSI
534;   Parameters:
535;       DS:SI:  NULL terminated string selected from dialog
536;       SS:BP:  Ptr to DIALOG
537;   Returns:
538;       Nothing
539;   Corrupts registers:
540;       All, except BP
541;--------------------------------------------------------------------
542ALIGN JUMP_ALIGN
543.ParseAndChangeToSubdirInDSSI:
544    mov     BYTE [si+12], NULL  ; Terminate with NULL (unnecessary spaces do not matter)
545.ChangeDirectoryToDSSI:
546    call    Directory_ChangeToPathFromDSSI
547    ; Fall to RefreshFilesToDisplay
548
549;--------------------------------------------------------------------
550; RefreshFilesToDisplay
551;   Parameters:
552;       SS:BP:  Ptr to DIALOG
553;   Returns:
554;       Nothing
555;   Corrupts registers:
556;       All, except BP
557;--------------------------------------------------------------------
558ALIGN JUMP_ALIGN
559RefreshFilesToDisplay:
560    call    InitializeMenuinitFromSSBP
561    jmp     MenuInit_RefreshMenuWindow
562
563
564;--------------------------------------------------------------------
565; HandleFunctionKeyFromAH
566;   Parameters:
567;       AH:     Scancode for function key
568;       SS:BP:  Ptr to DIALOG
569;   Returns:
570;       Nothing
571;   Corrupts registers:
572;       AX, SI, DI, BP
573;--------------------------------------------------------------------
574ALIGN JUMP_ALIGN
575HandleFunctionKeyFromAH:
576    call    GetDialogFlagsToAL
577    cmp     ah, KEY_FILEDIALOG_NEW_FILE_OR_DIR
578    je      SHORT HandleFunctionKeyForCreatingNewFileOrDirectory
579    cmp     ah, KEY_FILEDIALOG_SELECT_DIRECTORY
580    je      SHORT HandleFunctionKeyForSelectingDirectoryInsteadOfFile
581    cmp     ah, KEY_FILEDIALOG_CHANGE_DRIVE
582    je      SHORT HandleFunctionKeyForDriveChange
583ReturnWithoutHandlingKeystroke:
584    clc     ; Event not processed
585    ret
586
587
588;--------------------------------------------------------------------
589; HandleFunctionKeyForCreatingNewFileOrDirectory
590;   Parameters:
591;       AL:     File dialog flags
592;       SS:BP:  Ptr to DIALOG
593;   Returns:
594;       Closes file dialog
595;   Corrupts registers:
596;       All, except BP
597;--------------------------------------------------------------------
598ALIGN JUMP_ALIGN
599HandleFunctionKeyForCreatingNewFileOrDirectory:
600    test    al, FLG_FILEDIALOG_NEW
601    jz      SHORT ReturnWithoutHandlingKeystroke
602
603    mov     cx, STRING_DIALOG_IO_size
604    call    Memory_ReserveCXbytesFromStackToDSSI
605    call    .InitializeStringDialogIoInDSSIforInputtingFileName
606
607    CALL_MENU_LIBRARY GetStringWithIoInDSSI
608    mov     al, [si+STRING_DIALOG_IO.bUserCancellation]
609    add     sp, BYTE STRING_DIALOG_IO_size
610    test    al, al      ; User cancellation?
611    jnz     SHORT ReturnWithoutHandlingKeystroke
612    jmp     CloseFileDialogAfterSuccessfullSelection
613
614ALIGN JUMP_ALIGN
615.InitializeStringDialogIoInDSSIforInputtingFileName:
616    call    InitializeNullStringsToDialogInputInDSSI
617    mov     WORD [si+DIALOG_INPUT.fszTitle], g_szEnterNewFileOrDirectory
618    mov     WORD [si+STRING_DIALOG_IO.fnCharFilter], NULL
619    mov     WORD [si+STRING_DIALOG_IO.wBufferSize], FILENAME_BUFFER_SIZE
620    les     ax, [bp+DIALOG.fpDialogIO]
621    add     ax, BYTE FILE_DIALOG_IO.szFile
622    mov     [si+STRING_DIALOG_IO.fpReturnBuffer], ax
623    mov     [si+STRING_DIALOG_IO.fpReturnBuffer+2], es
624    ret
625
626
627;--------------------------------------------------------------------
628; HandleFunctionKeyForSelectingDirectoryInsteadOfFile
629;   Parameters:
630;       AL:     File dialog flags
631;       SS:BP:  Ptr to DIALOG
632;   Returns:
633;       Closes file dialog
634;   Corrupts registers:
635;       All, except BP
636;--------------------------------------------------------------------
637ALIGN JUMP_ALIGN
638HandleFunctionKeyForSelectingDirectoryInsteadOfFile:
639    test    al, FLG_FILEDIALOG_DIRECTORY
640    jz      SHORT ReturnWithoutHandlingKeystroke
641    ; Fall to CloseFileDialogAfterSuccessfullSelection
642
643;--------------------------------------------------------------------
644; CloseFileDialogAfterSuccessfullSelection
645;   Parameters:
646;       SS:BP:  Ptr to DIALOG
647;   Returns:
648;       Nothing (exits dialog)
649;   Corrupts registers:
650;       All, except BP
651;--------------------------------------------------------------------
652ALIGN JUMP_ALIGN
653CloseFileDialogAfterSuccessfullSelection:
654    lds     di, [bp+DIALOG.fpDialogIO]
655    mov     BYTE [di+FILE_DIALOG_IO.bUserCancellation], FALSE
656    jmp     MenuInit_CloseMenuWindow
657
658
659;--------------------------------------------------------------------
660; HandleFunctionKeyForDriveChange
661;   Parameters:
662;       AL:     File dialog flags
663;       SS:BP:  Ptr to DIALOG
664;   Returns:
665;       Nothing
666;   Corrupts registers:
667;       All, except BP
668;--------------------------------------------------------------------
669ALIGN JUMP_ALIGN
670HandleFunctionKeyForDriveChange:
671    test    al, FLG_FILEDIALOG_DRIVES
672    jz      SHORT ReturnWithoutHandlingKeystroke
673
674    call    .ShowDriveSelectionDialogAndGetDriveNumberToDL
675    jnc     SHORT RefreshFilesToDisplay
676    call    Drive_SetDefaultFromDL
677    jmp     SHORT RefreshFilesToDisplay
678
679;--------------------------------------------------------------------
680; .ShowDriveSelectionDialogAndGetDriveNumberToDL
681;   Parameters:
682;       SS:BP:  Ptr to DIALOG
683;   Returns:
684;       DL:     Drive selected by user
685;       CF:     Set if new drive selected
686;               Cleared if selection cancelled by user
687;   Corrupts registers:
688;       All, except BP
689;--------------------------------------------------------------------
690ALIGN JUMP_ALIGN
691.ShowDriveSelectionDialogAndGetDriveNumberToDL:
692    mov     cx, DIALOG_INPUT_size
693    call    Memory_ReserveCXbytesFromStackToDSSI
694    call    .InitializeDialogInputInDSSIforDriveSelection
695    call    DialogSelection_GetSelectionToAXwithInputInDSSI
696    add     sp, BYTE DIALOG_INPUT_size
697    cmp     ax, BYTE NO_ITEM_SELECTED   ; Clear CF if equal
698    jne     SHORT .ConvertDriveNumberToDLfromItemIndexInAX
699    ret
700
701ALIGN JUMP_ALIGN
702.InitializeDialogInputInDSSIforDriveSelection:
703    call    InitializeNullStringsToDialogInputInDSSI
704    call    LoadItemStringBufferToESDI
705    mov     WORD [si+DIALOG_INPUT.fszTitle], g_szSelectNewDrive
706    mov     [si+DIALOG_INPUT.fszItems], di
707    mov     [si+DIALOG_INPUT.fszItems+2], es
708    call    Drive_GetFlagsForAvailableDrivesToDXAX
709    ; Fall to .GenerateDriveSelectionStringToESDIfromDriveFlagsInDXAX
710
711;--------------------------------------------------------------------
712; .GenerateDriveSelectionStringToESDIfromDriveFlagsInDXAX
713;   Parameters:
714;       DX:AX:  Drive letter flags
715;       ES:DI:  Ptr to item string buffer
716;       SS:BP:  Ptr to DIALOG
717;   Returns:
718;       Nothing
719;   Corrupts registers:
720;       AX, BX, CX, DX, DI, ES
721;--------------------------------------------------------------------
722;ALIGN JUMP_ALIGN
723.GenerateDriveSelectionStringToESDIfromDriveFlagsInDXAX:
724    cld
725    xchg    cx, ax
726    mov     ax, 3A41h       ; A:
727ALIGN JUMP_ALIGN
728.BitShiftLoop:
729    shr     dx, 1
730    rcr     cx, 1
731    jnc     SHORT .CheckIfMoreDrivesLeft
732    stosw
733    mov     BYTE [es:di], LF
734    inc     di
735ALIGN JUMP_ALIGN
736.CheckIfMoreDrivesLeft:
737    inc     ax              ; Next drive letter
738    mov     bx, dx
739    or      bx, cx
740    jnz     SHORT .BitShiftLoop
741    jmp     TerminateESDIwithNull
742
743;--------------------------------------------------------------------
744; .ConvertDriveNumberToDLfromItemIndexInAX
745;   Parameters:
746;       AX:     Selected drive item 
747;   Returns:
748;       DL:     Drive number
749;       CF:     Set since drive selected
750;   Corrupts registers:
751;       AX, CX, DH
752;--------------------------------------------------------------------
753ALIGN JUMP_ALIGN
754.ConvertDriveNumberToDLfromItemIndexInAX:
755    mov     ah, -1
756    xchg    cx, ax
757    call    Drive_GetFlagsForAvailableDrivesToDXAX
758ALIGN JUMP_ALIGN
759.BitScanLoop:
760    shr     dx, 1
761    rcr     ax, 1
762    inc     ch              ; Increment drive number
763    sbb     cl, 0           ; Decrement selection index
764    jnc     SHORT .BitScanLoop
765    mov     dl, ch
766    stc                     ; Drive selected by user
767    ret
768
769
770;--------------------------------------------------------------------
771; InitializeNullStringsToDialogInputInDSSI
772;   Parameters:
773;       DS:SI:  Ptr to DIALOG_INPUT
774;       SS:BP:  Ptr to DIALOG
775;   Returns:
776;       Nothing
777;   Corrupts registers:
778;       AX
779;--------------------------------------------------------------------
780ALIGN JUMP_ALIGN
781InitializeNullStringsToDialogInputInDSSI:
782    mov     ax, g_szNull
783    mov     [si+DIALOG_INPUT.fszTitle], ax
784    mov     [si+DIALOG_INPUT.fszTitle+2], cs
785    mov     [si+DIALOG_INPUT.fszItems], ax
786    mov     [si+DIALOG_INPUT.fszItems+2], cs
787    mov     [si+DIALOG_INPUT.fszInfo], ax
788    mov     [si+DIALOG_INPUT.fszInfo+2], cs
789    ret
Note: See TracBrowser for help on using the repository browser.