File: regwatches.tcl

package info (click to toggle)
mcu8051ide 1.4.9-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 18,820 kB
  • sloc: tcl: 94,956; xml: 2,122; sh: 2,114; asm: 246; ansic: 96; makefile: 30; awk: 18
file content (2148 lines) | stat: -rw-r--r-- 62,967 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
#!/usr/bin/tclsh
# Part of MCU 8051 IDE ( http://https://sourceforge.net/projects/mcu8051ide/ )

############################################################################
#    Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera     #
#    martin.osmera@gmail.com                                               #
#                                                                          #
#    Copyright (C) 2014 by Moravia Microsystems, s.r.o.                    #
#    martin.osmera@gmail.com                                #
#                                                                          #
#    This program is free software; you can redistribute it and#or modify  #
#    it under the terms of the GNU General Public License as published by  #
#    the Free Software Foundation; either version 2 of the License, or     #
#    (at your option) any later version.                                   #
#                                                                          #
#    This program is distributed in the hope that it will be useful,       #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#    GNU General Public License for more details.                          #
#                                                                          #
#    You should have received a copy of the GNU General Public License     #
#    along with this program; if not, write to the                         #
#    Free Software Foundation, Inc.,                                       #
#    59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             #
############################################################################

# >>> File inclusion guard
if { ! [ info exists _REGWATCHES_TCL ] } {
set _REGWATCHES_TCL _
# <<< File inclusion guard

# --------------------------------------------------------------------------
# DESCRIPTION
# Implements register watches (part of Right Panel)
# --------------------------------------------------------------------------

class RegWatches {

	## COMMON
	public common watches_set_shortcuts	{}		;# Currently set shortcuts for register watches
	public common watches_shortcuts_cat	{watches}	;# Key shortcut categories related to register watches
	# Counter of embedded entry widgets in register watches
	public common watch_entry_count	0
	# Conter of instances
	public common regw_count		0
	## Highlighting tags for register watches
	 # {
	 #	{tag_name foreground_color ?bold_or_italic?}
	 #	...
	 # }
	public common watch_text_tags {
		{tag_Baddr	#DD0000	1}
		{tag_Xaddr	#AA00FF	1}
		{tag_Eaddr	#00AAFF	1}
		{tag_addr	#0000DD	1}
		{tag_name	#8888DD {}}
	}
	public common regfont [font create -family $::DEFAULT_FIXED_FONT -size [expr {int(-14 * $::font_size_factor)}]]
	# Popup menu for register watches
	public common WATCHMENU {
		{command	{Move top}	{$watches:top}		0	"rightPanel_watch_move_top"
			{top}		"Move this register watch to the top of list"}
		{command	{Move up}	{$watches:up}		0	"rightPanel_watch_move_up"
			{1uparrow}	"Move this register watch up"}
		{command	{Move down}	{$watches:down}		1	"rightPanel_watch_move_down"
			{1downarrow}	"Move this register watch down"}
		{command	{Move bottom}	{$watches:bottom}	2	"rightPanel_watch_move_bottom"
			{bottom}	"Move this register watch to the bottom of list"}
		{separator}
		{command	{Remove}	{$watches:remove}	2	"rightPanel_watch_remove"
			{button_cancel}	"Remove this register watch from the list"}
		{separator}
		{command	{Remove all}	{$watches:remove_all}	0	"rightPanel_watch_clear"
			{editdelete}	"Clear the list of register watches"}
		{separator}
		{command	{Save}		{}	0	"rightPanel_watch_save {} 1"	{filesave}
			"Save this list to a file"}
		{command	{Configure}	{}	0	"rightPanel_configure 0"	{configure}
			"Configure this panel"}
	}
	# Configuration menu
	public common CONFMENU {
		{cascade	"Sort by"		0	""	.sort		false 1 {
			{command	"Name"		{}	0	"rightPanel_watch_sort_by N"	{}
				""}
			{command	"Address"	{}	0	"rightPanel_watch_sort_by A"	{}
				""}
			{command	"Type"		{}	0	"rightPanel_watch_sort_by T"	{}
				""}
			{separator}
			{radiobutton	"Incremental"			{}	::RegWatches::sorting_order	1
				{}	0	""}
			{radiobutton	"Decremental"			{}	::RegWatches::sorting_order	0
				{}	0	""}
		}}
		{command	"Remove all"		{}	0	"rightPanel_watch_clear"	{editdelete}
			""}
		{separator}
		{checkbutton	"Autoload from code listing"	{}	{::RegWatches::menu_autoload}	1 0 0
			{rightPanel_watch_toggle_autoload_flag}}
		{checkbutton	"Clear on auto-load"		{}	{::RegWatches::menu_autoclear}	1 0 0
			{rightPanel_watch_toggle_autoclear_flag}}
	}

	## PRIVATE
	private variable enabled	0	;# Bool: enable procedures which are needless while loading project
	private variable obj_idx		;# Number of this object
	private variable parent			;# Widget: parent widget
	private variable regw_gui_initialized 0	;# Bool: GUI initialized

	private variable conf_button		;# Widget: Configuration button
	private variable conf_menu	{}	;# Configuration menu
	private variable watch_menu		;# ID of popup menu for "Register watches"
	private variable watch_text		;# ID of text widget representing list of register watches
	private variable watch_remove_button	;# ID of button "Remove watch"	- Register watches
	private variable watch_new_button	;# ID of button "New watch"	- Register watches
	private variable watch_add_button	;# ID of button "Add watch"	- Register watches
	private variable watch_addr_entry	;# ID of entry "Address"	- Register watches
	private variable watch_search_entry	;# ID of entry "Search"		- Register watches
	private variable watch_search_clear	;# ID of button "Clear search entry" - Register watches

	# Bool: Autoload from LST file
	private variable autoload_flag		[lindex $::CONFIG(REGWATCHES_CONFIG) 0]
	private variable autoclear_flag		[lindex $::CONFIG(REGWATCHES_CONFIG) 2]
	private variable watches_modified	0	;# Bool: Register watches definition modified
	private variable search_val_in_progress	0	;# Bool: Search entry validation in porgress
	private variable watch_file_name	{}	;# Name of file currently loaded in register watches
	private variable watch_curLine		0	;# Current line in list of register watches
	private variable watch_AN_valid_ena	1	;# Bool: Enable validation of address entry in register watches
	private variable validator_engaged	0	;# Bool: Address entry validation in progress
	private variable watches_enabled	0	;# Bool: Entry widgets in register watches enabled

	private variable watch_addrs {}		;# List - {hex_addr hex_addr ...}
	## Array of Lists - info about particular watch
	 #	format: $watch_data($hex_addr) -> {regName textVariable}
	 #	note: embedded entry path == $watch_text.$textVariable
	private variable watch_data


	## Object constructor
	constructor {} {
		incr regw_count
		set obj_idx $regw_count
	}

	## Object destructor
	destructor {
		if {$regw_gui_initialized} {
			# Remove status bar tips for popup menus
			menu_Sbar_remove $watch_menu

			# Unallocate GUI related variables
			unset RightPanel::watch_addr$obj_idx
			unset RightPanel::watch_name$obj_idx
		}
	}

	## Prepare object for creating its GUI
	 # @parm Widget _parent		- GUI parent widget
	 # @parm String watches_file	- Definition file for register watches
	 # @return void
	public method PrepareRegWatches {_parent filename} {
		set parent $_parent
		set watch_file_name $filename
		set regw_gui_initialized 0
	}

	## Create GUI of register watches
	 # @return void
	public method CreateRegWatchesGUI {} {
		if {$regw_gui_initialized} {return}
		set regw_gui_initialized 1

		# Top frame
		set icon_bar	[frame $parent.frm_rightPanel_watch_iconBar]
		 # Bottom frame
		set text_frame	[frame $parent.frm_rightPanel_watch_txt]
		 # Toolbar
		set tool_bar	[frame $parent.frm_rightPanel_watch_toolBar]

		# Button "Configure"
		set button [ttk::button $icon_bar.conf_but		\
			-image ::ICONS::16::configure			\
			-command "$this rightPanel_watch_cfg_menu"	\
			-style Flat.TButton				\
		]
		set conf_button $button
		pack $button -side left -padx 3
		# Separator
		pack [ttk::separator $icon_bar.sep_rightPanel_watch_ib_sepm0	\
			-orient vertical					\
		] -side left -fill y -padx 3
		# Button "Save"
		set button [ttk::button $icon_bar.but_rightPanel_watch_save	\
			-image ::ICONS::16::filesave				\
			-command "$this rightPanel_watch_save {} 1"		\
			-style Flat.TButton					\
		]
		pack $button -side left -padx 3
		DynamicHelp::add $button -text [mc "Save"]
		setStatusTip -widget $button	\
			-text [mc "Save"]
		# Button "Save as"
		set button [ttk::button $icon_bar.but_rightPanel_watch_saveas	\
			-image ::ICONS::16::filesaveas				\
			-command "$this rightPanel_watch_saveas"		\
			-style Flat.TButton					\
		]
		pack $button -side left -padx 3
		DynamicHelp::add $button -text [mc "Save under a different file name"]
		setStatusTip -widget $button	\
			-text [mc "Save under a different file name"]
		# Separator
		pack [ttk::separator $icon_bar.sep_rightPanel_watch_ib_sep0	\
			-orient vertical					\
		] -side left -fill y -padx 3
		# Button "Open"
		set button [ttk::button $icon_bar.but_rightPanel_watch_open	\
			-image ::ICONS::16::fileopen				\
			-command "$this rightPanel_watch_open"			\
			-style Flat.TButton					\
		]
		pack $button -side left -padx 3
		DynamicHelp::add $button -text [mc "Open *.wtc file"]
		setStatusTip -widget $button	\
			-text [mc "Open *.wtc file"]
		# Button "Import"
		set button [ttk::button $icon_bar.but_rightPanel_watch_imp	\
			-image ::ICONS::16::fileimport				\
			-style Flat.TButton					\
			-command "$this rightPanel_watch_import"		\
		]
		pack $button -side left -padx 3
		DynamicHelp::add $button -text [mc "Import list of registers from code listing or WTC file"]
		setStatusTip -widget $button	\
			-text [mc "Import list of registers from *.lst or *.wtc file"]
		# Entry "Search"
		set watch_search_entry [ttk::entry $icon_bar.search_entry		\
			-validate key							\
			-width 0							\
			-validatecommand "$this rightPanel_watch_search_validate %P"	\
		]
		DynamicHelp::add $watch_search_entry	\
			-text [mc "Enter your search string here"]
		pack $watch_search_entry -side left -fill x -expand 1
		setStatusTip -widget $watch_search_entry	\
			-text [mc "Search for a name"]
		# Button "Clear search string"
		set watch_search_clear [ttk::button $icon_bar.clear_search	\
			-image ::ICONS::16::clear_left				\
			-command "$watch_search_entry delete 0 end"		\
			-state disabled						\
			-style Flat.TButton					\
		]
		DynamicHelp::add $icon_bar.clear_search -text [mc "Clear search string"]
		pack $watch_search_clear -side right -after $watch_search_entry
		setStatusTip -widget $icon_bar.clear_search	\
			-text [mc "Clear search string"]

		# Entry "Address"
		set entry [ttk::entry $tool_bar.ent_rightPanel_watch_addr		\
			-textvariable RightPanel::watch_addr${regw_count}		\
			-validatecommand "$this rightPanel_watch_addr_validate %P"	\
			-validate key 							\
			-width 5							\
		]
		DynamicHelp::add $entry		\
			-text [mc "Register address:\n  1 or 2 digits\tinternal RAM (not SFR)\n  3 digits\t\texpanded RAM\n  4 digits\t\texternal RAM\n  dot and 2 digits\tBit"]
		setStatusTip -widget $entry	\
			-text [mc "Register address or bit address"]
		grid $entry -sticky w -row 2 -column 1
		bind $entry <Return> "$this rightPanel_watch_add"
		bind $entry <KP_Enter> "$this rightPanel_watch_add"

		# Entry "Name"
		set entry [ttk::entry $tool_bar.ent_rightPanel_watch_name		\
			-textvariable RightPanel::watch_name${regw_count}		\
			-validatecommand "$this rightPanel_watch_name_validate %P"	\
			-validate key							\
			-width 20							\
		]
		setStatusTip -widget $entry	\
			-text [mc "Name of the watch. Any string."]
		grid $entry -sticky w -row 2 -column 2 -padx 3
		bind $entry <Return> "$this rightPanel_watch_add"
		bind $entry <KP_Enter> "$this rightPanel_watch_add"
		# Button "Add"
		set watch_add_button [ttk::button $tool_bar.but_rightPanel_watch_add	\
			-image ::ICONS::16::add						\
			-command "$this rightPanel_watch_add"				\
			-style Flat.TButton						\
		]
		DynamicHelp::add $watch_add_button -text [mc "Add this entry to register watches"]
		setStatusTip -widget $watch_add_button	\
			-text [mc "Add this entry to register watches"]
		grid $watch_add_button -sticky w -row 2 -column 3
		# Button "New"
		set watch_new_button [ttk::button $tool_bar.but_rightPanel_watch_new	\
			-image ::ICONS::16::filenew					\
			-command "$this rightPanel_watch_new"				\
			-style Flat.TButton						\
		]
		DynamicHelp::add $watch_new_button -text [mc "New register watches entry"]
		setStatusTip -widget $watch_new_button	\
			-text [mc "Create new register watch"]
		grid $watch_new_button -sticky w -row 2 -column 4
		# Button "Remove"
		set watch_remove_button [ttk::button $tool_bar.but_rightPanel_watch_remove	\
			-image ::ICONS::16::button_cancel					\
			-command "$this rightPanel_watch_remove"				\
			-style Flat.TButton							\
		]
		DynamicHelp::add $watch_remove_button -text [mc "Remove this entry"]
		setStatusTip -widget $watch_remove_button	\
			-text [mc "Remove this entry"]
		grid $watch_remove_button -sticky w -row 2 -column 5
		# Label "Addr"
		set watch_addr_entry [label $tool_bar.lbl_rightPanel_watch_addr	\
			-text [mc "Addr"]					\
			-font ${Simulator_GUI::smallfont}			\
			-fg ${Simulator_GUI::small_color}			\
		]
		grid $watch_addr_entry -row 1 -column 1
		# Label "Register name"
		grid [label $tool_bar.lbl_rightPanel_watch_name		\
			-text [mc "Register name"]			\
			-font ${Simulator_GUI::smallfont}		\
			-fg ${Simulator_GUI::small_color}		\
		] -row 1 -column 2

		# Create text widget representing list of register watches
		set watch_text [text $text_frame.txt_rightPanel_watch		\
			-yscrollcommand "$text_frame.src_rightPanel_watch set"	\
			-bg {#FFFFFF} -font $regfont				\
			-cursor left_ptr					\
			-state disabled -exportselection 0			\
		]
		# Create text tags
		$this right_panel_create_highlighting_tags $watch_text $watch_text_tags -1
		$watch_text tag configure tag_curLine -background ${::RightPanel::selection_color_dark}

		# Create scrollbar
		pack [ttk::scrollbar $text_frame.src_rightPanel_watch	\
			-orient vertical				\
			-command "$watch_text yview"			\
		] -side right -fill y
		pack $watch_text -side left -fill both -expand 1
		# Create event bindings
		bind $watch_text <ButtonRelease-3>	"$this rightPanel_watch_popupmenu %X %Y %x %y; break"
		bind $watch_text <Button-1>		"$this rightPanel_watch_click %x %y; break"
		bind $watch_text <<Selection>>		"false_selection $watch_text; break"
		bind $watch_text <Key-Menu>		{break}

		# Pack frames
		pack $tool_bar -side bottom -anchor w
		pack $icon_bar -side top -fill x
		pack $text_frame -side top -fill both -expand 1
		rightPanel_watch_switch_line 1

		# Create popup menu
		set watch_menu $parent.menu_rightPanel_watch
		regwatches_makePopupMenu

		# Refresh highlighting tags
		rightPanel_refresh_regwatches_highlighting

		# Open definition file
		if {$watch_file_name != {}} {
			rightPanel_watch_openfile $watch_file_name . 0
		}
	}

	## Sort register watches
	 # @parm Char sorting_key
	 #	N - Sort by name
	 #	A - Sort by address
	 #	T - Sort by type
	 # @return void
	public method rightPanel_watch_sort_by {sorting_key} {
		# Pack all watches into one sigle list
		set list_to_sort [list]
		set type {}
		foreach addr [array names watch_data] {

			switch -- [string length $addr] {
				4 {
					set type {X}
				}
				3 {
					if {[string index $addr 0] == {.}} {
						set type {B}
					} else {
						set type {E}
					}
				}
				default {
					set type {D}
				}
			}

			lappend list_to_sort [list $addr [lindex $watch_data($addr) 0] $type]
		}

		# Incremental sorting order
		if {$::RegWatches::sorting_order} {
			set order {-increasing}
		# Decremental sorting order
		} else {
			set order {-decreasing}
		}

		switch -- $sorting_key {
			N {	;# Name
				set index 1
			}
			A {	;# Address
				set index 0
			}
			T {	;# Type
				set index 2
			}
		}

		# Sort the list
		set list_to_sort [lsort -dictionary $order -index $index $list_to_sort]

		# Refill the panel
		rightPanel_watch_clear 1
		foreach entry $list_to_sort {
			set addr [lindex $entry 0]
			set name [lindex $entry 1]

			rightPanel_watch_add $addr $name
		}
	}

	## Perform autoload on simulator start
	 # @parm String filename - Code listinf file
	 # @return void
	public method rightPanel_watch_autoload {filename} {
		if {!$autoload_flag} {return}
		if {![file exists $filename]} {return}

		if {$autoclear_flag} {
			rightPanel_watch_clear 1
		}
		rightPanel_watch_import_file $filename .
	}

	## Autoload flag toggled (this function should be invoked from configuration menu)
	 # @return void
	public method rightPanel_watch_toggle_autoload_flag {} {
		set autoload_flag $::RegWatches::menu_autoload
	}

	## Autoclear flag toggled (this function should be invoked from configuration menu)
	 # @return void
	public method rightPanel_watch_toggle_autoclear_flag {} {
		set autoclear_flag $::RegWatches::menu_autoclear
	}

	## Get configuration list
	 # @return void
	public method rightPanel_watch_get_config {} {
		return [list				\
			$autoload_flag			\
			$::RegWatches::sorting_order	\
			$autoclear_flag			\
		]
	}

	## Create configuration menu
	 # @return void
	private method create_conf_menu {} {
		if {$conf_menu != {}} {
			return
		}
		set conf_menu $parent.conf_menu
		menuFactory $CONFMENU $conf_menu 0 "$this " 0 {} [namespace current]

		watch_disEna_buttons
	}

	## Invoke configuration menu
	 # @return void
	public method rightPanel_watch_cfg_menu {} {
		create_conf_menu

		set x [winfo rootx $conf_button]
		set y [winfo rooty $conf_button]
		incr y [winfo height $conf_button]

		set ::RegWatches::menu_autoload $autoload_flag
		set ::RegWatches::menu_autoclear $autoclear_flag
		tk_popup $conf_menu $x $y
	}

	## Refresh highlighting tags
	 # @return void
	public method rightPanel_refresh_regwatches_highlighting {} {
		if {!$regw_gui_initialized} {return}
		$this right_panel_create_highlighting_tags $watch_text $watch_text_tags -1
	}

	## Recreate popup menu
	 # @return void
	public method regwatches_makePopupMenu {} {
		if {!$regw_gui_initialized} {return}
		if {[winfo exists $watch_menu]} {destroy $watch_menu}
		menuFactory $WATCHMENU $watch_menu 0 "$this " 0 {} [namespace current]
	}


	## Retrun name of file currently loaded in register watches
	 # @return String - filename
	public method getWatchesFileName {} {
		# Determinate project root path
		set prj_path [$this cget -projectPath]
		append prj_path {/}

		# Return relative directory location
		if {![string first $prj_path $watch_file_name]} {
			return [string range $watch_file_name [string length $prj_path] end]
		# Return absolute directory location
		} else {
			return $watch_file_name
		}
	}

	## (Re)set dynamic shortcuts for the given entry widget
	 # @parm Widget entry - Target entry widget
	 # @return void
	private method watch_entry_shortcuts_reset {entry} {
		if {!$regw_gui_initialized} {return}

		# Unset previous configuration
		foreach key $watches_set_shortcuts {
			bind $entry <$key> {}
		}
		set set_shortcuts {}

		# Iterate over shortcuts definition
		foreach block ${::SHORTCUTS_LIST} {
			# Determinate category
			set category	[lindex $block 0]
			if {[lsearch $watches_shortcuts_cat $category] == -1} {continue}

			# Determinate definition list and its length
			set block	[lreplace $block 0 2]
			set len		[llength $block]

			# Iterate over definition list and create bindings
			for {set i 0; set j 1} {$i < $len} {incr i 2; incr j 2} {
				# Determinate key sequence
				set key [lindex $block $i]
				if {[catch {
					set key $::SHORTCUTS_DB($category:$key)
				}]} then {
					continue
				}
				if {$key == {}} {continue}

				# Create and register new binding
				lappend watches_set_shortcuts $key
				set cmd [subst [lindex $block [list $j 1]]]
				append cmd {;break}
				bind $entry <$key> $cmd
			}
		}
	}

	## Get adjusted value of address entry (register watches)
	 # @parm String string - input data ("\n" == get value from entry widget)
	 # @return String - result address
	private method get_watchAddr {string} {

		# Evaluate input string
		if {$string == {} || $string == {.}} {
			return { .00}
		}
		if {$string == "\n"} {
			set string [subst -nocommands "\$::RightPanel::watch_addr${obj_idx}"]
			regsub {^\s+} $string {} string
		}
		if {[string index $string 0] == {.}} {
			set string [string replace $string 0 0]
			set bit_addr 1
		} else {
			set bit_addr 0
		}

		# Adjust address
		set len [string length $string]
		if {$len > 2} {
			if {$len != 4} {
				set string " $string"
			}
		} else {
			if {$len == 1} {
				set string "0$string"
			}
			set string "  $string"
		}

		# Resturn result
		if {$bit_addr} {
			return [string replace $string 1 1 {.}]
		} else {
			return [string toupper $string]
		}
	}

	## Get adjusted value of register name (Register watches)
	 # @parm String string - input data ("\n" == get value from entry widget)
	 # @return String - resulting register name
	private method get_watchName {string} {
		# Conditionaly get value from entry widget
		if {$string == "\n"} {
			set string [subst -nocommands "\$::RightPanel::watch_name${obj_idx}"]
			regsub {\t+$} $string {} string
		}

		# Adjust resulting string
		set len [string length $string]
		append string [string repeat { } [expr {23 - $len}]]

		# Return result
		return $string
	}

	## Validate content of address entry - Register watches
	 # @parm String value - input value
	 # @return Bool - result
	public method rightPanel_watch_addr_validate {value} {

		# Check if validation is enabled
		if {!$watch_AN_valid_ena} {return 1}

		# Check for allowed length
		if {[string length $value] > 4} {
			return 0
		}

		# Check for allowed characters
		if {!([regexp {^[A-Fa-f0-9]*$} $value] || [regexp {^\.[A-Fa-f0-9]{0,2}$} $value])} {
			return 0
		}

		# Change content of address field in register watches text widget
		if {$watch_curLine != 0 && $value != {}} {

			# Get address
			set value [get_watchAddr $value]
			regsub {^\s+} $value {} real_value

			# Check it the desired address is unique
			if {[lsearch -ascii -exact $watch_addrs $real_value] != -1} {
				Sbar [mc "Unable to assign, address is already in use"]
				return 1
			}

			# Modify variables related to the current entry
			set idx [expr {$watch_curLine - 1}]
			set addr [lindex $watch_addrs $idx]
			set var [lindex $watch_data($addr) 1]
			set watch_data($real_value) $watch_data($addr)
			unset watch_data($addr)
			lset watch_addrs $idx $real_value

			# Synchronize
			$watch_text.$var configure -state normal
			rightPanel_watch_sync $real_value
			$watch_text.$var configure -fg ${Simulator::normal_color}
			if {!$watches_enabled || [read_from_simulator $real_value] == {--}} {
				$watch_text.$var configure -state disabled
			}

			# Enable entry watches text widget
			$watch_text configure -state normal

			# Change content of address field
			$watch_text delete $watch_curLine.0 $watch_curLine.4
			$watch_text insert $watch_curLine.0 $value

			# Bit -> Byte
			if {[string index $addr 0] == {.} && [string index $real_value 0] != {.}} {
				$watch_text.$var configure -width 2
				help_window_hide

			# Byte -> Bit
			} elseif {[string index $addr 0] != {.} && [string index $real_value 0] == {.}} {
				$watch_text.$var configure -width 1
				help_window_hide
			}

			# Highlight address field
			set len [string length $real_value]
			if {$len == 4} {
				set addr_tag {tag_Xaddr}
			} elseif {$len == 3 && ([string index $real_value 0] == {.})} {
				set addr_tag {tag_Baddr}
			} elseif {$len == 3} {
				set addr_tag {tag_Eaddr}
			} else {
				set addr_tag {tag_addr}
			}
			$watch_text tag add $addr_tag $watch_curLine.0 $watch_curLine.4

			# Change selection
			$watch_text tag remove tag_curLine 1.0 end
			$watch_text tag add tag_curLine $watch_curLine.0 "$watch_curLine.0 + 1 line"

			$watch_text configure -state disabled

			# Adjust help window
			help_window_update_addr $addr $real_value
			bind $watch_text.[lindex $watch_data($real_value) 1] <Enter>	\
				"$this create_help_window_ram ${real_value}h; help_window_variable_addr"

			# Adjust flag: modified
			set watches_modified 1
		}

		# Success
		return 1
	}

	## Validate content of register name entry - Register watches
	 # @parm String value - input value
	 # @return Bool - result
	public method rightPanel_watch_name_validate {value} {
		# Check if validation is enabled
		if {!$watch_AN_valid_ena} {return 1}

		# Check for allowed length
		if {[string length $value] > 23} {
			return 0
		}

		# Change content of register name field in register watches text widget
		if {$watch_curLine != 0} {
			# Local variables
			set name [get_watchName $value]		;# Register name

			# Change reg. name in object variable watch_data
			lset watch_data([lindex $watch_addrs [expr {$watch_curLine - 1}]]) 0 [string trimright $value]

			# Enable list of watches widget
			$watch_text configure -state normal

			# Change current register name
			$watch_text delete $watch_curLine.5 "$watch_curLine.0 lineend - 1 char"
			$watch_text insert $watch_curLine.5 $name

			# Restore reg. name text tag
			$watch_text tag add tag_name $watch_curLine.5 $watch_curLine.28

			# Adjust selection
			$watch_text tag remove tag_curLine 1.0 end
			$watch_text tag add tag_curLine $watch_curLine.0 "$watch_curLine.0 + 1 line"

			# Disable list of watches widget
			$watch_text configure -state disabled

			# Adjust status modified
			set watches_modified 1
		}

		# Success
		$watch_search_entry delete 0 end
		return 1
	}

	## Validate content of embedded entries in list of register watches
	 # @parm String addr	- hexadecimal representation of register addres
	 # @parm String value	- string to validate
	 # @return Bool - result
	public method rightPanel_watch_value_validate {addr value} {
		if {$validator_engaged} {return 1}
		set validator_engaged 1

		# Check for allowed length
		if {[string length $value] > 2} {
			set validator_engaged 0
			return 0
		}

		# Check for allowed characters
		if {![regexp {^[A-Fa-f0-9]*$} $value]} {
			set validator_engaged 0
			return 0
		}

		## Synchronize new content with simulator engine
		if {[string index $addr 0] == {.}} {
			set addr [string replace $addr 0 0]
			set bit_addr 1
		} else {
			set bit_addr 0
		}
		set dec_addr [expr "0x$addr"]
		# Bit
		if {$bit_addr} {
			if {$value == {}} {
				set value 0
			}
			if {![regexp {^[01]?$} $value]} {
				set validator_engaged 0
				return 0
			}
			$this setBit $dec_addr $value

		# External RAM
		} elseif {[string length $addr] == 4} {
			$this setXdata $dec_addr $value
			$this Simulator_XDATA_sync $addr

		# Expanded RAM
		} elseif {[string length $addr] == 3} {
			$this setEram $dec_addr $value
			$this Simulator_XDATA_sync $addr

		# Internal RAM
		} else {
			$this setData $dec_addr $value
			$this SimGUI_disable_sync
			$this Simulator_GUI_sync I $dec_addr
			$this SimGUI_enable_sync
		}

		if {$bit_addr} {
			set addr .$addr
		}
		$watch_text.[lindex $watch_data($addr) 1] configure -fg ${Simulator::normal_color}

		# Synchronize with help window
		help_window_update $addr $value

		# Done ...
		set validator_engaged 0
		return 1
	}

	## Enable entry widgets in register watches
	 # AFFECT ALL ENTRIES (not only valid ones) !!!
	 # @return void
	public method rightPanel_watch_force_enable {} {
		if {!$regw_gui_initialized} {CreateRegWatchesGUI}

		set watches_enabled 1
		foreach addr $watch_addrs {
			$watch_text.[lindex $watch_data($addr) 1] configure -state normal
		}
	}

	## Enable entry widgets in register watches
	 # Affect only entries with valid address (implemented on current MCU)
	 # @return void
	public method rightPanel_watch_enable {} {
		if {!$regw_gui_initialized} {CreateRegWatchesGUI}

		set watches_enabled 1
		foreach addr $watch_addrs {
			if {[string index $addr 0] == {.}} {
				set addr [string replace $addr 0 0]
				set bit_addr 1
			} else {
				set bit_addr 0
			}
			set dec_addr	[expr "0x$addr"]
			set len		[string length $addr]

			# Bit
			if {$bit_addr} {
				if {$dec_addr > 0x7F} {
					if {![$this simulator_is_sfr_available [$this getRegOfBit $dec_addr]]} {
						continue
					}
				}
				set addr ".$addr"

			# Internal RAM
			} elseif {$len < 3} {
				if {$dec_addr >= [lindex [$this cget -procData] 3]} {
					continue
				}

			# Expanded RAM
			} elseif {$len == 3} {
				if {$dec_addr >= [lindex [$this cget -procData] 8]} {
					continue
				}

			# External RAM
			} else {
				if {$dec_addr >= [$this cget -P_option_mcu_xdata]} {
					continue
				}
			}

			$watch_text.[lindex $watch_data($addr) 1] configure -state normal
		}
	}

	## Disable all entry widgets in register watches
	 # @return void
	public method rightPanel_watch_disable {} {
		if {!$regw_gui_initialized} {return}

		set watches_enabled 0
		foreach addr $watch_addrs {
			$watch_text.[lindex $watch_data($addr) 1] configure -state disabled
		}
	}
	## Select line in list of register watches
	 # @parm Int x - relative X coordinate
	 # @parm Int y - relative Y coordinate
	 # @return void
	public method rightPanel_watch_click {x y} {
		rightPanel_watch_switch_line [expr {int([$watch_text index @$x,$y])}]
		$watch_search_entry delete 0 end
	}

	## Change current line in register watches
	 # @parm Int row - target line
	 # @return void
	public method rightPanel_watch_switch_line {row} {
		if {!$regw_gui_initialized} {return}
		set watch_AN_valid_ena 0

		# Determinate number of the last row
		set end [$watch_text index end]
		set end [expr {int($end) - 1}]

		# Restore previous state of the last selected entry box
		if {$watch_curLine} {
			set addr [lindex $watch_addrs [expr {$watch_curLine - 1}]]
			set var [lindex $watch_data($addr) 1]
			$watch_text.$var selection clear
			$watch_text.$var configure		\
				-disabledbackground {#FFFFFF}	\
				-bg {#FFFFFF}
		}

		# Enable/Disable buttons and Clear/Keep entry widgets at the bottom
		if {$row == $end} {
			$watch_remove_button	configure -state disabled
			$watch_new_button	configure -state disabled
			$watch_add_button	configure -state normal
			set watch_curLine 0
			$watch_text tag remove tag_curLine 1.0 end
			set ::RightPanel::watch_name${obj_idx} {}
			set ::RightPanel::watch_addr${obj_idx} {}
			set watch_AN_valid_ena 1
			return 0
		} else {
			set watch_curLine $row
			$watch_remove_button	configure -state normal
			$watch_new_button	configure -state normal
			$watch_add_button	configure -state disabled
		}

		# Determinate text indexes
		set idx0 "$row.0"
		set idx1 [expr {$row + 1}]
		append idx1 {.0}

		# Set selection tag
		$watch_text tag remove tag_curLine 1.0 end
		$watch_text tag add tag_curLine $idx0 $idx1

		# Adjust content of entry widgets at the bottom
		set addr [lindex $watch_addrs [expr {$watch_curLine - 1}]]
		set name [lindex $watch_data($addr) 0]
		set var [lindex $watch_data($addr) 1]

		set ::RightPanel::watch_name${obj_idx} [string trimright $name]
		set ::RightPanel::watch_addr${obj_idx} [string trimright $addr]

		# Change foreground color of current value entry
		$watch_text.$var configure				\
			-fg ${Simulator::normal_color}			\
			-bg ${::RightPanel::selection_color_dark}	\
			-disabledbackground ${::RightPanel::selection_color_dark}

		# Focus on value entry
		focus $watch_text.$var
		$watch_text.$var selection range 0 end
		$watch_text see $row.0

		set watch_AN_valid_ena 1
	}

	## Create a new register watch
	 # @parm String	- Hex address,		{} == Content of address entry
	 # @parm String	- Register name,	{} == Content of name entry
	 # @return void
	public method rightPanel_watch_add args {
		# Local variables
		set row		[$watch_text index end]		;# Last row in the list
		set row		[expr {int($row) - 1}]
		set addr	[lindex $args 0]		;# Register address (Hex String)
		set name	[lindex $args 1]		;# Watch name
		set shortAddr	{}				;# Register address (Hex Number)

		if {$addr == {} || $name == {}} {
			set addr	[get_watchAddr "\n"]
			set name	[get_watchName "\n"]
			set no_sbar	0
		} else {
			set addr	[get_watchAddr $addr]
			set name	[get_watchName $name]
			set no_sbar	1
		}
		set shortAddr [regsub {^\s*} $addr {}]

		# Check address validity
		if {$shortAddr == {}} {
			if {!$no_sbar} {
				Sbar [mc "You must specify the register address."]
			}
			return 0
		}
		if {[lsearch -ascii -exact $watch_addrs $shortAddr] != -1} {
			if {!$no_sbar} {
				Sbar [mc "Specified address is already used."]
			}
			return 0
		}

		# Enable text widget
		$watch_text configure -state normal
		# Insert address and watch name
		$watch_text insert end "$addr $name"
		# Insert text tags
		regsub {^ +} $addr {} addr
		set entry [watch_create_entry $addr $row $watch_entry_count]
		$watch_text window create end -window $entry -pady 0
		$watch_text insert end "\n"
		set len [string length $addr]
		if {$len == 4} {
			set addr_tag {tag_Xaddr}
		} elseif {$len == 3 && ([string index $addr 0] == {.})} {
			set addr_tag {tag_Baddr}
		} elseif {$len == 3} {
			set addr_tag {tag_Eaddr}
		} else {
			set addr_tag {tag_addr}
		}
		$watch_text tag add $addr_tag $row.0 $row.4
		$watch_text tag add tag_name $row.5 $row.28
		# Disable text widget
		$watch_text configure -state disabled

		# Register new watch
		regsub {\t+$} $name {} name
		lappend watch_addrs $addr
		set watch_data($addr) [list $name $watch_entry_count]

		# Synchronize
		rightPanel_watch_sync $addr
		$entry configure -fg ${Simulator::normal_color}

		# Enable/Disable the entry widget
		if {!$watches_enabled} {
			$entry configure -state disabled
		}

		incr watch_entry_count

		# Reevaluate button states
		watch_disEna_buttons

		# Clear search entry
		$watch_search_entry delete 0 end

		# Adjust status modified
		set watches_modified 1
	}

	## Create entry widget for embedding in list of watches
	 # @parm String addr	- hexadecimal register address
	 # @parm Int row	- target row in text widget
	 # @parm Variable var	- entry text variable
	 # @return Widget - resulting entry widget
	private method watch_create_entry {addr row var} {
		if {[string index $addr 0] == {.}} {
			set width 1
		} else {
			set width 2
		}

		# Create entry widget
		set entry [entry $watch_text.$var				\
			-width $width						\
			-font ${::Simulator_GUI::entry_font}			\
			-bg {#FFFFFF}		-validate key			\
			-takefocus 0		-highlightthickness 0		\
			-disabledbackground {#FFFFFF}				\
			-vcmd "$this rightPanel_watch_value_validate $addr %P"	\
			-bd 0			-justify right			\
		]

		# Set event bindings
		bind $entry <Button-1>		"$this rightPanel_watch_switch_line $row"
		bind $entry <Key-Up>		"$this rightPanel_watch_up 1"
		bind $entry <Key-Down>		"$this rightPanel_watch_down 1"
		bind $entry <Key-Next>		"$this rightPanel_watch_down 4"
		bind $entry <Key-Prior>		"$this rightPanel_watch_up 4"
		bind $entry <Motion>		{help_window_show %X %Y}
		bind $entry <Leave>		{help_window_hide}
		bind $entry <Enter>		"$this create_help_window_ram ${addr}h; help_window_variable_addr"
		bind $entry <Button-4>		"$watch_text yview scroll -5 units"
		bind $entry <Button-5>		"$watch_text yview scroll +5 units"
		watch_entry_shortcuts_reset $entry

		# Return entry reference
		return $entry
	}

	## Clear highlight for all registers
	 # @return void
	public method rightPanel_watch_clear_highlight {} {
		if {!$regw_gui_initialized} {return}

		foreach addr $watch_addrs {
			$watch_text.[lindex $watch_data($addr) 1] configure -fg ${Simulator::normal_color}
		}
	}

	## Clear highlight for the given register
	 # @return void
	public method rightPanel_watch_unhighlight {addr} {
		if {!$regw_gui_initialized} {return}

		if {[lsearch $watch_addrs $addr] == -1} {
			return
		}
		$watch_text.[lindex $watch_data($addr) 1] configure -fg ${Simulator::normal_color}
	}

	## Move current watch to the top
	 # @return void
	public method rightPanel_watch_move_top {} {
		rightPanel_watch_move 1
	}

	## Move current watch to up
	 # @return void
	public method rightPanel_watch_move_up {} {
		# Determinate target line
		set target_line [expr {$watch_curLine - 1}]
		if {$target_line == 0} {return 0}
		# Move watch
		rightPanel_watch_move $target_line
	}

	## Move current watch to down
	 # @return void
	public method rightPanel_watch_move_down {} {
		# Determinate target line
		set target_line [expr {$watch_curLine + 1}]
		set end [$watch_text index end]
		set end [expr {int($end) - 1}]
		if {$target_line == $end} {return 0}
		# Move watch
		rightPanel_watch_move $target_line
	}

	## Move current watch to the bottom
	 # @return void
	public method rightPanel_watch_move_bottom {} {
		# Determinate target line
		set target_line [$watch_text index end]
		set target_line [expr {int($target_line) - 2}]
		# Move watch
		rightPanel_watch_move $target_line
	}

	## Move current watch to the given line
	 # @parm Int target_line - target line
	 # @return void
	private method rightPanel_watch_move {target_line} {
		# Validate current line value
		if {$watch_curLine == 0} {return}

		# Local variables
		set cur_idx	[expr {$watch_curLine - 1}]	;# index in $watch_addrs -- current line
		set trg_idx	[expr {$target_line - 1}]	;# index in $watch_addrs -- target line
		set addr	[lindex $watch_addrs $cur_idx]	;# register address
		set name	[lindex $watch_data($addr) 0]	;# watch name
		set var		[lindex $watch_data($addr) 1]	;# textvariable of the value entry

		# Modify variables related to the watch
		set watch_addrs [lreplace $watch_addrs $cur_idx $cur_idx]
		set watch_addrs [linsert $watch_addrs $trg_idx $addr]

		# Enable the widget
		$watch_text configure -state normal
		# Change textual content
		$watch_text delete $watch_curLine.0 "$watch_curLine.0 + 1 line linestart"
		$watch_text insert $target_line.0 "[get_watchAddr $addr] [get_watchName $name]\n"
		# Destroy the current entry widget
		destroy $watch_text.$var
		# Change embedded entry
		set entry [watch_create_entry $addr $target_line $var]
		$watch_text window create [list $target_line.0 lineend] -window $entry -pady 0
		set len [string length $addr]
		if {$len == 4} {
			set addr_tag {tag_Xaddr}
		} elseif {$len == 3 && ([string index [string trim $addr] 0] == {.})} {
			set addr_tag {tag_Baddr}
		} elseif {$len == 3} {
			set addr_tag {tag_Eaddr}
		} else {
			set addr_tag {tag_addr}
		}
		# Restore text tags
		$watch_text tag add $addr_tag $target_line.0 $target_line.4
		$watch_text tag add tag_name $target_line.5 $target_line.28
		# Disable the widget
		$watch_text configure -state disabled

		# Synchronize entry widget content
		rightPanel_watch_sync $addr

		# Enable/Disable the entry widget
		if {!$watches_enabled} {
			$entry configure -state disabled
		}

		# Set current line
		set watch_curLine $target_line
		rightPanel_watch_switch_line $target_line

		# Clear search entry
		$watch_search_entry delete 0 end

		# Adjust status modified
		set watches_modified 1
	}

	## Change current line in list of register watches to the line above the current one
	 # @parm Int lines - number of lines to skip - 1
	 # @return void
	public method rightPanel_watch_up {lines} {
		# Determinate number of last row in the widget
		set end [$watch_text index end]
		set end [expr {int($end) - 2}]

		# Change current line (logicaly)
		set line $watch_curLine
		incr line -$lines
		if {$line < 1} {
			set line 1
		}

		# Change current line (physicaly)
		$watch_text see $watch_curLine.0
		rightPanel_watch_switch_line $line

		# Clear search entry
		$watch_search_entry delete 0 end
	}

	## Change current line in list of register watches to the line below the current one
	 # @parm Int lines - number of lines to skip - 1
	 # @return void
	public method rightPanel_watch_down {lines} {
		# Determinate number of last row in the widget
		set end [$watch_text index end]
		set end [expr {int($end) - 2}]

		# Change current line (logicaly)
		set line $watch_curLine
		incr line $lines
		if {$line > $end} {
			set line $end
		}

		# Change current line (physicaly)
		$watch_text see $watch_curLine.0
		rightPanel_watch_switch_line $line

		# Clear search entry
		$watch_search_entry delete 0 end
	}

	## Binding for button "New" (Clears entry widgets at the bottom and unselect current watch)
	 # @return void
	public method rightPanel_watch_new {} {
		set end [$watch_text index end]
		set end [expr {int($end) - 1}]
		rightPanel_watch_switch_line $end

		# Clear search entry
		$watch_search_entry delete 0 end
	}

	## Remove the current register watch
	 # @return void
	public method rightPanel_watch_remove {} {
		# Determinate register address
		set addr [lindex $watch_addrs [expr {$watch_curLine - 1}]]
		if {$addr != {}} {
			# Destroy value entry
			set var [lindex $watch_data($addr) 1]
			destroy $watch_text.$var
			# Unregister watch
			unset watch_data($addr)
			set idx [lsearch $watch_addrs $addr]
			set watch_addrs [lreplace $watch_addrs $idx $idx]

			# Remove watch from the text widget
			$watch_text configure -state normal
			$watch_text delete $watch_curLine.0 "$watch_curLine.0 + 1 line"
			$watch_text configure -state disabled
		}

		# Change current line
		if {$watch_curLine > [llength $watch_addrs]} {
			set watch_curLine [llength $watch_addrs]
		}
		if {$watch_curLine} {
			rightPanel_watch_switch_line $watch_curLine
		} else {
			rightPanel_watch_switch_line 1
		}

		# Reevaluate button states
		watch_disEna_buttons
		# Clear search entry
		$watch_search_entry delete 0 end
		# Adjust status modified
		set watches_modified 1
	}

	## Save watches definition to a file
	 # @parm String filename	- Target filename or an empty string
	 # @parm Bool force=0		- Do not ask for overwrite
	 # @return void
	public method rightPanel_watch_save {filename {force 0}} {
		if {!$regw_gui_initialized} {CreateRegWatchesGUI}

		if {$filename != {}} {
			set watch_file_name $filename
		}

		# If no filename specified -> invoke dislog "Save as"
		if {$watch_file_name == {}} {
			rightPanel_watch_saveas

		# Save file
		} else {
			# Set new filename
			if {!$::MICROSOFT_WINDOWS} {	;# POSIX way
				if {![regexp "^(~|/)" $watch_file_name]} {
				set filename "[$this cget -ProjectDir]/$watch_file_name"
				}
			} else {	;# Microsoft windows way
				if {![regexp {^\w:} $watch_file_name]} {
					set filename [file join [$this cget -ProjectDir] $watch_file_name]
				}
			}

			set watch_file_name [file normalize $watch_file_name]
			# Adjust file extension
			if {![regexp {\.wtc$} $watch_file_name]} {
				append watch_file_name {.wtc}
			}

			if {[file exists $watch_file_name] && [file isfile $watch_file_name]} {
				# Ask user for overwrite existing file
				if {!$force && [tk_messageBox	\
					-type yesno		\
					-icon question		\
					-parent .		\
					-title [mc "Overwrite file"]	\
					-message [mc "A file name '%s' already exists. Are you sure you want to overwrite it ?" [file tail $watch_file_name]]
					] != {yes}
				} then {
					return
				}
				# Create a backup file
				catch {
					file rename -force $watch_file_name "$watch_file_name~"
				}
			}
			if {[catch {
				set file [open $watch_file_name w 0640]
			}]} then {
				if {[winfo exists .fsd]} {
					set parent .fsd
				} else {
					set parent .
				}
				tk_messageBox		-type ok		\
					-parent $parent	-icon warning		\
					-title [mc "Error - MCU 8051 IDE"]	\
					-message [mc "Unable to access file \"%s\", check your permissions." $watch_file_name]
				return
			}

			# Write file header
			puts $file "# Watches definition file -- ${::APPNAME}"

			# Write watches definition
			puts -nonewline $file [regsub -all -line {\s+$} [$watch_text get 1.0 end] {}]

			# Finish
			close $file
			Sbar [mc "Definitions saved to \"%s\"" $watch_file_name]

			# Adjust status modified
			set watches_modified 0
		}
	}

	## Invoke dialog "Save as" - Register watches
	 # @return void
	public method rightPanel_watch_saveas {} {

		# Abort if there is already opened some file selection dialog
		if {[winfo exists .fsd]} {return}

		# Invoke the dialog
		KIFSD::FSD ::fsd	 					\
			-title [mc "Save watches - MCU 8051 IDE"]		\
			-directory [$this cget -ProjectDir]			\
			-defaultmask 0 -multiple 0 -filetypes [list				\
				[list [mc "MCU 8051 IDE watches definition"]	{*.wtc}]	\
				[list [mc "All files"]				{*}]		\
			]
		# Save file after press of OK button
		::fsd setokcmd {
			set ::filename [::fsd get]
			if {$::filename != {} && ![file isdirectory $::filename]} {
				${::X::actualProject} rightPanel_watch_save $::filename
			}
		}
		# Activate the dialog
		::fsd activate
	}

	## Open and process watches definition file
	 # @parm String filename	- name of source file
	 # @parm Widget parent		- GUI parent (for error dialogues)
	 # @parm Bool clear		- Clear watches before loading
	 # @return Bool - result
	public method rightPanel_watch_openfile {filename parent clear} {
		if {!$regw_gui_initialized} {CreateRegWatchesGUI}

		# Normalize filename
		if {!$::MICROSOFT_WINDOWS} {	;# POSIX way
			if {![regexp "^(~|/)" $filename]} {
			set filename "[$this cget -projectPath]/$filename"
			}
		} else {	;# Microsoft windows way
			if {![regexp {^\w:} $filename]} {
				set filename [file join [$this cget -projectPath] $filename]
			}
		}
		set filename [file normalize $filename]

		# Set new watches filename
		set watch_file_name $filename

		# Open file
		if {[catch {
			set file [open $filename r]
		}]} then {
			tk_messageBox						\
				-parent $parent					\
				-icon warning					\
				-type ok					\
				-title [mc "File access error"]			\
				-message [mc "Unable to read file '%s'" $filename]
			set watch_file_name {}
			return 0
		}

		# Verify input data validity
		while {![eof $file]} {
			set line [gets $file]

			# Skip comments and empty lines
			if {[regexp {^\s*#} $line]} {continue}
			if {[regexp {^\s*$} $line]} {continue}

			# Local variables
			regexp {^\s*\.?\w+} $line addr		;# Register address
			regsub {^\s*\.?\w+\s*} $line {} name	;# Watch name
			regsub {\s+$} $name {} name

			# Check for address and name validity
			if {
				![regexp {^\s*\.?[A-Fa-f0-9]+$} $addr]	||
				[string length $addr] > 4		||
				[string length $name] > 23
			} then {
				tk_messageBox				\
					-title [mc "Corrupted file"]	\
					-icon error -type ok  -parent $parent	\
					-message [mc "file: %s is either corrupted or it is not a file in expected format." $filename]
				return 0
			}
		}

		# Clear watches
		if {$clear} {
			rightPanel_watch_clear 1
		}

		# Parse input data
		seek $file 0
		while {![eof $file]} {
			set line [gets $file]

			# Skip comments and empty lines
			if {[regexp {^\s*#} $line]} {continue}
			if {[regexp {^\s*$} $line]} {continue}

			regexp {^\s*\.?\w+} $line addr		;# Register address
			regsub {^\s*\.?\w+\s*} $line {} name	;# Watch name
			set addr [string trimleft $addr]
			set name [string trimright $name]

			# Create new register watch
			rightPanel_watch_add $addr $name
		}

		# Deselect all
		rightPanel_watch_new

		# Reevaluate button states (icon bar)
		watch_disEna_buttons

		# Adjust status modified
		set watches_modified 0

		# Success
		close $file
		return 1
	}

	## Invoke dialog "Open file"
	 # @return void
	public method rightPanel_watch_open {} {
		# Invoke the dialog
		KIFSD::FSD ::fsd	 					\
			-title [mc "Load watches from file - MCU 8051 IDE"]	\
			-directory [$this cget -ProjectDir] -autoclose 0	\
			-defaultmask 0 -multiple 0 -filetypes [list				\
				[list [mc "MCU 8051 IDE watches definition"]	{*.wtc}]	\
				[list [mc "All files"]				{*}]		\
			]

		# Open file after press of OK button
		fsd setokcmd {
			# Get chosen file name
			set filename [::fsd get]
			if {[${::X::actualProject} rightPanel_watch_openfile $filename [::fsd get_window_name] 1]} {
				::fsd deactivate
				delete object fsd
			}
		}

		# Activate the dialog
		fsd activate
	}

	## Invoke dialog "Import file"
	 # @return void
	public method rightPanel_watch_import {} {
		# Invoke the dialog
		KIFSD::FSD ::fsd	 					\
			-title [mc "Import file - MCU 8051 IDE"]		\
			-directory [$this cget -ProjectDir] -autoclose 0	\
			-defaultmask 0 -multiple 0 -filetypes [list				\
				[list [mc "Code listing"]			{*.lst}]	\
				[list [mc "MCU 8051 IDE watches definition"]	{*.wtc}]	\
				[list [mc "All files"]				{*}]		\
			]

		# Open file after press of OK button
		fsd setokcmd {
			# Get chosen file name
			set filename [::fsd get]
			if {[${::X::actualProject} rightPanel_watch_import_file $filename [::fsd get_window_name]]} {
				::fsd deactivate
				delete object fsd
			}
		}

		# Activate the dialog
		fsd activate
	}

	## Import file
	 # @parm String filename	- Name of source file (*.lst or *.wtc)
	 # @parm Widget parent		- GUI parent (for error dialogues)
	 # @return Bool - result
	public method rightPanel_watch_import_file {filename parent} {
		if {!$regw_gui_initialized} {CreateRegWatchesGUI}

		# Determinate file type
		set filename [file normalize [file join [$this cget -ProjectDir] $filename]]
		set file_type 0
		switch -nocase -- [file extension $filename] {
			{.wtc} {	;# Watches definition file
				set file_type 1
			}
			{.lst} {	;# Code listing
				set file_type 2
			}
			default {	;# Try to detect file type by file header
				catch {
					set file [open $filename r]
					if {[string first {# Watches definition file} [gets $file]] == 0} {
						set file_type 1
					}
					close $file
				}
			}
		}

		# Unknown file type
		if {!$file_type} {
			tk_messageBox		\
				-parent .	\
				-type ok	\
				-icon warning	\
				-title [mc "Unknown file"]	\
				-message [mc "Unable to recognize file format"]
			return 0
		}

		# -----------------------------------------------------------------------
		## WTC file - load and exit procedure
		# -----------------------------------------------------------------------
		if {$file_type == 1} {
			return [rightPanel_watch_openfile $filename $parent 0]
		}


		# -----------------------------------------------------------------------
		# LST file
		# -----------------------------------------------------------------------

		# Try to open file
		if {[catch {
			set file [open $filename r]
		}]} then {
			tk_messageBox		\
				-parent .	\
				-type ok	\
				-icon warning	\
				-title [mc "File access error"]	\
				-message [mc "Unable to open file:\n'%s'" $filename]
			return 0
		}

		# Parse file
		set read_line 0
		set line {}
		set name {}
		set addr {}
		set type {}
		set bita 0
		while {![eof $file]} {
			set bita 0
			set line [gets $file]

			# Empty line - stop reading
			if {![string length [string trimright $line "  \f"]]} {
				set read_line 0
				continue

			# MCU 8051 IDE Assembler symbol table
			} elseif {![string first {SYMBOL TABLE:} $line]} {
				set read_line 1
				continue

			# ASEM-51 Assembler symbol table
			} elseif {![string first {------------------------------------------------------------} $line]} {
				set read_line 2
				continue
			}


			# MCU 8051 IDE Assembler symbol
			if {$read_line == 1} {
				if {![regexp {^\w+} $line name]} {
					continue
				}
				if {![regexp {[\w\s]+$} $line line]} {
					continue
				}
				set type [lindex $line 0]

				# Ignore all types except address
				if {[lindex $line 1] != {ADDR}} {
					continue
				}

				# Internal data memory
				if {$type == {D} || $type == {I}} {
					set addr [string range [lindex $line 2] 2 3]
				# External data memory (inluding ERAM, EEPROM, etc.)
				} elseif {$type == {X}} {
					set addr [string range [lindex $line 2] 0 3]
				# Bit addressable area
				} elseif {$type == {B}} {
					set bita 1
					set addr [string range [lindex $line 2] 2 3]
				# Another type of memory -> IGNORE
				} else {
					continue
				}

				# Ignore unused symbols
				if {[lindex $line end-1] == {NOT} || [lindex $line end-2] == {NOT}} {
					continue
				}

			# ASEM-51 Assembler symbol
			} elseif {$read_line == 2} {
				# Remove dangerous characters
				regsub -all {\{\}\"\"} $line {} line

				# Ignore unused symbols
				if {[llength $line] < 4} {
					continue
				}

				# Determinate address and symbol name
				set type [lindex $line 1]
				set addr [lindex $line 2]
				set name [lindex $line 0]

				# Accept only internal and external data memory
				if {$type != {IDATA} && $type != {DATA} && $type != {XDATA} && $type != {BIT}} {
					continue
				}
				if {$type == {BIT}} {
					set bita 1
				}

			# This line is not a part of symbol table
			} else {
				continue
			}

			# Address must be a valid hexadecimal value
			if {![string is xdigit -strict $addr]} {
				continue
			}

			# Exclude SFR's
			if {[lsearch -ascii -exact ${::ASMsyntaxHighlight::spec_registers} $name] != -1} {
				continue
			}

			# Create new register watch
			if {[string length $name] > 23} {
				set name [string range $name 0 16]
				append name {..}
			}

			if {$bita} {
				set addr .$addr
			}

			rightPanel_watch_add $addr $name
			set watches_modified 1
		}

		# Finalize
		rightPanel_watch_new
		watch_disEna_buttons
		close $file
		return 1
	}

	## Remove all register watches
	 # Bool force=0	- Don't ask for user comfirmation
	 # @return void
	public method rightPanel_watch_clear {{force 0}} {
		if {!$regw_gui_initialized} {CreateRegWatchesGUI}

		# Ask user for comfirmation
		if {!$force} {
			if {[tk_messageBox	\
				-parent .	\
				-type yesno	\
				-icon question	\
				-title [mc "Are you sure ?"]	\
				-message [mc "Do you really want to clear the panel ?"]
			] != {yes}} {
				return
			}
		}

		# Clear text widget
		$watch_text configure -state normal
		$watch_text delete 1.0 end
		$watch_text configure -state disabled

		# Destroy all embedded entry widgets
		foreach addr $watch_addrs {
			destroy $watch_text.[lindex $watch_data($addr) 1]
		}

		# Clear entries on the bottom bar
		set watch_curLine 0
		set ::RightPanel::watch_name${obj_idx} {}
		set ::RightPanel::watch_addr${obj_idx} {}

		# Unregister all watches
		set watch_addrs {}
		catch {
			array unset watch_data
		}

		# Reevaluate button states (icon bar)
		watch_disEna_buttons

		# Adjust status modified
		set watches_modified 1
	}

	## Search for the given string in the list of register watches -- search entry validator
	 # @parm String content	- String to find/validate
	 # @return Bool - result
	public method rightPanel_watch_search_validate {content} {
		if {$search_val_in_progress} {return 0}
		set search_val_in_progress 1

		# Enable/Disable button "Clear search entry"
		if {$content == {}} {
			$watch_search_clear configure -state disabled
		} else {
			$watch_search_clear configure -state normal
		}

		# Validate search string
		if {[regexp {^\s*$} $content]} {
			$watch_search_entry configure -style TEntry
			set search_val_in_progress 0
			return 1
		}
		if {[string length $content] > 23} {
			set search_val_in_progress 0
			return 0
		}

		# Search for the given string
		set i 1
		set content [string trimright $content]
		set content [string tolower $content]
		foreach addr $watch_addrs {
			if {![string first $content [string tolower [lindex $watch_data($addr) 0]]]} {
				$watch_search_entry configure -style StringFound.TEntry
				rightPanel_watch_switch_line $i
				focus $watch_search_entry
				set search_val_in_progress 0
				return 1
			}
			incr i
		}

		# String not found
		$watch_search_entry configure -style StringNotFound.TEntry
		set search_val_in_progress 0
		return 1
	}

	## Syncronize all register watches
	 # @return void
	public method rightPanel_watch_sync_all {} {
		if {!$regw_gui_initialized} {CreateRegWatchesGUI}

		# Iterate over addresses
		foreach addr $watch_addrs {
			# Synchronize
			rightPanel_watch_sync $addr
			# Clear highligh
			set var [lindex $watch_data($addr) 1]
			$watch_text.$var configure -fg ${Simulator::normal_color}
		}
	}

	## Read value from simulator engine
	 # @parm String addr - hexadecimal register address
	 # @return String - hexadecimal value or {--}
	private method read_from_simulator {addr} {
		## Determinate address type (Bit / Internal / Enternal / Expanded)
		if {[string index $addr 0] == {.}} {
			set addr [string replace $addr 0 0]
			if {![string length $addr]} {
				return {--}
			}
			set bit_addr 1
		} else {
			set bit_addr 0
		}
		set len		[string length $addr]
		set val		{--}
		set addr_dec	[expr "0x$addr"]

		# Bit
		if {$bit_addr} {
			if {$addr_dec > 0x7F} {
				if {[$this simulator_is_sfr_available [$this getRegOfBit $addr_dec]]} {
					set val [$this getBit $addr_dec]
				}
			} else {
				set val [$this getBit $addr_dec]
			}

		# Internal RAM
		} elseif {$len < 3} {
			# Normalize address
			if {$len == 1} {
				set addr "0$addr"
			}
			# Get register value
			if {$addr_dec < [lindex [$this cget -procData] 3]} {
				set val [$this getData $addr_dec]
			}

		# Expanded RAM
		} elseif {$len == 3} {
			if {$addr_dec < [lindex [$this cget -procData] 8]} {
				set val [$this getEram $addr_dec]
			}

		# External RAM
		} elseif {$len == 4} {
			if {$addr_dec < [$this cget -P_option_mcu_xdata]} {
				set val [$this getXdata $addr_dec]
			}
		}

		return $val
	}

	## Synchronize all bits in the specified SFR
	 # @parm Int dec_addr - SFR register address
	 # @return void
	public method rightPanel_watch_sync_sfr {dec_addr} {

		if {$validator_engaged} {
			return
		}
		if {$dec_addr % 8} {
			return
		}

		for {set i 0} {$i < 8} {incr i} {
			rightPanel_watch_sync .[format %X $dec_addr]
			incr dec_addr
		}
	}

	## Synchronize one register watch
	 # @parm String addr - hexadecimal register address
	 # @return Bool - result
	public method rightPanel_watch_sync {addr} {
		if {$validator_engaged} {return 1}
		if {!$regw_gui_initialized} {CreateRegWatchesGUI}

		# Detect bit address
		if {[string index $addr 0] == {.}} {
			set bit_addr 1
		} else {
			set bit_addr 0
		}

		# Get register value
		set val [read_from_simulator $addr]

		# Synchronize bits in the given register
		if {!$validator_engaged && [string length $addr] == 2} {

			set dec_addr [expr "0x$addr"]

			if {$dec_addr >= 0x20 && $dec_addr <= 0x2F} {
				set dec_addr [expr {($dec_addr - 0x20) * 8}]
				for {set i 0} {$i < 8} {incr i} {

					set hex_addr [format %X $dec_addr]
					if {[string length $hex_addr] == 1} {
						set hex_addr "0$hex_addr"
					}

					rightPanel_watch_sync .$hex_addr
					incr dec_addr
				}
			}
		}

		# Check for watch presence
		if {[lsearch -ascii -exact $watch_addrs $addr] == -1} {
			return 0
		}

		# Normalize register value
		if {!$bit_addr && [string length $val] == 1} {
			set val "0$val"
		}

		set var [lindex $watch_data($addr) 1]
		set path $watch_text.$var	;# Path to watch entry widget

		# Determinate original value
		set original_val [$watch_text.$var get]

		# Highlight value entry
		if { "0x$original_val" != "0x$val"} {
			$path configure -fg ${Simulator::highlight_color}
		}

		# Set new entry value
		set validator_engaged 1
		$watch_text.$var delete 0 end
		$watch_text.$var insert 0 $val
		set validator_engaged 0

		# Synchronize with help window
		help_window_update $addr $val

		# Done ...
		return 1
	}

	## Enable/Disable buttons on watches icon bar
	 # @return void
	private method watch_disEna_buttons {} {
		if {!$regw_gui_initialized} {return}

		if {[$watch_text index end] == {2.0}} {
			set state {disabled}
		} else {
			set state {normal}
		}

		if {$conf_menu != {}} {
			$conf_menu entryconfigure [::mc "Sort by"] -state $state
			$conf_menu entryconfigure [::mc "Remove all"] -state $state
		}
	}

	## Get status modified for register watches
	 # @return Bool - true if register watches were modified
	public method rightPanel_watch_modified {} {
		return $watches_modified
	}

	## Invoke register watches popup menu
	 # @parm Int X - absolute X coordinate
	 # @parm Int Y - absolute Y coordinate
	 # @parm Int x - relative X coordinate
	 # @parm Int y - relative Y coordinate
	 # @return void
	public method rightPanel_watch_popupmenu {X Y x y} {
		# Change current line
		rightPanel_watch_click $x $y

		## Enable/Disable menu items

		# If address entry is not empty -> disable all
		set addr [subst -nocommands "\$::RightPanel::watch_addr${obj_idx}"]
		if {$addr != {}} {
			set end [$watch_text index end]
		} else {
			set end {2.0}
		}
		# Empty list
		if {$end == {2.0}} {
			$watch_menu entryconfigure [::mc "Move top"]		-state disabled
			$watch_menu entryconfigure [::mc "Move up"]		-state disabled
			$watch_menu entryconfigure [::mc "Move down"]		-state disabled
			$watch_menu entryconfigure [::mc "Move bottom"]		-state disabled
			$watch_menu entryconfigure [::mc "Remove"]		-state disabled
			$watch_menu entryconfigure [::mc "Remove all"]		-state disabled
		# One item
		} elseif {$end == {3.0}} {
			$watch_menu entryconfigure [::mc "Move top"]		-state disabled
			$watch_menu entryconfigure [::mc "Move up"]		-state disabled
			$watch_menu entryconfigure [::mc "Move down"]		-state disabled
			$watch_menu entryconfigure [::mc "Move bottom"]		-state disabled
			$watch_menu entryconfigure [::mc "Remove"]		-state normal
			$watch_menu entryconfigure [::mc "Remove all"]		-state normal
		# More items
		} else {
			# First item
			if {$watch_curLine == 1} {
				$watch_menu entryconfigure [::mc "Move top"]	-state disabled
				$watch_menu entryconfigure [::mc "Move up"]	-state disabled
				$watch_menu entryconfigure [::mc "Move down"]	-state normal
				$watch_menu entryconfigure [::mc "Move bottom"]	-state normal
			# Last item
			} elseif {$watch_curLine == ($end - 2)} {
				$watch_menu entryconfigure [::mc "Move top"]	-state normal
				$watch_menu entryconfigure [::mc "Move up"]	-state normal
				$watch_menu entryconfigure [::mc "Move down"]	-state disabled
				$watch_menu entryconfigure [::mc "Move bottom"]	-state disabled
			# Any other item
			} else {
				$watch_menu entryconfigure [::mc "Move top"]	-state normal
				$watch_menu entryconfigure [::mc "Move up"]	-state normal
				$watch_menu entryconfigure [::mc "Move down"]	-state normal
				$watch_menu entryconfigure [::mc "Move bottom"]	-state normal
			}
			$watch_menu entryconfigure [::mc "Remove"]		-state normal
			$watch_menu entryconfigure [::mc "Remove all"]		-state normal
		}

		# Invoke popup menu
		tk_popup $watch_menu $X $Y
	}


	## Create bindings for defined key shortcuts -- register watches
	 # @return void
	public method rightPanel_watch_shortcuts_reevaluate {} {
		if {!$regw_gui_initialized} {return}
		foreach addr $watch_addrs {
			watch_entry_shortcuts_reset watch_text.[lindex $watch_data($addr) 1]
		}
	}

	## Set flag enabled
	 # @parm Bool bool - New value
	 # @return void
	public method right_panel_watches_set_enabled {bool} {
		set enabled $bool
	}
}

set ::RegWatches::menu_autoload  [lindex $::CONFIG(REGWATCHES_CONFIG) 0]
set ::RegWatches::sorting_order  [lindex $::CONFIG(REGWATCHES_CONFIG) 1]
set ::RegWatches::menu_autoclear [lindex $::CONFIG(REGWATCHES_CONFIG) 2]

# >>> File inclusion guard
}
# <<< File inclusion guard