Subversion Repositories Kolibri OS

Rev

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