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

Last change on this file since 162 was 162, checked in by krille_n_@…, 13 years ago

Changes to all parts of the project:

  • Size optimizations, mostly by excluding code from the BIOS.
  • Cleaned the source a bit, fixed spelling and grammar mistakes.
File size: 9.7 KB
Line 
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.
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.
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;--------------------------------------------------------------------
67; DisplayPrint_SignedWordFromAXWithBaseInBX
68;   Parameters:
69;       AX:     Word to display
70;       BX:     Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
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;--------------------------------------------------------------------
78%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
79ALIGN JUMP_ALIGN
80DisplayPrint_SignedWordFromAXWithBaseInBX:
81    test    ax, ax
82    jns     SHORT DisplayPrint_WordFromAXWithBaseInBX
83
84    push    ax
85    mov     al, '-'
86    call    DisplayPrint_CharacterFromAL
87    pop     ax
88    neg     ax
89    ; Fall to DisplayPrint_WordFromAXWithBaseInBX
90%endif
91
92;--------------------------------------------------------------------
93; DisplayPrint_WordFromAXWithBaseInBX
94;   Parameters:
95;       AX:     Word to display
96;       BX:     Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
97;       DS:     BDA segment (zero)
98;       ES:DI:  Ptr to cursor location in video RAM
99;   Returns:
100;       DI:     Updated offset to video RAM
101;   Corrupts registers:
102;       AX, DX
103;--------------------------------------------------------------------
104ALIGN JUMP_ALIGN
105DisplayPrint_WordFromAXWithBaseInBX:
106    push    cx
107    push    bx
108
109    xor     cx, cx
110ALIGN JUMP_ALIGN
111.DivideLoop:
112    xor     dx, dx              ; DX:AX now holds the integer
113    div     bx                  ; Divide DX:AX by base
114    push    dx                  ; Push remainder
115    inc     cx                  ; Increment character count
116    test    ax, ax              ; All divided?
117    jnz     SHORT .DivideLoop   ;  If not, loop
118
119    mov     bx, .rgcDigitToCharacter
120ALIGN JUMP_ALIGN
121.PrintNextDigit:
122    pop     ax                  ; Pop digit
123    eSEG    cs
124    xlatb
125    call    DisplayPrint_CharacterFromAL
126    loop    .PrintNextDigit
127
128    pop     bx
129    pop     cx
130    ret
131.rgcDigitToCharacter:   db  "0123456789ABCDEF"
132
133
134;--------------------------------------------------------------------
135; DisplayPrint_CharacterBufferFromBXSIwithLengthInCX
136;   Parameters:
137;       CX:     Buffer length (characters)
138;       BX:SI:  Ptr to NULL terminated string
139;       DS:     BDA segment (zero)
140;       ES:DI:  Ptr to cursor location in video RAM
141;   Returns:
142;       DI:     Updated offset to video RAM
143;   Corrupts registers:
144;       AX, DX
145;--------------------------------------------------------------------
146ALIGN JUMP_ALIGN
147DisplayPrint_CharacterBufferFromBXSIwithLengthInCX:
148    jcxz    .NothingToPrintSinceZeroLength
149    push    si
150    push    cx
151
152ALIGN JUMP_ALIGN
153.PrintNextCharacter:
154    mov     ds, bx
155    lodsb
156    LOAD_BDA_SEGMENT_TO ds, dx
157    call    DisplayPrint_CharacterFromAL
158    loop    .PrintNextCharacter
159
160    mov     ds, cx  ; Restore DS to BDA. Not needed unless DisplayPrint_CharacterFromAL changes DS.
161    pop     cx
162    pop     si
163.NothingToPrintSinceZeroLength:
164    ret
165
166
167;--------------------------------------------------------------------
168; DisplayPrint_NullTerminatedStringFromCSSI
169;   Parameters:
170;       CS:SI:  Ptr to NULL terminated string
171;       DS:     BDA segment (zero)
172;       ES:DI:  Ptr to cursor location in video RAM
173;   Returns:
174;       DI:     Updated offset to video RAM
175;   Corrupts registers:
176;       AX, DX
177;--------------------------------------------------------------------
178ALIGN JUMP_ALIGN
179DisplayPrint_NullTerminatedStringFromCSSI:
180    push    bx
181    mov     bx, cs
182    call    DisplayPrint_NullTerminatedStringFromBXSI
183    pop     bx
184    ret
185
186
187;--------------------------------------------------------------------
188; DisplayPrint_NullTerminatedStringFromBXSI
189;   Parameters:
190;       DS:     BDA segment (zero)
191;       BX:SI:  Ptr to NULL terminated string
192;       ES:DI:  Ptr to cursor location in video RAM
193;   Returns:
194;       DI:     Updated offset to video RAM
195;   Corrupts registers:
196;       AX, DX
197;--------------------------------------------------------------------
198ALIGN JUMP_ALIGN
199DisplayPrint_NullTerminatedStringFromBXSI:
200    push    si
201    push    cx
202
203    xor     cx, cx
204ALIGN JUMP_ALIGN
205.PrintNextCharacter:
206    mov     ds, bx              ; String segment to DS
207    lodsb
208    mov     ds, cx              ; BDA segment to DS
209    test    al, al              ; NULL?
210    jz      SHORT .EndOfString
211    call    DisplayPrint_CharacterFromAL
212    jmp     SHORT .PrintNextCharacter
213
214ALIGN JUMP_ALIGN
215.EndOfString:
216    pop     cx
217    pop     si
218    ret
219
220
221;--------------------------------------------------------------------
222; DisplayPrint_ClearScreenWithCharInALandAttributeInAH
223;   Parameters:
224;       AL:     Character to clear with
225;       AH:     Attribute to clear with
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_ClearScreenWithCharInALandAttributeInAH:
235    push    di
236    push    cx
237
238    xchg    cx, ax
239    xor     ax, ax
240    call    DisplayCursor_SetCoordinatesFromAX      ; Updates DI
241    call    DisplayPage_GetColumnsToALandRowsToAH
242    mul     ah      ; AX = AL*AH = Characters on screen
243    xchg    cx, ax  ; AX = Char+Attr, CX = WORDs to store
244    rep stosw
245
246    pop     cx
247    pop     di
248    mov     [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], di
249    ret
250
251
252;--------------------------------------------------------------------
253; DisplayPrint_ClearAreaWithHeightInAHandWidthInAL
254;   Parameters:
255;       AH:     Area height
256;       AL:     Area width
257;       DS:     BDA segment (zero)
258;       ES:DI:  Ptr to cursor location in video RAM
259;   Returns:
260;       DI:     Updated offset to video RAM
261;   Corrupts registers:
262;       AX, DX
263;--------------------------------------------------------------------
264%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
265ALIGN JUMP_ALIGN
266DisplayPrint_ClearAreaWithHeightInAHandWidthInAL:
267    push    si
268    push    cx
269    push    bx
270
271    xchg    bx, ax                          ; Area size to BX
272    call    DisplayCursor_GetSoftwareCoordinatesToAX
273    xchg    si, ax                          ; Software (Y,X) coordinates now in SI
274    xor     cx, cx
275
276ALIGN JUMP_ALIGN
277.ClearRowLoop:
278    mov     cl, bl                          ; Area width now in CX
279    mov     al, SCREEN_BACKGROUND_CHARACTER
280    call    DisplayPrint_RepeatCharacterFromALwithCountInCX
281
282    xchg    ax, si                          ; Coordinates to AX
283    inc     ah                              ; Increment row
284    mov     si, ax
285    call    DisplayCursor_SetCoordinatesFromAX
286    dec     bh                              ; Decrement rows left
287    jnz     SHORT .ClearRowLoop
288
289    pop     bx
290    pop     cx
291    pop     si
292    ret
293%endif
294
295
296;--------------------------------------------------------------------
297; DisplayPrint_RepeatCharacterFromALwithCountInCX
298;   Parameters:
299;       AL:     Character to display
300;       CX:     Repeat count
301;       DS:     BDA segment (zero)
302;       ES:DI:  Ptr to cursor location in video RAM
303;   Returns:
304;       DI:     Updated offset to video RAM
305;   Corrupts registers:
306;       AX, DX
307;--------------------------------------------------------------------
308ALIGN JUMP_ALIGN
309DisplayPrint_RepeatCharacterFromALwithCountInCX:
310    jcxz    .NothingToRepeat
311    push    cx
312
313ALIGN JUMP_ALIGN
314.RepeatCharacter:
315    push    ax
316    call    DisplayPrint_CharacterFromAL
317    pop     ax
318    loop    .RepeatCharacter
319
320    pop     cx
321.NothingToRepeat:
322    ret
323
324
325;--------------------------------------------------------------------
326; DisplayPrint_Newline
327;   Parameters:
328;       DS:     BDA segment (zero)
329;       ES:DI:  Ptr to cursor location in video RAM
330;   Returns:
331;       DI:     Updated offset to video RAM
332;   Corrupts registers:
333;       AX, DX
334;--------------------------------------------------------------------
335ALIGN JUMP_ALIGN
336DisplayPrint_Newline:
337    mov     al, LF
338    call    DisplayPrint_CharacterFromAL
339    mov     al, CR
340    ; Fall to DisplayPrint_CharacterFromAL
341
342;--------------------------------------------------------------------
343; DisplayPrint_CharacterFromAL
344;   Parameters:
345;       AL:     Character to display
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:
355    mov     ah, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
356    jmp     [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut]
Note: See TracBrowser for help on using the repository browser.