1 | ; File name : DisplayContext.asm
|
---|
2 | ; Project name : Assembly Library
|
---|
3 | ; Created date : 25.6.2010
|
---|
4 | ; Last update : 27.9.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
|
---|
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 | ;--------------------------------------------------------------------
|
---|
59 | ALIGN JUMP_ALIGN
|
---|
60 | DisplayContext_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 | ;--------------------------------------------------------------------
|
---|
83 | ALIGN JUMP_ALIGN
|
---|
84 | DisplayContext_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 | ;--------------------------------------------------------------------
|
---|
112 | ALIGN JUMP_ALIGN
|
---|
113 | DisplayContext_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 | ;--------------------------------------------------------------------
|
---|
129 | ALIGN JUMP_ALIGN
|
---|
130 | DisplayContext_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 | ;--------------------------------------------------------------------
|
---|
147 | ALIGN JUMP_ALIGN
|
---|
148 | DisplayContext_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_SetCharOutputFunctionFromAXwithAttribFlagInDL
|
---|
156 | ; Parameters:
|
---|
157 | ; AX: Offset to character output function
|
---|
158 | ; DL: Attribute Flag
|
---|
159 | ; DS: BDA segment (zero)
|
---|
160 | ; Returns:
|
---|
161 | ; Nothing
|
---|
162 | ; Corrupts registers:
|
---|
163 | ; Nothing
|
---|
164 | ;--------------------------------------------------------------------
|
---|
165 | ALIGN JUMP_ALIGN
|
---|
166 | DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInDL:
|
---|
167 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], ax
|
---|
168 | and BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], ~FLG_CONTEXT_ATTRIBUTES
|
---|
169 | mov al, dl
|
---|
170 | and al, FLG_CONTEXT_ATTRIBUTES
|
---|
171 | or [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], al
|
---|
172 | ret
|
---|
173 |
|
---|
174 |
|
---|
175 | ;--------------------------------------------------------------------
|
---|
176 | ; DisplayContext_SetCharacterAttributeFromAL
|
---|
177 | ; Parameters:
|
---|
178 | ; AL: Character attribute
|
---|
179 | ; DS: BDA segment (zero)
|
---|
180 | ; Returns:
|
---|
181 | ; Nothing
|
---|
182 | ; Corrupts registers:
|
---|
183 | ; Nothing
|
---|
184 | ;--------------------------------------------------------------------
|
---|
185 | ALIGN JUMP_ALIGN
|
---|
186 | DisplayContext_SetCharacterAttributeFromAL:
|
---|
187 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al
|
---|
188 | ret
|
---|
189 |
|
---|
190 |
|
---|
191 | ;--------------------------------------------------------------------
|
---|
192 | ; DisplayContext_SetCharacterOutputParameterFromAX
|
---|
193 | ; Parameters:
|
---|
194 | ; AX: Parameter for Character Output function
|
---|
195 | ; DS: BDA segment (zero)
|
---|
196 | ; Returns:
|
---|
197 | ; Nothing
|
---|
198 | ; Corrupts registers:
|
---|
199 | ; Nothing
|
---|
200 | ;--------------------------------------------------------------------
|
---|
201 | ALIGN JUMP_ALIGN
|
---|
202 | DisplayContext_SetCharacterOutputParameterFromAX:
|
---|
203 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], ax
|
---|
204 | ret
|
---|
205 |
|
---|
206 | ;--------------------------------------------------------------------
|
---|
207 | ; DisplayContext_GetCharacterOutputParameterToDX
|
---|
208 | ; Parameters:
|
---|
209 | ; DS: BDA segment (zero)
|
---|
210 | ; Returns:
|
---|
211 | ; DX: User parameter for Character Output function
|
---|
212 | ; Corrupts registers:
|
---|
213 | ; Nothing
|
---|
214 | ;--------------------------------------------------------------------
|
---|
215 | ALIGN JUMP_ALIGN
|
---|
216 | DisplayContext_GetCharacterOutputParameterToDX:
|
---|
217 | mov dx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam]
|
---|
218 | ret
|
---|
219 |
|
---|
220 |
|
---|
221 | ;--------------------------------------------------------------------
|
---|
222 | ; DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX
|
---|
223 | ; Parameters:
|
---|
224 | ; AX: Offset in bytes from some character to another
|
---|
225 | ; DS: BDA segment (zero)
|
---|
226 | ; Returns:
|
---|
227 | ; AX: Offset in characters from some character to another
|
---|
228 | ; Corrupts registers:
|
---|
229 | ; Nothing
|
---|
230 | ;--------------------------------------------------------------------
|
---|
231 | ALIGN JUMP_ALIGN
|
---|
232 | DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX:
|
---|
233 | test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
|
---|
234 | jz SHORT ReturnOffsetInAX
|
---|
235 | sar ax, 1 ; BYTE count to WORD count
|
---|
236 | ret
|
---|
237 |
|
---|
238 | ;--------------------------------------------------------------------
|
---|
239 | ; DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX
|
---|
240 | ; Parameters:
|
---|
241 | ; AX: Offset in characters from some character to another
|
---|
242 | ; DS: BDA segment (zero)
|
---|
243 | ; Returns:
|
---|
244 | ; AX: Offset in bytes from some character to another
|
---|
245 | ; Corrupts registers:
|
---|
246 | ; Nothing
|
---|
247 | ;--------------------------------------------------------------------
|
---|
248 | ALIGN JUMP_ALIGN
|
---|
249 | DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX:
|
---|
250 | test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
|
---|
251 | jz SHORT ReturnOffsetInAX
|
---|
252 | sal ax, 1 ; WORD count to BYTE count
|
---|
253 | ALIGN JUMP_ALIGN, ret
|
---|
254 | ReturnOffsetInAX:
|
---|
255 | ret
|
---|