1 | ; File name : MenuBorders.asm |
---|
2 | ; Project name : Assembly Library |
---|
3 | ; Created date : 14.7.2010 |
---|
4 | ; Last update : 25.11.2010 |
---|
5 | ; Author : Tomi Tilli |
---|
6 | ; Description : Functions for drawing menu borders. |
---|
7 | |
---|
8 | ; Struct containing border characters for different types of menu window lines |
---|
9 | struc BORDER_CHARS |
---|
10 | .cLeft resb 1 |
---|
11 | .cMiddle resb 1 |
---|
12 | .cRight resb 1 |
---|
13 | endstruc |
---|
14 | |
---|
15 | |
---|
16 | ; Section containing code |
---|
17 | SECTION .text |
---|
18 | |
---|
19 | ;-------------------------------------------------------------------- |
---|
20 | ; MenuBorders_RefreshAll |
---|
21 | ; Parameters |
---|
22 | ; SS:BP: Ptr to MENU |
---|
23 | ; Returns: |
---|
24 | ; Nothing |
---|
25 | ; Corrupts registers: |
---|
26 | ; AX, BX, CX, DX, SI, DI |
---|
27 | ;-------------------------------------------------------------------- |
---|
28 | ALIGN JUMP_ALIGN |
---|
29 | MenuBorders_RefreshAll: |
---|
30 | call MenuBorders_AdjustDisplayContextForDrawingBorders |
---|
31 | call GetNumberOfMiddleCharactersToDX |
---|
32 | call RefreshTitleBorders |
---|
33 | call RefreshItemBorders |
---|
34 | call RefreshInformationBorders |
---|
35 | call DrawBottomBorderLine |
---|
36 | call DrawTimeoutCounterOverBottomBorderLine |
---|
37 | jmp DrawBottomShadowLine |
---|
38 | |
---|
39 | |
---|
40 | ;-------------------------------------------------------------------- |
---|
41 | ; MenuBorders_RedrawBottomBorderLine |
---|
42 | ; Parameters |
---|
43 | ; SS:BP: Ptr to MENU |
---|
44 | ; Returns: |
---|
45 | ; Nothing |
---|
46 | ; Corrupts registers: |
---|
47 | ; AX, BX, DX, SI, DI |
---|
48 | ;-------------------------------------------------------------------- |
---|
49 | ALIGN JUMP_ALIGN |
---|
50 | MenuBorders_RedrawBottomBorderLine: |
---|
51 | call MenuBorders_AdjustDisplayContextForDrawingBorders |
---|
52 | call MenuLocation_GetBottomBordersTopLeftCoordinatesToAX |
---|
53 | CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX |
---|
54 | call GetNumberOfMiddleCharactersToDX |
---|
55 | jmp DrawBottomBorderLine |
---|
56 | |
---|
57 | |
---|
58 | ;-------------------------------------------------------------------- |
---|
59 | ; MenuBorders_RedrawTimeoutValue |
---|
60 | ; Parameters |
---|
61 | ; SS:BP: Ptr to MENU |
---|
62 | ; Returns: |
---|
63 | ; Nothing |
---|
64 | ; Corrupts registers: |
---|
65 | ; AX, BX, SI, DI |
---|
66 | ;-------------------------------------------------------------------- |
---|
67 | ALIGN JUMP_ALIGN |
---|
68 | MenuBorders_RedrawTimeoutValue: |
---|
69 | call MenuBorders_AdjustDisplayContextForDrawingBorders |
---|
70 | call MenuLocation_GetBottomBordersTopLeftCoordinatesToAX |
---|
71 | inc ah ; Increment for shadow border |
---|
72 | CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX |
---|
73 | jmp DrawTimeoutCounterOverBottomBorderLine |
---|
74 | |
---|
75 | |
---|
76 | ;-------------------------------------------------------------------- |
---|
77 | ; MenuBorders_AdjustDisplayContextForDrawingBorders |
---|
78 | ; Parameters |
---|
79 | ; SS:BP: Ptr to MENU |
---|
80 | ; Returns: |
---|
81 | ; Nothing |
---|
82 | ; Corrupts registers: |
---|
83 | ; AX, BX, SI, DI |
---|
84 | ;-------------------------------------------------------------------- |
---|
85 | ALIGN JUMP_ALIGN |
---|
86 | MenuBorders_AdjustDisplayContextForDrawingBorders: |
---|
87 | mov bl, ATTRIBUTES_ARE_USED |
---|
88 | mov ax, MenuCharOut_MenuTeletypeOutput |
---|
89 | CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInBL |
---|
90 | |
---|
91 | call CharOutLineSplitter_GetFirstBorderLineColumnOffsetToAX |
---|
92 | CALL_DISPLAY_LIBRARY SetCharacterOutputParameterFromAX |
---|
93 | |
---|
94 | call MenuLocation_GetTitleBordersTopLeftCoordinatesToAX |
---|
95 | CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX |
---|
96 | |
---|
97 | mov si, ATTRIBUTE_CHARS.cBordersAndBackground |
---|
98 | jmp MenuAttribute_SetToDisplayContextFromTypeInSI |
---|
99 | |
---|
100 | |
---|
101 | ;-------------------------------------------------------------------- |
---|
102 | ; MenuBorders_RefreshItemBorders |
---|
103 | ; Parameters |
---|
104 | ; SS:BP: Ptr to MENU |
---|
105 | ; Returns: |
---|
106 | ; Nothing |
---|
107 | ; Corrupts registers: |
---|
108 | ; AX, BX, CX, DX, SI, DI |
---|
109 | ;-------------------------------------------------------------------- |
---|
110 | ALIGN JUMP_ALIGN |
---|
111 | MenuBorders_RefreshItemBorders: |
---|
112 | call MenuBorders_AdjustDisplayContextForDrawingBorders |
---|
113 | call MenuLocation_GetItemBordersTopLeftCoordinatesToAX |
---|
114 | CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX |
---|
115 | |
---|
116 | call GetNumberOfMiddleCharactersToDX |
---|
117 | jmp SHORT RefreshItemBorders |
---|
118 | |
---|
119 | |
---|
120 | ;-------------------------------------------------------------------- |
---|
121 | ; GetNumberOfMiddleCharactersToDX |
---|
122 | ; Parameters |
---|
123 | ; SS:BP: Ptr to MENU |
---|
124 | ; Returns: |
---|
125 | ; DX: Number of middle border characters when drawing border lines |
---|
126 | ; Corrupts registers: |
---|
127 | ; Nothing |
---|
128 | ;-------------------------------------------------------------------- |
---|
129 | ALIGN JUMP_ALIGN |
---|
130 | GetNumberOfMiddleCharactersToDX: |
---|
131 | eMOVZX dx, BYTE [bp+MENUINIT.bWidth] |
---|
132 | sub dx, BYTE MENU_HORIZONTAL_BORDER_LINES |
---|
133 | ret |
---|
134 | |
---|
135 | |
---|
136 | ;-------------------------------------------------------------------- |
---|
137 | ; RefreshTitleBorders |
---|
138 | ; Parameters |
---|
139 | ; DX: Number of times to repeat middle character |
---|
140 | ; SS:BP: Ptr to MENU |
---|
141 | ; Returns: |
---|
142 | ; Nothing |
---|
143 | ; Corrupts registers: |
---|
144 | ; AX, BX, CX, SI, DI |
---|
145 | ;-------------------------------------------------------------------- |
---|
146 | ALIGN JUMP_ALIGN |
---|
147 | RefreshTitleBorders: |
---|
148 | call DrawTopBorderLine |
---|
149 | eMOVZX cx, BYTE [bp+MENUINIT.bTitleLines] |
---|
150 | jmp SHORT DrawTextBorderLinesByCXtimes |
---|
151 | |
---|
152 | ;-------------------------------------------------------------------- |
---|
153 | ; RefreshInformationBorders |
---|
154 | ; Parameters |
---|
155 | ; DX: Number of times to repeat middle character |
---|
156 | ; SS:BP: Ptr to MENU |
---|
157 | ; Returns: |
---|
158 | ; Nothing |
---|
159 | ; Corrupts registers: |
---|
160 | ; AX, BX, CX, SI, DI |
---|
161 | ;-------------------------------------------------------------------- |
---|
162 | ALIGN JUMP_ALIGN |
---|
163 | RefreshInformationBorders: |
---|
164 | call DrawSeparationBorderLine |
---|
165 | eMOVZX cx, BYTE [bp+MENUINIT.bInfoLines] |
---|
166 | jmp SHORT DrawTextBorderLinesByCXtimes |
---|
167 | |
---|
168 | ;-------------------------------------------------------------------- |
---|
169 | ; RefreshItemBorders |
---|
170 | ; Parameters |
---|
171 | ; DX: Number of times to repeat middle character |
---|
172 | ; SS:BP: Ptr to MENU |
---|
173 | ; Returns: |
---|
174 | ; Nothing |
---|
175 | ; Corrupts registers: |
---|
176 | ; AX, BX, CX, SI, DI |
---|
177 | ;-------------------------------------------------------------------- |
---|
178 | ALIGN JUMP_ALIGN |
---|
179 | RefreshItemBorders: |
---|
180 | call DrawSeparationBorderLine |
---|
181 | call MenuScrollbars_GetMaxVisibleItemsOnPageToCX |
---|
182 | DrawTextBorderLinesByCXtimes: |
---|
183 | mov bx, DrawTextBorderLine |
---|
184 | ; Fall to DrawBorderLinesByCXtimes |
---|
185 | |
---|
186 | ;-------------------------------------------------------------------- |
---|
187 | ; DrawBorderLinesByCXtimes |
---|
188 | ; Parameters |
---|
189 | ; BX: Offset to border drawing function |
---|
190 | ; CX: Number of border lines to draw |
---|
191 | ; DX: Number of times to repeat middle character |
---|
192 | ; SS:BP: Ptr to MENU |
---|
193 | ; Returns: |
---|
194 | ; Nothing |
---|
195 | ; Corrupts registers: |
---|
196 | ; AX, CX, SI, DI |
---|
197 | ;-------------------------------------------------------------------- |
---|
198 | DrawBorderLinesByCXtimes: |
---|
199 | jcxz .Return |
---|
200 | ALIGN JUMP_ALIGN |
---|
201 | .DrawBordersWithFunctionInBX: |
---|
202 | call bx |
---|
203 | loop .DrawBordersWithFunctionInBX |
---|
204 | .Return: |
---|
205 | ret |
---|
206 | |
---|
207 | |
---|
208 | ;-------------------------------------------------------------------- |
---|
209 | ; DrawTopBorderLine |
---|
210 | ; DrawSeparationBorderLine |
---|
211 | ; DrawBottomBorderLine |
---|
212 | ; DrawTimeoutCounterOverBottomBorderLine |
---|
213 | ; DrawBottomShadowLine |
---|
214 | ; DrawTextBorderLine |
---|
215 | ; Parameters |
---|
216 | ; DX: Number of times to repeat middle character |
---|
217 | ; SS:BP: Ptr to MENU |
---|
218 | ; Returns: |
---|
219 | ; Nothing |
---|
220 | ; Corrupts registers: |
---|
221 | ; AX, SI, DI |
---|
222 | ;-------------------------------------------------------------------- |
---|
223 | ALIGN JUMP_ALIGN |
---|
224 | DrawTopBorderLine: |
---|
225 | mov si, g_rgbTopBorderCharacters |
---|
226 | call PrintBorderCharactersFromCSSI |
---|
227 | jmp SHORT PrintNewlineToEndBorderLine |
---|
228 | |
---|
229 | ALIGN JUMP_ALIGN |
---|
230 | DrawSeparationBorderLine: |
---|
231 | mov si, g_rgbSeparationBorderCharacters |
---|
232 | jmp SHORT PrintBorderCharactersFromCSSIandShadowCharacter |
---|
233 | |
---|
234 | ALIGN JUMP_ALIGN |
---|
235 | DrawBottomBorderLine: |
---|
236 | mov si, g_rgbBottomBorderCharacters |
---|
237 | jmp SHORT PrintBorderCharactersFromCSSIandShadowCharacter |
---|
238 | |
---|
239 | ALIGN JUMP_ALIGN |
---|
240 | DrawTimeoutCounterOverBottomBorderLine: |
---|
241 | test BYTE [bp+MENU.bFlags], FLG_MENU_TIMEOUT_COUNTDOWN |
---|
242 | jz SHORT .NoNeedToDrawSinceTimeoutDisabled |
---|
243 | mov ax, (-1)<<8 ; Decrement row |
---|
244 | call MenuLocation_MoveCursorByALcolumnsAndAHrows |
---|
245 | call MenuTime_GetTimeoutSecondsLeftToAX |
---|
246 | call PrintTimeoutStringWithSecondsInAX |
---|
247 | jmp SHORT PrintNewlineToEndBorderLine |
---|
248 | .NoNeedToDrawSinceTimeoutDisabled: |
---|
249 | ret |
---|
250 | |
---|
251 | ALIGN JUMP_ALIGN |
---|
252 | DrawBottomShadowLine: |
---|
253 | mov ax, 1 ; Increment column |
---|
254 | call MenuLocation_MoveCursorByALcolumnsAndAHrows |
---|
255 | inc dx ; Increment repeat count... |
---|
256 | inc dx ; ...for both corner characters |
---|
257 | call PrintShadowCharactersByDXtimes |
---|
258 | dec dx ; Restore... |
---|
259 | dec dx ; ...DX |
---|
260 | ret |
---|
261 | |
---|
262 | ALIGN JUMP_ALIGN |
---|
263 | DrawTextBorderLine: |
---|
264 | mov si, g_rgbTextBorderCharacters |
---|
265 | ; Fall to PrintBorderCharactersFromCSSIandShadowCharacter |
---|
266 | |
---|
267 | ;-------------------------------------------------------------------- |
---|
268 | ; PrintBorderCharactersFromCSSIandShadowCharacter |
---|
269 | ; Parameters |
---|
270 | ; DX: Number of times to repeat middle character |
---|
271 | ; CS:SI: Ptr to BORDER_CHARS |
---|
272 | ; SS:BP: Ptr to MENU |
---|
273 | ; Returns: |
---|
274 | ; Nothing |
---|
275 | ; Corrupts registers: |
---|
276 | ; AX, SI, DI |
---|
277 | ;-------------------------------------------------------------------- |
---|
278 | ALIGN JUMP_ALIGN |
---|
279 | PrintBorderCharactersFromCSSIandShadowCharacter: |
---|
280 | call PrintBorderCharactersFromCSSI |
---|
281 | push dx |
---|
282 | mov dx, 1 |
---|
283 | call PrintShadowCharactersByDXtimes |
---|
284 | pop dx |
---|
285 | ; Fall to PrintNewlineToEndBorderLine |
---|
286 | |
---|
287 | ;-------------------------------------------------------------------- |
---|
288 | ; PrintNewlineToEndBorderLine |
---|
289 | ; Parameters |
---|
290 | ; SS:BP: Ptr to MENU |
---|
291 | ; Returns: |
---|
292 | ; Nothing |
---|
293 | ; Corrupts registers: |
---|
294 | ; AX, DI |
---|
295 | ;-------------------------------------------------------------------- |
---|
296 | ALIGN JUMP_ALIGN |
---|
297 | PrintNewlineToEndBorderLine: |
---|
298 | CALL_DISPLAY_LIBRARY PrintNewlineCharacters |
---|
299 | ret |
---|
300 | |
---|
301 | |
---|
302 | ;-------------------------------------------------------------------- |
---|
303 | ; PrintShadowCharactersByDXtimes |
---|
304 | ; Parameters |
---|
305 | ; DX: Number of shadow characters to print |
---|
306 | ; SS:BP: Ptr to MENU |
---|
307 | ; Returns: |
---|
308 | ; Nothing |
---|
309 | ; Corrupts registers: |
---|
310 | ; AX, SI, DI |
---|
311 | ;-------------------------------------------------------------------- |
---|
312 | ALIGN JUMP_ALIGN |
---|
313 | PrintShadowCharactersByDXtimes: |
---|
314 | CALL_DISPLAY_LIBRARY PushDisplayContext |
---|
315 | |
---|
316 | mov si, ATTRIBUTE_CHARS.cShadow |
---|
317 | call MenuAttribute_SetToDisplayContextFromTypeInSI |
---|
318 | |
---|
319 | push bx |
---|
320 | mov bl, ATTRIBUTES_ARE_USED |
---|
321 | mov ax, FAST_OUTPUT_WITH_ATTRIBUTE_ONLY |
---|
322 | CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInBL |
---|
323 | pop bx |
---|
324 | |
---|
325 | call PrintMultipleBorderCharactersFromAL ; AL does not matter |
---|
326 | |
---|
327 | CALL_DISPLAY_LIBRARY PopDisplayContext |
---|
328 | ret |
---|
329 | |
---|
330 | |
---|
331 | ;-------------------------------------------------------------------- |
---|
332 | ; PrintBorderCharactersFromCSSI |
---|
333 | ; Parameters |
---|
334 | ; DX: Number of times to repeat middle character |
---|
335 | ; CS:SI: Ptr to BORDER_CHARS |
---|
336 | ; SS:BP: Ptr to MENU |
---|
337 | ; Returns: |
---|
338 | ; Nothing |
---|
339 | ; Corrupts registers: |
---|
340 | ; AX, SI, DI |
---|
341 | ;-------------------------------------------------------------------- |
---|
342 | ALIGN JUMP_ALIGN |
---|
343 | PrintBorderCharactersFromCSSI: |
---|
344 | cld |
---|
345 | eSEG cs |
---|
346 | lodsb ; Load from [si+BORDER_CHARS.cLeft] to AL |
---|
347 | call MenuBorders_PrintSingleBorderCharacterFromAL |
---|
348 | |
---|
349 | eSEG cs |
---|
350 | lodsb ; Load from [si+BORDER_CHARS.cMiddle] to AL |
---|
351 | call PrintMultipleBorderCharactersFromAL |
---|
352 | |
---|
353 | eSEG cs |
---|
354 | lodsb ; Load from [si+BORDER_CHARS.cRight] to AL |
---|
355 | ; Fall to MenuBorders_PrintSingleBorderCharacterFromAL |
---|
356 | |
---|
357 | ;-------------------------------------------------------------------- |
---|
358 | ; MenuBorders_PrintSingleBorderCharacterFromAL |
---|
359 | ; PrintMultipleBorderCharactersFromAL |
---|
360 | ; Parameters |
---|
361 | ; AL: Character to print |
---|
362 | ; DX: Repeat count (PrintMultipleBorderCharactersFromAL) |
---|
363 | ; SS:BP: Ptr to MENU |
---|
364 | ; Returns: |
---|
365 | ; Nothing |
---|
366 | ; Corrupts registers: |
---|
367 | ; AX, DI |
---|
368 | ;-------------------------------------------------------------------- |
---|
369 | ALIGN JUMP_ALIGN |
---|
370 | MenuBorders_PrintSingleBorderCharacterFromAL: |
---|
371 | CALL_DISPLAY_LIBRARY PrintCharacterFromAL |
---|
372 | ret |
---|
373 | |
---|
374 | ALIGN JUMP_ALIGN |
---|
375 | PrintMultipleBorderCharactersFromAL: |
---|
376 | push cx |
---|
377 | mov cx, dx |
---|
378 | CALL_DISPLAY_LIBRARY PrintRepeatedCharacterFromALwithCountInCX |
---|
379 | pop cx |
---|
380 | ret |
---|
381 | |
---|
382 | |
---|
383 | ;-------------------------------------------------------------------- |
---|
384 | ; PrintTimeoutStringWithSecondsInAX |
---|
385 | ; Parameters |
---|
386 | ; AX: Seconds to print |
---|
387 | ; SS:BP: Ptr to MENU |
---|
388 | ; Returns: |
---|
389 | ; Nothing |
---|
390 | ; Corrupts registers: |
---|
391 | ; AX, SI, DI |
---|
392 | ;-------------------------------------------------------------------- |
---|
393 | ALIGN JUMP_ALIGN |
---|
394 | PrintTimeoutStringWithSecondsInAX: |
---|
395 | push bp |
---|
396 | |
---|
397 | xchg di, ax |
---|
398 | mov bp, sp |
---|
399 | call .GetTimeoutAttributeToAXfromSecondsInDI |
---|
400 | mov si, .szSelectionTimeout |
---|
401 | push ax ; Push attribute |
---|
402 | push di ; Push seconds |
---|
403 | CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI |
---|
404 | pop bp |
---|
405 | |
---|
406 | ; Draw right border with normal border color |
---|
407 | mov al, DOUBLE_RIGHT_HORIZONTAL_TO_SINGLE_VERTICAL |
---|
408 | jmp MenuBorders_PrintSingleBorderCharacterFromAL |
---|
409 | .szSelectionTimeout: |
---|
410 | db DOUBLE_BOTTOM_LEFT_CORNER |
---|
411 | db DOUBLE_LEFT_HORIZONTAL_TO_SINGLE_VERTICAL |
---|
412 | db "%AAutoselection in %2u s",NULL |
---|
413 | |
---|
414 | ;-------------------------------------------------------------------- |
---|
415 | ; .GetTimeoutAttributeToAXfromSecondsInDI |
---|
416 | ; Parameters |
---|
417 | ; DI: Seconds to print |
---|
418 | ; Returns: |
---|
419 | ; AX: Attribute byte for seconds |
---|
420 | ; Corrupts registers: |
---|
421 | ; SI |
---|
422 | ;-------------------------------------------------------------------- |
---|
423 | ALIGN JUMP_ALIGN |
---|
424 | .GetTimeoutAttributeToAXfromSecondsInDI: |
---|
425 | mov si, ATTRIBUTE_CHARS.cNormalTimeout |
---|
426 | cmp di, BYTE 3 |
---|
427 | eCMOVB si, ATTRIBUTE_CHARS.cHurryTimeout |
---|
428 | jmp MenuAttribute_GetToAXfromTypeInSI |
---|
429 | |
---|
430 | |
---|
431 | ; Lookup tables for border characters |
---|
432 | g_rgbTopBorderCharacters: |
---|
433 | istruc BORDER_CHARS |
---|
434 | at BORDER_CHARS.cLeft, db DOUBLE_TOP_LEFT_CORNER |
---|
435 | at BORDER_CHARS.cMiddle, db DOUBLE_HORIZONTAL |
---|
436 | at BORDER_CHARS.cRight, db DOUBLE_TOP_RIGHT_CORNER |
---|
437 | iend |
---|
438 | |
---|
439 | g_rgbSeparationBorderCharacters: |
---|
440 | istruc BORDER_CHARS |
---|
441 | at BORDER_CHARS.cLeft, db DOUBLE_VERTICAL_TO_RIGHT_SINGLE |
---|
442 | at BORDER_CHARS.cMiddle, db SINGLE_HORIZONTAL |
---|
443 | at BORDER_CHARS.cRight, db DOUBLE_VERTICAL_TO_LEFT_SINGLE |
---|
444 | iend |
---|
445 | |
---|
446 | g_rgbBottomBorderCharacters: |
---|
447 | istruc BORDER_CHARS |
---|
448 | at BORDER_CHARS.cLeft, db DOUBLE_BOTTOM_LEFT_CORNER |
---|
449 | at BORDER_CHARS.cMiddle, db DOUBLE_HORIZONTAL |
---|
450 | at BORDER_CHARS.cRight, db DOUBLE_BOTTOM_RIGHT_CORNER |
---|
451 | iend |
---|
452 | |
---|
453 | g_rgbTextBorderCharacters: |
---|
454 | istruc BORDER_CHARS |
---|
455 | at BORDER_CHARS.cLeft, db DOUBLE_VERTICAL |
---|
456 | at BORDER_CHARS.cMiddle, db ' ' |
---|
457 | at BORDER_CHARS.cRight, db DOUBLE_VERTICAL |
---|
458 | iend |
---|