[52] | 1 | ; Project name : Assembly Library
|
---|
| 2 | ; Description : Functions for processing characters in a string.
|
---|
| 3 |
|
---|
[376] | 4 | ;
|
---|
| 5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
| 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
|
---|
| 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.
|
---|
| 12 | ;
|
---|
| 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
|
---|
| 16 | ; GNU General Public License for more details.
|
---|
| 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
| 18 | ;
|
---|
| 19 |
|
---|
[52] | 20 | ; Section containing code
|
---|
| 21 | SECTION .text
|
---|
| 22 |
|
---|
| 23 | ;--------------------------------------------------------------------
|
---|
[67] | 24 | ; Character processing callback function prototype for StringProcess_DSSIwithFunctionInDX.
|
---|
[52] | 25 | ; Parameters:
|
---|
| 26 | ; AL: Character to process
|
---|
[67] | 27 | ; CX: Character number (index for next character)
|
---|
[52] | 28 | ; DS:SI: Ptr to next character
|
---|
| 29 | ; BX,DI,ES: Free to use by processing function
|
---|
| 30 | ; Returns:
|
---|
| 31 | ; CF: Clear to continue with next character
|
---|
| 32 | ; Set to stop processing
|
---|
| 33 | ; BX,DI,ES: Free to use by processing function
|
---|
| 34 | ; Corrupts registers:
|
---|
| 35 | ; AX
|
---|
| 36 | ;--------------------------------------------------------------------
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 | ;--------------------------------------------------------------------
|
---|
| 40 | ; StringProcess_DSSIwithFunctionInDX
|
---|
| 41 | ; Parameters:
|
---|
| 42 | ; DX: Character processing function
|
---|
| 43 | ; DS:SI: Ptr to NULL terminated string to convert
|
---|
| 44 | ; Returns:
|
---|
| 45 | ; CX: Number of characters processed
|
---|
| 46 | ; CF: Clear if all characters processed
|
---|
[162] | 47 | ; Set if terminated by processing function
|
---|
[52] | 48 | ; Corrupts registers:
|
---|
| 49 | ; Nothing (processing function can corrupt BX,DI,ES)
|
---|
| 50 | ;--------------------------------------------------------------------
|
---|
[369] | 51 | ALIGN STRING_JUMP_ALIGN
|
---|
[52] | 52 | StringProcess_DSSIwithFunctionInDX:
|
---|
| 53 | push si
|
---|
| 54 | push ax
|
---|
| 55 |
|
---|
| 56 | xor cx, cx
|
---|
[369] | 57 | ALIGN STRING_JUMP_ALIGN
|
---|
[52] | 58 | .ProcessNextCharacter:
|
---|
| 59 | lodsb
|
---|
| 60 | test al, al ; NULL to end string
|
---|
| 61 | jz SHORT .EndOfString ; Return with CF cleared
|
---|
| 62 | inc cx
|
---|
| 63 | call dx
|
---|
| 64 | jnc SHORT .ProcessNextCharacter
|
---|
| 65 |
|
---|
[369] | 66 | ALIGN STRING_JUMP_ALIGN
|
---|
[52] | 67 | .EndOfString:
|
---|
| 68 | pop ax
|
---|
| 69 | pop si
|
---|
| 70 | ret
|
---|
| 71 |
|
---|
| 72 |
|
---|
| 73 | ;--------------------------------------------------------------------
|
---|
| 74 | ; StringProcess_ConvertToLowerCase (callback function for StringProcess_DSSIwithFunctionInDX)
|
---|
| 75 | ; Parameters:
|
---|
| 76 | ; AL: Character to convert to lower case
|
---|
| 77 | ; DS:SI: Ptr to next character
|
---|
| 78 | ; Returns:
|
---|
| 79 | ; CF: Clear to continue processing
|
---|
| 80 | ; Corrupts registers:
|
---|
| 81 | ; AL
|
---|
| 82 | ;--------------------------------------------------------------------
|
---|
[369] | 83 | ALIGN STRING_JUMP_ALIGN
|
---|
[52] | 84 | StringProcess_ConvertToLowerCase:
|
---|
| 85 | call Char_ALtoLowerCaseLetter
|
---|
| 86 | mov [si-1], al
|
---|
| 87 | clc
|
---|
| 88 | ret
|
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 | ;--------------------------------------------------------------------
|
---|
| 92 | ; StringProcess_ConvertToWordInDIWithBaseInBX (callback function for StringProcess_DSSIwithFunctionInDX)
|
---|
| 93 | ; Parameters:
|
---|
| 94 | ; AL: Character to convert to lower case
|
---|
| 95 | ; BX: Numeric base (2, 10 or 16)
|
---|
| 96 | ; Returns:
|
---|
| 97 | ; CF: Clear to continue processing
|
---|
| 98 | ; Set if error
|
---|
| 99 | ; Corrupts registers:
|
---|
| 100 | ; AX
|
---|
| 101 | ;--------------------------------------------------------------------
|
---|
[369] | 102 | ALIGN STRING_JUMP_ALIGN
|
---|
[52] | 103 | StringProcess_ConvertToWordInDIWithBaseInBX:
|
---|
| 104 | call Char_ConvertIntegerToALfromDigitInALwithBaseInBX
|
---|
[162] | 105 | cmc
|
---|
| 106 | jc SHORT .InvalidCharacter
|
---|
[52] | 107 | push dx
|
---|
| 108 |
|
---|
| 109 | xor ah, ah ; Digit converted to integer now in AX
|
---|
| 110 | xchg ax, di
|
---|
| 111 | mul bx ; Old WORD *= base
|
---|
| 112 | jc SHORT .Overflow
|
---|
| 113 | add di, ax ; Add old WORD to new integer
|
---|
| 114 |
|
---|
| 115 | .Overflow:
|
---|
| 116 | pop dx
|
---|
| 117 | .InvalidCharacter:
|
---|
| 118 | ret
|
---|