[41] | 1 | ; Project name : Assembly Library
|
---|
| 2 | ; Description : Functions for handling characters.
|
---|
| 3 |
|
---|
[376] | 4 | ;
|
---|
[491] | 5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
[526] | 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
|
---|
[376] | 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.
|
---|
[491] | 12 | ;
|
---|
[376] | 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
|
---|
[491] | 16 | ; GNU General Public License for more details.
|
---|
[376] | 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
[491] | 18 | ;
|
---|
[376] | 19 |
|
---|
[41] | 20 | ; Section containing code
|
---|
| 21 | SECTION .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:
|
---|
[491] | 31 | ; CF: Set if character in range
|
---|
[162] | 32 | ; (Jumps to Char_CharIsNotValid if before range)
|
---|
[41] | 33 | ; Corrupts registers:
|
---|
| 34 | ; Nothing
|
---|
| 35 | ;--------------------------------------------------------------------
|
---|
| 36 | %macro IS_BETWEEN_IMMEDIATES 3
|
---|
| 37 | cmp %1, %2
|
---|
[162] | 38 | jb SHORT Char_CharIsNotValid
|
---|
[41] | 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 | ;--------------------------------------------------------------------
|
---|
[491] | 53 | %ifdef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
| 54 | %ifndef MODULE_HOTKEYS
|
---|
| 55 | %define EXCLUDE
|
---|
| 56 | %endif
|
---|
| 57 | %endif
|
---|
| 58 |
|
---|
| 59 | %ifndef EXCLUDE
|
---|
[369] | 60 | ALIGN STRING_JUMP_ALIGN
|
---|
[41] | 61 | Char_IsLowerCaseLetterInAL:
|
---|
| 62 | IS_BETWEEN_IMMEDIATES al, 'a', 'z'
|
---|
| 63 | ret
|
---|
[491] | 64 | %endif
|
---|
| 65 | %undef EXCLUDE
|
---|
[41] | 66 |
|
---|
[491] | 67 |
|
---|
[41] | 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 | ;--------------------------------------------------------------------
|
---|
[162] | 78 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
[369] | 79 | ALIGN STRING_JUMP_ALIGN
|
---|
[41] | 80 | Char_IsUpperCaseLetterInAL:
|
---|
| 81 | IS_BETWEEN_IMMEDIATES al, 'A', 'Z'
|
---|
| 82 | ret
|
---|
[162] | 83 | %endif
|
---|
[41] | 84 |
|
---|
[491] | 85 |
|
---|
[41] | 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 | ;--------------------------------------------------------------------
|
---|
[162] | 97 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
[369] | 98 | ALIGN STRING_JUMP_ALIGN
|
---|
[41] | 99 | Char_IsHexadecimalDigitInAL:
|
---|
| 100 | call Char_IsDecimalDigitInAL
|
---|
| 101 | jc SHORT Char_CharIsValid
|
---|
| 102 | call Char_ALtoLowerCaseLetter
|
---|
| 103 | IS_BETWEEN_IMMEDIATES al, 'a', 'f'
|
---|
| 104 | ret
|
---|
[162] | 105 | %endif
|
---|
[41] | 106 |
|
---|
[491] | 107 |
|
---|
[41] | 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 | ;--------------------------------------------------------------------
|
---|
[201] | 118 | %ifndef MODULE_STRINGS_COMPRESSED
|
---|
[369] | 119 | ALIGN STRING_JUMP_ALIGN
|
---|
[41] | 120 | Char_IsDecimalDigitInAL:
|
---|
| 121 | IS_BETWEEN_IMMEDIATES al, '0', '9'
|
---|
| 122 | ret
|
---|
[194] | 123 | %endif
|
---|
[41] | 124 |
|
---|
[491] | 125 |
|
---|
[41] | 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 | ;--------------------------------------------------------------------
|
---|
[162] | 138 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
[369] | 139 | ALIGN STRING_JUMP_ALIGN
|
---|
[41] | 140 | Char_ConvertIntegerToALfromDigitInALwithBaseInBX:
|
---|
| 141 | push dx
|
---|
| 142 | call Char_GetFilterFunctionToDXforNumericBaseInBX
|
---|
| 143 | call dx ; Converts to lower case
|
---|
| 144 | pop dx
|
---|
[162] | 145 | jnc SHORT Char_CharIsNotValid
|
---|
[41] | 146 |
|
---|
| 147 | cmp al, '9' ; Decimal digit
|
---|
| 148 | jbe SHORT .ConvertToDecimalDigit
|
---|
[145] | 149 | sub al, 'a'-'0'-10 ; Convert to hexadecimal integer
|
---|
[369] | 150 | ALIGN STRING_JUMP_ALIGN
|
---|
[41] | 151 | .ConvertToDecimalDigit:
|
---|
| 152 | sub al, '0' ; Convert to decimal integer
|
---|
[162] | 153 | ; Fall to Char_CharIsValid
|
---|
| 154 | %endif
|
---|
[41] | 155 |
|
---|
[491] | 156 |
|
---|
[41] | 157 | ;--------------------------------------------------------------------
|
---|
[162] | 158 | ; Char_CharIsValid
|
---|
| 159 | ; Char_CharIsNotValid
|
---|
[41] | 160 | ; Parameters:
|
---|
| 161 | ; Nothing
|
---|
| 162 | ; Returns:
|
---|
[162] | 163 | ; CF: Set for Char_CharIsValid
|
---|
| 164 | ; Cleared for Char_CharIsNotValid
|
---|
[41] | 165 | ; Corrupts registers:
|
---|
| 166 | ; Nothing
|
---|
| 167 | ;--------------------------------------------------------------------
|
---|
[162] | 168 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
[369] | 169 | ALIGN STRING_JUMP_ALIGN
|
---|
[41] | 170 | Char_CharIsValid:
|
---|
| 171 | stc
|
---|
| 172 | ret
|
---|
[162] | 173 | %endif
|
---|
[41] | 174 |
|
---|
[491] | 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
|
---|
[369] | 186 | ALIGN STRING_JUMP_ALIGN
|
---|
[162] | 187 | Char_CharIsNotValid:
|
---|
[41] | 188 | clc
|
---|
| 189 | ret
|
---|
[491] | 190 | %endif
|
---|
| 191 | %undef EXCLUDE
|
---|
[41] | 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 | ;--------------------------------------------------------------------
|
---|
[162] | 203 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
[369] | 204 | ALIGN STRING_JUMP_ALIGN
|
---|
[41] | 205 | Char_ALtoLowerCaseLetter:
|
---|
| 206 | call Char_IsUpperCaseLetterInAL ; Is upper case character?
|
---|
[181] | 207 | jmp SHORT Char_ALtoUpperCaseLetter.CheckCF
|
---|
[162] | 208 | %endif
|
---|
[41] | 209 |
|
---|
[491] | 210 |
|
---|
[41] | 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 | ;--------------------------------------------------------------------
|
---|
[491] | 220 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
[369] | 221 | ALIGN STRING_JUMP_ALIGN
|
---|
[41] | 222 | Char_ALtoUpperCaseLetter:
|
---|
| 223 | call Char_IsLowerCaseLetterInAL ; Is lower case character?
|
---|
[181] | 224 | .CheckCF:
|
---|
| 225 | jnc SHORT Char_ChangeCaseInAL.Return
|
---|
| 226 | ; Fall to Char_ChangeCaseInAL
|
---|
[489] | 227 | %endif
|
---|
[181] | 228 |
|
---|
[491] | 229 |
|
---|
[181] | 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 | ;--------------------------------------------------------------------
|
---|
[491] | 239 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
[181] | 240 | Char_ChangeCaseInAL:
|
---|
| 241 | xor al, 32
|
---|
[41] | 242 | .Return:
|
---|
| 243 | ret
|
---|
[491] | 244 | %endif
|
---|
[41] | 245 |
|
---|
[491] | 246 |
|
---|
[41] | 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 | ;--------------------------------------------------------------------
|
---|
[162] | 256 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
[369] | 257 | ALIGN STRING_JUMP_ALIGN
|
---|
[41] | 258 | Char_GetFilterFunctionToDXforNumericBaseInBX:
|
---|
| 259 | mov dx, Char_IsDecimalDigitInAL
|
---|
| 260 | cmp bl, 10
|
---|
| 261 | je SHORT .Return
|
---|
[162] | 262 | mov dx, Char_IsHexadecimalDigitInAL
|
---|
[41] | 263 | .Return:
|
---|
| 264 | ret
|
---|
[162] | 265 | %endif
|
---|