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

Last change on this file since 332 was 323, checked in by aitotat@…, 12 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
RevLine 
[41]1; Project name : Assembly Library
2; Description : Functions for display output.
3
4; Section containing code
5SECTION .text
6
[223]7
[41]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.
[48]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.
[162]28;
[41]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
[186]64
[41]65 ret
66
67
68;--------------------------------------------------------------------
[44]69; DisplayPrint_SignedWordFromAXWithBaseInBX
[41]70; Parameters:
71; AX: Word to display
[44]72; BX: Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
[41]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;--------------------------------------------------------------------
[134]80%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[41]81ALIGN JUMP_ALIGN
[44]82DisplayPrint_SignedWordFromAXWithBaseInBX:
83 test ax, ax
84 jns SHORT DisplayPrint_WordFromAXWithBaseInBX
[41]85
86 push ax
87 mov al, '-'
88 call DisplayPrint_CharacterFromAL
89 pop ax
90 neg ax
[44]91 ; Fall to DisplayPrint_WordFromAXWithBaseInBX
[134]92%endif
[41]93
[323]94
95%ifndef MODULE_STRINGS_COMPRESSED
[41]96;--------------------------------------------------------------------
[323]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;--------------------------------------------------------------------
[41]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
[323]137;--------------------------------------------------------------------
[41]138ALIGN JUMP_ALIGN
139DisplayPrint_WordFromAXWithBaseInBX:
140 push cx
[44]141 push bx
[41]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
[44]152
[323]153PrintAllPushedDigits:
154 mov bx, g_rgcDigitToCharacter
[41]155ALIGN JUMP_ALIGN
[44]156.PrintNextDigit:
157 pop ax ; Pop digit
[223]158 cs xlatb
[41]159 call DisplayPrint_CharacterFromAL
[44]160 loop .PrintNextDigit
[41]161
[44]162 pop bx
[41]163 pop cx
164 ret
[323]165g_rgcDigitToCharacter: db "0123456789ABCDEF"
[186]166
167%endif ; MODULE_STRINGS_COMPRESSED
[41]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;--------------------------------------------------------------------
[223]182%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[41]183ALIGN JUMP_ALIGN
184DisplayPrint_CharacterBufferFromBXSIwithLengthInCX:
[44]185 jcxz .NothingToPrintSinceZeroLength
186 push si
[41]187 push cx
188
189ALIGN JUMP_ALIGN
[44]190.PrintNextCharacter:
191 mov ds, bx
192 lodsb
193 LOAD_BDA_SEGMENT_TO ds, dx
194 call DisplayPrint_CharacterFromAL
195 loop .PrintNextCharacter
196
[41]197 pop cx
[44]198 pop si
199.NothingToPrintSinceZeroLength:
[41]200 ret
[194]201%endif
[41]202
[186]203
[41]204;--------------------------------------------------------------------
[67]205; DisplayPrint_ClearScreenWithCharInALandAttributeInAH
[41]206; Parameters:
[67]207; AL: Character to clear with
208; AH: Attribute to clear with
[41]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
[67]217DisplayPrint_ClearScreenWithCharInALandAttributeInAH:
[41]218 push di
[67]219 push cx
220
221 xchg cx, ax
[41]222 xor ax, ax
[67]223 call DisplayCursor_SetCoordinatesFromAX ; Updates DI
[41]224 call DisplayPage_GetColumnsToALandRowsToAH
[67]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
[41]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:
[42]243; DI: Updated offset to video RAM
[41]244; Corrupts registers:
245; AX, DX
246;--------------------------------------------------------------------
[134]247%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[41]248ALIGN JUMP_ALIGN
249DisplayPrint_ClearAreaWithHeightInAHandWidthInAL:
[42]250 push si
[41]251 push cx
252 push bx
253
[42]254 xchg bx, ax ; Area size to BX
[41]255 call DisplayCursor_GetSoftwareCoordinatesToAX
[42]256 xchg si, ax ; Software (Y,X) coordinates now in SI
257 xor cx, cx
[41]258
259ALIGN JUMP_ALIGN
[42]260.ClearRowLoop:
261 mov cl, bl ; Area width now in CX
[44]262 mov al, SCREEN_BACKGROUND_CHARACTER
[42]263 call DisplayPrint_RepeatCharacterFromALwithCountInCX
[41]264
[42]265 xchg ax, si ; Coordinates to AX
266 inc ah ; Increment row
267 mov si, ax
[41]268 call DisplayCursor_SetCoordinatesFromAX
[42]269 dec bh ; Decrement rows left
270 jnz SHORT .ClearRowLoop
[41]271
272 pop bx
273 pop cx
[42]274 pop si
[41]275 ret
[134]276%endif
[42]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:
[181]289; DX
[42]290;--------------------------------------------------------------------
291ALIGN JUMP_ALIGN
292DisplayPrint_RepeatCharacterFromALwithCountInCX:
[44]293 jcxz .NothingToRepeat
294 push cx
295
296ALIGN JUMP_ALIGN
297.RepeatCharacter:
[42]298 push ax
299 call DisplayPrint_CharacterFromAL
300 pop ax
[44]301 loop .RepeatCharacter
302
303 pop cx
304.NothingToRepeat:
[42]305 ret
[223]306
[186]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.
[223]323;;;
[186]324ALIGN JUMP_ALIGN
325DisplayPrint_NullTerminatedStringFromCSSI:
326 push bx
327 mov bx, cs
328 call DisplayPrint_NullTerminatedStringFromBXSI
329 pop bx
330 ret
331%endif
[42]332
333
[186]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)
[223]337;;;
[186]338
[42]339;--------------------------------------------------------------------
[44]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;--------------------------------------------------------------------
[186]349%ifdef MODULE_STRINGS_COMPRESSED
[44]350ALIGN JUMP_ALIGN
[186]351DisplayPrint_Newline_FormatAdjustBP:
[223]352 inc bp ; we didn't need a parameter after all, readjust BP
[186]353 inc bp
[194]354 ; fall through to DisplayPrint_Newline
[186]355%endif
356
[223]357ALIGN JUMP_ALIGN
[44]358DisplayPrint_Newline:
[52]359 mov al, LF
360 call DisplayPrint_CharacterFromAL
[44]361 mov al, CR
362 ; Fall to DisplayPrint_CharacterFromAL
363
364;--------------------------------------------------------------------
[42]365; DisplayPrint_CharacterFromAL
366; Parameters:
367; AL: Character to display
[186]368; Zero value is ignored (no characer is printed)
[42]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:
[186]378 test al,al
379 jz DisplayPrint_Ret
[241]380
[42]381 mov ah, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
382 jmp [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut]
[186]383
[223]384
[186]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
[223]416
417DisplayPrint_Ret: ; random ret to jump to
[186]418 ret
419
Note: See TracBrowser for help on using the repository browser.