kolibrios-fun/programs/media/voxel_editor/trunk/str.inc
IgorA 4cce570333 new voxel utilite 'vox_tgl'
git-svn-id: svn://kolibrios.org@5388 a494cfbc-eb01-0410-851d-a64ba20cac60
2015-01-29 11:59:15 +00:00

178 lines
3.7 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;
; ” ©« ¤«ï à ¡®âë á® áâப®¢ë¬¨ äã­ªæ¨ï¬¨
;
; str_len (str1)
; „«¨­  áâப¨ (¢®§¢à é ¥âáï ¢ eax)
; str_cat (str1, str2)
; „®¡ ¢«¥­¨¥ ª áâப¥ st1 áâப¨ str2
; str_n_cat (str1, str2, n_len)
; „®¡ ¢«¥­¨¥ ª áâப¥ st1 áâப¨ str2. …᫨ áâப  str2 ¤«¨­­¥¥ 祬 n_len, â® ¤®¡ ¢«ïîâáï ¯¥à¢ë¥ n_len ᨬ¢®«®¢.
; conv_str_to_int (buf)
; <EFBFBD>८¡à §®¢ ­¨¥ áâப¨ buf ¢ ç¨á«® (¢®§¢à é ¥âáï ¢ eax)
; convert_int_to_str (len)
; <EFBFBD>८¡à §®¢ ­¨¥ ç¨á«  (eax) ¢ áâபã (edi). len - ¤«¨­­  áâப¨ edi, ª®â®àãî ¬®¦­® ¨á¯®«ì§®¢ âì ¤«ï ¯à¥®¡à §®¢ ­¨ï.
;output:
; eax = strlen
align 4
proc str_len, str1:dword
mov eax,[str1]
@@:
cmp byte[eax],0
je @f
inc eax
jmp @b
@@:
sub eax,[str1]
ret
endp
align 4
proc str_cat uses eax ecx edi esi, str1:dword, str2:dword
mov esi,[str2]
stdcall str_len,esi
mov ecx,eax
inc ecx
mov edi,[str1]
stdcall str_len,edi
add edi,eax
cld
repne movsb
ret
endp
align 4
proc str_n_cat uses eax ecx edi esi, str1:dword, str2:dword, n_len:dword
mov esi,[str2]
mov ecx,[n_len]
mov edi,[str1]
stdcall str_len,edi
add edi,eax
cld
repne movsb
mov byte[edi],0
ret
endp
;input:
; buf - 㪠§ â¥«ì ­  áâபã, ç¨á«® ¤®«¦­® ¡ëâì ¢ 10 ¨«¨ 16 à¨ç­®¬ ¢¨¤¥
;output:
; eax - ç¨á«®
align 4
proc conv_str_to_int uses ebx ecx esi, buf:dword
xor eax,eax
xor ebx,ebx
mov esi,[buf]
;®¯à¥¤¥«¥­¨¥ ®âà¨æ â¥«ì­ëå ç¨á¥«
xor ecx,ecx
inc ecx
cmp byte[esi],'-'
jne @f
dec ecx
inc esi
@@:
cmp word[esi],'0x'
je .load_digit_16
.load_digit_10: ;áç¨â뢠­¨¥ 10-â¨ç­ëå æ¨äà
mov bl,byte[esi]
cmp bl,'0'
jl @f
cmp bl,'9'
jg @f
sub bl,'0'
imul eax,10
add eax,ebx
inc esi
jmp .load_digit_10
jmp @f
.load_digit_16: ;áç¨â뢠­¨¥ 16-à¨ç­ëå æ¨äà
add esi,2
.cycle_16:
mov bl,byte[esi]
cmp bl,'0'
jl @f
cmp bl,'f'
jg @f
cmp bl,'9'
jle .us1
cmp bl,'A'
jl @f ;®âᥨ¢ ¥¬ ᨬ¢®«ë >'9' ¨ <'A'
.us1: ;á®áâ ¢­®¥ ãá«®¢¨¥
cmp bl,'F'
jle .us2
cmp bl,'a'
jl @f ;®âᥨ¢ ¥¬ ᨬ¢®«ë >'F' ¨ <'a'
sub bl,32 ;¯¥à¥¢®¤¨¬ ᨬ¢®«ë ¢ ¢¥àå­¨© ॣ¨áâà, ¤«ï ã¯à®é¥­¨ï ¨å ¯®á«¥¤ã饩 ®¡à ¡®âª¨
.us2: ;á®áâ ¢­®¥ ãá«®¢¨¥
sub bl,'0'
cmp bl,9
jle .cor1
sub bl,7 ;convert 'A' to '10'
.cor1:
shl eax,4
add eax,ebx
inc esi
jmp .cycle_16
@@:
or ecx,ecx ;¥á«¨ ç¨á«® ®âà¨æ â¥«ì­®¥
jnz @f
neg eax
inc eax
@@:
ret
endp
;input:
; eax - ç¨á«®
; edi - ¡ãä¥à ¤«ï áâப¨
; len - ¤«¨­­  ¡ãä¥à 
;output:
align 4
proc convert_int_to_str, len:dword
pushad
mov esi,[len]
add esi,edi
dec esi
bt eax,31
jae @f
;¥á«¨ ç¨á«® ®âà¨æ â¥«ì­®¥
neg eax
;inc eax ;???
mov byte[edi],'-'
inc edi
@@:
call .str
popad
ret
endp
align 4
.str:
mov ecx,0x0a ;§ ¤ ¥âáï á¨á⥬  áç¨á«¥­¨ï ¨§¬¥­ïîâáï ॣ¨áâàë ebx,eax,ecx,edx ¢å®¤­ë¥ ¯ à ¬¥âàë eax - ç¨á«®
;¯à¥à¥¢®¤ ç¨á«  ¢ ASCII áâப㠢§®¤­ë¥ ¤ ­­ë¥ ecx=á¨á⥬  áç¨á«¥­ï edi  ¤à¥á ªã¤  § ¯¨á뢠âì, ¡ã¤¥¬ áâபã, ¯à¨ç¥¬ ª®­¥æ ¯¥à¥¬¥­­®©
cmp eax,ecx ;áà ¢­¨âì ¥á«¨ ¢ eax ¬¥­ìè¥ ç¥¬ ¢ ecx â® ¯¥à¥©â¨ ­  @@-1 â.¥. ­  pop eax
jb @f
xor edx,edx ;®ç¨áâ¨âì edx
div ecx ;à §¤¥«¨âì - ®áâ â®ª ¢ edx
push edx ;¯®«®¦¨âì ¢ á⥪
;dec edi ;ᬥ饭¨¥ ­¥®¡å®¤¨¬®¥ ¤«ï § ¯¨á¨ á ª®­æ  áâப¨
call .str ;¯¥à¥©â¨ ­  á ¬ã ᥡï â.¥. ¢ë§¢ âì á ¬ã á¥¡ï ¨ â ª ¤® ⮣® ¬®¬¥­â  ¯®ª  ¢ eax ­¥ áâ ­¥â ¬¥­ìè¥ ç¥¬ ¢ ecx
pop eax
@@: ;cmp al,10 ;¯à®¢¥à¨âì ­¥ ¬¥­ìè¥ «¨ §­ ç¥­¨¥ ¢ al 祬 10 (¤«ï á¨á⥬ë áç¨á«¥­ï 10 ¤ ­­ ï ª®¬ ­¤  - «¨è­ ï))
cmp edi,esi
jge @f
or al,0x30 ;¤ ­­ ï ª®¬ ­¤  ª®à®ç¥ 祬 ¤¢¥ ¢ëè¥
stosb ;§ ¯¨á âì í«¥¬¥­â ¨§ ॣ¨áâà  al ¢ ï祪㠯 ¬ï⨠es:edi
mov byte[edi],0 ;¢ ª®­¥æ áâப¨ áâ ¢¨¬ 0, çâ®-¡ë ­¥ ¢ë« §¨« ¬ãá®à
@@:
ret ;¯®ª  ¢ á⥪¥ åà ­¨âìáï ª®«-¢® ¢ë§®¢®¢ â® á⮫쪮 à § ¬ë ¨ ¡ã¤¥¬ ¢ë§ë¢ âìáï