From e16fce45c49b4a96fa54a1cd69a9d4c7900b719f Mon Sep 17 00:00:00 2001 From: Robert Greene Date: Mon, 9 Dec 2002 05:43:13 +0000 Subject: [PATCH] Added setBit, clearBit, setString, setWordValue. --- .../applecommander/storage/AppleUtil.java | 49 +++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/com/webcodepro/applecommander/storage/AppleUtil.java b/src/com/webcodepro/applecommander/storage/AppleUtil.java index a47f688..7683aa5 100644 --- a/src/com/webcodepro/applecommander/storage/AppleUtil.java +++ b/src/com/webcodepro/applecommander/storage/AppleUtil.java @@ -29,6 +29,9 @@ import java.util.GregorianCalendar; * @author: Rob Greene */ public class AppleUtil { + private static byte[] masks = { + (byte)0x01, (byte)0x02, (byte)0x04, (byte)0x08, + (byte)0x10, (byte)0x20, (byte)0x40, (byte)0x80 }; /** * Compute the value of a word. @@ -43,7 +46,15 @@ public class AppleUtil { */ public static int getWordValue(byte low, byte high) { return getUnsignedByte(low) + getUnsignedByte(high)*256; - } + } + + /** + * Set a word value. + */ + public static void setWordValue(byte[] buffer, int offset, int value) { + buffer[offset] = (byte)(value % 256); + buffer[offset+1] = (byte)(value / 256); + } /** * Compute the value of a 3 byte value. This may be ProDOS specific. @@ -80,10 +91,22 @@ public class AppleUtil { * Determine if a specific bit is set. */ public static boolean isBitSet(byte byt, int bit) { - byte[] masks = { (byte)0x01, (byte)0x02,(byte)0x04, (byte)0x08, - (byte)0x10, (byte)0x20, (byte)0x40, (byte)0x80 }; return (byt & masks[bit]) != 0; } + + /** + * Set a specific bit (turn it on). + */ + public static byte setBit(byte byt, int bit) { + return (byte) ((byt | masks[bit]) & 0xff); + } + + /** + * Clear a specific bit (turn it off). + */ + public static byte clearBit(byte byt, int bit) { + return (byte) ((byt & ~masks[bit]) & 0xff); + } /** * Extract a string from the buffer. @@ -97,6 +120,26 @@ public class AppleUtil { } return new String(value); } + + /** + * Create an Apple string that is space delimited. + */ + public static void setString(byte[] buffer, int offset, String string, int length) { + for (int i=0; i