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

Last change on this file since 506 was 491, checked in by krille_n_@…, 12 years ago

Changes:

  • Added a new define (USE_UNDOC_INTEL) that enables optimizations possible by using undocumented instructions available on all Intel processors and truly compatible clones. AFAIK the only exceptions are the NEC V-series and the Sony CXQ70108 processors so this option should be safe for use on the AT builds.
  • Building BIOSDRVS or the BIOS without MODULE_STRINGS_COMPRESSED would fail due to the recent code exclusions so I changed them a bit. Also fixed the mistaken change to Main.asm
  • Changed the Tandy specific info in Configuration_FullMode.txt so it matches the info in the Wiki.
  • Optimizations and fixes in general.
File size: 10.6 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 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;--------------------------------------------------------------------
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; DisplayContext_Pop
107; Parameters:
108; Nothing
109; Returns:
110; Nothing
111; Corrupts registers:
112; AX, DI
113;--------------------------------------------------------------------
114%ifdef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
115 %ifndef MODULE_BOOT_MENU
116 %define EXCLUDE
117 %endif
118%endif
119
120%ifndef EXCLUDE
121ALIGN DISPLAY_JUMP_ALIGN
122DisplayContext_Push:
123 mov di, ds ; Backup DS
124 LOAD_BDA_SEGMENT_TO ds, ax
125 pop ax ; Pop return address
126
127%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
128 %assign i 0
129 %rep DISPLAY_CONTEXT_size / 2
130 push WORD [VIDEO_BDA.displayContext + i]
131 %assign i i+2
132 %endrep
133%endif
134
135 mov ds, di ; Restore DS
136 jmp ax
137
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%endif ; EXCLUDE
160%undef EXCLUDE
161
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
174ALIGN DISPLAY_JUMP_ALIGN
175DisplayContext_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%endif ; EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
192
193
194;--------------------------------------------------------------------
195; DisplayContext_SetCharacterPointerFromBXAX
196; Parameters:
197; BX:AX: Ptr to destination for next character to output
198; DS: BDA segment (zero)
199; Returns:
200; ES:DI: Pointer that was in BX:AX
201; Corrupts registers:
202; AX
203;--------------------------------------------------------------------
204%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
205ALIGN DISPLAY_JUMP_ALIGN
206DisplayContext_SetCharacterPointerFromBXAX:
207 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], ax
208 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], bx
209 xchg di, ax
210 mov es, bx
211 ret
212%endif
213
214
215;--------------------------------------------------------------------
216; DisplayContext_GetCharacterPointerToBXAX
217; Parameters:
218; DS: BDA segment (zero)
219; Returns:
220; BX:AX: Ptr to destination for next character to output
221; Corrupts registers:
222; Nothing
223;--------------------------------------------------------------------
224%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
225ALIGN DISPLAY_JUMP_ALIGN
226DisplayContext_GetCharacterPointerToBXAX:
227 mov ax, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition]
228 mov bx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2]
229 ret
230%endif
231
232
233%ifdef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
234 %ifndef MODULE_BOOT_MENU
235 %define EXCLUDE
236 %endif
237%endif
238;--------------------------------------------------------------------
239; DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
240; Parameters:
241; AX: Offset to character output function
242; BL: Attribute Flag
243; DS: BDA segment (zero)
244; Returns:
245; Nothing
246; Corrupts registers:
247; BL
248;--------------------------------------------------------------------
249%ifndef EXCLUDE ; 1 of 3
250ALIGN DISPLAY_JUMP_ALIGN
251DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL:
252 and bl, FLG_CONTEXT_ATTRIBUTES
253 and BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], ~FLG_CONTEXT_ATTRIBUTES
254 or [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], bl
255 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], ax
256 ret
257%endif
258
259
260;--------------------------------------------------------------------
261; DisplayContext_SetCharacterAttributeFromAL
262; Parameters:
263; AL: Character attribute
264; DS: BDA segment (zero)
265; Returns:
266; Nothing
267; Corrupts registers:
268; Nothing
269;--------------------------------------------------------------------
270%ifndef EXCLUDE ; 2 of 3
271ALIGN DISPLAY_JUMP_ALIGN
272DisplayContext_SetCharacterAttributeFromAL:
273 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al
274 ret
275%endif
276
277
278;--------------------------------------------------------------------
279; DisplayContext_SetCharacterOutputParameterFromAX
280; Parameters:
281; AX: Parameter for Character Output function
282; DS: BDA segment (zero)
283; Returns:
284; Nothing
285; Corrupts registers:
286; Nothing
287;--------------------------------------------------------------------
288%ifndef EXCLUDE ; 3 of 3
289ALIGN DISPLAY_JUMP_ALIGN
290DisplayContext_SetCharacterOutputParameterFromAX:
291 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], ax
292 ret
293%endif
294
295%undef EXCLUDE
296
297
298;--------------------------------------------------------------------
299; DisplayContext_GetCharacterOutputParameterToDX
300; Parameters:
301; DS: BDA segment (zero)
302; Returns:
303; DX: User parameter for Character Output function
304; Corrupts registers:
305; Nothing
306;--------------------------------------------------------------------
307%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS OR EXCLUDE_FROM_XTIDECFG
308ALIGN DISPLAY_JUMP_ALIGN
309DisplayContext_GetCharacterOutputParameterToDX:
310 mov dx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam]
311 ret
312%endif
313
314
315;--------------------------------------------------------------------
316; DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX
317; Parameters:
318; AX: Offset in bytes from some character to another
319; DS: BDA segment (zero)
320; Returns:
321; AX: Offset in characters from some character to another
322; Corrupts registers:
323; Nothing
324;--------------------------------------------------------------------
325%ifndef MODULE_STRINGS_COMPRESSED
326ALIGN DISPLAY_JUMP_ALIGN
327DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX:
328 test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
329 jz SHORT ReturnOffsetInAX
330 sar ax, 1 ; BYTE count to WORD count
331 ret
332%endif
333
334
335;--------------------------------------------------------------------
336; DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX
337; Parameters:
338; AX: Offset in characters from some character to another
339; DS: BDA segment (zero)
340; Returns:
341; AX: Offset in bytes from some character to another
342; Corrupts registers:
343; Nothing
344;--------------------------------------------------------------------
345%ifndef MODULE_STRINGS_COMPRESSED
346ALIGN DISPLAY_JUMP_ALIGN
347DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX:
348 test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
349 jz SHORT ReturnOffsetInAX
350 sal ax, 1 ; WORD count to BYTE count
351ALIGN DISPLAY_JUMP_ALIGN, ret
352ReturnOffsetInAX:
353 ret
354%endif
Note: See TracBrowser for help on using the repository browser.