Subversion Repositories Kolibri OS

Rev

Rev 1764 | Details | Compare with Previous | Last modification | View Log | RSS feed

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