message buglets

This commit is contained in:
Denis Molony 2016-08-16 18:58:42 +10:00
parent 0e6a6e6c3f
commit 0e852d2a77
5 changed files with 75 additions and 52 deletions

View File

@ -56,13 +56,13 @@ public class Huffman
{
if ((tree[treePtr] & 0x02) != 0) // if has right leaf
return right[treePtr];
treePtr = right[treePtr]; // go to right node
treePtr = right[treePtr] & 0xFF; // go to right node
}
else // take left path
{
if ((tree[treePtr] & 0x01) != 0) // if has left leaf
return left[treePtr];
treePtr = left[treePtr]; // go to left node
treePtr = left[treePtr] & 0xFF; // go to left node
}
}
}

View File

@ -1,23 +1,24 @@
package com.bytezone.diskbrowser.wizardry;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.bytezone.common.Utility;
public class MessageBlock
public class MessageBlock implements Iterable<MessageDataBlock>
{
private final byte[] buffer;
// 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)
{
this.buffer = buffer;
indexOffset = Utility.getWord (buffer, 0);
indexLength = Utility.getWord (buffer, 2);
@ -26,12 +27,21 @@ public class MessageBlock
for (int i = 0, max = indexLength / 2; i < max; i++)
{
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 (buffer, i * 512, firstMessageNo);
new MessageDataBlock ("Block " + firstMessageNo, data, firstMessageNo);
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++)
@ -43,16 +53,9 @@ public class MessageBlock
return null;
}
// public int getBlock (int msgNo)
// {
// int ptr = indexOffset * 512;
//
// for (int i = 0; i < indexLength; i += 2)
// {
// int msg = Utility.getWord (buffer, ptr + i);
// if (msg > msgNo)
// return i - 1;
// }
// return indexLength - 1;
// }
@Override
public Iterator<MessageDataBlock> iterator ()
{
return messageDataBlocks.iterator ();
}
}

View File

@ -4,36 +4,30 @@ import java.util.ArrayList;
import java.util.List;
import com.bytezone.common.Utility;
import com.bytezone.diskbrowser.utilities.HexFormatter;
import com.bytezone.diskbrowser.applefile.AbstractFile;
public class MessageDataBlock
public class MessageDataBlock extends AbstractFile
{
private final byte[] buffer;
private final int offset;
// 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> ();
public MessageDataBlock (byte[] buffer, int offset, int firstMessageNo)
private Huffman huffman;
public MessageDataBlock (String name, byte[] buffer, int firstMessageNo)
{
this.buffer = buffer;
this.offset = offset;
super (name, buffer);
this.firstMessageNo = firstMessageNo;
boolean debug = firstMessageNo == 0;
if (debug)
{
System.out.println (HexFormatter.format (buffer, offset, 512));
System.out.println ();
}
int ptr = offset + 0x1FF; // last byte in block
int ptr = 0x1FF; // last byte in block
groupCount = buffer[ptr--] & 0xFF;
int currentMessageNo = firstMessageNo;
int totalMessageBytes = 0;
int totalMessageBytes = firstMessageNo == 1 ? 4 : 0;
for (int i = 0, max = groupCount - 1; i < groupCount; i++, max--)
{
@ -44,7 +38,7 @@ public class MessageDataBlock
int messageLength = buffer[ptr - j - 1] & 0xFF;
totalMessageBytes += messageLength;
Message message = new Message (currentMessageNo + j,
offset + totalMessageBytes - messageLength, messageLength);
totalMessageBytes - messageLength, messageLength);
messages.add (message);
}
@ -69,9 +63,6 @@ public class MessageDataBlock
currentMessageNo += skip;
}
}
if (debug)
System.out.println (this);
}
byte[] getMessage (int messageNo)
@ -86,6 +77,37 @@ public class MessageDataBlock
return null;
}
void setHuffman (Huffman huffman)
{
this.huffman = huffman;
}
@Override
public String getText ()
{
if (huffman == null)
return toString ();
StringBuilder text = new StringBuilder ();
text.append ("\n");
int lastMessageNo = messages.get (0).msgNo - 1;
for (Message message : messages)
{
if (message.msgNo != lastMessageNo + 1)
text.append ("\n");
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.getMessage (returnMessage)));
}
if (text.length () > 0)
text.deleteCharAt (text.length () - 1);
return text.toString ();
}
@Override
public String toString ()
{
@ -122,7 +144,7 @@ public class MessageDataBlock
StringBuilder text = new StringBuilder ();
String data = Utility.getHex (buffer, offset, length);
text.append (String.format ("%5d: %02X %02X : %s", msgNo, offset, length, data));
text.append (String.format ("%5d: %03X %02X : %s", msgNo, offset, length, data));
return text.toString ();
}

View File

@ -5,7 +5,6 @@ import java.awt.image.DataBuffer;
public class Wiz4Image extends AbstractImage
{
public Wiz4Image (String name, byte[] buffer)
{
super (name, buffer);
@ -14,8 +13,6 @@ public class Wiz4Image extends AbstractImage
DataBuffer db = image.getRaster ().getDataBuffer ();
int element = 0;
// System.out.println (HexFormatter.format (buffer));
for (int row = 0; row < 5; row++)
{
for (int line = 0; line < 8; line++)
@ -28,18 +25,12 @@ public class Wiz4Image extends AbstractImage
for (int bit = 0; bit < 7; bit++)
{
if ((b & 0x01) == 0x01)
{
db.setElem (element, 255);
// System.out.print ("X");
}
// else
// System.out.print (".");
b >>>= 1;
element++;
}
}
}
// System.out.println ();
}
}
}

View File

@ -79,6 +79,12 @@ public class Wizardry4BootDisk extends PascalDisk
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");
@ -89,9 +95,10 @@ public class Wizardry4BootDisk extends PascalDisk
byte[] buffer = fileEntry.getDataSource ().buffer;
Huffman huffman = new Huffman (buffer);
messageBlock.setHuffman (huffman);
for (int msg = 2043; msg <= 2045; msg++)
System.out.println (huffman.getMessage (messageBlock.getMessage (msg)));
// for (int msg = 2043; msg <= 2045; msg++)
// System.out.println (huffman.getMessage (messageBlock.getMessage (msg)));
}
}