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

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

Changes to Assembly Library:

  • Some minor size optimizations to Display Library.
File size: 9.5 KB
Line 
1; Project name : Assembly Library
2; Description : Functions for display output.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Supports following formatting types:
9; %a Specifies attribute for next character
10; %A Specifies attribute for remaining string (or until next %A)
11; %d Prints signed 16-bit decimal integer
12; %u Prints unsigned 16-bit decimal integer
13; %x Prints 16-bit hexadecimal integer
14; %s Prints string (from CS segment)
15; %S Prints string (far pointer)
16; %c Prints character
17; %t Prints character number of times (character needs to be pushed first, then repeat times)
18; %% Prints '%' character (no parameter pushed)
19;
20; Any placeholder can be set to minimum length by specifying
21; minimum number of characters. For example %8d would append spaces
22; after integer so that at least 8 characters would be printed.
23;
24; When placing '-' after number, then spaces will be used for prepending.
25; For example %8-d would prepend integer with spaces so that at least
26; 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_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;--------------------------------------------------------------------
78ALIGN JUMP_ALIGN
79DisplayPrint_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;--------------------------------------------------------------------
102ALIGN JUMP_ALIGN
103DisplayPrint_WordFromAXWithBaseInBX:
104 push cx
105 push bx
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
116
117 mov bx, .rgcDigitToCharacter
118ALIGN 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;--------------------------------------------------------------------
144ALIGN JUMP_ALIGN
145DisplayPrint_CharacterBufferFromBXSIwithLengthInCX:
146 jcxz .NothingToPrintSinceZeroLength
147 push si
148 push cx
149
150ALIGN 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;--------------------------------------------------------------------
176ALIGN JUMP_ALIGN
177DisplayPrint_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;--------------------------------------------------------------------
196ALIGN JUMP_ALIGN
197DisplayPrint_NullTerminatedStringFromBXSI:
198 push si
199 push cx
200
201 xor cx, cx
202ALIGN 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
212ALIGN JUMP_ALIGN
213.EndOfString:
214 pop cx
215 pop si
216 ret
217
218
219;--------------------------------------------------------------------
220; DisplayPrint_ClearScreenWithCharInALandAttributeInAH
221; Parameters:
222; AL: Character to clear with
223; AH: Attribute to clear with
224; DS: BDA segment (zero)
225; ES:DI: Ptr to cursor location in video RAM
226; Returns:
227; Nothing
228; Corrupts registers:
229; AX, DX
230;--------------------------------------------------------------------
231ALIGN JUMP_ALIGN
232DisplayPrint_ClearScreenWithCharInALandAttributeInAH:
233 push di
234 push cx
235
236 xchg cx, ax
237 xor ax, ax
238 call DisplayCursor_SetCoordinatesFromAX ; Updates DI
239 call DisplayPage_GetColumnsToALandRowsToAH
240 mul ah ; AX = AL*AH = Characters on screen
241 xchg cx, ax ; AX = Char+Attr, CX = WORDs to store
242 rep stosw
243
244 pop cx
245 pop di
246 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], di
247 ret
248
249
250;--------------------------------------------------------------------
251; DisplayPrint_ClearAreaWithHeightInAHandWidthInAL
252; Parameters:
253; AH: Area height
254; AL: Area width
255; DS: BDA segment (zero)
256; ES:DI: Ptr to cursor location in video RAM
257; Returns:
258; DI: Updated offset to video RAM
259; Corrupts registers:
260; AX, DX
261;--------------------------------------------------------------------
262ALIGN JUMP_ALIGN
263DisplayPrint_ClearAreaWithHeightInAHandWidthInAL:
264 push si
265 push cx
266 push bx
267
268 xchg bx, ax ; Area size to BX
269 call DisplayCursor_GetSoftwareCoordinatesToAX
270 xchg si, ax ; Software (Y,X) coordinates now in SI
271 xor cx, cx
272
273ALIGN JUMP_ALIGN
274.ClearRowLoop:
275 mov cl, bl ; Area width now in CX
276 mov al, SCREEN_BACKGROUND_CHARACTER
277 call DisplayPrint_RepeatCharacterFromALwithCountInCX
278
279 xchg ax, si ; Coordinates to AX
280 inc ah ; Increment row
281 mov si, ax
282 call DisplayCursor_SetCoordinatesFromAX
283 dec bh ; Decrement rows left
284 jnz SHORT .ClearRowLoop
285
286 pop bx
287 pop cx
288 pop si
289 ret
290
291
292;--------------------------------------------------------------------
293; DisplayPrint_RepeatCharacterFromALwithCountInCX
294; Parameters:
295; AL: Character to display
296; CX: Repeat count
297; DS: BDA segment (zero)
298; ES:DI: Ptr to cursor location in video RAM
299; Returns:
300; DI: Updated offset to video RAM
301; Corrupts registers:
302; AX, DX
303;--------------------------------------------------------------------
304ALIGN JUMP_ALIGN
305DisplayPrint_RepeatCharacterFromALwithCountInCX:
306 jcxz .NothingToRepeat
307 push cx
308
309ALIGN JUMP_ALIGN
310.RepeatCharacter:
311 push ax
312 call DisplayPrint_CharacterFromAL
313 pop ax
314 loop .RepeatCharacter
315
316 pop cx
317.NothingToRepeat:
318 ret
319
320
321;--------------------------------------------------------------------
322; DisplayPrint_Newline
323; Parameters:
324; DS: BDA segment (zero)
325; ES:DI: Ptr to cursor location in video RAM
326; Returns:
327; DI: Updated offset to video RAM
328; Corrupts registers:
329; AX, DX
330;--------------------------------------------------------------------
331ALIGN JUMP_ALIGN
332DisplayPrint_Newline:
333 mov al, LF
334 call DisplayPrint_CharacterFromAL
335 mov al, CR
336 ; Fall to DisplayPrint_CharacterFromAL
337
338;--------------------------------------------------------------------
339; DisplayPrint_CharacterFromAL
340; Parameters:
341; AL: Character to display
342; DS: BDA segment (zero)
343; ES:DI: Ptr to cursor location in video RAM
344; Returns:
345; DI: Updated offset to video RAM
346; Corrupts registers:
347; AX, DX
348;--------------------------------------------------------------------
349ALIGN JUMP_ALIGN
350DisplayPrint_CharacterFromAL:
351 mov ah, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
352 jmp [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut]
Note: See TracBrowser for help on using the repository browser.