Subversion Repositories Kolibri OS

Rev

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