1 | ; File name : Display.asm |
---|
2 | ; Project name : Assembly Library |
---|
3 | ; Created date : 26.6.2010 |
---|
4 | ; Last update : 27.9.2010 |
---|
5 | ; Author : Tomi Tilli |
---|
6 | ; Description : Functions for display output. |
---|
7 | |
---|
8 | ; Section containing code |
---|
9 | SECTION .text |
---|
10 | |
---|
11 | ;-------------------------------------------------------------------- |
---|
12 | ; Supports following formatting types: |
---|
13 | ; %a Specifies attribute for next character |
---|
14 | ; %A Specifies attribute for remaining string (or until next %A) |
---|
15 | ; %d Prints signed 16-bit decimal integer |
---|
16 | ; %u Prints unsigned 16-bit decimal integer |
---|
17 | ; %x Prints 16-bit hexadecimal integer |
---|
18 | ; %s Prints string (from CS segment) |
---|
19 | ; %S Prints string (far pointer) |
---|
20 | ; %c Prints character |
---|
21 | ; %t Prints character number of times (character needs to be pushed first, then repeat times) |
---|
22 | ; %% Prints '%' character (no parameter pushed) |
---|
23 | ; |
---|
24 | ; Any placeholder can be set to minimum length by specifying |
---|
25 | ; minimum number of characters. For example %8d would append spaces |
---|
26 | ; after integer so that at least 8 characters would be printed. |
---|
27 | ; |
---|
28 | ; DisplayPrint_FormattedNullTerminatedStringFromCSSI |
---|
29 | ; Parameters: |
---|
30 | ; BP: SP before pushing parameters |
---|
31 | ; DS: BDA segment (zero) |
---|
32 | ; CS:SI: Pointer to string to format |
---|
33 | ; ES:DI: Ptr to cursor location in video RAM |
---|
34 | ; Stack: Parameters for formatting placeholders. |
---|
35 | ; Parameter for first placeholder must be pushed first. |
---|
36 | ; Low word must pushed first for placeholders requiring |
---|
37 | ; 32-bit parameters (two words). |
---|
38 | ; Returns: |
---|
39 | ; DI: Updated offset to video RAM |
---|
40 | ; Corrupts registers: |
---|
41 | ; AX, DX |
---|
42 | ;-------------------------------------------------------------------- |
---|
43 | ALIGN JUMP_ALIGN |
---|
44 | DisplayPrint_FormattedNullTerminatedStringFromCSSI: |
---|
45 | push bp |
---|
46 | push si |
---|
47 | push cx |
---|
48 | push bx |
---|
49 | push WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute] |
---|
50 | |
---|
51 | dec bp ; Point BP to... |
---|
52 | dec bp ; ...first stack parameter |
---|
53 | call DisplayFormat_ParseCharacters |
---|
54 | |
---|
55 | ; Pop original character attribute |
---|
56 | pop ax |
---|
57 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al |
---|
58 | |
---|
59 | pop bx |
---|
60 | pop cx |
---|
61 | pop si |
---|
62 | pop bp |
---|
63 | ret |
---|
64 | |
---|
65 | |
---|
66 | ;-------------------------------------------------------------------- |
---|
67 | ; DisplayPrint_SignedWordFromAXWithBaseInBX |
---|
68 | ; Parameters: |
---|
69 | ; AX: Word to display |
---|
70 | ; BX: Integer base (binary=2, octal=8, decimal=10, hexadecimal=16) |
---|
71 | ; DS: BDA segment (zero) |
---|
72 | ; ES:DI: Ptr to cursor location in video RAM |
---|
73 | ; Returns: |
---|
74 | ; DI: Updated offset to video RAM |
---|
75 | ; Corrupts registers: |
---|
76 | ; AX, DX |
---|
77 | ;-------------------------------------------------------------------- |
---|
78 | ALIGN JUMP_ALIGN |
---|
79 | DisplayPrint_SignedWordFromAXWithBaseInBX: |
---|
80 | test ax, ax |
---|
81 | jns SHORT DisplayPrint_WordFromAXWithBaseInBX |
---|
82 | |
---|
83 | push ax |
---|
84 | mov al, '-' |
---|
85 | call DisplayPrint_CharacterFromAL |
---|
86 | pop ax |
---|
87 | neg ax |
---|
88 | ; Fall to DisplayPrint_WordFromAXWithBaseInBX |
---|
89 | |
---|
90 | ;-------------------------------------------------------------------- |
---|
91 | ; DisplayPrint_WordFromAXWithBaseInBX |
---|
92 | ; Parameters: |
---|
93 | ; AX: Word to display |
---|
94 | ; BX: Integer base (binary=2, octal=8, decimal=10, hexadecimal=16) |
---|
95 | ; DS: BDA segment (zero) |
---|
96 | ; ES:DI: Ptr to cursor location in video RAM |
---|
97 | ; Returns: |
---|
98 | ; DI: Updated offset to video RAM |
---|
99 | ; Corrupts registers: |
---|
100 | ; AX, DX |
---|
101 | ;-------------------------------------------------------------------- |
---|
102 | ALIGN JUMP_ALIGN |
---|
103 | DisplayPrint_WordFromAXWithBaseInBX: |
---|
104 | push cx |
---|
105 | push bx |
---|
106 | |
---|
107 | xor cx, cx |
---|
108 | ALIGN JUMP_ALIGN |
---|
109 | .DivideLoop: |
---|
110 | xor dx, dx ; DX:AX now holds the integer |
---|
111 | div bx ; Divide DX:AX by base |
---|
112 | push dx ; Push remainder |
---|
113 | inc cx ; Increment character count |
---|
114 | test ax, ax ; All divided? |
---|
115 | jnz SHORT .DivideLoop ; If not, loop |
---|
116 | |
---|
117 | mov bx, .rgcDigitToCharacter |
---|
118 | ALIGN JUMP_ALIGN |
---|
119 | .PrintNextDigit: |
---|
120 | pop ax ; Pop digit |
---|
121 | eSEG cs |
---|
122 | xlatb |
---|
123 | call DisplayPrint_CharacterFromAL |
---|
124 | loop .PrintNextDigit |
---|
125 | |
---|
126 | pop bx |
---|
127 | pop cx |
---|
128 | ret |
---|
129 | .rgcDigitToCharacter: db "0123456789ABCDEF" |
---|
130 | |
---|
131 | |
---|
132 | ;-------------------------------------------------------------------- |
---|
133 | ; DisplayPrint_CharacterBufferFromBXSIwithLengthInCX |
---|
134 | ; Parameters: |
---|
135 | ; CX: Buffer length (characters) |
---|
136 | ; BX:SI: Ptr to NULL terminated string |
---|
137 | ; DS: BDA segment (zero) |
---|
138 | ; ES:DI: Ptr to cursor location in video RAM |
---|
139 | ; Returns: |
---|
140 | ; DI: Updated offset to video RAM |
---|
141 | ; Corrupts registers: |
---|
142 | ; AX, DX |
---|
143 | ;-------------------------------------------------------------------- |
---|
144 | ALIGN JUMP_ALIGN |
---|
145 | DisplayPrint_CharacterBufferFromBXSIwithLengthInCX: |
---|
146 | jcxz .NothingToPrintSinceZeroLength |
---|
147 | push si |
---|
148 | push cx |
---|
149 | |
---|
150 | ALIGN JUMP_ALIGN |
---|
151 | .PrintNextCharacter: |
---|
152 | mov ds, bx |
---|
153 | lodsb |
---|
154 | LOAD_BDA_SEGMENT_TO ds, dx |
---|
155 | call DisplayPrint_CharacterFromAL |
---|
156 | loop .PrintNextCharacter |
---|
157 | |
---|
158 | LOAD_BDA_SEGMENT_TO ds, dx |
---|
159 | pop cx |
---|
160 | pop si |
---|
161 | .NothingToPrintSinceZeroLength: |
---|
162 | ret |
---|
163 | |
---|
164 | |
---|
165 | ;-------------------------------------------------------------------- |
---|
166 | ; DisplayPrint_NullTerminatedStringFromCSSI |
---|
167 | ; Parameters: |
---|
168 | ; CS:SI: Ptr to NULL terminated string |
---|
169 | ; DS: BDA segment (zero) |
---|
170 | ; ES:DI: Ptr to cursor location in video RAM |
---|
171 | ; Returns: |
---|
172 | ; DI: Updated offset to video RAM |
---|
173 | ; Corrupts registers: |
---|
174 | ; AX, DX |
---|
175 | ;-------------------------------------------------------------------- |
---|
176 | ALIGN JUMP_ALIGN |
---|
177 | DisplayPrint_NullTerminatedStringFromCSSI: |
---|
178 | push bx |
---|
179 | mov bx, cs |
---|
180 | call DisplayPrint_NullTerminatedStringFromBXSI |
---|
181 | pop bx |
---|
182 | ret |
---|
183 | |
---|
184 | |
---|
185 | ;-------------------------------------------------------------------- |
---|
186 | ; DisplayPrint_NullTerminatedStringFromBXSI |
---|
187 | ; Parameters: |
---|
188 | ; DS: BDA segment (zero) |
---|
189 | ; BX:SI: Ptr to NULL terminated string |
---|
190 | ; ES:DI: Ptr to cursor location in video RAM |
---|
191 | ; Returns: |
---|
192 | ; DI: Updated offset to video RAM |
---|
193 | ; Corrupts registers: |
---|
194 | ; AX, DX |
---|
195 | ;-------------------------------------------------------------------- |
---|
196 | ALIGN JUMP_ALIGN |
---|
197 | DisplayPrint_NullTerminatedStringFromBXSI: |
---|
198 | push si |
---|
199 | push cx |
---|
200 | |
---|
201 | xor cx, cx |
---|
202 | ALIGN JUMP_ALIGN |
---|
203 | .PrintNextCharacter: |
---|
204 | mov ds, bx ; String segment to DS |
---|
205 | lodsb |
---|
206 | mov ds, cx ; BDA segment to DS |
---|
207 | test al, al ; NULL? |
---|
208 | jz SHORT .EndOfString |
---|
209 | call DisplayPrint_CharacterFromAL |
---|
210 | jmp SHORT .PrintNextCharacter |
---|
211 | |
---|
212 | ALIGN JUMP_ALIGN |
---|
213 | .EndOfString: |
---|
214 | pop cx |
---|
215 | pop si |
---|
216 | ret |
---|
217 | |
---|
218 | |
---|
219 | ;-------------------------------------------------------------------- |
---|
220 | ; DisplayPrint_ClearScreen |
---|
221 | ; Parameters: |
---|
222 | ; DS: BDA segment (zero) |
---|
223 | ; ES:DI: Ptr to cursor location in video RAM |
---|
224 | ; Returns: |
---|
225 | ; Nothing |
---|
226 | ; Corrupts registers: |
---|
227 | ; AX, DX |
---|
228 | ;-------------------------------------------------------------------- |
---|
229 | ALIGN JUMP_ALIGN |
---|
230 | DisplayPrint_ClearScreen: |
---|
231 | push di |
---|
232 | xor ax, ax |
---|
233 | call DisplayCursor_SetCoordinatesFromAX |
---|
234 | call DisplayPage_GetColumnsToALandRowsToAH |
---|
235 | call DisplayPrint_ClearAreaWithHeightInAHandWidthInAL |
---|
236 | pop di |
---|
237 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], di |
---|
238 | ret |
---|
239 | |
---|
240 | |
---|
241 | ;-------------------------------------------------------------------- |
---|
242 | ; DisplayPrint_ClearAreaWithHeightInAHandWidthInAL |
---|
243 | ; Parameters: |
---|
244 | ; AH: Area height |
---|
245 | ; AL: Area width |
---|
246 | ; DS: BDA segment (zero) |
---|
247 | ; ES:DI: Ptr to cursor location in video RAM |
---|
248 | ; Returns: |
---|
249 | ; DI: Updated offset to video RAM |
---|
250 | ; Corrupts registers: |
---|
251 | ; AX, DX |
---|
252 | ;-------------------------------------------------------------------- |
---|
253 | ALIGN JUMP_ALIGN |
---|
254 | DisplayPrint_ClearAreaWithHeightInAHandWidthInAL: |
---|
255 | push si |
---|
256 | push cx |
---|
257 | push bx |
---|
258 | |
---|
259 | xchg bx, ax ; Area size to BX |
---|
260 | call DisplayCursor_GetSoftwareCoordinatesToAX |
---|
261 | xchg si, ax ; Software (Y,X) coordinates now in SI |
---|
262 | xor cx, cx |
---|
263 | |
---|
264 | ALIGN JUMP_ALIGN |
---|
265 | .ClearRowLoop: |
---|
266 | mov cl, bl ; Area width now in CX |
---|
267 | mov al, SCREEN_BACKGROUND_CHARACTER |
---|
268 | call DisplayPrint_RepeatCharacterFromALwithCountInCX |
---|
269 | |
---|
270 | xchg ax, si ; Coordinates to AX |
---|
271 | inc ah ; Increment row |
---|
272 | mov si, ax |
---|
273 | call DisplayCursor_SetCoordinatesFromAX |
---|
274 | dec bh ; Decrement rows left |
---|
275 | jnz SHORT .ClearRowLoop |
---|
276 | |
---|
277 | pop bx |
---|
278 | pop cx |
---|
279 | pop si |
---|
280 | ret |
---|
281 | |
---|
282 | |
---|
283 | ;-------------------------------------------------------------------- |
---|
284 | ; DisplayPrint_RepeatCharacterFromALwithCountInCX |
---|
285 | ; Parameters: |
---|
286 | ; AL: Character to display |
---|
287 | ; CX: Repeat count |
---|
288 | ; DS: BDA segment (zero) |
---|
289 | ; ES:DI: Ptr to cursor location in video RAM |
---|
290 | ; Returns: |
---|
291 | ; DI: Updated offset to video RAM |
---|
292 | ; Corrupts registers: |
---|
293 | ; AX, DX |
---|
294 | ;-------------------------------------------------------------------- |
---|
295 | ALIGN JUMP_ALIGN |
---|
296 | DisplayPrint_RepeatCharacterFromALwithCountInCX: |
---|
297 | jcxz .NothingToRepeat |
---|
298 | push cx |
---|
299 | |
---|
300 | ALIGN JUMP_ALIGN |
---|
301 | .RepeatCharacter: |
---|
302 | push ax |
---|
303 | call DisplayPrint_CharacterFromAL |
---|
304 | pop ax |
---|
305 | loop .RepeatCharacter |
---|
306 | |
---|
307 | pop cx |
---|
308 | .NothingToRepeat: |
---|
309 | ret |
---|
310 | |
---|
311 | |
---|
312 | ;-------------------------------------------------------------------- |
---|
313 | ; DisplayPrint_Newline |
---|
314 | ; Parameters: |
---|
315 | ; DS: BDA segment (zero) |
---|
316 | ; ES:DI: Ptr to cursor location in video RAM |
---|
317 | ; Returns: |
---|
318 | ; DI: Updated offset to video RAM |
---|
319 | ; Corrupts registers: |
---|
320 | ; AX, DX |
---|
321 | ;-------------------------------------------------------------------- |
---|
322 | ALIGN JUMP_ALIGN |
---|
323 | DisplayPrint_Newline: |
---|
324 | mov al, CR |
---|
325 | call DisplayPrint_CharacterFromAL |
---|
326 | mov al, LF |
---|
327 | ; Fall to DisplayPrint_CharacterFromAL |
---|
328 | |
---|
329 | |
---|
330 | ;-------------------------------------------------------------------- |
---|
331 | ; DisplayPrint_CharacterFromAL |
---|
332 | ; Parameters: |
---|
333 | ; AL: Character to display |
---|
334 | ; DS: BDA segment (zero) |
---|
335 | ; ES:DI: Ptr to cursor location in video RAM |
---|
336 | ; Returns: |
---|
337 | ; DI: Updated offset to video RAM |
---|
338 | ; Corrupts registers: |
---|
339 | ; AX, DX |
---|
340 | ;-------------------------------------------------------------------- |
---|
341 | ALIGN JUMP_ALIGN |
---|
342 | DisplayPrint_CharacterFromAL: |
---|
343 | mov ah, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute] |
---|
344 | jmp [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut] |
---|