From a6cc3529de3e0c68b12d0d28e53c0b09ea652685 Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Wed, 24 Aug 2016 00:14:04 +1000 Subject: [PATCH] linking messages to maps --- .../diskbrowser/wizardry/MazeGridV5.java | 28 +++++++- .../diskbrowser/wizardry/MazeLevel.java | 1 - .../diskbrowser/wizardry/MessageBlock.java | 11 +++ .../wizardry/MessageDataBlock.java | 12 ++++ .../wizardry/Wizardry4BootDisk.java | 67 ++++++++++--------- 5 files changed, 84 insertions(+), 35 deletions(-) diff --git a/src/com/bytezone/diskbrowser/wizardry/MazeGridV5.java b/src/com/bytezone/diskbrowser/wizardry/MazeGridV5.java index 7607239..5258259 100644 --- a/src/com/bytezone/diskbrowser/wizardry/MazeGridV5.java +++ b/src/com/bytezone/diskbrowser/wizardry/MazeGridV5.java @@ -8,21 +8,25 @@ import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.List; +import com.bytezone.common.Utility; import com.bytezone.diskbrowser.applefile.AbstractFile; import com.bytezone.diskbrowser.utilities.HexFormatter; public class MazeGridV5 extends AbstractFile { + private final MessageBlock messageBlock; List grids = new ArrayList (); int minX = 9999; int minY = 9999; int maxX = 0; int maxY = 0; - public MazeGridV5 (String name, byte[] buffer) + public MazeGridV5 (String name, byte[] buffer, MessageBlock messageBlock) { super (name, buffer); + this.messageBlock = messageBlock; + for (int i = 0; i < 16; i++) { MazeCell[][] grid = new MazeCell[8][8]; @@ -123,6 +127,28 @@ public class MazeGridV5 extends AbstractFile return cell; } + @Override + public String getHexDump () + { + StringBuilder text = new StringBuilder (super.getHexDump ()); + + text.append ("\n\n"); + text.append (HexFormatter.format (buffer, 0x550, 0x80)); + text.append ("\n\n"); + + for (int i = 0; i < 128; i += 2) + { + int msg = Utility.getWord (buffer, 0x550 + i); + if (msg >= 15000) + { + String message = messageBlock.getMessageText (msg); + text.append (String.format ("%4d %04X %s%n", i, msg, message)); + } + } + + return text.toString (); + } + private class MazeGrid { MazeCell[][] grid; diff --git a/src/com/bytezone/diskbrowser/wizardry/MazeLevel.java b/src/com/bytezone/diskbrowser/wizardry/MazeLevel.java index a82f37e..8fe612c 100755 --- a/src/com/bytezone/diskbrowser/wizardry/MazeLevel.java +++ b/src/com/bytezone/diskbrowser/wizardry/MazeLevel.java @@ -26,7 +26,6 @@ class MazeLevel extends AbstractFile @Override public String getHexDump () { - // StringBuilder text = new StringBuilder (super.getHexDump ()); StringBuilder text = new StringBuilder (); text.append ("West walls/doors\n\n"); diff --git a/src/com/bytezone/diskbrowser/wizardry/MessageBlock.java b/src/com/bytezone/diskbrowser/wizardry/MessageBlock.java index 891749c..eb1b4b3 100644 --- a/src/com/bytezone/diskbrowser/wizardry/MessageBlock.java +++ b/src/com/bytezone/diskbrowser/wizardry/MessageBlock.java @@ -36,6 +36,17 @@ public class MessageBlock extends AbstractFile implements Iterable messageNo) + return messageDataBlocks.get (i - 1).getText (messageNo); + } + return null; + } + 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 cb3bece..372f1d2 100644 --- a/src/com/bytezone/diskbrowser/wizardry/MessageDataBlock.java +++ b/src/com/bytezone/diskbrowser/wizardry/MessageDataBlock.java @@ -80,6 +80,18 @@ public class MessageDataBlock extends AbstractFile return null; } + String getText (int messageNo) + { + for (Message message : messages) + if (message.msgNo == messageNo) + { + byte[] returnMessage = new byte[message.length]; + System.arraycopy (buffer, message.offset, returnMessage, 0, message.length); + return huffman.decodeMessage (returnMessage); + } + return "*** not found ***"; + } + @Override public String getText () { diff --git a/src/com/bytezone/diskbrowser/wizardry/Wizardry4BootDisk.java b/src/com/bytezone/diskbrowser/wizardry/Wizardry4BootDisk.java index fbc001c..a62ec22 100644 --- a/src/com/bytezone/diskbrowser/wizardry/Wizardry4BootDisk.java +++ b/src/com/bytezone/diskbrowser/wizardry/Wizardry4BootDisk.java @@ -54,6 +54,35 @@ public class Wizardry4BootDisk extends PascalDisk fileEntry.getDataSource (); } + DefaultMutableTreeNode huffNode = findNode (currentRoot, "ASCII.HUFF"); + fileEntry = (FileEntry) huffNode.getUserObject (); + if (fileEntry != null) + { + + byte[] buffer = fileEntry.getDataSource ().buffer; + + 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); + fileEntry.setFile (messageBlock); + messagesNode.setAllowsChildren (true); + List blocks = fileEntry.getSectors (); + + int count = 0; + for (MessageDataBlock mdb : messageBlock) + { + List messageBlocks = new ArrayList (); + messageBlocks.add (blocks.get (count++)); + addToNode (mdb, messagesNode, messageBlocks); + } + } + if (version == 4) { DefaultMutableTreeNode scenarioNode = findNode (currentRoot, "SCENARIO.DATA"); @@ -107,35 +136,6 @@ public class Wizardry4BootDisk extends PascalDisk } } } - - DefaultMutableTreeNode huffNode = findNode (currentRoot, "ASCII.HUFF"); - fileEntry = (FileEntry) huffNode.getUserObject (); - if (fileEntry != null) - { - - byte[] buffer = fileEntry.getDataSource ().buffer; - - 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); - fileEntry.setFile (messageBlock); - messagesNode.setAllowsChildren (true); - List blocks = fileEntry.getSectors (); - - int count = 0; - for (MessageDataBlock mdb : messageBlock) - { - List messageBlocks = new ArrayList (); - messageBlocks.add (blocks.get (count++)); - addToNode (mdb, messagesNode, messageBlocks); - } - } } private void linkMazeLevels4 (DefaultMutableTreeNode scenarioNode, FileEntry fileEntry) @@ -170,10 +170,11 @@ public class Wizardry4BootDisk extends PascalDisk int base = 0x1800; for (int i = 0; i < 8; i++) { - int offset = base + i * 1024; - byte[] data = new byte[1024]; - System.arraycopy (buffer, offset, data, 0, data.length); - MazeGridV5 grid = new MazeGridV5 ("Maze level " + (i + 1), data); + int offset = base + i * 0x400; + byte[] data = new byte[2048]; + System.arraycopy (buffer, offset, data, 0, 1024); + System.arraycopy (buffer, offset + 8192, data, 1024, 1024); + MazeGridV5 grid = new MazeGridV5 ("Maze level " + (i + 1), data, messageBlock); List mazeBlocks = new ArrayList (); addToNode (grid, mazeNode, mazeBlocks);