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)
{
if ((depth++ & 0x07) == 0) // every 8th bit
currentByte = message[msgPtr++]; // get a new byte
if ((depth++ & 0x07) == 0) // every 8th bit...
currentByte = message[msgPtr++]; // ...get a new byte
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
byte nodeValue = buffer[treePtr + offset[currentBit]];

View File

@ -8,16 +8,13 @@ import com.bytezone.common.Utility;
public class MessageBlock implements Iterable<MessageDataBlock>
{
// private final byte[] buffer;
private final int indexOffset;
private final int indexLength;
private final List<MessageDataBlock> messageDataBlocks =
new ArrayList<MessageDataBlock> ();
private Huffman huffman;
public MessageBlock (byte[] buffer)
public MessageBlock (byte[] buffer, Huffman huffman)
{
indexOffset = Utility.getWord (buffer, 0);
indexLength = Utility.getWord (buffer, 2);
@ -29,19 +26,12 @@ public class MessageBlock implements Iterable<MessageDataBlock>
int firstMessageNo = Utility.getWord (buffer, ptr + i * 2);
byte[] data = new byte[512];
System.arraycopy (buffer, i * 512, data, 0, data.length);
MessageDataBlock messageDataBlock =
new MessageDataBlock ("Block " + firstMessageNo, data, firstMessageNo);
MessageDataBlock messageDataBlock = new MessageDataBlock (
"Block " + i + " Msg " + firstMessageNo, data, firstMessageNo, huffman);
messageDataBlocks.add (messageDataBlock);
}
}
public void setHuffman (Huffman huffman)
{
this.huffman = huffman;
for (MessageDataBlock messageDataBlock : messageDataBlocks)
messageDataBlock.setHuffman (huffman);
}
public byte[] getMessage (int messageNo)
{
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
{
// private final byte[] buffer;
// private final int offset;
final int firstMessageNo;
// private final int lastMessageNo;
private final int groupCount;
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);
this.firstMessageNo = firstMessageNo;
this.huffman = huffman;
int ptr = 0x1FF; // last byte in block
groupCount = buffer[ptr--] & 0xFF;
@ -77,11 +76,6 @@ public class MessageDataBlock extends AbstractFile
return null;
}
void setHuffman (Huffman huffman)
{
this.huffman = huffman;
}
@Override
public String getText ()
{
@ -98,8 +92,8 @@ public class MessageDataBlock extends AbstractFile
lastMessageNo = message.msgNo;
byte[] returnMessage = new byte[message.length];
System.arraycopy (buffer, message.offset, returnMessage, 0, message.length);
text.append (
String.format ("%5d %s%n", message.msgNo, huffman.decodeMessage (returnMessage)));
text.append (String.format ("%5d %s%n", message.msgNo,
huffman.decodeMessage (returnMessage)));
}
if (text.length () > 0)

View File

@ -20,9 +20,9 @@ public class Wizardry4BootDisk extends PascalDisk
{
public Header scenarioHeader;
List<AppleDisk> disks = new ArrayList<AppleDisk> ();
// protected Disk[] dataDisks;
private Relocator relocator;
private MessageBlock messageBlock;
private Huffman huffman;
public Wizardry4BootDisk (AppleDisk[] dataDisks)
{
@ -74,19 +74,6 @@ public class Wizardry4BootDisk extends PascalDisk
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");
fileEntry = (FileEntry) huffNode.getUserObject ();
if (fileEntry != null)
@ -94,10 +81,22 @@ public class Wizardry4BootDisk extends PascalDisk
byte[] buffer = fileEntry.getDataSource ().buffer;
Huffman huffman = new Huffman ("Huffman tree", buffer);
messageBlock.setHuffman (huffman);
huffman = new Huffman ("Huffman tree", buffer);
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)