source: xtideuniversalbios/trunk/Assembly_Library/Src/Menu/Dialog/DialogProgress.asm@ 125

Last change on this file since 125 was 73, checked in by Tomi Tilli, 14 years ago

Changes to Assembly Library:

  • Fixed library dependencies.
  • Progress Dialog now properly checks maximum progress value.
File size: 8.9 KB
Line 
1; File name : DialogProgress.asm
2; Project name : Assembly Library
3; Created date : 15.8.2010
4; Last update : 10.12.2010
5; Author : Tomi Tilli
6; Description : Displays progress bar dialog and starts progress task.
7
8; Section containing code
9SECTION .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;--------------------------------------------------------------------
21ALIGN JUMP_ALIGN
22DialogProgress_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:
35; AX, BX, CX, DX, SI, DI
36;--------------------------------------------------------------------
37ALIGN JUMP_ALIGN
38DialogProgress_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
56ALIGN 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;--------------------------------------------------------------------
73ALIGN JUMP_ALIGN
74ProgressEventHandler:
75 jmp [cs:bx+.rgfnEventHandlers]
76
77
78ALIGN JUMP_ALIGN
79.InitializeMenuinitFromDSSI:
80 mov ax, NO_ITEM_HIGHLIGHTED
81 call Dialog_EventInitializeMenuinitFromDSSIforSingleItemWithHighlightedItemInAX
82 lds si, [bp+DIALOG.fpDialogIO]
83 call TimerTicks_ReadFromBdaToAX
84 mov [si+PROGRESS_DIALOG_IO.wStartTimeTicks], ax
85
86 ; 0 = 65536 but it needs to be adjusted to 65535 prevent division by zero
87 cmp WORD [si+PROGRESS_DIALOG_IO.wMaxProgressValue], BYTE 0
88 jne SHORT CalculateProgressNeededBeforeUpdatingCharacter
89 dec WORD [si+PROGRESS_DIALOG_IO.wMaxProgressValue]
90 jmp SHORT CalculateProgressNeededBeforeUpdatingCharacter
91
92
93ALIGN JUMP_ALIGN
94.IdleProcessing:
95 call MenuInit_GetUserDataToDSSI
96 les di, [bp+DIALOG.fpDialogIO]
97 push bp
98 call [es:di+PROGRESS_DIALOG_IO.fnTaskWithParamInDSSI]
99 pop bp
100 call MenuInit_CloseMenuWindow
101 stc
102 ret
103
104
105ALIGN JUMP_ALIGN
106.RefreshItemFromCX:
107 lds si, [bp+DIALOG.fpDialogIO]
108 call DrawProgressBarFromDialogIoInDSSI
109 stc
110 ret
111
112
113ALIGN JUMP_ALIGN
114.RefreshInformation:
115 lds si, [bp+DIALOG.fpDialogIO]
116 call TimerTicks_ReadFromBdaToAX
117 sub ax, [si+PROGRESS_DIALOG_IO.wStartTimeTicks]
118 xchg dx, ax
119 call DrawTimeElapsedFromDX
120 call DrawTimeLeftFromProgressDialogIoInDSSIwithTimeElapsedInDX
121 stc
122 ret
123
124
125ALIGN WORD_ALIGN
126.rgfnEventHandlers:
127istruc MENUEVENT
128 at MENUEVENT.InitializeMenuinitFromDSSI, dw .InitializeMenuinitFromDSSI
129 at MENUEVENT.ExitMenu, dw Dialog_EventExitMenu
130 at MENUEVENT.IdleProcessing, dw .IdleProcessing
131 at MENUEVENT.ItemHighlightedFromCX, dw Dialog_EventNotHandled
132 at MENUEVENT.ItemSelectedFromCX, dw Dialog_EventNotHandled
133 at MENUEVENT.KeyStrokeInAX, dw Dialog_EventNotHandled
134 at MENUEVENT.RefreshTitle, dw Dialog_EventRefreshTitle
135 at MENUEVENT.RefreshInformation, dw .RefreshInformation
136 at MENUEVENT.RefreshItemFromCX, dw .RefreshItemFromCX
137iend
138
139
140;--------------------------------------------------------------------
141; CalculateProgressNeededBeforeUpdatingCharacter
142; Parameters:
143; DS:SI: Ptr to PROGRESS_DIALOG_IO
144; SS:BP: Ptr to DIALOG
145; Returns:
146; CF: Set since event handled
147; Corrupts:
148; AX, BX, DX, SI, DS
149;--------------------------------------------------------------------
150ALIGN JUMP_ALIGN
151CalculateProgressNeededBeforeUpdatingCharacter:
152 call MenuLocation_GetMaxTextLineLengthToAX
153 call GetProgressLengthToBXfromProgressDialogIoInDSSI
154 xchg ax, bx
155 xor dx, dx
156 div bx
157 mov [si+PROGRESS_DIALOG_IO.wProgressPerCharacter], ax
158 stc
159 ret
160
161
162;--------------------------------------------------------------------
163; DrawProgressBarFromDialogIoInDSSI
164; Parameters:
165; DS:SI: Ptr to PROGRESS_DIALOG_IO
166; SS:BP: Ptr to DIALOG
167; Returns:
168; Nothing
169; Corrupts:
170; AX, BX, CX, DX, DI
171;--------------------------------------------------------------------
172ALIGN JUMP_ALIGN
173DrawProgressBarFromDialogIoInDSSI:
174 call .GetFullCharsToCXandEmptyCharsToDXwithDialogIoInDSSI
175
176 mov al, PROGRESS_COMPLETE_CHARACTER
177 call .RepeatProgressCharacterCXtimesFromAL
178
179 mov cx, dx
180 mov al, PROGRESS_INCOMPLETE_CHARACTER
181 jmp SHORT .RepeatProgressCharacterCXtimesFromAL
182
183;--------------------------------------------------------------------
184; .GetFullCharsToCXandEmptyCharsToDXwithDialogIoInDSSI
185; Parameters:
186; DS:SI: Ptr to PROGRESS_DIALOG_IO
187; SS:BP: Ptr to DIALOG
188; Returns:
189; CX: Number of full progress bar characters
190; DX: Number of empty progress bar characters
191; Corrupts:
192; AX, BX
193;--------------------------------------------------------------------
194ALIGN JUMP_ALIGN
195.GetFullCharsToCXandEmptyCharsToDXwithDialogIoInDSSI:
196 call MenuLocation_GetMaxTextLineLengthToAX
197 mov cx, ax
198 mul WORD [si+PROGRESS_DIALOG_IO.wCurrentProgressValue]
199 call GetProgressLengthToBXfromProgressDialogIoInDSSI
200 div bx
201 xchg cx, ax ; AX = Text line length, CX = Number of full chars
202
203 sub ax, cx
204 xchg dx, ax ; DX = Number of empty chars
205 ret
206
207;--------------------------------------------------------------------
208; .RepeatProgressCharacterCXtimesFromAL
209; Parameters:
210; AL: Progress bar character to repeat
211; CX: Number of times to repeat the progress character
212; Returns:
213; Nothing
214; Corrupts:
215; AX, CX, DI
216;--------------------------------------------------------------------
217ALIGN JUMP_ALIGN
218.RepeatProgressCharacterCXtimesFromAL:
219 jcxz .NothingToRepeat
220 CALL_DISPLAY_LIBRARY PrintRepeatedCharacterFromALwithCountInCX
221ALIGN JUMP_ALIGN, ret
222.NothingToRepeat:
223 ret
224
225
226;--------------------------------------------------------------------
227; GetProgressLengthToBXfromProgressDialogIoInDSSI
228; Parameters:
229; DS:SI: Ptr to PROGRESS_DIALOG_IO
230; Returns:
231; BX: Progress length
232; Corrupts:
233; Nothing
234;--------------------------------------------------------------------
235ALIGN JUMP_ALIGN
236GetProgressLengthToBXfromProgressDialogIoInDSSI:
237 mov bx, [si+PROGRESS_DIALOG_IO.wMaxProgressValue]
238 sub bx, [si+PROGRESS_DIALOG_IO.wMinProgressValue]
239 ret
240
241
242;--------------------------------------------------------------------
243; DrawTimeElapsedFromDX
244; Parameters:
245; DX: Ticks elapsed
246; Returns:
247; Nothing
248; Corrupts:
249; AX, BX, CX, DI
250;--------------------------------------------------------------------
251ALIGN JUMP_ALIGN
252DrawTimeElapsedFromDX:
253 push si
254 push dx
255
256 mov si, g_szTimeElapsed
257 CALL_DISPLAY_LIBRARY PrintNullTerminatedStringFromCSSI
258 call FormatTicksFromDX
259
260 pop dx
261 pop si
262 ret
263
264
265;--------------------------------------------------------------------
266; DrawTimeLeftFromProgressDialogIoInDSSIwithTimeElapsedInDX
267; Parameters:
268; DX: Ticks elapsed
269; DS:SI: Ptr to PROGRESS_DIALOG_IO
270; Returns:
271; Nothing
272; Corrupts:
273; AX, BX, CX, DX, SI, DI
274;--------------------------------------------------------------------
275ALIGN JUMP_ALIGN
276DrawTimeLeftFromProgressDialogIoInDSSIwithTimeElapsedInDX:
277 push si
278 mov si, g_szTimeLeft
279 CALL_DISPLAY_LIBRARY PrintNullTerminatedStringFromCSSI
280 pop si
281
282 mov cx, [si+PROGRESS_DIALOG_IO.wCurrentProgressValue]
283 mov ax, [si+PROGRESS_DIALOG_IO.wMaxProgressValue]
284 sub ax, cx
285 mul dx ; Progress left * elapsed time
286
287 sub cx, [si+PROGRESS_DIALOG_IO.wMinProgressValue]
288 jcxz .PreventDivisionByZero
289 div cx ; AX = Estimated ticks left
290 xchg dx, ax
291 jmp SHORT FormatTicksFromDX
292.PreventDivisionByZero:
293 xor dx, dx
294 ; Fall to FormatTicksFromDX
295
296
297;--------------------------------------------------------------------
298; FormatTicksFromDX
299; Parameters:
300; DX: Ticks to format
301; Returns:
302; Nothing
303; Corrupts:
304; AX, CX, DX, SI, DI
305;--------------------------------------------------------------------
306ALIGN JUMP_ALIGN
307FormatTicksFromDX:
308 push bp
309
310 mov bp, sp
311 mov si, g_szTimeFormat
312 call TimerTicks_GetMinutesToAXfromTicksInDX
313 push ax
314 call TimerTicks_GetSecondsToAXfromTicksInDX
315 push ax
316 CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
317
318 pop bp
319 ret
Note: See TracBrowser for help on using the repository browser.