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

Last change on this file since 261 was 241, checked in by gregli@…, 13 years ago

Space optimizations in the Boot Menu and BootInfo routines, taking advantage of nested %s. Optimization in the init of RamVars to avoid writing the signature twice. Preparing for addition of serial floppy support, starting to break the assumption that our drives are always 80h or higher.

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