diff options
Diffstat (limited to 'lib/simulator')
23 files changed, 3252 insertions, 1603 deletions
diff --git a/lib/simulator/bitmap.tcl b/lib/simulator/bitmap.tcl index 6ed43e0..c2b4623 100755..100644 --- a/lib/simulator/bitmap.tcl +++ b/lib/simulator/bitmap.tcl @@ -2,7 +2,7 @@ # Part of MCU 8051 IDE ( http://mcu8051ide.sf.net ) ############################################################################ -# Copyright (C) 2007-2008 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 _BITMAP_TCL ] } { +set _BITMAP_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION -# Provides graphical view on bit addressable area in simulated MCU +# Provides graphical view on bit addressable area in simulated MCU. # -------------------------------------------------------------------------- class BitMap { ## COMMON - common count 0 ;# Int: Counter of object instances + common btmap_count 0 ;# Int: Counter of object instances # Last window geometry common win_geometry [lindex $::CONFIG(BITMAP_CONFIG) 0] @@ -52,15 +57,15 @@ class BitMap { common one_a_outline #DDFFDD ;# Color: Bit outline color for log. 1 (Selected bit) # Font: Normal font for canvas widget - common bitmap_n_font [font create \ - -family $::DEFAULT_FIXED_FONT \ - -size -12 \ + common bitmap_n_font [font create \ + -family $::DEFAULT_FIXED_FONT \ + -size [expr {int(-12 * $::font_size_factor)}] \ ] # Font: Bold font for canvas widget - common bitmap_b_font [font create \ - -family $::DEFAULT_FIXED_FONT \ - -size -12 \ - -weight bold \ + common bitmap_b_font [font create \ + -family $::DEFAULT_FIXED_FONT \ + -size [expr {int(-12 * $::font_size_factor)}] \ + -weight bold \ ] @@ -117,8 +122,8 @@ class BitMap { } # Create dialog window - set win [toplevel .bitmap_$count -class {Bitmap} -bg {#EEEEEE}] - incr count + set win [toplevel .bitmap_${btmap_count} -class {Bitmap} -bg ${::COMMON_BG_COLOR}] + incr btmap_count # ---------------------------------------------------------------- # Create main frame and canvas widget @@ -340,7 +345,7 @@ class BitMap { # Set window parameters wm protocol $win WM_DELETE_WINDOW "$this bitmap_close_dialog" wm resizable $win 0 0 - wm title $win [mc "Bit addressable area - %s - %s" [string trim $this {:}] "MCU 8051 IDE"] + wm title $win [mc "Bit addressable area - %s - %s - %s" [$this cget -P_option_mcu_type] [$this cget -projectName] "MCU 8051 IDE"] wm iconphoto $win ::ICONS::16::kcmmemory_BA catch { wm geometry $win $win_geometry @@ -365,14 +370,14 @@ class BitMap { if {$bits_states($addr)} { set outline $one_a_outline set fill $one_a_fill - } { + } else { set outline $zero_a_outline set fill $zero_a_fill } # Set new rectangle colors and changle cursor if {$enabled} { $bitmap_canvas itemconfigure $bits($addr) -outline $outline -fill $fill - $bitmap_canvas configure -cursor hand1 + $bitmap_canvas configure -cursor hand2 } ## Adjust address meters @@ -400,7 +405,7 @@ class BitMap { if {$bits_states($addr)} { set outline $one_outline set fill $one_fill - } { + } else { set outline $zero_outline set fill $zero_fill } @@ -479,7 +484,7 @@ class BitMap { if {$original_val != $bits_states($bit_addr)} { if {$bits_states($bit_addr)} { set fill $one_fill - } { + } else { set fill $zero_fill } @@ -500,7 +505,7 @@ class BitMap { for {set i 0} {$i < 128} {incr i} { if {$bits_states($i)} { set outline $one_outline - } { + } else { set outline $zero_outline } $bitmap_canvas itemconfigure $bits($i) -outline $outline @@ -508,3 +513,7 @@ class BitMap { } } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/engine/engine_auxiliary_alo_functions.tcl b/lib/simulator/engine/engine_auxiliary_alo_functions.tcl index d73b57e..8929268 100755..100644 --- a/lib/simulator/engine/engine_auxiliary_alo_functions.tcl +++ b/lib/simulator/engine/engine_auxiliary_alo_functions.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 _ENGINE_AUXILIARY_ALO_FUNCTIONS_TCL ] } { +set _ENGINE_AUXILIARY_ALO_FUNCTIONS_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Part of simulator engine functionality. @@ -71,7 +76,7 @@ private method alo_add {val} { incr val_h incr result -16 setBit $symbol(AC) 1 - } { + } else { setBit $symbol(AC) 0 } @@ -82,7 +87,7 @@ private method alo_add {val} { if {$result > 255} { incr result -256 setBit $symbol(C) 1 - } { + } else { setBit $symbol(C) 0 } @@ -91,7 +96,7 @@ private method alo_add {val} { setBit $symbol(OV) 1 } elseif {($val > 127) && ($sfr(224) > 127) && ($result < 128)} { setBit $symbol(OV) 1 - } { + } else { setBit $symbol(OV) 0 } @@ -139,7 +144,7 @@ private method alo_subb {val} { incr result_l 16 incr val_h setBit $symbol(AC) 1 - } { + } else { setBit $symbol(AC) 0 } @@ -150,7 +155,7 @@ private method alo_subb {val} { if {$result_h < 0} { incr result_h 16 setBit $symbol(C) 1 - } { + } else { setBit $symbol(C) 0 } @@ -162,10 +167,14 @@ private method alo_subb {val} { setBit $symbol(OV) 1 } elseif {($val < 128) && ($sfr(224) > 127) && ($result < 128)} { setBit $symbol(OV) 1 - } { + } else { setBit $symbol(OV) 0 } # Set Acc set sfr(224) $result } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/engine/engine_backward_stepping.tcl b/lib/simulator/engine/engine_backward_stepping.tcl index f7e1b66..7914c9b 100755..100644 --- a/lib/simulator/engine/engine_backward_stepping.tcl +++ b/lib/simulator/engine/engine_backward_stepping.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 _ENGINE_BACKWARD_STEPPING_TCL ] } { +set _ENGINE_BACKWARD_STEPPING_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Part of simulator engine functionality. @@ -113,7 +118,7 @@ public method stepback_discard_stack {} { public method simulator_get_SBS_len {} { if {${::Simulator::reverse_run_steps}} { return $stepback_length - } { + } else { return 0 } } @@ -124,3 +129,7 @@ public method simulator_get_SBS_len {} { public method simulator_set_SBS_len {value} { set stepback_length $value } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/engine/engine_control.tcl b/lib/simulator/engine/engine_control.tcl index efa00c9..6b76b5a 100755..100644 --- a/lib/simulator/engine/engine_control.tcl +++ b/lib/simulator/engine/engine_control.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 _ENGINE_CONTROL_TCL ] } { +set _ENGINE_CONTROL_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Part of simulator engine functionality. @@ -36,7 +41,7 @@ public method simulator_return_from_SP {intr__sub} { if {$intr__sub} { simulator_cancel_interrupt [lindex $inter_in_p_flags end] - } { + } else { ins_ret $this move_simulator_line $Line($pc) } @@ -88,17 +93,17 @@ public method simulator_resize_code_memory {new_size} { ## Get list of decimal address of implemented SFR # @return List - Implemented special function registers -public method simulator_get_avaliable_sfr {} { - return $avaliable_sfr +public method simulator_get_available_sfr {} { + return $available_sfr } -## Determinate whether the specified SFR is avaliable on the target MCU or not +## Determinate whether the specified SFR is available on the target MCU or not # @parm Int sfr_addr - Address of SFR register - # @return Bool - 1 == Avaliable; 0 == Not avaliable -public method simulator_is_sfr_avaliable {sfr_addr} { - if {[lsearch -ascii -exact $avaliable_sfr $sfr_addr] == -1} { + # @return Bool - 1 == available; 0 == Not available +public method simulator_is_sfr_available {sfr_addr} { + if {[lsearch -ascii -exact $available_sfr $sfr_addr] == -1} { return 0 - } { + } else { return 1 } } @@ -146,8 +151,9 @@ public method master_reset {mode} { set wdt_prescaler_val 0 ;# Int: Value of Watchdog prescaler set watchdog_value 0 ;# Int: Value of watchdog timer set eeprom_WR 0 ;# Bool: Data EEPROM write cycle in progress - - simulator_Sbar {} 0 $this ;# Clear simulator status bar + if {$::GUI_AVAILABLE} { + simulator_Sbar {} 0 $this ;# Clear simulator status bar + } set interrupt_on_next 0 ;# Bool: Engage interrupt routine on the next instruction cycle set interrupts_in_progress {} ;# Priority flags of interrupts which are in progress set inter_in_p_flags {} ;# Interrupt flags of interrupts which are in progress @@ -208,44 +214,44 @@ public method master_reset {mode} { foreach item $reset_reg_values_1 { set reg [lindex $item 0] switch -- $reg { - {T2CON} {if {!$feature_avaliable(t2)} {continue}} - {RCAP2L} {if {!$feature_avaliable(t2)} {continue}} - {RCAP2H} {if {!$feature_avaliable(t2)} {continue}} - {TL2} {if {!$feature_avaliable(t2)} {continue}} - {TH2} {if {!$feature_avaliable(t2)} {continue}} - {T2MOD} {if {!$feature_avaliable(t2mod)} {continue}} - {AUXR} {if {!$feature_avaliable(auxr)} {continue}} - {SCON} {if {!$feature_avaliable(uart)} {continue}} - {P0} {if {!$feature_avaliable(p0)} {continue}} - {P1} {if {!$feature_avaliable(p1)} {continue}} - {P2} {if {!$feature_avaliable(p2)} {continue}} - {P3} {if {!$feature_avaliable(p3)} {continue}} - {P4} {if {!$feature_avaliable(p4)} {continue}} - {ACSR} {if {!$feature_avaliable(acomparator)} {continue}} - {SADEN} {if {!$feature_avaliable(euart)} {continue}} - {SADDR} {if {!$feature_avaliable(euart)} {continue}} - {IPH} {if {!$feature_avaliable(iph)} {continue}} - {WDTCON} {if {!$feature_avaliable(wdtcon)} {continue}} + {T2CON} {if {!$feature_available(t2)} {continue}} + {RCAP2L} {if {!$feature_available(t2)} {continue}} + {RCAP2H} {if {!$feature_available(t2)} {continue}} + {TL2} {if {!$feature_available(t2)} {continue}} + {TH2} {if {!$feature_available(t2)} {continue}} + {T2MOD} {if {!$feature_available(t2mod)} {continue}} + {AUXR} {if {!$feature_available(auxr)} {continue}} + {SCON} {if {!$feature_available(uart)} {continue}} + {P0} {if {!$feature_available(p0)} {continue}} + {P1} {if {!$feature_available(p1)} {continue}} + {P2} {if {!$feature_available(p2)} {continue}} + {P3} {if {!$feature_available(p3)} {continue}} + {P4} {if {!$feature_available(p4)} {continue}} + {ACSR} {if {!$feature_available(acomparator)} {continue}} + {SADEN} {if {!$feature_available(euart)} {continue}} + {SADDR} {if {!$feature_available(euart)} {continue}} + {IPH} {if {!$feature_available(iph)} {continue}} + {WDTCON} {if {!$feature_available(wdtcon)} {continue}} {EECON} {if {!$eeprom_size} {continue}} - {SPCR} {if {!$feature_avaliable(spi)} {continue}} - {SPSR} {if {!$feature_avaliable(spi)} {continue}} + {SPCR} {if {!$feature_available(spi)} {continue}} + {SPSR} {if {!$feature_available(spi)} {continue}} {DP1H} { - if {!$feature_avaliable(ddp) || $feature_avaliable(hddptr)} { + if {!$feature_available(ddp) || $feature_available(hddptr)} { continue } } {DP1L} { - if {!$feature_avaliable(ddp) || $feature_avaliable(hddptr)} { + if {!$feature_available(ddp) || $feature_available(hddptr)} { continue } } {CLKREG} { - if {!$feature_avaliable(clkreg) && !$feature_avaliable(ckcon)} { + if {!$feature_available(clkreg) && !$feature_available(ckcon)} { continue } } {AUXR1} { - if {!$feature_avaliable(ddp) || $feature_avaliable(wdtcon)} { + if {!$feature_available(ddp) || $feature_available(wdtcon)} { continue } } @@ -256,10 +262,10 @@ public method master_reset {mode} { } # Restore bits which are not affected by reset - if {$feature_avaliable(pof) && $controllers_conf(POF)} { + if {$feature_available(pof) && $controllers_conf(POF)} { set sfr($symbol(PCON)) [expr {$sfr($symbol(PCON)) | 16}] } - if {$feature_avaliable(x2reset) && $controllers_conf(X2)} { + if {$feature_available(x2reset) && $controllers_conf(X2)} { set sfr($symbol(CLKREG)) [expr {$sfr($symbol(CLKREG)) | 1}] } @@ -275,17 +281,19 @@ public method master_reset {mode} { } # Synchronize with special GUI controls - $this simulator_GUI_cancel_write_to_eeprom ;# Abort data EEPROM write cycle - $this interrupt_monitor_reset ;# Reset interrupt monitor - $this subprograms_clear ;# Clear list subprograms - $this stopwatch_refresh ;# Stopwatch - $this stack_monitor_reset ;# clear stack monitor + if {$::GUI_AVAILABLE} { + $this simulator_GUI_cancel_write_to_eeprom ;# Abort data EEPROM write cycle + $this interrupt_monitor_reset ;# Reset interrupt monitor + $this subprograms_clear ;# Clear list subprograms + $this stopwatch_refresh ;# Stopwatch + $this stack_monitor_reset ;# clear stack monitor + } # Reset PALE (Peripheral Astraction Layer Engine) $this pale_reset for {set i 0} {$i < 5} {incr i} { set j 0 - foreach bit [split $feature_avaliable(port$i) {}] { + foreach bit [split $feature_available(port$i) {}] { if {$bit == 0} { $this pale_SLSF [list $i $j] 6 } @@ -344,10 +352,10 @@ public method stepback {} { simulator_set_special [lindex $stepback_spec $stepback_length] set opcode [getCode $pc] - if {[lsearch ${CompilerConsts::defined_OPCODE} $opcode] == -1} { + if {[lsearch ${::CompilerConsts::defined_OPCODE} $opcode] == -1} { incr run_statistics(4) -1 - } { - incr run_statistics(4) -[lindex $CompilerConsts::Opcode($opcode) 2] + } else { + incr run_statistics(4) -[lindex $::CompilerConsts::Opcode($opcode) 2] } incr run_statistics(0) [expr {int(($overall_time - $overall_time_org) * (12000000.0 / $clock_kHz))}] @@ -394,14 +402,17 @@ public method stepback {} { $this stack_monitor_pop } } - if {[llength $interrupts_in_progress]} { - simulator_Sbar [mc "Interrupt at vector 0x%s " [format %X [intr2vector [lindex $interrupts_in_progress end]]]] 1 $this - } { - simulator_Sbar {} 0 $this + if {$::GUI_AVAILABLE} { + if {[llength $interrupts_in_progress]} { + simulator_Sbar [mc "Interrupt at vector 0x%s " [format %X [intr2vector [lindex $interrupts_in_progress end]]]] 1 $this + } else { + simulator_Sbar {} 0 $this + } + + $this graph_stepback [expr {int(($overall_time_org - $overall_time) * 2)}] + $this interrupt_monitor_reevaluate + $this stopwatch_refresh } - $this graph_stepback [expr {int(($overall_time_org - $overall_time) * 2)}] - $this interrupt_monitor_reevaluate - $this stopwatch_refresh if {$eeprom_size} { for {set i 0} {$i < 32} {incr i} { ::X::sync_eeprom_write_buffer $i $this @@ -411,11 +422,13 @@ public method stepback {} { if {$eeprom_WR} { eeprom_controller [expr {int(($overall_time_org - $overall_time) * (-2))}] - } { - foreach reg $eeprom_prev { - ::X::sync_eeprom_clear_bg_hg [lindex $reg 0] $this + } else { + if {$::GUI_AVAILABLE} { + foreach reg $eeprom_prev { + ::X::sync_eeprom_clear_bg_hg [lindex $reg 0] $this + } + $this simulator_GUI_cancel_write_to_eeprom } - $this simulator_GUI_cancel_write_to_eeprom } $this Simulator_sync_PC_etc @@ -426,7 +439,7 @@ public method stepback {} { $this Simulator_GUI_sync S 224 if {!$stepback_length} { return 0 - } { + } else { return 1 } } @@ -449,7 +462,7 @@ public method step {} { return $Line($pc) # Invalid OP code - } { + } else { bell $this sim_txt_output [mc "No instruction found at 0x%s" [NumSystem::dec2hex $pc]] incr_pc 1 @@ -469,7 +482,7 @@ public method sim_stepover {} { set stepover_in_progress 0 # Engage - } { + } else { # Local variables set current_line 0 ;# Current line in source code set stepover_in_progress 1 ;# Bool: "Step over" mode flag @@ -486,7 +499,7 @@ public method sim_stepover {} { if {$code($pc) != {}} { set sync_ena 1 ;# Enable synchronization - while 1 { + while {1} { # Conditionaly abort simulation if {$break} { set break 0 @@ -536,7 +549,7 @@ public method sim_stepover {} { return $Line($pc) # No OP code - } { + } else { incr_pc 1 bell $this sim_txt_output [mc "No instruction found at 0x%s" [NumSystem::dec2hex $pc]] @@ -562,7 +575,7 @@ public method sim_run {} { set run_in_progress 0 ;# Bool: "Run" mode flag # Engage - } { + } else { set sync_ena 0 ;# Disabled synchronizations # Local variables @@ -570,9 +583,10 @@ public method sim_run {} { set simulation_in_progress 1 ;# Bool: Simulator engaged set idx 0 ;# Instruction index (GUI is updated after each 1000) set ::X::critical_procedure_in_progress 0 + set time_ms [clock milliseconds] ;# Int: High res. system timer, used here for regular GUI updates # Infinitely execute program instructions until break - while 1 { + while {1} { incr idx # Conditionaly abort simulation if {$break} { @@ -600,15 +614,19 @@ public method sim_run {} { # Execute instruction instruction_cycle - # Run update command after each 25 instructions - if {!($idx % 25)} { - update - } - # Update GUI after each 100 instructions - if {$idx >= 100} { - set idx 0 - $this Simulator_sync_PC_etc - update + if {$::GUI_AVAILABLE} { + if {([clock milliseconds] - $time_ms) > $GUI_UPDATE_INT} { + set idx 0 + $this Simulator_sync_PC_etc + update + set time_ms [clock milliseconds] + } + } else { + # Stop after 1000 instructions + if {$idx >= 1000} { + set idx 0 + set break 1 + } } # Handle breakpoints @@ -648,13 +666,13 @@ public method sim_animate {} { set animation_in_progress 0 ;# Bool: "Animation" mode flag # Engage - } { + } else { set animation_in_progress 1 ;# Bool: "Animation" mode flag set simulation_in_progress 1 ;# Bool: Simulator engaged set ::X::critical_procedure_in_progress 0 # Infinitely execute program instructions until break - while 1 { + while {1} { # Conditionaly abort simulation if {$break} { set simulation_in_progress 0 @@ -748,8 +766,8 @@ public method Simulator_shutdown {} { # @return void public method Simulator_initiate {} { set sync_ena 1 - simulator_system_power_on master_reset - + simulator_system_power_on # Reset watchdog set watchdog_value 0 @@ -757,3 +775,7 @@ public method Simulator_initiate {} { set break 0 } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/engine/engine_core.tcl b/lib/simulator/engine/engine_core.tcl index e974656..0c78129 100755..100644 --- a/lib/simulator/engine/engine_core.tcl +++ b/lib/simulator/engine/engine_core.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 _ENGINE_CORE_TCL ] } { +set _ENGINE_CORE_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Implements virtual 8051 processor. This class is a part 8051 simulator. @@ -54,9 +59,9 @@ class Simulator_ENGINE { ## COMMON common symbol ;# Array of SFR symbolic names (eg. $symbol(P0) == "80") - common DEBUG 1 ;# Turn on debugging common PIN ;# Array describing pins with some special function common PORT_LATCHES ;# List: Port latch registers + common GUI_UPDATE_INT 66;# Int: Time interval [ms] in which the GUI is regulary updated in the run mode # Default values for SFR (values to set after reset) common reset_reg_values { @@ -77,10 +82,10 @@ class Simulator_ENGINE { } ## PUBLIC - public variable programming_language 0 ;# Int: ID of used programing language (0 == Assembler; 1 == C language) + public variable programming_language 0 ;# Int: ID of used programming language (0 == Assembler; 1 == C language) ## PRIVATE - private variable breakpoints ;# Array of Lists of breakpoints (by line numbers) -- (eg '{1 45 399}') + private variable breakpoints ;# Array of Lists of breakpoints -- (eg '$breakpoints($file_number) == {1 45 399}') private variable ram ;# Array of internal RAM; addr: 0..255; val: 0..255 private variable eram ;# Array of expanded RAM; addr: 0..4096; val: 0..255 @@ -102,13 +107,13 @@ class Simulator_ENGINE { private variable Line ;# $Line($PC) == {line in source code} {filenumber} {level} {block} private variable list_of_filenames ;# List of filenames for [lindex $Line($pc) 1] - private variable line2PC ;# $line2PC($line) == PC + private variable line2PC ;# $line2PC($line_number,$file_number) == PC private variable bank 0 ;# Current register bank (0..3) private variable pc 0 ;# Program counter private variable clock_kHz 0 ;# MCU clock in kHz private variable time 0 ;# Number of instruction cycles consumed by current instruction private variable sync_ena 0 ;# Bool: Enabled synchronization with an external interface - private variable address_error 0 ;# Bool: Addressing error occured + private variable address_error 0 ;# Bool: Addressing error occurred private variable break 0 ;# Bool: Immediately terminate the loaded program private variable simulation_in_progress 0 ;# Bool: Engine is running @@ -118,19 +123,19 @@ class Simulator_ENGINE { private variable ports_previous_state {} ;# List: {P0_hex P1_hex P2_hex P3_hex P4_hex} private variable rmw_instruction 0 ;# Bool: This instruction is one of READ-MODIFY-WRITE ones - private variable avaliable_sfr {} ;# List: Addresses of implemented SFR - private variable feature_avaliable ;# Array: Avaliable features + private variable available_sfr {} ;# List: Addresses of implemented SFR + private variable feature_available ;# Array: available features private variable restricted_bits {} ;# List: Decimal addresses of unimplemented bits private variable write_only_regs {} ;# List: Decimal addresses of write only registers - private variable incomplite_regs {} ;# List: Decimal addresses of not fully implemented registers - private variable incomplite_regs_mask ;# Array: key == dec. addr.; val == mask of implemented bits + private variable incomplete_regs {} ;# List: Decimal addresses of not fully implemented registers + private variable incomplete_regs_mask ;# Array: key == dec. addr.; val == mask of implemented bits private variable DPL {DP0L} ;# Address of current DPL register (DTPR) private variable DPH {DP0H} ;# Address of current DPH register (DTPR) private variable hidden_DPTR0 {0 0} ;# Value of DPTR0 (if dual DPTR is hidden) private variable hidden_DPTR1 {0 0} ;# Value of DPTR1 (if dual DPTR is hidden) - private variable watchdog_value 0 ;# Int: Current value of watchdog timer (if avaliable) + private variable watchdog_value 0 ;# Int: Current value of watchdog timer (if available) private variable wdtrst_prev_val 0 ;# Int: Previous value of register WDTRST private variable wdt_prescaler_val 0 ;# Int: Watchdog prescaler value (content) @@ -272,3 +277,7 @@ class Simulator_ENGINE { # Initialize NS variables Simulator_ENGINE::InitializeNS + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/engine/engine_external_interface_management.tcl b/lib/simulator/engine/engine_external_interface_management.tcl index 30a5aed..5a1f220 100755..100644 --- a/lib/simulator/engine/engine_external_interface_management.tcl +++ b/lib/simulator/engine/engine_external_interface_management.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 _ENGINE_EXTERNAL_INTERFACE_MANAGEMENT_TCL ] } { +set _ENGINE_EXTERNAL_INTERFACE_MANAGEMENT_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Part of simulator engine functionality. @@ -29,20 +34,25 @@ # EXTERNAL INTERFACE MANAGEMENT PROCEDURES # -------------------------------------------------------------------------- +## Get value of bit X2 in CLKREG/CKCON if available + # @return Bool - X2 value (if unavailable then 0) +public method get_X2 {} { + return $controllers_conf(X2) +} -## Get value of bit SMOD0 in PCON if avaliable - # @return Bool - SMOD0 value (if unavaliable then 0) +## Get value of bit SMOD0 in PCON if available + # @return Bool - SMOD0 value (if unavailable then 0) public method get_SMOD0 {} { return $controllers_conf(SMOD0) } -## Set value of bit FE in SCON if avaliable - # @param Bool value - New value for SCON.FE (or SCON.SM0 if FE is not avaliable) +## Set value of bit FE in SCON if available + # @param Bool value - New value for SCON.FE (or SCON.SM0 if FE is not available) # @return void public method sim_engine_set_FE {value} { - if {$feature_avaliable(smod0)} { + if {$feature_available(smod0)} { set controllers_conf(FE) $value - } { + } else { sim_engine_set_SM0 $value } } @@ -54,12 +64,12 @@ public method sim_engine_set_SM0 {value} { set controllers_conf(SM0) $value } -## Get value of bit FE in SCON if avaliable - # @return Bool - FE value (if unavaliable then {}) +## Get value of bit FE in SCON if available + # @return Bool - FE value (if unavailable then {}) public method sim_engine_get_FE {} { - if {!$feature_avaliable(smod0)} { + if {!$feature_available(smod0)} { return {} - } { + } else { return $controllers_conf(FE) } } @@ -71,9 +81,14 @@ public method sim_engine_get_SM0 {} { } ## Get program run statistics - # @return List - Array run_statistics converted to list -public method get_run_statistics {} { - return [array get run_statistics] + # @parm Int idx = {} - Index to the array ``run_statistics'', empty string means entire array + # @return List/Int - Array run_statistics converted to list or Int +public method get_run_statistics {{idx {}}} { + if {$idx == {}} { + return [array get run_statistics] + } else { + return $run_statistics($idx) + } } ## Retrieve filename from list of files from which this program has been compiled @@ -97,9 +112,9 @@ public method simulator_get_filenumber {filename} { ## Get maximum valid interrupt priority level # @return Int - 0..3 public method simulator_get_max_intr_priority {} { - if {$feature_avaliable(iph)} { + if {$feature_available(iph)} { return 3 - } { + } else { return 1 } } @@ -185,7 +200,7 @@ private method set_interrupt_priority_flag {flag level} { } # Adjust register IPH - if {$feature_avaliable(iph)} { + if {$feature_available(iph)} { if {${::Simulator::reverse_run_steps}} { stepback_reg_change S $symbol(IPH) } @@ -194,7 +209,7 @@ private method set_interrupt_priority_flag {flag level} { if {$level / 2} { set sfr($symbol(IPH)) [expr $sfr($symbol(IPH)) | $bit_mask] # Clear priority bit - } { + } else { set sfr($symbol(IPH)) [expr $sfr($symbol(IPH)) & ($bit_mask ^ 255)] } @@ -210,7 +225,7 @@ private method set_interrupt_priority_flag {flag level} { if {$level % 2} { set sfr($symbol(IP)) [expr $sfr($symbol(IP)) | $bit_mask] # Clear priority bit - } { + } else { set sfr($symbol(IP)) [expr $sfr($symbol(IP)) & ($bit_mask ^ 255)] } # Adjust internal engine configuration @@ -277,7 +292,10 @@ public method simulator_clear_intr_flag {flag} { # Adjust internal engine configuration evaluate_sfr $addr - $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + + if {$::GUI_AVAILABLE} { + $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + } } ## Force return from certain interrupt @@ -299,11 +317,13 @@ public method simulator_cancel_interrupt {flag} { incr run_statistics(8) $this subprograms_return 1 - if {[llength $interrupts_in_progress]} { - set vector [format %X [intr2vector [lindex $interrupts_in_progress end]]] - simulator_Sbar [mc "Interrupt at vector 0x%s " $vector] 1 $this - } { - simulator_Sbar {} 0 $this + if {$::GUI_AVAILABLE} { + if {[llength $interrupts_in_progress]} { + set vector [format %X [intr2vector [lindex $interrupts_in_progress end]]] + simulator_Sbar [mc "Interrupt at vector 0x%s " $vector] 1 $this + } else { + simulator_Sbar {} 0 $this + } } set pch [stack_pop] @@ -348,10 +368,10 @@ public method simulator_get_interrupts_in_progress_pb {} { # @return List - Something like {IE0 TF0 IE1 TF1 RI TI CF} public method simulator_get_intr_flags {} { set result {IE0 TF0 IE1 TF1} - if {$feature_avaliable(uart)} {lappend result RI TI} - if {$feature_avaliable(spi)} {lappend result SPIF} - if {$feature_avaliable(t2)} {lappend result TF2 EXF2} - if {$feature_avaliable(acomparator)} {lappend result CF} + if {$feature_available(uart)} {lappend result RI TI} + if {$feature_available(spi)} {lappend result SPIF} + if {$feature_available(t2)} {lappend result TF2 EXF2} + if {$feature_available(acomparator)} {lappend result CF} return $result } @@ -384,13 +404,15 @@ public method simulator_cancel_write_to_eeprom {} { public method simulator_finalize_write_to_eeprom {} { if {!$eeprom_size || !$eeprom_WR} {return} - # Clear background highlight in EEPROM hexeditor + # Clear background highlight in EEPROM hex editor foreach reg $eeprom_prev { ::X::sync_eeprom_clear_bg_hg [lindex $reg 0] $this } # Adjust engine configuration - $this simulator_GUI_cancel_write_to_eeprom + if {$::GUI_AVAILABLE} { + $this simulator_GUI_cancel_write_to_eeprom + } set eeprom_WR 0 set eeprom_WR_time 0 set eeprom_WR_ofs {} @@ -419,17 +441,47 @@ public method simulator_line2address {line file} { set line [expr $line] if {[llength [array names line2PC -exact "$line,$file"]]} { return $line2PC($line,$file) - } { + } else { return {} } } +## Determinate list of all unreachable breakpoints in the code + # @return List - { { file_number line_number } ... } +public method simulator_getInvalidBreakpoints {} { + # Local variables + set ln 0 ;# Int: Line number + set fn 0 ;# Int: File number + set idx 0 ;# Index in list of breakpoints + + set list_of_breakpoints [list] + foreach {f b} [array get breakpoints] { + foreach l $b { + lappend list_of_breakpoints [list $f $l] + } + } + + foreach ln_fn [array names line2PC] { + scan $ln_fn {%d,%d} ln fn + + set idx [lsearch -ascii -exact $list_of_breakpoints [list $fn $ln]] + + if {$idx != -1} { + set list_of_breakpoints [lreplace $list_of_breakpoints $idx $idx] + } + } + + set list_of_breakpoints [lsort -integer -index 0 $list_of_breakpoints] + set list_of_breakpoints [lsort -integer -index 1 $list_of_breakpoints] + return $list_of_breakpoints +} + ## Set watchdog timer value # This procedure does nothing on MCUs without watchdog timer # @parm Int value - new value (0..8192) # @return void public method simulator_setWatchDogTimer {value} { - if {!$feature_avaliable(wtd)} {return} + if {!$feature_available(wtd)} {return} set watchdog_value $value } @@ -463,7 +515,7 @@ public method simulator_setWatchDogPrescalerValue {value} { # @parm Bool bool - 0 == STOP; 1 == START # @return void public method simulator_startStopWatchDogTimer {bool} { - if {!$feature_avaliable(wtd)} {return} + if {!$feature_available(wtd)} {return} set controllers_conf(WatchDogTimer) $bool } @@ -481,8 +533,10 @@ public method simulator_subprog_call {value} { stack_push [expr {($value & 0xFF00) >> 8}] incr run_statistics(6) $this subprograms_call 3 $pc $value - $this stack_monitor_set_last_values_as 1 2 - $this stopwatch_refresh + if {$::GUI_AVAILABLE} { + $this stack_monitor_set_last_values_as 1 2 + $this stopwatch_refresh + } set pc $value } @@ -511,7 +565,7 @@ public method simulator_get_line_number {} { return [lindex $Line($pc) 0] } -## Translate adress in program memory to line info +## Translate address in program memory to line info # @parm Int addr - Address to translate # @return List - Line information list public method simulator_address2line {addr} { @@ -567,7 +621,7 @@ public method setSfr {addr val} { {150} { ;# EECON if {$sfr(150) & 1} { set controllers_conf(WRTINH) 1 - } { + } else { set controllers_conf(WRTINH) 0 } } @@ -577,7 +631,7 @@ public method setSfr {addr val} { evaluate_sfr $addr 0 set stepback_ena $foo - # If adress points to Primary Accumulator (Acc) -> reevaluate PSW + # If address points to Primary Accumulator (Acc) -> reevaluate PSW if {$addr == 224} { $this Simulator_GUI_sync S 208 } @@ -690,8 +744,10 @@ public method getData {addr} { # @parm Int addr - register address # @return String - register value (2 hexadecimal digits) public method getSfr {addr} { + # Get hexadecimal value set result [format "%X" $sfr($addr)] + # Adjust the value if {[string length $result] == 1} { set result "0$result" @@ -861,7 +917,7 @@ public method load_program_from_adf {adf_file} { -icon warning \ -type ok \ -title [mc "Out of memory"] \ - -message [mc "%s has not enought program memory to load this program. Simulator will work but the loaded code is incomplite" [$this cget -P_option_mcu_type]] + -message [mc "%s has not enough program memory to load this program. Simulator will work but the loaded code is incomplete" [$this cget -P_option_mcu_type]] return 0 } set Line($addr) [list $lineNum $fileNum 0 0] ;# Set line number @@ -875,7 +931,7 @@ public method load_program_from_adf {adf_file} { # @parm File filename - Full name of source file from which SIM file was generaded # @parm File cdb_file - CDB file ID (content of *.cdb file) # @parm File ihx_file - HEX file ID (content of *.ihx or *.hex file) - # @return void + # @return Bool - 1 == Success; 0 == Failure public method load_program_from_cdb {filename cdb_file ihx_file} { unload_program ;# Clear current content of the program memory @@ -1023,6 +1079,12 @@ public method setEngineClock {clockkHz} { set clock_kHz $clockkHz } +## Get MCU clock frequency + # @return - clock frequency in kHz +public method getEngineClock {} { + return $clock_kHz +} + ## Get program uptime as human readable string # @return String - the time (eg. '2 s 42 ms 987 us') public method getTime {} { @@ -1031,7 +1093,7 @@ public method getTime {} { set s 0 set ms 0 set ns 0 - } { + } else { set s [expr {int($overall_time * (0.012 / $clock_kHz))}] set ms [expr {int($overall_time * (12000.0 / $clock_kHz)) % 1000000}] set ns [expr {int($overall_time * (12000000.0 / $clock_kHz)) % 1000}] @@ -1050,7 +1112,7 @@ public method getTime {} { set len [string length $ns] if {$len < 3} { set ns_s "[string repeat { } [expr {3 - $len}]]$ns" - } { + } else { set ns_s $ns } @@ -1058,7 +1120,7 @@ public method getTime {} { set len [string length $us] if {$len < 3} { set us_s "[string repeat { } [expr {3 - $len}]]$us" - } { + } else { set us_s $us } @@ -1066,19 +1128,19 @@ public method getTime {} { set len [string length $ms] if {$len < 3} { set ms_s "[string repeat { } [expr {3 - $len}]]$ms" - } { + } else { set ms_s $ms } # Adjust seconds and minutes strings if {[string length $s] == 1} { set s_s " $s" - } { + } else { set s_s $s } if {[string length $m] == 1} { set m_s " $m" - } { + } else { set m_s $m } @@ -1103,7 +1165,7 @@ public method getTime {} { } # Append micro-seconds if {$us > 0 || $result != {}} { - append result " ${us_s}us" + append result " ${us_s}µs" } # Append nano-seconds if {$ns > 0 || $result != {}} { @@ -1113,3 +1175,7 @@ public method getTime {} { # Done ... return [string trim $result] } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/engine/engine_hibernation.tcl b/lib/simulator/engine/engine_hibernation.tcl index 24d3adf..d5a5faa 100755..100644 --- a/lib/simulator/engine/engine_hibernation.tcl +++ b/lib/simulator/engine/engine_hibernation.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 _ENGINE_HIBERNATION_TCL ] } { +set _ENGINE_HIBERNATION_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Part of simulator engine functionality. @@ -39,16 +44,16 @@ public method simulator_get_special {} { $timer_0_running $timer_1_running $overall_time \ $overall_instructions $inter_in_p_flags $timer1_overflow - if {$feature_avaliable(t2)} { + if {$feature_available(t2)} { lappend result $timer_2_running $timer2_overflow } - if {$feature_avaliable(wtd)} { + if {$feature_available(wtd)} { lappend result $watchdog_value $wdtrst_prev_val } - if {$feature_avaliable(wdtcon)} { + if {$feature_available(wdtcon)} { lappend result $wdt_prescaler_val $controllers_conf(WatchDogPrescaler) } - if {$feature_avaliable(pwm)} { + if {$feature_available(pwm)} { lappend result $pwm_running $pwm_OCR } if {$eeprom_size} { @@ -64,13 +69,13 @@ public method simulator_get_special {} { lappend result $eeprom_WR_buff($i) } } - if {$feature_avaliable(hddptr)} { + if {$feature_available(hddptr)} { lappend result $hidden_DPTR0 $hidden_DPTR1 } - if {$feature_avaliable(acomparator)} { + if {$feature_available(acomparator)} { lappend result $anlcmp_running $anlcmp_output $anlcpm_db_timer } - if {$feature_avaliable(uart)} { + if {$feature_available(uart)} { lappend result \ $uart_clock_prescaler \ $uart_RX_clock \ @@ -100,25 +105,25 @@ public method simulator_set_special {list} { incr i } - if {$feature_avaliable(t2)} { + if {$feature_available(t2)} { set timer_2_running [lindex $list $i] incr i set timer2_overflow [lindex $list $i] incr i } - if {$feature_avaliable(wtd)} { + if {$feature_available(wtd)} { set watchdog_value [lindex $list $i] incr i set wdtrst_prev_val [lindex $list $i] incr i } - if {$feature_avaliable(wdtcon)} { + if {$feature_available(wdtcon)} { set wdt_prescaler_val [lindex $list $i] incr i set controllers_conf(WatchDogPrescaler) [lindex $list $i] incr i } - if {$feature_avaliable(pwm)} { + if {$feature_available(pwm)} { set pwm_running [lindex $list $i] incr i set pwm_OCR [lindex $list $i] @@ -142,13 +147,13 @@ public method simulator_set_special {list} { set eeprom_WR_buff($j) [lindex $list $i] } } - if {$feature_avaliable(hddptr)} { + if {$feature_available(hddptr)} { set hidden_DPTR0 [lindex $list $i] incr i set hidden_DPTR1 [lindex $list $i] incr i } - if {$feature_avaliable(acomparator)} { + if {$feature_available(acomparator)} { set anlcmp_running [lindex $list $i] incr i set anlcmp_output [lindex $list $i] @@ -156,7 +161,7 @@ public method simulator_set_special {list} { set anlcpm_db_timer [lindex $list $i] incr i } - if {$feature_avaliable(uart)} { + if {$feature_available(uart)} { set uart_clock_prescaler [lindex $list $i] incr i set uart_RX_clock [lindex $list $i] @@ -203,3 +208,7 @@ public method simulator_hib_append_SB_spec {list} { public method simulator_hib_append_SB_norm {list} { lappend stepback_normal $list } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/engine/engine_initialization_cleanup.tcl b/lib/simulator/engine/engine_initialization_cleanup.tcl index e8a1ffa..8865dd2 100755..100644 --- a/lib/simulator/engine/engine_initialization_cleanup.tcl +++ b/lib/simulator/engine/engine_initialization_cleanup.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 _ENGINE_INITIALIZATION_CLEANUP_TCL ] } { +set _ENGINE_INITIALIZATION_CLEANUP_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Part of simulator engine functionality. @@ -52,7 +57,7 @@ destructor { # This function is called after each simulator start # @return void private method simulator_system_power_on {} { - if {$feature_avaliable(wtd)} { + if {$feature_available(wtd)} { set sfr($symbol(WDTRST)) [undefined_octet] set wdtrst_prev_val $sfr($symbol(WDTRST)) if {$sync_ena} { @@ -60,7 +65,7 @@ private method simulator_system_power_on {} { } } - if {$feature_avaliable(uart)} { + if {$feature_available(uart)} { set sfr($symbol(SBUFR)) [undefined_octet] set sfr($symbol(SBUFT)) [undefined_octet] set controllers_conf(UART_M) 0 @@ -70,7 +75,7 @@ private method simulator_system_power_on {} { } } - if {$feature_avaliable(pof)} { + if {$feature_available(pof)} { set controllers_conf(POF) 1 set sfr($symbol(PCON)) 16 if {$sync_ena} { @@ -78,7 +83,7 @@ private method simulator_system_power_on {} { } } - if {$feature_avaliable(spi)} { + if {$feature_available(spi)} { set sfr($symbol(SPDR)) 0 if {$sync_ena} { catch {$this Simulator_GUI_sync S $symbol(SPDR)} @@ -103,7 +108,7 @@ public method simulator_initialize_mcu {} { + [$this cget -P_option_mcu_xcode])}] - # Parse processor definition and set array feature_avaliable + # Parse processor definition and set array feature_available foreach index { 5 6 7 9 10 11 17 20 21 22 23 24 25 26 @@ -118,24 +123,24 @@ public method simulator_initialize_mcu {} { auxrwdidle auxrdisrto xram xcode } { if {[lindex $proc_data $index] == {yes}} { - set feature_avaliable($name) 1 - } { - set feature_avaliable($name) 0 + set feature_available($name) 1 + } else { + set feature_available($name) 0 } } for {set i 12; set j 0} {$i < 17} {incr i; incr j} { set port_mask [lindex $proc_data $i] if {$port_mask != {} && $port_mask != {00000000}} { - set feature_avaliable(p$j) 1 - set feature_avaliable(port$j) $port_mask - } { - set feature_avaliable(p$j) 0 - set feature_avaliable(port$j) {00000000} + set feature_available(p$j) 1 + set feature_available(port$j) $port_mask + } else { + set feature_available(p$j) 0 + set feature_available(port$j) {00000000} } } - # Set incomplite_regs_mask, restricted_bits and incomplite_regs - array unset incomplite_regs_mask + # Set incomplete_regs_mask, restricted_bits and incomplete_regs + array unset incomplete_regs_mask set restricted_bits {} foreach reg_mask [lindex $proc_data 18] { set addr [string range $reg_mask 0 1] @@ -143,7 +148,7 @@ public method simulator_initialize_mcu {} { set addr [expr "0x$addr"] set mask [expr "0x$mask"] - set incomplite_regs_mask($addr) $mask + set incomplete_regs_mask($addr) $mask if {$addr > 127 && !($addr % 8)} { for {set i 1} {$i <= 128} {set i [expr {$i * 2}]; incr addr} { @@ -153,7 +158,7 @@ public method simulator_initialize_mcu {} { } } } - set incomplite_regs [array names incomplite_regs_mask] + set incomplete_regs [array names incomplete_regs_mask] # Determiate list of write-only registers set write_only_regs {} @@ -186,7 +191,7 @@ public method simulator_initialize_mcu {} { # Power on virtual uC and derminate list of implemented SFR simulator_system_power_on master_reset 0 - set avaliable_sfr [array names sfr] + set available_sfr [array names sfr] # Initialize/Clear code memory and data EEPROM simulator_clear_memory code @@ -312,18 +317,18 @@ proc InitializeNS {} { set PORT_LATCHES [list $symbol(P0) $symbol(P1) $symbol(P2) $symbol(P3) $symbol(P4)] } -## Shutdown simulator engine +## Stop simulator engine # @return void private method internal_shutdown {} { set break 1 $this Simulator_sync_clock } -## Determinate if the specified feature is avaliable on this MCU +## Determinate if the specified feature is available on this MCU # @parm String key - feature name (e.g. 'p0') # @return Bool - result (1 == yes; 0 == no) -public method get_feature_avaliable {key} { - return $feature_avaliable($key) +public method get_feature_available {key} { + return $feature_available($key) } ## Get number of implemented ports and list of port indexes @@ -331,10 +336,14 @@ public method get_feature_avaliable {key} { public method get_ports_info {} { set sum 0 for {set i 0} {$i < 5} {incr i} { - if {$feature_avaliable(p$i)} { + if {$feature_available(p$i)} { incr sum lappend lst $i } } return [list $sum $lst] } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/engine/engine_instructions.tcl b/lib/simulator/engine/engine_instructions.tcl index d732414..19c45af 100755..100644 --- a/lib/simulator/engine/engine_instructions.tcl +++ b/lib/simulator/engine/engine_instructions.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 _ENGINE_INSTRUCTIONS_TCL ] } { +set _ENGINE_INSTRUCTIONS_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Part of simulator engine functionality. @@ -41,7 +46,7 @@ private method ins_acall {haddr laddr} { stack_push [expr {($pc & 255)}] stack_push [expr {($pc & 0xFF00) >> 8}] - incr laddr [expr {$haddr << 8}] + incr laddr [expr {($haddr << 8) | $pc & 0x0f800}] incr run_statistics(6) $this subprograms_call 1 $pc $laddr $this stack_monitor_set_last_values_as 1 2 @@ -70,7 +75,7 @@ private method ins_add_D {addr} { } if {$addr < 128} { ins_add $ram($addr) - } { + } else { ins_add [read_sfr $addr] } } @@ -83,7 +88,7 @@ private method ins_add_ID {addr} { incr_pc 1 if {[check_address_validity I $addr]} { alo_add [undefined_octet] - } { + } else { alo_add $ram($addr) } evaluate_sfr 224 @@ -111,7 +116,7 @@ private method ins_addc_D {addr} { } if {$addr < 128} { ins_addc $ram($addr) - } { + } else { ins_addc [read_sfr $addr] } } @@ -125,7 +130,7 @@ private method ins_addc_ID {addr} { if {[check_address_validity I $addr]} { alo_addc [undefined_octet] return - } { + } else { alo_addc $ram($addr) } } @@ -136,7 +141,7 @@ private method ins_addc_ID {addr} { # @return void private method ins_ajmp {haddr laddr} { set time 2 - incr laddr [expr {$haddr << 8}] + incr laddr [expr {($haddr << 8) | $pc & 0x0f800}] set pc $laddr } @@ -155,7 +160,7 @@ private method ins_anl {addr val} { if {$sync_ena} { $this Simulator_sync_reg $addr } - } { + } else { set rmw_instruction 1 write_sfr $addr [expr {[read_sfr $addr] & $val}] evaluate_sfr $addr @@ -185,7 +190,7 @@ private method ins_anl_A_D {addr} { if {$sync_ena} { $this Simulator_sync_reg $addr } - } { + } else { ins_anl_A [read_sfr $addr] evaluate_sfr $addr } @@ -222,7 +227,7 @@ private method ins_anl_C_N {addr} { set time 2 if {[check_address_validity B $addr]} { setBit $symbol(C) [expr {rand() > 0.5}] - } { + } else { if {[getBit $addr]} {setBit $symbol(C) 0} } evaluate_bit $symbol(C) @@ -235,10 +240,10 @@ private method ins_anl_C_N {addr} { private method ins_cjne_AD {addr roff} { if {[check_address_validity D $addr]} { set val [undefined_octet] - } { + } else { if {$addr < 128} { set val $ram($addr) - } { + } else { set val $sfr($addr) } } @@ -254,15 +259,14 @@ private method ins_cjne {val0 val1 roff} { set time 2 if {$val0 != $val1} { - if {$val0 < $val1} { - setBit $symbol(C) 1 - } { - setBit $symbol(C) 0 - } - if {$roff > 127} {incr roff -256} incr_pc $roff } + if {$val0 < $val1} { + setBit $symbol(C) 1 + } else { + setBit $symbol(C) 0 + } } ## Instruction: CJNE @Ri, ... @@ -275,19 +279,18 @@ private method ins_cjne_ID {addr val1 roff} { if {[check_address_validity I $addr]} { set val0 [undefined_octet] - } { + } else { set val0 $ram($addr) } if {$val0 != $val1} { - if {$val0 < $val1} { - setBit $symbol(C) 1 - } { - setBit $symbol(C) 0 - } - if {$roff > 127} {incr roff -256} incr_pc $roff } + if {$val0 < $val1} { + setBit $symbol(C) 1 + } else { + setBit $symbol(C) 0 + } } ## Instruction: CLR @@ -309,7 +312,7 @@ private method ins_clr {opr} { setBit $symbol(C) 0 evaluate_bit $symbol(C) # Some bit - } { + } else { if {[check_address_validity B $opr]} {return} set rmw_instruction 1 setBit $opr 0 @@ -335,17 +338,17 @@ private method ins_cpl {opr} { } elseif {$opr == {C}} { if {[getBit $symbol(C)]} { setBit $symbol(C) 0 - } { + } else { setBit $symbol(C) 1 } evaluate_bit $symbol(C) # Some bit - } { + } else { if {[check_address_validity B $opr]} {return} set rmw_instruction 1 if {[getBit $opr]} { setBit $opr 0 - } { + } else { setBit $opr 1 } evaluate_bit $opr @@ -423,7 +426,7 @@ private method ins_div {} { setBit $symbol(OV) 1 set sfr(224) 0 set sfr($symbol(B)) 0 - } { + } else { setBit $symbol(OV) 0 set A $sfr(224) set sfr(224) [expr {$A / $sfr($symbol(B))}] @@ -449,7 +452,7 @@ private method ins_djnz {addr roff} { incr_pc $roff } evaluate_sfr $addr - } { + } else { if {$ram($addr) != 0} { if {$roff > 127} {incr roff -256} incr_pc $roff @@ -517,7 +520,7 @@ private method ins_jb {addr roff} { set time 2 if {[check_address_validity B $addr]} { set val [expr {rand() > 0.5}] - } { + } else { set val [getBit $addr] } if {$val} { @@ -534,7 +537,7 @@ private method ins_jnb {addr roff} { set time 2 if {[check_address_validity B $addr]} { set val [expr {rand() > 0.5}] - } { + } else { set val [getBit $addr] } if {!$val} { @@ -552,7 +555,7 @@ private method ins_jbc {addr roff} { set time 2 if {[check_address_validity B $addr]} { set val [expr {rand() > 0.5}] - } { + } else { set val [getBit $addr] } if {$val} { @@ -653,7 +656,7 @@ private method ins_mov {addr val} { if {$sync_ena} { $this Simulator_sync_reg $addr } - } { + } else { write_sfr $addr $val evaluate_sfr $addr } @@ -670,7 +673,7 @@ private method ins_mov_D {addr1 addr0} { if {[check_address_validity D $addr0]} {return} if {[check_address_validity D $addr1]} { set val [undefined_octet] - } { + } else { if {$addr1 < 128} { set val $ram($addr1) } { @@ -686,7 +689,7 @@ private method ins_mov_D {addr1 addr0} { if {$sync_ena} { $this Simulator_sync_reg $addr0 } - } { + } else { write_sfr $addr0 $val evaluate_sfr $addr0 } @@ -699,10 +702,10 @@ private method ins_mov_D {addr1 addr0} { private method ins_mov_ID2 {addr0 addr1} { if {[check_address_validity D $addr1]} { ins_mov_ID0 $addr0 [undefined_octet] - } { + } else { if {$addr1 < 128} { ins_mov_ID0 $addr0 $ram($addr1) - } { + } else { ins_mov_ID0 $addr0 [read_sfr $addr1] } } @@ -720,7 +723,7 @@ private method ins_mov_ID1 {addr addr_id} { if {[check_address_validity D $addr]} {return} if {[check_address_validity I $addr_id]} { set val [undefined_octet] - } { + } else { set val $ram($addr_id) } if {$addr < 128} { @@ -731,7 +734,7 @@ private method ins_mov_ID1 {addr addr_id} { if {$sync_ena} { $this Simulator_sync_reg $addr } - } { + } else { write_sfr $addr $val evaluate_sfr $addr } @@ -788,7 +791,7 @@ private method ins_mov_Rx_ADDR {idx addr} { } if {$addr < 128} { set ram($t_addr) $ram($addr) - } { + } else { set ram($t_addr) [read_sfr $addr] } @@ -806,21 +809,21 @@ private method ins_mov_bit {dest source} { if {$dest == {C}} { if {[check_address_validity B $source]} { set val [expr {rand() < 0.5}] - } { + } else { set val [getBit $source] } if {$val} { setBit $symbol(C) 1 - } { + } else { setBit $symbol(C) 0 } - } { + } else { set rmw_instruction 1 incr time if {[check_address_validity B $dest]} {return} if {[getBit $symbol(C)]} { setBit $dest 1 - } { + } else { setBit $dest 0 } } @@ -837,7 +840,7 @@ private method ins_movc {arg} { if {$arg == {DPTR}} { set addr [expr {($sfr(224) + $sfr($symbol($DPL))) + ($sfr($symbol($DPH)) << 8)}] # MOVC A, @A+PC - } { + } else { set addr $pc incr addr $sfr(224) } @@ -853,7 +856,7 @@ private method ins_movc {arg} { set sfr(224) [undefined_octet] } elseif {$code($addr) != {}} { set sfr(224) $code($addr) - } { + } else { set sfr(224) [undefined_octet] } @@ -885,14 +888,14 @@ private method ins_movx {opr0 opr1} { if {$Saddr < $eram_size && !$controllers_conf(EXTRAM)} { if {[check_address_validity E $Saddr]} { set sfr(224) [undefined_octet] - } { + } else { set sfr(224) $eram($Saddr) } # Read from data EEPROM } elseif {$Saddr < $eeprom_size && $controllers_conf(EEMEN)} { if {[check_address_validity P $Saddr]} { set sfr(224) [undefined_octet] - } { + } else { set complement_MSB 0 foreach reg $eeprom_prev { if {$Saddr == [lindex $reg 0]} { @@ -902,13 +905,13 @@ private method ins_movx {opr0 opr1} { } if {$complement_MSB} { set sfr(224) [expr {$eeprom($Saddr) ^ 0x80}] - } { + } else { set sfr(224) $eeprom($Saddr) } } # Read from external data memory } else { - if {$feature_avaliable(xram) && [$this pale_is_enabled]} { + if {$feature_available(xram) && [$this pale_is_enabled]} { for {set i -3} {$i < 0} {incr i} { if {!$controllers_conf(X2)} { $this pale_WPBBL $PIN(RD) {X} $i @@ -918,7 +921,7 @@ private method ins_movx {opr0 opr1} { $this pale_WPBBL $PIN(RD) {X} $i $this pale_WPBL 0 X $i $this pale_WPBL 2 X $i - } { + } else { incr i $this pale_WPBL 0 X [expr {int($i / 2)}] $this pale_WPBL 2 X [expr {int($i / 2)}] @@ -928,7 +931,7 @@ private method ins_movx {opr0 opr1} { } if {[check_address_validity X $Saddr]} { set sfr(224) [undefined_octet] - } { + } else { set sfr(224) $xram($Saddr) } } @@ -978,7 +981,7 @@ private method ins_movx {opr0 opr1} { set eeprom_WR_ofs "0x$offset" ::X::eeprom_write_buffer_set_offset $eeprom_WR_ofs $this - # Start EEPROM programing cycle + # Start EEPROM programming cycle if {!$controllers_conf(EELD)} { # Write data to data EEPROM set eeprom_prev {} @@ -993,7 +996,7 @@ private method ins_movx {opr0 opr1} { set eeprom_WR_buff($i) {} } - # Clear write buffer hexeditor + # Clear write buffer hex editor ::X::eeprom_write_buffer_set_offset {} $this ::X::clear_eeprom_write_buffer $this @@ -1017,7 +1020,7 @@ private method ins_movx {opr0 opr1} { # Write to external data memory } else { - if {$feature_avaliable(xram) && [$this pale_is_enabled]} { + if {$feature_available(xram) && [$this pale_is_enabled]} { for {set i -3} {$i < 0} {incr i} { if {!$controllers_conf(X2)} { $this pale_WPBBL $PIN(WR) {X} $i @@ -1027,7 +1030,7 @@ private method ins_movx {opr0 opr1} { $this pale_WPBBL $PIN(WR) {X} $i $this pale_WPBL 0 X $i $this pale_WPBL 2 X $i - } { + } else { incr i $this pale_WPBL 0 X [expr {int($i / 2)}] $this pale_WPBL 2 X [expr {int($i / 2)}] @@ -1037,6 +1040,7 @@ private method ins_movx {opr0 opr1} { } if {[check_address_validity X $Daddr]} {return} + stepback_reg_change X $Daddr set xram($Daddr) $sfr(224) } @@ -1062,7 +1066,7 @@ private method ins_mul {} { if {$result > 255} { set sfr(240) [expr {($result & 0xFF00) >> 8}] setBit $symbol(OV) 1 - } { + } else { set sfr(240) 0 setBit $symbol(OV) 0 } @@ -1096,7 +1100,7 @@ private method ins_orl {addr val} { if {$sync_ena} { $this Simulator_sync_reg $addr } - } { + } else { set rmw_instruction 1 write_sfr $addr [expr {[read_sfr $addr] | $val}] evaluate_sfr $addr @@ -1113,7 +1117,7 @@ private method ins_orl_D {addr0 addr1} { ins_orl $addr0 [undefined_octet] } elseif {$addr1 < 128} { ins_orl $addr0 $ram($addr1) - } { + } else { ins_orl $addr0 [read_sfr $addr1] } } @@ -1129,7 +1133,7 @@ private method ins_orl_ID {addr addr_id} { if {[check_address_validity D $addr]} {return} if {[check_address_validity I $addr_id]} { set val [undefined_octet] - } { + } else { set val $ram($addr_id) } if {$addr < 128} { @@ -1140,7 +1144,7 @@ private method ins_orl_ID {addr addr_id} { if {$sync_ena} { $this Simulator_sync_reg $addr } - } { + } else { set rmw_instruction 1 write_sfr $addr [expr {[read_sfr $addr] | $val}] evaluate_sfr $addr @@ -1157,7 +1161,7 @@ private method ins_orl_not_bit {addr} { setBit $symbol(C) [expr {rand() < 0.5}] } elseif {[getBit $symbol(C)] || ![getBit $addr]} { setBit $symbol(C) 1 - } { + } else { setBit $symbol(C) 0 } } @@ -1172,7 +1176,7 @@ private method ins_orl_bit {addr} { setBit $symbol(C) [expr {rand() < 0.5}] } elseif {[getBit $symbol(C)] || [getBit $addr]} { setBit $symbol(C) 1 - } { + } else { setBit $symbol(C) 0 } } @@ -1193,7 +1197,7 @@ private method ins_pop {addr} { if {$sync_ena} { $this Simulator_sync_reg $addr } - } { + } else { write_sfr $addr [stack_pop] evaluate_sfr $addr } @@ -1243,13 +1247,15 @@ private method ins_reti {} { $this interrupt_monitor_reti [lindex $inter_in_p_flags end] set interrupts_in_progress [lreplace $interrupts_in_progress end end] set inter_in_p_flags [lreplace $inter_in_p_flags end end] - if {[llength $interrupts_in_progress]} { - set vector [format %X [intr2vector [lindex $interrupts_in_progress end]]] - simulator_Sbar [mc "Interrupt at vector 0x%s " $vector] 1 $this - } { - simulator_Sbar {} 0 $this + if {$::GUI_AVAILABLE} { + if {[llength $interrupts_in_progress]} { + set vector [format %X [intr2vector [lindex $interrupts_in_progress end]]] + simulator_Sbar [mc "Interrupt at vector 0x%s " $vector] 1 $this + } else { + simulator_Sbar {} 0 $this + } } - } { + } else { $this simulator_invalid_reti_dlg $pc $Line($pc) } @@ -1295,7 +1301,7 @@ private method ins_rlc {} { if {$sfr(224) > 255} { incr sfr(224) -256 setBit $symbol(C) 1 - } { + } else { setBit $symbol(C) 0 } @@ -1313,7 +1319,7 @@ private method ins_rr {} { } if {[expr {$sfr(224) % 2}]} { set C 1 - } { + } else { set C 0 } @@ -1335,7 +1341,7 @@ private method ins_rrc {} { } if {[expr {$sfr(224) % 2}]} { set C 1 - } { + } else { set C 0 } @@ -1347,7 +1353,7 @@ private method ins_rrc {} { if {$C} { setBit $symbol(C) 1 - } { + } else { setBit $symbol(C) 0 } @@ -1363,7 +1369,7 @@ private method ins_setb {opr} { if {$opr == {C}} { setBit $symbol(C) 1 - } { + } else { if {[check_address_validity B $opr]} {return} set rmw_instruction 1 setBit $opr 1 @@ -1399,7 +1405,7 @@ private method ins_subb_D {addr} { ins_subb [undefined_octet] } elseif {$addr < 128} { ins_subb $ram($addr) - } { + } else { ins_subb $sfr($addr) } } @@ -1412,7 +1418,7 @@ private method ins_subb_ID {addr} { incr_pc 1 if {[check_address_validity I $addr]} { ins_subb [undefined_octet] - } { + } else { alo_subb $ram($addr) } evaluate_sfr 224 @@ -1457,7 +1463,7 @@ private method ins_xch {addr} { if {$sync_ena} { $this Simulator_sync_reg $addr } - } { + } else { set sfr(224) [read_sfr $addr] write_sfr $addr $A evaluate_sfr $addr @@ -1499,14 +1505,14 @@ private method ins_xchd {addr} { set val [undefined_octet] } elseif {$addr < 128} { set val $ram($addr) - } { + } else { set val $sfr($addr) } if {${::Simulator::reverse_run_steps}} { stepback_reg_change S 224 if {$addr < 128} { stepback_reg_change I $addr - } { + } else { stepback_reg_change S $addr } } @@ -1518,7 +1524,7 @@ private method ins_xchd {addr} { set val [expr {($val & 240) + $nibble0}] if {$addr < 128} { set ram($addr) $val - } { + } else { set sfr($addr) $val } @@ -1545,7 +1551,7 @@ private method ins_xrl {addr val} { if {$sync_ena} { $this Simulator_sync_reg $addr } - } { + } else { set rmw_instruction 1 write_sfr $addr [expr {[read_sfr $addr] ^ $val}] evaluate_sfr $addr @@ -1561,7 +1567,7 @@ private method ins_xrl_D {addr0 addr1} { ins_xrl $addr0 [undefined_octet] } elseif {$addr1 < 128} { ins_xrl $addr0 $ram($addr1) - } { + } else { ins_xrl $addr0 [read_sfr $addr1] } } @@ -1577,7 +1583,7 @@ private method ins_xrl_ID {addr addr_id} { if {[check_address_validity I $addr_id]} { set val [undefined_octet] - } { + } else { set val $ram($addr_id) } if {$addr < 128} { @@ -1588,9 +1594,13 @@ private method ins_xrl_ID {addr addr_id} { if {$sync_ena} { $this Simulator_sync_reg $addr } - } { + } else { set rmw_instruction 1 write_sfr $addr [expr {[read_sfr $addr] ^ $val}] evaluate_sfr $addr } } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/engine/engine_mcu_configuration.tcl b/lib/simulator/engine/engine_mcu_configuration.tcl index 7701583..2226a7d 100755..100644 --- a/lib/simulator/engine/engine_mcu_configuration.tcl +++ b/lib/simulator/engine/engine_mcu_configuration.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 _ENGINE_MCU_CONFIGURATION_TCL ] } { +set _ENGINE_MCU_CONFIGURATION_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Part of simulator engine functionality. @@ -53,7 +58,7 @@ private method increment_program_time {num} { return [watchdog_controller] } -## Adjust configuration acording to new value of the given bit +## Adjust configuration according to new value of the given bit # @parm Int addr - Bit address # @return void private method evaluate_bit {addr} { @@ -61,18 +66,18 @@ private method evaluate_bit {addr} { if {$sync_ena} { $this Simulator_sync_reg [getRegOfBit $addr] } - } { + } else { evaluate_sfr [getRegOfBit $addr] } } -## Evaluate list of interrupt priorities acording to values of IP and IPH +## Evaluate list of interrupt priorities according to values of IP and IPH # @return void private method evaluate_interrupt_priorities {} { # Determinate value of Interrupt Priority High register - if {$feature_avaliable(iph)} { + if {$feature_available(iph)} { set iph $sfr(183) - } { + } else { set iph 0 } @@ -115,17 +120,17 @@ private method evaluate_interrupt_priorities {} { foreach flag $controllers_conf(IP) ip $controllers_conf(IP_level) { switch -- $flag { PS { - if {$feature_avaliable(uart)} { + if {$feature_available(uart)} { lappend interrupt_pri_flg RI TI lappend interrupt_pri_num $ip $ip } - if {$feature_avaliable(spi)} { + if {$feature_available(spi)} { lappend interrupt_pri_flg SPIF lappend interrupt_pri_num $ip } } PT2 { - if {!$feature_avaliable(t2)} {continue} + if {!$feature_available(t2)} {continue} lappend interrupt_pri_flg EXF2 TF2 lappend interrupt_pri_num $ip $ip } @@ -146,7 +151,7 @@ private method evaluate_interrupt_priorities {} { lappend interrupt_pri_num $ip } PC { - if {!$feature_avaliable(acomparator)} {continue} + if {!$feature_available(acomparator)} {continue} lappend interrupt_pri_flg CF lappend interrupt_pri_num $ip } @@ -154,17 +159,16 @@ private method evaluate_interrupt_priorities {} { } # Adjust interrup monitor - $this interrupt_monitor_intr_prior $interrupt_pri_flg + if {$::GUI_AVAILABLE} { + $this interrupt_monitor_intr_prior $interrupt_pri_flg + } } -## Adjust configuration acording to new value of the given SFR - # @parm Int - Register address - # @parm Bool = 1 - Synchronize this SFR with external interface +## Adjust configuration according to new value of the given SFR + # @parm Int addr - Register address + # @parm Bool sync=1 - Synchronize this SFR with external interface # @return void -private method evaluate_sfr args { - set addr [lindex $args 0] - set sync [lindex $args 1] - +private method evaluate_sfr {addr {sync 1}} { switch -- $addr { 135 { ;# PCON 0x87 set SMOD0_prev $controllers_conf(SMOD0) @@ -179,7 +183,9 @@ private method evaluate_sfr args { write_conf 168 {EA EC ET2 ES ET1 EX1 ET0 EX0} # Inform interrupt monitor - $this interrupt_monitor_intr_ena_dis + if {$::GUI_AVAILABLE} { + $this interrupt_monitor_intr_ena_dis + } } 184 { ;# IP 0xB8 evaluate_interrupt_priorities @@ -190,7 +196,7 @@ private method evaluate_sfr args { # Determinate SM0 and FE if {$controllers_conf(SMOD0)} { set controllers_conf(FE) [expr {($sfr(152) & 0x80) ? 1 : 0}] - } { + } else { set controllers_conf(SM0) [expr {($sfr(152) & 0x80) ? 1 : 0}] } @@ -203,13 +209,17 @@ private method evaluate_sfr args { } # Inform interrupt monitor - $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + if {$::GUI_AVAILABLE} { + $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + } } 136 { ;# TCON 0x88 write_conf 136 {TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0} # Inform interrupt monitor - $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + if {$::GUI_AVAILABLE} { + $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + } } 137 { ;# TMOD 0x89 write_conf 137 {GATE1 CT1 M11 M01 GATE0 CT0 M10 M00} @@ -234,19 +244,18 @@ private method evaluate_sfr args { set bank [expr {($sfr(208) & 24) >> 3}] } 224 { ;# A 0xE0 - set A 0 set count 0 set mask 1 for {set i 0} {$i < 8} {incr i} { - if {[expr {$sfr(224) & $mask}] > 0} { + if {$sfr(224) & $mask} { incr count } set mask [expr {$mask << 1}] } - if {[expr {$count % 2}] == 1} { + if {$count % 2} { setBit $symbol(P) 1 - } { + } else { setBit $symbol(P) 0 } } @@ -256,11 +265,11 @@ private method evaluate_sfr args { write_conf 162 {- - - - - - - DPS} # Switch visible dual DPTR - if {!$feature_avaliable(hddptr)} { + if {!$feature_available(hddptr)} { if {$controllers_conf(DPS)} { set DPL {DP1L} set DPH {DP1H} - } { + } else { set DPL {DP0L} set DPH {DP0H} } @@ -269,13 +278,13 @@ private method evaluate_sfr args { } elseif {$DPS_org != $controllers_conf(DPS)} { if {$DPS_org} { set hidden_DPTR1 [list $sfr($symbol(DP0L)) $sfr($symbol(DP0H))] - } { + } else { set hidden_DPTR0 [list $sfr($symbol(DP0L)) $sfr($symbol(DP0H))] } if {$controllers_conf(DPS)} { set sfr($symbol(DP0L)) [lindex $hidden_DPTR1 0] set sfr($symbol(DP0H)) [lindex $hidden_DPTR1 1] - } { + } else { set sfr($symbol(DP0L)) [lindex $hidden_DPTR0 0] set sfr($symbol(DP0H)) [lindex $hidden_DPTR0 1] } @@ -290,13 +299,13 @@ private method evaluate_sfr args { } } 142 { ;# AUXR 0x8E - if {$feature_avaliable(wdtcon)} { - if {$feature_avaliable(intelpe)} { + if {$feature_available(wdtcon)} { + if {$feature_available(intelpe)} { write_conf 142 {- - - - - - IPE DISALE} - } { + } else { write_conf 142 {- - - - - - EXTRAM DISALE} } - } { + } else { write_conf 142 {- - - WDIDLE DISRTO - EXTRAM DISALE} } } @@ -306,7 +315,7 @@ private method evaluate_sfr args { set controllers_conf(WatchDogTimer) 1 set watchdog_value -$time - if {$feature_avaliable(wdtcon)} { + if {$feature_available(wdtcon)} { set controllers_conf(WDTEN) 1 set sfr(167) [expr {$sfr(167) | 1}] if {${::Simulator::reverse_run_steps}} { @@ -324,7 +333,9 @@ private method evaluate_sfr args { write_conf 200 {TF2 EXF2 RCLK TCLK EXEN2 TR2 CT2 CPRL2} # Inform interrupt monitor - $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + if {$::GUI_AVAILABLE} { + $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + } } 201 { ;# T2MOD 0xC9 write_conf 201 {- - - - - - T2OE DCEN} @@ -342,7 +353,9 @@ private method evaluate_sfr args { }] # Inform interrupt monitor - $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + if {$::GUI_AVAILABLE} { + $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + } } 183 { ;# IPH 0xB7 evaluate_interrupt_priorities @@ -354,12 +367,14 @@ private method evaluate_sfr args { write_conf 170 {SPIF WCOL LDEN - - - DISSO ENH} # Inform interrupt monitor - $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + if {$::GUI_AVAILABLE} { + $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + } } 167 { ;# WDTCON/WDTPRG 0xA7 - if {$feature_avaliable(wdtprg)} { + if {$feature_available(wdtprg)} { write_conf 167 {- - - - - PS2 PS1 PS0} - } { + } else { write_conf 167 {PS2 PS1 PS0 WDIDLE DISRTO HWDT WSWRST WDTEN} } set controllers_conf(WatchDogPrescaler) 0 @@ -395,7 +410,7 @@ private method evaluate_sfr args { if {$controllers_conf(DPS)} { set DPL {DP1L} set DPH {DP1H} - } { + } else { set DPL {DP0L} set DPH {DP0H} } @@ -423,7 +438,7 @@ private method write_conf {addr key_list} { if {[expr {$sfr($addr) & $mask}] == 0} { set controllers_conf($key) 0 - } { + } else { set controllers_conf($key) 1 } } @@ -499,7 +514,7 @@ private method incr_8b {type addr val} { private method stack_pop {} { if {[check_address_validity I $sfr(129)]} { set result [undefined_octet] - } { + } else { if {${::Simulator::reverse_run_steps}} { stepback_reg_change I $sfr(129) } @@ -540,7 +555,7 @@ public method stack_push {val} { } if {[check_address_validity I $sfr(129)]} { return - } { + } else { if {${::Simulator::reverse_run_steps}} { stepback_reg_change I $sfr(129) } @@ -553,3 +568,7 @@ public method stack_push {val} { evaluate_sfr 129 $this stack_monitor_push $sfr(129) $val } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/engine/engine_memory_management.tcl b/lib/simulator/engine/engine_memory_management.tcl index acf2978..e3a5828 100755..100644 --- a/lib/simulator/engine/engine_memory_management.tcl +++ b/lib/simulator/engine/engine_memory_management.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 _ENGINE_MEMORY_MANAGEMENT_TCL ] } { +set _ENGINE_MEMORY_MANAGEMENT_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Part of simulator engine functionality. @@ -40,11 +45,11 @@ private method getNextOperand {} { bell $this sim_txt_output [mc "Incomplete instruction (undefined operand/value missing in memory) at 0x%s" [NumSystem::dec2hex $pc]] return [undefined_octet] - } { + } else { if {$code($pc) == {}} { $this sim_txt_output [mc "Incomplete instruction (undefined operand/value missing in memory) at 0x%s. Using 0FFh as operand !" [NumSystem::dec2hex $pc]] return 255 - } { + } else { return $code($pc) } } @@ -59,11 +64,11 @@ private method getLastOperand {} { bell $this sim_txt_output [mc "Incomplete instruction (undefined operand/value missing in memory) at 0x%s" [NumSystem::dec2hex $pc]] set result [undefined_octet] - } { + } else { if {$code($pc) == {}} { $this sim_txt_output [mc "Incomplete instruction (undefined operand/value missing in memory) at 0x%s. Using 0FFh as operand !" [NumSystem::dec2hex $pc]] set result 255 - } { + } else { set result $code($pc) } } @@ -92,7 +97,7 @@ public method setBit {addr value} { if {${::Simulator::reverse_run_steps}} { if {$regAddr < 128} { stepback_reg_change I $regAddr - } { + } else { stepback_reg_change S $regAddr } } @@ -114,7 +119,7 @@ public method setBit {addr value} { } elseif {([expr {$ram($regAddr) & $mask}] == 0) && $value} { set ram($regAddr) [expr {$ram($regAddr) ^ $mask}] } - } { + } else { set sfr_val [read_sfr $regAddr] if {([expr {$sfr_val & $mask}] > 0) && !$value} { write_sfr $regAddr [expr {$sfr_val ^ $mask}] @@ -125,7 +130,7 @@ public method setBit {addr value} { if {$regAddr > 127} { evaluate_sfr $regAddr - } { + } else { if {$sync_ena} { $this Simulator_sync_reg $regAddr } @@ -161,19 +166,19 @@ public method getBitByReg {regAddr bitNumber} { if {$regAddr < 0x80} { if {[expr {$ram($regAddr) & $mask}] == 0} { return 0 - } { + } else { return 1 } - } { - if {[lsearch -ascii -exact $PORT_LATCHES $regAddr] != -1} { + } else { + if {[lsearch -ascii -exact $PORT_LATCHES $regAddr] != -1} { set byte [read_sfr $regAddr] - } { - set byte $sfr($regAddr) - } + } else { + set byte $sfr($regAddr) + } if {[expr {$byte & $mask}] == 0} { return 0 - } { + } else { return 1 } } @@ -187,7 +192,7 @@ public method getRegOfBit {addr} { if {$addr > 127} { set reg [expr {$reg * 8}] - } { + } else { incr reg 32 } @@ -247,7 +252,9 @@ private method check_address_validity {location address} { } internal_shutdown - $this invalid_addressing_dialog $location $address + if {$::GUI_AVAILABLE} { + $this invalid_addressing_dialog $location $address + } set address_error 1 return 1 } @@ -255,8 +262,10 @@ private method check_address_validity {location address} { ## Check if the specified address at the given location is implemented in this MCU # @parm Char location - Memory type # D == IDATA direct addressing or SFR + # S == SFR only # I == IDATA indirect addressing (or operations on stack) # B == Bit area + # J == Special Function Bits only # X == XDATA # C == CODE # E == ERAM @@ -269,7 +278,12 @@ public method simulator_address_range {location address} { if {$address < 128 && $address < $iram_size} { return 1 } - if {[lsearch $avaliable_sfr $address] != -1} { + if {[lsearch $available_sfr $address] != -1} { + return 1 + } + } + {S} { ;# SFR only + if {[lsearch $available_sfr $address] != -1} { return 1 } } @@ -286,7 +300,15 @@ public method simulator_address_range {location address} { if {$reg_addr < 128 && $reg_addr < $iram_size} { return 1 } - if {[lsearch $avaliable_sfr $reg_addr] != -1} { + if {[lsearch $available_sfr $reg_addr] != -1} { + return 1 + } + } + {J} { ;# Special Function Bits only + if {[lsearch $restricted_bits $address] != -1} { + return 0 + } + if {[lsearch $available_sfr [getRegOfBit $address]] != -1} { return 1 } } @@ -316,7 +338,8 @@ public method simulator_address_range {location address} { ## Write value to SFR # - It does not check address validity ! - # - Purpose is to write zero to unimplemented bits + # - Purpose is to write zero to unimplemented bits and handle special funtions + # triggered by write to specific SFR # @parm Int addr - Target address (128..255) # @parm Int value - New value (0.255) # @return void @@ -341,15 +364,15 @@ private method write_sfr {addr value} { # Interrupts configuration related SFR -- skip next interrupt if {$addr == $symbol(IP) || $addr == $symbol(IE) || $addr == $symbol(IPH)} { set skip_interrupt 1 - } { + } else { set skip_interrupt 0 } # Write specified value into the SFR - if {[lsearch $incomplite_regs $addr] == -1} { + if {[lsearch $incomplete_regs $addr] == -1} { set sfr($addr) $value - } { - set sfr($addr) [expr {$value & $incomplite_regs_mask($addr)}] + } else { + set sfr($addr) [expr {$value & $incomplete_regs_mask($addr)}] } } @@ -361,7 +384,7 @@ private method write_sfr {addr value} { private method read_sfr {addr} { # Port latch set port_number [lsearch -ascii -exact $PORT_LATCHES $addr] - if {!$rmw_instruction && $port_number != -1} { + if {!$rmw_instruction && $port_number != -1 && [$this pale_is_enabled]} { set result [$this pale_RRPV $port_number] # Write only register @@ -373,15 +396,19 @@ private method read_sfr {addr} { return [undefined_octet] # Fully implemeneted register - } elseif {[lsearch $incomplite_regs $addr] == -1} { + } elseif {[lsearch $incomplete_regs $addr] == -1} { return $sfr($addr) # Partialy implemented register - } { + } else { return [expr { - ($incomplite_regs_mask($addr) & $sfr($addr)) + ($incomplete_regs_mask($addr) & $sfr($addr)) + - (($incomplite_regs_mask($addr) ^ 0x0FF) & [undefined_octet]) + (($incomplete_regs_mask($addr) ^ 0x0FF) & [undefined_octet]) }] } } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/engine/engine_opcodes.tcl b/lib/simulator/engine/engine_opcodes.tcl index 6d43158..e06dc12 100755..100644 --- a/lib/simulator/engine/engine_opcodes.tcl +++ b/lib/simulator/engine/engine_opcodes.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 _ENGINE_OPCODES_TCL ] } { +set _ENGINE_OPCODES_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Part of simulator engine functionality. @@ -433,3 +438,7 @@ private method 108 {} {ins_xrl 224 $ram([R 4])} ;# 0x6C :: xrl A, R4 private method 109 {} {ins_xrl 224 $ram([R 5])} ;# 0x6D :: xrl A, R5 private method 110 {} {ins_xrl 224 $ram([R 6])} ;# 0x6E :: xrl A, R6 private method 111 {} {ins_xrl 224 $ram([R 7])} ;# 0x6F :: xrl A, R7 + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/engine/engine_text_based_interface.tcl b/lib/simulator/engine/engine_text_based_interface.tcl new file mode 100644 index 0000000..0b6448c --- /dev/null +++ b/lib/simulator/engine/engine_text_based_interface.tcl @@ -0,0 +1,1087 @@ +#!/usr/bin/tclsh +# Part of MCU 8051 IDE ( http://mcu8051ide.sf.net ) + +############################################################################ +# Copyright (C) 2011-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 _ENGINE_TEXT_BASED_INTERFACE_TCL ] } { +set _ENGINE_TEXT_BASED_INTERFACE_TCL _ +# <<< File inclusion guard + +# -------------------------------------------------------------------------- +# DESCRIPTION +# +# Command line interface for the simulator engine. Listens to simple commands, +# like `read-sfr-by-name PCON'. Each command must be on separate line, empty +# lines and everything after `#' characater are ignored. Response to every +# command is either `DONE' or +# `ERROR (line: <line_number>; command: <command>): <error_info>'. Some commands +# returns some values, in that case these values are printed before the `DONE' +# string. Commands are case insensitive, but the same may not apply for their +# arguments. +# +# Note: This interface is supposed to be available via main.tcl invoked with +# --simulator option. That means that to access this inteface it should be +# sufficient to run `mcu8051ide --simulator' command. +# +# List of commands: +# ================ +# +# COMMAND DESCRIPTION +# ------- ----------- +# echo-on +# echo-off +# set-mcu +# set-clock +# set-xcode +# set-xdata +# load-code +# load-code-adf +# load-code-cdb +# load-idata +# load-xdata +# load-eeprom +# load-eram +# dump-code +# dump-idata +# dump-xdata +# dump-eeprom +# dump-eram +# write-code +# write-idata +# write-xdata +# write-eeprom +# write-eram +# write-sfr +# write-sfr +# write-bit +# read-code +# read-idata +# read-xdata +# read-eeprom +# read-eram +# read-sfr +# read-sfr-by-name +# read-bit +# step +# step-back +# list-changes +# read-pc +# write-pc +# read-position +# reset +# run +# input +# output +# hibernate +# resume +# core-dump +# core-alter +# exit +# -------------------------------------------------------------------------- + +namespace eval SimulatorEngineCLI { + variable command_line + variable cmd_line_idx + variable simulator + variable line_counter + variable echo + variable error_reported + + class SimEngineWrapper { + inherit Simulator_ENGINE Pale + + common changed_registers [list] + + # TODO: get rid of these variables: + public variable procData {} + public variable P_option_mcu_type {} + public variable P_option_mcu_xdata 0 + public variable P_option_mcu_xcode 0 + public variable projectPath {.} + + public method is_ready {} { + if {[llength $procData]} { + return 1 + } else { + return 0 + } + } + + public method Simulator_GUI_sync args { + lappend changed_registers $args + } + + public method Simulator_sync_PC_etc {} { + } + + public method get_changed_registers {} { + return $changed_registers + } + + public method clear_changed_registers {} { + set changed_registers [list] + } + } + + proc enter_main_loop {} { + variable command_line + variable cmd_line_idx + variable simulator + variable line_counter 0 + variable echo 0 + variable error_reported + + set simulator [SimEngineWrapper #auto] + + namespace eval ::Simulator { + variable undefined_value 2 + variable reverse_run_steps 100 + } + + namespace eval ::X { + variable critical_procedure_in_progress 0 + } + + puts "READY" + + while {![eof stdin]} { + incr line_counter + set command_line [gets stdin] + set command_line [regsub {#.*$} $command_line {}] + set command_line [string trim $command_line] + set cmd_line_idx 1 + set error_reported 0 + + if {[catch { + set command [string tolower [lindex $command_line 0]] + }]} then { + set tmp $command_line + set command_line {<unknown>} + abort_now "Unable to understand line: \"$tmp\"" + } + + # Do nothing with an empty line + if {![string length $command_line]} { + continue + } + + if {$echo} { + puts "> $command_line" + } + if {[lsearch -ascii -exact {set-mcu echo-on echo-off} $command] == -1 && ![$simulator is_ready]} { + report_error "Processor type has to be specified first" + continue + } + if {[command_switch $command]} { + break + } + + if {!$error_reported} { + puts "OK" + } + } + puts "EXITING" + } + + proc command_switch {command} { + variable echo + switch -- $command { + {echo-on} { + expect_no_more_arguments + command__echo_on + } + {echo-off} { + expect_no_more_arguments + command__echo_off + } + {set-mcu} { + expect_string + expect_no_more_arguments + + command__set_mcu + } + {set-clock} { + expect_integer 1 99999 + expect_no_more_arguments + + command__set_clock + } + {set-xcode} { + expect_integer 0 65536 + expect_no_more_arguments + + command__set_xcode + } + {set-xdata} { + expect_integer 0 65536 + expect_no_more_arguments + + command__set_xdata + } + + {load-code} { + expect_no_more_arguments + command__load_code + } + {load-code-adf} { + expect_string + expect_no_more_arguments + + command__load_code_adf + } + {load-code-cdb} { + expect_string + expect_string + expect_string + expect_no_more_arguments + command__load_code_cdb + } + {load-idata} { + expect_no_more_arguments + command__load_idata + } + {load-xdata} { + expect_no_more_arguments + command__load_xdata + } + {load-eeprom} { + expect_no_more_arguments + command__load_eeprom + } + {load-eram} { + expect_no_more_arguments + command__load_eram + } + + {dump-code} { + expect_no_more_arguments + command__dump_code + } + {dump-idata} { + expect_no_more_arguments + command__dump_idata + } + {dump-xdata} { + expect_no_more_arguments + command__dump_xdata + } + {dump-eeprom} { + expect_no_more_arguments + command__dump_eeprom + } + {dump-eram} { + expect_no_more_arguments + command__dump_eram + } + + {write-code} { + expect_integer 0 65536 + expect_integer 0 256 + expect_no_more_arguments + + command__write_code + } + {write-idata} { + expect_integer 0 256 + expect_integer 0 256 + expect_no_more_arguments + + command__write_idata + } + {write-xdata} { + expect_integer 0 65536 + expect_integer 0 256 + expect_no_more_arguments + + command__write_xdata + } + {write-eeprom} { + expect_integer 0 65536 + expect_integer 0 256 + expect_no_more_arguments + + command__write_eeprom + } + {write-eram} { + expect_integer 0 65536 + expect_integer 0 256 + expect_no_more_arguments + + command__write_eram + } + {write-sfr} { + expect_integer 128 256 + expect_integer 0 256 + expect_no_more_arguments + + command__write_sfr + } + {write-sfr} { + expect_string + expect_integer 0 256 + expect_no_more_arguments + + command__write_sfr_by_name + } + {write-bit} { + expect_integer 0 256 + expect_integer 0 256 + expect_no_more_arguments + + command__write_bit + } + + {read-code} { + expect_integer 0 65536 + expect_no_more_arguments + + command__read_code + } + {read-idata} { + expect_integer 0 256 + expect_no_more_arguments + + command__read_idata + } + {read-xdata} { + expect_integer 0 65536 + expect_no_more_arguments + + command__read_xdata + } + {read-eeprom} { + expect_integer 0 65536 + expect_no_more_arguments + + command__read_eeprom + } + {read-eram} { + expect_integer 0 65536 + expect_no_more_arguments + + command__read_eram + } + {read-sfr} { + expect_integer 128 256 + expect_no_more_arguments + + command__read_sfr + } + {read-sfr-by-name} { + expect_string + expect_no_more_arguments + + command__read_sfr_by_name + } + {read-bit} { + expect_integer 0 256 + expect_no_more_arguments + + command__read_bit + } + + {step} { + expect_no_more_arguments + command__step + } + {step-back} { + expect_no_more_arguments + command__step_back + } + + {list-changes} { + expect_no_more_arguments + command__list_changes + } + {read-pc} { + expect_no_more_arguments + command__read_pc + } + {write-pc} { + expect_integer 0 65536 + expect_no_more_arguments + + command__write_pc + } + {read-position} { + expect_no_more_arguments + command__read_position + } + {reset} { + expect_no_more_arguments + command__reset + } + {run} { + expect_no_more_arguments + command__run + } + + {input} { + expect_integer 0 4 + expect_no_more_arguments + + command__input + } + {output} { + expect_integer 0 4 + expect_no_more_arguments + + command__output + } + + {hibernate} { + expect_string + expect_no_more_arguments + + command__hibernate + } + {resume} { + expect_string + expect_no_more_arguments + + command__resume + } + + {core-dump} { + expect_no_more_arguments + command__core_dump + } + {core-alter} { + expect_string + expect_no_more_arguments + + command__core_alter + } + + {exit} { + expect_no_more_arguments + return 1 + } + default { + report_error "Unrecognised command: \"$command\"" + } + } + return 0 + } + + proc abort_now {info} { + report_error $info + puts "ABORTING" + exit 1 + } + + proc report_error {info} { + variable error_reported + variable line_counter + variable command_line + + set error_reported 1 + puts stderr "ERROR (line: $line_counter; command: [lindex $command_line 0]): $info" + } + + proc expect_no_more_arguments {} { + variable command_line + variable cmd_line_idx + + if {[llength $command_line] > $cmd_line_idx} { + abort_now "Too many aguments given to to command [lindex $command_line 0]" + } + } + + proc expect_string {{max_length {}}} { + variable command_line + variable cmd_line_idx + + set arg [lindex $command_line $cmd_line_idx] + if {![string length $arg]} { + abort_now "Argument missing for command [lindex $command_line 0] at index $cmd_line_idx" + } elseif {$max_length != {} && [string length $arg] > $max_length} { + abort_now "Agrument given to command [lindex $command_line 0] at index $cmd_line_idx is too long, mimum allowed length is $max_length" + } + incr cmd_line_idx + } + + proc expect_integer {{min {}} {max {}}} { + variable command_line + variable cmd_line_idx + + set arg [lindex $command_line $cmd_line_idx] + if {![string is digit -strict $arg]} { + abort_now "Non integer agrument given to command [lindex $command_line 0] at index $cmd_line_idx" + } elseif {($min != {} && $arg < $min) || ($max != {} && $arg > $max)} { + abort_now "Integer agrument given to command [lindex $command_line 0] at index $cmd_line_idx is out of its allowed range \[$min;$max\]" + } + incr cmd_line_idx + } + + proc load_hex {set_command memory_size} { + variable simulator + + set hex_data {} + + while {![eof stdin]} { + set line [gets stdin] + append hex_data $line "\n" + + # Stop when EOF sequnce is found + if {[string range $line 7 8] == {01}} { + break + } + } + + ::IHexTools::free_resources + ::IHexTools::load_hex_data $hex_data + if {${::IHexTools::error_count}} { + report_error ${::IHexTools::error_string} + return + } + + if {${::IHexTools::highest_addr} >= $memory_size} { + report_error "You are attempting to load more data than the memory capacity allows. Capacity: $memory_size; Required: [expr {${::IHexTools::highest_addr} + 1}]" + } + + set val {} + for {set i 0} {$i < ${::IHexTools::highest_addr}} {incr i} { + set val [::IHexTools::get_value $i] + if {$val == -1} { + set val {} + } + $simulator $set_command $i $val + } + for {} {$i < $memory_size} {incr i} { + $simulator $set_command $i {} + } + } + + # ---------------------------------------------------------------------- + # COMMANDS + # ---------------------------------------------------------------------- + + proc command__echo_on {} { + variable echo 1 + } + proc command__echo_off {} { + variable echo 0 + } + proc command__set_mcu {} { + variable simulator + variable command_line + + set new_processor [string toupper [lindex $command_line 1]] + + if {[lsearch -ascii -exact [SelectMCU::get_available_processors] $new_processor] == -1} { + abort_now "Unsupported processor: [lindex $command_line 1]" + } + + $simulator configure -P_option_mcu_type $new_processor + set proc_data [SelectMCU::get_processor_details $new_processor] + if {$proc_data == {}} { + abort_now "Internal error" + } + $simulator configure -procData $proc_data + + $simulator simulator_initialize_mcu + } + proc command__set_clock {} { + variable simulator + variable command_line + + $simulator setEngineClock [lindex $command_line 1] + } + proc command__set_xcode {} { + variable simulator + variable command_line + + set arg [lindex $command_line 1] + + set icode [expr {[lindex [$simulator cget -procData] 2] * 1024}] + if {$arg > (0xFFFF - $icode)} { + abort_now "This MCU has CODE memory limit 0x10000 B (65536)" + } + + if {[lindex [$simulator cget -procData] 1] != {yes}} { + abort_now "This MCU cannot have connected external program memory" + } else { + $simulator configure -P_option_mcu_xcode $arg + $simulator simulator_resize_code_memory $arg + } + } + proc command__set_xdata {} { + variable simulator + variable command_line + + set arg [lindex $command_line 1] + if {[lindex [$simulator cget -procData] 0] != {yes}} { + abort_now "This MCU cannot have connected external data memory" + } else { + $simulator configure -P_option_mcu_xdata $arg + $simulator simulator_resize_xdata_memory $arg + } + } + proc command__reset {} { + variable simulator + $simulator master_reset - + } + + proc command__load_code {} { + variable simulator + variable command_line + + load_hex setCodeDEC [expr {[$simulator cget -P_option_mcu_xcode] + ([lindex [$simulator cget -procData] 2] * 1024)}] + } + + proc command__load_code_adf {} { + variable simulator + variable command_line + + if {[catch { + set file [open [lindex $command_line 1] {r}] + }]} then { + abort_now "Unable to open file: [lindex $command_line 1]" + } + + $simulator load_program_from_adf $file + foreach filename [$simulator simulator_get_list_of_filenames] { + $simulator Simulator_import_breakpoints $filename [list] + } + + catch { + close $file + } + } + proc command__load_code_cdb {} { + variable simulator + variable command_line + + set filename [lindex $command_line 1] + set cdb_flnm [lindex $command_line 2] + set ihx_flnm [lindex $command_line 3] + + set cdb_file {} + set ihx_file {} + + if {![file exists $filename]} { + report_error "File does not exist: \"$filename\"" + return + } + + if {[catch { + set cdb_file [open $cdb_flnm {r}] + }]} then { + report_error "Cannot open file: \"$cdb_flnm\"" + return + } + if {[catch { + set ihx_file [open $ihx_flnm {r}] + }]} then { + catch {close $cdb_file} + report_error "Cannot open file: \"$ihx_flnm\"" + return + } + + if {![$simulator load_program_from_cdb $filename $cdb_file $ihx_file]} { + report_error ${::IHexTools::error_string} + } else { + foreach filename [$simulator simulator_get_list_of_filenames] { + $simulator Simulator_import_breakpoints $filename [list] + } + } + + catch {close $cdb_file} + catch {close $ihx_file} + } + proc command__load_idata {} { + variable simulator + variable command_line + + load_hex setDataDEC [lindex [$simulator cget -procData] 3] + } + proc command__load_xdata {} { + variable simulator + variable command_line + + load_hex setXdataDEC [$simulator cget -P_option_mcu_xdata] + } + proc command__load_eeprom {} { + variable simulator + variable command_line + + load_hex setEepromDEC [lindex [$simulator cget -procData] 32] + } + proc command__load_eram {} { + variable simulator + variable command_line + + load_hex setEramDEC [lindex [$simulator cget -procData] 8] + } + proc command__dump_code {} { + variable simulator + variable command_line + + set capacity [expr {[$simulator cget -P_option_mcu_xcode] + ([lindex [$simulator cget -procData] 2] * 1024)}] + ::IHexTools::free_resources + for {set addr 0} {$addr < $capacity} {incr addr} { + ::IHexTools::content [$simulator getCode $addr] + } + puts -nonewline [::IHexTools::get_hex_data] + } + proc command__dump_idata {} { + variable simulator + variable command_line + + set capacity [lindex [$simulator cget -procData] 3] + ::IHexTools::free_resources + for {set addr 0} {$addr < $capacity} {incr addr} { + ::IHexTools::content [$simulator getData $addr] + } + puts -nonewline [::IHexTools::get_hex_data] + } + proc command__dump_xdata {} { + variable simulator + variable command_line + + set capacity [$simulator cget -P_option_mcu_xdata] + ::IHexTools::free_resources + for {set addr 0} {$addr < $capacity} {incr addr} { + ::IHexTools::content [$simulator getXdata $addr] + } + puts -nonewline [::IHexTools::get_hex_data] + } + proc command__dump_eeprom {} { + variable simulator + variable command_line + + set capacity [lindex [$simulator cget -procData] 32] + ::IHexTools::free_resources + for {set addr 0} {$addr < $capacity} {incr addr} { + ::IHexTools::content [$simulator getEeprom $addr] + } + puts -nonewline [::IHexTools::get_hex_data] + } + proc command__dump_eram {} { + variable simulator + variable command_line + + set capacity [lindex [$simulator cget -procData] 8] + ::IHexTools::free_resources + for {set addr 0} {$addr < $capacity} {incr addr} { + ::IHexTools::content [$simulator getEram $addr] + } + puts -nonewline [::IHexTools::get_hex_data] + } + proc command__write_code {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + set val [lindex $command_line 2] + + if {![$simulator simulator_address_range C $addr]} { + report_error "Invalid address: $addr" + } else { + $simulator setCodeDEC $addr $val + } + } + proc command__write_idata {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + set val [lindex $command_line 2] + + if {![$simulator simulator_address_range I $addr]} { + report_error "Invalid I-DATA address: $addr" + } else { + $simulator setDataDEC $addr $val + } + } + proc command__write_xdata {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + set val [lindex $command_line 2] + + if {![$simulator simulator_address_range X $addr]} { + report_error "Invalid X-DATA address: $addr" + } else { + $simulator setXdataDEC $addr $val + } + } + proc command__write_eeprom {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + set val [lindex $command_line 2] + + if {![$simulator simulator_address_range P $addr]} { + report_error "Invalid EEPROM address: $addr" + } else { + $simulator setEepromDEC $addr $val + } + } + proc command__write_eram {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + set val [lindex $command_line 2] + + if {![$simulator simulator_address_range E $addr]} { + report_error "Invalid ERAM address: $addr" + } else { + $simulator setEramDEC $addr $val + } + } + proc command__write_sfr {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + set val [lindex $command_line 2] + + if {![$simulator simulator_address_range S $addr]} { + report_error "Invalid SFR address: $addr" + } else { + if {$addr == $::Simulator_ENGINE::symbol(SBUFR)} { + set addr $::Simulator_ENGINE::symbol(SBUFT) + } + $simulator setSfrDEC $addr $val + } + } + proc command__write_sfr_by_name {} { + variable simulator + variable command_line + + set name [lindex $command_line 1] + set val [lindex $command_line 2] + + if {[lsearch -ascii -exact [array names ::Simulator_ENGINE::symbol] [string toupper $name]] == -1} { + report_error "Invalid SFR name: $name" + } else { + set addr $::Simulator_ENGINE::symbol([string toupper $name]) + + if {![$simulator simulator_address_range S $addr]} { + report_error "Invalid SFR address: $addr" + } else { + if {$addr == $::Simulator_ENGINE::symbol(SBUFR)} { + set addr $::Simulator_ENGINE::symbol(SBUFT) + } + $simulator setSfrDEC $addr $val + } + } + } + proc command__write_bit {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + set val [lindex $command_line 2] + + if {![$simulator simulator_address_range B $addr]} { + report_error "Invalid BIT address: $addr" + } else { + $simulator setBit $addr + } + } + proc command__read_code {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + + if {![$simulator simulator_address_range C $addr]} { + report_error "Invalid address: $addr" + } else { + puts [$simulator getCodeDEC $addr] + } + } + proc command__read_idata {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + + if {![$simulator simulator_address_range I $addr]} { + report_error "Invalid I-DATA address: $addr" + } else { + puts [$simulator getDataDEC $addr] + } + } + proc command__read_xdata {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + + if {![$simulator simulator_address_range X $addr]} { + report_error "Invalid X-DATA address: $addr" + } else { + puts [$simulator getXdataDEC $addr] + } + } + proc command__read_eeprom {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + + if {![$simulator simulator_address_range P $addr]} { + report_error "Invalid EEPROM address: $addr" + } else { + puts [$simulator getEepromDEC $addr] + } + } + proc command__read_eram {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + + if {![$simulator simulator_address_range E $addr]} { + report_error "Invalid ERAM address: $addr" + } else { + puts [$simulator getEramDEC $addr] + } + } + proc command__read_sfr {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + + if {![$simulator simulator_address_range S $addr]} { + report_error "Invalid SFR address: $addr" + } else { + puts [$simulator getSfrDEC $addr] + } + } + proc command__read_sfr_by_name {} { + variable simulator + variable command_line + + set name [lindex $command_line 1] + set val [lindex $command_line 2] + + if {[lsearch -ascii -exact [array names ::Simulator_ENGINE::symbol] [string toupper $name]] == -1} { + report_error "Invalid SFR name: $name" + } else { + set addr $::Simulator_ENGINE::symbol([string toupper $name]) + + if {![$simulator simulator_address_range S $addr]} { + report_error "Invalid SFR address: $addr" + } else { + puts [$simulator getSfrDEC $addr] + } + } + } + proc command__read_bit {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + + if {![$simulator simulator_address_range B $addr]} { + report_error "Invalid BIT address: $addr" + } else { + puts [$simulator getBit $addr] + } + } + proc command__step {} { + variable simulator + + $simulator clear_changed_registers + $simulator step + } + proc command__step_back {} { + variable simulator + + $simulator clear_changed_registers + puts [$simulator stepback] + } + proc command__list_changes {} { + variable simulator + variable command_line + + puts [$simulator get_changed_registers] + } + proc command__read_pc {} { + variable simulator + + puts [$simulator getPC] + } + proc command__write_pc {} { + variable simulator + variable command_line + + $simulator setPC [lindex $command_line 1] + } + proc command__read_position {} { + variable simulator + variable command_line + + set pos [$simulator simulator_getCurrentLine] + puts "F: \"[$simulator simulator_get_filename [lindex $pos 1]]\"" + puts "L: [lindex $pos 0]" + puts "V: [lindex $pos 2]" + puts "B: [lindex $pos 3]" + } + proc command__run {} { + variable simulator + $simulator sim_run + } + proc command__input {} { + variable simulator + variable command_line + # TODO: Complete it + } + proc command__output {} { + variable simulator + variable command_line + # TODO: Complete it + } + proc command__hibernate {} { + variable simulator + variable command_line + # TODO: Complete it + } + proc command__resume {} { + variable simulator + variable command_line + # TODO: Complete it + } + proc command__core_dump {} { + variable simulator + variable command_line + # TODO: Complete it + } + proc command__core_alter {} { + variable simulator + variable command_line + # TODO: Complete it + } +} + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/engine/engine_virtual_hw_controller.tcl b/lib/simulator/engine/engine_virtual_hw_controller.tcl index a597e27..a13c9b9 100755..100644 --- a/lib/simulator/engine/engine_virtual_hw_controller.tcl +++ b/lib/simulator/engine/engine_virtual_hw_controller.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 _ENGINE_VIRTUAL_HW_CONTROLLER_TCL ] } { +set _ENGINE_VIRTUAL_HW_CONTROLLER_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Part of simulator engine functionality. @@ -39,9 +44,9 @@ private method instruction_cycle {} { stepback_save_spec # Execute instruction - if {$DEBUG} { + if {${::DEBUG}} { $code($pc) - } { + } else { if {[catch { $code($pc) } result]} then { @@ -50,7 +55,10 @@ private method instruction_cycle {} { internal_shutdown incr_pc 1 } - puts stderr $result + # OP code 165d is invalid on 8051 + if {$code($pc) != 165} { + puts stderr ${::errorInfo} + } } } @@ -100,9 +108,9 @@ private method instruction_cycle {} { set rmw_instruction 1 set ports_previous_state [list] for {set i 0; set addr 128} {$i < 5} {incr i; incr addr 16} { - if {$feature_avaliable(p$i)} { + if {$feature_available(p$i)} { lappend ports_previous_state $sfr($addr) - } { + } else { lappend ports_previous_state 0 } } @@ -112,7 +120,7 @@ private method instruction_cycle {} { if {[$this pale_is_enabled]} { if {$controllers_conf(CEN)} { anlcmp_controller - } { + } else { set anlcmp_running 0 $this pale_SLSF $PIN(ANL0) 0 $this pale_SLSF $PIN(ANL1) 0 @@ -120,7 +128,7 @@ private method instruction_cycle {} { } # UART controller - if {$feature_avaliable(uart)} { + if {$feature_available(uart)} { if {($uart_RX_in_progress || $uart_TX_in_progress) && ${::Simulator::reverse_run_steps}} { stepback_reg_change S $symbol(SBUFR) stepback_reg_change S $symbol(SBUFT) @@ -134,9 +142,9 @@ private method instruction_cycle {} { set intx 1 ;# State of pin INTx set ext_int 0 ;# Local external interrupt flag - # Analyze port state + # Anylize port state for {set i -$time} {$i < 0} {incr i} { - # Determinate value of input pin INTx + # Determinate value of input pin INTX set intx [$this pale_RRPPV $PIN(INT${int_src}) $i] # Detect falling edge on INTx @@ -149,7 +157,7 @@ private method instruction_cycle {} { } # Just copy inverted value from INTx to IEx - } { + } else { set ext_int [expr {!$intx}] } } @@ -170,7 +178,7 @@ private method instruction_cycle {} { if {!$pwm_running} { set pwm_running 1 $this pale_SLSF $PIN(T1) 3 - } { + } else { # Make backup for affected SFR if {${::Simulator::reverse_run_steps}} { stepback_reg_change S $symbol(TL0) @@ -181,7 +189,7 @@ private method instruction_cycle {} { # Timer 0 is forced into mode 2 (8-bit autoreload) # TL1 is incremented after each T0 overflow incr sfr($symbol(TL0)) $time - while 1 { + while {1} { if {$sfr($symbol(TL0)) > 255} { set sfr($symbol(TL0)) [expr {$sfr($symbol(TL0)) - 256 + $sfr($symbol(TH0))}] # Increment TL1 @@ -199,11 +207,11 @@ private method instruction_cycle {} { set time_back [expr {256 - $sfr($symbol(TL0))}] if {$time_back >= 0} { $this pale_WPBBL $PIN(T1) 0 - } { + } else { $this pale_WPBBL $PIN(T1) $time_back } } - } { + } else { break } } @@ -241,7 +249,7 @@ private method instruction_cycle {} { $this Simulator_GUI_sync S $symbol(TH0) } # Shutdown timer 0 - } { + } else { set timer_0_running 0 } @@ -263,7 +271,7 @@ private method instruction_cycle {} { } } # Shutdown timer 1 - } { + } else { set timer_1_running 0 } @@ -282,7 +290,7 @@ private method instruction_cycle {} { } # Increment timer 2 - if {$feature_avaliable(t2)} { + if {$feature_available(t2)} { if {$controllers_conf(TR2)} { if {${::Simulator::reverse_run_steps}} { stepback_reg_change S $symbol(TL2) @@ -299,17 +307,21 @@ private method instruction_cycle {} { $this Simulator_GUI_sync S $symbol(RCAP2H) } # Shutdown timer 2 - } { + } else { set timer_2_running 0 } } # Manage interrupt monitor - $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + if {$::GUI_AVAILABLE} { + $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + } # Adjust stopwatch timer incr run_statistics(3) - $this stopwatch_refresh + if {$::GUI_AVAILABLE} { + $this stopwatch_refresh + } # Manage stack for stepback stack stepback_save_norm @@ -343,7 +355,7 @@ private method anlcmp_controller {} { set sample 1 } # Normal mode (sample every S4) - } { + } else { set sample 1 } # Sample port pins ANL0 and ANL1 @@ -418,7 +430,7 @@ private method timer_controller_2 {} { } # Timer 16-bit - } { + } else { set increment $time } @@ -431,11 +443,11 @@ private method timer_controller_2 {} { # 16-bit timer if {$timer_2_running && !$controllers_conf(CT2)} { set increment [expr {$time * 6}] - } { + } else { set increment 0 } if {[increment_timer2 $increment 1]} { - while 1 { + while {1} { set sfr($symbol(TH2)) $sfr($symbol(RCAP2H)) if {![increment_timer2 $sfr($symbol(RCAP2L)) 1]} { break @@ -444,7 +456,6 @@ private method timer_controller_2 {} { } # Detect transition on external input - puts "set controllers_conf(T2) [expr {!$controllers_conf(T2)}]" set controllers_conf(T2) [expr {!$controllers_conf(T2)}] } @@ -466,7 +477,7 @@ private method timer_controller_2 {} { set increment [expr {$increment * 6}] } if {[increment_timer2 $increment 1]} { - while 1 { + while {1} { set sfr($symbol(TH2)) $sfr($symbol(RCAP2H)) if {![increment_timer2 $sfr($symbol(RCAP2L)) 1]} { break @@ -518,7 +529,7 @@ private method timer_controller_2 {} { # Overflow if {$result == 1} { - while 1 { + while {1} { set sfr($symbol(TH2)) $sfr($symbol(RCAP2H)) if {![increment_timer2 $sfr($symbol(RCAP2L)) $updown]} { break @@ -531,7 +542,7 @@ private method timer_controller_2 {} { # Underflow if {!$updown || $result == -1} { - while 1 { + while {1} { set cur_val [expr {$sfr($symbol(TL2)) + ($sfr($symbol(TH2)) << 8)}] set min_val [expr {$sfr($symbol(RCAP2L)) + ($sfr($symbol(RCAP2H)) << 8)}] @@ -559,7 +570,7 @@ private method timer_controller_2 {} { # 16-bit Auto-reload (DCEN == 0) } elseif {$timer_2_running} { if {[increment_timer2 $increment 1]} { - while 1 { + while {1} { set sfr($symbol(TH2)) $sfr($symbol(RCAP2H)) if {![increment_timer2 $sfr($symbol(RCAP2L)) 1]} { break @@ -584,7 +595,7 @@ private method timer_controller_2 {} { private method increment_timer2 {increment_by updown} { if {$updown} { incr sfr($symbol(TL2)) $increment_by - } { + } else { incr sfr($symbol(TL2)) -$increment_by } @@ -637,7 +648,7 @@ private method uart_start_transmission {} { if {$controllers_conf(UART_M) == 0} { $this pale_SLSF $PIN(TXD) 2 $this pale_SLSF $PIN(RXD) 1 - } { + } else { $this pale_SLSF $PIN(TXD) 1 } } @@ -694,18 +705,18 @@ private method uart_controller {num} { if {$controllers_conf(UART_M) == 2} { if {$controllers_conf(SMOD)} { incr uart_RX_clock [expr {$uart_clock_prescaler / 2}] - } { + } else { incr uart_RX_clock [expr {$uart_clock_prescaler / 4}] } - } { + } else { # Timer 2 overflow if {$controllers_conf(RCLK)} { incr uart_RX_clock $timer2_overflow # Timer 1 overflow - } { + } else { if {$controllers_conf(SMOD)} { incr uart_RX_clock $timer1_overflow - } { + } else { incr uart_RX_clock [expr {$uart_clock_prescaler / 2}] } } @@ -741,7 +752,7 @@ private method uart_controller {num} { } # Frame error detection - if {$feature_avaliable(smod0) && !($uart_RX_shift_reg & 1)} { + if {$feature_available(smod0) && !($uart_RX_shift_reg & 1)} { set controllers_conf(FE) 1 if {$sync_ena} { $this Simulator_GUI_sync S $symbol(SCON) @@ -758,7 +769,7 @@ private method uart_controller {num} { setBit $symbol(RB8) [expr {$uart_RX_shift_reg & 2}] set sfr($symbol(SBUFR)) [expr {($uart_RX_shift_reg & 0x3FC) >> 2}] if {$controllers_conf(SM2)} { - if {$feature_avaliable(euart)} { + if {$feature_available(euart)} { # Check for broadcast address if {$sfr($symbol(SBUFR)) == ($sfr($symbol(SADEN)) | $sfr($symbol(SADDR)))} { setBit $symbol(RI) $controllers_conf(RB8) @@ -766,15 +777,15 @@ private method uart_controller {num} { } elseif {($sfr($symbol(SBUFR)) & $sfr($symbol(SADEN))) == ($sfr($symbol(SADDR)) & $sfr($symbol(SADEN)))} { setBit $symbol(RI) $controllers_conf(RB8) } - } { + } else { setBit $symbol(RI) $controllers_conf(RB8) } - } { + } else { setBit $symbol(RI) 1 } # Frame error - if {$feature_avaliable(smod0) && !($uart_RX_shift_reg & 1)} { + if {$feature_available(smod0) && !($uart_RX_shift_reg & 1)} { set controllers_conf(FE) 1 if {$sync_ena} { $this Simulator_GUI_sync S $symbol(SCON) @@ -801,7 +812,7 @@ private method uart_controller {num} { set uart_RX_shift_reg 0x1FE } # Mode 1, 2, 3 - Start bit starts reception - } { + } else { if {![$this pale_RRPPV $PIN(RXD)]} { set uart_RX_clock 0 set uart_RX_in_progress 1 @@ -845,7 +856,7 @@ private method uart_controller {num} { incr i $this pale_WPBBL $PIN(RXD) $bit_to_send $i $this pale_WPBBL $PIN(TXD) 1 $i - } { + } else { incr i $this pale_WPBBL $PIN(TXD) {|} [expr {int($i / 2)}] $this pale_WPBBL $PIN(RXD) $bit_to_send [expr {int($i / 2)}] @@ -874,18 +885,18 @@ private method uart_controller {num} { if {$controllers_conf(UART_M) == 2} { if {$controllers_conf(SMOD)} { incr uart_TX_clock [expr {$uart_clock_prescaler / 2}] - } { + } else { incr uart_TX_clock [expr {$uart_clock_prescaler / 4}] } - } { + } else { # Timer 2 overflow if {$controllers_conf(TCLK)} { incr uart_TX_clock $timer2_overflow # Timer 1 overflow - } { + } else { if {$controllers_conf(SMOD)} { incr uart_TX_clock $timer1_overflow - } { + } else { incr uart_TX_clock [expr {$uart_clock_prescaler / 2}] } } @@ -920,7 +931,7 @@ private method uart_controller {num} { if {$uart_clock_prescaler && $controllers_conf(UART_M)} { if {$controllers_conf(SMOD)} { set uart_clock_prescaler [expr {$uart_clock_prescaler % 2}] - } { + } else { set uart_clock_prescaler [expr {$uart_clock_prescaler % 4}] } } @@ -960,11 +971,11 @@ private method special_timer1_controller_T0_MOD_3 {} { } 2 { ;# Mode 2 - 8 bit auto-reload counter incr sfr($TL1) $time - while 1 { + while {1} { if {$sfr($TL1) > 255} { set sfr($TL1) [expr {$sfr($TL1) - 256 + $sfr($TH1)}] incr timer1_overflow - } { + } else { break } } @@ -988,7 +999,7 @@ private method timer_controller_01 {timer_num} { set timer_1_running 1 return } - } { + } else { if {!$timer_0_running} { set timer_0_running 1 return @@ -1014,7 +1025,7 @@ private method timer_controller_01 {timer_num} { set increment 0 } } - } { + } else { set increment $time # Trigered timer @@ -1036,7 +1047,7 @@ private method timer_controller_01 {timer_num} { setBit $symbol(TF1) 1 } # Increment TL0 - } { + } else { incr sfr($symbol(TL0)) $increment if {$sfr($symbol(TL0)) > 255} { set sfr($symbol(TL0)) [expr {$sfr($symbol(TL0)) - 256}] @@ -1088,14 +1099,14 @@ private method timer_controller_01 {timer_num} { } 2 { ;# Mode 2 - 8 bit auto-reload counter incr sfr($TL_addr) $increment - while 1 { + while {1} { if {$sfr($TL_addr) > 255} { set sfr($TL_addr) [expr {$sfr($TL_addr) - 256 + $sfr($TH_addr)}] setBit $symbol(TF${timer_num}) 1 if {$timer_num} { incr timer1_overflow } - } { + } else { break } } @@ -1118,7 +1129,7 @@ private method eeprom_controller {num} { internal_shutdown } - # Fill incomplite bytes with random values + # Fill incomplete bytes with random values set eeprom_prev_new [list] foreach reg $eeprom_prev { lappend eeprom_prev_new [lindex $reg 0] [undefined_octet] @@ -1177,7 +1188,7 @@ private method watchdog_controller {} { } if {$controllers_conf(WDTEN)} { set sfr(167) [expr {$sfr(167) | 1}] - } { + } else { set sfr(167) [expr {$sfr(167) - 1}] } if {$sync_ena} { @@ -1194,15 +1205,15 @@ private method watchdog_controller {} { set increment 0 if {$controllers_conf(WatchDogPrescaler)} { incr wdt_prescaler_val $time - while 1 { + while {1} { if {$wdt_prescaler_val >= $controllers_conf(WatchDogPrescaler)} { incr wdt_prescaler_val -$controllers_conf(WatchDogPrescaler) incr increment - } { + } else { break } } - } { + } else { set increment $time } @@ -1285,7 +1296,9 @@ private method interrupt_handler {IntName vector flag_bit immediately} { lappend inter_in_p_flags $flag_bit ;# List: Interrupt flags of interrupts which are in progress # Adjust status bar - simulator_Sbar [mc "Interrupt PC: 0x%s; line: %s; vector 0x%s " [format %X $pc] [lindex $Line($pc) 0] [format %X $vector]] 1 $this + if {$::GUI_AVAILABLE} { + simulator_Sbar [mc "Interrupt PC: 0x%s; line: %s; vector 0x%s " [format %X $pc] [lindex $Line($pc) 0] [format %X $vector]] 1 $this + } $this pale_interrupt $vector # Invoke LCALL to interrupt vector @@ -1378,14 +1391,14 @@ private method isInterruptActive {IntName} { } {PS} { ;# UART & SPI if {!$controllers_conf(ES)} {return 0} - if {$feature_avaliable(uart)} { + if {$feature_available(uart)} { if {$controllers_conf(TI)} { return {35 TI} } elseif {$controllers_conf(RI)} { return {35 RI} } } - if {$feature_avaliable(spi) && $controllers_conf(SPIE) && $controllers_conf(SPIF)} { + if {$feature_available(spi) && $controllers_conf(SPIE) && $controllers_conf(SPIF)} { return {35 SPIE} } } @@ -1411,3 +1424,7 @@ private method isInterruptActive {IntName} { } return 0 } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/hibernate.tcl b/lib/simulator/hibernate.tcl index c35f4f8..0cd090e 100755..100644 --- a/lib/simulator/hibernate.tcl +++ b/lib/simulator/hibernate.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 _HIBERNATE_TCL ] } { +set _HIBERNATE_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Provides program hibernation capability. It ohter words it can save @@ -59,16 +64,21 @@ class Hibernate { common mcu_variable ;# Bool: Checkbox variable for "Different processor" common xdata_variable ;# Int: RadioButton variable for "Different XDATA size" common md5_variable ;# Bool: Checkbox variable for "Different MD5 hash" - # Big font for dialog "Program resumption" - common big_font [font create \ - -family {helvetica} \ - -weight bold -size -35 \ - ] - # Normal font for dialog "Program resumption" - common text_font [font create \ - -family {helvetica} \ - -weight bold -size -14 \ - ] + + if {$::GUI_AVAILABLE} { + # Big font for dialog "Program resumption" + common big_font [font create \ + -family {helvetica} \ + -weight bold \ + -size [expr {int(-35 * $::font_size_factor)}] \ + ] + # Normal font for dialog "Program resumption" + common text_font [font create \ + -family {helvetica} \ + -weight bold \ + -size [expr {int(-14 * $::font_size_factor)}] \ + ] + } ## PRIVATE private variable parser ;# Object: Reference to active XML parser @@ -102,7 +112,7 @@ class Hibernate { } if {$for_what == {data}} { $mem_prg_bar configure -maximum $value - } { + } else { $stb_prg_bar configure -maximum $value } } @@ -128,15 +138,16 @@ class Hibernate { } # Create dialog window - set win [toplevel .hibernation_progress_dialog -class {Progress dialog} -bg {#EEEEEE}] + set win [toplevel .hibernation_progress_dialog -class {Progress dialog} -bg ${::COMMON_BG_COLOR}] # Create dialog header - pack [label $win.header \ - -text $header \ - -font [font create \ - -size -17 -weight {bold} \ - -family {helvetica} \ - ] \ + pack [label $win.header \ + -text $header \ + -font [font create \ + -size [expr {int(-17 * $::font_size_factor)}] \ + -weight {bold} \ + -family {helvetica} \ + ] \ ] -fill x # Create progress bar "Memory" @@ -167,7 +178,7 @@ class Hibernate { -compound left \ -image ::ICONS::16::button_cancel \ -command {set ::Hibernate::hib_abort 1} \ - ] -padx 10 -fill x + ] -pady 5 # Configure dialog window wm iconphoto $win ::ICONS::16::bar5 @@ -191,15 +202,15 @@ class Hibernate { public method hibernate_hibernate {filename sourcefile md5 exclude_stepback} { # Try to open the destination file if {[catch { - set file [open $filename w 420] - }]} { + set file [open $filename w 0640] + }]} then { return 0 } # Determinate depth of stepback stack and size of XDATA memory if {$exclude_stepback} { set stacklength 0 - } { + } else { set stacklength [$this simulator_get_SBS_len] } set xdata_size [$this cget -P_option_mcu_xdata] @@ -217,18 +228,18 @@ class Hibernate { puts -nonewline $file "\tThis is MCU 8051 IDE hibernation data file.\n" puts -nonewline $file "\tIt does not contain program code, only data.\n\n" puts -nonewline $file "\tPLEASE DO NOT EDIT THIS FILE MANUALY, BECAUSE\n" - puts -nonewline $file "\tBAD FORMATING OF THIS FILE WILL LEAD MCU 8051 IDE TO CRASH !\n" + puts -nonewline $file "\tBAD FORMATTING OF THIS FILE WILL LEAD MCU 8051 IDE TO CRASH !\n" puts -nonewline $file "-->\n" # Write DTD (Document Type Declaration) to the destination file - if {[file exists "${::LIB_DIRNAME}/../data/m5ihib.dtd"]} { + if {[file exists "${::ROOT_DIRNAME}/data/m5ihib.dtd"]} { if {[catch { - set dtd [open "${::LIB_DIRNAME}/../data/m5ihib.dtd" r] - }]} { + set dtd [open "${::ROOT_DIRNAME}/data/m5ihib.dtd" r] + }]} then { puts stderr "Unable to open m5ihib.dtd, please check your installation." } else { puts -nonewline $file "<!DOCTYPE m5ihib \[\n\n" - while 1 { + while {1} { if {[eof $dtd]} { close $dtd break @@ -333,7 +344,7 @@ class Hibernate { # Special function registers puts -nonewline $file "\t\t<sfr>\n" puts -nonewline $file "\t\t\t<addresses>\n\t\t\t\t" - set sfr [$this simulator_get_avaliable_sfr] + set sfr [$this simulator_get_available_sfr] set j 0 foreach addr $sfr { if {$j > 6} { @@ -366,7 +377,7 @@ class Hibernate { ## Write content of list of active interrupts puts -nonewline $file "\t<subprograms count=\"[$this subprograms_get_count]\">\n" - foreach sub [$this subprograms_get_formated_content] { + foreach sub [$this subprograms_get_formatted_content] { set source [lindex $sub 0] set target [lindex $sub 1] set type [lindex $sub 2] @@ -414,7 +425,7 @@ class Hibernate { hibernate_close_progress_dialog if {[catch {close $file}]} { return 0 - } { + } else { return 1 } } @@ -442,12 +453,12 @@ class Hibernate { # Open hibernation data file if {[catch { set file [open $filename {r}] - }]} { + }]} then { return 1 } # Show progress dialog - show_progress_dialog {Resuming hibernated program} 1 1 + show_progress_dialog [mc "Resuming hibernated program"] 1 1 # Create XML parser object if {[catch { @@ -455,12 +466,12 @@ class Hibernate { -elementstartcommand [list $this hibernate_xml_parser_element] \ -characterdatacommand [list $this hibernate_xml_parser_data] \ ] - }]} { + }]} then { hibernate_close_progress_dialog tk_messageBox \ -type ok -icon error -parent . \ -title "::xml::parser error" \ - -message "Unknown error occured in XML parser library,\nplease try to reinstall package \"tdom\"." + -message "Unknown error occurred in XML parser library,\nplease try to reinstall package \"tdom\"." return 2 } @@ -485,7 +496,7 @@ class Hibernate { # Close the file and free the parser if {[catch { close $file - }]} { + }]} then { set exit_code 1 } catch { @@ -500,13 +511,13 @@ class Hibernate { set interrupts_in_progress [$this simulator_get_interrupts_in_progress_pb] if {[llength $interrupts_in_progress]} { simulator_Sbar [mc "Interrupt at vector 0x%s " [format %X [$this intr2vector [lindex $interrupts_in_progress end]]]] 1 $this - } { + } else { simulator_Sbar {} 0 $this } set lineNum [$this simulator_getCurrentLine] if {$lineNum != {}} { $this move_simulator_line $lineNum - } { + } else { $this editor_procedure {} unset_simulator_line {} } ::X::stepback_button_set_ena [$this simulator_get_SBS_len] @@ -663,7 +674,7 @@ class Hibernate { } if {$source != {} && $target != {} && $type != {}} { $this subprograms_call $type $source $target - } { + } else { error "Invalid argument set in tag <step>" } } @@ -680,7 +691,7 @@ class Hibernate { $this simulator_set_SBS_len $stacklength progress_dialog_set_max stepback [expr {$stacklength / 10}] break - } { + } else { incr i } } @@ -861,7 +872,7 @@ class Hibernate { set xdata_variable 1 set md5_variable 1 - set win [toplevel .hibernation_bad_file_dialog -class {Error dialog} -bg {#EEEEEE}] + set win [toplevel .hibernation_bad_file_dialog -class {Error dialog} -bg ${::COMMON_BG_COLOR}] set dlg_result 1 set dlg_bits $differences @@ -931,13 +942,13 @@ class Hibernate { -compound left \ -image ::ICONS::16::ok \ ] - pack $dlg_ok_but -side left + pack $dlg_ok_but -side left -padx 2 pack [ttk::button $button_frame.button_cancel \ -text [mc "Cancel"] \ -command "$this hibernation_cls_dlg 1" \ -compound left \ -image ::ICONS::16::button_cancel \ - ] -side left + ] -side left -padx 2 pack $button_frame -side bottom -anchor e -padx 10 -pady 5 # Configure dialog window @@ -980,7 +991,7 @@ class Hibernate { # Create text widget for the given message set text_wdg [text $right_frame.top_text \ -width 0 -height 3 -wrap word -bd 0 \ - -relief flat -bg {#EEEEEE} \ + -relief flat -bg ${::COMMON_BG_COLOR} \ -font $text_font -cursor left_ptr \ ] $text_wdg insert end $text @@ -1004,7 +1015,7 @@ class Hibernate { public method hibernation_chbut_rabut_command {} { if {$file_variable && $mcu_variable && $xdata_variable && $md5_variable} { $dlg_ok_but configure -state normal - } { + } else { $dlg_ok_but configure -state disabled } } @@ -1027,7 +1038,7 @@ class Hibernate { $this configure -P_option_mcu_xdata $xdata_size ::X::close_hexedit xdata $this $this simulator_resize_xdata_memory $xdata_size - } { + } else { set xdata_size 0 } @@ -1049,3 +1060,7 @@ class Hibernate { } } } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/interruptmonitor.tcl b/lib/simulator/interruptmonitor.tcl index 5156382..510b070 100755..100644 --- a/lib/simulator/interruptmonitor.tcl +++ b/lib/simulator/interruptmonitor.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 _INTERRUPTMONITOR_TCL ] } { +set _INTERRUPTMONITOR_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Implements interrupt monitor @@ -29,33 +34,37 @@ class InterruptMonitor { ## COMMON common geometry ${::CONFIG(INTR_MON_GEOMETRY)} ;# Last window geometry - common count 0 ;# Counter of intances + common intr_mon_count 0 ;# Counter of intances common bg_color {#0088FF} ;# Color for highlighted background # Small header font - common header_font [font create \ - -size -17 -weight bold \ - -family {helvetica} \ + common header_font [font create \ + -size [expr {int(-17 * $::font_size_factor)}] \ + -weight bold \ + -family {helvetica} \ ] # Big header font - common header_font_big [font create \ - -size -21 -weight bold \ - -family {helvetica} \ + common header_font_big [font create \ + -size [expr {int(-21 * $::font_size_factor)}] \ + -weight bold \ + -family {helvetica} \ ] # Common label font - common lbl_font [font create \ - -size -12 \ - -family {helvetica} \ + common lbl_font [font create \ + -size [expr {int(-12 * $::font_size_factor)}] \ + -family {helvetica} \ ] # Font for value labels - common val_font [font create \ - -size -12 -weight bold \ - -family {helvetica} \ + common val_font [font create \ + -size [expr {int(-12 * $::font_size_factor)}] \ + -weight bold \ + -family {helvetica} \ ] # Font for value labels - underline - common val_font_under [font create \ - -size -12 -weight bold \ - -family {helvetica} \ - -underline 1 \ + common val_font_under [font create \ + -size [expr {int(-12 * $::font_size_factor)}] \ + -weight bold \ + -family {helvetica} \ + -underline 1 \ ] @@ -74,7 +83,7 @@ class InterruptMonitor { private variable in_progress_flg {} ;# List: Flags of interrupts which are in progress private variable intr_priorities {} ;# List: Interrupt flags in order of their priorities (decremental) private variable pending_flg {} ;# List: Flags of pending interrupts - private variable avaliable_interrs {} ;# List: Avaliable interrupt flags + private variable available_interrs {} ;# List: available interrupt flags private variable maximum_priority 0 ;# Int: Maximum valid priority @@ -106,7 +115,7 @@ class InterruptMonitor { set in_progress_flg {} set pending_flg {} set intr_priorities {} - set avaliable_interrs {} + set available_interrs {} if {[winfo exists $win]} { destroy $win @@ -120,22 +129,22 @@ class InterruptMonitor { set dialog_opened 1 # Create dialog window, main frame and status bar - set win [toplevel .interrupt_monitor$count -class {Interrupt monitor} -bg {#EEEEEE}] - incr count + set win [toplevel .interrupt_monitor${intr_mon_count} -class {Interrupt monitor} -bg ${::COMMON_BG_COLOR}] + incr intr_mon_count set main_frame [frame $win.main_frame] set status_bar [label $win.status_bar] # Create scrollable frames set in_progress_frame_f [ScrollableFrame $main_frame.in_p \ - -width 300 -areawidth 300 \ + -width 280 -areawidth 280 \ -yscrollcommand "$main_frame.in_p_scrl set" \ ] set pending_frame_f [ScrollableFrame $main_frame.pending \ - -width 230 -areawidth 230 \ + -width 250 -areawidth 250 \ -yscrollcommand "$main_frame.pend_scrl set" \ ] set priorities_frame_f [ScrollableFrame $main_frame.prior \ - -width 230 -areawidth 230 \ + -width 250 -areawidth 250 \ -yscrollcommand "$main_frame.prior_scrl set" \ ] @@ -144,11 +153,11 @@ class InterruptMonitor { set top_frame_1 [frame $main_frame.top_frame_1] set top_frame_2 [frame $main_frame.top_frame_2] foreach num {0 1 2} text { - {Interrupts in progress} - {Pending interrupts} - {Interrupt priorities} + "Interrupts in progress" + "Pending interrupts" + "Interrupt priorities" } { - set frame [subst "\$top_frame_${num}"] + set frame [subst -nocommands "\$top_frame_${num}"] pack [ttk::button $frame.expand \ -image ::ICONS::16::add \ -style Flat.TButton \ @@ -163,7 +172,7 @@ class InterruptMonitor { set_status_tip $frame.collapse [mc "Collapse all"] pack [label $frame.in_p_lbl \ -font $header_font \ - -text $text \ + -text [mc $text] \ ] -side left -fill x -expand 1 } @@ -203,7 +212,7 @@ class InterruptMonitor { # Fill GUI set maximum_priority [$this simulator_get_max_intr_priority] - interrupt_monitor_set_avaliable [$this simulator_get_intr_flags] + interrupt_monitor_set_available [$this simulator_get_intr_flags] interrupt_monitor_reevaluate # Pack main frame and create bottom frame @@ -217,17 +226,18 @@ class InterruptMonitor { -command "$this interrupt_monitor_close" \ -image ::ICONS::16::button_cancel \ ] -side right -pady 5 -padx 10 - set_status_tip $win.close_but {Close this dialog window} + set_status_tip $win.close_but [mc "Close this dialog window"] # Set window attributes wm iconphoto $win ::ICONS::16::kcmdf - wm title $win "[mc {Interrupt monitor}] - [string trim $this {:}] - MCU 8051 IDE" - wm minsize $win 840 270 + wm title $win "[mc {Interrupt monitor}] - [$this cget -projectName] - MCU 8051 IDE" + wm minsize $win 850 270 if {$geometry != {}} { + regsub {\+\d+\+} $geometry {+850+} geometry wm geometry $win $geometry } wm resizable $win 0 1 - wm protocol $win WM_DELETE_WINDOW "$this interrupt_monitor_close" + wm protocol $win WM_DELETE_WINDOW [list $this interrupt_monitor_close] bindtags $win [list $win Toplevel all .] } @@ -256,7 +266,7 @@ class InterruptMonitor { # Enable/Disabled buttons "Invoke this interrupt" set state [expr {([$this is_frozen]) ? "normal" : "disabled"}] - foreach flag $avaliable_interrs { + foreach flag $available_interrs { $priorities_frame.[string tolower $flag].secondary.exec_but configure -state $state } @@ -291,8 +301,8 @@ class InterruptMonitor { set in_progress_wdg {} set in_progress_flg {} set pending_flg {} - set intr_priorities $avaliable_interrs - foreach flag $avaliable_interrs { + set intr_priorities $available_interrs + foreach flag $available_interrs { set flag [string tolower $flag] $priorities_frame.$flag.secondary.exec_but configure -state normal } @@ -342,18 +352,18 @@ class InterruptMonitor { public method interrupt_monitor_collapse_expand {widget} { if {[winfo ismapped $widget]} { pack forget $widget - } { + } else { pack $widget -fill both -padx 2 -pady 2 } update } - ## Set avaliable interrupt flags + ## Set available interrupt flags # @parm List flags - Interrupt flags (e.g. {TF2 CF RI IE0}) # @return void - private method interrupt_monitor_set_avaliable {flags} { - # Set avaliable interrupts - set avaliable_interrs $flags + private method interrupt_monitor_set_available {flags} { + # Set available interrupts + set available_interrs $flags # Create sub windows in frame "Priorities" foreach flag_bit $flags { @@ -374,7 +384,7 @@ class InterruptMonitor { pack [label $secondary_frame.name \ -text [lindex $intr 3] -pady 0 \ -bg $bg_color -fg white \ - -cursor hand1 -anchor w \ + -cursor hand2 -anchor w \ ] -side left -anchor w -fill x -expand 1 bind $secondary_frame.name <Button-1> \ "$this interrupt_monitor_collapse_expand $primary_frame.tertiary" @@ -405,7 +415,7 @@ class InterruptMonitor { set row 2 set col 0 set pri_bits [lindex $intr 2] - if {[$this get_feature_avaliable iph]} { + if {[$this get_feature_available iph]} { set pri_bits [linsert $pri_bits 0 "[lindex $intr 2]H"] } foreach lbl { @@ -441,7 +451,7 @@ class InterruptMonitor { e_bit - p_bit - f_bit { - set cursor {hand1} + set cursor {hand2} set is_bit 1 } } @@ -514,11 +524,11 @@ class InterruptMonitor { } # Adjust value of priority level in each subwindow - foreach flag_bit $avaliable_interrs { + foreach flag_bit $available_interrs { set pri__clr [get_priority_and_color $flag_bit] set pri_bits [lindex [get_interrupt_details $flag_bit] 2] set flag_bit [string tolower $flag_bit] - if {[$this get_feature_avaliable iph]} { + if {[$this get_feature_available iph]} { lappend pri_bits "${pri_bits}H" } @@ -529,14 +539,14 @@ class InterruptMonitor { if {[lindex $pri__clr 0] == $maximum_priority} { $priorities_frame.$flag_bit.secondary.up_but \ configure -state disabled - } { + } else { $priorities_frame.$flag_bit.secondary.up_but \ configure -state normal } if {[lindex $pri__clr 0]} { $priorities_frame.$flag_bit.secondary.down_but \ configure -state normal - } { + } else { $priorities_frame.$flag_bit.secondary.down_but \ configure -state disabled } @@ -556,7 +566,7 @@ class InterruptMonitor { # Determinate new color if {[intr_mon_getBit $pri_bit]} { set color $::Simulator_GUI::on_color - } { + } else { set color $::Simulator_GUI::off_color } @@ -610,7 +620,7 @@ class InterruptMonitor { foreach flag $new_flag { if {[winfo exists $pending_frame.[string tolower $flag]]} { pack forget $pending_frame.[string tolower $flag] - } { + } else { create_pending_interrupt $flag } } @@ -626,11 +636,11 @@ class InterruptMonitor { } # Adjust colors of flag bits - foreach flag_bit $avaliable_interrs { + foreach flag_bit $available_interrs { # Determinate new color if {[intr_mon_getBit $flag_bit]} { set color $::Simulator_GUI::on_color - } { + } else { set color $::Simulator_GUI::off_color } set flag [string tolower $flag_bit] @@ -654,13 +664,13 @@ class InterruptMonitor { if {!$dialog_opened} {return} # Adjust colors of flag bits - foreach flag_bit $avaliable_interrs { + foreach flag_bit $available_interrs { set ena_bit [lindex [get_interrupt_details $flag_bit] 1] # Determinate new color if {[intr_mon_getBit $ena_bit]} { set color $::Simulator_GUI::on_color - } { + } else { set color $::Simulator_GUI::off_color } @@ -709,7 +719,7 @@ class InterruptMonitor { pack [label $secondary_frame.name \ -text [lindex $intr 3] -pady 0 \ -bg $bg_color -fg white \ - -cursor hand1 -anchor w \ + -cursor hand2 -anchor w \ ] -side left -anchor w -fill x -padx 3 -expand 1 bind $secondary_frame.name <Button-1> \ "$this interrupt_monitor_collapse_expand $primary_frame.tertiary" @@ -725,7 +735,7 @@ class InterruptMonitor { set tertiary_frame [frame $primary_frame.tertiary -bg {#FFFFFF}] # Priority: grid [label $tertiary_frame.priority_lbl \ - -pady 0 -text "Priority:" \ + -pady 0 -text [mc "Priority:"] \ -bg white -font $lbl_font \ ] -sticky w -pady 0 -row 0 -column 0 set pri__clr [get_priority_and_color $flag_bit] @@ -742,7 +752,7 @@ class InterruptMonitor { set row 2 set col 0 set pri_bits [lindex $intr 2] - if {[$this get_feature_avaliable iph]} { + if {[$this get_feature_available iph]} { set pri_bits [linsert $pri_bits 0 "[lindex $intr 2]H"] } foreach lbl { @@ -778,7 +788,7 @@ class InterruptMonitor { e_bit - p_bit - f_bit { - set cursor {hand1} + set cursor {hand2} set is_bit 1 } } @@ -864,7 +874,7 @@ class InterruptMonitor { pack [label $secondary_frame.name \ -text [lindex $intr 3] -pady 0 \ -bg $bg_color -fg white \ - -cursor hand1 -anchor w \ + -cursor hand2 -anchor w \ ] -side left -anchor w -fill x -padx 3 -expand 1 bind $secondary_frame.name <Button-1> \ "$this interrupt_monitor_collapse_expand $primary_frame.tertiary" @@ -880,7 +890,7 @@ class InterruptMonitor { set tertiary_frame [frame $primary_frame.tertiary -bg {#FFFFFF}] # Priority grid [label $tertiary_frame.priority_lbl \ - -pady 0 -text "Priority:" \ + -pady 0 -text [mc "Priority:"] \ -bg white -font $lbl_font \ ] -sticky w -pady 0 -row 0 -column 0 set pri__clr [get_priority_and_color $flag_bit] @@ -897,7 +907,7 @@ class InterruptMonitor { # Vector, Flag bit, Enable bit, Priority bits set row 2 set pri_bits [lindex $intr 2] - if {[$this get_feature_avaliable iph]} { + if {[$this get_feature_available iph]} { set pri_bits [linsert $pri_bits 0 "[lindex $intr 2]H"] } foreach lbl { @@ -932,7 +942,7 @@ class InterruptMonitor { e_bit - p_bit - f_bit { - set cursor {hand1} + set cursor {hand2} set is_bit 1 } } @@ -977,13 +987,13 @@ class InterruptMonitor { # Invoked from: set row 2 grid [label $tertiary_frame.lbl__$row \ - -text {Invoked from:} -pady 0 \ + -text [mc "Invoked from:"] -pady 0 \ -bg white -font $lbl_font \ ] -sticky w -row $row -column 3 -pady 0 -columnspan 2 incr row # PC: grid [label $tertiary_frame.lbl__$row \ - -pady 0 -text { PC:} \ + -pady 0 -text [mc " PC:"] \ -bg white -font $lbl_font \ ] -sticky w -row $row -column 3 -pady 0 grid [label $tertiary_frame.val__$row \ @@ -993,13 +1003,13 @@ class InterruptMonitor { incr row # File: grid [label $tertiary_frame.lbl__$row \ - -pady 0 -text [mc { File:}] \ + -pady 0 -text [mc " File:"] \ -bg white -font $lbl_font \ ] -sticky w -row $row -column 3 -pady 0 set filename [$this filelist_get_simulator_editor_obj] if {$filename != {}} { set filename [$filename cget -fullFileName] - } { + } else { set filename [lindex [$this simulator_get_list_of_filenames] 0] } grid [label $tertiary_frame.val__$row \ @@ -1009,7 +1019,7 @@ class InterruptMonitor { incr row # Line: grid [label $tertiary_frame.lbl__$row \ - -pady 0 -text [mc { Line:}] \ + -pady 0 -text [mc " Line:"] \ -bg white -font $lbl_font \ ] -sticky w -row $row -column 3 -pady 0 grid [label $tertiary_frame.val__$row \ @@ -1024,7 +1034,7 @@ class InterruptMonitor { set wdg [lindex $in_progress_wdg end] if {$wdg != {}} { pack $primary_frame -fill x -before $wdg -pady 2 - } { + } else { pack $primary_frame -fill x -pady 2 } @@ -1244,3 +1254,7 @@ class InterruptMonitor { } } } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/sfrmap.tcl b/lib/simulator/sfrmap.tcl index d6d16d2..65e5806 100755..100644 --- a/lib/simulator/sfrmap.tcl +++ b/lib/simulator/sfrmap.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 _SFRMAP_TCL ] } { +set _SFRMAP_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION -# Implements window showing the map of avaliable special function register +# Implements window showing the map of available special function register # -------------------------------------------------------------------------- class SFRMap { ## COMMON - common count 0 ;# Int: Counter of object instances + common sfrmap_count 0 ;# Int: Counter of object instances ## PRIVATE private variable dialog_opened 0 ;# Bool: Dialog window opened @@ -46,7 +51,7 @@ class SFRMap { private variable selected_entry -1 ;# Int: Address of selected entry box in the map constructor {} { - incr count + incr sfrmap_count } destructor { @@ -63,14 +68,14 @@ class SFRMap { # Create dialog window set enabled [$this is_frozen] - set win [toplevel .sfr_map$count -bg {#FFFFFF} -class {SFR map} -bg {#EEEEEE}] + set win [toplevel .sfr_map${sfrmap_count} -bg {#FFFFFF} -class {SFR map} -bg ${::COMMON_BG_COLOR}] # Create other widgets create_win_gui # Configure the window wm iconphoto $win ::ICONS::16::kcmmemory_S - wm title $win "Map of SFR area - [string trim $this {:}] - MCU 8051 IDE" + wm title $win "[mc {Map of SFR area}] - [$this cget -P_option_mcu_type] - [$this cget -projectName] - MCU 8051 IDE" wm resizable $win 0 0 wm protocol $win WM_DELETE_WINDOW "$this sfrmap_close_dialog" bindtags $win [list $win Toplevel all .] @@ -146,34 +151,29 @@ class SFRMap { set name [lindex $reg 1] set row 0 - lappend defined_sfr $addr - - switch -- $name { - {SBUFR} { - set name_d {SBUF R} - } - {SBUFT} { - set name_d {SBUF T} - } - default { - set name_d $name - } + if {$addr > 255} { + continue } - - set n_addr [expr {$addr & 0x0FF}] - if {$addr > 0xFF} { - set row 1 + if {$name == {SBUFR} || $name == {SBUFT}} { + set name {SBUF} } if {!($addr % 8)} { set fg {#00DDDD} - } { + } else { set fg {#0000DD} } - $main_frame.cell_$n_addr configure -bg {#FFFFFF} - grid [label $main_frame.lbl_${addr} \ - -text $name_d -bg {#FFFFFF} -fg $fg \ - ] -in $main_frame.cell_$n_addr -sticky nsw -row $row -column 0 + $main_frame.cell_$addr configure -bg {#FFFFFF} + pack [label $main_frame.lbl_${addr} \ + -text $name -bg {#FFFFFF} -fg $fg \ + ] -in $main_frame.cell_$addr -side left + + grid columnconfigure $main_frame.cell_$addr 0 -weight 1 + if {$name == {SBUF}} { + continue + } + lappend defined_sfr $addr + set entry [ttk::entry $main_frame.ent_${addr} \ -validatecommand "$this sfrmap_validate $addr h %P m" \ -style Simulator_WhiteBg.TEntry \ @@ -182,30 +182,11 @@ class SFRMap { -width 3 \ -font ${::Simulator_GUI::entry_font} \ ] - grid $entry -in $main_frame.cell_$n_addr -padx 1 -pady 1 -row $row -column 1 -sticky nse + pack $entry -in $main_frame.cell_$addr -side right $entry insert end [$this getSfr $addr] if {!$enabled} { $entry configure -state disabled } - if {$row} { - foreach widget [list \ - $main_frame.lbl_${addr} $main_frame.lbl_${n_addr} \ - $main_frame.ent_${addr} $main_frame.ent_${n_addr} \ - ] { - catch {$widget configure -highlightthickness 0} - catch {$widget configure -pady 0} - catch {$widget configure -bd 0} - - $widget configure -font [font create -family $::DEFAULT_FIXED_FONT -size -3] - grid configure $widget -pady 0 -ipady 0 - } - foreach widget [list $main_frame.lbl_${addr} $main_frame.lbl_${n_addr}] { - $widget configure -pady 0 - } - grid rowconfigure $main_frame.cell_$n_addr 0 -pad 0 - grid rowconfigure $main_frame.cell_$n_addr 1 -pad 0 - } - grid columnconfigure $main_frame.cell_$n_addr 0 -weight 1 bindtags $entry [list $entry TEntry $win all .] bind $entry <Motion> {help_window_show %X %Y+30} @@ -500,13 +481,13 @@ class SFRMap { set enabled $bool if {$bool} { set bool {normal} - } { + } else { set bool {disabled} } foreach entry [list $det_hex $det_oct $det_bin $det_dec] { $entry configure -state $bool } - foreach addr [$this simulator_get_avaliable_sfr] { + foreach addr $defined_sfr { $main_frame.ent_${addr} configure -state $bool } } @@ -521,3 +502,7 @@ class SFRMap { } } } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/simulator.tcl b/lib/simulator/simulator.tcl index 06ce985..8804022 100755..100644 --- a/lib/simulator/simulator.tcl +++ b/lib/simulator/simulator.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 _SIMULATOR_TCL ] } { +set _SIMULATOR_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Implements 8051 Simulator environment. @@ -38,14 +43,14 @@ source "${::LIB_DIRNAME}/simulator/engine/engine_core.tcl" ;# Simulator engine source "${::LIB_DIRNAME}/simulator/simulator_gui.tcl" ;# Simulator panel source "${::LIB_DIRNAME}/simulator/interruptmonitor.tcl" ;# Interrupt monitor -source "${::LIB_DIRNAME}/simulator/virtual_uart_term.tcl" ;# Virtual UART Terminal +source "${::LIB_DIRNAME}/simulator/uart_monitor.tcl" ;# UART monitor source "${::LIB_DIRNAME}/simulator/sfrmap.tcl" ;# SFR Map monitor source "${::LIB_DIRNAME}/simulator/stopwatch.tcl" ;# Stopwatch source "${::LIB_DIRNAME}/simulator/bitmap.tcl" ;# Map of bit addressable area source "${::LIB_DIRNAME}/simulator/stackmonitor.tcl" ;# Stack monitor class Simulator { - inherit Simulator_GUI Simulator_ENGINE InterruptMonitor SFRMap Stopwatch BitMap StackMonitor VirtualUartTerminal + inherit Simulator_GUI Simulator_ENGINE InterruptMonitor SFRMap Stopwatch BitMap StackMonitor UARTMonitor ## COMMON common highlight_color {#DD8800} ;# Foreground color for changed registers @@ -68,6 +73,7 @@ class Simulator { common ignore_invalid_USB 0 ;# Bool: Ignore "UART: Frame discarded" common ignore_invalid_UMC 0 ;# Bool: Ignore "UART mode has been changed while UART was engaged" common ignore_invalid_TMC 0 ;# Bool: Ignore "Timer mode has been changed while timer was running" + common ignore_invalid_brkpoints 0 ;# Bool: Do not warn user about invalid (unreachable) breakpoints common ignore_EEPROM_WR_fail 0 ;# Bool: Ignore EEPROM write failure (due to EECON.WRTINH, EECON.RDYBSY or EECON.EEMWE) common ignore_EEPROM_WR_abort 0 ;# Bool: Ignore EEPROM write cycle abort @@ -75,21 +81,26 @@ class Simulator { # Normal font for error dialog common error_normal_font [font create \ - -family {helvetica} -size -14 \ + -family {helvetica} \ + -size [expr {int(-14 * $::font_size_factor)}] \ ] # Bold font for error dialog common error_bold_font [font create \ -family $::DEFAULT_FIXED_FONT \ - -size -14 \ + -size [expr {int(-14 * $::font_size_factor)}] \ -weight bold \ ] # Header font for error dialog common error_header_font [font create \ - -family {helvetica} -size -17 -weight bold \ + -family {helvetica} \ + -size [expr {int(-17 * $::font_size_factor)}] \ + -weight bold \ ] # Main header font common error_main_header [font create \ - -family {helvetica} -size -20 -weight bold \ + -family {helvetica} \ + -size [expr {int(-20 * $::font_size_factor)}] \ + -weight bold \ ] ## PRIVATE @@ -98,7 +109,7 @@ class Simulator { private variable error_dialog_textwdg ;# Widget: Text widget used in error dialog private variable addr_error_save_type ;# Type of file to save - # Bool: Related to warnings dialogs + # Bool: Related to warnings dialogues private variable ignore_warnings_related_to_changes_in_SFR 0 ## Obejct constructor @@ -113,20 +124,22 @@ class Simulator { # Get new and old value of Program Counter set new_val [getPC] - set original_val [subst "\$::Simulator_GUI::ENV${obj_idx}_PC_dec"] + set original_val [subst -nocommands "\$::Simulator_GUI::ENV${obj_idx}_PC_dec"] # Display new value of PC and highlight it if it has changed set ::Simulator_GUI::ENV${obj_idx}_PC_dec $new_val - if {$highlight_ena && ($original_val != $new_val)} { - mark_entry PC + if {$original_val != $new_val} { + if {$highlight_ena} { + mark_entry PC + } $this sim_eval_PC dec $new_val } - # Mode program pointer in code mememory hexeditor + # Mode program pointer in code mememory hex editor ::X::program_counter_changed $this $new_val # Synchronize Watchdog - if {[$this get_feature_avaliable wtd]} { + if {[$this get_feature_available wtd]} { set val [format %X [$this simulator_getWatchDogTimerValue]] set len [string length $val] if {$len != 4} { @@ -136,7 +149,7 @@ class Simulator { $this simulator_evaluate_wtd_onoff_switch $this watchdog_validate $val - if {[$this get_feature_avaliable wdtcon] || [$this get_feature_avaliable wdtprg]} { + if {[$this get_feature_available wdtcon] || [$this get_feature_available wdtprg]} { set val [format %X [$this simulator_getWatchDogPrescalerValue]] if {[string length $val] == 1} { set val "0$val" @@ -206,7 +219,6 @@ class Simulator { # @parm Int addr - address of register to synchronize # @return void public method Simulator_GUI_sync {type addr} { - # Internal RAM if {$type == {I}} { # Get new and old value @@ -247,7 +259,7 @@ class Simulator { # Synchronize with C variables view if {$addr < 128} { $this cvarsview_sync E $addr - } { + } else { $this cvarsview_sync G $addr } @@ -279,10 +291,10 @@ class Simulator { # Determinate boolean value of the bit if {$psw == 0} { set bool 0 - } { + } else { if {[expr {$psw & $mask}] > 0} { set bool 1 - } { + } else { set bool 0 } } @@ -293,7 +305,7 @@ class Simulator { # Take care of bit color if {$bool} { $Simulator_panel_parent._PSW_$bit configure -fg $on_color - } { + } else { $Simulator_panel_parent._PSW_$bit configure -fg $off_color } } @@ -364,16 +376,16 @@ class Simulator { 134 {set regName {SPDR} } 150 {set regName {EECON} } 143 { - if {[$this get_feature_avaliable ckcon]} { + if {[$this get_feature_available ckcon]} { set regName {CKCON} - } { + } else { set regName {CLKREG} } } 167 { - if {[$this get_feature_avaliable wdtprg]} { + if {[$this get_feature_available wdtprg]} { set regName {WDTPRG} - } { + } else { set regName {WDTCON} } } @@ -393,7 +405,7 @@ class Simulator { # Synchronize with simulator control panel if {$name_resolved} { - set original_val [subst "\$::Simulator_GUI::ENV${obj_idx}_${regName}"] + set original_val [subst -nocommands "\$::Simulator_GUI::ENV${obj_idx}_${regName}"] set ::Simulator_GUI::ENV${obj_idx}_${regName} $new_val if {$highlight_ena && ($original_val != $new_val)} { @@ -410,7 +422,7 @@ class Simulator { set ::Simulator_GUI::ENV${obj_idx}_SFR(FE) $bit_FE if {$bit_FE} { $Simulator_panel_parent._SCON_FE configure -fg $::Simulator_GUI::on_color - } { + } else { $Simulator_panel_parent._SCON_FE configure -fg $::Simulator_GUI::off_color } } @@ -418,7 +430,7 @@ class Simulator { if {[$this sim_engine_get_SM0]} { $Simulator_panel_parent._SCON_SM0 configure -fg $::Simulator_GUI::on_color set ::Simulator_GUI::ENV${obj_idx}_SFR(SM0) 1 - } { + } else { $Simulator_panel_parent._SCON_SM0 configure -fg $::Simulator_GUI::off_color set ::Simulator_GUI::ENV${obj_idx}_SFR(SM0) 0 } @@ -477,7 +489,7 @@ class Simulator { } # Synchronize SFR - foreach addr [simulator_get_avaliable_sfr] { + foreach addr [simulator_get_available_sfr] { Simulator_GUI_sync S $addr } } @@ -517,7 +529,7 @@ class Simulator { # @return void public method simulator_clear_highlight {} { simulator_hexeditor clearHighlighting - foreach addr [simulator_get_avaliable_sfr] { + foreach addr [simulator_get_available_sfr] { unmark_entry $addr } foreach addr {R0 R1 R2 R3 R4 R5 R6 R7} { @@ -551,7 +563,7 @@ class Simulator { foreach wdg $widgets($addr) { if {[winfo class $wdg] == {TEntry}} { $wdg configure -style Simulator_HG.TEntry - } { + } else { $wdg configure -fg $highlight_color } } @@ -567,7 +579,7 @@ class Simulator { foreach wdg $widgets($addr) { if {[winfo class $wdg] == {TEntry}} { $wdg configure -style Simulator.TEntry - } { + } else { $wdg configure -fg $normal_color } } @@ -599,7 +611,7 @@ class Simulator { if {$addr_dec > 127} { set memory {special function registers area} set mem {SFR} - } { + } else { set mem {IDATA} set memory {internal data memory} } @@ -631,7 +643,7 @@ class Simulator { } # Create dialog window - set win [toplevel .undefined_result -class {Error dialog} -bg {#EEEEEE}] + set win [toplevel .undefined_result -class {Error dialog} -bg ${::COMMON_BG_COLOR}] # Create dialog header set top_frame [frame $win.top_frame] @@ -648,7 +660,7 @@ class Simulator { set text_wdg [text $middle_frame.text \ -height 0 -width 0 -font $error_normal_font \ -yscrollcommand "$middle_frame.scrollbar set" \ - -wrap word -relief flat -bg {#EEEEEE} \ + -wrap word -relief flat -bg ${::COMMON_BG_COLOR} \ -tabstyle wordprocessor \ ] set error_dialog_textwdg $text_wdg @@ -665,13 +677,13 @@ class Simulator { -compound left \ -text [mc "Save as plain text"] \ -command "$this simulator_addr_error_save T" \ - ] -side left + ] -side left -padx 2 pack [ttk::button $bottom_frame.save_as_xhtml \ -image ::ICONS::16::html \ -compound left \ -text [mc "Save as XHTML"] \ -command "$this simulator_addr_error_save X" \ - ] -side left + ] -side left -padx 2 pack [ttk::button $bottom_frame.ok \ -image ::ICONS::16::ok \ -compound left \ @@ -712,7 +724,7 @@ class Simulator { $text_wdg insert end [$this editor_procedure {} cget -filename] $text_wdg insert end [mc "\n\tProject:\t\t"] $text_wdg tag add tag_bold {insert linestart} insert - $text_wdg insert end [string trim $this {:}] + $text_wdg insert end [$this cget -projectName] # Processor details $text_wdg insert end [mc "\n\nProcessor details:"] @@ -742,7 +754,7 @@ class Simulator { pack [checkbutton $win.not_again_checkbutton \ -text [mc "Do not show this dialog again"] \ -variable ::Simulator::not_again_val \ - -command "::configDialogs::simulator::set_variable $conf_variable \$::Simulator::not_again_val" \ + -command "::configDialogues::simulator::set_variable $conf_variable \$::Simulator::not_again_val" \ ] -anchor w -padx 15 -pady 5 DynamicHelp::add $win.not_again_checkbutton \ -text [mc "See simulator configuration dialog\nMain Menu -> Configure -> Simulator"] @@ -753,7 +765,7 @@ class Simulator { focus -force $bottom_frame.ok wm title $win [mc "Undefined result - MCU 8051 IDE"] wm iconphoto $win ::ICONS::16::no - wm minsize $win 450 400 + wm minsize $win 470 400 wm protocol $win WM_DELETE_WINDOW " grab release $win destroy $win @@ -775,16 +787,16 @@ class Simulator { set error_dialog_project $this if {$type == {T}} { set init {error.log} - set filetypes { - {{Log files} {*.log} } - {{All files} {*} } - } - } { + set filetypes [list \ + [list [::mc "Log files"] {*.log}] \ + [list [::mc "All files"] {*}] \ + ] + } else { set init {error.html} - set filetypes { - {{XHTML files} {*.html}} - {{All files} {*} } - } + set filetypes [list \ + [list [::mc "HTML files"] {*.html}] \ + [list [::mc "All files"] {*}] \ + ] } # Invoke the file selection dialog @@ -803,8 +815,8 @@ class Simulator { if {![regexp "^(~|/)" $filename]} { set filename "[${::Simulator::error_dialog_project} cget -ProjectDir]/$filename" } - } { ;# Microsoft windows way - if {![regexp "^\w:" $filename]} { + } else { ;# Microsoft windows way + if {![regexp {^\w:} $filename]} { set filename [file join [${::Simulator::error_dialog_project} cget -ProjectDir] $filename] } } @@ -875,7 +887,7 @@ class Simulator { puts -nonewline $file [line_wrap 70 [$error_dialog_textwdg get 1.0 end]] ## SAVE AS XHTML - } { + } else { # Local variables set end [$error_dialog_textwdg index end] ;# Widget end index set last_index 0 ;# Current position (by characters) @@ -949,7 +961,7 @@ class Simulator { # Deterinate string to insert if {[lindex $range 2]} { set tag [lindex $range 1] - } { + } else { set tag "/[lindex $range 1]" } @@ -978,7 +990,7 @@ class Simulator { ## Invoke simulator warning dialog "UART: Frame discarded" # @parm Int pc - Value of program counter - # @parm Int line - Line in source code where this error occured + # @parm Int line - Line in source code where this error occurred # @return void public method simulator_uart_invalid_stop_bit {pc line} { if {$ignore_warnings_related_to_changes_in_SFR || ![$this sim_is_busy]} { @@ -990,12 +1002,12 @@ class Simulator { simulator_warning_dialog \ ignore_invalid_USB \ - [mc "UART: Frame discarded (acording to MCS-51 manual)\n"] $pc $line + [mc "UART: Frame discarded (according to MCS-51 manual)\n"] $pc $line } ## Invoke simulator warning dialog "UART mode has been changed while UART was engaged" # @parm Int pc - Value of program counter - # @parm Int line - Line in source code where this error occured + # @parm Int line - Line in source code where this error occurred # @return void public method simulator_invalid_uart_mode_change {pc line} { if {$ignore_warnings_related_to_changes_in_SFR || ![$this sim_is_busy]} { @@ -1012,7 +1024,7 @@ class Simulator { ## Invoke simulator warning dialog "Timer mode has been changed while timer was running" # @parm Int pc - Value of program counter - # @parm Int line - Line in source code where this error occured + # @parm Int line - Line in source code where this error occurred # @parm Int timer - Timer number (0/1/2) # @return void public method simulator_invalid_timer_mode_change {timer pc line} { @@ -1030,7 +1042,7 @@ class Simulator { ## Invoke watchdog reset dialog # @parm Int pc - Value of program counter - # @parm Int line - Line in source code where this error occured + # @parm Int line - Line in source code where this error occurred # @return void public method simulator_watchdog_reset {pc line} { if {$line == {}} { @@ -1045,7 +1057,7 @@ class Simulator { ## Invokes dialog "Stack Overflow" / "Stack underflow" # @parm String type - {over} == overflow; {under} == underflow # @parm Int pc - Value of program counter - # @parm Int line - Line in source code where this error occured + # @parm Int line - Line in source code where this error occurred # @return void public method simulator_stack_warning {type pc line} { if {$line == {}} { @@ -1054,7 +1066,7 @@ class Simulator { if {$type == {over}} { set foo {overflow} set conf_variable {ignore_stack_overflow} - } { + } else { set foo {underflow} set conf_variable {ignore_stack_underflow} } @@ -1066,7 +1078,7 @@ class Simulator { ## Invoke dialog "Invalid instruction OP code" # @parm Int pc - Value of program counter - # @parm Int line - Line in source code where this error occured + # @parm Int line - Line in source code where this error occurred # @return void public method simulator_invalid_instruction {pc line} { $this simulator_warning_dialog \ @@ -1078,7 +1090,7 @@ class Simulator { ## Invoke dialog "Reading from write-only register" # @parm Int addr - Register address # @parm Int pc - Value of program counter - # @parm Int line - Line in source code where this error occured + # @parm Int line - Line in source code where this error occurred # @return void public method simulator_reading_wr_only {addr pc line} { if {$line == {}} { @@ -1090,9 +1102,9 @@ class Simulator { [mc "Unable to read write-only register.\nRandom value returned.\n\nRegister:\t\t0x%s" [format %X $addr]] $pc $line } - ## Invoke dialog "EEPROM programing cycle abort" + ## Invoke dialog "EEPROM programming cycle abort" # @parm Int pc - Value of program counter - # @parm Int line - Line in source code where this error occured + # @parm Int line - Line in source code where this error occurred # @return void public method simulator_EEPROM_WR_abort {pc line} { if {$line == {}} { @@ -1106,7 +1118,7 @@ class Simulator { ## Invoke dialog "EEPROM write failed" # @parm Int pc - Value of program counter - # @parm Int line - Line in source code where this error occured + # @parm Int line - Line in source code where this error occurred # @return void public method simulator_EEPROM_WR_fail {pc line} { if {$line == {}} { @@ -1115,12 +1127,12 @@ class Simulator { simulator_warning_dialog \ ignore_EEPROM_WR_fail \ - [mc "Unable to initialize EEPROM programing cycle\nbecause EEMWE, RDYBSY and WRTINH must be set\n"] $pc $line + [mc "Unable to initialize EEPROM programming cycle\nbecause EEMWE, RDYBSY and WRTINH must be set\n"] $pc $line } ## Invoke dialog "Invalid return from interrupt" # @parm Int pc - Value of program counter - # @parm Int line - Line in source code where this error occured + # @parm Int line - Line in source code where this error occurred # @return void public method simulator_invalid_reti_dlg {pc line} { if {$line == {}} { @@ -1136,7 +1148,7 @@ class Simulator { # @parm String conf_variable - Configuration variable for disabling this dialog # @parm String text - Text to show # @parm Int pc - Value of program counter - # @parm List line - Line in source code where this error occured + # @parm List line - Line in source code where this error occurred # @return void public method simulator_warning_dialog {conf_variable text pc line} { @@ -1145,7 +1157,7 @@ class Simulator { if {[winfo exists $win]} { destroy $win } - toplevel $win -class {Error dialog} -bg {#EEEEEE} + toplevel $win -class {Error dialog} -bg ${::COMMON_BG_COLOR} ## Create dialog icon and text set top_frame [frame $win.top_frame] @@ -1166,7 +1178,7 @@ class Simulator { pack [checkbutton $bottom_frame.not_again_checkbutton \ -text [mc "Do not show this dialog again"] \ -variable ::Simulator::not_again_val \ - -command "::configDialogs::simulator::set_variable $conf_variable \$::Simulator::not_again_val" \ + -command "::configDialogues::simulator::set_variable $conf_variable \$::Simulator::not_again_val" \ ] -anchor w -side left -anchor w DynamicHelp::add $bottom_frame.not_again_checkbutton \ -text [mc "See simulator configuration dialog\nMain Menu -> Configure -> Simulator"] @@ -1199,4 +1211,21 @@ class Simulator { } tkwait window $win } + + ## Detect all invalid breakpoints (breakpoints at unreachable locations) and report them via messages panel + # @return void + public method report_invalid_breakpoints {} { + if {$ignore_invalid_brkpoints} { + return + } + + $this messages_text_append "\n" + foreach fn_ln [$this simulator_getInvalidBreakpoints] { + $this messages_text_append "[file tail [$this simulator_get_filename [lindex $fn_ln 0]]]:[lindex $fn_ln 1]: warning: Invalid breakpoint" + } + } +} + +# >>> File inclusion guard } +# <<< File inclusion guard diff --git a/lib/simulator/simulator_gui.tcl b/lib/simulator/simulator_gui.tcl index ddaba65..9ae70b9 100755..100644 --- a/lib/simulator/simulator_gui.tcl +++ b/lib/simulator/simulator_gui.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,9 +21,14 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################ +# >>> File inclusion guard +if { ! [ info exists _SIMULATOR_GUI_TCL ] } { +set _SIMULATOR_GUI_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION -# Provides graphical frontend for simulator engine (intended to be +# Provides graphical front-end for simulator engine (intended to be # used at the bottom panel). This class is part of class Simulator. # -------------------------------------------------------------------------- @@ -35,33 +40,47 @@ class Simulator_GUI { ## COMMON - common count 0 ;# Counter of instances + common sim_gui_count 0 ;# Counter of instances common name_color {#0000DD} ;# Color for register name labels (eg. 'SP') common name_nr_color {#8800DD} ;# Color for not-register name labels (eg. 'Clock') - common on_color {green} ;# Foreground color for bits in state 1 (for bit maps) - common off_color {red} ;# Foreground color for bits in state 0 (for bit maps) + common on_color {#00CC00} ;# Foreground color for bits in state 1 (for bit maps) + common off_color {#DD0000} ;# Foreground color for bits in state 0 (for bit maps) # Font for bit labels (eg. 'EA') - common bitfont [font create \ - -family {helvetica} \ - -size -11 \ - -weight bold] + common bitfont [font create \ + -family {helvetica} \ + -size [expr {int(-11 * $::font_size_factor)}] \ + -weight [expr {$::MICROSOFT_WINDOWS ? "normal" : "bold"}] \ + ] # Same as $bitfont but underlined - common bitfont_under [font create \ - -family {helvetica} \ - -size -11 -underline 1 \ - -weight bold] + common bitfont_under [font create \ + -family {helvetica} \ + -size [expr {int(-11 * $::font_size_factor)}] \ + -underline 1 \ + -weight [expr {$::MICROSOFT_WINDOWS ? "normal" : "bold"}] \ + ] # Color for small labels (eg. 'HEX') common small_color {#5599BB} # Font for small labels (eg. 'OCT') - common smallfont $::smallfont + common smallfont $::smallfont + if {$::MICROSOFT_WINDOWS} { ;# On MS Windows we need some smaller font to fit in + set smallfont [font create \ + -size [expr {int(-9 * $::font_size_factor)}] \ + -family {helvetica} \ + -weight normal \ + ] + } common hcolor {#FFAA00} ;# Highlight foreground color for entry widgets common hbcolor {#CCCCCC} ;# Highlight background color for entry widgets # Font for other memory entries (eg. PCON) - common entry_font [font create -size -12 -family $::DEFAULT_FIXED_FONT -weight bold] + common entry_font [font create \ + -size [expr {int(-12 * $::font_size_factor)}] \ + -family $::DEFAULT_FIXED_FONT \ + -weight [expr {$::MICROSOFT_WINDOWS ? "normal" : "bold"}] \ + ] # Postfixes for entry text variables common entry_variables { @@ -108,7 +127,7 @@ class Simulator_GUI { private variable set_pc_by_line_button {} ;# Button: Set PC by line number # Variables related to object initialization - private variable gui_initialized 0 ;# Bool: GUI created + private variable sim_gui_gui_initialized 0 ;# Bool: GUI created private variable parent ;# Parent widget ## PUBLIC @@ -121,14 +140,14 @@ class Simulator_GUI { ## Object constructor constructor {} { - incr count ;# Increment instances counter - set obj_idx $count ;# Set object index + incr sim_gui_count ;# Increment instances counter + set obj_idx $sim_gui_count ;# Set object index } ## Object destructor destructor { # Unallocate entry text variables - if {$gui_initialized} { + if {$sim_gui_gui_initialized} { SimGUI_clean_up } } @@ -138,19 +157,21 @@ class Simulator_GUI { # @return void public method PrepareSimulator {_parent} { set parent $_parent - set gui_initialized 0 + set sim_gui_gui_initialized 0 } ## Inform simulator panel than it has became active # @return void public method SimulatorTabRaised {} { + update idletasks + $scrollable_frame yview scroll 0 units } ## Initialize simulator GUI # @return void public method CreateSimulatorGUI {} { - if {$gui_initialized} {return} - set gui_initialized 1 + if {$sim_gui_gui_initialized} {return} + set sim_gui_gui_initialized 1 # Set object variables set disable_validation 1 @@ -196,7 +217,7 @@ class Simulator_GUI { {up0} "Set this bit to 1"} {command {Set to 0} {} 7 "bit_popup_menu_setto 0" {button_cancel} "Set this bit to 0"} - } $bitmenu 0 "$this " 0 {} + } $bitmenu 0 "$this " 0 {} [namespace current] # # Create left part @@ -210,7 +231,12 @@ class Simulator_GUI { if {[expr {$cap % 8}]} { incr hg } - set hexeditor [HexEditor hexeditor${obj_idx} $main_top_frame.left_frame 8 $hg 2 hex 0 1 8 $cap] + if {!$::MICROSOFT_WINDOWS} { + set height_in_number_of_rows 9 + } else { + set height_in_number_of_rows 11 + } + set hexeditor [HexEditor hexeditor${obj_idx} $main_top_frame.left_frame 8 $hg 2 hex 0 1 $height_in_number_of_rows $cap] $hexeditor bindCellValueChanged "$this simulator_hexedit_value_changed" $hexeditor bindCellLeave {help_window_hide} $hexeditor bindCellEnter "$this create_help_window_ram" @@ -228,14 +254,14 @@ class Simulator_GUI { set sim_gregs_f [frame $middle_f.gregs_frame] # Pack frames of middle part - pack $ctrl_f -fill x -padx 2 + pack $ctrl_f -fill x pack $sim_gregs_f - pack $middle_f -side left -fill both -anchor w + pack $middle_f -side left -fill both -anchor w -padx 5 # Create controls icon bar iconBarFactory $ctrl_f "X::" [string range $ctrl_f.controls_ 1 end] ::ICONS::16:: { - {start_stop "Initialize simulator" {launch} {__initiate_sim} - "Load sim file into simulator engine"} + {start_stop "Start/Stop simulator" {launch} {__initiate_sim} + "Load program into the simulator engine, or shutdown the MCU simulator."} {separator} {reset "Reset" {rebuild} {__reset -} "Perform HW reset"} @@ -250,7 +276,7 @@ class Simulator_GUI { "Run program and show results after each instruction"} {run "Run program" {2rightarrow} {__run} "Run program and show results after some time"} - } + } [namespace current] foreach slave [pack slaves $ctrl_f] { pack configure $slave -padx 0 } @@ -258,11 +284,11 @@ class Simulator_GUI { # Create separator under controls icon bar pack [ttk::separator $sim_gregs_f.mid_sep \ -orient horizontal \ - ] -fill x -expand 1 -pady 2 + ] -fill x -expand 1 -pady 2 -padx 5 ## Create registers: A B set sim_gregs_f_AB [frame $sim_gregs_f.gregs_f_AB] - pack $sim_gregs_f_AB -anchor w + pack $sim_gregs_f_AB -pady 5 # Create num. base headers set col 1 @@ -318,7 +344,7 @@ class Simulator_GUI { -validate key \ ] - setStatusTip -widget $entry -text $stip + setStatusTip -widget $entry -text [mc $stip] # Register register entry for disabling/enabling add_entry $entry # Register register entry for synchronizations @@ -333,7 +359,7 @@ class Simulator_GUI { $sim_gregs_f_AB._B_$base icursor \[$entry index insert\] focus $sim_gregs_f_AB._B_$base " - } { + } else { bind $entry <Key-Up> " $sim_gregs_f_AB._A_$base icursor \[$entry index insert\] focus $sim_gregs_f_AB._A_$base @@ -350,7 +376,7 @@ class Simulator_GUI { ## Create register: PSW set sim_gregs_f_PSW [frame $sim_gregs_f.gregs_f_PSW] - pack $sim_gregs_f_PSW -anchor w + pack $sim_gregs_f_PSW -pady 2 set ::Simulator_GUI::ENV${obj_idx}_PSW 0 create_bitmap_register $sim_gregs_f_PSW 1 PSW {C AC F0 RS1 RS0 OV - P} 0 { {Bit address: 0xD7 -- Carry Flag} @@ -387,7 +413,7 @@ class Simulator_GUI { -text "R$i" -fg $name_color -pady 0 \ -font $bitfont \ ] -row 1 -column $col -sticky we - setStatusTip -widget $sim_gregs_f_Rx._R${i}_l -text $stip + setStatusTip -widget $sim_gregs_f_Rx._R${i}_l -text [mc $stip] # Create register hexadecimal entry set ::Simulator_GUI::ENV${obj_idx}_R$i {00} @@ -439,10 +465,10 @@ class Simulator_GUI { pack $frame0 -side left -anchor nw # Create timers frame (hexadecimal entries and bitmaps) - set timers_frame [ttk::labelframe $frame0.timers_f \ - -padding 2 \ - -labelwidget [label $frame0.timers_lbl -text "TIMERS 0 & 1" -font $smallfont -pady 0]] - pack $timers_frame -anchor nw -fill x + set timers_frame [labelframe $frame0.timers_f \ + -pady 2 -padx 2 \ + -labelwidget [label $frame0.timers_lbl -text [mc "TIMERS 0 & 1"] -font $smallfont -pady 0]] + pack $timers_frame -anchor nw -fill x -padx 5 # Create frame for hexadecimal entries: TH1 TL1 TH0 TL0 set timers_values_f [frame $timers_frame.timers_values_f] @@ -633,20 +659,20 @@ class Simulator_GUI { } # Create frame for interrupt control registers (IE and IP) - set interrupt_frame [ttk::labelframe $frame0.interrupt_f \ - -padding 2 \ - -labelwidget [label $frame0.int_lbl -text "INTERRUPTS" -font $smallfont -pady 0]] - pack $interrupt_frame -anchor nw -fill x + set interrupt_frame [labelframe $frame0.interrupt_f \ + -pady 2 -padx 2 \ + -labelwidget [label $frame0.int_lbl -text [mc "INTERRUPTS"] -font $smallfont -pady 0]] + pack $interrupt_frame -anchor nw -fill x -pady 5 -padx 5 # Create IE, IP bitmaps - if {[$this get_feature_avaliable t2]} { + if {[$this get_feature_available t2]} { set et2 {ET2} set pt2 {PT2} set et2_stip {Bit address: 0xAD -- Enable or disable the Timer 2 overflow interrupt} set pt2_stip {Bit address: 0xBD -- Defines the Timer 2 interrupt priority level} - set et2_ttip {Timer 2 interrupt enable bit} + set et2_ttip {Timer 2 interrupt enable bit.} set pt2_ttip {Timer 2 interrupt priority bit} - } { + } else { set et2 {-} set pt2 {-} set et2_stip {Bit address: 0xAD -- Not implemented} @@ -654,14 +680,14 @@ class Simulator_GUI { set et2_ttip {Not implemented} set pt2_ttip {Not implemented} } - if {[$this get_feature_avaliable uart]} { + if {[$this get_feature_available uart]} { set es {ES} set ps {PS} set es_stip {Bit address: 0xAC -- Enable or disable the serial port interrupt} set ps_stip {Bit address: 0xBC -- Defines the Serial Port interrupt priority level} set es_ttip {Serial Port interrupt enable bit} set ps_ttip {Serial Port interrupt priority bit} - } { + } else { set es {-} set ps {-} set es_stip {Bit address: 0xAD -- Not implemented} @@ -669,14 +695,14 @@ class Simulator_GUI { set es_ttip {Not implemented} set ps_ttip {Not implemented} } - if {[$this get_feature_avaliable acomparator]} { + if {[$this get_feature_available acomparator]} { set ec {EC} set pc {PC} set ec_stip {Bit address: 0xAE -- Enable or disable the comparator interrupt} set pc_stip {Bit address: 0xBE -- Defines the comparator interrupt priority level} set ec_ttip {EC Comparator Interrupt Enable bit} set pc_ttip {Comparator Interrupt Priority bit} - } { + } else { set ec {-} set pc {-} set ec_stip {Bit address: 0xAE -- Not implemented} @@ -824,7 +850,7 @@ class Simulator_GUI { set addrs {} ;# Register addresses set stips {} ;# Status bar tips foreach reg {P0 P1 P2 P3 P4} addr {128 144 160 176 192} stip {0 1 2 3 4} { - if {[$this get_feature_avaliable [string tolower $reg]]} { + if {[$this get_feature_available [string tolower $reg]]} { lappend regs $reg lappend addrs $addr lappend stips [mc "SFR 0x%s: Latch of port %s" [symb_name_to_hex_addr $reg] $stip] @@ -842,7 +868,7 @@ class Simulator_GUI { -text "$reg:" -fg $name_color -pady 0 \ -font $bitfont \ ] -row $row -column 1 - setStatusTip -widget $frame1_top_left._${reg}_l -text $stip + setStatusTip -widget $frame1_top_left._${reg}_l -text [mc $stip] # Create binary entry set ::Simulator_GUI::ENV${obj_idx}_${reg}_bin {11111111} @@ -862,7 +888,7 @@ class Simulator_GUI { # Set entry event bindings bind $entry0 <FocusIn> "$this unmark_entry $addr" - setStatusTip -widget $entry0 -text $stip + setStatusTip -widget $entry0 -text [mc $stip] if {$row != 1} { bind $entry0 <Key-Up> " $frame1_top_left._Pxx[expr {$row-1}]_bin_e icursor \[$entry0 index insert\] @@ -914,66 +940,66 @@ class Simulator_GUI { ### Create bottom frame widgets (PCON SCON) ## Create register bitmaps # - PCON - if {[$this get_feature_avaliable pof]} { + if {[$this get_feature_available pof]} { set POF {POF} set pof_statusTip {Power Off Flag} set pof_tooltip {Power-Off Flag\nCleared to recognize next reset type.\nSet by hardware when VCC rises from 0 to its nominal voltage. Can also be set by software.} - } { + } else { set POF {-} set pof_statusTip {Not implemented} set pof_tooltip {Not implemented} } - if {[$this get_feature_avaliable gf1]} { + if {[$this get_feature_available gf1]} { set GF1 {GF1} set gf1_statusTip {General purpose flag bit} set gf1_tooltip {General purpose Flag\nCleared by user for general purpose usage.\nSet by user for general purpose usage.} - } { + } else { set GF1 {-} set gf1_statusTip {Not implemented} set gf1_tooltip {Not implemented} } - if {[$this get_feature_avaliable gf0]} { + if {[$this get_feature_available gf0]} { set GF0 {GF0} set gf0_statusTip {General purpose flag bit} set gf0_tooltip {General purpose Flag\nCleared by user for general purpose usage.\nSet by user for general purpose usage.} - } { + } else { set GF0 {-} set gf0_statusTip {Not implemented} set gf0_tooltip {Not implemented} } - if {[$this get_feature_avaliable pd]} { + if {[$this get_feature_available pd]} { set PD {PD} set pd_statusTip {Power down bit} set pd_tooltip {Power-Down mode bit\nCleared by hardware when reset occurs.\nSet to enter power-down mode.} - } { + } else { set PD {-} set pd_statusTip {Not implemented} set pd_tooltip {Not implemented} } - if {[$this get_feature_avaliable idl]} { + if {[$this get_feature_available idl]} { set IDL {IDL} set idl_statusTip {Idle mode bit} set idl_tooltip {Idle mode bit\nCleared by hardware when interrupt or reset occurs.\nSet to enter idle mode.} - } { + } else { set IDL {-} set idl_statusTip {Not implemented} set idl_tooltip {Not implemented} } - if {[$this get_feature_avaliable uart]} { + if {[$this get_feature_available uart]} { set SMOD1 {SMOD} set smod1_statusTip {Double baud rate bit} set smod1_tooltip {Serial port Mode bit 1 for UART\nSet to select double baud rate in mode 1, 2 or 3.} - if {[$this get_feature_avaliable smod0]} { + if {[$this get_feature_available smod0]} { append SMOD1 {1} set SMOD0 {SMOD0} set smod0_statusTip {Frame Error Select} set smod0_tooltip {Frame Error Select. When SMOD0 = 0, SCON.7 is SM0. When SMOD0 = 1, SCON.7 is FE.\nNote that FE will be set after a frame error\nregardless of the state of SMOD0.} - } { + } else { set SMOD0 {-} set smod0_statusTip {Not implemented} set smod0_tooltip {Not implemented} } - } { + } else { set SMOD1 {-} set smod1_statusTip {Not implemented} set smod1_tooltip {Not implemented} @@ -981,11 +1007,11 @@ class Simulator_GUI { set smod0_statusTip {Not implemented} set smod0_tooltip {Not implemented} } - if {[$this get_feature_avaliable pwm]} { + if {[$this get_feature_available pwm]} { set PWMEN {PWMEN} set pwmen_stip {Pulse Width Modulation Enable} set pwmen_ttip {Pulse Width Modulation Enable. When PWMEN = 1, Timer 0 and Timer 1 are\nconfigured as an 8-bit PWM counter with 8-bit auto-reload prescaler.\nThe PWM outputs on T1 (P3.5).} - } { + } else { set PWMEN {-} set pwmen_stip {Not implemented} set pwmen_ttip {Not implemented} @@ -1010,7 +1036,7 @@ class Simulator_GUI { $idl_tooltip \ ] # - SCON - if {[$this get_feature_avaliable uart]} { + if {[$this get_feature_available uart]} { create_bitmap_register $frame1_bottom 2 SCON {SM0 SM1 SM2 REN TB8 RB8 TI RI} 1 { {Bit address: 0x9F -- Serial Port mode specifier} {Bit address: 0x9E -- Serial Port mode specifier} @@ -1032,7 +1058,7 @@ class Simulator_GUI { } # Create bit FE (Frame error) - if {[$this get_feature_avaliable smod0]} { + if {[$this get_feature_available smod0]} { set FE_frm [frame $frame1_bottom._SCON_SM0_FE_frm] grid forget $Simulator_panel_parent._SCON_SM0 @@ -1043,7 +1069,7 @@ class Simulator_GUI { bind $Simulator_panel_parent._SCON_SM0 <ButtonRelease-3> "$this bit_popup_menu SM0 0 SCON 1 %X %Y" set label [label $Simulator_panel_parent._SCON_FE \ - -text {FE} -fg $off_color -cursor hand1 \ + -text {FE} -fg $off_color -cursor hand2 \ -bd 0 -font $bitfont -pady 0 -padx 0 \ ] pack $label -in $FE_frm -side left @@ -1053,7 +1079,7 @@ class Simulator_GUI { pack $Simulator_panel_parent._SCON_SM0 -in $FE_frm -side left - setStatusTip -widget $label -text {Bit address: 0x9F -- Framing Error bit} + setStatusTip -widget $label -text [mc "Bit address: 0x9F -- Framing Error bit"] bind $label <Enter> {+%W configure -font $::Simulator_GUI::bitfont_under} bind $label <Leave> {+%W configure -font $::Simulator_GUI::bitfont} DynamicHelp::add $label -text [subst {Clear to reset the error state, not cleared by a valid stop bit.\nSet by hardware when an invalid stop bit is detected.\nSMOD0 must be set to enable access to the FE bit}] @@ -1084,7 +1110,7 @@ class Simulator_GUI { {SFR 0x98: Serial port control register} } { incr row ;# Increment grid row - if {$reg == {SCON} && ![$this get_feature_avaliable uart]} { + if {$reg == {SCON} && ![$this get_feature_available uart]} { continue } @@ -1094,7 +1120,7 @@ class Simulator_GUI { # Create register name labels grid [label $frame1_bottom._${reg}_hex_l \ - -text {HEX} -fg $small_color -font $smallfont \ + -text {H:} -fg $small_color -font $smallfont \ ] -row $row -column 12 setStatusTip -widget $frame1_bottom._${reg}_hex_l -text [mc $stip] @@ -1137,9 +1163,9 @@ class Simulator_GUI { # Create label "DPTR:" if { - [$this get_feature_avaliable {ddp}] + [$this get_feature_available {ddp}] && - ![$this get_feature_avaliable {hddptr}] + ![$this get_feature_available {hddptr}] } then { set text {DPTR0:} } else { @@ -1204,7 +1230,7 @@ class Simulator_GUI { "Simulator_GUI::sim_entry_right $frame1_top_right_0._DPH_e $frame1_top_right_0._DPL_e" bind $frame1_top_right_0._DPL_e <Key-Left> \ "Simulator_GUI::sim_entry_left $frame1_top_right_0._DPL_e $frame1_top_right_0._DPH_e" - if {[$this get_feature_avaliable {ddp}]} { + if {[$this get_feature_available {ddp}]} { bind $frame1_top_right_0._DPH_e <Key-Down> " $frame1_top_right_0._DP1H_e icursor \[$frame1_top_right_0._DPH_e index insert\] focus $frame1_top_right_0._DP1H_e" @@ -1214,7 +1240,7 @@ class Simulator_GUI { } # Create vertical separator (DPTR + Clock)|(SP + SBUF) - if {[$this get_feature_avaliable {ddp}]} {set row 3} {set row 2} + if {[$this get_feature_available {ddp}]} {set row 3} {set row 2} grid [ttk::separator $frame1_top_right_0._SP_sep \ -orient vertical \ ] \ @@ -1229,7 +1255,7 @@ class Simulator_GUI { -text {SP:} -fg $name_color -pady 0 \ -font $bitfont \ ] -row 2 -column 4 -sticky w - setStatusTip -widget $frame1_top_right_0._SP_l -text {SFR 0x81: Stack pointer} + setStatusTip -widget $frame1_top_right_0._SP_l -text [mc "SFR 0x81: Stack pointer"] # Create hexadecimal entry for register: SP set ::Simulator_GUI::ENV${obj_idx}_SP {07} @@ -1243,7 +1269,7 @@ class Simulator_GUI { ] # Show and register created memory cell (SP) - grid $entry -row 2 -column 5 -sticky w + grid $entry -row 2 -column 5 add_entry $entry $this add_sfr_entry 129 $entry @@ -1258,7 +1284,7 @@ class Simulator_GUI { bind $entry <Enter> "$this create_help_window_ram SP; Sbar -freeze {SFR 0x81: Stack pointer}" # Create DPTR1 - if {[$this get_feature_avaliable {ddp}] && ![$this get_feature_avaliable {hddptr}]} { + if {[$this get_feature_available {ddp}] && ![$this get_feature_available {hddptr}]} { # Create label "DPTR1:" grid [label $frame1_top_right_0._DPTR1_l \ @@ -1315,7 +1341,7 @@ class Simulator_GUI { focus $frame1_top_right_0._DPL_e" set row 4 - } { + } else { set row 3 } @@ -1332,7 +1358,7 @@ class Simulator_GUI { -style Simulator.TEntry \ -textvariable ::Simulator_GUI::ENV${obj_idx}_CLOCK \ -font $entry_font \ - -width 6 \ + -width 7 \ -validate all \ -validatecommand "$this clock_validate %P" \ ] @@ -1359,13 +1385,13 @@ class Simulator_GUI { incr row # Create label "SBUF X:" - if {[$this get_feature_avaliable uart]} { + if {[$this get_feature_available uart]} { set label [label $frame1_top_right_0._${reg}_l \ -text "${regname}:" -fg $name_color \ -font $bitfont -pady 0 \ ] grid $label -row $row -column 4 - setStatusTip -widget $label -text $stip + setStatusTip -widget $label -text [mc $stip] # Create hexadecimal entry for memory cell: SBUF @@ -1404,7 +1430,7 @@ class Simulator_GUI { -text {PC:} -fg $name_nr_color \ -font $bitfont \ ] -side left - setStatusTip -widget $pc_lbl_but_frm._PC_l -text $stip + setStatusTip -widget $pc_lbl_but_frm._PC_l -text [mc $stip] set set_pc_by_line_button [ttk::button $pc_lbl_but_frm._PC_but \ -image ::ICONS::16::2_rightarrow \ -command "::X::__simulator_set_PC_by_line" \ @@ -1412,7 +1438,7 @@ class Simulator_GUI { ] pack $set_pc_by_line_button -side right -after $pc_lbl_but_frm._PC_l DynamicHelp::add $set_pc_by_line_button \ - -text [mc "Set PC (Program Counter) acording to\nline number in source code"] + -text [mc "Set PC (Program Counter) according to\nline number in source code"] add_entry $pc_lbl_but_frm._PC_but setStatusTip -widget $set_pc_by_line_button \ -text [mc "Set PC by line number"] @@ -1438,7 +1464,7 @@ class Simulator_GUI { -validatecommand "$this sim_eval_PC hex %P" \ -font $entry_font \ ] - setStatusTip -widget $frame1_top_right_0_0._PC_hex_e -text $stip + setStatusTip -widget $frame1_top_right_0_0._PC_hex_e -text [mc $stip] # Show and register created entry (PC - hex) grid $entry -row 1 -column 2 @@ -1467,7 +1493,7 @@ class Simulator_GUI { -validatecommand "$this sim_eval_PC dec %P" \ -font $entry_font \ ] - setStatusTip -widget $frame1_top_right_0_1._PC_dec_e -text $stip + setStatusTip -widget $frame1_top_right_0_1._PC_dec_e -text [mc $stip] # Show and register created entry (PC - dec) grid $entry -row 1 -column 2 @@ -1495,7 +1521,7 @@ class Simulator_GUI { -style TEntry \ -textvariable ::Simulator_GUI::ENV${obj_idx}_TIME \ -state readonly \ - -font [font create -size -12 -family $::DEFAULT_FIXED_FONT] \ + -font [font create -size [expr {int(-12 * $::font_size_factor)}] -family $::DEFAULT_FIXED_FONT] \ ] setStatusTip -widget $frame1_top_right_1._TIME_e -text [mc "Overall time"] @@ -1513,7 +1539,7 @@ class Simulator_GUI { set bottom_left_bottom_trow 0 ;# Row in grid # Create controls related to Timer/Couter 2 - if {[$this get_feature_avaliable t2]} { + if {[$this get_feature_available t2]} { incr bottom_left_bottom_row 4 set t2_frame [frame $bottom_left_frame.timers_f] pack $t2_frame @@ -1598,7 +1624,7 @@ class Simulator_GUI { -validatecommand "$this validate_Txx $reg %P" \ -font $entry_font \ ] - setStatusTip -widget $timers_values_f._Txx${col}_e -text $stip + setStatusTip -widget $timers_values_f._Txx${col}_e -text [mc $stip] # Show and register created memory cell grid $entry -row 2 -column $col @@ -1639,7 +1665,7 @@ class Simulator_GUI { {Timer 2 Capture/Reload bit\nIf RCLK=1 or TCLK=1, CP/RL2# is ignored and timer is forced to auto-reload on timer 2 overflow.\nClear to auto-reload on timer 2 overflows or negative transitions on T2EX pin if EXEN2=1.\nSet to capture on negative transitions on T2EX pin if EXEN2=1.} } - if {[$this get_feature_avaliable t2mod]} { + if {[$this get_feature_available t2mod]} { create_bitmap_register $timers_frame_reg 2 T2MOD {- - - - - - T2OE DCEN} 1 { {Reserved} {Reserved} @@ -1671,7 +1697,7 @@ class Simulator_GUI { } { incr col ;# Increment grid column - if {$reg == {T2MOD} && ![$this get_feature_avaliable t2mod]} { + if {$reg == {T2MOD} && ![$this get_feature_available t2mod]} { continue } @@ -1723,38 +1749,38 @@ class Simulator_GUI { set bottom_middle_row 0 ;# Row in grid # Registers: AUXR, AUXR1, ACSR, EECON, SPCR, SPSR, WDTCON. IPH, SPCR - if {[$this get_feature_avaliable t2]} { + if {[$this get_feature_available t2]} { set pt2h {PT2H} set pt2h_stip {Defines the Timer 2 interrupt priority level} set pt2h_ttip {Timer 2 interrupt priority bit} - } { + } else { set pt2h {-} set pt2h_stip {Not implemented} set pt2h_ttip {Not implemented} } - if {[$this get_feature_avaliable uart]} { + if {[$this get_feature_available uart]} { set psh {PSH} set psh_stip {Defines the Serial Port interrupt priority level} set psh_ttip {Serial Port interrupt priority bit} - } { + } else { set psh {-} set psh_stip {Not implemented} set psh_ttip {Not implemented} } - if {[$this get_feature_avaliable acomparator]} { + if {[$this get_feature_available acomparator]} { set pch {PCH} set pch_stip {Defines the comparator interrupt priority level} set pch_ttip {Comparator Interrupt Priority bit} - } { + } else { set pch {-} set pch_stip {Not implemented} set pch_ttip {Not implemented} } - if {[$this get_feature_avaliable pwdex]} { + if {[$this get_feature_available pwdex]} { set PWDEX {PWDEX} set pwdex_stip {Power-down Exit Mode} set pwdex_ttip {Power-down Exit Mode. When PWDEX = 1, wake up from Power-down is externally controlled.\nWhen PWDEX = 0, wake up from Power-down is internally timed.} - } { + } else { set PWDEX {-} set pwdex_stip {Not implemented} set pwdex_ttip {Not implemented} @@ -1763,7 +1789,7 @@ class Simulator_GUI { set EXTRAM {EXTRAM} set extram_statustip {Internal/External RAM access using MOVX} set extram_tooltip {Internal/External RAM access using MOVX @ Ri/@DPTR\nEXTRAM\tOperating Mode\n0\tInternal ERAM (00H-FFH) access using MOVX @ Ri/@DPTR\n1\tExternal data memory access} - } elseif {[$this get_feature_avaliable intelpe]} { + } elseif {[$this get_feature_available intelpe]} { set EXTRAM {IPE} set extram_statustip {Intel_Pwd_Exit} set extram_tooltip {When set, this bit configures the interrupt driven exit from power-down\nto resume execution on the rising edge of the interrupt signal. When\nthis bit is cleared, the execution resumes after a self-timed interval\n(nominal 2 ms) referenced from the falling edge of the interrupt signal.} @@ -1773,9 +1799,9 @@ class Simulator_GUI { set extram_tooltip {Reserved\nThe value read from this bit is indeterminate. Do not set this bit.} } if { - [$this get_feature_avaliable wdtcon] || - ![$this get_feature_avaliable wtd] || - ![$this get_feature_avaliable auxrdisrto] + [$this get_feature_available wdtcon] || + ![$this get_feature_available wtd] || + ![$this get_feature_available auxrdisrto] } then { set DISRTO {-} set disrto_stip {Reserved for future expansion} @@ -1786,9 +1812,9 @@ class Simulator_GUI { set disrto_ttip {Disable/Enable Reset out\nDISRTO\tOperating Mode\n0\tReset pin is driven High after WDT times out\n1\tReset pin is input only} } if { - [$this get_feature_avaliable wdtcon] || - ![$this get_feature_avaliable wtd] || - ![$this get_feature_avaliable auxrwdidle] + [$this get_feature_available wdtcon] || + ![$this get_feature_available wtd] || + ![$this get_feature_available auxrwdidle] } then { set WDIDLE {-} set wdidle_stip {Reserved for future expansion} @@ -1798,16 +1824,16 @@ class Simulator_GUI { set wdidle_stip {Disable/Enable WDT in IDLE mode} set wdidle_ttip {Disable/Enable WDT in IDLE mode\nWDIDLE\tOperating Mode\n0\tWDT continues to count in IDLE mode\n1\tWDT halts counting in IDLE mode} } - if {[$this get_feature_avaliable ao]} { + if {[$this get_feature_available ao]} { set DISALE {AO} - } { + } else { set DISALE {DISALE} } - if {[$this get_feature_avaliable auxr1gf3]} { + if {[$this get_feature_available auxr1gf3]} { set GF3 {GF3} set gf3_ttip {General purpose user flag} set gf3_stip {General purpose user flag} - } { + } else { set GF3 {-} set gf3_ttip {Reserved\nThe value read from this bit is indeterminate. Do not set this bit.} set gf3_stip {Reserved for future expansion} @@ -1829,8 +1855,8 @@ class Simulator_GUI { [list - $pch $pt2h $psh PT1H PX1H PT0H PX0H] \ [list - - - - - - $PWDEX X2] \ ] stip { - {SFR 0x8E: Auxillary Register} - {SFR 0xA2: Auxillary Register 1} + {SFR 0x8E: Auxiliary Register} + {SFR 0xA2: Auxiliary Register 1} {SFR 0x97: Analog Comparator Control and Status Register} {SFR 0x96: Data EEPROM Control Register} {SFR 0xD5: SPI Control Register} @@ -1843,14 +1869,14 @@ class Simulator_GUI { if {$cg_left && $bottom_middle_row > $bottom_left_bottom_row} { set left__right 1 set target_frame $bottom_left_bottom_frame - } { + } else { set left__right 0 set target_frame $bottom_middle_frame } switch -- $reg { {IPH} { - if {![$this get_feature_avaliable iph]} { + if {![$this get_feature_available iph]} { continue } create_bitmap_register $target_frame $row $reg $bits 1 [list \ @@ -1874,9 +1900,9 @@ class Simulator_GUI { ] } {CLKREG} { - if {[$this get_feature_avaliable clkreg]} { + if {[$this get_feature_available clkreg]} { set reg {CLKREG} - } elseif {[$this get_feature_avaliable ckcon]} { + } elseif {[$this get_feature_available ckcon]} { set reg {CKCON} } else { continue @@ -1932,7 +1958,7 @@ class Simulator_GUI { bind $Simulator_panel_parent._EECON_RDYBSY <ButtonRelease-3> {break} } {WDTCON} { - if {![$this get_feature_avaliable wdtcon] || [$this get_feature_avaliable wdtprg]} { + if {![$this get_feature_available wdtcon] || [$this get_feature_available wdtprg]} { continue } set psx_tooltip {Prescaler bits for the watchdog timer (WDT). When all three bits are cleared\nto 0, the watchdog timer has a nominal period of 16K machine cycles,\n(i.e. 16 ms at a XTAL frequency of 12 MHz in normal mode or 6 MHz in x2 mode).\nWhen all three bits are set to 1, the nominal period is 2048K machine cycles,\n(i.e. 2048 ms at 12 MHz clock frequency in normal mode or 6 MHz in x2 mode).} @@ -1958,7 +1984,7 @@ class Simulator_GUI { ] } {WDTPRG} { - if {![$this get_feature_avaliable wdtprg] || [$this get_feature_avaliable wdtcon]} { + if {![$this get_feature_available wdtprg] || [$this get_feature_available wdtcon]} { continue } set t_stip {Reserved} @@ -1981,7 +2007,7 @@ class Simulator_GUI { } } {SPSR} { - if {![$this get_feature_avaliable spi]} { + if {![$this get_feature_available spi]} { continue } create_bitmap_register $target_frame $row $reg $bits 1 { @@ -2005,7 +2031,7 @@ class Simulator_GUI { } } {SPCR} { - if {![$this get_feature_avaliable spi]} { + if {![$this get_feature_available spi]} { continue } create_bitmap_register $target_frame $row $reg $bits 1 [list \ @@ -2029,7 +2055,7 @@ class Simulator_GUI { ] } {ACSR} { - if {![$this get_feature_avaliable acomparator]} { + if {![$this get_feature_available acomparator]} { continue } set CMx_tooltip {Comparator Interrupt Mode\n 2 1 0\tInterrupt Mode\n--- --- ---\t---------------------------------------\n 0 0 0\tNegative (Low) level\n 0 0 1\tPositive edge\n 0 1 0\tToggle with debounce\n 0 1 1\tPositive edge with debounce\n 1 0 0\tNegative edge\n 1 0 1\tToggle\n 1 1 0\tNegative edge with debounce\n 1 1 1\tPositive (High) level} @@ -2053,8 +2079,8 @@ class Simulator_GUI { } {AUXR1} { if { - (![$this get_feature_avaliable ddp] || [$this get_feature_avaliable wdtcon]) - && ![$this get_feature_avaliable auxr1gf3] + (![$this get_feature_available ddp] || [$this get_feature_available wdtcon]) + && ![$this get_feature_available auxr1gf3] } then { continue } @@ -2079,7 +2105,7 @@ class Simulator_GUI { ] } {AUXR} { - if {![$this get_feature_avaliable auxr]} { + if {![$this get_feature_available auxr]} { continue } create_bitmap_register $target_frame $row $reg $bits 1 [list \ @@ -2129,7 +2155,7 @@ class Simulator_GUI { if {$reg != {EECON}} { set ::Simulator_GUI::ENV${obj_idx}_${reg} {00} - } { + } else { set ::Simulator_GUI::ENV${obj_idx}_${reg} {03} } @@ -2149,7 +2175,7 @@ class Simulator_GUI { if {$left__right} { incr bottom_left_bottom_row incr bottom_left_bottom_trow - } { + } else { incr bottom_middle_row } } @@ -2174,7 +2200,7 @@ class Simulator_GUI { pack $bottom_right_spec_frame -anchor nw -fill both ## Create watchdog timer controls - if {[$this get_feature_avaliable wtd]} { + if {[$this get_feature_available wtd]} { set bottom_right_present 1 set watchdog_frame [frame $bottom_right_frame.watchdog_frame] pack $watchdog_frame -anchor nw -before $bottom_right_reg_frame @@ -2188,8 +2214,8 @@ class Simulator_GUI { # Create ON/OFF switch set watchdog_onoff_switch [label $watchdog_frame.on_off_switch \ -text [mc "OFF"] -fg $off_color -pady 0 \ - -bd 1 -cursor hand1 -font [font create \ - -family $::DEFAULT_FIXED_FONT -size -12 \ + -bd 1 -cursor hand2 -font [font create \ + -family $::DEFAULT_FIXED_FONT -size [expr {int(-12 * $::font_size_factor)}] \ -weight bold \ ] \ ] @@ -2198,7 +2224,7 @@ class Simulator_GUI { pack $watchdog_onoff_switch -side left -padx 2 # Create entryBox for watchdog prescaler - if {[$this get_feature_avaliable wdtcon] || [$this get_feature_avaliable wdtprg]} { + if {[$this get_feature_available wdtcon] || [$this get_feature_available wdtprg]} { # Create hexadecimal entry for created entry: WatchDog set ::Simulator_GUI::ENV${obj_idx}_WatchDogP {00} set wdt_prescaler_entry [ttk::entry $watchdog_frame._WatchDogP_e\ @@ -2263,7 +2289,7 @@ class Simulator_GUI { {SFR 0x86: SPI Data Register} {SFR 0xA6: Watchdog reset} } { - if {![$this get_feature_avaliable $feature]} { + if {![$this get_feature_available $feature]} { continue } if {$col >= 4} { @@ -2357,7 +2383,7 @@ class Simulator_GUI { ## Show EEPROM write progress indicator # @return void public method simulator_GUI_invoke_write_to_eeprom {} { - if {!$gui_initialized} {return} + if {!$sim_gui_gui_initialized} {return} # Create EEPROM indicator frame and horizonatl separator above it set eeprom_operation_frame [frame $bottom_right_spec_frame.frame] @@ -2409,7 +2435,7 @@ class Simulator_GUI { ## Hide EEPROM write progress indicator # @return void public method simulator_GUI_cancel_write_to_eeprom {} { - if {!$gui_initialized} {return} + if {!$sim_gui_gui_initialized} {return} set ::Simulator_GUI::ENV${obj_idx}_EEPROM_prg 1 if {[winfo exists $eeprom_operation_frame]} { @@ -2421,7 +2447,7 @@ class Simulator_GUI { # @parm Int value - New progress value in percents minus one (1..101) # @return void public method simulator_WTE_prg_set {value} { - if {!$gui_initialized} {return} + if {!$sim_gui_gui_initialized} {return} if {$value < 1} { set value 1 @@ -2445,14 +2471,14 @@ class Simulator_GUI { $eeprom_progressbar configure -fg $clr } - ## Adjust watchdog on/off switch acording to current state + ## Adjust watchdog on/off switch according to current state # @return void public method simulator_evaluate_wtd_onoff_switch {} { - if {!$gui_initialized} {return} + if {!$sim_gui_gui_initialized} {return} if {[$this simulator_isWatchDogTimerRuning]} { $watchdog_onoff_switch configure -text [mc "ON "] -fg $on_color - } { + } else { $watchdog_onoff_switch configure -text [mc "OFF"] -fg $off_color } } @@ -2460,12 +2486,12 @@ class Simulator_GUI { ## Invert watchdog on/off flag # @return void public method simulator_invert_wtd_onoff_switch {} { - if {!$gui_initialized} {return} + if {!$sim_gui_gui_initialized} {return} if {!$sim_enabled} {return} if {[$this simulator_isWatchDogTimerRuning]} { $this simulator_startStopWatchDogTimer 0 - } { + } else { $this simulator_startStopWatchDogTimer 1 } simulator_evaluate_wtd_onoff_switch @@ -2512,7 +2538,7 @@ class Simulator_GUI { catch { if {!$dec_value || !$sim_enabled} { $wtd_clear_button configure -state disabled - } { + } else { $wtd_clear_button configure -state normal } } @@ -2541,7 +2567,7 @@ class Simulator_GUI { # This function cannot run multithreaded if {$sync_Txx_in_progress} { return 1 - } { + } else { set sync_Txx_in_progress 1 } @@ -2628,7 +2654,7 @@ class Simulator_GUI { } # Validation of THx, TLx or RCAPxL, RCAPxH - } { + } else { # Check for corrent value if {![entry_2_hex_validate $content]} { set sync_Txx_in_progress 0 @@ -2638,23 +2664,23 @@ class Simulator_GUI { ## Determinate vaiable of Tx entry and low-order and high-order bytes of Tx # TH0 or TL0 if {$registerName == {TH0} || $registerName == {TL0}} { - set hex_h [subst "\$::Simulator_GUI::ENV${obj_idx}_TH0"] - set hex_l [subst "\$::Simulator_GUI::ENV${obj_idx}_TL0"] + set hex_h [subst -nocommands "\$::Simulator_GUI::ENV${obj_idx}_TH0"] + set hex_l [subst -nocommands "\$::Simulator_GUI::ENV${obj_idx}_TL0"] set target_var "::Simulator_GUI::ENV${obj_idx}_T0" # TH1 or TL1 } elseif {$registerName == {TH1} || $registerName == {TL1}} { - set hex_h [subst "\$::Simulator_GUI::ENV${obj_idx}_TH1"] - set hex_l [subst "\$::Simulator_GUI::ENV${obj_idx}_TL1"] + set hex_h [subst -nocommands "\$::Simulator_GUI::ENV${obj_idx}_TH1"] + set hex_l [subst -nocommands "\$::Simulator_GUI::ENV${obj_idx}_TL1"] set target_var "::Simulator_GUI::ENV${obj_idx}_T1" # TH2 or TL2 } elseif {$registerName == {TH2} || $registerName == {TL2}} { - set hex_h [subst "\$::Simulator_GUI::ENV${obj_idx}_TH2"] - set hex_l [subst "\$::Simulator_GUI::ENV${obj_idx}_TL2"] + set hex_h [subst -nocommands "\$::Simulator_GUI::ENV${obj_idx}_TH2"] + set hex_l [subst -nocommands "\$::Simulator_GUI::ENV${obj_idx}_TL2"] set target_var "::Simulator_GUI::ENV${obj_idx}_T2" # RCAP2H or RCAP2L } elseif {$registerName == {RCAP2H} || $registerName == {RCAP2L}} { - set hex_h [subst "\$::Simulator_GUI::ENV${obj_idx}_RCAP2H"] - set hex_l [subst "\$::Simulator_GUI::ENV${obj_idx}_RCAP2L"] + set hex_h [subst -nocommands "\$::Simulator_GUI::ENV${obj_idx}_RCAP2H"] + set hex_l [subst -nocommands "\$::Simulator_GUI::ENV${obj_idx}_RCAP2L"] set target_var "::Simulator_GUI::ENV${obj_idx}_RCAP2" } @@ -2707,17 +2733,17 @@ class Simulator_GUI { # possibly new value of bit SCON.7 (FE/SM0) # @return void public method simulator_gui_SMOD0_changed {} { - set scon [subst "\$::Simulator_GUI::ENV${obj_idx}_SCON"] + set scon [subst -nocommands "\$::Simulator_GUI::ENV${obj_idx}_SCON"] if {$scon == {}} { set scon 0 } set scon [expr {"0x$scon" & 0x7F}] if {[$this get_SMOD0]} { - if {[subst "\$::Simulator_GUI::ENV${obj_idx}_SFR(FE)"]} { + if {[subst -nocommands "\$::Simulator_GUI::ENV${obj_idx}_SFR(FE)"]} { set scon [expr {$scon | 0x80}] } - } { - if {[subst "\$::Simulator_GUI::ENV${obj_idx}_SFR(SM0)"]} { + } else { + if {[subst -nocommands "\$::Simulator_GUI::ENV${obj_idx}_SFR(SM0)"]} { set scon [expr {$scon | 0x80}] } } @@ -2737,7 +2763,7 @@ class Simulator_GUI { # This function cannot run multithreaded if {$bitmap_hex_validation_ena} { set bitmap_hex_validation_ena 0 - } { + } else { return 1 } @@ -2771,7 +2797,7 @@ class Simulator_GUI { SCON { if {[$this get_SMOD0]} { lset bitList 0 FE - } { + } else { lset bitList 0 SM0 } } @@ -2789,7 +2815,7 @@ class Simulator_GUI { set bitVal [lindex $bits $i] if {$bitVal} { set color $on_color - } { + } else { set color $off_color } @@ -2831,7 +2857,7 @@ class Simulator_GUI { -text "[mc $name]:" -fg $name_color \ -anchor w -pady 0 -font $bitfont \ ] -row $row -column 1 -in $parent -sticky w - setStatusTip -widget $Simulator_panel_parent._${name}_l -text $stip + setStatusTip -widget $Simulator_panel_parent._${name}_l -text [mc $stip] set col 1 ;# Bit label column (2..9) set bitNum -1 ;# Bit number (0..7) @@ -2847,9 +2873,9 @@ class Simulator_GUI { incr Idx set idx $Idx set cursor {left_ptr} - } { + } else { set color $off_color - set cursor {hand1} + set cursor {hand2} set idx {} } @@ -2863,7 +2889,7 @@ class Simulator_GUI { bind $label <Enter> {+%W configure -font $::Simulator_GUI::bitfont_under} bind $label <Leave> {+%W configure -font $::Simulator_GUI::bitfont} } - DynamicHelp::add $label -text [subst [mc $tooltip]] + DynamicHelp::add $label -text [mc [subst $tooltip]] grid $label -row $row -column $col -in $parent # Skip registration of empty bits @@ -2894,7 +2920,7 @@ class Simulator_GUI { # @parm void public method bit_popup_menu_setto {bool} { if {!$sim_enabled} {return} - if {$bool != [subst "\$::Simulator_GUI::ENV${obj_idx}_SFR([lindex $bit_popup_menu_args 0])"]} { + if {$bool != [subst -nocommands "\$::Simulator_GUI::ENV${obj_idx}_SFR([lindex $bit_popup_menu_args 0])"]} { eval "sim_invert $bit_popup_menu_args" } } @@ -2908,7 +2934,7 @@ class Simulator_GUI { # This function cannot run multithreaded if {$sync_PC_in_progress} { return 1 - } { + } else { set sync_PC_in_progress 1 } @@ -2972,7 +2998,7 @@ class Simulator_GUI { set lineNum [$this simulator_getCurrentLine] if {$lineNum != {}} { $this move_simulator_line $lineNum - } { + } else { $this editor_procedure {} unset_simulator_line {} } } @@ -2992,7 +3018,7 @@ class Simulator_GUI { # This function cannot run multithreaded if {$sync_Px_in_progress} { return 1 - } { + } else { set sync_Px_in_progress 1 } @@ -3079,7 +3105,7 @@ class Simulator_GUI { # This function cannot run multithreaded if {$sync_AB_in_progress} { return 1 - } { + } else { set sync_AB_in_progress 1 } @@ -3089,7 +3115,7 @@ class Simulator_GUI { return 1 } - # Determinate maximum length acording to numeric base + # Determinate maximum length according to numeric base switch -- $num_base { {hex} {set max_len 2} {dec} {set max_len 3} @@ -3174,15 +3200,15 @@ class Simulator_GUI { } # Determinate character representation if {$dec > 31 && $dec < 127} { - set char [subst "\\u00$hex"] - } { + set char [subst -nocommands "\\u00$hex"] + } else { set char {} } # Synchronize with other entries foreach base {hex dec bin oct char} { if {$base == $num_base} {continue} - set ::Simulator_GUI::ENV${obj_idx}_${register}_$base [subst "\$$base"] + set ::Simulator_GUI::ENV${obj_idx}_${register}_$base [subst -nocommands "\$$base"] } # Synchronize with Right panel and Engine @@ -3194,7 +3220,7 @@ class Simulator_GUI { $this sfr_watches_sync 224 $dec_val $this sfrmap_map_sync 224 $dec_val # Register B - } { + } else { $this setSfr 240 $hex set dec_val [expr "0x$hex"] $this sfr_watches_sync 240 $dec_val @@ -3212,8 +3238,8 @@ class Simulator_GUI { # @return void public method create_help_window_Rx {R_index} { # Determinate true register address (decimal) - set RS0 [subst "\$::Simulator_GUI::ENV${obj_idx}_SFR(RS0)"] - set RS1 [subst "\$::Simulator_GUI::ENV${obj_idx}_SFR(RS1)"] + set RS0 [subst -nocommands "\$::Simulator_GUI::ENV${obj_idx}_SFR(RS0)"] + set RS1 [subst -nocommands "\$::Simulator_GUI::ENV${obj_idx}_SFR(RS1)"] if {$RS0} {incr R_index 8} if {$RS1} {incr R_index 16} @@ -3228,11 +3254,11 @@ class Simulator_GUI { # @parm String bit - Bit name (not address) # @return void public method sim_GUI_bit_set_clear {bool reg bit} { - if {!$gui_initialized} {return} + if {!$sim_gui_gui_initialized} {return} if {$bool} { $Simulator_panel_parent._${reg}_${bit} configure -fg $on_color - } { + } else { $Simulator_panel_parent._${reg}_${bit} configure -fg $off_color } } @@ -3244,14 +3270,14 @@ class Simulator_GUI { # @parm Bool hex_reg - Bitmap is connected to hexadecimal entry # @return void public method sim_invert {bitName bitNumber registerName hex_reg} { - if {!$gui_initialized} {return} + if {!$sim_gui_gui_initialized} {return} set decVal_increment 0 # Simulator must be engaged if {!$sim_enabled} {return} # Determinate bit boolean value - set bitBoolVal [subst "\$::Simulator_GUI::ENV${obj_idx}_SFR($bitName)"] + set bitBoolVal [subst -nocommands "\$::Simulator_GUI::ENV${obj_idx}_SFR($bitName)"] # Determinate bit decimal and hexadecimal value set addr [symb_name_to_hex_addr $registerName] @@ -3260,8 +3286,8 @@ class Simulator_GUI { set bitDecVal 0 set bitmap_hex_validation_ena 0 if {$hex_reg} { - set decVal [expr "0x[subst "\$::Simulator_GUI::ENV${obj_idx}_${registerName}"]"] - } { + set decVal [expr "0x[subst -nocommands "\$::Simulator_GUI::ENV${obj_idx}_${registerName}"]"] + } else { set decVal [$this getSfrDEC $addr] } switch -- $bitNumber { @@ -3279,7 +3305,7 @@ class Simulator_GUI { if {$bitBoolVal} { $Simulator_panel_parent._${registerName}_$bitName configure -fg $off_color set decVal_increment -$bitDecVal - } { + } else { $Simulator_panel_parent._${registerName}_$bitName configure -fg $on_color set decVal_increment $bitDecVal } @@ -3434,16 +3460,16 @@ class Simulator_GUI { {86} {return SPDR} {96} {return EECON} {8F} { - if {[$this get_feature_avaliable ckcon]} { + if {[$this get_feature_available ckcon]} { return {CKCON} - } { + } else { return {CLKREG} } } {A7} { - if {[$this get_feature_avaliable wdtcon]} { + if {[$this get_feature_available wdtcon]} { return {WDTCON} - } { + } else { return {WDTPRG} } } @@ -3453,7 +3479,7 @@ class Simulator_GUI { ## Switch active register bank (Current bank number is based on bits SFR(RS0) SFR(RS1)) # @return void public method sim_switch_bank {} { - if {!$gui_initialized} {return} + if {!$sim_gui_gui_initialized} {return} # Determinate bank offset set bnk [$this getBank] @@ -3461,7 +3487,7 @@ class Simulator_GUI { # Synchronize active bank register entries for {set i 0} {$i < 8} {incr i} { - set value [subst "\$::Simulator_GUI::ENV${obj_idx}_DATA([expr {$index + $i}])"] + set value [subst -nocommands "\$::Simulator_GUI::ENV${obj_idx}_DATA([expr {$index + $i}])"] set ::Simulator_GUI::ENV${obj_idx}_R$i $value } } @@ -3661,7 +3687,7 @@ class Simulator_GUI { # Register name (SFR only) } else { - set val [subst "\$::Simulator_GUI::ENV${obj_idx}_$addr"] + set val [subst -nocommands "\$::Simulator_GUI::ENV${obj_idx}_$addr"] set addr [symb_name_to_hex_addr $addr] append addr { SFR} } @@ -3675,9 +3701,12 @@ class Simulator_GUI { # @return Bool - result public method clock_validate {number} { # Check for allowed characters - if {![string is digit -strict $number]} { + if {$number == {}} { + set number 0 + } elseif {![regexp {^\d+(\.\d*)?$} $number]} { return 0 } + set number [string trimright $number {.}] # Check for allowed range if {$number > 99999} { @@ -3697,11 +3726,11 @@ class Simulator_GUI { # @parm String args - any arguments # @return void public method simulator_hexeditor {args} { - if {!$gui_initialized} {return} + if {!$sim_gui_gui_initialized} {return} eval "$hexeditor $args" } - ## Binding for event CellValueChanged in hexeditor + ## Binding for event CellValueChanged in hex editor # @parm Int address - Address of changed cell # @parm Int value - New cell value # @return void @@ -3716,7 +3745,7 @@ class Simulator_GUI { if {$address < 32} { set ::Simulator_GUI::ENV${obj_idx}_DATA($address) $value entry_bank_reg_sync $address $value - } { + } else { entry_idata_reg_sync $address $value } } @@ -3729,7 +3758,7 @@ class Simulator_GUI { public method simulator_gui_scroll_set {orient frac0 frac1} { if {$orient == {x}} { set scrollbar $horizontal_scrollbar - } { + } else { set scrollbar $vertical_scrollbar } @@ -3740,11 +3769,11 @@ class Simulator_GUI { update } # Show scrollbar - } { + } else { if {![winfo ismapped $scrollbar]} { if {$orient == {x}} { pack $scrollbar -fill x -side top -before $scrollable_frame - } { + } else { pack $scrollbar -fill y -side left } } @@ -3761,7 +3790,7 @@ class Simulator_GUI { unset ::Simulator_GUI::ENV${obj_idx}_${var} } } - if {$gui_initialized} { + if {$sim_gui_gui_initialized} { menu_Sbar_remove $bitmenu } } @@ -3781,14 +3810,14 @@ class Simulator_GUI { ## Change image on button "Step over" (from "Pause" to "Goto" or backwards) # @return void public method invert_stepover_button {} { - if {!$gui_initialized || !$sim_enabled} {return} + if {!$sim_gui_gui_initialized || !$sim_enabled} {return} # Determinate ID of the current image set image [$ctrl_f.controls_quick_step cget -image] # Change image if {$image == {::ICONS::16::goto2}} { $ctrl_f.controls_quick_step configure -image ::ICONS::16::player_pause - } { + } else { $ctrl_f.controls_quick_step configure -image ::ICONS::16::goto2 } } @@ -3796,14 +3825,14 @@ class Simulator_GUI { ## Change image on button "Animate" (from "Pause" to "Right arrow" or backwards) # @return void public method invert_animate_button {} { - if {!$gui_initialized || !$sim_enabled} {return} + if {!$sim_gui_gui_initialized || !$sim_enabled} {return} # Determinate ID of the current image set image [$ctrl_f.controls_animate cget -image] # Change image if {$image == {::ICONS::16::1rightarrow}} { $ctrl_f.controls_animate configure -image ::ICONS::16::player_pause - } { + } else { $ctrl_f.controls_animate configure -image ::ICONS::16::1rightarrow } } @@ -3811,14 +3840,14 @@ class Simulator_GUI { ## Change image on button "Run" (from "Pause" to "Double right arrow" or backwards) # @return void public method invert_run_button {} { - if {!$gui_initialized || !$sim_enabled} {return} + if {!$sim_gui_gui_initialized || !$sim_enabled} {return} # Determinate ID of the current image set image [$ctrl_f.controls_run cget -image] # Change image if {$image == {::ICONS::16::2rightarrow}} { $ctrl_f.controls_run configure -image ::ICONS::16::player_pause - } { + } else { $ctrl_f.controls_run configure -image ::ICONS::16::2rightarrow } } @@ -3826,11 +3855,11 @@ class Simulator_GUI { ## Set state of button "StepBack" on simulator control panel # @return void public method stepback_button_set_ena {bool} { - if {!$gui_initialized} {return} + if {!$sim_gui_gui_initialized} {return} if {$bool} { set state {normal} - } { + } else { set state {disabled} } $ctrl_f.controls_stepback configure -state $state @@ -3839,7 +3868,7 @@ class Simulator_GUI { ## Disable simulator control panel (shoud be called after simulator engine disengagement) # @return void public method sim_disable {} { - if {!$gui_initialized} {return} + if {!$sim_gui_gui_initialized} {return} set sim_enabled 0 ;# Clear enabled flag @@ -3877,7 +3906,7 @@ class Simulator_GUI { ## Enable simulator control panel (shoud be called after simulator engine engagement) # @return void public method sim_enable {} { - if {!$gui_initialized} {CreateSimulatorGUI} + if {!$sim_gui_gui_initialized} {CreateSimulatorGUI} set sim_enabled 1 ;# Set enabled flag @@ -3915,7 +3944,12 @@ class Simulator_GUI { # @parm String text - text to display # @return void public method sim_txt_output {txt} { - tk_messageBox -title [mc "Simulator"] -type ok -message $txt + tk_messageBox \ + -parent . \ + -icon info \ + -type ok \ + -message $txt \ + -title [mc "Simulator"] } ## Focus on the given target entry widget if the current insertion index is equivalent to the end index @@ -3944,10 +3978,10 @@ class Simulator_GUI { focus $target_entry } - ## Get list of avaliable SFRs + ## Get list of available SFRs # @return List - {{dec_addr reg_name} ...} public method simulator_get_sfrs {} { - if {!$gui_initialized} {CreateSimulatorGUI} + if {!$sim_gui_gui_initialized} {CreateSimulatorGUI} return $sf_registers } @@ -3967,15 +4001,15 @@ class Simulator_GUI { if {$bool} { if {[$widget cget -font] == $smallfont} { set bg $small_color - } { + } else { set bg $name_color } set fg {#FFFFFF} - } { - set bg {#EEEEEE} + } else { + set bg ${::COMMON_BG_COLOR} if {[$widget cget -font] == $smallfont} { set fg $small_color - } { + } else { set fg $name_color } } @@ -3984,3 +4018,7 @@ class Simulator_GUI { $widget configure -bg $bg -fg $fg } } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/stackmonitor.tcl b/lib/simulator/stackmonitor.tcl index 8f83ab2..b51fabb 100755..100644 --- a/lib/simulator/stackmonitor.tcl +++ b/lib/simulator/stackmonitor.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 _STACKMONITOR_TCL ] } { +set _STACKMONITOR_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION @@ -31,20 +36,20 @@ class StackMonitor { ## COMMON common push_value {} ;# String: Value to PUSH onto the stack by user - common count 0 ;# Int: Counter of intances + common stack_mon_count 0 ;# Int: Counter of intances common geometry ${::CONFIG(STACK_MON_GEOMETRY)} ;# Geometry: Last window geometry common collapsed ${::CONFIG(STACK_MON_COLLAPSED)};# Bool: Bottom bar hidden # Font for the text widget representing the stack (bold) - common font0 [font create \ - -family $::DEFAULT_FIXED_FONT \ - -size -12 \ - -weight bold \ + common font0 [font create \ + -family $::DEFAULT_FIXED_FONT \ + -size [expr {int(-12 * $::font_size_factor)}] \ + -weight bold \ ] # Font for the text widget representing the stack (normal) - common font1 [font create \ - -family $::DEFAULT_FIXED_FONT \ - -size -12 \ - -weight normal \ + common font1 [font create \ + -family $::DEFAULT_FIXED_FONT \ + -size [expr {int(-12 * $::font_size_factor)}] \ + -weight normal \ ] ## PRIVATE @@ -64,8 +69,8 @@ class StackMonitor { constructor {} { # Increment counter of object instances - incr count - set obj_idx $count + incr stack_mon_count + set obj_idx $stack_mon_count } destructor { @@ -84,8 +89,8 @@ class StackMonitor { set dialog_opened 1 # Create dialog window - set win [toplevel .stack_monitor$count -class {Interrupt monitor} -bg {#EEEEEE}] - incr count + set win [toplevel .stack_monitor${stack_mon_count} -class {Interrupt monitor} -bg ${::COMMON_BG_COLOR}] + incr stack_mon_count # Create window frames (main frame and status bar, etc.) set top_frame [frame $win.top_frame] @@ -106,19 +111,19 @@ class StackMonitor { -font $font0 -width 27 \ -justify left -anchor w -background {#DDDDDD} \ -bd 0 -text [mc "Addr HH Dec Binary Oct A"] \ - ] - pack $values_txt -fill y -expand 1 + ] -anchor w -fill x + pack $values_txt -fill both -expand 1 $values_txt tag configure tag_general -background {#CCCCFF} $values_txt tag configure tag_subprog -background {#CCFFCC} $values_txt tag configure tag_interrupt -background {#FFCCCC} bind $values_txt <ButtonRelease-3> {break} bind $values_txt <<Selection>> "false_selection $values_txt; break" # Scrollbar - pack $left_frame -side left -fill y -expand 1 + pack $left_frame -side left -fill both -expand 1 pack [ttk::scrollbar $top_frame.scrollbar \ -command "$values_txt yview" \ -orient vertical \ - ] -side right -fill y -expand 1 + ] -side right -fill y ## Stack pointer @@ -166,7 +171,7 @@ class StackMonitor { pack $col_exp_button -side right -padx 5 # Pack frames except for the bottom bar (with legend) - pack $top_frame -fill y -expand 1 + pack $top_frame -fill both -expand 1 pack $bottom_frame -anchor w -fill x ## Create bottom bar (with legend) @@ -178,7 +183,7 @@ class StackMonitor { pack [label $tool_frame.lf.sl1 -text [mc "Subprogram"] -font $font0 -bg {#CCFFCC}] -side left -fill y -padx 3 pack [label $tool_frame.lf.il1 -text [mc "Interrupt"] -font $font0 -bg {#FFCCCC}] -side left -fill y - # Show or keep the bottom bar hidden acording to previous session + # Show or keep the bottom bar hidden according to previous session if {!$collapsed} { set collapsed [expr {!$collapsed}] stack_monitor_col_exp @@ -187,7 +192,8 @@ class StackMonitor { # Set window attributes wm iconphoto $win ::ICONS::16::kcmmemory_ST - wm title $win [mc "Stack - %s - MCU 8051 IDE" [string trim $this {:}]] + wm title $win [mc "Stack - %s - MCU 8051 IDE" [$this cget -projectName]] + wm minsize $win 225 90 if {$geometry != {}} { wm geometry $win $geometry } @@ -313,7 +319,7 @@ class StackMonitor { if {$collapsed} { set image 2downarrow pack forget $tool_frame - } { + } else { set image 2uparrow pack $tool_frame -fill y -anchor nw } @@ -381,7 +387,7 @@ class StackMonitor { } # Create toplevel window - set dlg [toplevel .manual_push${obj_idx} -class {Push value onto stack} -bg {#EEEEEE}] + set dlg [toplevel .manual_push${obj_idx} -class {Push value onto stack} -bg ${::COMMON_BG_COLOR}] # Create label, entryBox and horizontal separator pack [label $dlg.lbl -text [mc "Push value onto stack (HEX)"]] -fill x -anchor w -padx 5 @@ -411,7 +417,7 @@ class StackMonitor { -compound left \ -image ::ICONS::16::down0 \ -command "$this stack_monitor_manual_push_val" \ - ] -side left + ] -side left -padx 2 pack [ttk::button $buttonFrame.cancel \ -width 5 \ -text [mc "Close"] \ @@ -420,18 +426,19 @@ class StackMonitor { -command " grab release $dlg destroy $dlg" \ - ] -side left + ] -side left -padx 2 pack $buttonFrame -side right -padx 5 # Set window attributes wm iconphoto $dlg ::ICONS::16::kcmmemory_ST wm title $dlg [mc "Push value onto stack."] wm minsize $dlg 200 60 + wm transient $dlg $win wm protocol $dlg WM_DELETE_WINDOW " grab release $dlg destroy $dlg" - raise $dlg update + raise $dlg focus $dlg.ent } @@ -472,7 +479,7 @@ class StackMonitor { if {$enabled} { set state {normal} - } { + } else { set state {disabled} } @@ -517,3 +524,7 @@ class StackMonitor { $values_txt configure -state disabled } } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/stopwatch.tcl b/lib/simulator/stopwatch.tcl index 407cdd3..353ac41 100755..100644 --- a/lib/simulator/stopwatch.tcl +++ b/lib/simulator/stopwatch.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 _STOPWATCH_TCL ] } { +set _STOPWATCH_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Stopwatch timer for MCU simulator @@ -28,7 +33,7 @@ class Stopwatch { ## Class variables - common count 0 ;# Int: Counter of class instances + common stopw_count 0 ;# Int: Counter of class instances # List: Short names of stopwatch entries common stats_keys { US CC IC @@ -43,16 +48,6 @@ class Stopwatch { {Subprogram calls} {RET} {RETI} {Breakpoints} } - # Normal font (for entry boxes) - common normal_font [font create \ - -family Helvetica \ - -size -12 -weight normal\ - ] - # Bold font (for entry boxes) - common bold_font [font create \ - -family Helvetica \ - -size -12 -weight bold \ - ] ## Private varibales private variable win ;# Widget: Dialog window @@ -68,15 +63,16 @@ class Stopwatch { constructor {} { # Configure ttk styles - if {!$count} { + if {!$stopw_count} { ttk::style configure Stopwatch.TEntry -fieldreadonlybackground {#F8F8F8} ttk::style configure Stopwatch_Focused_D.TEntry -fieldbackground {#AAAAFF} -fieldreadonlybackground {#AAAAFF} + ttk::style configure Stopwatch_Focused_D_Invalid.TEntry -fieldbackground {#AAAAFF} -foreground {#FF0000} ttk::style configure Stopwatch_Focused_I.TEntry -fieldbackground {#DDDDFF} -fieldreadonlybackground {#DDDDFF} } # Increment counter of object instances - set obj_idx $count - incr count + set obj_idx $stopw_count + incr stopw_count # Restore configuration from the previous session set i 0 @@ -116,7 +112,7 @@ class Stopwatch { # @return void public method stopwatch_invoke_dialog {} { if {$dialog_opened} {return} - set win [toplevel .stopwatch$obj_idx -class {Stopwatch} -bg {#EEEEEE}] + set win [toplevel .stopwatch$obj_idx -class {Stopwatch} -bg ${::COMMON_BG_COLOR}] set dialog_opened 1 set stopwatch_on 1 @@ -126,11 +122,15 @@ class Stopwatch { bind $win <Control-Key-q> "destroy $win; break" bindtags $win [list $win Toplevel all .] - wm title $win "[mc {Stopwatch}] - [string trim $this {:}] - MCU 8051 IDE" + wm title $win "[mc {Stopwatch}] - [$this cget -projectName] - MCU 8051 IDE" wm iconphoto $win ::ICONS::22::history wm protocol $win WM_DELETE_WINDOW "$this stopwatch_close" + wm resizable $win 0 0 + update catch { - wm geometry $win $window_geometry + wm geometry $win [regsub {^\=?\d+x\d+} $window_geometry \ + [regsub {\+\d+\+\d+$} [wm geometry $win] {}] \ + ] } } @@ -146,18 +146,18 @@ class Stopwatch { set stop_a 0 foreach key $stats_keys { # Overall - set org_O [subst "\$::Stopwatch::text_vars${obj_idx}($key,O)"] + set org_O [subst -nocommands "\$::Stopwatch::text_vars${obj_idx}($key,O)"] set ::Stopwatch::text_vars${obj_idx}($key,O) $run_statistics($i) # Current if {$stopwatch_on} { incr ::Stopwatch::text_vars${obj_idx}($key,C) [expr {$run_statistics($i) - $org_O}] - set stop_a [subst "\$::Stopwatch::text_vars${obj_idx}($key,S)"] + set stop_a [subst -nocommands "\$::Stopwatch::text_vars${obj_idx}($key,S)"] # Conditional stop - if {$stop_a && $stop_a <= [subst "\$::Stopwatch::text_vars${obj_idx}($key,C)"]} { + if {$stop_a && $stop_a <= [subst -nocommands "\$::Stopwatch::text_vars${obj_idx}($key,C)"]} { stopwatch_start_stop - if {[subst "\$::Stopwatch::text_vars${obj_idx}(stop_sim)"]} { + if {[subst -nocommands "\$::Stopwatch::text_vars${obj_idx}(stop_sim)"]} { if {[$this sim_run_in_progress]} { $this sim_run } elseif {[$this sim_anim_in_progress]} { @@ -232,7 +232,9 @@ class Stopwatch { # - Label "STOPPED" set label_stopped_lbl [label $top_frame.label_stopped_lbl \ -font [font create \ - -family {Helvetica} -size -21 -weight bold \ + -family {Helvetica} \ + -size -21 \ + -weight bold \ ] -text {STOPPED} -fg {#FF0000} -pady 0 \ ] @@ -299,6 +301,8 @@ class Stopwatch { bind $entrybox <Key-Down> "$this stopwatch_entry_key $key $tp down; break" bind $entrybox <Key-Left> "$this stopwatch_entry_key $key $tp left; break" bind $entrybox <Key-Right> "$this stopwatch_entry_key $key $tp right; break" + bind $entrybox <Shift-Key-Left> "continue" + bind $entrybox <Shift-Key-Right> "continue" bind $entrybox <Key-Tab> "$this stopwatch_entry_key $key $tp tab; break" if {!$::MICROSOFT_WINDOWS} { bind $entrybox <Key-ISO_Left_Tab> "$this stopwatch_entry_key $key $tp stab; break" @@ -356,7 +360,7 @@ class Stopwatch { $entryboxes($key,C) configure -style Stopwatch_Focused_I.TEntry $entryboxes($key,S) configure -style Stopwatch_Focused_I.TEntry $entryboxes($key,$type) configure -style Stopwatch_Focused_D.TEntry - } { + } else { $entryboxes($key,$type) selection clear $entryboxes($key,C) configure -style TEntry $entryboxes($key,S) configure -style TEntry @@ -459,11 +463,11 @@ class Stopwatch { # Adjust foreground color for entrybox in column "Current" if {$type == {C} && $string != {}} { - set max [subst "\$::Stopwatch::text_vars${obj_idx}($key,S)"] - if {$max && $string >= $max} { - $entryboxes($key,C) configure -fg {#FF0000} -font $bold_font - } { - $entryboxes($key,C) configure -fg {#000000} -font $normal_font + set max [subst -nocommands "\$::Stopwatch::text_vars${obj_idx}($key,S)"] + if {$max != {} && $max != 0 && $string >= $max} { + $entryboxes($key,C) configure -style Stopwatch_Focused_D_Invalid.TEntry + } else { + $entryboxes($key,C) configure -style Stopwatch_Focused_D.TEntry } } @@ -471,7 +475,7 @@ class Stopwatch { if {$type == {C} || $type == {S}} { if {$string != {} && $string != 0} { $clearbuttons($key,$type) configure -state normal - } { + } else { $clearbuttons($key,$type) configure -state disabled } } @@ -500,13 +504,13 @@ class Stopwatch { # @parm Bool text__html - File type (1 == Plain text; 0 == XHTML) # @return void public method stopwatch_save {text__html} { - # Determinate list of avaliable file extensions + # Determinate list of available file extensions if {$text__html} { set filetypes [list \ [list [::mc "Text files"] {*.txt}] \ [list [::mc "All files"] {*}] \ ] - } { + } else { set filetypes [list \ [list [::mc "HTML files"] {*.html}] \ [list [::mc "All files"] {*}] \ @@ -519,7 +523,7 @@ class Stopwatch { -directory [$this cget -projectPath] \ -master $win -filetypes [mc $filetypes] \ -defaultmask 0 -multiple 0 \ - -initialfile [string trim $this {:}] + -initialfile [$this cget -projectName] # Open file after press of OK button ::fsd setokcmd " @@ -544,7 +548,7 @@ class Stopwatch { if {![string length [file extension $filename]]} { if {$text__html} { append filename {.txt} - } { + } else { append filename {.html} } } @@ -559,7 +563,7 @@ class Stopwatch { -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 @@ -570,8 +574,8 @@ class Stopwatch { # Open the specified file if {[catch { - set file [open $filename w 420] - }]} { + set file [open $filename w 0640] + }]} then { tk_messageBox \ -parent . \ -type ok \ @@ -584,34 +588,33 @@ class Stopwatch { # Save as plain text if {$text__html} { set text {} - append text [string repeat { } 33] "Current" \ - [string repeat { } 10] "Stop after" \ - [string repeat { } 13] "Overall" + append text [string repeat { } 37] [mc "Current"] \ + [string repeat { } 10] [mc "Stop after"] \ + [string repeat { } 13] [mc "Overall"] puts $file $text foreach text $stats_names key $stats_keys { set text [mc $text] - append text [string repeat { } [expr {20 - [string length $text]}]] + append text [string repeat { } [expr {24 - [string length $text]}]] foreach subkey {C S O} { - set val [subst "\$::Stopwatch::text_vars${obj_idx}($key,$subkey)"] + set val [subst -nocommands "\$::Stopwatch::text_vars${obj_idx}($key,$subkey)"] append text [string repeat { } [expr {20 - [string length $val]}]] $val } puts $file $text } - puts $file "\nProject: [string trim $this {:}]" - puts $file "Date: [clock format [clock seconds] -format {%D}]" - puts $file "Generated by ${::APPNAME} ( http://mcu8051ide.sf.net )" + puts $file "\n[mc {Project:}] [$this cget -projectName]" + puts $file [mc "Generated by %s" "${::APPNAME} ( http://mcu8051ide.sf.net )"] # Save as XHTML - } { + } else { puts $file "<?xml version='1.0' encoding='utf-8' standalone='no'?>" puts $file "<!DOCTYPE html PUBLIC" puts $file "\t'-//W3C//DTD XHTML 1.1//EN'" puts $file "\t'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>" puts $file "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>" - puts $file "<!--\n\tCreator: ${::APPNAME}\n\tDate: [clock format [clock seconds] -format {%D}]\n-->" + puts $file "<!-- Creator: ${::APPNAME} -->" puts $file "\t<head>" - puts $file "\t\t<title>[string trim $this {:}] stopwatch state [clock format [clock seconds] -format {%D}]</title>" + puts $file "\t\t<title>[$this cget -projectName] stopwatch state [clock format [clock seconds] -format {%D}]</title>" puts $file "\t\t<meta http-equiv=\"Content-Type\" content=\"application/xhtml+xml; charset=UTF-8\" />" puts $file "\t\t<meta name=\"Generator\" content=\"${::APPNAME}\" />" puts $file "\t\t<style type=\"text/css\">" @@ -639,7 +642,7 @@ class Stopwatch { puts $file "\t\t<table style=\"border-width: 1px\">" puts $file "\t\t\t<col /><col /><col /><col />" puts $file "\t\t\t<thead>" - puts $file "\t\t\t\t<tr class=\"sw_header\"><th> </th><th>Current</th><th>Stop after</th><th>Overall</th></tr>" + puts $file "\t\t\t\t<tr class=\"sw_header\"><th> </th><th>[mc {Current}]</th><th>[mc {Stop after}]</th><th>[mc {Overall}]</th></tr>" puts $file "\t\t\t</thead>" puts $file "\t\t\t<tbody>" foreach text $stats_names key $stats_keys { @@ -647,7 +650,7 @@ class Stopwatch { puts $file "\t\t\t\t\t<td class=\"sw_header\">[mc $text]</td>" foreach subkey {C S O} { puts -nonewline $file "\t\t\t\t\t<td class=\"sw_$subkey\">" - puts -nonewline $file [subst "\$::Stopwatch::text_vars${obj_idx}($key,$subkey)"] + puts -nonewline $file [subst -nocommands "\$::Stopwatch::text_vars${obj_idx}($key,$subkey)"] puts $file "</td>" } puts $file "\t\t\t\t</tr>" @@ -656,9 +659,8 @@ class Stopwatch { puts $file "\t\t</table>" puts $file "\t\t<p>" - puts $file "\t\t\tProject: <b>[string trim $this {:}]</b><br />" - puts $file "\t\t\tDate: <b>[clock format [clock seconds] -format {%D}]</b><br />" - puts $file "\t\t\tGenerated by ${::APPNAME} ( <a href=\"http://mcu8051ide.sf.net\">http://mcu8051ide.sf.net</a> )" + puts $file "\t\t\t[mc {Project:}] <b>[$this cget -projectName]</b><br />" + puts $file "\t\t\t[mc {Generated by %s} "${::APPNAME} ( <a href=\"http://mcu8051ide.sf.net\">http://mcu8051ide.sf.net</a> )"]" puts $file "\t\t</p>" puts $file "\t</body>" @@ -680,7 +682,7 @@ class Stopwatch { local_status_tip $start_stop_button [mc "Stop"] pack forget $label_stopped_lbl # Stop - } { + } else { $start_stop_button configure -image ::ICONS::22::player_play local_status_tip $start_stop_button [mc "Start"] pack $label_stopped_lbl -side right -pady 0 -ipady 0 @@ -691,12 +693,16 @@ class Stopwatch { # @return void public method stopwatch_get_config {} { set result $window_geometry - lappend result [subst "\$::Stopwatch::text_vars${obj_idx}(stop_sim)"] + lappend result [subst -nocommands "\$::Stopwatch::text_vars${obj_idx}(stop_sim)"] foreach key $stats_keys { - lappend result [subst "\$::Stopwatch::text_vars${obj_idx}($key,S)"] + lappend result [subst -nocommands "\$::Stopwatch::text_vars${obj_idx}($key,S)"] } return $result } } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/uart_monitor.tcl b/lib/simulator/uart_monitor.tcl new file mode 100644 index 0000000..28d3b48 --- /dev/null +++ b/lib/simulator/uart_monitor.tcl @@ -0,0 +1,886 @@ +#!/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 _UART_MONITOR_TCL ] } { +set _UART_MONITOR_TCL _ +# <<< File inclusion guard + +# -------------------------------------------------------------------------- +# DESCRIPTION +# UART monitor +# ------------------------------------------------------------------------- + +class UARTMonitor { + + common geometry ${::CONFIG(UART_MON_GEOMETRY)} ;# Last window geometry + common uart_mon_count 0 ;# Counter of intances + + # Font: Tiny normal font + common tiny_font [font create \ + -family {helvetica} \ + -size [expr {int(-9 * $::font_size_factor)}] \ + -weight {normal} \ + ] + # Font: Big bold font + common big_font [font create \ + -family {helvetica} \ + -size [expr {int(-14 * $::font_size_factor)}] \ + -weight {bold} \ + ] + # Font: Normal font + common normal_font [font create \ + -family {helvetica} \ + -size [expr {int(-11 * $::font_size_factor)}] \ + -weight {normal} \ + ] + # Font: + common normal_fixed_font [font create \ + -family $::DEFAULT_FIXED_FONT \ + -size [expr {int(-11 * $::font_size_factor)}] \ + -weight {normal} \ + ] + # Font: + common bold_fixed_font [font create \ + -family $::DEFAULT_FIXED_FONT \ + -size [expr {int(-11 * $::font_size_factor)}] \ + -weight {bold} \ + ] + + common rect_size 12 + common empty_fill {#888888} + common empty_outline {#AAAAAA} + + common MAX_G_LOG_LENGTH 100 ;# Int: + common MAX_D_LOG_LENGTH 100 ;# Int: + + private variable dialog_opened 0 ;# Bool: Dialog window opened + private variable win ;# Widget: Dialog window + + private variable status_bar 1 + private variable rxd_frame + private variable txd_frame + + private variable general_log + private variable general_log_length + private variable data_transfer_log + private variable data_transfer_log_length + private variable canvas + private variable bit_rect + private variable uart_value_label + private variable shift_reg + private variable shift_reg_bits_written + private variable bit + + private variable graph_position + private variable graph_prev_states + private variable graph_elements + + constructor {} { + array set data_transfer_log_length { + r 0 t 0 + } + array set general_log_length { + r 0 t 0 + } + array set shift_reg { + r 0 t 0 + } + array set shift_reg_bits_written { + r 0 t 0 + } + array set graph_position { + r 0 t 0 + } + array set graph_prev_states { + t 1 r 1 + } + array set graph_elements { + t {} r {} + } + array set bit { + fe 0 sm0 0 + sm1 0 sm2 0 + ren 0 ti 0 + ri 0 smod1 0 + tclk 0 rclk 0 + } + } + + destructor { + uart_monitor_close + } + + ## Invoke interrupt monitor window + # @return void + public method uart_monitor_invoke_dialog {} { + set win [toplevel .uartmonitor${uart_mon_count}] + incr uart_mon_count + + set main_frame [frame $win.main_frame] + set status_bar [label $win.status_bar] + + # -------------------------------------------------------------- + # RECEIVER PART + # -------------------------------------------------------------- + grid [label $main_frame.r_header_lbl \ + -font $big_font \ + -text [mc "RxD line"] \ + ] -row 0 -column 1 -sticky w -padx 0 -columnspan 2 -sticky we + # Mode: + grid [label $main_frame.r_mode_lbl \ + -text [mc "Mode:"] \ + ] -row 1 -column 1 -sticky w -padx 5 + set uart_value_label(r_mode) [label $main_frame.r_mode_v_lbl] + grid $uart_value_label(r_mode) -row 1 -column 2 -sticky w -padx 5 + # Line function: + grid [label $main_frame.r_lf_lbl \ + -text [mc "Line function:"] \ + ] -row 2 -column 1 -sticky w -padx 5 + set uart_value_label(r_lf) [label $main_frame.r_lf_v_lbl] + grid $uart_value_label(r_lf) -row 2 -column 2 -sticky w -padx 5 + # BR Generator: + grid [label $main_frame.r_brg_lbl \ + -text [mc "BR Generator:"] \ + ] -row 3 -column 1 -sticky w -padx 5 + set uart_value_label(r_brg) [label $main_frame.r_brg_v_lbl] + grid $uart_value_label(r_brg) -row 3 -column 2 -sticky w -padx 5 + # BRG prescaler: + grid [label $main_frame.r_brgp_lbl \ + -text [mc "BRG prescaler:"] \ + ] -row 4 -column 1 -sticky w -padx 5 + set uart_value_label(r_brgp) [label $main_frame.r_brgp_v_lbl] + grid $uart_value_label(r_brgp) -row 4 -column 2 -sticky w -padx 5 + # Resulting bdps: + grid [label $main_frame.r_rbdps_lbl \ + -text [mc "Resulting bdps:"] \ + ] -row 5 -column 1 -sticky w -padx 5 + set uart_value_label(r_rbdps) [label $main_frame.r_rbdps_v_lbl] + grid $uart_value_label(r_rbdps) -row 5 -column 2 -sticky w -padx 5 + # State: + grid [label $main_frame.r_state_lbl \ + -text [mc "State:"] \ + ] -row 6 -column 1 -sticky w -padx 5 + set uart_value_label(r_state) [label $main_frame.r_state_v_lbl] + grid $uart_value_label(r_state) -row 6 -column 2 -sticky w -padx 5 + + set canvas(r) [canvas $main_frame.r_canvas \ + -width 240 \ + -height 175 \ + -bg $::COMMON_BG_COLOR \ + -highlightthickness 0 \ + ] + fill_canvas r + grid $canvas(r) -row 8 -column 1 -columnspan 2 -sticky we + + set data_transfer_log(r) [text $main_frame.r_data_transfer_log \ + -height 4 \ + -width 0 \ + -bd 0 \ + -bg $::COMMON_BG_COLOR \ + -highlightthickness 0 \ + -font $normal_fixed_font \ + -wrap none \ + -xscrollcommand [list $main_frame.r_stl_scrollbar set] \ + ] + $data_transfer_log(r) tag configure tag_bold -font $bold_fixed_font + $data_transfer_log(r) insert end [mc "HEX \nDEC \nOCT \nASCII "] + $data_transfer_log(r) configure -state disabled + for {set i 1} {$i <= 4} {incr i} { + $data_transfer_log(r) tag add tag_bold $i.0 $i.5 + } + grid $data_transfer_log(r) -row 9 -column 1 -columnspan 2 -sticky we + grid [ttk::scrollbar $main_frame.r_stl_scrollbar \ + -orient horizontal \ + -command [list $data_transfer_log(r) xview] \ + ] -row 10 -column 1 -columnspan 2 -sticky we + + set general_log_frame [frame $main_frame.r_general_log_frame] + set general_log(r) [text $general_log_frame.general_log \ + -height 4 \ + -width 0 \ + -yscrollcommand [list $general_log_frame.scrollbar set] \ + -state disabled \ + ] + set general_log_sc_bar [ttk::scrollbar $general_log_frame.scrollbar \ + -orient vertical \ + -command [list $general_log(r) yview] \ + ] + pack $general_log_sc_bar -side right -fill y + pack $general_log(r) -side left -fill both -expand 1 + grid $general_log_frame -row 11 -column 1 -columnspan 2 -sticky wens -pady 2 + + # -------------------------------------------------------------- + # TRANSMITTER PART + # -------------------------------------------------------------- + grid [label $main_frame.t_header_lbl \ + -font $big_font \ + -text [mc "TxD line"] \ + ] -row 0 -column 4 -sticky w -padx 0 -columnspan 2 -sticky we + # Mode: + grid [label $main_frame.t_mode_lbl \ + -text [mc "Mode:"] \ + ] -row 1 -column 4 -sticky w -padx 5 + set uart_value_label(t_mode) [label $main_frame.t_mode_v_lbl] + grid $uart_value_label(t_mode) -row 1 -column 5 -sticky w -padx 5 + # Line function: + grid [label $main_frame.t_lf_lbl \ + -text [mc "Line function:"] \ + ] -row 2 -column 4 -sticky w -padx 5 + set uart_value_label(t_lf) [label $main_frame.t_lf_v_lbl] + grid $uart_value_label(t_lf) -row 2 -column 5 -sticky w -padx 5 + # BR Generator: + grid [label $main_frame.t_brg_lbl \ + -text [mc "BR Generator:"] \ + ] -row 3 -column 4 -sticky w -padx 5 + set uart_value_label(t_brg) [label $main_frame.t_brg_v_lbl] + grid $uart_value_label(t_brg) -row 3 -column 5 -sticky w -padx 5 + # BRG prescaler: + grid [label $main_frame.t_brgp_lbl \ + -text [mc "BRG prescaler:"] \ + ] -row 4 -column 4 -sticky w -padx 5 + set uart_value_label(t_brgp) [label $main_frame.t_brgp_v_lbl] + grid $uart_value_label(t_brgp) -row 4 -column 5 -sticky w -padx 5 + # Resulting bdps: + grid [label $main_frame.t_rbdps_lbl \ + -text [mc "Resulting bdps:"] \ + ] -row 5 -column 4 -sticky w -padx 5 + set uart_value_label(t_rbdps) [label $main_frame.t_rbdps_v_lbl] + grid $uart_value_label(t_rbdps) -row 5 -column 5 -sticky w -padx 5 + # State: + grid [label $main_frame.t_state_lbl \ + -text [mc "State:"] \ + ] -row 6 -column 4 -sticky w -padx 5 + set uart_value_label(t_state) [label $main_frame.t_state_v_lbl] + grid $uart_value_label(t_state) -row 6 -column 5 -sticky w -padx 5 + + set canvas(t) [canvas $main_frame.t_canvas \ + -width 240 \ + -height 175 \ + -bg $::COMMON_BG_COLOR \ + -highlightthickness 0 \ + ] + fill_canvas t + grid $canvas(t) -row 8 -column 4 -columnspan 2 -sticky nw + + set data_transfer_log(t) [text $main_frame.t_data_transfer_log \ + -height 4 \ + -width 0 \ + -bd 0 \ + -bg $::COMMON_BG_COLOR \ + -highlightthickness 0 \ + -font $normal_fixed_font \ + -wrap none \ + -xscrollcommand [list $main_frame.t_stl_scrollbar set] \ + ] + $data_transfer_log(t) tag configure tag_bold -font $bold_fixed_font + $data_transfer_log(t) insert end [mc "HEX \nDEC \nOCT \nASCII "] + $data_transfer_log(t) configure -state disabled + for {set i 1} {$i <= 4} {incr i} { + $data_transfer_log(t) tag add tag_bold $i.0 $i.5 + } + grid $data_transfer_log(t) -row 9 -column 4 -columnspan 2 -sticky we + grid [ttk::scrollbar $main_frame.t_stl_scrollbar \ + -orient horizontal \ + -command [list $data_transfer_log(t) xview] \ + ] -row 10 -column 4 -columnspan 2 -sticky we + + set general_log_frame [frame $main_frame.t_general_log_frame] + set general_log(t) [text $general_log_frame.general_log \ + -height 4 \ + -width 0 \ + -yscrollcommand [list $general_log_frame.scrollbar set] \ + -state disabled \ + ] + set general_log_sc_bar [ttk::scrollbar $general_log_frame.scrollbar \ + -orient vertical \ + -command [list $general_log(t) yview] \ + ] + pack $general_log_sc_bar -side right -fill y + pack $general_log(t) -side left -fill both -expand 1 + grid $general_log_frame -row 11 -column 4 -columnspan 2 -sticky wens -pady 2 + + grid [ttk::separator $main_frame.sep -orient vertical] -row 0 -column 3 -rowspan 12 -padx 2 -sticky ns + pack $main_frame -fill y -padx 2 -pady 2 -anchor nw -expand 1 + + # Pack main frame and create bottom frame + pack $main_frame -fill both -expand 1 + pack [ttk::separator $win.sep -orient horizontal] \ + -fill x -pady 1 + pack $status_bar -side left -fill x -padx 5 + pack [ttk::button $win.close_but \ + -text [mc "Close"] \ + -compound left \ + -command [list $this uart_monitor_close] \ + -image ::ICONS::16::button_cancel \ + ] -side right -pady 2 -padx 5 + uart_monitor_set_status_tip $win.close_but [mc "Close this dialog window"] + + # Set window attributes + wm iconphoto $win ::ICONS::16::__blockdevice + wm title $win "[mc {UART Monitor}] - [$this cget -projectName] - MCU 8051 IDE" + wm minsize $win 500 500 + wm resizable $win 1 1 + wm protocol $win WM_DELETE_WINDOW [list $this uart_monitor_close] + bindtags $win [list $win Toplevel all .] + + update idletasks + if {$geometry != {}} { + regsub {\+\d+\+\d+} $geometry [format {+%d+%d} [winfo width $win] [winfo height $win]] geometry + wm geometry $win $geometry + } + + set dialog_opened 1 + +# #< DEBUG !!! +# uart_monitor_byte_received 100 111 132 +# uart_monitor_byte_transmitted 101 112 122 +# + uart_monitor_refresh_configuration + uart_monitor_write_to_log r "THIS TOOL IS NOT FUNCTIONAL YET!" + uart_monitor_write_to_log t "THIS TOOL IS NOT FUNCTIONAL YET!" +# +# uart_monitor_shift_reg_input r 1 1 +# uart_monitor_shift_reg_input r 1 0 +# uart_monitor_shift_reg_input r 1 0 +# uart_monitor_shift_reg_input r 1 1 +# uart_monitor_shift_reg_input r 1 1 +# +# uart_monitor_shift_reg_input t 0 1 +# uart_monitor_shift_reg_input t 0 0 +# uart_monitor_shift_reg_input t 0 0 +# uart_monitor_shift_reg_input t 0 1 +# uart_monitor_shift_reg_input t 0 1 +# +# uart_monitor_update_sbuf r +# uart_monitor_update_sbuf t +# +# uart_monitor_graph_draw t {1 0 1 0 1} +# uart_monitor_graph_draw t {1 0 1 1 1} +# uart_monitor_graph_draw t {0 1 1 1 1} +# uart_monitor_graph_draw t {1 0 1 1 1} +# uart_monitor_graph_draw t {1 0 1 1 0} +# uart_monitor_graph_draw t {1 0 1 0 1} +# uart_monitor_graph_draw t {1 0 1 1 1} +# uart_monitor_graph_draw t {0 1 1 1 1} +# uart_monitor_graph_draw t {1 0 1 1 1} +# uart_monitor_graph_draw t {1 0 1 1 0} +# #> DEBUG !!! + } + + public method uart_monitor_close {} { + if {!$dialog_opened} { + return + } + + set geometry [wm geometry $win] + set dialog_opened 0 + + if {[winfo exists $win]} { + destroy $win + } + } + + ## Set status bar tip for certain widget + # @parm Widget widget - Some button or label ... + # @parm String text - Status tip + # @return void + private method uart_monitor_set_status_tip {widget text} { + bind $widget <Enter> [list $status_bar configure -text $text] + bind $widget <Leave> [list $status_bar configure -text {}] + } + + private method fill_canvas {side} { + set labels [list 8 7 6 5 4 3 2 1 0] + + set x 5 + set j 0 + for {set i 0} {$i < 10} {incr i} { + set y 20 + set bit_rect(s,$side,$i) [$canvas($side) create rectangle $x $y \ + [expr {$x + $rect_size}] [expr {$y + $rect_size}] \ + -fill $empty_fill -outline $empty_outline \ + ] + + if {($side == {r} && $i > 0 && $i < 10) || ($side == {t} && $i >= 0 && $i < 9)} { + if {$j == 1} { + incr x 3 + } + set y 50 + set bit_rect(b,$side,$j) [$canvas($side) create rectangle $x $y \ + [expr {$x + $rect_size}] [expr {$y + $rect_size}] \ + -fill $empty_fill -outline $empty_outline \ + ] + $canvas($side) create text \ + [expr {$x + ($rect_size / 2)}] \ + [expr {$y + ($rect_size / 2)}] \ + -text [lindex $labels $j] \ + -font $tiny_font + if {$j == 1} { + incr x -3 + } + incr j + } + + incr x $rect_size + incr x 2 + } + + $canvas($side) create text 5 5 -anchor nw -font $normal_font -text [mc "The shift register:"] + $canvas($side) create text 5 35 -anchor nw -font $normal_font -text "SBUF [string toupper $side]:" + + # -------------------------------------------------------------- + + if {$side == {r}} { + set graph_label [list \ + [mc "RxD"] \ + [mc "RI"] \ + [mc "ALE"] \ + [mc "SHIFT"] \ + [mc "SBUF"] \ + ] + } else { + set graph_label [list \ + [mc "TxD"] \ + [mc "TI"] \ + [mc "ALE"] \ + [mc "SHIFT"] \ + [mc "SBUF"] \ + ] + } + for {set y 0} {$y < 5} {incr y} { + set y_0 [expr {75 + $y * 20}] + set y_1 [expr {$y_0 + 15}] + + for {set x 45} {$x <= 235} {incr x 5} { + $canvas($side) create line $x $y_0 $x $y_1 -fill {#AAAAAA} -tags grid -dash . + } + + $canvas($side) create text 5 $y_0 -anchor nw -font $bold_fixed_font -text [lindex $graph_label $y] + + incr y_0 -3 + $canvas($side) create line 45 $y_0 235 $y_0 -fill {#AAAAAA} -tags grid + } + } + + public method uart_monitor_refresh_configuration {} { + if {!$dialog_opened} { + return + } + + set pcon [$this getSfrDEC $::Simulator_ENGINE::symbol(PCON)] + set scon [$this getSfrDEC $::Simulator_ENGINE::symbol(SCON)] + + set bit(fe) [$this sim_engine_get_FE] + set bit(sm0) [$this sim_engine_get_SM0] + set bit(sm1) [expr {$scon & 0x40}] + set bit(sm2) [expr {$scon & 0x20}] + set bit(ren) [expr {$scon & 0x10}] + set bit(ti) [expr {$scon & 0x02}] + set bit(ri) [expr {$scon & 0x01}] + + set bit(smod1) [expr {$pcon & 0x80}] + + if {[$this get_feature_available t2]} { + set bit(tclk) [$this getBit $::Simulator_ENGINE::symbol(TCLK)] + set bit(rclk) [$this getBit $::Simulator_ENGINE::symbol(RCLK)] + } else { + set bit(tclk) 0 + set bit(rclk) 0 + } + + ## Determinate mode of operation + # Mode 0 + if {!$bit(sm0) && !$bit(sm1)} { + set mode [mc "0 (8-bit Shift register)"] + # Mode 1 + } elseif {!$bit(sm0) && $bit(sm1)} { + set mode [mc "1 (8-bit UART)"] + # Mode 2 + } elseif {$bit(sm0) && !$bit(sm1)} { + set mode [mc "2 (9-bit UART)"] + # Mode 3 + } elseif {$bit(sm0) && $bit(sm1)} { + set mode [mc "3 (9-bit UART)"] + } + + ## Determinate line functions + if {!$bit(sm0) && !$bit(sm1)} { + set r_lf [mc "Data input/output"] + set t_lf [mc "Shift clock output"] + } else { + set r_lf [mc "Data input"] + set t_lf [mc "Data output"] + } + + ## Determinate source of baud rate clock + if {$bit(sm1)} { + if {$bit(rclk)} { + set r_brg [mc "Timer 2"] + } else { + set r_brg [mc "Timer 1"] + } + if {$bit(tclk)} { + set t_brg [mc "Timer 2"] + } else { + set t_brg [mc "Timer 1"] + } + } else { + set r_brg [mc "Master clock"] + set t_brg [mc "Master clock"] + } + + ## Determinate resulting baud rate + set r_rbdps [determinate_baud_rate t] + set t_rbdps [determinate_baud_rate t] + + ## Determinate state of the interface + set r_state [mc "WAITING"] + set t_state [mc "WAITING"] + + # -------------------------------------------------------------- + # RECEIVER PART + # -------------------------------------------------------------- + $uart_value_label(r_mode) configure -text $mode + $uart_value_label(r_lf) configure -text $r_lf + $uart_value_label(r_brg) configure -text $r_brg + $uart_value_label(r_rbdps) configure -text $r_rbdps + $uart_value_label(r_state) configure -text $r_state + + # -------------------------------------------------------------- + # TRANSMITTER PART + # -------------------------------------------------------------- + $uart_value_label(t_mode) configure -text $mode + $uart_value_label(t_lf) configure -text $t_lf + $uart_value_label(t_brg) configure -text $t_brg + $uart_value_label(t_rbdps) configure -text $t_rbdps + $uart_value_label(t_state) configure -text $t_state + } + + private method determinate_baud_rate {side} { + # RxD side + if {$side == {r}} { + # Timer 2 + if {$bit(rclk)} { + return [mc "Determinated by timer 2"] + + # Timer 1 + } else { + set tmod [$this getSfrDEC $::Simulator_ENGINE::symbol(PCON)] + if {$tmod & 0x40} { + return [mc "Unknown"] + } + set clock_f [expr {1000 * [$this getEngineClock] * (1 + ([$this get_X2] ? 1 : 0))}] + set mode [expr {($tmod & 0x30) >> 4}] + switch -- $mode { + 0 { + return [expr {$clock_f / 8192.0}] + } + 1 { + return [expr {$clock_f / 65536.0}] + } + 2 { + set th1 [$this getSfrDEC $::Simulator_ENGINE::symbol(TH1)] + return [expr {$clock_f / (256.0 - $th1)}] + } + 3 { + return 0 + } + } + } + + # TxD side + } else { + # Timer 2 + if {$bit(tclk)} { + return [mc "Determinated by timer 2"] + + # Timer 1 + } else { + set tmod [$this getSfrDEC $::Simulator_ENGINE::symbol(PCON)] + if {$tmod & 0x40} { + return [mc "Unknown"] + } + set clock_f [expr {1000 * [$this getEngineClock] * (1 + ([$this get_X2] ? 1 : 0))}] + set mode [expr {($tmod & 0x30) >> 4}] + switch -- $mode { + 0 { + return [expr {$clock_f / 8192.0}] + } + 1 { + return [expr {$clock_f / 65536.0}] + } + 2 { + set th1 [$this getSfrDEC $::Simulator_ENGINE::symbol(TH1)] + return [expr {$clock_f / (256.0 - $th1)}] + } + 3 { + return 0 + } + } + } + } + + return [mc "Unknown"] + } + + public method uart_monitor_update_prescaler {side value} { + if {!$dialog_opened} { + return + } + + $uart_value_label(${side}_brgp) configure -text $value + } + + public method uart_monitor_byte_received {args} { + if {!$dialog_opened} { + return + } + + foreach byte $args { + write_to_data_transfer_log r $byte + } + } + + public method uart_monitor_byte_transmitted {args} { + if {!$dialog_opened} { + return + } + + foreach byte $args { + write_to_data_transfer_log t $byte + } + } + + private method write_to_data_transfer_log {side byte} { + if {!$dialog_opened} { + return + } + + $data_transfer_log($side) configure -state normal + if {$data_transfer_log_length($side) == $MAX_D_LOG_LENGTH} { + for {set i 1} {$i < 5} {incr i} { + $data_transfer_log($side) delete $i.4 $i.6 + } + incr data_transfer_log_length($side) -1 + } + + set i [expr {6 + $data_transfer_log_length($side) * 4}] + + $data_transfer_log($side) insert 1.$i [format {%3X } $byte] + $data_transfer_log($side) insert 2.$i [format {%3d } $byte] + $data_transfer_log($side) insert 3.$i [format {%3o } $byte] + if {[string is print -strict [format {%c} $byte]]} { + $data_transfer_log($side) insert 4.$i [format { %c } $byte] + } else { + $data_transfer_log($side) insert 4.$i { } + } + $data_transfer_log($side) configure -state disabled + + incr data_transfer_log_length($side) + } + + public method uart_monitor_write_to_log {side text} { + if {!$dialog_opened} { + return + } + + $general_log($side) configure -state normal + if {$general_log_length($side) == $MAX_G_LOG_LENGTH} { + $general_log($side) delete 1.0 2.0 + $general_log($side) mark set {end-1l lineend} + } + + $general_log($side) insert insert $text + $general_log($side) insert insert "\n" + $general_log($side) see insert + $general_log($side) configure -state disabled + } + + public method uart_monitor_shift_reg_input {side right__left bit_val} { + if {!$dialog_opened} { + return + } + + incr shift_reg_bits_written($side) + if {$right__left} { + set shift_reg($side) [expr {($shift_reg($side) >> 1) | (($bit_val ? 1 : 0) << 9)}] + set start 0 + set end [expr {$shift_reg_bits_written($side) - 1}] + } else { + set shift_reg($side) [expr {0x3FF & (($shift_reg($side) << 1) | ($bit_val ? 1 : 0))}] + set start [expr {9 - $shift_reg_bits_written($side)}] + set end 9 + } + + for {set i $start} {$i <= $end} {incr i} { + if {$shift_reg($side) & (1 << (9 - $i))} { + set outline ${::BitMap::one_outline} + set fill ${::BitMap::one_fill} + } else { + set outline ${::BitMap::zero_outline} + set fill ${::BitMap::zero_fill} + } + + $canvas($side) itemconfigure $bit_rect(s,$side,$i) \ + -outline $outline \ + -fill $fill + } + } + public method uart_monitor_shift_reg_clear {side} { + if {!$dialog_opened} { + return + } + + for {set i 0} {$i < 9} {incr i} { + $canvas($side) itemconfigure $bit_rect(s,$side,$i) \ + -outline $empty_outline \ + -fill $empty_fill + } + set shift_reg($side) 0 + set shift_reg_bits_written($side) 0 + } + public method uart_monitor_update_sbuf {side} { + if {!$dialog_opened} { + return + } + + if {$side == {r}} { + set sbuf [$this getSfrDEC $::Simulator_ENGINE::symbol(SBUFR)] + set bit8 [$this getBit $::Simulator_ENGINE::symbol(RB8)] + } else { + set sbuf [$this getSfrDEC $::Simulator_ENGINE::symbol(SBUFT)] + set bit8 [$this getBit $::Simulator_ENGINE::symbol(TB8)] + } + + for {set i 0} {$i < 9} {incr i} { + if {!$i} { + set value $bit8 + } else { + set value [expr {$sbuf & (1 << (8 - $i))}] + } + + if {$value} { + set outline ${::BitMap::one_outline} + set fill ${::BitMap::one_fill} + } else { + set outline ${::BitMap::zero_outline} + set fill ${::BitMap::zero_fill} + } + + $canvas($side) itemconfigure $bit_rect(b,$side,$i) \ + -outline $outline \ + -fill $fill + } + } + public method uart_monitor_graph_clear {side} { + $canvas($side) delete graph + + set graph_position($side) 0 + set graph_prev_states($side) 1 + set graph_elements($side) [list] + } + + public method uart_monitor_graph_draw {side values} { + if {$graph_position($side) == 190} { + $canvas($side) move graph -1 0 + foreach items [lindex $graph_elements($side) 0] { + foreach item $items { + $canvas($side) delete $item + } + } + set graph_elements($side) [lreplace $graph_elements($side) 0 0] + incr graph_position($side) -1 + } + + set x_0 [expr {45 + $graph_position($side)}] + set x_1 [expr {$x_0 + 1}] + + set i 0 + set prev_state [list] + set graph_elems [list] + foreach state $values { + set top [expr {75 + $i * 20}] + set mid [expr {82 + $i * 20}] + set bot [expr {90 + $i * 20}] + switch -- [lindex $graph_prev_states($side) $i] { + 0 { + switch -- $state { + 0 { ;# 0 --> 0 + lappend graph_elems [list \ + [$canvas($side) create line $x_0 $bot $x_1 $bot -tags graph -fill {#00FF00}] \ + ] + } + 1 { ;# 0 --> 1 + lappend graph_elems [list \ + [$canvas($side) create line $x_0 $top $x_0 $mid -tags graph -fill {#FF0000}] \ + [$canvas($side) create line $x_0 $mid $x_0 $bot -tags graph -fill {#00FF00}] \ + ] + } + default { + lappend graph_elems [list \ + [$canvas($side) create line $x_0 $top $x_0 $bot -tags graph -fill {#0000FF}] \ + ] + } + } + } + 1 { + switch -- $state { + 0 { ;# 1 --> 0 + lappend graph_elems [list \ + [$canvas($side) create line $x_0 $top $x_0 $mid -tags graph -fill {#FF0000}] \ + [$canvas($side) create line $x_0 $mid $x_0 $bot -tags graph -fill {#00FF00}] \ + ] + } + 1 { ;# 1 --> 1 + lappend graph_elems [list \ + [$canvas($side) create line $x_0 $top $x_1 $top -tags graph -fill {#FF0000}] \ + ] + } + default { + lappend graph_elems [list \ + [$canvas($side) create line $x_0 $top $x_0 $bot -tags graph -fill {#0000FF}] \ + ] + } + } + } + default { + lappend graph_elems [list \ + [$canvas($side) create line $x_0 $top $x_0 $bot -tags graph -fill {#0055FF}] \ + ] + } + } + + incr i + lappend prev_state $state + } + + incr graph_position($side) + set graph_prev_states($side) $prev_state + lappend graph_elements($side) $graph_elems + } +} + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/virtual_uart_term.tcl b/lib/simulator/virtual_uart_term.tcl deleted file mode 100755 index 29f3199..0000000 --- a/lib/simulator/virtual_uart_term.tcl +++ /dev/null @@ -1,646 +0,0 @@ -#!/usr/bin/tclsh -# Part of MCU 8051 IDE ( http://mcu8051ide.sf.net ) - -############################################################################ -# Copyright (C) 2010 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 -# UART monitor -# ------------------------------------------------------------------------- - -# LOAD PROGRAM ICONS -# ----------------------------- -if {$argv0 != {./virtual_uart_term.tcl}} { - set D 0 -} { - set D 1 -} -if {$D} { - package require Tk - package require img::png - package require Itcl - namespace import -force ::itcl::* - package require msgcat - namespace import -force ::msgcat::* - package require BWidget - set ::DEFAULT_FIXED_FONT {DejaVu Sans Mono} - set ::MICROSOFT_WINDOWS 0 - - set LIB_DIRNAME "/media/disk/mcu8051ide/lib" - source "$LIB_DIRNAME/lib/hexeditor.tcl" - - foreach directory {16x16 22x22 32x32} ns {16 22 32} { - namespace eval ::ICONS::${ns} {} - foreach filename [glob "${::LIB_DIRNAME}/../icons/${directory}/*.png"] { - set filename [file normalize $filename] - set iconname [file tail $filename] - regexp {^\w+} $iconname iconname - if {[catch { - image create photo ::ICONS::${ns}::${iconname} -format png -file $filename - } result]} then { - puts stderr {} - puts -nonewline stderr $result - image create photo ::ICONS::${ns}::${iconname} - } - } - } - - proc menuFactory {pattern path tearoff cmdPrefix shortcuts options} { - - # Create menu widget - eval "menu $path -tearoff $tearoff $options" - - # Iterate over menu definition list - foreach menuitem $pattern { - # Create array of options - for {set i 0} {$i < 9} {incr i} { - set menu($i) [lindex $menuitem $i] - } - # Determinate kind of operation - switch $menu(0) { - {command} { - # Item icon - if {$menu(5) != {}} { - set menu(5) "::ICONS::16::$menu(5)" - } - - # Adjust accelerator value - set menu(2) $menu(2) - - # Create menu command - $path add command \ - -label [mc $menu(1)] \ - -accelerator $menu(2) \ - -underline $menu(3) \ - -command "$cmdPrefix$menu(4)" \ - -image $menu(5) -compound left - - # Status bar tip - if {$menu(6) != {}} { - set itemIndex [$path index end] - menu_Sbar_add $path $itemIndex [mc $menu(6)] - bind $path <<MenuSelect>> "menu_Sbar $path \[%W index active\]" - bind $path <Leave> {Sbar {}} - } - } - {separator} {$path add separator} - {radiobutton} { - # Adjust command - if {$menu(5) != {}} { - set menu(5) "${cmdPrefix}$menu(5)" - } - - # Adjust accelerator value - set menu(2) [adjust_menu_accelerator $menu(2)] - - # Create radio button item - $path add radiobutton \ - -label [mc $menu(1)] \ - -accelerator $menu(2) \ - -variable $menu(3) \ - -value $menu(4) \ - -command $menu(5) \ - -underline $menu(6) \ - -compound left \ - -indicatoron 0 \ - -image ::ICONS::raoff \ - -selectimage ::ICONS::raon \ - -selectcolor {#EEEEEE} - - # Status bar tip - if {$menu(7) != {}} { - set itemIndex [$path index end] - menu_Sbar_add $path $itemIndex [mc $menu(7)] - bind $path <<MenuSelect>> "menu_Sbar $path \[%W index active\]" - bind $path <Leave> {Sbar {}} - } - } - {checkbutton} { - # Adjust command - if {$menu(7) != {}} { - set menu(7) "${cmdPrefix}$menu(7)" - } - # Adjust accelerator value - set menu(2) [adjust_menu_accelerator $menu(2)] - - # Create checkbutton item - $path add checkbutton \ - -label [mc $menu(1)] \ - -accelerator $menu(2) \ - -variable $menu(3) \ - -onvalue $menu(4) \ - -offvalue $menu(5) \ - -underline $menu(6) \ - -command $menu(7) \ - -compound left \ - -image ::ICONS::choff \ - -indicatoron 0 \ - -selectimage ::ICONS::chon \ - -selectcolor {#EEEEEE} - # Status bar tip - if {$menu(8) != {}} { - set itemIndex [$path index end] - menu_Sbar_add $path $itemIndex [mc $menu(8)] - bind $path <<MenuSelect>> "menu_Sbar $path \[%W index active\]" - bind $path <Leave> {Sbar {}} - } - } - {cascade} { - # Adjust menu name - set menu(4) "$path$menu(4)" - # Create new menu for cascade - if {$menu(7) != {}} { - menuFactory $menu(7) $menu(4) $menu(5) $cmdPrefix $menu(6) $options - } - # Item icon - if {$menu(3) != {}} { - set menu(3) "::ICONS::16::$menu(3)" - } - # Add cascade to this menu - $path add cascade -label [mc $menu(1)] -underline $menu(2) \ - -image $menu(3) -menu $menu(4) -compound left - } - {} {return} - default { - error "Menu creation failed -- unknown type: $menu(0)" - return -code 1 - } - } - } - } - - ttk::style theme use clam - # - ttk - set TTK_COMMON_BG {#E0E0E0} - ttk::style configure TFrame \ - -background {#EEEEEE} - - ttk::style configure TNotebook \ - -background {#EEEEEE} \ - -fieldbackground {red} - ttk::style map TNotebook \ - -background [list \ - active red \ - pressed blue \ - pressed green \ - ] - - font configure TkTextFont -family {helvetica} -size -12 -weight {normal} - font configure TkDefaultFont -family {helvetica} -size -12 -weight {normal} - - ttk::style configure StringNotFound.TEntry \ - -fieldbackground {#FFDDDD} - ttk::style configure StringFound.TEntry \ - -fieldbackground {#DDFFDD} - - ttk::style configure Simulator.TEntry - ttk::style map Simulator.TEntry \ - -fieldbackground [list readonly {#F8F8F8}] \ - -foreground [list readonly {#888888}] - ttk::style configure Simulator_HG.TEntry \ - -foreground {#CC8800} - ttk::style configure Simulator_WhiteBg.TEntry \ - -fieldbackground {#FFFFFF} \ - -fielddisabledbackground {#FFFFFF} - ttk::style configure Simulator_WhiteBg_HG.TEntry \ - -fieldbackground {#FFFFFF} \ - -fielddisabledbackground {#FFFFFF} \ - -foreground {#CC8800} - ttk::style configure Simulator_WhiteBg_Sel.TEntry \ - -fieldbackground {#DDDDFF} \ - -fielddisabledbackground {#DDDDFF} - ttk::style configure Simulator_WhiteBg_HG_Sel.TEntry \ - -foreground {#CC8800} \ - -fieldbackground {#DDDDFF} \ - -fielddisabledbackground {#DDDDFF} - - ttk::style configure Simulator_watchdogEntry_0.TEntry \ - -fieldbackground {#88FF88} \ - -fielddisabledbackground {#66DD66} - ttk::style map Simulator_watchdogEntry_0.TEntry \ - -foreground [list readonly {#888888}] - - ttk::style configure Simulator_watchdogEntry_1.TEntry \ - -fieldbackground {#FFFF55} \ - -fielddisabledbackground {#DDDD33} - ttk::style map Simulator_watchdogEntry_1.TEntry \ - -foreground [list readonly {#888888}] - - ttk::style configure Simulator_watchdogEntry_2.TEntry \ - -fieldbackground {#FF5555} \ - -fielddisabledbackground {#DD3333} - ttk::style map Simulator_watchdogEntry_2.TEntry \ - -foreground [list readonly {#888888}] - - ttk::style configure TLabelframe \ - -background {#EEEEEE} - ttk::style configure TLabel \ - -background {#EEEEEE} - - ttk::style configure TButton \ - -background $TTK_COMMON_BG \ - -padding 0 - ttk::style configure RedBg.TButton \ - -padding 0 - ttk::style map RedBg.TButton \ - -background [list \ - active {#FFBBBB} \ - !active {#FF8888} \ - ] \ - -foreground [list \ - active {#FF0000} \ - !active {#000000} \ - ] - ttk::style configure GreenBg.TButton \ - -padding 0 - ttk::style map GreenBg.TButton \ - -background [list \ - active {#BBFFBB} \ - !active {#88FF88} \ - ] \ - -foreground [list \ - active {#00FF00} \ - !active {#000000} \ - ] - - ttk::style configure Flat.TButton \ - -background {#EEEEEE} \ - -padding 0 \ - -borderwidth 1 \ - -relief flat - ttk::style map Flat.TButton \ - -relief [list active raised] \ - -background [list disabled {#EEEEEE}] - - ttk::style configure TMenubutton \ - -padding 0 \ - -background $TTK_COMMON_BG - ttk::style configure Flat.TMenubutton \ - -padding 0 \ - -background {#EEEEEE} \ - -borderwidth 1 \ - -relief flat - ttk::style map Flat.TMenubutton \ - -relief [list active raised] \ - -background [list disabled {#EEEEEE}] - - ttk::style configure FlatWhite.TButton \ - -padding 0 \ - -background {#FFFFFF} \ - -borderwidth 1 \ - -relief flat - ttk::style map FlatWhite.TButton \ - -relief [list active raised] \ - -background [list disabled {#FFFFFF}] - - ttk::style configure ToolButton.TButton \ - -background {#EEEEEE} \ - -padding 1 \ - -borderwidth 1 \ - -relief flat - ttk::style map ToolButton.TButton \ - -relief [list active raised] \ - -background [list disabled {#EEEEEE}] - - ttk::style configure TCombobox \ - -background $TTK_COMMON_BG \ - -fieldfont [font create -family {helvetica} -size -12 -weight {normal}] - ttk::style map TCombobox \ - -foreground [list disabled {#888888}] \ - -fieldbackground [list \ - readonly $TTK_COMMON_BG \ - disabled {#EEEEEE} \ - {!readonly !disabled} {#FFFFFF} \ - ] - - ttk::style configure TScrollbar \ - -background $TTK_COMMON_BG \ - -troughcolor {#F8F8F8} - - ttk::style configure TScale \ - -background $TTK_COMMON_BG - ttk::style map TScale \ - -troughcolor [list \ - disabled $TTK_COMMON_BG \ - !disabled {#F8F8F8} \ - ] - - ttk::style configure TProgressbar \ - -background $TTK_COMMON_BG \ - -troughcolor {#F8F8F8} - wm withdraw . -} - -class VirtualUartTerminal { - ## COMMON - common count 0 ;# Counter of intances - # Font: Big bold font - common bold_font [font create \ - -family {helvetica} \ - -size -12 -weight {bold} \ - ] - # Font: Tiny normal font - common tiny_font [font create \ - -family {helvetica} \ - -size -9 -weight {normal} \ - ] - # Font: Tiny bold font - common tiny_font_bold [font create \ - -family {helvetica} \ - -size -9 -weight {bold} \ - ] - # Font: Normal font - common normal_font [font create \ - -family {helvetica} \ - -size -11 -weight {normal} \ - ] - # Font: Also normal font, but a bit larger - common big_font [font create \ - -family {helvetica} \ - -size -12 -weight {normal} \ - ] - # List of Int: Available baud rates for RS232 - common available_baud_rates { - 50 75 110 134 150 200 - 300 600 1200 1800 2400 4800 - 9600 19200 38400 57600 115200 230400 - 460800 - } - - ## PRIVATE - private variable dialog_opened 0 ;# Bool: Dialog window opened - private variable win ;# Widget: Dialog window - private variable status_bar_label ;# Widget: Status bar - - private variable too_baud_conf {9600} ;# Int: Selected baud rate for communication - private variable too_parity_conf {n} ;# Char: Selected type of parity - private variable too_data_conf {8} ;# Int: Number of data bits - private variable too_stop_conf {1} ;# Int: Number of stop bits - - constructor {} { - } - - destructor { - } - - ## Close interrupt monitor window and free its resources - # @return void - public method virtual_uart_termial_close {} { - if {!$dialog_opened} { - return - } - - set geometry [wm geometry $win] - set dialog_opened 0 - set in_progress_wdg {} - set in_progress_flg {} - set pending_flg {} - set intr_priorities {} - set avaliable_interrs {} - - if {[winfo exists $win]} { - destroy $win - } - } - - ## Invoke interrupt monitor window - # @return void - public method virtual_uart_termial_invoke_dialog {} { - set dialog_opened 1 - - # Create window - set win [toplevel .virtual_uart_term$count -class [mc "UART Monitor"] -bg {#EEEEEE}] - incr count - - # Create status bar - set status_bar_label [label $win.status_bar_label -justify left -pady 0 -anchor w] - pack $status_bar_label -side bottom -fill x - - # Create top frame - set top_frame [frame $win.top_frame] - create_top_frame $top_frame - pack $top_frame -fill x -anchor nw - - # Create bottom frame - set bottom_frame [frame $win.bottom_frame] - create_bottom_frame $bottom_frame - pack $bottom_frame -fill x -anchor nw - - # Configure window - wm title $win [mc "Virtual UART Terminal - MCU 8051 IDE"] - wm iconphoto $win ::ICONS::16::_blockdevice - wm resizable $win 0 0 - wm protocol $win WM_DELETE_WINDOW "$this virtual_uart_termial_close" - } - - ## Set status bar tip for specified widget - # @parm Widget widget - Target widget - # @parm String text - Text of the stutus tip - # @return void - private method virtual_uart_termial_set_status_tip {widget text} { - bind $widget <Enter> "$status_bar_label configure -text {$text}" - bind $widget <Leave> "$status_bar_label configure -text {}" - } - - ## Create top frame in the dialog window (connector_canvas (left) and configuration (right)) - # @parm Widget target_frame - Parent frame - # @return void - private method create_top_frame {target_frame} { - # - ## FRAME: OUR MICROCONTROLLER - # - - # Create labelframe - set our_mcu_frame [ttk::labelframe $target_frame.our_mcu_frame \ - -padding 5 \ - -labelwidget [label $target_frame.our_mcu_label \ - -font $bold_font \ - -compound left \ - -text [mc "\"Our Microcontroller\""] \ - -image ::ICONS::16::configure \ - ] \ - ] - pack [label $our_mcu_frame.l -text "AAAA"] - pack $our_mcu_frame -side left -fill x -expand 1 -padx 5 - - - # - ## FRAME: THE OTHER DEVICE - # - - # Create labelframe - set the_other_one_frame [ttk::labelframe \ - $target_frame.the_other_one_frame \ - -padding 5 \ - -labelwidget [label $target_frame.too_label \ - -font $bold_font \ - -compound left \ - -text [mc "Terminal configuration"] \ - -image ::ICONS::16::configure \ - ] \ - ] - # - Baud rate - grid [label $the_other_one_frame.baud_lbl \ - -text [mc "Baud rate"] \ - ] -row 3 -column 1 -sticky w - set baud_cb [ttk::combobox $the_other_one_frame.baud_cb \ - -state readonly \ - -width 6 \ - -exportselection 0 \ - -values $available_baud_rates \ - ] - bind $baud_cb <<ComboboxSelected>> \ - "$this change_port_config b \[$the_other_one_frame.baud_cb get\]" - virtual_uart_termial_set_status_tip $baud_cb [mc "Connection speed in bps"] - grid $baud_cb -row 3 -column 2 -sticky w - $the_other_one_frame.baud_cb current [lsearch [$the_other_one_frame.baud_cb cget -values] $too_baud_conf] - # - Parity - grid [label $the_other_one_frame.parity_lbl \ - -text [mc "Parity"] \ - ] -row 4 -column 1 -sticky w - set parity_cb [ttk::combobox $the_other_one_frame.parity_cb \ - -values {none odd even mark space} \ - -state readonly \ - -width 6 \ - -exportselection 0 \ - ] - bind $parity_cb <<ComboboxSelected>> \ - "$this change_port_config p \[$the_other_one_frame.parity_cb get\]" - virtual_uart_termial_set_status_tip $parity_cb [mc "Parity"] - grid $parity_cb -row 4 -column 2 -sticky w - $the_other_one_frame.parity_cb current [lsearch {n o e m s} $too_parity_conf] - # - Data bits - grid [label $the_other_one_frame.data_lbl \ - -text [mc "Data bits"] \ - ] -row 5 -column 1 -sticky w - set data_cb [ttk::combobox $the_other_one_frame.data_cb \ - -state readonly \ - -width 1 \ - -values {5 6 7 8} \ - -exportselection 0 \ - ] - bind $data_cb <<ComboboxSelected>> \ - "$this change_port_config d \[$the_other_one_frame.data_cb get\]" - virtual_uart_termial_set_status_tip $data_cb [mc "Number of data bits"] - grid $data_cb -row 5 -column 2 -sticky w - $the_other_one_frame.data_cb current [lsearch [$the_other_one_frame.data_cb cget -values] $too_data_conf] - # - Stop bits - grid [label $the_other_one_frame.stop_lbl \ - -text [mc "Stop bits"] \ - ] -row 6 -column 1 -sticky w - set stop_cb [ttk::combobox $the_other_one_frame.stop_cb \ - -state readonly \ - -width 1 \ - -values {1 2} \ - -exportselection 0 \ - ] - bind $stop_cb <<ComboboxSelected>> \ - "$this change_port_config s \[$the_other_one_frame.stop_cb get\]" - virtual_uart_termial_set_status_tip $stop_cb [mc "Number of stop bits"] - grid $stop_cb -row 6 -column 2 -sticky w - $the_other_one_frame.stop_cb current [lsearch [$the_other_one_frame.stop_cb cget -values] $too_stop_conf] - pack $the_other_one_frame -side left -fill x -expand 1 -padx 5 - } - - ## Create bottom frame (hexadecimal editors) - # @parm Widget target_frame - Parent frame - # @return void - private method create_bottom_frame {target_frame} { - # Create headers ("Data to send", "Received data") - grid [label $target_frame.lbl_a \ - -text [mc "Data to send"] \ - -compound right \ - -image ::ICONS::16::forward \ - -padx 15 -font $bold_font \ - ] -row 0 -column 1 -columnspan 2 - grid [label $target_frame.lbl_b \ - -text [mc "Received data"] \ - -compound left \ - -image ::ICONS::16::forward \ - -padx 15 -font $bold_font \ - ] -row 0 -column 3 -columnspan 2 - - # Create hexadecimal editors - set send_hexeditor [HexEditor #auto \ - $target_frame.send_hexeditor 8 32 2 \ - hex 1 1 5 256 \ - ] - [$send_hexeditor getLeftView] configure -exportselection 0 - $send_hexeditor bindSelectionAction "$this hexeditor_selection s" - grid $target_frame.send_hexeditor -row 1 -column 1 -columnspan 2 - - set receive_hexeditor [HexEditor #auto \ - $target_frame.receive_hexeditor 8 32 2 \ - hex 1 1 5 256 \ - ] - [$send_hexeditor getLeftView] configure -exportselection 0 - $receive_hexeditor bindSelectionAction "$this hexeditor_selection r" - grid $target_frame.receive_hexeditor -row 1 -column 3 -columnspan 2 - - # Create buttons "Send selected" and "Clear selected" in send part - set send_selected_button [ttk::button \ - $target_frame.send_selected_button \ - -text [mc "Send selected"] \ - -image ::ICONS::16::forward \ - -command "$this send_selected" \ - -compound left \ - -state disabled \ - ] - set clear_selected_snd_button [ttk::button \ - $target_frame.clear_selected_snd_button \ - -text [mc "Clear selected"] \ - -image ::ICONS::16::eraser \ - -command "$this clear_selected_snd" \ - -compound left \ - -state disabled \ - ] - virtual_uart_termial_set_status_tip $send_selected_button [mc "Send selected data"] - virtual_uart_termial_set_status_tip $clear_selected_snd_button [mc "Remove selected data"] - grid $send_selected_button -row 2 -column 1 -sticky we - grid $clear_selected_snd_button -row 2 -column 2 -sticky we - - # Create buttons "Receive here" and "Clear selected" in reception part - set receive_here_button [ttk::button \ - $target_frame.receive_here_button \ - -text [mc "Receive here"] \ - -image ::ICONS::16::down0 \ - -command "$this receive_here" \ - -compound left \ - ] - set clear_selected_rec_button [ttk::button \ - $target_frame.clear_selected_rec_button \ - -text [mc "Clear selected"] \ - -image ::ICONS::16::eraser \ - -command "$this clear_selected_rec" \ - -compound left \ - -state disabled \ - ] - virtual_uart_termial_set_status_tip $receive_here_button [mc "Receive data on current cursor position"] - virtual_uart_termial_set_status_tip $clear_selected_rec_button [mc "Remove selected data"] - grid $receive_here_button -row 2 -column 3 -sticky we - grid $clear_selected_rec_button -row 2 -column 4 -sticky we - } -} - -if {$D} { - VirtualUartTerminal virtual_uart_term - virtual_uart_term virtual_uart_termial_invoke_dialog -} |