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