This commit is contained in:
Denis Molony 2016-08-18 16:35:54 +10:00
parent 428767d853
commit f6562b9ce2
4 changed files with 29 additions and 46 deletions

View File

@ -45,11 +45,11 @@ public class Huffman extends AbstractFile
while (true) while (true)
{ {
if ((depth++ & 0x07) == 0) // every 8th bit if ((depth++ & 0x07) == 0) // every 8th bit...
currentByte = message[msgPtr++]; // get a new byte currentByte = message[msgPtr++]; // ...get a new byte
int currentBit = currentByte & 0x01; // extract the next bit to process int currentBit = currentByte & 0x01; // extract the next bit to process
currentByte >>= 1; // and remove it from the byte currentByte >>= 1; // and remove it from the current byte
// use currentBit to determine whether to use the left or right node // use currentBit to determine whether to use the left or right node
byte nodeValue = buffer[treePtr + offset[currentBit]]; byte nodeValue = buffer[treePtr + offset[currentBit]];

View File

@ -8,16 +8,13 @@ import com.bytezone.common.Utility;
public class MessageBlock implements Iterable<MessageDataBlock> public class MessageBlock implements Iterable<MessageDataBlock>
{ {
// private final byte[] buffer;
private final int indexOffset; private final int indexOffset;
private final int indexLength; private final int indexLength;
private final List<MessageDataBlock> messageDataBlocks = private final List<MessageDataBlock> messageDataBlocks =
new ArrayList<MessageDataBlock> (); new ArrayList<MessageDataBlock> ();
private Huffman huffman; public MessageBlock (byte[] buffer, Huffman huffman)
public MessageBlock (byte[] buffer)
{ {
indexOffset = Utility.getWord (buffer, 0); indexOffset = Utility.getWord (buffer, 0);
indexLength = Utility.getWord (buffer, 2); indexLength = Utility.getWord (buffer, 2);
@ -29,19 +26,12 @@ public class MessageBlock implements Iterable<MessageDataBlock>
int firstMessageNo = Utility.getWord (buffer, ptr + i * 2); int firstMessageNo = Utility.getWord (buffer, ptr + i * 2);
byte[] data = new byte[512]; byte[] data = new byte[512];
System.arraycopy (buffer, i * 512, data, 0, data.length); System.arraycopy (buffer, i * 512, data, 0, data.length);
MessageDataBlock messageDataBlock = MessageDataBlock messageDataBlock = new MessageDataBlock (
new MessageDataBlock ("Block " + firstMessageNo, data, firstMessageNo); "Block " + i + " Msg " + firstMessageNo, data, firstMessageNo, huffman);
messageDataBlocks.add (messageDataBlock); messageDataBlocks.add (messageDataBlock);
} }
} }
public void setHuffman (Huffman huffman)
{
this.huffman = huffman;
for (MessageDataBlock messageDataBlock : messageDataBlocks)
messageDataBlock.setHuffman (huffman);
}
public byte[] getMessage (int messageNo) public byte[] getMessage (int messageNo)
{ {
for (int i = 0; i < messageDataBlocks.size (); i++) for (int i = 0; i < messageDataBlocks.size (); i++)

View File

@ -8,20 +8,19 @@ import com.bytezone.diskbrowser.applefile.AbstractFile;
public class MessageDataBlock extends AbstractFile public class MessageDataBlock extends AbstractFile
{ {
// private final byte[] buffer;
// private final int offset;
final int firstMessageNo; final int firstMessageNo;
// private final int lastMessageNo;
private final int groupCount; private final int groupCount;
private final List<Message> messages = new ArrayList<Message> (); private final List<Message> messages = new ArrayList<Message> ();
private Huffman huffman; private final Huffman huffman;
public MessageDataBlock (String name, byte[] buffer, int firstMessageNo) public MessageDataBlock (String name, byte[] buffer, int firstMessageNo,
Huffman huffman)
{ {
super (name, buffer); super (name, buffer);
this.firstMessageNo = firstMessageNo; this.firstMessageNo = firstMessageNo;
this.huffman = huffman;
int ptr = 0x1FF; // last byte in block int ptr = 0x1FF; // last byte in block
groupCount = buffer[ptr--] & 0xFF; groupCount = buffer[ptr--] & 0xFF;
@ -77,11 +76,6 @@ public class MessageDataBlock extends AbstractFile
return null; return null;
} }
void setHuffman (Huffman huffman)
{
this.huffman = huffman;
}
@Override @Override
public String getText () public String getText ()
{ {
@ -98,8 +92,8 @@ public class MessageDataBlock extends AbstractFile
lastMessageNo = message.msgNo; lastMessageNo = message.msgNo;
byte[] returnMessage = new byte[message.length]; byte[] returnMessage = new byte[message.length];
System.arraycopy (buffer, message.offset, returnMessage, 0, message.length); System.arraycopy (buffer, message.offset, returnMessage, 0, message.length);
text.append ( text.append (String.format ("%5d %s%n", message.msgNo,
String.format ("%5d %s%n", message.msgNo, huffman.decodeMessage (returnMessage))); huffman.decodeMessage (returnMessage)));
} }
if (text.length () > 0) if (text.length () > 0)

View File

@ -20,9 +20,9 @@ public class Wizardry4BootDisk extends PascalDisk
{ {
public Header scenarioHeader; public Header scenarioHeader;
List<AppleDisk> disks = new ArrayList<AppleDisk> (); List<AppleDisk> disks = new ArrayList<AppleDisk> ();
// protected Disk[] dataDisks;
private Relocator relocator; private Relocator relocator;
private MessageBlock messageBlock; private MessageBlock messageBlock;
private Huffman huffman;
public Wizardry4BootDisk (AppleDisk[] dataDisks) public Wizardry4BootDisk (AppleDisk[] dataDisks)
{ {
@ -74,19 +74,6 @@ public class Wizardry4BootDisk extends PascalDisk
linkMonsterImages (monstersNode, fileEntry); linkMonsterImages (monstersNode, fileEntry);
} }
DefaultMutableTreeNode messagesNode = findNode (currentRoot, "ASCII.KRN");
fileEntry = (FileEntry) messagesNode.getUserObject ();
if (fileEntry != null)
{
messageBlock = new MessageBlock (fileEntry.getDataSource ().buffer);
messagesNode.setAllowsChildren (true);
for (MessageDataBlock mdb : messageBlock)
{
List<DiskAddress> messageBlocks = new ArrayList<DiskAddress> ();
addToNode (mdb, messagesNode, messageBlocks);
}
}
DefaultMutableTreeNode huffNode = findNode (currentRoot, "ASCII.HUFF"); DefaultMutableTreeNode huffNode = findNode (currentRoot, "ASCII.HUFF");
fileEntry = (FileEntry) huffNode.getUserObject (); fileEntry = (FileEntry) huffNode.getUserObject ();
if (fileEntry != null) if (fileEntry != null)
@ -94,10 +81,22 @@ public class Wizardry4BootDisk extends PascalDisk
byte[] buffer = fileEntry.getDataSource ().buffer; byte[] buffer = fileEntry.getDataSource ().buffer;
Huffman huffman = new Huffman ("Huffman tree", buffer); huffman = new Huffman ("Huffman tree", buffer);
messageBlock.setHuffman (huffman);
fileEntry.setFile (huffman); fileEntry.setFile (huffman);
} }
DefaultMutableTreeNode messagesNode = findNode (currentRoot, "ASCII.KRN");
fileEntry = (FileEntry) messagesNode.getUserObject ();
if (fileEntry != null)
{
messageBlock = new MessageBlock (fileEntry.getDataSource ().buffer, huffman);
messagesNode.setAllowsChildren (true);
for (MessageDataBlock mdb : messageBlock)
{
List<DiskAddress> messageBlocks = new ArrayList<DiskAddress> ();
addToNode (mdb, messagesNode, messageBlocks);
}
}
} }
private void linkMazeLevels (DefaultMutableTreeNode scenarioNode, FileEntry fileEntry) private void linkMazeLevels (DefaultMutableTreeNode scenarioNode, FileEntry fileEntry)