source: xtideuniversalbios/trunk/Configurator/Src/Libraries/menu/menuprog.asm@ 122

Last change on this file since 122 was 2, checked in by Tomi Tilli, 14 years ago
File size: 6.0 KB
Line 
1; File name : menuprog.asm
2; Project name : Menu library
3; Created date : 23.11.2009
4; Last update : 23.11.2009
5; Author : Tomi Tilli
6; Description : ASM library to menu system.
7; Contains functions for displaying progress bar dialog.
8
9;--------------- Equates -----------------------------
10
11; Dialog init and return variables.
12; This is an expanded MSGVARS struct.
13struc PDLGVARS
14 .msgVars resb MSGVARS_size
15
16 ; Dialog parameters
17 .fpUser resb 4 ; Far pointer to user specific data
18 .ffnTask resb 4 ; Far pointer to task function
19
20 ; Return variables for different dialogs
21 .wRetUser resb 2 ; User specific return variable
22endstruc
23
24;--------------------------------------------------------------------
25; Function prototype for Progress Task function (PDLGVARS.fnTask).
26; Cursor will be set to Title string location so user may modify the
27; title string if needed.
28; Remember to return with RETF instead of RET!
29; Parameters:
30; DS:SI: User specified far pointer
31; Returns:
32; AX: User specified return code if CF set
33; Task completion percentage (0...100) if CF cleared
34; CF: Set if task was completed or cancelled
35; Cleared if task must be continued
36; Corrupts registers:
37; BX, CX, DX
38;--------------------------------------------------------------------
39
40
41;-------------- Private global variables -------------
42; Section containing initialized data
43;SECTION .data
44
45
46;-------------- Public functions ---------------------
47; Section containing code
48SECTION .text
49
50
51;--------------------------------------------------------------------
52; Displays progress bar dialog.
53;
54; MenuProg_Show
55; Parameters:
56; BL: Dialog width with borders included
57; BH: Dialog height with borders included
58; SS:BP: Ptr to MENUVARS
59; ES:DI: Far ptr to user specified task function
60; DS:SI: User specified far pointer
61; Returns:
62; AX: User specified return code
63; Corrupts registers:
64; BX, CX, DX
65;--------------------------------------------------------------------
66ALIGN JUMP_ALIGN
67MenuProg_Show:
68 ; Create stack frame
69 eENTER PDLGVARS_size, 0
70 sub bp, PDLGVARS_size ; Point to PDLGVARS
71
72 ; Initialize menu variables
73 mov [bp+MENUVARS.wSize], bx ; Menu size
74 mov [bp+PDLGVARS.fpUser], si ; Store user defined...
75 mov [bp+PDLGVARS.fpUser+2], ds ; ...far pointer
76 mov [bp+PDLGVARS.ffnTask], di ; Store far ptr to...
77 mov [bp+PDLGVARS.ffnTask+2], es ; ...task function
78 mov WORD [bp+MENUVARS.wTopDwnH], 0101h ; 1 title line, 1 info line
79 mov WORD [bp+MENUVARS.fnEvent], MenuProg_Event
80
81 ; Enter menu
82 call MenuCrsr_GetCenter ; Get X and Y coordinates to DX
83 xor cx, cx ; No menuitems
84 xor bx, bx ; Menu flags
85 xor ax, ax ; Selection timeout (disable)
86 call Menu_Init ; Returns only after dlg closed
87
88 ; Return
89 mov ax, [bp+PDLGVARS.wRetUser] ; Load user return variable
90 add bp, PDLGVARS_size ; Point to old BP
91 eLEAVE ; Destroy stack frame
92 ret
93
94
95;-------------- Private functions ---------------------
96
97;--------------------------------------------------------------------
98; Draws progress bar.
99;
100; MenuProg_DrawBar
101; Parameters:
102; AX: Completion percentage (0...100)
103; SS:BP: Ptr to PDLGVARS
104; Returns:
105; Nothing
106; Corrupts registers:
107; AX, BX, CX, DX
108;--------------------------------------------------------------------
109ALIGN JUMP_ALIGN
110MenuProg_DrawBar:
111 ; Calculate number of chars to draw
112 eMOVZX cx, BYTE [bp+MENUVARS.bWidth] ; Dialog width to CX
113 sub cl, 4 ; Sub borders, CX=bar width
114 mul cl ; AX=bar with * percentage
115 mov bx, 100 ; Prepare to div by 100
116 div bl ; AL=Full char cnt
117 sub cl, al ; CX=Empty char cnt
118 mov bl, al ; BX=full char cnt
119
120 ; Draw full chars
121 mov dl, FULL_BLCK ; Load full block char
122 xchg bx, cx ; CX=full chars, BX=empty chars
123 call Print_Repeat ; Repeat chars
124 mov dl, MIN_BLCK ; Load min block char
125 mov cx, bx ; CX=empty chars
126 call Print_Repeat ; Repeat chars
127 ret
128
129
130;--------------------------------------------------------------------
131; File dialog event handler.
132;
133; MenuProg_Event
134; Parameters:
135; BX: Callback event
136; CX: Selected menuitem index
137; DX: Event parameter (event specific)
138; SS:BP: Ptr to PDLGVARS
139; Returns:
140; AH: Event specific or unused
141; AL: 1=Event processed
142; 0=Event not processed (default action if any)
143; Corrupts registers:
144; BX, CX, DX
145;--------------------------------------------------------------------
146ALIGN JUMP_ALIGN
147MenuProg_Event:
148 cmp bx, EVNT_MNU_UPD ; Update menu string?
149 je .EventUpd ; If so, jump to update
150 xor ax, ax ; Event not processed
151 ret
152
153ALIGN JUMP_ALIGN
154.EventHandled: ; Return point from all handled events
155 mov ax, 1
156 ret
157
158;--------------------------------------------------------------------
159; EVNT_MNU_UPD event handler.
160;
161; .EventUpd
162; Parameters:
163; CX: Index of menuitem to update (MFL_UPD_ITEM only)
164; DL: Update flag:
165; MFL_UPD_TITLE Set to update title string
166; MFL_UPD_NFO Set to update info string
167; MFL_UPD_ITEM Set to update menuitem string
168; SS:BP: Ptr to PDLGVARS
169; Returns:
170; AX: 1 (Event processed)
171; Corrupts registers:
172; BX, CX, DX
173;--------------------------------------------------------------------
174ALIGN JUMP_ALIGN
175.EventUpd:
176 test dl, MFL_UPD_NFO ; Update info?
177 jz .EventHandled ; If not, do nothing and return
178
179 ; Start task
180 push ds
181 push si
182 mov si, [bp+PDLGVARS.fpUser] ; Load offset to user ptr
183 mov ds, [bp+PDLGVARS.fpUser+2] ; Load segment to user ptr
184 xor ax, ax ; Zero percent
185ALIGN JUMP_ALIGN
186.TaskLoop:
187 push ax
188 call MenuCrsr_PointInfo ; Point cursor to info string
189 pop ax
190 call MenuProg_DrawBar ; Draw progress bar
191 call MenuCrsr_PointTitle ; Point cursor to title string
192 call far [bp+PDLGVARS.ffnTask] ; Call task function
193 jnc .TaskLoop ; Loop until task complete
194
195 ; Task complete
196 mov [bp+PDLGVARS.wRetUser], ax ; Store user return value
197 pop si
198 pop ds
199 jmp MenuDlg_ExitHandler ; Close progress bar
Note: See TracBrowser for help on using the repository browser.