Subversion Repositories Kolibri OS

Rev

Rev 5115 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5115 Rev 5822
1
#include "kosSyst.h"
1
#include "kosSyst.h"
2
 
2
 
3
#define atexitBufferSize	32
3
#define atexitBufferSize	32
4
 
4
 
5
// Autobuild uses FASM method for exe->kos,
5
// Autobuild uses FASM method for exe->kos,
6
// MENUET01 header should be present in EXE.
6
// MENUET01 header should be present in EXE.
7
#ifdef AUTOBUILD
7
#ifdef AUTOBUILD
8
char kosExePath[1024];
8
char kosExePath[1024];
9
char exeStack[16384];
9
char exeStack[16384];
10
// must be alphabetically first in the image
10
// must be alphabetically first in the image
11
#pragma data_seg(".1seg")
11
#pragma data_seg(".1seg")
12
extern "C" struct
12
extern "C" struct
13
{
13
{
14
	char header[8];
14
	char header[8];
15
	int headerver;
15
	int headerver;
16
	void* entry;
16
	void* entry;
17
	void* i_end;
17
	void* i_end;
18
	void* memsize;
18
	void* memsize;
19
	void* stack;
19
	void* stack;
20
	void* params;
20
	void* params;
21
	void* icon;
21
	void* icon;
22
} header = {
22
} header = {
23
	{'M', 'E', 'N', 'U', 'E', 'T', '0', '1'},
23
	{'M', 'E', 'N', 'U', 'E', 'T', '0', '1'},
24
	1,
24
	1,
25
	&crtStartUp,
25
	&crtStartUp,
26
	0,	// filled by doexe2.asm
26
	0,	// filled by doexe2.asm
27
	0,	// filled by doexe2.asm
27
	0,	// filled by doexe2.asm
28
	exeStack + sizeof(exeStack),
28
	exeStack + sizeof(exeStack),
29
	NULL,
29
	NULL,
30
	kosExePath
30
	kosExePath
31
};
31
};
32
#pragma data_seg()
32
#pragma data_seg()
33
#else
33
#else
34
char *kosExePath = NULL;
34
char *kosExePath = NULL;
35
#endif
35
#endif
36
 
36
 
37
char pureCallMessage[] = "PURE function call!";
37
char pureCallMessage[] = "PURE function call!";
38
 
38
 
39
//
39
//
40
void (__cdecl *atExitList[atexitBufferSize])();
40
void (__cdecl *atExitList[atexitBufferSize])();
41
int atExitFnNum = 0;
41
int atExitFnNum = 0;
42
//
42
//
43
int __cdecl atexit( void (__cdecl *func )( void ))
43
int __cdecl atexit( void (__cdecl *func )( void ))
44
{
44
{
45
	//
45
	//
46
	if ( atExitFnNum < atexitBufferSize )
46
	if ( atExitFnNum < atexitBufferSize )
47
	{
47
	{
48
		//
48
		//
49
		atExitList[atExitFnNum++] = func;
49
		atExitList[atExitFnNum++] = func;
50
		return 0;
50
		return 0;
51
	}
51
	}
52
	else
52
	else
53
	{
53
	{
54
		return 1;
54
		return 1;
55
	}
55
	}
56
}
56
}
57
 
57
 
58
 
58
 
59
//
59
//
60
Dword RandomSeed = 1;
60
Dword RandomSeed = 1;
61
//
61
//
62
void rtlSrand( Dword seed )
62
void rtlSrand( Dword seed )
63
{
63
{
64
	RandomSeed = seed;
64
	RandomSeed = seed;
65
}
65
}
66
//
66
//
67
Dword rtlRand( void )
67
Dword rtlRand( void )
68
{
68
{
69
  //ìàñêà 0x80000776
69
  //ìàñêà 0x80000776
70
 
70
 
71
  Dword dwi, i;
71
  Dword dwi, i;
72
 
72
 
73
  for ( i = 0; i < 32; i++ )
73
  for ( i = 0; i < 32; i++ )
74
  {
74
  {
75
 
75
 
76
    dwi = RandomSeed & 0x80000776;
76
    dwi = RandomSeed & 0x80000776;
77
  
77
  
78
      __asm{
78
      __asm{
79
            mov   eax, dwi
79
            mov   eax, dwi
80
            mov   edx, eax
80
            mov   edx, eax
81
            bswap eax
81
            bswap eax
82
            xor   eax, edx
82
            xor   eax, edx
83
            xor   al, ah
83
            xor   al, ah
84
            setpo al
84
            setpo al
85
            movzx eax, al
85
            movzx eax, al
86
            mov   dwi, eax
86
            mov   dwi, eax
87
    }
87
    }
88
 
88
 
89
    RandomSeed = ( RandomSeed << 1 ) | ( dwi & 1 );
89
    RandomSeed = ( RandomSeed << 1 ) | ( dwi & 1 );
90
  }
90
  }
91
  
91
  
92
 return RandomSeed;
92
 return RandomSeed;
93
}
93
}
94
 
94
 
95
//
95
//
96
void * __cdecl memcpy( void *dst, const void *src, size_t bytesCount )
96
void * __cdecl memcpy( void *dst, const void *src, size_t bytesCount )
97
{
97
{
98
	__asm{
98
	__asm{
99
		mov edi, dst
99
		mov edi, dst
100
		mov eax, dst
100
		mov eax, dst
101
		mov esi, src
101
		mov esi, src
102
		mov ecx, bytesCount
102
		mov ecx, bytesCount
103
		rep movsb
103
		rep movsb
104
	}
104
	}
105
}
105
}
106
 
106
 
107
//
107
//
108
void memset( Byte *dst, Byte filler, Dword count )
108
void memset( Byte *dst, Byte filler, Dword count )
109
{
109
{
110
	//
110
	//
111
	__asm{
111
	__asm{
112
		mov edi, dst
112
		mov edi, dst
113
		mov al, filler
113
		mov al, filler
114
		mov ecx, count
114
		mov ecx, count
115
		rep stosb
115
		rep stosb
116
	}
116
	}
117
}
117
}
118
 
118
 
119
//
119
//
120
Dword rtlInterlockedExchange( Dword *target, Dword value )
120
Dword rtlInterlockedExchange( Dword *target, Dword value )
121
{
121
{
122
//	Dword result;
122
//	Dword result;
123
 
123
 
124
	//
124
	//
125
	__asm{
125
	__asm{
126
		mov eax, value
126
		mov eax, value
127
		mov ebx, target
127
		mov ebx, target
128
		xchg eax, [ebx]
128
		xchg eax, [ebx]
129
//		mov result, eax
129
//		mov result, eax
130
	}
130
	}
131
	//
131
	//
132
//	return result;
132
//	return result;
133
}
133
}
134
 
134
 
135
 
135
 
136
//////////////////////////////////////////////////////////////////////
136
//////////////////////////////////////////////////////////////////////
137
//
137
//
138
// êîïèðîâàíèå ñòðîêè
138
// êîïèðîâàíèå ñòðîêè
139
//
139
//
140
 
140
 
141
char * __cdecl strcpy( char *target, const char *source )
141
char * __cdecl strcpy( char *target, const char *source )
142
{
142
{
143
	char *result = target;
143
	char *result = target;
144
 
144
 
145
	while( target[0] = source[0] )
145
	while( target[0] = source[0] )
146
	{
146
	{
147
		target++;
147
		target++;
148
		source++;
148
		source++;
149
	}
149
	}
150
 
150
 
151
	return result;
151
	return result;
152
}
152
}
153
 
153
 
154
 
154
 
155
//////////////////////////////////////////////////////////////////////
155
//////////////////////////////////////////////////////////////////////
156
//
156
//
157
// ðåâåðñèâíûé ïîèñê ñèìâîëà
157
// ðåâåðñèâíûé ïîèñê ñèìâîëà
158
//
158
//
159
 
159
 
160
char * __cdecl strrchr( const char * string, int c )
160
char * __cdecl strrchr( const char * string, int c )
161
{
161
{
162
	char *cPtr;
162
	char *cPtr;
163
 
163
 
164
	//
164
	//
165
	for ( cPtr = (char *)string + strlen( string ); cPtr >= string; cPtr-- )
165
	for ( cPtr = (char *)string + strlen( string ); cPtr >= string; cPtr-- )
166
	{
166
	{
167
		//
167
		//
168
		if ( *cPtr == c ) return cPtr;
168
		if ( *cPtr == c ) return cPtr;
169
	}
169
	}
170
	//
170
	//
171
	return NULL;
171
	return NULL;
172
}
172
}
173
 
173
 
174
 
174
 
175
//////////////////////////////////////////////////////////////////////
175
//////////////////////////////////////////////////////////////////////
176
//
176
//
177
// îïðåäåëåíèå äëèíû ñòðîêè
177
// îïðåäåëåíèå äëèíû ñòðîêè
178
//
178
//
179
 
179
 
180
int __cdecl strlen( const char *line )
180
int __cdecl strlen( const char *line )
181
{
181
{
182
  int i;
182
  int i;
183
 
183
 
184
  for( i=0; line[i] != 0; i++ );
184
  for( i=0; line[i] != 0; i++ );
185
  return i;
185
  return i;
186
}
186
}
187
 
187
 
188
 
188
 
189
 
189
 
190
//////////////////////////////////////////////////////////////////////
190
//////////////////////////////////////////////////////////////////////
191
//
191
//
192
// ïåðåâîä øåñòíàäöàòèðè÷íîãî ÷èñëà â ñèìâîë
192
// ïåðåâîä øåñòíàäöàòèðè÷íîãî ÷èñëà â ñèìâîë
193
//
193
//
194
 
194
 
195
unsigned int num2hex( unsigned int num )
195
unsigned int num2hex( unsigned int num )
196
{
196
{
197
  if( num < 10 )
197
  if( num < 10 )
198
    return num + '0';
198
    return num + '0';
199
  return num - 10 + 'A';
199
  return num - 10 + 'A';
200
}
200
}
201
 
201
 
202
 
202
 
203
//////////////////////////////////////////////////////////////////////
203
//////////////////////////////////////////////////////////////////////
204
//
204
//
205
// âûâîä ñòðîêè íà ïå÷àòü
205
// âûâîä ñòðîêè íà ïå÷àòü
206
//
206
//
207
 
207
 
208
Dword dectab[] = { 1000000000, 100000000, 10000000, 1000000, 100000,
208
Dword dectab[] = { 1000000000, 100000000, 10000000, 1000000, 100000,
209
                   10000, 1000, 100, 10, 0 };
209
                   10000, 1000, 100, 10, 0 };
210
 
210
 
211
//
211
//
212
void sprintk( char *Str, PRINTK *arg )
212
void sprintk( char *Str, PRINTK *arg )
213
{
213
{
214
	int i, fmtlinesize, j, ac, k, flag;
214
	int i, fmtlinesize, j, ac, k, flag;
215
	Dword head, tail;
215
	Dword head, tail;
216
	char c;
216
	char c;
217
	
217
	
218
	//
218
	//
219
	ac = 0;
219
	ac = 0;
220
 
220
 
221
	//
221
	//
222
	fmtlinesize = strlen( arg->fmtline );
222
	fmtlinesize = strlen( arg->fmtline );
223
	//
223
	//
224
	if( fmtlinesize == 0 ) return;
224
	if( fmtlinesize == 0 ) return;
225
  
225
  
226
	//
226
	//
227
	for( i = 0, j = 0; i < fmtlinesize; i++ )
227
	for( i = 0, j = 0; i < fmtlinesize; i++ )
228
	{
228
	{
229
		//
229
		//
230
		c = arg->fmtline[i];
230
		c = arg->fmtline[i];
231
		//
231
		//
232
		if( c != '%' )
232
		if( c != '%' )
233
		{
233
		{
234
			Str[j++] = c;
234
			Str[j++] = c;
235
			continue;
235
			continue;
236
		}
236
		}
237
		//
237
		//
238
		i++;
238
		i++;
239
		//
239
		//
240
		if( i >= fmtlinesize ) break;
240
		if( i >= fmtlinesize ) break;
241
 
241
 
242
		//
242
		//
243
		flag = 0;
243
		flag = 0;
244
		//
244
		//
245
		c = arg->fmtline[i];
245
		c = arg->fmtline[i];
246
		//
246
		//
247
		switch( c )
247
		switch( c )
248
		{
248
		{
249
		//
249
		//
250
		case '%':
250
		case '%':
251
			Str[j++] = c;
251
			Str[j++] = c;
252
			break;
252
			break;
253
		// âûâîä ñòðîêè
253
		// âûâîä ñòðîêè
254
		case 'S':
254
		case 'S':
255
			for( k = 0; ( c = ((Byte *)arg->args[ac])[k] ) != 0; k++ )
255
			for( k = 0; ( c = ((Byte *)arg->args[ac])[k] ) != 0; k++ )
256
			{
256
			{
257
				Str[j++] = c;
257
				Str[j++] = c;
258
			}
258
			}
259
			ac++;
259
			ac++;
260
			break;
260
			break;
261
		// âûâîä áàéòà
261
		// âûâîä áàéòà
262
		case 'B':
262
		case 'B':
263
			k = (int)(arg->args[ac]) & 0xFF;
263
			k = (int)(arg->args[ac]) & 0xFF;
264
			Str[j++] = num2hex( ( k >> 4 ) & 0xF );
264
			Str[j++] = num2hex( ( k >> 4 ) & 0xF );
265
			Str[j++] = num2hex( k & 0xF );
265
			Str[j++] = num2hex( k & 0xF );
266
			ac++;
266
			ac++;
267
			break;
267
			break;
268
		// âûâîä ñèìâîëà
268
		// âûâîä ñèìâîëà
269
		case 'C':
269
		case 'C':
270
			Str[j++] = (int)(arg->args[ac]) & 0xFF;
270
			Str[j++] = (int)(arg->args[ac]) & 0xFF;
271
			ac++;
271
			ac++;
272
			break;
272
			break;
273
		// âûâîä äâîéíîãî ñëîâà â øåñòíàäöàòèðè÷íîì âèäå
273
		// âûâîä äâîéíîãî ñëîâà â øåñòíàäöàòèðè÷íîì âèäå
274
		case 'X':
274
		case 'X':
275
			for( k = 7; k >= 0; k-- )
275
			for( k = 7; k >= 0; k-- )
276
			{
276
			{
277
				//
277
				//
278
				c = num2hex ( ( (Dword)(arg->args[ac]) >> (k * 4) ) & 0xF );
278
				c = num2hex ( ( (Dword)(arg->args[ac]) >> (k * 4) ) & 0xF );
279
				//
279
				//
280
				if( c == '0' )
280
				if( c == '0' )
281
				{
281
				{
282
					if( flag ) Str[j++] = c;
282
					if( flag ) Str[j++] = c;
283
				}
283
				}
284
				else
284
				else
285
				{
285
				{
286
					flag++;
286
					flag++;
287
					Str[j++] = c;
287
					Str[j++] = c;
288
				}
288
				}
289
			}
289
			}
290
			//
290
			//
291
			if( flag == 0 ) Str[j++] = '0';
291
			if( flag == 0 ) Str[j++] = '0';
292
			ac++;
292
			ac++;
293
			break;
293
			break;
294
		// âûâîä äâîéíîãî ñëîâà â äåñÿòè÷íîì âèäå
294
		// âûâîä äâîéíîãî ñëîâà â äåñÿòè÷íîì âèäå
295
		case 'U':
295
		case 'U':
296
			head = (Dword)(arg->args[ac]);
296
			head = (Dword)(arg->args[ac]);
297
			tail = 0;
297
			tail = 0;
298
			for( k = 0; dectab[k] != 0; k++ )
298
			for( k = 0; dectab[k] != 0; k++ )
299
			{
299
			{
300
				tail = head % dectab[k];
300
				tail = head % dectab[k];
301
				head /= dectab[k];
301
				head /= dectab[k];
302
				c = head + '0';
302
				c = head + '0';
303
				if( c == '0' )
303
				if( c == '0' )
304
				{
304
				{
305
					if( flag ) Str[j++] = c;
305
					if( flag ) Str[j++] = c;
306
				}
306
				}
307
				else
307
				else
308
				{
308
				{
309
					flag++;
309
					flag++;
310
					Str[j++] = c;
310
					Str[j++] = c;
311
				}
311
				}
312
				//
312
				//
313
				head = tail;
313
				head = tail;
314
			}
314
			}
315
			//
315
			//
316
			c = head + '0';
316
			c = head + '0';
317
			Str[j++] = c;
317
			Str[j++] = c;
318
			ac++;
318
			ac++;
319
			break;
319
			break;
320
		// âûâîä 64-áèòíîãî ñëîâà â øåñòíàäöàòèðè÷íîì âèäå
320
		// âûâîä 64-áèòíîãî ñëîâà â øåñòíàäöàòèðè÷íîì âèäå
321
		case 'Q':
321
		case 'Q':
322
			for( k = 7; k >= 0; k-- )
322
			for( k = 7; k >= 0; k-- )
323
			{
323
			{
324
				//
324
				//
325
				c = num2hex ( ( *((unsigned int *)(arg->args[ac]) + 1) >> (k * 4) ) & 0xF );
325
				c = num2hex ( ( *((unsigned int *)(arg->args[ac]) + 1) >> (k * 4) ) & 0xF );
326
				//
326
				//
327
				if( c == '0' )
327
				if( c == '0' )
328
				{
328
				{
329
					if( flag ) Str[j++] = c;
329
					if( flag ) Str[j++] = c;
330
				}
330
				}
331
				else
331
				else
332
				{
332
				{
333
					flag++;
333
					flag++;
334
					Str[j++] = c;
334
					Str[j++] = c;
335
				}
335
				}
336
			}
336
			}
337
			//
337
			//
338
			for( k=7; k >= 0; k-- )
338
			for( k=7; k >= 0; k-- )
339
			{
339
			{
340
				//
340
				//
341
				c = num2hex ( ( *((unsigned int *)(arg->args[ac])) >> (k * 4) ) & 0xF );
341
				c = num2hex ( ( *((unsigned int *)(arg->args[ac])) >> (k * 4) ) & 0xF );
342
				//
342
				//
343
				if( c == '0' )
343
				if( c == '0' )
344
				{
344
				{
345
					if( flag ) Str[j++] = c;
345
					if( flag ) Str[j++] = c;
346
				}
346
				}
347
				else
347
				else
348
				{
348
				{
349
					flag++;
349
					flag++;
350
					Str[j++] = c;
350
					Str[j++] = c;
351
				}
351
				}
352
			}
352
			}
353
			//
353
			//
354
			if( flag == 0 ) Str[j++] = '0';
354
			if( flag == 0 ) Str[j++] = '0';
355
			//
355
			//
356
			ac++;
356
			ac++;
357
			break;
357
			break;
358
		//
358
		//
359
		default:
359
		default:
360
			break;
360
			break;
361
		}
361
		}
362
	}
362
	}
363
	//
363
	//
364
	Str[j] = 0;
364
	Str[j] = 0;
365
}
365
}
366
 
366
 
367
 
367
 
368
// ôóíêöèÿ -1 çàâåðøåíèÿ ïðîöåññà
368
// ôóíêöèÿ -1 çàâåðøåíèÿ ïðîöåññà
369
void kos_ExitApp()
369
void kos_ExitApp()
370
{
370
{
371
	int i;
371
	int i;
372
 
372
 
373
	//
373
	//
374
	for ( i = atExitFnNum - 1; i >= 0; i-- )
374
	for ( i = atExitFnNum - 1; i >= 0; i-- )
375
	{
375
	{
376
		//
376
		//
377
		atExitList[i]();
377
		atExitList[i]();
378
	}
378
	}
379
	//
379
	//
380
	__asm{
380
	__asm{
381
		mov eax, -1
381
		mov eax, -1
382
		int 0x40
382
		int 0x40
383
	}
383
	}
384
}
384
}
385
 
385
 
386
 
386
 
387
// ôóíêöèÿ 0
387
// ôóíêöèÿ 0
388
void kos_DefineAndDrawWindow(
388
void kos_DefineAndDrawWindow(
389
	Word x, Word y,
389
	Word x, Word y,
390
	Word sizeX, Word sizeY,
390
	Word sizeX, Word sizeY,
391
	Byte mainAreaType,
391
	Byte mainAreaType,
392
	Dword mainAreaColour,
392
	Dword mainAreaColour,
393
	Byte headerType,
393
	Byte headerType,
394
	Dword headerColour,
394
	Dword headerColour,
395
	Dword borderColour
395
	char *title
396
	)
396
	)
397
{
397
{
398
	Dword arg1, arg2, arg3, arg4;
398
	Dword arg1, arg2, arg3, arg4;
399
 
399
 
400
	//
400
	//
401
	arg1 = ( x << 16 ) + sizeX;
401
	arg1 = ( x << 16 ) + sizeX;
402
	arg2 = ( y << 16 ) + sizeY;
402
	arg2 = ( y << 16 ) + sizeY;
403
	arg3 = ( mainAreaType << 24 ) | mainAreaColour;
403
	arg3 = ( mainAreaType << 24 ) | mainAreaColour;
404
	arg4 = ( headerType << 24 ) | headerColour;
404
	arg4 = ( headerType << 24 ) | headerColour;
405
	//
405
	//
406
	__asm{
406
	__asm{
407
		mov eax, 0
407
		mov eax, 0
408
		mov ebx, arg1
408
		mov ebx, arg1
409
		mov ecx, arg2
409
		mov ecx, arg2
410
		mov edx, arg3
410
		mov edx, arg3
411
		mov esi, arg4
411
		mov esi, arg4
412
		mov edi, borderColour
412
		mov edi, title
413
		int 0x40
413
		int 0x40
414
	}
414
	}
415
}
415
}
416
 
416
 
417
 
417
 
418
// ôóíêöèÿ 1 ïîñòàâèòü òî÷êó
418
// ôóíêöèÿ 1 ïîñòàâèòü òî÷êó
419
void kos_PutPixel( Dword x, Dword y, Dword colour )
419
void kos_PutPixel( Dword x, Dword y, Dword colour )
420
{
420
{
421
	//
421
	//
422
	__asm{
422
	__asm{
423
		mov eax, 1
423
		mov eax, 1
424
		mov ebx, x
424
		mov ebx, x
425
		mov ecx, y
425
		mov ecx, y
426
		mov edx, colour
426
		mov edx, colour
427
		int 0x40
427
		int 0x40
428
	}
428
	}
429
}
429
}
430
 
430
 
431
 
431
 
432
// ôóíêöèÿ 2 ïîëó÷èòü êîä íàæàòîé êëàâèøè
432
// ôóíêöèÿ 2 ïîëó÷èòü êîä íàæàòîé êëàâèøè
433
bool kos_GetKey( Byte &keyCode )
433
bool kos_GetKey( Byte &keyCode )
434
{
434
{
435
	Dword result;
435
	Dword result;
436
 
436
 
437
	//
437
	//
438
	__asm{
438
	__asm{
439
		mov eax, 2
439
		mov eax, 2
440
		int 0x40
440
		int 0x40
441
		mov result, eax
441
		mov result, eax
442
	}
442
	}
443
	//
443
	//
444
	keyCode = result >> 8;
444
	keyCode = result >> 8;
445
	//
445
	//
446
	return ( result & 0xFF ) == 0;
446
	return ( result & 0xFF ) == 0;
447
}
447
}
448
 
448
 
449
 
449
 
450
// ôóíêöèÿ 3 ïîëó÷èòü âðåìÿ
450
// ôóíêöèÿ 3 ïîëó÷èòü âðåìÿ
451
Dword kos_GetSystemClock()
451
Dword kos_GetSystemClock()
452
{
452
{
453
//	Dword result;
453
//	Dword result;
454
 
454
 
455
	//
455
	//
456
	__asm{
456
	__asm{
457
		mov eax, 3
457
		mov eax, 3
458
		int 0x40
458
		int 0x40
459
//		mov result, eax
459
//		mov result, eax
460
	}
460
	}
461
	//
461
	//
462
//	return result;
462
//	return result;
463
}
463
}
464
 
464
 
465
 
465
 
466
// ôóíêöèÿ 4
466
// ôóíêöèÿ 4
467
void kos_WriteTextToWindow(
467
void kos_WriteTextToWindow(
468
	Word x,
468
	Word x,
469
	Word y,
469
	Word y,
470
	Byte fontType,
470
	Byte fontType,
471
	Dword textColour,
471
	Dword textColour,
472
	char *textPtr,
472
	char *textPtr,
473
	Dword textLen
473
	Dword textLen
474
	)
474
	)
475
{
475
{
476
	Dword arg1, arg2;
476
	Dword arg1, arg2;
477
 
477
 
478
	//
478
	//
479
	arg1 = ( x << 16 ) | y;
479
	arg1 = ( x << 16 ) | y;
480
	arg2 = ( fontType << 24 ) | textColour;
480
	arg2 = ( fontType << 24 ) | textColour;
481
	//
481
	//
482
	__asm{
482
	__asm{
483
		mov eax, 4
483
		mov eax, 4
484
		mov ebx, arg1
484
		mov ebx, arg1
485
		mov ecx, arg2
485
		mov ecx, arg2
486
		mov edx, textPtr
486
		mov edx, textPtr
487
		mov esi, textLen
487
		mov esi, textLen
488
		int 0x40
488
		int 0x40
489
	}
489
	}
490
}
490
}
491
 
491
 
492
 
492
 
493
// ôóíêöèÿ 5 ïàóçà, â ñîòûõ äîëÿõ ñåêóíäû
493
// ôóíêöèÿ 5 ïàóçà, â ñîòûõ äîëÿõ ñåêóíäû
494
void kos_Pause( Dword value )
494
void kos_Pause( Dword value )
495
{
495
{
496
	//
496
	//
497
	__asm{
497
	__asm{
498
		mov eax, 5
498
		mov eax, 5
499
		mov ebx, value
499
		mov ebx, value
500
		int 0x40
500
		int 0x40
501
	}
501
	}
502
}
502
}
503
 
503
 
504
 
504
 
505
// ôóíêöèÿ 7 íàðèñîâàòü èçîáðàæåíèå
505
// ôóíêöèÿ 7 íàðèñîâàòü èçîáðàæåíèå
506
void kos_PutImage( RGB * imagePtr, Word sizeX, Word sizeY, Word x, Word y )
506
void kos_PutImage( RGB * imagePtr, Word sizeX, Word sizeY, Word x, Word y )
507
{
507
{
508
	Dword arg1, arg2;
508
	Dword arg1, arg2;
509
 
509
 
510
	//
510
	//
511
	arg1 = ( sizeX << 16 ) | sizeY;
511
	arg1 = ( sizeX << 16 ) | sizeY;
512
	arg2 = ( x << 16 ) | y;
512
	arg2 = ( x << 16 ) | y;
513
	//
513
	//
514
	__asm{
514
	__asm{
515
		mov eax, 7
515
		mov eax, 7
516
		mov ebx, imagePtr
516
		mov ebx, imagePtr
517
		mov ecx, arg1
517
		mov ecx, arg1
518
		mov edx, arg2
518
		mov edx, arg2
519
		int 0x40
519
		int 0x40
520
	}
520
	}
521
}
521
}
522
 
522
 
523
 
523
 
524
 
524
 
525
// ôóíêöèÿ 8 îïðåäåëèòü êíîïêó
525
// ôóíêöèÿ 8 îïðåäåëèòü êíîïêó
526
void kos_DefineButton( Word x, Word y, Word sizeX, Word sizeY, Dword buttonID, Dword colour )
526
void kos_DefineButton( Word x, Word y, Word sizeX, Word sizeY, Dword buttonID, Dword colour )
527
{
527
{
528
	Dword arg1, arg2;
528
	Dword arg1, arg2;
529
 
529
 
530
	//
530
	//
531
	arg1 = ( x << 16 ) | sizeX;
531
	arg1 = ( x << 16 ) | sizeX;
532
	arg2 = ( y << 16 ) | sizeY;
532
	arg2 = ( y << 16 ) | sizeY;
533
	//
533
	//
534
	__asm{
534
	__asm{
535
		mov eax, 8
535
		mov eax, 8
536
		mov ebx, arg1
536
		mov ebx, arg1
537
		mov ecx, arg2
537
		mov ecx, arg2
538
		mov edx, buttonID
538
		mov edx, buttonID
539
		mov esi, colour
539
		mov esi, colour
540
		int 0x40
540
		int 0x40
541
	}
541
	}
542
}
542
}
543
 
543
 
544
 
544
 
545
// ôóíêöèÿ 9 - èíôîðìàöèÿ î ïðîöåññå
545
// ôóíêöèÿ 9 - èíôîðìàöèÿ î ïðîöåññå
546
Dword kos_ProcessInfo( sProcessInfo *targetPtr, Dword processID )
546
Dword kos_ProcessInfo( sProcessInfo *targetPtr, Dword processID )
547
{
547
{
548
//	Dword result;
548
//	Dword result;
549
 
549
 
550
	//
550
	//
551
	__asm{
551
	__asm{
552
		mov eax, 9
552
		mov eax, 9
553
		mov ebx, targetPtr
553
		mov ebx, targetPtr
554
		mov ecx, processID
554
		mov ecx, processID
555
		int 0x40
555
		int 0x40
556
//		mov result, eax
556
//		mov result, eax
557
	}
557
	}
558
	//
558
	//
559
//	return result;
559
//	return result;
560
}
560
}
561
 
561
 
562
 
562
 
563
// ôóíêöèÿ 10
563
// ôóíêöèÿ 10
564
Dword kos_WaitForEvent()
564
Dword kos_WaitForEvent()
565
{
565
{
566
//	Dword result;
566
//	Dword result;
567
 
567
 
568
	__asm{
568
	__asm{
569
		mov eax, 10
569
		mov eax, 10
570
		int 0x40
570
		int 0x40
571
//		mov result, eax
571
//		mov result, eax
572
	}
572
	}
573
	
573
	
574
//	return result;
574
//	return result;
575
}
575
}
576
 
576
 
577
 
577
 
578
// ôóíêöèÿ 11
578
// ôóíêöèÿ 11
579
Dword kos_CheckForEvent()
579
Dword kos_CheckForEvent()
580
{
580
{
581
//	Dword result;
581
//	Dword result;
582
 
582
 
583
	__asm{
583
	__asm{
584
		mov eax, 11
584
		mov eax, 11
585
		int 0x40
585
		int 0x40
586
//		mov result, eax
586
//		mov result, eax
587
	}
587
	}
588
	
588
	
589
//	return result;
589
//	return result;
590
}
590
}
591
 
591
 
592
 
592
 
593
// ôóíêöèÿ 12
593
// ôóíêöèÿ 12
594
void kos_WindowRedrawStatus( Dword status )
594
void kos_WindowRedrawStatus( Dword status )
595
{
595
{
596
	__asm{
596
	__asm{
597
		mov eax, 12
597
		mov eax, 12
598
		mov ebx, status
598
		mov ebx, status
599
		int 0x40
599
		int 0x40
600
	}
600
	}
601
}
601
}
602
 
602
 
603
 
603
 
604
// ôóíêöèÿ 13 íàðèñîâàòü ïîëîñó
604
// ôóíêöèÿ 13 íàðèñîâàòü ïîëîñó
605
void kos_DrawBar( Word x, Word y, Word sizeX, Word sizeY, Dword colour )
605
void kos_DrawBar( Word x, Word y, Word sizeX, Word sizeY, Dword colour )
606
{
606
{
607
	Dword arg1, arg2;
607
	Dword arg1, arg2;
608
 
608
 
609
	//
609
	//
610
	arg1 = ( x << 16 ) | sizeX;
610
	arg1 = ( x << 16 ) | sizeX;
611
	arg2 = ( y << 16 ) | sizeY;
611
	arg2 = ( y << 16 ) | sizeY;
612
	//
612
	//
613
	__asm{
613
	__asm{
614
		mov eax, 13
614
		mov eax, 13
615
		mov ebx, arg1
615
		mov ebx, arg1
616
		mov ecx, arg2
616
		mov ecx, arg2
617
		mov edx, colour
617
		mov edx, colour
618
		int 0x40
618
		int 0x40
619
	}
619
	}
620
}
620
}
621
 
621
 
622
 
622
 
623
// ôóíêöèÿ 17
623
// ôóíêöèÿ 17
624
bool kos_GetButtonID( Dword &buttonID )
624
bool kos_GetButtonID( Dword &buttonID )
625
{
625
{
626
	Dword result;
626
	Dword result;
627
 
627
 
628
	//
628
	//
629
	__asm{
629
	__asm{
630
		mov eax, 17
630
		mov eax, 17
631
		int 0x40
631
		int 0x40
632
		mov result, eax
632
		mov result, eax
633
	}
633
	}
634
	//
634
	//
635
	buttonID = result >> 8;
635
	buttonID = result >> 8;
636
	//
636
	//
637
	return (result & 0xFF) == 0;
637
	return (result & 0xFF) == 0;
638
}
638
}
639
 
639
 
640
 
640
 
641
// ôóíêöèÿ 23
641
// ôóíêöèÿ 23
642
Dword kos_WaitForEvent( Dword timeOut )
642
Dword kos_WaitForEvent( Dword timeOut )
643
{
643
{
644
//	Dword result;
644
//	Dword result;
645
 
645
 
646
	__asm{
646
	__asm{
647
		mov eax, 23
647
		mov eax, 23
648
		mov ebx, timeOut
648
		mov ebx, timeOut
649
		int 0x40
649
		int 0x40
650
//		mov result, eax
650
//		mov result, eax
651
	}
651
	}
652
	
652
	
653
//	return result;
653
//	return result;
654
}
654
}
655
 
655
 
656
 
656
 
657
// ïîëó÷åíèå èíôîðìàöèè î ñîñòîÿíèè "ìûøè" ôóíêöèÿ 37
657
// ïîëó÷åíèå èíôîðìàöèè î ñîñòîÿíèè "ìûøè" ôóíêöèÿ 37
658
void kos_GetMouseState( Dword & buttons, int & cursorX, int & cursorY )
658
void kos_GetMouseState( Dword & buttons, int & cursorX, int & cursorY )
659
{
659
{
660
	Dword mB;
660
	Dword mB;
661
	Word curX;
661
	Word curX;
662
	Word curY;
662
	Word curY;
663
	sProcessInfo sPI;
663
	sProcessInfo sPI;
664
 
664
 
665
	//
665
	//
666
	__asm{
666
	__asm{
667
		mov		eax, 37
667
		mov		eax, 37
668
		mov		ebx, 0
668
		mov		ebx, 0
669
		int		0x40
669
		int		0x40
670
		mov		curY, ax
670
		mov		curY, ax
671
		shr		eax, 16
671
		shr		eax, 16
672
		mov		curX, ax
672
		mov		curX, ax
673
		mov		eax, 37
673
		mov		eax, 37
674
		mov		ebx, 2
674
		mov		ebx, 2
675
		int		0x40
675
		int		0x40
676
		mov		mB, eax
676
		mov		mB, eax
677
	}
677
	}
678
	//
678
	//
679
	kos_ProcessInfo( &sPI );
679
	kos_ProcessInfo( &sPI );
680
	//
680
	//
681
	buttons = mB;
681
	buttons = mB;
682
	cursorX = curX - sPI.processInfo.x_start;
682
	cursorX = curX - sPI.processInfo.x_start;
683
	cursorY = curY - sPI.processInfo.y_start;
683
	cursorY = curY - sPI.processInfo.y_start;
684
}
684
}
685
 
685
 
686
 
686
 
687
// ôóíêöèÿ 40 óñòàíîâèòü ìàñêó ñîáûòèé
687
// ôóíêöèÿ 40 óñòàíîâèòü ìàñêó ñîáûòèé
688
void kos_SetMaskForEvents( Dword mask )
688
void kos_SetMaskForEvents( Dword mask )
689
{
689
{
690
	//
690
	//
691
	__asm{
691
	__asm{
692
		mov eax, 40
692
		mov eax, 40
693
		mov ebx, mask
693
		mov ebx, mask
694
		int 0x40
694
		int 0x40
695
	}
695
	}
696
}
696
}
697
 
697
 
698
 
698
 
699
// ôóíêöèÿ 47 âûâåñòè â îêíî ïðèëîæåíèÿ ÷èñëî
699
// ôóíêöèÿ 47 âûâåñòè â îêíî ïðèëîæåíèÿ ÷èñëî
700
void kos_DisplayNumberToWindow(
700
void kos_DisplayNumberToWindow(
701
   Dword value,
701
   Dword value,
702
   Dword digitsNum,
702
   Dword digitsNum,
703
   Word x,
703
   Word x,
704
   Word y,
704
   Word y,
705
   Dword colour,
705
   Dword colour,
706
   eNumberBase nBase,
706
   eNumberBase nBase,
707
   bool valueIsPointer
707
   bool valueIsPointer
708
   )
708
   )
709
{
709
{
710
	Dword arg1, arg2;
710
	Dword arg1, arg2;
711
 
711
 
712
	//
712
	//
713
	arg1 = ( valueIsPointer ? 1 : 0 ) |
713
	arg1 = ( valueIsPointer ? 1 : 0 ) |
714
		( ((Byte)nBase) << 8 ) |
714
		( ((Byte)nBase) << 8 ) |
715
		( ( digitsNum & 0x1F ) << 16 );
715
		( ( digitsNum & 0x1F ) << 16 );
716
	arg2 = ( x << 16 ) | y;
716
	arg2 = ( x << 16 ) | y;
717
	//
717
	//
718
	__asm{
718
	__asm{
719
		mov eax, 47
719
		mov eax, 47
720
		mov ebx, arg1
720
		mov ebx, arg1
721
		mov ecx, value
721
		mov ecx, value
722
		mov edx, arg2
722
		mov edx, arg2
723
		mov esi, colour
723
		mov esi, colour
724
		int 0x40
724
		int 0x40
725
	}
725
	}
726
}
726
}
727
 
727
 
-
 
728
 
-
 
729
// 48, 4 -- get skin height
-
 
730
Dword kos_GetSkinHeight()
-
 
731
{
-
 
732
	__asm{
-
 
733
		mov eax, 48
-
 
734
		mov ebx, 4
-
 
735
		int 0x40
-
 
736
	}
-
 
737
}
-
 
738
 
728
 
739
 
729
// ôóíêöèÿ 70 äîñòóï ê ôàéëîâîé ñèñòåìå
740
// ôóíêöèÿ 70 äîñòóï ê ôàéëîâîé ñèñòåìå
730
Dword kos_FileSystemAccess( kosFileInfo *fileInfo )
741
Dword kos_FileSystemAccess( kosFileInfo *fileInfo )
731
{
742
{
732
//	Dword result;
743
//	Dword result;
733
 
744
 
734
	//
745
	//
735
	__asm{
746
	__asm{
736
		mov eax, 70
747
		mov eax, 70
737
		mov ebx, fileInfo
748
		mov ebx, fileInfo
738
		int 0x40
749
		int 0x40
739
//		mov result, eax
750
//		mov result, eax
740
	}
751
	}
741
	//
752
	//
742
//	return result;
753
//	return result;
743
}
754
}
744
 
755
 
745
 
756
 
746
// ôóíêöèÿ 63 âûâîä ñèìâîëÿ â îêíî îòëàäêè
757
// ôóíêöèÿ 63 âûâîä ñèìâîëÿ â îêíî îòëàäêè
747
void kos_DebugOutChar( char ccc )
758
void kos_DebugOutChar( char ccc )
748
{
759
{
749
	//
760
	//
750
	__asm{
761
	__asm{
751
		mov eax, 63
762
		mov eax, 63
752
		mov ebx, 1
763
		mov ebx, 1
753
		mov cl, ccc
764
		mov cl, ccc
754
		int 0x40
765
		int 0x40
755
	}
766
	}
756
}
767
}
757
 
768
 
758
 
769
 
759
// ôóíêöèÿ 66 ðåæèì ïîëó÷åíèÿ äàííûõ îò êëàâèàòóðû
770
// ôóíêöèÿ 66 ðåæèì ïîëó÷åíèÿ äàííûõ îò êëàâèàòóðû
760
void kos_SetKeyboardDataMode( Dword mode )
771
void kos_SetKeyboardDataMode( Dword mode )
761
{
772
{
762
	//
773
	//
763
	__asm{
774
	__asm{
764
		mov eax, 66
775
		mov eax, 66
765
		mov ebx, 1
776
		mov ebx, 1
766
		mov ecx, mode
777
		mov ecx, mode
767
		int 0x40
778
		int 0x40
768
	}
779
	}
769
}
780
}
770
 
781
 
771
 
782
 
772
// âûâîä ñòðîêè â îêíî îòëàäêè
783
// âûâîä ñòðîêè â îêíî îòëàäêè
773
void rtlDebugOutString( char *str )
784
void rtlDebugOutString( char *str )
774
{
785
{
775
	//
786
	//
776
	for ( ; str[0] != 0; str++ )
787
	for ( ; str[0] != 0; str++ )
777
	{
788
	{
778
		kos_DebugOutChar( str[0] );
789
		kos_DebugOutChar( str[0] );
779
	}
790
	}
780
	//
791
	//
781
	kos_DebugOutChar( 13 );
792
	kos_DebugOutChar( 13 );
782
	kos_DebugOutChar( 10 );
793
	kos_DebugOutChar( 10 );
783
}
794
}
784
 
795
 
785
 
796
 
786
// ôóíêöèÿ 64 èçìåíåíèå êîëè÷åñòâà ïàìÿòè, âûäåëåííîé äëÿ ïðîãðàììû
797
// ôóíêöèÿ 64 èçìåíåíèå êîëè÷åñòâà ïàìÿòè, âûäåëåííîé äëÿ ïðîãðàììû
787
bool kos_ApplicationMemoryResize( Dword targetSize )
798
bool kos_ApplicationMemoryResize( Dword targetSize )
788
{
799
{
789
	Dword result;
800
	Dword result;
790
 
801
 
791
	//
802
	//
792
	__asm{
803
	__asm{
793
		mov eax, 64
804
		mov eax, 64
794
		mov ebx, 1
805
		mov ebx, 1
795
		mov ecx, targetSize
806
		mov ecx, targetSize
796
		int 0x40
807
		int 0x40
797
		mov result, eax
808
		mov result, eax
798
	}
809
	}
799
	//
810
	//
800
	return result == 0;
811
	return result == 0;
801
}
812
}
802
 
813
 
803
 
814
 
804
// ôóíêöèÿ 67 èçìåíèòü ïàðàìåòðû îêíà, ïàðàìåòð == -1 íå ìåíÿåòñÿ
815
// ôóíêöèÿ 67 èçìåíèòü ïàðàìåòðû îêíà, ïàðàìåòð == -1 íå ìåíÿåòñÿ
805
void kos_ChangeWindow( Dword x, Dword y, Dword sizeX, Dword sizeY )
816
void kos_ChangeWindow( Dword x, Dword y, Dword sizeX, Dword sizeY )
806
{
817
{
807
	//
818
	//
808
	__asm{
819
	__asm{
809
		mov eax, 67
820
		mov eax, 67
810
		mov ebx, x
821
		mov ebx, x
811
		mov ecx, y
822
		mov ecx, y
812
		mov edx, sizeX
823
		mov edx, sizeX
813
		mov esi, sizeY
824
		mov esi, sizeY
814
		int 0x40
825
		int 0x40
815
	}
826
	}
816
}
827
}
817
 
828
 
-
 
829
 
-
 
830
// 71,1 set window caption
-
 
831
void kos_SetWindowCaption(char *caption)
-
 
832
{
-
 
833
	__asm{
-
 
834
		mov eax, 71
-
 
835
		mov ebx, 1
-
 
836
		mov ecx, caption
-
 
837
		int 0x40
-
 
838
	}
-
 
839
}
818
 
840
 
819
 
841
 
820
// âûçîâ àáñòðàêòíîãî ìåòîäà
842
// âûçîâ àáñòðàêòíîãî ìåòîäà
821
int __cdecl _purecall()
843
int __cdecl _purecall()
822
{
844
{
823
	rtlDebugOutString( pureCallMessage );
845
	rtlDebugOutString( pureCallMessage );
824
	kos_ExitApp();
846
	kos_ExitApp();
825
	return 0;
847
	return 0;
826
}
848
}
827
 
849
 
828
 
850
 
829
// âûçîâ ñòàòè÷åñêèõ èíèöèàëèçàòîðîâ
851
// âûçîâ ñòàòè÷åñêèõ èíèöèàëèçàòîðîâ
830
// çàîäíî èíèöèàëèçàöèÿ ãåíåðàòîðà ñëó÷àéíûõ ÷èñåë
852
// çàîäíî èíèöèàëèçàöèÿ ãåíåðàòîðà ñëó÷àéíûõ ÷èñåë
831
#pragma section(".CRT$XCA",long,read,write)
853
#pragma section(".CRT$XCA",long,read,write)
832
#pragma section(".CRT$XCZ",long,read,write)
854
#pragma section(".CRT$XCZ",long,read,write)
833
typedef void (__cdecl *_PVFV)(void);
855
typedef void (__cdecl *_PVFV)(void);
834
__declspec(allocate(".CRT$XCA"))  _PVFV __xc_a[1] = { NULL };
856
__declspec(allocate(".CRT$XCA"))  _PVFV __xc_a[1] = { NULL };
835
__declspec(allocate(".CRT$XCZ"))  _PVFV __xc_z[1] = { NULL };
857
__declspec(allocate(".CRT$XCZ"))  _PVFV __xc_z[1] = { NULL };
836
//
858
//
837
#pragma comment(linker, "/merge:.CRT=.rdata")
859
#pragma comment(linker, "/merge:.CRT=.rdata")
838
//
860
//
839
void crtStartUp()
861
void crtStartUp()
840
{
862
{
841
#ifdef AUTOBUILD
863
#ifdef AUTOBUILD
842
// linker will try to remove unused variables; force header to be included
864
// linker will try to remove unused variables; force header to be included
843
	header.header;
865
	header.header;
844
#endif
866
#endif
845
	// âûçûâàåì èíèöèàëèçàòîðû ïî ñïèñêó, NULL'û èãíîðèðóåì
867
	// âûçûâàåì èíèöèàëèçàòîðû ïî ñïèñêó, NULL'û èãíîðèðóåì
846
	for ( _PVFV *pbegin = __xc_a; pbegin < __xc_z; pbegin++ )
868
	for ( _PVFV *pbegin = __xc_a; pbegin < __xc_z; pbegin++ )
847
	{
869
	{
848
		//
870
		//
849
		if ( *pbegin != NULL )
871
		if ( *pbegin != NULL )
850
			(**pbegin)();
872
			(**pbegin)();
851
	}
873
	}
852
	// èíèöèàëèçèðóåì ãåíåðàòîð ñëó÷àéíûõ ÷èñåë
874
	// èíèöèàëèçèðóåì ãåíåðàòîð ñëó÷àéíûõ ÷èñåë
853
	rtlSrand( kos_GetSystemClock() );
875
	rtlSrand( kos_GetSystemClock() );
854
#ifndef AUTOBUILD
876
#ifndef AUTOBUILD
855
	// ïóòü ê ôàéëó ïðîöåññà
877
	// ïóòü ê ôàéëó ïðîöåññà
856
	kosExePath = *((char **)0x20);
878
	kosExePath = *((char **)0x20);
857
#endif
879
#endif
858
	// âûçîâ ãëàâíîé ôóíêöèè ïðèëîæåíèÿ
880
	// âûçîâ ãëàâíîé ôóíêöèè ïðèëîæåíèÿ
859
	kos_Main();
881
	kos_Main();
860
	// âûõîä
882
	// âûõîä
861
	kos_ExitApp();
883
	kos_ExitApp();
862
}
884
}