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

Last change on this file since 334 was 323, checked in by aitotat@…, 13 years ago

Changes to Assembly Library:

  • Added Display Library function for printing QWORDs.
  • Added couple of function numbers to BiosFunctions.inc
File size: 11.4 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%ifndef MODULE_STRINGS_COMPRESSED
96;--------------------------------------------------------------------
97; DisplayPrint_QWordFromSSBPwithBaseInBX
98; Parameters:
99; SS:BP: QWord to display
100; BX: Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
101; DS: BDA segment (zero)
102; ES:DI: Ptr to cursor location in video RAM
103; Returns:
104; DI: Updated offset to video RAM
105; Corrupts registers:
106; AX, DX, [SS:BP]
107;--------------------------------------------------------------------
108ALIGN JUMP_ALIGN
109DisplayPrint_QWordFromSSBPwithBaseInBX:
110 push cx
111 push bx
112
113 mov cx, bx ; CX = Integer base
114 xor bx, bx ; BX = Character count
115ALIGN JUMP_ALIGN
116.DivideLoop:
117 call Math_DivQWatSSBPbyCX; Divide by base
118 push dx ; Push remainder
119 inc bx ; Increment character count
120 cmp WORD [bp], BYTE 0 ; All divided?
121 jne SHORT .DivideLoop ; If not, loop
122 mov cx, bx ; Character count to CX
123 jmp SHORT PrintAllPushedDigits
124
125
126;--------------------------------------------------------------------
127; DisplayPrint_WordFromAXWithBaseInBX
128; Parameters:
129; AX: Word to display
130; BX: Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
131; DS: BDA segment (zero)
132; ES:DI: Ptr to cursor location in video RAM
133; Returns:
134; DI: Updated offset to video RAM
135; Corrupts registers:
136; AX, DX
137;--------------------------------------------------------------------
138ALIGN JUMP_ALIGN
139DisplayPrint_WordFromAXWithBaseInBX:
140 push cx
141 push bx
142
143 xor cx, cx
144ALIGN JUMP_ALIGN
145.DivideLoop:
146 xor dx, dx ; DX:AX now holds the integer
147 div bx ; Divide DX:AX by base
148 push dx ; Push remainder
149 inc cx ; Increment character count
150 test ax, ax ; All divided?
151 jnz SHORT .DivideLoop ; If not, loop
152
153PrintAllPushedDigits:
154 mov bx, g_rgcDigitToCharacter
155ALIGN JUMP_ALIGN
156.PrintNextDigit:
157 pop ax ; Pop digit
158 cs xlatb
159 call DisplayPrint_CharacterFromAL
160 loop .PrintNextDigit
161
162 pop bx
163 pop cx
164 ret
165g_rgcDigitToCharacter: db "0123456789ABCDEF"
166
167%endif ; MODULE_STRINGS_COMPRESSED
168
169
170;--------------------------------------------------------------------
171; DisplayPrint_CharacterBufferFromBXSIwithLengthInCX
172; Parameters:
173; CX: Buffer length (characters)
174; BX:SI: Ptr to NULL terminated string
175; DS: BDA segment (zero)
176; ES:DI: Ptr to cursor location in video RAM
177; Returns:
178; DI: Updated offset to video RAM
179; Corrupts registers:
180; AX, DX
181;--------------------------------------------------------------------
182%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
183ALIGN JUMP_ALIGN
184DisplayPrint_CharacterBufferFromBXSIwithLengthInCX:
185 jcxz .NothingToPrintSinceZeroLength
186 push si
187 push cx
188
189ALIGN JUMP_ALIGN
190.PrintNextCharacter:
191 mov ds, bx
192 lodsb
193 LOAD_BDA_SEGMENT_TO ds, dx
194 call DisplayPrint_CharacterFromAL
195 loop .PrintNextCharacter
196
197 pop cx
198 pop si
199.NothingToPrintSinceZeroLength:
200 ret
201%endif
202
203
204;--------------------------------------------------------------------
205; DisplayPrint_ClearScreenWithCharInALandAttributeInAH
206; Parameters:
207; AL: Character to clear with
208; AH: Attribute to clear with
209; DS: BDA segment (zero)
210; ES:DI: Ptr to cursor location in video RAM
211; Returns:
212; Nothing
213; Corrupts registers:
214; AX, DX
215;--------------------------------------------------------------------
216ALIGN JUMP_ALIGN
217DisplayPrint_ClearScreenWithCharInALandAttributeInAH:
218 push di
219 push cx
220
221 xchg cx, ax
222 xor ax, ax
223 call DisplayCursor_SetCoordinatesFromAX ; Updates DI
224 call DisplayPage_GetColumnsToALandRowsToAH
225 mul ah ; AX = AL*AH = Characters on screen
226 xchg cx, ax ; AX = Char+Attr, CX = WORDs to store
227 rep stosw
228
229 pop cx
230 pop di
231 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], di
232 ret
233
234
235;--------------------------------------------------------------------
236; DisplayPrint_ClearAreaWithHeightInAHandWidthInAL
237; Parameters:
238; AH: Area height
239; AL: Area width
240; DS: BDA segment (zero)
241; ES:DI: Ptr to cursor location in video RAM
242; Returns:
243; DI: Updated offset to video RAM
244; Corrupts registers:
245; AX, DX
246;--------------------------------------------------------------------
247%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
248ALIGN JUMP_ALIGN
249DisplayPrint_ClearAreaWithHeightInAHandWidthInAL:
250 push si
251 push cx
252 push bx
253
254 xchg bx, ax ; Area size to BX
255 call DisplayCursor_GetSoftwareCoordinatesToAX
256 xchg si, ax ; Software (Y,X) coordinates now in SI
257 xor cx, cx
258
259ALIGN JUMP_ALIGN
260.ClearRowLoop:
261 mov cl, bl ; Area width now in CX
262 mov al, SCREEN_BACKGROUND_CHARACTER
263 call DisplayPrint_RepeatCharacterFromALwithCountInCX
264
265 xchg ax, si ; Coordinates to AX
266 inc ah ; Increment row
267 mov si, ax
268 call DisplayCursor_SetCoordinatesFromAX
269 dec bh ; Decrement rows left
270 jnz SHORT .ClearRowLoop
271
272 pop bx
273 pop cx
274 pop si
275 ret
276%endif
277
278
279;--------------------------------------------------------------------
280; DisplayPrint_RepeatCharacterFromALwithCountInCX
281; Parameters:
282; AL: Character to display
283; CX: Repeat count
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; DX
290;--------------------------------------------------------------------
291ALIGN JUMP_ALIGN
292DisplayPrint_RepeatCharacterFromALwithCountInCX:
293 jcxz .NothingToRepeat
294 push cx
295
296ALIGN JUMP_ALIGN
297.RepeatCharacter:
298 push ax
299 call DisplayPrint_CharacterFromAL
300 pop ax
301 loop .RepeatCharacter
302
303 pop cx
304.NothingToRepeat:
305 ret
306
307
308;--------------------------------------------------------------------
309; DisplayPrint_NullTerminatedStringFromCSSI
310; Parameters:
311; CS:SI: Ptr to NULL terminated string
312; DS: BDA segment (zero)
313; ES:DI: Ptr to cursor location in video RAM
314; Returns:
315; DI: Updated offset to video RAM
316; Corrupts registers:
317; AX, DX
318;--------------------------------------------------------------------
319%ifndef MODULE_STRINGS_COMPRESSED
320;;;
321;;; Take care when using this routine with compressed strings (which is why it is disabled).
322;;; All strings in CSSI should go through the DisplayFormatCompressed code to be decoded.
323;;;
324ALIGN JUMP_ALIGN
325DisplayPrint_NullTerminatedStringFromCSSI:
326 push bx
327 mov bx, cs
328 call DisplayPrint_NullTerminatedStringFromBXSI
329 pop bx
330 ret
331%endif
332
333
334;;;
335;;; Note that the following routines need to be at the bottom of this file
336;;; to accomodate short jumps from the next file (DisplayFormat/DisplayFormatCompressed)
337;;;
338
339;--------------------------------------------------------------------
340; DisplayPrint_Newline
341; Parameters:
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;--------------------------------------------------------------------
349%ifdef MODULE_STRINGS_COMPRESSED
350ALIGN JUMP_ALIGN
351DisplayPrint_Newline_FormatAdjustBP:
352 inc bp ; we didn't need a parameter after all, readjust BP
353 inc bp
354 ; fall through to DisplayPrint_Newline
355%endif
356
357ALIGN JUMP_ALIGN
358DisplayPrint_Newline:
359 mov al, LF
360 call DisplayPrint_CharacterFromAL
361 mov al, CR
362 ; Fall to DisplayPrint_CharacterFromAL
363
364;--------------------------------------------------------------------
365; DisplayPrint_CharacterFromAL
366; Parameters:
367; AL: Character to display
368; Zero value is ignored (no characer is printed)
369; DS: BDA segment (zero)
370; ES:DI: Ptr to cursor location in video RAM
371; Returns:
372; DI: Updated offset to video RAM
373; Corrupts registers:
374; AX, DX
375;--------------------------------------------------------------------
376ALIGN JUMP_ALIGN
377DisplayPrint_CharacterFromAL:
378 test al,al
379 jz DisplayPrint_Ret
380
381 mov ah, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
382 jmp [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut]
383
384
385;--------------------------------------------------------------------
386; DisplayPrint_NullTerminatedStringFromBXSI
387; Parameters:
388; DS: BDA segment (zero)
389; BX:SI: Ptr to NULL terminated string
390; ES:DI: Ptr to cursor location in video RAM
391; Returns:
392; DI: Updated offset to video RAM
393; Corrupts registers:
394; AX, DX
395;--------------------------------------------------------------------
396ALIGN JUMP_ALIGN
397DisplayPrint_NullTerminatedStringFromBXSI:
398 push si
399 push cx
400
401 xor cx, cx
402ALIGN JUMP_ALIGN
403.PrintNextCharacter:
404 mov ds, bx ; String segment to DS
405 lodsb
406 mov ds, cx ; BDA segment to DS
407 test al, al ; NULL?
408 jz SHORT .EndOfString
409 call DisplayPrint_CharacterFromAL
410 jmp SHORT .PrintNextCharacter
411
412ALIGN JUMP_ALIGN
413.EndOfString:
414 pop cx
415 pop si
416
417DisplayPrint_Ret: ; random ret to jump to
418 ret
419
Note: See TracBrowser for help on using the repository browser.