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

Last change on this file since 584 was 293, checked in by krille_n_@…, 12 years ago

Commit 1/2 (Library, Configurators and Serial Server):

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