summaryrefslogtreecommitdiff
path: root/lib/simulator/simulator.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/simulator/simulator.tcl')
-rw-r--r--[-rwxr-xr-x]lib/simulator/simulator.tcl165
1 files changed, 97 insertions, 68 deletions
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