OSDN Git Service

fixed an issue of bakapi.exe while in pan mode you cannot escape until you press...
[proj16/16.git] / 16 / ADT2PLAY / parserio.pas
1 unit ParserIO;
2 interface
3
4 type
5   tDUMMY_BUFF = array[0..PRED(655350)] of Byte;
6
7 function Scan(var buf; skip,size: Longint; str: String): Longint;
8 function SensitiveScan(var buf; skip,size: Longint; str: String): Longint;
9 function Compare(var buf1,buf2; size: Longint): Boolean;
10 function Empty(var buf; size: Longint): Boolean;
11 function CountLines(var buf; size: Longint): Longint;
12 function Update16(var buf; size: Longint; crc: Word): Word;
13 function Update32(var buf; size: Longint; crc: Longint): Longint;
14
15 implementation
16
17 var
18   CRC16_table: array[BYTE] of Word;
19   CRC32_table: array[BYTE] of Longint;
20
21 function Scan(var buf; skip,size: Longint; str: String): Longint; assembler;
22 asm
23         mov     edi,[str]
24         mov     esi,[str]
25         xor     eax,eax
26         lodsb
27         stosb
28         xor     ecx,ecx
29         mov     ecx,eax
30         xor     ebx,ebx
31         mov     ebx,eax
32         jecxz    @@9
33 @@1:    lodsb
34         cmp     al,'a'
35         jb      @@2
36         cmp     al,'z'
37         ja      @@2
38         sub     al,20h
39 @@2:    stosb
40         loop    @@1
41         sub     edi,ebx
42         mov     esi,[buf]
43         add     esi,skip
44         mov     ecx,size
45         sub     ecx,skip
46         jecxz   @@8
47         cld
48         sub     ecx,ebx
49         jb      @@8
50         inc     ecx
51 @@4:    mov     ah,[edi]
52         and     ah,NOT 20h
53 @@5:    lodsb
54         and     al,NOT 20h
55         cmp     al,ah
56         loopne  @@5
57         jne     @@8
58         dec     esi
59         mov     edx,ecx
60         mov     ecx,ebx
61 @@6:    repe    cmpsb
62         je      @@10
63         mov     al,[esi-1]
64         cmp     al,'a'
65         jb      @@7
66         cmp     al,'z'
67         ja      @@7
68         sub     al,20h
69 @@7:    cmp     al,[edi-1]
70         je      @@6
71         sub     ecx,ebx
72         add     esi,ecx
73         add     edi,ecx
74         inc     esi
75         mov     ecx,edx
76         jne     @@4
77 @@8:    xor     eax,eax
78         jmp     @@11
79 @@9:    mov     eax,1
80         jmp     @@11
81 @@10:   sub     esi,ebx
82         mov     eax,esi
83         sub     eax,dword ptr buf
84         inc     eax
85 @@11:   dec     eax
86 end;
87
88 function SensitiveScan(var buf; skip,size: Longint; str: String): Longint; assembler;
89 asm
90         mov     edi,[buf]
91         add     edi,skip
92         mov     esi,[str]
93         mov     ecx,size
94         sub     ecx,skip
95         xor     eax,eax
96         jecxz   @@3
97         cld
98         lodsb
99         cmp     al,1
100         jb      @@5
101         ja      @@1
102         lodsb
103         repne   scasb
104         jne     @@3
105         jmp     @@5
106 @@1:    xor     ah,ah
107         mov     ebx,eax
108         dec     ebx
109         mov     edx,ecx
110         sub     edx,eax
111         jb      @@3
112         lodsb
113         add     edx,2
114 @@2:    dec     edx
115         mov     ecx,edx
116         repne   scasb
117         jne     @@3
118         mov     edx,ecx
119         mov     ecx,ebx
120         rep     cmpsb
121         je      @@4
122         sub     ecx,ebx
123         add     esi,ecx
124         add     edi,ecx
125         inc     edi
126         or      edx,edx
127         jne     @@2
128 @@3:    xor     eax,eax
129         jmp     @@6
130 @@4:    sub     edi,ebx
131 @@5:    mov     eax,edi
132         sub     eax,dword ptr buf
133 @@6:    dec     eax
134 end;
135
136 function Compare(var buf1,buf2; size: Longint): Boolean; assembler;
137 asm
138         xor     edx,edx
139         mov     eax,size
140         cmp     eax,16
141         jb      @@3
142         mov     ecx,4
143         div     ecx
144         mov     ecx,eax
145         jecxz   @@1
146         mov     esi,[buf1]
147         mov     edi,[buf2]
148         cld
149         repz    cmpsd
150         jnz     @@2
151         mov     ecx,edx
152         jecxz   @@1
153         repz    cmpsb
154         jnz     @@2
155 @@1:    mov     al,1
156         jmp     @@6
157 @@2:    xor     al,al
158         jmp     @@6
159 @@3:    mov     ecx,size
160         jecxz   @@4
161         mov     esi,[buf1]
162         mov     edi,[buf2]
163         cld
164         repz    cmpsb
165         jnz     @@5
166 @@4:    mov     al,1
167         jmp     @@6
168 @@5:    xor     al,al
169 @@6:
170 end;
171
172 function Empty(var buf; size: Longint): Boolean; assembler;
173 asm
174         xor     edx,edx
175         mov     eax,size
176         cmp     eax,16
177         jb      @@3
178         mov     ecx,4
179         div     ecx
180         mov     ecx,eax
181         jecxz   @@1
182         mov     edi,[buf]
183         xor     eax,eax
184         repz    scasd
185         jnz     @@2
186         mov     ecx,edx
187         jecxz   @@1
188         repz    scasb
189         jnz     @@2
190 @@1:    mov     al,1
191         jmp     @@6
192 @@2:    xor     al,al
193         jmp     @@6
194 @@3:    mov     ecx,size
195         jecxz   @@4
196         mov     edi,[buf]
197         xor     eax,eax
198         repz    scasb
199         jnz     @@5
200 @@4:    mov     al,1
201         jmp     @@6
202 @@5:    xor     al,al
203 @@6:
204 end;
205
206 function CountLines(var buf; size: Longint): Longint; assembler;
207 asm
208         mov     edi,[buf]
209         mov     ecx,size
210         mov     edx,edi
211         add     edx,ecx
212         xor     ebx,ebx
213         jecxz   @@3
214 @@1:    mov     al,0dh
215         repnz   scasb
216         jnz     @@3
217         cmp     byte ptr [edi],0ah
218         jnz     @@2
219         inc     edi
220         inc     ebx
221 @@2:    cmp     edi,edx
222         jb      @@1
223 @@3:    mov     eax,ebx
224 end;
225
226 function Update16(var buf; size: Longint; crc: Word): Word; assembler;
227 asm
228         mov     esi,[buf]
229         lea     edi,[CRC16_table]
230         mov     bx,crc
231         mov     ecx,size
232         jecxz   @@2
233 @@1:    xor     ax,ax
234         lodsb
235         mov     dl,bh
236         xor     dh,dh
237         xor     bh,bh
238         xor     bx,ax
239         and     ebx,000000ffh
240         shl     ebx,1
241         mov     bx,[edi+ebx]
242         xor     bx,dx
243         loop    @@1
244 @@2:    mov     ax,bx
245 end;
246
247 function Update32(var buf; size: Longint; crc: Longint): Longint; assembler;
248 asm
249         mov     esi,[buf]
250         lea     edi,[CRC32_table]
251         mov     ebx,crc
252         mov     ecx,size
253         jecxz   @@2
254 @@1:    xor     eax,eax
255         lodsb
256         xor     ebx,eax
257         mov     edx,ebx
258         and     ebx,000000ffh
259         shl     ebx,2
260         mov     ebx,[edi+ebx]
261         shr     edx,8
262         and     edx,00ffffffh
263         xor     ebx,edx
264         loop    @@1
265 @@2:    mov     eax,ebx
266 end;
267
268 procedure make_table_16bit;
269
270 var
271   crc: Word;
272   n,index: Byte;
273
274 begin
275   For index := 0 to 255 do
276   begin
277     crc := index;
278     For n := 1 to 8 do
279       If Odd(crc) then crc := crc SHR 1 XOR $0a001
280       else crc := crc SHR 1;
281     CRC16_table[index] := crc;
282   end;
283 end;
284
285 procedure make_table_32bit;
286
287 var
288   crc: DWord;
289   n,index: Byte;
290
291 begin
292   For index := 0 to 255 do
293     begin
294       crc := index;
295       For n := 1 to 8 do
296         If Odd(crc) then crc := crc SHR 1 XOR $0edb88320
297         else crc := crc SHR 1;
298       CRC32_table[index] := crc;
299     end;
300 end;
301
302 begin
303   make_table_16bit;
304   make_table_32bit;
305 end.