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

Last change on this file since 184 was 83, checked in by krille_n_@…, 14 years ago

Minor size optimizations in various files.

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