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

Last change on this file since 64 was 52, checked in by aitotat, 14 years ago

Changes to Assembly Library:
Completely rewritten line splitting (slower but no need to modify string).
Some changes to string processing functions.
Saved few bytes from CGA detection.

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