Subversion Repositories Kolibri OS

Rev

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