Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
903 leency 1
//CODED by Veliant, Leency. GNU GPL licence.
2
 
3
#startaddress 0
4
#code32 TRUE
5
 
976 leency 6
byte   os_name[8]   = {'M','E','N','U','E','T','0','1'};
903 leency 7
dword  os_version   = 0x00000001;
8
dword  start_addr   = #main;
9
dword  final_addr   = #stop+32;
10
dword  alloc_mem    = 0x00100000;
11
dword  x86esp_reg   = 0x00100000;   // 0x0007fff0;
12
dword  I_Param      = #param;
13
dword  I_Icon       = 0x0;
14
char param[256]="";
15
 
16
//Events
935 leency 17
#define evMouse		6
903 leency 18
#define evButton	3
19
#define evKey		2
20
#define evReDraw	1
21
 
22
//Button options
23
#define BT_DEL		0x80000000
24
#define BT_HIDE		0x40000000
25
#define BT_NOFRAME	0x20000000
26
 
27
#define OLD			-1
28
#define true		1
29
#define false		0
30
 
31
 
32
 
33
struct mouse{
976 leency 34
 int x,y,lkm,pkm,hor,vert;
903 leency 35
 void get();
36
};
37
 
38
void mouse::get()
39
{
40
	EAX = 37;
41
	EBX = 1;
42
	$int	0x40
43
	$mov	ebx, eax
44
	$shr	eax, 16
45
	$and	ebx,0x0000FFFF
46
	x = EAX;
975 leency 47
	y = EBX;
903 leency 48
	EAX = 37;
49
	EBX = 2;
50
	$int	0x40
51
	$mov	ebx, eax
52
	$and	eax, 0x00000001
53
	$shr	ebx, 1
54
	$and	ebx, 0x00000001
55
	lkm = EAX;
56
	pkm = EBX;
57
	EAX = 37; //скролл
58
	EBX = 7;
59
	$int	0x40
60
	$mov	ebx, eax
61
	$shr	eax, 16
62
	$and	ebx,0x0000FFFF
63
	//hor = EAX;
64
	vert = EBX;
65
}
66
 
67
//---------------------------------------------------------------------------
68
struct proc_info{
69
	dword	use_cpu;
70
	word	pos_in_stack,num_slot,rezerv1;
71
	char	name[11];
72
	char	rezerv2;
73
	dword	adress,use_memory,ID,left,top,width,height;
74
	word	status_slot,rezerv3;
75
	dword	work_left,work_top,work_width,work_height;
76
	char	status_window;
937 leency 77
	void	GetInfo(dword ECX);
78
#define SelfInfo -1
903 leency 79
};
80
 
937 leency 81
void proc_info::GetInfo(dword ECX)
903 leency 82
{
83
	EAX = 9;
84
	EBX = #use_cpu;
937 leency 85
	$int  0x40
903 leency 86
}
87
//-------------------------------------------------------------------------------
88
 
89
inline fastcall dword WaitEvent(){
90
 EAX = 10;              // wait here for event
91
 $int 0x40
92
}
93
 
944 leency 94
inline fastcall void SetEventMask(dword EBX)
937 leency 95
{
96
 EAX = 40;
97
 $int 0x40
944 leency 98
}
903 leency 99
 
100
inline fastcall word GetKey(){
101
 EAX = 2;              // just read this key from buffer
102
 $int  0x40
103
 EAX = EAX >> 8;
104
}
105
 
106
inline fastcall word GetButtonID(){
107
 EAX = 17;            // Get ID
108
 $int  0x40
109
 EAX = EAX >> 8;
110
}
111
 
935 leency 112
inline fastcall void ExitProcess(){
113
 EAX = -1;            // close this program
114
 $int 0x40
115
}
903 leency 116
 
984 leency 117
inline fastcall void Pause(dword EBX){
937 leency 118
	$mov eax, 5       //Пауза, в сотых долях секунды
935 leency 119
	$int 0x40
937 leency 120
}
935 leency 121
 
122
//------------------------------------------------------------------------------
123
void DefineAndDrawWindow(dword x,y,sizeX,sizeY,byte mainAreaType,dword
124
	mainAreaColor,byte headerType,dword headerColor,EDI)
903 leency 125
{
935 leency 126
	EBX = x << 16 + sizeX;
127
	ECX = y << 16 + sizeY;
128
	EDX = mainAreaType << 24 | mainAreaColor;
129
	ESI = headerType << 24 | headerColor;
130
	$xor eax,eax
131
	$int 0x40
132
}
133
 
984 leency 134
inline fastcall void CreateThread(dword ECX,EDX)
975 leency 135
{
136
	EAX = 51;
137
	EBX = 1;
138
	$int 0x40
139
}
140
 
935 leency 141
inline fastcall void DrawTitle(dword ECX){
903 leency 142
	EAX = 71;
143
	EBX = 1;
144
	$int 0x40;
145
}
146
 
935 leency 147
 
148
inline fastcall void WindowRedrawStatus(dword EBX){
149
	EAX = 12;              //tell os about windowdraw
150
	$int 0x40
151
}
152
 
153
inline fastcall dword GetSkinWidth(){
903 leency 154
	EAX = 48;
155
	EBX = 4;
156
	$int 0x40
157
}
158
 
984 leency 159
inline fastcall void MoveSize(dword EBX,ECX,EDX,ESI){
935 leency 160
	EAX = 67;
161
	$int 0x40
903 leency 162
}
163
 
935 leency 164
//------------------------------------------------------------------------------
903 leency 165
 
935 leency 166
inline fastcall dword strlen(dword EDI){
976 leency 167
	EAX=0;
168
	ECX=-1;
903 leency 169
	$REPNE $SCASB
935 leency 170
	EAX-=2+ECX;
903 leency 171
}
172
 
173
 
935 leency 174
inline fastcall copystr(dword ESI,EDI)
175
{
176
	$cld
177
l1:
178
	$lodsb
179
	$stosb
180
	$test al,al
181
	$jnz l1
182
}
183
 
184
 
984 leency 185
byte fastcall TestBit(EAX, CL)
186
{
187
	$shr eax,cl
188
	$and eax,1
189
}
190
 
191
 
935 leency 192
char buffer[11]="";
193
inline fastcall dword IntToStr(dword ESI)
194
{
195
     $mov     edi, #buffer
196
     $mov     ecx, 10
197
     $test     esi, esi
198
     $jns     f1
199
     $mov     al, '-'
200
     $stosb
201
     $neg     esi
202
f1:
203
     $mov     eax, esi
204
     $push     -'0'
205
f2:
206
     $xor     edx, edx
207
     $div     ecx
208
     $push     edx
209
     $test     eax, eax
210
     $jnz     f2
211
f3:
212
     $pop     eax
213
     $add     al, '0'
214
     $stosb
215
     $jnz     f3
216
     $mov     eax, #buffer
217
     $ret
218
}
219
 
220
 
984 leency 221
dword StrToCol(char* htmlcolor)
222
{
223
  dword j=1, color=0; char ch=0x00;
224
  IF (ESBYTE[htmlcolor]<>'#') RETURN;
225
  FOR (;j<7;j++)
226
  {
227
    ch=ESBYTE[htmlcolor+j];
228
    IF ((ch>='0') && (ch<='9')) ch -= '0';
229
    IF ((ch>='A') && (ch<='F')) ch -= 'A'-10;
230
    IF ((ch>='a') && (ch<='f')) ch -= 'a'-10;
231
    color = color*0x10 + ch;
232
  }
233
  EAX=color;
234
}
235
 
236
 
975 leency 237
inline fastcall int strcmp(ESI, EDI)
903 leency 238
{
975 leency 239
	loop()
240
	{
241
		IF (DSBYTE[ESI]
242
		IF (DSBYTE[ESI]>DSBYTE[EDI]) RETURN 1;
243
		IF (DSBYTE[ESI]=='\0') RETURN 0;
244
		ESI++;
245
		EDI++;
246
	}
903 leency 247
}
248
 
249
 
975 leency 250
inline fastcall unsigned int find_symbol(ESI,BL)
251
{
252
	int jj=0, last=-1;
253
	do{
254
		jj++;
255
		$lodsb
256
		IF(AL==BL) last=jj;
257
	} while(AL!=0);
258
	return last;
259
}
260
 
261
 
262
inline fastcall memmov( EDI, ESI, ECX)
263
{
264
  asm {
265
    MOV EAX, ECX
266
    CMP EDI, ESI
267
    JG L1
268
    JE L2
269
    SAR ECX, 2
270
    JS L2
271
    REP MOVSD
272
    MOV ECX, EAX
273
    AND ECX, 3
274
    REP MOVSB
275
    JMP SHORT L2
276
L1: LEA ESI, DSDWORD[ ESI+ECX-4]
277
    LEA EDI, DSDWORD[ EDI+ECX-4]
278
    SAR ECX, 2
279
    JS L2
280
    STD
281
    REP MOVSD
282
    MOV ECX, EAX
283
    AND ECX, 3
284
    ADD ESI, 3
285
    ADD EDI, 3
286
    REP MOVSB
287
    CLD
288
L2:
289
  }
290
}
291
 
292
 
984 leency 293
inline fastcall ChangeCase(dword EDX)
903 leency 294
{
295
	AL=DSBYTE[EDX];
296
	IF(AL>='a')&&(AL<='z')DSBYTE[EDX]=AL&0x5f;
975 leency 297
	IF (AL>=160) && (AL<=175) DSBYTE[EDX] = AL - 32;	//р-я
298
	IF (AL>=224) && (AL<=239) DSBYTE[EDX] = AL - 80;	//р-я
903 leency 299
	do{
975 leency 300
		EDX++;
903 leency 301
		AL=DSBYTE[EDX];
975 leency 302
		IF(AL>='A')&&(AL<='Z'){DSBYTE[EDX]=AL|0x20; continue;}
303
		IF(AL>='А')&&(AL<='П')DSBYTE[EDX]=AL|0x20; //а-п
304
		IF (AL>=144) && (AL<=159) DSBYTE[EDX] = AL + 80;	//р-я
903 leency 305
	}while(AL!=0);
306
}
307
 
975 leency 308
 
935 leency 309
//------------------------------------------------------------------------------
310
inline fastcall void PutPixel(dword EBX,ECX,EDX){
311
  EAX=1;
312
  $int 0x40
903 leency 313
}
314
 
935 leency 315
void DefineButton(dword x,y,w,h,EDX,ESI){
316
	EAX = 8;
317
	EBX = x<<16+w;
975 leency 318
	ECX = y<<16+h;
903 leency 319
	$int 0x40
320
}
321
 
935 leency 322
inline fastcall void DeleteButton(dword EDX)
903 leency 323
{
324
	EAX = 8;
935 leency 325
	EDX += BT_DEL;
326
	$int 0x40;
903 leency 327
}
328
 
329
void WriteText(dword x,y,byte fontType, dword color, EDX, ESI)
330
{
331
	EAX = 4;
975 leency 332
	EBX = x<<16+y;
903 leency 333
	ECX = fontType<<24+color;
334
	$int 0x40;
335
}
336
 
337
void DrawBar(dword x,y,w,h,EDX)
338
{
935 leency 339
	#speed
903 leency 340
	EAX = 13;
341
	EBX = x<<16+w;
975 leency 342
	ECX = y<<16+h;
903 leency 343
 	$int 0x40
935 leency 344
	#codesize
903 leency 345
}
346
 
975 leency 347
void DrawRegion_3D(dword x,y,width,height,color1,color2)
903 leency 348
{
975 leency 349
	DrawBar(x,y,width+1,1,color1); //полоса гор сверху
350
	DrawBar(x,y+1,1,height-1,color1); //полоса слева
351
	DrawBar(x+width,y+1,1,height,color2); //полоса справа
352
	DrawBar(x,y+height,width,1,color2); //полоса гор снизу
903 leency 353
}
354
 
355
void DrawFlatButton(dword x,y,width,height,id,color,text)
356
{
975 leency 357
	DrawRegion_3D(x,y,width,height,0x94AECE,0x94AECE);
358
	DrawRegion_3D(x+1,y+1,width-2,height-2,0xFFFFFF,0xC7C7C7);
903 leency 359
	DrawBar(x+2,y+2,width-3,height-3,color); //заливка
935 leency 360
	IF (id<>0)	DefineButton(x,y,width,height,id+BT_HIDE,0xEFEBEF); //кнопка
903 leency 361
	WriteText(-strlen(text)*6+width/2+x+1,height/2-3+y,0x80,0,text,0);
362
}
363
 
364
void PutImage(dword EBX,w,h,x,y)
365
{
366
	EAX = 7;
367
	ECX = w<<16+h;
975 leency 368
	EDX = x<<16+y;
903 leency 369
	$int 0x40
370
}
371
 
935 leency 372
void PutPaletteImage(dword EBX,w,h,x,y, EDI)
903 leency 373
{
935 leency 374
	EAX = 65;
375
	ECX = w<<16+h;
975 leency 376
	EDX = x<<16+y;
935 leency 377
	ESI = 8;
378
	EBP = 0;
903 leency 379
	$int 0x40
935 leency 380
}
903 leency 381
 
944 leency 382
//------------------------------------------------------------------------------
383
inline fastcall dword WriteDebug(dword EDX)
384
{
385
	$push ebx
386
	$push ecx
387
	$mov eax, 63
388
	$mov ebx, 1
389
next_char:
390
	$mov ecx, DSDWORD[edx]
391
	$or	 cl, cl
392
	$jz  done
393
	$int 0x40
394
	$inc edx
395
	$jmp next_char
396
done:
397
	$mov cl, 13
398
	$int 0x40
399
	$mov cl, 10
400
	$int 0x40
401
	$pop ecx
402
	$pop ebx
403
}