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

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

Changes:

  • Update of the copyright notices to include the year 2013.
File size: 7.7 KB
Line 
1; Project name : Assembly Library
2; Description : Functions for drawing scroll bars over menu borders.
3
4;
5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 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
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:
32; AX
33;--------------------------------------------------------------------
34ALIGN MENU_JUMP_ALIGN
35MenuScrollbars_AreScrollbarsNeeded:
36 xchg ax, cx
37 call MenuScrollbars_GetMaxVisibleItemsOnPageToCX
38 cmp cx, [bp+MENUINIT.wItems] ; Set CF if max visible < total items
39 xchg cx, ax
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;--------------------------------------------------------------------
53ALIGN MENU_JUMP_ALIGN
54MenuScrollbars_GetScrollCharacterToALForLineInDI:
55 call MenuScrollbars_GetMaxVisibleItemsOnPageToCX
56 ; Get first thumb line to AX
57 mov ax, [bp+MENU.wFirstVisibleItem]
58 call .CalculateFirstOrLastThumbLineToAX
59
60 cmp di, ax ; Before first thumb line?
61 jb SHORT .ReturnTrackCharacter
62 call .GetLastThumbLineToAX
63 cmp ax, di ; After last thumb line?
64ALIGN MENU_JUMP_ALIGN
65.ReturnTrackCharacter:
66 mov al, SCROLL_TRACK_CHARACTER
67 jb SHORT .Return
68 mov al, SCROLL_THUMB_CHARACTER
69ALIGN MENU_JUMP_ALIGN, ret
70.Return:
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; DX
82;--------------------------------------------------------------------
83ALIGN MENU_JUMP_ALIGN
84.GetLastThumbLineToAX:
85 call MenuScrollbars_GetLastVisibleItemOnPageToAX
86 ; Fall to .CalculateFirstOrLastThumbLineToAX
87
88;--------------------------------------------------------------------
89; .CalculateFirstOrLastThumbLineToAX
90; Parameters
91; AX: Index of first or last visible item on page
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; DX
98;--------------------------------------------------------------------
99ALIGN MENU_JUMP_ALIGN
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;--------------------------------------------------------------------
116ALIGN MENU_JUMP_ALIGN
117MenuScrollbars_MoveHighlightedItemByAX:
118 mov cx, [bp+MENUINIT.wHighlightedItem]
119 add cx, ax
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
139ALIGN MENU_JUMP_ALIGN
140.RotateNegativeItemInCX:
141 add cx, dx
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;--------------------------------------------------------------------
154ALIGN MENU_JUMP_ALIGN
155.ScrollPageForNewItemInCX:
156 call MenuScrollbars_IsItemInCXonVisiblePage
157 jc SHORT .HighlightNewItemOnCX
158
159 mov dx, [bp+MENU.wFirstVisibleItem]
160 sub dx, [bp+MENUINIT.wHighlightedItem]
161
162 ; Get MaxFirstVisibleItem to AX
163 push cx
164 call MenuScrollbars_GetMaxVisibleItemsOnPageToCX
165 mov ax, [bp+MENUINIT.wItems]
166 sub ax, cx
167 pop cx
168
169 add dx, cx
170 jns .DXisPositive
171 cwd ; This won't work if MaxFirstVisibleItem > 32767
172
173ALIGN MENU_JUMP_ALIGN
174.DXisPositive:
175 cmp ax, dx
176 jb .AXisLessThanDX
177 xchg dx, ax
178
179ALIGN MENU_JUMP_ALIGN
180.AXisLessThanDX:
181 mov [bp+MENU.wFirstVisibleItem], ax
182 call MenuText_RefreshAllItems
183
184ALIGN MENU_JUMP_ALIGN
185.HighlightNewItemOnCX:
186 jmp MenuEvent_HighlightItemFromCX
187
188
189;--------------------------------------------------------------------
190; MenuScrollbars_IsItemInCXonVisiblePage
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;--------------------------------------------------------------------
200ALIGN MENU_JUMP_ALIGN
201MenuScrollbars_IsItemInCXonVisiblePage:
202 cmp [bp+MENU.wFirstVisibleItem], cx
203 ja SHORT .ItemIsNotVisible
204
205 call MenuScrollbars_GetLastVisibleItemOnPageToAX
206 cmp cx, ax
207 ja SHORT .ItemIsNotVisible
208 stc ; Item is visible
209ALIGN MENU_JUMP_ALIGN, ret
210.ItemIsNotVisible:
211 ret
212
213
214;--------------------------------------------------------------------
215; MenuScrollbars_GetLastVisibleItemOnPageToAX
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;--------------------------------------------------------------------
223ALIGN MENU_JUMP_ALIGN
224MenuScrollbars_GetLastVisibleItemOnPageToAX:
225 xchg cx, ax
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;--------------------------------------------------------------------
242ALIGN MENU_JUMP_ALIGN
243MenuScrollbars_GetActualVisibleItemsOnPageToCX:
244 call MenuScrollbars_GetMaxVisibleItemsOnPageToCX
245 cmp cx, [bp+MENUINIT.wItems]
246 jb SHORT .Return
247 mov cx, [bp+MENUINIT.wItems]
248ALIGN MENU_JUMP_ALIGN, ret
249.Return:
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;--------------------------------------------------------------------
262ALIGN MENU_JUMP_ALIGN
263MenuScrollbars_GetMaxVisibleItemsOnPageToCX:
264 eMOVZX cx, [bp+MENUINIT.bHeight]
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.