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