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

Last change on this file since 49 was 48, checked in by Tomi Tilli, 14 years ago

Changes to Assembly Library:
Added functions to clear Menu Title and Information areas.
Implemented automatic line change when writing Menu Title and Information areas.
CGA snow related functions have been moved to CgaSnow.asm.
Keyboard input functions no longer produce beep for backspace.

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