source: xtideuniversalbios/trunk/Assembly_Library/Src/Menu/MenuScrollbars.asm@ 391

Last change on this file since 391 was 376, checked in by gregli@…, 13 years ago

WIDE checkin... Added copyright and license information to sorce files, as per the GPL instructions for usage.

File size: 7.7 KB
RevLine 
[41]1; Project name : Assembly Library
2; Description : Functions for drawing scroll bars over menu borders.
3
[376]4;
5; XTIDE Universal BIOS and Associated Tools
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.
12;
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
16; GNU General Public License for more details.
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
19
20
[41]21; Section containing code
22SECTION .text
23
24;--------------------------------------------------------------------
25; MenuScrollbars_AreScrollbarsNeeded
26; Parameters
27; SS:BP: Ptr to MENU
28; Returns:
29; CF: Set if scroll bars are needed
30; Cleared if no scroll bars needed
31; Corrupts registers:
[67]32; AX
[41]33;--------------------------------------------------------------------
[369]34ALIGN MENU_JUMP_ALIGN
[41]35MenuScrollbars_AreScrollbarsNeeded:
[67]36 xchg ax, cx
[41]37 call MenuScrollbars_GetMaxVisibleItemsOnPageToCX
38 cmp cx, [bp+MENUINIT.wItems] ; Set CF if max visible < total items
[67]39 xchg cx, ax
[41]40 ret
41
42
43;--------------------------------------------------------------------
44; MenuScrollbars_GetScrollCharacterToALForLineInDI
45; Parameters
46; DI: Index of item line to draw
47; SS:BP: Ptr to MENU
48; Returns:
49; AL: Scroll track or thumb character
50; Corrupts registers:
51; AH, CX, DX
52;--------------------------------------------------------------------
[369]53ALIGN MENU_JUMP_ALIGN
[41]54MenuScrollbars_GetScrollCharacterToALForLineInDI:
55 call MenuScrollbars_GetMaxVisibleItemsOnPageToCX
[181]56 ; Get first thumb line to AX
57 mov ax, [bp+MENU.wFirstVisibleItem]
58 call .CalculateFirstOrLastThumbLineToAX
59
[41]60 cmp di, ax ; Before first thumb line?
61 jb SHORT .ReturnTrackCharacter
62 call .GetLastThumbLineToAX
[181]63 cmp ax, di ; After last thumb line?
[369]64ALIGN MENU_JUMP_ALIGN
[41]65.ReturnTrackCharacter:
66 mov al, SCROLL_TRACK_CHARACTER
[181]67 jb SHORT .Return
68 mov al, SCROLL_THUMB_CHARACTER
[369]69ALIGN MENU_JUMP_ALIGN, ret
[181]70.Return:
[41]71 ret
72
73;--------------------------------------------------------------------
74; .GetLastThumbLineToAX
75; Parameters
76; CX: Max visible items on page
77; SS:BP: Ptr to MENU
78; Returns:
79; AX: Item line for last thumb character
80; Corrupts registers:
81; CX, DX
[133]82;--------------------------------------------------------------------
[369]83ALIGN MENU_JUMP_ALIGN
[41]84.GetLastThumbLineToAX:
85 call MenuScrollbars_GetLastVisibleItemOnPageToAX
[181]86 ; Fall to .CalculateFirstOrLastThumbLineToAX
[41]87
88;--------------------------------------------------------------------
[181]89; .CalculateFirstOrLastThumbLineToAX
[41]90; Parameters
[181]91; AX: Index of first or last visible item on page
[41]92; CX: Max visible items on page
93; SS:BP: Ptr to MENU
94; Returns:
95; AX: Item line for first thumb character
96; Corrupts registers:
97; CX, DX
98;--------------------------------------------------------------------
[369]99ALIGN MENU_JUMP_ALIGN
[41]100.CalculateFirstOrLastThumbLineToAX:
101 mul cx
102 div WORD [bp+MENUINIT.wItems]
103 ret ; (Visible items on page * First visible item on page) / total items
104
105
106;--------------------------------------------------------------------
107; MenuScrollbars_MoveHighlightedItemByAX
108; Parameters
109; AX: Signed offset to new item to be highlighted
110; SS:BP: Ptr to MENU
111; Returns:
112; Nothing
113; Corrupts registers:
114; AX, BX, CX, DX, SI, DI
115;--------------------------------------------------------------------
[369]116ALIGN MENU_JUMP_ALIGN
[41]117MenuScrollbars_MoveHighlightedItemByAX:
[52]118 mov cx, [bp+MENUINIT.wHighlightedItem]
[41]119 add cx, ax
[181]120 ; Fall to .RotateItemInCX
121
122;--------------------------------------------------------------------
123; .RotateItemInCX
124; Parameters
125; CX: Possibly under of overflown item to be rotated
126; SS:BP: Ptr to MENU
127; Returns:
128; CX: Valid item index
129; Corrupts registers:
130; DX
131;--------------------------------------------------------------------
132;.RotateItemInCX:
133 mov dx, [bp+MENUINIT.wItems]
134 test cx, cx
135 js SHORT .RotateNegativeItemInCX
136 sub cx, dx
137 jae SHORT .ScrollPageForNewItemInCX
138
[369]139ALIGN MENU_JUMP_ALIGN
[181]140.RotateNegativeItemInCX:
141 add cx, dx
[41]142 ; Fall to .ScrollPageForNewItemInCX
143
144;--------------------------------------------------------------------
145; .ScrollPageForNewItemInCX
146; Parameters
147; CX: New item to be highlighted
148; SS:BP: Ptr to MENU
149; Returns:
150; Nothing
151; Corrupts registers:
152; AX, BX, CX, DX, SI, DI
153;--------------------------------------------------------------------
[369]154ALIGN MENU_JUMP_ALIGN
[41]155.ScrollPageForNewItemInCX:
156 call MenuScrollbars_IsItemInCXonVisiblePage
157 jc SHORT .HighlightNewItemOnCX
158
159 mov dx, [bp+MENU.wFirstVisibleItem]
[52]160 sub dx, [bp+MENUINIT.wHighlightedItem]
[41]161
[181]162 ; Get MaxFirstVisibleItem to AX
[41]163 push cx
164 call MenuScrollbars_GetMaxVisibleItemsOnPageToCX
165 mov ax, [bp+MENUINIT.wItems]
166 sub ax, cx
167 pop cx
168
[181]169 add dx, cx
170 jns .DXisPositive
171 cwd ; This won't work if MaxFirstVisibleItem > 32767
172
[369]173ALIGN MENU_JUMP_ALIGN
[181]174.DXisPositive:
175 cmp ax, dx
176 jb .AXisLessThanDX
177 xchg dx, ax
[41]178
[369]179ALIGN MENU_JUMP_ALIGN
[181]180.AXisLessThanDX:
181 mov [bp+MENU.wFirstVisibleItem], ax
182 call MenuText_RefreshAllItems
[41]183
[369]184ALIGN MENU_JUMP_ALIGN
[181]185.HighlightNewItemOnCX:
186 jmp MenuEvent_HighlightItemFromCX
[41]187
188
189;--------------------------------------------------------------------
[105]190; MenuScrollbars_IsItemInCXonVisiblePage
[41]191; Parameters
192; CX: Item whose visibility is to be checked
193; SS:BP: Ptr to MENU
194; Returns:
195; CF: Set if item is on visible page
196; Cleared if item is not on visible page
197; Corrupts registers:
198; AX
199;--------------------------------------------------------------------
[369]200ALIGN MENU_JUMP_ALIGN
[41]201MenuScrollbars_IsItemInCXonVisiblePage:
[133]202 cmp [bp+MENU.wFirstVisibleItem], cx
203 ja SHORT .ItemIsNotVisible
[41]204
205 call MenuScrollbars_GetLastVisibleItemOnPageToAX
206 cmp cx, ax
207 ja SHORT .ItemIsNotVisible
208 stc ; Item is visible
[369]209ALIGN MENU_JUMP_ALIGN, ret
[41]210.ItemIsNotVisible:
211 ret
212
213
214;--------------------------------------------------------------------
[105]215; MenuScrollbars_GetLastVisibleItemOnPageToAX
[41]216; Parameters
217; SS:BP: Ptr to MENU
218; Returns:
219; AX: Index of last visible item on page
220; Corrupts registers:
221; Nothing
222;--------------------------------------------------------------------
[369]223ALIGN MENU_JUMP_ALIGN
[41]224MenuScrollbars_GetLastVisibleItemOnPageToAX:
[181]225 xchg cx, ax
[41]226 call MenuScrollbars_GetActualVisibleItemsOnPageToCX
227 xchg ax, cx
228 dec ax
229 add ax, [bp+MENU.wFirstVisibleItem]
230 ret
231
232
233;--------------------------------------------------------------------
234; MenuScrollbars_GetActualVisibleItemsOnPageToCX
235; Parameters
236; SS:BP: Ptr to MENU
237; Returns:
238; CX: Currently visible items
239; Corrupts registers:
240; Nothing
241;--------------------------------------------------------------------
[369]242ALIGN MENU_JUMP_ALIGN
[41]243MenuScrollbars_GetActualVisibleItemsOnPageToCX:
244 call MenuScrollbars_GetMaxVisibleItemsOnPageToCX
[181]245 cmp cx, [bp+MENUINIT.wItems]
246 jb SHORT .Return
247 mov cx, [bp+MENUINIT.wItems]
[369]248ALIGN MENU_JUMP_ALIGN, ret
[181]249.Return:
[41]250 ret
251
252
253;--------------------------------------------------------------------
254; MenuScrollbars_GetMaxVisibleItemsOnPageToCX
255; Parameters
256; SS:BP: Ptr to MENU
257; Returns:
258; CX: Maximum number of visible items
259; Corrupts registers:
260; Nothing
261;--------------------------------------------------------------------
[369]262ALIGN MENU_JUMP_ALIGN
[41]263MenuScrollbars_GetMaxVisibleItemsOnPageToCX:
[293]264 eMOVZX cx, [bp+MENUINIT.bHeight]
[41]265 sub cl, [bp+MENUINIT.bTitleLines]
266 sub cl, [bp+MENUINIT.bInfoLines]
267 sub cl, MENU_VERTICAL_BORDER_LINES
268 ret
Note: See TracBrowser for help on using the repository browser.