[52] | 1 | ; Project name : Assembly Library
|
---|
| 2 | ; Description : Functions for splitting strings to item lines.
|
---|
| 3 |
|
---|
| 4 | struc ITEM_LINE_SPLITTER
|
---|
| 5 | .wMaxTextLineLength resb 2
|
---|
| 6 | .wLineToFind resb 2
|
---|
| 7 | .wStartOfLine resb 2
|
---|
| 8 | endstruc
|
---|
| 9 |
|
---|
| 10 | ; Section containing code
|
---|
| 11 | SECTION .text
|
---|
| 12 |
|
---|
| 13 | ;--------------------------------------------------------------------
|
---|
| 14 | ; ItemLineSplitter_GetLinesToAXforStringInDSSI
|
---|
| 15 | ; Parameters:
|
---|
| 16 | ; DS:SI: Ptr to string
|
---|
| 17 | ; SS:BP: Ptr to MENU
|
---|
| 18 | ; Returns:
|
---|
| 19 | ; AX: Number of lines on string
|
---|
| 20 | ; Corrupts registers:
|
---|
| 21 | ; BX, CX, DX, SI
|
---|
| 22 | ;--------------------------------------------------------------------
|
---|
| 23 | ALIGN JUMP_ALIGN
|
---|
| 24 | ItemLineSplitter_GetLinesToAXforStringInDSSI:
|
---|
| 25 | push di
|
---|
| 26 |
|
---|
| 27 | call MenuLocation_GetMaxTextLineLengthToAX
|
---|
| 28 | eENTER_STRUCT ITEM_LINE_SPLITTER_size
|
---|
| 29 | mov [bp+ITEM_LINE_SPLITTER.wMaxTextLineLength], ax
|
---|
| 30 | mov WORD [bp+ITEM_LINE_SPLITTER.wLineToFind], -1
|
---|
| 31 |
|
---|
| 32 | xor bx, bx ; Line index
|
---|
| 33 | mov di, si ; Start of first word
|
---|
| 34 | mov dx, ProcessCharacterFromStringToSplit
|
---|
| 35 | call StringProcess_DSSIwithFunctionInDX
|
---|
| 36 |
|
---|
| 37 | lea ax, [bx+1]
|
---|
| 38 | eLEAVE_STRUCT ITEM_LINE_SPLITTER_size
|
---|
| 39 | pop di
|
---|
| 40 | ret
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 | ;--------------------------------------------------------------------
|
---|
| 44 | ; ItemLineSplitter_GetLineToDSSIandLengthToCXfromStringInDSSIwithIndexInCX
|
---|
| 45 | ; Parameters:
|
---|
| 46 | ; CX: Index of line to search for
|
---|
| 47 | ; DS:SI: Ptr to string
|
---|
| 48 | ; SS:BP: Ptr to MENU
|
---|
| 49 | ; Returns:
|
---|
| 50 | ; CX: Line length
|
---|
| 51 | ; DS:SI: Ptr to beginning of line
|
---|
| 52 | ; CF: Set if wanted line was found
|
---|
| 53 | ; Corrupts registers:
|
---|
| 54 | ; AX, BX, DX
|
---|
| 55 | ;--------------------------------------------------------------------
|
---|
| 56 | ALIGN JUMP_ALIGN
|
---|
| 57 | ItemLineSplitter_GetLineToDSSIandLengthToCXfromStringInDSSIwithIndexInCX:
|
---|
| 58 | push di
|
---|
| 59 |
|
---|
| 60 | call MenuLocation_GetMaxTextLineLengthToAX
|
---|
| 61 | eENTER_STRUCT ITEM_LINE_SPLITTER_size
|
---|
| 62 | mov [bp+ITEM_LINE_SPLITTER.wMaxTextLineLength], ax
|
---|
| 63 | mov [bp+ITEM_LINE_SPLITTER.wLineToFind], cx
|
---|
| 64 | mov [bp+ITEM_LINE_SPLITTER.wStartOfLine], si
|
---|
| 65 |
|
---|
| 66 | xor bx, bx ; Line index
|
---|
| 67 | mov di, si ; Start of first word
|
---|
| 68 | mov dx, ProcessCharacterFromStringToSplit
|
---|
| 69 | call StringProcess_DSSIwithFunctionInDX
|
---|
| 70 |
|
---|
| 71 | mov si, [bp+ITEM_LINE_SPLITTER.wStartOfLine]
|
---|
| 72 | jc SHORT .ReturnLineInDSSIandLengthInCX
|
---|
| 73 | call String_GetLengthFromDSSItoCX ; Last or invalid line. Just return last line.
|
---|
| 74 |
|
---|
| 75 | ALIGN JUMP_ALIGN
|
---|
| 76 | .ReturnLineInDSSIandLengthInCX:
|
---|
| 77 | eLEAVE_STRUCT ITEM_LINE_SPLITTER_size
|
---|
| 78 | pop di
|
---|
| 79 | stc
|
---|
| 80 | ret
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | ;--------------------------------------------------------------------
|
---|
| 84 | ; Character processing callback function prototype for StringProcess_DSSIwithFunctionInBX.
|
---|
| 85 | ; ProcessCharacterFromStringToSplit
|
---|
| 86 | ; Parameters:
|
---|
| 87 | ; AL: Character to process
|
---|
| 88 | ; BX: Line index
|
---|
| 89 | ; CX: Number of characters processed (Characters on line so far)
|
---|
| 90 | ; DS:SI: Ptr to next character
|
---|
| 91 | ; DS:DI: Start of current word
|
---|
| 92 | ; SS:BP: Ptr to ITEM_LINE_SPLITTER
|
---|
| 93 | ; Returns:
|
---|
| 94 | ; CF: Clear to continue with next character
|
---|
| 95 | ; Set to stop processing
|
---|
| 96 | ; BX: Line index
|
---|
| 97 | ; CX: Characters on line so far
|
---|
| 98 | ; DS:DI: Start of current word
|
---|
| 99 | ; Corrupts registers:
|
---|
| 100 | ; AX
|
---|
| 101 | ;--------------------------------------------------------------------
|
---|
| 102 | ALIGN JUMP_ALIGN
|
---|
| 103 | ProcessCharacterFromStringToSplit:
|
---|
| 104 | cmp al, ' '
|
---|
| 105 | ja SHORT .CheckLineLength
|
---|
| 106 | mov di, si ; DS:DI now points start of new word
|
---|
| 107 | je SHORT .CheckLineLength
|
---|
| 108 |
|
---|
| 109 | cmp al, LF
|
---|
| 110 | je SHORT .ChangeToNextLine
|
---|
| 111 | cmp al, CR
|
---|
| 112 | jne SHORT .IgnoreUnsupportedControlCharacter
|
---|
| 113 | xor cx, cx ; Carriage return so reset line length so far
|
---|
| 114 |
|
---|
| 115 | ALIGN JUMP_ALIGN
|
---|
| 116 | .CheckLineLength:
|
---|
[181] | 117 | cmp [bp+ITEM_LINE_SPLITTER.wMaxTextLineLength], cx
|
---|
| 118 | jb SHORT .ChangeToNextLine
|
---|
| 119 | ret ; With CF cleared
|
---|
[52] | 120 |
|
---|
| 121 | ALIGN JUMP_ALIGN
|
---|
| 122 | .ChangeToNextLine:
|
---|
| 123 | cmp bx, [bp+ITEM_LINE_SPLITTER.wLineToFind]
|
---|
| 124 | je SHORT .WantedLineFound
|
---|
| 125 |
|
---|
| 126 | inc bx ; Increment line
|
---|
[133] | 127 | xor cx, cx ; Zero character counter (and clear CF)
|
---|
[52] | 128 | mov si, di ; Start from complete word
|
---|
| 129 | mov [bp+ITEM_LINE_SPLITTER.wStartOfLine], di
|
---|
| 130 | ret
|
---|
| 131 |
|
---|
| 132 | ALIGN JUMP_ALIGN
|
---|
| 133 | .IgnoreUnsupportedControlCharacter:
|
---|
| 134 | dec cx
|
---|
| 135 | clc
|
---|
| 136 | ret
|
---|
| 137 |
|
---|
| 138 | ALIGN JUMP_ALIGN
|
---|
| 139 | .WantedLineFound:
|
---|
| 140 | lea cx, [di-1]
|
---|
| 141 | sub cx, [bp+ITEM_LINE_SPLITTER.wStartOfLine]
|
---|
| 142 | stc
|
---|
| 143 | ret
|
---|