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

Last change on this file since 254 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
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
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;--------------------------------------------------------------------
[223]106
[186]107%ifndef MODULE_STRINGS_COMPRESSED
[223]108
[41]109ALIGN JUMP_ALIGN
110DisplayPrint_WordFromAXWithBaseInBX:
111 push cx
[44]112 push bx
[41]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
[44]123
124 mov bx, .rgcDigitToCharacter
[41]125ALIGN JUMP_ALIGN
[44]126.PrintNextDigit:
127 pop ax ; Pop digit
[223]128 cs xlatb
[41]129 call DisplayPrint_CharacterFromAL
[44]130 loop .PrintNextDigit
[41]131
[44]132 pop bx
[41]133 pop cx
134 ret
135.rgcDigitToCharacter: db "0123456789ABCDEF"
[186]136
137%endif ; MODULE_STRINGS_COMPRESSED
[41]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;--------------------------------------------------------------------
[223]152%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[41]153ALIGN JUMP_ALIGN
154DisplayPrint_CharacterBufferFromBXSIwithLengthInCX:
[44]155 jcxz .NothingToPrintSinceZeroLength
156 push si
[41]157 push cx
158
159ALIGN JUMP_ALIGN
[44]160.PrintNextCharacter:
161 mov ds, bx
162 lodsb
163 LOAD_BDA_SEGMENT_TO ds, dx
164 call DisplayPrint_CharacterFromAL
165 loop .PrintNextCharacter
166
[41]167 pop cx
[44]168 pop si
169.NothingToPrintSinceZeroLength:
[41]170 ret
[194]171%endif
[41]172
[186]173
[41]174;--------------------------------------------------------------------
[67]175; DisplayPrint_ClearScreenWithCharInALandAttributeInAH
[41]176; Parameters:
[67]177; AL: Character to clear with
178; AH: Attribute to clear with
[41]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
[67]187DisplayPrint_ClearScreenWithCharInALandAttributeInAH:
[41]188 push di
[67]189 push cx
190
191 xchg cx, ax
[41]192 xor ax, ax
[67]193 call DisplayCursor_SetCoordinatesFromAX ; Updates DI
[41]194 call DisplayPage_GetColumnsToALandRowsToAH
[67]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
[41]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:
[42]213; DI: Updated offset to video RAM
[41]214; Corrupts registers:
215; AX, DX
216;--------------------------------------------------------------------
[134]217%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[41]218ALIGN JUMP_ALIGN
219DisplayPrint_ClearAreaWithHeightInAHandWidthInAL:
[42]220 push si
[41]221 push cx
222 push bx
223
[42]224 xchg bx, ax ; Area size to BX
[41]225 call DisplayCursor_GetSoftwareCoordinatesToAX
[42]226 xchg si, ax ; Software (Y,X) coordinates now in SI
227 xor cx, cx
[41]228
229ALIGN JUMP_ALIGN
[42]230.ClearRowLoop:
231 mov cl, bl ; Area width now in CX
[44]232 mov al, SCREEN_BACKGROUND_CHARACTER
[42]233 call DisplayPrint_RepeatCharacterFromALwithCountInCX
[41]234
[42]235 xchg ax, si ; Coordinates to AX
236 inc ah ; Increment row
237 mov si, ax
[41]238 call DisplayCursor_SetCoordinatesFromAX
[42]239 dec bh ; Decrement rows left
240 jnz SHORT .ClearRowLoop
[41]241
242 pop bx
243 pop cx
[42]244 pop si
[41]245 ret
[134]246%endif
[42]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:
[181]259; DX
[42]260;--------------------------------------------------------------------
261ALIGN JUMP_ALIGN
262DisplayPrint_RepeatCharacterFromALwithCountInCX:
[44]263 jcxz .NothingToRepeat
264 push cx
265
266ALIGN JUMP_ALIGN
267.RepeatCharacter:
[42]268 push ax
269 call DisplayPrint_CharacterFromAL
270 pop ax
[44]271 loop .RepeatCharacter
272
273 pop cx
274.NothingToRepeat:
[42]275 ret
[223]276
[186]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.
[223]293;;;
[186]294ALIGN JUMP_ALIGN
295DisplayPrint_NullTerminatedStringFromCSSI:
296 push bx
297 mov bx, cs
298 call DisplayPrint_NullTerminatedStringFromBXSI
299 pop bx
300 ret
301%endif
[42]302
303
[186]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)
[223]307;;;
[186]308
[42]309;--------------------------------------------------------------------
[44]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;--------------------------------------------------------------------
[186]319%ifdef MODULE_STRINGS_COMPRESSED
[44]320ALIGN JUMP_ALIGN
[186]321DisplayPrint_Newline_FormatAdjustBP:
[223]322 inc bp ; we didn't need a parameter after all, readjust BP
[186]323 inc bp
[194]324 ; fall through to DisplayPrint_Newline
[186]325%endif
326
[223]327ALIGN JUMP_ALIGN
[44]328DisplayPrint_Newline:
[52]329 mov al, LF
330 call DisplayPrint_CharacterFromAL
[44]331 mov al, CR
332 ; Fall to DisplayPrint_CharacterFromAL
333
334;--------------------------------------------------------------------
[42]335; DisplayPrint_CharacterFromAL
336; Parameters:
337; AL: Character to display
[186]338; Zero value is ignored (no characer is printed)
[42]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:
[186]348 test al,al
349 jz DisplayPrint_Ret
[241]350
[42]351 mov ah, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
352 jmp [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut]
[186]353
[223]354
[186]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
[223]386
387DisplayPrint_Ret: ; random ret to jump to
[186]388 ret
389
Note: See TracBrowser for help on using the repository browser.