Fixed a bug in the mouse, added functions in string.h, optimized some functions.

git-svn-id: svn://kolibrios.org@5573 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
pavelyakov 2015-07-11 16:01:28 +00:00
parent 64effed438
commit 312f091355
2 changed files with 425 additions and 218 deletions

View File

@ -65,7 +65,7 @@ char program_path[4096];
/** /**
* The structure of the mouse * The structure of the mouse
* x - coordinate X * x - coordinate X
* ó - coordinate Ó * y - coordinate Y
* xx and yy - time coordinates * xx and yy - time coordinates
* lkm - left mouse button * lkm - left mouse button
* pkm - right mouse button * pkm - right mouse button
@ -82,6 +82,7 @@ char program_path[4096];
void get(); void get();
}; };
//get new attributes mouse
:void mouse::get() :void mouse::get()
{ {
EAX = 37; EAX = 37;
@ -126,8 +127,9 @@ char program_path[4096];
//when you press the mouse button //when you press the mouse button
else { else {
up = false; up = false;
down = key; if(key) down = true;
if(down)tmp=key; else down = false;
if(down) tmp = key;
if((xx!=x)||(yy!=y)){ if((xx!=x)||(yy!=y)){
move = true; move = true;
xx = x; xx = x;
@ -136,7 +138,8 @@ char program_path[4096];
else move = false; else move = false;
} }
EAX = 37; //áªà®«« //scroll
EAX = 37;
EBX = 7; EBX = 7;
$int 0x40 $int 0x40
$mov ebx, eax $mov ebx, eax

View File

@ -2,33 +2,40 @@
// strcmp( ESI, EDI) // strcmp( ESI, EDI)
// strlen( EDI) // strlen( EDI)
// strcpy( EDI, ESI) --- 0 if == // strcpy( EDI, ESI) --- 0 if ==
// strncpy(dword text1,text2,signed length)
// strcat( EDI, ESI) // strcat( EDI, ESI)
// strncat(dword text1,text2,signed length) --- pasting the text of a certain length
// strchr( ESI,BL) --- find first BL // strchr( ESI,BL) --- find first BL
// strrchr( ESI,BL) --- find last BL // strrchr( ESI,BL) --- find last BL
// strstr( EBX, EDX) // strstr( EBX, EDX)
// itoa( ESI) // itoa(signed long number) --- convert the number as a string
// atoi( EAX) // atoi(dword text) --- convert a string as a number
// strupr( ESI) // strupr( ESI)
// strlwr( ESI) --- kyrillic symbols may not work // strlwr( ESI) --- kyrillic symbols may not work
// strttl( EDX) // strttl( EDX)
// strtok( ESI) // strtok( ESI)
// strtrim( ESI) --- removes "blank" characters (\r, \n and space) // strltrim(dword text) --- removes "blank" characters on the left (\r, \n and space)
// strrtrim(dword text) --- removes "blank" characters on the right (\r, \n and space)
// strtrim(dword text) --- delete "empty" characters (\ r \ n and space) on both sides
// chrnum(dword searchin, char symbol) // chrnum(dword searchin, char symbol)
// strcpyb(dword searchin, copyin, startstr, endstr) --- copy string between strings // strcpyb(dword searchin, copyin, startstr, endstr) --- copy string between strings
// strnumb(dword searchin, startstr, endstr) --- get number between strings // strnumb(dword searchin, startstr, endstr) --- get number between strings
// strdup(dword text) --- allocation under the text
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/*
inline fastcall signed int strcmp( ESI, EDI) inline fastcall signed int strcmp( ESI, EDI)
{ {
loop() loop()
{ {
IF (DSBYTE[ESI]<DSBYTE[EDI]) RETURN -1; IF (DSBYTE[ESI]<DSBYTE[EDI]) RETURN -1;
IF (DSBYTE[ESI]>DSBYTE[EDI]) RETURN 1; IF (DSBYTE[ESI]>DSBYTE[EDI]) RETURN 1;
IF (DSBYTE[ESI]=='\0') RETURN 0; IF (DSBYTE[ESI]=='\0') RETURN 0;
ESI++; ESI++;
EDI++; EDI++;
} }
} }
*/
inline fastcall signed int strncmp( ESI, EDI, ECX) inline fastcall signed int strncmp( ESI, EDI, ECX)
@ -55,53 +62,174 @@ L1:
inline fastcall unsigned int strlen( EDI) inline fastcall unsigned int strlen( EDI)
{ {
$xor eax, eax $xor eax, eax
$mov ecx, -1 $mov ecx, -1
$REPNE $SCASB $REPNE $SCASB
EAX-=2+ECX; EAX-=2+ECX;
}
signed int strcmp(dword text1, text2)
{
char s1,s2;
dword p1,p2;
p1 = text1;
p2 = text2;
loop()
{
s1 = DSBYTE[text1];
s2 = DSBYTE[text2];
if(s1==s2)
{
if(s1==0) return 0;
}
else {
return -1;
}
$inc text1
$inc text2
}
return 0;
} }
inline fastcall void strcpy( EDI, ESI) inline fastcall void strcpy( EDI, ESI)
{ {
$cld $cld
L2: L2:
$lodsb $lodsb
$stosb $stosb
$test al,al $test al,al
$jnz L2 $jnz L2
} }
void strncpy(dword text1, text2, signed len)
signed o1,o2;
{
o1 = len/4;
o2 = len-4*o1;
while(o1){
ESDWORD[text1] = ESDWORD[text2];
text1 += 4;
text2 += 4;
$dec o1
}
while(o2){
ESBYTE[text1] = ESBYTE[text2];
$inc text1
$inc text2
$dec o2
}
}
inline fastcall int strlcpy(dword ESI, EDI, EBX) inline fastcall int strlcpy(dword ESI, EDI, EBX)
{ {
if (EBX<0) return -1; if (EBX<0) return -1;
EDX=0; EDX=0;
do { do {
DSBYTE[ESI]=DSBYTE[EDI]; DSBYTE[ESI]=DSBYTE[EDI];
ESI++; ESI++;
EDI++; EDI++;
EDX++; EDX++;
if (EDX==EBX) { DSBYTE[ESI]='\0'; return -1;} if (EDX==EBX) { DSBYTE[ESI]='\0'; return -1;}
} while(DSBYTE[EDI-1]!='\0'); } while(DSBYTE[EDI-1]!='\0');
return 0; return 0;
} }
inline fastcall strtrim( ESI) /*
inline fastcall void strtrim( ESI)
{ {
EDI = ESI; EDI = ESI;
do{ do{
AL=DSBYTE[EDI]; AL=DSBYTE[EDI];
if (AL != '\32') && (AL != '\13') && (AL != '\10') if (AL != '\32') && (AL != '\13') && (AL != '\10')
{ {
DSBYTE[ESI]=AL; DSBYTE[ESI]=AL;
ESI++; $inc ESI
} }
EDI++; $inc EDI
}while(AL!=0); }while(AL!=0);
DSBYTE[ESI] = '\0'; DSBYTE[ESI] = '\0';
}
*/
byte __isWhite(int s){ if (s==13)||(s==32)||(s==10)||(s==9) return true; return false; }
void strltrim(dword text){
int s;
dword back_text;
back_text = text;
s = ESBYTE[text];
while(__isWhite(s))
{
$inc text
s = ESBYTE[text];
}
loop()
{
ESBYTE[back_text] = s;
$inc back_text
if(!s) break;
$inc text
s = ESBYTE[text];
};
} }
void strrtrim(dword text)
{
int s;
dword p;
do {
s = ESBYTE[text];
if(__isWhite(s))
{
p = text;
while(__isWhite(s))
{
$inc text;
s = ESBYTE[text];
}
}
else $inc text
} while(s);
$dec text
s = ESBYTE[text];
if(__isWhite(s)) ESBYTE[p] = 0;
}
void strtrim(dword text){
int s;
dword p,back_text;
back_text = text;
s = ESBYTE[text];
while(__isWhite(s))
{
$inc text
s = ESBYTE[text];
}
do {
s = ESBYTE[text];
if(__isWhite(s))
{
p = back_text;
while(__isWhite(s))
{
ESBYTE[back_text] = s;
$inc back_text
$inc text;
s = ESBYTE[text];
}
}
else {
ESBYTE[back_text] = s;
$inc back_text
$inc text
}
} while(s);
$dec text
s = ESBYTE[text];
if(__isWhite(s)) ESBYTE[p] = 0;
}
inline fastcall void strcat( EDI, ESI) inline fastcall void strcat( EDI, ESI)
{ {
@ -128,50 +256,75 @@ inline fastcall void strcat( EDI, ESI)
and ecx, 3 and ecx, 3
rep movsb rep movsb
mov eax, ebx mov eax, ebx
}
}
void strncat(dword text1, text2, signed len)
signed o1,o2;
char s;
{
s = ESBYTE[text1];
while(s){
$inc text1
s = ESBYTE[text1];
}
o1 = len/4;
o2 = len-4*o1;
while(o1){
ESDWORD[text1] = ESDWORD[text2];
text1 += 4;
text2 += 4;
$dec o1
}
while(o2){
ESBYTE[text1] = ESBYTE[text2];
$inc text1
$inc text2
$dec o2
} }
} }
inline fastcall void chrcat(ESI, BL) inline fastcall void chrcat(ESI, BL)
{ {
EDI = strlen(ESI); EDI = strlen(ESI);
ESBYTE[ESI+EDI] = BL; ESBYTE[ESI+EDI] = BL;
ESBYTE[ESI+EDI+1] = 0; ESBYTE[ESI+EDI+1] = 0;
} }
inline fastcall signed int strchr( ESI,BL) inline fastcall signed int strchr( ESI,BL)
{ {
int jj=0; int jj=0;
do{ do{
jj++; jj++;
$lodsb $lodsb
IF(AL==BL) return jj; IF(AL==BL) return jj;
} while(AL!=0); } while(AL!=0);
return 0; return 0;
} }
inline fastcall signed int strrchr( ESI,BL) inline fastcall signed int strrchr( ESI,BL)
{ {
int jj=0, last=0; int jj=0, last=0;
do{ do{
jj++; jj++;
$lodsb $lodsb
IF(AL==BL) last=jj; IF(AL==BL) last=jj;
} while(AL!=0); } while(AL!=0);
return last; return last;
} }
int chrnum(dword searchin, char symbol) int chrnum(dword searchin, char symbol)
{ {
int num = 0; int num = 0;
while(DSBYTE[searchin]) while(DSBYTE[searchin])
{ {
if (DSBYTE[searchin] == symbol) num++; if (DSBYTE[searchin] == symbol) num++;
searchin++; searchin++;
} }
return num; return num;
} }
@ -216,213 +369,264 @@ LS3:
dword strcmpi(dword cmp1, cmp2) dword strcmpi(dword cmp1, cmp2)
{ {
char si, ue; char si, ue;
loop() loop()
{ {
si = DSBYTE[cmp1]; si = DSBYTE[cmp1];
ue = DSBYTE[cmp2]; ue = DSBYTE[cmp2];
if (si>='A') && (si<='Z') si +=32; if (si>='A') && (si<='Z') si +=32;
if (ue>='A') && (ue<='Z') ue +=32; if (ue>='A') && (ue<='Z') ue +=32;
if (si != ue) return -1; if (si != ue) return -1;
cmp1++; cmp1++;
cmp2++; cmp2++;
if ((DSBYTE[cmp1]=='\0') && (DSBYTE[cmp2]=='\0')) return 0; if ((DSBYTE[cmp1]=='\0') && (DSBYTE[cmp2]=='\0')) return 0;
if (DSBYTE[cmp1]=='\0') return -1; if (DSBYTE[cmp1]=='\0') return -1;
if (DSBYTE[cmp2]=='\0') return 1; if (DSBYTE[cmp2]=='\0') return 1;
} }
} }
dword strstri(dword searchin, usestr_s) dword strstri(dword searchin, usestr_s)
{ {
dword usestr_e = usestr_s; dword usestr_e = usestr_s;
char si, ue; char si, ue;
while(DSBYTE[searchin]) while(DSBYTE[searchin])
{ {
si = DSBYTE[searchin]; si = DSBYTE[searchin];
ue = DSBYTE[usestr_e]; ue = DSBYTE[usestr_e];
if (si>='A') && (si<='Z') si +=32; if (si>='A') && (si<='Z') si +=32;
if (ue>='A') && (ue<='Z') ue +=32; if (ue>='A') && (ue<='Z') ue +=32;
if (si == ue) usestr_e++; else usestr_e = usestr_s; if (si == ue) usestr_e++; else usestr_e = usestr_s;
searchin++; searchin++;
if (DSBYTE[usestr_e]=='\0') return searchin; if (DSBYTE[usestr_e]=='\0') return searchin;
} }
return 0; return 0;
} }
unsigned int strcpyb(dword search_in, copyin, startstr, endstr) unsigned int strcpyb(dword search_in, copyin, startstr, endstr)
{ {
dword startp, endp; dword startp, endp;
dword copyin_start_off = copyin; dword copyin_start_off = copyin;
if (startstr==0) startp = search_in; else startp = strstr(search_in, startstr) + strlen(startstr); if (startstr==0) startp = search_in; else startp = strstr(search_in, startstr) + strlen(startstr);
endp = strstri(startp, endstr); endp = strstri(startp, endstr);
if (endp==0) endp = startp+strlen(search_in); if (endp==0) endp = startp+strlen(search_in);
//if (startp==endp) return 0; //if (startp==endp) return 0;
do do
{ {
DSBYTE[copyin] = DSBYTE[startp]; DSBYTE[copyin] = DSBYTE[startp];
copyin++; copyin++;
startp++; startp++;
} }
while (startp<endp); while (startp<endp);
DSBYTE[copyin] = '\0'; DSBYTE[copyin] = '\0';
return copyin_start_off; return copyin_start_off;
} }
/*void strcat(char *to, char *from) /*void strcat(char *to, char *from)
{ {
while(*to) to++; while(*to) to++;
while(*from) while(*from)
{ {
*to = *from; *to = *from;
to++; to++;
from++; from++;
} }
*to = '\0'; *to = '\0';
}*/ }*/
inline fastcall dword atoi( EDI) inline fastcall dword atoi( EDI)
{ {
$push ebx $push ebx
$push esi $push esi
ESI=EDI; ESI=EDI;
while (DSBYTE[ESI]==' ') ESI++; while (DSBYTE[ESI]==' ') ESI++;
if (DSBYTE[ESI]=='-') ESI++; if (DSBYTE[ESI]=='-') ESI++;
EAX=0; EAX=0;
while (DSBYTE[ESI]>='0') && (DSBYTE[ESI]<='9') while (DSBYTE[ESI]>='0') && (DSBYTE[ESI]<='9')
{ {
$xor ebx, ebx $xor ebx, ebx
EBX = DSBYTE[ESI]-'0'; EBX = DSBYTE[ESI]-'0';
EAX *= 10; EAX *= 10;
EAX += EBX; EAX += EBX;
ESI++; ESI++;
} }
IF (DSBYTE[EDI]=='-') -EAX; IF (DSBYTE[EDI]=='-') -EAX;
$pop esi $pop esi
$pop ebx $pop ebx
} }
inline fastcall strupr( ESI) inline fastcall strupr( ESI)
{ {
do{ do{
AL=DSBYTE[ESI]; AL=DSBYTE[ESI];
IF(AL>='a')IF(AL<='z')DSBYTE[ESI]=AL&0x5f; IF(AL>='a')IF(AL<='z')DSBYTE[ESI]=AL&0x5f;
IF (AL>=160) && (AL<=175) DSBYTE[ESI] = AL - 32; //à-ï IF (AL>=160) && (AL<=175) DSBYTE[ESI] = AL - 32; //à-ï
IF (AL>=224) && (AL<=239) DSBYTE[ESI] = AL - 80; //à-ï IF (AL>=224) && (AL<=239) DSBYTE[ESI] = AL - 80; //à-ï
ESI++; ESI++;
}while(AL!=0); }while(AL!=0);
} }
inline fastcall strlwr( ESI) inline fastcall strlwr( ESI)
{ {
do{ do{
$LODSB $LODSB
IF(AL>='A')&&(AL<='Z'){ IF(AL>='A')&&(AL<='Z'){
AL+=0x20; AL+=0x20;
DSBYTE[ESI-1]=AL; DSBYTE[ESI-1]=AL;
CONTINUE; CONTINUE;
} }
}while(AL!=0); }while(AL!=0);
} }
inline fastcall strttl( EDX) inline fastcall strttl( EDX)
{ {
AL=DSBYTE[EDX]; AL=DSBYTE[EDX];
IF(AL>='a')&&(AL<='z')DSBYTE[EDX]=AL&0x5f; IF(AL>='a')&&(AL<='z')DSBYTE[EDX]=AL&0x5f;
IF (AL>=160) && (AL<=175) DSBYTE[EDX] = AL - 32; //à-ï IF (AL>=160) && (AL<=175) DSBYTE[EDX] = AL - 32; //à-ï
IF (AL>=224) && (AL<=239) DSBYTE[EDX] = AL - 80; //à-ï IF (AL>=224) && (AL<=239) DSBYTE[EDX] = AL - 80; //à-ï
do{ do{
EDX++; EDX++;
AL=DSBYTE[EDX]; AL=DSBYTE[EDX];
IF(AL>='A')&&(AL<='Z'){DSBYTE[EDX]=AL|0x20; CONTINUE;} IF(AL>='A')&&(AL<='Z'){DSBYTE[EDX]=AL|0x20; CONTINUE;}
IF(AL>='')&&(AL<='<EFBFBD>')DSBYTE[EDX]=AL|0x20; //  IF(AL>='')&&(AL<='<EFBFBD>')DSBYTE[EDX]=AL|0x20; // 
IF (AL>=144) && (AL<=159) DSBYTE[EDX] = AL + 80; //à-ï IF (AL>=144) && (AL<=159) DSBYTE[EDX] = AL + 80; //à-ï
}while(AL!=0); }while(AL!=0);
} }
/*
dword itoa( ESI) dword itoa( ESI)
{ {
unsigned char buffer[11]; unsigned char buffer[11];
$pusha $pusha
EDI = #buffer; EDI = #buffer;
ECX = 10; ECX = 10;
if (ESI < 0) if (ESI < 0)
{ {
$mov al, '-' $mov al, '-'
$stosb $stosb
$neg esi $neg esi
} }
$mov eax, esi $mov eax, esi
$push -'0' $push -'0'
F2: F2:
$xor edx, edx $xor edx, edx
$div ecx $div ecx
$push edx $push edx
$test eax, eax $test eax, eax
$jnz F2 $jnz F2
F3: F3:
$pop eax $pop eax
$add al, '0' $add al, '0'
$stosb $stosb
$jnz F3 $jnz F3
$mov al, '\0' $mov al, '\0'
$stosb $stosb
$popa $popa
return #buffer; return #buffer;
} }
*/
dword itoa(signed long number)
{
unsigned char buf[11];
dword ret;
byte cmd;
long mask,tmp;
mask = 1000000000;
cmd = true;
if(!number){
ESBYTE[buf] = '0';
ESBYTE[buf+1] = 0;
return buf;
}
ret = buf;
if(number<0)
{
$neg number
ESBYTE[buf] = '-';
$inc buf
}
while(mask)
{
tmp = number / mask;
tmp = tmp%10;
if(cmd){
if(tmp){
ESBYTE[buf] = tmp + '0';
$inc buf
cmd = false;
}
}
else {
ESBYTE[buf] = tmp + '0';
$inc buf
}
mask /= 10;
}
ESBYTE[buf] = 0;
return ret;
}
inline fastcall itoa_(signed int EDI, ESI) inline fastcall itoa_(signed int EDI, ESI)
{ {
$pusha $pusha
EBX = EDI; EBX = EDI;
ECX = 10; ECX = 10;
if (ESI > 90073741824) if (ESI > 90073741824)
{ {
$mov al, '-' $mov al, '-'
$stosb $stosb
$neg esi $neg esi
} }
$mov eax, esi $mov eax, esi
$push -'0' $push -'0'
F2: F2:
$xor edx, edx $xor edx, edx
$div ecx $div ecx
$push edx $push edx
$test eax, eax $test eax, eax
$jnz F2 $jnz F2
F3: F3:
$pop eax $pop eax
$add al, '0' $add al, '0'
$stosb $stosb
$jnz F3 $jnz F3
$mov al, '\0' $mov al, '\0'
$stosb $stosb
$popa $popa
return EBX; return EBX;
} }
dword strdup(dword text)
{
dword l = strlen(text);
dword ret = malloc(l+1);
strncpy(ret,text,l);
return ret;
}
void debugi(dword d_int) void debugi(dword d_int)
{ {
char tmpch[12]; char tmpch[12];
itoa_(#tmpch, d_int); itoa_(#tmpch, d_int);
debugln(#tmpch); debugln(#tmpch);
} }
#define strncpy strcpyn //#define strncpy strcpyn
#define strnmov strmovn #define strnmov strmovn
#define stricmp strcmpi #define stricmp strcmpi
#define strcmpn strncmp #define strcmpn strncmp