[41] | 1 | ; Project name : Assembly Library
|
---|
| 2 | ; Description : Functions for handling characters.
|
---|
| 3 |
|
---|
[376] | 4 | ;
|
---|
[526] | 5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
| 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.
|
---|
[526] | 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
|
---|
[526] | 16 | ; GNU General Public License for more details.
|
---|
[376] | 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
[526] | 18 | ;
|
---|
[376] | 19 |
|
---|
[41] | 20 | ; Section containing code
|
---|
| 21 | SECTION .text
|
---|
| 22 |
|
---|
| 23 | ;--------------------------------------------------------------------
|
---|
[53] | 24 | ; String_ConvertDSSItoLowerCase
|
---|
| 25 | ; Parameters:
|
---|
| 26 | ; DS:SI: Ptr to string to convert
|
---|
| 27 | ; Returns:
|
---|
| 28 | ; CX: Number of characters processed
|
---|
| 29 | ; Corrupts registers:
|
---|
| 30 | ; Nothing
|
---|
| 31 | ;--------------------------------------------------------------------
|
---|
[369] | 32 | ALIGN STRING_JUMP_ALIGN
|
---|
[53] | 33 | String_ConvertDSSItoLowerCase:
|
---|
| 34 | push dx
|
---|
| 35 | push ax
|
---|
| 36 |
|
---|
| 37 | mov dx, StringProcess_ConvertToLowerCase
|
---|
| 38 | call StringProcess_DSSIwithFunctionInDX
|
---|
| 39 |
|
---|
| 40 | pop ax
|
---|
| 41 | pop dx
|
---|
| 42 | ret
|
---|
| 43 |
|
---|
| 44 |
|
---|
| 45 | ;--------------------------------------------------------------------
|
---|
[41] | 46 | ; String_ConvertWordToAXfromStringInDSSIwithBaseInBX
|
---|
| 47 | ; Parameters:
|
---|
| 48 | ; BX: Numeric base (10 or 16)
|
---|
| 49 | ; DS:SI: Ptr to string to convert
|
---|
| 50 | ; Returns:
|
---|
| 51 | ; AX: Word converted from string
|
---|
[53] | 52 | ; CX: Number of characters processed
|
---|
[293] | 53 | ; CF: Cleared if successful
|
---|
[52] | 54 | ; Set if error during conversion
|
---|
[41] | 55 | ; Corrupts registers:
|
---|
[52] | 56 | ; Nothing
|
---|
[41] | 57 | ;--------------------------------------------------------------------
|
---|
[369] | 58 | ALIGN STRING_JUMP_ALIGN
|
---|
[41] | 59 | String_ConvertWordToAXfromStringInDSSIwithBaseInBX:
|
---|
[52] | 60 | push di
|
---|
| 61 | push dx
|
---|
[41] | 62 |
|
---|
[52] | 63 | xor di, di
|
---|
| 64 | mov dx, StringProcess_ConvertToWordInDIWithBaseInBX
|
---|
| 65 | call StringProcess_DSSIwithFunctionInDX
|
---|
| 66 | xchg ax, di
|
---|
[41] | 67 |
|
---|
[52] | 68 | pop dx
|
---|
| 69 | pop di
|
---|
[41] | 70 | ret
|
---|
| 71 |
|
---|
| 72 |
|
---|
| 73 | ;--------------------------------------------------------------------
|
---|
[53] | 74 | ; String_CopyDSSItoESDIandGetLengthToCX
|
---|
[41] | 75 | ; Parameters:
|
---|
| 76 | ; DS:SI: Ptr to source NULL terminated string
|
---|
| 77 | ; ES:DI: Ptr to destination buffer
|
---|
| 78 | ; Returns:
|
---|
| 79 | ; CX: Number of characters copied
|
---|
| 80 | ; SI,DI: Updated by CX characters
|
---|
[621] | 81 | ; CF: Cleared
|
---|
[41] | 82 | ; Corrupts registers:
|
---|
| 83 | ; Nothing
|
---|
| 84 | ;--------------------------------------------------------------------
|
---|
[369] | 85 | ALIGN STRING_JUMP_ALIGN
|
---|
[53] | 86 | String_CopyDSSItoESDIandGetLengthToCX:
|
---|
[41] | 87 | push ax
|
---|
[52] | 88 |
|
---|
[41] | 89 | xor cx, cx
|
---|
[369] | 90 | ALIGN STRING_JUMP_ALIGN
|
---|
[52] | 91 | .CopyNextCharacter:
|
---|
[41] | 92 | lodsb ; Load from DS:SI to AL
|
---|
[621] | 93 | test al, al ; NULL to end string? (Clears CF)
|
---|
| 94 | jz SHORT PopAXandReturn
|
---|
[41] | 95 | stosb ; Store from AL to ES:DI
|
---|
| 96 | inc cx ; Increment number of characters written
|
---|
[52] | 97 | jmp SHORT .CopyNextCharacter
|
---|
[41] | 98 |
|
---|
[46] | 99 |
|
---|
| 100 | ;--------------------------------------------------------------------
|
---|
[52] | 101 | ; String_GetLengthFromDSSItoCX
|
---|
[46] | 102 | ; Parameters:
|
---|
[52] | 103 | ; DS:SI: Ptr to NULL terminated string
|
---|
[46] | 104 | ; Returns:
|
---|
[52] | 105 | ; CX: String length in characters
|
---|
[46] | 106 | ; Corrupts registers:
|
---|
| 107 | ; Nothing
|
---|
| 108 | ;--------------------------------------------------------------------
|
---|
[369] | 109 | ALIGN STRING_JUMP_ALIGN
|
---|
[52] | 110 | String_GetLengthFromDSSItoCX:
|
---|
| 111 | push ax
|
---|
[46] | 112 | push si
|
---|
| 113 |
|
---|
[54] | 114 | call Registers_ExchangeDSSIwithESDI
|
---|
[52] | 115 | xor ax, ax ; Find NULL
|
---|
| 116 | mov cx, -1 ; Full segment if necessary
|
---|
| 117 | repne scasb
|
---|
| 118 | mov cx, di
|
---|
[54] | 119 | call Registers_ExchangeDSSIwithESDI
|
---|
[46] | 120 |
|
---|
[52] | 121 | pop si
|
---|
| 122 | stc
|
---|
| 123 | sbb cx, si ; Subtract NULL
|
---|
[621] | 124 | PopAXandReturn:
|
---|
[46] | 125 | pop ax
|
---|
| 126 | ret
|
---|