add support for CCSv4 DSS loading
diff --git a/src/part2/examples/txn/platforms/ez430_rf2500/load.bat b/src/part2/examples/txn/platforms/ez430_rf2500/load.bat
index 6e4397c..c7fbab1 100644
--- a/src/part2/examples/txn/platforms/ez430_rf2500/load.bat
+++ b/src/part2/examples/txn/platforms/ez430_rf2500/load.bat
@@ -15,6 +15,18 @@
     set DEBUGSERVER=C:\Program Files\Texas Instruments\CC Essentials v3.1\DebugServer

 )

 

+REM Path to Rhino JAR File

+set RHINO_JAR="%DEBUGSERVER%\scripting\lib\rhino\js.jar"

+

+REM Path to DebugServer JAR File

+set SCRIPTING_JARS="%DEBUGSERVER%\scripting\lib\dss.jar"

+

+if not exist %RHINO_JAR% (

+  "%DEBUGSERVER%\..\scripting\bin\dss.bat" %~dp0/load_ccs.xs  -c %~dp0/TargetConfiguration.ccxml -a %*

+  if errorlevel 1 exit 1

+  exit 0

+)

+  

 REM *************************************************************************

 set PATH=%DEBUGSERVER%\scripting\lib;%PATH%

 set PATH=%DEBUGSERVER%\bin\win32;%PATH%

@@ -22,12 +34,6 @@
 set PATH=%DEBUGSERVER%\win32\drivers;%PATH%

 REM *************************************************************************

 

-REM Path to Rhino JAR File

-set RHINO_JAR="%DEBUGSERVER%\scripting\lib\rhino\js.jar"

-

-REM Path to DebugServer JAR File

-set SCRIPTING_JARS="%DEBUGSERVER%\scripting\lib\dss.jar"

-

 REM Name of Rhino Shell Java Application

 set RHINO_SHELL=org.mozilla.javascript.tools.shell.Main

 

@@ -55,3 +61,5 @@
 REM Launch Rhino script engine.  Import the scripting package.

 "%JAVA_HOME%\bin\java.exe" -DXPCOM.RUNTIME="%DEBUGSERVER%\win32" -cp %RHINO_JAR%;%SCRIPTING_JARS% %RHINO_SHELL% %~dp0/load.xs  -c %~dp0/SystemSetup.xml -a %*

 endlocal

+

+

diff --git a/src/part2/examples/txn/platforms/ez430_rf2500/load.xs b/src/part2/examples/txn/platforms/ez430_rf2500/load.xs
index b5a3359..e1f2fbb 100644
--- a/src/part2/examples/txn/platforms/ez430_rf2500/load.xs
+++ b/src/part2/examples/txn/platforms/ez430_rf2500/load.xs
@@ -29,13 +29,14 @@
 // Import the DSS packages into our namespace to save on typing
 importPackage(Packages.com.ti.debug.engine.scripting);
 importPackage(Packages.com.ti.ccstudio.scripting.environment);
-importPackage(Packages.java.lang);
 
 // Create our scripting environment object
 var script = new ScriptingEnvironment();
 
 // only show warnings or worse (the default is much more verbose)
 script.traceSetConsoleLevel(TraceLevel.WARNING);
+//script.traceBegin("Log.xml", "DefaultStylesheet.xsl");
+//script.traceSetFileLevel(TraceLevel.ALL);
 
 // Get the Debug Server and start a Debug Session
 var debugServer = script.getServer("DebugServer.1");
@@ -50,7 +51,9 @@
 // (ScriptingEnvironment has a concept of a working folder and for all of
 // the APIs which take path names as arguments you can either pass a relative
 // path or an absolute path)
+print("loading " + arguments[0] + " ...");
 debugSession.memory.loadProgram(arguments[0]);
+print("starting " + arguments[0] + " ...");
 
 if (aflag == false) {
     // Set a breakpoint at "exit"
@@ -61,20 +64,22 @@
     debugSession.target.run();
 
     // Using an expression - get the current value of the PC
-    nPC = debugSession.expression.evaluate("PC");
+    var pc = debugSession.expression.evaluate("PC");
 
     // Verify we halted at the correct address.
-    if (nPC != progExit) {
+    if (pc != progExit) {
         print("FAIL: Expected halt at 0x" + Long.toHexString(progExit)
-              + ", actually halted at 0x" + Long.toHexString(nPC));
+              + ", actually halted at 0x" + Long.toHexString(pc));
     }
 }
 else {
     // let 'r rip!
     debugSession.target.runAsynch();
+    debugSession.target.disconnect();
 }
 
 // All done
+
 debugSession.terminate();
 debugServer.stop();
 
diff --git a/src/part2/examples/txn/platforms/ez430_rf2500/load_ccs.xs b/src/part2/examples/txn/platforms/ez430_rf2500/load_ccs.xs
new file mode 100644
index 0000000..dd9be66
--- /dev/null
+++ b/src/part2/examples/txn/platforms/ez430_rf2500/load_ccs.xs
@@ -0,0 +1,85 @@
+if (arguments.length < 1) {
+    print("usage: load [-a] [-c config.xml] prog");
+    java.lang.System.exit(1);
+}
+
+var config = null;
+var aflag = false;
+
+while (arguments[0][0] == '-') {
+    switch (arguments[0][1]) {
+        case 'a': {
+            aflag = true;
+            break;
+        }
+        case 'c': {
+            config = arguments[1];
+            arguments.shift();
+            break;
+        }
+    }
+    arguments.shift();
+}
+
+/* if no debug config file is specified, use one in the current directory */
+if (config == null) {
+    config = "./TargetConfiguration.ccxml";
+}
+
+// Import the DSS packages into our namespace to save on typing
+importPackage(Packages.com.ti.debug.engine.scripting);
+importPackage(Packages.com.ti.ccstudio.scripting.environment);
+
+// Create our scripting environment object
+var script = ScriptingEnvironment.instance();
+
+// only show warnings or worse (the default is much more verbose)
+script.traceSetConsoleLevel(TraceLevel.WARNING);
+//script.traceBegin("Log.xml", "DefaultStylesheet.xsl");
+//script.traceSetFileLevel(TraceLevel.ALL);
+
+// Get the Debug Server and start a Debug Session
+var debugServer = script.getServer("DebugServer.1");
+debugServer.setConfig(config);
+
+var debugSession = debugServer.openSession(".*");
+
+// Connect to the Target
+debugSession.target.connect();
+
+// Load a program
+// (ScriptingEnvironment has a concept of a working folder and for all of
+// the APIs which take path names as arguments you can either pass a relative
+// path or an absolute path)
+print("loading " + arguments[0] + " ...");
+debugSession.memory.loadProgram(arguments[0]);
+print("starting " + arguments[0] + " ...");
+
+if (aflag == false) {
+    // Set a breakpoint at "exit"
+    var progExit = debugSession.symbol.getAddress("xdc_runtime_System_exit__F");
+    var bp1 = debugSession.breakpoint.add(progExit);
+
+    // Run.  Should halt at first BP
+    debugSession.target.run();
+
+    // Using an expression - get the current value of the PC
+    var pc = debugSession.expression.evaluate("PC");
+
+    // Verify we halted at the correct address.
+    if (pc != progExit) {
+        print("FAIL: Expected halt at 0x" + Long.toHexString(progExit)
+              + ", actually halted at 0x" + Long.toHexString(pc));
+    }
+}
+else {
+    // let 'r rip!
+    debugSession.target.runAsynch();
+    debugSession.target.disconnect();
+}
+
+// All done
+debugSession.terminate();
+debugServer.stop();
+
+java.lang.System.exit(0);