Subversion Repositories Kolibri OS

Rev

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