Rev 6471 | Rev 7129 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6471 | Rev 6502 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License. ;; |
4 | ;; Distributed under terms of the GNU General Public License. ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
7 | 7 | ||
8 | $Revision: 6471 $ |
- | |
9 | 8 | $Revision: 6502 $ |
|
10 | - | ||
11 | iglobal |
- | |
12 | ; pointer to memory for path replace table, |
- | |
13 | ; size of one record is 128 bytes: 64 bytes for search pattern + 64 bytes for replace string |
- | |
14 | 9 | ||
15 | ; start with one entry: sys -> |
10 | iglobal |
16 | full_file_name_table dd sysdir_name |
- | |
17 | .size dd 1 |
- | |
18 | 11 | full_file_name_table dd sysdir_name |
|
19 | tmp_file_name_size dd 1 |
12 | .size dd 1 |
20 | endg |
13 | endg |
21 | 14 | ||
22 | uglobal |
15 | uglobal |
23 | ; Parser_params will initialize: sysdir_name = "sys", sysdir_path = |
- | |
24 | sysdir_name rb 64 |
16 | sysdir_name rb 64 ; 'sys',0 |
25 | sysdir_path rb 64 |
17 | sysdir_path rb 64 |
26 | sysdir_name1 rb 64 |
18 | sysdir_name1 rb 64 |
27 | sysdir_path1 rb 64 |
19 | sysdir_path1 rb 64 |
28 | - | ||
29 | ; for example: |
- | |
30 | ;dir_name1 db 'KolibriOS',0 |
- | |
31 | ; rb 64-8 |
- | |
32 | ;dir_path1 db 'HD0/1',0 |
- | |
33 | ; rb 64-6 |
- | |
34 | endg |
- | |
35 | - | ||
36 | uglobal |
- | |
37 | tmp_file_name_table dd ? |
- | |
38 | endg |
20 | endg |
- | 21 | ; Example: |
|
- | 22 | ; align 64 |
|
- | 23 | ; sysdir_name1 db 'KolibriOS',0 |
|
- | 24 | ; align 64 |
|
- | 25 | ; sysdir_path1 db 'HD0/1',0 |
|
39 | - | ||
40 | ; use bx_from_load and init system directory /sys |
26 | |
41 | proc Parser_params |
27 | proc Parser_params |
42 | locals |
28 | locals |
43 | buff db 4 dup(?) ; for test cd |
29 | buff rb 4 ; for test cd |
44 | endl |
30 | endl |
45 | mov eax, [OS_BASE+0x10000+bx_from_load] |
31 | mov eax, [OS_BASE+0x10000+bx_from_load] |
46 | mov ecx, sysdir_path |
32 | mov ecx, sysdir_path |
47 | mov [ecx-64], dword 'sys' |
33 | mov [ecx-64], dword 'sys' |
- | 34 | mov [ecx-2], byte 3 |
|
- | 35 | mov [ecx-1], byte '/' |
|
48 | cmp al, 'r'; if ram disk |
36 | cmp al, 'r' ; ram disk |
49 | jnz @f |
37 | jnz @f |
50 | mov [ecx], dword 'RD/?' |
38 | mov [ecx], dword 'RD/?' |
51 | mov [ecx+3], byte ah |
39 | mov [ecx+3], byte ah |
52 | mov [ecx+4], byte 0 |
40 | mov [ecx+4], byte 0 |
53 | ret |
41 | ret |
- | 42 | ||
54 | @@: |
43 | @@: |
55 | cmp al, 'm'; if ram disk |
44 | cmp al, 'm' |
56 | jnz @f |
45 | jnz .hard_disk |
57 | mov [ecx], dword 'CD?/'; if cd disk {m} |
46 | mov [ecx], dword 'CD?/' |
58 | mov [ecx+4], byte '1' |
47 | mov [ecx+4], byte '1' |
59 | mov [ecx+5], dword '/KOL' |
48 | mov [ecx+5], dword '/KOL' |
60 | mov [ecx+9], dword 'IBRI' |
49 | mov [ecx+9], dword 'IBRI' |
61 | mov [ecx+13], byte 0 |
50 | mov [ecx+13], byte 0 |
62 | .next_cd: |
51 | .next_cd: |
63 | mov [ecx+2], byte ah |
52 | mov [ecx+2], byte ah |
64 | inc ah |
53 | inc ah |
65 | cmp ah, '5' |
54 | cmp ah, '5' |
66 | je .not_found_cd |
55 | je @f |
67 | lea edx, [buff] |
56 | lea edx, [buff] |
68 | pushad |
57 | pushad |
69 | stdcall read_file, read_firstapp, edx, 0, 4 |
58 | stdcall read_file, read_firstapp, edx, 0, 4 |
70 | popad |
59 | popad |
71 | cmp [edx], dword 'MENU' |
60 | cmp [edx], dword 'MENU' |
72 | jne .next_cd |
61 | jne .next_cd |
73 | jmp .ok |
- | |
74 | - | ||
75 | @@: |
62 | @@: |
- | 63 | ret |
|
- | 64 | ||
- | 65 | .hard_disk: |
|
76 | sub al, 49 |
66 | sub al, '1' |
77 | mov [ecx], dword 'HD?/'; if hard disk |
67 | mov [ecx], dword 'HD?/' |
78 | mov [ecx+2], byte al |
68 | mov [ecx+2], byte al |
79 | mov [ecx+4], byte ah |
69 | mov [ecx+4], byte ah |
80 | mov [ecx+5], dword '/KOL' |
70 | mov [ecx+5], dword '/KOL' |
81 | mov [ecx+9], dword 'IBRI' |
71 | mov [ecx+9], dword 'IBRI' |
82 | mov [ecx+13], byte 0 |
72 | mov [ecx+13], byte 0 |
83 | .ok: |
- | |
84 | .not_found_cd: |
- | |
85 | ret |
- | |
86 | endp |
- | |
87 | - | ||
88 | proc load_file_parse_table |
- | |
89 | stdcall kernel_alloc, 0x1000 |
- | |
90 | mov [tmp_file_name_table], eax |
- | |
91 | mov edi, eax |
- | |
92 | mov esi, sysdir_name |
- | |
93 | mov ecx, 128/4 |
- | |
94 | rep movsd |
- | |
95 | - | ||
96 | invoke ini.enum_keys, conf_fname, conf_path_sect, get_every_key |
- | |
97 | - | ||
98 | mov eax, [tmp_file_name_table] |
- | |
99 | mov [full_file_name_table], eax |
- | |
100 | mov eax, [tmp_file_name_size] |
- | |
101 | mov [full_file_name_table.size], eax |
- | |
102 | ret |
- | |
103 | endp |
- | |
104 | - | ||
105 | uglobal |
- | |
106 | def_val_1 db 0 |
- | |
107 | endg |
- | |
108 | - | ||
109 | proc get_every_key stdcall, f_name, sec_name, key_name |
- | |
110 | mov esi, [key_name] |
- | |
111 | mov ecx, esi |
- | |
112 | cmp byte [esi], '/' |
- | |
113 | jnz @f |
- | |
114 | inc esi |
- | |
115 | @@: |
- | |
116 | mov edi, [tmp_file_name_size] |
- | |
117 | shl edi, 7 |
- | |
118 | cmp edi, 0x1000 |
- | |
119 | jae .stop_parse |
- | |
120 | add edi, [tmp_file_name_table] |
- | |
121 | lea ebx, [edi+64] |
- | |
122 | @@: |
- | |
123 | cmp edi, ebx |
- | |
124 | jae .skip_this_key |
- | |
125 | lodsb |
- | |
126 | test al, al |
- | |
127 | jz @f |
- | |
128 | or al, 20h |
- | |
129 | stosb |
- | |
130 | jmp @b |
- | |
131 | @@: |
- | |
132 | stosb |
- | |
133 | - | ||
134 | invoke ini.get_str, [f_name], [sec_name], ecx, ebx, 64, def_val_1 |
- | |
135 | - | ||
136 | cmp byte [ebx], '/' |
- | |
137 | jnz @f |
- | |
138 | lea esi, [ebx+1] |
- | |
139 | mov edi, ebx |
- | |
140 | mov ecx, 63 |
- | |
141 | rep movsb |
- | |
142 | @@: |
- | |
143 | push ebp |
- | |
144 | mov ebp, [tmp_file_name_table] |
- | |
145 | mov ecx, [tmp_file_name_size] |
- | |
146 | jecxz .noreplace |
- | |
147 | mov eax, ecx |
- | |
148 | dec eax |
- | |
149 | shl eax, 7 |
- | |
150 | add ebp, eax |
- | |
151 | .replace_loop: |
- | |
152 | mov edi, ebx |
- | |
153 | mov esi, ebp |
- | |
154 | @@: |
- | |
155 | lodsb |
- | |
156 | test al, al |
- | |
157 | jz .doreplace |
- | |
158 | mov dl, [edi] |
- | |
159 | inc edi |
- | |
160 | test dl, dl |
- | |
161 | jz .replace_loop_cont |
- | |
162 | or dl, 20h |
- | |
163 | cmp al, dl |
- | |
164 | jz @b |
- | |
165 | jmp .replace_loop_cont |
- | |
166 | .doreplace: |
- | |
167 | cmp byte [edi], 0 |
- | |
168 | jz @f |
- | |
169 | cmp byte [edi], '/' |
- | |
170 | jnz .replace_loop_cont |
- | |
171 | @@: |
- | |
172 | lea esi, [ebp+64] |
- | |
173 | call .replace |
- | |
174 | jc .skip_this_key2 |
- | |
175 | .replace_loop_cont: |
- | |
176 | sub ebp, 128 |
- | |
177 | loop .replace_loop |
- | |
178 | .noreplace: |
- | |
179 | pop ebp |
- | |
180 | - | ||
181 | inc [tmp_file_name_size] |
- | |
182 | .skip_this_key: |
- | |
183 | xor eax, eax |
- | |
184 | inc eax |
- | |
185 | ret |
- | |
186 | .skip_this_key2: |
- | |
187 | pop ebp |
- | |
188 | jmp .skip_this_key |
- | |
189 | .stop_parse: |
- | |
190 | xor eax, eax |
- | |
191 | ret |
- | |
192 | endp |
- | |
193 | - | ||
194 | proc get_every_key.replace |
- | |
195 | ; in: ebx->destination, esi->first part of name, edi->second part of name |
- | |
196 | ; maximum length is 64 bytes |
- | |
197 | ; out: CF=1 <=> overflow |
- | |
198 | ; 1) allocate temporary buffer in stack |
- | |
199 | sub esp, 64 |
- | |
200 | ; 2) save second part of name to temporary buffer |
- | |
201 | push esi |
- | |
202 | lea esi, [esp+4] ; esi->tmp buffer |
- | |
203 | xchg esi, edi ; edi->tmp buffer, esi->source |
- | |
204 | @@: |
- | |
205 | lodsb |
- | |
206 | stosb |
- | |
207 | test al, al |
- | |
208 | jnz @b |
- | |
209 | ; 3) copy first part of name to destination |
- | |
210 | pop esi |
- | |
211 | mov edi, ebx |
- | |
212 | @@: |
- | |
213 | lodsb |
- | |
214 | test al, al |
- | |
215 | jz @f |
- | |
216 | stosb |
- | |
217 | jmp @b |
- | |
218 | @@: |
- | |
219 | ; 4) restore second part of name from temporary buffer to destination |
- | |
220 | ; (may cause overflow) |
- | |
221 | lea edx, [ebx+64] ; limit of destination |
- | |
222 | mov esi, esp |
- | |
223 | @@: |
- | |
224 | cmp edi, edx |
- | |
225 | jae .overflow |
- | |
226 | lodsb |
- | |
227 | stosb |
- | |
228 | test al, al |
- | |
229 | jnz @b |
- | |
230 | ; all is OK |
- | |
231 | add esp, 64 ; CF is cleared |
- | |
232 | ret |
- | |
233 | .overflow: |
- | |
234 | ; name is too long |
- | |
235 | add esp, 64 |
- | |
236 | stc |
- | |
237 | ret |
73 | ret |
238 | endp |
74 | endp |
239 | 75 | ||
240 | cp866toUpper: |
76 | cp866toUpper: |
241 | ; convert cp866 character in al to uppercase |
77 | ; convert cp866 character in al to uppercase |
242 | cmp al, 'a' |
78 | cmp al, 'a' |
243 | jb .ret |
79 | jb .ret |
244 | cmp al, 'z' |
80 | cmp al, 'z' |
245 | jbe @f |
81 | jbe @f |
246 | cmp al, 0xA0 |
82 | cmp al, 0xA0 |
247 | jb .ret |
83 | jb .ret |
248 | cmp al, 0xB0 |
84 | cmp al, 0xB0 |
249 | jb @f |
85 | jb @f |
250 | cmp al, 0xE0 |
86 | cmp al, 0xE0 |
251 | jb .ret |
87 | jb .ret |
252 | cmp al, 0xF0 |
88 | cmp al, 0xF0 |
253 | jb .rus |
89 | jb .rus |
254 | cmp al, 0xF7 |
90 | cmp al, 0xF7 |
255 | ja .ret |
91 | ja .ret |
256 | and eax, -2 |
92 | and eax, -2 |
257 | .ret: |
93 | .ret: |
258 | ret |
94 | ret |
259 | 95 | ||
260 | @@: |
96 | @@: |
261 | sub eax, 32 |
97 | sub eax, 32 |
262 | ret |
98 | ret |
263 | 99 | ||
264 | .rus: |
100 | .rus: |
265 | sub eax, 0xE0-0x90 |
101 | sub eax, 0xE0-0x90 |
266 | ret |
102 | ret |
267 | 103 | ||
268 | utf16toUpper: |
104 | utf16toUpper: |
269 | ; convert UTF-16 character in ax to uppercase |
105 | ; convert UTF-16 character in ax to uppercase |
270 | cmp ax, 'a' |
106 | cmp ax, 'a' |
271 | jb .ret |
107 | jb .ret |
272 | cmp ax, 'z' |
108 | cmp ax, 'z' |
273 | jbe @f |
109 | jbe @f |
274 | cmp ax, 430h |
110 | cmp ax, 430h |
275 | jb .ret |
111 | jb .ret |
276 | cmp ax, 450h |
112 | cmp ax, 450h |
277 | jb @f |
113 | jb @f |
278 | cmp ax, 460h |
114 | cmp ax, 460h |
279 | jnc .ret |
115 | jnc .ret |
280 | sub eax, 80 |
116 | sub eax, 80 |
281 | .ret: |
117 | .ret: |
282 | ret |
118 | ret |
283 | 119 | ||
284 | @@: |
120 | @@: |
285 | sub eax, 32 |
121 | sub eax, 32 |
286 | ret |
122 | ret |
287 | 123 | ||
288 | uni2ansi_char: |
124 | uni2ansi_char: |
289 | ; convert UNICODE character in ax to ANSI character in al using cp866 encoding |
125 | ; convert UNICODE character in ax to ANSI character in al using cp866 encoding |
290 | cmp ax, 0x80 |
126 | cmp ax, 0x80 |
291 | jb .ret |
127 | jb .ret |
292 | cmp ax, 0xB6 |
128 | cmp ax, 0xB6 |
293 | jz .B6 |
129 | jz .B6 |
294 | cmp ax, 0x400 |
130 | cmp ax, 0x400 |
295 | jb .unk |
131 | jb .unk |
296 | cmp ax, 0x410 |
132 | cmp ax, 0x410 |
297 | jb @f |
133 | jb @f |
298 | cmp ax, 0x440 |
134 | cmp ax, 0x440 |
299 | jb .rus1 |
135 | jb .rus1 |
300 | cmp ax, 0x450 |
136 | cmp ax, 0x450 |
301 | jb .rus2 |
137 | jb .rus2 |
302 | cmp ax, 0x460 |
138 | cmp ax, 0x460 |
303 | jb @f |
139 | jb @f |
304 | .unk: |
140 | .unk: |
305 | mov al, '_' |
141 | mov al, '_' |
306 | .ret: |
142 | .ret: |
307 | ret |
143 | ret |
308 | 144 | ||
309 | .B6: |
145 | .B6: |
310 | mov al, 20 |
146 | mov al, 20 |
311 | ret |
147 | ret |
312 | 148 | ||
313 | .rus1: ; 0x410-0x43F -> 0x80-0xAF |
149 | .rus1: ; 0x410-0x43F -> 0x80-0xAF |
314 | add al, 0x70 |
150 | add al, 0x70 |
315 | ret |
151 | ret |
316 | 152 | ||
317 | .rus2: ; 0x440-0x44F -> 0xE0-0xEF |
153 | .rus2: ; 0x440-0x44F -> 0xE0-0xEF |
318 | add al, 0xA0 |
154 | add al, 0xA0 |
319 | ret |
155 | ret |
320 | 156 | ||
321 | @@: |
157 | @@: |
322 | push ecx edi |
158 | push ecx edi |
323 | mov ecx, 8 |
159 | mov ecx, 8 |
324 | mov edi, .table |
160 | mov edi, .table |
325 | repnz scasb |
161 | repnz scasb |
326 | mov ah, cl |
162 | mov ah, cl |
327 | pop edi ecx |
163 | pop edi ecx |
328 | jnz .unk |
164 | jnz .unk |
329 | mov al, 0xF7 |
165 | mov al, 0xF7 |
330 | sub al, ah |
166 | sub al, ah |
331 | ret |
167 | ret |
332 | 168 | ||
333 | .table db 1, 51h, 4, 54h, 7, 57h, 0Eh, 5Eh |
169 | .table db 1, 51h, 4, 54h, 7, 57h, 0Eh, 5Eh |
334 | 170 | ||
335 | ansi2uni_char: |
171 | ansi2uni_char: |
336 | ; convert ANSI character in al to UNICODE character in ax, using cp866 encoding |
172 | ; convert ANSI character in al to UNICODE character in ax, using cp866 encoding |
337 | movzx eax, al |
173 | movzx eax, al |
338 | cmp al, 0x80 |
174 | cmp al, 0x80 |
339 | jb @f ; 0x00-0x7F - trivial map |
175 | jb @f ; 0x00-0x7F - trivial map |
340 | cmp al, 0xB0 |
176 | cmp al, 0xB0 |
341 | jb .rus ; 0x80-0xAF -> 0x410-0x43F |
177 | jb .rus ; 0x80-0xAF -> 0x410-0x43F |
342 | cmp al, 0xE0 |
178 | cmp al, 0xE0 |
343 | jb .unk |
179 | jb .unk |
344 | cmp al, 0xF0 |
180 | cmp al, 0xF0 |
345 | jb .rus2 ; 0xE0-0xEF -> 0x440-0x44F |
181 | jb .rus2 ; 0xE0-0xEF -> 0x440-0x44F |
346 | cmp al, 0xF8 |
182 | cmp al, 0xF8 |
347 | jnc .unk |
183 | jnc .unk |
348 | mov al, [eax+uni2ansi_char.table-0xF0] |
184 | mov al, [eax+uni2ansi_char.table-0xF0] |
349 | add ax, 400h |
185 | add ax, 400h |
350 | ret |
186 | ret |
351 | 187 | ||
352 | @@: |
188 | @@: |
353 | cmp al, 20 |
189 | cmp al, 20 |
354 | jnz .ret |
190 | jnz .ret |
355 | mov al, 0xB6 |
191 | mov al, 0xB6 |
356 | .ret: |
192 | .ret: |
357 | ret |
193 | ret |
358 | 194 | ||
359 | .rus: |
195 | .rus: |
360 | add ax, 0x410-0x80 |
196 | add ax, 0x410-0x80 |
361 | ret |
197 | ret |
362 | 198 | ||
363 | .rus2: |
199 | .rus2: |
364 | add ax, 0x440-0xE0 |
200 | add ax, 0x440-0xE0 |
365 | ret |
201 | ret |
366 | 202 | ||
367 | .unk: |
203 | .unk: |
368 | mov al, '_' |
204 | mov al, '_' |
369 | ret |
205 | ret |
370 | 206 | ||
371 | cp866toUTF8_string: |
207 | cp866toUTF8_string: |
372 | ; in: |
208 | ; in: |
373 | ; esi -> cp866 string (could be zero terminated) |
209 | ; esi -> cp866 string (could be zero terminated) |
374 | ; edi -> buffer for UTF-8 string |
210 | ; edi -> buffer for UTF-8 string |
375 | ; ecx = buffer size (signed) |
211 | ; ecx = buffer size (signed) |
376 | lodsb |
212 | lodsb |
377 | call ansi2uni_char |
213 | call ansi2uni_char |
378 | push eax |
214 | push eax |
379 | call UTF16to8 |
215 | call UTF16to8 |
380 | pop eax |
216 | pop eax |
381 | js @f |
217 | js @f |
382 | test eax, eax |
218 | test eax, eax |
383 | jnz cp866toUTF8_string |
219 | jnz cp866toUTF8_string |
384 | @@: |
220 | @@: |
385 | ret |
221 | ret |
386 | 222 | ||
387 | ; SF=1 -> counter |
223 | ; SF=1 -> counter |
388 | ; ZF=1 -> zero char |
224 | ; ZF=1 -> zero char |
389 | 225 | ||
390 | UTF16to8_string: |
226 | UTF16to8_string: |
391 | ; in: |
227 | ; in: |
392 | ; esi -> UTF-16 string (could be zero terminated) |
228 | ; esi -> UTF-16 string (could be zero terminated) |
393 | ; edi -> buffer for UTF-8 string |
229 | ; edi -> buffer for UTF-8 string |
394 | ; ecx = buffer size (signed) |
230 | ; ecx = buffer size (signed) |
395 | xor eax, eax |
231 | xor eax, eax |
396 | @@: |
232 | @@: |
397 | lodsw |
233 | lodsw |
398 | push eax |
234 | push eax |
399 | call UTF16to8 |
235 | call UTF16to8 |
400 | pop eax |
236 | pop eax |
401 | js @f |
237 | js @f |
402 | test eax, eax |
238 | test eax, eax |
403 | jnz @b |
239 | jnz @b |
404 | @@: |
240 | @@: |
405 | ret |
241 | ret |
406 | 242 | ||
407 | UTF16to8: |
243 | UTF16to8: |
408 | ; in: |
244 | ; in: |
409 | ; eax = UTF-16 char |
245 | ; eax = UTF-16 char |
410 | ; edi -> buffer for UTF-8 char (increasing) |
246 | ; edi -> buffer for UTF-8 char (increasing) |
411 | ; ecx = byte counter (decreasing) |
247 | ; ecx = byte counter (decreasing) |
412 | dec ecx |
248 | dec ecx |
413 | js .ret |
249 | js .ret |
414 | cmp eax, 80h |
250 | cmp eax, 80h |
415 | jnc @f |
251 | jnc @f |
416 | stosb |
252 | stosb |
417 | test eax, eax ; SF=0 |
253 | test eax, eax ; SF=0 |
418 | .ret: |
254 | .ret: |
419 | ret |
255 | ret |
420 | 256 | ||
421 | @@: |
257 | @@: |
422 | dec ecx |
258 | dec ecx |
423 | js .ret |
259 | js .ret |
424 | cmp eax, 800h |
260 | cmp eax, 800h |
425 | jnc @f |
261 | jnc @f |
426 | shl eax, 2 |
262 | shl eax, 2 |
427 | shr al, 2 |
263 | shr al, 2 |
428 | or eax, 1100000010000000b |
264 | or eax, 1100000010000000b |
429 | xchg al, ah |
265 | xchg al, ah |
430 | stosw |
266 | stosw |
431 | ret |
267 | ret |
432 | 268 | ||
433 | @@: |
269 | @@: |
434 | dec ecx |
270 | dec ecx |
435 | js .ret |
271 | js .ret |
436 | shl eax, 4 |
272 | shl eax, 4 |
437 | shr ax, 2 |
273 | shr ax, 2 |
438 | shr al, 2 |
274 | shr al, 2 |
439 | or eax, 111000001000000010000000b |
275 | or eax, 111000001000000010000000b |
440 | bswap eax |
276 | bswap eax |
441 | shr eax, 8 |
277 | shr eax, 8 |
442 | stosb |
278 | stosb |
443 | shr eax, 8 |
279 | shr eax, 8 |
444 | stosw |
280 | stosw |
445 | ret |
281 | ret |
446 | 282 | ||
447 | utf8to16: |
283 | utf8to16: |
448 | ; in: esi -> UTF-8 char (increasing) |
284 | ; in: esi -> UTF-8 char (increasing) |
449 | ; out: ax = UTF-16 char |
285 | ; out: ax = UTF-16 char |
450 | lodsb |
286 | lodsb |
451 | test al, al |
287 | test al, al |
452 | jns .got |
288 | jns .got |
453 | shl al, 2 |
289 | shl al, 2 |
454 | jnc utf8to16 |
290 | jnc utf8to16 |
455 | @@: |
291 | @@: |
456 | shl ax, 8 |
292 | shl ax, 8 |
457 | lodsb |
293 | lodsb |
458 | test al, al |
294 | test al, al |
459 | jns .got |
295 | jns .got |
460 | shl al, 2 |
296 | shl al, 2 |
461 | jc @b |
297 | jc @b |
462 | shr ah, 2 |
298 | shr ah, 2 |
463 | shl ax, 3 |
299 | shl ax, 3 |
464 | jnc @f |
300 | jnc @f |
465 | shl eax, 3 |
301 | shl eax, 3 |
466 | lodsb |
302 | lodsb |
467 | test al, al |
303 | test al, al |
468 | jns .got |
304 | jns .got |
469 | shl al, 2 |
305 | shl al, 2 |
470 | jc @b |
306 | jc @b |
471 | shr eax, 2 |
307 | shr eax, 2 |
472 | ret |
308 | ret |
473 | 309 | ||
474 | @@: |
310 | @@: |
475 | shr ax, 5 |
311 | shr ax, 5 |
476 | ret |
312 | ret |
477 | 313 | ||
478 | .got: |
314 | .got: |
479 | xor ah, ah |
315 | xor ah, ah |
480 | ret |
316 | ret |
481 | 317 | ||
482 | strlen: |
318 | strlen: |
483 | ; in: esi -> source |
319 | ; in: esi -> source |
484 | ; out: ecx = length |
320 | ; out: ecx = length |
485 | push edi eax |
321 | push edi eax |
486 | or ecx, -1 |
322 | or ecx, -1 |
487 | mov edi, esi |
323 | mov edi, esi |
488 | xor eax, eax |
324 | xor eax, eax |
489 | repnz scasb |
325 | repnz scasb |
490 | inc ecx |
326 | inc ecx |
491 | not ecx |
327 | not ecx |
492 | pop eax edi |
328 | pop eax edi |
493 | ret=> |
329 | ret |