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

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

Changes to Assembly Library:

  • Progress dialog now prevents max progress value from being zero.
File size: 8.4 KB
RevLine 
[41]1; File name : DialogProgress.asm
2; Project name : Assembly Library
3; Created date : 15.8.2010
[64]4; Last update : 5.12.2010
[41]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:
[48]35; AX, BX, CX, DX, SI, DI
[41]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:
[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
[64]85 MAX_U WORD [si+PROGRESS_DIALOG_IO.wMaxProgressValue], 0FFFFh ; Max cannot be zero
[41]86 jmp SHORT CalculateProgressNeededBeforeUpdatingCharacter
87
88
89ALIGN JUMP_ALIGN
90.IdleProcessing:
91 call MenuInit_GetUserDataToDSSI
92 les di, [bp+DIALOG.fpDialogIO]
[64]93 push bp
[41]94 call [es:di+PROGRESS_DIALOG_IO.fnTaskWithParamInDSSI]
[64]95 pop bp
[41]96 call MenuInit_CloseMenuWindow
97 stc
98 ret
99
100
101ALIGN JUMP_ALIGN
102.RefreshItemFromCX:
103 lds si, [bp+DIALOG.fpDialogIO]
104 call DrawProgressBarFromDialogIoInDSSI
105 stc
106 ret
107
108
109ALIGN JUMP_ALIGN
110.RefreshInformation:
111 lds si, [bp+DIALOG.fpDialogIO]
112 call TimerTicks_ReadFromBdaToAX
113 sub ax, [si+PROGRESS_DIALOG_IO.wStartTimeTicks]
114 xchg dx, ax
115 call DrawTimeElapsedFromDX
116 call DrawTimeLeftFromProgressDialogIoInDSSIwithTimeElapsedInDX
117 stc
118 ret
119
120
121ALIGN WORD_ALIGN
122.rgfnEventHandlers:
123istruc MENUEVENT
124 at MENUEVENT.InitializeMenuinitFromDSSI, dw .InitializeMenuinitFromDSSI
[58]125 at MENUEVENT.ExitMenu, dw Dialog_EventExitMenu
[41]126 at MENUEVENT.IdleProcessing, dw .IdleProcessing
127 at MENUEVENT.ItemHighlightedFromCX, dw Dialog_EventNotHandled
128 at MENUEVENT.ItemSelectedFromCX, dw Dialog_EventNotHandled
129 at MENUEVENT.KeyStrokeInAX, dw Dialog_EventNotHandled
130 at MENUEVENT.RefreshTitle, dw Dialog_EventRefreshTitle
131 at MENUEVENT.RefreshInformation, dw .RefreshInformation
132 at MENUEVENT.RefreshItemFromCX, dw .RefreshItemFromCX
133iend
134
135
136;--------------------------------------------------------------------
137; CalculateProgressNeededBeforeUpdatingCharacter
138; Parameters:
139; DS:SI: Ptr to PROGRESS_DIALOG_IO
140; SS:BP: Ptr to DIALOG
141; Returns:
142; CF: Set since event handled
143; Corrupts:
144; AX, BX, DX, SI, DS
145;--------------------------------------------------------------------
146ALIGN JUMP_ALIGN
147CalculateProgressNeededBeforeUpdatingCharacter:
148 call MenuLocation_GetMaxTextLineLengthToAX
149 call GetProgressLengthToBXfromProgressDialogIoInDSSI
150 xchg ax, bx
151 xor dx, dx
152 div bx
153 mov [si+PROGRESS_DIALOG_IO.wProgressPerCharacter], ax
154 stc
155 ret
156
157
158;--------------------------------------------------------------------
159; DrawProgressBarFromDialogIoInDSSI
160; Parameters:
161; DS:SI: Ptr to PROGRESS_DIALOG_IO
162; SS:BP: Ptr to DIALOG
163; Returns:
164; Nothing
165; Corrupts:
166; AX, BX, CX, DX, DI
167;--------------------------------------------------------------------
168ALIGN JUMP_ALIGN
169DrawProgressBarFromDialogIoInDSSI:
170 call .GetFullCharsToCXandEmptyCharsToDXwithDialogIoInDSSI
171 jcxz .DrawEmptyCharsOnly
172
[45]173 mov al, PROGRESS_COMPLETE_CHARACTER
[41]174 CALL_DISPLAY_LIBRARY PrintRepeatedCharacterFromALwithCountInCX
175
176.DrawEmptyCharsOnly:
177 mov cx, dx
178 jcxz .NothingLeftToDraw
[45]179 mov al, PROGRESS_INCOMPLETE_CHARACTER
[41]180 CALL_DISPLAY_LIBRARY PrintRepeatedCharacterFromALwithCountInCX
181
182.NothingLeftToDraw:
183 ret
184
185;--------------------------------------------------------------------
186; .GetFullCharsToCXandEmptyCharsToDXwithDialogIoInDSSI
187; Parameters:
188; DS:SI: Ptr to PROGRESS_DIALOG_IO
189; SS:BP: Ptr to DIALOG
190; Returns:
191; CX: Number of full progress bar characters
192; DX: Number of empty progress bar characters
193; Corrupts:
194; AX, BX
195;--------------------------------------------------------------------
196ALIGN JUMP_ALIGN
197.GetFullCharsToCXandEmptyCharsToDXwithDialogIoInDSSI:
198 call MenuLocation_GetMaxTextLineLengthToAX
199 mov cx, ax
200 mul WORD [si+PROGRESS_DIALOG_IO.wCurrentProgressValue]
201 call GetProgressLengthToBXfromProgressDialogIoInDSSI
202 div bx
203 xchg cx, ax ; AX = Text line length, CX = Number of full chars
204
205 sub ax, cx
206 xchg dx, ax ; DX = Number of empty chars
207 ret
208
209
210;--------------------------------------------------------------------
211; GetProgressLengthToBXfromProgressDialogIoInDSSI
212; Parameters:
213; DS:SI: Ptr to PROGRESS_DIALOG_IO
214; Returns:
215; BX: Progress length
216; Corrupts:
217; Nothing
218;--------------------------------------------------------------------
219ALIGN JUMP_ALIGN
220GetProgressLengthToBXfromProgressDialogIoInDSSI:
221 mov bx, [si+PROGRESS_DIALOG_IO.wMaxProgressValue]
222 sub bx, [si+PROGRESS_DIALOG_IO.wMinProgressValue]
223 ret
224
225
226;--------------------------------------------------------------------
227; DrawTimeElapsedFromDX
228; Parameters:
229; DX: Ticks elapsed
230; Returns:
231; Nothing
232; Corrupts:
233; AX, BX, CX, DI
234;--------------------------------------------------------------------
235ALIGN JUMP_ALIGN
236DrawTimeElapsedFromDX:
237 push si
238 push dx
239
240 mov si, g_szTimeElapsed
241 CALL_DISPLAY_LIBRARY PrintNullTerminatedStringFromCSSI
242 call FormatTicksFromDX
243
244 pop dx
245 pop si
246 ret
247
248
249;--------------------------------------------------------------------
250; DrawTimeLeftFromProgressDialogIoInDSSIwithTimeElapsedInDX
251; Parameters:
252; DX: Ticks elapsed
253; DS:SI: Ptr to PROGRESS_DIALOG_IO
254; Returns:
255; Nothing
256; Corrupts:
257; AX, BX, CX, DX, SI, DI
258;--------------------------------------------------------------------
259ALIGN JUMP_ALIGN
260DrawTimeLeftFromProgressDialogIoInDSSIwithTimeElapsedInDX:
261 push si
262 mov si, g_szTimeLeft
263 CALL_DISPLAY_LIBRARY PrintNullTerminatedStringFromCSSI
264 pop si
265
266 mov cx, [si+PROGRESS_DIALOG_IO.wCurrentProgressValue]
267 mov ax, [si+PROGRESS_DIALOG_IO.wMaxProgressValue]
268 sub ax, cx
269 mul dx ; Progress left * elapsed time
270
271 sub cx, [si+PROGRESS_DIALOG_IO.wMinProgressValue]
272 jcxz .PreventDivisionByZero
273 div cx ; AX = Estimated ticks left
274 xchg dx, ax
275 jmp SHORT FormatTicksFromDX
276.PreventDivisionByZero:
277 xor dx, dx
278 ; Fall to FormatTicksFromDX
279
280
281;--------------------------------------------------------------------
282; FormatTicksFromDX
283; Parameters:
284; DX: Ticks to format
285; Returns:
286; Nothing
287; Corrupts:
288; AX, CX, DX, SI, DI
289;--------------------------------------------------------------------
290ALIGN JUMP_ALIGN
291FormatTicksFromDX:
292 push bp
293
294 mov bp, sp
295 mov si, g_szTimeFormat
296 call TimerTicks_GetMinutesToAXfromTicksInDX
297 push ax
298 call TimerTicks_GetSecondsToAXfromTicksInDX
299 push ax
300 CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
301
302 pop bp
303 ret
Note: See TracBrowser for help on using the repository browser.