Subversion Repositories Kolibri OS

Rev

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

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