source: xtideuniversalbios/trunk/Assembly_Library/Src/Menu/MenuBorders.asm @ 60

Last change on this file since 60 was 60, checked in by aitotat, 13 years ago

Changes to Assembly Library:

  • Timeout count down is now stopped when any key pressed.
File size: 13.1 KB
Line 
1; File name     :   MenuBorders.asm
2; Project name  :   Assembly Library
3; Created date  :   14.7.2010
4; Last update   :   25.11.2010
5; Author        :   Tomi Tilli
6; Description   :   Functions for drawing menu borders.
7
8; Struct containing border characters for different types of menu window lines
9struc BORDER_CHARS
10    .cLeft      resb    1
11    .cMiddle    resb    1
12    .cRight     resb    1
13endstruc
14
15
16; Section containing code
17SECTION .text
18
19;--------------------------------------------------------------------
20; MenuBorders_RefreshAll
21;   Parameters
22;       SS:BP:  Ptr to MENU
23;   Returns:
24;       Nothing
25;   Corrupts registers:
26;       AX, BX, CX, DX, SI, DI
27;--------------------------------------------------------------------
28ALIGN JUMP_ALIGN   
29MenuBorders_RefreshAll:
30    call    MenuBorders_AdjustDisplayContextForDrawingBorders
31    call    GetNumberOfMiddleCharactersToDX
32    call    RefreshTitleBorders
33    call    RefreshItemBorders
34    call    RefreshInformationBorders
35    call    DrawBottomBorderLine
36    call    DrawTimeoutCounterOverBottomBorderLine
37    jmp     DrawBottomShadowLine
38
39
40;--------------------------------------------------------------------
41; MenuBorders_RedrawBottomBorderLine
42;   Parameters
43;       SS:BP:  Ptr to MENU
44;   Returns:
45;       Nothing
46;   Corrupts registers:
47;       AX, BX, DX, SI, DI
48;--------------------------------------------------------------------
49ALIGN JUMP_ALIGN
50MenuBorders_RedrawBottomBorderLine:
51    call    MenuBorders_AdjustDisplayContextForDrawingBorders
52    call    MenuLocation_GetBottomBordersTopLeftCoordinatesToAX
53    CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX
54    call    GetNumberOfMiddleCharactersToDX
55    jmp     DrawBottomBorderLine
56
57
58;--------------------------------------------------------------------
59; MenuBorders_RedrawTimeoutValue
60;   Parameters
61;       SS:BP:  Ptr to MENU
62;   Returns:
63;       Nothing
64;   Corrupts registers:
65;       AX, BX, SI, DI
66;--------------------------------------------------------------------
67ALIGN JUMP_ALIGN
68MenuBorders_RedrawTimeoutValue:
69    call    MenuBorders_AdjustDisplayContextForDrawingBorders
70    call    MenuLocation_GetBottomBordersTopLeftCoordinatesToAX
71    inc     ah      ; Increment for shadow border
72    CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX
73    jmp     DrawTimeoutCounterOverBottomBorderLine
74
75
76;--------------------------------------------------------------------
77; MenuBorders_AdjustDisplayContextForDrawingBorders
78;   Parameters
79;       SS:BP:  Ptr to MENU
80;   Returns:
81;       Nothing
82;   Corrupts registers:
83;       AX, BX, SI, DI
84;--------------------------------------------------------------------
85ALIGN JUMP_ALIGN
86MenuBorders_AdjustDisplayContextForDrawingBorders:
87    mov     bl, ATTRIBUTES_ARE_USED
88    mov     ax, MenuCharOut_MenuTeletypeOutput
89    CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInBL
90
91    call    CharOutLineSplitter_GetFirstBorderLineColumnOffsetToAX
92    CALL_DISPLAY_LIBRARY SetCharacterOutputParameterFromAX
93
94    call    MenuLocation_GetTitleBordersTopLeftCoordinatesToAX
95    CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX
96
97    mov     si, ATTRIBUTE_CHARS.cBordersAndBackground
98    jmp     MenuAttribute_SetToDisplayContextFromTypeInSI
99
100
101;--------------------------------------------------------------------
102; MenuBorders_RefreshItemBorders
103;   Parameters
104;       SS:BP:  Ptr to MENU
105;   Returns:
106;       Nothing
107;   Corrupts registers:
108;       AX, BX, CX, DX, SI, DI
109;--------------------------------------------------------------------
110ALIGN JUMP_ALIGN
111MenuBorders_RefreshItemBorders:
112    call    MenuBorders_AdjustDisplayContextForDrawingBorders
113    call    MenuLocation_GetItemBordersTopLeftCoordinatesToAX
114    CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX
115
116    call    GetNumberOfMiddleCharactersToDX
117    jmp     SHORT RefreshItemBorders
118
119
120;--------------------------------------------------------------------
121; GetNumberOfMiddleCharactersToDX
122;   Parameters
123;       SS:BP:  Ptr to MENU
124;   Returns:
125;       DX:     Number of middle border characters when drawing border lines
126;   Corrupts registers:
127;       Nothing
128;--------------------------------------------------------------------
129ALIGN JUMP_ALIGN
130GetNumberOfMiddleCharactersToDX:
131    eMOVZX  dx, BYTE [bp+MENUINIT.bWidth]
132    sub     dx, BYTE MENU_HORIZONTAL_BORDER_LINES
133    ret
134
135
136;--------------------------------------------------------------------
137; RefreshTitleBorders
138;   Parameters
139;       DX:     Number of times to repeat middle character
140;       SS:BP:  Ptr to MENU
141;   Returns:
142;       Nothing
143;   Corrupts registers:
144;       AX, BX, CX, SI, DI
145;--------------------------------------------------------------------
146ALIGN JUMP_ALIGN
147RefreshTitleBorders:
148    call    DrawTopBorderLine
149    eMOVZX  cx, BYTE [bp+MENUINIT.bTitleLines]
150    jmp     SHORT DrawTextBorderLinesByCXtimes
151
152;--------------------------------------------------------------------
153; RefreshInformationBorders
154;   Parameters
155;       DX:     Number of times to repeat middle character
156;       SS:BP:  Ptr to MENU
157;   Returns:
158;       Nothing
159;   Corrupts registers:
160;       AX, BX, CX, SI, DI
161;--------------------------------------------------------------------
162ALIGN JUMP_ALIGN
163RefreshInformationBorders:
164    call    DrawSeparationBorderLine
165    eMOVZX  cx, BYTE [bp+MENUINIT.bInfoLines]
166    jmp     SHORT DrawTextBorderLinesByCXtimes
167
168;--------------------------------------------------------------------
169; RefreshItemBorders
170;   Parameters
171;       DX:     Number of times to repeat middle character
172;       SS:BP:  Ptr to MENU
173;   Returns:
174;       Nothing
175;   Corrupts registers:
176;       AX, BX, CX, SI, DI
177;--------------------------------------------------------------------
178ALIGN JUMP_ALIGN
179RefreshItemBorders:
180    call    DrawSeparationBorderLine
181    call    MenuScrollbars_GetMaxVisibleItemsOnPageToCX
182DrawTextBorderLinesByCXtimes:
183    mov     bx, DrawTextBorderLine
184    ; Fall to DrawBorderLinesByCXtimes
185
186;--------------------------------------------------------------------
187; DrawBorderLinesByCXtimes
188;   Parameters
189;       BX:     Offset to border drawing function
190;       CX:     Number of border lines to draw
191;       DX:     Number of times to repeat middle character
192;       SS:BP:  Ptr to MENU
193;   Returns:
194;       Nothing
195;   Corrupts registers:
196;       AX, CX, SI, DI
197;--------------------------------------------------------------------
198DrawBorderLinesByCXtimes:
199    jcxz    .Return
200ALIGN JUMP_ALIGN
201.DrawBordersWithFunctionInBX:
202    call    bx
203    loop    .DrawBordersWithFunctionInBX
204.Return:
205    ret
206
207
208;--------------------------------------------------------------------
209; DrawTopBorderLine
210; DrawSeparationBorderLine
211; DrawBottomBorderLine
212; DrawTimeoutCounterOverBottomBorderLine
213; DrawBottomShadowLine
214; DrawTextBorderLine
215;   Parameters
216;       DX:     Number of times to repeat middle character
217;       SS:BP:  Ptr to MENU
218;   Returns:
219;       Nothing
220;   Corrupts registers:
221;       AX, SI, DI
222;--------------------------------------------------------------------
223ALIGN JUMP_ALIGN
224DrawTopBorderLine:
225    mov     si, g_rgbTopBorderCharacters
226    call    PrintBorderCharactersFromCSSI
227    jmp     SHORT PrintNewlineToEndBorderLine
228
229ALIGN JUMP_ALIGN
230DrawSeparationBorderLine:
231    mov     si, g_rgbSeparationBorderCharacters
232    jmp     SHORT PrintBorderCharactersFromCSSIandShadowCharacter
233
234ALIGN JUMP_ALIGN
235DrawBottomBorderLine:
236    mov     si, g_rgbBottomBorderCharacters
237    jmp     SHORT PrintBorderCharactersFromCSSIandShadowCharacter
238
239ALIGN JUMP_ALIGN
240DrawTimeoutCounterOverBottomBorderLine:
241    test    BYTE [bp+MENU.bFlags], FLG_MENU_TIMEOUT_COUNTDOWN
242    jz      SHORT .NoNeedToDrawSinceTimeoutDisabled
243    mov     ax, (-1)<<8 ; Decrement row
244    call    MenuLocation_MoveCursorByALcolumnsAndAHrows
245    call    MenuTime_GetTimeoutSecondsLeftToAX
246    call    PrintTimeoutStringWithSecondsInAX
247    jmp     SHORT PrintNewlineToEndBorderLine
248.NoNeedToDrawSinceTimeoutDisabled:
249    ret
250
251ALIGN JUMP_ALIGN
252DrawBottomShadowLine:
253    mov     ax, 1       ; Increment column
254    call    MenuLocation_MoveCursorByALcolumnsAndAHrows
255    inc     dx          ; Increment repeat count...
256    inc     dx          ; ...for both corner characters
257    call    PrintShadowCharactersByDXtimes
258    dec     dx          ; Restore...
259    dec     dx          ; ...DX
260    ret
261
262ALIGN JUMP_ALIGN
263DrawTextBorderLine:
264    mov     si, g_rgbTextBorderCharacters
265    ; Fall to PrintBorderCharactersFromCSSIandShadowCharacter
266
267;--------------------------------------------------------------------
268; PrintBorderCharactersFromCSSIandShadowCharacter
269;   Parameters
270;       DX:     Number of times to repeat middle character
271;       CS:SI:  Ptr to BORDER_CHARS
272;       SS:BP:  Ptr to MENU
273;   Returns:
274;       Nothing
275;   Corrupts registers:
276;       AX, SI, DI
277;--------------------------------------------------------------------
278ALIGN JUMP_ALIGN
279PrintBorderCharactersFromCSSIandShadowCharacter:
280    call    PrintBorderCharactersFromCSSI
281    push    dx
282    mov     dx, 1
283    call    PrintShadowCharactersByDXtimes
284    pop     dx
285    ; Fall to PrintNewlineToEndBorderLine
286
287;--------------------------------------------------------------------
288; PrintNewlineToEndBorderLine
289;   Parameters
290;       SS:BP:  Ptr to MENU
291;   Returns:
292;       Nothing
293;   Corrupts registers:
294;       AX, DI
295;--------------------------------------------------------------------
296ALIGN JUMP_ALIGN
297PrintNewlineToEndBorderLine:
298    CALL_DISPLAY_LIBRARY PrintNewlineCharacters
299    ret
300
301
302;--------------------------------------------------------------------
303; PrintShadowCharactersByDXtimes
304;   Parameters
305;       DX:     Number of shadow characters to print
306;       SS:BP:  Ptr to MENU
307;   Returns:
308;       Nothing
309;   Corrupts registers:
310;       AX, SI, DI
311;--------------------------------------------------------------------
312ALIGN JUMP_ALIGN
313PrintShadowCharactersByDXtimes:
314    CALL_DISPLAY_LIBRARY PushDisplayContext
315
316    mov     si, ATTRIBUTE_CHARS.cShadow
317    call    MenuAttribute_SetToDisplayContextFromTypeInSI
318
319    push    bx
320    mov     bl, ATTRIBUTES_ARE_USED
321    mov     ax, FAST_OUTPUT_WITH_ATTRIBUTE_ONLY
322    CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInBL
323    pop     bx
324
325    call    PrintMultipleBorderCharactersFromAL ; AL does not matter
326
327    CALL_DISPLAY_LIBRARY PopDisplayContext
328    ret
329
330
331;--------------------------------------------------------------------
332; PrintBorderCharactersFromCSSI
333;   Parameters
334;       DX:     Number of times to repeat middle character
335;       CS:SI:  Ptr to BORDER_CHARS
336;       SS:BP:  Ptr to MENU
337;   Returns:
338;       Nothing
339;   Corrupts registers:
340;       AX, SI, DI
341;--------------------------------------------------------------------
342ALIGN JUMP_ALIGN
343PrintBorderCharactersFromCSSI:
344    cld
345    eSEG    cs
346    lodsb           ; Load from [si+BORDER_CHARS.cLeft] to AL
347    call    MenuBorders_PrintSingleBorderCharacterFromAL
348
349    eSEG    cs
350    lodsb           ; Load from [si+BORDER_CHARS.cMiddle] to AL
351    call    PrintMultipleBorderCharactersFromAL
352
353    eSEG    cs
354    lodsb           ; Load from [si+BORDER_CHARS.cRight] to AL
355    ; Fall to MenuBorders_PrintSingleBorderCharacterFromAL
356
357;--------------------------------------------------------------------
358; MenuBorders_PrintSingleBorderCharacterFromAL
359; PrintMultipleBorderCharactersFromAL
360;   Parameters
361;       AL:     Character to print
362;       DX:     Repeat count (PrintMultipleBorderCharactersFromAL)
363;       SS:BP:  Ptr to MENU
364;   Returns:
365;       Nothing
366;   Corrupts registers:
367;       AX, DI
368;--------------------------------------------------------------------
369ALIGN JUMP_ALIGN
370MenuBorders_PrintSingleBorderCharacterFromAL:
371    CALL_DISPLAY_LIBRARY PrintCharacterFromAL
372    ret
373
374ALIGN JUMP_ALIGN
375PrintMultipleBorderCharactersFromAL:
376    push    cx
377    mov     cx, dx
378    CALL_DISPLAY_LIBRARY PrintRepeatedCharacterFromALwithCountInCX
379    pop     cx
380    ret
381
382
383;--------------------------------------------------------------------
384; PrintTimeoutStringWithSecondsInAX
385;   Parameters
386;       AX:     Seconds to print
387;       SS:BP:  Ptr to MENU
388;   Returns:
389;       Nothing
390;   Corrupts registers:
391;       AX, SI, DI
392;--------------------------------------------------------------------
393ALIGN JUMP_ALIGN
394PrintTimeoutStringWithSecondsInAX:
395    push    bp
396
397    xchg    di, ax
398    mov     bp, sp
399    call    .GetTimeoutAttributeToAXfromSecondsInDI
400    mov     si, .szSelectionTimeout
401    push    ax          ; Push attribute
402    push    di          ; Push seconds
403    CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
404    pop     bp
405
406    ; Draw right border with normal border color
407    mov     al, DOUBLE_RIGHT_HORIZONTAL_TO_SINGLE_VERTICAL
408    jmp     MenuBorders_PrintSingleBorderCharacterFromAL
409.szSelectionTimeout:
410    db      DOUBLE_BOTTOM_LEFT_CORNER
411    db      DOUBLE_LEFT_HORIZONTAL_TO_SINGLE_VERTICAL
412    db      "%AAutoselection in %2u s",NULL
413
414;--------------------------------------------------------------------
415; .GetTimeoutAttributeToAXfromSecondsInDI
416;   Parameters
417;       DI:     Seconds to print
418;   Returns:
419;       AX:     Attribute byte for seconds
420;   Corrupts registers:
421;       SI
422;--------------------------------------------------------------------
423ALIGN JUMP_ALIGN
424.GetTimeoutAttributeToAXfromSecondsInDI:
425    mov     si, ATTRIBUTE_CHARS.cNormalTimeout
426    cmp     di, BYTE 3
427    eCMOVB  si, ATTRIBUTE_CHARS.cHurryTimeout
428    jmp     MenuAttribute_GetToAXfromTypeInSI
429
430
431; Lookup tables for border characters
432g_rgbTopBorderCharacters:
433istruc BORDER_CHARS
434    at  BORDER_CHARS.cLeft,     db  DOUBLE_TOP_LEFT_CORNER
435    at  BORDER_CHARS.cMiddle,   db  DOUBLE_HORIZONTAL
436    at  BORDER_CHARS.cRight,    db  DOUBLE_TOP_RIGHT_CORNER
437iend
438
439g_rgbSeparationBorderCharacters:
440istruc BORDER_CHARS
441    at  BORDER_CHARS.cLeft,     db  DOUBLE_VERTICAL_TO_RIGHT_SINGLE
442    at  BORDER_CHARS.cMiddle,   db  SINGLE_HORIZONTAL
443    at  BORDER_CHARS.cRight,    db  DOUBLE_VERTICAL_TO_LEFT_SINGLE
444iend
445
446g_rgbBottomBorderCharacters:
447istruc BORDER_CHARS
448    at  BORDER_CHARS.cLeft,     db  DOUBLE_BOTTOM_LEFT_CORNER
449    at  BORDER_CHARS.cMiddle,   db  DOUBLE_HORIZONTAL
450    at  BORDER_CHARS.cRight,    db  DOUBLE_BOTTOM_RIGHT_CORNER
451iend
452
453g_rgbTextBorderCharacters:
454istruc BORDER_CHARS
455    at  BORDER_CHARS.cLeft,     db  DOUBLE_VERTICAL
456    at  BORDER_CHARS.cMiddle,   db  ' '
457    at  BORDER_CHARS.cRight,    db  DOUBLE_VERTICAL
458iend
Note: See TracBrowser for help on using the repository browser.