Subversion Repositories Kolibri OS

Rev

Rev 1005 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1005 Rev 1764
1
#include "func.h"
1
#include "func.h"
2
 
2
 
3
int SysColor = 0;
3
int SysColor = 0;
4
char debuf[50] = "";
4
char debuf[50] = "";
5
 
5
 
6
// ïî÷åìó-òî íå áûëî â ñòàíäàðòíîé áèáëèîòåêå
6
// ïî÷åìó-òî íå áûëî â ñòàíäàðòíîé áèáëèîòåêå
7
void kos_DrawLine( Word x1, Word y1, Word x2, Word y2, Dword colour, Dword invert )
7
void kos_DrawLine( Word x1, Word y1, Word x2, Word y2, Dword colour, Dword invert )
8
{
8
{
9
	Dword arg1, arg2, arg3;
9
	Dword arg1, arg2, arg3;
10
 
10
 
11
	//
11
	//
12
	arg1 = ( x1 << 16 ) | x2;
12
	arg1 = ( x1 << 16 ) | x2;
13
	arg2 = ( y1 << 16 ) | y2;
13
	arg2 = ( y1 << 16 ) | y2;
14
	arg3 = (invert)?0x01000000:colour;
14
	arg3 = (invert)?0x01000000:colour;
15
	//
15
	//
16
	__asm{
16
	__asm{
17
		mov eax, 38
17
		mov eax, 38
18
		mov ebx, arg1
18
		mov ebx, arg1
19
		mov ecx, arg2
19
		mov ecx, arg2
20
		mov edx, arg3
20
		mov edx, arg3
21
		int 0x40
21
		int 0x40
22
	}
22
	}
23
}
23
}
24
 
24
 
25
// ïîõèùåíî èç áèáëèîòåêè ê C--
25
// ïîõèùåíî èç áèáëèîòåêè ê C--
26
void DrawRegion(Dword x,Dword y,Dword width,Dword height,Dword color1)
26
void DrawRegion(Dword x,Dword y,Dword width,Dword height,Dword color1)
27
{
27
{
28
	kos_DrawBar(x,y,width,1,color1); //ïîëîñà ãîð ñâåðõó
28
	kos_DrawBar(x,y,width,1,color1); //ïîëîñà ãîð ñâåðõó
29
	kos_DrawBar(x,y+height,width,1,color1); //ïîëîñà ãîð ñíèçó
29
	kos_DrawBar(x,y+height,width,1,color1); //ïîëîñà ãîð ñíèçó
30
	kos_DrawBar(x,y,1,height,color1); //ïîëîñà âåðò ñëåâà
30
	kos_DrawBar(x,y,1,height,color1); //ïîëîñà âåðò ñëåâà
31
	kos_DrawBar(x+width,y,1,height+1,color1); //ïîëîñà âåðò ñïðàâà
31
	kos_DrawBar(x+width,y,1,height+1,color1); //ïîëîñà âåðò ñïðàâà
32
}
32
}
33
 
33
 
34
 
34
 
35
// äà, ýòî áàÿí
35
// äà, ýòî áàÿí
36
int atoi(const char* string)
36
int atoi(const char* string)
37
{
37
{
38
	int res=0;
38
	int res=0;
39
	int sign=0;
39
	int sign=0;
40
	const char* ptr;
40
	const char* ptr;
41
	for (ptr=string; *ptr && *ptr<=' ';ptr++);
41
	for (ptr=string; *ptr && *ptr<=' ';ptr++);
42
	if (*ptr=='-') {sign=1;++ptr;}
42
	if (*ptr=='-') {sign=1;++ptr;}
43
	while (*ptr >= '0' && *ptr <= '9')
43
	while (*ptr >= '0' && *ptr <= '9')
44
	{
44
	{
45
		res = res*10 + *ptr++ - '0';
45
		res = res*10 + *ptr++ - '0';
46
	}
46
	}
47
	if (sign) res = -res;
47
	if (sign) res = -res;
48
	return res;
48
	return res;
49
}
49
}
50
 
50
 
51
/*int abs(int n)
51
/*int abs(int n)
52
{
52
{
53
	return (n<0)?-n:n;
53
	return (n<0)?-n:n;
54
}*/
54
}*/
55
 
55
 
56
 
56
 
57
 
57
 
58
 
58
 
59
 
59
 
60
double fabs(double x)
60
double __cdecl fabs(double x)
61
{
61
{
62
	__asm	fld	x
62
	__asm	fld	x
63
	__asm	fabs
63
	__asm	fabs
64
}
64
}
65
#define M_PI       3.14159265358979323846
65
#define M_PI       3.14159265358979323846
66
double cos(double x)
66
double __cdecl cos(double x)
67
{
67
{
68
	__asm	fld	x
68
	__asm	fld	x
69
	__asm	fcos
69
	__asm	fcos
70
}
70
}
71
double sin(double x)
71
double __cdecl sin(double x)
72
{
72
{
73
	__asm	fld	x
73
	__asm	fld	x
74
	__asm	fsin
74
	__asm	fsin
75
}
75
}
76
 
76
 
77
int di(double x)
77
int di(double x)
78
{
78
{
79
	int a;
79
	int a;
80
	__asm fld x
80
	__asm fld x
81
	__asm fistp a
81
	__asm fistp a
82
	return a;
82
	return a;
83
}
83
}
84
 
84
 
85
double id(int x)
85
double id(int x)
86
{
86
{
87
	double a;
87
	double a;
88
	__asm fild x
88
	__asm fild x
89
	__asm fstp a
89
	__asm fstp a
90
	return a;
90
	return a;
91
}
91
}
92
 
92
 
93
bool isalpha(char c)
93
bool isalpha(char c)
94
{
94
{
95
	return (c==' ' || c=='\n' || c=='\t' || c=='\r');
95
	return (c==' ' || c=='\n' || c=='\t' || c=='\r');
96
}
96
}
97
 
97
 
98
// ýòà ôóíêöèÿ - âåëîñèïåä. íî ïðîùå áûëî íàïèñàòü ÷åì íàéòè.
98
// ýòà ôóíêöèÿ - âåëîñèïåä. íî ïðîùå áûëî íàïèñàòü ÷åì íàéòè.
99
double convert(char *s, int *len)
99
double convert(char *s, int *len)
100
{
100
{
101
 
101
 
102
	int i;
102
	int i;
103
 
103
 
104
 
104
 
105
	double sign,res, tail, div;
105
	double sign,res, tail, div;
106
 
106
 
107
	res = 0.0;
107
	res = 0.0;
108
 
108
 
109
	i=0;
109
	i=0;
110
	while (s[i] && isalpha(s[i])) i++;
110
	while (s[i] && isalpha(s[i])) i++;
111
	if (len) *len=i;
111
	if (len) *len=i;
112
	if (s[i] == '\0')
112
	if (s[i] == '\0')
113
		return ERROR_END;
113
		return ERROR_END;
114
 
114
 
115
	sign=1.0;
115
	sign=1.0;
116
	if (s[i] == '-')
116
	if (s[i] == '-')
117
	{
117
	{
118
		sign=-1.0;
118
		sign=-1.0;
119
		i++;
119
		i++;
120
	}
120
	}
121
	while (s[i] && s[i] >= '0' && s[i] <= '9')
121
	while (s[i] && s[i] >= '0' && s[i] <= '9')
122
	{
122
	{
123
		res *= 10.0;
123
		res *= 10.0;
124
		res += id(s[i] - '0');
124
		res += id(s[i] - '0');
125
		i++;
125
		i++;
126
	}
126
	}
127
	if (len) *len=i;
127
	if (len) *len=i;
128
	if (!s[i] || isalpha(s[i]))
128
	if (!s[i] || isalpha(s[i]))
129
		return sign*res;
129
		return sign*res;
130
	if (s[i] != '.' && s[i] != ',')
130
	if (s[i] != '.' && s[i] != ',')
131
		return ERROR;
131
		return ERROR;
132
	i++;
132
	i++;
133
	if (len) *len=i;
133
	if (len) *len=i;
134
	if (!s[i])
134
	if (!s[i])
135
		return sign*res;
135
		return sign*res;
136
	
136
	
137
	div = 1.0;
137
	div = 1.0;
138
	tail = 0.0;
138
	tail = 0.0;
139
	while (s[i] && s[i] >= '0' && s[i] <= '9')
139
	while (s[i] && s[i] >= '0' && s[i] <= '9')
140
	{
140
	{
141
		tail *= 10.0;
141
		tail *= 10.0;
142
		tail += id(s[i] - '0');
142
		tail += id(s[i] - '0');
143
		div *= 10.0;
143
		div *= 10.0;
144
		i++;		
144
		i++;		
145
	}
145
	}
146
	res += tail/div;
146
	res += tail/div;
147
	if (len) *len=i;
147
	if (len) *len=i;
148
	return sign*res;
148
	return sign*res;
149
}
149
}
150
 
150
 
151
 
151
 
152
 
152
 
153
#define PREC 2
153
#define PREC 2
154
 
154
 
155
double double_tab[]={1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15};
155
double double_tab[]={1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15};
156
 
156
 
157
// ýòî sprintf, óìåþùèé ôîðìàòèðîâàòü _òîëüêî_ âåùåñòâåííûå ÷èñëà (double) %f
157
// ýòî sprintf, óìåþùèé ôîðìàòèðîâàòü _òîëüêî_ âåùåñòâåííûå ÷èñëà (double) %f
158
void format( char *Str, int len, char* Format, ... )
158
void format( char *Str, int len, char* Format, ... )
159
{
159
{
160
	int i, fmtlinesize, j, k, flag;
160
	int i, fmtlinesize, j, k, flag;
161
	char c;
161
	char c;
162
	va_list arglist;
162
	va_list arglist;
163
	//
163
	//
164
	va_start(arglist, Format);
164
	va_start(arglist, Format);
165
 
165
 
166
	//
166
	//
167
	fmtlinesize = strlen( Format );
167
	fmtlinesize = strlen( Format );
168
	//
168
	//
169
	if( fmtlinesize == 0 ) return;
169
	if( fmtlinesize == 0 ) return;
170
 
170
 
171
	for (i = 0; i < len; i++)
171
	for (i = 0; i < len; i++)
172
		Str[i] = 0;
172
		Str[i] = 0;
173
  
173
  
174
	//
174
	//
175
	for( i = 0, j = 0; i < fmtlinesize; i++ )
175
	for( i = 0, j = 0; i < fmtlinesize; i++ )
176
	{
176
	{
177
		//
177
		//
178
		c = Format[i];
178
		c = Format[i];
179
		//
179
		//
180
		if( c != '%' )
180
		if( c != '%' )
181
		{
181
		{
182
			Str[j++] = c;
182
			Str[j++] = c;
183
			continue;
183
			continue;
184
		}
184
		}
185
		//
185
		//
186
		i++;
186
		i++;
187
		//
187
		//
188
		if( i >= fmtlinesize ) break;
188
		if( i >= fmtlinesize ) break;
189
 
189
 
190
		//
190
		//
191
		flag = 0;
191
		flag = 0;
192
		//
192
		//
193
		c = Format[i];
193
		c = Format[i];
194
		//
194
		//
195
		switch( c )
195
		switch( c )
196
		{
196
		{
197
		//
197
		//
198
		case '%':
198
		case '%':
199
			Str[j++] = c;
199
			Str[j++] = c;
200
			break;
200
			break;
201
		// auaia aauanoaaiiiai ?enea
201
		// auaia aauanoaaiiiai ?enea
202
		case 'f':
202
		case 'f':
203
			// ii?aaaeeou ?enei oeo? ai oi?ee
203
			// ii?aaaeeou ?enei oeo? ai oi?ee
204
			double val, w;
204
			double val, w;
205
			int p;
205
			int p;
206
			val = va_arg(arglist, double);
206
			val = va_arg(arglist, double);
207
			if (val < 0.0)
207
			if (val < 0.0)
208
			{
208
			{
209
				Str[j++] = '-';
209
				Str[j++] = '-';
210
				val = -val;
210
				val = -val;
211
			}
211
			}
212
			for (k = 0; k < 15; k++)
212
			for (k = 0; k < 15; k++)
213
				if (val < double_tab[k])
213
				if (val < double_tab[k])
214
					break;
214
					break;
215
 
215
 
216
			if (val < 1.0)
216
			if (val < 1.0)
217
			{
217
			{
218
				Str[j++] = '0';
218
				Str[j++] = '0';
219
			}
219
			}
220
			
220
			
221
			for (p = 1; p < k + 1; p++)
221
			for (p = 1; p < k + 1; p++)
222
			{
222
			{
223
				Str[j++] = '0' + di(val / double_tab[k - p] - 0.499) % 10;
223
				Str[j++] = '0' + di(val / double_tab[k - p] - 0.499) % 10;
224
			}
224
			}
225
			Str[j++] = '.';
225
			Str[j++] = '.';
226
			w = 0.1;
226
			w = 0.1;
227
			for (p = 0; p < 2; p++)
227
			for (p = 0; p < 2; p++)
228
			{
228
			{
229
				val-=floor(val);
229
				val-=floor(val);
230
				Str[j++] = '0' + di(val / w - 0.499) % 10;
230
				Str[j++] = '0' + di(val / w - 0.499) % 10;
231
				w /= 10.0;
231
				w /= 10.0;
232
			}
232
			}
233
 
233
 
234
		//
234
		//
235
		default:
235
		default:
236
			break;
236
			break;
237
		}
237
		}
238
	}
238
	}
239
	//
239
	//
240
	Str[j] = 0;
240
	Str[j] = 0;
241
}
241
}
242
 
242
 
243
void *memcpy(void *dst, const void *src, unsigned size)
243
#ifndef AUTOBUILD
-
 
244
void *memcpy(void *dst, const void *src, unsigned size)
244
{
245
{
245
	while (size--)
246
	while (size--)
246
		*((char*)dst+size) = *((char*)src+size);
247
		*((char*)dst+size) = *((char*)src+size);
247
	return dst;
248
	return dst;
248
}
249
}
249
 
250
#endif
250
int strcmp(const char *s1, const char *s2)
251
 
-
 
252
int strcmp(const char *s1, const char *s2)
251
{
253
{
252
	int i;
254
	int i;
253
 
255
 
254
	if (s1 == NULL)
256
	if (s1 == NULL)
255
		if (s2 == NULL)
257
		if (s2 == NULL)
256
			return 0;
258
			return 0;
257
		else
259
		else
258
			return 1;
260
			return 1;
259
	else
261
	else
260
		if (s2 == NULL)
262
		if (s2 == NULL)
261
			return 1;
263
			return 1;
262
 
264
 
263
	for (i = 0;;i++)
265
	for (i = 0;;i++)
264
	{
266
	{
265
		if (s1[i] == '\0')
267
		if (s1[i] == '\0')
266
			if (s2[i] == '\0')
268
			if (s2[i] == '\0')
267
				return 0;
269
				return 0;
268
			else
270
			else
269
				return 1;
271
				return 1;
270
		else
272
		else
271
			if (s2[i] == '\0')
273
			if (s2[i] == '\0')
272
				return 1;
274
				return 1;
273
			else
275
			else
274
			{
276
			{
275
				if (s1[i] != s2[i])
277
				if (s1[i] != s2[i])
276
					return 1;
278
					return 1;
277
			}
279
			}
278
	}
280
	}
279
	return 0;
281
	return 0;
280
}
282
}
281
 
283
 
282
kol_struct_import* kol_cofflib_load(char *name)
284
kol_struct_import* kol_cofflib_load(char *name)
283
{
285
{
284
//asm ("int $0x40"::"a"(68), "b"(19), "c"(name));
286
//asm ("int $0x40"::"a"(68), "b"(19), "c"(name));
285
	__asm
287
	__asm
286
	{
288
	{
287
		mov eax, 68
289
		mov eax, 68
288
		mov ebx, 19
290
		mov ebx, 19
289
		mov ecx, name
291
		mov ecx, name
290
		int 0x40
292
		int 0x40
291
	}
293
	}
292
}
294
}
293
 
295
 
294
 
296
 
295
void* kol_cofflib_procload (kol_struct_import *imp, char *name)
297
void* kol_cofflib_procload (kol_struct_import *imp, char *name)
296
{
298
{
297
	
299
	
298
int i;
300
int i;
299
for (i=0;;i++)
301
for (i=0;;i++)
300
	if ( NULL == ((imp+i) -> name))
302
	if ( NULL == ((imp+i) -> name))
301
		break;
303
		break;
302
	else
304
	else
303
		if ( 0 == strcmp(name, (imp+i)->name) )
305
		if ( 0 == strcmp(name, (imp+i)->name) )
304
			return (imp+i)->data;
306
			return (imp+i)->data;
305
return NULL;
307
return NULL;
306
 
308
 
307
}
309
}
308
 
310
 
309
 
311
 
310
unsigned kol_cofflib_procnum (kol_struct_import *imp)
312
unsigned kol_cofflib_procnum (kol_struct_import *imp)
311
{
313
{
312
	
314
	
313
unsigned i, n;
315
unsigned i, n;
314
 
316
 
315
for (i=n=0;;i++)
317
for (i=n=0;;i++)
316
	if ( NULL == ((imp+i) -> name))
318
	if ( NULL == ((imp+i) -> name))
317
		break;
319
		break;
318
	else
320
	else
319
		n++;
321
		n++;
320
 
322
 
321
return n;
323
return n;
322
 
324
 
323
}
325
}
324
 
326
 
325
 
327
 
326
void kol_cofflib_procname (kol_struct_import *imp, char *name, unsigned n)
328
void kol_cofflib_procname (kol_struct_import *imp, char *name, unsigned n)
327
{
329
{
328
	
330
	
329
unsigned i;
331
unsigned i;
330
*name = 0;
332
*name = 0;
331
 
333
 
332
for (i=0;;i++)
334
for (i=0;;i++)
333
	if ( NULL == ((imp+i) -> name))
335
	if ( NULL == ((imp+i) -> name))
334
		break;
336
		break;
335
	else
337
	else
336
		if ( i == n )
338
		if ( i == n )
337
			{
339
			{
338
			strcpy(name, ((imp+i)->name));
340
			strcpy(name, ((imp+i)->name));
339
			break;
341
			break;
340
			}
342
			}
341
 
343
 
342
}
344
}
343
 
345
 
344
 
346
 
345
 
347
 
346
/*
348
/*
347
end of system part
349
end of system part
348
*/
350
*/
349
 
351
 
350
 
352
 
351
// ïîñêîëüêó ÿ ïîðòèðîâàë ñ äðåâíåãî äîñà...
353
// ïîñêîëüêó ÿ ïîðòèðîâàë ñ äðåâíåãî äîñà...
352
void line( int x1, int y1, int x2, int y2)
354
void line( int x1, int y1, int x2, int y2)
353
{
355
{
354
	kos_DrawLine(x1,y1,x2,y2,SysColor,0);
356
	kos_DrawLine(x1,y1,x2,y2,SysColor,0);
355
}
357
}
356
 
358
 
357
void outtextxy( int x, int y, char *s, int len)
359
void outtextxy( int x, int y, char *s, int len)
358
{
360
{
359
	kos_WriteTextToWindow(x,y,0,SysColor,s,len);
361
	kos_WriteTextToWindow(x,y,0,SysColor,s,len);
360
}
362
}
361
 
363
 
362
double textwidth( char *s, int len)
364
double textwidth( char *s, int len)
363
{
365
{
364
	int i;
366
	int i;
365
	for (i = 0; i < len; i++)
367
	for (i = 0; i < len; i++)
366
		if (s[i] == 0)
368
		if (s[i] == 0)
367
			break;
369
			break;
368
	return id(i * 6);
370
	return id(i * 6);
369
}
371
}
370
 
372
 
371
double textheight( char *s, int len)
373
double textheight( char *s, int len)
372
{
374
{
373
	return 8.0;
375
	return 8.0;
374
}
376
}
375
 
377
 
376
void setcolor( DWORD color)
378
void setcolor( DWORD color)
377
{
379
{
378
	SysColor = color;
380
	SysColor = color;
379
}
381
}
380
 
382
 
381
void rectangle( int x1, int y1, int x2, int y2)
383
void rectangle( int x1, int y1, int x2, int y2)
382
{
384
{
383
	kos_DrawBar(x1,y1,x2-x1,y2-y1,SysColor);
385
	kos_DrawBar(x1,y1,x2-x1,y2-y1,SysColor);
384
}
386
}
385
}*/
387
}*/
386
 
388
 
387
 
389
 
388
 
390
 
389
 
391
 
390
 
392
 
391
double>
393
double>