Merge branch 'buttonbox' of git://git.gag.com/fw/altos into buttonbox
[fw/altos] / ao-tools / altosui / AltosDebug.java
index 06c9a0bdb9808eadac132843ce3eab38c420b5ab..9aa35d3f2f834813d7cfdd51a5dbf2a631b750ee 100644 (file)
@@ -19,11 +19,10 @@ package altosui;
 
 import java.lang.*;
 import java.io.*;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.LinkedList;
-import java.util.Iterator;
-import altosui.AltosSerial;
-import altosui.AltosRomconfig;
+import java.util.concurrent.*;
+import java.util.*;
+
+import libaltosJNI.*;
 
 public class AltosDebug extends AltosSerial {
 
@@ -58,47 +57,12 @@ public class AltosDebug extends AltosSerial {
        public static final byte GET_CHIP_ID =          0x68;
 
 
-       static boolean ishex(int c) {
-               if ('0' <= c && c <= '9')
-                       return true;
-               if ('a' <= c && c <= 'f')
-                       return true;
-               if ('A' <= c && c <= 'F')
-                       return true;
-               return false;
-       }
-
-       static boolean ishex(String s) {
-               for (int i = 0; i < s.length(); i++)
-                       if (!ishex(s.charAt(i)))
-                               return false;
-               return true;
-       }
-       static boolean isspace(int c) {
-               switch (c) {
-               case ' ':
-               case '\t':
-                       return true;
-               }
-               return false;
-       }
-
-       static int fromhex(int c) {
-               if ('0' <= c && c <= '9')
-                       return c - '0';
-               if ('a' <= c && c <= 'f')
-                       return c - 'a' + 10;
-               if ('A' <= c && c <= 'F')
-                       return c - 'A' + 10;
-               return -1;
-       }
-
        boolean debug_mode;
 
        void ensure_debug_mode() {
                if (!debug_mode) {
-                       printf("m 0\nD\n");
-                       flush_reply();
+                       printf("D\n");
+                       flush_input();
                        debug_mode = true;
                }
        }
@@ -138,21 +102,21 @@ public class AltosDebug extends AltosSerial {
                throws IOException, InterruptedException {
                byte[]  data = new byte[length];
 
-               flush_reply();
+               flush_input();
                ensure_debug_mode();
                printf("I %x %x\n", length, address);
                int i = 0;
                int start = 0;
                while (i < length) {
                        String  line = get_reply().trim();
-                       if (!ishex(line) || line.length() % 2 != 0)
+                       if (!Altos.ishex(line) || line.length() % 2 != 0)
                                throw new IOException(
                                        String.format
                                        ("Invalid reply \"%s\"", line));
                        int this_time = line.length() / 2;
                        for (int j = 0; j < this_time; j++)
-                               data[start + j] = (byte) ((fromhex(line.charAt(j*2)) << 4) +
-                                                 fromhex(line.charAt(j*2+1)));
+                               data[start + j] = (byte) ((Altos.fromhex(line.charAt(j*2)) << 4) +
+                                                 Altos.fromhex(line.charAt(j*2+1)));
                        start += this_time;
                        i += this_time;
                }
@@ -190,7 +154,7 @@ public class AltosDebug extends AltosSerial {
        public byte[] read_bytes(int length)
                throws IOException, InterruptedException {
 
-               flush_reply();
+               flush_input();
                ensure_debug_mode();
                printf("G %x\n", length);
                int i = 0;
@@ -199,7 +163,7 @@ public class AltosDebug extends AltosSerial {
                        String line = get_reply().trim();
                        String tokens[] = line.split("\\s+");
                        for (int j = 0; j < tokens.length; j++) {
-                               if (!ishex(tokens[j]) ||
+                               if (!Altos.ishex(tokens[j]) ||
                                    tokens[j].length() != 2)
                                        throw new IOException(
                                                String.format
@@ -296,4 +260,8 @@ public class AltosDebug extends AltosSerial {
        public void reset() {
                printf ("R\n");
        }
+
+       public AltosDebug (altos_device in_device) throws FileNotFoundException, AltosSerialInUseException {
+               super(in_device);
+       }
 }
\ No newline at end of file