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