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

Last change on this file since 126 was 105, checked in by Tomi Tilli, 14 years ago

Changes to Assembly Library:

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