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

Last change on this file since 189 was 181, checked in by krille_n_@…, 13 years ago

Changes to all parts of the project:

  • Size optimizations.
  • Added a define (EXCLUDE_FROM_XTIDECFG) to exclude unused library code from XTIDECFG.
  • Tried to minimize time spent with interrupts disabled.
  • Some minor attempts to improve speed (reordering instructions etc).
  • Tried to improve readability, did some cleanup and fixed some errors in comments.
File size: 9.5 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 %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;--------------------------------------------------------------------
141; DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX
142; Parameters:
143; CX: Off screen buffer length in characters
144; ES:BX: Ptr to off screen buffer
145; Returns:
146; Nothing
147; Corrupts registers:
148; AX, DI
149;--------------------------------------------------------------------
150%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
151ALIGN JUMP_ALIGN
152DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX:
153 push ds
154
155 LOAD_BDA_SEGMENT_TO ds, di
156 xchg ax, bx
157 mov bx, es
158 call DisplayContext_SetCharacterPointerFromBXAX ; ES:DI now has the pointer
159
160 mov bl, ATTRIBUTES_NOT_USED
161 mov ax, BUFFER_OUTPUT_WITH_CHAR_ONLY
162 call DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
163 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], cx
164
165 mov bx, di
166 pop ds
167 ret
168%endif
169
170
171;--------------------------------------------------------------------
172; DisplayContext_SetCharacterPointerFromBXAX
173; Parameters:
174; BX:AX: Ptr to destination for next character to output
175; DS: BDA segment (zero)
176; Returns:
177; ES:DI: Pointer that was in BX:AX
178; Corrupts registers:
179; AX
180;--------------------------------------------------------------------
181%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
182ALIGN JUMP_ALIGN
183DisplayContext_SetCharacterPointerFromBXAX:
184 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], ax
185 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], bx
186 xchg di, ax
187 mov es, bx
188 ret
189%endif
190
191
192;--------------------------------------------------------------------
193; DisplayContext_GetCharacterPointerToBXAX
194; Parameters:
195; DS: BDA segment (zero)
196; Returns:
197; BX:AX: Ptr to destination for next character to output
198; Corrupts registers:
199; Nothing
200;--------------------------------------------------------------------
201%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
202ALIGN JUMP_ALIGN
203DisplayContext_GetCharacterPointerToBXAX:
204 mov ax, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition]
205 mov bx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2]
206 ret
207%endif
208
209
210;--------------------------------------------------------------------
211; DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
212; Parameters:
213; AX: Offset to character output function
214; BL: Attribute Flag
215; DS: BDA segment (zero)
216; Returns:
217; Nothing
218; Corrupts registers:
219; BL
220;--------------------------------------------------------------------
221ALIGN JUMP_ALIGN
222DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL:
223 and bl, FLG_CONTEXT_ATTRIBUTES
224 and BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], ~FLG_CONTEXT_ATTRIBUTES
225 or [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], bl
226 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], ax
227 ret
228
229
230;--------------------------------------------------------------------
231; DisplayContext_SetCharacterAttributeFromAL
232; Parameters:
233; AL: Character attribute
234; DS: BDA segment (zero)
235; Returns:
236; Nothing
237; Corrupts registers:
238; Nothing
239;--------------------------------------------------------------------
240ALIGN JUMP_ALIGN
241DisplayContext_SetCharacterAttributeFromAL:
242 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al
243 ret
244
245
246;--------------------------------------------------------------------
247; DisplayContext_SetCharacterOutputParameterFromAX
248; Parameters:
249; AX: Parameter for Character Output function
250; DS: BDA segment (zero)
251; Returns:
252; Nothing
253; Corrupts registers:
254; Nothing
255;--------------------------------------------------------------------
256ALIGN JUMP_ALIGN
257DisplayContext_SetCharacterOutputParameterFromAX:
258 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], ax
259 ret
260
261;--------------------------------------------------------------------
262; DisplayContext_GetCharacterOutputParameterToDX
263; Parameters:
264; DS: BDA segment (zero)
265; Returns:
266; DX: User parameter for Character Output function
267; Corrupts registers:
268; Nothing
269;--------------------------------------------------------------------
270%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS OR EXCLUDE_FROM_XTIDECFG ; This is currently unused (dead code)
271ALIGN JUMP_ALIGN
272DisplayContext_GetCharacterOutputParameterToDX:
273 mov dx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam]
274 ret
275%endif
276
277
278;--------------------------------------------------------------------
279; DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX
280; Parameters:
281; AX: Offset in bytes from some character to another
282; DS: BDA segment (zero)
283; Returns:
284; AX: Offset in characters from some character to another
285; Corrupts registers:
286; Nothing
287;--------------------------------------------------------------------
288ALIGN JUMP_ALIGN
289DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX:
290 test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
291 jz SHORT ReturnOffsetInAX
292 sar ax, 1 ; BYTE count to WORD count
293 ret
294
295;--------------------------------------------------------------------
296; DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX
297; Parameters:
298; AX: Offset in characters from some character to another
299; DS: BDA segment (zero)
300; Returns:
301; AX: Offset in bytes from some character to another
302; Corrupts registers:
303; Nothing
304;--------------------------------------------------------------------
305ALIGN JUMP_ALIGN
306DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX:
307 test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
308 jz SHORT ReturnOffsetInAX
309 sal ax, 1 ; WORD count to BYTE count
310ALIGN JUMP_ALIGN, ret
311ReturnOffsetInAX:
312 ret
Note: See TracBrowser for help on using the repository browser.