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