Subversion Repositories Kolibri OS

Rev

Rev 7031 | Rev 7054 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6021 leency 1
//CODED by Veliant, Leency, Nable, Pavelyakov. GNU GPL licence.
2
 
5598 pavelyakov 3
#ifndef INCLUDE_KOLIBRI_H
5582 pavelyakov 4
#define INCLUDE_KOLIBRI_H
5576 pavelyakov 5
 
5676 pavelyakov 6
#pragma option OST
7
#pragma option ON
8
#pragma option cri-
9
#pragma option -CPA
10
#initallvar 0
11
#jumptomain FALSE
12
 
3067 leency 13
#startaddress 0
5676 pavelyakov 14
 
3067 leency 15
#code32 TRUE
5676 pavelyakov 16
 
3067 leency 17
char   os_name[8]   = {'M','E','N','U','E','T','0','1'};
18
dword  os_version   = 0x00000001;
5648 pavelyakov 19
dword  start_addr   = #______INIT______;
20
dword  final_addr   = #______STOP______+32;
3363 leency 21
dword  alloc_mem    = MEMSIZE;
22
dword  x86esp_reg   = MEMSIZE;
3067 leency 23
dword  I_Param      = #param;
24
dword  I_Path       = #program_path;
25
char param[4096];
26
char program_path[4096];
27
 
6651 leency 28
#define bool      int
5883 pavelyakov 29
 
3363 leency 30
#define NULL      0
31
#define OLD      -1
32
#define true      1
33
#define false     0
34
 
6039 leency 35
//Process Events
4536 leency 36
#define evReDraw  1
37
#define evKey     2
38
#define evButton  3
6978 leency 39
#define evExit    4
5576 pavelyakov 40
#define evDesktop 5
3067 leency 41
#define evMouse   6
5576 pavelyakov 42
#define evIPC     7
4536 leency 43
#define evNetwork 8
5576 pavelyakov 44
#define evDebug   9
3067 leency 45
 
6978 leency 46
//Event mask bits for function 40
7031 leency 47
#define EVM_REDRAW                1b
48
#define EVM_KEY                  10b
49
#define EVM_BUTTON              100b
50
#define EVM_EXIT               1000b
51
#define EVM_BACKGROUND        10000b
52
#define EVM_MOUSE            100000b
53
#define EVM_IPC             1000000b
54
#define EVM_STACK          10000000b
55
#define EVM_DEBUG         100000000b
56
#define EVM_STACK2       1000000000b
6978 leency 57
#define EVM_MOUSE_FILTER  0x80000000
58
#define EVM_CURSOR_FILTER 0x40000000
59
 
3067 leency 60
//Button options
61
#define BT_DEL      0x80000000
62
#define BT_HIDE     0x40000000
63
#define BT_NOFRAME  0x20000000
64
 
65
//-------------------------------------------------------------------------
66
 
5674 pavelyakov 67
#include "../lib/system.h"
68
#include "../lib/mouse.h"
6285 leency 69
#include "../lib/keyboard.h"
5674 pavelyakov 70
 
6751 leency 71
inline fastcall dword calc(EAX) { return EAX; }
6742 leency 72
 
5477 leency 73
:struct raw_image {
74
	dword w, h, data;
75
};
76
 
3067 leency 77
//------------------------------------------------------------------------------
5582 pavelyakov 78
:dword wait_event_code;
3067 leency 79
inline fastcall dword WaitEvent()
80
{
81
	$mov eax,10
82
	$int 0x40
5576 pavelyakov 83
	wait_event_code = EAX;
5591 pavelyakov 84
	//if(wait_event_code==evMouse) MOUSE.get();
85
	//return wait_event_code;
3067 leency 86
}
87
 
88
inline fastcall dword CheckEvent()
89
{
90
	$mov eax,11
91
	$int 0x40
92
}
93
 
5576 pavelyakov 94
inline fastcall dword WaitEventTimeout(EBX)
3067 leency 95
{
96
	$mov eax,23
97
	$int 0x40
98
}
99
 
6978 leency 100
inline fastcall dword SetEventMask(EBX)
3067 leency 101
{
102
	$mov eax,40
103
	$int 0x40
104
}
105
 
106
 
5576 pavelyakov 107
inline fastcall pause(EBX)
3067 leency 108
{
109
	$mov eax, 5
110
	$int 0x40
111
}
112
 
113
inline fastcall word GetButtonID()
114
{
115
	$mov eax,17
116
	$int  0x40
117
	$shr eax,8
118
}
119
 
120
inline fastcall dword GetFreeRAM()
121
{
122
	$mov eax, 18
123
	$mov ebx, 16
124
	$int 0x40
6980 leency 125
	//return eax = free RAM in Kb
3067 leency 126
}
127
 
6791 leency 128
inline fastcall dword LoadDriver(ECX) //ECX - èìÿ äðàéâåðà
3067 leency 129
{
130
	$mov eax, 68
131
	$mov ebx, 16
132
	$int 0x40
6791 leency 133
	//return 0 - íåóäà÷à, èíà÷å eax = õýíäë äðàéâåðà
3067 leency 134
}
135
 
6791 leency 136
inline fastcall dword RuleDriver(ECX) //óêàçàòåëü íà óïðàâëÿþùóþ ñòðóêòóðó
3067 leency 137
{
138
	$mov eax, 68
139
	$mov ebx, 17
140
	$int 0x40
6791 leency 141
	//return eax = îïðåäåëÿåòñÿ äðàéâåðîì
3067 leency 142
}
143
 
144
struct proc_info
145
{
146
	#define SelfInfo -1
147
	dword	use_cpu;
148
	word	pos_in_stack,num_slot,rezerv1;
4137 leency 149
	unsigned char name[11];
3067 leency 150
	char	rezerv2;
151
	dword	adress,use_memory,ID,left,top,width,height;
152
	word	status_slot,rezerv3;
153
	dword	work_left,work_top,work_width,work_height;
154
	char	status_window;
3107 leency 155
	dword   cwidth,cheight;
156
	byte    reserved[1024-71-8];
3067 leency 157
};
158
 
5576 pavelyakov 159
inline fastcall void GetProcessInfo(EBX, ECX)
3067 leency 160
{
161
	$mov eax,9;
162
	$int  0x40
3107 leency 163
	DSDWORD[EBX+71] = DSDWORD[EBX+42] - 9; //set cwidth
7051 leency 164
	DSDWORD[EBX+75] = DSDWORD[EBX+46] - skin_height - 4; //set cheight
3067 leency 165
}
166
 
167
inline fastcall int GetPointOwner( EBX, ECX) //ebx=m.x, ecx=m.y
168
{
169
	$mov eax,34
170
	$int 0x40
171
}
172
 
173
inline fastcall int GetProcessSlot( ECX)
174
{
175
	EAX = 18;
176
	EBX = 21;
177
	$int 0x40
178
}
179
 
180
inline fastcall int GetActiveProcess()
181
{
182
	EAX = 18;
183
	EBX = 7;
184
	$int 0x40
185
}
186
 
4081 leency 187
:int CheckActiveProcess(int Form_ID)
188
{
4166 leency 189
	int id9=GetProcessSlot(Form_ID);
190
	if (id9==GetActiveProcess()) return 1;
4081 leency 191
	return 0;
192
}
193
 
3114 leency 194
inline fastcall void ActivateWindow( ECX)
195
{
196
	EAX = 18;
197
	EBX = 3;
198
	$int 0x40
199
}
200
 
5421 leency 201
inline fastcall int MinimizeWindow()
202
{
203
	EAX = 18;
204
	EBX = 10;
205
	$int 0x40
206
}
207
 
5576 pavelyakov 208
inline fastcall int CreateThread(ECX,EDX)
3067 leency 209
{
210
	$mov eax,51
211
	$mov ebx,1
212
	$int 0x40
213
}
214
 
215
inline fastcall void SwitchToAnotherThread()
216
{
217
	$mov eax,68
218
	$mov ebx,1
219
	$int 0x40
220
}
221
 
3458 leency 222
inline fastcall int SendWindowMessage( ECX, EDX)
3444 leency 223
{
224
	$mov eax, 72
225
	$mov ebx, 1
226
	$int 0x40
227
}
228
 
3067 leency 229
inline fastcall int KillProcess( ECX)
230
{
231
	$mov eax,18;
232
	$mov ebx,18;
233
	$int 0x40
234
}
235
 
236
#define TURN_OFF 2
237
#define REBOOT 3
238
#define KERNEL 4
239
inline fastcall int ExitSystem( ECX)
240
{
241
	$mov eax, 18
242
	$mov ebx, 9
243
	$int 0x40
244
}
245
 
246
inline fastcall ExitProcess()
247
{
248
	$mov eax,-1;
249
	$int 0x40
250
}
251
 
252
//------------------------------------------------------------------------------
253
 
6563 leency 254
inline fastcall void SetCurDir( ECX)
255
{
256
  EAX=30;
257
  EBX=1;
258
  $int 0x40
259
}
6504 punk_joker 260
 
261
 
6791 leency 262
//eax = ÿçûê ñèñòåìû (1=eng, 2=fi, 3=ger, 4=rus)
6662 leency 263
#define SYS_LANG_ENG 1
264
#define SYS_LANG_FIN 2
265
#define SYS_LANG_GER 3
266
#define SYS_LANG_RUS 4
3067 leency 267
inline fastcall int GetSystemLanguage()
268
{
269
	EAX = 26;
270
	EBX = 5;
271
	$int 0x40
272
}
273
 
274
inline fastcall GetSkinHeight()
275
{
276
	$push ebx
277
	$mov  eax,48
278
	$mov  ebx,4
279
	$int 0x40
280
	$pop  ebx
281
}
282
 
283
inline fastcall void SetSystemSkin( ECX)
284
{
285
	EAX = 48;
286
	EBX = 8;
287
	$int 0x40
288
}
289
 
290
inline fastcall int GetScreenWidth()
291
{
292
	$mov eax, 14
293
	$int 0x40
294
	$shr eax, 16
295
}
296
 
297
inline fastcall int GetScreenHeight()
298
{
299
	$mov eax, 14
300
	$int 0x40
301
	$and eax,0x0000FFFF
302
}
303
 
5421 leency 304
inline fastcall int GetClientTop()
305
{
306
	$mov eax, 48
307
	$mov ebx, 5
308
	$int 0x40
6058 leency 309
	$mov eax, ebx
310
	$shr eax, 16
5421 leency 311
}
312
 
313
inline fastcall int GetClientHeight()
314
{
315
	$mov eax, 48
316
	$mov ebx, 5
317
	$int 0x40
6058 leency 318
	$mov eax, ebx
5421 leency 319
}
320
 
3067 leency 321
inline fastcall dword LoadLibrary( ECX)
322
{
323
	$mov eax, 68
324
	$mov ebx, 19
325
	$int  0x40
326
}
327
 
328
inline fastcall int TestBit( EAX, CL)
329
{
330
	$shr eax,cl
331
	$and eax,1
332
}
333
 
334
//------------------------------------------------------------------------------
335
 
6746 leency 336
:void DefineAndDrawWindow(dword _x, _y, _w, _h, _window_type, _bgcolor, _title, _flags)
3067 leency 337
{
338
	EAX = 12;              // function 12:tell os about windowdraw
339
	EBX = 1;
340
	$int 0x40
341
 
5576 pavelyakov 342
	$xor EAX,EAX
6746 leency 343
	EBX = _x << 16 + _w;
344
	ECX = _y << 16 + _h;
345
	EDX = _window_type << 24 | _bgcolor;
346
	EDI = _title;
347
	ESI = _flags;
3067 leency 348
	$int 0x40
349
 
6742 leency 350
 
3067 leency 351
	EAX = 12;              // function 12:tell os about windowdraw
352
	EBX = 2;
353
	$int 0x40
354
}
355
 
356
inline fastcall MoveSize( EBX,ECX,EDX,ESI)
357
{
358
	$mov eax, 67
359
	$int 0x40
360
}
361
 
362
inline fastcall void DrawTitle( ECX)
363
{
364
	EAX = 71;
365
	EBX = 1;
366
	$int 0x40;
367
}
368
 
6794 leency 369
// @EDX is a process id, -1 for self
6791 leency 370
// @ESI is a new LayerBehaviour
371
// @RETURN: EAX, 0 is fail, 1 is success
6794 leency 372
#define ZPOS_DESKTOP     -2
373
#define ZPOS_ALWAYS_BACK -1
374
#define ZPOS_NORMAL      0
375
#define ZPOS_ALWAYS_TOP  1
6791 leency 376
inline fastcall dword SetWindowLayerBehaviour(EDX, ESI)
377
{
378
	EAX = 18;
379
	EBX = 25;
380
	ECX = 2;
381
	$int 64
382
}
383
 
6735 leency 384
:void WriteTextB(dword x,y,byte fontType, dword color, str_offset)
3067 leency 385
{
386
	EAX = 4;
387
	EBX = x<<16+y;
388
	ECX = fontType<<24+color;
6735 leency 389
	EDX = str_offset;
3363 leency 390
	ESI = 0;
3067 leency 391
	$int 0x40;
3107 leency 392
	$add ebx, 1<<16
393
	$int 0x40
3067 leency 394
}
395
 
6735 leency 396
:void WriteText(dword x,y,byte fontType, dword color, str_offset)
3107 leency 397
{
398
	EAX = 4;
399
	EBX = x<<16+y;
400
	ECX = fontType<<24+color;
6735 leency 401
	EDX = str_offset;
3107 leency 402
	$int 0x40;
403
}
404
 
6742 leency 405
:dword WriteBufText(dword x,y,byte fontType, dword color, str_offset, buf_offset)
3467 leency 406
{
407
	EAX = 4;
408
	EBX = x<<16+y;
409
	ECX = fontType<<24+color;
6742 leency 410
	EDX = str_offset;
411
	EDI = buf_offset;
3467 leency 412
	$int 0x40;
413
}
414
 
6742 leency 415
:void WriteNumber(dword x,y,byte fontType, dword color, count, number_or_offset)
3067 leency 416
{
417
	EAX = 47;
418
	EBX = count<<16;
6735 leency 419
	ECX = number_or_offset;
3067 leency 420
	EDX = x<<16+y;
421
	ESI = fontType<<24+color;
422
	$int 0x40;
423
}
424
 
6735 leency 425
:void CopyScreen(dword dst_offset, x, y, w, h)
3067 leency 426
{
427
  EAX = 36;
6735 leency 428
  EBX = dst_offset;
3363 leency 429
  ECX = w << 16 + h;
3067 leency 430
  EDX = x << 16 + y;
431
  $int  0x40;
432
}
433
 
6791 leency 434
:dword GetPixelColorFromScreen(dword _x, _y)
3067 leency 435
{
6791 leency 436
	EAX = 35;
437
	EBX = _y * screen.width + _x;
438
	$int 64
3067 leency 439
}
440
 
6735 leency 441
:void _PutImage(dword x,y, w,h, data_offset)
3067 leency 442
{
443
	EAX = 7;
6735 leency 444
	EBX = data_offset;
3067 leency 445
	ECX = w<<16+h;
446
	EDX = x<<16+y;
447
	$int 0x40
448
}
449
 
450
void PutPaletteImage(dword EBX,w,h,x,y,ESI,EDI)
451
{
452
	EAX = 65;
453
	ECX = w<<16+h;
454
	EDX = x<<16+y;
455
	EBP = 0;
456
	$int 0x40
6742 leency 457
}
3067 leency 458
 
459
inline fastcall void PutPixel( EBX,ECX,EDX)
460
{
461
  EAX=1;
462
  $int 0x40
463
}
464
 
6742 leency 465
:void DrawBar(dword x,y,w,h,color)
3067 leency 466
{
3225 leency 467
	if (h<=0) || (h>60000) || (w<=0) || (w>60000) return; //bad boy :)
3067 leency 468
	EAX = 13;
469
	EBX = x<<16+w;
470
	ECX = y<<16+h;
6742 leency 471
	EDX = color;
6058 leency 472
	$int 0x40
3067 leency 473
}
474
 
475
void DefineButton(dword x,y,w,h,EDX,ESI)
476
{
3107 leency 477
	EAX = 8;
478
	$push edx
479
	EDX += BT_DEL;
480
	$int 0x40;
481
	$pop edx
3067 leency 482
	EBX = x<<16+w;
483
	ECX = y<<16+h;
484
	$int 0x40
485
}
486
 
5582 pavelyakov 487
inline RefreshWindow(dword ID_REFRESH,ID_ACTIVE)
488
{
489
	EAX = 18;
490
	EBX = 22;
491
	ECX = 3;
492
	EDX = ID_REFRESH;
493
	$int 0x40
494
	EAX = 18;
495
	EBX = 3;
496
	EDX = ID_ACTIVE;
497
	$int 0x40
498
}
499
 
6742 leency 500
:void UnsafeDefineButton(dword x,y,w,h,id,color)
3107 leency 501
{
502
	EAX = 8;
503
	EBX = x<<16+w;
504
	ECX = y<<16+h;
6742 leency 505
	EDX = id;
506
	ESI = color;
3107 leency 507
	$int 0x40
508
}
509
 
6791 leency 510
void DefineDragableWindow(dword _x, _y, _w, _h)
511
{
512
	DefineAndDrawWindow(_x, _y, _w, _h, 0x41,0x000000,NULL,0b);
513
}
514
 
515
:void EventDragWindow()
516
{
517
	dword tmp_x,tmp_y;
518
	dword z1,z2;
519
	tmp_x = mouse.x;
520
	tmp_y = mouse.y;
521
	do {
522
		mouse.get();
523
		if (tmp_x!=mouse.x) || (tmp_y!=mouse.y)
524
		{
525
			z1 = Form.left + mouse.x - tmp_x;
526
			z2 = Form.top + mouse.y - tmp_y;
527
			if(z1<=10) || (z1>20000) z1=0; else if(z1>screen.width-Form.width-10)z1=screen.width-Form.width;
528
			if(z2<=10) || (z2>20000) z2=0; else if(z2>screen.height-Form.height-10)z2=screen.height-Form.height;
529
			MoveSize(z1 , z2, OLD, OLD);
530
			draw_window();
531
		}
532
		pause(1);
533
	} while (mouse.lkm);
534
}
535
 
536
:void DefineHiddenButton(dword _x, _y, _w, _h, _id)
537
{
538
	DefineButton(_x, _y, _w, _h, _id + BT_HIDE, 0);
539
}
540
 
3067 leency 541
inline fastcall void DeleteButton( EDX)
542
{
543
	EAX = 8;
544
	EDX += BT_DEL;
5630 leency 545
	$int 0x40
5548 leency 546
}
547
 
548
inline fastcall dword GetStartTime()
549
{
550
	$mov eax,26
551
	$mov ebx,9
552
	$int 0x40
5575 pavelyakov 553
}
554
 
5606 pavelyakov 555
:dword X_EventRedrawWindow,Y_EventRedrawWindow;
556
:void _EventRedrawWindow()
557
{
558
	loop()switch(WaitEvent())
559
	{
560
		case evReDraw:
6747 leency 561
			DefineAndDrawWindow(X_EventRedrawWindow,Y_EventRedrawWindow,100,1,0x34,0xFFFFFF,NULL,0);
5606 pavelyakov 562
			pause(10);
563
			ExitProcess();
564
			break;
565
	}
566
}
5760 pavelyakov 567
:char REDRAW_BUFF_EVENT_[4096];
5606 pavelyakov 568
:void EventRedrawWindow(dword x,y)
569
{
570
	X_EventRedrawWindow = x;
571
	Y_EventRedrawWindow = y;
5760 pavelyakov 572
	CreateThread(#_EventRedrawWindow,#REDRAW_BUFF_EVENT_+4092);
5606 pavelyakov 573
}
574
 
6285 leency 575
:struct obj
5576 pavelyakov 576
{
6285 leency 577
	dword x,y,w,h;
6738 leency 578
	void set_size();
6285 leency 579
};
580
 
6738 leency 581
:void obj::set_size(dword _x, _y, _w, _h)
5576 pavelyakov 582
{
6285 leency 583
	x=_x;
584
	y=_y;
585
	w=_w;
586
	h=_h;
5576 pavelyakov 587
}
588
 
5582 pavelyakov 589
:struct _screen
590
{
591
	dword width,height;
592
} screen;
593
 
6041 leency 594
:byte skin_height;
5582 pavelyakov 595
 
5640 pavelyakov 596
:void DrawDate(dword x, y, color, in_date)
597
{
598
	EDI = in_date;
599
	EAX = 47;
600
	EBX = 2<<16;
601
	EDX = x<<16+y;
6280 punk_joker 602
	ESI = 0x90<<24+color;
5640 pavelyakov 603
	ECX = EDI.date.day;
604
	$int 0x40;
6285 leency 605
	EDX += 20<<16;
5640 pavelyakov 606
	ECX = EDI.date.month;
607
	$int 0x40;
6285 leency 608
	EDX += 20<<16;
5640 pavelyakov 609
	EBX = 4<<16;
610
	ECX = EDI.date.year;
611
	$int 0x40;
6285 leency 612
	DrawBar(x+17,y+10,2,2,color);
613
	DrawBar(x+37,y+10,2,2,color);
5640 pavelyakov 614
}
615
 
5646 pavelyakov 616
:void __path_name__(dword BUF,PATH)
617
{
618
	dword beg = PATH;
619
	dword pos = PATH;
620
	dword sav = PATH;
621
	dword i;
622
	while(DSBYTE[pos])
623
	{
624
		if(DSBYTE[pos]=='/')sav = pos;
625
		pos++;
626
	}
627
	i = sav-beg;
628
	while(i)
629
	{
630
		DSBYTE[BUF] = DSBYTE[beg];
631
		beg++;
632
		BUF++;
633
		i--;
634
	}
635
	/*while(DSBYTE[beg])
636
	{
637
		DSBYTE[BUF1] = DSBYTE[beg];
638
		beg++;
639
		BUF1++;
640
	}*/
641
	//DSBYTE[BUF1] = 0;
642
	DSBYTE[BUF] = 0;
643
}
5648 pavelyakov 644
char __BUF_DIR__[4096];
645
:struct SELF
646
{
647
	dword dir;
648
	dword file;
649
	dword path;
650
} self;
5646 pavelyakov 651
 
6791 leency 652
dword __generator;  // random number generator - äëÿ ãåíåðàöèè ñëó÷àéíûõ ÷èñåë
5575 pavelyakov 653
 
5582 pavelyakov 654
:dword program_path_length;
5576 pavelyakov 655
 
5575 pavelyakov 656
//The initialization of the initial data before running
5648 pavelyakov 657
void ______INIT______()
5575 pavelyakov 658
{
6761 leency 659
	//if (program_path[0]!='/') I_Path++;
6759 leency 660
 
5648 pavelyakov 661
	self.dir = #__BUF_DIR__;
662
	self.file = 0;
663
	self.path = I_Path;
664
	__path_name__(#__BUF_DIR__,I_Path);
5646 pavelyakov 665
 
6041 leency 666
	skin_height   = GetSkinHeight();
6771 leency 667
	screen.width  = GetScreenWidth()+1;
668
	screen.height = GetScreenHeight()+1;
5582 pavelyakov 669
 
5996 leency 670
	DOUBLE_CLICK_DELAY = GetMouseDoubleClickDelay();
5575 pavelyakov 671
	__generator = GetStartTime();
5651 pavelyakov 672
 
6021 leency 673
	mem_init();
5651 pavelyakov 674
 
6735 leency 675
 
5575 pavelyakov 676
	main();
5933 pavelyakov 677
	ExitProcess();
5598 pavelyakov 678
}
5648 pavelyakov 679
______STOP______:
6021 leency 680
#endif
681
 
682
#ifndef INCLUDE_MEM_H
683
#include "../lib/mem.h"
684
#endif
6058 leency 685
 
686
#ifndef INCLUDE_DEBUG_H
687
#include "../lib/debug.h"
688
#endif