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
RevLine 
[41]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.
[48]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.
[41]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;--------------------------------------------------------------------
[67]220; DisplayPrint_ClearScreenWithCharInALandAttributeInAH
[41]221; Parameters:
[67]222; AL: Character to clear with
223; AH: Attribute to clear with
[41]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
[67]232DisplayPrint_ClearScreenWithCharInALandAttributeInAH:
[41]233 push di
[67]234 push cx
235
236 xchg cx, ax
[41]237 xor ax, ax
[67]238 call DisplayCursor_SetCoordinatesFromAX ; Updates DI
[41]239 call DisplayPage_GetColumnsToALandRowsToAH
[67]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
[41]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:
[42]258; DI: Updated offset to video RAM
[41]259; Corrupts registers:
260; AX, DX
261;--------------------------------------------------------------------
262ALIGN JUMP_ALIGN
263DisplayPrint_ClearAreaWithHeightInAHandWidthInAL:
[42]264 push si
[41]265 push cx
266 push bx
267
[42]268 xchg bx, ax ; Area size to BX
[41]269 call DisplayCursor_GetSoftwareCoordinatesToAX
[42]270 xchg si, ax ; Software (Y,X) coordinates now in SI
271 xor cx, cx
[41]272
273ALIGN JUMP_ALIGN
[42]274.ClearRowLoop:
275 mov cl, bl ; Area width now in CX
[44]276 mov al, SCREEN_BACKGROUND_CHARACTER
[42]277 call DisplayPrint_RepeatCharacterFromALwithCountInCX
[41]278
[42]279 xchg ax, si ; Coordinates to AX
280 inc ah ; Increment row
281 mov si, ax
[41]282 call DisplayCursor_SetCoordinatesFromAX
[42]283 dec bh ; Decrement rows left
284 jnz SHORT .ClearRowLoop
[41]285
286 pop bx
287 pop cx
[42]288 pop si
[41]289 ret
[42]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:
[44]306 jcxz .NothingToRepeat
307 push cx
308
309ALIGN JUMP_ALIGN
310.RepeatCharacter:
[42]311 push ax
312 call DisplayPrint_CharacterFromAL
313 pop ax
[44]314 loop .RepeatCharacter
315
316 pop cx
317.NothingToRepeat:
[42]318 ret
319
320
321;--------------------------------------------------------------------
[44]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:
[52]333 mov al, LF
334 call DisplayPrint_CharacterFromAL
[44]335 mov al, CR
336 ; Fall to DisplayPrint_CharacterFromAL
337
338;--------------------------------------------------------------------
[42]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.