source: xtideuniversalbios/tags/XTIDE_Universal_BIOS_v1.1.0/Src/Libraries/menu/menudraw.asm@ 530

Last change on this file since 530 was 3, checked in by Tomi Tilli, 14 years ago
File size: 14.2 KB
Line 
1; File name : menudraw.asm
2; Project name : Menu library
3; Created date : 9.11.2009
4; Last update : 21.1.2010
5; Author : Tomi Tilli
6; Description : ASM library to menu system.
7; Contains menu drawing functions.
8
9;--------------- Equates -----------------------------
10
11
12
13;-------------- Private global variables -------------
14; Section containing initialized data
15;SECTION .data
16
17g_strTimeout: db B_LL,BHL_TVR,"Selection Timeout %us",TVL_BHR,STOP
18
19
20;-------------- Public functions ---------------------
21; Section containing code
22SECTION .text
23
24
25;--------------------------------------------------------------------
26; Clears screen.
27;
28; Parameters:
29; Nothing
30; Returns:
31; Nothing
32; Corrupts registers:
33; AX, BX, CX, DX
34;--------------------------------------------------------------------
35ALIGN JUMP_ALIGN
36MenuDraw_ClrScr:
37 xor dx, dx ; Cursor to (0,0)
38 call MenuCrsr_SetCursor
39 mov ah, 0Fh ; Get Current Video Mode
40 int 10h
41 mov al, CNT_SCRN_ROW ; Load row count
42 mul ah ; AX=Column count * row count
43 mov cx, ax ; Copy char count to CX
44 mov bx, ATTR_MDA_NORMAL ; Page zero, normal attribute
45 mov ax, 0920h ; Write Char and attr, space char
46 int 10h
47 ret
48
49
50;--------------------------------------------------------------------
51; Changes line. When printing menu strings, this function must be
52; called instead of normal Print_Newline.
53;
54; MenuDraw_NewlineStrClrLn Clear current line from cursor pos before newline
55; MenuDraw_NewlineStr
56; Parameters:
57; SS:BP: Ptr to MENUVARS
58; Returns:
59; Nothing
60; Corrupts registers:
61; AX, BX, DX
62;--------------------------------------------------------------------
63ALIGN JUMP_ALIGN
64MenuDraw_NewlineStrClrLn:
65 push cx
66 call MenuCrsr_GetCursor ; Get current cursor to DX
67 eMOVZX cx, BYTE [bp+MENUVARS.bWidth] ; Load menu width
68 add cl, [bp+MENUVARS.bInitX] ; Add menu start X coord
69 sub cl, W_OFF_CRSR_STR & 0FFh ; Subtract right borders
70 sub cl, dl ; Subtract current X coord
71 mov dl, ' ' ; Clear with space
72 call Print_Repeat ; Clear line to the end
73 pop cx
74ALIGN JUMP_ALIGN
75MenuDraw_NewlineStr:
76 push cx
77 call MenuCrsr_GetCursor ; Get current cursor to DX
78 mov dl, [bp+MENUVARS.bInitX] ; Load X offset to border
79 add dx, W_OFF_CRSR_STR ; Inc X and Y
80 call MenuCrsr_SetCursor ; Set new cursor
81 pop cx
82 ret
83
84
85;--------------------------------------------------------------------
86; Draws multiline Title or Info string.
87;
88; MenuDraw_MultilineStr
89; Parameters:
90; CX: Max Title or Info line count (menu initialization params)
91; ES:DI: Ptr to STOP terminated string to display
92; SS:BP: Ptr to MENUVARS
93; Returns:
94; Nothing
95; Corrupts registers:
96; AX, BX, CX, DX
97;--------------------------------------------------------------------
98%ifdef USE_MENU_DIALOGS
99ALIGN JUMP_ALIGN
100MenuDraw_MultilineStr:
101 push si
102 xor si, si
103ALIGN JUMP_ALIGN
104.LineLoop:
105 xchg cx, si ; Idx to CX, count to SI
106 push cx
107 call MenuMsg_WriteLine ; Write line
108 pop cx
109 jc .Return ; Return if last token written
110 call MenuDraw_NewlineStr ; Cursor to next line
111 inc cx ; Increment line index
112 xchg cx, si ; Count to CX, idx to SI
113 loop .LineLoop ; Loop while lines left
114ALIGN JUMP_ALIGN
115.Return:
116 pop si
117 ret
118%endif ; USE_MENU_DIALOGS
119
120
121;--------------------------------------------------------------------
122; Draws menu component.
123;
124; MenuDraw_Title Draws Title borders and user string
125; MenuDraw_Info Draws Info borders and user string
126; MenuDraw_AllItems Draws Item borders and all user menuitems
127; MenuDraw_TitleNoBord MenuDraw_Title without clearing old chars
128; MenuDraw_InfoNoBord MenuDraw_Info without clearing old chars
129; MenuDraw_AllItemsNoBord MenuDraw_AllItems without clearing old chars
130; Parameters:
131; SS:BP: Ptr to MENUVARS
132; Returns:
133; Nothing
134; Corrupts registers:
135; AX, BX, CX, DX
136;--------------------------------------------------------------------
137;ALIGN JUMP_ALIGN
138;MenuDraw_Title:
139; call MenuDraw_TitleBorders ; Draw borders to clear old strings
140ALIGN JUMP_ALIGN
141MenuDraw_TitleNoBord:
142 cmp BYTE [bp+MENUVARS.bTitleH], 0 ; Any title strings?
143 jz MenuDraw_NothingToDraw ; If not, return
144 call MenuCrsr_PointTitle ; Set cursor position
145 mov dl, MFL_UPD_TITLE ; Update title string
146 jmp MenuDraw_SendEvent
147
148;ALIGN JUMP_ALIGN
149;MenuDraw_Info:
150; call MenuDraw_InfoBorders ; Draw borders to clear old strings
151ALIGN JUMP_ALIGN
152MenuDraw_InfoNoBord:
153 cmp BYTE [bp+MENUVARS.bInfoH], 0 ; Any info strings?
154 jz MenuDraw_NothingToDraw ; If not, return
155 test BYTE [bp+MENUVARS.bFlags], FLG_MNU_HIDENFO
156 jnz MenuDraw_NothingToDraw ; Return if info is hidden
157 call MenuCrsr_PointInfo ; Set cursor position
158 mov dl, MFL_UPD_NFO ; Update title string
159 jmp MenuDraw_SendEvent
160
161;ALIGN JUMP_ALIGN
162;MenuDraw_AllItems:
163; call MenuDraw_ItemBorders ; Draw borders to clear old strings
164ALIGN JUMP_ALIGN
165MenuDraw_AllItemsNoBord:
166 cmp WORD [bp+MENUVARS.wItemCnt], 0 ; Any items to draw?
167 jz MenuDraw_NothingToDraw ; If not, return
168 call MenuCrsr_Point1stItem ; Set cursor position
169 mov cx, [bp+MENUVARS.wItemTop] ; Load idx of first menuitem to draw
170 eMOVZX dx, BYTE [bp+MENUVARS.bVisCnt] ; Load number of visible menuitems
171 MIN_U dx, [bp+MENUVARS.wItemCnt] ; Limit to item count
172 add dx, cx ; One past last menuitem to draw
173ALIGN JUMP_ALIGN
174.DrawLoop:
175 push dx
176 call MenuDraw_Item ; Draw menuitem
177 pop dx
178 inc cx ; Increment menuitem index
179 cmp cx, dx ; More items left?
180 jb .DrawLoop ; If so, loop
181 jmp MenuDraw_NothingToDraw
182
183ALIGN JUMP_ALIGN
184MenuDraw_SendEvent:
185 mov bx, EVNT_MNU_UPD ; Update string
186 call MenuLoop_SendEvent
187ALIGN JUMP_ALIGN
188MenuDraw_NothingToDraw:
189 call MenuCrsr_PointBelowBrdr ; Cursor to safe location
190 ret
191
192
193;--------------------------------------------------------------------
194; Draws Menuitem without borders.
195; This function does not set initial cursor position but does
196; change line for next menuitem!
197;
198; MenuDraw_Item
199; Parameters:
200; CX: Index of menuitem to draw
201; SS:BP: Ptr to MENUVARS
202; Returns:
203; AL: 1=Menuitem drawed by user event handler
204; 0=Menuitem not drawed by user event handler
205; Corrupts registers:
206; AH, BX, DX
207;--------------------------------------------------------------------
208ALIGN JUMP_ALIGN
209MenuDraw_Item:
210 push cx
211 test BYTE [bp+MENUVARS.bFlags], FLG_MNU_NOARRW
212 jnz .DrawString ; Don't draw arrow unless wanted
213 mov dl, RARROW ; Prepare to draw selection arrow
214 cmp cx, [bp+MENUVARS.wItemSel] ; Drawing selected item?
215 je .DrawArrow ; If so, jump to draw arrow
216 mov dl, ' ' ; Load space instead of arrow
217ALIGN JUMP_ALIGN
218.DrawArrow:
219 PRINT_CHAR
220 mov dl, ' ' ; Draw space before user str
221 PRINT_CHAR
222ALIGN JUMP_ALIGN
223.DrawString:
224 mov dl, MFL_UPD_ITEM ; Draw item string
225 mov bx, EVNT_MNU_UPD ; Update string
226 call [bp+MENUVARS.fnEvent] ; Send event
227 call MenuDraw_NewlineStr ; Move cursor to next menuitem
228 pop cx
229 ret
230
231
232;-------------- Private functions --------------------
233
234;--------------------------------------------------------------------
235; Changes line. When printing menu borders, this function must be
236; called instead of normal Print_Newline.
237; Parameters:
238; SS:BP: Ptr to MENUVARS
239; Returns:
240; Nothing
241; Corrupts registers:
242; AX, BX, CX, DX
243;--------------------------------------------------------------------
244ALIGN JUMP_ALIGN
245MenuDraw_NewlineBrdr:
246 call MenuCrsr_GetCursor ; Get current cursor to DX
247 mov dl, [bp+MENUVARS.bInitX] ; Load X offset to border
248 inc dh ; Increment Y coordinate
249 jmp MenuCrsr_SetCursor ; Set new cursor
250
251
252;--------------------------------------------------------------------
253; Draws menu borders. User strings will be cleared.
254;
255; MenuDraw_TitleBorders Draws Title borders
256; MenuDraw_InfoBorders Draws Info borders
257; MenuDraw_ItemBorders Draws Item borders
258; MenuDraw_Timeout Draw timeout border (not whole InfoBorders)
259; Parameters:
260; SS:BP: Ptr to MENUVARS
261; Returns:
262; Nothing
263; Corrupts registers:
264; AX, BX, CX, DX
265;--------------------------------------------------------------------
266ALIGN JUMP_ALIGN
267MenuDraw_TitleBorders:
268 xor dx, dx ; Zero DX
269 call MenuCrsr_PointTitleBrdr ; Set cursor
270 call MenuDraw_TopBorder ; Draw top border
271 call MenuDraw_NewlineBrdr ; Change line
272 eMOVZX cx, BYTE [bp+MENUVARS.bTitleH] ; Load number of title strings
273 jcxz .Return ; Return if no title strings
274ALIGN JUMP_ALIGN
275.LineLoop:
276 push cx
277 call MenuDraw_StringBorder
278 call MenuDraw_NewlineBrdr
279 pop cx
280 loop .LineLoop
281 jmp MenuDraw_MiddleBorder ; Thin border before menuitems
282ALIGN JUMP_ALIGN
283.Return:
284 ret
285
286ALIGN JUMP_ALIGN
287MenuDraw_InfoBorders:
288 xor dx, dx ; Zero DX
289 call MenuCrsr_PointNfoBrdr ; Set cursor
290 cmp BYTE [bp+MENUVARS.bInfoH], 0 ; Any info strings?
291 jz MenuDraw_BottomBorder ; If not, draw bottom border
292 test BYTE [bp+MENUVARS.bFlags], FLG_MNU_HIDENFO
293 jnz MenuDraw_BottomBorder ; Draw bottom border if info is hidden
294 call MenuDraw_MiddleBorder ; Draw middle border
295 call MenuDraw_NewlineBrdr ; Change line
296 eMOVZX cx, BYTE [bp+MENUVARS.bInfoH] ; Load number of info strings
297ALIGN JUMP_ALIGN
298.LineLoop:
299 push cx
300 call MenuDraw_StringBorder
301 call MenuDraw_NewlineBrdr
302 pop cx
303 loop .LineLoop
304 jmp MenuDraw_BottomBorder
305
306ALIGN JUMP_ALIGN
307MenuDraw_Timeout:
308 xor dx, dx ; Zero DX
309 call MenuCrsr_PointNfoBrdr ; Set cursor
310 mov ch, [bp+MENUVARS.bInfoH] ; Load info str count to CH
311 test ch, ch ; Any info strings?
312 jz MenuDraw_BottomBorder ; If not, draw bottom border
313 inc ch ; Increment for info top border
314 xor cl, cl ; Zero X coordinate
315 call MenuCrsr_Move ; Move cursor
316 jmp MenuDraw_BottomBorder
317
318ALIGN JUMP_ALIGN
319MenuDraw_ItemBorders:
320 cmp WORD [bp+MENUVARS.wItemCnt], 0 ; Any items?
321 jz .Return ; If not, return
322 xor dx, dx ; Zero DX
323 call MenuCrsr_PointItemBrdr ; Set cursor
324 eMOVZX cx, BYTE [bp+MENUVARS.bVisCnt] ; Load max number of item strings
325ALIGN JUMP_ALIGN
326.LineLoop:
327 push cx
328 call MenuDraw_ScrollBorder
329 call MenuDraw_NewlineBrdr
330 pop cx
331 loop .LineLoop
332.Return:
333 ret
334
335
336;--------------------------------------------------------------------
337; Draw horizontal border line to current cursor location.
338; MenuDraw_TopBorder Draw thick top menu border
339; MenuDraw_StringBorder Draw thick user string border
340; MenuDraw_ScrollBorder Draw scrolling border for menuitems
341; MenuDraw_MiddleBorder Draw thin middle menu border
342; MenuDraw_BottomBorder Draw thick bottom menu border with timeout if set
343; Parameters:
344; CX: Loop counter (Items left, MenuDraw_ScrollBorder only)
345; SS:BP: Ptr to MENUVARS
346; Returns:
347; Nothing
348; Corrupts registers:
349; AX, BX, CX, DX
350;--------------------------------------------------------------------
351ALIGN JUMP_ALIGN
352MenuDraw_TopBorder:
353 mov bh, B_TL
354 mov bl, B_H
355 mov dh, B_TR
356 jmp MenuDraw_BorderChars
357
358ALIGN JUMP_ALIGN
359MenuDraw_StringBorder:
360 mov bh, B_V
361 mov bl, ' '
362 mov dh, B_V
363 jmp MenuDraw_BorderChars
364
365ALIGN JUMP_ALIGN
366MenuDraw_ScrollBorder:
367 call MenuDraw_GetScrollChar ; Load scroll char to DH
368 mov bh, B_V
369 mov bl, ' '
370 jmp MenuDraw_BorderChars
371
372ALIGN JUMP_ALIGN
373MenuDraw_MiddleBorder:
374 mov bh, BVL_THR
375 mov bl, T_H
376 mov dh, THL_BVR
377
378ALIGN JUMP_ALIGN
379MenuDraw_BorderChars:
380 mov dl, bh ; Leftmost
381 PRINT_CHAR
382 eMOVZX cx, BYTE [bp+MENUVARS.bWidth]
383 times 2 dec cx ; Subtract borders
384 mov dl, bl ; Middle
385 call Print_Repeat
386 mov dl, dh ; Rightmost
387 PRINT_CHAR
388 ret
389
390ALIGN JUMP_ALIGN
391MenuDraw_BottomBorder:
392 mov bh, B_LL
393 mov bl, B_H
394 mov dh, B_LR
395 cmp WORD [bp+MENUVARS.wTimeInit], 0 ; Timeout enabled?
396 jz MenuDraw_BorderChars ; If not, draw normal
397
398 ; Print timeout value
399 push ds
400 push si
401 push cs
402 pop ds ; Copy CS to DS
403 mov si, g_strTimeout ; Load ptr to timeout str (DS:SI)
404 mov ax, 55 ; 1 timer tick = 54.945ms
405 mul WORD [bp+MENUVARS.wTimeout] ; DX:AX = millisecs
406 eSHR_IM ax, 10 ; ms to s (close enough to 1000)
407 push ax ; Push seconds
408 call Print_Format ; Print timeout
409 add sp, 2 ; Clean stack
410 pop si
411 pop ds
412
413 ; Print remaining border chars
414 call MenuCrsr_GetCursor ; Get cursor location to DX
415 sub dl, [bp+MENUVARS.bInitX] ; Compensate for start X...
416 inc dx ; ...and lower right corner
417 mov dh, [bp+MENUVARS.bWidth] ; Load menu width to DH
418 sub dh, dl ; Subtract current X coordinate
419 eMOVZX cx, dh ; Number of border chars needed
420 mov dl, B_H
421 call Print_Repeat
422 mov dl, B_LR
423 PRINT_CHAR
424 ret
425
426
427;--------------------------------------------------------------------
428; Returns character for scroll bars if needed.
429; If scroll bars are not needed, normal border character will be returned.
430;
431; Note! Current implementation doesn't always return thumb character
432; if there are a lot of pages. Checking last char only is not enough.
433;
434; MenuDraw_GetScrollChar
435; Parameters:
436; CX: Loop counter (Items left, MenuDraw_ScrollBorder only)
437; SS:BP: Ptr to MENUVARS
438; Returns:
439; DH: Scroll bar character
440; Corrupts registers:
441; AX, BX, CX, DL
442;--------------------------------------------------------------------
443ALIGN JUMP_ALIGN
444MenuDraw_GetScrollChar:
445 mov dh, B_V ; Assume no scroll bars needed
446 mov ax, [bp+MENUVARS.wItemCnt] ; Load menuitem count to AX
447 eMOVZX bx, BYTE [bp+MENUVARS.bVisCnt] ; Load visible menuitems to BX
448 cmp ax, bx ; Need scroll bars?
449 jbe .Return ; If not, return
450
451 ; Calculate last menuitem index for thumb char on this line
452 push bx ; Store number of visible menuitems
453 sub bx, cx ; Calculate Line index
454 inc bx ; Increment for next line index
455 mul bx ; DX:AX=Total item count * Next line idx
456 pop bx ; Pop number of visible menuitems
457 div bx ; AX=First Menuitem for next string line
458 dec ax ; AX=Last Menuitem for this string line
459
460 ; Draw thumb or track
461 mov dh, FULL_BLCK ; Assume thumb line
462 call Menu_IsItemVisible ; Is thumb menuitem visible?
463 jc .Return ; If so, draw thumb
464 mov dh, T_V ; Load track character
465ALIGN JUMP_ALIGN
466.Return:
467 ret
Note: See TracBrowser for help on using the repository browser.