source: xtideuniversalbios/trunk/Assembly_Library/Src/String/Char.asm@ 489

Last change on this file since 489 was 489, checked in by gregli@…, 12 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: 6.9 KB
Line 
1; Project name : Assembly Library
2; Description : Functions for handling characters.
3
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
20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
24; This macro can only be used within this source file!!!
25; IS_BETWEEN_IMMEDIATES
26; Parameters:
27; %1: Value to check
28; %2: First accepted value in range
29; %3: Last accepted value in range
30; Returns:
31; CF: Set if character is range
32; (Jumps to Char_CharIsNotValid if before range)
33; Corrupts registers:
34; Nothing
35;--------------------------------------------------------------------
36%macro IS_BETWEEN_IMMEDIATES 3
37 cmp %1, %2
38 jb SHORT Char_CharIsNotValid
39 cmp %1, (%3)+1 ; Set CF if %1 is lesser
40%endmacro
41
42
43;--------------------------------------------------------------------
44; Char_IsLowerCaseLetterInAL
45; Parameters:
46; AL: Character to check
47; Returns:
48; CF: Set if character is lower case letter ('a'...'z')
49; Cleared if character is not lower case letter
50; Corrupts registers:
51; Nothing
52;--------------------------------------------------------------------
53ALIGN STRING_JUMP_ALIGN
54Char_IsLowerCaseLetterInAL:
55 IS_BETWEEN_IMMEDIATES al, 'a', 'z'
56 ret
57
58;--------------------------------------------------------------------
59; Char_IsUpperCaseLetterInAL
60; Parameters:
61; AL: Character to check
62; Returns:
63; CF: Set if character is upper case letter ('A'...'Z')
64; Cleared if character is not upper case letter
65; Corrupts registers:
66; Nothing
67;--------------------------------------------------------------------
68%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
69ALIGN STRING_JUMP_ALIGN
70Char_IsUpperCaseLetterInAL:
71 IS_BETWEEN_IMMEDIATES al, 'A', 'Z'
72 ret
73%endif
74
75;--------------------------------------------------------------------
76; Char_IsHexadecimalDigitInAL
77; Parameters:
78; AL: Character to check
79; Returns:
80; AL: Character converted to lower case
81; CF: Set if character is decimal digit ('0'...'F')
82; Cleared if character is not decimal digit
83; Corrupts registers:
84; Nothing
85;--------------------------------------------------------------------
86%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
87ALIGN STRING_JUMP_ALIGN
88Char_IsHexadecimalDigitInAL:
89 call Char_IsDecimalDigitInAL
90 jc SHORT Char_CharIsValid
91 call Char_ALtoLowerCaseLetter
92 IS_BETWEEN_IMMEDIATES al, 'a', 'f'
93 ret
94%endif
95
96;--------------------------------------------------------------------
97; Char_IsDecimalDigitInAL
98; Parameters:
99; AL: Character to check
100; Returns:
101; CF: Set if character is decimal digit ('0'...'9')
102; Cleared if character is not decimal digit
103; Corrupts registers:
104; Nothing
105;--------------------------------------------------------------------
106%ifndef MODULE_STRINGS_COMPRESSED
107ALIGN STRING_JUMP_ALIGN
108Char_IsDecimalDigitInAL:
109 IS_BETWEEN_IMMEDIATES al, '0', '9'
110 ret
111%endif
112
113;--------------------------------------------------------------------
114; Char_ConvertIntegerToALfromDigitInALwithBaseInBX
115; Parameters:
116; AL: Character to convert
117; BX: Numeric base (10 or 16)
118; Returns:
119; AL: Character converted to integer
120; CF: Set if character was valid
121; Cleared if character was invalid
122; Corrupts registers:
123; Nothing
124;--------------------------------------------------------------------
125%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
126ALIGN STRING_JUMP_ALIGN
127Char_ConvertIntegerToALfromDigitInALwithBaseInBX:
128 push dx
129 call Char_GetFilterFunctionToDXforNumericBaseInBX
130 call dx ; Converts to lower case
131 pop dx
132 jnc SHORT Char_CharIsNotValid
133
134 cmp al, '9' ; Decimal digit
135 jbe SHORT .ConvertToDecimalDigit
136 sub al, 'a'-'0'-10 ; Convert to hexadecimal integer
137ALIGN STRING_JUMP_ALIGN
138.ConvertToDecimalDigit:
139 sub al, '0' ; Convert to decimal integer
140 ; Fall to Char_CharIsValid
141%endif
142
143;--------------------------------------------------------------------
144; Char_CharIsValid
145; Char_CharIsNotValid
146; Parameters:
147; Nothing
148; Returns:
149; CF: Set for Char_CharIsValid
150; Cleared for Char_CharIsNotValid
151; Corrupts registers:
152; Nothing
153;--------------------------------------------------------------------
154%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
155ALIGN STRING_JUMP_ALIGN
156Char_CharIsValid:
157 stc
158 ret
159%endif
160
161ALIGN STRING_JUMP_ALIGN
162Char_CharIsNotValid:
163 clc
164 ret
165
166
167;--------------------------------------------------------------------
168; Char_ALtoLowerCaseLetter
169; Parameters:
170; AL: Character to convert
171; Returns:
172; AL: Character with possible conversion
173; Corrupts registers:
174; Nothing
175;--------------------------------------------------------------------
176%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
177ALIGN STRING_JUMP_ALIGN
178Char_ALtoLowerCaseLetter:
179 call Char_IsUpperCaseLetterInAL ; Is upper case character?
180 jmp SHORT Char_ALtoUpperCaseLetter.CheckCF
181%endif
182
183
184;--------------------------------------------------------------------
185; Char_ALtoUpperCaseLetter
186; Parameters:
187; AL: Character to convert
188; Returns:
189; AL: Character with possible conversion
190; Corrupts registers:
191; Nothing
192;--------------------------------------------------------------------
193%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
194ALIGN STRING_JUMP_ALIGN
195Char_ALtoUpperCaseLetter:
196 call Char_IsLowerCaseLetterInAL ; Is lower case character?
197.CheckCF:
198 jnc SHORT Char_ChangeCaseInAL.Return
199 ; Fall to Char_ChangeCaseInAL
200%endif
201
202
203;--------------------------------------------------------------------
204; Char_ChangeCaseInAL
205; Parameters:
206; AL: Character to convert (must be A-Z or a-z)
207; Returns:
208; AL: Character converted
209; Corrupts registers:
210; Nothing
211;--------------------------------------------------------------------
212Char_ChangeCaseInAL:
213 xor al, 32
214.Return:
215 ret
216
217;--------------------------------------------------------------------
218; Char_GetFilterFunctionToDXforNumericBaseInBX
219; Parameters
220; BX: Numeric base (10 or 16)
221; Returns:
222; CS:DX: Ptr to character filter function
223; Corrupts registers:
224; Nothing
225;--------------------------------------------------------------------
226%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
227ALIGN STRING_JUMP_ALIGN
228Char_GetFilterFunctionToDXforNumericBaseInBX:
229 mov dx, Char_IsDecimalDigitInAL
230 cmp bl, 10
231 je SHORT .Return
232 mov dx, Char_IsHexadecimalDigitInAL
233.Return:
234 ret
235%endif
Note: See TracBrowser for help on using the repository browser.