// BootTerm.java: bootstrap program for loading code into HC11 // includes terminal emulator after loading file // // Fred Martin / computer science / UML // Thu Oct 10 01:22:26 2002 // updated Sat Oct 4 13:46:39 2003 // updated Tue Oct 7 15:55:12 2003 import java.io.*; class BootTerm { private static Serial s; private static File f; public static void main(String[] argv) { setup(argv); // select serial port and init Serial object System.out.println("Using serial port " + s.getPortName()); byte[] buf = ReadRel.read(f); System.out.println("Serial port is open. Turn on HC11 and press to continue..."); try { System.in.read(); } catch (Exception e) { e.printStackTrace(); } System.out.println("Writing to serial line..."); try { s.put(0xff); // send baud rate detect byte s.put(buf); // dump 512 bytes to serial port } catch (Exception e) { e.printStackTrace(); } s.flush(); // make sure all chars get out before exiting System.out.println("Done."); System.out.println("Starting terminal emulator... type CTRL-C to exit."); try { Thread.sleep(3000); } catch (Exception e) { e.printStackTrace(); } term(); } private static void term() { int i; while (true) { i = s.get(); if (i == -1) continue; if ((i > 31) && (i < 128)) // ascii System.out.print((char)i); else if (i == 13) // carriage return System.out.println(); else if (i != 10) // not linefeed, unprintable char, display a dot // System.out.print("."); System.out.print(" <" + java.lang.Integer.toHexString(i) + "> "); } } private static void setup(String[] args) { if (args.length < 2) { System.out.println("Usage: BootTerm filename[.rel] serial-port"); System.out.println("Loads a .rel object file into 68HC11E1's 512 bytes of RAM"); System.out.println("And then starts a simple terminal emulator.\n"); s = new Serial(); String[] ports=s.portsAvailable(); int nPorts= ports.length; System.out.println("Available ports are:"); for (int i=0; i< nPorts; i++) { System.out.println(" " + ports[i] + " "); } System.out.println(); System.exit(0); } String fn = args[0]; if (!fn.endsWith(".rel")) fn = fn + ".rel"; f = new File(fn); if (!f.exists()) { System.out.println("File " + f + " does not exist. Sorry."); System.exit(1); } if (!f.canRead()) { System.out.println("File " + f + " exists, but I can't read it. Sorry."); System.exit(1); } s = new Serial(args[1]); } }