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

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

Changes:

  • Added a new define (USE_UNDOC_INTEL) that enables optimizations possible by using undocumented instructions available on all Intel processors and truly compatible clones. AFAIK the only exceptions are the NEC V-series and the Sony CXQ70108 processors so this option should be safe for use on the AT builds.
  • Building BIOSDRVS or the BIOS without MODULE_STRINGS_COMPRESSED would fail due to the recent code exclusions so I changed them a bit. Also fixed the mistaken change to Main.asm
  • Changed the Tandy specific info in Configuration_FullMode.txt so it matches the info in the Wiki.
  • Optimizations and fixes in general.
File size: 12.4 KB
RevLine 
[41]1; Project name  :   Assembly Library
2; Description   :   Functions for display output.
3
[376]4;
[491]5; XTIDE Universal BIOS and Associated Tools
[376]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.
[491]12;
[376]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
[491]16; GNU General Public License for more details.
[376]17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
[491]18;
[376]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
[41]111;--------------------------------------------------------------------
112; DisplayPrint_WordFromAXWithBaseInBX
113;   Parameters:
114;       AX:     Word to display
115;       BX:     Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
116;       DS:     BDA segment (zero)
117;       ES:DI:  Ptr to cursor location in video RAM
118;   Returns:
119;       DI:     Updated offset to video RAM
120;   Corrupts registers:
121;       AX, DX
[376]122;--------------------------------------------------------------------
[491]123%ifndef MODULE_STRINGS_COMPRESSED
[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
[491]154%endif ; MODULE_STRINGS_COMPRESSED
155
[341]156;--------------------------------------------------------------------
157; DisplayPrint_QWordFromSSBPwithBaseInBX
158;   Parameters:
159;       SS:BP:  QWord to display
160;       BX:     Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
161;       DS:     BDA segment (zero)
162;       ES:DI:  Ptr to cursor location in video RAM
163;   Returns:
164;       DI:     Updated offset to video RAM
165;   Corrupts registers:
166;       AX, DX, [SS:BP]
167;--------------------------------------------------------------------
[491]168%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS OR EXCLUDE_FROM_XTIDECFG
[369]169ALIGN DISPLAY_JUMP_ALIGN
[341]170DisplayPrint_QWordFromSSBPwithBaseInBX:
171    push    cx
172    push    bx
173
174    mov     cx, bx              ; CX = Integer base
175    xor     bx, bx              ; BX = Character count
[369]176ALIGN DISPLAY_JUMP_ALIGN
[341]177.DivideLoop:
178    call    Math_DivQWatSSBPbyCX; Divide by base
179    push    dx                  ; Push remainder
180    inc     bx                  ; Increment character count
181    cmp     WORD [bp], BYTE 0   ; All divided?
182    jne     SHORT .DivideLoop   ;  If not, loop
183    mov     cx, bx              ; Character count to CX
184    jmp     SHORT PrintAllPushedDigits
[491]185%endif
[41]186
187
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
[41]222;--------------------------------------------------------------------
[67]223; DisplayPrint_ClearScreenWithCharInALandAttributeInAH
[41]224;   Parameters:
[67]225;       AL:     Character to clear with
226;       AH:     Attribute to clear with
[41]227;       DS:     BDA segment (zero)
228;       ES:DI:  Ptr to cursor location in video RAM
229;   Returns:
230;       Nothing
231;   Corrupts registers:
232;       AX, DX
233;--------------------------------------------------------------------
[491]234%ifdef INCLUDE_MENU_LIBRARY
[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
[491]253
254
[41]255;--------------------------------------------------------------------
256; DisplayPrint_ClearAreaWithHeightInAHandWidthInAL
257;   Parameters:
258;       AH:     Area height
259;       AL:     Area width
260;       DS:     BDA segment (zero)
261;       ES:DI:  Ptr to cursor location in video RAM
262;   Returns:
[42]263;       DI:     Updated offset to video RAM
[41]264;   Corrupts registers:
265;       AX, DX
266;--------------------------------------------------------------------
[134]267%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[369]268ALIGN DISPLAY_JUMP_ALIGN
[41]269DisplayPrint_ClearAreaWithHeightInAHandWidthInAL:
[42]270    push    si
[41]271    push    cx
272    push    bx
273
[42]274    xchg    bx, ax                          ; Area size to BX
[41]275    call    DisplayCursor_GetSoftwareCoordinatesToAX
[42]276    xchg    si, ax                          ; Software (Y,X) coordinates now in SI
277    xor     cx, cx
[41]278
[369]279ALIGN DISPLAY_JUMP_ALIGN
[42]280.ClearRowLoop:
281    mov     cl, bl                          ; Area width now in CX
[44]282    mov     al, SCREEN_BACKGROUND_CHARACTER
[42]283    call    DisplayPrint_RepeatCharacterFromALwithCountInCX
[41]284
[42]285    xchg    ax, si                          ; Coordinates to AX
286    inc     ah                              ; Increment row
287    mov     si, ax
[41]288    call    DisplayCursor_SetCoordinatesFromAX
[42]289    dec     bh                              ; Decrement rows left
290    jnz     SHORT .ClearRowLoop
[41]291
292    pop     bx
293    pop     cx
[42]294    pop     si
[41]295    ret
[134]296%endif
[42]297
298
299;--------------------------------------------------------------------
300; DisplayPrint_RepeatCharacterFromALwithCountInCX
301;   Parameters:
302;       AL:     Character to display
303;       CX:     Repeat count
304;       DS:     BDA segment (zero)
305;       ES:DI:  Ptr to cursor location in video RAM
306;   Returns:
307;       DI:     Updated offset to video RAM
308;   Corrupts registers:
[181]309;       DX
[42]310;--------------------------------------------------------------------
[369]311ALIGN DISPLAY_JUMP_ALIGN
[42]312DisplayPrint_RepeatCharacterFromALwithCountInCX:
[44]313    jcxz    .NothingToRepeat
314    push    cx
315
[369]316ALIGN DISPLAY_JUMP_ALIGN
[44]317.RepeatCharacter:
[42]318    push    ax
319    call    DisplayPrint_CharacterFromAL
320    pop     ax
[44]321    loop    .RepeatCharacter
322
323    pop     cx
324.NothingToRepeat:
[42]325    ret
[223]326
[376]327
[186]328;--------------------------------------------------------------------
329; DisplayPrint_NullTerminatedStringFromCSSI
330;   Parameters:
331;       CS:SI:  Ptr to NULL terminated string
332;       DS:     BDA segment (zero)
333;       ES:DI:  Ptr to cursor location in video RAM
334;   Returns:
335;       DI:     Updated offset to video RAM
336;   Corrupts registers:
337;       AX, DX
338;--------------------------------------------------------------------
[376]339%ifndef MODULE_STRINGS_COMPRESSED
340;;;
341;;; Take care when using this routine with compressed strings (which is why it is disabled).
342;;; All strings in CSSI should go through the DisplayFormatCompressed code to be decoded.
343;;;
[369]344ALIGN DISPLAY_JUMP_ALIGN
[186]345DisplayPrint_NullTerminatedStringFromCSSI:
346    push    bx
347    mov     bx, cs
348    call    DisplayPrint_NullTerminatedStringFromBXSI
349    pop     bx
350    ret
[376]351%endif
[42]352
353
[376]354;;;
355;;; Note that the following routines need to be at the bottom of this file
356;;; to accomodate short jumps from the next file (DisplayFormat/DisplayFormatCompressed)
357;;;
358
[42]359;--------------------------------------------------------------------
[44]360; DisplayPrint_Newline
361;   Parameters:
362;       DS:     BDA segment (zero)
363;       ES:DI:  Ptr to cursor location in video RAM
364;   Returns:
365;       DI:     Updated offset to video RAM
366;   Corrupts registers:
367;       AX, DX
368;--------------------------------------------------------------------
[376]369%ifdef MODULE_STRINGS_COMPRESSED
[369]370ALIGN DISPLAY_JUMP_ALIGN
[376]371DisplayPrint_Newline_FormatAdjustBP:
372    inc     bp                  ; we didn't need a parameter after all, readjust BP
373    inc     bp
374    ; fall through to DisplayPrint_Newline
375%endif
376
[369]377ALIGN DISPLAY_JUMP_ALIGN
[44]378DisplayPrint_Newline:
[52]379    mov     al, LF
380    call    DisplayPrint_CharacterFromAL
[44]381    mov     al, CR
382    ; Fall to DisplayPrint_CharacterFromAL
383
384;--------------------------------------------------------------------
[42]385; DisplayPrint_CharacterFromAL
386;   Parameters:
387;       AL:     Character to display
[376]388;               Zero value is ignored (no characer is printed)
[42]389;       DS:     BDA segment (zero)
390;       ES:DI:  Ptr to cursor location in video RAM
391;   Returns:
392;       DI:     Updated offset to video RAM
393;   Corrupts registers:
394;       AX, DX
395;--------------------------------------------------------------------
[369]396ALIGN DISPLAY_JUMP_ALIGN
[42]397DisplayPrint_CharacterFromAL:
[376]398    test    al,al
399    jz      DisplayPrint_Ret
400
[42]401    mov     ah, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
402    jmp     [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut]
[223]403
[376]404
[186]405;--------------------------------------------------------------------
406; DisplayPrint_NullTerminatedStringFromBXSI
407;   Parameters:
408;       DS:     BDA segment (zero)
409;       BX:SI:  Ptr to NULL terminated string
410;       ES:DI:  Ptr to cursor location in video RAM
411;   Returns:
412;       DI:     Updated offset to video RAM
413;   Corrupts registers:
414;       AX, DX
415;--------------------------------------------------------------------
[369]416ALIGN DISPLAY_JUMP_ALIGN
[186]417DisplayPrint_NullTerminatedStringFromBXSI:
418    push    si
419    push    cx
420
421    xor     cx, cx
[369]422ALIGN DISPLAY_JUMP_ALIGN
[186]423.PrintNextCharacter:
424    mov     ds, bx              ; String segment to DS
425    lodsb
426    mov     ds, cx              ; BDA segment to DS
427    test    al, al              ; NULL?
428    jz      SHORT .EndOfString
429    call    DisplayPrint_CharacterFromAL
430    jmp     SHORT .PrintNextCharacter
431
[369]432ALIGN DISPLAY_JUMP_ALIGN
[186]433.EndOfString:
434    pop     cx
435    pop     si
[376]436
437DisplayPrint_Ret:               ; random ret to jump to
[186]438    ret
439
Note: See TracBrowser for help on using the repository browser.