Removed stupid HexFormatter call

This commit is contained in:
Denis Molony 2016-12-18 09:07:55 +11:00
parent 871fb79913
commit 5ed0d0d16a
23 changed files with 553 additions and 538 deletions

View File

@ -61,14 +61,15 @@ public class AssemblerStatement
lastMnemonic = as.mnemonic;
System.out.println ();
}
System.out.printf ("%3s %-15s %s%n", as.mnemonic, AssemblerConstants.mode[as.mode], as);
System.out.printf ("%3s %-15s %s%n", as.mnemonic,
AssemblerConstants.mode[as.mode], as);
}
}
public AssemblerStatement (byte opcode)
{
this.value = opcode;
this.opcode = HexFormatter.intValue (opcode);
this.opcode = opcode & 0xFF;
this.mnemonic = AssemblerConstants.mnemonics[this.opcode];
this.size = AssemblerConstants.sizes2[this.opcode];
this.operand = "";
@ -128,8 +129,8 @@ public class AssemblerStatement
{
operand1 = b;
String address = "$" + HexFormatter.format2 (b);
// if (this.mnemonic.equals ("JSR"))
// this.target = HexFormatter.intValue (b);
// if (this.mnemonic.equals ("JSR"))
// this.target = HexFormatter.intValue (b);
switch (this.opcode)
{
@ -173,7 +174,7 @@ public class AssemblerStatement
case 0xE4: // CPX
case 0xE5: // SBC
case 0xE6: // INC
target = HexFormatter.intValue (b);
target = b & 0xFF;
operand = address;
mode = 8; // Zero page
break;
@ -253,7 +254,7 @@ public class AssemblerStatement
case 0xF0: // BEQ
offset = b;
mode = 14; // relative
this.target = HexFormatter.intValue (b);
this.target = b & 0xFF;
break;
default:
@ -266,10 +267,10 @@ public class AssemblerStatement
operand1 = b1;
operand2 = b2;
String address = "$" + HexFormatter.format2 (b2) + HexFormatter.format2 (b1);
// if (this.mnemonic.equals ("JSR") || this.mnemonic.equals ("JMP")
// || this.mnemonic.equals ("BIT") || this.mnemonic.equals ("STA")
// || this.mnemonic.equals ("LDA"))
// this.target = HexFormatter.intValue (b1, b2);
// if (this.mnemonic.equals ("JSR") || this.mnemonic.equals ("JMP")
// || this.mnemonic.equals ("BIT") || this.mnemonic.equals ("STA")
// || this.mnemonic.equals ("LDA"))
// this.target = HexFormatter.intValue (b1, b2);
switch (this.opcode)
{
@ -358,6 +359,7 @@ public class AssemblerStatement
{
if (offset == 0)
return String.format ("%d %3s %-10s %02X", size, mnemonic, operand, value);
return String.format ("%d %3s %-10s %02X", size, mnemonic, operand + "+" + offset, value);
return String.format ("%d %3s %-10s %02X", size, mnemonic, operand + "+" + offset,
value);
}
}

View File

@ -1,31 +1,30 @@
package com.bytezone.diskbrowser.applefile;
import com.bytezone.diskbrowser.utilities.HexFormatter;
public class Charset extends AbstractFile
{
public Charset (String name, byte[] buffer)
{
super (name, buffer);
}
public Charset (String name, byte[] buffer)
{
super (name, buffer);
}
public String getText ()
{
StringBuilder text = new StringBuilder ();
for (int i = 0; i < buffer.length; i += 8)
{
for (int line = 7; line >= 0; line--)
{
int value = HexFormatter.intValue (buffer[i + line]);
for (int bit = 0; bit < 8; bit++)
{
text.append ((value & 0x01) == 1 ? "X" : ".");
value >>= 1;
}
text.append ("\n");
}
text.append ("\n");
}
return text.toString ();
}
@Override
public String getText ()
{
StringBuilder text = new StringBuilder ();
for (int i = 0; i < buffer.length; i += 8)
{
for (int line = 7; line >= 0; line--)
{
int value = buffer[i + line] & 0xFF;
for (int bit = 0; bit < 8; bit++)
{
text.append ((value & 0x01) == 1 ? "X" : ".");
value >>= 1;
}
text.append ("\n");
}
text.append ("\n");
}
return text.toString ();
}
}

View File

@ -5,17 +5,18 @@ import com.bytezone.diskbrowser.utilities.HexFormatter;
public class IntegerBasicProgram extends AbstractFile
{
private static String[] tokens =
{ "?", "?", "?", " : ", "?", "?", "?", "?", "?", "?", "?", "?", "CLR", "?", "?", "?",
"HIMEM: ", "LOMEM: ", " + ", " - ", " * ", " / ", " = ", " # ", " >= ", " > ",
" <= ", " <> ", " < ", " AND ", " OR ", " MOD ", "^", "+", "(", ",", " THEN ",
" THEN ", ",", ",", "\"", "\"", "(", "!", "!", "(", "PEEK ", "RND ", "SGN", "ABS",
"PDL", "RNDX", "(", "+", "-", "NOT ", "(", "=", "#", "LEN(", "ASC(", "SCRN(", ",",
"(", "$", "$", "(", ", ", ",", ";", ";", ";", ",", ",", ",", "TEXT", "GR ", "CALL ",
"DIM ", "DIM ", "TAB ", "END", "INPUT ", "INPUT ", "INPUT ", "FOR ", " = ", " TO ",
" STEP ", "NEXT ", ",", "RETURN", "GOSUB ", "REM ", "LET ", "GOTO ", "IF ", "PRINT ",
"PRINT ", "PRINT", "POKE ", ",", "COLOR=", "PLOT", ",", "HLIN", ",", " AT ", "VLIN ",
",", " AT ", "VTAB ", " = ", " = ", ")", ")", "LIST ", ",", "LIST ", "POP ",
"NODSP ", "NODSP ", "NOTRACE ", "DSP ", "DSP ", "TRACE ", "PR#", "IN#", };
{ "?", "?", "?", " : ", "?", "?", "?", "?", "?", "?", "?", "?", "CLR", "?", "?",
"?", "HIMEM: ", "LOMEM: ", " + ", " - ", " * ", " / ", " = ", " # ", " >= ",
" > ", " <= ", " <> ", " < ", " AND ", " OR ", " MOD ", "^", "+", "(", ",",
" THEN ", " THEN ", ",", ",", "\"", "\"", "(", "!", "!", "(", "PEEK ", "RND ",
"SGN", "ABS", "PDL", "RNDX", "(", "+", "-", "NOT ", "(", "=", "#", "LEN(", "ASC(",
"SCRN(", ",", "(", "$", "$", "(", ", ", ",", ";", ";", ";", ",", ",", ",", "TEXT",
"GR ", "CALL ", "DIM ", "DIM ", "TAB ", "END", "INPUT ", "INPUT ", "INPUT ",
"FOR ", " = ", " TO ", " STEP ", "NEXT ", ",", "RETURN", "GOSUB ", "REM ", "LET ",
"GOTO ", "IF ", "PRINT ", "PRINT ", "PRINT", "POKE ", ",", "COLOR=", "PLOT", ",",
"HLIN", ",", " AT ", "VLIN ", ",", " AT ", "VTAB ", " = ", " = ", ")", ")",
"LIST ", ",", "LIST ", "POP ", "NODSP ", "NODSP ", "NOTRACE ", "DSP ", "DSP ",
"TRACE ", "PR#", "IN#", };
public IntegerBasicProgram (String name, byte[] buffer)
{
@ -27,8 +28,8 @@ public class IntegerBasicProgram extends AbstractFile
{
StringBuilder pgm = new StringBuilder ();
pgm.append ("Name : " + name + "\n");
pgm.append ("Length : $" + HexFormatter.format4 (buffer.length) + " (" + buffer.length
+ ")\n\n");
pgm.append ("Length : $" + HexFormatter.format4 (buffer.length) + " ("
+ buffer.length + ")\n\n");
int ptr = 0;
boolean looksLikeAssembler = checkForAssembler (); // this can probably go
@ -36,7 +37,7 @@ public class IntegerBasicProgram extends AbstractFile
while (ptr < buffer.length)
{
int lineLength = HexFormatter.intValue (buffer[ptr]);
int lineLength = buffer[ptr] & 0xFF;
/*
* It appears that lines ending in 00 are S-C Assembler programs, and
* lines ending in 01 are Integer Basic programs.
@ -86,7 +87,7 @@ public class IntegerBasicProgram extends AbstractFile
pgm.append (' ');
continue;
}
int b = HexFormatter.intValue (buffer[i]);
int b = buffer[i] & 0xFF;
pgm.append ((char) b);
}
}
@ -97,7 +98,7 @@ public class IntegerBasicProgram extends AbstractFile
while (ptr < buffer.length)
{
int lineLength = HexFormatter.intValue (buffer[ptr]);
int lineLength = buffer[ptr] & 0xFF;
if (lineLength == 255)
System.out.printf ("Line length %d%n", lineLength);
int p2 = ptr + lineLength - 1;
@ -122,7 +123,7 @@ public class IntegerBasicProgram extends AbstractFile
System.out.println ("Empty buffer array");
return false;
}
int lineLength = HexFormatter.intValue (buffer[0]);
int lineLength = buffer[0] & 0xFF;
if (lineLength <= 0)
return false;
return buffer[lineLength - 1] == 0;
@ -130,8 +131,7 @@ public class IntegerBasicProgram extends AbstractFile
private void appendSCAssembler (StringBuilder pgm, int ptr, int lineLength)
{
int lineNumber = HexFormatter.intValue (buffer[ptr + 2]) * 256
+ HexFormatter.intValue (buffer[ptr + 1]);
int lineNumber = (buffer[ptr + 2] & 0xFF) * 256 + (buffer[ptr + 1] & 0xFF);
pgm.append (String.format ("%4d: ", lineNumber));
int p2 = ptr + 3;
while (buffer[p2] != 0)
@ -168,18 +168,18 @@ public class IntegerBasicProgram extends AbstractFile
for (int p = ptr + 3; p < ptr + lineLength - 1; p++)
{
int b = HexFormatter.intValue (buffer[p]);
int b = buffer[p] & 0xFF;
if (b == 0x03 // token for colon (:)
&& !inString && !inRemark && buffer[p + 1] != 1) // not end of line
&& !inString && !inRemark && buffer[p + 1] != 1) // not end of line
{
pgm.append (":\n" + " ".substring (0, lineTab));
continue;
}
if (b >= 0xB0 && b <= 0xB9 // numeric literal
&& (buffer[p - 1] & 0x80) == 0 // not a variable name
&& !inString && !inRemark)
&& (buffer[p - 1] & 0x80) == 0 // not a variable name
&& !inString && !inRemark)
{
pgm.append (HexFormatter.intValue (buffer[p + 1], buffer[p + 2]));
p += 2;
@ -217,13 +217,13 @@ public class IntegerBasicProgram extends AbstractFile
pgm.append ("Name : " + name + "\n");
pgm.append ("Length : $" + HexFormatter.format4 (buffer.length) + " (" + buffer.length
+ ")\n\n");
+ ")\n\n");
int ptr = 0;
while (ptr < buffer.length)
{
int lineLength = HexFormatter.intValue (buffer[ptr]);
int lineLength = buffer[ptr] & 0xFF;
int p2 = ptr + lineLength - 1;
if (p2 < 0 || p2 >= buffer.length || buffer[p2] > 1)
{

View File

@ -5,6 +5,18 @@ import java.util.List;
import com.bytezone.diskbrowser.utilities.HexFormatter;
/*-
* Offset Meaning
* 0 # of shapes
* 1 unused
* 2-3 offset to shape #1 (S1)
* 3-4 offset to shape #2 (S2)
* S1-S1+1 shape definition #1
* S1+n last byte = 0
* S2-S2+1 shape definition #1
* S2+n last byte = 0
*/
public class ShapeTable extends AbstractFile
{
private static final int SIZE = 400;
@ -23,7 +35,7 @@ public class ShapeTable extends AbstractFile
for (int i = 0; i < totalShapes; i++)
{
int offset = HexFormatter.intValue (buffer[i * 2 + 2], buffer[i * 2 + 3]);
int offset = HexFormatter.getShort (buffer, i * 2 + 2);
int[][] grid = new int[SIZE][SIZE];
int row = startPos;
int col = row;
@ -147,7 +159,7 @@ public class ShapeTable extends AbstractFile
return false;
// check index points inside the file
int offset = HexFormatter.intValue (buffer[ptr], buffer[ptr + 1]);
int offset = HexFormatter.getShort (buffer, ptr);
if (offset == 0 || offset >= buffer.length)
return false;

View File

@ -4,239 +4,242 @@ import com.bytezone.diskbrowser.utilities.HexFormatter;
public class StoredVariables extends AbstractFile
{
public StoredVariables (String name, byte[] buffer)
{
super (name, buffer);
}
public StoredVariables (String name, byte[] buffer)
{
super (name, buffer);
}
public String getText ()
{
StringBuilder text = new StringBuilder ();
String strValue = null;
int intValue = 0;
// double doubleValue = 0.0;
int strPtr = buffer.length;
@Override
public String getText ()
{
StringBuilder text = new StringBuilder ();
String strValue = null;
int intValue = 0;
// double doubleValue = 0.0;
int strPtr = buffer.length;
text.append ("File length : " + HexFormatter.format4 (buffer.length));
int totalLength = HexFormatter.intValue (buffer[0], buffer[1]);
text.append ("\nTotal length : " + HexFormatter.format4 (totalLength));
text.append ("File length : " + HexFormatter.format4 (buffer.length));
int totalLength = HexFormatter.intValue (buffer[0], buffer[1]);
text.append ("\nTotal length : " + HexFormatter.format4 (totalLength));
int varLength = HexFormatter.intValue (buffer[2], buffer[3]);
text.append ("\nVar length : " + HexFormatter.format4 (varLength));
text.append ("\n\n");
int varLength = HexFormatter.intValue (buffer[2], buffer[3]);
text.append ("\nVar length : " + HexFormatter.format4 (varLength));
text.append ("\n\n");
// list simple variables
// list simple variables
int ptr = 5;
while (ptr < varLength + 5)
{
String variableName = getVariableName (buffer[ptr], buffer[ptr + 1]);
text.append (variableName);
int ptr = 5;
while (ptr < varLength + 5)
{
String variableName = getVariableName (buffer[ptr], buffer[ptr + 1]);
text.append (variableName);
char suffix = variableName.charAt (variableName.length () - 1);
if (suffix == '$')
{
int strLength = HexFormatter.intValue (buffer[ptr + 2]);
strPtr -= strLength;
strValue = HexFormatter.getString (buffer, strPtr, strLength);
text.append (" = " + strValue);
}
else if (suffix == '%')
{
intValue = HexFormatter.intValue (buffer[ptr + 3], buffer[ptr + 2]);
if ((buffer[ptr + 2] & 0x80) > 0)
intValue -= 65536;
text.append (" = " + intValue);
}
else
{
if (hasValue (ptr + 2))
{
String value = HexFormatter.floatValue (buffer, ptr + 2) + "";
if (value.endsWith (".0"))
text.append (" = " + value.substring (0, value.length () - 2));
else
text.append (" = " + value);
}
}
char suffix = variableName.charAt (variableName.length () - 1);
if (suffix == '$')
{
int strLength = buffer[ptr + 2] & 0xFF;
strPtr -= strLength;
strValue = HexFormatter.getString (buffer, strPtr, strLength);
text.append (" = " + strValue);
}
else if (suffix == '%')
{
intValue = HexFormatter.intValue (buffer[ptr + 3], buffer[ptr + 2]);
if ((buffer[ptr + 2] & 0x80) > 0)
intValue -= 65536;
text.append (" = " + intValue);
}
else
{
if (hasValue (ptr + 2))
{
String value = HexFormatter.floatValue (buffer, ptr + 2) + "";
if (value.endsWith (".0"))
text.append (" = " + value.substring (0, value.length () - 2));
else
text.append (" = " + value);
}
}
text.append ("\n");
ptr += 7;
}
listArrays (text, ptr, totalLength, strPtr);
text.append ("\n");
ptr += 7;
}
listArrays (text, ptr, totalLength, strPtr);
return text.toString ();
}
return text.toString ();
}
private String getVariableName (byte b1, byte b2)
{
char c1, c2, suffix;
private String getVariableName (byte b1, byte b2)
{
char c1, c2, suffix;
if ((b1 & 0x80) > 0) // integer
{
c1 = (char) (b1 & 0x7F);
c2 = (char) (b2 & 0x7F);
suffix = '%';
}
else if ((b2 & 0x80) > 0) // string
{
c1 = (char) b1;
c2 = (char) (b2 & 0x7F);
suffix = '$';
}
else
{
c1 = (char) b1;
c2 = (char) b2;
suffix = ' ';
}
if ((b1 & 0x80) > 0) // integer
{
c1 = (char) (b1 & 0x7F);
c2 = (char) (b2 & 0x7F);
suffix = '%';
}
else if ((b2 & 0x80) > 0) // string
{
c1 = (char) b1;
c2 = (char) (b2 & 0x7F);
suffix = '$';
}
else
{
c1 = (char) b1;
c2 = (char) b2;
suffix = ' ';
}
StringBuffer variableName = new StringBuffer ();
variableName.append (c1);
if (c2 > 32)
variableName.append (c2);
if (suffix != ' ')
variableName.append (suffix);
StringBuffer variableName = new StringBuffer ();
variableName.append (c1);
if (c2 > 32)
variableName.append (c2);
if (suffix != ' ')
variableName.append (suffix);
return variableName.toString ();
}
return variableName.toString ();
}
private String getDimensionText (int[] values)
{
StringBuilder text = new StringBuilder ("(");
for (int i = 0; i < values.length; i++)
{
text.append (values[i]);
if (i < values.length - 1)
text.append (',');
}
return text.append (')').toString ();
}
private String getDimensionText (int[] values)
{
StringBuilder text = new StringBuilder ("(");
for (int i = 0; i < values.length; i++)
{
text.append (values[i]);
if (i < values.length - 1)
text.append (',');
}
return text.append (')').toString ();
}
private void listArrays (StringBuilder text, int ptr, int totalLength, int strPtr)
{
while (ptr < totalLength + 5)
{
String variableName = getVariableName (buffer[ptr], buffer[ptr + 1]);
text.append ("\n");
int offset = HexFormatter.intValue (buffer[ptr + 2], buffer[ptr + 3]);
int dimensions = HexFormatter.intValue (buffer[ptr + 4]);
int[] dimensionSizes = new int[dimensions];
int totalElements = 0;
for (int i = 0; i < dimensions; i++)
{
int p = i * 2 + 5 + ptr;
int elements = HexFormatter.intValue (buffer[p + 1], buffer[p]);
dimensionSizes[dimensions - i - 1] = elements - 1;
if (totalElements == 0)
totalElements = elements;
else
totalElements *= elements;
}
private void listArrays (StringBuilder text, int ptr, int totalLength, int strPtr)
{
while (ptr < totalLength + 5)
{
String variableName = getVariableName (buffer[ptr], buffer[ptr + 1]);
text.append ("\n");
int offset = HexFormatter.intValue (buffer[ptr + 2], buffer[ptr + 3]);
int dimensions = buffer[ptr + 4] & 0xFF;
int[] dimensionSizes = new int[dimensions];
int totalElements = 0;
for (int i = 0; i < dimensions; i++)
{
int p = i * 2 + 5 + ptr;
int elements = HexFormatter.intValue (buffer[p + 1], buffer[p]);
dimensionSizes[dimensions - i - 1] = elements - 1;
if (totalElements == 0)
totalElements = elements;
else
totalElements *= elements;
}
int headerSize = 5 + dimensions * 2;
int elementSize = (offset - headerSize) / totalElements;
int headerSize = 5 + dimensions * 2;
int elementSize = (offset - headerSize) / totalElements;
int p = ptr + headerSize;
int[] values = new int[dimensions];
for (int i = 0; i < values.length; i++)
values[i] = 0;
out: while (true)
{
text.append (variableName + " " + getDimensionText (values) + " = ");
if (elementSize == 2)
{
int intValue = HexFormatter.intValue (buffer[p + 1], buffer[p]);
if ((buffer[p] & 0x80) > 0)
intValue -= 65536;
text.append (intValue + "\n");
}
else if (elementSize == 3)
{
int strLength = HexFormatter.intValue (buffer[p]);
if (strLength > 0)
{
strPtr -= strLength;
text.append (HexFormatter.getString (buffer, strPtr, strLength));
}
text.append ("\n");
}
else if (elementSize == 5)
{
if (hasValue (p))
text.append (HexFormatter.floatValue (buffer, p));
text.append ("\n");
}
p += elementSize;
int cp = 0;
while (++values[cp] > dimensionSizes[cp])
{
values[cp++] = 0;
if (cp >= values.length)
break out;
}
}
ptr += offset;
}
}
int p = ptr + headerSize;
int[] values = new int[dimensions];
for (int i = 0; i < values.length; i++)
values[i] = 0;
out: while (true)
{
text.append (variableName + " " + getDimensionText (values) + " = ");
if (elementSize == 2)
{
int intValue = HexFormatter.intValue (buffer[p + 1], buffer[p]);
if ((buffer[p] & 0x80) > 0)
intValue -= 65536;
text.append (intValue + "\n");
}
else if (elementSize == 3)
{
int strLength = buffer[p] & 0xFF;
if (strLength > 0)
{
strPtr -= strLength;
text.append (HexFormatter.getString (buffer, strPtr, strLength));
}
text.append ("\n");
}
else if (elementSize == 5)
{
if (hasValue (p))
text.append (HexFormatter.floatValue (buffer, p));
text.append ("\n");
}
p += elementSize;
int cp = 0;
while (++values[cp] > dimensionSizes[cp])
{
values[cp++] = 0;
if (cp >= values.length)
break out;
}
}
ptr += offset;
}
}
private boolean hasValue (int p)
{
for (int i = 0; i < 5; i++)
if (buffer[p + i] != 0)
return true;
return false;
}
private boolean hasValue (int p)
{
for (int i = 0; i < 5; i++)
if (buffer[p + i] != 0)
return true;
return false;
}
public String getHexDump ()
{
StringBuffer text = new StringBuffer ();
@Override
public String getHexDump ()
{
StringBuffer text = new StringBuffer ();
text.append ("File length : " + HexFormatter.format4 (buffer.length));
int totalLength = HexFormatter.intValue (buffer[0], buffer[1]);
text.append ("\nTotal length : " + HexFormatter.format4 (totalLength));
text.append ("File length : " + HexFormatter.format4 (buffer.length));
int totalLength = HexFormatter.intValue (buffer[0], buffer[1]);
text.append ("\nTotal length : " + HexFormatter.format4 (totalLength));
int varLength = HexFormatter.intValue (buffer[2], buffer[3]);
text.append ("\nVar length : " + HexFormatter.format4 (varLength));
int varLength = HexFormatter.intValue (buffer[2], buffer[3]);
text.append ("\nVar length : " + HexFormatter.format4 (varLength));
int unknown = HexFormatter.intValue (buffer[4]);
text.append ("\nUnknown : " + HexFormatter.format2 (unknown));
text.append ("\n\n");
int unknown = buffer[4] & 0xFF;
text.append ("\nUnknown : " + HexFormatter.format2 (unknown));
text.append ("\n\n");
int ptr = 5;
text.append ("Simple variables : \n\n");
while (ptr < varLength + 5)
{
text.append (HexFormatter.format (buffer, ptr, 7, false, 0) + "\n");
ptr += 7;
}
text.append ("\nArrays : \n\n");
while (ptr < totalLength + 5)
{
int offset = HexFormatter.intValue (buffer[ptr + 2], buffer[ptr + 3]);
int dimensions = HexFormatter.intValue (buffer[ptr + 4]);
int[] dimensionSizes = new int[dimensions];
int totalElements = 0;
for (int i = 0; i < dimensions; i++)
{
int p = i * 2 + 5 + ptr;
int elements = HexFormatter.intValue (buffer[p + 1], buffer[p]);
dimensionSizes[dimensions - i - 1] = elements;
if (totalElements == 0)
totalElements = elements;
else
totalElements *= elements;
}
int headerSize = 5 + dimensions * 2;
text.append (HexFormatter.format (buffer, ptr, headerSize, false, 0) + "\n\n");
text.append (HexFormatter.format (buffer, ptr + headerSize, offset - headerSize, false, 0)
+ "\n\n");
ptr += offset;
}
text.append ("Strings : \n\n");
int length = buffer.length - ptr;
text.append (HexFormatter.format (buffer, ptr, length, false, 0) + "\n\n");
int ptr = 5;
text.append ("Simple variables : \n\n");
while (ptr < varLength + 5)
{
text.append (HexFormatter.format (buffer, ptr, 7, false, 0) + "\n");
ptr += 7;
}
text.append ("\nArrays : \n\n");
while (ptr < totalLength + 5)
{
int offset = HexFormatter.intValue (buffer[ptr + 2], buffer[ptr + 3]);
int dimensions = buffer[ptr + 4] & 0xFF;
int[] dimensionSizes = new int[dimensions];
int totalElements = 0;
for (int i = 0; i < dimensions; i++)
{
int p = i * 2 + 5 + ptr;
int elements = HexFormatter.intValue (buffer[p + 1], buffer[p]);
dimensionSizes[dimensions - i - 1] = elements;
if (totalElements == 0)
totalElements = elements;
else
totalElements *= elements;
}
int headerSize = 5 + dimensions * 2;
text.append (HexFormatter.format (buffer, ptr, headerSize, false, 0) + "\n\n");
text.append (
HexFormatter.format (buffer, ptr + headerSize, offset - headerSize, false, 0)
+ "\n\n");
ptr += offset;
}
text.append ("Strings : \n\n");
int length = buffer.length - ptr;
text.append (HexFormatter.format (buffer, ptr, length, false, 0) + "\n\n");
return text.toString ();
}
return text.toString ();
}
}

View File

@ -1,51 +1,49 @@
package com.bytezone.diskbrowser.applefile;
import com.bytezone.diskbrowser.utilities.HexFormatter;
public class WizardryTitle extends AbstractFile
{
public WizardryTitle (String name, byte[] buffer)
{
super (name, buffer);
}
public WizardryTitle (String name, byte[] buffer)
{
super (name, buffer);
}
@Override
public String getText ()
{
int size = 20;
StringBuilder text = new StringBuilder ();
for (int i = 0; i < buffer.length; i += size)
{
for (int line = 0; line < size; line++)
{
int p = i + line;
if (p >= buffer.length)
break;
int value = HexFormatter.intValue (buffer[p]);
text = decode2 (value, text);
}
text.append ("\n");
}
return text.toString ();
}
@Override
public String getText ()
{
int size = 20;
StringBuilder text = new StringBuilder ();
for (int i = 0; i < buffer.length; i += size)
{
for (int line = 0; line < size; line++)
{
int p = i + line;
if (p >= buffer.length)
break;
int value = buffer[p] & 0xFF;
text = decode2 (value, text);
}
text.append ("\n");
}
return text.toString ();
}
private StringBuilder decode (int value, StringBuilder text)
{
for (int bit = 0; bit < 8; bit++)
{
text.append ((value & 0x01) == 1 ? "X" : " ");
value >>= 1;
}
return text;
}
private StringBuilder decode (int value, StringBuilder text)
{
for (int bit = 0; bit < 8; bit++)
{
text.append ((value & 0x01) == 1 ? "X" : " ");
value >>= 1;
}
return text;
}
private StringBuilder decode2 (int value, StringBuilder text)
{
for (int bit = 7; bit >= 0; bit--)
{
text.append ((value & 0x01) == 1 ? "X" : " ");
value >>= 1;
}
return text;
}
private StringBuilder decode2 (int value, StringBuilder text)
{
for (int bit = 7; bit >= 0; bit--)
{
text.append ((value & 0x01) == 1 ? "X" : " ");
value >>= 1;
}
return text;
}
}

View File

@ -34,8 +34,8 @@ class DosCatalogSector extends AbstractSector
if (buffer[i] == (byte) 0xFF)
{
addText (text, buffer, i + 0, 2,
"DEL: file @ " + HexFormatter.format2 (buffer[i + 32]) + " "
+ HexFormatter.format2 (buffer[i + 1]));
"DEL: file @ " + HexFormatter.format2 (buffer[i + 32]) + " "
+ HexFormatter.format2 (buffer[i + 1]));
addText (text, buffer, i + 2, 1, "DEL: File type " + getType (buffer[i + 2]));
if (buffer[i + 3] == 0)
addText (text, buffer, i + 3, 4, "");
@ -73,7 +73,7 @@ class DosCatalogSector extends AbstractSector
int max = buffer[offset] == (byte) 0xFF ? 32 : 33;
for (int i = 3; i < max; i++)
{
int c = HexFormatter.intValue (buffer[i + offset]);
int c = buffer[i + offset] & 0xFF;
if (c == 136)
{
if (text.length () > 0)

View File

@ -26,7 +26,7 @@ class DosVTOCSector extends AbstractSector
this.parentDisk = parentDisk;
DOSVersion = buffer[3];
volume = HexFormatter.intValue (buffer[6]);
volume = buffer[6] & 0xFF;
maxTSPairs = buffer[39];
lastAllocTrack = buffer[48];
direction = buffer[49];
@ -64,9 +64,8 @@ class DosVTOCSector extends AbstractSector
extra = "(VTOC and Catalog)";
else
extra = "";
addText (text, buffer, i, 4,
String.format ("Track %02X %s %s", (i - 56) / 4,
getBitmap (buffer[i], buffer[i + 1]), extra));
addText (text, buffer, i, 4, String.format ("Track %02X %s %s", (i - 56) / 4,
getBitmap (buffer[i], buffer[i + 1]), extra));
}
text.deleteCharAt (text.length () - 1);

View File

@ -131,7 +131,7 @@ public class PascalDisk extends AbstractFormattedDisk
public static boolean checkFormat (AppleDisk disk, boolean debug)
{
byte[] buffer = disk.readSector (2);
int nameLength = HexFormatter.intValue (buffer[6]);
int nameLength = buffer[6] & 0xFF;
if (nameLength < 1 || nameLength > 7)
{
if (debug)
@ -188,7 +188,7 @@ public class PascalDisk extends AbstractFormattedDisk
return false;
if (kind == 0)
return false;
nameLength = HexFormatter.intValue (buffer[ptr + 6]);
nameLength = buffer[ptr + 6] & 0xFF;
if (nameLength < 1 || nameLength > 15)
return false;
int lastByte = HexFormatter.intValue (buffer[ptr + 22], buffer[ptr + 23]);

View File

@ -30,9 +30,9 @@ abstract class CatalogEntry implements AppleFileSource
name = HexFormatter.getString (entryBuffer, 1, entryBuffer[0] & 0x0F);
storageType = (entryBuffer[0] & 0xF0) >> 4;
created = HexFormatter.getAppleDate (entryBuffer, 24);
version = HexFormatter.intValue (entryBuffer[28]);
minVersion = HexFormatter.intValue (entryBuffer[29]);
access = HexFormatter.intValue (entryBuffer[30]);
version = entryBuffer[28] & 0xFF;
minVersion = entryBuffer[29] & 0xFF;
access = entryBuffer[30] & 0xFF;
}
@Override

View File

@ -12,8 +12,8 @@ abstract class DirectoryHeader extends CatalogEntry
{
super (parentDisk, entryBuffer);
entryLength = HexFormatter.intValue (entryBuffer[31]);
entriesPerBlock = HexFormatter.intValue (entryBuffer[32]);
entryLength = entryBuffer[31] & 0xFF;
entriesPerBlock = entryBuffer[32] & 0xFF;
fileCount = HexFormatter.intValue (entryBuffer[33], entryBuffer[34]);
}
}

View File

@ -49,7 +49,7 @@ class ProdosCatalogSector extends AbstractSector
addText (text, buffer, i, 1, typeText + ", " + hex2 + " = Name length");
addText (text, buffer, i + 1, 4,
HexFormatter.getString (buffer, i + 1, nameLength));
HexFormatter.getString (buffer, i + 1, nameLength));
switch (fileType)
{
@ -80,9 +80,9 @@ class ProdosCatalogSector extends AbstractSector
private String doFileDescription (int offset)
{
StringBuilder text = new StringBuilder ();
int fileType = HexFormatter.intValue (buffer[offset + 16]);
int fileType = buffer[offset + 16] & 0xFF;
addText (text, buffer, offset + 16, 1,
"File type (" + ProdosConstants.fileTypes[fileType] + ")");
"File type (" + ProdosConstants.fileTypes[fileType] + ")");
addTextAndDecimal (text, buffer, offset + 17, 2, "Key pointer");
addTextAndDecimal (text, buffer, offset + 19, 2, "Blocks used");
addTextAndDecimal (text, buffer, offset + 21, 3, "EOF");
@ -93,7 +93,7 @@ class ProdosCatalogSector extends AbstractSector
addText (text, buffer, offset + 29, 1, "Minimum version");
addText (text, buffer, offset + 30, 1, "Access");
addTextAndDecimal (text, buffer, offset + 31, 2,
"Auxilliary type - " + getAuxilliaryText (fileType));
"Auxilliary type - " + getAuxilliaryText (fileType));
GregorianCalendar modified = HexFormatter.getAppleDate (buffer, offset + 33);
String dateM = modified == null ? "" : parent.df.format (modified.getTime ());
addText (text, buffer, offset + 33, 4, "Modification date : " + dateM);
@ -191,7 +191,7 @@ class ProdosCatalogSector extends AbstractSector
{
StringBuilder text = new StringBuilder ();
for (int i = offset, max = offset + 15; i < max && buffer[i] != 0; i++)
text.append ((char) HexFormatter.intValue (buffer[i]));
text.append ((char) buffer[i] & 0xFF);
return text.toString ();
}
}

View File

@ -60,7 +60,7 @@ class ProdosDirectory extends AbstractFile
case ProdosConstants.TYPE_PASCAL_ON_PROFILE:
case ProdosConstants.TYPE_GSOS_EXTENDED_FILE:
case ProdosConstants.TYPE_SUBDIRECTORY:
int type = HexFormatter.intValue (buffer[i + 16]);
int type = buffer[i + 16] & 0xFF;
int blocks = HexFormatter.intValue (buffer[i + 19], buffer[i + 20]);
GregorianCalendar created = HexFormatter.getAppleDate (buffer, i + 24);
@ -74,7 +74,7 @@ class ProdosDirectory extends AbstractFile
modified == null ? "" : parentFD.stf.format (modified.getTime ());
int eof =
HexFormatter.intValue (buffer[i + 21], buffer[i + 22], buffer[i + 23]);
int fileType = HexFormatter.intValue (buffer[i + 16]);
int fileType = buffer[i + 16] & 0xFF;
locked = (buffer[i + 30] & 0xE0) == 0xE0 ? " " : "*";
switch (fileType)
@ -97,17 +97,17 @@ class ProdosDirectory extends AbstractFile
}
text.append (String.format ("%s%-15s %3s %5d %9s %5s %9s %5s %8d %7s%n",
locked, filename, ProdosConstants.fileTypes[type],
blocks, dateM, timeM, dateC, timeC, eof, subType));
locked, filename, ProdosConstants.fileTypes[type], blocks, dateM, timeM,
dateC, timeC, eof, subType));
break;
default:
text.append (" <Unknown strage type : " + storageType + newLine);
}
}
text.append (String.format (
"%nBLOCKS FREE:%5d BLOCKS USED:%5d TOTAL BLOCKS:%5d%n",
freeBlocks, usedBlocks, totalBlocks));
text.append (
String.format ("%nBLOCKS FREE:%5d BLOCKS USED:%5d TOTAL BLOCKS:%5d%n",
freeBlocks, usedBlocks, totalBlocks));
return text.toString ();
}

View File

@ -18,8 +18,8 @@ class SubDirectoryHeader extends DirectoryHeader
this.parentDirectory = parent.parentDirectory;
parentPointer = HexFormatter.intValue (entryBuffer[35], entryBuffer[36]);
parentSequence = HexFormatter.intValue (entryBuffer[37]);
parentSize = HexFormatter.intValue (entryBuffer[38]);
parentSequence = entryBuffer[37] & 0xFF;
parentSize = entryBuffer[38] & 0xFF;
}
@Override
@ -27,7 +27,7 @@ class SubDirectoryHeader extends DirectoryHeader
{
String locked = (access == 0x01) ? "*" : " ";
return String.format (" %s%-40s %15s", locked, "/" + name,
parentDisk.df.format (created.getTime ()));
parentDisk.df.format (created.getTime ()));
}
@Override

View File

@ -151,7 +151,7 @@ public class HexFormatter
for (int i = offset; i < offset + length; i++)
{
int c = intValue (buffer[i]);
int c = buffer[i] & 0xFF;
if (c > 127)
{
if (c < 160)
@ -176,7 +176,7 @@ public class HexFormatter
for (int i = offset; i < offset + length; i++)
{
int c = intValue (buffer[i]);
int c = buffer[i] & 0xFF;
if (c == 136 && text.length () > 0)
{
System.out.println (text.toString ());
@ -241,7 +241,7 @@ public class HexFormatter
public static char byteValue (byte b)
{
int c = intValue (b);
int c = b & 0xFF;
if (c > 127)
c -= 128;
if (c > 95)
@ -288,24 +288,19 @@ public class HexFormatter
return text;
}
public static int intValue (byte b1)
{
// int i1 = b1;
// if (i1 < 0)
// i1 += 256;
// return i1;
return b1 & 0xFF;
}
// public static int intValue (byte b1)
// {
// return b1 & 0xFF;
// }
public static int intValue (byte b1, byte b2)
{
return intValue (b1) + intValue (b2) * 256;
return (b1 & 0xFF) + (b2 & 0xFF) * 256;
}
public static int intValue (byte b1, byte b2, byte b3)
{
return intValue (b1) + intValue (b2) * 256 + intValue (b3) * 65536;
return (b1 & 0xFF) + (b2 & 0xFF) * 256 + (b3 & 0xFF) * 65536;
}
public static int getLong (byte[] buffer, int ptr)
@ -330,6 +325,17 @@ public class HexFormatter
return val;
}
public static int getShort (byte[] buffer, int ptr)
{
int val = 0;
for (int i = 1; i >= 0; i--)
{
val <<= 8;
val += buffer[ptr + i] & 0xFF;
}
return val;
}
public static int getShortBigEndian (byte[] buffer, int ptr)
{
int val = 0;
@ -379,11 +385,11 @@ public class HexFormatter
{
double val = 0;
int exponent = HexFormatter.intValue (buffer[offset]) - 0x80;
int exponent = (buffer[offset] & 0xFF) - 0x80;
int mantissa =
(buffer[offset + 1] & 0x7F) * 0x1000000 + intValue (buffer[offset + 2]) * 0x10000
+ intValue (buffer[offset + 3]) * 0x100 + intValue (buffer[offset + 4]);
(buffer[offset + 1] & 0x7F) * 0x1000000 + (buffer[offset + 2] & 0xFF) * 0x10000
+ (buffer[offset + 3] & 0xFF) * 0x100 + (buffer[offset + 4] & 0xFF);
int weight1 = 1;
long weight2 = 2147483648L;
@ -428,8 +434,8 @@ public class HexFormatter
int year = (date & 0xFE00) >> 9;
int month = (date & 0x01E0) >> 5;
int day = date & 0x001F;
int hour = HexFormatter.intValue (buffer[offset + 3]) & 0x1F;
int minute = HexFormatter.intValue (buffer[offset + 2]) & 0x3F;
int hour = buffer[offset + 3] & 0x1F;
int minute = buffer[offset + 2] & 0x3F;
if (year < 70)
year += 2000;
else
@ -441,7 +447,7 @@ public class HexFormatter
public static GregorianCalendar getPascalDate (byte[] buffer, int offset)
{
int year = intValue (buffer[offset + 1]);
int year = (buffer[offset + 1] & 0xFF);
int day = (buffer[offset] & 0xF0) >> 4;
int month = buffer[offset] & 0x0F;
if (day == 0 || month == 0)
@ -458,7 +464,7 @@ public class HexFormatter
public static String getPascalString (byte[] buffer, int offset)
{
int length = HexFormatter.intValue (buffer[offset]);
int length = buffer[offset] & 0xFF;
return HexFormatter.getString (buffer, offset + 1, length);
}
}

View File

@ -32,13 +32,13 @@ class Character extends AbstractFile
attributes = new Attributes ();
stats = new Statistics ();
stats.race = races[HexFormatter.intValue (buffer[34])];
stats.typeInt = HexFormatter.intValue (buffer[36]);
stats.race = races[buffer[34] & 0xFF];
stats.typeInt = buffer[36] & 0xFF;
stats.type = types[stats.typeInt];
stats.ageInWeeks = HexFormatter.intValue (buffer[38], buffer[39]);
stats.statusValue = buffer[40];
stats.status = statuses[stats.statusValue];
stats.alignment = alignments[HexFormatter.intValue (buffer[42])];
stats.alignment = alignments[buffer[42] & 0xFF];
stats.gold = HexFormatter.intValue (buffer[52], buffer[53])
+ HexFormatter.intValue (buffer[54], buffer[55]) * 10000;
@ -50,30 +50,30 @@ class Character extends AbstractFile
stats.hitsMax = HexFormatter.intValue (buffer[136], buffer[137]);
stats.armourClass = buffer[176];
attributes.strength = HexFormatter.intValue (buffer[44]) % 16;
attributes.strength = (buffer[44] & 0xFF) % 16;
if (attributes.strength < 3)
attributes.strength += 16;
attributes.array[0] = attributes.strength;
int i1 = HexFormatter.intValue (buffer[44]) / 16;
int i2 = HexFormatter.intValue (buffer[45]) % 4;
int i1 = (buffer[44] & 0xFF) / 16;
int i2 = (buffer[45] & 0xFF) % 4;
attributes.intelligence = i1 / 2 + i2 * 8;
attributes.array[1] = attributes.intelligence;
attributes.piety = HexFormatter.intValue (buffer[45]) / 4;
attributes.piety = (buffer[45] & 0xFF) / 4;
attributes.array[2] = attributes.piety;
attributes.vitality = HexFormatter.intValue (buffer[46]) % 16;
attributes.vitality = (buffer[46] & 0xFF) % 16;
if (attributes.vitality < 3)
attributes.vitality += 16;
attributes.array[3] = attributes.vitality;
int a1 = HexFormatter.intValue (buffer[46]) / 16;
int a2 = HexFormatter.intValue (buffer[47]) % 4;
int a1 = (buffer[46] & 0xFF) / 16;
int a2 = (buffer[47] & 0xFF) % 4;
attributes.agility = a1 / 2 + a2 * 8;
attributes.array[4] = attributes.agility;
attributes.luck = HexFormatter.intValue (buffer[47]) / 4;
attributes.luck = (buffer[47] & 0xFF) / 4;
attributes.array[5] = attributes.luck;
}
@ -86,7 +86,7 @@ class Character extends AbstractFile
for (int ptr = 60; totItems > 0; ptr += 8, totItems--)
{
int itemID = HexFormatter.intValue (buffer[ptr + 6]);
int itemID = buffer[ptr + 6] & 0xFF;
if (scenario == 3)
itemID = (itemID + 24) % 256;
if (itemID >= 0 && itemID < itemList.size ())

View File

@ -4,24 +4,24 @@ import com.bytezone.diskbrowser.utilities.HexFormatter;
class CodedMessage extends Message
{
public static int codeOffset = 185;
public static int codeOffset = 185;
public CodedMessage (byte[] buffer)
{
super (buffer);
}
public CodedMessage (byte[] buffer)
{
super (buffer);
}
@Override
protected String getLine (int offset)
{
int length = HexFormatter.intValue (buffer[offset]);
byte[] translation = new byte[length];
codeOffset--;
for (int j = 0; j < length; j++)
{
translation[j] = buffer[offset + 1 + j];
translation[j] -= codeOffset - j * 3;
}
return HexFormatter.getString (translation, 0, length);
}
@Override
protected String getLine (int offset)
{
int length = buffer[offset] & 0xFF;
byte[] translation = new byte[length];
codeOffset--;
for (int j = 0; j < length; j++)
{
translation[j] = buffer[offset + 1 + j];
translation[j] -= codeOffset - j * 3;
}
return HexFormatter.getString (translation, 0, length);
}
}

View File

@ -186,7 +186,7 @@ class Header
{
for (int j = 0; j < 8; j++)
{
int value = HexFormatter.intValue (buffer[i + line + j * 8]);
int value = buffer[i + line + j * 8] & 0xFF;
for (int bit = 0; bit < 7; bit++)
{
if ((value & 0x01) == 1)
@ -217,10 +217,10 @@ class Header
public ScenarioData (byte[] buffer, int seq, List<DiskAddress> sectors)
{
int offset = 42 + seq * 2;
dunno = HexFormatter.intValue (buffer[offset]);
total = HexFormatter.intValue (buffer[offset + 16]);
totalBlocks = HexFormatter.intValue (buffer[offset + 32]);
dataOffset = HexFormatter.intValue (buffer[offset + 48]);
dunno = buffer[offset] & 0xFF;
total = buffer[offset + 16] & 0xFF;
totalBlocks = buffer[offset + 32] & 0xFF;
dataOffset = buffer[offset + 48] & 0xFF;
type = seq;
this.sectors = new ArrayList<DiskAddress> (totalBlocks);

View File

@ -5,137 +5,137 @@ import com.bytezone.diskbrowser.utilities.HexFormatter;
class Item extends AbstractFile implements Comparable<Item>
{
public final int itemID;
private final int type;
private final long cost;
public int partyOwns;
String genericName;
static int counter = 0;
public final Dice damage;
public final int armourClass;
public final int speed;
public final int itemID;
private final int type;
private final long cost;
public int partyOwns;
String genericName;
static int counter = 0;
public final Dice damage;
public final int armourClass;
public final int speed;
public Item (String name, byte[] buffer)
{
super (name, buffer);
itemID = counter++;
type = buffer[32];
cost =
HexFormatter.intValue (buffer[44], buffer[45])
+ HexFormatter.intValue (buffer[46], buffer[47]) * 10000
+ HexFormatter.intValue (buffer[48], buffer[49]) * 100000000L;
genericName = HexFormatter.getPascalString (buffer, 16);
damage = new Dice (buffer, 66);
armourClass = buffer[62];
speed = buffer[72];
}
public Item (String name, byte[] buffer)
{
super (name, buffer);
itemID = counter++;
type = buffer[32];
cost = HexFormatter.intValue (buffer[44], buffer[45])
+ HexFormatter.intValue (buffer[46], buffer[47]) * 10000
+ HexFormatter.intValue (buffer[48], buffer[49]) * 100000000L;
genericName = HexFormatter.getPascalString (buffer, 16);
damage = new Dice (buffer, 66);
armourClass = buffer[62];
speed = buffer[72];
}
@Override
public String getText ()
{
StringBuilder text = new StringBuilder ();
@Override
public String getText ()
{
StringBuilder text = new StringBuilder ();
text.append ("Name ......... : " + name);
// int length = HexFormatter.intValue (buffer[16]);
text.append ("\nGeneric name . : " + genericName);
text.append ("\nType ......... : " + type);
text.append ("\nCost ......... : " + cost);
text.append ("\nArmour class . : " + armourClass);
text.append ("\nDamage ....... : " + damage);
text.append ("\nSpeed ........ : " + speed);
text.append ("\nCursed? ...... : " + isCursed ());
int stock = getStockOnHand ();
text.append ("\nStock on hand : " + stock);
if (stock < 0)
text.append (" (always in stock)");
text.append ("Name ......... : " + name);
// int length = HexFormatter.intValue (buffer[16]);
text.append ("\nGeneric name . : " + genericName);
text.append ("\nType ......... : " + type);
text.append ("\nCost ......... : " + cost);
text.append ("\nArmour class . : " + armourClass);
text.append ("\nDamage ....... : " + damage);
text.append ("\nSpeed ........ : " + speed);
text.append ("\nCursed? ...... : " + isCursed ());
int stock = getStockOnHand ();
text.append ("\nStock on hand : " + stock);
if (stock < 0)
text.append (" (always in stock)");
return text.toString ();
}
return text.toString ();
}
public int getType ()
{
return type;
}
public int getType ()
{
return type;
}
// public int getArmourClass ()
// {
// return buffer[62];
// }
// public int getArmourClass ()
// {
// return buffer[62];
// }
// public int getSpeed ()
// {
// return HexFormatter.intValue (buffer[72]);
// }
// public int getSpeed ()
// {
// return HexFormatter.intValue (buffer[72]);
// }
public long getCost ()
{
return cost;
}
public long getCost ()
{
return cost;
}
public boolean isCursed ()
{
return buffer[36] != 0;
}
public boolean isCursed ()
{
return buffer[36] != 0;
}
public int getStockOnHand ()
{
if (buffer[50] == -1 && buffer[51] == -1)
return -1;
public int getStockOnHand ()
{
if (buffer[50] == -1 && buffer[51] == -1)
return -1;
return HexFormatter.intValue (buffer[50], buffer[51]);
}
return HexFormatter.intValue (buffer[50], buffer[51]);
}
public boolean canUse (int type2)
{
int users = HexFormatter.intValue (buffer[54]);
return ((users >>> type2) & 1) == 1;
}
public boolean canUse (int type2)
{
int users = buffer[54] & 0xFF;
return ((users >>> type2) & 1) == 1;
}
@Override
public String toString ()
{
StringBuilder line = new StringBuilder ();
line.append (String.format ("%-16s", name));
if (buffer[36] == -1)
line.append ("(c) ");
else
line.append (" ");
line.append (String.format ("%02X ", buffer[62]));
line.append (String.format ("%02X ", buffer[34]));
line.append (String.format ("%02X %02X", buffer[50], buffer[51]));
@Override
public String toString ()
{
StringBuilder line = new StringBuilder ();
line.append (String.format ("%-16s", name));
if (buffer[36] == -1)
line.append ("(c) ");
else
line.append (" ");
line.append (String.format ("%02X ", buffer[62]));
line.append (String.format ("%02X ", buffer[34]));
line.append (String.format ("%02X %02X", buffer[50], buffer[51]));
// if (buffer[50] == -1 && buffer[51] == -1)
// line.append ("* ");
// else
// line.append (HexFormatter.intValue (buffer[50], buffer[51]) + " ");
// if (buffer[50] == -1 && buffer[51] == -1)
// line.append ("* ");
// else
// line.append (HexFormatter.intValue (buffer[50], buffer[51]) + " ");
for (int i = 38; i < 44; i++)
line.append (HexFormatter.format2 (buffer[i]) + " ");
for (int i = 48; i < 50; i++)
line.append (HexFormatter.format2 (buffer[i]) + " ");
for (int i = 52; i < 62; i++)
line.append (HexFormatter.format2 (buffer[i]) + " ");
// for (int i = 64; i < 78; i++)
// line.append (HexFormatter.format2 (buffer[i]) + " ");
for (int i = 38; i < 44; i++)
line.append (HexFormatter.format2 (buffer[i]) + " ");
for (int i = 48; i < 50; i++)
line.append (HexFormatter.format2 (buffer[i]) + " ");
for (int i = 52; i < 62; i++)
line.append (HexFormatter.format2 (buffer[i]) + " ");
// for (int i = 64; i < 78; i++)
// line.append (HexFormatter.format2 (buffer[i]) + " ");
return line.toString ();
}
return line.toString ();
}
public String getDump (int block)
{
StringBuilder line = new StringBuilder (String.format ("%3d %-16s", itemID, name));
int lo = block == 0 ? 32 : block == 1 ? 46 : 70;
int hi = lo + 24;
if (hi > buffer.length)
hi = buffer.length;
for (int i = lo; i < hi; i++)
line.append (String.format ("%02X ", buffer[i]));
return line.toString ();
}
public String getDump (int block)
{
StringBuilder line = new StringBuilder (String.format ("%3d %-16s", itemID, name));
int lo = block == 0 ? 32 : block == 1 ? 46 : 70;
int hi = lo + 24;
if (hi > buffer.length)
hi = buffer.length;
for (int i = lo; i < hi; i++)
line.append (String.format ("%02X ", buffer[i]));
return line.toString ();
}
public int compareTo (Item otherItem)
{
Item item = otherItem;
return this.type - item.type;
}
@Override
public int compareTo (Item otherItem)
{
Item item = otherItem;
return this.type - item.type;
}
}

View File

@ -88,13 +88,13 @@ public class MazeGridV5 extends AbstractFile
int offset = gridNo * 16 + column * 2 + row / 4;
int value;
value = HexFormatter.intValue (buffer[offset + 0]);
value = buffer[offset + 0] & 0xFF;
value >>>= (row % 4) * 2;
cell.eastWall = ((value & 1) == 1);
value >>>= 1;
cell.eastDoor = ((value & 1) == 1);
value = HexFormatter.intValue (buffer[offset + 256]);
value = buffer[offset + 256] & 0xFF;
value >>>= (row % 4) * 2;
cell.northWall = ((value & 1) == 1);
value >>>= 1;

View File

@ -105,9 +105,7 @@ class Monster extends AbstractFile implements Comparable<Monster>
StringBuilder text = new StringBuilder ();
// these values definitely affect the damage a monster does (when breathing?)
int exp2 =
(HexFormatter.intValue (buffer[72]) * HexFormatter.intValue (buffer[74]) - 1)
* 20;
int exp2 = ((buffer[72] & 0xFF) * (buffer[74] & 0xFF) - 1) * 20;
int exp3 = weight2[speed]; // 1-6
int exp4 = (10 - armourClass) * 40;
int exp5 = getBonus (35, mageSpellLevel);
@ -191,9 +189,7 @@ class Monster extends AbstractFile implements Comparable<Monster>
public int getExperience ()
{
// these values definitely affect the damage a monster does (when breathing?)
int exp2 =
(HexFormatter.intValue (buffer[72]) * HexFormatter.intValue (buffer[74]) - 1)
* 20;
int exp2 = ((buffer[72] & 0xFF) * (buffer[74] & 0xFF) - 1) * 20;
int exp3 = weight2[speed];
int exp4 = (10 - armourClass) * 40;
int exp5 = getBonus (35, mageSpellLevel);

View File

@ -4,15 +4,15 @@ import com.bytezone.diskbrowser.utilities.HexFormatter;
class PlainMessage extends Message
{
public PlainMessage (byte[] buffer)
{
super (buffer);
}
public PlainMessage (byte[] buffer)
{
super (buffer);
}
@Override
protected String getLine (int offset)
{
int length = HexFormatter.intValue (buffer[offset]);
return HexFormatter.getString (buffer, offset + 1, length);
}
@Override
protected String getLine (int offset)
{
int length = buffer[offset] & 0xFF;
return HexFormatter.getString (buffer, offset + 1, length);
}
}

View File

@ -255,7 +255,7 @@ public class WizardryScenarioDisk extends PascalDisk
int recLen = 208;
for (int ptr = 0; ptr < 832; ptr += recLen)
{
int nameLength = HexFormatter.intValue (buffer[ptr]);
int nameLength = buffer[ptr] & 0xFF;
if (nameLength == 0xC3 || buffer[ptr + 40] == 0x07)
continue;
String name = HexFormatter.getString (buffer, ptr + 1, nameLength);
@ -308,7 +308,7 @@ public class WizardryScenarioDisk extends PascalDisk
int recLen = 158;
for (int ptr = 0; ptr < 948; ptr += recLen)
{
int nameLength = HexFormatter.intValue (buffer[ptr + 32]);
int nameLength = buffer[ptr + 32] & 0xFF;
if (nameLength == 0 || nameLength == 255)
break;
String itemName = HexFormatter.getString (buffer, ptr + 33, nameLength);