Subversion Repositories Kolibri OS

Rev

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