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

Last change on this file since 47 was 44, checked in by Tomi Tilli, 14 years ago

Spaces can now be generated before format specifier when printing formatted string.
Background character and attribute can now be easily specified before compiling.

File size: 9.2 KB
RevLine 
[41]1; File name : Display.asm
2; Project name : Assembly Library
3; Created date : 26.6.2010
[44]4; Last update : 27.9.2010
[41]5; Author : Tomi Tilli
6; Description : Functions for display output.
7
8; Section containing code
9SECTION .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;--------------------------------------------------------------------
43ALIGN JUMP_ALIGN
44DisplayPrint_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;--------------------------------------------------------------------
[44]67; DisplayPrint_SignedWordFromAXWithBaseInBX
[41]68; Parameters:
69; AX: Word to display
[44]70; BX: Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
[41]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;--------------------------------------------------------------------
78ALIGN JUMP_ALIGN
[44]79DisplayPrint_SignedWordFromAXWithBaseInBX:
80 test ax, ax
81 jns SHORT DisplayPrint_WordFromAXWithBaseInBX
[41]82
83 push ax
84 mov al, '-'
85 call DisplayPrint_CharacterFromAL
86 pop ax
87 neg ax
[44]88 ; Fall to DisplayPrint_WordFromAXWithBaseInBX
[41]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;--------------------------------------------------------------------
102ALIGN JUMP_ALIGN
103DisplayPrint_WordFromAXWithBaseInBX:
104 push cx
[44]105 push bx
[41]106
107 xor cx, cx
108ALIGN 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
[44]116
117 mov bx, .rgcDigitToCharacter
[41]118ALIGN JUMP_ALIGN
[44]119.PrintNextDigit:
120 pop ax ; Pop digit
121 eSEG cs
122 xlatb
[41]123 call DisplayPrint_CharacterFromAL
[44]124 loop .PrintNextDigit
[41]125
[44]126 pop bx
[41]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;--------------------------------------------------------------------
144ALIGN JUMP_ALIGN
145DisplayPrint_CharacterBufferFromBXSIwithLengthInCX:
[44]146 jcxz .NothingToPrintSinceZeroLength
147 push si
[41]148 push cx
149
150ALIGN JUMP_ALIGN
[44]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
[41]159 pop cx
[44]160 pop si
161.NothingToPrintSinceZeroLength:
[41]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;--------------------------------------------------------------------
176ALIGN JUMP_ALIGN
177DisplayPrint_NullTerminatedStringFromCSSI:
[44]178 push bx
[41]179 mov bx, cs
[44]180 call DisplayPrint_NullTerminatedStringFromBXSI
181 pop bx
182 ret
[41]183
[44]184
[41]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;--------------------------------------------------------------------
196ALIGN JUMP_ALIGN
197DisplayPrint_NullTerminatedStringFromBXSI:
[44]198 push si
199 push cx
[41]200
[44]201 xor cx, cx
[41]202ALIGN JUMP_ALIGN
[44]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
[41]211
212ALIGN JUMP_ALIGN
[44]213.EndOfString:
214 pop cx
215 pop si
[41]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;--------------------------------------------------------------------
229ALIGN JUMP_ALIGN
230DisplayPrint_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:
[42]249; DI: Updated offset to video RAM
[41]250; Corrupts registers:
251; AX, DX
252;--------------------------------------------------------------------
253ALIGN JUMP_ALIGN
254DisplayPrint_ClearAreaWithHeightInAHandWidthInAL:
[42]255 push si
[41]256 push cx
257 push bx
258
[42]259 xchg bx, ax ; Area size to BX
[41]260 call DisplayCursor_GetSoftwareCoordinatesToAX
[42]261 xchg si, ax ; Software (Y,X) coordinates now in SI
262 xor cx, cx
[41]263
264ALIGN JUMP_ALIGN
[42]265.ClearRowLoop:
266 mov cl, bl ; Area width now in CX
[44]267 mov al, SCREEN_BACKGROUND_CHARACTER
[42]268 call DisplayPrint_RepeatCharacterFromALwithCountInCX
[41]269
[42]270 xchg ax, si ; Coordinates to AX
271 inc ah ; Increment row
272 mov si, ax
[41]273 call DisplayCursor_SetCoordinatesFromAX
[42]274 dec bh ; Decrement rows left
275 jnz SHORT .ClearRowLoop
[41]276
277 pop bx
278 pop cx
[42]279 pop si
[41]280 ret
[42]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;--------------------------------------------------------------------
295ALIGN JUMP_ALIGN
296DisplayPrint_RepeatCharacterFromALwithCountInCX:
[44]297 jcxz .NothingToRepeat
298 push cx
299
300ALIGN JUMP_ALIGN
301.RepeatCharacter:
[42]302 push ax
303 call DisplayPrint_CharacterFromAL
304 pop ax
[44]305 loop .RepeatCharacter
306
307 pop cx
308.NothingToRepeat:
[42]309 ret
310
311
312;--------------------------------------------------------------------
[44]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;--------------------------------------------------------------------
322ALIGN JUMP_ALIGN
323DisplayPrint_Newline:
324 mov al, CR
325 call DisplayPrint_CharacterFromAL
326 mov al, LF
327 ; Fall to DisplayPrint_CharacterFromAL
328
329
330;--------------------------------------------------------------------
[42]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;--------------------------------------------------------------------
341ALIGN JUMP_ALIGN
342DisplayPrint_CharacterFromAL:
343 mov ah, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
344 jmp [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut]
Note: See TracBrowser for help on using the repository browser.