source: xtideuniversalbios/trunk/Assembly_Library/Src/Display/DisplayContext.asm@ 396

Last change on this file since 396 was 376, checked in by gregli@…, 13 years ago

WIDE checkin... Added copyright and license information to sorce files, as per the GPL instructions for usage.

File size: 10.5 KB
Line 
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
21SECTION .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;--------------------------------------------------------------------
32ALIGN DISPLAY_JUMP_ALIGN
33DisplayContext_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 mov ax, [VIDEO_BDA.wCursorShape]
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;--------------------------------------------------------------------
97ALIGN DISPLAY_JUMP_ALIGN
98DisplayContext_SynchronizeToHardware:
99 call DisplayPage_SynchronizeToHardware
100 call DisplayCursor_SynchronizeShapeToHardware
101 jmp DisplayCursor_SynchronizeCoordinatesToHardware
102
103
104;--------------------------------------------------------------------
105; DisplayContext_Push
106; Parameters:
107; Nothing
108; Returns:
109; Nothing
110; Corrupts registers:
111; AX, DI
112;--------------------------------------------------------------------
113ALIGN DISPLAY_JUMP_ALIGN
114DisplayContext_Push:
115 mov di, ds ; Backup DS
116 LOAD_BDA_SEGMENT_TO ds, ax
117 pop ax ; Pop return address
118
119%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
120 %assign i 0
121 %rep DISPLAY_CONTEXT_size / 2
122 push WORD [VIDEO_BDA.displayContext + i]
123 %assign i i+2
124 %endrep
125%endif
126
127 mov ds, di ; Restore DS
128 jmp ax
129
130;--------------------------------------------------------------------
131; DisplayContext_Pop
132; Parameters:
133; Nothing
134; Returns:
135; Nothing
136; Corrupts registers:
137; AX, DI
138;--------------------------------------------------------------------
139ALIGN DISPLAY_JUMP_ALIGN
140DisplayContext_Pop:
141 mov di, ds ; Backup DS
142 LOAD_BDA_SEGMENT_TO ds, ax
143 pop ax ; Pop return address
144
145%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
146 %assign i DISPLAY_CONTEXT_size-2
147 %rep DISPLAY_CONTEXT_size / 2
148 pop WORD [VIDEO_BDA.displayContext + i]
149 %assign i i-2
150 %endrep
151%endif
152
153 push ax ; Push return address
154 push dx
155 call DisplayContext_SynchronizeToHardware
156 pop dx
157 mov ds, di ; Restore DS
158 ret
159
160
161;--------------------------------------------------------------------
162; DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX
163; Parameters:
164; CX: Off screen buffer length in characters
165; ES:BX: Ptr to off screen buffer
166; Returns:
167; Nothing
168; Corrupts registers:
169; AX, DI
170;--------------------------------------------------------------------
171%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
172ALIGN DISPLAY_JUMP_ALIGN
173DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX:
174 push ds
175
176 LOAD_BDA_SEGMENT_TO ds, di
177 xchg ax, bx
178 mov bx, es
179 call DisplayContext_SetCharacterPointerFromBXAX ; ES:DI now has the pointer
180
181 mov bl, ATTRIBUTES_NOT_USED
182 mov ax, BUFFER_OUTPUT_WITH_CHAR_ONLY
183 call DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
184 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], cx
185
186 mov bx, di
187 pop ds
188 ret
189%endif
190
191
192;--------------------------------------------------------------------
193; DisplayContext_SetCharacterPointerFromBXAX
194; Parameters:
195; BX:AX: Ptr to destination for next character to output
196; DS: BDA segment (zero)
197; Returns:
198; ES:DI: Pointer that was in BX:AX
199; Corrupts registers:
200; AX
201;--------------------------------------------------------------------
202%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
203ALIGN DISPLAY_JUMP_ALIGN
204DisplayContext_SetCharacterPointerFromBXAX:
205 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], ax
206 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], bx
207 xchg di, ax
208 mov es, bx
209 ret
210%endif
211
212
213;--------------------------------------------------------------------
214; DisplayContext_GetCharacterPointerToBXAX
215; Parameters:
216; DS: BDA segment (zero)
217; Returns:
218; BX:AX: Ptr to destination for next character to output
219; Corrupts registers:
220; Nothing
221;--------------------------------------------------------------------
222%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
223ALIGN DISPLAY_JUMP_ALIGN
224DisplayContext_GetCharacterPointerToBXAX:
225 mov ax, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition]
226 mov bx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2]
227 ret
228%endif
229
230
231;--------------------------------------------------------------------
232; DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
233; Parameters:
234; AX: Offset to character output function
235; BL: Attribute Flag
236; DS: BDA segment (zero)
237; Returns:
238; Nothing
239; Corrupts registers:
240; BL
241;--------------------------------------------------------------------
242ALIGN DISPLAY_JUMP_ALIGN
243DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL:
244 and bl, FLG_CONTEXT_ATTRIBUTES
245 and BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], ~FLG_CONTEXT_ATTRIBUTES
246 or [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], bl
247 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], ax
248 ret
249
250
251;--------------------------------------------------------------------
252; DisplayContext_SetCharacterAttributeFromAL
253; Parameters:
254; AL: Character attribute
255; DS: BDA segment (zero)
256; Returns:
257; Nothing
258; Corrupts registers:
259; Nothing
260;--------------------------------------------------------------------
261ALIGN DISPLAY_JUMP_ALIGN
262DisplayContext_SetCharacterAttributeFromAL:
263 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al
264 ret
265
266
267;--------------------------------------------------------------------
268; DisplayContext_SetCharacterOutputParameterFromAX
269; Parameters:
270; AX: Parameter for Character Output function
271; DS: BDA segment (zero)
272; Returns:
273; Nothing
274; Corrupts registers:
275; Nothing
276;--------------------------------------------------------------------
277ALIGN DISPLAY_JUMP_ALIGN
278DisplayContext_SetCharacterOutputParameterFromAX:
279 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], ax
280 ret
281
282
283;--------------------------------------------------------------------
284; DisplayContext_GetCharacterOutputParameterToDX
285; Parameters:
286; DS: BDA segment (zero)
287; Returns:
288; DX: User parameter for Character Output function
289; Corrupts registers:
290; Nothing
291;--------------------------------------------------------------------
292%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS OR EXCLUDE_FROM_XTIDECFG ; This is currently unused (dead code)
293ALIGN DISPLAY_JUMP_ALIGN
294DisplayContext_GetCharacterOutputParameterToDX:
295 mov dx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam]
296 ret
297%endif
298
299
300;--------------------------------------------------------------------
301; DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX
302; Parameters:
303; AX: Offset in bytes from some character to another
304; DS: BDA segment (zero)
305; Returns:
306; AX: Offset in characters from some character to another
307; Corrupts registers:
308; Nothing
309;--------------------------------------------------------------------
310%ifndef MODULE_STRINGS_COMPRESSED
311ALIGN DISPLAY_JUMP_ALIGN
312DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX:
313 test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
314 jz SHORT ReturnOffsetInAX
315 sar ax, 1 ; BYTE count to WORD count
316 ret
317%endif
318
319
320;--------------------------------------------------------------------
321; DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX
322; Parameters:
323; AX: Offset in characters from some character to another
324; DS: BDA segment (zero)
325; Returns:
326; AX: Offset in bytes from some character to another
327; Corrupts registers:
328; Nothing
329;--------------------------------------------------------------------
330%ifndef MODULE_STRINGS_COMPRESSED
331ALIGN DISPLAY_JUMP_ALIGN
332DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX:
333 test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
334 jz SHORT ReturnOffsetInAX
335 sal ax, 1 ; WORD count to BYTE count
336ALIGN DISPLAY_JUMP_ALIGN, ret
337ReturnOffsetInAX:
338 ret
339%endif
Note: See TracBrowser for help on using the repository browser.