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