1 | ; Project name : Assembly Library
|
---|
2 | ; Description : Functions for handling characters.
|
---|
3 |
|
---|
4 | ; Section containing code
|
---|
5 | SECTION .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
|
---|
16 | ; (Jumps to Char_CharIsNotValid if before range)
|
---|
17 | ; Corrupts registers:
|
---|
18 | ; Nothing
|
---|
19 | ;--------------------------------------------------------------------
|
---|
20 | %macro IS_BETWEEN_IMMEDIATES 3
|
---|
21 | cmp %1, %2
|
---|
22 | jb SHORT Char_CharIsNotValid
|
---|
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 | ;--------------------------------------------------------------------
|
---|
37 | ALIGN JUMP_ALIGN
|
---|
38 | Char_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 | ;--------------------------------------------------------------------
|
---|
52 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
53 | ALIGN JUMP_ALIGN
|
---|
54 | Char_IsUpperCaseLetterInAL:
|
---|
55 | IS_BETWEEN_IMMEDIATES al, 'A', 'Z'
|
---|
56 | ret
|
---|
57 | %endif
|
---|
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 | ;--------------------------------------------------------------------
|
---|
70 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
71 | ALIGN JUMP_ALIGN
|
---|
72 | Char_IsHexadecimalDigitInAL:
|
---|
73 | call Char_IsDecimalDigitInAL
|
---|
74 | jc SHORT Char_CharIsValid
|
---|
75 | call Char_ALtoLowerCaseLetter
|
---|
76 | IS_BETWEEN_IMMEDIATES al, 'a', 'f'
|
---|
77 | ret
|
---|
78 | %endif
|
---|
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 | ;--------------------------------------------------------------------
|
---|
90 | %ifndef MODULE_STRINGS_COMPRESSED
|
---|
91 | ALIGN JUMP_ALIGN
|
---|
92 | Char_IsDecimalDigitInAL:
|
---|
93 | IS_BETWEEN_IMMEDIATES al, '0', '9'
|
---|
94 | ret
|
---|
95 | %endif
|
---|
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 | ;--------------------------------------------------------------------
|
---|
109 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
110 | ALIGN JUMP_ALIGN
|
---|
111 | Char_ConvertIntegerToALfromDigitInALwithBaseInBX:
|
---|
112 | push dx
|
---|
113 | call Char_GetFilterFunctionToDXforNumericBaseInBX
|
---|
114 | call dx ; Converts to lower case
|
---|
115 | pop dx
|
---|
116 | jnc SHORT Char_CharIsNotValid
|
---|
117 |
|
---|
118 | cmp al, '9' ; Decimal digit
|
---|
119 | jbe SHORT .ConvertToDecimalDigit
|
---|
120 | sub al, 'a'-'0'-10 ; Convert to hexadecimal integer
|
---|
121 | ALIGN JUMP_ALIGN
|
---|
122 | .ConvertToDecimalDigit:
|
---|
123 | sub al, '0' ; Convert to decimal integer
|
---|
124 | ; Fall to Char_CharIsValid
|
---|
125 | %endif
|
---|
126 |
|
---|
127 | ;--------------------------------------------------------------------
|
---|
128 | ; Char_CharIsValid
|
---|
129 | ; Char_CharIsNotValid
|
---|
130 | ; Parameters:
|
---|
131 | ; Nothing
|
---|
132 | ; Returns:
|
---|
133 | ; CF: Set for Char_CharIsValid
|
---|
134 | ; Cleared for Char_CharIsNotValid
|
---|
135 | ; Corrupts registers:
|
---|
136 | ; Nothing
|
---|
137 | ;--------------------------------------------------------------------
|
---|
138 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
139 | ALIGN JUMP_ALIGN
|
---|
140 | Char_CharIsValid:
|
---|
141 | stc
|
---|
142 | ret
|
---|
143 | %endif
|
---|
144 |
|
---|
145 | ALIGN JUMP_ALIGN
|
---|
146 | Char_CharIsNotValid:
|
---|
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 | ;--------------------------------------------------------------------
|
---|
160 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
161 | ALIGN JUMP_ALIGN
|
---|
162 | Char_ALtoLowerCaseLetter:
|
---|
163 | call Char_IsUpperCaseLetterInAL ; Is upper case character?
|
---|
164 | jmp SHORT Char_ALtoUpperCaseLetter.CheckCF
|
---|
165 | %endif
|
---|
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 | ;--------------------------------------------------------------------
|
---|
176 | ALIGN JUMP_ALIGN
|
---|
177 | Char_ALtoUpperCaseLetter:
|
---|
178 | call Char_IsLowerCaseLetterInAL ; Is lower case character?
|
---|
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 | ;--------------------------------------------------------------------
|
---|
192 | Char_ChangeCaseInAL:
|
---|
193 | xor al, 32
|
---|
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 | ;--------------------------------------------------------------------
|
---|
206 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
207 | ALIGN JUMP_ALIGN
|
---|
208 | Char_GetFilterFunctionToDXforNumericBaseInBX:
|
---|
209 | mov dx, Char_IsDecimalDigitInAL
|
---|
210 | cmp bl, 10
|
---|
211 | je SHORT .Return
|
---|
212 | mov dx, Char_IsHexadecimalDigitInAL
|
---|
213 | .Return:
|
---|
214 | ret
|
---|
215 | %endif
|
---|