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

Last change on this file since 477 was 376, checked in by gregli@…, 13 years ago

WIDE checkin... Added copyright and license information to sorce files, as per the GPL instructions for usage.

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; Char_ALtoUpperCaseLetter
185; Parameters:
186; AL: Character to convert
187; Returns:
188; AL: Character with possible conversion
189; Corrupts registers:
190; Nothing
191;--------------------------------------------------------------------
192ALIGN STRING_JUMP_ALIGN
193Char_ALtoUpperCaseLetter:
194 call Char_IsLowerCaseLetterInAL ; Is lower case character?
195.CheckCF:
196 jnc SHORT Char_ChangeCaseInAL.Return
197 ; Fall to Char_ChangeCaseInAL
198
199;--------------------------------------------------------------------
200; Char_ChangeCaseInAL
201; Parameters:
202; AL: Character to convert (must be A-Z or a-z)
203; Returns:
204; AL: Character converted
205; Corrupts registers:
206; Nothing
207;--------------------------------------------------------------------
208Char_ChangeCaseInAL:
209 xor al, 32
210.Return:
211 ret
212
213;--------------------------------------------------------------------
214; Char_GetFilterFunctionToDXforNumericBaseInBX
215; Parameters
216; BX: Numeric base (10 or 16)
217; Returns:
218; CS:DX: Ptr to character filter function
219; Corrupts registers:
220; Nothing
221;--------------------------------------------------------------------
222%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
223ALIGN STRING_JUMP_ALIGN
224Char_GetFilterFunctionToDXforNumericBaseInBX:
225 mov dx, Char_IsDecimalDigitInAL
226 cmp bl, 10
227 je SHORT .Return
228 mov dx, Char_IsHexadecimalDigitInAL
229.Return:
230 ret
231%endif
Note: See TracBrowser for help on using the repository browser.