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

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

Changes to Assembly Library:

  • Progress Bar now displays properly.
File size: 8.8 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 MAX_U WORD [si+PROGRESS_DIALOG_IO.wMaxProgressValue], 1 ; Max cannot be zero
86 jmp SHORT CalculateProgressNeededBeforeUpdatingCharacter
87
88
89ALIGN JUMP_ALIGN
90.IdleProcessing:
91 call MenuInit_GetUserDataToDSSI
92 les di, [bp+DIALOG.fpDialogIO]
93 push bp
94 call [es:di+PROGRESS_DIALOG_IO.fnTaskWithParamInDSSI]
95 pop bp
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
125 at MENUEVENT.ExitMenu, dw Dialog_EventExitMenu
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
172 mov al, PROGRESS_COMPLETE_CHARACTER
173 call .RepeatProgressCharacterCXtimesFromAL
174
175 mov cx, dx
176 mov al, PROGRESS_INCOMPLETE_CHARACTER
177 jmp SHORT .RepeatProgressCharacterCXtimesFromAL
178
179;--------------------------------------------------------------------
180; .GetFullCharsToCXandEmptyCharsToDXwithDialogIoInDSSI
181; Parameters:
182; DS:SI: Ptr to PROGRESS_DIALOG_IO
183; SS:BP: Ptr to DIALOG
184; Returns:
185; CX: Number of full progress bar characters
186; DX: Number of empty progress bar characters
187; Corrupts:
188; AX, BX
189;--------------------------------------------------------------------
190ALIGN JUMP_ALIGN
191.GetFullCharsToCXandEmptyCharsToDXwithDialogIoInDSSI:
192 call MenuLocation_GetMaxTextLineLengthToAX
193 mov cx, ax
194 mul WORD [si+PROGRESS_DIALOG_IO.wCurrentProgressValue]
195 call GetProgressLengthToBXfromProgressDialogIoInDSSI
196 div bx
197 xchg cx, ax ; AX = Text line length, CX = Number of full chars
198
199 sub ax, cx
200 xchg dx, ax ; DX = Number of empty chars
201 ret
202
203;--------------------------------------------------------------------
204; .RepeatProgressCharacterCXtimesFromAL
205; Parameters:
206; AL: Progress bar character to repeat
207; CX: Number of times to repeat the progress character
208; Returns:
209; Nothing
210; Corrupts:
211; AX, CX, DI
212;--------------------------------------------------------------------
213ALIGN JUMP_ALIGN
214.RepeatProgressCharacterCXtimesFromAL:
215 jcxz .NothingToRepeat
216 CALL_DISPLAY_LIBRARY PrintRepeatedCharacterFromALwithCountInCX
217ALIGN JUMP_ALIGN, ret
218.NothingToRepeat:
219 ret
220
221
222;--------------------------------------------------------------------
223; GetProgressLengthToBXfromProgressDialogIoInDSSI
224; Parameters:
225; DS:SI: Ptr to PROGRESS_DIALOG_IO
226; Returns:
227; BX: Progress length
228; Corrupts:
229; Nothing
230;--------------------------------------------------------------------
231ALIGN JUMP_ALIGN
232GetProgressLengthToBXfromProgressDialogIoInDSSI:
233 mov bx, [si+PROGRESS_DIALOG_IO.wMaxProgressValue]
234 sub bx, [si+PROGRESS_DIALOG_IO.wMinProgressValue]
235 ret
236
237
238;--------------------------------------------------------------------
239; DrawTimeElapsedFromDX
240; Parameters:
241; DX: Ticks elapsed
242; Returns:
243; Nothing
244; Corrupts:
245; AX, BX, CX, DI
246;--------------------------------------------------------------------
247ALIGN JUMP_ALIGN
248DrawTimeElapsedFromDX:
249 push si
250 push dx
251
252 mov si, g_szTimeElapsed
253 CALL_DISPLAY_LIBRARY PrintNullTerminatedStringFromCSSI
254 call FormatTicksFromDX
255
256 pop dx
257 pop si
258 ret
259
260
261;--------------------------------------------------------------------
262; DrawTimeLeftFromProgressDialogIoInDSSIwithTimeElapsedInDX
263; Parameters:
264; DX: Ticks elapsed
265; DS:SI: Ptr to PROGRESS_DIALOG_IO
266; Returns:
267; Nothing
268; Corrupts:
269; AX, BX, CX, DX, SI, DI
270;--------------------------------------------------------------------
271ALIGN JUMP_ALIGN
272DrawTimeLeftFromProgressDialogIoInDSSIwithTimeElapsedInDX:
273 push si
274 mov si, g_szTimeLeft
275 CALL_DISPLAY_LIBRARY PrintNullTerminatedStringFromCSSI
276 pop si
277
278 mov cx, [si+PROGRESS_DIALOG_IO.wCurrentProgressValue]
279 mov ax, [si+PROGRESS_DIALOG_IO.wMaxProgressValue]
280 sub ax, cx
281 mul dx ; Progress left * elapsed time
282
283 sub cx, [si+PROGRESS_DIALOG_IO.wMinProgressValue]
284 jcxz .PreventDivisionByZero
285 div cx ; AX = Estimated ticks left
286 xchg dx, ax
287 jmp SHORT FormatTicksFromDX
288.PreventDivisionByZero:
289 xor dx, dx
290 ; Fall to FormatTicksFromDX
291
292
293;--------------------------------------------------------------------
294; FormatTicksFromDX
295; Parameters:
296; DX: Ticks to format
297; Returns:
298; Nothing
299; Corrupts:
300; AX, CX, DX, SI, DI
301;--------------------------------------------------------------------
302ALIGN JUMP_ALIGN
303FormatTicksFromDX:
304 push bp
305
306 mov bp, sp
307 mov si, g_szTimeFormat
308 call TimerTicks_GetMinutesToAXfromTicksInDX
309 push ax
310 call TimerTicks_GetSecondsToAXfromTicksInDX
311 push ax
312 CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
313
314 pop bp
315 ret
Note: See TracBrowser for help on using the repository browser.