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

Last change on this file since 52 was 52, checked in by aitotat, 14 years ago

Changes to Assembly Library:
Completely rewritten line splitting (slower but no need to modify string).
Some changes to string processing functions.
Saved few bytes from CGA detection.

File size: 9.4 KB
Line 
1; File name     :   Display.asm
2; Project name  :   Assembly Library
3; Created date  :   26.6.2010
4; Last update   :   11.10.2010
5; Author        :   Tomi Tilli
6; Description   :   Functions for display output.
7
8; Section containing code
9SECTION .text
10
11;--------------------------------------------------------------------
12; Supports following formatting types:
13;   %a      Specifies attribute for next character
14;   %A      Specifies attribute for remaining string (or until next %A)
15;   %d      Prints signed 16-bit decimal integer
16;   %u      Prints unsigned 16-bit decimal integer
17;   %x      Prints 16-bit hexadecimal integer
18;   %s      Prints string (from CS segment)
19;   %S      Prints string (far pointer)
20;   %c      Prints character
21;   %t      Prints character number of times (character needs to be pushed first, then repeat times)
22;   %%      Prints '%' character (no parameter pushed)
23;
24;   Any placeholder can be set to minimum length by specifying
25;   minimum number of characters. For example %8d would append spaces
26;   after integer so that at least 8 characters would be printed.
27;
28;   When placing '-' after number, then spaces will be used for prepending.
29;   For example %8-d would prepend integer with spaces so that at least
30;   8 characters would be printed.
31; 
32; DisplayPrint_FormattedNullTerminatedStringFromCSSI
33;   Parameters:
34;       BP:     SP before pushing parameters
35;       DS:     BDA segment (zero)
36;       CS:SI:  Pointer to string to format
37;       ES:DI:  Ptr to cursor location in video RAM
38;       Stack:  Parameters for formatting placeholders.
39;               Parameter for first placeholder must be pushed first.
40;               Low word must pushed first for placeholders requiring
41;               32-bit parameters (two words).
42;   Returns:
43;       DI:     Updated offset to video RAM
44;   Corrupts registers:
45;       AX, DX
46;--------------------------------------------------------------------
47ALIGN JUMP_ALIGN
48DisplayPrint_FormattedNullTerminatedStringFromCSSI:
49    push    bp
50    push    si
51    push    cx
52    push    bx
53    push    WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
54
55    dec     bp                  ; Point BP to...
56    dec     bp                  ; ...first stack parameter
57    call    DisplayFormat_ParseCharacters
58
59    ; Pop original character attribute
60    pop     ax
61    mov     [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al
62
63    pop     bx
64    pop     cx
65    pop     si
66    pop     bp
67    ret
68
69
70;--------------------------------------------------------------------
71; DisplayPrint_SignedWordFromAXWithBaseInBX
72;   Parameters:
73;       AX:     Word to display
74;       BX:     Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
75;       DS:     BDA segment (zero)
76;       ES:DI:  Ptr to cursor location in video RAM
77;   Returns:
78;       DI:     Updated offset to video RAM
79;   Corrupts registers:
80;       AX, DX
81;--------------------------------------------------------------------
82ALIGN JUMP_ALIGN
83DisplayPrint_SignedWordFromAXWithBaseInBX:
84    test    ax, ax
85    jns     SHORT DisplayPrint_WordFromAXWithBaseInBX
86
87    push    ax
88    mov     al, '-'
89    call    DisplayPrint_CharacterFromAL
90    pop     ax
91    neg     ax
92    ; Fall to DisplayPrint_WordFromAXWithBaseInBX
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;--------------------------------------------------------------------
106ALIGN JUMP_ALIGN
107DisplayPrint_WordFromAXWithBaseInBX:
108    push    cx
109    push    bx
110
111    xor     cx, cx
112ALIGN JUMP_ALIGN
113.DivideLoop:
114    xor     dx, dx              ; DX:AX now holds the integer
115    div     bx                  ; Divide DX:AX by base
116    push    dx                  ; Push remainder
117    inc     cx                  ; Increment character count
118    test    ax, ax              ; All divided?
119    jnz     SHORT .DivideLoop   ;  If not, loop
120
121    mov     bx, .rgcDigitToCharacter
122ALIGN JUMP_ALIGN
123.PrintNextDigit:
124    pop     ax                  ; Pop digit
125    eSEG    cs
126    xlatb
127    call    DisplayPrint_CharacterFromAL
128    loop    .PrintNextDigit
129
130    pop     bx
131    pop     cx
132    ret
133.rgcDigitToCharacter:   db  "0123456789ABCDEF"
134
135
136;--------------------------------------------------------------------
137; DisplayPrint_CharacterBufferFromBXSIwithLengthInCX
138;   Parameters:
139;       CX:     Buffer length (characters)
140;       BX:SI:  Ptr to NULL terminated string
141;       DS:     BDA segment (zero)
142;       ES:DI:  Ptr to cursor location in video RAM
143;   Returns:
144;       DI:     Updated offset to video RAM
145;   Corrupts registers:
146;       AX, DX
147;--------------------------------------------------------------------
148ALIGN JUMP_ALIGN
149DisplayPrint_CharacterBufferFromBXSIwithLengthInCX:
150    jcxz    .NothingToPrintSinceZeroLength
151    push    si
152    push    cx
153
154ALIGN JUMP_ALIGN
155.PrintNextCharacter:
156    mov     ds, bx
157    lodsb
158    LOAD_BDA_SEGMENT_TO ds, dx
159    call    DisplayPrint_CharacterFromAL
160    loop    .PrintNextCharacter
161
162    LOAD_BDA_SEGMENT_TO ds, dx
163    pop     cx
164    pop     si
165.NothingToPrintSinceZeroLength:
166    ret
167
168
169;--------------------------------------------------------------------
170; DisplayPrint_NullTerminatedStringFromCSSI
171;   Parameters:
172;       CS:SI:  Ptr to NULL terminated string
173;       DS:     BDA segment (zero)
174;       ES:DI:  Ptr to cursor location in video RAM
175;   Returns:
176;       DI:     Updated offset to video RAM
177;   Corrupts registers:
178;       AX, DX
179;--------------------------------------------------------------------
180ALIGN JUMP_ALIGN
181DisplayPrint_NullTerminatedStringFromCSSI:
182    push    bx
183    mov     bx, cs
184    call    DisplayPrint_NullTerminatedStringFromBXSI
185    pop     bx
186    ret
187
188
189;--------------------------------------------------------------------
190; DisplayPrint_NullTerminatedStringFromBXSI
191;   Parameters:
192;       DS:     BDA segment (zero)
193;       BX:SI:  Ptr to NULL terminated string
194;       ES:DI:  Ptr to cursor location in video RAM
195;   Returns:
196;       DI:     Updated offset to video RAM
197;   Corrupts registers:
198;       AX, DX
199;--------------------------------------------------------------------
200ALIGN JUMP_ALIGN
201DisplayPrint_NullTerminatedStringFromBXSI:
202    push    si
203    push    cx
204
205    xor     cx, cx
206ALIGN JUMP_ALIGN
207.PrintNextCharacter:
208    mov     ds, bx              ; String segment to DS
209    lodsb
210    mov     ds, cx              ; BDA segment to DS
211    test    al, al              ; NULL?
212    jz      SHORT .EndOfString
213    call    DisplayPrint_CharacterFromAL
214    jmp     SHORT .PrintNextCharacter
215
216ALIGN JUMP_ALIGN
217.EndOfString:
218    pop     cx
219    pop     si
220    ret
221
222
223;--------------------------------------------------------------------
224; DisplayPrint_ClearScreen
225;   Parameters:
226;       DS:     BDA segment (zero)
227;       ES:DI:  Ptr to cursor location in video RAM
228;   Returns:
229;       Nothing
230;   Corrupts registers:
231;       AX, DX
232;--------------------------------------------------------------------
233ALIGN JUMP_ALIGN
234DisplayPrint_ClearScreen:
235    push    di
236    xor     ax, ax
237    call    DisplayCursor_SetCoordinatesFromAX
238    call    DisplayPage_GetColumnsToALandRowsToAH
239    call    DisplayPrint_ClearAreaWithHeightInAHandWidthInAL
240    pop     di
241    mov     [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], di
242    ret
243
244
245;--------------------------------------------------------------------
246; DisplayPrint_ClearAreaWithHeightInAHandWidthInAL
247;   Parameters:
248;       AH:     Area height
249;       AL:     Area width
250;       DS:     BDA segment (zero)
251;       ES:DI:  Ptr to cursor location in video RAM
252;   Returns:
253;       DI:     Updated offset to video RAM
254;   Corrupts registers:
255;       AX, DX
256;--------------------------------------------------------------------
257ALIGN JUMP_ALIGN
258DisplayPrint_ClearAreaWithHeightInAHandWidthInAL:
259    push    si
260    push    cx
261    push    bx
262
263    xchg    bx, ax                          ; Area size to BX
264    call    DisplayCursor_GetSoftwareCoordinatesToAX
265    xchg    si, ax                          ; Software (Y,X) coordinates now in SI
266    xor     cx, cx
267
268ALIGN JUMP_ALIGN
269.ClearRowLoop:
270    mov     cl, bl                          ; Area width now in CX
271    mov     al, SCREEN_BACKGROUND_CHARACTER
272    call    DisplayPrint_RepeatCharacterFromALwithCountInCX
273
274    xchg    ax, si                          ; Coordinates to AX
275    inc     ah                              ; Increment row
276    mov     si, ax
277    call    DisplayCursor_SetCoordinatesFromAX
278    dec     bh                              ; Decrement rows left
279    jnz     SHORT .ClearRowLoop
280
281    pop     bx
282    pop     cx
283    pop     si
284    ret
285
286
287;--------------------------------------------------------------------
288; DisplayPrint_RepeatCharacterFromALwithCountInCX
289;   Parameters:
290;       AL:     Character to display
291;       CX:     Repeat count
292;       DS:     BDA segment (zero)
293;       ES:DI:  Ptr to cursor location in video RAM
294;   Returns:
295;       DI:     Updated offset to video RAM
296;   Corrupts registers:
297;       AX, DX
298;--------------------------------------------------------------------
299ALIGN JUMP_ALIGN
300DisplayPrint_RepeatCharacterFromALwithCountInCX:
301    jcxz    .NothingToRepeat
302    push    cx
303
304ALIGN JUMP_ALIGN
305.RepeatCharacter:
306    push    ax
307    call    DisplayPrint_CharacterFromAL
308    pop     ax
309    loop    .RepeatCharacter
310
311    pop     cx
312.NothingToRepeat:
313    ret
314
315
316;--------------------------------------------------------------------
317; DisplayPrint_Newline
318;   Parameters:
319;       DS:     BDA segment (zero)
320;       ES:DI:  Ptr to cursor location in video RAM
321;   Returns:
322;       DI:     Updated offset to video RAM
323;   Corrupts registers:
324;       AX, DX
325;--------------------------------------------------------------------
326ALIGN JUMP_ALIGN
327DisplayPrint_Newline:
328    mov     al, LF
329    call    DisplayPrint_CharacterFromAL
330    mov     al, CR
331    ; Fall to DisplayPrint_CharacterFromAL
332
333;--------------------------------------------------------------------
334; DisplayPrint_CharacterFromAL
335;   Parameters:
336;       AL:     Character to display
337;       DS:     BDA segment (zero)
338;       ES:DI:  Ptr to cursor location in video RAM
339;   Returns:
340;       DI:     Updated offset to video RAM
341;   Corrupts registers:
342;       AX, DX
343;--------------------------------------------------------------------
344ALIGN JUMP_ALIGN
345DisplayPrint_CharacterFromAL:
346    mov     ah, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
347    jmp     [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut]
Note: See TracBrowser for help on using the repository browser.