Rev 6462 | Rev 6502 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6462 | Rev 6471 | ||
---|---|---|---|
Line 3... | Line 3... | ||
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 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 7... | Line 7... | ||
7 | 7 | ||
Line 8... | Line 8... | ||
8 | $Revision: 6462 $ |
8 | $Revision: 6471 $ |
9 | 9 | ||
10 | 10 | ||
Line 235... | Line 235... | ||
235 | add esp, 64 |
235 | add esp, 64 |
236 | stc |
236 | stc |
237 | ret |
237 | ret |
238 | endp |
238 | endp |
Line 239... | Line -... | ||
239 | - | ||
240 | 239 | ||
241 | char_todown: |
240 | cp866toUpper: |
242 | ; convert character in al to downcase, using cp866 encoding |
241 | ; convert cp866 character in al to uppercase |
243 | cmp al, 'A' |
242 | cmp al, 'a' |
244 | jb .ret |
243 | jb .ret |
245 | cmp al, 'Z' |
244 | cmp al, 'z' |
246 | jbe .az |
245 | jbe @f |
247 | cmp al, 0x80 ; 'А' |
246 | cmp al, 0xA0 |
- | 247 | jb .ret |
|
- | 248 | cmp al, 0xB0 |
|
248 | jb .ret |
249 | jb @f |
- | 250 | cmp al, 0xE0 |
|
- | 251 | jb .ret |
|
249 | cmp al, 0x90 ; 'Р' |
252 | cmp al, 0xF0 |
250 | jb .rus |
- | |
251 | cmp al, 0xF0 ; 'Ё' |
- | |
252 | jz .yo |
253 | jb .rus |
253 | cmp al, 0x9F ; 'Я' |
254 | cmp al, 0xF7 |
254 | ja .ret |
- | |
255 | ; 0x90-0x9F -> 0xE0-0xEF |
255 | ja .ret |
256 | add al, 0xE0-0x90 |
256 | and eax, -2 |
257 | .ret: |
257 | .ret: |
Line 258... | Line 258... | ||
258 | ret |
258 | ret |
259 | - | ||
260 | .az: |
259 | |
261 | .rus: ; 0x80-0x8F -> 0xA0-0xAF |
260 | @@: |
Line 262... | Line 261... | ||
262 | add al, 0x20 |
261 | sub eax, 32 |
263 | ret |
262 | ret |
264 | 263 | ||
Line 265... | Line -... | ||
265 | .yo: |
- | |
266 | inc al |
264 | .rus: |
267 | ret |
265 | sub eax, 0xE0-0x90 |
268 | 266 | ret |
|
269 | 267 | ||
270 | char_toupper: |
268 | utf16toUpper: |
271 | ; convert character in al to uppercase, using cp866 encoding |
269 | ; convert UTF-16 character in ax to uppercase |
272 | cmp al, 'a' |
270 | cmp ax, 'a' |
273 | jb .ret |
271 | jb .ret |
274 | cmp al, 'z' |
272 | cmp ax, 'z' |
275 | jbe .az |
273 | jbe @f |
276 | cmp al, 0xA0 ; 'а' |
- | |
277 | jb .ret |
- | |
278 | cmp al, 0xE0 ; 'р' |
274 | cmp ax, 430h |
279 | jb .rus |
275 | jb .ret |
280 | cmp al, 0xF1 ; 'ё' |
- | |
281 | jz .yo |
276 | cmp ax, 450h |
282 | cmp al, 0xEF ; 'я' |
277 | jb @f |
283 | ja .ret |
278 | cmp ax, 460h |
Line 284... | Line 279... | ||
284 | ; 0xE0-0xEF -> 0x90-0x9F |
279 | jnc .ret |
285 | sub al, 0xE0-0x90 |
- | |
286 | .ret: |
- | |
287 | ret |
- | |
288 | - | ||
289 | .az: |
- | |
290 | .rus: ; 0xA0-0xAF -> 0x80-0x8F |
- | |
291 | and al, not 0x20 |
- | |
292 | ret |
- | |
293 | - | ||
294 | .yo: |
- | |
295 | dec al |
- | |
296 | ret |
- | |
297 | - | ||
298 | - | ||
299 | uni2ansi_str: |
- | |
300 | ; convert UNICODE zero-terminated string to ASCII-string (codepage 866) |
- | |
301 | ; in: esi->source, edi->buffer (may be esi=edi) |
280 | sub eax, 80 |
302 | ; destroys: eax,esi,edi |
- | |
303 | lodsw |
281 | .ret: |
Line 304... | Line -... | ||
304 | call uni2ansi_char |
- | |
305 | stosb |
282 | ret |
306 | test al, al |
283 | |
307 | jnz uni2ansi_str |
284 | @@: |
308 | ret |
285 | sub eax, 32 |
309 | 286 | ret |
|
Line 353... | Line 330... | ||
353 | sub al, ah |
330 | sub al, ah |
354 | ret |
331 | ret |
Line 355... | Line 332... | ||
355 | 332 | ||
Line 356... | Line -... | ||
356 | .table db 1, 51h, 4, 54h, 7, 57h, 0Eh, 5Eh |
- | |
357 | 333 | .table db 1, 51h, 4, 54h, 7, 57h, 0Eh, 5Eh |
|
358 | 334 | ||
359 | ansi2uni_char: |
335 | ansi2uni_char: |
360 | ; convert ANSI character in al to UNICODE character in ax, using cp866 encoding |
336 | ; convert ANSI character in al to UNICODE character in ax, using cp866 encoding |
361 | movzx eax, al |
337 | movzx eax, al |
Line 390... | Line 366... | ||
390 | 366 | ||
391 | .unk: |
367 | .unk: |
392 | mov al, '_' |
368 | mov al, '_' |
Line 393... | Line 369... | ||
393 | ret |
369 | ret |
- | 370 | ||
- | 371 | cp866toUTF8_string: |
|
394 | 372 | ; in: |
|
395 | utf8_to_cp866: |
373 | ; esi -> cp866 string (could be zero terminated) |
- | 374 | ; edi -> buffer for UTF-8 string |
|
396 | ; in: esi, edi, ecx |
375 | ; ecx = buffer size (signed) |
397 | ; destroys esi, edi, ecx, eax |
376 | lodsb |
398 | call utf8to16 |
377 | call ansi2uni_char |
- | 378 | push eax |
|
399 | js utf8to16.ret |
379 | call UTF16to8 |
- | 380 | pop eax |
|
400 | call uni2ansi_char |
381 | js @f |
- | 382 | test eax, eax |
|
- | 383 | jnz cp866toUTF8_string |
|
Line -... | Line 384... | ||
- | 384 | @@: |
|
- | 385 | ret |
|
- | 386 | ||
- | 387 | ; SF=1 -> counter |
|
- | 388 | ; ZF=1 -> zero char |
|
- | 389 | ||
- | 390 | UTF16to8_string: |
|
- | 391 | ; in: |
|
- | 392 | ; esi -> UTF-16 string (could be zero terminated) |
|
- | 393 | ; edi -> buffer for UTF-8 string |
|
- | 394 | ; ecx = buffer size (signed) |
|
- | 395 | xor eax, eax |
|
- | 396 | @@: |
|
- | 397 | lodsw |
|
- | 398 | push eax |
|
- | 399 | call UTF16to8 |
|
- | 400 | pop eax |
|
- | 401 | js @f |
|
- | 402 | test eax, eax |
|
- | 403 | jnz @b |
|
401 | stosb |
404 | @@: |
402 | jmp utf8_to_cp866 |
405 | ret |
403 | 406 | ||
- | 407 | UTF16to8: |
|
404 | utf8to16: |
408 | ; in: |
- | 409 | ; eax = UTF-16 char |
|
- | 410 | ; edi -> buffer for UTF-8 char (increasing) |
|
- | 411 | ; ecx = byte counter (decreasing) |
|
- | 412 | dec ecx |
|
- | 413 | js .ret |
|
- | 414 | cmp eax, 80h |
|
405 | ; in: |
415 | jnc @f |
406 | ; esi -> string |
416 | stosb |
- | 417 | test eax, eax ; SF=0 |
|
- | 418 | .ret: |
|
- | 419 | ret |
|
- | 420 | ||
- | 421 | @@: |
|
407 | ; ecx = byte counter |
422 | dec ecx |
408 | ; out: |
423 | js .ret |
- | 424 | cmp eax, 800h |
|
- | 425 | jnc @f |
|
- | 426 | shl eax, 2 |
|
- | 427 | shr al, 2 |
|
- | 428 | or eax, 1100000010000000b |
|
- | 429 | xchg al, ah |
|
- | 430 | stosw |
|
409 | ; SF=1 -> end |
431 | ret |
410 | ; ax = UTF-16 char |
432 | |
- | 433 | @@: |
|
- | 434 | dec ecx |
|
- | 435 | js .ret |
|
- | 436 | shl eax, 4 |
|
- | 437 | shr ax, 2 |
|
- | 438 | shr al, 2 |
|
- | 439 | or eax, 111000001000000010000000b |
|
- | 440 | bswap eax |
|
- | 441 | shr eax, 8 |
|
- | 442 | stosb |
|
- | 443 | shr eax, 8 |
|
- | 444 | stosw |
|
- | 445 | ret |
|
- | 446 | ||
411 | ; changes esi, ecx |
447 | utf8to16: |
412 | dec ecx |
448 | ; in: esi -> UTF-8 char (increasing) |
413 | js .ret |
449 | ; out: ax = UTF-16 char |
414 | lodsb |
450 | lodsb |
415 | test al, al |
451 | test al, al |
416 | jns .got |
452 | jns .got |
417 | shl al, 2 |
453 | shl al, 2 |
418 | jnc utf8to16 |
- | |
419 | @@: |
- | |
420 | shl ax, 8 |
454 | jnc utf8to16 |
421 | dec ecx |
455 | @@: |
422 | js .ret |
456 | shl ax, 8 |
423 | lodsb |
457 | lodsb |
424 | test al, al |
458 | test al, al |
425 | jns .got |
459 | jns .got |
426 | shl al, 2 |
460 | shl al, 2 |
427 | jc @b |
461 | jc @b |
428 | shr ah, 2 |
462 | shr ah, 2 |
429 | shl ax, 3 |
- | |
430 | jnc @f |
- | |
431 | shl eax, 3 |
463 | shl ax, 3 |
432 | dec ecx |
464 | jnc @f |
433 | js .ret |
465 | shl eax, 3 |
434 | lodsb |
466 | lodsb |
435 | test al, al |
467 | test al, al |
Line 443... | Line 475... | ||
443 | shr ax, 5 |
475 | shr ax, 5 |
444 | ret |
476 | ret |
Line 445... | Line 477... | ||
445 | 477 | ||
446 | .got: |
478 | .got: |
447 | xor ah, ah |
- | |
448 | .ret: |
479 | xor ah, ah |
Line 449... | Line 480... | ||
449 | ret |
480 | ret |
450 | 481 | ||
451 | strlen: |
482 | strlen: |