1 | ; File name : DisplayContext.asm
|
---|
2 | ; Project name : Assembly Library
|
---|
3 | ; Created date : 25.6.2010
|
---|
4 | ; Last update : 9.10.2010
|
---|
5 | ; Author : Tomi Tilli
|
---|
6 | ; Description : Functions for managing display context.
|
---|
7 |
|
---|
8 | ; Section containing code
|
---|
9 | SECTION .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 | ;--------------------------------------------------------------------
|
---|
20 | ALIGN JUMP_ALIGN
|
---|
21 | DisplayContext_Initialize:
|
---|
22 | call .DetectAndSetDisplaySegment ; and .InitializeFlags
|
---|
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 | xor ax, ax
|
---|
27 | call DisplayCursor_SetCoordinatesFromAX
|
---|
28 | jmp DisplayContext_SynchronizeToHardware
|
---|
29 |
|
---|
30 | ;--------------------------------------------------------------------
|
---|
31 | ; .DetectAndSetDisplaySegment
|
---|
32 | ; Parameters:
|
---|
33 | ; DS: BDA segment (zero)
|
---|
34 | ; Returns:
|
---|
35 | ; Nothing
|
---|
36 | ; Corrupts registers:
|
---|
37 | ; AX, DX
|
---|
38 | ;--------------------------------------------------------------------
|
---|
39 | .DetectAndSetDisplaySegment:
|
---|
40 | mov ax, COLOR_TEXT_SEGMENT
|
---|
41 | cmp BYTE [VIDEO_BDA.bMode], MDA_TEXT_MODE
|
---|
42 | jne SHORT .StoreSegmentToDisplayContext
|
---|
43 | mov ax, MONO_TEXT_SEGMENT
|
---|
44 | .StoreSegmentToDisplayContext:
|
---|
45 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], ax
|
---|
46 | ; Fall to InitializeFlags
|
---|
47 |
|
---|
48 | ;--------------------------------------------------------------------
|
---|
49 | ; .InitializeFlags
|
---|
50 | ; Parameters:
|
---|
51 | ; DS: BDA segment (zero)
|
---|
52 | ; Returns:
|
---|
53 | ; Nothing
|
---|
54 | ; Corrupts registers:
|
---|
55 | ; AX, DX
|
---|
56 | ;--------------------------------------------------------------------
|
---|
57 | .InitializeFlags:
|
---|
58 | mov dl, FLG_CONTEXT_ATTRIBUTES
|
---|
59 | call CgaSnow_IsCgaPresent
|
---|
60 | jnc SHORT .DoNotSetCgaFlag
|
---|
61 | or dl, FLG_CONTEXT_CGA
|
---|
62 | .DoNotSetCgaFlag:
|
---|
63 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], dl
|
---|
64 | ret
|
---|
65 |
|
---|
66 |
|
---|
67 | ;--------------------------------------------------------------------
|
---|
68 | ; DisplayContext_Push
|
---|
69 | ; Parameters:
|
---|
70 | ; Nothing
|
---|
71 | ; Returns:
|
---|
72 | ; Nothing
|
---|
73 | ; Corrupts registers:
|
---|
74 | ; AX, DI
|
---|
75 | ;--------------------------------------------------------------------
|
---|
76 | ALIGN JUMP_ALIGN
|
---|
77 | DisplayContext_Push:
|
---|
78 | mov di, ds ; Backup DS
|
---|
79 | LOAD_BDA_SEGMENT_TO ds, ax
|
---|
80 | pop ax ; Pop return address
|
---|
81 |
|
---|
82 | %assign i 0
|
---|
83 | %rep DISPLAY_CONTEXT_size / 2
|
---|
84 | push WORD [VIDEO_BDA.displayContext + i]
|
---|
85 | %assign i i+2
|
---|
86 | %endrep
|
---|
87 |
|
---|
88 | mov ds, di ; Restore DS
|
---|
89 | jmp ax
|
---|
90 |
|
---|
91 | ;--------------------------------------------------------------------
|
---|
92 | ; DisplayContext_Pop
|
---|
93 | ; Parameters:
|
---|
94 | ; Nothing
|
---|
95 | ; Returns:
|
---|
96 | ; Nothing
|
---|
97 | ; Corrupts registers:
|
---|
98 | ; AX, DI
|
---|
99 | ;--------------------------------------------------------------------
|
---|
100 | ALIGN JUMP_ALIGN
|
---|
101 | DisplayContext_Pop:
|
---|
102 | mov di, ds ; Backup DS
|
---|
103 | LOAD_BDA_SEGMENT_TO ds, ax
|
---|
104 | pop ax ; Pop return address
|
---|
105 |
|
---|
106 | %assign i DISPLAY_CONTEXT_size-2
|
---|
107 | %rep DISPLAY_CONTEXT_size / 2
|
---|
108 | pop WORD [VIDEO_BDA.displayContext + i]
|
---|
109 | %assign i i-2
|
---|
110 | %endrep
|
---|
111 |
|
---|
112 | push ax ; Push return address
|
---|
113 | push dx
|
---|
114 | call DisplayContext_SynchronizeToHardware
|
---|
115 | pop dx
|
---|
116 | mov ds, di ; Restore DS
|
---|
117 | ret
|
---|
118 |
|
---|
119 |
|
---|
120 | ;--------------------------------------------------------------------
|
---|
121 | ; DisplayContext_PrepareOffScreenBufferInESBXtoESDI
|
---|
122 | ; Parameters:
|
---|
123 | ; BX:AX: Ptr to off screen buffer
|
---|
124 | ; Returns:
|
---|
125 | ; Nothing
|
---|
126 | ; Corrupts registers:
|
---|
127 | ; AX
|
---|
128 | ;--------------------------------------------------------------------
|
---|
129 | ALIGN JUMP_ALIGN
|
---|
130 | DisplayContext_PrepareOffScreenBufferInESBXtoESDI:
|
---|
131 | push ds
|
---|
132 |
|
---|
133 | LOAD_BDA_SEGMENT_TO ds, di
|
---|
134 | xchg ax, bx
|
---|
135 | mov bx, es
|
---|
136 | call DisplayContext_SetCharacterPointerFromBXAX ; ES:DI now has the pointer
|
---|
137 |
|
---|
138 | mov bl, ATTRIBUTES_NOT_USED
|
---|
139 | mov ax, BUFFER_OUTPUT_WITH_CHAR_ONLY
|
---|
140 | call DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
|
---|
141 |
|
---|
142 | mov bx, di
|
---|
143 | pop ds
|
---|
144 | ret
|
---|
145 |
|
---|
146 |
|
---|
147 | ;--------------------------------------------------------------------
|
---|
148 | ; DisplayContext_SynchronizeToHardware
|
---|
149 | ; Parameters:
|
---|
150 | ; DS: BDA segment (zero)
|
---|
151 | ; Returns:
|
---|
152 | ; Nothing
|
---|
153 | ; Corrupts registers:
|
---|
154 | ; AX, DX
|
---|
155 | ;--------------------------------------------------------------------
|
---|
156 | ALIGN JUMP_ALIGN
|
---|
157 | DisplayContext_SynchronizeToHardware:
|
---|
158 | call DisplayPage_SynchronizeToHardware
|
---|
159 | call DisplayCursor_SynchronizeShapeToHardware
|
---|
160 | jmp DisplayCursor_SynchronizeCoordinatesToHardware
|
---|
161 |
|
---|
162 |
|
---|
163 | ;--------------------------------------------------------------------
|
---|
164 | ; DisplayContext_SetCharacterPointerFromBXAX
|
---|
165 | ; Parameters:
|
---|
166 | ; BX:AX: Ptr to destination for next character to output
|
---|
167 | ; DS: BDA segment (zero)
|
---|
168 | ; Returns:
|
---|
169 | ; ES:DI: Pointer that was in BX:AX
|
---|
170 | ; Corrupts registers:
|
---|
171 | ; AX
|
---|
172 | ;--------------------------------------------------------------------
|
---|
173 | ALIGN JUMP_ALIGN
|
---|
174 | DisplayContext_SetCharacterPointerFromBXAX:
|
---|
175 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], ax
|
---|
176 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], bx
|
---|
177 | xchg di, ax
|
---|
178 | mov es, bx
|
---|
179 | ret
|
---|
180 |
|
---|
181 |
|
---|
182 | ;--------------------------------------------------------------------
|
---|
183 | ; DisplayContext_GetCharacterPointerToBXAX
|
---|
184 | ; Parameters:
|
---|
185 | ; DS: BDA segment (zero)
|
---|
186 | ; Returns:
|
---|
187 | ; BX:AX: Ptr to destination for next character to output
|
---|
188 | ; Corrupts registers:
|
---|
189 | ; Nothing
|
---|
190 | ;--------------------------------------------------------------------
|
---|
191 | ALIGN JUMP_ALIGN
|
---|
192 | DisplayContext_GetCharacterPointerToBXAX:
|
---|
193 | mov ax, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition]
|
---|
194 | mov bx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2]
|
---|
195 | ret
|
---|
196 |
|
---|
197 |
|
---|
198 | ;--------------------------------------------------------------------
|
---|
199 | ; DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
|
---|
200 | ; Parameters:
|
---|
201 | ; AX: Offset to character output function
|
---|
202 | ; BL: Attribute Flag
|
---|
203 | ; DS: BDA segment (zero)
|
---|
204 | ; Returns:
|
---|
205 | ; Nothing
|
---|
206 | ; Corrupts registers:
|
---|
207 | ; BL
|
---|
208 | ;--------------------------------------------------------------------
|
---|
209 | ALIGN JUMP_ALIGN
|
---|
210 | DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL:
|
---|
211 | and bl, FLG_CONTEXT_ATTRIBUTES
|
---|
212 | and BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], ~FLG_CONTEXT_ATTRIBUTES
|
---|
213 | or [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], bl
|
---|
214 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], ax
|
---|
215 | ret
|
---|
216 |
|
---|
217 |
|
---|
218 | ;--------------------------------------------------------------------
|
---|
219 | ; DisplayContext_SetCharacterAttributeFromAL
|
---|
220 | ; Parameters:
|
---|
221 | ; AL: Character attribute
|
---|
222 | ; DS: BDA segment (zero)
|
---|
223 | ; Returns:
|
---|
224 | ; Nothing
|
---|
225 | ; Corrupts registers:
|
---|
226 | ; Nothing
|
---|
227 | ;--------------------------------------------------------------------
|
---|
228 | ALIGN JUMP_ALIGN
|
---|
229 | DisplayContext_SetCharacterAttributeFromAL:
|
---|
230 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al
|
---|
231 | ret
|
---|
232 |
|
---|
233 |
|
---|
234 | ;--------------------------------------------------------------------
|
---|
235 | ; DisplayContext_SetCharacterOutputParameterFromAX
|
---|
236 | ; Parameters:
|
---|
237 | ; AX: Parameter for Character Output function
|
---|
238 | ; DS: BDA segment (zero)
|
---|
239 | ; Returns:
|
---|
240 | ; Nothing
|
---|
241 | ; Corrupts registers:
|
---|
242 | ; Nothing
|
---|
243 | ;--------------------------------------------------------------------
|
---|
244 | ALIGN JUMP_ALIGN
|
---|
245 | DisplayContext_SetCharacterOutputParameterFromAX:
|
---|
246 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], ax
|
---|
247 | ret
|
---|
248 |
|
---|
249 | ;--------------------------------------------------------------------
|
---|
250 | ; DisplayContext_GetCharacterOutputParameterToDX
|
---|
251 | ; Parameters:
|
---|
252 | ; DS: BDA segment (zero)
|
---|
253 | ; Returns:
|
---|
254 | ; DX: User parameter for Character Output function
|
---|
255 | ; Corrupts registers:
|
---|
256 | ; Nothing
|
---|
257 | ;--------------------------------------------------------------------
|
---|
258 | ALIGN JUMP_ALIGN
|
---|
259 | DisplayContext_GetCharacterOutputParameterToDX:
|
---|
260 | mov dx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam]
|
---|
261 | ret
|
---|
262 |
|
---|
263 |
|
---|
264 | ;--------------------------------------------------------------------
|
---|
265 | ; DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX
|
---|
266 | ; Parameters:
|
---|
267 | ; AX: Offset in bytes from some character to another
|
---|
268 | ; DS: BDA segment (zero)
|
---|
269 | ; Returns:
|
---|
270 | ; AX: Offset in characters from some character to another
|
---|
271 | ; Corrupts registers:
|
---|
272 | ; Nothing
|
---|
273 | ;--------------------------------------------------------------------
|
---|
274 | ALIGN JUMP_ALIGN
|
---|
275 | DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX:
|
---|
276 | test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
|
---|
277 | jz SHORT ReturnOffsetInAX
|
---|
278 | sar ax, 1 ; BYTE count to WORD count
|
---|
279 | ret
|
---|
280 |
|
---|
281 | ;--------------------------------------------------------------------
|
---|
282 | ; DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX
|
---|
283 | ; Parameters:
|
---|
284 | ; AX: Offset in characters from some character to another
|
---|
285 | ; DS: BDA segment (zero)
|
---|
286 | ; Returns:
|
---|
287 | ; AX: Offset in bytes from some character to another
|
---|
288 | ; Corrupts registers:
|
---|
289 | ; Nothing
|
---|
290 | ;--------------------------------------------------------------------
|
---|
291 | ALIGN JUMP_ALIGN
|
---|
292 | DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX:
|
---|
293 | test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
|
---|
294 | jz SHORT ReturnOffsetInAX
|
---|
295 | sal ax, 1 ; WORD count to BYTE count
|
---|
296 | ALIGN JUMP_ALIGN, ret
|
---|
297 | ReturnOffsetInAX:
|
---|
298 | ret
|
---|