Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
2359 IgorA 1
use32
7514 IgorA 2
	org 0
3
	db 'MENUET01'
4
	dd 1,start,i_end,mem,stacktop,0,sys_path
2359 IgorA 5
 
6
include '../../../macros.inc'
7
include '../../../proc32.inc'
7514 IgorA 8
include '../../../KOSfuncs.inc'
9
include '../../../load_img.inc'
2359 IgorA 10
include '../../../develop/libraries/box_lib/load_lib.mac'
11
 
12
@use_library_mem mem.Alloc,mem.Free,mem.ReAlloc,dll.Load
7514 IgorA 13
hed db 'Life 31.10.18',0 ;подпись окна
2359 IgorA 14
 
15
run_file_70 FileInfoBlock
16
image_data dd 0 ;указатель на временную память. для нужен преобразования изображения
17
 
18
IMAGE_TOOLBAR_ICON_SIZE equ 16*16*3
19
image_data_toolbar dd 0
20
 
21
 
22
;--------------------------------------
23
struct Cell
24
	x dd ? ;+0
25
	y dd ? ;+4
7514 IgorA 26
	tc  dd ? ;+8 поколение в котором родилась особь
27
	liv db ? ;+12 живая ячейка или нет
28
	so  db ? ;+13 число соседей
2359 IgorA 29
ends
30
 
7514 IgorA 31
MAX_CELL equ 90000 ;должно быть кратно 4
32
COL_MEM equ 64 ;число цветов для отличия молодых и старых
2359 IgorA 33
 
34
cell dd 0 ;указатель на память со структурами ячеек
35
memCell dd 0
36
CellColors dd 0
37
 
38
macro get_cell_offset reg,ind
39
{
40
	mov reg,ind
41
	imul reg,sizeof.Cell
42
	add reg,dword[cell]
43
}
44
 
45
er_oom db 0 ;на случай исчерпания памяти
46
tim_ch db 0 ;автоматически просчитывать поколения
47
poc_stop dd 1 ;просчет на число поколений
48
Cor_x dd 0
49
Cor_y dd 0
50
tim dd 0 ;время (поколение)
51
b_sort dd 0 ;граница для сортированных ячеек
52
osob dd 0 ;число особей
53
zoom db 3 ;масштаб поля
54
txt_zoom db 'Масштаб:',0
55
txt_gen db 'Поколение:',0
56
txt_osob db 'Особей:',0
57
 
58
;настройка массива с цветами
59
; col_pole - цвет поля
60
; col_cell_n - цвет новой ячейки
61
; col_cell_o - цвет старой ячейки
62
align 4
63
proc pole_init_colors uses eax ebx ecx edx esi edi, col_pole:dword, col_cell_n:dword, col_cell_o:dword
7514 IgorA 64
	mov esi,[CellColors]
65
	mov ebx,[col_pole]
2359 IgorA 66
	mov dword[esi],ebx
67
 
68
	add esi,4
69
	mov edi,COL_MEM
70
	dec edi
71
	shl edi,2
72
	add edi,esi
73
	; esi - указатель на 1-й градиентный цвет
74
	; edi - указатель на последний градиентный цвет
7514 IgorA 75
	mov eax,[col_cell_n]
76
	mov ebx,[col_cell_o]
2359 IgorA 77
 
78
	mov dword[esi],eax
79
	mov dword[edi],ebx
80
	;need save ecx edx
81
	stdcall middle_colors, esi,edi
82
 
83
	ret
84
endp
85
 
86
;вспомогательная функция для находжения среднего цвета и записи его в массив
87
;input:
88
; eax - цвет начальный
89
; ebx - цвет конечный
90
;зазрушаються: ecx, edx
91
align 4
92
proc middle_colors uses edi esi, i0:dword, i1:dword
7514 IgorA 93
	mov esi,[i0]
94
	mov edi,[i1]
2359 IgorA 95
	;перед вызовом функции
96
	;dword[esi]=eax
97
	;dword[edi]=ebx
98
	sub edi,esi
99
	shr edi,1
100
	btr edi,1 ;округляем до 4-х, т. к. нужно получить адрес (округление хитрое - убираем один бит вместо предполагаемых 2-х)
101
	add edi,esi
102
	cmp edi,esi
103
	je @f
104
		push eax ebx
105
 
106
		mov ecx,eax
107
		mov edx,ebx
108
 
109
		;находим средний цвет между eax и ebx
110
		and ebx,111111101111111011111110b ;убираем последние биты в цветах r, g, b
111
		and eax,111111101111111011111110b
112
		add eax,ebx ;сумируем цвета из r, g, b
113
		shr eax,1   ;делим на 2
114
		mov dword[edi],eax
115
 
116
		;рекурсивный вызов для дробления верхней половины
117
		mov ebx,eax
118
		mov eax,ecx
119
		stdcall middle_colors, [i0],edi
120
 
121
		;рекурсивный вызов для дробления нижней половины
122
		mov eax,ebx
123
		mov ebx,edx
124
		stdcall middle_colors, edi,[i1]
125
 
126
		pop ebx eax
127
	@@:
128
	ret
129
endp
130
 
131
align 4
7514 IgorA 132
proc pole_clear uses eax ecx edi
2359 IgorA 133
	xor eax,eax
134
	mov dword[tim],eax
135
	mov dword[osob],eax
136
	mov  byte[tim_ch],al
137
	mov dword[Cor_x],eax
138
	mov dword[Cor_y],eax
139
	mov dword[b_sort],eax
140
	mov  byte[er_oom],al
141
	cld
7514 IgorA 142
	mov ecx,(MAX_CELL*sizeof.Cell)/4
143
	mov edi,[cell]
144
	rep stosd ;memset(cell,0,sizeof(Cell)*MAX_CELL);
145
	mov edi,[memCell]
2359 IgorA 146
	mov ecx,MAX_CELL
147
	@@:
148
		stosd ;for(i=0;i
149
		inc eax
150
		loop @b
151
	ret
7514 IgorA 152
endp
2359 IgorA 153
align 4
154
proc pole_cell_creat, x:dword, y:dword, li:dword
155
	pushad ;eax ebx ecx edx edi
156
 
157
	; *** если клетка уже была создана
158
	stdcall pole_cell_find, [x],[y]
159
	cmp eax,0
160
	je @f ;if(i){
161
		get_cell_offset ebx,eax
162
		cmp dword[li],0
163
		jne .else_if ;if(!li)
164
			; если создается пустая клетка
165
			inc byte[ebx+13] ;+13 = .so
166
			jmp .fun_e
167
		.else_if: ;else if(!(cell[i].liv&1) ){
168
		bt word[ebx+12],0 ;+12 = .liv
169
			; если создается живая клетка
170
			; и раньше клетка была создана но оказалась пустой
171
			jae .creat_border_cells
172
		jmp .fun_e
173
	@@:
174
 
175
	; *** создание новой ячейки
176
	; находим номер свободной ячейки (i) для добавления новой
7514 IgorA 177
	mov edi,[memCell]
2359 IgorA 178
	inc dword[edi]
179
	cmp dword[edi],MAX_CELL
180
	jne @f
181
		dec dword[edi]
182
		mov byte[tim_ch],0
183
		;... need call message: "eror out of memory" ...
184
		;... вывод сообщения переполнения надо добавить  ...
185
		mov byte[er_oom],0
186
		jmp .fun_e ;return;
187
	@@:
7514 IgorA 188
	mov eax,[edi]
2359 IgorA 189
	shl eax,2
7514 IgorA 190
	add eax,[memCell] ;eax -> memCell[firstC]
191
	get_cell_offset ebx,[eax]
2359 IgorA 192
 
7514 IgorA 193
	mov ecx,[x]
2359 IgorA 194
	mov dword[ebx],ecx ;+0 = .x
7514 IgorA 195
	mov edx,[y]
2359 IgorA 196
	mov dword[ebx+4],edx ;+4 = .y
7514 IgorA 197
	mov eax,[tim]
2359 IgorA 198
	mov dword[ebx+8],eax ;+8 = .tc
199
	mov byte[ebx+12],0 ;+12 = .liv
200
 
201
	cmp dword[li],0
202
	jne @f
203
		mov byte[ebx+13],1 ;+13 = .so
204
		jmp .fun_e
205
	@@:
206
	mov byte[ebx+13],0 ;+13 = .so
207
 
208
	.creat_border_cells:
209
		inc dword[osob]
210
		or byte[ebx+12],1 ;+12 = .liv
7514 IgorA 211
		mov ecx,[x]
2359 IgorA 212
		dec ecx
7514 IgorA 213
		mov edx,[y]
2359 IgorA 214
		dec edx
215
		stdcall pole_cell_creat,ecx,edx,0
216
		inc edx
217
		stdcall pole_cell_creat,ecx,edx,0
218
		inc edx
219
		stdcall pole_cell_creat,ecx,edx,0
220
		inc ecx
221
		stdcall pole_cell_creat,ecx,edx,0
222
		sub edx,2
223
		stdcall pole_cell_creat,ecx,edx,0
224
		inc ecx
225
		stdcall pole_cell_creat,ecx,edx,0
226
		inc edx
227
		stdcall pole_cell_creat,ecx,edx,0
228
		inc edx
229
		stdcall pole_cell_creat,ecx,edx,0
230
	.fun_e:
231
	popad ;edi edx ecx ebx eax
232
	ret
233
endp
234
 
235
;output:
236
; eax - index
237
align 4
238
proc pole_cell_find, x:dword, y:dword
7514 IgorA 239
	mov eax,[memCell]
2359 IgorA 240
	cmp dword[eax],0
241
	jne @f
242
		xor eax,eax ;if(!fristC) return 0;
243
		jmp .fun_e
244
	@@:
245
 
246
	xor eax,eax ;fnd=0;
247
	cmp dword[b_sort],0
248
	je @f
249
		stdcall pole_bin_find, [memCell], [x],[y], [b_sort] ;i=BinFind(memCell, x,y, b_sort);
250
		cmp eax,0
251
		je @f
252
			shl eax,2
7514 IgorA 253
			add eax,[memCell]
254
			mov eax,[eax] ;if(i) fnd=memCell[i];
2359 IgorA 255
			jmp .fun_e
256
	@@:
257
 
258
	cmp eax,0
259
	jne @f ;if(!fnd){ // поиск ячейки за бинарным деревом
260
		push ebx ecx edx edi esi
261
		;ebx -> i
262
		;ecx -> firstC
263
		;edx -> &memCell[i]
264
		;edi -> cell[memCell[i]]
7514 IgorA 265
		mov ecx,[memCell]
266
		mov ebx,[b_sort]
2359 IgorA 267
		mov edx,ebx
268
		shl edx,2
269
		add edx,ecx
7514 IgorA 270
		mov ecx,[ecx]
2359 IgorA 271
		.cycle_b: ;for(i=b_sort+1;i<=fristC;i++)
2501 IgorA 272
			inc ebx
273
			cmp ebx,ecx
274
			jg .cycle_e
2359 IgorA 275
			add edx,4
7514 IgorA 276
			get_cell_offset edi,[edx]
277
			mov esi,[x]
2359 IgorA 278
			cmp dword[edi],esi ;+0 = .x
279
			jne .if_e
7514 IgorA 280
			mov esi,[y]
2359 IgorA 281
			cmp dword[edi+4],esi ;+4 = .y
282
			jne .if_e
283
				;if(cell[memCell[i]].x==x && cell[memCell[i]].y==y){
7514 IgorA 284
				mov eax,[edx] ;fnd=memCell[i];
2359 IgorA 285
				jmp .cycle_e ;break;
286
			.if_e:
2501 IgorA 287
			jmp .cycle_b
2359 IgorA 288
		.cycle_e:
289
		pop esi edi edx ecx ebx
290
	@@:
291
	.fun_e:
292
	ret
293
endp
294
 
295
;output:
296
; eax - index
297
align 4
298
proc pole_bin_find, mas:dword, fx:dword, fy:dword, k:dword
299
	push ebx ecx edx edi
300
	xor eax,eax
301
	mov ebx,1 ;ebx - максимальный порядок для дерева
302
	@@:
303
	cmp dword[k],ebx
304
	jle @f ;while(k>por)
305
		shl ebx,1 ;por<<=1;
306
		jmp @b
307
	@@:
308
	cmp dword[k],ebx
309
	jge @f ;if(k
310
		shr ebx,1 ;por>>=1;
311
	@@:
312
	mov ecx,ebx ;i=por;
313
 
314
	;ecx -> i
315
	;edi -> mas[i]
316
	.cycle_b: ;do{
317
		shr ebx,1 ;por>>=1;
318
 
319
		mov edi,ecx
320
		shl edi,2
7514 IgorA 321
		add edi,[mas]
2359 IgorA 322
		;if(compare_cells_mb(mas[i],fx,fy)){
323
		stdcall pole_compare_cells_mb_coords, dword[edi],[fx],[fy]
324
		cmp dl,0
325
		je .if_u0_e
326
			@@: ;while(i+por>k)
327
			mov edx,ecx
328
			add edx,ebx
7514 IgorA 329
			cmp edx,[k] ;i+por>k
2359 IgorA 330
			jle @f
331
				shr ebx,1 ;por>>=1;
332
				jmp @b
333
			@@:
334
			add ecx,ebx ;i+=por;
335
			jmp .if_e
336
		.if_u0_e:
337
		;else if(compare_cells_bm(mas[i],fx,fy))i-=por;
338
		stdcall pole_compare_cells_bm_coords, dword[edi],[fx],[fy]
339
		cmp dl,0
340
		je .if_u1_e
341
			sub ecx,ebx
342
			jmp .if_e
343
		.if_u1_e:
344
		;else { m=i; por=0; }
345
			mov eax,ecx
346
			xor ebx,ebx
347
		.if_e:
348
	cmp ebx,0
349
	jne .cycle_b ;}while(por);
350
 
351
	pop edi edx ecx ebx
352
	ret
353
endp
354
 
355
;output:
356
; dl
357
align 4
358
proc pole_compare_cells_bm_coords, i0:dword, fx:dword, fy:dword
359
	push eax ebx ecx
360
	get_cell_offset eax,[i0]
361
	;eax -> cell[i0]
7514 IgorA 362
	mov ebx,[fx]
2359 IgorA 363
	cmp dword[eax],ebx
364
	jle @f
365
		mov dl,1
366
		jmp .fun_e
367
	@@:
7514 IgorA 368
	mov ecx,[fy]
2359 IgorA 369
	cmp dword[eax+4],ecx
370
	jle @f
371
	cmp dword[eax],ebx
372
	jne @f
373
		mov dl,1
374
		jmp .fun_e
375
	@@:
376
	xor dl,dl
377
	.fun_e:
378
	pop ecx ebx eax
379
	ret
380
endp
381
 
382
;output:
383
; dl
384
align 4
385
proc pole_compare_cells_mb_coords, i0:dword, fx:dword, fy:dword
386
	push eax ebx ecx
387
	get_cell_offset eax,[i0]
388
	;eax -> cell[i0]
7514 IgorA 389
	mov ebx,[fx]
2359 IgorA 390
	cmp dword[eax],ebx
391
	jge @f
392
		mov dl,1
393
		jmp .fun_e
394
	@@:
7514 IgorA 395
	mov ecx,[fy]
2359 IgorA 396
	cmp dword[eax+4],ecx
397
	jge @f
398
	cmp dword[eax],ebx
399
	jne @f
400
		mov dl,1
401
		jmp .fun_e
402
	@@:
403
	xor dl,dl
404
	.fun_e:
405
	pop ecx ebx eax
406
	ret
407
endp
408
 
409
;output:
410
; dl
411
align 4
412
proc pole_compare_cells_bm, i0:dword, i1:dword
413
	push eax ebx ecx
414
	get_cell_offset eax,[i0] ;eax -> cell[i0]
415
	get_cell_offset ebx,[i1] ;ebx -> cell[i1]
7514 IgorA 416
	mov ecx,[ebx] ;+0 = .x
2359 IgorA 417
	cmp dword[eax],ecx
418
	jle @f ;x0>x1
419
		mov dl,1
420
		jmp .fun_e
421
	@@:
422
	jne @f ;x0==x1
7514 IgorA 423
	mov ecx,[ebx+4] ;+4 = .y
2359 IgorA 424
	cmp dword[eax+4],ecx
425
	jle @f ;y0>y1
426
		mov dl,1
427
		jmp .fun_e
428
	@@:
429
	xor dl,dl
430
	.fun_e:
431
	pop ecx ebx eax
432
	ret
433
endp
434
 
435
align 4
436
pole_paint:
437
	pushad
438
	;eax -> firstC
439
	;ebx -> i
440
	;ecx -> cell[memCell[i]]
441
	;edx -> color
442
	;edi -> coord_x
443
	;esi -> coord_y
7514 IgorA 444
	mov eax,[memCell]
2359 IgorA 445
	cmp dword[eax],0
446
	je .no_draw
447
 
7514 IgorA 448
	mov eax,[eax]
2359 IgorA 449
	mov ebx,1
450
 
451
;---
452
	@@: ;while(i
7514 IgorA 453
		cmp ebx,[b_sort]
2359 IgorA 454
		jge @f ;переходим на начало нижнего цикла
455
		mov ecx,ebx
456
		shl ecx,2
7514 IgorA 457
		add ecx,[memCell]
458
		get_cell_offset ecx,[ecx]
459
		mov edx,[ecx] ;+0 = .x
460
		add edx,[Cor_x]
2359 IgorA 461
		cmp edx,0
462
		jge @f ;переходим на начало нижнего цикла
463
			inc ebx ;i++; // для пропуска ячеек за окном слева
464
		jmp @b
465
	@@:
466
 
467
	cmp byte[zoom],2
468
	jge .zoom2
469
	@@: ;for(;i<=fristC;i++){
470
		mov ecx,ebx
471
		shl ecx,2
7514 IgorA 472
		add ecx,[memCell]
473
		get_cell_offset ecx,[ecx]
2359 IgorA 474
;...
7514 IgorA 475
		mov edi,[Cor_x]
476
		add edi,[ecx] ;+0 = .x
477
		mov esi,[Cor_y]
478
		add esi,[ecx+4] ;+4 = .y
2359 IgorA 479
		bt word[ecx+12],0 ;+12 = .liv
480
		jc .cell_1
481
			;не живая ячейка
7514 IgorA 482
			mov edx,[CellColors]
483
			mov edx,[edx]
2359 IgorA 484
			jmp .cell_0
485
		.cell_1:
486
			;живая ячейка
7514 IgorA 487
			mov edx,[tim]
2359 IgorA 488
			inc edx
7514 IgorA 489
			sub edx,[ecx+8] ;+8 = .tc
2359 IgorA 490
			cmp edx,COL_MEM
491
			jle .in_color
492
				mov edx,COL_MEM
493
			.in_color:
494
			shl edx,2
7514 IgorA 495
			add edx,[CellColors]
496
			mov edx,[edx]
2359 IgorA 497
		.cell_0:
498
		stdcall [buf2d_set_pixel], buf_0, edi, esi, edx
499
;...
500
		inc ebx
501
		cmp ebx,eax
502
		jle @b
503
 
504
	jmp .no_draw
505
	.zoom2:
506
 
507
	@@: ;for(;i<=fristC;i++){
508
		mov ecx,ebx
509
		shl ecx,2
7514 IgorA 510
		add ecx,[memCell]
511
		get_cell_offset ecx,[ecx]
2359 IgorA 512
 
513
		xor edx,edx
514
		mov dl,byte[zoom] ;edx используется для внесения zoom в 4 байтное число
7514 IgorA 515
		mov edi,[ecx] ;+0 = .x
516
		add edi,[Cor_x]
2359 IgorA 517
		imul edi,edx
7514 IgorA 518
		mov esi,[ecx+4] ;+4 = .y
519
		add esi,[Cor_y]
2359 IgorA 520
		imul esi,edx
521
		bt word[ecx+12],0 ;+12 = .liv
522
		jc .z2_cell_1
523
			;не живая ячейка
7514 IgorA 524
			mov edx,[CellColors]
525
			mov edx,[edx]
2359 IgorA 526
			jmp .z2_cell_0
527
		.z2_cell_1:
528
			;живая ячейка
7514 IgorA 529
			mov edx,[tim]
2359 IgorA 530
			inc edx
7514 IgorA 531
			sub edx,[ecx+8] ;+8 = .tc
2359 IgorA 532
			cmp edx,COL_MEM
533
			jle .z2_in_color
534
				mov edx,COL_MEM
535
			.z2_in_color:
536
			shl edx,2
7514 IgorA 537
			add edx,[CellColors]
538
			mov edx,[edx]
2359 IgorA 539
		.z2_cell_0:
540
		xor ecx,ecx
541
		mov cl,byte[zoom] ;ecx используется для внесения zoom в 4 байтное число
542
		;;;dec ecx
543
		stdcall [buf2d_filled_rect_by_size], buf_0, edi, esi, ecx, ecx, edx
544
		inc ebx
545
		cmp ebx,eax
546
		jle @b
547
 
548
	.no_draw:
549
	popad
550
	ret
551
 
552
align 4
553
pole_next_gen:
554
	pushad
555
	;eax -> firstC
556
	;ebx -> i
557
	;ecx -> &memCell[i]
558
	;edx -> cell[memCell[i]]
559
 
7514 IgorA 560
	mov eax,[memCell]
2359 IgorA 561
	mov ecx,eax
7514 IgorA 562
	mov eax,[eax]
2359 IgorA 563
	cmp eax,1
564
	jl .fun_e
565
	inc dword[tim]
566
	mov ebx,1
567
	@@: ;for(i=1;i<=firstC;i++)
568
		add ecx,4
7514 IgorA 569
		get_cell_offset edx,[ecx]
2359 IgorA 570
		bt word[edx+12],0 ;+12 = .liv
571
		jae .if_0_e
572
			; сохранение ячейки (соседей 2 или 3)
573
			cmp byte[edx+13],2 ;+13 = .so
574
			je .if_2_e
575
			cmp byte[edx+13],3 ;+13 = .so
576
			je .if_2_e
577
			jmp .change
578
		.if_0_e:
579
			; создание ячейки (соседей 3)
580
			cmp byte[edx+13],3 ;+13 = .so
581
			jne .if_1_e
582
			.change:
583
				or byte[edx+12],2 ;+12 = .liv
584
				jmp .if_2_e
585
		.if_1_e:
586
			; удаление пустой ячейки для освобождения памяти
587
			cmp byte[edx+13],0 ;+13 = .so
588
			jne .if_2_e
7514 IgorA 589
			mov edi,[edx+8] ;+8 = .tc
2359 IgorA 590
			add edi,5 ; 5 - время сохранения пустой ячейки, до её удаления
7514 IgorA 591
			cmp edi,[tim]
2359 IgorA 592
			jge .if_2_e
593
				mov edi,eax
594
				shl edi,2
7514 IgorA 595
				add edi,[memCell] ;edi -> &memCell[fristC]
596
				mov esi,[edi] ;swp=memCell[fristC];
597
				mov edx,[ecx] ;edx - уже не используем, потому можем портить
2359 IgorA 598
				mov dword[edi],edx ;memCell[fristC]=memCell[i];
599
				mov dword[ecx],esi ;memCell[i]=swp;
600
				dec eax
601
				dec ebx
602
				sub ecx,4
603
		.if_2_e:
604
 
605
		inc ebx
606
		cmp ebx,eax
607
		jle @b
7514 IgorA 608
	mov ebx,[memCell]
2359 IgorA 609
	mov dword[ebx],eax ;firstC <- eax
610
 
611
	mov dword[b_sort],eax
612
	stdcall pole_fl_sort, dword[memCell],eax
613
 
7514 IgorA 614
	mov ecx,[memCell]
2359 IgorA 615
	mov ebx,1
616
	@@: ;for(i=1;i<=firstC;i++)
617
		add ecx,4
7514 IgorA 618
		get_cell_offset edx,[ecx]
2359 IgorA 619
		bt word[edx+12],1 ;+12 = .liv
620
		jae .no_change
621
			xor byte[edx+12],3 ;+12 = .liv
7514 IgorA 622
			mov edi,[tim]
2359 IgorA 623
			mov dword[edx+8],edi ;+8 = .tc
624
			bt word[edx+12],0 ;+12 = .liv
625
			jc .new_cell
626
				push eax
7514 IgorA 627
				mov edi,[edx]
2359 IgorA 628
				dec edi
7514 IgorA 629
				mov esi,[edx+4]
2359 IgorA 630
				dec esi
631
				dec dword[osob]
632
				;дальше значение edx портится
633
				stdcall pole_cell_find,edi,esi
634
				get_cell_offset edx,eax
635
				dec byte[edx+13] ;+13 = .so
636
				inc esi
637
				stdcall pole_cell_find,edi,esi
638
				get_cell_offset edx,eax
639
				dec byte[edx+13] ;+13 = .so
640
				inc esi
641
				stdcall pole_cell_find,edi,esi
642
				get_cell_offset edx,eax
643
				dec byte[edx+13] ;+13 = .so
644
				inc edi
645
				stdcall pole_cell_find,edi,esi
646
				get_cell_offset edx,eax
647
				dec byte[edx+13] ;+13 = .so
648
				sub esi,2
649
				stdcall pole_cell_find,edi,esi
650
				get_cell_offset edx,eax
651
				dec byte[edx+13] ;+13 = .so
652
				inc edi
653
				stdcall pole_cell_find,edi,esi
654
				get_cell_offset edx,eax
655
				dec byte[edx+13] ;+13 = .so
656
				inc esi
657
				stdcall pole_cell_find,edi,esi
658
				get_cell_offset edx,eax
659
				dec byte[edx+13] ;+13 = .so
660
				inc esi
661
				stdcall pole_cell_find,edi,esi
662
				get_cell_offset edx,eax
663
				dec byte[edx+13] ;+13 = .so
664
				pop eax
665
				jmp .no_change
666
			.new_cell: ; появилась новая ячейка
667
				inc dword[osob]
7514 IgorA 668
				mov edi,[edx]
2359 IgorA 669
				dec edi
7514 IgorA 670
				mov esi,[edx+4]
2359 IgorA 671
				dec esi
672
				stdcall pole_cell_creat,edi,esi,0
673
				inc esi
674
				stdcall pole_cell_creat,edi,esi,0
675
				inc esi
676
				stdcall pole_cell_creat,edi,esi,0
677
				inc edi
678
				stdcall pole_cell_creat,edi,esi,0
679
				sub esi,2
680
				stdcall pole_cell_creat,edi,esi,0
681
				inc edi
682
				stdcall pole_cell_creat,edi,esi,0
683
				inc esi
684
				stdcall pole_cell_creat,edi,esi,0
685
				inc esi
686
				stdcall pole_cell_creat,edi,esi,0
687
		.no_change:
688
		inc ebx
689
		cmp ebx,eax
690
		jle @b
691
	.fun_e:
692
	popad
693
	ret
694
 
695
;Сортировка вектора a[1..n] методом Флойда
696
align 4
697
proc pole_fl_sort, a:dword, n:dword
698
	pushad
7514 IgorA 699
	mov ecx,[a]
2359 IgorA 700
	;Формировать исходное частично упорядоченное дерево
7514 IgorA 701
	mov eax,[n]
2359 IgorA 702
	shr eax,1
703
	@@: ;for(i=n>>1; i>=2; i--)
704
		stdcall pole_fl_surface, ecx,eax,[n] ;(a,i,n)
705
		dec eax
706
		cmp eax,2
707
		jge @b
708
	;Выполнить процедуру всплытия Флойда для каждого поддерева
7514 IgorA 709
	mov eax,[n]
2359 IgorA 710
	@@: ;for(i=n; i>=2; i--){
711
		stdcall pole_fl_surface, ecx,1,eax ;(a,1,i)
712
		;Поместить найденный максимальный элемент в конец списка
713
		mov edi,eax
714
		shl edi,2
715
		add edi,ecx ;edi -> &a[i]
7514 IgorA 716
		mov esi,[edi] ;w=a[i];
717
		mov edx,[ecx+4]
2359 IgorA 718
		mov dword[edi],edx ;a[i]=a[1];
719
		mov dword[ecx+4],esi ;a[1]=w;
720
 
721
		dec eax
722
		cmp eax,2
723
		jge @b
724
	popad
725
	ret
726
endp
727
 
728
;Процедура всплытия Флойда по дереву a[1..k]
729
align 4
730
proc pole_fl_surface, a:dword, i:dword, k:dword
731
locals
732
	copy dd ?
733
endl
734
	pushad
735
	;edx -> ...
736
	;edi -> m
737
	;esi -> j
7514 IgorA 738
	mov eax,[a]
739
	mov ebx,[i]
740
	mov ecx,[k]
2359 IgorA 741
 
742
	mov edx,ebx
743
	shl edx,2
744
	add edx,eax
7514 IgorA 745
	mov edx,[edx]
2359 IgorA 746
	mov dword[copy],edx ;copy=a[i];
747
	mov edi,ebx
748
	shl edi,1 ;m=i<<1;
749
	.cycle_b: ;while (m<=k) {
750
		cmp edi,ecx
751
		jg .cycle_e
752
		jne @f ;if (m==k) j=m;
753
			mov esi,edi
754
			jmp .else_e
755
		@@: ;else if (pole_compare_cells_bm(a[m],a[m+1])) j=m;
756
		mov edx,edi
757
		shl edx,2
758
		add edx,eax
759
		stdcall pole_compare_cells_bm, dword[edx],dword[edx+4]
760
		cmp dl,0
761
		je @f
762
			mov esi,edi
763
			jmp .else_e
764
		@@: ;else j=m+1;
765
			mov esi,edi
766
			inc esi
767
		.else_e:
768
 
769
		;if (pole_compare_cells_bm(a[j],copy)) {
770
		mov edx,esi
771
		shl edx,2
772
		add edx,eax
773
		stdcall pole_compare_cells_bm, dword[edx],dword[copy]
774
		cmp dl,0
775
		je .cycle_e ;} else break; //выход из цикла
776
 
777
		mov edx,esi
778
		shl edx,2
779
		add edx,eax
780
		push dword[edx] ;push a[j];
781
		mov edx,ebx
782
		shl edx,2
783
		add edx,eax
784
		pop dword[edx] ;a[i]=a[j];
785
		mov ebx,esi ;i=j;
786
		mov edi,ebx
787
		shl edi,1 ;m=i<<1;
788
 
789
		jmp .cycle_b
790
	.cycle_e:
791
 
792
	;значения многих регистров уже не важны т. к. конец функции
793
	shl ebx,2
794
	add eax,ebx
7514 IgorA 795
	mov edx,[copy]
2359 IgorA 796
	mov dword[eax],edx ;a[i]=copy;
797
 
798
	popad
799
	ret
800
endp
801
;--------------------------------------
802
 
803
 
804
align 4
805
start:
806
	load_libraries l_libs_start,l_libs_end
807
	;проверка на сколько удачно загузилась наша либа
808
	mov	ebp,lib_7
809
	cmp	dword [ebp+ll_struc_size-4],0
810
	jz	@f
7514 IgorA 811
		mcall SF_TERMINATE_PROCESS ;exit not correct
2359 IgorA 812
	@@:
7514 IgorA 813
	mcall SF_STYLE_SETTINGS,SSF_GET_COLORS,sc,sizeof.system_colors
814
	mcall SF_SET_EVENTS_MASK,0x27
2359 IgorA 815
	stdcall [OpenDialog_Init],OpenDialog_data ;подготовка диалога
816
 
817
	stdcall [buf2d_create], buf_0 ;создание буфера
818
 
819
	stdcall mem.Alloc,MAX_CELL*sizeof.Cell
820
	mov [cell],eax
821
	stdcall mem.Alloc,MAX_CELL*4
822
	mov [memCell],eax
823
	stdcall mem.Alloc,(COL_MEM+1)*4
824
	mov [CellColors],eax
7514 IgorA 825
	include_image_file 'toolbar.png', image_data_toolbar
2359 IgorA 826
 
2501 IgorA 827
	;настройка цветов ячеек
828
	stdcall pole_init_colors, 0xffffd0,0xff0000,0x0000ff
2359 IgorA 829
	call pole_clear
830
	call pole_paint ;рисование поля в буфере (не на экране)
831
 
832
	;xor eax,eax
833
	;mov edi,txt_zoom.zi
834
	;mov al,byte[zoom]
835
	;call tl_convert_to_str
836
 
7514 IgorA 837
	mcall SF_SYSTEM_GET,SSF_TIME_COUNT
2359 IgorA 838
	mov [last_time],eax
839
 
840
align 4
841
red_win:
842
	call draw_window
843
 
844
align 4
845
still:
7514 IgorA 846
	mcall SF_SYSTEM_GET,SSF_TIME_COUNT
2359 IgorA 847
	mov ebx,[last_time]
848
	add ebx,10 ;задержка
849
	cmp ebx,eax
850
	jge @f
851
		mov ebx,eax
852
	@@:
853
	sub ebx,eax
7514 IgorA 854
	mcall SF_WAIT_EVENT_TIMEOUT
2359 IgorA 855
	cmp eax,0
856
	je timer_funct
857
 
858
	cmp al,1
859
	jz red_win
860
	cmp al,2
861
	jz key
862
	cmp al,3
863
	jz button
864
 
865
	jmp still
866
 
867
align 4
868
timer_funct:
869
	pushad
7514 IgorA 870
	mcall SF_SYSTEM_GET,SSF_TIME_COUNT
2359 IgorA 871
	mov [last_time],eax
872
 
873
	cmp byte[tim_ch],0
874
	je @f
875
		;call but_next_gen
876
		cld
7514 IgorA 877
		mov ecx,[poc_stop]
2359 IgorA 878
		cmp ecx,1
879
		jg .clear
880
			mov ecx,1 ;исправление ecx на случай чисел меньших 1
881
			jmp .cycle
882
		.clear: ;чистим поле если есть просчет на несколько поколений за 1 такт таймера
883
			stdcall [buf2d_clear], buf_0, [buf_0.color]
884
		.cycle:
885
			call pole_next_gen
886
			loop .cycle
887
		call pole_paint
888
		stdcall [buf2d_draw], buf_0
889
		call draw_pok
890
	@@:
891
	popad
892
	jmp still
893
 
894
align 4
895
draw_window:
896
pushad
7514 IgorA 897
	mcall SF_REDRAW,SSF_BEGIN_DRAW
2359 IgorA 898
	mov edx,[sc.work]
7514 IgorA 899
	or  edx,0x33000000
2359 IgorA 900
	mov edi,hed
7514 IgorA 901
	mcall SF_CREATE_WINDOW,(20 shl 16)+485,(20 shl 16)+415
2359 IgorA 902
 
7514 IgorA 903
	mcall SF_DEFINE_BUTTON,(5 shl 16)+20,(5 shl 16)+20,3, [sc.work_button]
2359 IgorA 904
 
905
	mov ebx,(30 shl 16)+20
906
	mov edx,4
907
	int 0x40
908
 
909
	mov ebx,(55 shl 16)+20
910
	mov edx,5
911
	int 0x40
912
 
913
	mov ebx,(85 shl 16)+20
914
	mov edx,6
915
	int 0x40
916
 
917
	mov ebx,(110 shl 16)+20
918
	mov edx,7
919
	int 0x40
920
 
921
	mov ebx,(135 shl 16)+20
922
	mov edx,8
923
	int 0x40
924
 
925
	mov ebx,(165 shl 16)+20
926
	mov edx,9
927
	int 0x40
928
 
929
	mov ebx,(190 shl 16)+20
930
	mov edx,10
931
	int 0x40
932
 
933
	mov ebx,(220 shl 16)+20
934
	mov edx,11
935
	int 0x40
936
 
937
	mov ebx,(245 shl 16)+20
938
	mov edx,12
939
	int 0x40
940
 
941
	mov ebx,(270 shl 16)+20
942
	mov edx,13
943
	int 0x40
944
 
945
	mov ebx,(295 shl 16)+20
946
	mov edx,14
947
	int 0x40
948
 
7514 IgorA 949
	mcall SF_PUT_IMAGE,[image_data_toolbar],(16 shl 16)+16,(32 shl 16)+7
2359 IgorA 950
 
951
	add ebx,IMAGE_TOOLBAR_ICON_SIZE
952
	mov edx,(87 shl 16)+7 ;run once
953
	int 0x40
954
 
955
	add ebx,IMAGE_TOOLBAR_ICON_SIZE
956
	mov edx,(112 shl 16)+7 ;run auto
957
	int 0x40
958
	add ebx,IMAGE_TOOLBAR_ICON_SIZE
959
	mov edx,(137 shl 16)+7 ;stop
960
	int 0x40
961
 
962
	add ebx,IMAGE_TOOLBAR_ICON_SIZE
963
	mov edx,(167 shl 16)+7 ;-
964
	int 0x40
965
	add ebx,IMAGE_TOOLBAR_ICON_SIZE
966
	mov edx,(192 shl 16)+7 ;+
967
	int 0x40
968
 
969
	add ebx,IMAGE_TOOLBAR_ICON_SIZE
970
	mov edx,(222 shl 16)+7 ;move up
971
	int 0x40
972
	add ebx,IMAGE_TOOLBAR_ICON_SIZE
973
	mov edx,(247 shl 16)+7 ;move doun
974
	int 0x40
975
	add ebx,IMAGE_TOOLBAR_ICON_SIZE
976
	mov edx,(272 shl 16)+7 ;move left
977
	int 0x40
978
	add ebx,IMAGE_TOOLBAR_ICON_SIZE
979
	mov edx,(297 shl 16)+7 ;move up
980
	int 0x40
981
 
982
	call draw_pok
983
 
984
	stdcall [buf2d_draw], buf_0
985
 
7514 IgorA 986
	mcall SF_REDRAW,SSF_END_DRAW
2359 IgorA 987
popad
988
	ret
989
 
990
align 4
991
draw_pok:
7514 IgorA 992
	mov eax,SF_DRAW_TEXT
2359 IgorA 993
	mov ebx,325*65536+5
994
	mov ecx,[sc.work_text]
995
	or  ecx,0x80000000 ;or (1 shl 30)
996
	mov edx,txt_zoom
997
	;mov edi,[sc.work]
998
	int 0x40
999
	add bx,9
1000
	mov edx,txt_gen
1001
	int 0x40
1002
	add bx,9
1003
	mov edx,txt_osob
1004
	int 0x40
1005
 
7514 IgorA 1006
	mov eax,SF_DRAW_NUMBER
2359 IgorA 1007
	xor ecx,ecx
1008
	mov cl,byte[zoom]
1009
	mov ebx,(2 shl 16)
1010
	mov edx,(325+6*9)*65536+5
1011
	mov esi,[sc.work_button_text]
1012
	or  esi,(1 shl 30)
1013
	mov edi,[sc.work_button]
1014
	int 0x40 ;масштаб
1015
	mov ebx,(5 shl 16)
1016
	mov ecx,[tim]
1017
	add edx,(6*2)*65536+9
1018
	int 0x40 ;время
1019
	mov ebx,(5 shl 16)
1020
	mov ecx,[osob]
1021
	add edx,(6*0)*65536+9
1022
	int 0x40 ;популяция
1023
	ret
1024
 
1025
align 4
1026
key:
7514 IgorA 1027
	mcall SF_GET_KEY
2359 IgorA 1028
	jmp still
1029
 
1030
 
1031
align 4
1032
button:
7514 IgorA 1033
	mcall SF_GET_BUTTON
2359 IgorA 1034
	cmp ah,3
1035
	jne @f
1036
		call but_new_file
7514 IgorA 1037
		jmp still
2359 IgorA 1038
	@@:
1039
	cmp ah,4
1040
	jne @f
1041
		call but_open_file
7514 IgorA 1042
		jmp still
2359 IgorA 1043
	@@:
1044
	cmp ah,5
1045
	jne @f
1046
		call but_save_file
7514 IgorA 1047
		jmp still
2359 IgorA 1048
	@@:
1049
	cmp ah,6
1050
	jne @f
1051
		call but_next_gen
7514 IgorA 1052
		jmp still
2359 IgorA 1053
	@@:
1054
	cmp ah,7
1055
	jne @f
1056
		call but_run
7514 IgorA 1057
		jmp still
2359 IgorA 1058
	@@:
1059
	cmp ah,8
1060
	jne @f
1061
		call but_stop
7514 IgorA 1062
		jmp still
2359 IgorA 1063
	@@:
1064
	cmp ah,9
1065
	jne @f
1066
		call but_zoom_p
7514 IgorA 1067
		jmp still
2359 IgorA 1068
	@@:
1069
	cmp ah,10
1070
	jne @f
1071
		call but_zoom_m
7514 IgorA 1072
		jmp still
2359 IgorA 1073
	@@:
1074
	cmp ah,11
1075
	jne @f
1076
		call but_pole_up
7514 IgorA 1077
		jmp still
2359 IgorA 1078
	@@:
1079
	cmp ah,12
1080
	jne @f
1081
		call but_pole_dn
7514 IgorA 1082
		jmp still
2359 IgorA 1083
	@@:
1084
	cmp ah,13
1085
	jne @f
1086
		call but_pole_left
7514 IgorA 1087
		jmp still
2359 IgorA 1088
	@@:
1089
	cmp ah,14
1090
	jne @f
1091
		call but_pole_right
7514 IgorA 1092
		jmp still
2359 IgorA 1093
	@@:
1094
	cmp ah,1
1095
	jne still
1096
.exit:
1097
	stdcall [buf2d_delete],buf_0
7514 IgorA 1098
	stdcall mem.Free,[open_file_lif]
2359 IgorA 1099
	stdcall mem.Free,[cell]
1100
	stdcall mem.Free,[memCell]
1101
	stdcall mem.Free,[CellColors]
1102
	stdcall mem.Free,[image_data_toolbar]
7514 IgorA 1103
	mcall SF_TERMINATE_PROCESS
2359 IgorA 1104
 
1105
 
1106
align 4
1107
but_new_file:
1108
	ret
1109
 
1110
align 4
7514 IgorA 1111
open_file_lif dd 0 ;указатель на память для открытия файлов
1112
open_file_size dd 0 ;размер открытого файла
2359 IgorA 1113
 
1114
align 4
1115
but_open_file:
1116
	pushad
1117
	copy_path open_dialog_name,communication_area_default_path,file_name,0
1118
	mov [OpenDialog_data.type],0
1119
	stdcall [OpenDialog_Start],OpenDialog_data
1120
	cmp [OpenDialog_data.status],2
1121
	je .end_open_file
1122
	;код при удачном открытии диалога
1123
 
7514 IgorA 1124
	mov [run_file_70.Function], SSF_GET_INFO
2359 IgorA 1125
	mov [run_file_70.Position], 0
1126
	mov [run_file_70.Flags], 0
7514 IgorA 1127
	mov dword[run_file_70.Count], 0
1128
	mov dword[run_file_70.Buffer], open_b
2359 IgorA 1129
	mov byte[run_file_70+20], 0
1130
	mov dword[run_file_70.FileName], openfile_path
7514 IgorA 1131
	mcall SF_FILE,run_file_70
1132
 
1133
	mov ecx,dword[open_b+32] ;+32 qword: размер файла в байтах
1134
	inc ecx ;for text files
1135
	stdcall mem.ReAlloc,[open_file_lif],ecx
1136
	mov [open_file_lif],eax
1137
	dec ecx ;for text files
1138
	mov byte[eax+ecx],0 ;for text files
1139
 
1140
	mov [run_file_70.Function], SSF_READ_FILE
1141
	mov [run_file_70.Position], 0
1142
	mov [run_file_70.Flags], 0
1143
	mov [run_file_70.Count], ecx
1144
	m2m dword[run_file_70.Buffer], dword[open_file_lif]
1145
	mov byte[run_file_70+20], 0
1146
	mov dword[run_file_70.FileName], openfile_path
1147
	mcall SF_FILE,run_file_70 ;загружаем файл изображения
1148
	test eax,eax
1149
	jnz .end_open_file
2359 IgorA 1150
	cmp ebx,0xffffffff
1151
	je .end_open_file
1152
 
7514 IgorA 1153
	mov [open_file_size],ebx
1154
	mcall SF_SET_CAPTION,1,openfile_path
2359 IgorA 1155
 
1156
	call pole_clear
7514 IgorA 1157
	mov eax,[buf_0.w]
2359 IgorA 1158
	shr eax,1
1159
	xor ecx,ecx
1160
	mov cl,byte[zoom]
1161
	cmp cx,2
1162
	jl @f ;деление на величину zoom
1163
		xor edx,edx
1164
		div ecx
1165
	@@:
7514 IgorA 1166
	add [Cor_x],eax
1167
	mov eax,[buf_0.h]
2359 IgorA 1168
	shr eax,1
1169
	cmp cx,2
1170
	jl @f ;деление на величину zoom
1171
		xor edx,edx
1172
		div ecx
1173
	@@:
7514 IgorA 1174
	add [Cor_y],eax
2359 IgorA 1175
 
1176
	;eax - first x position
1177
	;ebx - x position
1178
	;ecx - y position
7514 IgorA 1179
	;edx - конец файла
1180
	mov edi,[open_file_lif]
2359 IgorA 1181
	xor ebx,ebx
1182
	xor ecx,ecx
1183
	mov eax,ebx
7514 IgorA 1184
	mov edx,[open_file_lif]
1185
	add edx,[open_file_size]
2359 IgorA 1186
	@@:
1187
		cmp byte[edi],'*'
1188
		jne .no_cell
1189
			stdcall pole_cell_creat, ebx,ecx,1
1190
			inc ebx
1191
		.no_cell:
1192
		cmp byte[edi],'.'
1193
		jne .cell_move
1194
			inc ebx
1195
		.cell_move:
1196
		cmp byte[edi],13
1197
		jne .cell_nl
1198
			mov ebx,eax
1199
			inc ecx
1200
		.cell_nl:
1201
		cmp word[edi],'#P' ;смена позиции
1202
		jne .pos
1203
			inc edi ;пропуск '#'
1204
			.space:
1205
				inc edi ;пропуск 'P' и ' '
1206
				cmp byte[edi],' '
1207
				je .space
1208
			stdcall conv_str_to_int,edi
1209
			mov ebx,eax
1210
			cmp byte[edi],'-'
1211
			jne .digit
1212
				inc edi
1213
			.digit:
1214
				cmp byte[edi],'0'
1215
				jl .digit_no
1216
				cmp byte[edi],'9'
1217
				jg .digit_no
1218
				inc edi
1219
				jmp .digit
1220
			.digit_no:
1221
			;.space_1:
1222
				inc edi ;пропуск 'P' и ' '
1223
				cmp byte[edi],' '
1224
				je .digit_no ;.space_1
1225
			stdcall conv_str_to_int,edi
1226
			mov ecx,eax
1227
			mov eax,ebx ;восстановление левого отступа в eax
1228
		.pos:
1229
		inc edi
7514 IgorA 1230
		cmp edi,edx
1231
		jl @b
2359 IgorA 1232
	;---
1233
	stdcall [buf2d_clear], buf_0, [buf_0.color] ;чистим буфер
1234
	call pole_paint ;рисуем поле (на случай если есть сетка или текстовые подписи)
1235
	stdcall [buf2d_draw], buf_0 ;обновляем буфер на экране
1236
	.end_open_file:
1237
	popad
1238
	ret
1239
 
1240
align 4
1241
but_save_file:
1242
	ret
1243
 
1244
align 4
1245
but_next_gen:
1246
	call pole_next_gen
1247
	call pole_paint
1248
	stdcall [buf2d_draw], buf_0
1249
	pushad
1250
		call draw_pok
1251
	popad
1252
	ret
1253
 
1254
align 4
1255
but_run:
1256
	mov byte[tim_ch],1
1257
	ret
1258
 
1259
align 4
1260
but_stop:
1261
	mov byte[tim_ch],0
1262
	;cld
1263
	;mov ecx,100
1264
	;@@:
1265
	;       call pole_next_gen
1266
	;loop @b
1267
	;stdcall [buf2d_clear], buf_0, [buf_0.color]
1268
	;call pole_paint
1269
	;stdcall [buf2d_draw], buf_0
1270
	ret
1271
 
1272
align 4
1273
but_zoom_p:
1274
	cmp byte[zoom],16
1275
	jge @f
1276
		pushad
1277
		;вычисление сдвигов для поля, которые обеспечат центровку поля при увеличении масштаба
1278
		xor ecx,ecx
1279
		mov cl,byte[zoom]
1280
		xor edx,edx
7514 IgorA 1281
		mov eax,[buf_0.w]
2359 IgorA 1282
		shr eax,1 ;в eax половина ширины поля
1283
		mov ebx,eax ;делаем резервную копию eax
1284
		div ecx ;делим eax на текущий масштаб
1285
		xchg eax,ebx
1286
		xor edx,edx
1287
		inc ecx
1288
		div ecx ;делим eax на новый масштаб
1289
		sub ebx,eax ;вычисляется сдвиг поля который обеспечит центровку поля
1290
		sub dword[Cor_x],ebx ;сдвигаем поле зрения по оси x
1291
		xor ecx,ecx
1292
		mov cl,byte[zoom]
1293
		xor edx,edx
7514 IgorA 1294
		mov eax,[buf_0.h]
2359 IgorA 1295
		shr eax,1
1296
		mov ebx,eax
1297
		div ecx
1298
		xchg eax,ebx
1299
		xor edx,edx
1300
		inc ecx
1301
		div ecx
1302
		sub ebx,eax
1303
		sub dword[Cor_y],ebx ;сдвигаем поле зрения по оси y
1304
 
1305
		inc byte[zoom]
1306
		;xor eax,eax
1307
		;mov edi,txt_zoom.zi
1308
		;mov al,byte[zoom]
1309
		;call tl_convert_to_str
1310
		call draw_pok
1311
		popad
1312
 
1313
		cmp dword[poc_stop],1
1314
		jle .buf_clear
1315
		cmp byte[tim_ch],0
1316
		jne @f
1317
			.buf_clear:
1318
			stdcall [buf2d_clear], buf_0, [buf_0.color]
1319
			call pole_paint
1320
			stdcall [buf2d_draw], buf_0
1321
	@@:
1322
	ret
1323
 
1324
align 4
1325
but_zoom_m:
1326
	cmp byte[zoom],1
1327
	jle @f
1328
		pushad
1329
		;вычисление сдвигов для поля, которые обеспечат центровку поля при уменьшении масштаба
1330
		xor ecx,ecx
1331
		mov cl,byte[zoom]
1332
		xor edx,edx
7514 IgorA 1333
		mov eax,[buf_0.w]
2359 IgorA 1334
		shr eax,1 ;в eax половина ширины поля
1335
		mov ebx,eax ;делаем резервную копию eax
1336
		div ecx ;делим eax на текущий масштаб
1337
		xchg eax,ebx
1338
		xor edx,edx
1339
		dec ecx
1340
		div ecx ;делим eax на новый масштаб
1341
		sub ebx,eax ;вычисляется сдвиг поля который обеспечит центровку поля
1342
		sub dword[Cor_x],ebx ;сдвигаем поле зрения по оси x
1343
		xor ecx,ecx
1344
		mov cl,byte[zoom]
1345
		xor edx,edx
7514 IgorA 1346
		mov eax,[buf_0.h]
2359 IgorA 1347
		shr eax,1
1348
		mov ebx,eax
1349
		div ecx
1350
		xchg eax,ebx
1351
		xor edx,edx
1352
		dec ecx
1353
		div ecx
1354
		sub ebx,eax
1355
		sub dword[Cor_y],ebx ;сдвигаем поле зрения по оси y
1356
 
1357
		dec byte[zoom]
1358
		;xor eax,eax
1359
		;mov edi,txt_zoom.zi
1360
		;mov al,byte[zoom]
1361
		;call tl_convert_to_str
1362
		call draw_pok
1363
		popad
1364
 
1365
		cmp dword[poc_stop],1
1366
		jle .buf_clear
1367
		cmp byte[tim_ch],0
1368
		jne @f
1369
			.buf_clear:
1370
			stdcall [buf2d_clear], buf_0, [buf_0.color]
1371
			call pole_paint
1372
			stdcall [buf2d_draw], buf_0
1373
	@@:
1374
	ret
1375
 
1376
align 4
1377
but_pole_up:
1378
	push eax ecx edx
7514 IgorA 1379
	mov eax,[buf_0.h]
2359 IgorA 1380
	shr eax,2
1381
	xor ecx,ecx
1382
	mov cl,byte[zoom]
1383
	cmp cx,2
1384
	jl @f ;деление на величину zoom
1385
		xor edx,edx
1386
		div ecx
1387
	@@:
1388
	add dword[Cor_y],eax
1389
	pop edx ecx eax
1390
	stdcall [buf2d_clear], buf_0, [buf_0.color]
1391
	call pole_paint
1392
	stdcall [buf2d_draw], buf_0
1393
	ret
1394
 
1395
align 4
1396
but_pole_dn:
1397
	push eax ecx edx
7514 IgorA 1398
	mov eax,[buf_0.h]
2359 IgorA 1399
	shr eax,2
1400
	xor ecx,ecx
1401
	mov cl,byte[zoom]
1402
	cmp cx,2
1403
	jl @f ;деление на величину zoom
1404
		xor edx,edx
1405
		div ecx
1406
	@@:
1407
	sub dword[Cor_y],eax
1408
	pop edx ecx eax
1409
	stdcall [buf2d_clear], buf_0, [buf_0.color]
1410
	call pole_paint
1411
	stdcall [buf2d_draw], buf_0
1412
	ret
1413
 
1414
align 4
1415
but_pole_left:
1416
	push eax ecx edx
7514 IgorA 1417
	mov eax,[buf_0.w]
2359 IgorA 1418
	shr eax,2
1419
	xor ecx,ecx
1420
	mov cl,byte[zoom]
1421
	cmp cx,2
1422
	jl @f ;деление на величину zoom
1423
		xor edx,edx
1424
		div ecx
1425
	@@:
1426
	add dword[Cor_x],eax
1427
	pop edx ecx eax
1428
	stdcall [buf2d_clear], buf_0, [buf_0.color]
1429
	call pole_paint
1430
	stdcall [buf2d_draw], buf_0
1431
	ret
1432
 
1433
align 4
1434
but_pole_right:
1435
	push eax ecx edx
7514 IgorA 1436
	mov eax,[buf_0.w]
2359 IgorA 1437
	shr eax,2
1438
	xor ecx,ecx
1439
	mov cl,byte[zoom]
1440
	cmp cx,2
1441
	jl @f ;деление на величину zoom
1442
		xor edx,edx
1443
		div ecx
1444
	@@:
1445
	sub dword[Cor_x],eax
1446
	pop edx ecx eax
1447
	stdcall [buf2d_clear], buf_0, [buf_0.color]
1448
	call pole_paint
1449
	stdcall [buf2d_draw], buf_0
1450
	ret
1451
 
1452
;align 4
1453
;but_bru_clear:
1454
;        ret
1455
 
1456
;input:
1457
; buf - указатель на строку, число должно быть в 10 или 16 ричном виде
1458
;output:
1459
; eax - число
1460
align 4
1461
proc conv_str_to_int, buf:dword
1462
	xor eax,eax
1463
	push ebx ecx esi
1464
	xor ebx,ebx
1465
	mov esi,[buf]
1466
	;определение отрицательных чисел
1467
	xor ecx,ecx
1468
	inc ecx
1469
	cmp byte[esi],'-'
1470
	jne @f
1471
		dec ecx
1472
		inc esi
1473
	@@:
1474
 
1475
	cmp word[esi],'0x'
1476
	je .load_digit_16
1477
 
1478
	.load_digit_10: ;считывание 10-тичных цифр
1479
		mov bl,byte[esi]
1480
		cmp bl,'0'
1481
		jl @f
1482
		cmp bl,'9'
1483
		jg @f
1484
			sub bl,'0'
1485
			imul eax,10
1486
			add eax,ebx
1487
			inc esi
1488
			jmp .load_digit_10
1489
	jmp @f
1490
 
1491
	.load_digit_16: ;считывание 16-ричных цифр
1492
		add esi,2
1493
	.cycle_16:
1494
		mov bl,byte[esi]
1495
		cmp bl,'0'
1496
		jl @f
1497
		cmp bl,'f'
1498
		jg @f
1499
		cmp bl,'9'
1500
		jle .us1
1501
			cmp bl,'A'
1502
			jl @f ;отсеиваем символы >'9' и <'A'
1503
		.us1: ;составное условие
1504
		cmp bl,'F'
1505
		jle .us2
1506
			cmp bl,'a'
1507
			jl @f ;отсеиваем символы >'F' и <'a'
1508
			sub bl,32 ;переводим символы в верхний регистр, для упрощения их последущей обработки
1509
		.us2: ;составное условие
1510
			sub bl,'0'
1511
			cmp bl,9
1512
			jle .cor1
1513
				sub bl,7 ;convert 'A' to '10'
1514
			.cor1:
1515
			shl eax,4
1516
			add eax,ebx
1517
			inc esi
1518
			jmp .cycle_16
1519
	@@:
1520
	cmp ecx,0 ;если число отрицательное
1521
	jne @f
1522
		sub ecx,eax
1523
		mov eax,ecx
1524
	@@:
1525
	pop esi ecx ebx
1526
	ret
1527
endp
1528
 
1529
;данные для диалога открытия файлов
1530
align 4
1531
OpenDialog_data:
1532
.type			dd 0 ;0 - открыть, 1 - сохранить, 2 - выбрать дтректорию
1533
.procinfo		dd procinfo	;+4
1534
.com_area_name		dd communication_area_name	;+8
1535
.com_area		dd 0	;+12
1536
.opendir_path		dd plugin_path	;+16
1537
.dir_default_path	dd default_dir ;+20
1538
.start_path		dd file_name ;+24 путь к диалогу открытия файлов
1539
.draw_window		dd draw_window	;+28
1540
.status 		dd 0	;+32
1541
.openfile_path		dd openfile_path	;+36 путь к открываемому файлу
1542
.filename_area		dd filename_area	;+40
1543
.filter_area		dd Filter
1544
.x:
1545
.x_size 		dw 420 ;+48 ; Window X size
1546
.x_start		dw 10 ;+50 ; Window X position
1547
.y:
1548
.y_size 		dw 320 ;+52 ; Window y size
1549
.y_start		dw 10 ;+54 ; Window Y position
1550
 
1551
default_dir db '/rd/1',0
1552
 
1553
communication_area_name:
1554
	db 'FFFFFFFF_open_dialog',0
1555
open_dialog_name:
1556
	db 'opendial',0
1557
communication_area_default_path:
1558
	db '/rd/1/File managers/',0
1559
 
1560
Filter:
1561
dd Filter.end - Filter ;.1
1562
.1:
1563
db 'LIF',0
1564
db 'RLE',0
1565
.end:
1566
db 0
1567
 
1568
 
1569
 
1570
head_f_i:
1571
head_f_l db 'Системная ошибка',0
1572
 
1573
system_dir_0 db '/sys/lib/'
1574
lib_name_0 db 'proc_lib.obj',0
1575
err_message_found_lib_0 db 'Не найдена библиотека ',39,'proc_lib.obj',39,0
1576
err_message_import_0 db 'Ошибка при импорте библиотеки ',39,'proc_lib.obj',39,0
1577
 
1578
system_dir_1 db '/sys/lib/'
1579
lib_name_1 db 'libimg.obj',0
1580
err_message_found_lib_1 db 'Не найдена библиотека ',39,'libimg.obj',39,0
1581
err_message_import_1 db 'Ошибка при импорте библиотеки ',39,'libimg.obj',39,0
1582
 
1583
system_dir_7 db '/sys/lib/'
1584
lib_name_7 db 'buf2d.obj',0
1585
err_msg_found_lib_7 db 'Не найдена библиотека ',39,'buf2d.obj',39,0
1586
err_msg_import_7 db 'Ошибка при импорте библиотеки ',39,'buf2d',39,0
1587
 
1588
l_libs_start:
1589
	lib0 l_libs lib_name_0, sys_path, file_name, system_dir_0,\
1590
		err_message_found_lib_0, head_f_l, proclib_import,err_message_import_0, head_f_i
1591
	lib1 l_libs lib_name_1, sys_path, file_name, system_dir_1,\
1592
		err_message_found_lib_1, head_f_l, import_libimg, err_message_import_1, head_f_i
1593
	lib_7 l_libs lib_name_7, sys_path, library_path, system_dir_7,\
1594
		err_msg_found_lib_7,head_f_l,import_buf2d,err_msg_import_7,head_f_i
1595
l_libs_end:
1596
 
1597
align 4
1598
import_libimg:
1599
	dd alib_init1
1600
	img_is_img  dd aimg_is_img
1601
	img_info    dd aimg_info
1602
	img_from_file dd aimg_from_file
1603
	img_to_file dd aimg_to_file
1604
	img_from_rgb dd aimg_from_rgb
1605
	img_to_rgb  dd aimg_to_rgb
1606
	img_to_rgb2 dd aimg_to_rgb2
1607
	img_decode  dd aimg_decode
1608
	img_encode  dd aimg_encode
1609
	img_create  dd aimg_create
1610
	img_destroy dd aimg_destroy
1611
	img_destroy_layer dd aimg_destroy_layer
1612
	img_count   dd aimg_count
1613
	img_lock_bits dd aimg_lock_bits
1614
	img_unlock_bits dd aimg_unlock_bits
1615
	img_flip    dd aimg_flip
1616
	img_flip_layer dd aimg_flip_layer
1617
	img_rotate  dd aimg_rotate
1618
	img_rotate_layer dd aimg_rotate_layer
1619
	img_draw    dd aimg_draw
1620
 
1621
	dd 0,0
1622
	alib_init1   db 'lib_init',0
1623
	aimg_is_img  db 'img_is_img',0 ;определяет по данным, может ли библиотека сделать из них изображение
1624
	aimg_info    db 'img_info',0
1625
	aimg_from_file db 'img_from_file',0
1626
	aimg_to_file db 'img_to_file',0
1627
	aimg_from_rgb db 'img_from_rgb',0
1628
	aimg_to_rgb  db 'img_to_rgb',0 ;преобразование изображения в данные RGB
1629
	aimg_to_rgb2 db 'img_to_rgb2',0
1630
	aimg_decode  db 'img_decode',0 ;автоматически определяет формат графических данных
1631
	aimg_encode  db 'img_encode',0
1632
	aimg_create  db 'img_create',0
1633
	aimg_destroy db 'img_destroy',0
1634
	aimg_destroy_layer db 'img_destroy_layer',0
1635
	aimg_count   db 'img_count',0
1636
	aimg_lock_bits db 'img_lock_bits',0
1637
	aimg_unlock_bits db 'img_unlock_bits',0
1638
	aimg_flip    db 'img_flip',0
1639
	aimg_flip_layer db 'img_flip_layer',0
1640
	aimg_rotate  db 'img_rotate',0
1641
	aimg_rotate_layer db 'img_rotate_layer',0
1642
	aimg_draw    db 'img_draw',0
1643
 
1644
align 4
1645
proclib_import: ;описание экспортируемых функций
1646
	OpenDialog_Init dd aOpenDialog_Init
1647
	OpenDialog_Start dd aOpenDialog_Start
1648
dd 0,0
1649
	aOpenDialog_Init db 'OpenDialog_init',0
1650
	aOpenDialog_Start db 'OpenDialog_start',0
1651
 
1652
align 4
1653
import_buf2d:
1654
	init dd sz_init
1655
	buf2d_create dd sz_buf2d_create
1656
	buf2d_create_f_img dd sz_buf2d_create_f_img
1657
	buf2d_clear dd sz_buf2d_clear
1658
	buf2d_draw dd sz_buf2d_draw
1659
	buf2d_delete dd sz_buf2d_delete
1660
	buf2d_line dd sz_buf2d_line
1661
	buf2d_rect_by_size dd sz_buf2d_rect_by_size
1662
	buf2d_filled_rect_by_size dd sz_buf2d_filled_rect_by_size
1663
	buf2d_circle dd sz_buf2d_circle
1664
	buf2d_img_hdiv2 dd sz_buf2d_img_hdiv2
1665
	buf2d_img_wdiv2 dd sz_buf2d_img_wdiv2
1666
	buf2d_conv_24_to_8 dd sz_buf2d_conv_24_to_8
1667
	buf2d_conv_24_to_32 dd sz_buf2d_conv_24_to_32
1668
	buf2d_bit_blt dd sz_buf2d_bit_blt
1669
	buf2d_bit_blt_transp dd sz_buf2d_bit_blt_transp
1670
	buf2d_bit_blt_alpha dd sz_buf2d_bit_blt_alpha
1671
	buf2d_curve_bezier dd sz_buf2d_curve_bezier
1672
	buf2d_convert_text_matrix dd sz_buf2d_convert_text_matrix
1673
	buf2d_draw_text dd sz_buf2d_draw_text
1674
	buf2d_crop_color dd sz_buf2d_crop_color
1675
	buf2d_offset_h dd sz_buf2d_offset_h
1676
	buf2d_flood_fill dd sz_buf2d_flood_fill
1677
	buf2d_set_pixel dd sz_buf2d_set_pixel
1678
	dd 0,0
1679
	sz_init db 'lib_init',0
1680
	sz_buf2d_create db 'buf2d_create',0
1681
	sz_buf2d_create_f_img db 'buf2d_create_f_img',0
1682
	sz_buf2d_clear db 'buf2d_clear',0
1683
	sz_buf2d_draw db 'buf2d_draw',0
1684
	sz_buf2d_delete db 'buf2d_delete',0
1685
	sz_buf2d_line db 'buf2d_line',0
1686
	sz_buf2d_rect_by_size db 'buf2d_rect_by_size',0
1687
	sz_buf2d_filled_rect_by_size db 'buf2d_filled_rect_by_size',0
1688
	sz_buf2d_circle db 'buf2d_circle',0
1689
	sz_buf2d_img_hdiv2 db 'buf2d_img_hdiv2',0
1690
	sz_buf2d_img_wdiv2 db 'buf2d_img_wdiv2',0
1691
	sz_buf2d_conv_24_to_8 db 'buf2d_conv_24_to_8',0
1692
	sz_buf2d_conv_24_to_32 db 'buf2d_conv_24_to_32',0
1693
	sz_buf2d_bit_blt db 'buf2d_bit_blt',0
1694
	sz_buf2d_bit_blt_transp db 'buf2d_bit_blt_transp',0
1695
	sz_buf2d_bit_blt_alpha db 'buf2d_bit_blt_alpha',0
1696
	sz_buf2d_curve_bezier db 'buf2d_curve_bezier',0
1697
	sz_buf2d_convert_text_matrix db 'buf2d_convert_text_matrix',0
1698
	sz_buf2d_draw_text db 'buf2d_draw_text',0
1699
	sz_buf2d_crop_color db 'buf2d_crop_color',0
1700
	sz_buf2d_offset_h db 'buf2d_offset_h',0
1701
	sz_buf2d_flood_fill db 'buf2d_flood_fill',0
1702
	sz_buf2d_set_pixel db 'buf2d_set_pixel',0
1703
 
1704
mouse_dd dd 0x0
1705
sc system_colors
1706
last_time dd 0
1707
 
1708
align 16
1709
procinfo process_information
1710
 
1711
align 4
1712
buf_0: dd 0 ;a?азаa?лi на ?aa?a ?зо?aаж?н?i
1713
	dw 5 ;+4 left
1714
	dw 35 ;+6 top
1715
.w: dd 460 ;+8 w
1716
.h: dd 340 ;+12 h
1717
.color: dd 0xffffd0 ;+16 color
1718
	db 24 ;+20 bit in pixel
1719
 
1720
;этот код не мой, он преобразует число в строку
1721
;input:
1722
; eax = value
1723
; edi = string buffer
1724
;output:
1725
align 4
1726
tl_convert_to_str:
1727
	pushad
1728
		mov dword[edi+1],0
1729
		call .str
1730
	popad
1731
	ret
1732
 
1733
align 4
1734
.str:
1735
	mov ecx,0x0a ;задается система счисления изменяются регистры ebx,eax,ecx,edx входные параметры eax - число
1736
    ;преревод числа в ASCII строку взодные данные ecx=система счисленя edi адрес куда записывать, будем строку, причем конец переменной
1737
	cmp eax,ecx  ;сравнить если в eax меньше чем в ecx то перейти на @@-1 т.е. на pop eax
1738
	jb @f
1739
		xor edx,edx  ;очистить edx
1740
		div ecx      ;разделить - остаток в edx
1741
		push edx     ;положить в стек
1742
		;dec edi             ;смещение необходимое для записи с конца строки
1743
		call .str ;перейти на саму себя т.е. вызвать саму себя и так до того момента пока в eax не станет меньше чем в ecx
1744
		pop eax
1745
	@@: ;cmp al,10 ;проверить не меньше ли значение в al чем 10 (для системы счисленя 10 данная команда - лишная))
1746
	or al,0x30  ;данная команда короче  чем две выше
1747
	stosb	    ;записать элемент из регистра al в ячеку памяти es:edi
1748
	ret	      ;вернуться чень интересный ход т.к. пока в стеке храниться кол-во вызовов то столько раз мы и будем вызываться
1749
 
1750
i_end:
1751
	rb 1024
1752
stacktop:
1753
	sys_path rb 1024
1754
	file_name:
1755
		rb 1024 ;4096
1756
	library_path rb 1024
1757
	plugin_path rb 4096
1758
	openfile_path rb 4096
1759
	filename_area rb 256
1760
mem: