[41] | 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 |
---|
[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 | ;-------------------------------------------------------------------- |
---|
| 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 | ;-------------------------------------------------------------------- |
---|
[162] | 52 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS |
---|
[41] | 53 | ALIGN JUMP_ALIGN |
---|
| 54 | Char_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] | 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 |
---|
[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 | ;-------------------------------------------------------------------- |
---|
| 90 | ALIGN JUMP_ALIGN |
---|
| 91 | Char_IsDecimalDigitInAL: |
---|
| 92 | IS_BETWEEN_IMMEDIATES al, '0', '9' |
---|
| 93 | ret |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | ;-------------------------------------------------------------------- |
---|
| 97 | ; Char_ConvertIntegerToALfromDigitInALwithBaseInBX |
---|
| 98 | ; Parameters: |
---|
| 99 | ; AL: Character to convert |
---|
| 100 | ; BX: Numeric base (10 or 16) |
---|
| 101 | ; Returns: |
---|
| 102 | ; AL: Character converted to integer |
---|
| 103 | ; CF: Set if character was valid |
---|
| 104 | ; Cleared if character was invalid |
---|
| 105 | ; Corrupts registers: |
---|
| 106 | ; Nothing |
---|
| 107 | ;-------------------------------------------------------------------- |
---|
[162] | 108 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS |
---|
[41] | 109 | ALIGN JUMP_ALIGN |
---|
| 110 | Char_ConvertIntegerToALfromDigitInALwithBaseInBX: |
---|
| 111 | push dx |
---|
| 112 | call Char_GetFilterFunctionToDXforNumericBaseInBX |
---|
| 113 | call dx ; Converts to lower case |
---|
| 114 | pop dx |
---|
[162] | 115 | jnc SHORT Char_CharIsNotValid |
---|
[41] | 116 | |
---|
| 117 | cmp al, '9' ; Decimal digit |
---|
| 118 | jbe SHORT .ConvertToDecimalDigit |
---|
[145] | 119 | sub al, 'a'-'0'-10 ; Convert to hexadecimal integer |
---|
[41] | 120 | ALIGN JUMP_ALIGN |
---|
| 121 | .ConvertToDecimalDigit: |
---|
| 122 | sub al, '0' ; Convert to decimal integer |
---|
[162] | 123 | ; Fall to Char_CharIsValid |
---|
| 124 | %endif |
---|
[41] | 125 | |
---|
| 126 | ;-------------------------------------------------------------------- |
---|
[162] | 127 | ; Char_CharIsValid |
---|
| 128 | ; Char_CharIsNotValid |
---|
[41] | 129 | ; Parameters: |
---|
| 130 | ; Nothing |
---|
| 131 | ; Returns: |
---|
[162] | 132 | ; CF: Set for Char_CharIsValid |
---|
| 133 | ; Cleared for Char_CharIsNotValid |
---|
[41] | 134 | ; Corrupts registers: |
---|
| 135 | ; Nothing |
---|
| 136 | ;-------------------------------------------------------------------- |
---|
[162] | 137 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS |
---|
[41] | 138 | ALIGN JUMP_ALIGN |
---|
| 139 | Char_CharIsValid: |
---|
| 140 | stc |
---|
| 141 | ret |
---|
[162] | 142 | %endif |
---|
[41] | 143 | |
---|
| 144 | ALIGN JUMP_ALIGN |
---|
[162] | 145 | Char_CharIsNotValid: |
---|
[41] | 146 | clc |
---|
| 147 | ret |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | ;-------------------------------------------------------------------- |
---|
| 151 | ; Char_ALtoLowerCaseLetter |
---|
| 152 | ; Parameters: |
---|
| 153 | ; AL: Character to convert |
---|
| 154 | ; Returns: |
---|
| 155 | ; AL: Character with possible conversion |
---|
| 156 | ; Corrupts registers: |
---|
| 157 | ; Nothing |
---|
| 158 | ;-------------------------------------------------------------------- |
---|
[162] | 159 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS |
---|
[41] | 160 | ALIGN JUMP_ALIGN |
---|
| 161 | Char_ALtoLowerCaseLetter: |
---|
| 162 | call Char_IsUpperCaseLetterInAL ; Is upper case character? |
---|
| 163 | jnc SHORT .Return ; If not, return |
---|
| 164 | add al, 'a'-'A' ; Convert to lower case |
---|
| 165 | .Return: |
---|
| 166 | ret |
---|
[162] | 167 | %endif |
---|
[41] | 168 | |
---|
| 169 | ;-------------------------------------------------------------------- |
---|
| 170 | ; Char_ALtoUpperCaseLetter |
---|
| 171 | ; Parameters: |
---|
| 172 | ; AL: Character to convert |
---|
| 173 | ; Returns: |
---|
| 174 | ; AL: Character with possible conversion |
---|
| 175 | ; Corrupts registers: |
---|
| 176 | ; Nothing |
---|
| 177 | ;-------------------------------------------------------------------- |
---|
| 178 | ALIGN JUMP_ALIGN |
---|
| 179 | Char_ALtoUpperCaseLetter: |
---|
| 180 | call Char_IsLowerCaseLetterInAL ; Is lower case character? |
---|
| 181 | jnc SHORT .Return ; If not, return |
---|
| 182 | sub al, 'a'-'A' ; Convert to upper case |
---|
| 183 | .Return: |
---|
| 184 | ret |
---|
| 185 | |
---|
| 186 | |
---|
| 187 | ;-------------------------------------------------------------------- |
---|
| 188 | ; Char_GetFilterFunctionToDXforNumericBaseInBX |
---|
| 189 | ; Parameters |
---|
| 190 | ; BX: Numeric base (10 or 16) |
---|
| 191 | ; Returns: |
---|
| 192 | ; CS:DX: Ptr to character filter function |
---|
| 193 | ; Corrupts registers: |
---|
| 194 | ; Nothing |
---|
| 195 | ;-------------------------------------------------------------------- |
---|
[162] | 196 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS |
---|
[41] | 197 | ALIGN JUMP_ALIGN |
---|
| 198 | Char_GetFilterFunctionToDXforNumericBaseInBX: |
---|
| 199 | mov dx, Char_IsDecimalDigitInAL |
---|
| 200 | cmp bl, 10 |
---|
| 201 | je SHORT .Return |
---|
[162] | 202 | mov dx, Char_IsHexadecimalDigitInAL |
---|
[41] | 203 | .Return: |
---|
| 204 | ret |
---|
[162] | 205 | %endif |
---|