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

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

Fixed up conditional compilation so that we can continue to build without string compression.

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