From 47aa8b00b2b11df13a100489e0f904a4947177ef Mon Sep 17 00:00:00 2001 From: Andrej Shadura Date: Tue, 8 May 2018 15:59:31 +0200 Subject: Import Upstream version 1.4.7 --- lib/utilities/asciichart.tcl | 89 ++- lib/utilities/baseconverter.tcl | 952 ++++++++++++++++++++++++++++++++ lib/utilities/baseconvertor.tcl | 912 ------------------------------ lib/utilities/eightsegment.tcl | 64 ++- lib/utilities/hexeditdlg.tcl | 257 +++++---- lib/utilities/notes.tcl | 51 +- lib/utilities/rs232debugger.tcl | 166 +++--- lib/utilities/speccalc.tcl | 611 +++++++++++--------- lib/utilities/symbol_viewer.tcl | 104 ++-- lib/utilities/table_of_instructions.tcl | 692 +++++++++++++++++++++++ 10 files changed, 2404 insertions(+), 1494 deletions(-) mode change 100755 => 100644 lib/utilities/asciichart.tcl create mode 100644 lib/utilities/baseconverter.tcl delete mode 100755 lib/utilities/baseconvertor.tcl mode change 100755 => 100644 lib/utilities/eightsegment.tcl mode change 100755 => 100644 lib/utilities/hexeditdlg.tcl mode change 100755 => 100644 lib/utilities/notes.tcl mode change 100755 => 100644 lib/utilities/rs232debugger.tcl mode change 100755 => 100644 lib/utilities/speccalc.tcl mode change 100755 => 100644 lib/utilities/symbol_viewer.tcl create mode 100644 lib/utilities/table_of_instructions.tcl (limited to 'lib/utilities') diff --git a/lib/utilities/asciichart.tcl b/lib/utilities/asciichart.tcl old mode 100755 new mode 100644 index 01ac86e..bc44f3e --- a/lib/utilities/asciichart.tcl +++ b/lib/utilities/asciichart.tcl @@ -2,7 +2,7 @@ # Part of MCU 8051 IDE ( http://mcu8051ide.sf.net ) ############################################################################ -# Copyright (C) 2007-2009 by Martin Ošmera # +# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera # # martin.osmera@gmail.com # # # # This program is free software; you can redistribute it and#or modify # @@ -21,14 +21,19 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################ +# >>> File inclusion guard +if { ! [ info exists _ASCIICHART_TCL ] } { +set _ASCIICHART_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Interactive ASCII chart # -------------------------------------------------------------------------- class AsciiChart { - common count 0 ;# Int: Counter of object instances - common ASCII_TABLE ;# Array of List: ASCII table + common ascii_chr_count 0 ;# Int: Counter of object instances + common ASCII_TABLE ;# Array of List: ASCII table array set ASCII_TABLE { 0 {NUL ^@ \\0 {Null character}} 1 {SOH ^A {} {Start of Header}} @@ -110,25 +115,27 @@ class AsciiChart { constructor {} { # Configure local ttk styles - ttk::style configure AsciiChart_BlueFg.TEntry -foreground {#0000DD} - ttk::style configure AsciiChart_RedFg.TEntry -foreground {#DD0000} + ttk::style configure AsciiChart_BlueFg.TEntry -foreground {#0000DD} + ttk::style configure AsciiChart_RedFg.TEntry -foreground {#DD0000} + ttk::style configure AsciiChart_RedBg.TEntry -fieldbackground {#FFDDDD} + ttk::style configure AsciiChart_GreenBg.TEntry -fieldbackground {#DDFFDD} # Create dialog window set window_visible 1 - set win [toplevel .asciichart$count -class {ASCII chart} -bg {#EEEEEE}] - set obj_idx $count - incr count + set win [toplevel .asciichart${ascii_chr_count} -class {ASCII chart} -bg ${::COMMON_BG_COLOR}] + set obj_idx $ascii_chr_count + incr ascii_chr_count # Create dialog GUI create_gui # Set window event bindings - bind $win "::itcl::delete object $this; break" + bind $win "$this close_window; break" bindtags $win [list $win Toplevel all .] # Set window parameters wm iconphoto $win ::ICONS::16::math_matrix - wm title $win "ASCII chart - MCU 8051 IDE" + wm title $win "[mc {ASCII chart}] - MCU 8051 IDE" wm resizable $win 0 0 wm protocol $win WM_DELETE_WINDOW "$this close_window" } @@ -173,7 +180,7 @@ class AsciiChart { set status_bar_lbl [label $bottom_frame.status_bar_lbl -justify left -anchor w] pack $status_bar_lbl -side left -fill x -in $bottom_frame pack [ttk::button $bottom_frame.close_but \ - -text "Exit" \ + -text [mc "Exit"] \ -command "$this close_window" \ -compound left \ -image ::ICONS::16::exit \ @@ -182,14 +189,14 @@ class AsciiChart { ## Create main frame set main_frame [frame $win.main_frame -bg {#DDDDDD}] # Create vertical header - grid [frame $main_frame.top_right_lbl -bg {#EEEEEE}] -sticky wens -row 0 -column 0 + grid [frame $main_frame.top_right_lbl -bg ${::COMMON_BG_COLOR}] -sticky wens -row 0 -column 0 set header [list {} \ {0x0_} {0x1_} {0x2_} {0x3_} \ {0x4_} {0x5_} {0x6_} {0x7_} \ ] for {set y 1} {$y < 9} {incr y} { grid [label $main_frame.vh_lbl$y -text [lindex $header $y] -bg {#FFFFFF}] \ - -row $y -column 0 -pady [expr {$y % 2}] -sticky ns + -row $y -column 0 -pady [expr {$y % 2}] -sticky wens set vh_cells([expr {$y - 1}]) $main_frame.vh_lbl$y } # Create horizontal header @@ -201,7 +208,7 @@ class AsciiChart { ] for {set x 1} {$x < 17} {incr x} { grid [label $main_frame.hh_lbl$x -text [lindex $header $x] -bg {#FFFFFF}] \ - -row 0 -column $x -padx [expr {$x % 2}] -sticky we + -row 0 -column $x -padx [expr {$x % 2}] -sticky wens set hh_cells([expr {$x - 1}]) $main_frame.hh_lbl$x } # Create ASCII chart matrix @@ -225,7 +232,7 @@ class AsciiChart { set val [lindex $ASCII_TABLE($address) 0] if {[string length $val] > 1} { set foreground {#DD0000} - } { + } else { set foreground {#0000DD} } @@ -239,15 +246,36 @@ class AsciiChart { -bg white -pady 0 \ ] - grid $frame -row $y -column $x -padx [expr {$x % 2}] -pady [expr {$y % 2}] -sticky we + grid $frame -row $y -column $x -padx [expr {$x % 2}] -pady [expr {$y % 2}] -sticky wens set cells($address) $frame foreach wdg [list $frame $frame.val_lbl $frame.char_lbl] { bind $wdg "$this cell_enter $address" bind $wdg "$this cell_leave $address" bind $wdg "$this cell_click $address" } + + if {$address < 127} { + bind $frame [list $this cell_click [expr {$address + 1}]] + } + if {$address > 0} { + bind $frame [list $this cell_click [expr {$address - 1}]] + } + if {$address > 16} { + bind $frame [list $this cell_click [expr {$address - 16}]] + } + if {$address < 112} { + bind $frame [list $this cell_click [expr {$address + 16}]] + } + incr address } + } + # Ensure than all cells have the same width and heigh + for {set i 0} {$i < 17} {incr i} { + grid columnconfigure $main_frame $i -uniform ascii + } + for {set i 1} {$i < 9} {incr i} { + grid rowconfigure $main_frame $i -uniform ascii } # Show ASCII chart pack $main_frame -pady 5 -side top @@ -255,7 +283,7 @@ class AsciiChart { ## Create details frame (character details) # Create labelframe set details_frame_header_frm [frame $win.details_frame_header_frm] - pack [label $details_frame_header_frm.lbl -text "Character: "] -side left + pack [label $details_frame_header_frm.lbl -text [mc "Character: "]] -side left set char_ent [ttk::entry $details_frame_header_frm.ent \ -validatecommand "$this char_ent_validator %P" \ -width 4 \ @@ -407,6 +435,7 @@ class AsciiChart { set selected_cell -1 return } + focus $cells($address) select_cell $address if {$selected_cell != -1} { fill_entryboxes $address {} @@ -459,7 +488,7 @@ class AsciiChart { # Set new background color if {$keep_current} { sel_bg_color $selected_cell {#DDFFDD} - } { + } else { sel_bg_color $selected_cell {#FFFFFF} } @@ -526,7 +555,7 @@ class AsciiChart { $char_ent insert insert $value if {[string length $value] > 1} { $char_ent configure -style AsciiChart_RedFg.TEntry - } { + } else { $char_ent configure -style AsciiChart_BlueFg.TEntry } } @@ -569,7 +598,7 @@ class AsciiChart { ## Validator for entrybox "Character" # @parm String string - New entrybox contents - # @return Bool - Allways 1 + # @return Bool - Always 1 public method char_ent_validator {string} { if {!$validation_ena} {return 1} set validation_ena 0 @@ -599,7 +628,7 @@ class AsciiChart { if {$length > 1} { $char_ent configure -style AsciiChart_RedFg.TEntry - } { + } else { $char_ent configure -style AsciiChart_BlueFg.TEntry } @@ -638,7 +667,7 @@ class AsciiChart { # Empty input string set length [string length $string] if {!$length} { - $widget configure -bg {#FFFFFF} + $widget configure -style TEntry clear_entryboxes $type unselect_current_cell 0 0 set validation_ena 1 @@ -684,7 +713,7 @@ class AsciiChart { if {$string > 127 || $string < 0} { clear_entryboxes $type unselect_current_cell 0 0 - $widget configure -bg {#FFDDDD} + $widget configure -style AsciiChart_RedBg.TEntry set validation_ena 1 return 1 } @@ -692,7 +721,7 @@ class AsciiChart { # Adjust GUI (ACII chart and details frame) select_cell $string fill_entryboxes $string $type - $widget configure -bg {#DDFFDD} + $widget configure -style AsciiChart_GreenBg.TEntry return 1 } @@ -710,14 +739,14 @@ class AsciiChart { if {$type == {C}} { set widget $caret_not_ent set index 1 - } { + } else { set widget $escape_seq_ent set index 2 } # Empty input string if {![string length $string]} { - $widget configure -bg {#FFFFFF} + $widget configure -style TEntry clear_entryboxes $type unselect_current_cell 0 0 set validation_ena 1 @@ -736,7 +765,7 @@ class AsciiChart { select_cell $i fill_entryboxes $i $type - $widget configure -bg {#DDFFDD} + $widget configure -style AsciiChart_GreenBg.TEntry set validation_ena 1 return 1 } @@ -745,8 +774,12 @@ class AsciiChart { # String not found clear_entryboxes $type unselect_current_cell 0 0 - $widget configure -bg {#FFDDDD} + $widget configure -style AsciiChart_RedBg.TEntry set validation_ena 1 return 1 } } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/utilities/baseconverter.tcl b/lib/utilities/baseconverter.tcl new file mode 100644 index 0000000..82d656a --- /dev/null +++ b/lib/utilities/baseconverter.tcl @@ -0,0 +1,952 @@ +#!/usr/bin/tclsh +# Part of MCU 8051 IDE ( http://mcu8051ide.sf.net ) + +############################################################################ +# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera # +# 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 _BASECONVERTER_TCL ] } { +set _BASECONVERTER_TCL _ +# <<< File inclusion guard + + +# -------------------------------------------------------------------------- +# DESCRIPTION +# Utility "Base Converter" +# -------------------------------------------------------------------------- + +class BaseConverter { + ## COMMON + common base_c_count 0 ;# Int: Counter of class instances + common INITIAL_HEIGHT 130 ;# Int: Initial heightof the window in pixels + common INITIAL_WIDTH 150 ;# Int: Initial width of the window in pixels + common EXTENDED_WIDTH 340 ;# Int: Width of the window when it is in extended mode + + # On MS Windows these values has to be a bit different + if {$::MICROSOFT_WINDOWS} { + set INITIAL_HEIGHT 125 + set INITIAL_WIDTH 165 + set EXTENDED_WIDTH 355 + } + # Font entryboxes + common entry_font [font create \ + -size -12 \ + -family $::DEFAULT_FIXED_FONT \ + -weight bold \ + ] + + ## PRIVATE + private variable win ;# Widget: Window + private variable win_obj ;# Object: Window object + + private variable less_more_button ;# Widget: Button "Less/More" + private variable enlarge_shrink_button ;# Widget: Button "Enlarge/Shrink" + + private variable right_top_frame ;# Widget: Right top frame + private variable left_top_frame ;# Widget: Left top frame + + private variable less_more 0 ;# Bool: Mode flag "More" + private variable large 0 ;# Bool: Flag enlarged + + private variable left_rows_created 0 ;# Int: Number of created rows in the left frame + private variable right_rows_created 0 ;# Int: Number of created rows in the right frame + + private variable validation_in_progress 0 ;# Bool: Validation procedure in progress + + private variable val_to_set [list {} {} {}] ;# List: Decimal values to set in the bottom 3 entryboxes after enlarge + + private variable entry_h ;# Array of Widget: Entrybox "HEX", index is row (starting from 0) + private variable entry_d ;# Array of Widget: Entrybox "DEC", index is row (starting from 0) + private variable entry_b ;# Array of Widget: Entrybox "BIN", index is row (starting from 0) + private variable entry_o ;# Array of Widget: Entrybox "OCT", index is row (starting from 0) + private variable entry_t ;# Array of Widget: Canvas containing bits + private variable entry_c0 ;# Array of Widget: Entrybox "BCD L", index is row (starting from 0) + private variable entry_c1 ;# Array of Widget: Entrybox "BCD H", index is row (starting from 0) + private variable entry_a ;# Array of Widget: Entrybox "ASCII", index is row (starting from 0) + private variable bit ;# CanvasObject: bit rectangle, $bit(row_number,bit_number) + + ## Object constructor + constructor {} { + # Configure ttk styles + if {!$base_c_count} { + ttk::style configure BaseConverter_Focused_D.TEntry -fieldbackground {#AAAAFF} + ttk::style configure BaseConverter_Focused_I.TEntry -fieldbackground {#DDDDFF} + ttk::style configure BaseConverter_NotFocused.TEntry + } + + incr base_c_count + + create_window + create_gui + } + + ## Object destructor + destructor { + } + + ## Commence a new configuration + # @parm List conf_list - Configuration list previously returned by proc. "get_config" + # @return void + public method set_config {conf_list} { + # Set window position + $win_obj geometry \ + {} {} \ + [lindex $conf_list {0 2}] \ + [lindex $conf_list {0 3}] + + # Adjust modes + if {[lindex $conf_list 2]} { + less_more + } + if {[lindex $conf_list 3]} { + enlarge_shrink + } + + # Fill in the entryboxes + for {set i 0} {$i < $left_rows_created} {incr i} { + validate {t} $i [lindex $conf_list [list 4 $i]] + } + if {$left_rows_created < 6} { + for {set i 0; set j 3} {$i < 3} {incr i; incr j} { + lset val_to_set $i [lindex $conf_list [list 4 $j]] + } + } + + # Adjust flag "Shaded" + if {[lindex $conf_list 1]} { + update + $win_obj collapse_expand + } + } + + ## Get configuration list + # @return List - Configuration list + public method get_config {} { + # Create list of current values in the entryboxes + set values {} + lappend values [$entry_d(0) get] [$entry_d(1) get] [$entry_d(2) get] + if {$left_rows_created > 3} { + lappend values \ + [$entry_d(3) get] \ + [$entry_d(4) get] \ + [$entry_d(5) get] + } else { + lappend values {} {} {} + } + + # Finalize configuration list + return [list \ + [$win_obj geometry] \ + [$win_obj get_minim_flag] \ + $less_more \ + $large \ + $values \ + ] + } + + ## Create window using class "InnerWindow" + # @return void + private method create_window {} { + set win_obj [InnerWindow #auto \ + .baseconverter_${base_c_count} \ + [list $INITIAL_WIDTH $INITIAL_HEIGHT 100 100] \ + [mc "Converter"] \ + ::ICONS::16::kaboodleloop \ + "$this close_window" \ + ] + set win [$win_obj get_frame] + } + + ## Create all window GUI + # @return void + private method create_gui {} { + # Create frames + set top_frame [frame $win.top_frame] + set left_top_frame [frame $top_frame.left_frame] + set right_top_frame [frame $top_frame.right_frame] + set bottom_frame [frame $win.bottom_frame] + + # Start in mode "Shirked" + !"More" + create_left_frame + + ## Create buttons in the bottom frame + # Button "Enlarge"/"Shrink" + set enlarge_shrink_button \ + [ttk::button $bottom_frame.enlarge_shrink_button \ + -text [mc "Enlarge"] \ + -compound left \ + -image ::ICONS::16::1downarrow \ + -command "$this enlarge_shrink" \ + -width 7 \ + -style Flat.TButton \ + ] + pack $enlarge_shrink_button -side left -padx 2 -pady 2 + # Button "More"/"Less" + set less_more_button [ttk::button $bottom_frame.less_more_button\ + -text [mc "More"] \ + -compound right \ + -image ::ICONS::16::1rightarrow \ + -command "$this less_more" \ + -width 5 \ + -style Flat.TButton \ + ] + pack $less_more_button -side right -padx 2 -pady 2 + + # Pack frames + pack $left_top_frame -side left -anchor nw + pack $top_frame -fill both -expand 1 + pack $bottom_frame -fill x + + # Focus the firts hexadecimal entrybox + focus -force $entry_h(0) + } + + ## Close the window and forget configuration + # Calls proc. "::X::__base_converter_close" + # @return void + public method close_window {} { + ::X::__base_converter_close $this + $win_obj close_window + delete object $this + } + + ## Validator for entryboxes + # Can be used to set a certain value for a certain row in this way: + # validate {t} $row_number $decimal_value + # @parm Char type - Value source + # h - Hexadecimal + # d - Decimal + # b - Binary + # o - Octal + # c0 - BCD - Low order nibble + # c1 - BCD - High order nibble + # a - ASCII + # t - Bits (Do not validate, just accept) + # @parm Int row - Row number, starting at zero + # @parm String content - String to validate and evaluate + # @return Bool - 1 == Legal; 0 == Illegal + public method validate {type row content} { + # This method cannot be recursive in any way + if {$validation_in_progress} {return 1} + set validation_in_progress 1 + + # Local variables + set result 1 ;# Bool: Result of validation + set zero_length 0 ;# Bool: Zero length input string + set value {} ;# Mixed: Decimal representation the validate value or {} (no value) + + # Detect zero length input string + if {[string length $content]} { + set zero_length 0 + } else { + set zero_length 1 + set content 0 + } + + # Validate input string + switch -- $type { + {h} { ;# Hexadecimal + if {![regexp {^[[:xdigit:]]{0,2}$} $content]} { + set result 0 + } else { + scan $content "%x" value + } + } + {d} { ;# Decimal + if {![regexp {^[[:digit:]]{0,3}$} $content]} { + set result 0 + } elseif {$content > 255} { + set result 0 + } else { + set value $content + } + } + {b} { ;# Binary + if {![regexp {^[01]{0,8}$} $content]} { + set result 0 + } else { + set value [NumSystem::bin2dec $content] + } + } + {o} { ;# Octal + if {![regexp {^[0-7]{0,3}$} $content]} { + set result 0 + } elseif {$content > 377} { + set result 0 + } else { + scan $content "%o" value + } + } + {c0} { ;# BCD - Low order nibble + if {![regexp {^[[:digit:]]{0,2}$} $content]} { + set result 0 + } elseif {$content > 15} { + set result 0 + } else { + set value [$entry_c1($row) get] + if {![string length $value]} { + set value 0 + } + set value [expr {$content + ($value << 4)}] + } + set zero_length 0 + } + {c1} { ;# BCD - High order nibble + if {![regexp {^[[:digit:]]{0,2}$} $content]} { + set result 0 + } elseif {$content > 15} { + set result 0 + } else { + set value [$entry_c0($row) get] + if {![string length $value]} { + set value 0 + } + set value [expr {$value + ($content << 4)}] + } + set zero_length 0 + } + {a} { ;# ASCII + if {$zero_length} { + set content {} + } + set zero_length 0 + + if {[string length $content] > 1} { + set result 0 + } else { + set value [NumSystem::ascii2dec $content] + } + + if {![string length $value]} { + set value [$entry_d($row) get] + if {![string length $value]} { + set zero_length 1 + } + } + } + {t} { ;# Bits (Do not validate, just accept) + set value $content + } + } + + # Synchronize with the other entryboxes on the row + if {$result} { + fill_entryboxes $row $value $zero_length $type + } + + # Finish ... + set validation_in_progress 0 + return $result + } + + ## Synchronize the specified value with the other entryboxes on the row + # @parm Int row - Row number + # @parm Int value - Value to fill in (in decimal) + # @parm Bool zero_length - Just clear all entryboxes + # @parm Char exclude - Entrybox to exclude during filling + # h - Hexadecimal + # d - Decimal + # b - Binary + # o - Octal + # c0 - BCD - Low order nibble + # c1 - BCD - High order nibble + # a - ASCII + # t - No meaning ... + # @return void + private method fill_entryboxes {row value zero_length exclude} { + # Clear entryboxes on the left + foreach w [list \ + $entry_h($row) $entry_d($row) \ + $entry_b($row) $entry_o($row) \ + ] t { + h d + b o + } \ + { + if {$exclude == $t} { + continue + } + $w delete 0 end + } + + # Fill in entryboxes on the left + if {!$zero_length} { + if {$exclude != {h}} { + $entry_h($row) insert 0 [format {%X} $value] + } + if {$exclude != {d}} { + $entry_d($row) insert 0 $value + } + if {$exclude != {b}} { + $entry_b($row) insert 0 [NumSystem::dec2bin $value] + } + if {$exclude != {o}} { + $entry_o($row) insert 0 [format {%o} $value] + } + } + + if {$row < $right_rows_created} { + # Clear entryboxes on the right + foreach w [list $entry_c0($row) $entry_c1($row) $entry_a($row)] \ + t {c0 c1 a} \ + { + if {$exclude == $t} { + continue + } + + $w delete 0 end + } + + # Adjust canvas widget with bit rectangles + set mask 1 + for {set i 0} {$i < 8} {incr i} { + if {$zero_length} { + set fill {#FFFFFF} + set outline {#888888} + } elseif {[expr $value & $mask]} { + set fill ${::BitMap::one_fill} + set outline ${::BitMap::one_outline} + } else { + set fill ${::BitMap::zero_fill} + set outline ${::BitMap::zero_outline} + } + + $entry_t($row) itemconfigure $bit($row,$i) \ + -fill $fill -outline $outline + + set mask [expr {$mask << 1}] + } + + # Fill in entryboxes on the right + if {!$zero_length} { + if {$exclude != {c0}} { + $entry_c0($row) insert 0 [expr {$value & 0x0F}] + } + if {$exclude != {c1}} { + $entry_c1($row) insert 0 [expr {$value >> 4}] + } + if {$exclude != {a}} { + if {$value > 31 && $value < 127} { + $entry_a($row) insert 0 [format {%c} $value] + } + } + } + } + } + + ## Handles event on canvas widget with bits, + # @parm Int r - Row number (0..5) + # @parm Int b - Bit number (0..7) + # @return void + public method bit_enter {r b} { + # Determinate current rectangle fill and outline + set fill [$entry_t($r) itemcget $bit($r,$b) -fill] + set outline [$entry_t($r) itemcget $bit($r,$b) -outline] + + # Determinate new rectangle fill and outline + if {$fill == ${::BitMap::one_fill}} { + set fill ${::BitMap::one_a_fill} + set outline ${::BitMap::one_a_outline} + } elseif {$fill == ${::BitMap::zero_fill}} { + set fill ${::BitMap::zero_a_fill} + set outline ${::BitMap::zero_a_outline} + } + + # Set new rectangle fill and outline and adjust cursor + $entry_t($r) itemconfigure $bit($r,$b) \ + -fill $fill -outline $outline + $entry_t($r) configure -cursor hand2 + } + + ## Handles event on canvas widget with bits, + # @parm Int r - Row number (0..5) + # @parm Int b - Bit number (0..7) + # @return void + public method bit_leave {r b} { + # Determinate current rectangle fill and outline + set fill [$entry_t($r) itemcget $bit($r,$b) -fill] + set outline [$entry_t($r) itemcget $bit($r,$b) -outline] + + # Determinate new rectangle fill and outline + if {$fill == ${::BitMap::one_a_fill}} { + set fill ${::BitMap::one_fill} + set outline ${::BitMap::one_outline} + } elseif {$fill == ${::BitMap::zero_a_fill}} { + set fill ${::BitMap::zero_fill} + set outline ${::BitMap::zero_outline} + } + + # Set new rectangle fill and outline and adjust cursor + $entry_t($r) itemconfigure $bit($r,$b) \ + -fill $fill -outline $outline + $entry_t($r) configure -cursor left_ptr + } + + ## Handles event on canvas widget with bits, + # @parm Int r - Row number (0..5) + # @parm Int b - Bit number (0..7) + # @return void + public method bit_click {r b} { + # Determinate current rectangle fill + set fill [$entry_t($r) itemcget $bit($r,$b) -fill] + + # Determinate new bit value + if { + $fill == ${::BitMap::one_a_fill} + || + $fill == ${::BitMap::one_fill} + } then { + set value 0 + } else { + set value [expr {1 << $b}] + } + + # Determinate new value for the whole row + set dec [$entry_d($r) get] + if {![string length $dec]} { + set dec 0 + } + set dec [expr {$dec & (0x0FF ^ (1 << $b))}] + incr dec $value + + # Set new value for the whole row + validate {t} $r $dec + } + + ## Set envent binds specific to this appliaction for the specified entrybox + # @parm Widget w - Entrybox widget + # @parm Char t - Entrybox type + # h - Hexadecimal + # d - Decimal + # b - Binary + # o - Octal + # c0 - BCD - Low order nibble + # c1 - BCD - High order nibble + # a - ASCII + # @parm Int r - Row number (0..5) + # @return void + private method set_bindings_for_an_entrybox {w t r} { + bind $w "$this entry_key $t $r u; break" + bind $w "$this entry_key $t $r d; break" + bind $w "$this entry_key $t $r l; break" + bind $w "$this entry_key $t $r r; break" + bind $w "$this entry_key $t $r t; break" + if {!$::MICROSOFT_WINDOWS} { + bind $w "$this entry_key $t $r s; break" + } + bind $w "$this entry_key $t $r e; break" + bind $w "$this entry_key $t $r e; break" + + bind $w "$this entry_focus $t $r 1" + bind $w "$this entry_focus $t $r 0" + } + + ## Create the left frame of the window + # @return void + private method create_left_frame {} { + # Create labels + if {!$left_rows_created} { + set col 1 + foreach text { + {HEX} {DEC} {BIN} {OCT} + } { + grid [label $left_top_frame.header_lbl_${col} \ + -font $::smallfont -text [mc $text] -pady 0 \ + ] -pady 0 -ipady 0 -row 1 -column $col + incr col + } + } + + # Create entryboxes + set row 0 + for {set row $left_rows_created} {$row < ($large ? 6 : 3)} {incr row} { + set col 1 + foreach width { + 2 3 8 3 + } type { + h d b o + } \ + { + set entry_wgd [ttk::entry $left_top_frame.e_${type}_$row \ + -width $width \ + -validate key \ + -validatecommand "$this validate $type $row %P" \ + -style BaseConverter_NotFocused.TEntry \ + -font $entry_font \ + ] + set entry_${type}($row) $entry_wgd + grid $entry_wgd -row [expr {$row + 2}] -column $col + + set_bindings_for_an_entrybox $entry_wgd $type $row + + incr col + } + } + set left_rows_created $row + + if {$large} { + for {set i 0; set j 3} {$i < 3} {incr i; incr j} { + validate {t} $j [lindex $val_to_set $i] + } + } + } + + ## Create the left frame of the window + # @return void + private method create_right_frame {} { + # Create labels + if {!$right_rows_created} { + set col 1 + grid [label $right_top_frame.header_lbl_${col} \ + -font $::smallfont -text [mc "Bits"] -pady 0 \ + ] -pady 0 -ipady 0 -row 1 -column $col + incr col + grid [label $right_top_frame.header_lbl_${col} \ + -font $::smallfont -text [mc "BCD"] -pady 0 \ + ] -pady 0 -ipady 0 -row 1 -column $col -columnspan 2 + incr col 2 + grid [label $right_top_frame.header_lbl_${col} \ + -font $::smallfont -text [mc "ASCII"] -pady 0\ + ] -pady 0 -ipady 0 -row 1 -column $col + incr col + } + + # Create entryboxes and canvas widget + set row 0 + for {set row $right_rows_created} {$row < ($large ? 6 : 3)} {incr row} { + set col 1 + foreach type { + t c a + } \ + { + switch -- $type { + {a} { ;# ASCII + set entry_wgd [ttk::entry $right_top_frame.e_${type}_$row \ + -width 2 \ + -validate all \ + -validatecommand "$this validate ${type} $row %P" \ + -style BaseConverter_NotFocused.TEntry \ + -font $entry_font \ + ] + set entry_${type}($row) $entry_wgd + grid $entry_wgd -row [expr {$row + 2}] -column $col + set_bindings_for_an_entrybox $entry_wgd $type $row + } + {c} { ;# BCD + set entry_wgd [ttk::entry $right_top_frame.e_${type}1_$row \ + -width 2 \ + -validate all \ + -validatecommand "$this validate ${type}1 $row %P" \ + -style BaseConverter_NotFocused.TEntry \ + -font $entry_font \ + ] + set entry_${type}1($row) $entry_wgd + grid $entry_wgd -row [expr {$row + 2}] -column $col + set_bindings_for_an_entrybox $entry_wgd "${type}1" $row + + incr col + + set entry_wgd [ttk::entry $right_top_frame.e_${type}0_$row \ + -width 2 \ + -validate all \ + -validatecommand "$this validate ${type}0 $row %P" \ + -style BaseConverter_NotFocused.TEntry \ + -font $entry_font \ + ] + set entry_${type}0($row) $entry_wgd + grid $entry_wgd -row [expr {$row + 2}] -column $col + set_bindings_for_an_entrybox $entry_wgd "${type}0" $row + } + {t} { ;# Bits + set x0 2 + + set y0 0 + set y1 2 + + + set canvas [canvas $right_top_frame.canvas_${row} \ + -width 118 -height 18 -bd 0 -bg white \ + -relief flat -highlightthickness 0 \ + ] + grid $canvas -row [expr {$row + 2}] -column $col + set entry_${type}($row) $canvas + + for {set b 7} {$b >= 0} {incr b -1} { + + # Create bit rectagle + set bit($row,$b) [$canvas create \ + rectangle $x0 $y1 \ + [expr {$x0 + 12}] \ + [expr {$y1 + 12}] \ + -fill {#FFFFFF} \ + -outline {#888888} \ + ] + + $canvas bind $bit($row,$b) "$this bit_enter $row $b" + $canvas bind $bit($row,$b) "$this bit_leave $row $b" + $canvas bind $bit($row,$b) "$this bit_click $row $b" + + # Adjust X position for the next rectagle + incr x0 14 + if {$b == 4} { + incr x0 3 + } + } + } + } + + incr col + } + } + set right_rows_created $row + } + + ## Switch between modes "Enlarged" and "Shrinked" + # @return void + public method enlarge_shrink {} { + # Invert the mode flag + set large [expr {!$large}] + + # Adjust buttons on the bottom bar and create the missing widgets if nessesary + if {$large} { + create_right_frame + create_left_frame + $win_obj geometry {} [expr {[winfo height $entry_h(0)] * 3 + $INITIAL_HEIGHT}] {} {} + $enlarge_shrink_button configure \ + -image ::ICONS::16::1uparrow \ + -text [mc "Shrink"] + } else { + $win_obj geometry {} $INITIAL_HEIGHT {} {} + $enlarge_shrink_button configure \ + -image ::ICONS::16::1downarrow \ + -text [mc "Enlarge"] + + for {set i 0; set j 3} {$i < 3} {incr i; incr j} { + lset val_to_set $i [$entry_d($j) get] + } + } + + # Show or hide appropriate GUI elements + foreach w [list \ + entry_h entry_d entry_b \ + entry_o entry_t entry_c1\ + entry_c0 entry_a \ + ] c { + 1 2 3 + 4 1 2 + 3 4 + } { + for {set i 3; set r 5} {$i < 6} {incr i; incr r} { + if {$large} { + grid [subst -nocommands "\$${w}($i)"] -column $c -row $r + } else { + grid forget [subst -nocommands "\$${w}($i)"] + } + } + } + + } + + ## Switch between modes "More" and "Less" + # @return void + public method less_more {} { + # Invert the mode flag + set less_more [expr {!$less_more}] + + # Adjust GUI + if {$less_more} { + create_right_frame + pack $right_top_frame -side left -anchor nw + $less_more_button configure \ + -compound left -text [mc "Less"] \ + -image ::ICONS::16::1leftarrow + $win_obj geometry $EXTENDED_WIDTH {} {} {} + + for {set i 0} {$i < $right_rows_created} {incr i} { + validate {t} $i [$entry_d($i) get] + } + } else { + pack forget $right_top_frame + $less_more_button configure \ + -compound right -text [mc "More"] \ + -image ::ICONS::16::1rightarrow + $win_obj geometry $INITIAL_WIDTH {} {} {} + } + } + + ## Entybox event handler for and + # Change entryboxes background colors + # @parm Char type - Entrybox type + # h - Hexadecimal + # d - Decimal + # b - Binary + # o - Octal + # c0 - BCD - Low order nibble + # c1 - BCD - High order nibble + # a - ASCII + # @parm Int row - Row number (0..5) + # @parm Bool focused - 1 == ; 0 == + # @return void + public method entry_focus {type row focused} { + if {$focused} { + set style BaseConverter_Focused_I.TEntry + set bg {#DDDDFF} + } else { + set style BaseConverter_NotFocused.TEntry + set bg {#FFFFFF} + } + + foreach w [list \ + $entry_h($row) $entry_d($row) \ + $entry_b($row) $entry_o($row) \ + ] \ + { + $w configure -style $style + } + + if {$right_rows_created > $row} { + foreach w [list \ + $entry_c1($row) \ + $entry_c0($row) \ + $entry_a($row) \ + ] \ + { + $w configure -style $style + } + + $entry_t($row) configure -bg $bg + } + + if {$focused} { + [subst -nocommands "\$entry_${type}($row)"] configure -style BaseConverter_Focused_D.TEntry + } else { + [subst -nocommands "\$entry_${type}($row)"] selection clear + } + + } + + + ## Entybox event handler for , , , , , + #+ , and + # @parm Char type - Entrybox type + # h - Hexadecimal + # d - Decimal + # b - Binary + # o - Octal + # c0 - BCD - Low order nibble + # c1 - BCD - High order nibble + # a - ASCII + # @parm Int y - Row number (0..5) + # @parm Char key - Key pressed + # u - Up + # d - Down + # l - Left + # r - Right + # t - Tab + # s - Shift-Tab + # e - Enter + # @return void + public method entry_key {type y key} { + set entrybox [subst -nocommands "\$entry_${type}($y)"] + set insert [$entrybox index insert] + set max_y $left_rows_created + incr max_y -1 + switch -- $type { + {h} {set x 0} + {d} {set x 1} + {b} {set x 2} + {o} {set x 3} + {c1} {set x 4} + {c0} {set x 5} + {a} {set x 6} + } + + $entrybox selection clear + switch -- $key { + {u} { ;# Up + if {!$y} { + return + } + incr y -1 + } + {d} { ;# Down + if {$y == $max_y} { + return + } + incr y + } + {l} { ;# Left + if {!$x || $insert} { + $entrybox icursor [expr {$insert-1}] + return + } + incr x -1 + } + {r} { ;# Right + if {($x == 6) || ($insert != [$entrybox index end])} { + $entrybox icursor [expr {$insert+1}] + return + } + incr x + } + {t} { ;# Tab + if {$x == 6} { + return + } + incr x + } + {s} { ;# Shift-Tab + if {!$x} { + return + } + incr x -1 + } + {e} { ;# Enter + if {$y == $max_y} { + return + } + incr y + } + } + + if {$x > 3 && $y >= $right_rows_created} { + return + } + + set insert [expr {[$entrybox index end] - $insert}] + switch -- $x { + {0} {set type h} + {1} {set type d} + {2} {set type b} + {3} {set type o} + {4} {set type c1} + {5} {set type c0} + {6} {set type a} + } + set entrybox [subst -nocommands "\$entry_${type}($y)"] + $entrybox selection range 0 end + $entrybox icursor [expr {[$entrybox index end] - $insert}] + focus $entrybox + } +} + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/utilities/baseconvertor.tcl b/lib/utilities/baseconvertor.tcl deleted file mode 100755 index ded53cb..0000000 --- a/lib/utilities/baseconvertor.tcl +++ /dev/null @@ -1,912 +0,0 @@ -#!/usr/bin/tclsh -# Part of MCU 8051 IDE ( http://mcu8051ide.sf.net ) - -############################################################################ -# Copyright (C) 2007-2009 by Martin Ošmera # -# 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. # -############################################################################ - - -# -------------------------------------------------------------------------- -# DESCRIPTION -# Utility "Base Convertor" -# -------------------------------------------------------------------------- - -class BaseConvertor { - ## COMMON - common count 0 ;# Int: Counter of class instances - - ## PRIVATE - private variable win ;# Widget: Window - private variable win_obj ;# Object: Window object - - private variable less_more_button ;# Widget: Button "Less/More" - private variable enlarge_shrink_button ;# Widget: Button "Enlarge/Shrink" - - private variable right_top_frame ;# Widget: Right top frame - private variable left_top_frame ;# Widget: Left top frame - - private variable less_more 0 ;# Bool: Mode flag "More" - private variable large 0 ;# Bool: Flag enlarged - - private variable left_rows_created 0 ;# Int: Number of created rows in the left frame - private variable right_rows_created 0 ;# Int: Number of created rows in the right frame - - private variable validation_in_progress 0 ;# Bool: Validation procedure in progress - - private variable val_to_set [list {} {} {}] ;# List: Decimal values to set in the bottom 3 entryboxes after enlarge - - private variable entry_h ;# Array of Widget: Entrybox "HEX", index is row (starting from 0) - private variable entry_d ;# Array of Widget: Entrybox "DEC", index is row (starting from 0) - private variable entry_b ;# Array of Widget: Entrybox "BIN", index is row (starting from 0) - private variable entry_o ;# Array of Widget: Entrybox "OCT", index is row (starting from 0) - private variable entry_t ;# Array of Widget: Canvas containing bits - private variable entry_c0 ;# Array of Widget: Entrybox "BCD L", index is row (starting from 0) - private variable entry_c1 ;# Array of Widget: Entrybox "BCD H", index is row (starting from 0) - private variable entry_a ;# Array of Widget: Entrybox "ASCII", index is row (starting from 0) - private variable bit ;# CanvasObject: bit rectangle, $bit(row_number,bit_number) - - ## Object constructor - constructor {} { - # Configure ttk styles - if {!$count} { - ttk::style configure BaseConvertor_Focused_D.TEntry -fieldbackground {#AAAAFF} - ttk::style configure BaseConvertor_Focused_I.TEntry -fieldbackground {#DDDDFF} - } - - incr count - - create_window - create_gui - } - - ## Object destructor - destructor { - } - - ## Commence a new configuration - # @parm List conf_list - Configuration list previously returned by proc. "get_config" - # @return void - public method set_config {conf_list} { - # Set window position - $win_obj geometry \ - {} {} \ - [lindex $conf_list {0 2}] \ - [lindex $conf_list {0 3}] - - # Adjust modes - if {[lindex $conf_list 2]} { - less_more - } - if {[lindex $conf_list 3]} { - enlarge_shrink - } - - # Fill in the entryboxes - for {set i 0} {$i < $left_rows_created} {incr i} { - validate {t} $i [lindex $conf_list [list 4 $i]] - } - if {$left_rows_created < 6} { - for {set i 0; set j 3} {$i < 3} {incr i; incr j} { - lset val_to_set $i [lindex $conf_list [list 4 $j]] - } - } - - # Adjust flag "Shaded" - if {[lindex $conf_list 1]} { - update - $win_obj collapse_expand - } - } - - ## Get configuration list - # @return List - Configuration list - public method get_config {} { - # Create list of current values in the entryboxes - set values {} - lappend values [$entry_d(0) get] [$entry_d(1) get] [$entry_d(2) get] - if {$left_rows_created > 3} { - lappend values \ - [$entry_d(3) get] \ - [$entry_d(4) get] \ - [$entry_d(5) get] - } { - lappend values {} {} {} - } - - # Finalize configuration list - return [list \ - [$win_obj geometry] \ - [$win_obj get_minim_flag] \ - $less_more \ - $large \ - $values \ - ] - } - - ## Create window using class "InnerWindow" - # @return void - private method create_window {} { - set win_obj [InnerWindow #auto \ - .baseconvertor_${count} \ - [list 160 130 100 100] \ - [mc "Convertor"] \ - ::ICONS::16::kaboodleloop \ - "$this close_window" \ - ] - set win [$win_obj get_frame] - } - - ## Create all window GUI - # @return void - private method create_gui {} { - # Create frames - set top_frame [frame $win.top_frame] - set left_top_frame [frame $top_frame.left_frame] - set right_top_frame [frame $top_frame.right_frame] - set bottom_frame [frame $win.bottom_frame] - - # Start in mode "Shirked" + !"More" - create_left_frame - - ## Create buttons in the bottom frame - # Button "Enlarge"/"Shrink" - set enlarge_shrink_button \ - [ttk::button $bottom_frame.enlarge_shrink_button \ - -text [mc "Enlarge"] \ - -compound left \ - -image ::ICONS::16::1downarrow \ - -command "$this enlarge_shrink" \ - -width 7 \ - ] - pack $enlarge_shrink_button -side left - # Button "More"/"Less" - set less_more_button [ttk::button $bottom_frame.less_more_button\ - -text [mc "More"] \ - -compound right \ - -image ::ICONS::16::1rightarrow \ - -command "$this less_more" \ - -width 5 \ - ] - pack $less_more_button -side right - - # Pack frames - pack $left_top_frame -side left -anchor nw - pack $top_frame -fill both -expand 1 - pack $bottom_frame -fill x - - # Focus the firts hexadecimal entrybox - focus -force $entry_h(0) - } - - ## Close the window and forget configuration - # Calls proc. "::X::__base_convertor_close" - # @return void - public method close_window {} { - ::X::__base_convertor_close $this - $win_obj close_window - delete object $this - } - - ## Validator for entryboxes - # Can be used to set a certain value for a certain row in this way: - # validate {t} $row_number $decimal_value - # @parm Char type - Value source - # h - Hexadecimal - # d - Decimal - # b - Binary - # o - Octal - # c0 - BCD - Low order nibble - # c1 - BCD - High order nibble - # a - ASCII - # t - Bits (Do not validate, just accept) - # @parm Int row - Row number, starting at zero - # @parm String content - String to validate and evaluate - # @return Bool - 1 == Legal; 0 == Illegal - public method validate {type row content} { - # This method cannot be recursive in any way - if {$validation_in_progress} {return 1} - set validation_in_progress 1 - - # Local variables - set result 1 ;# Bool: Result of validation - set zero_length 0 ;# Bool: Zero length input string - set value {} ;# Mixed: Decimal representation the validate value or {} (no value) - - # Detect zero length input string - if {[string length $content]} { - set zero_length 0 - } { - set zero_length 1 - set content 0 - } - - # Validate input string - switch -- $type { - {h} { ;# Hexadecimal - if {![regexp {^[[:xdigit:]]{0,2}$} $content]} { - set result 0 - } { - scan $content "%x" value - } - } - {d} { ;# Decimal - if {![regexp {^[[:digit:]]{0,3}$} $content]} { - set result 0 - } elseif {$content > 255} { - set result 0 - } { - set value $content - } - } - {b} { ;# Binary - if {![regexp {^[01]{0,8}$} $content]} { - set result 0 - } { - set value [NumSystem::bin2dec $content] - } - } - {o} { ;# Octal - if {![regexp {^[0-7]{0,3}$} $content]} { - set result 0 - } elseif {$content > 377} { - set result 0 - } { - scan $content "%o" value - } - } - {c0} { ;# BCD - Low order nibble - if {![regexp {^[[:digit:]]{0,2}$} $content]} { - set result 0 - } elseif {$content > 15} { - set result 0 - } { - set value [$entry_c1($row) get] - if {![string length $value]} { - set value 0 - } - set value [expr {$content + ($value << 4)}] - } - set zero_length 0 - } - {c1} { ;# BCD - High order nibble - if {![regexp {^[[:digit:]]{0,2}$} $content]} { - set result 0 - } elseif {$content > 15} { - set result 0 - } { - set value [$entry_c0($row) get] - if {![string length $value]} { - set value 0 - } - set value [expr {$value + ($content << 4)}] - } - set zero_length 0 - } - {a} { ;# ASCII - if {$zero_length} { - set content {} - } - set zero_length 0 - - if {[string length $content] > 1} { - set result 0 - } { - set value [NumSystem::ascii2dec $content] - } - - if {![string length $value]} { - set value [$entry_d($row) get] - if {![string length $value]} { - set zero_length 1 - } - } - } - {t} { ;# Bits (Do not validate, just accept) - set value $content - } - } - - # Synchronize with the other entryboxes on the row - if {$result} { - fill_entryboxes $row $value $zero_length $type - } - - # Finish ... - set validation_in_progress 0 - return $result - } - - ## Synchronize the specified value with the other entryboxes on the row - # @parm Int row - Row number - # @parm Int value - Value to fill in (in decimal) - # @parm Bool zero_length - Just clear all entryboxes - # @parm Char exclude - Entrybox to exclude during filling - # h - Hexadecimal - # d - Decimal - # b - Binary - # o - Octal - # c0 - BCD - Low order nibble - # c1 - BCD - High order nibble - # a - ASCII - # t - No meaning ... - # @return void - private method fill_entryboxes {row value zero_length exclude} { - # Clear entryboxes on the left - foreach w [list \ - $entry_h($row) $entry_d($row) \ - $entry_b($row) $entry_o($row) \ - ] t { - h d - b o - } \ - { - if {$exclude == $t} { - continue - } - $w delete 0 end - } - - # Fill in entryboxes on the left - if {!$zero_length} { - if {$exclude != {h}} { - $entry_h($row) insert 0 [format {%X} $value] - } - if {$exclude != {d}} { - $entry_d($row) insert 0 $value - } - if {$exclude != {b}} { - $entry_b($row) insert 0 [NumSystem::dec2bin $value] - } - if {$exclude != {o}} { - $entry_o($row) insert 0 [format {%o} $value] - } - } - - if {$row < $right_rows_created} { - # Clear entryboxes on the right - foreach w [list $entry_c0($row) $entry_c1($row) $entry_a($row)] \ - t {c0 c1 a} \ - { - if {$exclude == $t} { - continue - } - - $w delete 0 end - } - - # Adjust canvas widget with bit rectangles - set mask 1 - for {set i 0} {$i < 8} {incr i} { - if {$zero_length} { - set fill {#FFFFFF} - set outline {#888888} - } elseif {[expr $value & $mask]} { - set fill ${::BitMap::one_fill} - set outline ${::BitMap::one_outline} - } { - set fill ${::BitMap::zero_fill} - set outline ${::BitMap::zero_outline} - } - - $entry_t($row) itemconfigure $bit($row,$i) \ - -fill $fill -outline $outline - - set mask [expr {$mask << 1}] - } - - # Fill in entryboxes on the right - if {!$zero_length} { - if {$exclude != {c0}} { - $entry_c0($row) insert 0 [expr {$value & 0x0F}] - } - if {$exclude != {c1}} { - $entry_c1($row) insert 0 [expr {$value >> 4}] - } - if {$exclude != {a}} { - if {$value > 31 && $value < 127} { - $entry_a($row) insert 0 [format {%c} $value] - } - } - } - } - } - - ## Handles event on canvas widget with bits, - # @parm Int r - Row number (0..5) - # @parm Int b - Bit number (0..7) - # @return void - public method bit_enter {r b} { - # Determinate current rectangle fill and outline - set fill [$entry_t($r) itemcget $bit($r,$b) -fill] - set outline [$entry_t($r) itemcget $bit($r,$b) -outline] - - # Determinate new rectangle fill and outline - if {$fill == ${::BitMap::one_fill}} { - set fill ${::BitMap::one_a_fill} - set outline ${::BitMap::one_a_outline} - } elseif {$fill == ${::BitMap::zero_fill}} { - set fill ${::BitMap::zero_a_fill} - set outline ${::BitMap::zero_a_outline} - } - - # Set new rectangle fill and outline and adjust cursor - $entry_t($r) itemconfigure $bit($r,$b) \ - -fill $fill -outline $outline - $entry_t($r) configure -cursor hand1 - } - - ## Handles event on canvas widget with bits, - # @parm Int r - Row number (0..5) - # @parm Int b - Bit number (0..7) - # @return void - public method bit_leave {r b} { - # Determinate current rectangle fill and outline - set fill [$entry_t($r) itemcget $bit($r,$b) -fill] - set outline [$entry_t($r) itemcget $bit($r,$b) -outline] - - # Determinate new rectangle fill and outline - if {$fill == ${::BitMap::one_a_fill}} { - set fill ${::BitMap::one_fill} - set outline ${::BitMap::one_outline} - } elseif {$fill == ${::BitMap::zero_a_fill}} { - set fill ${::BitMap::zero_fill} - set outline ${::BitMap::zero_outline} - } - - # Set new rectangle fill and outline and adjust cursor - $entry_t($r) itemconfigure $bit($r,$b) \ - -fill $fill -outline $outline - $entry_t($r) configure -cursor left_ptr - } - - ## Handles event on canvas widget with bits, - # @parm Int r - Row number (0..5) - # @parm Int b - Bit number (0..7) - # @return void - public method bit_click {r b} { - # Determinate current rectangle fill - set fill [$entry_t($r) itemcget $bit($r,$b) -fill] - - # Determinate new bit value - if { - $fill == ${::BitMap::one_a_fill} - || - $fill == ${::BitMap::one_fill} - } then { - set value 0 - } else { - set value [expr {1 << $b}] - } - - # Determinate new value for the whole row - set dec [$entry_d($r) get] - if {![string length $dec]} { - set dec 0 - } - set dec [expr {$dec & (0x0FF ^ (1 << $b))}] - incr dec $value - - # Set new value for the whole row - validate {t} $r $dec - } - - ## Set envent binds specific to this appliaction for the specified entrybox - # @parm Widget w - Entrybox widget - # @parm Char t - Entrybox type - # h - Hexadecimal - # d - Decimal - # b - Binary - # o - Octal - # c0 - BCD - Low order nibble - # c1 - BCD - High order nibble - # a - ASCII - # @parm Int r - Row number (0..5) - # @return void - private method set_bindings_for_an_entrybox {w t r} { - bind $w "$this entry_key $t $r u; break" - bind $w "$this entry_key $t $r d; break" - bind $w "$this entry_key $t $r l; break" - bind $w "$this entry_key $t $r r; break" - bind $w "$this entry_key $t $r t; break" - if {!$::MICROSOFT_WINDOWS} { - bind $w "$this entry_key $t $r s; break" - } - bind $w "$this entry_key $t $r e; break" - bind $w "$this entry_key $t $r e; break" - - bind $w "$this entry_focus $t $r 1" - bind $w "$this entry_focus $t $r 0" - } - - ## Create the left frame of the window - # @return void - private method create_left_frame {} { - # Create labels - if {!$left_rows_created} { - set col 1 - foreach text { - {HEX} {DEC} {BIN} {OCT} - } { - grid [label $left_top_frame.header_lbl_${col} \ - -font $::smallfont -text [mc $text] -pady 0 \ - ] -pady 0 -ipady 0 -row 1 -column $col - incr col - } - } - - # Create entryboxes - set row 0 - for {set row $left_rows_created} {$row < ($large ? 6 : 3)} {incr row} { - set col 1 - foreach width { - 2 3 8 3 - } type { - h d b o - } \ - { - set entry_wgd [ttk::entry $left_top_frame.e_${type}_$row \ - -width $width \ - -validate key \ - -validatecommand "$this validate $type $row %P" \ - ] - set entry_${type}($row) $entry_wgd - grid $entry_wgd -row [expr {$row + 2}] -column $col - - set_bindings_for_an_entrybox $entry_wgd $type $row - - incr col - } - } - set left_rows_created $row - - if {$large} { - for {set i 0; set j 3} {$i < 3} {incr i; incr j} { - validate {t} $j [lindex $val_to_set $i] - } - } - } - - ## Create the left frame of the window - # @return void - private method create_right_frame {} { - # Create labels - if {!$right_rows_created} { - set col 1 - grid [label $right_top_frame.header_lbl_${col} \ - -font $::smallfont -text [mc "Bits"] -pady 0 \ - ] -pady 0 -ipady 0 -row 1 -column $col - incr col - grid [label $right_top_frame.header_lbl_${col} \ - -font $::smallfont -text [mc "BCD"] -pady 0 \ - ] -pady 0 -ipady 0 -row 1 -column $col -columnspan 2 - incr col 2 - grid [label $right_top_frame.header_lbl_${col} \ - -font $::smallfont -text [mc "ASCII"] -pady 0\ - ] -pady 0 -ipady 0 -row 1 -column $col - incr col - } - - # Create entryboxes and canvas widget - set row 0 - for {set row $right_rows_created} {$row < ($large ? 6 : 3)} {incr row} { - set col 1 - foreach type { - t c a - } \ - { - switch -- $type { - {a} { ;# ASCII - set entry_wgd [ttk::entry $right_top_frame.e_${type}_$row \ - -width 2 \ - -validate all \ - -validatecommand "$this validate ${type} $row %P" \ - ] - set entry_${type}($row) $entry_wgd - grid $entry_wgd -row [expr {$row + 2}] -column $col - set_bindings_for_an_entrybox $entry_wgd $type $row - } - {c} { ;# BCD - set entry_wgd [ttk::entry $right_top_frame.e_${type}1_$row \ - -width 2 \ - -validate all \ - -validatecommand "$this validate ${type}1 $row %P" \ - ] - set entry_${type}1($row) $entry_wgd - grid $entry_wgd -row [expr {$row + 2}] -column $col - set_bindings_for_an_entrybox $entry_wgd "${type}1" $row - - incr col - - set entry_wgd [ttk::entry $right_top_frame.e_${type}0_$row \ - -width 2 \ - -validate all \ - -validatecommand "$this validate ${type}0 $row %P" \ - ] - set entry_${type}0($row) $entry_wgd - grid $entry_wgd -row [expr {$row + 2}] -column $col - set_bindings_for_an_entrybox $entry_wgd "${type}0" $row - } - {t} { ;# Bits - set x0 2 - - set y0 0 - set y1 2 - - - set canvas [canvas $right_top_frame.canvas_${row} \ - -width 118 -height 18 -bd 0 -bg white \ - -relief flat -highlightthickness 0 \ - ] - grid $canvas -row [expr {$row + 2}] -column $col - set entry_${type}($row) $canvas - - for {set b 7} {$b >= 0} {incr b -1} { - - # Create bit rectagle - set bit($row,$b) [$canvas create \ - rectangle $x0 $y1 \ - [expr {$x0 + 12}] \ - [expr {$y1 + 12}] \ - -fill {#FFFFFF} \ - -outline {#888888} \ - ] - - $canvas bind $bit($row,$b) "$this bit_enter $row $b" - $canvas bind $bit($row,$b) "$this bit_leave $row $b" - $canvas bind $bit($row,$b) "$this bit_click $row $b" - - # Adjust X position for the next rectagle - incr x0 14 - if {$b == 4} { - incr x0 3 - } - } - } - } - - incr col - } - } - set right_rows_created $row - } - - ## Switch between modes "Enlarged" and "Shrinked" - # @return void - public method enlarge_shrink {} { - # Invert the mode flag - set large [expr {!$large}] - - # Adjust buttons on the bottom bar and create the missing widgets if nessesary - if {$large} { - create_right_frame - create_left_frame - $win_obj geometry {} [expr {[winfo height $entry_h(0)] * 3 + 130}] {} {} - $enlarge_shrink_button configure \ - -image ::ICONS::16::1uparrow \ - -text [mc "Shrink"] - } { - $win_obj geometry {} 130 {} {} - $enlarge_shrink_button configure \ - -image ::ICONS::16::1downarrow \ - -text [mc "Enlarge"] - } - - # Show or hide appropriate GUI elements - foreach w [list \ - entry_h entry_d entry_b \ - entry_o entry_t entry_c1\ - entry_c0 entry_a \ - ] c { - 1 2 3 - 4 1 2 - 3 4 - } { - for {set i 3; set r 5} {$i < 6} {incr i; incr r} { - if {$large} { - grid [subst "\$${w}($i)"] -column $c -row $r - } { - grid forget [subst "\$${w}($i)"] - } - } - } - - } - - ## Switch between modes "More" and "Less" - # @return void - public method less_more {} { - # Invert the mode flag - set less_more [expr {!$less_more}] - - # Adjust GUI - if {$less_more} { - create_right_frame - pack $right_top_frame -side left -anchor nw - $less_more_button configure \ - -compound left -text [mc "Less"] \ - -image ::ICONS::16::1leftarrow - $win_obj geometry 350 {} {} {} - - for {set i 0} {$i < $right_rows_created} {incr i} { - validate {t} $i [$entry_d($i) get] - } - } { - pack forget $right_top_frame - $less_more_button configure \ - -compound right -text [mc "More"] \ - -image ::ICONS::16::1rightarrow - $win_obj geometry 160 {} {} {} - } - } - - ## Entybox event handler for and - # Change entryboxes background colors - # @parm Char type - Entrybox type - # h - Hexadecimal - # d - Decimal - # b - Binary - # o - Octal - # c0 - BCD - Low order nibble - # c1 - BCD - High order nibble - # a - ASCII - # @parm Int row - Row number (0..5) - # @parm Bool focused - 1 == ; 0 == - # @return void - public method entry_focus {type row focused} { - if {$focused} { - set style BaseConvertor_Focused_I.TEntry - set bg {#DDDDFF} - } { - set style TEntry - set bg {#FFFFFF} - } - - foreach w [list \ - $entry_h($row) $entry_d($row) \ - $entry_b($row) $entry_o($row) \ - ] \ - { - $w configure -style $style - } - - if {$right_rows_created > $row} { - foreach w [list \ - $entry_c1($row) \ - $entry_c0($row) \ - $entry_a($row) \ - ] \ - { - $w configure -style $style - } - - $entry_t($row) configure -bg $bg - } - - if {$focused} { - [subst "\$entry_${type}($row)"] configure -style BaseConvertor_Focused_D.TEntry - } { - [subst "\$entry_${type}($row)"] selection clear - } - - } - - - ## Entybox event handler for , , , , , - #+ , and - # @parm Char type - Entrybox type - # h - Hexadecimal - # d - Decimal - # b - Binary - # o - Octal - # c0 - BCD - Low order nibble - # c1 - BCD - High order nibble - # a - ASCII - # @parm Int y - Row number (0..5) - # @parm Char key - Key pressed - # u - Up - # d - Down - # l - Left - # r - Right - # t - Tab - # s - Shift-Tab - # e - Enter - # @return void - public method entry_key {type y key} { - set entrybox [subst "\$entry_${type}($y)"] - set insert [$entrybox index insert] - set max_y $left_rows_created - incr max_y -1 - switch -- $type { - {h} {set x 0} - {d} {set x 1} - {b} {set x 2} - {o} {set x 3} - {c1} {set x 4} - {c0} {set x 5} - {a} {set x 6} - } - - $entrybox selection clear - switch -- $key { - {u} { ;# Up - if {!$y} { - return - } - incr y -1 - } - {d} { ;# Down - if {$y == $max_y} { - return - } - incr y - } - {l} { ;# Left - if {!$x || $insert} { - $entrybox icursor [expr {$insert-1}] - return - } - incr x -1 - } - {r} { ;# Right - if {($x == 6) || ($insert != [$entrybox index end])} { - $entrybox icursor [expr {$insert+1}] - return - } - incr x - } - {t} { ;# Tab - if {$x == 6} { - return - } - incr x - } - {s} { ;# Shift-Tab - if {!$x} { - return - } - incr x -1 - } - {e} { ;# Enter - if {$y == $max_y} { - return - } - incr y - } - } - - if {$x > 3 && $y >= $right_rows_created} { - return - } - - set insert [expr {[$entrybox index end] - $insert}] - switch -- $x { - {0} {set type h} - {1} {set type d} - {2} {set type b} - {3} {set type o} - {4} {set type c1} - {5} {set type c0} - {6} {set type a} - } - set entrybox [subst "\$entry_${type}($y)"] - $entrybox selection range 0 end - $entrybox icursor [expr {[$entrybox index end] - $insert}] - focus $entrybox - } -} diff --git a/lib/utilities/eightsegment.tcl b/lib/utilities/eightsegment.tcl old mode 100755 new mode 100644 index de1903b..601d078 --- a/lib/utilities/eightsegment.tcl +++ b/lib/utilities/eightsegment.tcl @@ -2,7 +2,7 @@ # Part of MCU 8051 IDE ( http://mcu8051ide.sf.net ) ############################################################################ -# Copyright (C) 2007-2009 by Martin Ošmera # +# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera # # martin.osmera@gmail.com # # # # This program is free software; you can redistribute it and#or modify # @@ -21,13 +21,18 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################ +# >>> File inclusion guard +if { ! [ info exists _EIGHTSEGMENT_TCL ] } { +set _EIGHTSEGMENT_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # 8 segment LED display configurator # -------------------------------------------------------------------------- class EightSegment { - common count 0 ;# Int: Counter of object instances + common ld_ed_count 0 ;# Int: Counter of object instances private variable obj_idx ;# Int: Current object ID private variable win ;# Widget: Dialog window @@ -37,9 +42,9 @@ class EightSegment { private variable canvas_objects ;# Array: LED segments in canvas widget private variable validation_ena 1 ;# Bool: Entryboxs validation enabled - private variable cc_hex_entry ;# Widget: Entrybox "Common catode - Hex" - private variable cc_dec_entry ;# Widget: Entrybox "Common catode - Dec" - private variable cc_bin_entry ;# Widget: Entrybox "Common catode - Bin" + private variable cc_hex_entry ;# Widget: Entrybox "Common cathode - Hex" + private variable cc_dec_entry ;# Widget: Entrybox "Common cathode - Dec" + private variable cc_bin_entry ;# Widget: Entrybox "Common cathode - Bin" private variable ca_hex_entry ;# Widget: Entrybox "Common anode - Hex" private variable ca_dec_entry ;# Widget: Entrybox "Common anode - Dec" private variable ca_bin_entry ;# Widget: Entrybox "Common anode - Bin" @@ -49,9 +54,9 @@ class EightSegment { constructor {} { # Create dialog window - set win [toplevel .eightsegment$count -class {8 segment editor} -bg {#EEEEEE}] - set obj_idx $count - incr count + set win [toplevel .eightsegment${ld_ed_count} -class {8 segment editor} -bg ${::COMMON_BG_COLOR}] + set obj_idx $ld_ed_count + incr ld_ed_count # Restore last session for {set i 0} {$i < 8} {incr i} { @@ -75,7 +80,7 @@ class EightSegment { # Set window parameters wm iconphoto $win ::ICONS::16::8seg - wm title $win "8 segment editor" + wm title $win [mc "8 segment editor"] wm resizable $win 0 0 wm protocol $win WM_DELETE_WINDOW "::itcl::delete object $this" } @@ -100,7 +105,7 @@ class EightSegment { # Highlight ComboBoxes related to pins which are in confict for {set segment 0} {$segment < 8} {incr segment} { - set pin [subst "\$::EightSegment::con_${obj_idx}_$segment"] + set pin [subst -nocommands "\$::EightSegment::con_${obj_idx}_$segment"] set seg2pin($segment) $pin for {set i 0} {$i < 8} {incr i} { @@ -133,9 +138,9 @@ class EightSegment { ttk::style configure EightSegment_RedFg.TCombobox -foreground {#FF0000} ## Create entryboxes - # - Common catode + # - Common cathode set left_frame [frame $main_frame.left_frame] - grid [label $left_frame.header_CC_lbl -text [mc "Common catode"]] \ + grid [label $left_frame.header_CC_lbl -text [mc "Common cathode"]] \ -row 0 -column 0 -columnspan 4 -sticky w grid [label $left_frame.sub_header_CC_hex_lbl -text [mc "Hex:"]] \ -row 1 -column 1 -sticky w @@ -297,7 +302,7 @@ class EightSegment { -text [mc "Close"] \ -command "::itcl::delete object $this" \ -image ::ICONS::16::exit \ - ] -side right -pady 5 + ] -side right -pady 5 -padx 5 pack $status_bar -side left -fill x # Pack window frames @@ -315,11 +320,11 @@ class EightSegment { } ## Copy contents of the specified exntrybox to clipboard - # @parm Char common_electrode - C == Catode; A == Anode + # @parm Char common_electrode - C == Cathode; A == Anode # @parm Char radix - H == Hexadecimal; D == Decimal; B == Binary # @return void public method copy_contents {common_electrode radix} { - # Common catode + # Common cathode if {$common_electrode == {C}} { switch -- $radix { {H} {set widget ${cc_hex_entry}} @@ -327,7 +332,7 @@ class EightSegment { {B} {set widget ${cc_bin_entry}} } # Common anode - } { + } else { switch -- $radix { {H} {set widget ${ca_hex_entry}} {D} {set widget ${ca_dec_entry}} @@ -349,7 +354,7 @@ class EightSegment { } ## Value entrybox validator - # @parm Char common_electrode - C == Catode; A == Anode + # @parm Char common_electrode - C == Cathode; A == Anode # @parm Char radix - H == Hexadecimal; D == Decimal; B == Binary # @parm String value - String to validate # @return Bool - always 1 @@ -387,10 +392,19 @@ class EightSegment { } # Convert value to decimal - if {$radix == {H}} { - set value [expr "0x$value"] - } elseif {$radix == {B}} { - set value [::NumSystem::bin2dec $value] + switch -- $radix { + {H} { + set value [expr "0x$value"] + } + {B} { + set value [::NumSystem::bin2dec $value] + } + {D} { + set value [string trimleft $value 0] + if {$value == {}} { + set value 0 + } + } } # Adjust array $led() (LED states) @@ -400,7 +414,7 @@ class EightSegment { set leds($i) [expr {$value & $mask}] set mask [expr {$mask * 2}] } - } { + } else { set mask 1 for {set i 0} {$i < 8} {incr i} { set leds($i) [expr {!($value & $mask)}] @@ -422,7 +436,7 @@ class EightSegment { for {set i 0} {$i < 8} {incr i} { if {$leds($seg2pin($i))} { $canvas_widget itemconfigure $canvas_objects($i) -fill #FF0000 - } { + } else { $canvas_widget itemconfigure $canvas_objects($i) -fill #FFFFFF } } @@ -507,3 +521,7 @@ class EightSegment { } } set ::EightSegment::config $::CONFIG(EIGHT_SEG_EDITOR) + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/utilities/hexeditdlg.tcl b/lib/utilities/hexeditdlg.tcl old mode 100755 new mode 100644 index 42175f1..c18df59 --- a/lib/utilities/hexeditdlg.tcl +++ b/lib/utilities/hexeditdlg.tcl @@ -2,7 +2,7 @@ # Part of MCU 8051 IDE ( http://mcu8051ide.sf.net ) ############################################################################ -# Copyright (C) 2007-2009 by Martin Ošmera # +# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera # # martin.osmera@gmail.com # # # # This program is free software; you can redistribute it and#or modify # @@ -21,6 +21,11 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################ +# >>> File inclusion guard +if { ! [ info exists _HEXEDITDLG_TCL ] } { +set _HEXEDITDLG_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Prodides hexadecimal editor for external data and program memory. @@ -34,16 +39,16 @@ class HexEditDlg { common cell {0} ;# Current cell (0 - 0xFFFF) common current_view {left} ;# Focused view {left right} # Font for mode combobox - common mode_cb_font [font create \ - -family {Helvetica} \ - -size -17 \ - -weight bold \ + common mode_cb_font [font create \ + -family {Helvetica} \ + -size [expr {int(-17 * $::font_size_factor)}] \ + -weight bold \ ] # General normal size bold font - common bold_font [font create \ - -family $::DEFAULT_FIXED_FONT \ - -size -12 \ - -weight bold \ + common bold_font [font create \ + -family $::DEFAULT_FIXED_FONT \ + -size [expr {int(-12 * $::font_size_factor)}] \ + -weight bold \ ] # Status bar tips for main menu for XDATA mode common HELPFILE_XDATA { @@ -62,8 +67,8 @@ class HexEditDlg { {} {} {Invoke dialog for searching strings in the text} - {Find next occurence of the search string} - {Find previous occurence of the search string} + {Find next occurrence of the search string} + {Find previous occurrence of the search string} } { {Switch view mode to hexadecimal} {Switch view mode to decimal} @@ -86,8 +91,8 @@ class HexEditDlg { {} {} {Invoke dialog for searching strings in the text} - {Find next occurence of the search string} - {Find previous occurence of the search string} + {Find next occurrence of the search string} + {Find previous occurrence of the search string} } { {Switch view mode to hexadecimal} {Switch view mode to decimal} @@ -138,7 +143,7 @@ class HexEditDlg { set project $_project set type $_type set obj_idx $count - set win [toplevel .hexeditdlg${obj_idx} -class {Hex Editor} -bg {#EEEEEE}] + set win [toplevel .hexeditdlg${obj_idx} -class {Hex Editor} -bg ${::COMMON_BG_COLOR}] set loaded_lines [string repeat [string repeat 0 0xFF] 0xFF] incr count ;# Increment instance counter @@ -180,7 +185,7 @@ class HexEditDlg { if {$type == {code}} { if {[$project is_frozen]} { set state normal - } { + } else { set state disabled } @@ -199,7 +204,7 @@ class HexEditDlg { # Fill EntryBoxes if {$cell >= $capacity} { set current_cell [expr {$capacity - 1}] - } { + } else { set current_cell $cell } set value [$hexeditor get_values $current_cell $current_cell] @@ -208,7 +213,7 @@ class HexEditDlg { set validation_ena 1 # Pack dialog frames - pack $tool_bar_frame -fill x -anchor w + pack $tool_bar_frame -fill x -anchor w -padx 3 pack $middle_frame -anchor nw -after $tool_bar_frame -pady 10 pack $bottom_frame -anchor w -after $middle_frame pack $statusbar_frame -side bottom -fill x -after $bottom_frame @@ -235,7 +240,7 @@ class HexEditDlg { wm resizable $win 0 0 if {$mode == {hex}} { wm geometry $win ${win_pos} - } { + } else { wm geometry $win ${win_pos} } @@ -243,7 +248,7 @@ class HexEditDlg { wm iconphoto $win ::ICONS::16::$window_icon if {$type == {uni}} { wm protocol $win WM_DELETE_WINDOW "$this quit" - } { + } else { wm protocol $win WM_DELETE_WINDOW \ [list ::X::close_hexedit $type $project] } @@ -289,9 +294,9 @@ class HexEditDlg { ## Create menu widgets # Main set mainmenu [menu $win.mainmenu \ - -bd 0 -tearoff 0 -bg {#EEEEEE} \ + -bd 0 -tearoff 0 -bg ${::COMMON_BG_COLOR} \ -activeforeground {#6666FF} \ - -activebackground {#EEEEEE} \ + -activebackground ${::COMMON_BG_COLOR} \ ] set file_menu [menu $mainmenu.file_menu -tearoff 0] ;# Main -> File set edit_menu [menu $mainmenu.edit_menu -tearoff 0] ;# Main -> Edit @@ -307,71 +312,71 @@ class HexEditDlg { # Create File menu if {$type == {code}} { - $file_menu add command -label "Open ADF" -compound left \ + $file_menu add command -label [mc "Open ADF"] -compound left \ -command "$this opensim" -underline 0 \ -image ::ICONS::16::fileopen } - $file_menu add command -label "Open IHEX8" -compound left \ + $file_menu add command -label [mc "Open IHEX8"] -compound left \ -accelerator "Ctrl+O" -command "$this openhex" \ -image ::ICONS::16::fileopen -underline 1 $file_menu add separator - $file_menu add command -label "Save" -compound left \ + $file_menu add command -label [mc "Save"] -compound left \ -accelerator "Ctrl+S" -command "$this save" \ -image ::ICONS::16::filesave -underline 0 - $file_menu add command -label "Save as" -compound left \ + $file_menu add command -label [mc "Save as"] -compound left \ -accelerator "Ctrl+Shift+S" -command "$this saveas" \ -image ::ICONS::16::filesaveas -underline 1 $file_menu add separator if {$type != {code}} { - $file_menu add command -label "Reload" -compound left \ - -accelerator "F5" -command "$this reload" \ + $file_menu add command -label [mc "Reload"] -compound left \ + -accelerator "F5" -command "$this reload" \ -image ::ICONS::16::reload -underline 1 $file_menu add separator } - $file_menu add command -label "Exit" -compound left \ - -accelerator "Ctrl+Q" -command "$this quit" \ + $file_menu add command -label [mc "Exit"] -compound left \ + -accelerator "Ctrl+Q" -command "$this quit" \ -image ::ICONS::16::exit -underline 1 # Create Edit menu - $edit_menu add command -label "Copy" -compound left \ + $edit_menu add command -label [mc "Copy"] -compound left \ -accelerator "Ctrl+C" -command "$this text_copy" \ -image ::ICONS::16::editcopy -underline 0 - $edit_menu add command -label "Paste" -compound left \ + $edit_menu add command -label [mc "Paste"] -compound left \ -accelerator "Ctrl+V" -command "$this text_paste" \ -image ::ICONS::16::editpaste -underline 0 $edit_menu add separator - $edit_menu add command -label "Find" -compound left \ - -accelerator "Ctrl+F" -command "$this find_string 0" \ + $edit_menu add command -label [mc "Find"] -compound left \ + -accelerator "Ctrl+F" -command "$this find_string 0" \ -image ::ICONS::16::find -underline 0 - $edit_menu add command -label "Find next" -compound left \ - -accelerator "F3" -command "$this find_string 1" \ + $edit_menu add command -label [mc "Find next"] -compound left \ + -accelerator "F3" -command "$this find_string 1" \ -image ::ICONS::16::1downarrow -underline 5 - $edit_menu add command -label "Find previous" -compound left \ - -accelerator "Shift+F3" -command "$this find_string 2" \ + $edit_menu add command -label [mc "Find previous"] -compound left \ + -accelerator "Shift+F3" -command "$this find_string 2" \ -image ::ICONS::16::1uparrow -underline 8 # Create Mode menu set ::HexEditDlg::mode_${obj_idx} $mode - $mode_menu add radiobutton -label "HEX" \ + $mode_menu add radiobutton -label [mc "HEX"] \ -variable ::HexEditDlg::mode_${obj_idx} \ -indicatoron 0 -compound left -image ::ICONS::raoff \ -selectimage ::ICONS::raon -value {hex} -underline 0 \ -command [list $this adjust_mode] - $mode_menu add radiobutton -label "DEC" \ + $mode_menu add radiobutton -label [mc "DEC"] \ -variable ::HexEditDlg::mode_${obj_idx} \ -indicatoron 0 -compound left -image ::ICONS::raoff \ -selectimage ::ICONS::raon -value {dec} -underline 0 \ -command [list $this adjust_mode] - $mode_menu add radiobutton -label "OCT" \ + $mode_menu add radiobutton -label [mc "OCT"] \ -variable ::HexEditDlg::mode_${obj_idx} \ -indicatoron 0 -compound left -image ::ICONS::raoff \ -selectimage ::ICONS::raon -value {oct} -underline 0 \ -command [list $this adjust_mode] # Create Main menu - $mainmenu add cascade -label "File" -underline 0 -menu $file_menu - $mainmenu add cascade -label "Edit" -underline 0 -menu $edit_menu - $mainmenu add cascade -label "Mode" -underline 0 -menu $mode_menu + $mainmenu add cascade -label [mc "File"] -underline 0 -menu $file_menu + $mainmenu add cascade -label [mc "Edit"] -underline 0 -menu $edit_menu + $mainmenu add cascade -label [mc "Mode"] -underline 0 -menu $mode_menu $win configure -menu $mainmenu } @@ -462,8 +467,8 @@ class HexEditDlg { bind $wdg [list $this sbar_show {}] } - ## Create hexeditor and entryboxes for address and value - # @parm Widget middle_frame - Frame for hexeditor + ## Create hex editor and entryboxes for address and value + # @parm Widget middle_frame - Frame for hex editor # @parm Widget bottom_frame - Frame for entryboxes # @return void private method create_middle_bottom_frame {middle_frame bottom_frame} { @@ -475,7 +480,7 @@ class HexEditDlg { set hexeditor [HexEditor editor${obj_idx} $middle_frame 16 $hg 4 $mode 1 0 16 $capacity] if {$current_view == {left}} { $hexeditor focus_left_view - } { + } else { $hexeditor focus_right_view } $hexeditor setCurrentCell $cell @@ -535,7 +540,7 @@ class HexEditDlg { if {$type == {code}} { if {[$project is_frozen]} { set state normal - } { + } else { set state disabled } @@ -624,7 +629,7 @@ class HexEditDlg { $project rightPanel_watch_sync $hex_addr # Code memory - } { + } else { $project setCodeDEC $addr $val } } @@ -639,7 +644,7 @@ class HexEditDlg { set modified $bool if {$modified} { wm title $win "\[modified\] [wm title $win]" - } { + } else { wm title $win [string range [wm title $win] 11 end] } } @@ -647,7 +652,7 @@ class HexEditDlg { ## Parse given data (IHEX-8 and load it into the editor + sync with external components) # @parm String hex_data - input data - # @return void + # @return Bool - 1 == success; 0 == failure private method readHex {hex_data} { # Any EOL -> LF regsub -all {\r\n?} $hex_data "\n" hex_data @@ -657,7 +662,7 @@ class HexEditDlg { # Local variables set pointer 0 ;# Current address set line_number 0 ;# Number of the current line - set errors_count 0 ;# Number of errors occured while parsing ihex file + set errors_count 0 ;# Number of errors occurred while parsing ihex file set eof 0 ;# Bool: EOF detected set error_string {} ;# Text of error message @@ -736,7 +741,7 @@ class HexEditDlg { set number [string range $data $i $j] if {$type == {uni}} { $hexeditor setValue $pointer [expr "0x$number"] - } { + } else { write_to_simulator $pointer [expr "0x$number"] } incr pointer @@ -752,7 +757,7 @@ class HexEditDlg { # Invoke error dialog if {$errors_count} { # Create dialog window - set dialog [toplevel .error_message_dialog -bg {#EEEEEE}] + set dialog [toplevel $win.error_message_dialog -bg ${::COMMON_BG_COLOR}] # Create main frame (text widget and scrolbar) set main_frame [frame $dialog.main_frame] @@ -785,13 +790,16 @@ class HexEditDlg { # Set window attributes wm iconphoto $dialog ::ICONS::16::no - wm title $dialog [mc "Error(s) occured while parsing IHEX file"] + wm title $dialog [mc "Error(s) occurred while parsing IHEX file"] wm minsize $dialog 500 250 wm protocol $dialog WM_DELETE_WINDOW "grab release $dialog; destroy $dialog" wm transient $dialog $win grab $dialog raise $dialog tkwait window $dialog + return 0 + } else { + return 1 } } @@ -806,7 +814,7 @@ class HexEditDlg { set hexlen 2 set octlen 3 set binlen 8 - } { + } else { set hexlen 4 set octlen 7 set binlen 16 @@ -818,7 +826,7 @@ class HexEditDlg { set oct {} set bin {} # Non empty value -> convert - } { + } else { # To hexadecimal set hex [format %X $value] set len [string length $hex] @@ -903,7 +911,7 @@ class HexEditDlg { sbar_show {} } - ## This method should be called after value change in hexeditor + ## This method should be called after value change in hex editor # This method writes new value to simulator engine, watchers and EntryBoxes # @parm Int addr - Address of changed cell # @parm int val - New value of the entry @@ -917,7 +925,7 @@ class HexEditDlg { set validation_ena 1 } - ## This method should be called after current cell change in hexeditor + ## This method should be called after current cell change in hex editor # Synchronizes EntryBoxes # @parm Int addr - New cell address # @return void @@ -945,7 +953,7 @@ class HexEditDlg { # Check for valid characters if {$valtype == {val}} { set m 1 - } { + } else { set m 2 } set len [string length $value] @@ -998,7 +1006,7 @@ class HexEditDlg { set validation_ena 1 return 0 } - } { + } else { if {$value >= $capacity} { set validation_ena 1 return 0 @@ -1010,7 +1018,7 @@ class HexEditDlg { if {$valtype == {val}} { $hexeditor setValue $current_cell $value write_to_simulator $current_cell $value - } { + } else { set current_cell $value $hexeditor setCurrentCell $value } @@ -1026,11 +1034,11 @@ class HexEditDlg { # @return void public method prog_jump {} { if {$type != {code}} {return} - $project setPC [subst "\$::HexEditDlg::dec_addr_${obj_idx}"] + $project setPC [subst -nocommands "\$::HexEditDlg::dec_addr_${obj_idx}"] set lineNum [$project simulator_getCurrentLine] if {$lineNum != {}} { $project move_simulator_line $lineNum - } { + } else { $project editor_procedure {} unset_simulator_line {} } $project Simulator_sync_PC_etc @@ -1040,11 +1048,11 @@ class HexEditDlg { # @return void public method sub_call {} { if {$type != {code}} {return} - $project simulator_subprog_call [subst "\$::HexEditDlg::dec_addr_${obj_idx}"] + $project simulator_subprog_call [subst -nocommands "\$::HexEditDlg::dec_addr_${obj_idx}"] set lineNum [$project simulator_getCurrentLine] if {$lineNum != {}} { $project move_simulator_line $lineNum - } { + } else { $project editor_procedure {} unset_simulator_line {} } $project Simulator_sync_PC_etc @@ -1053,10 +1061,10 @@ class HexEditDlg { ## Adjust view mode to state of mode menu # @return void public method adjust_mode {} { - $mode_combo_box current [lsearch {hex dec oct} [subst "\$::HexEditDlg::mode_${obj_idx}"]] + $mode_combo_box current [lsearch {hex dec oct} [subst -nocommands "\$::HexEditDlg::mode_${obj_idx}"]] sbar_show {Working ...} update - $hexeditor switch_mode [subst "\$::HexEditDlg::mode_${obj_idx}"] + $hexeditor switch_mode [subst -nocommands "\$::HexEditDlg::mode_${obj_idx}"] sbar_show {Working} } @@ -1078,7 +1086,7 @@ class HexEditDlg { } if {$type == {uni}} { delete object $this - } { + } else { ::X::close_hexedit $type $project } } @@ -1102,7 +1110,7 @@ class HexEditDlg { if {$type == {code}} { $left_sbar_label configure -text \ [mc [lindex $HELPFILE_CODE [list $help_file_index $entry_index]]] - } { + } else { $left_sbar_label configure -text \ [mc [lindex $HELPFILE_XDATA [list $help_file_index $entry_index]]] } @@ -1189,6 +1197,19 @@ class HexEditDlg { # Reload content of HexEditor # @return void public method reload {} { + + if {$modified} { + set response [tk_messageBox \ + -parent $win \ + -type yesno \ + -icon warning \ + -title [mc "File modified"] \ + -message [mc "Content of the hex editor has been changed.\nDo you really want to reload without saving it?"]] + if {$response == {no}} { + return + } + } + # Store original cursor position set current_cursor_pos [$hexeditor getCurrentCell] @@ -1198,7 +1219,7 @@ class HexEditDlg { if {$ext != {} && $opened_file != {}} { open_file $opened_file $ext } - } { + } else { refresh } @@ -1209,21 +1230,21 @@ class HexEditDlg { } ## Action for Menu/Toolbar - Save as - # Save current content of hexeditor as IHEX8 file and ask for file name + # Save current content of hex editor as IHEX8 file and ask for file name # @return void public method saveas {} { set directory [file dirname $opened_file] if {$type == {uni}} { if {${::X::project_menu_locked}} { set project {} - } { + } else { set project ${::X::actualProject} } } if {$directory == {.}} { if {$project == {}} { set directory ${::X::defaultDirectory} - } { + } else { set directory [$project cget -projectPath] } } @@ -1232,11 +1253,11 @@ class HexEditDlg { -title [mc "Save file - MCU 8051 IDE"] \ -master $win \ -directory $directory \ - -initialfile [$middle_sbar_label cget -text] \ - -defaultmask 0 -multiple 0 -filetypes { - {{IHEX8} {*.{hex,ihx}} } - {{All files} {*} } - } + -initialfile [$middle_sbar_label cget -text] \ + -defaultmask 0 -multiple 0 -filetypes [list \ + [list [mc "Intel 8 HEX"] {*.{hex,ihx}} ] \ + [list [mc "All files"] {*} ] \ + ] fsd setokcmd "$this save_file_proc \[::HexEditDlg::fsd get\]" fsd activate } @@ -1259,14 +1280,14 @@ class HexEditDlg { if {$type == {uni}} { if {${::X::project_menu_locked}} { set project {} - } { + } else { set project ${::X::actualProject} } } if {$directory == {.}} { if {$project == {}} { set directory ${::X::defaultDirectory} - } { + } else { set directory [$project cget -projectPath] } } @@ -1274,10 +1295,10 @@ class HexEditDlg { KIFSD::FSD fsd \ -title [mc "Open file - MCU 8051 IDE"] \ -master $win -directory $directory \ - -defaultmask 0 -multiple 0 -filetypes { - {{IHEX8} {*.{hex,ihx}} } - {{All files} {*} } - } + -defaultmask 0 -multiple 0 -filetypes [list \ + [list [mc "Intel 8 HEX"] {*.{hex,ihx}} ] \ + [list [mc "All files"] {*} ] \ + ] fsd setokcmd "$this open_file \[::HexEditDlg::fsd get\] hex" fsd activate } @@ -1294,10 +1315,10 @@ class HexEditDlg { KIFSD::FSD fsd \ -title [mc "Open file - MCU 8051 IDE"] \ -master $win -directory $directory \ - -defaultmask 0 -multiple 0 -filetypes { - {{Simulator file} {*.adb} } - {{All files} {*} } - } + -defaultmask 0 -multiple 0 -filetypes [list \ + [list [mc "Simulator file"] {*.adb} ] \ + [list [mc "All files"] {*} ] \ + ] fsd setokcmd "$this open_file \[::HexEditDlg::fsd get\] adf" fsd activate } @@ -1305,7 +1326,7 @@ class HexEditDlg { ## Open the give file and load its contents into editor # @parm String filename - Relative or absolute filename # @parm String extension - Fily type {adf hex} - # @return void + # @return Bool - 1 == success; 0 == failure public method open_file {filename extension} { # Store original cursor position set current_cursor_pos [$hexeditor getCurrentCell] @@ -1316,14 +1337,14 @@ class HexEditDlg { if {$type == {uni}} { if {${::X::project_menu_locked}} { set project {} - } { + } else { set project ${::X::actualProject} } } if {$directory == {.}} { if {$project == {}} { set directory ${::X::defaultDirectory} - } { + } else { set directory [$project cget -projectPath] } } @@ -1331,8 +1352,8 @@ class HexEditDlg { if {![regexp "^(~|/)" $filename]} { set filename "$directory/$filename" } - } { ;# Microsoft windows way - if {![regexp "^\w:" $filename]} { + } else { ;# Microsoft windows way + if {![regexp {^\w:} $filename]} { set filename [file join $directory $filename] } } @@ -1347,20 +1368,20 @@ class HexEditDlg { -icon warning \ -title [mc "Permission denied"] \ -message [mc "Unable to open file:\n%s" $filename] - return + return 0 } # Clear editor if {$type == {uni}} { $hexeditor fill_views - } { + } else { $project simulator_clear_memory $type } # Load contents if {$extension == {adf}} { $project load_program_from_adf $filename - } { + } else { readHex [read $file] } @@ -1373,6 +1394,8 @@ class HexEditDlg { update $hexeditor setCurrentCell $current_cursor_pos $hexeditor seeCell $current_cursor_pos + + return 1 } ## Save content of the editor into the given file in format IHEX8 @@ -1386,14 +1409,14 @@ class HexEditDlg { if {$type == {uni}} { if {${::X::project_menu_locked}} { set project {} - } { + } else { set project ${::X::actualProject} } } if {$directory == {.}} { if {$project == {}} { set directory ${::X::defaultDirectory} - } { + } else { set directory [$project cget -projectPath] } } @@ -1402,7 +1425,7 @@ class HexEditDlg { set filename "$directory/$filename" } } { ;# Microsoft windows way - if {![regexp "^\w:" $filename]} { + if {![regexp {^\w:} $filename]} { set filename [file join $directory $filename] } } @@ -1411,7 +1434,7 @@ class HexEditDlg { if {![regexp {\.(hex|ihx)$} $filename]} { if {$type != {code} && $type != {uni} } { append filename {.xdata.hex} - } { + } else { append filename {.hex} } } @@ -1431,7 +1454,7 @@ class HexEditDlg { -title [mc "Overwrite file"] \ -message [mc "A file name '%s' already exists. Are you sure you want to overwrite it ?" [file tail $filename]] ] != {yes} - } { + } then { return } # Create a backup file @@ -1458,8 +1481,8 @@ class HexEditDlg { # Open file if {[catch { - set file [open $filename w 420] - }]} { + set file [open $filename w 0640] + }]} then { tk_messageBox \ -parent $win \ -type ok \ @@ -1560,11 +1583,14 @@ class HexEditDlg { } # Save EOF - puts -nonewline $file {:00000001FF} + puts $file {:00000001FF} # Done ... close $file setModified 0 + if {$::MICROSOFT_WINDOWS} { ;# "/" --> "\" + regsub -all {/} $filename "\\" filename + } sbar_show [mc "File %s saved" $filename] } @@ -1595,7 +1621,7 @@ class HexEditDlg { # GENERAL PUBLIC INTERFACE # ------------------------------------------------------------------- - ## Inform hexeditor about simulator start or shutdown + ## Inform hex editor about simulator start or shutdown # @parm Bool started - 1 == Simulator started; 0 == Simulator stopped # @return void public method simulator_stared_stopped {started} { @@ -1605,7 +1631,7 @@ class HexEditDlg { if {$started} { set state {normal} - } { + } else { set state {disabled} } $sub_call_but configure -state $state @@ -1614,7 +1640,8 @@ class HexEditDlg { [$hexeditor get_popup_menu] entryconfigure [::mc "LCALL this_address"] -state $state } - ## Move program pointer (highlight cells) -- Avaliable only for code memory hexeditor + ## Move program pointer (highlight cells) + # -- available only for code memory hex editor # @parm Int new_PC - New program counter # @parm Int int_length - Instruction length # @return void @@ -1647,12 +1674,14 @@ class HexEditDlg { for {set i 0} {$i < $int_length} {incr i} { $hexeditor set_bg_hg $new_PC 1 2 + $hexeditor set_bg_hg $new_PC 0 1 incr new_PC } $hexeditor seeCell $new_PC } - ## Directly move program pointer (do not affect previous PC pointer) -- Avaliable only for code memory hexeditor + ## Directly move program pointer (do not affect previous PC pointer) + # -- available only for code memory hex editor # @parm Int new_PC - New program counter (-1 == unresolved) # @parm Int int_length - Instruction length # @return void @@ -1697,7 +1726,7 @@ class HexEditDlg { } ## Write value to the editor - # - avaliable only in modes: XDATA and ERAM + # - available only in modes: XDATA and ERAM # @parm String address - hexadecimal address # @return void public method reg_sync {address} { @@ -1733,7 +1762,7 @@ class HexEditDlg { set loaded_lines [string repeat [string repeat 0 0xFF] 0xFF] load_data_to_current_view - setModified 1 + setModified 0 } ## Get configuration list @@ -1752,7 +1781,7 @@ class HexEditDlg { set cell [lindex $config 2] set current_view [lindex $config 3] - # load configuration for hexeditor widget + # load configuration for hex editor widget ::HexEditor::load_config_list [lindex $config 4] # Validate loaded values @@ -1785,9 +1814,13 @@ class HexEditDlg { if {$type == {uni}} { if {$modified} { wm title $win "\[modified\] $filename - [mc {Hexadecimal editor}] - MCU 8051 IDE" - } { + } else { wm title $win "$filename - [mc {Hexadecimal editor}] - MCU 8051 IDE" } } } } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/utilities/notes.tcl b/lib/utilities/notes.tcl old mode 100755 new mode 100644 index f39312f..d74b652 --- a/lib/utilities/notes.tcl +++ b/lib/utilities/notes.tcl @@ -2,7 +2,7 @@ # Part of MCU 8051 IDE ( http://mcu8051ide.sf.net ) ############################################################################ -# Copyright (C) 2007-2009 by Martin Ošmera # +# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera # # martin.osmera@gmail.com # # # # This program is free software; you can redistribute it and#or modify # @@ -21,6 +21,11 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################ +# >>> File inclusion guard +if { ! [ info exists _NOTES_TCL ] } { +set _NOTES_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION: # Scribble notes independent on project @@ -32,10 +37,10 @@ class Notes { common bgcolor {#EEEE55} ;# Color: Background color for title bar and window border common bgcolor2 {#FFFF88} ;# Color: Background color for the canvas widget # Font: For inserted text - common canvas_text_font [font create \ - -family $::DEFAULT_FIXED_FONT \ - -size -14 \ - -weight bold \ + common canvas_text_font [font create \ + -family $::DEFAULT_FIXED_FONT \ + -size [expr {int(-14 * $::font_size_factor)}] \ + -weight bold \ ] # List: Popup menu for the canvas widget common MENU { @@ -118,7 +123,7 @@ class Notes { set filename $_file_name if {$_geometry == {}} { set geometry {50 50 300 300} - } { + } else { set geometry $_geometry } @@ -133,7 +138,7 @@ class Notes { -relief flat ttk::style map Notes_Flat.TButton \ -relief [list active raised] \ - -background [list disabled {#EEEEEE}] + -background [list disabled ${::COMMON_BG_COLOR}] create_win } @@ -270,7 +275,7 @@ class Notes { if {[prompt_for_text]} { $canvas_widget configure -cursor cross set w $mode_text_but - } { + } else { if {$drawing_mode_org == {T}} { set drawing_mode_org {M} } @@ -321,7 +326,7 @@ class Notes { pack forget $main_frame place $win -height [expr {[winfo height $win.title_bar] + 4}] # Unshade - } { + } else { set image _1uparrow pack $main_frame -fill both -expand 1 -padx 2 -pady 2 place $win -height [expr {[lindex $geometry 3] + 2}] @@ -336,7 +341,7 @@ class Notes { set popup_menu_created 1 set menu $canvas_widget.menu - menuFactory $MENU $menu 0 "$this " 0 {} + menuFactory $MENU $menu 0 "$this " 0 {} [namespace current] } ## Popup menu @@ -484,7 +489,7 @@ class Notes { -image ::ICONS::16::grid1 \ ] DynamicHelp::add $bottom_frame.mode_rectangle_but -text [mc "Retangle"] - setStatusTip -widget $mode_rectangle_but -text [mc "Draw retangles"] + setStatusTip -widget $mode_rectangle_but -text [mc "Draw rectangles"] pack $mode_rectangle_but -side left -ipady 0 # - Button "Oval" set mode_oval_but [ttk::button $bottom_frame.mode_oval_but \ @@ -523,7 +528,7 @@ class Notes { -command "$this select_color" \ -bd 1 -relief raised -overrelief raised \ -activebackground $selected_color \ - -bg $selected_color -pady 0 \ + -bg $selected_color -pady 0 -width 2 \ ] DynamicHelp::add $bottom_frame.select_color_but -text [mc "Select color"] setStatusTip -widget $select_color_but -text [mc "Select color"] @@ -597,7 +602,7 @@ class Notes { # @return void private method prompt_for_text {} { set ::Notes::text_prompt_text {} - set dialog [toplevel .notes_pd -bg {#EEEEEE}] + set dialog [toplevel .notes_pd -bg ${::COMMON_BG_COLOR}] ## Create top frame set frame [frame $dialog.frm] @@ -865,10 +870,10 @@ class Notes { KIFSD::FSD ::fsd \ -directory $directory \ -title [mc "Insert image from file"] \ - -defaultmask 0 -multiple 0 -filetypes { - {{PNG files} {*.png}} - {{All files} {*}} - } + -defaultmask 0 -multiple 0 -filetypes [list \ + [list [mc "Portable network graphics"] {*.png} ] \ + [list [mc "All files"] {*} ] \ + ] ::fsd setokcmd "$this load_image_file \[::fsd get\]" ::fsd activate @@ -881,10 +886,12 @@ class Notes { set loaded_image {} if {[catch { set loaded_image [image create photo -file $file] - }]} { - tk_messageBox \ + }]} then { + tk_messageBox \ + -parent . \ + -type ok \ + -icon warning \ -title [mc "Unable to read file"] \ - -type ok -icon warning \ -message [mc "Unable to read file:\n%s" $file] return } @@ -894,3 +901,7 @@ class Notes { } } } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/utilities/rs232debugger.tcl b/lib/utilities/rs232debugger.tcl old mode 100755 new mode 100644 index dacb8d5..af2354b --- a/lib/utilities/rs232debugger.tcl +++ b/lib/utilities/rs232debugger.tcl @@ -2,7 +2,7 @@ # Part of MCU 8051 IDE ( http://mcu8051ide.sf.net ) ############################################################################ -# Copyright (C) 2007-2009 by Martin Ošmera # +# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera # # martin.osmera@gmail.com # # # # This program is free software; you can redistribute it and#or modify # @@ -21,6 +21,11 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################ +# >>> File inclusion guard +if { ! [ info exists _RS232DEBUGGER_TCL ] } { +set _RS232DEBUGGER_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION @@ -31,29 +36,34 @@ class RS232Debugger { ## COMMON common count 0 ;# Int: Counter of class instances # Font: Big bold font - common bold_font [font create \ - -family {helvetica} \ - -size -12 -weight {bold} \ + common bold_font [font create \ + -family {helvetica} \ + -size [expr {int(-12 * $::font_size_factor)}] \ + -weight {bold} \ ] # Font: Tiny normal font - common tiny_font [font create \ - -family {helvetica} \ - -size -9 -weight {normal} \ + common tiny_font [font create \ + -family {helvetica} \ + -size [expr {int(-9 * $::font_size_factor)}] \ + -weight {normal} \ ] # Font: Tiny bold font - common tiny_font_bold [font create \ - -family {helvetica} \ - -size -9 -weight {bold} \ + common tiny_font_bold [font create \ + -family {helvetica} \ + -size [expr {int(-9 * $::font_size_factor)}] \ + -weight {bold} \ ] # Font: Normal font - common normal_font [font create \ - -family {helvetica} \ - -size -11 -weight {normal} \ + common normal_font [font create \ + -family {helvetica} \ + -size [expr {int(-11 * $::font_size_factor)}] \ + -weight {normal} \ ] # Font: Also normal font, but a bit larger - common big_font [font create \ - -family {helvetica} \ - -size -12 -weight {normal} \ + common big_font [font create \ + -family {helvetica} \ + -size [expr {int(-12 * $::font_size_factor)}] \ + -weight {normal} \ ] # Int: Pool interval for selected RS232 interface common POOL_INTERVAL 50 ;# mili-seconds @@ -92,13 +102,13 @@ class RS232Debugger { private variable clear_selected_rec_button ;# Widget: Button "Clear selected" in section "Receive" private variable receive_here_button ;# Widget: Button "Receive here" private variable clear_selected_snd_button ;# Widget: Button "Clear selected" in section "Send" - private variable receive_hexeditor ;# Object: Hexeditor intented for reception - private variable send_hexeditor ;# Object: Hexeditor intented for sending + private variable receive_hexeditor ;# Object: Hex editor intented for reception + private variable send_hexeditor ;# Object: Hex editor intented for sending private variable pool_timer {} ;# Object: Pool timer object private variable channel {} ;# Channel: Opened device file private variable port_filename {} ;# String: Device file name - private variable reception_address 0 ;# Int: Address in reception hexeditor where received data are stored + private variable reception_address 0 ;# Int: Address in reception hex editor where received data are stored private variable reception_enabled 1 ;# Bool: Reception enabled private variable prev_tty_status ;# List: Previous TTY status (before any action performed by this code) @@ -130,7 +140,7 @@ class RS232Debugger { -foreground {#000000} \ -background {#DDDDDD} ttk::style map RS232Debugger_SignalAllDefault.TButton \ - -background [list active {#EEEEEE}] + -background [list active ${::COMMON_BG_COLOR}] ttk::style configure RS232Debugger_SignalTxDTrue.TButton \ -background {#AAFFAA} \ @@ -150,7 +160,7 @@ class RS232Debugger { -background {#DDDDDD} \ -foreground {#000000} ttk::style map RS232Debugger_SignalTxDFalse.TButton \ - -background [list active {#EEEEEE}] \ + -background [list active ${::COMMON_BG_COLOR}] \ -foreground [list active {#000000}] ttk::style configure RS232Debugger_SignalNormalFalse.TButton \ @@ -216,7 +226,7 @@ class RS232Debugger { create_gui set_tty_controls_state 0 - # Restore data displayed in hexeditors + # Restore data displayed in hex editors foreach idx {5 6} hexedit [list $receive_hexeditor $send_hexeditor] { set data [lindex $config_list $idx] if {![llength $data]} { @@ -228,7 +238,7 @@ class RS232Debugger { } } - # restore addresses of current cells in hexeditors + # restore addresses of current cells in hex editors $receive_hexeditor setCurrentCell [lindex $config_list 7] $send_hexeditor setCurrentCell [lindex $config_list 8] } @@ -249,7 +259,7 @@ class RS232Debugger { # Cancel pool timer catch {after cancel $pool_timer} - # Close opended channel + # Close opened channel if {$channel !={}} { catch {fileevent $channel readable {}} catch {close $channel} @@ -263,7 +273,7 @@ class RS232Debugger { # @return void private method create_gui {} { # Create window - set win [toplevel .rs232debugger$count -class [mc "RS232 Debugger"] -bg {#EEEEEE}] + set win [toplevel .rs232debugger$count -class [mc "RS232 Debugger"] -bg ${::COMMON_BG_COLOR}] # Create status bar set status_bar_label [label $win.status_bar_label -justify left -pady 0 -anchor w] @@ -381,13 +391,13 @@ class RS232Debugger { $connector_canvas bind gnd_wire "$this wire_leave gnd" ## Write texts - $connector_canvas create text \ - [expr {$x + 10}] [expr {$y - 25}] \ - -anchor n -justify left \ + $connector_canvas create text \ + [expr {$x + 10}] [expr {$y - 30}] \ + -anchor n -justify left \ -font $big_font -text [mc "RS-232\nDTE"] - $connector_canvas create text \ + $connector_canvas create text \ [expr {$x + 10}] [expr {$y + 100}] \ - -anchor n -justify left \ + -anchor n -justify left \ -font $big_font -text [mc "DE-9"] } @@ -510,7 +520,7 @@ class RS232Debugger { bind $dtr_button "$this wire_enter dtr" bind $dtr_button "$this wire_leave dtr" $connector_canvas create window \ - [expr {$x + 100}] [expr {$y + 95}] \ + [expr {$x + 100}] [expr {$y + 90}] \ -anchor center -window $dtr_button $connector_canvas create line \ @@ -539,7 +549,7 @@ class RS232Debugger { bind $rts_button "$this wire_enter rts" bind $rts_button "$this wire_leave rts" $connector_canvas create window \ - [expr {$x + 135}] [expr {$y + 95}] \ + [expr {$x + 135}] [expr {$y + 90}] \ -anchor center -window $rts_button $connector_canvas create line \ @@ -568,7 +578,7 @@ class RS232Debugger { bind $break_button "$this wire_enter txd" bind $break_button "$this wire_leave txd" $connector_canvas create window \ - [expr {$x + 180}] [expr {$y + 95}] \ + [expr {$x + 180}] [expr {$y + 90}] \ -anchor center -window $break_button $connector_canvas create line \ @@ -617,10 +627,10 @@ class RS232Debugger { # Create canvas widget set connector_canvas [canvas $target_frame.canvas \ - -width 280 -height 150 -bg {#EEEEEE} \ + -width 280 -height 150 -bg ${::COMMON_BG_COLOR} \ -bd 0 -relief flat -highlightthickness 0 \ ] - pack $connector_canvas -side left -anchor sw + pack $connector_canvas -side left -padx 5 ;#-anchor sw # Fill in the connector canvas draw_connector 20 30 @@ -642,7 +652,7 @@ class RS232Debugger { -image ::ICONS::16::configure \ ] \ ] - pack $conf_frame -side left -anchor nw + pack $conf_frame -side right -anchor nw -padx 5 # - Physical port grid [label $conf_frame.port_lbl \ -text [mc "Physical port"] \ @@ -687,13 +697,16 @@ class RS232Debugger { -text [mc "Parity"] \ ] -row 4 -column 1 -sticky w set parity_cb [ttk::combobox $conf_frame.parity_cb \ - -values {none odd even mark space} \ -state readonly \ -width 6 \ -exportselection 0 \ + -values [list [mc "none"] \ + [mc "odd"] [mc "even"] \ + [mc "mark"] [mc "space"] \ + ] ] bind $parity_cb <> \ - "$this change_port_config p \[$conf_frame.parity_cb get\]" + "$this change_port_config p \[$conf_frame.parity_cb current\]" set_status_tip $parity_cb [mc "Parity"] grid $parity_cb -row 4 -column 2 -sticky w $conf_frame.parity_cb current [lsearch {n o e m s} $parity_conf] @@ -852,7 +865,7 @@ class RS232Debugger { if {[file exists $content]} { if {$port_filename == $content} { $port_combobox configure -style RS232Debugger_FileInUse.TCombobox - } { + } else { $port_combobox configure -style RS232Debugger_FileFound.TCombobox } # Not exiting file @@ -924,7 +937,7 @@ class RS232Debugger { -message \"[mc {Unable to open the specified file}]\n\n\${reason}\"" # -> Success } else { - # Try to configure opened channel acording to specified parameters + # Try to configure opened channel according to specified parameters if {[catch { fconfigure $channel \ -handshake none \ @@ -964,24 +977,7 @@ class RS232Debugger { set baud_conf $value } {p} { ;# Parity bit - switch -- $value { - {none} { - set value {n} - } - {odd} { - set value {o} - } - {even} { - set value {e} - } - {mark} { - set value {m} - } - {space} { - set value {s} - } - } - set parity_conf $value + set parity_conf [lindex {n o e m s} $value] } {d} { ;# Data bits set data_conf $value @@ -1004,31 +1000,31 @@ class RS232Debugger { -parent $win \ -type ok \ -icon error \ - -title [mc "Uknown failure"] \ + -title [mc "Unknown failure"] \ -message [mc "Unable to change port configuration"] } } - ## Handle selection event in hexeditor + ## Handle selection event in hex editor # @parm Char editor - Editor ID # @parm Bool anything_selected - 1 == anything selected; 0 == Nothing selected # @return void public method hexeditor_selection {editor anything_selected} { if {$anything_selected} { set state {normal} - } { + } else { set state {disabled} } if {$editor == {s}} { $send_selected_button configure -state $state $clear_selected_snd_button configure -state $state - } { + } else { $clear_selected_rec_button configure -state $state } } - ## Clear selected data in send hexeditor + ## Clear selected data in send hex editor # @return void public method clear_selected_snd {} { # Get range of text indexes determinating the selection @@ -1142,7 +1138,7 @@ class RS232Debugger { if {[winfo exists .data_lost_dialog]} { return } - set dialog [toplevel .data_lost_dialog -class [mc "Error message"] -bg {#EEEEEE}] + set dialog [toplevel .data_lost_dialog -class [mc "Error message"] -bg ${::COMMON_BG_COLOR}] pack [label $dialog.label \ -font $bold_font -compound left -padx 5 \ @@ -1181,7 +1177,7 @@ class RS232Debugger { tkwait window $dialog } - ## Clear selected data in receive hexeditor + ## Clear selected data in receive hex editor # @return void public method clear_selected_rec {} { set rangeofselection [$receive_hexeditor getRangeOfSelection] @@ -1200,7 +1196,7 @@ class RS232Debugger { ## Enable/Disable reception # @return void public method reception_ena_dis {} { - set reception_enabled [subst "\$::RS232Debugger::enable_reception${obj_idx}"] + set reception_enabled [subst -nocommands "\$::RS232Debugger::enable_reception${obj_idx}"] } ## Read TTY status from the interface and update GUI accordingly @@ -1212,15 +1208,15 @@ class RS232Debugger { # Read TTY status if {[catch { set ttystatus [fconfigure $channel -ttystatus] - }]} { + }]} then { unknown_port_io_error return } - # Check whether any change occured + # Check whether any change occurred if {$prev_tty_status(0) == $ttystatus} { return - } { + } else { set prev_tty_status(0) $ttystatus } @@ -1256,7 +1252,7 @@ class RS232Debugger { foreach signal {cts dsr ri dcd} value $args { if {$prev_tty_status($signal) == $value} { continue - } { + } else { set prev_tty_status($signal) $value } @@ -1280,7 +1276,7 @@ class RS232Debugger { } } - ## Report an unknown IO error occured on the interface + ## Report an unknown IO error occurred on the interface # Plus disable reception and safely terminate connection # @return void private method unknown_port_io_error {} { @@ -1326,7 +1322,7 @@ class RS232Debugger { set state {normal} set state2 {readonly} set_tty_controls_to_defaults - } { + } else { set state {disabled} set state2 {disabled} set_tty_controls_to_unknown_state @@ -1382,33 +1378,33 @@ class RS232Debugger { switch -- $value { 0 { ;# Loical 0 if {$wire == {break}} { - [subst "\${${wire}_button}"] configure -text {Break} \ + [subst -nocommands "\${${wire}_button}"] configure -text {Break} \ -style RS232Debugger_SignalTxDFalse.TButton $connector_canvas itemconfigure txd_wire -fill {#0000FF} - } { - [subst "\${${wire}_button}"] configure -text {1} \ + } else { + [subst -nocommands "\${${wire}_button}"] configure -text {1} \ -style RS232Debugger_SignalNormalFalse.TButton $connector_canvas itemconfigure ${wire}_wire -fill {#FF0000} } } 1 { ;# Logical 1 if {$wire == {break}} { - [subst "\${${wire}_button}"] configure -text {BREAK} \ + [subst -nocommands "\${${wire}_button}"] configure -text {BREAK} \ -style RS232Debugger_SignalTxDTrue.TButton $connector_canvas itemconfigure txd_wire -fill {#00FF00} - } { - [subst "\${${wire}_button}"] configure -text {0} \ + } else { + [subst -nocommands "\${${wire}_button}"] configure -text {0} \ -style RS232Debugger_SignalNormalTrue.TButton $connector_canvas itemconfigure ${wire}_wire -fill {#00FF00} } } default { ;# Unknown state if {$wire == {break}} { - [subst "\${${wire}_button}"] configure -text {Break} \ + [subst -nocommands "\${${wire}_button}"] configure -text {Break} \ -style RS232Debugger_SignalAllDefault.TButton $connector_canvas itemconfigure txd_wire -fill {#0000FF} - } { - [subst "\${${wire}_button}"] configure -text {-} \ + } else { + [subst -nocommands "\${${wire}_button}"] configure -text {-} \ -style RS232Debugger_SignalAllDefault.TButton $connector_canvas itemconfigure ${wire}_wire -fill {#888888} } @@ -1418,7 +1414,7 @@ class RS232Debugger { if {[catch { fconfigure $channel -ttycontrol [list $wire $value] - }]} { + }]} then { unknown_port_io_error return } @@ -1452,9 +1448,13 @@ class RS232Debugger { # @return void public method wire_leave {wire} { $connector_canvas itemconfigure ${wire}_wire -width 1 - $connector_canvas itemconfigure ${wire}_pin -fill {#EEEEEE} + $connector_canvas itemconfigure ${wire}_pin -fill ${::COMMON_BG_COLOR} $connector_canvas itemconfigure ${wire}_num -font $tiny_font $status_bar_label configure -text {} } } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/utilities/speccalc.tcl b/lib/utilities/speccalc.tcl old mode 100755 new mode 100644 index 67a9430..49db83b --- a/lib/utilities/speccalc.tcl +++ b/lib/utilities/speccalc.tcl @@ -2,7 +2,7 @@ # Part of MCU 8051 IDE ( http://mcu8051ide.sf.net ) ############################################################################ -# Copyright (C) 2007-2009 by Martin Ošmera # +# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera # # martin.osmera@gmail.com # # # # This program is free software; you can redistribute it and#or modify # @@ -21,6 +21,11 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################ +# >>> File inclusion guard +if { ! [ info exists _SPECCALC_TCL ] } { +set _SPECCALC_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION @@ -34,7 +39,7 @@ class SpecCalc { ## COMMON common count 0 ;# Int: Counter of class instances - common diagram_counter 0 ;# Int: Counter of diagram dialogs instances + common diagram_counter 0 ;# Int: Counter of diagram dialogues instances # List of pages descriptors for PagesManager common page_list { loops timer01 timer2 spi @@ -67,10 +72,10 @@ class SpecCalc { ttk::style configure SpecCalc_RedBg.TCombobox -fieldbackground {#FFCCCC} ttk::style configure SpecCalc_Flat.TButton -background {#FFFFFF} -padding 0 -borderwidth 1 -relief flat - ttk::style map SpecCalc_Flat.TButton -relief [list active raised] -background [list disabled {#EEEEEE} active {#EEEEFF}] + ttk::style map SpecCalc_Flat.TButton -relief [list active raised] -background [list disabled ${::COMMON_BG_COLOR} active {#EEEEFF}] ttk::style configure SpecCalc_Spec.TButton -background {#CCCCFF} -padding 0 - ttk::style map SpecCalc_Spec.TButton -background [list disabled {#EEEEEE} active {#DDDDFF}] + ttk::style map SpecCalc_Spec.TButton -background [list disabled ${::COMMON_BG_COLOR} active {#DDDDFF}] create_gui } @@ -86,7 +91,7 @@ class SpecCalc { [list [$widgets(loops,time_ent) get] \ [$widgets(loops,time_cb) current] \ [$widgets(loops,clock_cb) get] \ - [$widgets(loops,clock_type_cb) current] \ + [$widgets(loops,clock_type_cb) current] \ [$widgets(loops,reg_ent0) get] \ [$widgets(loops,reg_ent1) get] \ [$widgets(loops,reg_ent2) get] \ @@ -102,7 +107,7 @@ class SpecCalc { [$widgets(timer01,clock_type_cb) current] \ [$widgets(timer01,mode_cb) current] \ [$widgets(timer01,psc_cb) current] \ - [subst "\${::SpecCalc::spec_chb_$obj_idx}"] \ + [subst -nocommands "\${::SpecCalc::spec_chb_$obj_idx}"] \ ] [list \ [$widgets(timer2,time_ent) get] \ [$widgets(timer2,time_cb) current] \ @@ -111,14 +116,14 @@ class SpecCalc { [$widgets(timer2,mode_cb) current] \ ] [list \ - [subst "\$::SpecCalc::timer2_clk_fosc_$obj_idx"]\ - [subst "\$::SpecCalc::timer2_clk_freq_$obj_idx"]\ - [subst "\$::SpecCalc::timer2_clk_x2_$obj_idx"] \ + [subst -nocommands "\$::SpecCalc::timer2_clk_fosc_$obj_idx"] \ + [subst -nocommands "\$::SpecCalc::timer2_clk_freq_$obj_idx"] \ + [subst -nocommands "\$::SpecCalc::timer2_clk_x2_$obj_idx"] \ ] [list \ [wm geometry $win] \ $active_page \ ] [list \ - [subst "\${::SpecCalc::double_chb_$obj_idx}"] \ + [subst -nocommands "\${::SpecCalc::double_chb_$obj_idx}"] \ [$widgets(spi,sck_ent00) get] \ ] ] @@ -148,7 +153,7 @@ class SpecCalc { # @return void private method create_gui {} { # Create dialog window and the main frame - set win [toplevel .spec_calc$count -class [mc "Special Calculator - MCU 8051 IDE"] -bg {#EEEEEE}] + set win [toplevel .spec_calc$count -class [mc "Special Calculator - MCU 8051 IDE"] -bg ${::COMMON_BG_COLOR}] set main_frame [frame $win.main_frame] # Create status bar @@ -192,7 +197,7 @@ class SpecCalc { if {[llength $config]} { wm geometry $win [lindex $config {4 0}] switch_page [lindex $config {4 1}] - } { + } else { wm geometry $win 400x350 switch_page loops } @@ -222,10 +227,10 @@ class SpecCalc { } page $page_list \ { set buttons($page) [ttk::button $target_frame.${page}_button \ - -image ::ICONS::22::$icon \ - -text [mc $name] -compound top \ - -command "$this switch_page $page" \ - -style Flat.TButton \ + -image ::ICONS::22::$icon \ + -text [mc $name] -compound top \ + -command "$this switch_page $page" \ + -style Flat.TButton \ ] pack $buttons($page) -anchor n set_status_tip $buttons($page) [mc $stip] @@ -236,7 +241,7 @@ class SpecCalc { # @parm Widget target_frame - Frame widget in which the GUI should be created # @return void private method create_right_frame {target_frame} { - set pages_manager [PagesManager $target_frame.pages_manager -background {#eeeeee}] + set pages_manager [PagesManager $target_frame.pages_manager -background ${::COMMON_BG_COLOR}] pack $pages_manager -fill both -expand 1 foreach page $page_list { @@ -363,13 +368,13 @@ class SpecCalc { -command "$this calc loops copy_but {}" \ ] pack $widgets(loops,copy_but) -side right - set widgets(loops,results) [text $bottom_frame_b.text \ - -state disabled -width 0 -height 0 -bg white \ - -yscrollcommand "$bottom_frame_b.scrollbar set" \ - -takefocus 1 -font [font create \ - -family $::DEFAULT_FIXED_FONT \ - -size -14 \ - ] \ + set widgets(loops,results) [text $bottom_frame_b.text \ + -state disabled -width 0 -height 0 -bg white \ + -yscrollcommand "$bottom_frame_b.scrollbar set" \ + -takefocus 1 -font [font create \ + -family $::DEFAULT_FIXED_FONT \ + -size [expr {int(-14 * $::font_size_factor)}] \ + ] \ ] ASMsyntaxHighlight::create_tags $widgets(loops,results) 14 $::DEFAULT_FIXED_FONT bind $widgets(loops,results) "focus %W" @@ -394,13 +399,13 @@ class SpecCalc { # Create page header - pack [label $pages($page).header \ - -text [mc "Create a wait loop"] \ - -font [font create \ - -family {helvetica} \ - -size -17 \ - -weight bold \ - ] \ + pack [label $pages($page).header \ + -text [mc "Create a wait loop"] \ + -font [font create \ + -family {helvetica} \ + -size [expr {int(-17 * $::font_size_factor)}] \ + -weight bold \ + ] \ ] -pady 5 pack $top_frame -anchor nw pack $regs_frame -anchor nw -fill x @@ -413,15 +418,15 @@ class SpecCalc { if {[llength $config]} { $widgets(loops,time_ent) insert 0 [lindex $config {0 0}] $widgets(loops,time_cb) current [lindex $config {0 1}] - $widgets(loops,clock_cb) delete 0 end - $widgets(loops,clock_cb) insert 0 [lindex $config {0 2}] + $widgets(loops,clock_cb) delete 0 end + $widgets(loops,clock_cb) insert 0 [lindex $config {0 2}] $widgets(loops,clock_type_cb) current [lindex $config {0 3}] for {set i 0; set k 4} {$i < 8} {incr i; incr k} { $widgets(loops,reg_ent$i) insert 0 [lindex $config [list 0 $k]] } - } { + } else { $widgets(loops,time_cb) current 1 $widgets(loops,clock_cb) current 2 $widgets(loops,clock_type_cb) current 0 @@ -569,9 +574,9 @@ class SpecCalc { # - TH set widgets(timer01,th) [ \ entry $bottom_frame.th_r_lbl -state readonly \ - -readonlybackground {#EEEEEE} \ + -readonlybackground ${::COMMON_BG_COLOR} \ -disabledforeground {#000000} \ - -fg {#888888} -bg {#EEEEEE} \ + -fg {#888888} -bg ${::COMMON_BG_COLOR} \ -relief flat -highlightthickness 0 -bd 0 \ -textvariable ::SpecCalc::timer01_th_$obj_idx \ ] @@ -580,8 +585,8 @@ class SpecCalc { # - TL set widgets(timer01,tl) [ \ entry $bottom_frame.tl_r_lbl -state readonly \ - -fg {#888888} -bg {#EEEEEE} \ - -readonlybackground {#EEEEEE} \ + -fg {#888888} -bg ${::COMMON_BG_COLOR} \ + -readonlybackground ${::COMMON_BG_COLOR} \ -disabledforeground {#000000} \ -relief flat -highlightthickness 0 -bd 0 \ -textvariable ::SpecCalc::timer01_tl_$obj_idx \ @@ -591,8 +596,8 @@ class SpecCalc { # - RH set widgets(timer01,rh) [ \ entry $bottom_frame.rh_r_lbl -state readonly \ - -fg {#888888} -bg {#EEEEEE} \ - -readonlybackground {#EEEEEE} \ + -fg {#888888} -bg ${::COMMON_BG_COLOR} \ + -readonlybackground ${::COMMON_BG_COLOR} \ -disabledforeground {#000000} \ -relief flat -highlightthickness 0 -bd 0 \ -textvariable ::SpecCalc::timer01_rh_$obj_idx \ @@ -601,8 +606,8 @@ class SpecCalc { # - RL set widgets(timer01,rl) [ \ entry $bottom_frame.rl_r_lbl -state readonly \ - -fg {#888888} -bg {#EEEEEE} \ - -readonlybackground {#EEEEEE} \ + -fg {#888888} -bg ${::COMMON_BG_COLOR} \ + -readonlybackground ${::COMMON_BG_COLOR} \ -disabledforeground {#000000} \ -relief flat -highlightthickness 0 -bd 0 \ -textvariable ::SpecCalc::timer01_rl_$obj_idx \ @@ -611,8 +616,8 @@ class SpecCalc { # - Repeats set widgets(timer01,repeats) [ \ entry $bottom_frame.reps_lbl -state readonly \ - -fg {#888888} -bg {#EEEEEE} \ - -readonlybackground {#EEEEEE} \ + -fg {#888888} -bg ${::COMMON_BG_COLOR} \ + -readonlybackground ${::COMMON_BG_COLOR} \ -disabledforeground {#000000} \ -relief flat -highlightthickness 0 -bd 0 \ -textvariable ::SpecCalc::timer01_repeats_$obj_idx\ @@ -622,8 +627,8 @@ class SpecCalc { # - Rest set widgets(timer01,rest) [ \ entry $bottom_frame.rest_r_lbl -state readonly \ - -fg {#888888} -bg {#EEEEEE} \ - -readonlybackground {#EEEEEE} \ + -fg {#888888} -bg ${::COMMON_BG_COLOR} \ + -readonlybackground ${::COMMON_BG_COLOR} \ -disabledforeground {#000000} \ -relief flat -highlightthickness 0 -bd 0 \ -textvariable ::SpecCalc::timer01_rest_$obj_idx \ @@ -636,13 +641,13 @@ class SpecCalc { # Create page header - pack [label $pages($page).header \ - -text [mc "Calculate timer 0/1 preset"] \ - -font [font create \ - -family {helvetica} \ - -size -17 \ - -weight bold \ - ] \ + pack [label $pages($page).header \ + -text [mc "Calculate timer 0/1 preset"] \ + -font [font create \ + -family {helvetica} \ + -size [expr {int(-17 * $::font_size_factor)}] \ + -weight bold \ + ] \ ] -pady 5 pack $top_frame -anchor nw pack [ttk::separator $pages($page).sep \ @@ -682,7 +687,7 @@ class SpecCalc { private method create_page_timer2 {} { # Create notebook set page {timer2} - set nb [NoteBook $pages($page).nb -side top -arcradius 4 -bg {#EEEEEE}] + set nb [ModernNoteBook $pages($page).nb] # - Page "Preset" set preset_frame [$nb insert end {Preset} \ -text [mc "Preset"] \ @@ -805,10 +810,10 @@ class SpecCalc { # - RCAL2H set widgets(timer2,rcal2h) [ entry $bottom_frame.rcal2h_r_lbl -state readonly \ - -fg {#888888} -bg {#EEEEEE} \ + -fg {#888888} -bg ${::COMMON_BG_COLOR} \ -relief flat -highlightthickness 0 -bd 0 \ -textvariable ::SpecCalc::timer2_rcal2h_$obj_idx \ - -readonlybackground {#EEEEEE} \ + -readonlybackground ${::COMMON_BG_COLOR} \ -disabledforeground {#000000} \ ] set ::SpecCalc::timer2_rcal2h_$obj_idx [mc "Do not change"] @@ -816,10 +821,10 @@ class SpecCalc { # - RCAL2L set widgets(timer2,rcal2l) [ entry $bottom_frame.rcal2l_r_lbl -state readonly \ - -fg {#888888} -bg {#EEEEEE} \ + -fg {#888888} -bg ${::COMMON_BG_COLOR} \ -relief flat -highlightthickness 0 -bd 0 \ -textvariable ::SpecCalc::timer2_rcal2l_$obj_idx \ - -readonlybackground {#EEEEEE} \ + -readonlybackground ${::COMMON_BG_COLOR} \ -disabledforeground {#000000} \ ] set ::SpecCalc::timer2_rcal2l_$obj_idx [mc "Do not change"] @@ -827,10 +832,10 @@ class SpecCalc { # - T2H set widgets(timer2,t2h) [ entry $bottom_frame.t2h_r_lbl -state readonly \ - -fg {#888888} -bg {#EEEEEE} \ + -fg {#888888} -bg ${::COMMON_BG_COLOR} \ -relief flat -highlightthickness 0 -bd 0 \ -textvariable ::SpecCalc::timer2_t2h_$obj_idx \ - -readonlybackground {#EEEEEE} \ + -readonlybackground ${::COMMON_BG_COLOR} \ -disabledforeground {#000000} \ ] set ::SpecCalc::timer2_t2h_$obj_idx [mc "Do not change"] @@ -838,21 +843,21 @@ class SpecCalc { # - T2L set widgets(timer2,t2l) [ entry $bottom_frame.t2l_r_lbl -state readonly \ - -fg {#888888} -bg {#EEEEEE} \ + -fg {#888888} -bg ${::COMMON_BG_COLOR} \ -relief flat -highlightthickness 0 -bd 0 \ -textvariable ::SpecCalc::timer2_t2l_$obj_idx \ - -readonlybackground {#EEEEEE} \ + -readonlybackground ${::COMMON_BG_COLOR} \ -disabledforeground {#000000} \ ] set ::SpecCalc::timer2_t2l_$obj_idx [mc "Do not change"] grid $widgets(timer2,t2l) -row 4 -column 3 -sticky w # - Repeats - set widgets(timer2,repeats) [ \ - entry $bottom_frame.repeats_lbl -state readonly \ - -fg {#888888} -bg {#EEEEEE} \ - -relief flat -highlightthickness 0 -bd 0 \ - -readonlybackground {#EEEEEE} \ - -disabledforeground {#000000} \ + set widgets(timer2,repeats) [ \ + entry $bottom_frame.repeats_lbl -state readonly \ + -fg {#888888} -bg ${::COMMON_BG_COLOR} \ + -relief flat -highlightthickness 0 -bd 0 \ + -readonlybackground ${::COMMON_BG_COLOR} \ + -disabledforeground {#000000} \ -textvariable ::SpecCalc::timer2_repeats_$obj_idx \ ] set ::SpecCalc::timer2_repeats_$obj_idx [mc "none"] @@ -860,9 +865,9 @@ class SpecCalc { # - Rest set widgets(timer2,rest) [ \ entry $bottom_frame.rest_r_lbl -state readonly \ - -fg {#888888} -bg {#EEEEEE} \ + -fg {#888888} -bg ${::COMMON_BG_COLOR} \ -relief flat -highlightthickness 0 -bd 0 \ - -readonlybackground {#EEEEEE} \ + -readonlybackground ${::COMMON_BG_COLOR} \ -disabledforeground {#000000} \ -textvariable ::SpecCalc::timer2_rest_$obj_idx \ ] @@ -874,13 +879,13 @@ class SpecCalc { # Create page header - pack [label $preset_frame.header \ - -text [mc "Calculate timer 2 preset"] \ - -font [font create \ - -family {helvetica} \ - -size -17 \ - -weight bold \ - ] \ + pack [label $preset_frame.header \ + -text [mc "Calculate timer 2 preset"] \ + -font [font create \ + -family {helvetica} \ + -size [expr {int(-17 * $::font_size_factor)}] \ + -weight bold \ + ] \ ] -pady 5 pack $top_frame -pady 5 -anchor nw pack [ttk::separator $preset_frame.sep \ @@ -892,11 +897,11 @@ class SpecCalc { if {[llength $config]} { $widgets(timer2,time_ent) insert 0 [lindex $config {2 0}] $widgets(timer2,time_cb) current [lindex $config {2 1}] - $widgets(timer2,clock_cb) delete 0 end - $widgets(timer2,clock_cb) insert 0 [lindex $config {1 2}] + $widgets(timer2,clock_cb) delete 0 end + $widgets(timer2,clock_cb) insert 0 [lindex $config {1 2}] $widgets(timer2,clock_type_cb) current [lindex $config {2 3}] $widgets(timer2,mode_cb) current [lindex $config {2 4}] - } { + } else { $widgets(timer2,time_cb) current 1 $widgets(timer2,clock_cb) current 2 $widgets(timer2,clock_type_cb) current 0 @@ -972,10 +977,10 @@ class SpecCalc { # - RCAL2H set widgets(timer2,clk_rcal2h) [ entry $bottom_frame.clk_rcal2h_r_lbl -state readonly \ - -fg {#888888} -bg {#EEEEEE} -validate key \ + -fg {#888888} -bg ${::COMMON_BG_COLOR} -validate key \ -relief flat -highlightthickness 0 -bd 0 -width 5 \ -textvariable ::SpecCalc::timer2_clk_rcal2h_$obj_idx \ - -readonlybackground {#EEEEEE} \ + -readonlybackground ${::COMMON_BG_COLOR} \ -disabledforeground {#000000} \ ] set ::SpecCalc::timer2_clk_rcal2h_$obj_idx "--" @@ -983,10 +988,10 @@ class SpecCalc { # - RCAL2L set widgets(timer2,clk_rcal2l) [ entry $bottom_frame.clk_rcal2l_r_lbl -state readonly \ - -fg {#888888} -bg {#EEEEEE} -validate key \ + -fg {#888888} -bg ${::COMMON_BG_COLOR} -validate key \ -relief flat -highlightthickness 0 -bd 0 -width 5 \ -textvariable ::SpecCalc::timer2_clk_rcal2l_$obj_idx \ - -readonlybackground {#EEEEEE} \ + -readonlybackground ${::COMMON_BG_COLOR} \ -disabledforeground {#000000} \ ] set ::SpecCalc::timer2_clk_rcal2l_$obj_idx "--" @@ -994,10 +999,10 @@ class SpecCalc { # RCAL2H set widgets(timer2,clk_rcal2h_d) [ entry $bottom_frame.clk_rcal2h_d_r_lbl -state readonly \ - -fg {#888888} -bg {#EEEEEE} -validate key \ + -fg {#888888} -bg ${::COMMON_BG_COLOR} -validate key \ -relief flat -highlightthickness 0 -bd 0 -width 5 \ -textvariable ::SpecCalc::timer2_clk_rcal2h_d_$obj_idx \ - -readonlybackground {#EEEEEE} \ + -readonlybackground ${::COMMON_BG_COLOR} \ -disabledforeground {#000000} \ ] set ::SpecCalc::timer2_clk_rcal2h_d_$obj_idx "--" @@ -1005,10 +1010,10 @@ class SpecCalc { # - RCAL2L set widgets(timer2,clk_rcal2l_d) [ entry $bottom_frame.clk_rcal2l_d_r_lbl -state readonly \ - -fg {#888888} -bg {#EEEEEE} -validate key \ + -fg {#888888} -bg ${::COMMON_BG_COLOR} -validate key \ -relief flat -highlightthickness 0 -bd 0 -width 5 \ -textvariable ::SpecCalc::timer2_clk_rcal2l_d_$obj_idx \ - -readonlybackground {#EEEEEE} \ + -readonlybackground ${::COMMON_BG_COLOR} \ -disabledforeground {#000000} \ ] set ::SpecCalc::timer2_clk_rcal2l_d_$obj_idx "--" @@ -1016,10 +1021,10 @@ class SpecCalc { # - Error set widgets(timer2,clk_error) [ entry $bottom_frame.clk_error_r_lbl -state readonly \ - -fg {#888888} -bg {#EEEEEE} -validate key \ + -fg {#888888} -bg ${::COMMON_BG_COLOR} -validate key \ -relief flat -highlightthickness 0 -bd 0 -width 12 \ -textvariable ::SpecCalc::timer2_clk_error_$obj_idx \ - -readonlybackground {#EEEEEE} \ + -readonlybackground ${::COMMON_BG_COLOR} \ -disabledforeground {#000000} \ ] set ::SpecCalc::timer2_clk_error_$obj_idx "--" @@ -1033,30 +1038,30 @@ class SpecCalc { set ::SpecCalc::timer2_clk_fosc_$obj_idx [lindex $config {3 0}] set ::SpecCalc::timer2_clk_freq_$obj_idx [lindex $config {3 1}] set ::SpecCalc::timer2_clk_x2_$obj_idx [lindex $config {3 2}] - } { + } else { set ::SpecCalc::timer2_clk_fosc_$obj_idx {} set ::SpecCalc::timer2_clk_freq_$obj_idx {} set ::SpecCalc::timer2_clk_x2_$obj_idx {0} } # Create page header - pack [label $clock_out_frame.header \ - -text [mc "Calculate clock output"] \ - -font [font create \ - -family {helvetica} \ - -size -17 \ - -weight bold \ - ] \ + pack [label $clock_out_frame.header \ + -text [mc "Calculate clock output"] \ + -font [font create \ + -family {helvetica} \ + -size [expr {int(-17 * $::font_size_factor)}] \ + -weight bold \ + ] \ ] -pady 5 - pack [label $clock_out_frame.math \ - -image [image create photo \ - -format png \ - -file "${::LIB_DIRNAME}/../icons/other/math0.png" \ - ] \ + pack [label $clock_out_frame.math \ + -image [image create photo \ + -format png \ + -file "${::ROOT_DIRNAME}/icons/other/math0.png" \ + ] \ ] -pady 5 pack $bottom_frame -anchor nw $nb raise {Preset} - pack $nb -fill both -expand 1 + pack [$nb get_nb] -fill both -expand 1 } ## Create page for calculating SPI related values @@ -1102,10 +1107,10 @@ class SpecCalc { grid $widgets(spi,sck_ent00) -row 2 -column 2 grid [label $top_frame.spr1_1_lbl \ - -text "0" \ + -text "0" \ ] -row 3 -column 0 grid [label $top_frame.spr0_1_lbl \ - -text "1" \ + -text "1" \ ] -row 3 -column 1 set widgets(spi,sck_ent01) [ttk::entry $top_frame.sck_1_ent \ -width 9 \ @@ -1115,10 +1120,10 @@ class SpecCalc { grid $widgets(spi,sck_ent01) -row 3 -column 2 grid [label $top_frame.spr1_2_lbl \ - -text "1" \ + -text "1" \ ] -row 4 -column 0 grid [label $top_frame.spr0_2_lbl \ - -text "0" \ + -text "0" \ ] -row 4 -column 1 set widgets(spi,sck_ent10) [ttk::entry $top_frame.sck_2_ent \ -width 9 \ @@ -1128,10 +1133,10 @@ class SpecCalc { grid $widgets(spi,sck_ent10) -row 4 -column 2 grid [label $top_frame.spr1_3_lbl \ - -text "1" \ + -text "1" \ ] -row 5 -column 0 grid [label $top_frame.spr0_3_lbl \ - -text "1" \ + -text "1" \ ] -row 5 -column 1 set widgets(spi,sck_ent11) [ttk::entry $top_frame.sck_3_ent \ -width 9 \ @@ -1144,26 +1149,26 @@ class SpecCalc { pack [label $bottom_frame.res_lbl0 \ -text [mc "Set MCU oscillator to "] \ ] -side left - set widgets(spi,result) [ \ - entry $bottom_frame.result_ent \ - -readonlybackground {#EEEEEE} \ - -disabledforeground {#000000} \ - -bg {#EEEEEE} -width 0 -bd 1 -state readonly \ - -relief flat -highlightthickness 0 \ - -textvariable ::SpecCalc::spi_result_$obj_idx \ + set widgets(spi,result) [ \ + entry $bottom_frame.result_ent \ + -readonlybackground ${::COMMON_BG_COLOR} \ + -disabledforeground {#000000} \ + -bg ${::COMMON_BG_COLOR} -width 0 -bd 1 -state readonly \ + -relief flat -highlightthickness 0 \ + -textvariable ::SpecCalc::spi_result_$obj_idx \ ] pack $widgets(spi,result) -side left pack [label $bottom_frame.res_lbl1 \ - -text [mc " kHz"] \ + -text [mc " kHz"] \ ] -side left - pack [label $pages($page).header \ - -text [mc "Calculate oscillator frequency"] \ - -font [font create \ - -family {helvetica} \ - -size -17 \ - -weight bold \ - ] \ + pack [label $pages($page).header \ + -text [mc "Calculate oscillator frequency"] \ + -font [font create \ + -family {helvetica} \ + -size [expr {int(-17 * $::font_size_factor)}] \ + -weight bold \ + ] \ ] -pady 5 pack $top_frame -pady 5 -anchor nw pack [ttk::separator $pages($page).sep \ @@ -1205,7 +1210,7 @@ class SpecCalc { } } - ## Auxiliary procedure for procedure "calculate_loops" + ## Auxiliary function for function "calculate_loops" # @parm float time # @parm float rest # @parm Bool is_spec @@ -1239,7 +1244,7 @@ class SpecCalc { set time [expr {$time / $div}] if {$res($len) == 256} { set res($len) 0 - } { + } else { set res($len) $div } @@ -1250,7 +1255,7 @@ class SpecCalc { incr len if {$len > 1} { incr res(0) -2 - } { + } else { incr res(0) -1 } set correction 0 @@ -1266,13 +1271,13 @@ class SpecCalc { if {$i == 1} { if {[lindex $is_spec $i]} { set correction 1 - } { + } else { set correction 2 } - } { + } else { if {[lindex $is_spec $i]} { set correction [expr {($correction * $res($i)) + ($res($i) * 2) + 1}] - } { + } else { set correction [expr {($correction * $res($i)) + ($res($i) * 3) + 2}] } } @@ -1282,10 +1287,126 @@ class SpecCalc { return [list $rest $len [array get res]] } - ## Report an error occured during evaluation of the wait loop - # @return void - private method calculate_loops_evaluation_error {} { - error "Please report this bug. Method ::SpecCalc::calculate_loops --> Evaluation error. Dump: \n\$widgets(loops,time_ent) == $widgets(loops,time_ent)\n\$widgets(loops,time_cb) == $widgets(loops,time_cb)\n\$widgets(loops,clock_cb) == $widgets(loops,clock_cb)\n\$widgets(loops,clock_type_cb) == $widgets(loops,clock_type_cb)\n\$widgets(loops,reg_ent0) == $widgets(loops,reg_ent0)\n\$widgets(loops,reg_ent1) == $widgets(loops,reg_ent1)\n\$widgets(loops,reg_ent2) == $widgets(loops,reg_ent2)\n\$widgets(loops,reg_ent3) == $widgets(loops,reg_ent3)\n\$widgets(loops,reg_ent4) == $widgets(loops,reg_ent4)\n\$widgets(loops,reg_ent5) == $widgets(loops,reg_ent5)\n\$widgets(loops,reg_ent6) == $widgets(loops,reg_ent6)\n\$widgets(loops,reg_ent7) == $widgets(loops,reg_ent7)" + private method calculate_loops_AUX2 {time clock is_spec} { + set time_org $time + set i 0 + set result [list] + set lowest_rest {} + set last_rest {} + set result_c {} + set result_fin_i 0 + for {set i 0} {$i < 8} {incr i} { + set rest $time_org + set time [expr {int($time)}] + set rest [expr {$rest - $time}] + + if {!$i && $time_org < 2.0} { + lappend result [list [expr {$time_org * 2.0 + 1.0}] 0 [list 0 {} 1 {} 2 {} 3 {} 4 {} 5 {} 6 {} 7 {}]] + break + } + + set result_c [calculate_loops_AUX $time $rest $is_spec] + if {$result_c == {0}} { + return {} + } + lappend result $result_c + + if {$lowest_rest == {}} { + set lowest_rest [lindex $result_c 0] + + } elseif {$lowest_rest < 0} { + if { + ( [lindex $result_c 0] >= 0 ) + || + ( abs($lowest_rest) > abs([lindex $result_c 0]) ) + } then { + set result_fin_i $i + set lowest_rest [lindex $result_c 0] + } + + } elseif { + ( [lindex $result_c 0] >= 0 ) + && + ( $lowest_rest > [lindex $result_c 0] ) + } then { + set result_fin_i $i + set lowest_rest [lindex $result_c 0] + } + + if {$last_rest == [lindex $result_c 0] || ![lindex $result_c 0]} { + break + } + set last_rest [lindex $result_c 0] + set time [expr {$time_org + ($last_rest / 2.0)}] + } + + return [lindex $result $result_fin_i] + } + + private method calculate_loops_AUX3 {len is_spec res_list reg_list} { + set e_no_of_spaces ${::Editor::number_of_spaces} + if {$e_no_of_spaces == 1} { + set e_no_of_spaces 5 + } elseif {$e_no_of_spaces <= 4} { + set e_no_of_spaces 6 + } + + array set res $res_list + array set reg $reg_list + set last_branch 0 + set branch 0 + for {set i 0} {$i < $len} {incr i} { + set branch $last_branch + set val $res($i) + + set val [string range [format {%X} $res($i)] end-1 end] + set val "[string repeat {0} [expr {3 - [string length $val]}]]$val" + + set cmp {} + if {[lindex $is_spec $i]} { + if {!$i} { + if {${::Editor::spaces_no_tabs}} { + set cmp "\n[string repeat { } ${::Editor::number_of_spaces}]NOP" + } else { + set cmp "\n\tNOP" + } + incr branch 1 + } + } else { + incr branch 2 + } + incr branch 4 + + set last_branch $branch + if {!$i} { + set branch 0 + incr last_branch -4 + } + + if {$branch == {0}} { + set branch {} + } else { + set branch "-$branch" + } + + if {${::Editor::spaces_no_tabs}} { + set res($i) [list \ + "[string repeat { } ${::Editor::number_of_spaces}]DJNZ[string repeat { } [expr {$e_no_of_spaces - 4}]]$reg($i), \$$branch" \ + "[string repeat { } ${::Editor::number_of_spaces}]MOV[string repeat { } [expr {$e_no_of_spaces - 3}]]$reg($i), #${val}h$cmp" \ + ] + } else { + set res($i) [list \ + "\tDJNZ\t$reg($i), \$$branch" \ + "\tMOV\t$reg($i), #${val}h$cmp" \ + ] + } + } + for {set i [expr {$len - 1}]} {$i >= 0} {incr i -1} { + $widgets(loops,results) insert end "[lindex $res($i) 1]\n" + } + for {set i 0} {$i < $len} {incr i} { + $widgets(loops,results) insert end "[lindex $res($i) 0]\n" + } } ## Generate wait loop acoring to specified criteria @@ -1302,7 +1423,7 @@ class SpecCalc { if {[lsearch -ascii -exact {R0 R1 R2 R3 R4 R5 R6 R7 A} [string toupper $reg($i)]] != -1} { lappend is_spec 1 - } { + } else { lappend is_spec 0 } } @@ -1329,52 +1450,28 @@ class SpecCalc { return 0 } + set e_no_of_spaces ${::Editor::number_of_spaces} + if {$e_no_of_spaces == 1} { + set e_no_of_spaces 5 + } elseif {$e_no_of_spaces <= 4} { + set e_no_of_spaces 6 + } + set time [expr {$time * [lindex {1.0 1000.0 1000000.0 1000000000.0} [$widgets(loops,time_cb) current]] / 2.0}] - set clock [expr {[lindex {12.0 6.0 1.0} [$widgets(loops,clock_type_cb) current]] / $clock}] + set clock [expr {$clock / [lindex {12000000.0 6000000.0 1000000.0} [$widgets(loops,clock_type_cb) current]]}] set time [expr {$time * $clock}] - set time_org $time - set i 0 - set result [list] - set lowes_rest $time - set last_rest {} - set result_c {} - set result_fin_i 0 - for {set i 0} {$i < 8} {incr i} { - - set rest $time_org - set time [expr {int($time)}] - set rest [expr {$rest - $time}] - - set result_c [calculate_loops_AUX $time $rest $is_spec] - if {$result_c == {0}} { - return 0 - } - lappend result $result_c - - if {$lowes_rest == {}} { - set lowes_rest [lindex $result_c 0] - - } elseif {($lowes_rest < 0) && ([lindex $result_c 0] >= 0)} { - set result_fin_i $i - set lowes_rest [lindex $result_c 0] - - } elseif {abs($lowes_rest) > abs([lindex $result_c 0])} { - set result_fin_i $i - set lowes_rest [lindex $result_c 0] - } - - if {$last_rest == [lindex $result_c 0] || ![lindex $result_c 0]} { - break - } - set last_rest [lindex $result_c 0] - set time [expr {$time_org + ($last_rest / 2.0)}] + if {$time <= 258.5} { + set time [expr {$time - 0.5}] } - set time $time_org - set rest [lindex $result [list $result_fin_i 0]] - set len [lindex $result [list $result_fin_i 1]] - array set res [lindex $result [list $result_fin_i 2]] + set final_results [calculate_loops_AUX2 $time $clock $is_spec] + if {$final_results == {}} { + return 0 + } + set rest [lindex $final_results 0] + set len [lindex $final_results 1] + array set res [lindex $final_results 2] for {set i 0} {$i < $len} {incr i} { set error 0 @@ -1402,87 +1499,62 @@ class SpecCalc { } $widgets(loops,results) insert end "\n" - set last_branch 0 - set branch 0 - for {set i 0} {$i < $len} {incr i} { - set branch $last_branch - set val $res($i) - - set val [string range [format {%X} $res($i)] end-1 end] - set val "[string repeat {0} [expr {3 - [string length $val]}]]$val" - - set cmp {} - if {[lindex $is_spec $i]} { - if {!$i} { - set cmp "\n\tNOP" - incr branch 1 - } - } { - incr branch 2 - } - incr branch 4 + calculate_loops_AUX3 $len $is_spec [array get res] [array get reg] - set last_branch $branch - if {!$i} { - set branch 0 - incr last_branch -4 - } - if {$branch == {0}} { - set branch {} - } { - set branch "-$branch" + while {$rest > 514} { + set final_results [calculate_loops_AUX2 [expr {$rest / 2.0}] $clock $is_spec] + if {$final_results == {}} { + return 0 } - - set res($i) [list \ - "\tDJNZ\t$reg($i), \$$branch" \ - "\tMOV\t$reg($i), #${val}h$cmp" \ - ] - } - - for {set i [expr {$len - 1}]} {$i >= 0} {incr i -1} { - $widgets(loops,results) insert end "[lindex $res($i) 1]\n" - } - - for {set i 0} {$i < $len} {incr i} { - $widgets(loops,results) insert end "[lindex $res($i) 0]\n" + set rest [lindex $final_results 0] + calculate_loops_AUX3 [lindex $final_results 1] $is_spec [lindex $final_results 2] [array get reg] } if {$rest <= 4} { for {set i 0} {$i < 5} {incr i} { - if {int(ceil($rest)) > 0.5} { - $widgets(loops,results) insert end "\tNOP\n" + if {int(ceil($rest)) >= 0.5} { + if {${::Editor::spaces_no_tabs}} { + $widgets(loops,results) insert end "[string repeat { } ${::Editor::number_of_spaces}]NOP\n" + } else { + $widgets(loops,results) insert end "\tNOP\n" + } set rest [expr {$rest - 1}] } } - } { + } else { if {[lindex $is_spec 0]} { set rest [expr {$rest - 1}] - } { + } else { set rest [expr {$rest - 2}] } set val [expr {int($rest / 2)}] set rest [expr {$rest - ($val * 2.0)}] if {$val == 256} { set val 0 - } elseif {$val > 256} { - status_tip [mc "Unable to evaluate"] - calculate_loops_clear_results - return 0 } + set val [string range [format {%X} $val] end-1 end] set val "[string repeat {0} [expr {3 - [string length $val]}]]$val" - $widgets(loops,results) insert end "\tMOV\t$reg(0), #${val}h\n" - $widgets(loops,results) insert end "\tDJNZ\t$reg(0), \$\n" - if {int(ceil($rest)) > 0.5} { - $widgets(loops,results) insert end "\tNOP\n" - set rest [expr {$rest - 1}] + if {${::Editor::spaces_no_tabs}} { + $widgets(loops,results) insert end "[string repeat { } ${::Editor::number_of_spaces}]MOV[string repeat { } [expr {$e_no_of_spaces - 3}]]$reg(0), #${val}h\n" + $widgets(loops,results) insert end "[string repeat { } ${::Editor::number_of_spaces}]DJNZ[string repeat { } [expr {$e_no_of_spaces - 4}]]$reg(0), \$\n" + if {int(ceil($rest)) >= 0.5} { + $widgets(loops,results) insert end "[string repeat { } ${::Editor::number_of_spaces}]NOP\n" + set rest [expr {$rest - 1}] + } + } else { + $widgets(loops,results) insert end "\tMOV\t$reg(0), #${val}h\n" + $widgets(loops,results) insert end "\tDJNZ\t$reg(0), \$\n" + if {int(ceil($rest)) >= 0.5} { + $widgets(loops,results) insert end "\tNOP\n" + set rest [expr {$rest - 1}] + } } } set rest [expr {$rest * 1.0 / $clock}] $widgets(loops,results) insert end [mc "; Rest: %s\n" [adjust_rest $rest]] - $widgets(loops,results) insert end [mc "; END: Wait loop"] set end [expr {int([$widgets(loops,results) index end])}] @@ -1510,7 +1582,7 @@ class SpecCalc { private method calculate_loops_enable_copy {enable} { if {$enable} { set enable {normal} - } { + } else { set enable {disabled} } $widgets(loops,copy_but) configure -state $enable @@ -1521,13 +1593,11 @@ class SpecCalc { public method calculate_timer01 {} { set time [$widgets(timer01,time_ent) get] if {$time == {} || $time == 0} { - status_tip [mc "Invalid time"] return 0 } set clock [$widgets(timer01,clock_cb) get] if {$clock == {} || $clock == 0} { - status_tip [mc "Invalid clock rate"] return 0 } status_tip "" @@ -1544,11 +1614,11 @@ class SpecCalc { } set time [expr {$time * [lindex {1.0 1000.0 1000000.0 1000000000.0} [$widgets(timer01,time_cb) current]]}] - set clock [expr {[lindex {12.0 6.0 1.0} [$widgets(timer01,clock_type_cb) current]] / $clock}] + set clock [expr {$clock / [lindex {12000000.0 6000000.0 1000000.0} [$widgets(timer01,clock_type_cb) current]]}] set time [expr {$time * $clock}] set time_int [expr {int($time)}] - set enhanced [subst "\$::SpecCalc::spec_chb_$obj_idx"] + set enhanced [subst -nocommands "\$::SpecCalc::spec_chb_$obj_idx"] set prescaler [$widgets(timer01,psc_cb) current] # Set default results @@ -1561,7 +1631,7 @@ class SpecCalc { {0} { ;# 9 -> 16 bit counter if {$enhanced} { set bits [expr {$prescaler + 9}] - } { + } else { set bits 13 } set capacity [expr {1 << $bits}] @@ -1574,7 +1644,7 @@ class SpecCalc { if {[expr {!($time_int & $full_mask)}]} { incr repeats -1 set stepsPerIter $full_mask - } { + } else { set stepsPerIter [expr {$time_int / $repeats}] set tmp [expr {$capacity - $stepsPerIter}] set low [expr {$tmp & $low_mask}] @@ -1592,7 +1662,6 @@ class SpecCalc { set rest [adjust_rest $rest] if {$repeats > 1} { - status_tip [mc "Value is too high"] return 0 } @@ -1619,7 +1688,7 @@ class SpecCalc { incr repeats -1 set stepsPerIter 0xFFFF set tmp 0 - } { + } else { set stepsPerIter [expr {$time_int / $repeats}] set tmp [expr {0x10000 - $stepsPerIter}] set low [expr {$tmp & 0xFF}] @@ -1637,7 +1706,7 @@ class SpecCalc { if {$tmp < 0} { set rest [expr {abs($tmp)}] set tmp 0 - } { + } else { set rest 0 } set tmp [expr {$tmp & 0x0FFFF}] @@ -1666,7 +1735,7 @@ class SpecCalc { foreach w {rh rl tl th rest repeats} { $widgets(timer01,$w) configure -fg {#000000} } - } { + } else { if {$repeats > 1} { status_tip [mc "Value is too high"] return 0 @@ -1688,7 +1757,7 @@ class SpecCalc { if {[expr {!($time_int & 0xFF)}]} { incr repeats -1 set stepsPerIter 0xFF - } { + } else { set stepsPerIter [expr {$time_int / $repeats}] set low [expr {0x100 - $stepsPerIter}] set high $low @@ -1705,7 +1774,7 @@ class SpecCalc { if {$low < 0} { set rest [expr {abs($low)}] set low 0 - } { + } else { set rest 0 } @@ -1736,13 +1805,11 @@ class SpecCalc { public method calculate_timer2 {} { set time [$widgets(timer2,time_ent) get] if {$time == {} || $time == 0} { - status_tip [mc "Invalid time"] return 0 } set clock [$widgets(timer2,clock_cb) get] if {$clock == {} || $clock == 0} { - status_tip [mc "Invalid clock rate"] return 0 } status_tip "" @@ -1759,7 +1826,7 @@ class SpecCalc { } set time [expr {$time * [lindex {1.0 1000.0 1000000.0 1000000000.0} [$widgets(timer2,time_cb) current]]}] - set clock [expr {[lindex {12.0 6.0 1.0} [$widgets(timer2,clock_type_cb) current]] / $clock}] + set clock [expr {$clock / [lindex {12000000.0 6000000.0 1000000.0} [$widgets(timer2,clock_type_cb) current]]}] set time [expr {$time * $clock}] set time_int [expr {int($time)}] set mode [$widgets(timer2,mode_cb) current] @@ -1781,13 +1848,13 @@ class SpecCalc { set low_p $low set high_p $high - } { + } else { # Calculate tempotary results if {[expr {!($time_int & 0xFFFF)}]} { incr repeats -1 set stepsPerIter 0xFFFF set tmp 0 - } { + } else { set stepsPerIter [expr {$time_int / $repeats}] set tmp [expr {0x10000 - $stepsPerIter}] set rest [expr {$time_int - ((0x10000 - $tmp) * $repeats)}] @@ -1805,7 +1872,7 @@ class SpecCalc { if {$tmp < 0} { set rest [expr {abs($tmp)}] set tmp 0 - } { + } else { set rest 0 } set tmp [expr {$tmp & 0x0FFFF}] @@ -1911,9 +1978,9 @@ class SpecCalc { ## Perform calculation intented for page "Timer 2 clock output" # @return void public method calculate_timer2_clk {} { - set o [subst "\$::SpecCalc::timer2_clk_fosc_$obj_idx"] - set f [subst "\$::SpecCalc::timer2_clk_freq_$obj_idx"] - set x [subst "\$::SpecCalc::timer2_clk_x2_$obj_idx"] + set o [subst -nocommands "\$::SpecCalc::timer2_clk_fosc_$obj_idx"] + set f [subst -nocommands "\$::SpecCalc::timer2_clk_freq_$obj_idx"] + set x [subst -nocommands "\$::SpecCalc::timer2_clk_x2_$obj_idx"] if { ![string length $o] || ![string length $f] || ![string length $x] || $f == 0 || $o == 0 @@ -1950,7 +2017,7 @@ class SpecCalc { # @parm # @return void private method calculate_spi {type value} { - set const [subst "\$::SpecCalc::double_chb_$obj_idx"] + set const [subst -nocommands "\$::SpecCalc::double_chb_$obj_idx"] switch -- $type { {sck_ent00} { @@ -2085,14 +2152,10 @@ class SpecCalc { return 1 } {compute_but} { - if {[catch { - if {[calculate_loops]} { - calculate_loops_enable_copy 1 - } { - calculate_loops_enable_copy 0 - } - }]} { - calculate_loops_evaluation_error + if {[calculate_loops]} { + calculate_loops_enable_copy 1 + } else { + calculate_loops_enable_copy 0 } } {copy_but} { @@ -2160,7 +2223,7 @@ class SpecCalc { grid $widgets(timer01,rl) -row 4 -column 3 -sticky w grid $widgets(timer01,eq3) -row 3 -column 2 grid $widgets(timer01,eq4) -row 4 -column 2 - } { + } else { grid forget $widgets(timer01,psc_lbl) grid forget $widgets(timer01,psc_cb) grid forget $widgets(timer01,rh_l) @@ -2327,25 +2390,25 @@ class SpecCalc { switch -- [$widgets(timer01,mode_cb) current] { 0 { set title [mc "Timer 0/1 in mode 0"] - if {[subst "\${::SpecCalc::spec_chb_$obj_idx}"]} { + if {[subst -nocommands "\${::SpecCalc::spec_chb_$obj_idx}"]} { set image {timer_01_0e} - } { + } else { set image {timer_01_0} } } 1 { set title [mc "Timer 0/1 in mode 1"] - if {[subst "\${::SpecCalc::spec_chb_$obj_idx}"]} { + if {[subst -nocommands "\${::SpecCalc::spec_chb_$obj_idx}"]} { set image {timer_01_1e} - } { + } else { set image {timer_01_1} } } 2 { set title [mc "Timer 0/1 in mode 2"] - if {[subst "\${::SpecCalc::spec_chb_$obj_idx}"]} { + if {[subst -nocommands "\${::SpecCalc::spec_chb_$obj_idx}"]} { set image {timer_01_2e} - } { + } else { set image {timer_01_2} } } @@ -2376,9 +2439,9 @@ class SpecCalc { } } - set dlg [toplevel .spec_calc_diagram_$diagram_counter -class [mc "Diagram or formula"] -bg {#EEEEEE}] + set dlg [toplevel .spec_calc_diagram_$diagram_counter -class [mc "Diagram or formula"] -bg ${::COMMON_BG_COLOR}] pack [label $dlg.image \ - -image [image create photo -format png -file "${::LIB_DIRNAME}/../icons/other/$image.png"] + -image [image create photo -format png -file "${::ROOT_DIRNAME}/icons/other/$image.png"] ] -fill both wm title $dlg $title @@ -2388,3 +2451,7 @@ class SpecCalc { incr diagram_counter } } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/utilities/symbol_viewer.tcl b/lib/utilities/symbol_viewer.tcl old mode 100755 new mode 100644 index 3df57b4..c46b8ac --- a/lib/utilities/symbol_viewer.tcl +++ b/lib/utilities/symbol_viewer.tcl @@ -2,7 +2,7 @@ # Part of MCU 8051 IDE ( http://mcu8051ide.sf.net ) ############################################################################ -# Copyright (C) 2007-2009 by Martin Ošmera # +# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera # # martin.osmera@gmail.com # # # # This program is free software; you can redistribute it and#or modify # @@ -21,6 +21,11 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################ +# >>> File inclusion guard +if { ! [ info exists _SYMBOL_VIEWER_TCL ] } { +set _SYMBOL_VIEWER_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Implements assembly language symbols viewer (from code listing) @@ -31,17 +36,21 @@ class SymbolViewer { # Int: Counter of object intances common count 0 # Font: Just normal font used in the table - common normal_font [font create \ - -family $::DEFAULT_FIXED_FONT \ - -size -15 \ - -weight normal \ + common normal_font [font create \ + -family $::DEFAULT_FIXED_FONT \ + -size [expr {int(-14 * $::font_size_factor)}] \ + -weight normal \ ] # Font: Bold font (the same size as $normal_font) - common bold_font [font create \ - -family $::DEFAULT_FIXED_FONT \ - -size -15 \ - -weight bold \ + common bold_font [font create \ + -family $::DEFAULT_FIXED_FONT \ + -size [expr {int(-14 * $::font_size_factor)}] \ + -weight bold \ ] + if {$::MICROSOFT_WINDOWS} { + # it's better to do not use bold font for this purpose on MS Windows® + set bold_font $normal_font + } # Dialog configuration common config_list $::CONFIG(SYMBOL_VIEWER_CONFIG) @@ -62,7 +71,7 @@ class SymbolViewer { constructor {} { # Create dialog window - set win [toplevel .symbolviewer$count -class {Defined symbols} -bg {#EEEEEE}] + set win [toplevel .symbolviewer$count -class {Defined symbols} -bg ${::COMMON_BG_COLOR}] set obj_idx $count incr count @@ -93,16 +102,19 @@ class SymbolViewer { # Configure dialog window wm iconphoto $win ::ICONS::16::symbol wm title $win [mc "Assembly symbol table - MCU 8051 IDE"] - wm minsize $win 620 350 + wm minsize $win 520 350 wm protocol $win WM_DELETE_WINDOW "$this close_window" + update catch { - wm geometry $win [lindex $config_list $i] + wm geometry $win [regsub {^\=?\d+x\d+} [lindex $config_list $i] \ + [regsub {\+\d+\+\d+$} [wm geometry $win] {}] \ + ] } # Set ... incr i set ::SymbolViewer::display_${obj_idx}(Special) [lindex $config_list $i] - if {[subst "\$::SymbolViewer::display_${obj_idx}(Special)"] == {}} { + if {[subst -nocommands "\$::SymbolViewer::display_${obj_idx}(Special)"] == {}} { set ::SymbolViewer::display_${obj_idx}(Special) 1 } } @@ -114,16 +126,16 @@ class SymbolViewer { } set i 0 foreach name {DATA IDATA XDATA CODE BIT Number used unused} { - lset config_list $i [subst "\$::SymbolViewer::display_${obj_idx}($name)"] + lset config_list $i [subst -nocommands "\$::SymbolViewer::display_${obj_idx}($name)"] incr i } - lset config_list $i [subst "\$::SymbolViewer::sort_by_${obj_idx}"] + lset config_list $i [subst -nocommands "\$::SymbolViewer::sort_by_${obj_idx}"] incr i - lset config_list $i [subst "\$::SymbolViewer::sort_by_order_${obj_idx}"] + lset config_list $i [subst -nocommands "\$::SymbolViewer::sort_by_order_${obj_idx}"] incr i lset config_list $i [wm geometry $win] incr i - lset config_list $i [subst "\$::SymbolViewer::display_${obj_idx}(Special)"] + lset config_list $i [subst -nocommands "\$::SymbolViewer::display_${obj_idx}(Special)"] # Clean up unset ::SymbolViewer::sort_by_${obj_idx} @@ -182,7 +194,7 @@ class SymbolViewer { $text_widget tag configure used_YES -foreground {#00DD00} $text_widget tag configure used_NO -foreground {#DD0000} $text_widget tag configure tag_sel -background {#DDDDDD} -font $bold_font - $text_widget tag configure nth_row -background {#EEEEEE} + $text_widget tag configure nth_row -background ${::COMMON_BG_COLOR} $text_widget tag raise tag_sel nth_row } @@ -383,10 +395,10 @@ class SymbolViewer { if {$opened_file == {}} { if {${::X::project_menu_locked}} { set directory {~} - } { + } else { set directory [${::X::actualProject} cget -projectPath] } - } { + } else { set directory [file dirname $opened_file] } @@ -394,10 +406,10 @@ class SymbolViewer { KIFSD::FSD ::fsd \ -title [mc "Load symbol table - MCU 8051 IDE"] \ -directory $directory -master $win \ - -defaultmask 0 -multiple 0 -filetypes { - {{Code listing} {*.lst} } - {{All files} {*} } - } + -defaultmask 0 -multiple 0 -filetypes [list \ + [list [mc "Code listing"] {*.lst} ] \ + [list [mc "All files"] {*} ] \ + ] # Open the selected after press of OK button ::fsd setokcmd " @@ -420,7 +432,7 @@ class SymbolViewer { public method open_file {ignore_errors filename} { if {[catch { set file [open $filename r] - }]} { + }]} then { if {!$ignore_errors} { tk_messageBox \ -parent $win \ @@ -472,7 +484,7 @@ class SymbolViewer { set type [lindex $line 0] if {$type == {S}} { set addr [lindex $line end] - } { + } else { set addr [string replace [lindex $line 2] end end] } @@ -516,7 +528,7 @@ class SymbolViewer { if {$type == {S} || $type == {R}} { lappend symbol_table_data [list $name $type $addr {0} $used] - } { + } else { lappend symbol_table_data [list $name $type $addr [expr "0x$addr"] $used] } } @@ -528,18 +540,18 @@ class SymbolViewer { refresh } - ## Sort list of loaded symbols acording to user settings + ## Sort list of loaded symbols according to user settings # @return void private method sort_table {} { - if {[subst "\$::SymbolViewer::sort_by_order_${obj_idx}"]} { + if {[subst -nocommands "\$::SymbolViewer::sort_by_order_${obj_idx}"]} { set order {-decreasing} - } { + } else { set order {-increasing} } - set index [subst "\$::SymbolViewer::sort_by_${obj_idx}"] + set index [subst -nocommands "\$::SymbolViewer::sort_by_${obj_idx}"] if {$index == 3} { set type {-integer} - } { + } else { set type {-dictionary} } @@ -562,21 +574,21 @@ class SymbolViewer { {S} {set type {Special}} {R} {set type {Special}} } - if {![subst "\$::SymbolViewer::display_${obj_idx}($type)"]} { + if {![subst -nocommands "\$::SymbolViewer::display_${obj_idx}($type)"]} { return 0 } # Adjust flag USED if {$used} { - if {![subst "\$::SymbolViewer::display_${obj_idx}(used)"]} { + if {![subst -nocommands "\$::SymbolViewer::display_${obj_idx}(used)"]} { return 0 } - set used {YES} - } { - if {![subst "\$::SymbolViewer::display_${obj_idx}(unused)"]} { + set used [mc "YES"] + } else { + if {![subst -nocommands "\$::SymbolViewer::display_${obj_idx}(unused)"]} { return 0 } - set used {NO} + set used [mc "NO"] } return [list $type $used] @@ -602,7 +614,7 @@ class SymbolViewer { lset current_line 1 [string index [lindex $current_line 1] 0] if {[lindex $current_line 4] == {YES}} { lset current_line 4 1 - } { + } else { lset current_line 4 0 } } @@ -646,7 +658,7 @@ class SymbolViewer { if {$type == {Special}} { $text_widget insert insert $hexv $text_widget insert insert [string repeat { } [expr {16 - [string length $hexv]}]] - } { + } else { $text_widget insert insert $hexv $text_widget insert insert { } $text_widget insert insert $decv @@ -673,7 +685,7 @@ class SymbolViewer { if {$cur_found} { $text_widget tag add tag_sel $current_line.0 $current_line.0+1l $text_widget see $current_line.0 - } { + } else { set current_line {} } @@ -706,7 +718,7 @@ class SymbolViewer { set string [string tolower [string trimleft $string 0]] $clear_but configure -state normal # Empty string -> abort - } { + } else { $search_entry configure -style TEntry $clear_but configure -state disabled return 1 @@ -749,7 +761,7 @@ class SymbolViewer { if {$found_idx == -1} { $search_entry configure -style StringNotFound.TEntry # String found - } { + } else { set current_line [expr {$found_idx + 1}] $text_widget tag add tag_sel $current_line.0 $current_line.0+1l $text_widget see $current_line.0 @@ -795,7 +807,7 @@ class SymbolViewer { select_line $x $y if {$current_line == {}} { set state disabled - } { + } else { set state normal } foreach entry {{Copy symbol name} {Copy hex value} {Copy dec value} {Copy line}} { @@ -835,3 +847,7 @@ class SymbolViewer { clipboard append [string trim [$text_widget get $current_line.$s $current_line.$e]] } } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/utilities/table_of_instructions.tcl b/lib/utilities/table_of_instructions.tcl new file mode 100644 index 0000000..b6587b2 --- /dev/null +++ b/lib/utilities/table_of_instructions.tcl @@ -0,0 +1,692 @@ +#!/usr/bin/tclsh +# Part of MCU 8051 IDE ( http://mcu8051ide.sf.net ) + +############################################################################ +# Copyright (C) 2011 by Martin Ošmera # +# 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 _TABLE_OF_INSTRUCTIONS_TCL ] } { +set _TABLE_OF_INSTRUCTIONS_TCL _ +# <<< File inclusion guard + +# -------------------------------------------------------------------------- +# DESCRIPTION +# 8051 Instruction Table +# -------------------------------------------------------------------------- + +class TableOfInstructions { + common tbl_of_inst_count 0 ;# Int: Counter of object instances + common oprs_color {#00DD00} ;# RGB Color: Number of operands + common len_color {#00AA55} ;# RGB Color: Instruction length + common time_color {#8800DD} ;# RGB Color: Time to execute + common ins_color {#0000DD} ;# RGB Color: Instruction mnemonics + + # Font for instruction name + common instruction_font [font create \ + -family {helvetica} \ + -size [expr {int(-10 * $::font_size_factor)}] \ + ] + # Font for numbers below the instruction name + common number_font [font create \ + -family {helvetica} \ + -size [expr {int(-10 * $::font_size_factor)}] \ + -weight {bold} \ + ] + # Font for labels in details frame (normal) + common details_n_font [font create \ + -family {helvetica} \ + -size [expr {int(-12 * $::font_size_factor)}] \ + ] + # Font for labels in details frame (bold) + common details_b_font [font create \ + -family {helvetica} \ + -size [expr {int(-12 * $::font_size_factor)}] \ + -weight {bold} \ + ] + + private variable win ;# Widget: Dialog window + private variable window_visible 0 ;# Bool: Visibility flag + private variable cells ;# Array of Widget: Chart cell frames + private variable vh_cells ;# Array of Widget: Vertical headers + private variable hh_cells ;# Array of Widget: Horizontal headers + private variable selected_cell -1 ;# Int: Currently selected cell + private variable status_bar_lbl ;# Widget: Status bar + private variable validation_ena 1 ;# Bool: EntryBox validation enabled + private variable matrix_frame ;# Widget: Frame for the chart + private variable vertical_scrollbar ;# Widget: Scrollbar for the scrollable frame + private variable scrollable_frame ;# Widget: Scrollable frame containing the chart + + private variable opcode_ent ;# Widget: Entry box with the OP code + private variable title_v_lbl ;# Widget: Label containing instruction name along with its operands + private variable class_v_lbl ;# Widget: Label containing the class + private variable desc_v_lbl ;# Widget: Label containing the description + private variable length_v_lbl ;# Widget: Label containing the length + private variable time_v_lbl ;# Widget: Label containing the time + private variable flags_v_lbl ;# Widget: Label containing the flags + private variable note_v_lbl ;# Widget: Label containing the note + + constructor {} { + # Configure local ttk styles + ttk::style configure TblOfIns_RedBg.TEntry -fieldbackground {#FFDDDD} + ttk::style configure TblOfIns_GreenBg.TEntry -fieldbackground {#DDFFDD} + + # Create dialog window + set window_visible 1 + set win [toplevel .tableofinstructions${tbl_of_inst_count} -class {8051 Instruction Table} -bg ${::COMMON_BG_COLOR}] + incr tbl_of_inst_count + + # Create dialog GUI + create_gui + + # Set window event bindings + bind $win "$this close_window; break" + bindtags $win [list $win Toplevel all .] + + # Set window parameters + wm iconphoto $win ::ICONS::16::fsview + wm title $win "[mc {8051 Instruction Table}] - MCU 8051 IDE" + wm resizable $win 0 1 + wm protocol $win WM_DELETE_WINDOW "$this close_window" + update + + # Compute required width of the window + set w [winfo width $matrix_frame.hh_lbl1] + incr w [winfo width $vertical_scrollbar] + for {set i 0} {$i < 16} {incr i} { + incr w [winfo width $matrix_frame.cell_$i] + incr w + } + wm minsize $win $w 400 + } + + destructor { + destroy $win + } + + ## Determinate wheather the window is visble or not + # @return Bool - Visibility flag + public method is_visible {} { + return $window_visible + } + + ## Raise dialog window (insure than it is visible) + # @return void + public method raise_window {} { + if {!$window_visible} {return} + raise $win . + } + + ## Restore dialog window + # @return void + public method restore_window {} { + set window_visible 1 + wm deiconify $win + raise $win . + } + + ## Close dialog window, but keep object + # @return void + public method close_window {} { + set window_visible 0 + wm withdraw $win + } + + ## Create window GUI + # @return void + private method create_gui {} { + ## Create bottom frame + set bottom_frame [frame $win.bottom_frame] + set status_bar_lbl [label $bottom_frame.status_bar_lbl -justify left -anchor w] + pack $status_bar_lbl -side left -fill x -in $bottom_frame -padx 5 + pack [ttk::button $bottom_frame.close_but \ + -text [mc "Exit"] \ + -command "$this close_window" \ + -compound left \ + -image ::ICONS::16::exit \ + ] -side right -padx 5 -pady 5 + + ## Create main frame + set main_frame [frame $win.main_frame -bg ${::COMMON_BG_COLOR}] + set scrollable_frame [ScrollableFrame $main_frame.scrollable_frame \ + -bg ${::COMMON_BG_COLOR} \ + -yscrollcommand "$main_frame.vertical_scrollbar set" \ + ] + set matrix_frame [$scrollable_frame getframe] + bind $matrix_frame "$scrollable_frame yview scroll +1 units; break" + bind $matrix_frame "$scrollable_frame yview scroll -1 units; break" + set vertical_scrollbar [ttk::scrollbar $main_frame.vertical_scrollbar \ + -orient vertical -command "$main_frame.scrollable_frame yview" \ + ] + # Create vertical header + set header [list {} \ + {0x0_} {0x1_} {0x2_} {0x3_} \ + {0x4_} {0x5_} {0x6_} {0x7_} \ + {0x8_} {0x9_} {0xA_} {0xB_} \ + {0xC_} {0xD_} {0xE_} {0xF_} \ + ] + grid [frame $matrix_frame.top_right_lbl -bg ${::COMMON_BG_COLOR}] -sticky wens -row 0 -column 0 + for {set y 1} {$y < 17} {incr y} { + grid [label $matrix_frame.vh_lbl$y -text [lindex $header $y] -bg {#FFFFFF}] \ + -row $y -column 0 -pady [expr {$y % 2}] -sticky wens + set vh_cells([expr {$y - 1}]) $matrix_frame.vh_lbl$y + } + # Create horizontal header + set header [list {} \ + {0x_0} {0x_1} {0x_2} {0x_3} \ + {0x_4} {0x_5} {0x_6} {0x_7} \ + {0x_8} {0x_9} {0x_A} {0x_B} \ + {0x_C} {0x_D} {0x_E} {0x_F} \ + ] + for {set x 1} {$x < 17} {incr x} { + grid [label $matrix_frame.hh_lbl$x -text [lindex $header $x] -bg {#FFFFFF}] \ + -row 0 -column $x -padx [expr {$x % 2}] -sticky wens + set hh_cells([expr {$x - 1}]) $matrix_frame.hh_lbl$x + } + # Create instruction table + set address -1 + for {set y 1} {$y < 17} {incr y} { + for {set x 1} {$x < 17} {incr x} { + incr address + + # Create cell frame + set frame [frame $matrix_frame.cell_$address \ + -bg white -bd 0 \ + ] + + # Get instruction OP code in 2-digits uppercase hexadecimal form + set opcode [convert_to_opcode $address] + + # Handle undefined OP codes (0xA5) + if {[lsearch -ascii -exact ${::CompilerConsts::defined_OPCODE} $opcode] == -1} { + destroy $frame + continue + } + + # Get some information about the instruction + set def $::CompilerConsts::Opcode($opcode) + set instruction [string toupper [lindex $def 0]] + set operands [llength [lindex $def 1]] + set length [lindex $def 2] + set time [lindex $def 4] + + # Create label containing instruction name + pack [label $frame.ins_lbl \ + -text $instruction \ + -fg $ins_color \ + -bg white \ + -pady 0 \ + -font $instruction_font \ + ] + + # Create label widgets for numbers belowe instruction name + set f [frame $frame.f] + foreach val [list $operands $length $time ] \ + wdg [list oprs_lbl len_lbl time_lbl ] \ + fg [list $oprs_color $len_color $time_color ] \ + { + pack [label $frame.$wdg \ + -text $val \ + -fg $fg \ + -bg white \ + -pady 0 \ + -font $number_font \ + ] -side left + } + pack $f + + grid $frame -row $y -column $x -padx [expr {$x % 2}] -pady [expr {$y % 2}] -sticky wens + set cells($address) $frame + foreach wdg [list $frame $frame.f $frame.ins_lbl $frame.oprs_lbl $frame.len_lbl $frame.time_lbl] { + bind $wdg "$this cell_enter $address" + bind $wdg "$this cell_leave $address" + bind $wdg "$this cell_click $address; focus $frame" + + bind $wdg "$scrollable_frame yview scroll +1 units; break" + bind $wdg "$scrollable_frame yview scroll -1 units; break" + } + + if {$address < 255} { + bind $frame [list $this cell_click [expr {$address + 1}]] + } + if {$address > 0} { + bind $frame [list $this cell_click [expr {$address - 1}]] + } + if {$address > 16} { + bind $frame [list $this cell_click [expr {$address - 16}]] + } + if {$address < 240} { + bind $frame [list $this cell_click [expr {$address + 16}]] + } + } + } + # Ensure than all cells have the same width and heigh + for {set i 0} {$i < 17} {incr i} { + grid columnconfigure $matrix_frame $i -uniform toi + } + for {set i 1} {$i < 17} {incr i} { + grid rowconfigure $matrix_frame $i -uniform toi + } + + # Create middle frame (contains details and legend) + set middle_frame [frame $win.middle_frame] + + ## Create legend + set legend_frame [frame $middle_frame.legend_frame] + grid [label $legend_frame.l_h \ + -font $instruction_font \ + -text "Legend:" \ + ] -column 0 -row 0 -columnspan 2 -sticky w + # Instruction mnemonics + grid [label $legend_frame.l03 \ + -fg $ins_color \ + -bg $ins_color \ + -text {X} \ + -font $number_font \ + ] -column 0 -row 1 -sticky w -padx 2 + grid [label $legend_frame.l13 \ + -text [mc "Mnemonics"] \ + -font $number_font \ + ] -column 1 -row 1 -sticky w + # Number of operands + grid [label $legend_frame.l00 \ + -fg $oprs_color \ + -bg $oprs_color \ + -text {X} \ + -font $number_font \ + ] -column 0 -row 2 -sticky w -padx 2 + grid [label $legend_frame.l10 \ + -text [mc "Operands"] \ + -font $number_font \ + ] -column 1 -row 2 -sticky w + # Length + grid [label $legend_frame.l01 \ + -fg $len_color \ + -bg $len_color \ + -text {X} \ + -font $number_font \ + ] -column 0 -row 3 -sticky w -padx 2 + grid [label $legend_frame.l11 \ + -text [mc "Length"] \ + -font $number_font \ + ] -column 1 -row 3 -sticky w + # Time + grid [label $legend_frame.l02 \ + -fg $time_color \ + -bg $time_color \ + -text {X} \ + -font $number_font \ + ] -column 0 -row 4 -sticky w -padx 2 + grid [label $legend_frame.l12 \ + -text [mc "Time"] \ + -font $number_font \ + ] -column 1 -row 4 -sticky w + + ## Create details frame + # Create labelframe + set details_frame_header_frm [frame $win.details_frame_header_frm] + pack [label $details_frame_header_frm.lbl \ + -text [mc "OP code (hex): "] \ + -font $details_n_font \ + ] -side left + set opcode_ent [ttk::entry $details_frame_header_frm.ent \ + -validatecommand "$this opcode_validator %P" \ + -width 4 \ + -validate key \ + ] + pack $opcode_ent -side left + set title_v_lbl [label $details_frame_header_frm.title_v_lbl \ + -fg $ins_color \ + -font $details_b_font \ + ] + pack $title_v_lbl -side left -padx 15 + set details_frame [ttk::labelframe $middle_frame.details_frame \ + -labelwidget $details_frame_header_frm \ + -padding 5 \ + ] + # Labels: Class & Description + grid [label $details_frame.class_l_lbl \ + -text [mc "Class: "] \ + -font $details_b_font \ + ] -row 0 -column 0 -sticky w + set class_v_lbl [label $details_frame.class_v_lbl -font $details_n_font] + grid $class_v_lbl -row 0 -column 1 -sticky w + grid [label $details_frame.desc_l_lbl \ + -text [mc "Description: "] \ + -font $details_b_font \ + ] -row 1 -column 0 -sticky w + set desc_v_lbl [label $details_frame.desc_v_lbl -font $details_n_font] + grid $desc_v_lbl -row 1 -column 1 -sticky w + # Labels: Length & Time + grid [label $details_frame.length_l_lbl \ + -text [mc "Length: "] \ + -font $details_b_font \ + ] -row 0 -column 2 -sticky w + set length_v_lbl [label $details_frame.length_v_lbl -font $details_n_font] + grid $length_v_lbl -row 0 -column 3 -sticky w + grid [label $details_frame.time_l_lbl \ + -text [mc "Time: "] \ + -font $details_b_font \ + ] -row 1 -column 2 -sticky w + set time_v_lbl [label $details_frame.time_v_lbl -font $details_n_font] + grid $time_v_lbl -row 1 -column 3 -sticky w + # Label: Note & Flags + grid [label $details_frame.note_l_lbl \ + -text [mc "Note: "] \ + -font $details_b_font \ + ] -row 2 -column 0 -sticky w + set note_v_lbl [label $details_frame.note_v_lbl -font $details_n_font] + grid $note_v_lbl -row 2 -column 1 -sticky w + grid [label $details_frame.flags_l_lbl \ + -text [mc "Flags: "] \ + -font $details_b_font \ + ] -row 2 -column 2 -sticky w + set flags_v_lbl [label $details_frame.flags_v_lbl -font $number_font -fg {#DD0000}] + grid $flags_v_lbl -row 2 -column 3 -sticky w + # Configure details frame + grid columnconfigure $details_frame 1 -weight 1 + grid columnconfigure $details_frame 3 -minsize [expr {int(55 * $::font_size_factor)}] + + # Finalize ... + pack $scrollable_frame -side left -fill both -expand 1 + pack $vertical_scrollbar -side right -fill y + pack $main_frame -pady 5 -side top -fill both -expand 1 + pack $details_frame -padx 5 -fill x -side left -expand 1 + pack $legend_frame -padx 5 -side right -anchor nw + pack $middle_frame -fill x + pack $bottom_frame -fill x + } + + ## Validator for entrybox "OP code" + # @parm String string - New entrybox contents + # @return Bool - Always 1 + public method opcode_validator {string} { + if {!$validation_ena} {return 1} + + # Handle an empty string + if {![string length $string]} { + $opcode_ent configure -style TEntry + return 1 + } + + # Check for maximum allowable length + if {[string length $string] > 2} { + return 0 + } + + # Normalize the length + if {[string length $string] == 1} { + set string "0$string" + } + + # Check whether the given value is really a hexadecimal number + if {![string is xdigit -strict $string]} { + $opcode_ent configure -style TblOfIns_RedBg.TEntry + return 1 + } + + # Convert the string to upper case letters and to integer + set string [string toupper $string] + set address [expr "0x$string"] + + # Check for existence of the given OP code + if {[lsearch -ascii -exact ${::CompilerConsts::defined_OPCODE} $string] == -1} { + $opcode_ent configure -style TblOfIns_RedBg.TEntry + tk_messageBox \ + -type ok \ + -icon info \ + -parent $win \ + -title [mc "OP code not defined"] \ + -message [mc "This instruction does not exist on 8051"] + return 1 + } + + # Highlight the cell with the corresponding instruction + $opcode_ent configure -style TblOfIns_GreenBg.TEntry + select_cell $address + if {$selected_cell != -1} { + fill_details $address 1 + } + return 1 + } + + ## Set background color for certain cell in the chart matrix + # @parm Int address - Cell address + # @parm Color color - New background color + # @return void + private method sel_bg_color {address color} { + set frame $cells($address) + foreach wdg [list $frame $frame.f $frame.ins_lbl $frame.oprs_lbl $frame.len_lbl $frame.time_lbl] { + $wdg configure -bg $color + } + + $hh_cells([expr {$address & 0x0F}]) configure -bg $color + $vh_cells([expr {($address & 0xF0) >> 4}]) configure -bg $color + } + + ## Handles event when mouse pointer enters certain cell in the chart + # @parm Int address - Cell address + # @return void + public method cell_enter {address} { + $status_bar_lbl configure -text {} + if {$selected_cell != $address} { + sel_bg_color $address {#DDFFDD} + } + + set def $::CompilerConsts::Opcode([convert_to_opcode $address]) + $status_bar_lbl configure -text "[string toupper [lindex $def 0]] [join [lindex $def 1] {, }]" + } + + ## Handles event when mouse pointer leaves certain cell in the chart + # @parm Int address - Cell address + # @return void + public method cell_leave {address} { + if {$selected_cell == $address} { + return + } + sel_bg_color $address {#FFFFFF} + $status_bar_lbl configure -text {} + + if {$selected_cell != -1} { + $hh_cells([expr {$selected_cell & 0x0F}]) configure -bg {#BBBBFF} + $vh_cells([expr {($selected_cell & 0xF0) >> 4}]) configure -bg {#BBBBFF} + } + } + + ## Handles event when clicks on certain cell in the chart + # @parm Int address - Cell address + # @return void + public method cell_click {address} { + if {$selected_cell == $address} { + unselect_current_cell 1 1 + set selected_cell -1 + return + } + if {![winfo exists $matrix_frame.cell_$address]} { + return + } + + focus $matrix_frame.cell_$address + select_cell $address + if {$selected_cell != -1} { + fill_details $address + } + } + + ## Select specified cell in the chart (mark as selected and adjust details frame) + # @parm Int address - Cell address + # @return void + private method select_cell {address} { + if {$selected_cell != -1} { + unselect_current_cell 0 0 + } + set selected_cell $address + sel_bg_color $address {#BBBBFF} + } + + ## Unselect specified cell in the chart (mark as normal and clear details frame) + # @parm Bool keep_current - Mark cell as a cell under mouse pointer (light green bg. color) + # @parm Bool affect_entryboxes - Clear entryboxes in details frame + # @return void + private method unselect_current_cell {keep_current affect_entryboxes} { + if {$selected_cell == -1} { + return + } + + # Set new background color + if {$keep_current} { + sel_bg_color $selected_cell {#DDFFDD} + } else { + sel_bg_color $selected_cell {#FFFFFF} + } + + # Clear entryboxes in details frame + if {$affect_entryboxes} { + $title_v_lbl configure -text {} + $class_v_lbl configure -text {} + $desc_v_lbl configure -text {} + $length_v_lbl configure -text {} + $time_v_lbl configure -text {} + $flags_v_lbl configure -text {} + $note_v_lbl configure -text {} + + set validation_ena 0 + $opcode_ent delete 0 end + $opcode_ent configure -style TEntry + set validation_ena 1 + } + } + + ## Get instruction OP code in 2-digits uppercase hexadecimal form + # @parm Int int_address - OP code in decimal form + # @return String - 2-digits uppercase hexadecimal number (e.g. ``B9'') + private method convert_to_opcode {int_address} { + set opcode [format %X $int_address] + if {[string length $opcode] == 1} { + set opcode "0$opcode" + } + return $opcode + } + + ## Fill the details about the instruction + # @parm Int address - Integer representation of the instruction OP code + # @parm Bool exclude_opcode - Do not affect the entry box with OP code + # @return void + public method fill_details {address {exclude_opcode 0}} { + $scrollable_frame see $matrix_frame.cell_$address + + ## Obtain detailed informations about the instruction + + set opcode [convert_to_opcode $address] + set def $::CompilerConsts::Opcode($opcode) + + set instruction [lindex $def 0] ;# Instruction name + set operands [lindex $def 1] ;# Oprand types + set length [lindex $def 2] ;# Instruction length + set time [lindex $def 4] ;# Time + + set operands_tmp [list] + foreach operand $operands { + switch -glob -nocase -- $operand { + a - + c - + ab - + @dptr - + @a+dptr - + @a+pc - + dptr { + set operand [string toupper $operand] + } + r? { + set operand {Rn} + } + @r? { + set operand {@Ri} + } + imm8 { + set operand {#data} + } + imm16 { + set operand {#data16} + } + code8 { + set operand {rel} + } + code11 { + set operand {addr11} + } + code16 { + set operand {addr16} + } + bit { + set operand {bit} + } + /bit { + set operand {/bit} + } + data { + set operand {direct} + } + } + lappend operands_tmp $operand + } + + set operands [join $operands_tmp {, }] + set instruction [string toupper $instruction] + set title "$instruction\t$operands" + + set idx [lsearch -ascii -exact ${::InstructionDetails::INSTRUCTION_DESCRIPTION} $title] + if {$idx == -1} { + set ins_class {} + set ins_desc {} + set ins_note {} + set flags {} + } else { + incr idx + set def [lindex ${::InstructionDetails::INSTRUCTION_DESCRIPTION} $idx] + set ins_desc [lindex $def 0] + set ins_class [lindex $def 1] + set ins_note [lindex $def 2] + set flags {} + + foreach i {0 1 2} f {C OV AC} { + if {[string length [lindex $def [list 3 $i]]]} { + lappend flags $f + } + } + } + + if {!$exclude_opcode} { + $opcode_ent delete 0 end + $opcode_ent insert 0 $opcode + } + + $title_v_lbl configure -text $title + $class_v_lbl configure -text [namespace eval ::InstructionDetails "mc {$ins_class}"] + $desc_v_lbl configure -text [namespace eval ::InstructionDetails "mc {$ins_desc}"] + $length_v_lbl configure -text $length + $time_v_lbl configure -text $time + $flags_v_lbl configure -text [join $flags {, }] + $note_v_lbl configure -text [namespace eval ::InstructionDetails "mc {$ins_note}"] + } +} + +# >>> File inclusion guard +} +# <<< File inclusion guard -- cgit v1.2.3