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

Last change on this file since 581 was 526, checked in by krille_n_@…, 12 years ago

Changes:

  • Update of the copyright notices to include the year 2013.
File size: 7.3 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-2013 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 in 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;--------------------------------------------------------------------
53%ifdef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
54 %ifndef MODULE_HOTKEYS
55 %define EXCLUDE
56 %endif
57%endif
58
59%ifndef EXCLUDE
60ALIGN STRING_JUMP_ALIGN
61Char_IsLowerCaseLetterInAL:
62 IS_BETWEEN_IMMEDIATES al, 'a', 'z'
63 ret
64%endif
65%undef EXCLUDE
66
67
68;--------------------------------------------------------------------
69; Char_IsUpperCaseLetterInAL
70; Parameters:
71; AL: Character to check
72; Returns:
73; CF: Set if character is upper case letter ('A'...'Z')
74; Cleared if character is not upper case letter
75; Corrupts registers:
76; Nothing
77;--------------------------------------------------------------------
78%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
79ALIGN STRING_JUMP_ALIGN
80Char_IsUpperCaseLetterInAL:
81 IS_BETWEEN_IMMEDIATES al, 'A', 'Z'
82 ret
83%endif
84
85
86;--------------------------------------------------------------------
87; Char_IsHexadecimalDigitInAL
88; Parameters:
89; AL: Character to check
90; Returns:
91; AL: Character converted to lower case
92; CF: Set if character is decimal digit ('0'...'F')
93; Cleared if character is not decimal digit
94; Corrupts registers:
95; Nothing
96;--------------------------------------------------------------------
97%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
98ALIGN STRING_JUMP_ALIGN
99Char_IsHexadecimalDigitInAL:
100 call Char_IsDecimalDigitInAL
101 jc SHORT Char_CharIsValid
102 call Char_ALtoLowerCaseLetter
103 IS_BETWEEN_IMMEDIATES al, 'a', 'f'
104 ret
105%endif
106
107
108;--------------------------------------------------------------------
109; Char_IsDecimalDigitInAL
110; Parameters:
111; AL: Character to check
112; Returns:
113; CF: Set if character is decimal digit ('0'...'9')
114; Cleared if character is not decimal digit
115; Corrupts registers:
116; Nothing
117;--------------------------------------------------------------------
118%ifndef MODULE_STRINGS_COMPRESSED
119ALIGN STRING_JUMP_ALIGN
120Char_IsDecimalDigitInAL:
121 IS_BETWEEN_IMMEDIATES al, '0', '9'
122 ret
123%endif
124
125
126;--------------------------------------------------------------------
127; Char_ConvertIntegerToALfromDigitInALwithBaseInBX
128; Parameters:
129; AL: Character to convert
130; BX: Numeric base (10 or 16)
131; Returns:
132; AL: Character converted to integer
133; CF: Set if character was valid
134; Cleared if character was invalid
135; Corrupts registers:
136; Nothing
137;--------------------------------------------------------------------
138%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
139ALIGN STRING_JUMP_ALIGN
140Char_ConvertIntegerToALfromDigitInALwithBaseInBX:
141 push dx
142 call Char_GetFilterFunctionToDXforNumericBaseInBX
143 call dx ; Converts to lower case
144 pop dx
145 jnc SHORT Char_CharIsNotValid
146
147 cmp al, '9' ; Decimal digit
148 jbe SHORT .ConvertToDecimalDigit
149 sub al, 'a'-'0'-10 ; Convert to hexadecimal integer
150ALIGN STRING_JUMP_ALIGN
151.ConvertToDecimalDigit:
152 sub al, '0' ; Convert to decimal integer
153 ; Fall to Char_CharIsValid
154%endif
155
156
157;--------------------------------------------------------------------
158; Char_CharIsValid
159; Char_CharIsNotValid
160; Parameters:
161; Nothing
162; Returns:
163; CF: Set for Char_CharIsValid
164; Cleared for Char_CharIsNotValid
165; Corrupts registers:
166; Nothing
167;--------------------------------------------------------------------
168%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
169ALIGN STRING_JUMP_ALIGN
170Char_CharIsValid:
171 stc
172 ret
173%endif
174
175
176%ifdef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
177 %ifndef MODULE_HOTKEYS
178 %define EXCLUDE
179 %endif
180 %ifndef MODULE_STRINGS_COMPRESSED
181 %undef EXCLUDE
182 %endif
183%endif
184
185%ifndef EXCLUDE
186ALIGN STRING_JUMP_ALIGN
187Char_CharIsNotValid:
188 clc
189 ret
190%endif
191%undef EXCLUDE
192
193
194;--------------------------------------------------------------------
195; Char_ALtoLowerCaseLetter
196; Parameters:
197; AL: Character to convert
198; Returns:
199; AL: Character with possible conversion
200; Corrupts registers:
201; Nothing
202;--------------------------------------------------------------------
203%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
204ALIGN STRING_JUMP_ALIGN
205Char_ALtoLowerCaseLetter:
206 call Char_IsUpperCaseLetterInAL ; Is upper case character?
207 jmp SHORT Char_ALtoUpperCaseLetter.CheckCF
208%endif
209
210
211;--------------------------------------------------------------------
212; Char_ALtoUpperCaseLetter
213; Parameters:
214; AL: Character to convert
215; Returns:
216; AL: Character with possible conversion
217; Corrupts registers:
218; Nothing
219;--------------------------------------------------------------------
220%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
221ALIGN STRING_JUMP_ALIGN
222Char_ALtoUpperCaseLetter:
223 call Char_IsLowerCaseLetterInAL ; Is lower case character?
224.CheckCF:
225 jnc SHORT Char_ChangeCaseInAL.Return
226 ; Fall to Char_ChangeCaseInAL
227%endif
228
229
230;--------------------------------------------------------------------
231; Char_ChangeCaseInAL
232; Parameters:
233; AL: Character to convert (must be A-Z or a-z)
234; Returns:
235; AL: Character converted
236; Corrupts registers:
237; Nothing
238;--------------------------------------------------------------------
239%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
240Char_ChangeCaseInAL:
241 xor al, 32
242.Return:
243 ret
244%endif
245
246
247;--------------------------------------------------------------------
248; Char_GetFilterFunctionToDXforNumericBaseInBX
249; Parameters
250; BX: Numeric base (10 or 16)
251; Returns:
252; CS:DX: Ptr to character filter function
253; Corrupts registers:
254; Nothing
255;--------------------------------------------------------------------
256%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
257ALIGN STRING_JUMP_ALIGN
258Char_GetFilterFunctionToDXforNumericBaseInBX:
259 mov dx, Char_IsDecimalDigitInAL
260 cmp bl, 10
261 je SHORT .Return
262 mov dx, Char_IsHexadecimalDigitInAL
263.Return:
264 ret
265%endif
Note: See TracBrowser for help on using the repository browser.