Class AppleUtil
Date created: Oct 5, 2002 4:16:16 PM
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidchangeOrderByBlock(BlockDevice sourceOrder, BlockDevice targetOrder) Change block order from source order to target order by copying block by block.static voidchangeOrderBySector(TrackSectorDevice sourceDevice, TrackSectorDevice targetDevice) Change sector order from source order to target order by copying tracks and sectors between devices.static byteclearBit(byte byt, int bit) Clear a specific bit (turn it off).static intconvertFormattedWord(String word) Convert a typical Apple formatted word.static intget3ByteValue(byte[] buffer, int offset) Compute the value of a 3 byte value.static byte[]getApplesoftFloat(double number) Convert a double number to an Applesoft float.static intgetBitCount(byte byt) Count the number of bits set in a byte.static StringgetFormatted3ByteAddress(int addr) Format a 3 byte value as hexadecimal.static StringgetFormattedByte(int byt) Format a byte value as hexadecimal.static StringgetFormattedWord(int word) Format a word value as hexadecimal.static StringgetHexDump(byte[] bytes) Generate a simple hex dump from the given byte array.static StringgetHexDump(int address, byte[] bytes) static StringgetNiceFilename(String filename) Make a "nice" filename.static DategetPascalDate(byte[] buffer, int offset) Extract a Pascal date from the buffer.
Bits 0-3: month (1-12)
Bits 4-8: day (1-31)
Bits 9-15: year (0-99)static StringgetPascalString(byte[] buffer, int offset) Extract a Pascal string from the buffer.static DategetProdosDate(byte[] buffer, int offset) Extract a ProDOS date from the buffer.static StringgetProdosString(byte[] buffer, int offset) Extract a ProDOS string from the buffer.static doublegetSaneNumber(byte[] buffer, int offset) Pull a SANE formatted number from the buffer and return it as a Java double datatype.static intgetSignedWordValue(byte[] buffer, int offset) Compute the signed value of a word.static StringgetString(byte[] buffer, int offset, int length) Extract a string from the buffer.static intgetUnsignedByte(byte value) Extract out an unsigned byte as an int.static intgetUnsignedByte(byte[] buffer, int offset) Extract out an unsigned byte as an int.static intgetWordValue(byte[] buffer, int offset) Compute the value of a word.static intgetWordValue(byte low, byte high) Compute the value of a word.static booleanisBitSet(byte byt, int bit) Determine if a specific bit is set.static voidset3ByteValue(byte[] buffer, int offset, int value) Set the value of a 3 byte value.static bytesetBit(byte byt, int bit) Set a specific bit (turn it on).static voidsetPascalDate(byte[] buffer, int offset, Date date) Set a Pascal data to the buffer.
Bits 0-3: month (1-12)
Bits 4-8: day (1-31)
Bits 9-15: year (0-99)static voidsetPascalString(byte[] buffer, int offset, String string, int maxLength) Set a Pascal string into the buffer.static voidsetProdosDate(byte[] buffer, int offset, Date date) Set a ProDOS date into the buffer.static voidsetProdosString(byte[] buffer, int offset, String string, int maxLength) Sets a ProDOS string into the buffer.static voidCreate an Apple string that is the same length as the given string.static voidCreate an Apple string that is space delimited.static voidCreate an Apple string that is space delimited.static voidsetWordValue(byte[] buffer, int offset, int value) Set a word value.static byte[]unpackBytes(byte[] compressedData) Mimic the Apple IIGS UnPackBytes method call.
-
Constructor Details
-
AppleUtil
public AppleUtil()
-
-
Method Details
-
getWordValue
public static int getWordValue(byte[] buffer, int offset) Compute the value of a word. Pulls value from buffer given the offset. A word is two bytes, in standard Apple LO/HI format. -
getWordValue
public static int getWordValue(byte low, byte high) Compute the value of a word. -
getSignedWordValue
public static int getSignedWordValue(byte[] buffer, int offset) Compute the signed value of a word. -
setWordValue
public static void setWordValue(byte[] buffer, int offset, int value) Set a word value. -
get3ByteValue
public static int get3ByteValue(byte[] buffer, int offset) Compute the value of a 3 byte value. This may be ProDOS specific. Pulls value from buffer given the offset. Stored in standard Apple LO/HI format. -
set3ByteValue
public static void set3ByteValue(byte[] buffer, int offset, int value) Set the value of a 3 byte value. -
getUnsignedByte
public static int getUnsignedByte(byte value) Extract out an unsigned byte as an int. All Java bytes are signed; need to convert to an int and remove the sign. -
getUnsignedByte
public static int getUnsignedByte(byte[] buffer, int offset) Extract out an unsigned byte as an int. All Java bytes are signed; need to convert to an int and remove the sign. -
getBitCount
public static int getBitCount(byte byt) Count the number of bits set in a byte. -
isBitSet
public static boolean isBitSet(byte byt, int bit) Determine if a specific bit is set. -
setBit
public static byte setBit(byte byt, int bit) Set a specific bit (turn it on). -
clearBit
public static byte clearBit(byte byt, int bit) Clear a specific bit (turn it off). -
getString
Extract a string from the buffer. -
setString
Create an Apple string that is space delimited. -
setString
public static void setString(byte[] buffer, int offset, String string, int length, boolean highBitOn) Create an Apple string that is space delimited. -
setString
Create an Apple string that is the same length as the given string. -
getPascalString
Extract a Pascal string from the buffer. -
setPascalString
Set a Pascal string into the buffer. -
getPascalDate
Extract a Pascal date from the buffer.
Bits 0-3: month (1-12)
Bits 4-8: day (1-31)
Bits 9-15: year (0-99) -
setPascalDate
Set a Pascal data to the buffer.
Bits 0-3: month (1-12)
Bits 4-8: day (1-31)
Bits 9-15: year (0-99) -
getProdosString
Extract a ProDOS string from the buffer. -
setProdosString
Sets a ProDOS string into the buffer. -
getFormattedByte
Format a byte value as hexadecimal. -
getFormattedWord
Format a word value as hexadecimal. -
getFormatted3ByteAddress
Format a 3 byte value as hexadecimal. -
convertFormattedWord
Convert a typical Apple formatted word. This is essentially a hex string that may start with a '$' and has 1 - 4 digits. -
getProdosDate
Extract a ProDOS date from the buffer. -
setProdosDate
Set a ProDOS date into the buffer. -
getNiceFilename
Make a "nice" filename. Some of the Apple ][ file names have characters that are unpalatable - such as "/" or "\" or ":" which are directory separators along with other characters that are not allowed by various operating systems. This method just sanitizes the filename. -
unpackBytes
public static byte[] unpackBytes(byte[] compressedData) Mimic the Apple IIGS UnPackBytes method call. The compression is very similar the RLE, but has the following coding conventions:
00xx xxxx = 1 to 64 bytes follow (all different)
01xx xxxx = 3, 5, 6, or 7 repeats of next byte
10xx xxxx = 1 to 64 repeats of next 4 bytes
11xx xxxx = 1 to 64 repeats of next byte taken as 4 bytes
The 6 data bits are stored as length-1; hence 000000 is a length of 1 and 111111 is a length of 64. -
getSaneNumber
public static double getSaneNumber(byte[] buffer, int offset) Pull a SANE formatted number from the buffer and return it as a Java double datatype. Fortunately, SANE is the IEEE 754 format which _is_ Java's double datatype. The Double class has an intrinsic longBitsToDouble method to do this. The SANE/IEEE 754 format is setup as such:E SSSSSSSSSSS FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...F
Where E is the sign bit, S is the exponent bits and F is the fraction bits. The format is discussed within the Double class documentation as around the web. Be aware that the fraction bits are base 2. Meaning that a fraction of .101 is, in reality, a binary fraction. In decimal, this is 1/2 + 0/4 + 1/8 = 5/8 or .625. See http://www.psc.edu/general/software/packages/ieee/ieee.html for an example.
0 1........11 12....................................63
Note: SANE numbers, as stored by AppleWorks are in typical low/high format.
-
getApplesoftFloat
public static byte[] getApplesoftFloat(double number) Convert a double number to an Applesoft float. This is a 5 byte number. See "Applesoft: Internals" for more details and review the Merlin-generated Applesoft source code.Since the number is 5 bytes long, a float will not work - hence the double. Some precision is lost, but (hopefully) nothing significant!
More specifically, the mapping is as follows:
(Applesoft)
EEEEEEEE SFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF
(IEEE 754 - Java)
SEEEEEEE EEEEFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF
The mapping will blank the following Double bits:
S000EEEE EEEEFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFF0000 00000000 00000000 -
getHexDump
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. -
getHexDump
-
changeOrderByBlock
Change block order from source order to target order by copying block by block. -
changeOrderBySector
public static void changeOrderBySector(TrackSectorDevice sourceDevice, TrackSectorDevice targetDevice) Change sector order from source order to target order by copying tracks and sectors between devices.
-