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

Last change on this file since 421 was 376, checked in by gregli@…, 13 years ago

WIDE checkin... Added copyright and license information to sorce files, as per the GPL instructions for usage.

File size: 9.0 KB
RevLine 
[41]1; Project name : Assembly Library
2; Description : Displays progress bar dialog and starts progress task.
3
[376]4;
5; XTIDE Universal BIOS and Associated Tools
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.
12;
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
16; GNU General Public License for more details.
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
19
20
[41]21; Section containing code
22SECTION .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;--------------------------------------------------------------------
34ALIGN JUMP_ALIGN
35DialogProgress_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;--------------------------------------------------------------------
50ALIGN JUMP_ALIGN
51DialogProgress_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
60ALIGN 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
71ALIGN 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;--------------------------------------------------------------------
88ALIGN JUMP_ALIGN
89ProgressEventHandler:
90 jmp [cs:bx+.rgfnEventHandlers]
91
92
93ALIGN 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
101 ; 0 = 65536 but it needs to be adjusted to 65535 prevent division by zero
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
108ALIGN 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
120ALIGN JUMP_ALIGN
121.RefreshItemFromCX:
122 lds si, [bp+DIALOG.fpDialogIO]
123 call DrawProgressBarFromDialogIoInDSSI
124 stc
125 ret
126
127
128ALIGN 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
140ALIGN WORD_ALIGN
141.rgfnEventHandlers:
142istruc 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
152iend
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;--------------------------------------------------------------------
165ALIGN JUMP_ALIGN
166CalculateProgressNeededBeforeUpdatingCharacter:
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;--------------------------------------------------------------------
187ALIGN JUMP_ALIGN
188DrawProgressBarFromDialogIoInDSSI:
[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;--------------------------------------------------------------------
216ALIGN JUMP_ALIGN
217.RepeatProgressCharacterCXtimesFromAL:
218 jcxz .NothingToRepeat
219 CALL_DISPLAY_LIBRARY PrintRepeatedCharacterFromALwithCountInCX
220ALIGN JUMP_ALIGN, ret
221.NothingToRepeat:
222 ret
[41]223
[69]224
[41]225;--------------------------------------------------------------------
226; GetProgressLengthToBXfromProgressDialogIoInDSSI
227; Parameters:
228; DS:SI: Ptr to PROGRESS_DIALOG_IO
229; Returns:
230; BX: Progress length
231; Corrupts:
232; Nothing
233;--------------------------------------------------------------------
234ALIGN JUMP_ALIGN
235GetProgressLengthToBXfromProgressDialogIoInDSSI:
236 mov bx, [si+PROGRESS_DIALOG_IO.wMaxProgressValue]
237 sub bx, [si+PROGRESS_DIALOG_IO.wMinProgressValue]
238 ret
239
[181]240
[41]241;--------------------------------------------------------------------
242; DrawTimeElapsedFromDX
243; Parameters:
244; DX: Ticks elapsed
245; Returns:
246; Nothing
247; Corrupts:
248; AX, BX, CX, DI
249;--------------------------------------------------------------------
250ALIGN JUMP_ALIGN
251DrawTimeElapsedFromDX:
252 push si
253 push dx
254
255 mov si, g_szTimeElapsed
256 CALL_DISPLAY_LIBRARY PrintNullTerminatedStringFromCSSI
257 call FormatTicksFromDX
258
259 pop dx
260 pop si
261 ret
262
263
264;--------------------------------------------------------------------
265; DrawTimeLeftFromProgressDialogIoInDSSIwithTimeElapsedInDX
266; Parameters:
267; DX: Ticks elapsed
268; DS:SI: Ptr to PROGRESS_DIALOG_IO
269; Returns:
270; Nothing
271; Corrupts:
272; AX, BX, CX, DX, SI, DI
273;--------------------------------------------------------------------
274ALIGN JUMP_ALIGN
275DrawTimeLeftFromProgressDialogIoInDSSIwithTimeElapsedInDX:
276 push si
277 mov si, g_szTimeLeft
278 CALL_DISPLAY_LIBRARY PrintNullTerminatedStringFromCSSI
279 pop si
280
281 mov cx, [si+PROGRESS_DIALOG_IO.wCurrentProgressValue]
282 mov ax, [si+PROGRESS_DIALOG_IO.wMaxProgressValue]
283 sub ax, cx
284 mul dx ; Progress left * elapsed time
285
286 sub cx, [si+PROGRESS_DIALOG_IO.wMinProgressValue]
[181]287 jz SHORT .PreventDivisionByZero
[41]288 div cx ; AX = Estimated ticks left
289 xchg dx, ax
[181]290 SKIP2B f ; cmp ax, <next instruction>
[41]291.PreventDivisionByZero:
292 xor dx, dx
293 ; Fall to FormatTicksFromDX
294
295
296;--------------------------------------------------------------------
297; FormatTicksFromDX
298; Parameters:
299; DX: Ticks to format
300; Returns:
301; Nothing
302; Corrupts:
303; AX, CX, DX, SI, DI
304;--------------------------------------------------------------------
305ALIGN JUMP_ALIGN
306FormatTicksFromDX:
307 push bp
308
309 mov bp, sp
310 mov si, g_szTimeFormat
311 call TimerTicks_GetMinutesToAXfromTicksInDX
312 push ax
313 call TimerTicks_GetSecondsToAXfromTicksInDX
314 push ax
315 CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
316
317 pop bp
318 ret
Note: See TracBrowser for help on using the repository browser.