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

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

Fixed up conditional compilation so that we can continue to build without string compression.

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