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