1 | ; Project name : Menu library |
---|
2 | ; Description : ASM library to menu system. |
---|
3 | ; Contains menu cursor functions. |
---|
4 | |
---|
5 | ;--------------- Equates ----------------------------- |
---|
6 | |
---|
7 | W_OFF_CRSR_STR EQU 0102h ; User string cursor offset |
---|
8 | |
---|
9 | |
---|
10 | ;-------------- Private global variables ------------- |
---|
11 | ; Section containing initialized data |
---|
12 | ;SECTION .data |
---|
13 | |
---|
14 | |
---|
15 | ;-------------- Public functions --------------------- |
---|
16 | ; Section containing code |
---|
17 | SECTION .text |
---|
18 | |
---|
19 | ;-------------------------------------------------------------------- |
---|
20 | ; Returns X and Y coordinates for menu top left corner. |
---|
21 | ; This function is used for calculating initial coordinates when |
---|
22 | ; initializing menu for first time. |
---|
23 | ; Parameters: |
---|
24 | ; SS:BP: Ptr to MENUVARS |
---|
25 | ; Returns: |
---|
26 | ; DL: X coordinate for centered menu |
---|
27 | ; DH: Y coordinate for centered menu |
---|
28 | ; Corrupts registers: |
---|
29 | ; AX, BX |
---|
30 | ;-------------------------------------------------------------------- |
---|
31 | ALIGN JUMP_ALIGN |
---|
32 | MenuCrsr_GetCenter: |
---|
33 | mov ah, 0Fh ; Get Current Video Mode |
---|
34 | int 10h |
---|
35 | mov dl, ah ; Copy column count to DL |
---|
36 | sub dl, [bp+MENUVARS.bWidth] ; Subtract menu width from columns |
---|
37 | shr dl, 1 ; Divide by 2 for start X |
---|
38 | mov dh, CNT_SCRN_ROW ; Load row count |
---|
39 | sub dh, [bp+MENUVARS.bHeight] ; Subtract menu height from rows |
---|
40 | shr dh, 1 ; Divide by 2 for start y |
---|
41 | ret |
---|
42 | |
---|
43 | |
---|
44 | ;-------------------------------------------------------------------- |
---|
45 | ; Sets cursor to start of menu string. |
---|
46 | ; MenuCrsr_Point1stItem Sets cursor to first menuitem string |
---|
47 | ; MenuCrsr_PointInfo Sets cursor to info string |
---|
48 | ; MenuCrsr_PointTitle Sets cursor to title string |
---|
49 | ; Parameters: |
---|
50 | ; SS:BP: Ptr to MENUVARS |
---|
51 | ; Returns: |
---|
52 | ; Nothing |
---|
53 | ; Corrupts registers: |
---|
54 | ; AX, BX, CX, DX |
---|
55 | ;-------------------------------------------------------------------- |
---|
56 | ALIGN JUMP_ALIGN |
---|
57 | MenuCrsr_Point1stItem: |
---|
58 | xor dx, dx ; Zero DX |
---|
59 | call MenuCrsr_PointItemBrdr ; Point to item border (left) |
---|
60 | mov cx, W_OFF_CRSR_STR & 0FFh ; Offset to user string (move X only) |
---|
61 | jmp MenuCrsr_Move ; Move cursor |
---|
62 | ALIGN JUMP_ALIGN |
---|
63 | MenuCrsr_PointInfo: |
---|
64 | xor dx, dx ; Zero DX |
---|
65 | call MenuCrsr_PointNfoBrdr ; Point to Info border (top left) |
---|
66 | mov cx, W_OFF_CRSR_STR ; Movement from border to user str |
---|
67 | jmp MenuCrsr_Move ; Move cursor |
---|
68 | ALIGN JUMP_ALIGN |
---|
69 | MenuCrsr_PointTitle: |
---|
70 | xor dx, dx ; Zero DX |
---|
71 | call MenuCrsr_PointTitleBrdr ; Point to Title border (top left) |
---|
72 | mov cx, W_OFF_CRSR_STR ; Movement from border to user str |
---|
73 | jmp MenuCrsr_Move ; Move cursor |
---|
74 | |
---|
75 | |
---|
76 | ;-------------------------------------------------------------------- |
---|
77 | ; Sets cursor to start of wanted menuitem string. |
---|
78 | ; |
---|
79 | ; MenuCrsr_PointNthItem |
---|
80 | ; Parameters: |
---|
81 | ; CX: Menuitem index where to set cursor |
---|
82 | ; SS:BP: Ptr to MENUVARS |
---|
83 | ; Returns: |
---|
84 | ; Nothing |
---|
85 | ; Corrupts registers: |
---|
86 | ; AX, BX, DX |
---|
87 | ;-------------------------------------------------------------------- |
---|
88 | ALIGN JUMP_ALIGN |
---|
89 | MenuCrsr_PointNthItem: |
---|
90 | push cx |
---|
91 | push cx |
---|
92 | call MenuCrsr_Point1stItem ; Point to topmost menuitem |
---|
93 | pop cx |
---|
94 | sub cx, [bp+MENUVARS.wItemTop] ; Number of newlines needed |
---|
95 | jcxz .Return |
---|
96 | ALIGN JUMP_ALIGN |
---|
97 | .NewLineLoop: |
---|
98 | call MenuDraw_NewlineStr |
---|
99 | loop .NewLineLoop |
---|
100 | ALIGN JUMP_ALIGN |
---|
101 | .Return: |
---|
102 | pop cx |
---|
103 | ret |
---|
104 | |
---|
105 | |
---|
106 | ;-------------------------------------------------------------------- |
---|
107 | ; Sets cursor to start of menu border. |
---|
108 | ; MenuCrsr_PointBelowBrdr Sets cursor to below menu bottom border |
---|
109 | ; MenuCrsr_PointNfoBrdr Sets cursor to top left corner of info borders |
---|
110 | ; MenuCrsr_PointItemBrdr Sets cursor to first menuitem left border |
---|
111 | ; MenuCrsr_PointTitleBrdr Sets cursor to top left corner of title borders |
---|
112 | ; Parameters: |
---|
113 | ; DX: 0 |
---|
114 | ; SS:BP: Ptr to MENUVARS |
---|
115 | ; Returns: |
---|
116 | ; Nothing |
---|
117 | ; Corrupts registers: |
---|
118 | ; AX, BX, DX |
---|
119 | ;-------------------------------------------------------------------- |
---|
120 | ALIGN JUMP_ALIGN |
---|
121 | MenuCrsr_PointBelowBrdr: |
---|
122 | mov dh, [bp+MENUVARS.bInfoH] ; Load info height without borders |
---|
123 | test dh, dh ; Info displayed? |
---|
124 | jz .BottomOnly ; If not, continue |
---|
125 | inc dh ; Increment Y for top border |
---|
126 | ALIGN JUMP_ALIGN |
---|
127 | .BottomOnly: |
---|
128 | inc dh ; Increment Y for bottom border |
---|
129 | ALIGN JUMP_ALIGN |
---|
130 | MenuCrsr_PointNfoBrdr: |
---|
131 | add dh, [bp+MENUVARS.bVisCnt] ; Load max number of visible menuitems |
---|
132 | ALIGN JUMP_ALIGN |
---|
133 | MenuCrsr_PointItemBrdr: |
---|
134 | inc dh ; Add title top border |
---|
135 | mov al, [bp+MENUVARS.bTitleH] ; Load title height |
---|
136 | add dh, al ; Add title height to DH |
---|
137 | test al, al ; Title visible? |
---|
138 | jz MenuCrsr_PointTitleBrdr ; If not, jump to set cursor |
---|
139 | inc dh ; Title bottom border |
---|
140 | ALIGN JUMP_ALIGN |
---|
141 | MenuCrsr_PointTitleBrdr: |
---|
142 | add dx, [bp+MENUVARS.wInitCrsr] ; Add initial cursor position |
---|
143 | ; Fall to MenuCrsr_SetCursor |
---|
144 | |
---|
145 | |
---|
146 | ;-------------------------------------------------------------------- |
---|
147 | ; Sets cursor position in DX. |
---|
148 | ; Parameters: |
---|
149 | ; DL: Cursor X coordinate |
---|
150 | ; DH: Cursor Y coordinate |
---|
151 | ; Returns: |
---|
152 | ; Nothing |
---|
153 | ; Corrupts registers: |
---|
154 | ; AX, BX |
---|
155 | ;-------------------------------------------------------------------- |
---|
156 | ALIGN JUMP_ALIGN |
---|
157 | MenuCrsr_SetCursor: |
---|
158 | mov ah, 02h ; Set Cursor Position and Size |
---|
159 | SKIP2B bx ; mov bx, <next instruction> |
---|
160 | ; Fall through to MenuCrsr_GetCursor |
---|
161 | |
---|
162 | |
---|
163 | ;-------------------------------------------------------------------- |
---|
164 | ; Return cursor position in DX. |
---|
165 | ; Parameters: |
---|
166 | ; Nothing |
---|
167 | ; Returns: |
---|
168 | ; CL: Cursor start scan line |
---|
169 | ; CH: Cursor end scan line |
---|
170 | ; DL: Cursor X coordinate |
---|
171 | ; DH: Cursor Y coordinate |
---|
172 | ; Corrupts registers: |
---|
173 | ; AX, BX |
---|
174 | ;-------------------------------------------------------------------- |
---|
175 | ;ALIGN JUMP_ALIGN |
---|
176 | MenuCrsr_GetCursor: |
---|
177 | mov ah, 03h ; Get Cursor Position and Size |
---|
178 | xor bx, bx ; Zero page |
---|
179 | int 10h |
---|
180 | ret |
---|
181 | |
---|
182 | |
---|
183 | ;-------------------------------------------------------------------- |
---|
184 | ; Moves cursor from current location. |
---|
185 | ; Parameters: |
---|
186 | ; CL: Cursor X coordinate movement (can be negative) |
---|
187 | ; CH: Cursor Y coordinate movement (can be negative) |
---|
188 | ; Returns: |
---|
189 | ; Nothing |
---|
190 | ; Corrupts registers: |
---|
191 | ; AX, BX, DX |
---|
192 | ;-------------------------------------------------------------------- |
---|
193 | ALIGN JUMP_ALIGN |
---|
194 | MenuCrsr_Move: |
---|
195 | push cx |
---|
196 | call MenuCrsr_GetCursor ; Get cursor position to DX |
---|
197 | pop cx |
---|
198 | add dl, cl ; Move X |
---|
199 | add dh, ch ; Move Y |
---|
200 | jmp MenuCrsr_SetCursor |
---|
201 | |
---|
202 | |
---|
203 | ;-------------------------------------------------------------------- |
---|
204 | ; Shows cursor that has been hidden. |
---|
205 | ; Parameters: |
---|
206 | ; Nothing |
---|
207 | ; Returns: |
---|
208 | ; Nothing |
---|
209 | ; Corrupts registers: |
---|
210 | ; AX, CX |
---|
211 | ;-------------------------------------------------------------------- |
---|
212 | ALIGN JUMP_ALIGN |
---|
213 | MenuCrsr_Show: |
---|
214 | mov cx, 0607h ; Two line cursor near or at the bottom of cell |
---|
215 | jmp MenuCrsr_SetShape |
---|
216 | |
---|
217 | |
---|
218 | ;-------------------------------------------------------------------- |
---|
219 | ; Hides cursor. |
---|
220 | ; Parameters: |
---|
221 | ; Nothing |
---|
222 | ; Returns: |
---|
223 | ; Nothing |
---|
224 | ; Corrupts registers: |
---|
225 | ; AX, CX |
---|
226 | ;-------------------------------------------------------------------- |
---|
227 | ALIGN JUMP_ALIGN |
---|
228 | MenuCrsr_Hide: |
---|
229 | mov cx, 2000h |
---|
230 | ; Fall to MenuCrsr_SetShape |
---|
231 | |
---|
232 | ;-------------------------------------------------------------------- |
---|
233 | ; Sets cursor shape. |
---|
234 | ; Parameters: |
---|
235 | ; CL: Cursor start scan line |
---|
236 | ; CH: Cursor end scan line |
---|
237 | ; Returns: |
---|
238 | ; Nothing |
---|
239 | ; Corrupts registers: |
---|
240 | ; AX |
---|
241 | ;-------------------------------------------------------------------- |
---|
242 | ALIGN JUMP_ALIGN |
---|
243 | MenuCrsr_SetShape: |
---|
244 | mov ax, 0103h ; Set Text-Mode Cursor Shape |
---|
245 | ; AL=assumed video mode to prevent lock ups on some BIOSes |
---|
246 | int 10h |
---|
247 | ret |
---|