Subversion Repositories Kolibri OS

Rev

Rev 5916 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2462 IgorA 1
;
2
; функци для создания и редактирования проводов
3
;
4
 
5
;--------------------------------------
6
struct Cell
7
	x dd ? ;+0
8
	y dd ? ;+4
9
	liv db ? ;+8
10
	napr db ? ;+9
11
ends
12
 
13
offs_cell_x equ 0
14
offs_cell_y equ 4
15
offs_cell_liv equ 8
16
offs_cell_napr equ 9
17
 
18
;структура для создания поля
19
align 4
20
pole:
21
.index dd 0
22
cell dd 0 ;указатель на память со структурами ячеек
23
.max_cell dd 90000
24
.b_sort dd 0 ;граница для сортированных ячеек
25
 
26
pole_index    equ dword[edi]
27
pole_data     equ dword[edi +4] ;указатель на память со структурами ячеек
28
pole_max_cell equ dword[edi +8]
29
pole_b_sort   equ dword[edi+12] ;граница для сортированных ячеек
2501 IgorA 30
offs_pole_b_sort equ 12
2462 IgorA 31
 
32
macro get_cell_offset reg,ind
33
{
34
	mov reg,ind
35
	imul reg,sizeof.Cell
36
	add reg,dword[cell]
37
}
38
 
39
er_oom db 0 ;на случай исчерпания памяти
40
Cor_x dd 0
41
Cor_y dd 0
42
zoom db 3 ;масштаб поля
43
txt_zoom db 'Масштаб:',0
44
txt_osob db 'Точек:',0
45
txt_info: db 'Размер: '
46
.size: rb 16
47
txt_mull db '*',0
48
txt_space db ' ',0
49
txt_nl db 13,10,0
50
txt_buf rb 32
51
 
52
 
53
align 4
54
proc pole_init uses eax ebx edi, pole:dword
55
	mov edi,dword[pole]
56
 
57
	;*** код с одной областью в памяти ***
58
	mov ebx,4
59
	add ebx,sizeof.Cell
60
	imul ebx,pole_max_cell
61
	stdcall mem.Alloc,ebx
62
	mov pole_index,eax
63
 
64
	mov ebx,pole_max_cell
65
	shl ebx,2
66
	add eax,ebx
67
	mov pole_data,eax
68
 
69
	stdcall pole_clear, edi
70
	stdcall pole_paint, edi ;рисование поля в буфере (не на экране)
71
	ret
72
endp
73
 
74
align 4
75
proc pole_delete uses edi, pole:dword
76
	mov edi,dword[pole]
77
	stdcall mem.Free,pole_index
78
	ret
79
endp
80
 
81
;чистка проводов на схеме
82
align 4
83
proc pole_clear uses eax ecx edi, pole:dword
84
	mov edi,dword[pole]
85
 
86
	xor eax,eax
87
	mov pole_b_sort,eax
88
	mov byte[er_oom],al
89
	cld
90
	mov ecx,pole_max_cell
91
	imul ecx,sizeof.Cell
92
	mov edi,pole_data
93
	repne stosb ;memset(cell,0,sizeof(Cell)*pole_max_cell);
94
 
95
	mov edi,dword[pole]
96
	mov ecx,pole_max_cell
97
	mov edi,pole_index
98
	@@:
99
		stosd ;for(i=0;i
100
		inc eax
101
		loop @b
102
	ret
103
endp
104
 
105
align 4
106
proc pole_cell_creat, pole:dword, x:dword, y:dword, li:dword
107
	pushad
108
	mov edi,dword[pole]
109
	mov esi,pole_index
110
 
111
	; *** если клетка уже была создана
112
	stdcall pole_cell_find, [pole], [x],[y]
113
	cmp eax,0
114
	je @f
115
		get_cell_offset ebx,eax
116
		jmp .change
117
	@@:
118
 
119
	; *** создание новой ячейки
120
	; находим номер свободной ячейки (i) для добавления новой
121
	;mov esi,pole_index
122
	inc dword[esi]
123
	mov ebx,pole_max_cell
124
	cmp dword[esi],ebx
125
	jne @f
126
		dec dword[esi]
127
		;... need call message: "eror out of memory" ...
128
		;... вывод сообщения переполнения надо добавить  ...
129
		mov byte[er_oom],0
130
		jmp .fun_e ;return;
131
	@@:
132
	mov eax,dword[esi] ;eax - номер для последней ячейки
133
	shl eax,2
134
	add eax,pole_index ;eax - указатель на добавляемую ячейку (в конец массива)
135
	get_cell_offset ebx,dword[eax]
136
	mov ecx,dword[x]
137
	mov dword[ebx],ecx ;+0 = .x
138
	mov edx,dword[y]
139
	mov dword[ebx+4],edx ;+4 = .y
140
	.change:
141
		mov ecx,[li]
142
		mov byte[ebx+offs_cell_liv],cl
143
	.fun_e:
144
	popad
145
	ret
146
endp
147
 
148
;удаление ячейки
149
align 4
150
proc pole_cell_delete, pole:dword, x:dword, y:dword
151
	pushad
152
	mov edi,dword[pole]
2501 IgorA 153
	mov ebx,edi
154
	add ebx,offs_pole_b_sort
2462 IgorA 155
	mov esi,pole_index
156
 
157
	mov ecx,[esi]
158
	cmp ecx,1
159
	jl .fun_e
160
 
161
	stdcall pole_cell_find, [pole], [x],[y]
162
	cmp eax,0
163
	je .fun_e ;если клетка не была создана
164
 
165
	dec dword[esi]
166
 
167
	mov edi,esi
168
	add edi,4
169
	mov edx,ecx
170
	cld
171
	repnz scasd ;поиск
172
	sub edi,4
173
 
2501 IgorA 174
	cmp dword[ebx],1 ;[ebx]=pole_b_sort
175
	jl @f
176
	mov eax,edi
177
	sub eax,esi ;esi=pole_index
178
	shr eax,2
179
	dec eax
180
	cmp [ebx],eax ;eax - позиция указателя удаляемой ячейки
181
	jle @f ;было jl @f
182
		dec dword[ebx]
183
	@@:
184
 
2462 IgorA 185
	shl edx,2
186
	add edx,esi ;конечный элемент массива
187
	sub edx,edi
188
	shr edx,2
189
	mov ecx,edx
190
 
191
	bt ecx,31
192
	jc .fun_e
193
		mov esi,edi
194
		add esi,4
195
		mov edx,[edi] ;сохранение текущего указателя
196
		cld
197
		rep movsd
198
		mov [edi],edx ;восстановление текущего указателя (в конце массива)
199
	.fun_e:
200
	popad
201
	ret
202
endp
203
 
2501 IgorA 204
if debug
2462 IgorA 205
align 4
206
proc but_test_pole, pole:dword
207
	pushad
208
	stdcall [buf2d_clear], buf_0, [buf_0.color]
209
 
210
	mov edi,dword[pole]
211
	stdcall pole_paint,edi
212
	mov ebx,5
213
 
214
	mov esi,pole_index
215
	mov ecx,[esi]
2501 IgorA 216
 
217
	mov eax,pole_b_sort
2462 IgorA 218
	mov edi,open_file_lif
2501 IgorA 219
	stdcall convert_int_to_str
2523 IgorA 220
	stdcall [buf2d_draw_text], buf_0, buf_font,edi,5,ebx,[shem_colors] ;рисуем b_sort
2501 IgorA 221
	add ebx,18
2462 IgorA 222
 
223
	mov eax,[esi]
224
	add esi,4
225
	stdcall convert_int_to_str
2523 IgorA 226
	stdcall [buf2d_draw_text], buf_0, buf_font,edi,5,ebx,[shem_colors] ;рисуем число точек
2462 IgorA 227
	add ebx,9
228
 
229
	cmp ecx,1
230
	jl .end_dr
231
	cld
232
	@@:
233
		mov eax,[esi]
234
		add esi,4
235
		stdcall convert_int_to_str
2574 IgorA 236
		stdcall [buf2d_draw_text], buf_0, buf_font,edi,5,ebx,[color_captions] ;рисуем указатели на массивы точек
2462 IgorA 237
		add ebx,9
238
		loop @b
239
	.end_dr:
240
	mov ecx,4
241
	cld
242
	@@:
243
		mov eax,[esi]
244
		add esi,4
245
		stdcall convert_int_to_str
2523 IgorA 246
		stdcall [buf2d_draw_text], buf_0, buf_font,edi,5,ebx,[color_border] ;рисуем 4 строки указателей
2462 IgorA 247
		add ebx,9
248
		loop @b
249
 
250
	stdcall [buf2d_draw], buf_0
251
 
252
	;call redraw_pole
253
	popad
254
	ret
255
endp
256
end if
257
 
258
;output:
259
; eax - index
260
align 4
261
proc pole_cell_find uses edi, pole:dword, x:dword, y:dword
262
	mov edi,dword[pole]
263
 
264
	mov eax,pole_index
265
	cmp dword[eax],0
266
	jne @f
267
		xor eax,eax ;if(!fristC) return 0;
268
		jmp .fun_e
269
	@@:
270
 
271
	xor eax,eax ;fnd=0;
272
	cmp pole_b_sort,0
273
	je @f
274
		stdcall pole_bin_find, pole_index, [x],[y], pole_b_sort ;i=BinFind(pole_index, x,y, pole_b_sort);
275
		cmp eax,0
276
		je @f
277
			shl eax,2
278
			add eax,pole_index
279
			mov eax,dword[eax] ;if(i) fnd=pole_index[i];
280
			jmp .fun_e
281
	@@:
282
 
283
	cmp eax,0
284
	jne @f ;поиск ячейки за бинарным деревом
285
		push ebx ecx edx esi
286
		;ebx -> i
287
		;ecx -> firstC
288
		;edx -> &pole_index[i]
289
		;esi -> cell[pole_index[i]]
290
		mov ecx,pole_index
291
		mov ebx,pole_b_sort
292
		mov edx,ebx
293
		shl edx,2
294
		add edx,ecx
295
		mov ecx,dword[ecx]
296
		.cycle_b: ;for(i=pole_b_sort+1;i<=fristC;i++)
2501 IgorA 297
			inc ebx
298
			cmp ebx,ecx
299
			jg .not_found
2462 IgorA 300
			add edx,4
301
			get_cell_offset esi,dword[edx]
302
			mov eax,dword[x]
303
			cmp dword[esi],eax ;+0 = .x
304
			jne .if_e
305
			mov eax,dword[y]
306
			cmp dword[esi+4],eax ;+4 = .y
307
			jne .if_e
308
				;if(cell[pole_index[i]].x==x && cell[pole_index[i]].y==y){
309
				mov eax,dword[edx] ;fnd=pole_index[i];
310
				jmp .cycle_e ;break;
311
			.if_e:
2501 IgorA 312
			jmp .cycle_b
313
			.not_found:
2462 IgorA 314
		xor eax,eax ;восстанавливаем нулевое значение если не нашли ячейку (в цикле eax портится при проверке координат)
315
		.cycle_e:
316
		pop esi edx ecx ebx
317
	@@:
318
	.fun_e:
319
	ret
320
endp
321
 
322
;output:
323
; eax - index
324
align 4
325
proc pole_bin_find uses ebx ecx edx edi, mas:dword, fx:dword, fy:dword, k:dword
326
	xor eax,eax
327
	mov ebx,1 ;ebx - максимальный порядок для дерева
328
	@@:
329
	cmp dword[k],ebx
330
	jle @f ;while(k>por)
331
		shl ebx,1 ;por<<=1;
332
		jmp @b
333
	@@:
334
	cmp dword[k],ebx
335
	jge @f ;if(k
336
		shr ebx,1 ;por>>=1;
337
	@@:
338
	mov ecx,ebx ;i=por;
339
 
340
	;ecx -> i
341
	;edi -> mas[i]
342
	.cycle_b: ;do{
343
		shr ebx,1 ;por>>=1;
344
 
345
		mov edi,ecx
346
		shl edi,2
347
		add edi,dword[mas]
348
		;if(compare_cells_mb(mas[i],fx,fy)){
349
		stdcall pole_compare_cells_mb_coords, dword[edi],[fx],[fy]
350
		cmp dl,0
351
		je .if_u0_e
352
			@@: ;while(i+por>k)
353
			mov edx,ecx
354
			add edx,ebx
355
			cmp edx,dword[k] ;i+por>k
356
			jle @f
357
				shr ebx,1 ;por>>=1;
358
				jmp @b
359
			@@:
360
			add ecx,ebx ;i+=por;
361
			jmp .if_e
362
		.if_u0_e:
363
		;else if(compare_cells_bm(mas[i],fx,fy))i-=por;
364
		stdcall pole_compare_cells_bm_coords, dword[edi],[fx],[fy]
365
		cmp dl,0
366
		je .if_u1_e
367
			sub ecx,ebx
368
			jmp .if_e
369
		.if_u1_e:
370
		;else { m=i; por=0; }
371
			mov eax,ecx
372
			xor ebx,ebx
373
		.if_e:
374
	cmp ebx,0
375
	jne .cycle_b ;}while(por);
376
 
377
	ret
378
endp
379
 
2501 IgorA 380
;сдвиг всех ячеек (и объектов)
381
align 4
382
proc pole_move_all, pole:dword, m_d_x:dword, m_d_y:dword
383
pushad
384
	mov edi,dword[pole]
385
	mov edx,[m_d_x]
386
	mov esi,[m_d_y]
387
 
388
	mov eax,pole_index
389
	cmp dword[eax],0
390
	je .end_0 ;если нет ячеек (проводов) то выход
391
 
392
	mov ecx,dword[eax]
393
	cld
394
	@@: ;цикл по всем ячейкам
395
		add eax,4
396
		mov ebx,[eax]
397
		imul ebx,sizeof.Cell
398
		add ebx,pole_data
399
 
400
		add dword[ebx+offs_cell_x],edx
401
		add dword[ebx+offs_cell_y],esi
402
		loop @b
403
	.end_0:
404
 
405
	;цикл по логическим элементам и подписям
5916 IgorA 406
	stdcall dword[tl_node_poi_get_info], tree1,0
2501 IgorA 407
	@@:
408
		cmp eax,0
409
		je .end_1
410
		cmp word[eax],el_icon_elems ;получение через eax тип иконки
411
		je .mov_1
412
		cmp word[eax],el_icon_captions
413
		je .mov_1
414
			jmp .end_mov_1
415
		.mov_1:
5916 IgorA 416
			mov ecx,eax
417
			stdcall [tl_node_poi_get_data], tree1,eax
418
			add [eax],edx ;coord x
419
			add [eax+4],esi ;coord y
420
			mov eax,ecx
2501 IgorA 421
		.end_mov_1:
5916 IgorA 422
		stdcall dword[tl_node_poi_get_next_info], tree1,eax ;переходим к следущему узлу
2501 IgorA 423
		jmp @b
424
	.end_1:
425
 
426
popad
427
	ret
428
endp
429
 
2462 IgorA 430
;output:
431
; dl
432
align 4
433
proc pole_compare_cells_bm_coords uses eax ebx ecx, i0:dword, fx:dword, fy:dword
434
	get_cell_offset eax,[i0]
435
	;eax -> cell[i0]
436
	mov ebx,dword[fx]
437
	cmp dword[eax],ebx
438
	jle @f
439
		mov dl,1
440
		jmp .fun_e
441
	@@:
442
	mov ecx,dword[fy]
443
	cmp dword[eax+4],ecx
444
	jle @f
445
	cmp dword[eax],ebx
446
	jne @f
447
		mov dl,1
448
		jmp .fun_e
449
	@@:
450
	xor dl,dl
451
	.fun_e:
452
	ret
453
endp
454
 
455
;output:
456
; dl
457
align 4
458
proc pole_compare_cells_mb_coords uses eax ebx ecx, i0:dword, fx:dword, fy:dword
459
	get_cell_offset eax,[i0]
460
	;eax -> cell[i0]
461
	mov ebx,dword[fx]
462
	cmp dword[eax],ebx
463
	jge @f
464
		mov dl,1
465
		jmp .fun_e
466
	@@:
467
	mov ecx,dword[fy]
468
	cmp dword[eax+4],ecx
469
	jge @f
470
	cmp dword[eax],ebx
471
	jne @f
472
		mov dl,1
473
		jmp .fun_e
474
	@@:
475
	xor dl,dl
476
	.fun_e:
477
	ret
478
endp
479
 
480
;output:
481
; dl
482
align 4
483
proc pole_compare_cells_bm, i0:dword, i1:dword
484
	push eax ebx ecx
485
	get_cell_offset eax,[i0] ;eax -> cell[i0]
486
	get_cell_offset ebx,[i1] ;ebx -> cell[i1]
487
	mov ecx,dword[ebx] ;+0 = .x
488
	cmp dword[eax],ecx
489
	jle @f ;x0>x1
490
		mov dl,1
491
		jmp .fun_e
492
	@@:
493
	jne @f ;x0==x1
494
	mov ecx,dword[ebx+4] ;+4 = .y
495
	cmp dword[eax+4],ecx
496
	jle @f ;y0>y1
497
		mov dl,1
498
		jmp .fun_e
499
	@@:
500
	xor dl,dl
501
	.fun_e:
502
	pop ecx ebx eax
503
	ret
504
endp
505
 
506
;description:
507
; чистка ячеек (проводов), установка на всех проводах 0-го сигнала
508
; нужно вызывать при формировании или перед запуском схемы
509
align 4
510
proc pole_reset_cells uses eax ebx ecx edi, pole:dword
511
	mov edi,dword[pole]
512
	mov eax,pole_index
513
	cmp dword[eax],0
514
	je .fun_e ;если нет ячеек (проводов) то выход
515
 
516
	mov ecx,dword[eax]
517
	cld
518
	@@: ;цикл по всем ячейкам
519
		add eax,4
520
		mov ebx,[eax]
521
		imul ebx,sizeof.Cell
522
		add ebx,pole_data
523
		;and byte[ebx+offs_cell_liv],0xfe ;сброс младшего бита
524
		cmp byte[ebx+offs_cell_liv],2
525
		je .no_clear
526
			mov byte[ebx+offs_cell_liv],0
527
		.no_clear:
528
		loop @b
529
	.fun_e:
530
	ret
531
endp
532
 
533
align 4
534
proc p_paint_elems uses eax esi
5916 IgorA 535
	stdcall dword[tl_node_poi_get_info], tree1,0
2462 IgorA 536
	@@:
5916 IgorA 537
		cmp eax,0
2462 IgorA 538
		je @f
5916 IgorA 539
		mov esi,eax
2462 IgorA 540
		cmp word[esi],el_icon_elems ;получение через esi тип иконки
541
		jne .end_element
5916 IgorA 542
			stdcall [tl_node_poi_get_data], tree1,esi
2462 IgorA 543
			stdcall el_draw, eax
544
		.end_element:
545
		cmp word[esi],el_icon_captions ;получение через esi тип иконки
546
		jne .end_caption
5916 IgorA 547
			stdcall [tl_node_poi_get_data], tree1,esi
2462 IgorA 548
			stdcall capt_draw, eax
549
		.end_caption:
5916 IgorA 550
		stdcall dword[tl_node_poi_get_next_info], tree1,esi
2462 IgorA 551
		jmp @b
552
	@@:
553
	ret
554
endp
555
 
556
;description:
557
; функция рисования элемента на поле
558
align 4
559
proc el_draw, h_elem:dword
560
	pushad
2574 IgorA 561
 
2462 IgorA 562
	mov edi,[h_elem]
563
	mov eax,[edi] ;coord x
564
	mov ebx,[edi+4] ;coord y
565
 
566
	movzx edi,byte[edi+sp_offs_el_type]
567
	imul edi,size_el_opt
568
	add edi,el_opt_beg ;edi - указатель на структуру со свойствами элемента
569
 
570
	movzx ecx,byte[edi+el_offs_box_x]
571
	movzx edx,byte[edi+el_offs_box_y]
572
	dec ecx
573
	dec edx
574
 
575
	push eax ebx
576
		mov esi,[h_elem]
577
		movzx esi,byte[esi+8]
578
		push dword[edi+el_offs_col]
579
		push ebx
580
		push eax
581
		stdcall move_rotate_n90, ecx,edx,esi
582
		stdcall draw_scaled_rect, eax,ebx ;рисовани корпуса элемента
583
	pop ebx eax
584
 
585
	;*** алгоритм рисования ног ***
586
	movzx esi,byte[zoom]
587
	cmp esi,1
588
	jne .end_m1
589
		;*** рисование ног при 1-м масштабе ***
590
		;входные ноги
591
		mov esi,[h_elem]
592
		stdcall el_get_leg_coords,esi,0 ;установка параметров 0-й ноги
593
		add eax,[Cor_x]
594
		add ebx,[Cor_y]
595
		movzx esi,byte[esi+8]
596
		stdcall move_rotate_n90, 1,0,esi
2487 IgorA 597
		mov edx,1
2462 IgorA 598
		@@:
599
			stdcall [buf2d_set_pixel], buf_0, eax,ebx,dword[edi+el_offs_col]
2487 IgorA 600
			mov ecx,[edi+el_offs_legs_inp]
601
			movzx ecx,byte[ecx+edx]
2462 IgorA 602
			cmp ecx,0
603
			je @f
604
			stdcall move_rotate_n90, 0,ecx,esi
605
			inc edx
606
			jmp @b
607
		@@:
608
 
609
		;выходные ноги
610
		mov esi,[h_elem]
611
		stdcall el_get_leg_coords,esi,(1 shl 16) ;установка параметров 0-й ноги
612
		add eax,[Cor_x] ;для работы с buf2d_line
613
		add ebx,[Cor_y] ;для работы с buf2d_line
614
		movzx esi,byte[esi+8]
615
		stdcall move_rotate_n90, -2,0,esi
616
		mov edx,el_offs_legs_out
617
		inc edx
618
		@@:
619
			push dword[edi+el_offs_col]
620
			stdcall move_rotate_n90, 1,0,esi
621
			push ebx
622
			push eax
623
			stdcall move_rotate_n90, -1,0,esi
624
			;stdcall draw_scaled_rect, eax,ebx
625
			stdcall [buf2d_line], buf_0, eax,ebx
626
			movzx ecx,byte[edi+edx]
627
			cmp ecx,0
628
			je @f
629
			stdcall move_rotate_n90, 0,ecx,esi
630
			inc edx
631
			jmp @b
632
		@@:
633
 
634
		jmp .end_mn
635
	.end_m1:
636
		;*** рисование ног при n-м масштабе ***
637
		;входные ноги
638
		xor edx,edx
639
		@@:
640
			stdcall el_get_leg_coords,[h_elem],edx
641
			mov ecx,eax
642
			or ecx,ebx
643
			jz @f
644
			mov ecx,[h_elem]
645
			movzx ecx,byte[ecx+8]
646
			stdcall move_rotate_n90, 1,0,ecx
647
			add eax,[Cor_x]
648
			add ebx,[Cor_y]
649
			imul eax,esi
650
			imul ebx,esi
651
			stdcall [buf2d_filled_rect_by_size], buf_0, eax,ebx,esi,esi, dword[edi+el_offs_col]
652
			inc edx
653
			jmp @b
654
		@@:
655
 
656
		;выходные ноги
657
		mov edx,(1 shl 16)
658
		@@:
659
			stdcall el_get_leg_coords,[h_elem],edx
660
			mov ecx,eax
661
			or ecx,ebx
662
			jz @f
663
			mov ecx,[h_elem]
664
			movzx ecx,byte[ecx+8]
665
 
666
			push dword[edi+el_offs_col]
667
			stdcall move_rotate_n90, -2,0,ecx
668
			push ebx
669
			push eax
670
			stdcall move_rotate_n90, 1,0,ecx
671
			stdcall draw_scaled_rect, eax,ebx
672
 
673
			inc edx
674
			jmp @b
675
		@@:
676
	.end_mn:
677
	popad
678
	ret
679
endp
680
 
2507 IgorA 681
;description:
682
;рисование подписей
2462 IgorA 683
align 4
684
proc capt_draw uses eax ebx edi esi, h_capt:dword
685
	mov edi,[h_capt]
686
	mov eax,[edi] ;coord x
687
	mov ebx,[edi+4] ;coord y
2507 IgorA 688
 
689
	movzx esi,byte[zoom]
690
	cmp esi,3
691
	jl @f
692
		;рисование рамки, вокруг занятой точки
2574 IgorA 693
		stdcall draw_point_border, eax,ebx, [color_captions]
2507 IgorA 694
	@@:
695
 
2462 IgorA 696
	add eax,[Cor_x]
697
	add ebx,[Cor_y]
698
 
699
	cmp esi,1
700
	jle @f
701
		imul eax,esi
702
		imul ebx,esi
703
	@@:
704
 
2507 IgorA 705
	cmp esi,3
706
	jl @f
707
		;сдвиг надписи с учетом рамки
708
		add eax,esi
709
		inc eax
710
	@@:
711
 
2462 IgorA 712
	add edi,capt_offs ;edi - указатель на полную подпись (с координатами)
713
	call str_next_val
714
	call str_next_val
2574 IgorA 715
	stdcall [buf2d_draw_text], buf_0, buf_font,edi,eax,ebx,[color_captions] ;рисуем строку с текстом
2462 IgorA 716
	ret
717
endp
718
 
719
;description:
2507 IgorA 720
; функция для выделения точечных объектов на крупных масштабах
721
; данная функция очень похожа на draw_signal_rect
722
align 4
723
proc draw_point_border uses eax ebx edi, x0:dword,y0:dword, color:dword
724
	movzx edi,byte[zoom]
725
	mov ebx,[y0]
726
	mov eax,[x0]
727
 
728
	add ebx,[Cor_y]
729
	imul ebx,edi
730
	add eax,[Cor_x]
731
	imul eax,edi
732
 
733
	stdcall [buf2d_rect_by_size], buf_0, eax,ebx,edi,edi, dword[color]
734
	ret
735
endp
736
 
737
;description:
2462 IgorA 738
; подфункция для рисования увеличенных прямоугольников на схеме
739
align 4
740
proc draw_scaled_rect uses eax ebx ecx edx edi, x0:dword,y0:dword,x1:dword,y1:dword, color:dword
741
	movzx edi,byte[zoom]
742
	mov edx,[y1]
743
	mov ecx,[x1]
744
	mov ebx,[y0]
745
	mov eax,[x0]
746
 
747
	cmp eax,ecx
748
	jle @f
749
		xchg eax,ecx
750
	@@:
751
	sub ecx,eax
752
	cmp ebx,edx
753
	jle @f
754
		xchg ebx,edx
755
	@@:
756
	sub edx,ebx
757
 
758
	inc ecx
759
	inc edx
760
 
761
	imul edx,edi
762
	imul ecx,edi
763
	add ebx,[Cor_y]
764
	imul ebx,edi
765
	add eax,[Cor_x]
766
	imul eax,edi
767
 
768
	stdcall [buf2d_filled_rect_by_size], buf_0, eax,ebx,ecx,edx, dword[color]
769
	ret
770
endp
771
 
772
align 4
773
proc pole_paint, pole:dword
774
	pushad
775
 
776
	;*** роисование рамки
777
	mov eax,[Cor_x]
778
	mov ebx,[Cor_y]
779
	mov ecx,[shem_w]
780
	mov edx,[shem_h]
781
	movzx esi,byte[zoom]
782
	cmp esi,1
783
	jle @f
784
		imul eax,esi
785
		imul ebx,esi
786
		imul ecx,esi
787
		imul edx,esi
788
	@@:
789
	dec eax
790
	dec ebx
791
	add ecx,2
792
	add edx,2
2523 IgorA 793
	stdcall [buf2d_rect_by_size], buf_0, eax,ebx, ecx,edx, [color_border]
2462 IgorA 794
 
795
	;eax -> firstC
796
	;ebx -> i
797
	;ecx -> cell[pole_index[i]]
798
	;edx -> color
799
 
800
	mov edi,dword[pole]
801
	mov eax,pole_index
802
	cmp dword[eax],0
803
	je .no_draw
804
 
805
	mov eax,dword[eax]
806
	mov ebx,1
807
 
808
;---
809
	@@: ;while(i
810
		cmp ebx,pole_b_sort
811
		jge @f ;переходим на начало нижнего цикла
812
		mov ecx,ebx
813
		shl ecx,2
814
		add ecx,pole_index
815
		get_cell_offset ecx,dword[ecx]
816
		mov edx,dword[ecx] ;+0 = .x
817
		add edx,dword[Cor_x]
818
		cmp edx,0
819
		jge @f ;переходим на начало нижнего цикла
820
			inc ebx ;i++; // для пропуска ячеек за окном слева
821
		jmp @b
822
	@@:
823
 
824
	;eax -> pole_index[firstC]
825
	;ebx -> pole_index[i]
826
	;edi -> coord_x
827
	;esi -> coord_y
828
	shl eax,2
829
	shl ebx,2
830
	add eax,pole_index
831
	add ebx,pole_index
832
 
833
	cmp byte[zoom],2
834
	jge .zoom2
835
	@@: ;for(;i<=fristC;i++){
836
		get_cell_offset ecx,dword[ebx]
837
;...
838
		mov edi,dword[Cor_x]
839
		add edi,dword[ecx] ;+0 = .x
840
		mov esi,dword[Cor_y]
841
		add esi,dword[ecx+4] ;+4 = .y
842
		movzx edx,byte[ecx+offs_cell_liv]
843
		and edx,3 ;ограничение
844
		shl edx,2
845
		add edx,shem_colors
846
		stdcall [buf2d_set_pixel], buf_0, edi, esi, [edx]
847
;...
848
		add ebx,4
849
		cmp ebx,eax
850
		jle @b
851
 
852
	jmp .no_draw
853
	.zoom2:
854
 
855
	@@: ;for(;i<=fristC;i++){
856
		get_cell_offset ecx,dword[ebx]
857
 
858
		movzx edx,byte[zoom] ;edx используется для внесения zoom в 4 байтное число
859
		mov edi,dword[ecx] ;+0 = .x
860
		add edi,dword[Cor_x]
861
		imul edi,edx
862
		mov esi,dword[ecx+4] ;+4 = .y
863
		add esi,dword[Cor_y]
864
		imul esi,edx
865
 
866
		movzx edx,byte[ecx+offs_cell_liv]
867
		and edx,3 ;ограничение
868
		shl edx,2
869
		add edx,shem_colors
870
 
871
		movzx ecx,byte[zoom]
872
		;;;dec ecx
873
		stdcall [buf2d_filled_rect_by_size], buf_0, edi, esi, ecx, ecx, [edx]
874
		add ebx,4
875
		cmp ebx,eax
876
		jle @b
877
 
878
	.no_draw:
879
	popad
880
	call p_paint_elems
881
	ret
882
endp
883
 
884
;Сортировка ячеек поля, нужна для более быстрого поиска
885
align 4
886
proc pole_sort uses eax edi, pole:dword
887
	mov edi,dword[pole]
888
	mov eax,pole_index
889
	mov eax,dword[eax] ;firstC -> eax
890
	stdcall pole_fl_sort, pole_index,eax ;сортируем все ячейки
891
	mov pole_b_sort,eax ;ставим число отсортированных ячеек равное числу всех существующих ячеек
892
	ret
893
endp
894
 
895
;Сортировка вектора a[1..n] методом Флойда
896
;Элемент a[0] в сортировке не участвует
897
align 4
898
proc pole_fl_sort uses eax ecx edx edi esi, a:dword, n:dword
899
	mov ecx,dword[a]
900
	;Формировать исходное частично упорядоченное дерево
901
	mov eax,dword[n]
902
	shr eax,1
903
	@@: ;for(i=n>>1; i>=2; i--)
904
		stdcall pole_fl_surface, ecx,eax,[n] ;(a,i,n)
905
		dec eax
906
		cmp eax,2
907
		jge @b
908
	;Выполнить процедуру всплытия Флойда для каждого поддерева
909
	mov eax,dword[n]
910
	@@: ;for(i=n; i>=2; i--){
911
		stdcall pole_fl_surface, ecx,1,eax ;(a,1,i)
912
		;Поместить найденный максимальный элемент в конец списка
913
		mov edi,eax
914
		shl edi,2
915
		add edi,ecx ;edi -> &a[i]
916
		mov esi,dword[edi] ;w=a[i];
917
		mov edx,dword[ecx+4]
918
		mov dword[edi],edx ;a[i]=a[1];
919
		mov dword[ecx+4],esi ;a[1]=w;
920
 
921
		dec eax
922
		cmp eax,2
923
		jge @b
924
	ret
925
endp
926
 
927
;Процедура всплытия Флойда по дереву a[1..k]
928
align 4
929
proc pole_fl_surface, a:dword, i:dword, k:dword
930
locals
931
	copy dd ?
932
endl
933
	pushad
934
	;edx -> ...
935
	;edi -> m
936
	;esi -> j
937
	mov eax,dword[a]
938
	mov ebx,dword[i]
939
	mov ecx,dword[k]
940
 
941
	mov edx,ebx
942
	shl edx,2
943
	add edx,eax
944
	mov edx,dword[edx]
945
	mov dword[copy],edx ;copy=a[i];
946
	mov edi,ebx
947
	shl edi,1 ;m=i<<1;
948
	.cycle_b: ;while (m<=k) {
949
		cmp edi,ecx
950
		jg .cycle_e
951
		jne @f ;if (m==k) j=m;
952
			mov esi,edi
953
			jmp .else_e
954
		@@: ;else if (pole_compare_cells_bm(a[m],a[m+1])) j=m;
955
		mov edx,edi
956
		shl edx,2
957
		add edx,eax
958
		stdcall pole_compare_cells_bm, dword[edx],dword[edx+4]
959
		cmp dl,0
960
		je @f
961
			mov esi,edi
962
			jmp .else_e
963
		@@: ;else j=m+1;
964
			mov esi,edi
965
			inc esi
966
		.else_e:
967
 
968
		;if (pole_compare_cells_bm(a[j],copy)) {
969
		mov edx,esi
970
		shl edx,2
971
		add edx,eax
972
		stdcall pole_compare_cells_bm, dword[edx],dword[copy]
973
		cmp dl,0
974
		je .cycle_e ;} else break; //выход из цикла
975
 
976
		mov edx,esi
977
		shl edx,2
978
		add edx,eax
979
		push dword[edx] ;push a[j];
980
		mov edx,ebx
981
		shl edx,2
982
		add edx,eax
983
		pop dword[edx] ;a[i]=a[j];
984
		mov ebx,esi ;i=j;
985
		mov edi,ebx
986
		shl edi,1 ;m=i<<1;
987
 
988
		jmp .cycle_b
989
	.cycle_e:
990
 
991
	;значения многих регистров уже не важны т. к. конец функции
992
	shl ebx,2
993
	add eax,ebx
994
	mov edx,dword[copy]
995
	mov dword[eax],edx ;a[i]=copy;
996
 
997
	popad
998
	ret
999
endp
1000
;--------------------------------------
1001
 
1002
align 4
6213 IgorA 1003
proc pole_draw_pok, pole:dword
1004
pushad
2462 IgorA 1005
	;mov edi,dword[pole]
1006
 
1007
	mov ecx,[sc.work_text]
1008
	or  ecx,0x80000000 ;or (1 shl 30)
1009
	;mov edi,[sc.work]
6213 IgorA 1010
	mcall SF_DRAW_TEXT,(400 shl 16)+5,,txt_zoom
2462 IgorA 1011
 
1012
	add bx,9
1013
	mov edx,txt_osob
1014
	int 0x40
1015
 
1016
	add bx,9
1017
	mov edx,txt_info
1018
	int 0x40
1019
 
1020
	movzx ecx,byte[zoom]
2501 IgorA 1021
	mov edx,(400+6*9)*65536+5
2462 IgorA 1022
	mov esi,[sc.work_button_text]
1023
	or  esi,(1 shl 30)
1024
	mov edi,[sc.work_button]
6213 IgorA 1025
	mcall SF_DRAW_NUMBER,(2 shl 16) ;масштаб
2462 IgorA 1026
 
1027
	mov edi,dword[pole]
1028
	mov ecx,pole_index
1029
	mov ecx,[ecx]
1030
	mov edi,[sc.work_button]
1031
	add edx,(6*0)*65536+9
6213 IgorA 1032
	mcall ,(5 shl 16) ;число точек
1033
popad
2462 IgorA 1034
	ret
1035
endp
1036
 
1037
align 4
1038
but_zoom_p:
1039
	cmp byte[zoom],16
1040
	jge @f
1041
		pushad
1042
		;вычисление сдвигов для поля, которые обеспечат центровку поля при увеличении масштаба
1043
		movzx ecx,byte[zoom]
1044
		xor edx,edx
1045
		mov eax,dword[buf_0.w]
1046
		shr eax,1 ;в eax половина ширины поля
1047
		mov ebx,eax ;делаем резервную копию eax
1048
		div ecx ;делим eax на текущий масштаб
1049
		xchg eax,ebx
1050
		xor edx,edx
1051
		inc ecx
1052
		div ecx ;делим eax на новый масштаб
1053
		sub ebx,eax ;вычисляется сдвиг поля который обеспечит центровку поля
1054
		sub dword[Cor_x],ebx ;сдвигаем поле зрения по оси x
1055
		xor ecx,ecx
1056
		mov cl,byte[zoom]
1057
		xor edx,edx
1058
		mov eax,dword[buf_0.h]
1059
		shr eax,1
1060
		mov ebx,eax
1061
		div ecx
1062
		xchg eax,ebx
1063
		xor edx,edx
1064
		inc ecx
1065
		div ecx
1066
		sub ebx,eax
1067
		sub dword[Cor_y],ebx ;сдвигаем поле зрения по оси y
1068
 
1069
		inc byte[zoom]
1070
		stdcall pole_draw_pok, pole
1071
		popad
1072
 
1073
		.buf_clear:
1074
			call redraw_pole
1075
	@@:
1076
	ret
1077
 
1078
align 4
1079
but_zoom_m:
1080
	cmp byte[zoom],1
1081
	jle @f
1082
		pushad
1083
		;вычисление сдвигов для поля, которые обеспечат центровку поля при уменьшении масштаба
1084
		movzx ecx,byte[zoom]
1085
		xor edx,edx
1086
		mov eax,dword[buf_0.w]
1087
		shr eax,1 ;в eax половина ширины поля
1088
		mov ebx,eax ;делаем резервную копию eax
1089
		div ecx ;делим eax на текущий масштаб
1090
		xchg eax,ebx
1091
		xor edx,edx
1092
		dec ecx
1093
		div ecx ;делим eax на новый масштаб
1094
		sub ebx,eax ;вычисляется сдвиг поля который обеспечит центровку поля
1095
		sub dword[Cor_x],ebx ;сдвигаем поле зрения по оси x
1096
		xor ecx,ecx
1097
		mov cl,byte[zoom]
1098
		xor edx,edx
1099
		mov eax,dword[buf_0.h]
1100
		shr eax,1
1101
		mov ebx,eax
1102
		div ecx
1103
		xchg eax,ebx
1104
		xor edx,edx
1105
		dec ecx
1106
		div ecx
1107
		sub ebx,eax
1108
		sub dword[Cor_y],ebx ;сдвигаем поле зрения по оси y
1109
 
1110
		dec byte[zoom]
1111
		stdcall pole_draw_pok, pole
1112
		popad
1113
 
1114
		.buf_clear:
1115
			call redraw_pole
1116
	@@:
1117
	ret
1118
 
1119
;центровка схемы по центру экрана
1120
align 4
1121
proc but_center uses eax ebx ecx edx
1122
	movzx ecx,byte[zoom]
1123
	cmp ecx,1
1124
	jle .end_m_1
1125
		mov eax,[buf_0.w]
1126
		mov ebx,[shem_w]
1127
		imul ebx,ecx
1128
 
1129
		sub eax,ebx
1130
		xor edx,edx
1131
		shl ecx,1
1132
		cmp eax,0
1133
		jge @f
1134
			neg eax
1135
			inc eax
1136
			div ecx
1137
			neg eax
1138
			inc eax
1139
			jmp .set_x
1140
		@@:
1141
			div ecx
1142
		.set_x:
1143
		mov [Cor_x],eax
1144
		mov eax,[buf_0.h]
1145
		mov ebx,[shem_h]
1146
		shr ecx,1
1147
		imul ebx,ecx
1148
		sub eax,ebx
1149
		xor edx,edx
1150
		shl ecx,1
1151
		cmp eax,0
1152
		jge @f
1153
			neg eax
1154
			inc eax
1155
			div ecx
1156
			neg eax
1157
			inc eax
1158
			jmp .set_y
1159
		@@:
1160
			div ecx
1161
		.set_y:
1162
		mov [Cor_y],eax
1163
		jmp .end_m_n
1164
	.end_m_1:
1165
		mov eax,[buf_0.w]
1166
		sub eax,[shem_w]
1167
		shr eax,1
1168
		bt eax,30
1169
		jnc @f
1170
			bts eax,31
1171
		@@:
1172
		mov [Cor_x],eax
1173
		mov eax,[buf_0.h]
1174
		sub eax,[shem_h]
1175
		shr eax,1
1176
		bt eax,30
1177
		jnc @f
1178
			bts eax,31
1179
		@@:
1180
		mov [Cor_y],eax
1181
	.end_m_n:
1182
	call redraw_pole
1183
	ret
1184
endp
1185
 
1186
align 4
1187
but_pole_up:
1188
	push eax ecx edx
1189
	mov eax,dword[buf_0.h]
1190
	shr eax,2
1191
	movzx ecx,byte[zoom]
1192
	cmp cx,2
1193
	jl @f ;деление на величину zoom
1194
		xor edx,edx
1195
		div ecx
1196
	@@:
1197
	add dword[Cor_y],eax
1198
	pop edx ecx eax
1199
	call redraw_pole
1200
	ret
1201
 
1202
align 4
1203
but_pole_dn:
1204
	push eax ecx edx
1205
	mov eax,dword[buf_0.h]
1206
	shr eax,2
1207
	xor ecx,ecx
1208
	mov cl,byte[zoom]
1209
	cmp cx,2
1210
	jl @f ;деление на величину zoom
1211
		xor edx,edx
1212
		div ecx
1213
	@@:
1214
	sub dword[Cor_y],eax
1215
	pop edx ecx eax
1216
	call redraw_pole
1217
	ret
1218
 
1219
align 4
1220
but_pole_left:
1221
	push eax ecx edx
1222
	mov eax,dword[buf_0.w]
1223
	shr eax,2
1224
	xor ecx,ecx
1225
	mov cl,byte[zoom]
1226
	cmp cx,2
1227
	jl @f ;деление на величину zoom
1228
		xor edx,edx
1229
		div ecx
1230
	@@:
1231
	add dword[Cor_x],eax
1232
	pop edx ecx eax
1233
	call redraw_pole
1234
	ret
1235
 
1236
align 4
1237
but_pole_right:
1238
	push eax ecx edx
1239
	mov eax,dword[buf_0.w]
1240
	shr eax,2
1241
	xor ecx,ecx
1242
	mov cl,byte[zoom]
1243
	cmp cx,2
1244
	jl @f ;деление на величину zoom
1245
		xor edx,edx
1246
		div ecx
1247
	@@:
1248
	sub dword[Cor_x],eax
1249
	pop edx ecx eax
1250
	call redraw_pole
1251
	ret
1252
 
1253
;output:
1254
; edx - count created points
1255
align 4
1256
proc shem_create_line uses eax ebx ecx edi, x:dword, y:dword, opt:dword
1257
	mov edi,pole
1258
	xor edx,edx
1259
 
1260
	mov ebx,[x]
1261
	mov ecx,[y]
1262
	bt dword[opt],0
1263
	jnc @f
1264
	.line_lr:
1265
		inc ebx
1266
		cmp ebx,[shem_w]
1267
		jge @f
1268
		stdcall pole_cell_find, pole,ebx,ecx
1269
		cmp eax,0
1270
		je .u0
1271
			imul eax,sizeof.Cell
1272
			add eax,pole_data
1273
			cmp byte[eax+offs_cell_liv],1
1274
			jne @f
1275
		.u0:
1276
		stdcall pole_cell_creat, pole,ebx,ecx,1
1277
		inc edx
1278
		jmp .line_lr
1279
	@@:
1280
 
1281
	mov ebx,[x]
1282
	;mov ecx,[y]
1283
	bt dword[opt],2
1284
	jnc @f
1285
	.line_rl:
1286
		dec ebx
1287
		cmp ebx,0
1288
		jl @f
1289
		stdcall pole_cell_find, pole,ebx,ecx
1290
		cmp eax,0
1291
		je .u1
1292
			imul eax,sizeof.Cell
1293
			add eax,pole_data
1294
			cmp byte[eax+offs_cell_liv],1
1295
			jne @f
1296
		.u1:
1297
		stdcall pole_cell_creat, pole,ebx,ecx,1
1298
		inc edx
1299
		jmp .line_rl
1300
	@@:
1301
 
1302
	mov ebx,[x]
1303
	mov ecx,[y]
1304
	bt dword[opt],3
1305
	jnc @f
1306
	.line_du:
1307
		dec ecx
1308
		cmp ecx,0
1309
		jl @f
1310
		stdcall pole_cell_find, pole,ebx,ecx
1311
		cmp eax,0
1312
		je .u2
1313
			imul eax,sizeof.Cell
1314
			add eax,pole_data
1315
			cmp byte[eax+offs_cell_liv],1
1316
			jne @f
1317
		.u2:
1318
		stdcall pole_cell_creat, pole,ebx,ecx,1
1319
		inc edx
1320
		jmp .line_du
1321
	@@:
1322
 
1323
	;mov ebx,[x]
1324
	mov ecx,[y]
1325
	bt dword[opt],1
1326
	jnc @f
1327
	.line_ud:
1328
		inc ecx
1329
		cmp ecx,[shem_h]
1330
		jge @f
1331
		stdcall pole_cell_find, pole,ebx,ecx
1332
		cmp eax,0
1333
		je .u3
1334
			imul eax,sizeof.Cell
1335
			add eax,pole_data
1336
			cmp byte[eax+offs_cell_liv],1
1337
			jne @f
1338
		.u3:
1339
		stdcall pole_cell_creat, pole,ebx,ecx,1
1340
		inc edx
1341
		jmp .line_ud
1342
	@@:
1343
 
1344
	ret
1345
endp
1346
 
1347
align 4
1348
redraw_pole:
1349
	stdcall [buf2d_clear], buf_0, [buf_0.color]
1350
	stdcall pole_paint, pole
1351
	stdcall [buf2d_draw], buf_0
1352
	ret