Subversion Repositories Kolibri OS

Rev

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