#!/usr/bin/wish -f

###############################################################################
## CONFIGURING this script:
##
##  As of tkisem version 4.5.8 on Linux systems, this file SHOULD NOT REQUIRE
##  ANY CUSTOMIZATION (unless you've got wish elsewhere than above).
##
## 1. If you're on a Unix system, replace the first line with the full
##    pathname of your wish interpreter (be certain to leave the "-f" after
##    the pathname).  This wish interpreter must be at least 7.5 (for file 
##    split/join commands, 8.0 or higher preferred).
##    
## 2. Set the library directory ('libdir', below) to the full pathname of where 
##    you installed the library and help file.
##
## 3. Set the library extension: for Unix systems, this is 'so'.
##
###############################################################################

set libdir [eval file join [lreplace [file split [file dirname $argv0]] end end lib]]
set lib_ext so
# $Format: "set release $ProjectVersion$"$
set release 4.5.12

###############################################################################
# Other configurable options -- 
###############################################################################

# how to display registers
# the default is  regular  which uses the names %r0 through %r31
# the alternative is  window  which uses the names %g0-%g7, %o0-%o7, etc
set reg_view regular

#--------------------------isem devices----------------------------------------
#
# the address is the memory address for the device
# the mode specifies which address spaces the device appears in -- it always
#   mapped into supervisor space, if mode is set to user, it is also mapped
#   into user space

set gx_address 0x100000
set gx_mode user

set console_address 0x110000
set console_mode user

set halt_address 0x120000
set halt_mode user

set timer_int_level 1
set timer_address 0x130000
set timer_mode user

###############################################################################
# end of configuration
###############################################################################

source "$libdir/isem_com.tcl"

###############################################################################
# this is where it starts!
###############################################################################
frame .cmd_line
pack .cmd_line
label .cmd_line.lbl -text "Command"
entry .cmd_line.entry -width 70 -textvariable command -relief sunken -font fixed
pack .cmd_line.lbl -side left
pack .cmd_line.entry -side left

bind .cmd_line.entry <Return> {eval_command}

frame .commands
pack .commands
text .commands.text -width 80 -height 25 -relief sunken -bd 2 -font fixed \
    -yscrollcommand ".commands.scroll set" -state disabled
scrollbar .commands.scroll -command ".commands.text yview"
pack .commands.scroll -side right -fill y
pack .commands.text -side left

#------------------------------------------------------------------------------
# the gx device
#------------------------------------------------------------------------------
toplevel .gx
wm title .gx "ISEM GX device"
isem_gx .gx.display
pack .gx.display

proc gx {op addr bytemask value} {

    if {$op == "read"} {
	return [.gx.display read]
    } else {
	.gx.display write $value $addr
    }
}

isem_device gx $gx_address $gx_mode

proc outs {msg} {
    .commands.text configure -state normal
    .commands.text insert end [format "%s\n" $msg]
    .commands.text yview -pickplace end
    .commands.text configure -state disabled
}

proc outc {ch} {
    .commands.text configure -state normal
    .commands.text insert end $ch
    .commands.text yview -pickplace end
    .commands.text configure -state disabled
}

set poll_op update

reset
