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

Last change on this file since 131 was 115, checked in by Tomi Tilli, 14 years ago

Changes to Assembly Library:

  • Current cursor coordinates won't no longer be reset when initializing Display Library.
File size: 9.2 KB
RevLine 
[41]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
[44]20 mov BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], SCREEN_BACKGROUND_ATTRIBUTE
[101]21 ; Fall to .DetectAndSetDisplaySegment
[41]22
23;--------------------------------------------------------------------
24; .DetectAndSetDisplaySegment
25; Parameters:
26; DS: BDA segment (zero)
27; Returns:
28; Nothing
29; Corrupts registers:
[50]30; AX, DX
[41]31;--------------------------------------------------------------------
32.DetectAndSetDisplaySegment:
[50]33 mov ax, COLOR_TEXT_SEGMENT
[41]34 cmp BYTE [VIDEO_BDA.bMode], MDA_TEXT_MODE
[101]35 eCMOVE ah, MONO_TEXT_SEGMENT >> 8
[50]36 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], ax
[101]37 ; Fall to .InitializeFlags
[50]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
[101]55 ; Fall to .InitializeCursor
[41]56
[101]57;--------------------------------------------------------------------
58; .InitializeCursor
59; Parameters:
60; DS: BDA segment (zero)
61; Returns:
62; Nothing
63; Corrupts registers:
64; AX, DX
65;--------------------------------------------------------------------
66.InitializeCursor:
[115]67 call DisplayCursor_GetHardwareCoordinatesToAX ; Coordinates before init
68 call DisplayCursor_SetCoordinatesFromAX ; Cursor to Display Context
[101]69 ; Fall to DisplayContext_SynchronizeToHardware
[41]70
71;--------------------------------------------------------------------
[101]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;--------------------------------------------------------------------
[41]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 %assign i 0
103 %rep DISPLAY_CONTEXT_size / 2
104 push WORD [VIDEO_BDA.displayContext + i]
105 %assign i i+2
106 %endrep
107
108 mov ds, di ; Restore DS
109 jmp ax
110
111;--------------------------------------------------------------------
112; DisplayContext_Pop
113; Parameters:
114; Nothing
115; Returns:
116; Nothing
117; Corrupts registers:
118; AX, DI
119;--------------------------------------------------------------------
120ALIGN JUMP_ALIGN
121DisplayContext_Pop:
122 mov di, ds ; Backup DS
123 LOAD_BDA_SEGMENT_TO ds, ax
124 pop ax ; Pop return address
125
126 %assign i DISPLAY_CONTEXT_size-2
127 %rep DISPLAY_CONTEXT_size / 2
128 pop WORD [VIDEO_BDA.displayContext + i]
129 %assign i i-2
130 %endrep
131
132 push ax ; Push return address
133 push dx
134 call DisplayContext_SynchronizeToHardware
135 pop dx
136 mov ds, di ; Restore DS
137 ret
138
139
140;--------------------------------------------------------------------
[52]141; DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX
[48]142; Parameters:
[52]143; CX: Off screen buffer length in characters
144; ES:BX: Ptr to off screen buffer
[48]145; Returns:
146; Nothing
147; Corrupts registers:
[52]148; AX, DI
[48]149;--------------------------------------------------------------------
150ALIGN JUMP_ALIGN
[52]151DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX:
[48]152 push ds
153
154 LOAD_BDA_SEGMENT_TO ds, di
155 xchg ax, bx
156 mov bx, es
157 call DisplayContext_SetCharacterPointerFromBXAX ; ES:DI now has the pointer
158
159 mov bl, ATTRIBUTES_NOT_USED
160 mov ax, BUFFER_OUTPUT_WITH_CHAR_ONLY
161 call DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
[52]162 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], cx
[48]163
164 mov bx, di
165 pop ds
166 ret
167
168
169;--------------------------------------------------------------------
[41]170; DisplayContext_SetCharacterPointerFromBXAX
171; Parameters:
172; BX:AX: Ptr to destination for next character to output
173; DS: BDA segment (zero)
174; Returns:
[48]175; ES:DI: Pointer that was in BX:AX
[41]176; Corrupts registers:
177; AX
178;--------------------------------------------------------------------
179ALIGN JUMP_ALIGN
180DisplayContext_SetCharacterPointerFromBXAX:
181 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], ax
182 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], bx
183 xchg di, ax
184 mov es, bx
185 ret
186
187
188;--------------------------------------------------------------------
189; DisplayContext_GetCharacterPointerToBXAX
190; Parameters:
191; DS: BDA segment (zero)
192; Returns:
193; BX:AX: Ptr to destination for next character to output
194; Corrupts registers:
195; Nothing
196;--------------------------------------------------------------------
197ALIGN JUMP_ALIGN
198DisplayContext_GetCharacterPointerToBXAX:
199 mov ax, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition]
200 mov bx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2]
201 ret
202
203
204;--------------------------------------------------------------------
[45]205; DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
[41]206; Parameters:
207; AX: Offset to character output function
[45]208; BL: Attribute Flag
[41]209; DS: BDA segment (zero)
210; Returns:
211; Nothing
212; Corrupts registers:
[50]213; BL
[41]214;--------------------------------------------------------------------
215ALIGN JUMP_ALIGN
[45]216DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL:
[50]217 and bl, FLG_CONTEXT_ATTRIBUTES
218 and BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], ~FLG_CONTEXT_ATTRIBUTES
219 or [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], bl
[41]220 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], ax
221 ret
222
223
224;--------------------------------------------------------------------
225; DisplayContext_SetCharacterAttributeFromAL
226; Parameters:
227; AL: Character attribute
228; DS: BDA segment (zero)
229; Returns:
230; Nothing
231; Corrupts registers:
232; Nothing
233;--------------------------------------------------------------------
234ALIGN JUMP_ALIGN
235DisplayContext_SetCharacterAttributeFromAL:
236 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al
237 ret
238
239
240;--------------------------------------------------------------------
241; DisplayContext_SetCharacterOutputParameterFromAX
242; Parameters:
243; AX: Parameter for Character Output function
244; DS: BDA segment (zero)
245; Returns:
246; Nothing
247; Corrupts registers:
248; Nothing
249;--------------------------------------------------------------------
250ALIGN JUMP_ALIGN
251DisplayContext_SetCharacterOutputParameterFromAX:
252 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], ax
253 ret
254
255;--------------------------------------------------------------------
256; DisplayContext_GetCharacterOutputParameterToDX
257; Parameters:
258; DS: BDA segment (zero)
259; Returns:
260; DX: User parameter for Character Output function
261; Corrupts registers:
262; Nothing
263;--------------------------------------------------------------------
264ALIGN JUMP_ALIGN
265DisplayContext_GetCharacterOutputParameterToDX:
266 mov dx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam]
267 ret
[44]268
269
270;--------------------------------------------------------------------
271; DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX
272; Parameters:
273; AX: Offset in bytes from some character to another
274; DS: BDA segment (zero)
275; Returns:
276; AX: Offset in characters from some character to another
277; Corrupts registers:
278; Nothing
279;--------------------------------------------------------------------
280ALIGN JUMP_ALIGN
281DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX:
282 test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
283 jz SHORT ReturnOffsetInAX
284 sar ax, 1 ; BYTE count to WORD count
285 ret
286
287;--------------------------------------------------------------------
288; DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX
289; Parameters:
290; AX: Offset in characters from some character to another
291; DS: BDA segment (zero)
292; Returns:
293; AX: Offset in bytes from some character to another
294; Corrupts registers:
295; Nothing
296;--------------------------------------------------------------------
297ALIGN JUMP_ALIGN
298DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX:
299 test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
300 jz SHORT ReturnOffsetInAX
301 sal ax, 1 ; WORD count to BYTE count
302ALIGN JUMP_ALIGN, ret
303ReturnOffsetInAX:
304 ret
Note: See TracBrowser for help on using the repository browser.