[41] | 1 | ; Project name : Assembly Library |
---|
| 2 | ; Description : Displays file dialog. |
---|
| 3 | |
---|
[376] | 4 | ; |
---|
[505] | 5 | ; XTIDE Universal BIOS and Associated Tools |
---|
[625] | 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2023 by XTIDE Universal BIOS Team. |
---|
[376] | 7 | ; |
---|
| 8 | ; This program is free software; you can redistribute it and/or modify |
---|
| 9 | ; it under the terms of the GNU General Public License as published by |
---|
| 10 | ; the Free Software Foundation; either version 2 of the License, or |
---|
| 11 | ; (at your option) any later version. |
---|
[505] | 12 | ; |
---|
[376] | 13 | ; This program is distributed in the hope that it will be useful, |
---|
| 14 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
[505] | 16 | ; GNU General Public License for more details. |
---|
[376] | 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 18 | ; |
---|
[41] | 19 | |
---|
| 20 | CURRENTDIR_CHARACTERS EQU 002Eh |
---|
| 21 | UPDIR_CHARACTERS EQU 2E2Eh |
---|
| 22 | |
---|
| 23 | ; Section containing code |
---|
| 24 | SECTION .text |
---|
| 25 | |
---|
| 26 | ;-------------------------------------------------------------------- |
---|
| 27 | ; DialogFile_GetFileNameWithIoInDSSI |
---|
| 28 | ; Parameters: |
---|
| 29 | ; DS:SI: Ptr to FILE_DIALOG_IO |
---|
| 30 | ; SS:BP: Ptr to parent MENU |
---|
| 31 | ; Returns: |
---|
| 32 | ; Nothing |
---|
| 33 | ; Corrupts registers: |
---|
[593] | 34 | ; AX, BX, CX, DX, DI |
---|
[41] | 35 | ;-------------------------------------------------------------------- |
---|
| 36 | ALIGN JUMP_ALIGN |
---|
| 37 | DialogFile_GetFileNameWithIoInDSSI: |
---|
[593] | 38 | ; We need to store default drive because user might change drive but |
---|
| 39 | ; then cancel the file selection. In that case the original default directory |
---|
| 40 | ; must be restored. |
---|
| 41 | call Drive_GetDefaultToAL |
---|
| 42 | push ax |
---|
| 43 | |
---|
[41] | 44 | mov bx, FileEventHandler |
---|
| 45 | mov BYTE [si+FILE_DIALOG_IO.bUserCancellation], TRUE |
---|
[593] | 46 | call Dialog_DisplayWithDialogInputInDSSIandHandlerInBX |
---|
[41] | 47 | |
---|
[593] | 48 | ; Now restore the default drive if user cancellation |
---|
| 49 | pop dx |
---|
| 50 | cmp BYTE [si+FILE_DIALOG_IO.bUserCancellation], TRUE |
---|
[596] | 51 | jne SHORT .UserDidNotCancel |
---|
| 52 | jmp Drive_SetDefaultFromDL |
---|
| 53 | |
---|
| 54 | .UserDidNotCancel: |
---|
[593] | 55 | ret |
---|
[41] | 56 | |
---|
[593] | 57 | |
---|
[41] | 58 | ;-------------------------------------------------------------------- |
---|
| 59 | ; FileEventHandler |
---|
| 60 | ; Common parameters for all events: |
---|
| 61 | ; BX: Menu event (anything from MENUEVENT struct) |
---|
| 62 | ; SS:BP: Ptr to DIALOG |
---|
| 63 | ; Common return values for all events: |
---|
| 64 | ; CF: Set if event processed |
---|
| 65 | ; Cleared if event not processed |
---|
| 66 | ; Corrupts registers: |
---|
| 67 | ; All |
---|
| 68 | ;-------------------------------------------------------------------- |
---|
| 69 | ALIGN JUMP_ALIGN |
---|
| 70 | FileEventHandler: |
---|
| 71 | jmp [cs:bx+.rgfnEventHandlers] |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | ALIGN JUMP_ALIGN |
---|
| 75 | .ItemSelectedFromCX: |
---|
| 76 | call LoadItemStringBufferToESDI |
---|
[106] | 77 | call Registers_CopyESDItoDSSI |
---|
[52] | 78 | call ItemLineSplitter_GetLineToDSSIandLengthToCXfromStringInDSSIwithIndexInCX |
---|
[41] | 79 | jmp ParseSelectionFromItemLineInDSSI |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | ALIGN JUMP_ALIGN |
---|
| 83 | .RefreshInformation: |
---|
| 84 | call GetInfoLinesToCXandDialogFlagsToAX |
---|
| 85 | mov si, [cs:.rgszInfoStringLookup] |
---|
| 86 | xor bx, bx |
---|
| 87 | xchg dx, ax |
---|
| 88 | ALIGN JUMP_ALIGN |
---|
| 89 | .InfoLineLoop: |
---|
| 90 | shr dl, 1 |
---|
| 91 | jnc SHORT .CheckNextFlag |
---|
| 92 | mov si, [cs:bx+.rgszInfoStringLookup] |
---|
| 93 | push bx |
---|
| 94 | CALL_DISPLAY_LIBRARY PrintNullTerminatedStringFromCSSI |
---|
| 95 | pop bx |
---|
| 96 | ALIGN JUMP_ALIGN |
---|
| 97 | .CheckNextFlag: |
---|
| 98 | inc bx |
---|
| 99 | inc bx |
---|
| 100 | loop .InfoLineLoop |
---|
| 101 | stc ; Event processed |
---|
| 102 | ret |
---|
| 103 | |
---|
| 104 | |
---|
[53] | 105 | ALIGN JUMP_ALIGN |
---|
| 106 | .RefreshItemFromCX: |
---|
| 107 | call LoadItemStringBufferToESDI |
---|
| 108 | mov ax, FILE_STRING_LENGTH |
---|
| 109 | xchg ax, cx |
---|
| 110 | mul cx |
---|
| 111 | add di, ax |
---|
| 112 | mov si, di |
---|
| 113 | mov bx, es |
---|
| 114 | dec cx ; Do not print LF at the end of file string |
---|
| 115 | CALL_DISPLAY_LIBRARY PrintCharBufferFromBXSIwithLengthInCX |
---|
| 116 | stc |
---|
| 117 | ret |
---|
| 118 | |
---|
| 119 | |
---|
[41] | 120 | ALIGN WORD_ALIGN |
---|
| 121 | .rgszInfoStringLookup: |
---|
| 122 | dw g_szChangeDrive |
---|
[625] | 123 | %ifndef EXCLUDE_FROM_XTIDECFG |
---|
[41] | 124 | dw g_szSelectDirectory |
---|
| 125 | dw g_szCreateNew |
---|
[625] | 126 | %endif |
---|
[41] | 127 | |
---|
| 128 | .rgfnEventHandlers: |
---|
| 129 | istruc MENUEVENT |
---|
| 130 | at MENUEVENT.InitializeMenuinitFromDSSI, dw InitializeMenuinitFromSSBP |
---|
[58] | 131 | at MENUEVENT.ExitMenu, dw Dialog_EventExitMenu |
---|
[41] | 132 | at MENUEVENT.IdleProcessing, dw Dialog_EventNotHandled |
---|
| 133 | at MENUEVENT.ItemHighlightedFromCX, dw Dialog_EventNotHandled |
---|
| 134 | at MENUEVENT.ItemSelectedFromCX, dw .ItemSelectedFromCX |
---|
| 135 | at MENUEVENT.KeyStrokeInAX, dw HandleFunctionKeyFromAH |
---|
| 136 | at MENUEVENT.RefreshTitle, dw Dialog_EventRefreshTitle |
---|
| 137 | at MENUEVENT.RefreshInformation, dw .RefreshInformation |
---|
[53] | 138 | at MENUEVENT.RefreshItemFromCX, dw .RefreshItemFromCX |
---|
[41] | 139 | iend |
---|
| 140 | |
---|
| 141 | |
---|
| 142 | ;-------------------------------------------------------------------- |
---|
[54] | 143 | ; ReInitializeMenuinitFromSSBP |
---|
[41] | 144 | ; InitializeMenuinitFromSSBP |
---|
| 145 | ; Parameters: |
---|
| 146 | ; SS:BP: Ptr to DIALOG |
---|
| 147 | ; Returns: |
---|
| 148 | ; Nothing |
---|
| 149 | ; Corrupts registers: |
---|
| 150 | ; All, except BP |
---|
| 151 | ;-------------------------------------------------------------------- |
---|
| 152 | ALIGN JUMP_ALIGN |
---|
[54] | 153 | ReInitializeMenuinitFromSSBP: |
---|
| 154 | call DisplayLoadingMessageInInformationArea |
---|
[41] | 155 | InitializeMenuinitFromSSBP: |
---|
| 156 | call LoadItemStringBufferToESDI |
---|
| 157 | call CreateStringFromCurrentDirectoryContentsToESDI |
---|
[46] | 158 | call LoadItemStringBufferToESDI |
---|
| 159 | call SortDirectoryContentsStringFromESDIwithCountInCX |
---|
[625] | 160 | xor ax, ax |
---|
| 161 | mov [es:di-1], al ; Terminate with NULL |
---|
[106] | 162 | call Registers_CopySSBPtoDSSI |
---|
[52] | 163 | call Dialog_EventInitializeMenuinitFromDSSIwithHighlightedItemInAX |
---|
[41] | 164 | call GetInfoLinesToCXandDialogFlagsToAX |
---|
| 165 | mov [bp+MENUINIT.bInfoLines], cl |
---|
| 166 | CALL_DISPLAY_LIBRARY GetColumnsToALandRowsToAH |
---|
| 167 | mov [bp+MENUINIT.bHeight], ah ; Always max height |
---|
[52] | 168 | mov WORD [bp+MENU.wFirstVisibleItem], 0 |
---|
[41] | 169 | ret |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | ;-------------------------------------------------------------------- |
---|
| 173 | ; LoadItemStringBufferToESDI |
---|
| 174 | ; Parameters: |
---|
| 175 | ; SS:BP: Ptr to DIALOG |
---|
| 176 | ; Returns: |
---|
| 177 | ; ES:DI: Ptr to item string buffer |
---|
| 178 | ; Corrupts registers: |
---|
| 179 | ; Nothing |
---|
| 180 | ;-------------------------------------------------------------------- |
---|
| 181 | ALIGN JUMP_ALIGN |
---|
| 182 | LoadItemStringBufferToESDI: |
---|
| 183 | les di, [bp+DIALOG.fpDialogIO] |
---|
| 184 | les di, [es:di+FILE_DIALOG_IO.fszItemBuffer] |
---|
| 185 | ret |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | ;-------------------------------------------------------------------- |
---|
| 189 | ; CreateStringFromCurrentDirectoryContentsToESDI |
---|
| 190 | ; Parameters: |
---|
| 191 | ; ES:DI: Buffer where to create item string |
---|
| 192 | ; SS:BP: Ptr to DIALOG |
---|
| 193 | ; Returns: |
---|
[46] | 194 | ; CX: Number of files or directories found |
---|
[41] | 195 | ; Corrupts registers: |
---|
[53] | 196 | ; AX, BX, DX, SI, DI, DS |
---|
[41] | 197 | ;-------------------------------------------------------------------- |
---|
| 198 | ALIGN JUMP_ALIGN |
---|
| 199 | CreateStringFromCurrentDirectoryContentsToESDI: |
---|
[53] | 200 | mov bx, di |
---|
| 201 | CALL_DISPLAY_LIBRARY PushDisplayContext |
---|
| 202 | mov cx, -1 |
---|
| 203 | CALL_DISPLAY_LIBRARY PrepareOffScreenBufferInESBXwithLengthInCX ; ES:DI now points to buffer |
---|
| 204 | |
---|
[41] | 205 | lds si, [bp+DIALOG.fpDialogIO] |
---|
[293] | 206 | eMOVZX cx, [si+FILE_DIALOG_IO.bFileAttributes] |
---|
[41] | 207 | lds si, [si+FILE_DIALOG_IO.fpFileFilterString] |
---|
| 208 | call Directory_UpdateDTAForFirstMatchForDSSIwithAttributesInCX |
---|
[53] | 209 | |
---|
[41] | 210 | call .ClearDLifInRootDirectory |
---|
| 211 | call Directory_GetDiskTransferAreaAddressToDSSI |
---|
[46] | 212 | xor cx, cx ; Clear file/directory count |
---|
[53] | 213 | call .FindMatchingFilesAndPrintThemToOffScreenBuffer |
---|
[41] | 214 | |
---|
[505] | 215 | JMP_DISPLAY_LIBRARY PopDisplayContext |
---|
[41] | 216 | |
---|
| 217 | ;-------------------------------------------------------------------- |
---|
| 218 | ; .ClearDLifInRootDirectory |
---|
| 219 | ; Parameters: |
---|
| 220 | ; SS:BP: Ptr to DIALOG |
---|
| 221 | ; ES:DI: Ptr to destination string buffer |
---|
| 222 | ; Returns: |
---|
| 223 | ; DL: Cleared if in root directory |
---|
| 224 | ; Set if in any other directory |
---|
| 225 | ; Corrupts registers: |
---|
| 226 | ; AX, SI, DS |
---|
| 227 | ;-------------------------------------------------------------------- |
---|
| 228 | ALIGN JUMP_ALIGN |
---|
| 229 | .ClearDLifInRootDirectory: |
---|
[106] | 230 | call Registers_CopyESDItoDSSI |
---|
[41] | 231 | call Directory_WriteCurrentPathToDSSI |
---|
| 232 | mov dl, [si] |
---|
| 233 | ret |
---|
| 234 | |
---|
| 235 | ;-------------------------------------------------------------------- |
---|
[53] | 236 | ; .FindMatchingFilesAndPrintThemToOffScreenBuffer |
---|
[41] | 237 | ; Parameters: |
---|
[53] | 238 | ; CX: Initial directory count |
---|
| 239 | ; DL: Zero if root directory selected |
---|
| 240 | ; DS:SI: Ptr to DTA with first matching file |
---|
[41] | 241 | ; Returns: |
---|
[53] | 242 | ; CX: Incremented by number of files/directories found |
---|
[41] | 243 | ; Corrupts registers: |
---|
[53] | 244 | ; AX, BX, DX, DI, DS |
---|
[41] | 245 | ;-------------------------------------------------------------------- |
---|
| 246 | ALIGN JUMP_ALIGN |
---|
[53] | 247 | .FindMatchingFilesAndPrintThemToOffScreenBuffer: |
---|
| 248 | call AppendFileFromDTAinDSSItoOffScreenBuffer |
---|
| 249 | call Directory_UpdateDTAForNextMatchUsingPreviousParameters |
---|
| 250 | jnc SHORT .FindMatchingFilesAndPrintThemToOffScreenBuffer |
---|
[41] | 251 | ret |
---|
| 252 | |
---|
[46] | 253 | |
---|
[41] | 254 | ;-------------------------------------------------------------------- |
---|
[53] | 255 | ; AppendFileFromDTAinDSSItoOffScreenBuffer |
---|
[41] | 256 | ; Parameters: |
---|
[589] | 257 | ; CX: Files/directories found |
---|
[41] | 258 | ; DL: Zero if root directory selected |
---|
| 259 | ; DS:SI: Ptr to DTA containing file information |
---|
| 260 | ; Returns: |
---|
[46] | 261 | ; CX: Incremented by number of files/directories found |
---|
[41] | 262 | ; Corrupts registers: |
---|
[53] | 263 | ; AX, BX |
---|
[41] | 264 | ;-------------------------------------------------------------------- |
---|
| 265 | ALIGN JUMP_ALIGN |
---|
[53] | 266 | AppendFileFromDTAinDSSItoOffScreenBuffer: |
---|
[592] | 267 | cmp WORD [si+DTA.szFile], CURRENTDIR_CHARACTERS |
---|
| 268 | je SHORT .Return ; We never want "." |
---|
| 269 | test dl, dl |
---|
| 270 | jnz SHORT .NotInRootDirectory |
---|
| 271 | cmp WORD [si+DTA.szFile], UPDIR_CHARACTERS |
---|
| 272 | je SHORT .Return ; No ".." when in root directory |
---|
| 273 | .NotInRootDirectory: |
---|
[46] | 274 | inc cx ; Nothing filtered so increment files/directories |
---|
[41] | 275 | |
---|
| 276 | push bp |
---|
| 277 | push si |
---|
[53] | 278 | push dx |
---|
[46] | 279 | push cx |
---|
[41] | 280 | call .FormatFileOrDirectoryToBufferFromDTAinDSSI |
---|
[46] | 281 | pop cx |
---|
[53] | 282 | pop dx |
---|
[41] | 283 | pop si |
---|
| 284 | pop bp |
---|
[592] | 285 | .Return: |
---|
[41] | 286 | ret |
---|
| 287 | |
---|
| 288 | ;-------------------------------------------------------------------- |
---|
| 289 | ; .FormatFileOrDirectoryToBufferFromDTAinDSSI |
---|
| 290 | ; Parameters: |
---|
| 291 | ; DS:SI: Ptr to DTA containing file information |
---|
| 292 | ; Returns: |
---|
| 293 | ; Nothing |
---|
| 294 | ; Corrupts registers: |
---|
| 295 | ; AX, BX, CX, DX, SI, DI, BP |
---|
| 296 | ;-------------------------------------------------------------------- |
---|
| 297 | ALIGN JUMP_ALIGN |
---|
| 298 | .FormatFileOrDirectoryToBufferFromDTAinDSSI: |
---|
| 299 | mov bp, sp |
---|
| 300 | lea ax, [si+DTA.szFile] |
---|
| 301 | |
---|
| 302 | test BYTE [si+DTA.bFileAttributes], FLG_FILEATTR_DIRECTORY |
---|
| 303 | jnz SHORT .FormatDirectory |
---|
[46] | 304 | ; Fall to .FormatFile |
---|
[41] | 305 | |
---|
[46] | 306 | ;-------------------------------------------------------------------- |
---|
| 307 | ; .FormatFile |
---|
| 308 | ; Parameters: |
---|
| 309 | ; BP: SP before pushing formatting parameters |
---|
| 310 | ; DS:AX: Far pointer to file name |
---|
| 311 | ; DS:SI: Ptr to DTA containing file information |
---|
| 312 | ; Returns: |
---|
| 313 | ; Nothing |
---|
| 314 | ; Corrupts registers: |
---|
[53] | 315 | ; AX, BX, CX, DX, SI, DI |
---|
[46] | 316 | ;-------------------------------------------------------------------- |
---|
| 317 | .FormatFile: |
---|
| 318 | xchg si, ax |
---|
[53] | 319 | call String_ConvertDSSItoLowerCase |
---|
[46] | 320 | xchg ax, si |
---|
[52] | 321 | |
---|
| 322 | ; Push parameters for file name |
---|
[53] | 323 | push ax ; Push file name offset |
---|
| 324 | push ds ; Push file name segment |
---|
[46] | 325 | |
---|
| 326 | ; Push parameters for file size |
---|
[41] | 327 | mov ax, [si+DTA.dwFileSize] |
---|
| 328 | mov dx, [si+DTA.dwFileSize+2] |
---|
| 329 | xor bx, bx |
---|
| 330 | xor cx, cx |
---|
| 331 | call Size_GetSizeToAXAndCharToDLfromBXDXAXwithMagnitudeInCX |
---|
| 332 | mov cl, 'i' |
---|
| 333 | cmp dl, ' ' |
---|
| 334 | eCMOVE cl, dl |
---|
| 335 | push ax |
---|
| 336 | push dx |
---|
| 337 | push cx |
---|
[46] | 338 | |
---|
| 339 | ; Format to buffer |
---|
[41] | 340 | mov si, g_szFileFormat |
---|
| 341 | jmp SHORT .FormatStringInCSSIandReturn |
---|
| 342 | |
---|
[46] | 343 | ;-------------------------------------------------------------------- |
---|
| 344 | ; .FormatDirectory |
---|
| 345 | ; Parameters: |
---|
| 346 | ; BP: SP before pushing formatting parameters |
---|
| 347 | ; DS:AX: Far pointer to directory name |
---|
| 348 | ; DS:SI: Ptr to DTA containing file information |
---|
| 349 | ; Returns: |
---|
| 350 | ; Nothing |
---|
| 351 | ; Corrupts registers: |
---|
[53] | 352 | ; AX, SI, DI |
---|
[46] | 353 | ;-------------------------------------------------------------------- |
---|
[41] | 354 | ALIGN JUMP_ALIGN |
---|
| 355 | .FormatDirectory: |
---|
[46] | 356 | push ax ; Push directory name offset |
---|
| 357 | push ds ; Push directory name segment |
---|
[41] | 358 | mov ax, g_szSub |
---|
| 359 | cmp WORD [si+DTA.szFile], UPDIR_CHARACTERS |
---|
| 360 | eCMOVE ax, g_szUp |
---|
| 361 | push ax |
---|
| 362 | mov si, g_szDirectoryFormat |
---|
| 363 | ALIGN JUMP_ALIGN |
---|
| 364 | .FormatStringInCSSIandReturn: |
---|
[505] | 365 | JMP_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI |
---|
[41] | 366 | |
---|
| 367 | |
---|
| 368 | ;-------------------------------------------------------------------- |
---|
[46] | 369 | ; SortDirectoryContentsStringFromESDIwithCountInCX |
---|
| 370 | ; Parameters: |
---|
| 371 | ; CX: Number of files and directories |
---|
| 372 | ; ES:DI: Buffer containing directory contents string |
---|
| 373 | ; SS:BP: Ptr to DIALOG |
---|
| 374 | ; Returns: |
---|
[53] | 375 | ; ES:DI: Ptr to end of directory contents string |
---|
[46] | 376 | ; Corrupts registers: |
---|
[53] | 377 | ; AX, BX, CX, DX, SI, DS |
---|
[46] | 378 | ;-------------------------------------------------------------------- |
---|
| 379 | ALIGN JUMP_ALIGN |
---|
| 380 | SortDirectoryContentsStringFromESDIwithCountInCX: |
---|
[106] | 381 | call Registers_CopyESDItoDSSI |
---|
[46] | 382 | |
---|
[181] | 383 | ; Add directory contents string length to DI |
---|
[53] | 384 | mov ax, FILE_STRING_LENGTH |
---|
[181] | 385 | push ax |
---|
[53] | 386 | mul cx |
---|
| 387 | add di, ax |
---|
| 388 | |
---|
[181] | 389 | mov dx, cx |
---|
| 390 | pop cx |
---|
| 391 | mov bx, .FileStringComparator |
---|
| 392 | jmp Sort_ItemsFromDSSIwithCountInDXsizeInCXandComparatorInBX |
---|
| 393 | |
---|
[46] | 394 | ;-------------------------------------------------------------------- |
---|
| 395 | ; .FileStringComparator |
---|
| 396 | ; Parameters: |
---|
| 397 | ; CX: Item size in bytes |
---|
| 398 | ; DS:SI: Ptr to first item to compare |
---|
| 399 | ; ES:DI: Ptr to second item to compare |
---|
| 400 | ; Returns: |
---|
[181] | 401 | ; FLAGS: Signed comparison between first and second item |
---|
[46] | 402 | ; Corrupts registers: |
---|
| 403 | ; Nothing |
---|
| 404 | ;-------------------------------------------------------------------- |
---|
| 405 | ALIGN JUMP_ALIGN |
---|
| 406 | .FileStringComparator: |
---|
| 407 | push di |
---|
| 408 | push si |
---|
| 409 | push cx |
---|
| 410 | push bx |
---|
| 411 | |
---|
| 412 | mov bx, FILE_STRING_LENGTH-2 ; Zero BH |
---|
| 413 | cmp WORD [si], UPDIR_CHARACTERS |
---|
| 414 | je SHORT .ForceValueFromDSSItoBeLess |
---|
| 415 | mov bl, [si+bx] |
---|
| 416 | cmp bl, [es:di+FILE_STRING_LENGTH-2] ; 'B' for files, 'R' for directories |
---|
| 417 | jne SHORT .ForceValueFromDSSItoBeMoreOrLess |
---|
| 418 | repe cmpsb ; Two directories or two files |
---|
| 419 | |
---|
| 420 | ALIGN JUMP_ALIGN |
---|
| 421 | .ReturnFromComparison: |
---|
| 422 | pop bx |
---|
| 423 | pop cx |
---|
| 424 | pop si |
---|
| 425 | pop di |
---|
| 426 | ret |
---|
| 427 | ALIGN JUMP_ALIGN |
---|
| 428 | .ForceValueFromDSSItoBeMoreOrLess: |
---|
| 429 | ja SHORT .ForceValueFromDSSItoBeLess ; Directory in SI, file in DI |
---|
| 430 | xchg bl, bh |
---|
| 431 | ; Fall to ForceValueFromDSSItoBeLess |
---|
| 432 | ALIGN JUMP_ALIGN |
---|
| 433 | .ForceValueFromDSSItoBeLess: |
---|
| 434 | cmp bh, bl |
---|
| 435 | jmp SHORT .ReturnFromComparison |
---|
| 436 | |
---|
| 437 | |
---|
| 438 | ;-------------------------------------------------------------------- |
---|
[41] | 439 | ; GetInfoLinesToCXandDialogFlagsToAX |
---|
| 440 | ; Parameters: |
---|
| 441 | ; SS:BP: Ptr to DIALOG |
---|
| 442 | ; Returns: |
---|
| 443 | ; AX: Dialog flags |
---|
| 444 | ; CX: Number of info lines to be displayed |
---|
| 445 | ; Corrupts registers: |
---|
| 446 | ; SI, DS |
---|
| 447 | ;-------------------------------------------------------------------- |
---|
| 448 | ALIGN JUMP_ALIGN |
---|
| 449 | GetInfoLinesToCXandDialogFlagsToAX: |
---|
[592] | 450 | ePUSH_T ax, Bit_GetSetCountToCXfromAX |
---|
| 451 | xor ah, ah |
---|
| 452 | ; Fall to GetDialogFlagsToAL |
---|
[41] | 453 | |
---|
| 454 | ;-------------------------------------------------------------------- |
---|
| 455 | ; GetDialogFlagsToAL |
---|
| 456 | ; Parameters: |
---|
| 457 | ; SS:BP: Ptr to DIALOG |
---|
| 458 | ; Returns: |
---|
| 459 | ; AL: Dialog flags |
---|
| 460 | ; Corrupts registers: |
---|
| 461 | ; SI, DS |
---|
| 462 | ;-------------------------------------------------------------------- |
---|
| 463 | ALIGN JUMP_ALIGN |
---|
| 464 | GetDialogFlagsToAL: |
---|
| 465 | lds si, [bp+DIALOG.fpDialogIO] |
---|
| 466 | mov al, [si+FILE_DIALOG_IO.bDialogFlags] |
---|
| 467 | ret |
---|
| 468 | |
---|
| 469 | |
---|
| 470 | ;-------------------------------------------------------------------- |
---|
| 471 | ; ParseSelectionFromItemLineInDSSI |
---|
| 472 | ; Parameters: |
---|
| 473 | ; DS:SI: Ptr to char buffer containing file or directory to be selected |
---|
| 474 | ; SS:BP: Ptr to DIALOG |
---|
| 475 | ; Returns: |
---|
| 476 | ; Nothing |
---|
| 477 | ; Corrupts registers: |
---|
| 478 | ; All, except BP |
---|
| 479 | ;-------------------------------------------------------------------- |
---|
| 480 | ALIGN JUMP_ALIGN |
---|
| 481 | ParseSelectionFromItemLineInDSSI: |
---|
[46] | 482 | mov ax, [si] |
---|
| 483 | cmp ax, UPDIR_CHARACTERS |
---|
| 484 | je SHORT .ChangeToUpdir |
---|
| 485 | call Char_IsUpperCaseLetterInAL |
---|
| 486 | jc SHORT .ParseAndChangeToSubdirInDSSI |
---|
[141] | 487 | call Char_IsDecimalDigitInAL |
---|
| 488 | jc SHORT .ParseAndChangeToSubdirInDSSI ; Assume subdir and check for errors |
---|
[46] | 489 | ; Fall to .ParseAndSelectFileFromDSSI |
---|
[41] | 490 | |
---|
| 491 | ;-------------------------------------------------------------------- |
---|
[46] | 492 | ; .ParseAndSelectFileFromDSSI |
---|
[41] | 493 | ; Parameters: |
---|
[46] | 494 | ; DS:SI: NULL terminated string selected from dialog |
---|
[41] | 495 | ; SS:BP: Ptr to DIALOG |
---|
| 496 | ; Returns: |
---|
| 497 | ; Nothing (exits dialog) |
---|
| 498 | ; Corrupts registers: |
---|
| 499 | ; All, except BP |
---|
| 500 | ;-------------------------------------------------------------------- |
---|
[46] | 501 | .ParseAndSelectFileFromDSSI: |
---|
[41] | 502 | les di, [bp+DIALOG.fpDialogIO] |
---|
| 503 | add di, BYTE FILE_DIALOG_IO.szFile |
---|
| 504 | mov cx, FILENAME_BUFFER_SIZE-1 |
---|
[50] | 505 | call Memory_CopyCXbytesFromDSSItoESDI |
---|
[41] | 506 | xor ax, ax |
---|
| 507 | stosb ; Terminate with NULL |
---|
[293] | 508 | jmp SHORT CloseFileDialogAfterSuccessfulSelection |
---|
[41] | 509 | |
---|
| 510 | ;-------------------------------------------------------------------- |
---|
[46] | 511 | ; .ChangeToUpdir |
---|
[41] | 512 | ; Parameters: |
---|
| 513 | ; SS:BP: Ptr to DIALOG |
---|
| 514 | ; Returns: |
---|
| 515 | ; Nothing |
---|
| 516 | ; Corrupts registers: |
---|
| 517 | ; All, except BP |
---|
| 518 | ;-------------------------------------------------------------------- |
---|
| 519 | ALIGN JUMP_ALIGN |
---|
[46] | 520 | .ChangeToUpdir: |
---|
[51] | 521 | push cs |
---|
| 522 | pop ds |
---|
[46] | 523 | mov si, g_szUpdir |
---|
| 524 | jmp SHORT .ChangeDirectoryToDSSI |
---|
| 525 | |
---|
| 526 | ;-------------------------------------------------------------------- |
---|
| 527 | ; .ParseAndChangeToSubdirInDSSI |
---|
| 528 | ; Parameters: |
---|
| 529 | ; DS:SI: NULL terminated string selected from dialog |
---|
| 530 | ; SS:BP: Ptr to DIALOG |
---|
| 531 | ; Returns: |
---|
| 532 | ; Nothing |
---|
| 533 | ; Corrupts registers: |
---|
| 534 | ; All, except BP |
---|
| 535 | ;-------------------------------------------------------------------- |
---|
| 536 | ALIGN JUMP_ALIGN |
---|
| 537 | .ParseAndChangeToSubdirInDSSI: |
---|
| 538 | mov BYTE [si+12], NULL ; Terminate with NULL (unnecessary spaces do not matter) |
---|
| 539 | .ChangeDirectoryToDSSI: |
---|
[41] | 540 | call Directory_ChangeToPathFromDSSI |
---|
[141] | 541 | jc SHORT .ParseAndSelectFileFromDSSI ; Must have been a file starting with number |
---|
[41] | 542 | ; Fall to RefreshFilesToDisplay |
---|
| 543 | |
---|
| 544 | ;-------------------------------------------------------------------- |
---|
| 545 | ; RefreshFilesToDisplay |
---|
| 546 | ; Parameters: |
---|
| 547 | ; SS:BP: Ptr to DIALOG |
---|
| 548 | ; Returns: |
---|
| 549 | ; Nothing |
---|
| 550 | ; Corrupts registers: |
---|
| 551 | ; All, except BP |
---|
| 552 | ;-------------------------------------------------------------------- |
---|
| 553 | ALIGN JUMP_ALIGN |
---|
| 554 | RefreshFilesToDisplay: |
---|
[54] | 555 | call ReInitializeMenuinitFromSSBP |
---|
[41] | 556 | jmp MenuInit_RefreshMenuWindow |
---|
| 557 | |
---|
| 558 | |
---|
| 559 | ;-------------------------------------------------------------------- |
---|
| 560 | ; HandleFunctionKeyFromAH |
---|
| 561 | ; Parameters: |
---|
| 562 | ; AH: Scancode for function key |
---|
| 563 | ; SS:BP: Ptr to DIALOG |
---|
| 564 | ; Returns: |
---|
| 565 | ; Nothing |
---|
| 566 | ; Corrupts registers: |
---|
| 567 | ; AX, SI, DI, BP |
---|
| 568 | ;-------------------------------------------------------------------- |
---|
| 569 | ALIGN JUMP_ALIGN |
---|
| 570 | HandleFunctionKeyFromAH: |
---|
| 571 | call GetDialogFlagsToAL |
---|
[625] | 572 | %ifndef EXCLUDE_FROM_XTIDECFG |
---|
[41] | 573 | cmp ah, KEY_FILEDIALOG_NEW_FILE_OR_DIR |
---|
| 574 | je SHORT HandleFunctionKeyForCreatingNewFileOrDirectory |
---|
| 575 | cmp ah, KEY_FILEDIALOG_SELECT_DIRECTORY |
---|
| 576 | je SHORT HandleFunctionKeyForSelectingDirectoryInsteadOfFile |
---|
[625] | 577 | %endif |
---|
[41] | 578 | cmp ah, KEY_FILEDIALOG_CHANGE_DRIVE |
---|
| 579 | je SHORT HandleFunctionKeyForDriveChange |
---|
| 580 | ReturnWithoutHandlingKeystroke: |
---|
| 581 | clc ; Event not processed |
---|
| 582 | ret |
---|
| 583 | |
---|
| 584 | |
---|
| 585 | ;-------------------------------------------------------------------- |
---|
| 586 | ; HandleFunctionKeyForCreatingNewFileOrDirectory |
---|
| 587 | ; Parameters: |
---|
| 588 | ; AL: File dialog flags |
---|
| 589 | ; SS:BP: Ptr to DIALOG |
---|
| 590 | ; Returns: |
---|
| 591 | ; Closes file dialog |
---|
| 592 | ; Corrupts registers: |
---|
| 593 | ; All, except BP |
---|
| 594 | ;-------------------------------------------------------------------- |
---|
[625] | 595 | %ifndef EXCLUDE_FROM_XTIDECFG |
---|
[41] | 596 | ALIGN JUMP_ALIGN |
---|
| 597 | HandleFunctionKeyForCreatingNewFileOrDirectory: |
---|
| 598 | test al, FLG_FILEDIALOG_NEW |
---|
| 599 | jz SHORT ReturnWithoutHandlingKeystroke |
---|
| 600 | |
---|
[602] | 601 | mov cl, STRING_DIALOG_IO_size |
---|
| 602 | call Memory_ReserveCLbytesFromStackToDSSI |
---|
[41] | 603 | |
---|
[568] | 604 | ;;; InitializeStringDialogIoInDSSIforInputtingFileName |
---|
[41] | 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 |
---|
[568] | 613 | ;;; |
---|
[41] | 614 | |
---|
[568] | 615 | CALL_MENU_LIBRARY GetStringWithIoInDSSI |
---|
| 616 | mov al, [si+STRING_DIALOG_IO.bUserCancellation] |
---|
| 617 | add sp, BYTE STRING_DIALOG_IO_size |
---|
| 618 | test al, al ; User cancellation? |
---|
| 619 | jnz SHORT ReturnWithoutHandlingKeystroke |
---|
| 620 | jmp CloseFileDialogAfterSuccessfulSelection |
---|
[41] | 621 | |
---|
[568] | 622 | |
---|
[41] | 623 | ;-------------------------------------------------------------------- |
---|
| 624 | ; HandleFunctionKeyForSelectingDirectoryInsteadOfFile |
---|
| 625 | ; Parameters: |
---|
| 626 | ; AL: File dialog flags |
---|
| 627 | ; SS:BP: Ptr to DIALOG |
---|
| 628 | ; Returns: |
---|
| 629 | ; Closes file dialog |
---|
| 630 | ; Corrupts registers: |
---|
| 631 | ; All, except BP |
---|
| 632 | ;-------------------------------------------------------------------- |
---|
| 633 | ALIGN JUMP_ALIGN |
---|
| 634 | HandleFunctionKeyForSelectingDirectoryInsteadOfFile: |
---|
| 635 | test al, FLG_FILEDIALOG_DIRECTORY |
---|
| 636 | jz SHORT ReturnWithoutHandlingKeystroke |
---|
[293] | 637 | ; Fall to CloseFileDialogAfterSuccessfulSelection |
---|
[625] | 638 | %endif ; EXCLUDE_FROM_XTIDECFG |
---|
[41] | 639 | |
---|
| 640 | ;-------------------------------------------------------------------- |
---|
[293] | 641 | ; CloseFileDialogAfterSuccessfulSelection |
---|
[41] | 642 | ; Parameters: |
---|
| 643 | ; SS:BP: Ptr to DIALOG |
---|
| 644 | ; Returns: |
---|
| 645 | ; Nothing (exits dialog) |
---|
| 646 | ; Corrupts registers: |
---|
| 647 | ; All, except BP |
---|
| 648 | ;-------------------------------------------------------------------- |
---|
| 649 | ALIGN JUMP_ALIGN |
---|
[293] | 650 | CloseFileDialogAfterSuccessfulSelection: |
---|
[41] | 651 | lds di, [bp+DIALOG.fpDialogIO] |
---|
| 652 | mov BYTE [di+FILE_DIALOG_IO.bUserCancellation], FALSE |
---|
| 653 | jmp MenuInit_CloseMenuWindow |
---|
| 654 | |
---|
| 655 | |
---|
| 656 | ;-------------------------------------------------------------------- |
---|
| 657 | ; HandleFunctionKeyForDriveChange |
---|
| 658 | ; Parameters: |
---|
| 659 | ; AL: File dialog flags |
---|
| 660 | ; SS:BP: Ptr to DIALOG |
---|
| 661 | ; Returns: |
---|
| 662 | ; Nothing |
---|
| 663 | ; Corrupts registers: |
---|
| 664 | ; All, except BP |
---|
| 665 | ;-------------------------------------------------------------------- |
---|
| 666 | ALIGN JUMP_ALIGN |
---|
| 667 | HandleFunctionKeyForDriveChange: |
---|
| 668 | test al, FLG_FILEDIALOG_DRIVES |
---|
| 669 | jz SHORT ReturnWithoutHandlingKeystroke |
---|
| 670 | |
---|
[54] | 671 | call DisplayLoadingMessageInInformationArea |
---|
[602] | 672 | mov cl, DRIVE_DIALOG_IO_size |
---|
| 673 | call Memory_ReserveCLbytesFromStackToDSSI |
---|
[54] | 674 | call .DisplayDriveSelectionDialogWithIoInDSSI |
---|
| 675 | call .ChangeDriveToUserSelectionFromIoInDSSI |
---|
| 676 | add sp, BYTE DRIVE_DIALOG_IO_size |
---|
[592] | 677 | .UserCancelledDriveChange: |
---|
[54] | 678 | ret |
---|
[41] | 679 | |
---|
| 680 | ;-------------------------------------------------------------------- |
---|
[54] | 681 | ; .DisplayDriveSelectionDialogWithIoInDSSI |
---|
[41] | 682 | ; Parameters: |
---|
[54] | 683 | ; DS:SI: Ptr to uninitialized DRIVE_DIALOG_IO |
---|
[41] | 684 | ; SS:BP: Ptr to DIALOG |
---|
| 685 | ; Returns: |
---|
[54] | 686 | ; DS:SI: Ptr to DRIVE_DIALOG_IO |
---|
[41] | 687 | ; Corrupts registers: |
---|
[54] | 688 | ; AX, DI |
---|
[41] | 689 | ;-------------------------------------------------------------------- |
---|
| 690 | ALIGN JUMP_ALIGN |
---|
[54] | 691 | .DisplayDriveSelectionDialogWithIoInDSSI: |
---|
[41] | 692 | call InitializeNullStringsToDialogInputInDSSI |
---|
| 693 | mov WORD [si+DIALOG_INPUT.fszTitle], g_szSelectNewDrive |
---|
[525] | 694 | JMP_MENU_LIBRARY GetDriveWithIoInDSSI |
---|
[41] | 695 | |
---|
| 696 | ;-------------------------------------------------------------------- |
---|
[54] | 697 | ; .ChangeDriveToUserSelectionFromIoInDSSI |
---|
[41] | 698 | ; Parameters: |
---|
[54] | 699 | ; DS:SI: Ptr to DRIVE_DIALOG_IO |
---|
[41] | 700 | ; SS:BP: Ptr to DIALOG |
---|
| 701 | ; Returns: |
---|
| 702 | ; Nothing |
---|
| 703 | ; Corrupts registers: |
---|
[54] | 704 | ; All, except BP |
---|
[41] | 705 | ;-------------------------------------------------------------------- |
---|
| 706 | ALIGN JUMP_ALIGN |
---|
[54] | 707 | .ChangeDriveToUserSelectionFromIoInDSSI: |
---|
| 708 | cmp BYTE [si+DRIVE_DIALOG_IO.bUserCancellation], FALSE |
---|
| 709 | jne SHORT .UserCancelledDriveChange |
---|
[41] | 710 | |
---|
[592] | 711 | ; Install our Custom Critical Error Handler to catch "Drive Not Ready" errors. This handler only works on DOS 3.0+ systems |
---|
| 712 | ; but that should be OK because only DOS 3.1+ will trigger it. Under older DOS versions drives are enumerated using |
---|
| 713 | ; GET_DOS_DRIVE_PARAMETER_BLOCK_FOR_SPECIFIC_DRIVE which will access the drive so we know it is available at this point. |
---|
| 714 | mov dx, DosCritical_CustomHandler |
---|
| 715 | call DosCritical_InstallNewHandlerFromCSDX |
---|
| 716 | |
---|
| 717 | ; Save the current drive on stack in case the selected drive is not ready and the user decides to cancel the change. |
---|
| 718 | call Drive_GetDefaultToAL |
---|
| 719 | xchg dx, ax |
---|
| 720 | |
---|
| 721 | .RetryDrive: |
---|
| 722 | push dx ; Save the previous current drive to stack |
---|
| 723 | |
---|
[54] | 724 | mov dl, [si+DRIVE_DIALOG_IO.bReturnDriveNumber] |
---|
| 725 | call Drive_SetDefaultFromDL |
---|
[592] | 726 | |
---|
| 727 | ; Now we must try to force a media access to catch "Drive Not Ready". |
---|
| 728 | push ds |
---|
| 729 | push ss |
---|
| 730 | pop ds |
---|
[602] | 731 | ePUSH_T ax, CURRENTDIR_CHARACTERS ; The high byte is zero |
---|
[592] | 732 | mov cx, FLG_FILEATTR_DIRECTORY |
---|
| 733 | mov dx, sp |
---|
| 734 | mov ax, FIND_FIRST_MATCHING_FILE<<8 |
---|
| 735 | int DOS_INTERRUPT_21h |
---|
[601] | 736 | ; Returns ERR_DOS_NO_MORE_FILES only when the root directory is the current directory (at least under Windows XP). |
---|
| 737 | cmp al, ERR_DOS_PATH_NOT_FOUND |
---|
[592] | 738 | pop ax |
---|
| 739 | pop ds |
---|
| 740 | |
---|
| 741 | pop dx ; Restore the previous current drive from stack |
---|
| 742 | |
---|
| 743 | xchg ah, [cs:bLastCriticalError] ; Zero bLastCriticalError and fetch error code to AH |
---|
[601] | 744 | je SHORT .DriveIsNotReady ; A removable drive with no media (or possibly a drive that has not been formatted?) |
---|
[592] | 745 | cmp ah, ERR_DOS_DRIVE_NOT_READY |
---|
| 746 | jne SHORT .DriveIsReady |
---|
[601] | 747 | .DriveIsNotReady: |
---|
[592] | 748 | mov bx, g_szDlgDriveNotReady |
---|
| 749 | call Dialogs_DisplayYesNoResponseDialogWithTitleStringInBX |
---|
| 750 | jz SHORT .RetryDrive |
---|
| 751 | ; The user cancelled the drive change. Restore current drive to what it was previously. |
---|
| 752 | call Drive_SetDefaultFromDL |
---|
| 753 | jmp DosCritical_RestoreDosHandler |
---|
| 754 | |
---|
| 755 | .DriveIsReady: |
---|
| 756 | call DosCritical_RestoreDosHandler |
---|
[54] | 757 | jmp RefreshFilesToDisplay |
---|
[41] | 758 | |
---|
| 759 | |
---|
| 760 | ;-------------------------------------------------------------------- |
---|
[54] | 761 | ; DisplayLoadingMessageInInformationArea |
---|
[53] | 762 | ; Parameters: |
---|
[54] | 763 | ; SS:BP: Ptr to DIALOG |
---|
[53] | 764 | ; Returns: |
---|
| 765 | ; Nothing |
---|
| 766 | ; Corrupts registers: |
---|
[54] | 767 | ; AX, BX, CX, DX, SI, DI |
---|
[53] | 768 | ;-------------------------------------------------------------------- |
---|
| 769 | ALIGN JUMP_ALIGN |
---|
[54] | 770 | DisplayLoadingMessageInInformationArea: |
---|
| 771 | call MenuText_ClearInformationArea |
---|
| 772 | call MenuText_PrepareToDrawInformationArea |
---|
| 773 | mov si, g_szLoadingPleaseWait |
---|
[505] | 774 | JMP_DISPLAY_LIBRARY PrintNullTerminatedStringFromCSSI |
---|
[53] | 775 | |
---|
| 776 | |
---|
| 777 | ;-------------------------------------------------------------------- |
---|
[41] | 778 | ; InitializeNullStringsToDialogInputInDSSI |
---|
| 779 | ; Parameters: |
---|
| 780 | ; DS:SI: Ptr to DIALOG_INPUT |
---|
| 781 | ; SS:BP: Ptr to DIALOG |
---|
| 782 | ; Returns: |
---|
| 783 | ; Nothing |
---|
| 784 | ; Corrupts registers: |
---|
| 785 | ; AX |
---|
| 786 | ;-------------------------------------------------------------------- |
---|
| 787 | ALIGN JUMP_ALIGN |
---|
| 788 | InitializeNullStringsToDialogInputInDSSI: |
---|
| 789 | mov ax, g_szNull |
---|
| 790 | mov [si+DIALOG_INPUT.fszTitle], ax |
---|
| 791 | mov [si+DIALOG_INPUT.fszTitle+2], cs |
---|
| 792 | mov [si+DIALOG_INPUT.fszItems], ax |
---|
| 793 | mov [si+DIALOG_INPUT.fszItems+2], cs |
---|
| 794 | mov [si+DIALOG_INPUT.fszInfo], ax |
---|
| 795 | mov [si+DIALOG_INPUT.fszInfo+2], cs |
---|
| 796 | ret |
---|