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

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

Changes to Assembly Library:
File Dialog is now compatible with new line splitting.

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