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

Last change on this file since 398 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
RevLine 
[41]1; Project name : Assembly Library
2; Description : Functions for managing display context.
3
[376]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
[41]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;--------------------------------------------------------------------
[369]32ALIGN DISPLAY_JUMP_ALIGN
[41]33DisplayContext_Initialize:
34 mov WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], DEFAULT_CHARACTER_OUTPUT
[44]35 mov BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], SCREEN_BACKGROUND_ATTRIBUTE
[287]36 mov ax, [VIDEO_BDA.wCursorShape]
37 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCursorShape], ax
[101]38 ; Fall to .DetectAndSetDisplaySegment
[41]39
40;--------------------------------------------------------------------
41; .DetectAndSetDisplaySegment
42; Parameters:
43; DS: BDA segment (zero)
44; Returns:
45; Nothing
46; Corrupts registers:
[50]47; AX, DX
[41]48;--------------------------------------------------------------------
49.DetectAndSetDisplaySegment:
[50]50 mov ax, COLOR_TEXT_SEGMENT
[41]51 cmp BYTE [VIDEO_BDA.bMode], MDA_TEXT_MODE
[101]52 eCMOVE ah, MONO_TEXT_SEGMENT >> 8
[50]53 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], ax
[101]54 ; Fall to .InitializeFlags
[50]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
[101]72 ; Fall to .InitializeCursor
[41]73
[101]74;--------------------------------------------------------------------
75; .InitializeCursor
76; Parameters:
77; DS: BDA segment (zero)
78; Returns:
79; Nothing
80; Corrupts registers:
81; AX, DX
82;--------------------------------------------------------------------
83.InitializeCursor:
[115]84 call DisplayCursor_GetHardwareCoordinatesToAX ; Coordinates before init
85 call DisplayCursor_SetCoordinatesFromAX ; Cursor to Display Context
[101]86 ; Fall to DisplayContext_SynchronizeToHardware
[41]87
88;--------------------------------------------------------------------
[101]89; DisplayContext_SynchronizeToHardware
90; Parameters:
91; DS: BDA segment (zero)
92; Returns:
93; Nothing
94; Corrupts registers:
95; AX, DX
96;--------------------------------------------------------------------
[369]97ALIGN DISPLAY_JUMP_ALIGN
[101]98DisplayContext_SynchronizeToHardware:
99 call DisplayPage_SynchronizeToHardware
100 call DisplayCursor_SynchronizeShapeToHardware
101 jmp DisplayCursor_SynchronizeCoordinatesToHardware
102
103
104;--------------------------------------------------------------------
[41]105; DisplayContext_Push
106; Parameters:
107; Nothing
108; Returns:
109; Nothing
110; Corrupts registers:
111; AX, DI
112;--------------------------------------------------------------------
[369]113ALIGN DISPLAY_JUMP_ALIGN
[41]114DisplayContext_Push:
115 mov di, ds ; Backup DS
116 LOAD_BDA_SEGMENT_TO ds, ax
117 pop ax ; Pop return address
118
[194]119%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
[41]120 %assign i 0
121 %rep DISPLAY_CONTEXT_size / 2
122 push WORD [VIDEO_BDA.displayContext + i]
123 %assign i i+2
124 %endrep
[194]125%endif
126
[41]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;--------------------------------------------------------------------
[369]139ALIGN DISPLAY_JUMP_ALIGN
[41]140DisplayContext_Pop:
141 mov di, ds ; Backup DS
142 LOAD_BDA_SEGMENT_TO ds, ax
143 pop ax ; Pop return address
144
[194]145%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
[41]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
[194]151%endif
152
[41]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;--------------------------------------------------------------------
[52]162; DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX
[48]163; Parameters:
[52]164; CX: Off screen buffer length in characters
165; ES:BX: Ptr to off screen buffer
[48]166; Returns:
167; Nothing
168; Corrupts registers:
[52]169; AX, DI
[48]170;--------------------------------------------------------------------
[133]171%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[369]172ALIGN DISPLAY_JUMP_ALIGN
[52]173DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX:
[48]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
[52]184 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], cx
[48]185
186 mov bx, di
187 pop ds
188 ret
[133]189%endif
[48]190
191
192;--------------------------------------------------------------------
[41]193; DisplayContext_SetCharacterPointerFromBXAX
194; Parameters:
195; BX:AX: Ptr to destination for next character to output
196; DS: BDA segment (zero)
197; Returns:
[48]198; ES:DI: Pointer that was in BX:AX
[41]199; Corrupts registers:
200; AX
201;--------------------------------------------------------------------
[133]202%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[369]203ALIGN DISPLAY_JUMP_ALIGN
[41]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
[133]210%endif
[41]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;--------------------------------------------------------------------
[133]222%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[369]223ALIGN DISPLAY_JUMP_ALIGN
[41]224DisplayContext_GetCharacterPointerToBXAX:
225 mov ax, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition]
226 mov bx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2]
227 ret
[133]228%endif
[41]229
230
231;--------------------------------------------------------------------
[45]232; DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
[41]233; Parameters:
234; AX: Offset to character output function
[45]235; BL: Attribute Flag
[41]236; DS: BDA segment (zero)
237; Returns:
238; Nothing
239; Corrupts registers:
[50]240; BL
[41]241;--------------------------------------------------------------------
[369]242ALIGN DISPLAY_JUMP_ALIGN
[45]243DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL:
[50]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
[41]247 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], ax
248 ret
[194]249
[41]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;--------------------------------------------------------------------
[369]261ALIGN DISPLAY_JUMP_ALIGN
[41]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;--------------------------------------------------------------------
[369]277ALIGN DISPLAY_JUMP_ALIGN
[41]278DisplayContext_SetCharacterOutputParameterFromAX:
279 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], ax
280 ret
281
[194]282
[41]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
[133]291;--------------------------------------------------------------------
[181]292%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS OR EXCLUDE_FROM_XTIDECFG ; This is currently unused (dead code)
[369]293ALIGN DISPLAY_JUMP_ALIGN
[181]294DisplayContext_GetCharacterOutputParameterToDX:
295 mov dx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam]
296 ret
297%endif
[44]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
[133]309;--------------------------------------------------------------------
[201]310%ifndef MODULE_STRINGS_COMPRESSED
[369]311ALIGN DISPLAY_JUMP_ALIGN
[44]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
[194]317%endif
[44]318
[194]319
[44]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
[133]329;--------------------------------------------------------------------
[201]330%ifndef MODULE_STRINGS_COMPRESSED
[369]331ALIGN DISPLAY_JUMP_ALIGN
[44]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
[369]336ALIGN DISPLAY_JUMP_ALIGN, ret
[44]337ReturnOffsetInAX:
338 ret
[194]339%endif
Note: See TracBrowser for help on using the repository browser.