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

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

Changes to Assembly Library:
Added functions to clear Menu Title and Information areas.
Implemented automatic line change when writing Menu Title and Information areas.
CGA snow related functions have been moved to CgaSnow.asm.
Keyboard input functions no longer produce beep for backspace.

File size: 8.4 KB
Line 
1; File name : DisplayContext.asm
2; Project name : Assembly Library
3; Created date : 25.6.2010
4; Last update : 5.10.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_PrepareOffScreenBufferInESBXtoESDI
105; Parameters:
106; BX:AX: Ptr to off screen buffer
107; Returns:
108; Nothing
109; Corrupts registers:
110; AX
111;--------------------------------------------------------------------
112ALIGN JUMP_ALIGN
113DisplayContext_PrepareOffScreenBufferInESBXtoESDI:
114 push ds
115
116 LOAD_BDA_SEGMENT_TO ds, di
117 xchg ax, bx
118 mov bx, es
119 call DisplayContext_SetCharacterPointerFromBXAX ; ES:DI now has the pointer
120
121 mov bl, ATTRIBUTES_NOT_USED
122 mov ax, BUFFER_OUTPUT_WITH_CHAR_ONLY
123 call DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
124
125 mov bx, di
126 pop ds
127 ret
128
129
130;--------------------------------------------------------------------
131; DisplayContext_SynchronizeToHardware
132; Parameters:
133; DS: BDA segment (zero)
134; Returns:
135; Nothing
136; Corrupts registers:
137; AX, DX
138;--------------------------------------------------------------------
139ALIGN JUMP_ALIGN
140DisplayContext_SynchronizeToHardware:
141 call DisplayPage_SynchronizeToHardware
142 call DisplayCursor_SynchronizeShapeToHardware
143 jmp DisplayCursor_SynchronizeCoordinatesToHardware
144
145
146;--------------------------------------------------------------------
147; DisplayContext_SetCharacterPointerFromBXAX
148; Parameters:
149; BX:AX: Ptr to destination for next character to output
150; DS: BDA segment (zero)
151; Returns:
152; ES:DI: Pointer that was in BX:AX
153; Corrupts registers:
154; AX
155;--------------------------------------------------------------------
156ALIGN JUMP_ALIGN
157DisplayContext_SetCharacterPointerFromBXAX:
158 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], ax
159 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], bx
160 xchg di, ax
161 mov es, bx
162 ret
163
164
165;--------------------------------------------------------------------
166; DisplayContext_GetCharacterPointerToBXAX
167; Parameters:
168; DS: BDA segment (zero)
169; Returns:
170; BX:AX: Ptr to destination for next character to output
171; Corrupts registers:
172; Nothing
173;--------------------------------------------------------------------
174ALIGN JUMP_ALIGN
175DisplayContext_GetCharacterPointerToBXAX:
176 mov ax, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition]
177 mov bx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2]
178 ret
179
180
181;--------------------------------------------------------------------
182; DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
183; Parameters:
184; AX: Offset to character output function
185; BL: Attribute Flag
186; DS: BDA segment (zero)
187; Returns:
188; Nothing
189; Corrupts registers:
190; Nothing
191;--------------------------------------------------------------------
192ALIGN JUMP_ALIGN
193DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL:
194 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], ax
195 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], bl
196 ret
197
198
199;--------------------------------------------------------------------
200; DisplayContext_SetCharacterAttributeFromAL
201; Parameters:
202; AL: Character attribute
203; DS: BDA segment (zero)
204; Returns:
205; Nothing
206; Corrupts registers:
207; Nothing
208;--------------------------------------------------------------------
209ALIGN JUMP_ALIGN
210DisplayContext_SetCharacterAttributeFromAL:
211 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al
212 ret
213
214
215;--------------------------------------------------------------------
216; DisplayContext_SetCharacterOutputParameterFromAX
217; Parameters:
218; AX: Parameter for Character Output function
219; DS: BDA segment (zero)
220; Returns:
221; Nothing
222; Corrupts registers:
223; Nothing
224;--------------------------------------------------------------------
225ALIGN JUMP_ALIGN
226DisplayContext_SetCharacterOutputParameterFromAX:
227 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], ax
228 ret
229
230;--------------------------------------------------------------------
231; DisplayContext_GetCharacterOutputParameterToDX
232; Parameters:
233; DS: BDA segment (zero)
234; Returns:
235; DX: User parameter for Character Output function
236; Corrupts registers:
237; Nothing
238;--------------------------------------------------------------------
239ALIGN JUMP_ALIGN
240DisplayContext_GetCharacterOutputParameterToDX:
241 mov dx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam]
242 ret
243
244
245;--------------------------------------------------------------------
246; DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX
247; Parameters:
248; AX: Offset in bytes from some character to another
249; DS: BDA segment (zero)
250; Returns:
251; AX: Offset in characters from some character to another
252; Corrupts registers:
253; Nothing
254;--------------------------------------------------------------------
255ALIGN JUMP_ALIGN
256DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX:
257 test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
258 jz SHORT ReturnOffsetInAX
259 sar ax, 1 ; BYTE count to WORD count
260 ret
261
262;--------------------------------------------------------------------
263; DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX
264; Parameters:
265; AX: Offset in characters from some character to another
266; DS: BDA segment (zero)
267; Returns:
268; AX: Offset in bytes from some character to another
269; Corrupts registers:
270; Nothing
271;--------------------------------------------------------------------
272ALIGN JUMP_ALIGN
273DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX:
274 test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
275 jz SHORT ReturnOffsetInAX
276 sal ax, 1 ; WORD count to BYTE count
277ALIGN JUMP_ALIGN, ret
278ReturnOffsetInAX:
279 ret
Note: See TracBrowser for help on using the repository browser.