source: xtideuniversalbios/trunk/Assembly_Library/Src/Display/DisplayPrint.asm@ 208

Last change on this file since 208 was 194, checked in by gregli@…, 13 years ago

ifdef'd out more unused code. Also added a tool for looking through the listing and the output of the precompiler to aid in finding dead code. Some changes in the files are to add annotations for the tool to avoid false positives.

File size: 10.6 KB
Line 
1; Project name : Assembly Library
2; Description : Functions for display output.
3
4; Section containing code
5SECTION .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;--------------------------------------------------------------------
44ALIGN JUMP_ALIGN
45DisplayPrint_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
81ALIGN JUMP_ALIGN
82DisplayPrint_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
109ALIGN JUMP_ALIGN
110DisplayPrint_WordFromAXWithBaseInBX:
111 push cx
112 push bx
113
114 xor cx, cx
115ALIGN 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
125ALIGN 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%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
154
155ALIGN JUMP_ALIGN
156DisplayPrint_CharacterBufferFromBXSIwithLengthInCX:
157 jcxz .NothingToPrintSinceZeroLength
158 push si
159 push cx
160
161ALIGN JUMP_ALIGN
162.PrintNextCharacter:
163 mov ds, bx
164 lodsb
165 LOAD_BDA_SEGMENT_TO ds, dx
166 call DisplayPrint_CharacterFromAL
167 loop .PrintNextCharacter
168
169 ;mov ds, cx ; Restore DS to BDA. Not needed unless DisplayPrint_CharacterFromAL changes DS.
170 pop cx
171 pop si
172.NothingToPrintSinceZeroLength:
173 ret
174%endif
175
176
177
178
179;--------------------------------------------------------------------
180; DisplayPrint_ClearScreenWithCharInALandAttributeInAH
181; Parameters:
182; AL: Character to clear with
183; AH: Attribute to clear with
184; DS: BDA segment (zero)
185; ES:DI: Ptr to cursor location in video RAM
186; Returns:
187; Nothing
188; Corrupts registers:
189; AX, DX
190;--------------------------------------------------------------------
191ALIGN JUMP_ALIGN
192DisplayPrint_ClearScreenWithCharInALandAttributeInAH:
193 push di
194 push cx
195
196 xchg cx, ax
197 xor ax, ax
198 call DisplayCursor_SetCoordinatesFromAX ; Updates DI
199 call DisplayPage_GetColumnsToALandRowsToAH
200 mul ah ; AX = AL*AH = Characters on screen
201 xchg cx, ax ; AX = Char+Attr, CX = WORDs to store
202 rep stosw
203
204 pop cx
205 pop di
206 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], di
207 ret
208
209
210;--------------------------------------------------------------------
211; DisplayPrint_ClearAreaWithHeightInAHandWidthInAL
212; Parameters:
213; AH: Area height
214; AL: Area width
215; DS: BDA segment (zero)
216; ES:DI: Ptr to cursor location in video RAM
217; Returns:
218; DI: Updated offset to video RAM
219; Corrupts registers:
220; AX, DX
221;--------------------------------------------------------------------
222%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
223ALIGN JUMP_ALIGN
224DisplayPrint_ClearAreaWithHeightInAHandWidthInAL:
225 push si
226 push cx
227 push bx
228
229 xchg bx, ax ; Area size to BX
230 call DisplayCursor_GetSoftwareCoordinatesToAX
231 xchg si, ax ; Software (Y,X) coordinates now in SI
232 xor cx, cx
233
234ALIGN JUMP_ALIGN
235.ClearRowLoop:
236 mov cl, bl ; Area width now in CX
237 mov al, SCREEN_BACKGROUND_CHARACTER
238 call DisplayPrint_RepeatCharacterFromALwithCountInCX
239
240 xchg ax, si ; Coordinates to AX
241 inc ah ; Increment row
242 mov si, ax
243 call DisplayCursor_SetCoordinatesFromAX
244 dec bh ; Decrement rows left
245 jnz SHORT .ClearRowLoop
246
247 pop bx
248 pop cx
249 pop si
250 ret
251%endif
252
253
254;--------------------------------------------------------------------
255; DisplayPrint_RepeatCharacterFromALwithCountInCX
256; Parameters:
257; AL: Character to display
258; CX: Repeat count
259; DS: BDA segment (zero)
260; ES:DI: Ptr to cursor location in video RAM
261; Returns:
262; DI: Updated offset to video RAM
263; Corrupts registers:
264; DX
265;--------------------------------------------------------------------
266ALIGN JUMP_ALIGN
267DisplayPrint_RepeatCharacterFromALwithCountInCX:
268 jcxz .NothingToRepeat
269 push cx
270
271ALIGN JUMP_ALIGN
272.RepeatCharacter:
273 push ax
274 call DisplayPrint_CharacterFromAL
275 pop ax
276 loop .RepeatCharacter
277
278 pop cx
279.NothingToRepeat:
280
281 ret
282
283;--------------------------------------------------------------------
284; DisplayPrint_NullTerminatedStringFromCSSI
285; Parameters:
286; CS:SI: Ptr to NULL terminated string
287; DS: BDA segment (zero)
288; ES:DI: Ptr to cursor location in video RAM
289; Returns:
290; DI: Updated offset to video RAM
291; Corrupts registers:
292; AX, DX
293;--------------------------------------------------------------------
294
295%ifndef MODULE_STRINGS_COMPRESSED
296;;;
297;;; Take care when using this routine with compressed strings (which is why it is disabled).
298;;; All strings in CSSI should go through the DisplayFormatCompressed code to be decoded.
299;;;
300ALIGN JUMP_ALIGN
301DisplayPrint_NullTerminatedStringFromCSSI:
302 push bx
303 mov bx, cs
304 call DisplayPrint_NullTerminatedStringFromBXSI
305 pop bx
306
307 ret
308%endif
309
310
311
312
313;;;
314;;; Note that the following routines need to be at the bottom of this file
315;;; to accomodate short jumps from the next file (DisplayFormat/DisplayFormatCompressed)
316;;;
317
318;--------------------------------------------------------------------
319; DisplayPrint_Newline
320; Parameters:
321; DS: BDA segment (zero)
322; ES:DI: Ptr to cursor location in video RAM
323; Returns:
324; DI: Updated offset to video RAM
325; Corrupts registers:
326; AX, DX
327;--------------------------------------------------------------------
328%ifdef MODULE_STRINGS_COMPRESSED
329ALIGN JUMP_ALIGN
330DisplayPrint_Newline_FormatAdjustBP:
331 inc bp ; we didn't need a parameter after all, readjust BP
332 inc bp
333 ; fall through to DisplayPrint_Newline
334%endif
335
336ALIGN JUMP_ALIGN
337
338DisplayPrint_Newline:
339 mov al, LF
340 call DisplayPrint_CharacterFromAL
341 mov al, CR
342 ; Fall to DisplayPrint_CharacterFromAL
343
344;--------------------------------------------------------------------
345; DisplayPrint_CharacterFromAL
346; Parameters:
347; AL: Character to display
348; Zero value is ignored (no characer is printed)
349; DS: BDA segment (zero)
350; ES:DI: Ptr to cursor location in video RAM
351; Returns:
352; DI: Updated offset to video RAM
353; Corrupts registers:
354; AX, DX
355;--------------------------------------------------------------------
356ALIGN JUMP_ALIGN
357DisplayPrint_CharacterFromAL:
358%ifdef MODULE_STRINGS_COMPRESSED
359 test al,al
360 jz DisplayPrint_Ret
361%endif
362 mov ah, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
363 jmp [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut]
364
365
366
367;--------------------------------------------------------------------
368; DisplayPrint_NullTerminatedStringFromBXSI
369; Parameters:
370; DS: BDA segment (zero)
371; BX:SI: Ptr to NULL terminated string
372; ES:DI: Ptr to cursor location in video RAM
373; Returns:
374; DI: Updated offset to video RAM
375; Corrupts registers:
376; AX, DX
377;--------------------------------------------------------------------
378ALIGN JUMP_ALIGN
379DisplayPrint_NullTerminatedStringFromBXSI:
380 push si
381 push cx
382
383 xor cx, cx
384ALIGN JUMP_ALIGN
385.PrintNextCharacter:
386 mov ds, bx ; String segment to DS
387 lodsb
388 mov ds, cx ; BDA segment to DS
389 test al, al ; NULL?
390 jz SHORT .EndOfString
391 call DisplayPrint_CharacterFromAL
392 jmp SHORT .PrintNextCharacter
393
394ALIGN JUMP_ALIGN
395.EndOfString:
396 pop cx
397 pop si
398
399DisplayPrint_Ret: ; random ret to jump to
400 ret
401
402
Note: See TracBrowser for help on using the repository browser.