From f6562b9ce2a60af4f609389277ac2486dd7fd03e Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Thu, 18 Aug 2016 16:35:54 +1000 Subject: [PATCH] tidying --- .../diskbrowser/wizardry/Huffman.java | 10 +++--- .../diskbrowser/wizardry/MessageBlock.java | 16 ++-------- .../wizardry/MessageDataBlock.java | 18 ++++------- .../wizardry/Wizardry4BootDisk.java | 31 +++++++++---------- 4 files changed, 29 insertions(+), 46 deletions(-) diff --git a/src/com/bytezone/diskbrowser/wizardry/Huffman.java b/src/com/bytezone/diskbrowser/wizardry/Huffman.java index 44cf47b..cc162fb 100644 --- a/src/com/bytezone/diskbrowser/wizardry/Huffman.java +++ b/src/com/bytezone/diskbrowser/wizardry/Huffman.java @@ -41,15 +41,15 @@ public class Huffman extends AbstractFile private byte getChar () { - int treePtr = 0; // start at the root + int treePtr = 0; // start at the root 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 + int currentBit = currentByte & 0x01; // extract the next bit to process + 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]]; diff --git a/src/com/bytezone/diskbrowser/wizardry/MessageBlock.java b/src/com/bytezone/diskbrowser/wizardry/MessageBlock.java index 1f69046..3040b74 100644 --- a/src/com/bytezone/diskbrowser/wizardry/MessageBlock.java +++ b/src/com/bytezone/diskbrowser/wizardry/MessageBlock.java @@ -8,16 +8,13 @@ import com.bytezone.common.Utility; public class MessageBlock implements Iterable { - // private final byte[] buffer; private final int indexOffset; private final int indexLength; private final List messageDataBlocks = new ArrayList (); - 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 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++) diff --git a/src/com/bytezone/diskbrowser/wizardry/MessageDataBlock.java b/src/com/bytezone/diskbrowser/wizardry/MessageDataBlock.java index 4f024b6..2fce987 100644 --- a/src/com/bytezone/diskbrowser/wizardry/MessageDataBlock.java +++ b/src/com/bytezone/diskbrowser/wizardry/MessageDataBlock.java @@ -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 messages = new ArrayList (); - 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) diff --git a/src/com/bytezone/diskbrowser/wizardry/Wizardry4BootDisk.java b/src/com/bytezone/diskbrowser/wizardry/Wizardry4BootDisk.java index 8aab2fc..afbb468 100644 --- a/src/com/bytezone/diskbrowser/wizardry/Wizardry4BootDisk.java +++ b/src/com/bytezone/diskbrowser/wizardry/Wizardry4BootDisk.java @@ -20,9 +20,9 @@ public class Wizardry4BootDisk extends PascalDisk { public Header scenarioHeader; List disks = new ArrayList (); - // 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 messageBlocks = new ArrayList (); - 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 messageBlocks = new ArrayList (); + addToNode (mdb, messagesNode, messageBlocks); + } + } } private void linkMazeLevels (DefaultMutableTreeNode scenarioNode, FileEntry fileEntry)