1 | ; Project name : Assembly Library |
---|
2 | ; Description : Functions for managing display context. |
---|
3 | |
---|
4 | ; |
---|
5 | ; XTIDE Universal BIOS and Associated Tools |
---|
6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team. |
---|
7 | ; |
---|
8 | ; This program is free software; you can redistribute it and/or modify |
---|
9 | ; it under the terms of the GNU General Public License as published by |
---|
10 | ; the Free Software Foundation; either version 2 of the License, or |
---|
11 | ; (at your option) any later version. |
---|
12 | ; |
---|
13 | ; This program is distributed in the hope that it will be useful, |
---|
14 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | ; GNU General Public License for more details. |
---|
17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
18 | ; |
---|
19 | |
---|
20 | ; Section containing code |
---|
21 | SECTION .text |
---|
22 | |
---|
23 | ;-------------------------------------------------------------------- |
---|
24 | ; DisplayContext_Initialize |
---|
25 | ; Parameters: |
---|
26 | ; DS: BDA segment (zero) |
---|
27 | ; Returns: |
---|
28 | ; Nothing |
---|
29 | ; Corrupts registers: |
---|
30 | ; AX, DX, DI |
---|
31 | ;-------------------------------------------------------------------- |
---|
32 | ALIGN DISPLAY_JUMP_ALIGN |
---|
33 | DisplayContext_Initialize: |
---|
34 | mov WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], DEFAULT_CHARACTER_OUTPUT |
---|
35 | mov BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], SCREEN_BACKGROUND_ATTRIBUTE |
---|
36 | call DisplayCursor_GetDefaultCursorShapeToAX |
---|
37 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCursorShape], ax |
---|
38 | ; Fall to .DetectAndSetDisplaySegment |
---|
39 | |
---|
40 | ;-------------------------------------------------------------------- |
---|
41 | ; .DetectAndSetDisplaySegment |
---|
42 | ; Parameters: |
---|
43 | ; DS: BDA segment (zero) |
---|
44 | ; Returns: |
---|
45 | ; Nothing |
---|
46 | ; Corrupts registers: |
---|
47 | ; AX, DX |
---|
48 | ;-------------------------------------------------------------------- |
---|
49 | .DetectAndSetDisplaySegment: |
---|
50 | mov ax, COLOR_TEXT_SEGMENT |
---|
51 | cmp BYTE [VIDEO_BDA.bMode], MDA_TEXT_MODE |
---|
52 | eCMOVE ah, MONO_TEXT_SEGMENT >> 8 |
---|
53 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], ax |
---|
54 | ; Fall to .InitializeFlags |
---|
55 | |
---|
56 | ;-------------------------------------------------------------------- |
---|
57 | ; .InitializeFlags |
---|
58 | ; Parameters: |
---|
59 | ; DS: BDA segment (zero) |
---|
60 | ; Returns: |
---|
61 | ; Nothing |
---|
62 | ; Corrupts registers: |
---|
63 | ; AX, DX |
---|
64 | ;-------------------------------------------------------------------- |
---|
65 | .InitializeFlags: |
---|
66 | mov dl, FLG_CONTEXT_ATTRIBUTES |
---|
67 | call CgaSnow_IsCgaPresent |
---|
68 | jnc SHORT .DoNotSetCgaFlag |
---|
69 | or dl, FLG_CONTEXT_CGA |
---|
70 | .DoNotSetCgaFlag: |
---|
71 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], dl |
---|
72 | ; Fall to .InitializeCursor |
---|
73 | |
---|
74 | ;-------------------------------------------------------------------- |
---|
75 | ; .InitializeCursor |
---|
76 | ; Parameters: |
---|
77 | ; DS: BDA segment (zero) |
---|
78 | ; Returns: |
---|
79 | ; Nothing |
---|
80 | ; Corrupts registers: |
---|
81 | ; AX, DX |
---|
82 | ;-------------------------------------------------------------------- |
---|
83 | .InitializeCursor: |
---|
84 | call DisplayCursor_GetHardwareCoordinatesToAX ; Coordinates before init |
---|
85 | call DisplayCursor_SetCoordinatesFromAX ; Cursor to Display Context |
---|
86 | ; Fall to DisplayContext_SynchronizeToHardware |
---|
87 | |
---|
88 | ;-------------------------------------------------------------------- |
---|
89 | ; DisplayContext_SynchronizeToHardware |
---|
90 | ; Parameters: |
---|
91 | ; DS: BDA segment (zero) |
---|
92 | ; Returns: |
---|
93 | ; Nothing |
---|
94 | ; Corrupts registers: |
---|
95 | ; AX, DX |
---|
96 | ;-------------------------------------------------------------------- |
---|
97 | ALIGN DISPLAY_JUMP_ALIGN |
---|
98 | DisplayContext_SynchronizeToHardware: |
---|
99 | call DisplayPage_SynchronizeToHardware |
---|
100 | call DisplayCursor_SynchronizeShapeToHardware |
---|
101 | jmp DisplayCursor_SynchronizeCoordinatesToHardware |
---|
102 | |
---|
103 | |
---|
104 | %ifdef INCLUDE_MENU_LIBRARY |
---|
105 | |
---|
106 | ;-------------------------------------------------------------------- |
---|
107 | ; DisplayContext_Push |
---|
108 | ; Parameters: |
---|
109 | ; Nothing |
---|
110 | ; Returns: |
---|
111 | ; Nothing |
---|
112 | ; Corrupts registers: |
---|
113 | ; AX, DI |
---|
114 | ;-------------------------------------------------------------------- |
---|
115 | ALIGN DISPLAY_JUMP_ALIGN |
---|
116 | DisplayContext_Push: |
---|
117 | mov di, ds ; Backup DS |
---|
118 | LOAD_BDA_SEGMENT_TO ds, ax |
---|
119 | pop ax ; Pop return address |
---|
120 | |
---|
121 | %ifndef CHECK_FOR_UNUSED_ENTRYPOINTS |
---|
122 | %assign i 0 |
---|
123 | %rep DISPLAY_CONTEXT_size / 2 |
---|
124 | push WORD [VIDEO_BDA.displayContext + i] |
---|
125 | %assign i i+2 |
---|
126 | %endrep |
---|
127 | %endif |
---|
128 | |
---|
129 | mov ds, di ; Restore DS |
---|
130 | jmp ax |
---|
131 | |
---|
132 | ;-------------------------------------------------------------------- |
---|
133 | ; DisplayContext_Pop |
---|
134 | ; Parameters: |
---|
135 | ; Nothing |
---|
136 | ; Returns: |
---|
137 | ; Nothing |
---|
138 | ; Corrupts registers: |
---|
139 | ; AX, DI |
---|
140 | ;-------------------------------------------------------------------- |
---|
141 | ALIGN DISPLAY_JUMP_ALIGN |
---|
142 | DisplayContext_Pop: |
---|
143 | mov di, ds ; Backup DS |
---|
144 | LOAD_BDA_SEGMENT_TO ds, ax |
---|
145 | pop ax ; Pop return address |
---|
146 | |
---|
147 | %ifndef CHECK_FOR_UNUSED_ENTRYPOINTS |
---|
148 | %assign i DISPLAY_CONTEXT_size-2 |
---|
149 | %rep DISPLAY_CONTEXT_size / 2 |
---|
150 | pop WORD [VIDEO_BDA.displayContext + i] |
---|
151 | %assign i i-2 |
---|
152 | %endrep |
---|
153 | %endif |
---|
154 | |
---|
155 | push ax ; Push return address |
---|
156 | push dx |
---|
157 | call DisplayContext_SynchronizeToHardware |
---|
158 | pop dx |
---|
159 | mov ds, di ; Restore DS |
---|
160 | ret |
---|
161 | %endif |
---|
162 | |
---|
163 | ;-------------------------------------------------------------------- |
---|
164 | ; DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX |
---|
165 | ; Parameters: |
---|
166 | ; CX: Off screen buffer length in characters |
---|
167 | ; ES:BX: Ptr to off screen buffer |
---|
168 | ; Returns: |
---|
169 | ; Nothing |
---|
170 | ; Corrupts registers: |
---|
171 | ; AX, DI |
---|
172 | ;-------------------------------------------------------------------- |
---|
173 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS |
---|
174 | ALIGN DISPLAY_JUMP_ALIGN |
---|
175 | DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX: |
---|
176 | push ds |
---|
177 | |
---|
178 | LOAD_BDA_SEGMENT_TO ds, di |
---|
179 | xchg ax, bx |
---|
180 | mov bx, es |
---|
181 | call DisplayContext_SetCharacterPointerFromBXAX ; ES:DI now has the pointer |
---|
182 | |
---|
183 | mov bl, ATTRIBUTES_NOT_USED |
---|
184 | mov ax, BUFFER_OUTPUT_WITH_CHAR_ONLY |
---|
185 | call DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL |
---|
186 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], cx |
---|
187 | |
---|
188 | mov bx, di |
---|
189 | pop ds |
---|
190 | ret |
---|
191 | |
---|
192 | %endif ; INCLUDE_MENU_LIBRARY |
---|
193 | |
---|
194 | |
---|
195 | ;-------------------------------------------------------------------- |
---|
196 | ; DisplayContext_SetCharacterPointerFromBXAX |
---|
197 | ; Parameters: |
---|
198 | ; BX:AX: Ptr to destination for next character to output |
---|
199 | ; DS: BDA segment (zero) |
---|
200 | ; Returns: |
---|
201 | ; ES:DI: Pointer that was in BX:AX |
---|
202 | ; Corrupts registers: |
---|
203 | ; AX |
---|
204 | ;-------------------------------------------------------------------- |
---|
205 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS |
---|
206 | ALIGN DISPLAY_JUMP_ALIGN |
---|
207 | DisplayContext_SetCharacterPointerFromBXAX: |
---|
208 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], ax |
---|
209 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], bx |
---|
210 | xchg di, ax |
---|
211 | mov es, bx |
---|
212 | ret |
---|
213 | %endif |
---|
214 | |
---|
215 | |
---|
216 | ;-------------------------------------------------------------------- |
---|
217 | ; DisplayContext_GetCharacterPointerToBXAX |
---|
218 | ; Parameters: |
---|
219 | ; DS: BDA segment (zero) |
---|
220 | ; Returns: |
---|
221 | ; BX:AX: Ptr to destination for next character to output |
---|
222 | ; Corrupts registers: |
---|
223 | ; Nothing |
---|
224 | ;-------------------------------------------------------------------- |
---|
225 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS |
---|
226 | ALIGN DISPLAY_JUMP_ALIGN |
---|
227 | DisplayContext_GetCharacterPointerToBXAX: |
---|
228 | mov ax, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition] |
---|
229 | mov bx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2] |
---|
230 | ret |
---|
231 | %endif |
---|
232 | |
---|
233 | %ifdef INCLUDE_MENU_LIBRARY |
---|
234 | |
---|
235 | ;-------------------------------------------------------------------- |
---|
236 | ; DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL |
---|
237 | ; Parameters: |
---|
238 | ; AX: Offset to character output function |
---|
239 | ; BL: Attribute Flag |
---|
240 | ; DS: BDA segment (zero) |
---|
241 | ; Returns: |
---|
242 | ; Nothing |
---|
243 | ; Corrupts registers: |
---|
244 | ; BL |
---|
245 | ;-------------------------------------------------------------------- |
---|
246 | ALIGN DISPLAY_JUMP_ALIGN |
---|
247 | DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL: |
---|
248 | and bl, FLG_CONTEXT_ATTRIBUTES |
---|
249 | and BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], ~FLG_CONTEXT_ATTRIBUTES |
---|
250 | or [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], bl |
---|
251 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], ax |
---|
252 | ret |
---|
253 | |
---|
254 | |
---|
255 | ;-------------------------------------------------------------------- |
---|
256 | ; DisplayContext_SetCharacterAttributeFromAL |
---|
257 | ; Parameters: |
---|
258 | ; AL: Character attribute |
---|
259 | ; DS: BDA segment (zero) |
---|
260 | ; Returns: |
---|
261 | ; Nothing |
---|
262 | ; Corrupts registers: |
---|
263 | ; Nothing |
---|
264 | ;-------------------------------------------------------------------- |
---|
265 | ALIGN DISPLAY_JUMP_ALIGN |
---|
266 | DisplayContext_SetCharacterAttributeFromAL: |
---|
267 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al |
---|
268 | ret |
---|
269 | |
---|
270 | |
---|
271 | ;-------------------------------------------------------------------- |
---|
272 | ; DisplayContext_SetCharacterOutputParameterFromAX |
---|
273 | ; Parameters: |
---|
274 | ; AX: Parameter for Character Output function |
---|
275 | ; DS: BDA segment (zero) |
---|
276 | ; Returns: |
---|
277 | ; Nothing |
---|
278 | ; Corrupts registers: |
---|
279 | ; Nothing |
---|
280 | ;-------------------------------------------------------------------- |
---|
281 | ALIGN DISPLAY_JUMP_ALIGN |
---|
282 | DisplayContext_SetCharacterOutputParameterFromAX: |
---|
283 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], ax |
---|
284 | ret |
---|
285 | |
---|
286 | %endif ; INCLUDE_MENU_LIBRARY |
---|
287 | |
---|
288 | ;-------------------------------------------------------------------- |
---|
289 | ; DisplayContext_GetCharacterOutputParameterToDX |
---|
290 | ; Parameters: |
---|
291 | ; DS: BDA segment (zero) |
---|
292 | ; Returns: |
---|
293 | ; DX: User parameter for Character Output function |
---|
294 | ; Corrupts registers: |
---|
295 | ; Nothing |
---|
296 | ;-------------------------------------------------------------------- |
---|
297 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS OR EXCLUDE_FROM_XTIDECFG ; This is currently unused (dead code) |
---|
298 | ALIGN DISPLAY_JUMP_ALIGN |
---|
299 | DisplayContext_GetCharacterOutputParameterToDX: |
---|
300 | mov dx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam] |
---|
301 | ret |
---|
302 | %endif |
---|
303 | |
---|
304 | |
---|
305 | ;-------------------------------------------------------------------- |
---|
306 | ; DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX |
---|
307 | ; Parameters: |
---|
308 | ; AX: Offset in bytes from some character to another |
---|
309 | ; DS: BDA segment (zero) |
---|
310 | ; Returns: |
---|
311 | ; AX: Offset in characters from some character to another |
---|
312 | ; Corrupts registers: |
---|
313 | ; Nothing |
---|
314 | ;-------------------------------------------------------------------- |
---|
315 | %ifndef MODULE_STRINGS_COMPRESSED |
---|
316 | ALIGN DISPLAY_JUMP_ALIGN |
---|
317 | DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX: |
---|
318 | test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES |
---|
319 | jz SHORT ReturnOffsetInAX |
---|
320 | sar ax, 1 ; BYTE count to WORD count |
---|
321 | ret |
---|
322 | %endif |
---|
323 | |
---|
324 | |
---|
325 | ;-------------------------------------------------------------------- |
---|
326 | ; DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX |
---|
327 | ; Parameters: |
---|
328 | ; AX: Offset in characters from some character to another |
---|
329 | ; DS: BDA segment (zero) |
---|
330 | ; Returns: |
---|
331 | ; AX: Offset in bytes from some character to another |
---|
332 | ; Corrupts registers: |
---|
333 | ; Nothing |
---|
334 | ;-------------------------------------------------------------------- |
---|
335 | %ifndef MODULE_STRINGS_COMPRESSED |
---|
336 | ALIGN DISPLAY_JUMP_ALIGN |
---|
337 | DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX: |
---|
338 | test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES |
---|
339 | jz SHORT ReturnOffsetInAX |
---|
340 | sal ax, 1 ; WORD count to BYTE count |
---|
341 | ALIGN DISPLAY_JUMP_ALIGN, ret |
---|
342 | ReturnOffsetInAX: |
---|
343 | ret |
---|
344 | %endif |
---|