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

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

Initial string compression checkin. All changes are under MODULE_STRINGS_COMPRESSED, and this can still be turned off. With this checkin, the serial and ebios code can both be turned on at the same time and still we remain below the 8K boundary (barely). I still need to chekin StringsCompress.pl after some more code cleanup. The output, in StringsCompressed.asm is checked in here, and should continue be to checkin when Strings.asm is changed, for those who do not have/want to run the Perl script to recreate it.

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