Subversion Repositories Kolibri OS

Rev

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