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

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

Initial commit for Assembly Library.

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