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

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

Changes:

  • A few minor optimizations.
File size: 11.0 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-2013 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 %ifdef USE_386
130 %rep DISPLAY_CONTEXT_size / 4
131 push DWORD [VIDEO_BDA.displayContext + i]
132 %assign i i+4
133 %endrep
134 %else
135 %rep DISPLAY_CONTEXT_size / 2
136 push WORD [VIDEO_BDA.displayContext + i]
137 %assign i i+2
138 %endrep
139 %endif
140%endif
141
142 mov ds, di ; Restore DS
143 jmp ax
144
145
146ALIGN DISPLAY_JUMP_ALIGN
147DisplayContext_Pop:
148 mov di, ds ; Backup DS
149 LOAD_BDA_SEGMENT_TO ds, ax
150 pop ax ; Pop return address
151
152%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
153 %ifdef USE_386
154 %assign i DISPLAY_CONTEXT_size-4
155 %rep DISPLAY_CONTEXT_size / 4
156 pop DWORD [VIDEO_BDA.displayContext + i]
157 %assign i i-4
158 %endrep
159 %else
160 %assign i DISPLAY_CONTEXT_size-2
161 %rep DISPLAY_CONTEXT_size / 2
162 pop WORD [VIDEO_BDA.displayContext + i]
163 %assign i i-2
164 %endrep
165 %endif
166%endif
167
168 push ax ; Push return address
169 push dx
170 call DisplayContext_SynchronizeToHardware
171 pop dx
172 mov ds, di ; Restore DS
173 ret
174%endif ; EXCLUDE
175%undef EXCLUDE
176
177
178;--------------------------------------------------------------------
179; DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX
180; Parameters:
181; CX: Off screen buffer length in characters
182; ES:BX: Ptr to off screen buffer
183; Returns:
184; Nothing
185; Corrupts registers:
186; AX, DI
187;--------------------------------------------------------------------
188%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
189ALIGN DISPLAY_JUMP_ALIGN
190DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX:
191 push ds
192
193 LOAD_BDA_SEGMENT_TO ds, di
194 xchg ax, bx
195 mov bx, es
196 call DisplayContext_SetCharacterPointerFromBXAX ; ES:DI now has the pointer
197
198 mov bl, ATTRIBUTES_NOT_USED
199 mov ax, BUFFER_OUTPUT_WITH_CHAR_ONLY
200 call DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
201 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], cx
202
203 mov bx, di
204 pop ds
205 ret
206%endif ; EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
207
208
209;--------------------------------------------------------------------
210; DisplayContext_SetCharacterPointerFromBXAX
211; Parameters:
212; BX:AX: Ptr to destination for next character to output
213; DS: BDA segment (zero)
214; Returns:
215; ES:DI: Pointer that was in BX:AX
216; Corrupts registers:
217; AX
218;--------------------------------------------------------------------
219%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
220ALIGN DISPLAY_JUMP_ALIGN
221DisplayContext_SetCharacterPointerFromBXAX:
222 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], ax
223 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], bx
224 xchg di, ax
225 mov es, bx
226 ret
227%endif
228
229
230;--------------------------------------------------------------------
231; DisplayContext_GetCharacterPointerToBXAX
232; Parameters:
233; DS: BDA segment (zero)
234; Returns:
235; BX:AX: Ptr to destination for next character to output
236; Corrupts registers:
237; Nothing
238;--------------------------------------------------------------------
239%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
240ALIGN DISPLAY_JUMP_ALIGN
241DisplayContext_GetCharacterPointerToBXAX:
242 mov ax, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition]
243 mov bx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2]
244 ret
245%endif
246
247
248%ifdef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
249 %ifndef MODULE_BOOT_MENU
250 %define EXCLUDE
251 %endif
252%endif
253;--------------------------------------------------------------------
254; DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
255; Parameters:
256; AX: Offset to character output function
257; BL: Attribute Flag
258; DS: BDA segment (zero)
259; Returns:
260; Nothing
261; Corrupts registers:
262; BL
263;--------------------------------------------------------------------
264%ifndef EXCLUDE ; 1 of 3
265ALIGN DISPLAY_JUMP_ALIGN
266DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL:
267 and bl, FLG_CONTEXT_ATTRIBUTES
268 and BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], ~FLG_CONTEXT_ATTRIBUTES
269 or [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], bl
270 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], ax
271 ret
272%endif
273
274
275;--------------------------------------------------------------------
276; DisplayContext_SetCharacterAttributeFromAL
277; Parameters:
278; AL: Character attribute
279; DS: BDA segment (zero)
280; Returns:
281; Nothing
282; Corrupts registers:
283; Nothing
284;--------------------------------------------------------------------
285%ifndef EXCLUDE ; 2 of 3
286ALIGN DISPLAY_JUMP_ALIGN
287DisplayContext_SetCharacterAttributeFromAL:
288 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al
289 ret
290%endif
291
292
293;--------------------------------------------------------------------
294; DisplayContext_SetCharacterOutputParameterFromAX
295; Parameters:
296; AX: Parameter for Character Output function
297; DS: BDA segment (zero)
298; Returns:
299; Nothing
300; Corrupts registers:
301; Nothing
302;--------------------------------------------------------------------
303%ifndef EXCLUDE ; 3 of 3
304ALIGN DISPLAY_JUMP_ALIGN
305DisplayContext_SetCharacterOutputParameterFromAX:
306 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], ax
307 ret
308%endif
309
310%undef EXCLUDE
311
312
313;--------------------------------------------------------------------
314; DisplayContext_GetCharacterOutputParameterToDX
315; Parameters:
316; DS: BDA segment (zero)
317; Returns:
318; DX: User parameter for Character Output function
319; Corrupts registers:
320; Nothing
321;--------------------------------------------------------------------
322%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS OR EXCLUDE_FROM_XTIDECFG
323ALIGN DISPLAY_JUMP_ALIGN
324DisplayContext_GetCharacterOutputParameterToDX:
325 mov dx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam]
326 ret
327%endif
328
329
330;--------------------------------------------------------------------
331; DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX
332; Parameters:
333; AX: Offset in bytes from some character to another
334; DS: BDA segment (zero)
335; Returns:
336; AX: Offset in characters from some character to another
337; Corrupts registers:
338; Nothing
339;--------------------------------------------------------------------
340%ifndef MODULE_STRINGS_COMPRESSED
341ALIGN DISPLAY_JUMP_ALIGN
342DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX:
343 test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
344 jz SHORT ReturnOffsetInAX
345 sar ax, 1 ; BYTE count to WORD count
346 ret
347%endif
348
349
350;--------------------------------------------------------------------
351; DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX
352; Parameters:
353; AX: Offset in characters from some character to another
354; DS: BDA segment (zero)
355; Returns:
356; AX: Offset in bytes from some character to another
357; Corrupts registers:
358; Nothing
359;--------------------------------------------------------------------
360%ifndef MODULE_STRINGS_COMPRESSED
361ALIGN DISPLAY_JUMP_ALIGN
362DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX:
363 test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
364 jz SHORT ReturnOffsetInAX
365 sal ax, 1 ; WORD count to BYTE count
366ALIGN DISPLAY_JUMP_ALIGN, ret
367ReturnOffsetInAX:
368 ret
369%endif
Note: See TracBrowser for help on using the repository browser.