[41] | 1 | ; Project name : Assembly Library
|
---|
| 2 | ; Description : Displays progress bar dialog and starts progress task.
|
---|
| 3 |
|
---|
| 4 | ; Section containing code
|
---|
| 5 | SECTION .text
|
---|
| 6 |
|
---|
| 7 | ;--------------------------------------------------------------------
|
---|
| 8 | ; DialogProgress_GetStringWithIoInDSSI
|
---|
| 9 | ; Parameters:
|
---|
| 10 | ; DS:SI: Ptr to PROGRESS_DIALOG_IO
|
---|
| 11 | ; SS:BP: Ptr to parent MENU
|
---|
| 12 | ; Returns:
|
---|
| 13 | ; Nothing
|
---|
| 14 | ; Corrupts registers:
|
---|
| 15 | ; AX, BX, CX, DX, SI, DI
|
---|
| 16 | ;--------------------------------------------------------------------
|
---|
| 17 | ALIGN JUMP_ALIGN
|
---|
| 18 | DialogProgress_StartProgressTaskWithIoInDSSIandParamInDXAX:
|
---|
| 19 | mov bx, ProgressEventHandler
|
---|
| 20 | jmp Dialog_DisplayWithDialogInputInDSSIandHandlerInBX
|
---|
| 21 |
|
---|
| 22 |
|
---|
| 23 | ;--------------------------------------------------------------------
|
---|
| 24 | ; DialogProgress_SetProgressValueFromAX
|
---|
| 25 | ; Parameters
|
---|
| 26 | ; AX: Progress bar value to set
|
---|
| 27 | ; SS:BP: Ptr to DIALOG
|
---|
| 28 | ; Returns:
|
---|
| 29 | ; Nothing
|
---|
| 30 | ; Corrupts registers:
|
---|
[48] | 31 | ; AX, BX, CX, DX, SI, DI
|
---|
[41] | 32 | ;--------------------------------------------------------------------
|
---|
| 33 | ALIGN JUMP_ALIGN
|
---|
| 34 | DialogProgress_SetProgressValueFromAX:
|
---|
| 35 | push ds
|
---|
| 36 |
|
---|
| 37 | lds si, [bp+DIALOG.fpDialogIO]
|
---|
| 38 | mov bx, [si+PROGRESS_DIALOG_IO.wMaxProgressValue]
|
---|
[181] | 39 | cmp ax, bx
|
---|
| 40 | jb SHORT .AXlessThanBX
|
---|
| 41 | mov ax, bx
|
---|
| 42 | jmp SHORT .UpdateProgressBar
|
---|
| 43 | ALIGN JUMP_ALIGN
|
---|
| 44 | .AXlessThanBX:
|
---|
[41] | 45 | mov bx, ax
|
---|
| 46 | sub bx, [si+PROGRESS_DIALOG_IO.wCurrentProgressValue]
|
---|
| 47 | cmp bx, [si+PROGRESS_DIALOG_IO.wProgressPerCharacter]
|
---|
| 48 | jb SHORT .ReturnWithoutUpdate
|
---|
| 49 | .UpdateProgressBar:
|
---|
| 50 | mov [si+PROGRESS_DIALOG_IO.wCurrentProgressValue], ax
|
---|
| 51 | xor ax, ax
|
---|
| 52 | call MenuText_RefreshItemFromAX
|
---|
| 53 | call MenuText_RefreshInformation
|
---|
| 54 | ALIGN JUMP_ALIGN
|
---|
| 55 | .ReturnWithoutUpdate:
|
---|
| 56 | pop ds
|
---|
| 57 | ret
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | ;--------------------------------------------------------------------
|
---|
| 61 | ; ProgressEventHandler
|
---|
| 62 | ; Common parameters for all events:
|
---|
| 63 | ; BX: Menu event (anything from MENUEVENT struct)
|
---|
| 64 | ; SS:BP: Ptr to DIALOG
|
---|
| 65 | ; Common return values for all events:
|
---|
| 66 | ; CF: Set if event processed
|
---|
| 67 | ; Cleared if event not processed
|
---|
| 68 | ; Corrupts registers:
|
---|
| 69 | ; All
|
---|
| 70 | ;--------------------------------------------------------------------
|
---|
| 71 | ALIGN JUMP_ALIGN
|
---|
| 72 | ProgressEventHandler:
|
---|
| 73 | jmp [cs:bx+.rgfnEventHandlers]
|
---|
| 74 |
|
---|
| 75 |
|
---|
| 76 | ALIGN JUMP_ALIGN
|
---|
| 77 | .InitializeMenuinitFromDSSI:
|
---|
[52] | 78 | mov ax, NO_ITEM_HIGHLIGHTED
|
---|
| 79 | call Dialog_EventInitializeMenuinitFromDSSIforSingleItemWithHighlightedItemInAX
|
---|
[41] | 80 | lds si, [bp+DIALOG.fpDialogIO]
|
---|
| 81 | call TimerTicks_ReadFromBdaToAX
|
---|
| 82 | mov [si+PROGRESS_DIALOG_IO.wStartTimeTicks], ax
|
---|
[73] | 83 |
|
---|
| 84 | ; 0 = 65536 but it needs to be adjusted to 65535 prevent division by zero
|
---|
| 85 | cmp WORD [si+PROGRESS_DIALOG_IO.wMaxProgressValue], BYTE 0
|
---|
| 86 | jne SHORT CalculateProgressNeededBeforeUpdatingCharacter
|
---|
| 87 | dec WORD [si+PROGRESS_DIALOG_IO.wMaxProgressValue]
|
---|
[41] | 88 | jmp SHORT CalculateProgressNeededBeforeUpdatingCharacter
|
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 | ALIGN JUMP_ALIGN
|
---|
| 92 | .IdleProcessing:
|
---|
| 93 | call MenuInit_GetUserDataToDSSI
|
---|
| 94 | les di, [bp+DIALOG.fpDialogIO]
|
---|
[64] | 95 | push bp
|
---|
[41] | 96 | call [es:di+PROGRESS_DIALOG_IO.fnTaskWithParamInDSSI]
|
---|
[64] | 97 | pop bp
|
---|
[41] | 98 | call MenuInit_CloseMenuWindow
|
---|
| 99 | stc
|
---|
| 100 | ret
|
---|
| 101 |
|
---|
| 102 |
|
---|
| 103 | ALIGN JUMP_ALIGN
|
---|
| 104 | .RefreshItemFromCX:
|
---|
| 105 | lds si, [bp+DIALOG.fpDialogIO]
|
---|
| 106 | call DrawProgressBarFromDialogIoInDSSI
|
---|
| 107 | stc
|
---|
| 108 | ret
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 | ALIGN JUMP_ALIGN
|
---|
| 112 | .RefreshInformation:
|
---|
| 113 | lds si, [bp+DIALOG.fpDialogIO]
|
---|
| 114 | call TimerTicks_ReadFromBdaToAX
|
---|
| 115 | sub ax, [si+PROGRESS_DIALOG_IO.wStartTimeTicks]
|
---|
| 116 | xchg dx, ax
|
---|
| 117 | call DrawTimeElapsedFromDX
|
---|
| 118 | call DrawTimeLeftFromProgressDialogIoInDSSIwithTimeElapsedInDX
|
---|
| 119 | stc
|
---|
| 120 | ret
|
---|
| 121 |
|
---|
| 122 |
|
---|
| 123 | ALIGN WORD_ALIGN
|
---|
| 124 | .rgfnEventHandlers:
|
---|
| 125 | istruc MENUEVENT
|
---|
| 126 | at MENUEVENT.InitializeMenuinitFromDSSI, dw .InitializeMenuinitFromDSSI
|
---|
[58] | 127 | at MENUEVENT.ExitMenu, dw Dialog_EventExitMenu
|
---|
[41] | 128 | at MENUEVENT.IdleProcessing, dw .IdleProcessing
|
---|
| 129 | at MENUEVENT.ItemHighlightedFromCX, dw Dialog_EventNotHandled
|
---|
| 130 | at MENUEVENT.ItemSelectedFromCX, dw Dialog_EventNotHandled
|
---|
| 131 | at MENUEVENT.KeyStrokeInAX, dw Dialog_EventNotHandled
|
---|
| 132 | at MENUEVENT.RefreshTitle, dw Dialog_EventRefreshTitle
|
---|
| 133 | at MENUEVENT.RefreshInformation, dw .RefreshInformation
|
---|
| 134 | at MENUEVENT.RefreshItemFromCX, dw .RefreshItemFromCX
|
---|
| 135 | iend
|
---|
| 136 |
|
---|
| 137 |
|
---|
| 138 | ;--------------------------------------------------------------------
|
---|
| 139 | ; CalculateProgressNeededBeforeUpdatingCharacter
|
---|
| 140 | ; Parameters:
|
---|
| 141 | ; DS:SI: Ptr to PROGRESS_DIALOG_IO
|
---|
| 142 | ; SS:BP: Ptr to DIALOG
|
---|
| 143 | ; Returns:
|
---|
| 144 | ; CF: Set since event handled
|
---|
| 145 | ; Corrupts:
|
---|
| 146 | ; AX, BX, DX, SI, DS
|
---|
| 147 | ;--------------------------------------------------------------------
|
---|
| 148 | ALIGN JUMP_ALIGN
|
---|
| 149 | CalculateProgressNeededBeforeUpdatingCharacter:
|
---|
| 150 | call MenuLocation_GetMaxTextLineLengthToAX
|
---|
| 151 | call GetProgressLengthToBXfromProgressDialogIoInDSSI
|
---|
| 152 | xchg ax, bx
|
---|
| 153 | xor dx, dx
|
---|
| 154 | div bx
|
---|
| 155 | mov [si+PROGRESS_DIALOG_IO.wProgressPerCharacter], ax
|
---|
| 156 | stc
|
---|
| 157 | ret
|
---|
| 158 |
|
---|
| 159 |
|
---|
| 160 | ;--------------------------------------------------------------------
|
---|
| 161 | ; DrawProgressBarFromDialogIoInDSSI
|
---|
| 162 | ; Parameters:
|
---|
| 163 | ; DS:SI: Ptr to PROGRESS_DIALOG_IO
|
---|
| 164 | ; SS:BP: Ptr to DIALOG
|
---|
| 165 | ; Returns:
|
---|
| 166 | ; Nothing
|
---|
| 167 | ; Corrupts:
|
---|
| 168 | ; AX, BX, CX, DX, DI
|
---|
| 169 | ;--------------------------------------------------------------------
|
---|
| 170 | ALIGN JUMP_ALIGN
|
---|
| 171 | DrawProgressBarFromDialogIoInDSSI:
|
---|
[181] | 172 | ; Get full chars to CX and empty chars to DX
|
---|
[41] | 173 | call MenuLocation_GetMaxTextLineLengthToAX
|
---|
| 174 | mov cx, ax
|
---|
| 175 | mul WORD [si+PROGRESS_DIALOG_IO.wCurrentProgressValue]
|
---|
| 176 | call GetProgressLengthToBXfromProgressDialogIoInDSSI
|
---|
| 177 | div bx
|
---|
| 178 | xchg cx, ax ; AX = Text line length, CX = Number of full chars
|
---|
| 179 | sub ax, cx
|
---|
| 180 | xchg dx, ax ; DX = Number of empty chars
|
---|
| 181 |
|
---|
[181] | 182 | mov al, PROGRESS_COMPLETE_CHARACTER
|
---|
| 183 | call .RepeatProgressCharacterCXtimesFromAL
|
---|
| 184 |
|
---|
| 185 | mov cx, dx
|
---|
| 186 | mov al, PROGRESS_INCOMPLETE_CHARACTER
|
---|
| 187 | ; Fall to .RepeatProgressCharacterCXtimesFromAL
|
---|
| 188 |
|
---|
[69] | 189 | ;--------------------------------------------------------------------
|
---|
| 190 | ; .RepeatProgressCharacterCXtimesFromAL
|
---|
| 191 | ; Parameters:
|
---|
| 192 | ; AL: Progress bar character to repeat
|
---|
| 193 | ; CX: Number of times to repeat the progress character
|
---|
| 194 | ; Returns:
|
---|
| 195 | ; Nothing
|
---|
| 196 | ; Corrupts:
|
---|
| 197 | ; AX, CX, DI
|
---|
| 198 | ;--------------------------------------------------------------------
|
---|
| 199 | ALIGN JUMP_ALIGN
|
---|
| 200 | .RepeatProgressCharacterCXtimesFromAL:
|
---|
| 201 | jcxz .NothingToRepeat
|
---|
| 202 | CALL_DISPLAY_LIBRARY PrintRepeatedCharacterFromALwithCountInCX
|
---|
| 203 | ALIGN JUMP_ALIGN, ret
|
---|
| 204 | .NothingToRepeat:
|
---|
| 205 | ret
|
---|
[41] | 206 |
|
---|
[69] | 207 |
|
---|
[41] | 208 | ;--------------------------------------------------------------------
|
---|
| 209 | ; GetProgressLengthToBXfromProgressDialogIoInDSSI
|
---|
| 210 | ; Parameters:
|
---|
| 211 | ; DS:SI: Ptr to PROGRESS_DIALOG_IO
|
---|
| 212 | ; Returns:
|
---|
| 213 | ; BX: Progress length
|
---|
| 214 | ; Corrupts:
|
---|
| 215 | ; Nothing
|
---|
| 216 | ;--------------------------------------------------------------------
|
---|
| 217 | ALIGN JUMP_ALIGN
|
---|
| 218 | GetProgressLengthToBXfromProgressDialogIoInDSSI:
|
---|
| 219 | mov bx, [si+PROGRESS_DIALOG_IO.wMaxProgressValue]
|
---|
| 220 | sub bx, [si+PROGRESS_DIALOG_IO.wMinProgressValue]
|
---|
| 221 | ret
|
---|
| 222 |
|
---|
[181] | 223 |
|
---|
[41] | 224 | ;--------------------------------------------------------------------
|
---|
| 225 | ; DrawTimeElapsedFromDX
|
---|
| 226 | ; Parameters:
|
---|
| 227 | ; DX: Ticks elapsed
|
---|
| 228 | ; Returns:
|
---|
| 229 | ; Nothing
|
---|
| 230 | ; Corrupts:
|
---|
| 231 | ; AX, BX, CX, DI
|
---|
| 232 | ;--------------------------------------------------------------------
|
---|
| 233 | ALIGN JUMP_ALIGN
|
---|
| 234 | DrawTimeElapsedFromDX:
|
---|
| 235 | push si
|
---|
| 236 | push dx
|
---|
| 237 |
|
---|
| 238 | mov si, g_szTimeElapsed
|
---|
| 239 | CALL_DISPLAY_LIBRARY PrintNullTerminatedStringFromCSSI
|
---|
| 240 | call FormatTicksFromDX
|
---|
| 241 |
|
---|
| 242 | pop dx
|
---|
| 243 | pop si
|
---|
| 244 | ret
|
---|
| 245 |
|
---|
| 246 |
|
---|
| 247 | ;--------------------------------------------------------------------
|
---|
| 248 | ; DrawTimeLeftFromProgressDialogIoInDSSIwithTimeElapsedInDX
|
---|
| 249 | ; Parameters:
|
---|
| 250 | ; DX: Ticks elapsed
|
---|
| 251 | ; DS:SI: Ptr to PROGRESS_DIALOG_IO
|
---|
| 252 | ; Returns:
|
---|
| 253 | ; Nothing
|
---|
| 254 | ; Corrupts:
|
---|
| 255 | ; AX, BX, CX, DX, SI, DI
|
---|
| 256 | ;--------------------------------------------------------------------
|
---|
| 257 | ALIGN JUMP_ALIGN
|
---|
| 258 | DrawTimeLeftFromProgressDialogIoInDSSIwithTimeElapsedInDX:
|
---|
| 259 | push si
|
---|
| 260 | mov si, g_szTimeLeft
|
---|
| 261 | CALL_DISPLAY_LIBRARY PrintNullTerminatedStringFromCSSI
|
---|
| 262 | pop si
|
---|
| 263 |
|
---|
| 264 | mov cx, [si+PROGRESS_DIALOG_IO.wCurrentProgressValue]
|
---|
| 265 | mov ax, [si+PROGRESS_DIALOG_IO.wMaxProgressValue]
|
---|
| 266 | sub ax, cx
|
---|
| 267 | mul dx ; Progress left * elapsed time
|
---|
| 268 |
|
---|
| 269 | sub cx, [si+PROGRESS_DIALOG_IO.wMinProgressValue]
|
---|
[181] | 270 | jz SHORT .PreventDivisionByZero
|
---|
[41] | 271 | div cx ; AX = Estimated ticks left
|
---|
| 272 | xchg dx, ax
|
---|
[181] | 273 | SKIP2B f ; cmp ax, <next instruction>
|
---|
[41] | 274 | .PreventDivisionByZero:
|
---|
| 275 | xor dx, dx
|
---|
| 276 | ; Fall to FormatTicksFromDX
|
---|
| 277 |
|
---|
| 278 |
|
---|
| 279 | ;--------------------------------------------------------------------
|
---|
| 280 | ; FormatTicksFromDX
|
---|
| 281 | ; Parameters:
|
---|
| 282 | ; DX: Ticks to format
|
---|
| 283 | ; Returns:
|
---|
| 284 | ; Nothing
|
---|
| 285 | ; Corrupts:
|
---|
| 286 | ; AX, CX, DX, SI, DI
|
---|
| 287 | ;--------------------------------------------------------------------
|
---|
| 288 | ALIGN JUMP_ALIGN
|
---|
| 289 | FormatTicksFromDX:
|
---|
| 290 | push bp
|
---|
| 291 |
|
---|
| 292 | mov bp, sp
|
---|
| 293 | mov si, g_szTimeFormat
|
---|
| 294 | call TimerTicks_GetMinutesToAXfromTicksInDX
|
---|
| 295 | push ax
|
---|
| 296 | call TimerTicks_GetSecondsToAXfromTicksInDX
|
---|
| 297 | push ax
|
---|
| 298 | CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
|
---|
| 299 |
|
---|
| 300 | pop bp
|
---|
| 301 | ret
|
---|