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

Last change on this file since 489 was 489, checked in by gregli@…, 11 years ago

Added version string to initial title banner, for cases where there is not a boot menu (just hotkeys, or no hotkeys). Also ifdef'd out some unused code.

File size: 12.4 KB
RevLine 
[41]1; Project name  :   Assembly Library
2; Description   :   Functions for display output.
3
[376]4;
5; XTIDE Universal BIOS and Associated Tools 
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
7;
8; This program is free software; you can redistribute it and/or modify
9; it under the terms of the GNU General Public License as published by
10; the Free Software Foundation; either version 2 of the License, or
11; (at your option) any later version.
12; 
13; This program is distributed in the hope that it will be useful,
14; but WITHOUT ANY WARRANTY; without even the implied warranty of
15; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16; GNU General Public License for more details.     
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;       
19
[41]20; Section containing code
21SECTION .text
22
[376]23
[41]24;--------------------------------------------------------------------
25; Supports following formatting types:
26;   %a      Specifies attribute for next character
27;   %A      Specifies attribute for remaining string (or until next %A)
28;   %d      Prints signed 16-bit decimal integer
29;   %u      Prints unsigned 16-bit decimal integer
30;   %x      Prints 16-bit hexadecimal integer
31;   %s      Prints string (from CS segment)
32;   %S      Prints string (far pointer)
33;   %c      Prints character
34;   %t      Prints character number of times (character needs to be pushed first, then repeat times)
35;   %%      Prints '%' character (no parameter pushed)
36;
37;   Any placeholder can be set to minimum length by specifying
38;   minimum number of characters. For example %8d would append spaces
39;   after integer so that at least 8 characters would be printed.
[48]40;
41;   When placing '-' after number, then spaces will be used for prepending.
42;   For example %8-d would prepend integer with spaces so that at least
43;   8 characters would be printed.
[162]44;
[41]45; DisplayPrint_FormattedNullTerminatedStringFromCSSI
46;   Parameters:
47;       BP:     SP before pushing parameters
48;       DS:     BDA segment (zero)
49;       CS:SI:  Pointer to string to format
50;       ES:DI:  Ptr to cursor location in video RAM
51;       Stack:  Parameters for formatting placeholders.
52;               Parameter for first placeholder must be pushed first.
53;               Low word must pushed first for placeholders requiring
54;               32-bit parameters (two words).
55;   Returns:
56;       DI:     Updated offset to video RAM
57;   Corrupts registers:
58;       AX, DX
59;--------------------------------------------------------------------
[369]60ALIGN DISPLAY_JUMP_ALIGN
[41]61DisplayPrint_FormattedNullTerminatedStringFromCSSI:
62    push    bp
63    push    si
64    push    cx
65    push    bx
66    push    WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
67
68    dec     bp                  ; Point BP to...
69    dec     bp                  ; ...first stack parameter
70    call    DisplayFormat_ParseCharacters
71
72    ; Pop original character attribute
73    pop     ax
74    mov     [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al
75
76    pop     bx
77    pop     cx
78    pop     si
79    pop     bp
[376]80
[41]81    ret
82
83
84;--------------------------------------------------------------------
[44]85; DisplayPrint_SignedWordFromAXWithBaseInBX
[41]86;   Parameters:
87;       AX:     Word to display
[44]88;       BX:     Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
[41]89;       DS:     BDA segment (zero)
90;       ES:DI:  Ptr to cursor location in video RAM
91;   Returns:
92;       DI:     Updated offset to video RAM
93;   Corrupts registers:
94;       AX, DX
95;--------------------------------------------------------------------
[134]96%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[369]97ALIGN DISPLAY_JUMP_ALIGN
[44]98DisplayPrint_SignedWordFromAXWithBaseInBX:
99    test    ax, ax
100    jns     SHORT DisplayPrint_WordFromAXWithBaseInBX
[41]101
102    push    ax
103    mov     al, '-'
104    call    DisplayPrint_CharacterFromAL
105    pop     ax
106    neg     ax
[44]107    ; Fall to DisplayPrint_WordFromAXWithBaseInBX
[134]108%endif
[41]109
[376]110
[323]111%ifndef MODULE_STRINGS_COMPRESSED
[41]112;--------------------------------------------------------------------
113; DisplayPrint_WordFromAXWithBaseInBX
114;   Parameters:
115;       AX:     Word to display
116;       BX:     Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
117;       DS:     BDA segment (zero)
118;       ES:DI:  Ptr to cursor location in video RAM
119;   Returns:
120;       DI:     Updated offset to video RAM
121;   Corrupts registers:
122;       AX, DX
[376]123;--------------------------------------------------------------------
[369]124ALIGN DISPLAY_JUMP_ALIGN
[41]125DisplayPrint_WordFromAXWithBaseInBX:
126    push    cx
[44]127    push    bx
[41]128
129    xor     cx, cx
[369]130ALIGN DISPLAY_JUMP_ALIGN
[41]131.DivideLoop:
132    xor     dx, dx              ; DX:AX now holds the integer
133    div     bx                  ; Divide DX:AX by base
134    push    dx                  ; Push remainder
135    inc     cx                  ; Increment character count
136    test    ax, ax              ; All divided?
137    jnz     SHORT .DivideLoop   ;  If not, loop
[44]138
[323]139PrintAllPushedDigits:
140    mov     bx, g_rgcDigitToCharacter
[369]141ALIGN DISPLAY_JUMP_ALIGN
[44]142.PrintNextDigit:
143    pop     ax                  ; Pop digit
[376]144    cs xlatb
[41]145    call    DisplayPrint_CharacterFromAL
[44]146    loop    .PrintNextDigit
[41]147
[44]148    pop     bx
[41]149    pop     cx
150    ret
[341]151
[323]152g_rgcDigitToCharacter:  db  "0123456789ABCDEF"
[341]153
154;--------------------------------------------------------------------
155; DisplayPrint_QWordFromSSBPwithBaseInBX
156;   Parameters:
157;       SS:BP:  QWord to display
158;       BX:     Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
159;       DS:     BDA segment (zero)
160;       ES:DI:  Ptr to cursor location in video RAM
161;   Returns:
162;       DI:     Updated offset to video RAM
163;   Corrupts registers:
164;       AX, DX, [SS:BP]
165;--------------------------------------------------------------------
166%ifndef EXCLUDE_FROM_XTIDECFG   ; Not used in XTIDECFG
[369]167ALIGN DISPLAY_JUMP_ALIGN
[341]168DisplayPrint_QWordFromSSBPwithBaseInBX:
169    push    cx
170    push    bx
171
172    mov     cx, bx              ; CX = Integer base
173    xor     bx, bx              ; BX = Character count
[369]174ALIGN DISPLAY_JUMP_ALIGN
[341]175.DivideLoop:
176    call    Math_DivQWatSSBPbyCX; Divide by base
177    push    dx                  ; Push remainder
178    inc     bx                  ; Increment character count
179    cmp     WORD [bp], BYTE 0   ; All divided?
180    jne     SHORT .DivideLoop   ;  If not, loop
181    mov     cx, bx              ; Character count to CX
182    jmp     SHORT PrintAllPushedDigits
183%endif  ; EXCLUDE_FROM_XTIDECFG
[41]184
[376]185%endif  ; MODULE_STRINGS_COMPRESSED
[41]186
[376]187
[41]188;--------------------------------------------------------------------
189; DisplayPrint_CharacterBufferFromBXSIwithLengthInCX
190;   Parameters:
191;       CX:     Buffer length (characters)
192;       BX:SI:  Ptr to NULL terminated string
193;       DS:     BDA segment (zero)
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;--------------------------------------------------------------------
[223]200%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[369]201ALIGN DISPLAY_JUMP_ALIGN
[41]202DisplayPrint_CharacterBufferFromBXSIwithLengthInCX:
[44]203    jcxz    .NothingToPrintSinceZeroLength
204    push    si
[41]205    push    cx
206
[369]207ALIGN DISPLAY_JUMP_ALIGN
[44]208.PrintNextCharacter:
209    mov     ds, bx
210    lodsb
211    LOAD_BDA_SEGMENT_TO ds, dx
212    call    DisplayPrint_CharacterFromAL
213    loop    .PrintNextCharacter
214
[41]215    pop     cx
[44]216    pop     si
217.NothingToPrintSinceZeroLength:
[41]218    ret
[376]219%endif
[41]220
[376]221
[489]222%ifdef INCLUDE_MENU_LIBRARY
[41]223;--------------------------------------------------------------------
[67]224; DisplayPrint_ClearScreenWithCharInALandAttributeInAH
[41]225;   Parameters:
[67]226;       AL:     Character to clear with
227;       AH:     Attribute to clear with
[41]228;       DS:     BDA segment (zero)
229;       ES:DI:  Ptr to cursor location in video RAM
230;   Returns:
231;       Nothing
232;   Corrupts registers:
233;       AX, DX
234;--------------------------------------------------------------------
[369]235ALIGN DISPLAY_JUMP_ALIGN
[67]236DisplayPrint_ClearScreenWithCharInALandAttributeInAH:
[41]237    push    di
[67]238    push    cx
239
240    xchg    cx, ax
[41]241    xor     ax, ax
[67]242    call    DisplayCursor_SetCoordinatesFromAX      ; Updates DI
[41]243    call    DisplayPage_GetColumnsToALandRowsToAH
[67]244    mul     ah      ; AX = AL*AH = Characters on screen
245    xchg    cx, ax  ; AX = Char+Attr, CX = WORDs to store
246    rep stosw
247
248    pop     cx
[41]249    pop     di
250    mov     [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], di
251    ret
[489]252%endif
253       
[41]254;--------------------------------------------------------------------
255; DisplayPrint_ClearAreaWithHeightInAHandWidthInAL
256;   Parameters:
257;       AH:     Area height
258;       AL:     Area width
259;       DS:     BDA segment (zero)
260;       ES:DI:  Ptr to cursor location in video RAM
261;   Returns:
[42]262;       DI:     Updated offset to video RAM
[41]263;   Corrupts registers:
264;       AX, DX
265;--------------------------------------------------------------------
[134]266%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[369]267ALIGN DISPLAY_JUMP_ALIGN
[41]268DisplayPrint_ClearAreaWithHeightInAHandWidthInAL:
[42]269    push    si
[41]270    push    cx
271    push    bx
272
[42]273    xchg    bx, ax                          ; Area size to BX
[41]274    call    DisplayCursor_GetSoftwareCoordinatesToAX
[42]275    xchg    si, ax                          ; Software (Y,X) coordinates now in SI
276    xor     cx, cx
[41]277
[369]278ALIGN DISPLAY_JUMP_ALIGN
[42]279.ClearRowLoop:
280    mov     cl, bl                          ; Area width now in CX
[44]281    mov     al, SCREEN_BACKGROUND_CHARACTER
[42]282    call    DisplayPrint_RepeatCharacterFromALwithCountInCX
[41]283
[42]284    xchg    ax, si                          ; Coordinates to AX
285    inc     ah                              ; Increment row
286    mov     si, ax
[41]287    call    DisplayCursor_SetCoordinatesFromAX
[42]288    dec     bh                              ; Decrement rows left
289    jnz     SHORT .ClearRowLoop
[41]290
291    pop     bx
292    pop     cx
[42]293    pop     si
[41]294    ret
[134]295%endif
[42]296
297
298;--------------------------------------------------------------------
299; DisplayPrint_RepeatCharacterFromALwithCountInCX
300;   Parameters:
301;       AL:     Character to display
302;       CX:     Repeat count
303;       DS:     BDA segment (zero)
304;       ES:DI:  Ptr to cursor location in video RAM
305;   Returns:
306;       DI:     Updated offset to video RAM
307;   Corrupts registers:
[181]308;       DX
[42]309;--------------------------------------------------------------------
[369]310ALIGN DISPLAY_JUMP_ALIGN
[42]311DisplayPrint_RepeatCharacterFromALwithCountInCX:
[44]312    jcxz    .NothingToRepeat
313    push    cx
314
[369]315ALIGN DISPLAY_JUMP_ALIGN
[44]316.RepeatCharacter:
[42]317    push    ax
318    call    DisplayPrint_CharacterFromAL
319    pop     ax
[44]320    loop    .RepeatCharacter
321
322    pop     cx
323.NothingToRepeat:
[42]324    ret
[223]325
[376]326
[186]327;--------------------------------------------------------------------
328; DisplayPrint_NullTerminatedStringFromCSSI
329;   Parameters:
330;       CS:SI:  Ptr to NULL terminated string
331;       DS:     BDA segment (zero)
332;       ES:DI:  Ptr to cursor location in video RAM
333;   Returns:
334;       DI:     Updated offset to video RAM
335;   Corrupts registers:
336;       AX, DX
337;--------------------------------------------------------------------
[376]338%ifndef MODULE_STRINGS_COMPRESSED
339;;;
340;;; Take care when using this routine with compressed strings (which is why it is disabled).
341;;; All strings in CSSI should go through the DisplayFormatCompressed code to be decoded.
342;;;
[369]343ALIGN DISPLAY_JUMP_ALIGN
[186]344DisplayPrint_NullTerminatedStringFromCSSI:
345    push    bx
346    mov     bx, cs
347    call    DisplayPrint_NullTerminatedStringFromBXSI
348    pop     bx
349    ret
[376]350%endif
[42]351
352
[376]353;;;
354;;; Note that the following routines need to be at the bottom of this file
355;;; to accomodate short jumps from the next file (DisplayFormat/DisplayFormatCompressed)
356;;;
357
[42]358;--------------------------------------------------------------------
[44]359; DisplayPrint_Newline
360;   Parameters:
361;       DS:     BDA segment (zero)
362;       ES:DI:  Ptr to cursor location in video RAM
363;   Returns:
364;       DI:     Updated offset to video RAM
365;   Corrupts registers:
366;       AX, DX
367;--------------------------------------------------------------------
[376]368%ifdef MODULE_STRINGS_COMPRESSED
[369]369ALIGN DISPLAY_JUMP_ALIGN
[376]370DisplayPrint_Newline_FormatAdjustBP:
371    inc     bp                  ; we didn't need a parameter after all, readjust BP
372    inc     bp
373    ; fall through to DisplayPrint_Newline
374%endif
375
[369]376ALIGN DISPLAY_JUMP_ALIGN
[44]377DisplayPrint_Newline:
[52]378    mov     al, LF
379    call    DisplayPrint_CharacterFromAL
[44]380    mov     al, CR
381    ; Fall to DisplayPrint_CharacterFromAL
382
383;--------------------------------------------------------------------
[42]384; DisplayPrint_CharacterFromAL
385;   Parameters:
386;       AL:     Character to display
[376]387;               Zero value is ignored (no characer is printed)
[42]388;       DS:     BDA segment (zero)
389;       ES:DI:  Ptr to cursor location in video RAM
390;   Returns:
391;       DI:     Updated offset to video RAM
392;   Corrupts registers:
393;       AX, DX
394;--------------------------------------------------------------------
[369]395ALIGN DISPLAY_JUMP_ALIGN
[42]396DisplayPrint_CharacterFromAL:
[376]397    test    al,al
398    jz      DisplayPrint_Ret
399
[42]400    mov     ah, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
401    jmp     [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut]
[223]402
[376]403
[186]404;--------------------------------------------------------------------
405; DisplayPrint_NullTerminatedStringFromBXSI
406;   Parameters:
407;       DS:     BDA segment (zero)
408;       BX:SI:  Ptr to NULL terminated string
409;       ES:DI:  Ptr to cursor location in video RAM
410;   Returns:
411;       DI:     Updated offset to video RAM
412;   Corrupts registers:
413;       AX, DX
414;--------------------------------------------------------------------
[369]415ALIGN DISPLAY_JUMP_ALIGN
[186]416DisplayPrint_NullTerminatedStringFromBXSI:
417    push    si
418    push    cx
419
420    xor     cx, cx
[369]421ALIGN DISPLAY_JUMP_ALIGN
[186]422.PrintNextCharacter:
423    mov     ds, bx              ; String segment to DS
424    lodsb
425    mov     ds, cx              ; BDA segment to DS
426    test    al, al              ; NULL?
427    jz      SHORT .EndOfString
428    call    DisplayPrint_CharacterFromAL
429    jmp     SHORT .PrintNextCharacter
430
[369]431ALIGN DISPLAY_JUMP_ALIGN
[186]432.EndOfString:
433    pop     cx
434    pop     si
[376]435
436DisplayPrint_Ret:               ; random ret to jump to
[186]437    ret
438
Note: See TracBrowser for help on using the repository browser.