Subversion Repositories Kolibri OS

Rev

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