diff --git a/src/com/webcodepro/applecommander/util/AppleUtil.java b/src/com/webcodepro/applecommander/util/AppleUtil.java index 4a94c6e..f0e63e0 100644 --- a/src/com/webcodepro/applecommander/util/AppleUtil.java +++ b/src/com/webcodepro/applecommander/util/AppleUtil.java @@ -21,6 +21,7 @@ package com.webcodepro.applecommander.util; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.PrintWriter; import java.util.Date; import java.util.GregorianCalendar; @@ -31,6 +32,17 @@ import java.util.GregorianCalendar; * @author Rob Greene */ public class AppleUtil { + /** + * This is the number of bytes to display per line. + */ + private static final int BYTES_PER_LINE = 16; + + /** + * This is the ASCII space character as used by the Apple ][. + * The high bit is off. + */ + private static final int APPLE_SPACE = 0x20; + /** * Bit masks used for the bit shifting or testing operations. */ @@ -502,4 +514,55 @@ public class AppleUtil { (byte) ((result & byte5Mask) >> 24 & 0xff) }; } + + /** + * Generate a simple hex dump from the given byte array. + *

+ * This is in the general form of:
+ * MMMMMM: HH HH HH HH HH HH HH HH HH HH HH HH HH HH HH HH AAAAAAAA AAAAAAAA
+ * Where MMMMMM = memory address, HH = hex byte, and + * A = ASCII character. + */ + public static String getHexDump(byte[] bytes) { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + PrintWriter printer = new PrintWriter(output); + printer.print(" Offset "); + printer.print("Hex Data "); + printer.println("Characters"); + printer.print("======= "); + printer.print("================================================ "); + printer.println("================="); + for (int offset=0; offset= (byte)APPLE_SPACE) { + printer.print(ch); + } else { + printer.print('.'); + } + } else { + printer.print(' '); + } + } + printer.println(); + } + printer.println("** END **"); + printer.flush(); + printer.close(); + return output.toString(); + } }