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

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

Initial commit for Assembly Library.

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