source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Libraries/menu/menudraw.asm @ 10

Last change on this file since 10 was 10, checked in by aitotat, 14 years ago

Now assembles with Yasm

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   :   25.5.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    eMOVZX  cx, BYTE [bp+MENUVARS.bInfoH]   ; Load number of info strings
291    test    BYTE [bp+MENUVARS.bFlags], FLG_MNU_HIDENFO  ; Information hidden?
292    jnz     SHORT .JumpToBottomBorder
293    test    cx, cx                          ; Any info strings?
294    jz      SHORT MenuDraw_BottomBorder
295    push    cx
296    call    MenuDraw_MiddleBorder           ; Draw middle border
297    call    MenuDraw_NewlineBrdr            ; Change line
298    pop     cx
299ALIGN JUMP_ALIGN
300.LineLoop:
301    push    cx
302    call    MenuDraw_StringBorder
303    call    MenuDraw_NewlineBrdr
304    pop     cx
305    loop    .LineLoop
306ALIGN JUMP_ALIGN
307.JumpToBottomBorder:
308    jmp     SHORT MenuDraw_BottomBorder
309
310ALIGN JUMP_ALIGN
311MenuDraw_Timeout:
312    xor     dx, dx                          ; Zero DX
313    call    MenuCrsr_PointNfoBrdr           ; Set cursor
314    mov     ch, [bp+MENUVARS.bInfoH]        ; Load info str count to CH
315    and     cx, 0FF00h                      ; Any info strings? (clears CL)
316    jz      SHORT MenuDraw_BottomBorder     ;  If not, draw bottom border
317    inc     ch                              ; Increment for info top border
318    call    MenuCrsr_Move                   ; Move cursor
319    jmp     SHORT MenuDraw_BottomBorder
320
321ALIGN JUMP_ALIGN
322MenuDraw_ItemBorders:
323    cmp     WORD [bp+MENUVARS.wItemCnt], BYTE 0 ; Any items?
324    jz      SHORT .Return                   ;  If not, return
325    xor     dx, dx                          ; Zero DX
326    call    MenuCrsr_PointItemBrdr          ; Set cursor
327    eMOVZX  cx, BYTE [bp+MENUVARS.bVisCnt]  ; Load max number of item strings
328ALIGN JUMP_ALIGN
329.LineLoop:
330    push    cx
331    call    MenuDraw_ScrollBorder
332    call    MenuDraw_NewlineBrdr
333    pop     cx
334    loop    .LineLoop
335.Return:
336    ret
337
338
339;--------------------------------------------------------------------
340; Draw horizontal border line to current cursor location.
341; MenuDraw_TopBorder    Draw thick top menu border
342; MenuDraw_StringBorder Draw thick user string border
343; MenuDraw_ScrollBorder Draw scrolling border for menuitems
344; MenuDraw_MiddleBorder Draw thin middle menu border
345; MenuDraw_BottomBorder Draw thick bottom menu border with timeout if set
346;   Parameters:
347;       CX:     Loop counter (Items left, MenuDraw_ScrollBorder only)
348;       SS:BP:  Ptr to MENUVARS
349;   Returns:
350;       Nothing
351;   Corrupts registers:
352;       AX, BX, CX, DX
353;--------------------------------------------------------------------
354ALIGN JUMP_ALIGN
355MenuDraw_TopBorder:
356    mov     bh, B_TL
357    mov     bl, B_H
358    mov     dh, B_TR
359    jmp     SHORT MenuDraw_BorderChars
360   
361ALIGN JUMP_ALIGN
362MenuDraw_StringBorder:
363    mov     bh, B_V
364    mov     bl, ' '
365    mov     dh, B_V
366    jmp     SHORT MenuDraw_BorderChars
367
368ALIGN JUMP_ALIGN
369MenuDraw_ScrollBorder:
370    call    MenuDraw_GetScrollChar          ; Load scroll char to DH
371    mov     bh, B_V
372    mov     bl, ' '
373    jmp     SHORT MenuDraw_BorderChars
374
375ALIGN JUMP_ALIGN
376MenuDraw_MiddleBorder:
377    mov     bh, BVL_THR
378    mov     bl, T_H
379    mov     dh, THL_BVR
380
381ALIGN JUMP_ALIGN
382MenuDraw_BorderChars:
383    mov     dl, bh                          ; Leftmost
384    PRINT_CHAR
385    eMOVZX  cx, BYTE [bp+MENUVARS.bWidth]
386    times 2 dec cx                          ; Subtract borders
387    mov     dl, bl                          ; Middle
388    call    Print_Repeat
389    mov     dl, dh                          ; Rightmost
390    PRINT_CHAR
391    ret
392
393ALIGN JUMP_ALIGN
394MenuDraw_BottomBorder:
395    mov     bh, B_LL
396    mov     bl, B_H
397    mov     dh, B_LR
398    cmp     WORD [bp+MENUVARS.wTimeInit], 0 ; Timeout enabled?
399    jz      MenuDraw_BorderChars            ;  If not, draw normal
400
401    ; Print timeout value
402    push    ds
403    push    si
404    push    cs
405    pop     ds                              ; Copy CS to DS
406    mov     si, g_strTimeout                ; Load ptr to timeout str (DS:SI)
407    mov     ax, 55                          ; 1 timer tick = 54.945ms
408    mul     WORD [bp+MENUVARS.wTimeout]     ; DX:AX = millisecs
409    eSHR_IM ax, 10                          ; ms to s (close enough to 1000)
410    push    ax                              ; Push seconds
411    call    Print_Format                    ; Print timeout
412    add     sp, 2                           ; Clean stack
413    pop     si
414    pop     ds
415
416    ; Print remaining border chars
417    call    MenuCrsr_GetCursor              ; Get cursor location to DX
418    sub     dl, [bp+MENUVARS.bInitX]        ; Compensate for start X...
419    inc     dx                              ; ...and lower right corner
420    mov     dh, [bp+MENUVARS.bWidth]        ; Load menu width to DH
421    sub     dh, dl                          ; Subtract current X coordinate
422    eMOVZX  cx, dh                          ; Number of border chars needed
423    mov     dl, B_H
424    call    Print_Repeat
425    mov     dl, B_LR
426    PRINT_CHAR
427    ret
428
429
430;--------------------------------------------------------------------
431; Returns character for scroll bars if needed.
432; If scroll bars are not needed, normal border character will be returned.
433;
434; Note! Current implementation doesn't always return thumb character
435;       if there are a lot of pages. Checking last char only is not enough.
436;
437; MenuDraw_GetScrollChar
438;   Parameters:
439;       CX:     Loop counter (Items left, MenuDraw_ScrollBorder only)
440;       SS:BP:  Ptr to MENUVARS
441;   Returns:
442;       DH:     Scroll bar character
443;   Corrupts registers:
444;       AX, BX, CX, DL
445;--------------------------------------------------------------------
446ALIGN JUMP_ALIGN
447MenuDraw_GetScrollChar:
448    mov     dh, B_V                     ; Assume no scroll bars needed
449    mov     ax, [bp+MENUVARS.wItemCnt]  ; Load menuitem count to AX
450    eMOVZX  bx, BYTE [bp+MENUVARS.bVisCnt]  ; Load visible menuitems to BX
451    cmp     ax, bx                      ; Need scroll bars?
452    jbe     .Return                     ;  If not, return
453   
454    ; Calculate last menuitem index for thumb char on this line
455    push    bx                          ; Store number of visible menuitems
456    sub     bx, cx                      ; Calculate Line index
457    inc     bx                          ; Increment for next line index
458    mul     bx                          ; DX:AX=Total item count * Next line idx
459    pop     bx                          ; Pop number of visible menuitems
460    div     bx                          ; AX=First Menuitem for next string line
461    dec     ax                          ; AX=Last Menuitem for this string line
462
463    ; Draw thumb or track
464    mov     dh, FULL_BLCK               ; Assume thumb line
465    call    Menu_IsItemVisible          ; Is thumb menuitem visible?
466    jc      .Return                     ;  If so, draw thumb
467    mov     dh, T_V                     ; Load track character
468ALIGN JUMP_ALIGN
469.Return:
470    ret
Note: See TracBrowser for help on using the repository browser.