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

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

Display Library no more produces CGA snow.

File size: 10.1 KB
Line 
1; File name : Display.asm
2; Project name : Assembly Library
3; Created date : 26.6.2010
4; Last update : 18.9.2010
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;--------------------------------------------------------------------
67; DisplayPrint_SignedDecimalIntegerFromAX
68; Parameters:
69; AX: Word to display
70; DS: BDA segment (zero)
71; ES:DI: Ptr to cursor location in video RAM
72; Returns:
73; BX: Number of characters printed
74; DI: Updated offset to video RAM
75; Corrupts registers:
76; AX, DX
77;--------------------------------------------------------------------
78ALIGN JUMP_ALIGN
79DisplayPrint_SignedDecimalIntegerFromAX:
80 mov bx, 10
81 test ah, 1<<7 ; Sign bit set?
82 jz SHORT DisplayPrint_WordFromAXWithBaseInBX
83
84 push ax
85 mov al, '-'
86 call DisplayPrint_CharacterFromAL
87 pop ax
88 neg ax
89 call DisplayPrint_WordFromAXWithBaseInBX
90 inc bx ; Increment character count for '-'
91 ret
92
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; BX: Number of characters printed
103; DI: Updated offset to video RAM
104; Corrupts registers:
105; AX, DX
106;--------------------------------------------------------------------
107ALIGN JUMP_ALIGN
108DisplayPrint_WordFromAXWithBaseInBX:
109 push cx
110
111 xor cx, cx
112ALIGN JUMP_ALIGN
113.DivideLoop:
114 xor dx, dx ; DX:AX now holds the integer
115 div bx ; Divide DX:AX by base
116 push dx ; Push remainder
117 inc cx ; Increment character count
118 test ax, ax ; All divided?
119 jnz SHORT .DivideLoop ; If not, loop
120 mov dx, cx ; Character count to DX
121ALIGN JUMP_ALIGN
122.PrintLoop:
123 pop bx ; Pop digit
124 mov al, [cs:bx+.rgcDigitToCharacter]
125 call DisplayPrint_CharacterFromAL
126 loop .PrintLoop
127 mov bx, dx ; Return characters printed
128
129 pop cx
130 ret
131.rgcDigitToCharacter: db "0123456789ABCDEF"
132
133
134;--------------------------------------------------------------------
135; DisplayPrint_CharacterBufferFromBXSIwithLengthInCX
136; Parameters:
137; CX: Buffer length (characters)
138; BX:SI: Ptr to NULL terminated string
139; DS: BDA segment (zero)
140; ES:DI: Ptr to cursor location in video RAM
141; Returns:
142; BX: Number of characters printed
143; DI: Updated offset to video RAM
144; Corrupts registers:
145; AX, DX
146;--------------------------------------------------------------------
147ALIGN JUMP_ALIGN
148DisplayPrint_CharacterBufferFromBXSIwithLengthInCX:
149 push cx
150
151 mov es, bx ; Buffer now in ES:SI
152 xor bx, bx ; Zero character counter
153 jcxz .BufferPrinted
154ALIGN JUMP_ALIGN
155.CharacterOutputLoop:
156 mov al, [es:bx+si]
157 inc bx
158 call LoadDisplaySegmentAndPrintCharacterFromAL
159 loop .CharacterOutputLoop
160.BufferPrinted:
161 mov es, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2]
162 pop cx
163 ret
164
165
166;--------------------------------------------------------------------
167; DisplayPrint_NullTerminatedStringFromCSSI
168; Parameters:
169; CS:SI: Ptr to NULL terminated string
170; DS: BDA segment (zero)
171; ES:DI: Ptr to cursor location in video RAM
172; Returns:
173; BX: Number of characters printed
174; DI: Updated offset to video RAM
175; Corrupts registers:
176; AX, DX
177;--------------------------------------------------------------------
178ALIGN JUMP_ALIGN
179DisplayPrint_NullTerminatedStringFromCSSI:
180 mov bx, cs
181 ; Fall to DisplayPrint_NullTerminatedStringFromBXSI
182
183;--------------------------------------------------------------------
184; DisplayPrint_NullTerminatedStringFromBXSI
185; Parameters:
186; DS: BDA segment (zero)
187; BX:SI: Ptr to NULL terminated string
188; ES:DI: Ptr to cursor location in video RAM
189; Returns:
190; BX: Number of characters printed
191; DI: Updated offset to video RAM
192; Corrupts registers:
193; AX, DX
194;--------------------------------------------------------------------
195ALIGN JUMP_ALIGN
196DisplayPrint_NullTerminatedStringFromBXSI:
197 mov es, bx ; String now in ES:SI
198 xor bx, bx ; Zero character counter
199ALIGN JUMP_ALIGN
200.CharacterOutputLoop:
201 mov al, [es:bx+si]
202 test al, al
203 jz SHORT .AllCharacterPrinted
204 inc bx
205
206 call LoadDisplaySegmentAndPrintCharacterFromAL
207 jmp SHORT .CharacterOutputLoop
208ALIGN JUMP_ALIGN
209.AllCharacterPrinted:
210 mov es, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2]
211 ret
212
213;--------------------------------------------------------------------
214; LoadDisplaySegmentAndPrintCharacterFromAL
215; Parameters:
216; AL: Character to print
217; DI: Offset to cursor location in video RAM
218; DS: BDA segment (zero)
219; Returns:
220; DI: Updated offset to video RAM
221; Corrupts registers:
222; AX, DX
223;--------------------------------------------------------------------
224ALIGN JUMP_ALIGN
225LoadDisplaySegmentAndPrintCharacterFromAL:
226 push es
227 mov es, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2]
228 call DisplayPrint_CharacterFromAL
229 pop es
230 ret
231
232
233;--------------------------------------------------------------------
234; DisplayPrint_Newline
235; Parameters:
236; DS: BDA segment (zero)
237; ES:DI: Ptr to cursor location in video RAM
238; Returns:
239; DI: Updated offset to video RAM
240; Corrupts registers:
241; AX, DX
242;--------------------------------------------------------------------
243ALIGN JUMP_ALIGN
244DisplayPrint_Newline:
245 mov al, CR
246 call DisplayPrint_CharacterFromAL
247 mov al, LF
248 jmp SHORT DisplayPrint_CharacterFromAL
249
250
251;--------------------------------------------------------------------
252; DisplayPrint_ClearScreen
253; Parameters:
254; DS: BDA segment (zero)
255; ES:DI: Ptr to cursor location in video RAM
256; Returns:
257; Nothing
258; Corrupts registers:
259; AX, DX
260;--------------------------------------------------------------------
261ALIGN JUMP_ALIGN
262DisplayPrint_ClearScreen:
263 push di
264 xor ax, ax
265 call DisplayCursor_SetCoordinatesFromAX
266 call DisplayPage_GetColumnsToALandRowsToAH
267 call DisplayPrint_ClearAreaWithHeightInAHandWidthInAL
268 pop di
269 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], di
270 ret
271
272
273;--------------------------------------------------------------------
274; DisplayPrint_ClearAreaWithHeightInAHandWidthInAL
275; Parameters:
276; AH: Area height
277; AL: Area width
278; DS: BDA segment (zero)
279; ES:DI: Ptr to cursor location in video RAM
280; Returns:
281; DI: Updated offset to video RAM
282; Corrupts registers:
283; AX, DX
284;--------------------------------------------------------------------
285ALIGN JUMP_ALIGN
286DisplayPrint_ClearAreaWithHeightInAHandWidthInAL:
287 push si
288 push cx
289 push bx
290
291 xchg bx, ax ; Area size to BX
292 call DisplayCursor_GetSoftwareCoordinatesToAX
293 xchg si, ax ; Software (Y,X) coordinates now in SI
294 xor cx, cx
295
296ALIGN JUMP_ALIGN
297.ClearRowLoop:
298 mov cl, bl ; Area width now in CX
299 mov al, ' ' ; Clear with space
300 call DisplayPrint_RepeatCharacterFromALwithCountInCX
301
302 xchg ax, si ; Coordinates to AX
303 inc ah ; Increment row
304 mov si, ax
305 call DisplayCursor_SetCoordinatesFromAX
306 dec bh ; Decrement rows left
307 jnz SHORT .ClearRowLoop
308
309 pop bx
310 pop cx
311 pop si
312 ret
313
314
315;--------------------------------------------------------------------
316; DisplayPrint_RepeatCharacterFromALwithCountInCX
317; Parameters:
318; AL: Character to display
319; CX: Repeat count
320; DS: BDA segment (zero)
321; ES:DI: Ptr to cursor location in video RAM
322; Returns:
323; DI: Updated offset to video RAM
324; Corrupts registers:
325; AX, DX
326;--------------------------------------------------------------------
327ALIGN JUMP_ALIGN
328DisplayPrint_RepeatCharacterFromALwithCountInCX:
329 push ax
330 call DisplayPrint_CharacterFromAL
331 pop ax
332 loop DisplayPrint_RepeatCharacterFromALwithCountInCX
333 ret
334
335
336;--------------------------------------------------------------------
337; DisplayPrint_CharacterFromAL
338; Parameters:
339; AL: Character to display
340; DS: BDA segment (zero)
341; ES:DI: Ptr to cursor location in video RAM
342; Returns:
343; DI: Updated offset to video RAM
344; Corrupts registers:
345; AX, DX
346;--------------------------------------------------------------------
347ALIGN JUMP_ALIGN
348DisplayPrint_CharacterFromAL:
349 mov ah, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
350 jmp [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut]
Note: See TracBrowser for help on using the repository browser.