Subversion Repositories Kolibri OS

Rev

Rev 2814 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2568 leency 1
//CODED by Veliant, Leency 2008-2012. GNU GPL licence.
2
 
3
#startaddress 0
4
#code32 TRUE
5
 
6
byte   os_name[8]   = {'M','E','N','U','E','T','0','1'};
7
dword  os_version   = 0x00000001;
8
dword  start_addr   = #main;
9
dword  final_addr   = #stop+32;
10
dword  alloc_mem    = 0x00070000;
2770 leency 11
dword  x86esp_reg   = 0x00070000;
2568 leency 12
dword  I_Param      = #param;
13
dword  I_Path       = #program_path;
14
 
15
char param[4096];
16
char program_path[4096];
17
 
18
 
19
//Events
20
#define evMouse		6
21
#define evButton	3
22
#define evKey		2
23
#define evReDraw	1
24
 
25
//Button options
26
#define BT_DEL		0x80000000
27
#define BT_HIDE		0x40000000
28
#define BT_NOFRAME	0x20000000
29
 
30
#define OLD			-1
31
#define true		1
32
#define false		0
33
 
34
 
35
 
2814 leency 36
struct mouse
37
{
2568 leency 38
	unsigned int x,y,lkm,pkm,hor,vert;
39
	void get();
40
};
41
 
42
inline fastcall int TestBit(EAX, CL)
43
{
44
	$shr eax,cl
45
	$and eax,1
46
}
47
 
48
void mouse::get()
49
{
50
	EAX = 37;
51
	EBX = 1;
52
	$int	0x40
53
	$mov	ebx, eax
54
	$shr	eax, 16
55
	$and	ebx,0x0000FFFF
56
	x = EAX;
57
	y = EBX;
58
 
59
	EAX = 37;
60
	EBX = 2;
61
	$int	0x40
62
	$mov	ebx, eax
63
	$and	eax, 0x00000001
64
	$shr	ebx, 1
65
	$and	ebx, 0x00000001
66
	lkm = EAX;
67
	pkm = EBX;
68
 
69
	EAX = 37; //scroll
70
	EBX = 7;
71
	$int	0x40
72
	$mov	ebx, eax
73
	$shr	eax, 16
74
	$and	ebx,0x0000FFFF
75
	//hor = EAX;
76
	vert = EBX;
77
}
78
 
79
//---------------------------------------------------------------------------
2814 leency 80
struct proc_info
81
{
82
	#define SelfInfo -1
2568 leency 83
	dword	use_cpu;
84
	word	pos_in_stack,num_slot,rezerv1;
85
	char	name[11];
86
	char	rezerv2;
87
	dword	adress,use_memory,ID,left,top,width,height;
88
	word	status_slot,rezerv3;
89
	dword	work_left,work_top,work_width,work_height;
90
	char	status_window;
2814 leency 91
	void	GetInfo( ECX);
2568 leency 92
	byte    reserved[1024-71];
93
};
94
 
2814 leency 95
void proc_info::GetInfo( EBX, ECX)
2568 leency 96
{
2814 leency 97
	$mov eax,9;
98
	$int 0x40
2568 leency 99
}
100
 
2814 leency 101
inline fastcall int GetSlot( ECX)
2568 leency 102
{
2814 leency 103
	$mov eax,18;
104
	$mov ebx,21;
2568 leency 105
	$int 0x40
106
}
107
 
108
inline fastcall int ActiveProcess()
109
{
2814 leency 110
	$mov eax,18;
111
	$mov ebx,7;
2568 leency 112
	$int 0x40
113
}
114
 
115
//-------------------------------------------------------------------------------
116
 
117
inline fastcall dword WaitEvent(){
2814 leency 118
	$mov eax,10;
2568 leency 119
	$int 0x40
120
}
121
 
2814 leency 122
inline fastcall void SetEventMask( EBX)
2568 leency 123
{
124
	EAX = 40;
125
	$int 0x40
126
}
127
 
2814 leency 128
inline fastcall word GetKey(){ //+Gluk fix
2568 leency 129
		$push edx
130
@getkey:
131
		$mov  eax,2
132
		$int  0x40
133
		$cmp eax,1
134
		$jne getkeyi
135
		$mov ah,dh
136
		$jmp getkeyii //jz?
137
@getkeyi:
138
		$mov dh,ah
139
		$jmp getkey
140
@getkeyii:
141
		$pop edx
142
		EAX = EAX >> 8;
143
}
144
 
145
inline fastcall word GetButtonID(){
146
	EAX = 17;            // Get ID
147
	$int  0x40
148
	EAX = EAX >> 8;
149
}
150
 
151
inline fastcall void ExitProcess(){
152
	EAX = -1;            // close this program
153
	$int 0x40
154
}
155
 
2875 leency 156
inline fastcall void Pause( EBX){
2814 leency 157
	$mov eax, 5
2568 leency 158
	$int 0x40
159
}
160
 
161
//------------------------------------------------------------------------------
2875 leency 162
void DefineAndDrawWindow(dword x,y,sizeX,sizeY,byte mainAreaType, dword mainAreaColour, EDI)
2568 leency 163
{
164
	EAX = 12;              // function 12:tell os about windowdraw
165
	EBX = 1;
166
	$int 0x40
167
 
168
	EBX = x << 16 + sizeX;
169
	ECX = y << 16 + sizeY;
170
	EDX = mainAreaType << 24 | mainAreaColour;
171
	$xor eax,eax
172
	$int 0x40
173
 
174
	EAX = 12;              // function 12:tell os about windowdraw
175
	EBX = 2;
176
	$int 0x40
177
}
178
 
2814 leency 179
inline fastcall void CreateThread( ECX,EDX)
2568 leency 180
{
181
	EAX = 51;
182
	EBX = 1;
183
	$int 0x40
184
}
185
 
2814 leency 186
inline fastcall void DrawTitle( ECX){
2568 leency 187
	EAX = 71;
188
	EBX = 1;
189
	$int 0x40;
190
}
191
 
2875 leency 192
inline fastcall dword GetSkinHeight()
193
{
194
	$push ebx
195
	$mov  eax,48
196
	$mov  ebx,4
2568 leency 197
	$int 0x40
2875 leency 198
	$pop  ebx
2568 leency 199
}
200
 
2661 leency 201
inline fastcall dword GetScreenHeight()
202
{
203
	EAX = 14;
204
	$int 0x40
205
	$and eax,0x0000FFFF
206
}
207
 
2814 leency 208
inline fastcall void MoveSize( EBX,ECX,EDX,ESI){
209
	$mov eax,67;
2568 leency 210
	$int 0x40
211
}
212
 
213
//------------------------------------------------------------------------------
214
 
2814 leency 215
inline fastcall dword strlen( EDI)
216
{
2568 leency 217
	asm {
218
	  xor ecx, ecx
219
	  xor eax, eax
220
	  dec ecx
221
	  repne scasb
222
	  sub eax, 2
223
	  sub eax, ecx
224
	}
225
}
226
 
227
 
2814 leency 228
inline fastcall copystr( ESI,EDI)
2568 leency 229
{
230
	$cld
231
l1:
232
	$lodsb
233
	$stosb
234
	$test al,al
235
	$jnz l1
236
}
237
 
238
char buffer[11];
2814 leency 239
inline fastcall dword IntToStr( ESI)
2568 leency 240
{
241
     $mov     edi, #buffer
242
     $mov     ecx, 10
243
     $test     esi, esi
244
     $jns     f1
245
     $mov     al, '-'
246
     $stosb
247
     $neg     esi
248
f1:
249
     $mov     eax, esi
250
     $push     -'0'
251
f2:
252
     $xor     edx, edx
253
     $div     ecx
254
     $push     edx
255
     $test     eax, eax
256
     $jnz     f2
257
f3:
258
     $pop     eax
259
     $add     al, '0'
260
     $stosb
261
     $jnz     f3
262
     $mov     eax, #buffer
263
     $ret
264
}
265
 
266
inline fastcall dword StrToInt()
267
{
268
	ESI=EDI=EAX;
269
	IF(DSBYTE[ESI]=='-')ESI++;
270
	EAX=0;
271
	BH=AL;
272
	do{
273
		BL=DSBYTE[ESI]-'0';
274
		EAX=EAX*10+EBX;
275
		ESI++;
276
	}while(DSBYTE[ESI]>0);
277
	IF(DSBYTE[EDI]=='-') -EAX;
278
}
279
 
280
dword StrToCol(char* htmlcolor)
281
{
282
  dword j, color=0;
283
  char ch=0x00;
284
 
285
  FOR (j=0; j<6; j++)
286
  {
287
    ch=ESBYTE[htmlcolor+j];
288
    IF ((ch>='0') && (ch<='9')) ch -= '0';
289
    IF ((ch>='A') && (ch<='F')) ch -= 'A'-10;
290
    IF ((ch>='a') && (ch<='f')) ch -= 'a'-10;
291
    color = color*0x10 + ch;
292
  }
293
 
294
  return color;
295
}
296
 
297
inline fastcall int strcmp(ESI, EDI)
298
{
299
	loop()
300
	{
301
		IF (DSBYTE[ESI]
302
		IF (DSBYTE[ESI]>DSBYTE[EDI]) RETURN 1;
303
		IF (DSBYTE[ESI]=='\0') RETURN 0;
304
		ESI++;
305
		EDI++;
306
	}
307
}
308
 
309
 
2875 leency 310
inline fastcall signed int strncmp( ESI, EDI, ECX)
2568 leency 311
{
2875 leency 312
  asm {
313
    MOV EBX, EDI
314
    XOR EAX, EAX
315
    MOV EDX, ECX
316
    OR ECX, ECX
317
    JE L1
318
    REPNE SCASB
319
    SUB EDX, ECX
320
    MOV ECX, EDX
321
    MOV EDI, EBX
322
    XOR EBX, EBX
323
    REPE CMPSB
324
    MOV AL, DSBYTE[ ESI-1]
325
    MOV BL, DSBYTE[ EDI-1]
326
    SUB EAX, EBX
327
L1:
328
  }
329
}
330
 
331
 
332
inline fastcall unsigned int strchr(ESI,BL)
333
{
2568 leency 334
	int jj=0, last=-1;
335
	do{
336
		jj++;
337
		$lodsb
338
		IF(AL==BL) last=jj;
339
	} while(AL!=0);
340
	return last;
341
}
342
 
343
 
2875 leency 344
inline fastcall TitleCase( EDX)
2568 leency 345
{
346
	AL=DSBYTE[EDX];
347
	IF(AL>='a')&&(AL<='z')DSBYTE[EDX]=AL&0x5f;
348
	IF (AL>=160) && (AL<=175) DSBYTE[EDX] = AL - 32;	//а-п
349
	IF (AL>=224) && (AL<=239) DSBYTE[EDX] = AL - 80;	//а-п
350
	do{
351
		EDX++;
352
		AL=DSBYTE[EDX];
353
		IF(AL>='A')&&(AL<='Z'){DSBYTE[EDX]=AL|0x20; CONTINUE;}
354
		IF(AL>='Ђ')&&(AL<='Џ')DSBYTE[EDX]=AL|0x20; // -Ї
355
		IF (AL>=144) && (AL<=159) DSBYTE[EDX] = AL + 80;	//а-п
356
	}while(AL!=0);
357
}
358
 
359
 
360
//------------------------------------------------------------------------------
2814 leency 361
inline fastcall void PutPixel( EBX,ECX,EDX)
362
{
2568 leency 363
  EAX=1;
364
  $int 0x40
365
}
366
 
367
void DefineButton(dword x,y,w,h,EDX,ESI)
368
{
369
 	EAX = 8;
370
	$push edx
371
	EDX += BT_DEL; //вначале удаляем кнопу с эти ид, потом создаём
372
	$int 0x40;
373
	EBX = x<<16+w;
374
	ECX = y<<16+h;
375
 	$pop edx
376
	$int 0x40
377
}
378
 
2814 leency 379
inline fastcall void DeleteButton( EDX)
2568 leency 380
{
381
	EAX = 8;
382
	EDX += BT_DEL;
383
	$int 0x40;
384
}
385
 
386
void WriteText(dword x,y,byte fontType, dword color, EDX, ESI)
387
{
388
	EAX = 4;
389
	EBX = x<<16+y;
390
	ECX = fontType<<24+color;
391
	$int 0x40;
392
}
393
 
394
void DrawBar(dword x,y,w,h,EDX)
395
{
396
	EAX = 13;
397
	EBX = x<<16+w;
398
	ECX = y<<16+h;
399
 	$int 0x40
400
}
401
 
402
void DrawRegion_3D(dword x,y,width,height,color1,color2)
403
{
2814 leency 404
	DrawBar(x,y,width+1,1,color1);
405
	DrawBar(x,y+1,1,height-1,color1);
406
	DrawBar(x+width,y+1,1,height,color2);
407
	DrawBar(x,y+height,width,1,color2);
2568 leency 408
}
409
 
410
void DrawFlatButton(dword x,y,width,height,id,color,text)
411
{
412
	DrawRegion_3D(x,y,width,height,0x94AECE,0x94AECE);
413
	DrawRegion_3D(x+1,y+1,width-2,height-2,0xFFFFFF,0xC7C7C7);
2814 leency 414
	DrawBar(x+2,y+2,width-3,height-3,color);
415
	IF (id<>0)	DefineButton(x+1,y+1,width-2,height-2,id+BT_HIDE,0xEFEBEF);
2568 leency 416
	WriteText(-strlen(text)*6+width/2+x+1,height/2-3+y,0x80,0,text,0);
417
}
418
 
419
void PutPaletteImage(dword EBX,w,h,x,y, EDI)
420
{
421
	EAX = 65;
422
	ECX = w<<16+h;
423
	EDX = x<<16+y;
424
	ESI = 8;
425
	EBP = 0;
426
	$int 0x40
427
}
428
 
429
void PutImage(dword EBX,w,h,x,y)
430
{
431
	EAX = 7;
432
	ECX = w<<16+h;
433
	EDX = x<<16+y;
434
	$int 0x40
435
}
436
 
437
//------------------------------------------------------------------------------
2814 leency 438
inline fastcall void debug( EDX)
2568 leency 439
{
2875 leency 440
	$push eax
441
	$push ebx
442
	$push ecx
2568 leency 443
	$mov eax, 63
444
	$mov ebx, 1
445
next_char:
446
	$mov ecx, DSDWORD[edx]
447
	$or	 cl, cl
448
	$jz  done
449
	$int 0x40
450
	$inc edx
451
	$jmp next_char
452
done:
453
	$mov cl, 13
454
	$int 0x40
455
	$mov cl, 10
456
	$int 0x40
2875 leency 457
	$pop eax
458
	$pop ebx
459
	$pop ecx
2568 leency 460
}