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

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

Changes to assembly library:
Changed SetCharOutputFunctionFromAXwithAttribFlagInDL to SetCharOutputFunctionFromAXwithAttribFlagInBL since DX register gets corrupted by Display_FunctionFromDI.
Implemented quicksort.

File size: 7.7 KB
Line 
1; File name : DisplayContext.asm
2; Project name : Assembly Library
3; Created date : 25.6.2010
4; Last update : 28.9.2010
5; Author : Tomi Tilli
6; Description : Functions for managing display context.
7
8; Section containing code
9SECTION .text
10
11;--------------------------------------------------------------------
12; DisplayContext_Initialize
13; Parameters:
14; DS: BDA segment (zero)
15; Returns:
16; Nothing
17; Corrupts registers:
18; AX, DX, DI
19;--------------------------------------------------------------------
20ALIGN JUMP_ALIGN
21DisplayContext_Initialize:
22 call .DetectAndSetDisplaySegment
23 mov WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], DEFAULT_CHARACTER_OUTPUT
24 mov WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCursorShape], CURSOR_NORMAL
25 mov BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], SCREEN_BACKGROUND_ATTRIBUTE
26 mov BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
27
28 xor ax, ax
29 call DisplayCursor_SetCoordinatesFromAX
30 jmp SHORT DisplayContext_SynchronizeToHardware
31
32;--------------------------------------------------------------------
33; .DetectAndSetDisplaySegment
34; Parameters:
35; DS: BDA segment (zero)
36; Returns:
37; Nothing
38; Corrupts registers:
39; Nothing
40;--------------------------------------------------------------------
41.DetectAndSetDisplaySegment:
42 mov WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], COLOR_TEXT_SEGMENT
43 cmp BYTE [VIDEO_BDA.bMode], MDA_TEXT_MODE
44 jne SHORT .Return
45 sub WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], COLOR_TEXT_SEGMENT - MONO_TEXT_SEGMENT
46.Return:
47 ret
48
49
50;--------------------------------------------------------------------
51; DisplayContext_Push
52; Parameters:
53; Nothing
54; Returns:
55; Nothing
56; Corrupts registers:
57; AX, DI
58;--------------------------------------------------------------------
59ALIGN JUMP_ALIGN
60DisplayContext_Push:
61 mov di, ds ; Backup DS
62 LOAD_BDA_SEGMENT_TO ds, ax
63 pop ax ; Pop return address
64
65 %assign i 0
66 %rep DISPLAY_CONTEXT_size / 2
67 push WORD [VIDEO_BDA.displayContext + i]
68 %assign i i+2
69 %endrep
70
71 mov ds, di ; Restore DS
72 jmp ax
73
74;--------------------------------------------------------------------
75; DisplayContext_Pop
76; Parameters:
77; Nothing
78; Returns:
79; Nothing
80; Corrupts registers:
81; AX, DI
82;--------------------------------------------------------------------
83ALIGN JUMP_ALIGN
84DisplayContext_Pop:
85 mov di, ds ; Backup DS
86 LOAD_BDA_SEGMENT_TO ds, ax
87 pop ax ; Pop return address
88
89 %assign i DISPLAY_CONTEXT_size-2
90 %rep DISPLAY_CONTEXT_size / 2
91 pop WORD [VIDEO_BDA.displayContext + i]
92 %assign i i-2
93 %endrep
94
95 push ax ; Push return address
96 push dx
97 call DisplayContext_SynchronizeToHardware
98 pop dx
99 mov ds, di ; Restore DS
100 ret
101
102
103;--------------------------------------------------------------------
104; DisplayContext_SynchronizeToHardware
105; Parameters:
106; DS: BDA segment (zero)
107; Returns:
108; Nothing
109; Corrupts registers:
110; AX, DX
111;--------------------------------------------------------------------
112ALIGN JUMP_ALIGN
113DisplayContext_SynchronizeToHardware:
114 call DisplayPage_SynchronizeToHardware
115 call DisplayCursor_SynchronizeShapeToHardware
116 jmp DisplayCursor_SynchronizeCoordinatesToHardware
117
118
119;--------------------------------------------------------------------
120; DisplayContext_SetCharacterPointerFromBXAX
121; Parameters:
122; BX:AX: Ptr to destination for next character to output
123; DS: BDA segment (zero)
124; Returns:
125; ES:DI: Pointer that was in DX:AX
126; Corrupts registers:
127; AX
128;--------------------------------------------------------------------
129ALIGN JUMP_ALIGN
130DisplayContext_SetCharacterPointerFromBXAX:
131 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], ax
132 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], bx
133 xchg di, ax
134 mov es, bx
135 ret
136
137
138;--------------------------------------------------------------------
139; DisplayContext_GetCharacterPointerToBXAX
140; Parameters:
141; DS: BDA segment (zero)
142; Returns:
143; BX:AX: Ptr to destination for next character to output
144; Corrupts registers:
145; Nothing
146;--------------------------------------------------------------------
147ALIGN JUMP_ALIGN
148DisplayContext_GetCharacterPointerToBXAX:
149 mov ax, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition]
150 mov bx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2]
151 ret
152
153
154;--------------------------------------------------------------------
155; DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
156; Parameters:
157; AX: Offset to character output function
158; BL: Attribute Flag
159; DS: BDA segment (zero)
160; Returns:
161; Nothing
162; Corrupts registers:
163; Nothing
164;--------------------------------------------------------------------
165ALIGN JUMP_ALIGN
166DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL:
167 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], ax
168 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], bl
169 ret
170
171
172;--------------------------------------------------------------------
173; DisplayContext_SetCharacterAttributeFromAL
174; Parameters:
175; AL: Character attribute
176; DS: BDA segment (zero)
177; Returns:
178; Nothing
179; Corrupts registers:
180; Nothing
181;--------------------------------------------------------------------
182ALIGN JUMP_ALIGN
183DisplayContext_SetCharacterAttributeFromAL:
184 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al
185 ret
186
187
188;--------------------------------------------------------------------
189; DisplayContext_SetCharacterOutputParameterFromAX
190; Parameters:
191; AX: Parameter for Character Output function
192; DS: BDA segment (zero)
193; Returns:
194; Nothing
195; Corrupts registers:
196; Nothing
197;--------------------------------------------------------------------
198ALIGN JUMP_ALIGN
199DisplayContext_SetCharacterOutputParameterFromAX:
200 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], ax
201 ret
202
203;--------------------------------------------------------------------
204; DisplayContext_GetCharacterOutputParameterToDX
205; Parameters:
206; DS: BDA segment (zero)
207; Returns:
208; DX: User parameter for Character Output function
209; Corrupts registers:
210; Nothing
211;--------------------------------------------------------------------
212ALIGN JUMP_ALIGN
213DisplayContext_GetCharacterOutputParameterToDX:
214 mov dx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam]
215 ret
216
217
218;--------------------------------------------------------------------
219; DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX
220; Parameters:
221; AX: Offset in bytes from some character to another
222; DS: BDA segment (zero)
223; Returns:
224; AX: Offset in characters from some character to another
225; Corrupts registers:
226; Nothing
227;--------------------------------------------------------------------
228ALIGN JUMP_ALIGN
229DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX:
230 test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
231 jz SHORT ReturnOffsetInAX
232 sar ax, 1 ; BYTE count to WORD count
233 ret
234
235;--------------------------------------------------------------------
236; DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX
237; Parameters:
238; AX: Offset in characters from some character to another
239; DS: BDA segment (zero)
240; Returns:
241; AX: Offset in bytes from some character to another
242; Corrupts registers:
243; Nothing
244;--------------------------------------------------------------------
245ALIGN JUMP_ALIGN
246DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX:
247 test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
248 jz SHORT ReturnOffsetInAX
249 sal ax, 1 ; WORD count to BYTE count
250ALIGN JUMP_ALIGN, ret
251ReturnOffsetInAX:
252 ret
Note: See TracBrowser for help on using the repository browser.