Subversion Repositories Kolibri OS

Rev

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