source: xtideuniversalbios/trunk/Assembly_Library/Src/Display/DisplayFormatCompressed.asm@ 621

Last change on this file since 621 was 580, checked in by krille_n_@…, 10 years ago

Changes:

  • XTIDECFG: Fixed a bug from r459 where the menu option for selection of default boot drive would be missing if the BIOS had been built without MODULE_HOTKEYS. The menu option is now visible if either or both of MODULE_HOTKEYS and MODULE_BOOT_MENU is available.
  • BIOS: Disabled ATA-ID validation by adding a new define (NO_ATAID_VALIDATION) and making it the default for all builds since at least two WD Caviar drive models are incompatible with it.
  • Fixed the "No Fixed Disk Present in FDISK"-bug introduced in r551 which means the Tiny build now works without including MODULE_DRIVEXLATE.
  • Fixed a bug from r528 where pressing hotkey F6 would not initiate detection of serial drives.
  • Fixed a bug from r186 in DisplayFormatCompressed.asm where the boot menu would print the IRQ in hexadecimal format when it should be in decimal format.
  • Optimizations and fixes.
File size: 9.7 KB
Line 
1; Project name : Assembly Library
2; Description : Functions for displaying formatted strings.
3; ** Compressed Strings edition **
4; This is a plug replacement for DisplayFormat.asm,
5; working instead with precompiled and slightly compressed strings.
6
7;
8; XTIDE Universal BIOS and Associated Tools
9; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
10;
11; This program is free software; you can redistribute it and/or modify
12; it under the terms of the GNU General Public License as published by
13; the Free Software Foundation; either version 2 of the License, or
14; (at your option) any later version.
15;
16; This program is distributed in the hope that it will be useful,
17; but WITHOUT ANY WARRANTY; without even the implied warranty of
18; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19; GNU General Public License for more details.
20; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21;
22
23;=============================================================================================
24;
25; Strings are compressed in a simple manner:
26; 1. The two most common characters, space and null, are removed
27; 2. Format specifiers are reduced to a single byte, including length information
28;
29; Format of bytes in the string are:
30; 01 xxxxxx Character in x plus StringsCompressed_NormalBase
31; 10 xxxxxx Character in x plus StringsCompressed_NormalBase, followed by a null (last character)
32; 11 xxxxxx Character in x plus StringsCompressed_NormalBase, followed by a space
33; 00 1 yyyyy Character/Format in lookup table StringsCopmressed_TranslatesAndFormats
34; 00 0 yyyyy Character/Format in lookup table StringsCompressed_TranslatesAndFormats, followed by a null
35;
36; StringsCompressed_NormalBase is defined by the compressor, but is usually around 0x40,
37; which gives a range of 0x40 to 0x7f, or roughly the upper and lower case letters.
38;
39; StringsCompressed_TranslatesAndFormats is a lookup table with the first few bytes being translation
40; characters, and the last few bytes being format jump offsets from DisplayFormatCompressed_BaseFormatOffset.
41; The dividing line is defined by StringsCompressed_FormatsBegin
42;
43; The assignments of the first two bits above is not by accident. The translates/format branch is 00
44; which is easy to test for. The '01' for "normal" (no null or space) and '001' for translates/format "normal"
45; match, allowing the translates/format codes to be shifted left by 1 and then tested with the same instructions.
46;
47; It is always possible to say that a null character follows the current character - thus there is
48; no way (nor need) to specify a zero character.
49;
50; Note that this code is optimized for size, not speed. Since this code is used only during initialization
51; and only for the user interface, small performance hits should not be noticed. It will seem odd to do so
52; much "preload", just in case a branch is taken, but that is cheaper (in size) than adding additional branches.
53;
54
55; Section containing code
56SECTION .text
57
58;--------------------------------------------------------------------
59; Format Handlers
60;
61; Names of format handlers are DisplayFormatCompressed_Format_* where * is
62; replaced with the format code after the '%' in the original string,
63; with '-' replaced with '_'.
64;
65; Parameters:
66; DS: BDA segment (zero)
67; AX: Parameter to Format
68; ES:DI: Ptr to cursor location in video RAM
69; Returns:
70; DI: Updated offset to video RAM
71; Corrupts registers:
72; AX, BX, CX, DX, SI
73;--------------------------------------------------------------------
74
75;
76; The following routines do not need any pre or post processing and can be jumped to directly.
77; Note that they need to be within 256 bytes of DisplayFormatCompressed_BaseFormatOffset
78;
79%define DisplayFormatCompressed_Format_c DisplayPrint_CharacterFromAL
80%define DisplayFormatCompressed_Format_nl DisplayPrint_Newline_FormatAdjustBP
81%define DisplayFormatCompressed_Format_s DisplayFormat_ParseCharacters_FromAX
82
83DisplayFormatCompressed_Format_A:
84 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al
85DisplayFormatCompressed_ret: ; jump target for other routines who need a "ret"
86 ret
87
88DisplayFormatCompressed_Format_z:
89 xor bx, bx
90 xchg si, ax
91 jmp SHORT DisplayPrint_NullTerminatedStringFromBXSI
92
93DisplayFormatCompressed_Format_x:
94DisplayFormatCompressed_Format_5_x:
95 mov si, 16 ; hex output, change base to 16
96 mov bx, (04<<8) + 'h' ; 4 bytes, with postfix character 'h' to emit
97 ; (note that the count includes the 'h')
98 SKIP2B f ; Fall through to DisplayFormatCompressed_Format_u
99
100DisplayFormatCompressed_Format_2_u:
101 mov bh, 2 ; only two characters (instead of the default 5)
102 ; fall through
103
104DisplayFormatCompressed_Format_u:
105DisplayFormatCompressed_Format_5_u:
106 push bx ; push postfix character - either a zero (default) or a 'h'
107 mov bl, bh ; preserve character count for .PrintLoop
108
109.DivLoop:
110 xor dx, dx ; Zero DX for division
111 div si ; DX:AX / 10 => AX=quot, DX=rem
112 push dx ; Push digit
113
114 dec bh
115 jnz SHORT .DivLoop
116
117.PrintLoop:
118 pop ax ; Pop digit, postfix character on last iteration
119
120 dec bl ; on second to last iteration, emit digit whether it is zero or not
121 jz SHORT .PrintDigit
122 js SHORT DisplayPrint_CharacterFromAL ; on last iteration, emit postfix character
123 ; if it is zero, DisplayPrint_CharacterFromAL will not emit
124
125 or bh, al ; skip leading zeros, bh keeps track if we have emitted anything non-zero
126 jnz SHORT .PrintDigit ; note that bh starts at zero, from the loop above
127
128 test ch, 2 ; are we padding with leading spaces?
129 jnz SHORT .PrintLoop ; test the even/odd of the format byte in the string
130
131 mov al, 89h ; emit space
132
133.PrintDigit:
134 cmp al, 10 ; Convert binary digit in AL to ASCII hex digit ('0'-'9' or 'A'-'F')
135 sbb al, 69h
136 das
137
138 call DisplayPrint_CharacterFromAL
139 jmp SHORT .PrintLoop
140
141DisplayFormatCompressed_Format_2_I:
142 test ax, ax
143 jnz SHORT DisplayFormatCompressed_Format_2_u
144 mov si, g_szDashForZero ; if parameter equals zero, emit dash string instead
145 SKIP2B bx ; Fall through to DisplayFormat_ParseCharacters
146
147;--------------------------------------------------------------------
148; DisplayFormat_ParseCharacters
149; Parameters:
150; DS: BDA segment (zero)
151; SS:BP: Pointer to first format parameter (-=2 updates to next parameter)
152; CS:SI: Pointer to string to format
153; ES:DI: Ptr to cursor location in video RAM
154; Returns:
155; CS:SI: Ptr to end of format string (ptr to one past NULL)
156; DI: Updated offset to video RAM
157; Corrupts registers:
158; AX, BX, CX, DX, BP
159;--------------------------------------------------------------------
160DisplayFormatCompressed_BaseFormatOffset:
161DisplayFormat_ParseCharacters_FromAX:
162 mov si, ax
163 ; fall through to DisplayFormat_ParseCharacters
164
165ALIGN DISPLAY_JUMP_ALIGN
166DisplayFormat_ParseCharacters:
167;
168; This routine is used to output all strings from the ROM. The strings in ROMVARS are not compressed,
169; and must be handled differently.
170;
171 cmp si, BYTE 7Fh ; well within the boundaries of ROMVARS_size
172 mov bx, cs ; preload bx with cs in case we take the following jump
173 jb SHORT DisplayPrint_NullTerminatedStringFromBXSI
174
175.decode:
176 cs lodsb ; load next byte of the string
177 mov ch, al ; save a copy for later processing of high order bits
178 test al, 0C0h ; check for translation/format character
179 jz SHORT DisplayFormatCompressed_TranslatesAndFormats
180
181 and al, 3Fh ; "Normal" character, mask off high order bits
182 add al, StringsCompressed_NormalBase ; and add character offset (usually around 0x40)
183
184.output:
185 call DisplayPrint_CharacterFromAL
186
187.process_after_output:
188 eSHL_IM ch, 1 ; check high order bits for end of string or space
189 jns SHORT DisplayFormatCompressed_ret
190 jnc SHORT .decode
191 mov al, ' '
192 call DisplayPrint_CharacterFromAL
193 jmp SHORT .decode
194
195
196ALIGN DISPLAY_JUMP_ALIGN
197DisplayFormatCompressed_TranslatesAndFormats:
198;
199; This routine is here (above DisplayFormat_ParseCharacters) to reduce the amount of code between
200; DisplayFormatCompressed_BaseFormatOffset and jump targets (must fit in 256 bytes)
201;
202 eSHL_IM ch, 1 ; setup ch for later testing of null in .process_after_output
203 and ax, 001Fh ; also clears AH for addition with BX and DX below
204
205 mov bx, StringsCompressed_TranslatesAndFormats ; calculate offset of translation/formats offset byte
206 add bx, ax
207
208 cmp al, StringsCompressed_FormatsBegin ; determine if this is a translation or a format
209 mov al, [cs:bx] ; fetch translation/formats byte
210 jb SHORT DisplayFormat_ParseCharacters.output ; check if this a translation or a format
211 ; if it is translation, output and postprocess for eos
212 ; note that the flags for this conditional jump were
213 ; set with the cmp al,StringsCompressed_FormatsBegin
214
215 mov dx, DisplayFormatCompressed_BaseFormatOffset ; calculate address to jump to for format handler
216 sub dx, ax
217
218 mov ax, [bp] ; preload ax with parameter
219 dec bp ; if no parameter is needed (format 'nl' for example),
220 dec bp ; the format handler can reincrement bp
221
222 mov bx, 0500h ; preload bh with 5 decimal places for numeric output
223 ; bl is zero, indicating not to output a 'h' (default base 10)
224
225 push si ; preserve si and cx, in the case of outputing a string
226 push cx
227
228 mov si, 10 ; preload si with 10 for numeric output (default base 10)
229 call dx ; call the format routine
230
231 pop cx ; restore cx and si
232 pop si
233
234 jmp SHORT DisplayFormat_ParseCharacters.process_after_output ; continue postprocessing, check for end of string
Note: See TracBrowser for help on using the repository browser.