source: xtideuniversalbios/trunk/Assembly_Library/Src/Menu/Dialog/ItemLineSplitter.asm@ 143

Last change on this file since 143 was 133, checked in by krille_n_@…, 14 years ago

Size optimizations in various files in the Assembly Library. Also a very small change to a string in XTIDE_Universal_BIOS_Configurator_v2/Src/Strings.asm

File size: 4.0 KB
RevLine 
[52]1; Project name : Assembly Library
2; Description : Functions for splitting strings to item lines.
3
4struc ITEM_LINE_SPLITTER
5 .wMaxTextLineLength resb 2
6 .wLineToFind resb 2
7 .wStartOfLine resb 2
8endstruc
9
10; Section containing code
11SECTION .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;--------------------------------------------------------------------
23ALIGN JUMP_ALIGN
24ItemLineSplitter_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;--------------------------------------------------------------------
56ALIGN JUMP_ALIGN
57ItemLineSplitter_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
75ALIGN 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;--------------------------------------------------------------------
102ALIGN JUMP_ALIGN
103ProcessCharacterFromStringToSplit:
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
115ALIGN JUMP_ALIGN
116.CheckLineLength:
117 cmp cx, [bp+ITEM_LINE_SPLITTER.wMaxTextLineLength]
118 ja SHORT .ChangeToNextLine
119 clc
120 ret
121
122ALIGN JUMP_ALIGN
123.ChangeToNextLine:
124 cmp bx, [bp+ITEM_LINE_SPLITTER.wLineToFind]
125 je SHORT .WantedLineFound
126
127 inc bx ; Increment line
[133]128 xor cx, cx ; Zero character counter (and clear CF)
[52]129 mov si, di ; Start from complete word
130 mov [bp+ITEM_LINE_SPLITTER.wStartOfLine], di
131 ret
132
133ALIGN JUMP_ALIGN
134.IgnoreUnsupportedControlCharacter:
135 dec cx
136 clc
137 ret
138
139ALIGN JUMP_ALIGN
140.WantedLineFound:
141 lea cx, [di-1]
142 sub cx, [bp+ITEM_LINE_SPLITTER.wStartOfLine]
143 stc
144 ret
Note: See TracBrowser for help on using the repository browser.