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-2023 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 | xchg bx, ax
|
---|
54 | inc ax
|
---|
55 | eLEAVE_STRUCT ITEM_LINE_SPLITTER_size
|
---|
56 | pop di
|
---|
57 | ret
|
---|
58 |
|
---|
59 |
|
---|
60 | ;--------------------------------------------------------------------
|
---|
61 | ; ItemLineSplitter_GetLineToDSSIandLengthToCXfromStringInDSSIwithIndexInCX
|
---|
62 | ; Parameters:
|
---|
63 | ; CX: Index of line to search for
|
---|
64 | ; DS:SI: Ptr to string
|
---|
65 | ; SS:BP: Ptr to MENU
|
---|
66 | ; Returns:
|
---|
67 | ; CX: Line length
|
---|
68 | ; DS:SI: Ptr to beginning of line
|
---|
69 | ; CF: Set if wanted line was found
|
---|
70 | ; Corrupts registers:
|
---|
71 | ; AX, BX, DX
|
---|
72 | ;--------------------------------------------------------------------
|
---|
73 | ALIGN JUMP_ALIGN
|
---|
74 | ItemLineSplitter_GetLineToDSSIandLengthToCXfromStringInDSSIwithIndexInCX:
|
---|
75 | push di
|
---|
76 |
|
---|
77 | call MenuLocation_GetMaxTextLineLengthToAX
|
---|
78 | eENTER_STRUCT ITEM_LINE_SPLITTER_size
|
---|
79 | mov [bp+ITEM_LINE_SPLITTER.wMaxTextLineLength], ax
|
---|
80 | mov [bp+ITEM_LINE_SPLITTER.wLineToFind], cx
|
---|
81 | mov [bp+ITEM_LINE_SPLITTER.wStartOfLine], si
|
---|
82 |
|
---|
83 | xor bx, bx ; Line index
|
---|
84 | mov di, si ; Start of first word
|
---|
85 | mov dx, ProcessCharacterFromStringToSplit
|
---|
86 | call StringProcess_DSSIwithFunctionInDX
|
---|
87 |
|
---|
88 | mov si, [bp+ITEM_LINE_SPLITTER.wStartOfLine]
|
---|
89 | jc SHORT .ReturnLineInDSSIandLengthInCX
|
---|
90 | call String_GetLengthFromDSSItoCX ; Last or invalid line. Just return last line.
|
---|
91 |
|
---|
92 | ALIGN JUMP_ALIGN
|
---|
93 | .ReturnLineInDSSIandLengthInCX:
|
---|
94 | eLEAVE_STRUCT ITEM_LINE_SPLITTER_size
|
---|
95 | pop di
|
---|
96 | stc
|
---|
97 | ret
|
---|
98 |
|
---|
99 |
|
---|
100 | ;--------------------------------------------------------------------
|
---|
101 | ; Character processing callback function prototype for StringProcess_DSSIwithFunctionInBX.
|
---|
102 | ; ProcessCharacterFromStringToSplit
|
---|
103 | ; Parameters:
|
---|
104 | ; AL: Character to process
|
---|
105 | ; BX: Line index
|
---|
106 | ; CX: Number of characters processed (Characters on line so far)
|
---|
107 | ; DS:SI: Ptr to next character
|
---|
108 | ; DS:DI: Start of current word
|
---|
109 | ; SS:BP: Ptr to ITEM_LINE_SPLITTER
|
---|
110 | ; Returns:
|
---|
111 | ; CF: Clear to continue with next character
|
---|
112 | ; Set to stop processing
|
---|
113 | ; BX: Line index
|
---|
114 | ; CX: Characters on line so far
|
---|
115 | ; DS:DI: Start of current word
|
---|
116 | ; Corrupts registers:
|
---|
117 | ; AX
|
---|
118 | ;--------------------------------------------------------------------
|
---|
119 | ALIGN JUMP_ALIGN
|
---|
120 | ProcessCharacterFromStringToSplit:
|
---|
121 | cmp al, ' '
|
---|
122 | jbe SHORT .ControlCharacterOrSpace
|
---|
123 |
|
---|
124 | .CheckLineLength:
|
---|
125 | cmp [bp+ITEM_LINE_SPLITTER.wMaxTextLineLength], cx
|
---|
126 | jb SHORT .ChangeToNextLine
|
---|
127 | ret ; With CF cleared
|
---|
128 |
|
---|
129 | ALIGN JUMP_ALIGN
|
---|
130 | .ChangeToNextLine:
|
---|
131 | cmp bx, [bp+ITEM_LINE_SPLITTER.wLineToFind]
|
---|
132 | je SHORT .WantedLineFound
|
---|
133 |
|
---|
134 | inc bx ; Increment line
|
---|
135 | mov si, di ; Start from complete word
|
---|
136 | mov [bp+ITEM_LINE_SPLITTER.wStartOfLine], di
|
---|
137 | .CarriageReturn:
|
---|
138 | xor cx, cx ; Zero character counter (and clear CF)
|
---|
139 | ret
|
---|
140 |
|
---|
141 | ALIGN JUMP_ALIGN
|
---|
142 | .ControlCharacterOrSpace:
|
---|
143 | mov di, si ; DS:DI now points start of new word
|
---|
144 | je SHORT .CheckLineLength ; Jump if space
|
---|
145 | cmp al, LF
|
---|
146 | je SHORT .ChangeToNextLine
|
---|
147 | cmp al, CR
|
---|
148 | je SHORT .CarriageReturn ; Reset line length
|
---|
149 | ; Unsupported control character - ignore it
|
---|
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
|
---|