source: xtideuniversalbios/trunk/Configurator/Src/Libraries/menu/menufile.asm@ 68

Last change on this file since 68 was 2, checked in by Tomi Tilli, 15 years ago
File size: 9.8 KB
Line 
1; File name : menufile.asm
2; Project name : Menu library
3; Created date : 20.11.2009
4; Last update : 8.1.2010
5; Author : Tomi Tilli
6; Description : ASM library to menu system.
7; Contains functions for displaying file dialog.
8
9;--------------- Equates -----------------------------
10
11; Dialog init and return variables.
12; This is an expanded MSGVARS struct.
13struc FDLGVARS
14 .msgVars resb MSGVARS_size
15
16 ; Dialog parameters
17 .fpFileSrch resb 4 ; Far pointer to file search string
18 .wFileCnt resb 2 ; Number of directories and files to display
19 .wDrvCnt resb 2 ; Valid drive letter count
20
21 ; Return variables for different dialogs
22 .fpDTA resb 4 ; Ptr to DTA for selected file
23 .fSuccess resb 1 ; Was data inputted successfully by user
24 resb 1 ; Alignment
25endstruc
26
27
28;-------------- Private global variables -------------
29; Section containing initialized data
30;SECTION .data
31
32g_szDir: db "[%S]",STOP
33g_szDrv: db "[%c:]",STOP
34
35
36;-------------- Public functions ---------------------
37; Section containing code
38SECTION .text
39
40
41;--------------------------------------------------------------------
42; Displays file dialog.
43;
44; MenuFile_ShowDlg
45; Parameters:
46; BL: Dialog width with borders included
47; SS:BP: Ptr to MENUVARS
48; ES:DI: Ptr to STOP terminated string to display
49; DS:SI: Ptr to file search string (* and ? wildcards supported)
50; Returns:
51; DS:SI: Ptr to selected file name string
52; CF: Set if user data inputted successfully
53; Cleared is input cancelled
54; Corrupts registers:
55; BX, CX
56;--------------------------------------------------------------------
57ALIGN JUMP_ALIGN
58MenuFile_ShowDlg:
59 ; Create stack frame
60 eENTER FDLGVARS_size, 0
61 sub bp, FDLGVARS_size ; Point to FDLGVARS
62
63 ; Initialize menu variables
64 mov bh, CNT_SCRN_ROW ; Menu height
65 mov [bp+MENUVARS.wSize], bx ; Menu size
66 mov [bp+MSGVARS.wStrOff], di ; Store far ptr...
67 mov [bp+MSGVARS.wStrSeg], es ; ...to info string to display
68 mov [bp+FDLGVARS.fpFileSrch], si ; Store far pointer...
69 mov [bp+FDLGVARS.fpFileSrch+2], ds ; ...to file search string
70 ;call File_GetValidDrvCnt ; Get drive letter count to CX (drive support broken! Works on DOSBox, not on DOS 6.22)
71 xor cx, cx
72 mov [bp+FDLGVARS.wDrvCnt], cx
73 mov WORD [bp+MENUVARS.fnEvent], MenuFile_Event
74 mov BYTE [bp+FDLGVARS.fSuccess], 0 ; For user cancel
75 call MenuMsg_GetLineCnt ; Get Info line count to CX
76 xchg cl, ch ; CH=Info lines, CL=Title lines
77 mov [bp+MENUVARS.wTopDwnH], cx
78
79 ; Enter menu
80 mov dx, si ; File search str ptr to DS:DX
81 call MenuFile_GetItemCnt ; Get menuitem count to CX
82 call MenuCrsr_GetCenter ; Get X and Y coordinates to DX
83 xor ax, ax ; Selection timeout (disable)
84 xor bx, bx ; Menu flags
85 call Menu_Init ; Returns only after dlg closed
86
87 ; Return
88 mov si, [bp+FDLGVARS.fpDTA] ; Load offset to return DTA
89 mov ds, [bp+FDLGVARS.fpDTA+2] ; Load segment to return DTA
90 mov bl, [bp+FDLGVARS.fSuccess] ; Load success flag
91 add bp, FDLGVARS_size ; Point to old BP
92 eLEAVE ; Destroy stack frame
93 rcr bl, 1 ; Move success flag to CF
94 ret
95
96
97;-------------- Private functions ---------------------
98
99;--------------------------------------------------------------------
100; File dialog event handler.
101;
102; MenuFile_Event
103; Parameters:
104; DS:DX: Ptr to file search string (for example *.* or C:\temp\*.txt)
105; SS:BP: Ptr to FDLGVARS
106; Returns:
107; CX: Number of menuitems to display files and drives
108; Corrupts registers:
109; AX
110;--------------------------------------------------------------------
111ALIGN JUMP_ALIGN
112MenuFile_GetItemCnt:
113 call File_FindAndCount ; Get message line count to CX
114 mov [bp+FDLGVARS.wFileCnt], cx ; Store file and dir count
115 add cx, [bp+FDLGVARS.wDrvCnt] ; Add drive letter count to CX
116 ret
117
118
119;--------------------------------------------------------------------
120; Directory, File and Drive rendering functions for menuitems.
121; Cursor is assumed to be on correct position when this function is called.
122;
123; MenuFile_DrawItem
124; Parameters:
125; CX: Index of menuitem to draw
126; SS:BP: Ptr to FDLGVARS
127; Returns:
128; Nothing
129; Corrupts registers:
130; AX, BX, CX, DX
131;--------------------------------------------------------------------
132ALIGN JUMP_ALIGN
133MenuFile_DrawItem:
134 push ds
135 mov dx, [bp+FDLGVARS.fpFileSrch] ; Load ptr to file search str
136 mov ds, [bp+FDLGVARS.fpFileSrch+2]
137 call File_GetDTA ; Get DTA ptr to DS:BX
138 jc .DrawDrv ; No dir or file, draw drive
139 test BYTE [bx+DTA.bFileAttr], FLG_FATTR_DIR
140 jnz .DrawDir
141
142;--------------------------------------------------------------------
143; Directory, File and Drive rendering for menuitems.
144; Cursor is assumed to be on correct position.
145;
146; .DrawFile Draws file menuitem
147; .DrawDir Draws directory menuitem
148; .DrawDrv Draws drive menuitem
149; Parameters:
150; CX: Index of menuitem to draw
151; DS:BX: Ptr to DTA for menuitem (not for .DrawDrv)
152; SS:BP: Ptr to FDLGVARS
153; Returns:
154; Nothing
155; Corrupts registers:
156; AX, BX, CX, DX
157;--------------------------------------------------------------------
158.DrawFile:
159 lea dx, [bx+DTA.szFile] ; DS:DX now points to filename string
160 PRINT_STR
161 pop ds
162 ret
163ALIGN JUMP_ALIGN
164.DrawDir:
165 push si
166 lea ax, [bx+DTA.szFile] ; Dir string offset to AX
167 push ds ; Push dir string segment
168 push ax ; Push dir string offset
169 push cs ; Copy CS...
170 pop ds ; ...to DS for format string
171 mov si, g_szDir ; Format string now in DS:SI
172 call Print_Format
173 add sp, 4 ; Clean stack variables
174 pop si
175 pop ds
176 ret
177ALIGN JUMP_ALIGN
178.DrawDrv:
179 push si
180 sub cx, [bp+FDLGVARS.wFileCnt] ; Menuitem to valid drive index
181 call File_GetNthValidDrv ; Get letter to AX
182 push ax ; Push drive letter
183 push cs ; Copy CS...
184 pop ds ; ...to DS for format string
185 mov si, g_szDrv ; Format string now in DS:SI
186 call Print_Format
187 add sp, 2 ; Clean stack variables
188 pop si
189 pop ds
190 ret
191
192
193;--------------------------------------------------------------------
194; File dialog event handler.
195;
196; MenuFile_Event
197; Parameters:
198; BX: Callback event
199; CX: Selected menuitem index
200; DX: Event parameter (event specific)
201; SS:BP: Ptr to FDLGVARS
202; Returns:
203; AH: Event specific or unused
204; AL: 1=Event processed
205; 0=Event not processed (default action if any)
206; Corrupts registers:
207; BX, CX, DX
208;--------------------------------------------------------------------
209ALIGN JUMP_ALIGN
210MenuFile_Event:
211 cmp bx, EVNT_MNU_UPD ; Above last supported?
212 ja .EventNotHandled ; If so, return
213 shl bx, 1 ; Shift for word lookup
214 jmp [cs:bx+.rgwEventJump] ; Jumpt to handle event
215ALIGN WORD_ALIGN
216.rgwEventJump:
217 dw .EventExit ; 0, EVNT_MNU_EXIT
218 dw .EventSelChg ; 1, EVNT_MMU_SELCHG
219 dw .EventSelSet ; 2, EVNT_MNU_SELSET
220 dw .EventKey ; 3, EVNT_MNU_KEY
221 dw .EventUpd ; 4, EVNT_MNU_UPD
222
223; Events that do not require any handling
224ALIGN JUMP_ALIGN
225.EventSelChg:
226.EventKey:
227.EventNotHandled:
228 xor ax, ax ; Event not processed
229 ret
230ALIGN JUMP_ALIGN
231.EventExit:
232.EventHandled: ; Return point from all handled events
233 mov ax, 1
234 ret
235
236
237;--------------------------------------------------------------------
238; EVNT_MNU_SELSET event handler.
239;
240; .EventSelSet
241; Parameters:
242; CX: Index of menuitem that user selected
243; SS:BP: Ptr to FDLGVARS
244;--------------------------------------------------------------------
245ALIGN JUMP_ALIGN
246.EventSelSet:
247 push ds
248 cmp cx, [bp+FDLGVARS.wFileCnt] ; Selecting file or dir?
249 jae .ChgDrv ; If not, must be drive
250 mov dx, [bp+FDLGVARS.fpFileSrch] ; Load ptr to file search str
251 mov ds, [bp+FDLGVARS.fpFileSrch+2]
252 call File_GetDTA ; Get DTA ptr to DS:BX
253 rcl al, 1 ; CF to AL
254 test BYTE [bx+DTA.bFileAttr], FLG_FATTR_DIR
255 jnz .ChgDir ; If directory, go change
256
257 ; File selected, close dialog
258 not al ; Invert CF
259 mov [bp+FDLGVARS.fSuccess], al ; Store success flag
260 mov [bp+FDLGVARS.fpDTA], bx ; Store offset to DTA
261 mov [bp+FDLGVARS.fpDTA+2], ds ; Store segment to DTA
262 pop ds
263 jmp MenuDlg_ExitHandler ; Close dialog
264
265ALIGN JUMP_ALIGN
266.ChgDrv:
267 sub cx, [bp+FDLGVARS.wFileCnt] ; Menuitem to drive index
268 call File_GetNthValidDrv ; Drv device num to DX
269 call File_SetDrive ; Change drive
270 jmp .ChangeDone ; Update menu
271ALIGN JUMP_ALIGN
272.ChgDir:
273 lea dx, [bx+DTA.szFile] ; Offset to new path
274 call File_ChangeDir ; Change directory
275ALIGN JUMP_ALIGN
276.ChangeDone:
277 mov dx, [bp+FDLGVARS.fpFileSrch] ; Load ptr to file search str
278 mov ds, [bp+FDLGVARS.fpFileSrch+2]
279 call MenuFile_GetItemCnt ; Get file count from new dir
280 pop ds
281 xor dx, dx ; Redraw only necessary
282 call Menu_InvItemCnt ; Redraw with new items
283 jmp .EventHandled
284
285;--------------------------------------------------------------------
286; EVNT_MNU_UPD event handler.
287;
288; .EventUpd
289; Parameters:
290; CX: Index of menuitem to update (MFL_UPD_ITEM only)
291; DL: Update flag:
292; MFL_UPD_TITLE Set to update title string
293; MFL_UPD_NFO Set to update info string
294; MFL_UPD_ITEM Set to update menuitem string
295; SS:BP: Ptr to FDLGVARS
296;--------------------------------------------------------------------
297ALIGN JUMP_ALIGN
298.EventUpd:
299 test dl, MFL_UPD_TITLE ; Update title?
300 jnz .EventNotHandled ; If so, return without handling event
301 test dl, MFL_UPD_NFO ; Update info?
302 jnz .DrawInfo ; If so, jump to update
303
304 ; Update Menuitem
305 call MenuFile_DrawItem ; Draw menuitem
306 jmp .EventHandled
307
308 ; Update Info string
309ALIGN JUMP_ALIGN
310.DrawInfo:
311 push es
312 push di
313 mov di, [bp+MSGVARS.wStrOff] ; Load string offset
314 mov es, [bp+MSGVARS.wStrSeg] ; Load string segment
315 eMOVZX cx, BYTE [bp+MENUVARS.bInfoH] ; Load info line count to CX
316 call MenuDraw_MultilineStr ; Draw multiline str
317 pop di
318 pop es
319 jmp .EventHandled
Note: See TracBrowser for help on using the repository browser.