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

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

Changes to all parts of the project:

  • Size optimizations, mostly by excluding code from the BIOS.
  • Cleaned the source a bit, fixed spelling and grammar mistakes.
File size: 9.5 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;--------------------------------------------------------------------
[133]150%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[48]151ALIGN JUMP_ALIGN
[52]152DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX:
[48]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
[52]163 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], cx
[48]164
165 mov bx, di
166 pop ds
167 ret
[133]168%endif
[48]169
170
171;--------------------------------------------------------------------
[41]172; DisplayContext_SetCharacterPointerFromBXAX
173; Parameters:
174; BX:AX: Ptr to destination for next character to output
175; DS: BDA segment (zero)
176; Returns:
[48]177; ES:DI: Pointer that was in BX:AX
[41]178; Corrupts registers:
179; AX
180;--------------------------------------------------------------------
[133]181%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[41]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
[133]189%endif
[41]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;--------------------------------------------------------------------
[133]201%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[41]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
[133]207%endif
[41]208
209
210;--------------------------------------------------------------------
[45]211; DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
[41]212; Parameters:
213; AX: Offset to character output function
[45]214; BL: Attribute Flag
[41]215; DS: BDA segment (zero)
216; Returns:
217; Nothing
218; Corrupts registers:
[50]219; BL
[41]220;--------------------------------------------------------------------
221ALIGN JUMP_ALIGN
[45]222DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL:
[50]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
[41]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
[133]269;--------------------------------------------------------------------
[162]270;%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS ; This appears to be completely unused
271;ALIGN JUMP_ALIGN
272;DisplayContext_GetCharacterOutputParameterToDX:
273; mov dx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam]
274; ret
275;%endif
[44]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
[133]287;--------------------------------------------------------------------
[44]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
[133]304;--------------------------------------------------------------------
[44]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.