Subversion Repositories Kolibri OS

Rev

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