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

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

Changes:

  • Reverted the changes to MenuEvents.inc done in r492 since they broke the F1 key function in XTIDECFG.
  • Added a tail-call optimized variant of the CALL_DISPLAY_LIBRARY macro (JMP_DISPLAY_LIBRARY).
  • Put a block size limit in AH1Eh_ChangeXTCFmodeBasedOnControlRegisterInAL. I think it's needed but if not, it's easy to remove.
  • Other optimizations and fixes.
File size: 13.4 KB
RevLine 
[41]1; Project name : Assembly Library
2; Description : Functions for drawing menu borders.
3
[376]4;
[505]5; XTIDE Universal BIOS and Associated Tools
[376]6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
7;
8; This program is free software; you can redistribute it and/or modify
9; it under the terms of the GNU General Public License as published by
10; the Free Software Foundation; either version 2 of the License, or
11; (at your option) any later version.
[505]12;
[376]13; This program is distributed in the hope that it will be useful,
14; but WITHOUT ANY WARRANTY; without even the implied warranty of
15; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
[505]16; GNU General Public License for more details.
[376]17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
19
[505]20
[41]21; Struct containing border characters for different types of menu window lines
22struc BORDER_CHARS
23 .cLeft resb 1
24 .cMiddle resb 1
25 .cRight resb 1
26endstruc
27
28
29; Section containing code
30SECTION .text
31
32;--------------------------------------------------------------------
33; MenuBorders_RefreshAll
34; Parameters
35; SS:BP: Ptr to MENU
36; Returns:
37; Nothing
38; Corrupts registers:
39; AX, BX, CX, DX, SI, DI
40;--------------------------------------------------------------------
[369]41ALIGN MENU_JUMP_ALIGN
[41]42MenuBorders_RefreshAll:
[223]43%ifndef USE_186
[41]44 call MenuBorders_AdjustDisplayContextForDrawingBorders
[67]45 call MenuBorders_GetNumberOfMiddleCharactersToDX
[41]46 call RefreshTitleBorders
47 call RefreshItemBorders
48 call RefreshInformationBorders
49 call DrawBottomBorderLine
[60]50 jmp DrawBottomShadowLine
[223]51%else
52 push DrawBottomShadowLine
53 push DrawBottomBorderLine
54 push RefreshInformationBorders
55 push RefreshItemBorders
56 push RefreshTitleBorders
57 push MenuBorders_GetNumberOfMiddleCharactersToDX
58 jmp MenuBorders_AdjustDisplayContextForDrawingBorders
59%endif
[41]60
61
62;--------------------------------------------------------------------
[60]63; MenuBorders_RedrawBottomBorderLine
64; Parameters
65; SS:BP: Ptr to MENU
66; Returns:
67; Nothing
68; Corrupts registers:
69; AX, BX, DX, SI, DI
70;--------------------------------------------------------------------
[369]71ALIGN MENU_JUMP_ALIGN
[60]72MenuBorders_RedrawBottomBorderLine:
73 call MenuBorders_AdjustDisplayContextForDrawingBorders
74 call MenuLocation_GetBottomBordersTopLeftCoordinatesToAX
75 CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX
[67]76 call MenuBorders_GetNumberOfMiddleCharactersToDX
[62]77 jmp SHORT DrawBottomBorderLine
[60]78
79
80;--------------------------------------------------------------------
[104]81; MenuBorders_RefreshItemBorders
82; Parameters
83; SS:BP: Ptr to MENU
84; Returns:
85; Nothing
86; Corrupts registers:
87; AX, BX, CX, DX, SI, DI
88;--------------------------------------------------------------------
[194]89%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[369]90ALIGN MENU_JUMP_ALIGN
[104]91MenuBorders_RefreshItemBorders:
92 call MenuBorders_AdjustDisplayContextForDrawingBorders
93 call MenuLocation_GetItemBordersTopLeftCoordinatesToAX
94 CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX
95
96 call MenuBorders_GetNumberOfMiddleCharactersToDX
97 jmp SHORT RefreshItemBorders
[194]98%endif
[104]99
[223]100
[104]101;--------------------------------------------------------------------
[41]102; MenuBorders_AdjustDisplayContextForDrawingBorders
103; Parameters
104; SS:BP: Ptr to MENU
105; Returns:
106; Nothing
107; Corrupts registers:
[45]108; AX, BX, SI, DI
[41]109;--------------------------------------------------------------------
[369]110ALIGN MENU_JUMP_ALIGN
[41]111MenuBorders_AdjustDisplayContextForDrawingBorders:
[45]112 mov bl, ATTRIBUTES_ARE_USED
[52]113 mov ax, MenuCharOut_MenuTeletypeOutput
[45]114 CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInBL
[41]115
[52]116 call CharOutLineSplitter_GetFirstBorderLineColumnOffsetToAX
[41]117 CALL_DISPLAY_LIBRARY SetCharacterOutputParameterFromAX
118
119 call MenuLocation_GetTitleBordersTopLeftCoordinatesToAX
120 CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX
121
122 mov si, ATTRIBUTE_CHARS.cBordersAndBackground
123 jmp MenuAttribute_SetToDisplayContextFromTypeInSI
124
125
126;--------------------------------------------------------------------
[67]127; MenuBorders_GetNumberOfMiddleCharactersToDX
[41]128; Parameters
129; SS:BP: Ptr to MENU
130; Returns:
131; DX: Number of middle border characters when drawing border lines
132; Corrupts registers:
133; Nothing
134;--------------------------------------------------------------------
[369]135ALIGN MENU_JUMP_ALIGN
[67]136MenuBorders_GetNumberOfMiddleCharactersToDX:
[293]137 eMOVZX dx, [bp+MENUINIT.bWidth]
[41]138 sub dx, BYTE MENU_HORIZONTAL_BORDER_LINES
139 ret
140
141
142;--------------------------------------------------------------------
143; RefreshTitleBorders
144; Parameters
145; DX: Number of times to repeat middle character
146; SS:BP: Ptr to MENU
147; Returns:
148; Nothing
149; Corrupts registers:
150; AX, BX, CX, SI, DI
151;--------------------------------------------------------------------
[369]152ALIGN MENU_JUMP_ALIGN
[41]153RefreshTitleBorders:
154 call DrawTopBorderLine
[293]155 eMOVZX cx, [bp+MENUINIT.bTitleLines]
[41]156 jmp SHORT DrawTextBorderLinesByCXtimes
157
158;--------------------------------------------------------------------
159; RefreshInformationBorders
160; Parameters
161; DX: Number of times to repeat middle character
162; SS:BP: Ptr to MENU
163; Returns:
164; Nothing
165; Corrupts registers:
166; AX, BX, CX, SI, DI
167;--------------------------------------------------------------------
[369]168ALIGN MENU_JUMP_ALIGN
[41]169RefreshInformationBorders:
170 call DrawSeparationBorderLine
[293]171 eMOVZX cx, [bp+MENUINIT.bInfoLines]
[41]172 jmp SHORT DrawTextBorderLinesByCXtimes
173
174;--------------------------------------------------------------------
175; RefreshItemBorders
176; Parameters
177; DX: Number of times to repeat middle character
178; SS:BP: Ptr to MENU
179; Returns:
180; Nothing
181; Corrupts registers:
182; AX, BX, CX, SI, DI
183;--------------------------------------------------------------------
[369]184ALIGN MENU_JUMP_ALIGN
[41]185RefreshItemBorders:
186 call DrawSeparationBorderLine
187 call MenuScrollbars_GetMaxVisibleItemsOnPageToCX
[104]188 ; Fall to DrawTextBorderLinesByCXtimes
[41]189
190;--------------------------------------------------------------------
[104]191; DrawTextBorderLinesByCXtimes
[41]192; Parameters
193; CX: Number of border lines to draw
194; DX: Number of times to repeat middle character
195; SS:BP: Ptr to MENU
196; Returns:
197; Nothing
198; Corrupts registers:
199; AX, CX, SI, DI
200;--------------------------------------------------------------------
[104]201DrawTextBorderLinesByCXtimes:
202 jcxz .NoBorderLinesToDraw
[369]203ALIGN MENU_JUMP_ALIGN
[41]204.DrawBordersWithFunctionInBX:
[104]205 call DrawTextBorderLine
[41]206 loop .DrawBordersWithFunctionInBX
[104]207.NoBorderLinesToDraw:
[41]208 ret
209
210
211;--------------------------------------------------------------------
212; DrawTopBorderLine
213; DrawSeparationBorderLine
214; DrawBottomBorderLine
[60]215; DrawTimeoutCounterOverBottomBorderLine
[41]216; DrawBottomShadowLine
217; DrawTextBorderLine
218; Parameters
219; DX: Number of times to repeat middle character
220; SS:BP: Ptr to MENU
221; Returns:
222; Nothing
223; Corrupts registers:
224; AX, SI, DI
225;--------------------------------------------------------------------
[369]226ALIGN MENU_JUMP_ALIGN
[41]227DrawTopBorderLine:
228 mov si, g_rgbTopBorderCharacters
229 call PrintBorderCharactersFromCSSI
230 jmp SHORT PrintNewlineToEndBorderLine
231
[369]232ALIGN MENU_JUMP_ALIGN
[41]233DrawSeparationBorderLine:
234 mov si, g_rgbSeparationBorderCharacters
235 jmp SHORT PrintBorderCharactersFromCSSIandShadowCharacter
236
[369]237ALIGN MENU_JUMP_ALIGN
[41]238DrawBottomBorderLine:
239 mov si, g_rgbBottomBorderCharacters
[62]240 test BYTE [bp+MENU.bFlags], FLG_MENU_TIMEOUT_COUNTDOWN
241 jz SHORT PrintBorderCharactersFromCSSIandShadowCharacter
[41]242
[62]243 call DrawTimeoutCounterString
244 sub dx, BYTE MENU_TIMEOUT_STRING_CHARACTERS
245 mov si, g_BottomBorderWithTimeoutCharacters
246 call PrintBorderCharactersFromCSSIandShadowCharacter
247 add dx, BYTE MENU_TIMEOUT_STRING_CHARACTERS
[60]248 ret
249
[369]250ALIGN MENU_JUMP_ALIGN
[41]251DrawBottomShadowLine:
[104]252 CALL_DISPLAY_LIBRARY GetSoftwareCoordinatesToAX
253 inc ax ; Move one column left
254 CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX
[41]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
[369]262ALIGN MENU_JUMP_ALIGN
[41]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;--------------------------------------------------------------------
[369]278ALIGN MENU_JUMP_ALIGN
[41]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;--------------------------------------------------------------------
[369]296ALIGN MENU_JUMP_ALIGN
[41]297PrintNewlineToEndBorderLine:
[505]298 JMP_DISPLAY_LIBRARY PrintNewlineCharacters
[41]299
300
301;--------------------------------------------------------------------
302; PrintShadowCharactersByDXtimes
303; Parameters
304; DX: Number of shadow characters to print
305; SS:BP: Ptr to MENU
306; Returns:
307; Nothing
308; Corrupts registers:
309; AX, SI, DI
310;--------------------------------------------------------------------
[369]311ALIGN MENU_JUMP_ALIGN
[41]312PrintShadowCharactersByDXtimes:
313 CALL_DISPLAY_LIBRARY PushDisplayContext
314
315 mov si, ATTRIBUTE_CHARS.cShadow
316 call MenuAttribute_SetToDisplayContextFromTypeInSI
317
[45]318 push bx
319 mov bl, ATTRIBUTES_ARE_USED
[41]320 mov ax, FAST_OUTPUT_WITH_ATTRIBUTE_ONLY
[45]321 CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInBL
322 pop bx
[41]323
[67]324 call MenuBorders_PrintMultipleBorderCharactersFromAL ; AL does not matter
[41]325
[505]326 JMP_DISPLAY_LIBRARY PopDisplayContext
[41]327
328
329;--------------------------------------------------------------------
330; PrintBorderCharactersFromCSSI
331; Parameters
332; DX: Number of times to repeat middle character
333; CS:SI: Ptr to BORDER_CHARS
334; SS:BP: Ptr to MENU
335; Returns:
336; Nothing
337; Corrupts registers:
338; AX, SI, DI
339;--------------------------------------------------------------------
[369]340ALIGN MENU_JUMP_ALIGN
[41]341PrintBorderCharactersFromCSSI:
[223]342 cs lodsb ; Load from [cs:si+BORDER_CHARS.cLeft] to AL
[41]343 call MenuBorders_PrintSingleBorderCharacterFromAL
344
[223]345 cs lodsb ; Load from [cs:si+BORDER_CHARS.cMiddle] to AL
[67]346 call MenuBorders_PrintMultipleBorderCharactersFromAL
[41]347
[223]348 cs lodsb ; Load from [cs:si+BORDER_CHARS.cRight] to AL
[41]349 ; Fall to MenuBorders_PrintSingleBorderCharacterFromAL
350
351;--------------------------------------------------------------------
352; MenuBorders_PrintSingleBorderCharacterFromAL
[67]353; MenuBorders_PrintMultipleBorderCharactersFromAL
[41]354; Parameters
355; AL: Character to print
[67]356; DX: Repeat count (MenuBorders_PrintMultipleBorderCharactersFromAL)
[41]357; SS:BP: Ptr to MENU
358; Returns:
359; Nothing
360; Corrupts registers:
361; AX, DI
362;--------------------------------------------------------------------
[369]363ALIGN MENU_JUMP_ALIGN
[41]364MenuBorders_PrintSingleBorderCharacterFromAL:
[505]365 JMP_DISPLAY_LIBRARY PrintCharacterFromAL
[41]366
[369]367ALIGN MENU_JUMP_ALIGN
[67]368MenuBorders_PrintMultipleBorderCharactersFromAL:
[41]369 push cx
370 mov cx, dx
371 CALL_DISPLAY_LIBRARY PrintRepeatedCharacterFromALwithCountInCX
372 pop cx
373 ret
374
375
[60]376;--------------------------------------------------------------------
[62]377; DrawTimeoutCounterString
[60]378; Parameters
[62]379; SS:BP: Ptr to MENU
380; Returns:
381; Nothing
382; Corrupts registers:
383; AX, SI, DI
384;--------------------------------------------------------------------
[369]385ALIGN MENU_JUMP_ALIGN
[62]386DrawTimeoutCounterString:
387 call MenuTime_GetTimeoutSecondsLeftToAX
388 ; Fall to .PrintTimeoutStringWithSecondsInAX
389
390;--------------------------------------------------------------------
391; .PrintTimeoutStringWithSecondsInAX
392; Parameters
[60]393; AX: Seconds to print
394; SS:BP: Ptr to MENU
395; Returns:
396; Nothing
397; Corrupts registers:
398; AX, SI, DI
399;--------------------------------------------------------------------
[62]400.PrintTimeoutStringWithSecondsInAX:
[104]401 ; Get attribute to AX
402 xchg di, ax
403 mov si, ATTRIBUTE_CHARS.cNormalTimeout
404 cmp di, BYTE MENU_TIMEOUT_SECONDS_FOR_HURRY
405 eCMOVB si, ATTRIBUTE_CHARS.cHurryTimeout
406 call MenuAttribute_GetToAXfromTypeInSI
407
[60]408 push bp
409 mov bp, sp
[182]410 mov si, g_szSelectionTimeout
[60]411 push ax ; Push attribute
412 push di ; Push seconds
413 CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
414 pop bp
[62]415 ret
[60]416
[41]417; Lookup tables for border characters
418g_rgbTopBorderCharacters:
419istruc BORDER_CHARS
420 at BORDER_CHARS.cLeft, db DOUBLE_TOP_LEFT_CORNER
421 at BORDER_CHARS.cMiddle, db DOUBLE_HORIZONTAL
422 at BORDER_CHARS.cRight, db DOUBLE_TOP_RIGHT_CORNER
423iend
424
425g_rgbSeparationBorderCharacters:
426istruc BORDER_CHARS
427 at BORDER_CHARS.cLeft, db DOUBLE_VERTICAL_TO_RIGHT_SINGLE
428 at BORDER_CHARS.cMiddle, db SINGLE_HORIZONTAL
429 at BORDER_CHARS.cRight, db DOUBLE_VERTICAL_TO_LEFT_SINGLE
430iend
431
432g_rgbBottomBorderCharacters:
433istruc BORDER_CHARS
434 at BORDER_CHARS.cLeft, db DOUBLE_BOTTOM_LEFT_CORNER
435 at BORDER_CHARS.cMiddle, db DOUBLE_HORIZONTAL
436 at BORDER_CHARS.cRight, db DOUBLE_BOTTOM_RIGHT_CORNER
437iend
438
[62]439g_BottomBorderWithTimeoutCharacters:
440istruc BORDER_CHARS
441 at BORDER_CHARS.cLeft, db DOUBLE_RIGHT_HORIZONTAL_TO_SINGLE_VERTICAL
442 at BORDER_CHARS.cMiddle, db DOUBLE_HORIZONTAL
443 at BORDER_CHARS.cRight, db DOUBLE_BOTTOM_RIGHT_CORNER
444iend
445
[41]446g_rgbTextBorderCharacters:
447istruc BORDER_CHARS
448 at BORDER_CHARS.cLeft, db DOUBLE_VERTICAL
449 at BORDER_CHARS.cMiddle, db ' '
450 at BORDER_CHARS.cRight, db DOUBLE_VERTICAL
451iend
Note: See TracBrowser for help on using the repository browser.