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

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

Changes to Assembly Library:
File handle is now properly returned when opening file.
Added function for getting file size by using file handle.

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