Subversion Repositories Kolibri OS

Rev

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