Subversion Repositories Kolibri OS

Rev

Rev 9632 | Rev 9699 | 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
5576 pavelyakov 43
#define evDesktop 5
3067 leency 44
#define evMouse   6
5576 pavelyakov 45
#define evIPC     7
4536 leency 46
#define evNetwork 8
5576 pavelyakov 47
#define evDebug   9
3067 leency 48
 
6978 leency 49
//Event mask bits for function 40
7031 leency 50
#define EVM_REDRAW                1b
51
#define EVM_KEY                  10b
52
#define EVM_BUTTON              100b
7569 leency 53
#define EVM_DESKTOPBG         10000b
7031 leency 54
#define EVM_MOUSE            100000b
55
#define EVM_IPC             1000000b
56
#define EVM_STACK          10000000b
57
#define EVM_DEBUG         100000000b
58
#define EVM_STACK2       1000000000b
6978 leency 59
#define EVM_MOUSE_FILTER  0x80000000
60
#define EVM_CURSOR_FILTER 0x40000000
61
 
3067 leency 62
//Button options
63
#define BT_DEL      0x80000000
64
#define BT_HIDE     0x40000000
65
#define BT_NOFRAME  0x20000000
66
 
7054 leency 67
#define CLOSE_BTN 1
68
 
3067 leency 69
//-------------------------------------------------------------------------
70
 
5674 pavelyakov 71
#include "../lib/system.h"
72
#include "../lib/mouse.h"
6285 leency 73
#include "../lib/keyboard.h"
5674 pavelyakov 74
 
6751 leency 75
inline fastcall dword calc(EAX) { return EAX; }
6742 leency 76
 
7913 leency 77
 
5477 leency 78
:struct raw_image {
79
	dword w, h, data;
80
};
81
 
3067 leency 82
//------------------------------------------------------------------------------
83
inline fastcall dword WaitEvent()
84
{
85
	$mov eax,10
86
	$int 0x40
87
}
88
 
89
inline fastcall dword CheckEvent()
90
{
91
	$mov eax,11
92
	$int 0x40
93
}
94
 
8045 pavelyakov 95
inline fastcall dword WaitEventTimeout(EBX)
3067 leency 96
{
7310 pavelyakov 97
	EAX = 23;
3067 leency 98
	$int 0x40
99
}
100
 
6978 leency 101
inline fastcall dword SetEventMask(EBX)
3067 leency 102
{
103
	$mov eax,40
104
	$int 0x40
105
}
106
 
107
 
5576 pavelyakov 108
inline fastcall pause(EBX)
3067 leency 109
{
110
	$mov eax, 5
111
	$int 0x40
112
}
113
 
114
inline fastcall word GetButtonID()
115
{
116
	$mov eax,17
117
	$int  0x40
118
	$shr eax,8
119
}
120
 
8396 leency 121
inline fastcall int GetKernelRev()
122
{
123
	char buf[16];
124
	EAX = 18;
125
	EBX = 13;
126
	ECX = #buf;
127
	$int 0x40
128
	EAX = ESDWORD[#buf+5];
129
}
130
 
3067 leency 131
inline fastcall dword GetFreeRAM()
132
{
133
	$mov eax, 18
134
	$mov ebx, 16
135
	$int 0x40
7358 leency 136
	//return eax = free RAM size in Kb
3067 leency 137
}
138
 
7358 leency 139
inline fastcall dword GetTotalRAM()
140
{
141
	$mov eax, 18
142
	$mov ebx, 17
143
	$int 0x40
144
	//return eax = total RAM size in Kb
145
}
146
 
7356 leency 147
inline fastcall int GetCpuIdleCount()
148
{
149
	EAX = 18;
150
	EBX = 4;
151
	$int 0x40
152
}
153
 
154
inline fastcall int GetCpuFrequency()
155
{
156
	EAX = 18;
157
	EBX = 5;
158
	$int 0x40
159
}
160
 
6791 leency 161
inline fastcall dword LoadDriver(ECX) //ECX - èìÿ äðàéâåðà
3067 leency 162
{
163
	$mov eax, 68
164
	$mov ebx, 16
165
	$int 0x40
6791 leency 166
	//return 0 - íåóäà÷à, èíà÷å eax = õýíäë äðàéâåðà
3067 leency 167
}
168
 
6791 leency 169
inline fastcall dword RuleDriver(ECX) //óêàçàòåëü íà óïðàâëÿþùóþ ñòðóêòóðó
3067 leency 170
{
171
	$mov eax, 68
172
	$mov ebx, 17
173
	$int 0x40
6791 leency 174
	//return eax = îïðåäåëÿåòñÿ äðàéâåðîì
3067 leency 175
}
176
 
177
struct proc_info
178
{
179
	#define SelfInfo -1
180
	dword	use_cpu;
7266 leency 181
	word	pos_in_stack,slot,rezerv1;
4137 leency 182
	unsigned char name[11];
3067 leency 183
	char	rezerv2;
184
	dword	adress,use_memory,ID,left,top,width,height;
185
	word	status_slot,rezerv3;
8012 leency 186
	dword	cleft,ctop,cwidth,cheight;
3067 leency 187
	char	status_window;
9089 leency 188
	byte    reserved[1024-71];
3067 leency 189
};
190
 
7225 leency 191
:void GetProcessInfo(dword _process_struct_pointer, _process_id)
3067 leency 192
{
7225 leency 193
	EAX = 9;
194
	EBX = _process_struct_pointer;
195
	ECX = _process_id;
3067 leency 196
	$int  0x40
197
}
198
 
199
inline fastcall int GetPointOwner( EBX, ECX) //ebx=m.x, ecx=m.y
200
{
201
	$mov eax,34
202
	$int 0x40
203
}
204
 
205
inline fastcall int GetProcessSlot( ECX)
206
{
207
	EAX = 18;
208
	EBX = 21;
209
	$int 0x40
210
}
211
 
212
inline fastcall int GetActiveProcess()
213
{
214
	EAX = 18;
215
	EBX = 7;
216
	$int 0x40
217
}
218
 
4081 leency 219
:int CheckActiveProcess(int Form_ID)
220
{
4166 leency 221
	int id9=GetProcessSlot(Form_ID);
222
	if (id9==GetActiveProcess()) return 1;
4081 leency 223
	return 0;
224
}
225
 
7266 leency 226
inline fastcall void ActivateWindow( ECX) //ECX - slot
3114 leency 227
{
228
	EAX = 18;
229
	EBX = 3;
230
	$int 0x40
231
}
232
 
9459 leency 233
:void ActivateWindow_Self()
234
{
235
	proc_info Form;
236
	GetProcessInfo(#Form, SelfInfo);
237
	ActivateWindow(GetProcessSlot(Form.ID));
238
}
239
 
7254 leency 240
:void RefreshWindow(dword ID_REFRESH,ID_ACTIVE)
241
{
242
	ActivateWindow(ID_REFRESH);
243
	ActivateWindow(ID_ACTIVE);
244
}
245
 
5421 leency 246
inline fastcall int MinimizeWindow()
247
{
248
	EAX = 18;
249
	EBX = 10;
250
	$int 0x40
251
}
252
 
5576 pavelyakov 253
inline fastcall int CreateThread(ECX,EDX)
3067 leency 254
{
255
	$mov eax,51
256
	$mov ebx,1
257
	$int 0x40
258
}
259
 
260
inline fastcall void SwitchToAnotherThread()
261
{
262
	$mov eax,68
263
	$mov ebx,1
264
	$int 0x40
265
}
266
 
3458 leency 267
inline fastcall int SendWindowMessage( ECX, EDX)
3444 leency 268
{
269
	$mov eax, 72
270
	$mov ebx, 1
271
	$int 0x40
272
}
273
 
3067 leency 274
inline fastcall int KillProcess( ECX)
275
{
276
	$mov eax,18;
277
	$mov ebx,18;
278
	$int 0x40
279
}
280
 
281
#define TURN_OFF 2
282
#define REBOOT 3
283
#define KERNEL 4
284
inline fastcall int ExitSystem( ECX)
285
{
286
	$mov eax, 18
287
	$mov ebx, 9
288
	$int 0x40
289
}
290
 
291
inline fastcall ExitProcess()
292
{
293
	$mov eax,-1;
294
	$int 0x40
295
}
296
 
297
//------------------------------------------------------------------------------
298
 
6791 leency 299
//eax = ÿçûê ñèñòåìû (1=eng, 2=fi, 3=ger, 4=rus)
7590 leency 300
///SYSFUNC DOESN'T WORK!!!  =>  https://bit.ly/2XNdiTD
6662 leency 301
#define SYS_LANG_ENG 1
302
#define SYS_LANG_FIN 2
303
#define SYS_LANG_GER 3
304
#define SYS_LANG_RUS 4
3067 leency 305
inline fastcall int GetSystemLanguage()
306
{
307
	EAX = 26;
308
	EBX = 5;
309
	$int 0x40
310
}
311
 
7235 leency 312
#define BUTTON_STYLE_FLAT 0
313
#define BUTTON_STYLE_GRADIENT 1
314
inline fastcall SetButtonStyle(ECX) //ECX - button style
315
{
316
	$mov eax,48
317
	$mov ebx,1
318
	int 64
319
}
320
 
3067 leency 321
inline fastcall GetSkinHeight()
322
{
323
	$push ebx
324
	$mov  eax,48
325
	$mov  ebx,4
326
	$int 0x40
327
	$pop  ebx
328
}
329
 
330
inline fastcall void SetSystemSkin( ECX)
331
{
332
	EAX = 48;
333
	EBX = 8;
334
	$int 0x40
335
}
336
 
337
inline fastcall int GetScreenWidth()
338
{
339
	$mov eax, 14
340
	$int 0x40
341
	$shr eax, 16
342
}
343
 
344
inline fastcall int GetScreenHeight()
345
{
346
	$mov eax, 14
347
	$int 0x40
348
	$and eax,0x0000FFFF
349
}
350
 
5421 leency 351
inline fastcall int GetClientTop()
352
{
353
	$mov eax, 48
354
	$mov ebx, 5
355
	$int 0x40
6058 leency 356
	$mov eax, ebx
357
	$shr eax, 16
5421 leency 358
}
359
 
360
inline fastcall int GetClientHeight()
361
{
362
	$mov eax, 48
363
	$mov ebx, 5
364
	$int 0x40
6058 leency 365
	$mov eax, ebx
5421 leency 366
}
367
 
3067 leency 368
inline fastcall dword LoadLibrary( ECX)
369
{
370
	$mov eax, 68
371
	$mov ebx, 19
372
	$int  0x40
373
}
374
 
375
inline fastcall int TestBit( EAX, CL)
376
{
377
	$shr eax,cl
378
	$and eax,1
379
}
380
 
7166 leency 381
:void SetClientScreenArea(dword _left, _right, _top, _bottom)
382
{
383
	EAX = 48;
384
	EBX = 6;
385
	ECX = _left * 65536 + _right;
386
	EDX = _top * 65536 + _bottom;
387
	$int 64;
388
}
389
 
3067 leency 390
//------------------------------------------------------------------------------
391
 
8946 leency 392
#define ROLLED_UP 0x04
6746 leency 393
:void DefineAndDrawWindow(dword _x, _y, _w, _h, _window_type, _bgcolor, _title, _flags)
3067 leency 394
{
395
	EAX = 12;              // function 12:tell os about windowdraw
396
	EBX = 1;
397
	$int 0x40
398
 
5576 pavelyakov 399
	$xor EAX,EAX
6746 leency 400
	EBX = _x << 16 + _w;
401
	ECX = _y << 16 + _h;
402
	EDX = _window_type << 24 | _bgcolor;
403
	EDI = _title;
404
	ESI = _flags;
3067 leency 405
	$int 0x40
406
 
407
	EAX = 12;              // function 12:tell os about windowdraw
408
	EBX = 2;
409
	$int 0x40
410
}
411
 
412
inline fastcall MoveSize( EBX,ECX,EDX,ESI)
413
{
414
	$mov eax, 67
415
	$int 0x40
416
}
417
 
418
inline fastcall void DrawTitle( ECX)
419
{
420
	EAX = 71;
421
	EBX = 1;
422
	$int 0x40;
423
}
424
 
6794 leency 425
// @EDX is a process id, -1 for self
6791 leency 426
// @ESI is a new LayerBehaviour
427
// @RETURN: EAX, 0 is fail, 1 is success
6794 leency 428
#define ZPOS_DESKTOP     -2
429
#define ZPOS_ALWAYS_BACK -1
430
#define ZPOS_NORMAL      0
431
#define ZPOS_ALWAYS_TOP  1
6791 leency 432
inline fastcall dword SetWindowLayerBehaviour(EDX, ESI)
433
{
434
	EAX = 18;
435
	EBX = 25;
436
	ECX = 2;
437
	$int 64
438
}
439
 
6735 leency 440
:void WriteTextB(dword x,y,byte fontType, dword color, str_offset)
3067 leency 441
{
9602 leency 442
	WriteText(x,y,fontType, color, str_offset);
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
 
9693 leency 468
:void WriteNumber(dword x,y,byte fontType, dword color, flags, number_or_offset)
3067 leency 469
{
470
	EAX = 47;
9693 leency 471
	EBX = flags;
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;
9597 leency 490
	EBX = _y * screen.w + _x;
6791 leency 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
 
9602 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
{
551
	EAX = 13;
552
	EBX = x<<16+w;
553
	ECX = y<<16+h;
6742 leency 554
	EDX = color;
6058 leency 555
	$int 0x40
3067 leency 556
}
557
 
7203 leency 558
:void DefineButton(dword x,y,w,h,id,color)
3067 leency 559
{
3107 leency 560
	EAX = 8;
7203 leency 561
	EDX = id + BT_DEL;
3107 leency 562
	$int 0x40;
7203 leency 563
	EDX = id;
564
	ESI = color;
3067 leency 565
	EBX = x<<16+w;
566
	ECX = y<<16+h;
567
	$int 0x40
568
}
569
 
6742 leency 570
:void UnsafeDefineButton(dword x,y,w,h,id,color)
3107 leency 571
{
572
	EAX = 8;
573
	EBX = x<<16+w;
574
	ECX = y<<16+h;
6742 leency 575
	EDX = id;
576
	ESI = color;
3107 leency 577
	$int 0x40
578
}
579
 
7160 leency 580
:void DefineDragableWindow(dword _x, _y, _w, _h)
6791 leency 581
{
9602 leency 582
	DefineAndDrawWindow(_x, _y, _w, _h, 0x41,0x000000,EDI,0b);
6791 leency 583
}
584
 
7166 leency 585
:void DefineUnDragableWindow(dword _x, _y, _w, _h)
586
{
9602 leency 587
	DefineAndDrawWindow(_x, _y, _w, _h, 0x01, 0, EDI, 0x01fffFFF);
7166 leency 588
}
589
 
6791 leency 590
:void EventDragWindow()
591
{
7422 leency 592
	proc_info Form1;
6791 leency 593
	dword tmp_x,tmp_y;
594
	dword z1,z2;
595
	tmp_x = mouse.x;
596
	tmp_y = mouse.y;
597
	do {
7422 leency 598
		GetProcessInfo(#Form1, SelfInfo);
6791 leency 599
		mouse.get();
600
		if (tmp_x!=mouse.x) || (tmp_y!=mouse.y)
601
		{
7422 leency 602
			z1 = Form1.left + mouse.x - tmp_x;
603
			z2 = Form1.top + mouse.y - tmp_y;
9597 leency 604
			if(z1<=10) || (z1>20000) z1=0; else if(z1>screen.w-Form1.width-10)z1=screen.w-Form1.width;
605
			if(z2<=10) || (z2>20000) z2=0; else if(z2>screen.h-Form1.height-10)z2=screen.h-Form1.height;
6791 leency 606
			MoveSize(z1 , z2, OLD, OLD);
607
			draw_window();
608
		}
609
		pause(1);
610
	} while (mouse.lkm);
611
}
612
 
613
:void DefineHiddenButton(dword _x, _y, _w, _h, _id)
614
{
9632 leency 615
	DefineButton(_x, _y, _w, _h, _id + BT_HIDE, 0);
6791 leency 616
}
617
 
3067 leency 618
inline fastcall void DeleteButton( EDX)
619
{
620
	EAX = 8;
621
	EDX += BT_DEL;
5630 leency 622
	$int 0x40
5548 leency 623
}
624
 
625
inline fastcall dword GetStartTime()
626
{
627
	$mov eax,26
628
	$mov ebx,9
629
	$int 0x40
5575 pavelyakov 630
}
631
 
5606 pavelyakov 632
:dword X_EventRedrawWindow,Y_EventRedrawWindow;
633
:void _EventRedrawWindow()
634
{
9602 leency 635
	DefineAndDrawWindow(X_EventRedrawWindow,Y_EventRedrawWindow,1,1,0x34,0xFFFFFF,EDI,0);
7244 leency 636
	ExitProcess();
5606 pavelyakov 637
}
5760 pavelyakov 638
:char REDRAW_BUFF_EVENT_[4096];
5606 pavelyakov 639
:void EventRedrawWindow(dword x,y)
640
{
641
	X_EventRedrawWindow = x;
642
	Y_EventRedrawWindow = y;
5760 pavelyakov 643
	CreateThread(#_EventRedrawWindow,#REDRAW_BUFF_EVENT_+4092);
5606 pavelyakov 644
}
645
 
5582 pavelyakov 646
:struct _screen
647
{
9597 leency 648
	dword w,h;
5582 pavelyakov 649
} screen;
650
 
9597 leency 651
:byte skin_h;
5582 pavelyakov 652
 
7773 leency 653
dword __generator;  // random number generator init
5646 pavelyakov 654
 
5575 pavelyakov 655
//The initialization of the initial data before running
7982 leency 656
:void ______INIT______()
5575 pavelyakov 657
{
9597 leency 658
	skin_h   = @GetSkinHeight();
659
	screen.w  = @GetScreenWidth()+1;
660
	screen.h = @GetScreenHeight()+1;
7981 leency 661
	__generator = @GetStartTime();
7812 leency 662
	mem_init();
5575 pavelyakov 663
	main();
5598 pavelyakov 664
}
5648 pavelyakov 665
______STOP______:
6021 leency 666
#endif
667
 
668
#ifndef INCLUDE_MEM_H
669
#include "../lib/mem.h"
670
#endif
6058 leency 671
 
672
#ifndef INCLUDE_DEBUG_H
673
#include "../lib/debug.h"
7773 leency 674
#endif
675
 
676
#ifndef INCLUDE_IPC_H
677
#include "../lib/ipc.h"
8043 pavelyakov 678
#endif