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