This commit is contained in:
Denis Molony 2016-03-24 10:37:59 +11:00
parent 48b95db89b
commit 8fd7bd1a29
21 changed files with 968 additions and 934 deletions

View File

@ -10,9 +10,9 @@ import com.bytezone.diskbrowser.utilities.HexFormatter;
public abstract class AbstractFile implements DataSource
{
public String name;
protected String name;
public byte[] buffer;
AssemblerProgram assembler;
protected AssemblerProgram assembler;
protected BufferedImage image;
public AbstractFile (String name, byte[] buffer)
@ -27,6 +27,11 @@ public abstract class AbstractFile implements DataSource
return "Name : " + name + "\n\nNo text description";
}
public String getName ()
{
return name;
}
@Override
public String getAssembler ()
{

View File

@ -26,6 +26,7 @@ public class SimpleText2 extends AbstractFile
}
}
@Override
public String getText ()
{
StringBuilder text = new StringBuilder ();
@ -39,12 +40,14 @@ public class SimpleText2 extends AbstractFile
return text.toString ();
}
@Override
public String getHexDump ()
{
StringBuilder text = new StringBuilder ();
for (Integer i : lineStarts)
text.append (HexFormatter.formatNoHeader (buffer, i, (buffer[i] & 0xFF) + 1) + "\n");
text.append (HexFormatter.formatNoHeader (buffer, i, (buffer[i] & 0xFF) + 1)
+ "\n");
text.append (HexFormatter.formatNoHeader (buffer, buffer.length - 2, 2) + "\n");
return text.toString ();
@ -69,67 +72,67 @@ public class SimpleText2 extends AbstractFile
while (line.length () < 10)
line.append (' ');
if (val == 0xDC)
line.append (String.format ("EQU", val));
line.append (String.format ("EQU %02X", val));
else if (val == 0xD0)
line.append (String.format ("STA", val));
line.append (String.format ("STA %02X", val));
else if (val == 0xD2)
line.append (String.format ("STY", val));
line.append (String.format ("STY %02X", val));
else if (val == 0xD4)
line.append (String.format ("LSR", val));
line.append (String.format ("LSR %02X", val));
else if (val == 0xD5)
line.append (String.format ("ROR", val));
line.append (String.format ("ROR %02X", val));
else if (val == 0xD7)
line.append (String.format ("ASL", val));
line.append (String.format ("ASL %02X", val));
else if (val == 0xD9)
line.append (String.format ("EQ ", val));
line.append (String.format ("EQ %02X", val));
else if (val == 0xDB)
line.append (String.format ("TGT", val));
line.append (String.format ("TGT %02X", val));
else if (val == 0xDA)
line.append (String.format ("ORG", val));
line.append (String.format ("ORG %02X", val));
else if (val == 0xB1)
line.append (String.format ("TYA", val));
line.append (String.format ("TYA %02X", val));
else if (val == 0xC1)
line.append (String.format ("AND", val));
line.append (String.format ("AND %02X", val));
else if (val == 0xC4)
line.append (String.format ("CMP", val));
line.append (String.format ("CMP %02X", val));
else if (val == 0xC8)
line.append (String.format ("EOR", val));
line.append (String.format ("EOR %02X", val));
else if (val == 0xCA)
line.append (String.format ("JMP", val));
line.append (String.format ("JMP %02X", val));
else if (val == 0xCB)
line.append (String.format ("JSR", val));
line.append (String.format ("JSR %02X", val));
else if (val == 0xCD)
line.append (String.format ("LDA", val));
line.append (String.format ("LDA %02X", val));
else if (val == 0xCE)
line.append (String.format ("LDX", val));
line.append (String.format ("LDX %02X", val));
else if (val == 0xCF)
line.append (String.format ("LDY", val));
line.append (String.format ("LDY %02X", val));
else if (val == 0xA1)
line.append (String.format ("PHA", val));
line.append (String.format ("PHA %02X", val));
else if (val == 0xA2)
line.append (String.format ("PLA", val));
line.append (String.format ("PLA %02X", val));
else if (val == 0xA5)
line.append (String.format ("RTS", val));
line.append (String.format ("RTS %02X", val));
else if (val == 0xA9)
line.append (String.format ("SEC", val));
line.append (String.format ("SEC %02X", val));
else if (val == 0xAD)
line.append (String.format ("TAY", val));
line.append (String.format ("TAY %02X", val));
else if (val == 0x82)
line.append (String.format ("BMI", val));
line.append (String.format ("BMI %02X", val));
else if (val == 0x84)
line.append (String.format ("BCS", val));
line.append (String.format ("BCS %02X", val));
else if (val == 0x85)
line.append (String.format ("BPL", val));
line.append (String.format ("BPL %02X", val));
else if (val == 0x86)
line.append (String.format ("BNE", val));
line.append (String.format ("BNE %02X", val));
else if (val == 0x87)
line.append (String.format ("BEQ", val));
line.append (String.format ("BEQ %02X", val));
else if (val == 0x99)
line.append (String.format ("CLC", val));
line.append (String.format ("CLC %02X", val));
else if (val == 0x9C)
line.append (String.format ("DEX", val));
line.append (String.format ("DEX %02X", val));
else if (val == 0x9F)
line.append (String.format ("INY", val));
line.append (String.format ("INY %02X", val));
else
line.append (String.format (".%02X.", val));

View File

@ -38,7 +38,7 @@ public class VisicalcFile extends AbstractFile
debug = value;
}
public void setDebug (boolean value)
public static void setDebug (boolean value)
{
debug = value;
}

View File

@ -11,6 +11,7 @@ import com.bytezone.diskbrowser.applefile.AppleFileSource;
public class TextDiskCreator extends AbstractDiskCreator
{
@Override
public void createDisk ()
{
File f = new File ("D:\\DiskDetails.txt");
@ -27,6 +28,7 @@ public class TextDiskCreator extends AbstractDiskCreator
}
finally
{
if (out != null)
try
{
out.close ();
@ -47,13 +49,14 @@ public class TextDiskCreator extends AbstractDiskCreator
while (children.hasMoreElements ())
{
DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement ();
DefaultMutableTreeNode node = children.nextElement ();
AppleFileSource afs = (AppleFileSource) node.getUserObject ();
out.write (afs.getDataSource ().getText () + String.format ("%n"));
}
}
@Override
public String getMenuText ()
{
return "create text disk";

View File

@ -114,7 +114,7 @@ public class DirectoryEntry implements AppleFileSource
public String line ()
{
int blocks = ((rc & 0xF0) >> 3) + (((rc & 0x0F) + 7) / 8);
// int blocks = ((rc & 0xF0) >> 3) + (((rc & 0x0F) + 7) / 8);
String bytes = HexFormatter.getHexString (blockList, 0, 16);
bytes = bytes.replaceAll ("00", " ");

View File

@ -192,7 +192,11 @@ public abstract class AbstractFormattedDisk implements FormattedDisk
public String getName ()
{
if (originalPath != null)
return originalPath.getFileName ().toString ();
{
Path path = originalPath.getFileName ();
if (path != null)
return path.toString ();
}
return disk.getFile ().getName ();
}

View File

@ -170,10 +170,10 @@ abstract class AbstractCatalogEntry implements AppleFileSource
case Binary: // binary file
case Relocatable: // relocatable binary file
if (buffer.length == 0)
appleFile = new AssemblerProgram (name, buffer, 0);
else
{
// if (buffer.length == 0)
// appleFile = new AssemblerProgram (name, buffer, 0);
// else
// {
int loadAddress = HexFormatter.intValue (buffer[0], buffer[1]);
reportedLength = HexFormatter.intValue (buffer[2], buffer[3]);
if (reportedLength == 0)
@ -221,7 +221,7 @@ abstract class AbstractCatalogEntry implements AppleFileSource
.setExtraBuffer (buffer, exactBuffer.length + 4,
buffer.length - (exactBuffer.length + 4));
}
}
// }
break;
case SS: // what is this?
@ -235,7 +235,7 @@ abstract class AbstractCatalogEntry implements AppleFileSource
break;
case BB: // what is this?
int loadAddress = HexFormatter.intValue (buffer[0], buffer[1]);
loadAddress = HexFormatter.intValue (buffer[0], buffer[1]);
reportedLength = HexFormatter.intValue (buffer[2], buffer[3]);
exactBuffer = new byte[reportedLength];
System.arraycopy (buffer, 4, exactBuffer, 0, reportedLength);

View File

@ -23,10 +23,11 @@ public class DiskBrowser extends JFrame implements DiskSelectionListener, QuitLi
{
super (windowTitle);
State state = new State (prefs);
if (false)
{
State state = new State (prefs);
state.clear ();
}
JToolBar toolBar = new JToolBar ("Toolbar", JToolBar.HORIZONTAL);
MenuHandler menuHandler = new MenuHandler (prefs);

View File

@ -4,14 +4,7 @@ import java.awt.image.BufferedImage;
import java.io.File;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.*;
import java.util.zip.CRC32;
import java.util.zip.Checksum;
@ -49,8 +42,8 @@ public class TreeBuilder
public TreeBuilder (File folder)
{
assert(folder.exists ());
assert(folder.isDirectory ());
assert (folder.exists ());
assert (folder.isDirectory ());
long start = System.currentTimeMillis ();
@ -299,6 +292,9 @@ public class TreeBuilder
+ " Date Size Type\n");
text.append ("- ----------------------------------------"
+ " ----------- -------------- ---------\n");
File[] files = file.listFiles ();
if (files != null)
for (File f : file.listFiles ())
{
String name = f.getName ();
@ -313,6 +309,7 @@ public class TreeBuilder
f.isDirectory () ? "D" : " ", name, sdf.format (d),
size, type));
}
if (text.length () > 0)
text.deleteCharAt (text.length () - 1);
return text.toString ();

View File

@ -30,9 +30,8 @@ class AttributeManager extends AbstractFile
int count = 0;
for (Statistic stat : list)
{
DefaultMutableTreeNode child =
new DefaultMutableTreeNode (new DefaultAppleFileSource (("Attribute " + count++), stat
.getText (), disk));
DefaultMutableTreeNode child = new DefaultMutableTreeNode (
new DefaultAppleFileSource (("Attribute " + count++), stat.getText (), disk));
node.add (child);
child.setAllowsChildren (false);
}
@ -66,10 +65,11 @@ class AttributeManager extends AbstractFile
String getText ()
{
StringBuilder text = new StringBuilder ("Objects with attribute " + id + " set:\n\n");
StringBuilder text =
new StringBuilder ("Objects with attribute " + id + " set:\n\n");
for (ZObject o : list)
{
text.append (String.format ("%3d %-28s%n", o.id, o.name));
text.append (String.format ("%3d %-28s%n", o.id, o.getName ()));
}
if (text.length () > 0)
text.deleteCharAt (text.length () - 1);

View File

@ -33,8 +33,10 @@ class CodeManager extends AbstractFile
for (Routine routine : routines.values ())
{
DefaultMutableTreeNode node =
new DefaultMutableTreeNode (new DefaultAppleFileSource (String.format ("%3d %s (%04X)",
++count, routine.name, routine.startPtr / 2), routine, disk));
new DefaultMutableTreeNode (new DefaultAppleFileSource (
String.format ("%3d %s (%04X)", ++count, routine.getName (),
routine.startPtr / 2),
routine, disk));
node.setAllowsChildren (false);
root.add (node);
}
@ -45,9 +47,10 @@ class CodeManager extends AbstractFile
System.out.printf ("%nWalking the code block%n%n");
int total = 0;
int ptr = header.highMemory;
while (ptr < header.stringPointer)
{
if (ptr % 2 == 1) // routine must start on a word boundary
if (ptr >= 0 && ptr % 2 == 1) // routine must start on a word boundary
ptr++;
if (containsRoutineAt (ptr))
@ -93,10 +96,10 @@ class CodeManager extends AbstractFile
for (Routine r : routines.values ())
{
int gap = r.startPtr - nextAddress;
text.append (String.format (
"%3d %05X %5d %3d %2d %3d %3d %4d %04X%n", ++count,
r.startPtr, r.length, r.instructions.size (), r.strings, r.calledBy.size (), r.calls
.size (), gap, r.startPtr / 2));
text.append (String
.format ("%3d %05X %5d %3d %2d %3d %3d %4d %04X%n",
++count, r.startPtr, r.length, r.instructions.size (), r.strings,
r.calledBy.size (), r.calls.size (), gap, r.startPtr / 2));
nextAddress = r.startPtr + r.length;
}

View File

@ -128,9 +128,13 @@ public class InfocomDisk extends AbstractFormattedDisk
break;
}
}
if (buffer != null)
{
int ptr = 255;
while (buffer[ptr--] == 0)
fileSize--;
}
return fileSize;
}

View File

@ -58,7 +58,7 @@ class ObjectManager extends InfocomAbstractFile implements Iterable<ZObject>
FormattedDisk disk)
{
DefaultMutableTreeNode child = new DefaultMutableTreeNode (
new DefaultAppleFileSource (object.name, object, disk));
new DefaultAppleFileSource (object.getName (), object, disk));
parentNode.add (child);
if (object.sibling > 0)
buildObjectTree (header.objectManager.list.get (object.sibling - 1), parentNode,

View File

@ -34,8 +34,8 @@ class PropertyManager extends AbstractFile
if (stat.list.size () > 0)
{
String title = "Property " + header.propertyNames[stat.id].trim ();
DefaultMutableTreeNode child =
new DefaultMutableTreeNode (new DefaultAppleFileSource (title, stat.getText (), disk));
DefaultMutableTreeNode child = new DefaultMutableTreeNode (
new DefaultAppleFileSource (title, stat.getText (), disk));
node.add (child);
child.setAllowsChildren (false);
}
@ -72,11 +72,13 @@ class PropertyManager extends AbstractFile
String getText ()
{
StringBuilder text = new StringBuilder ("Objects with property " + id + " set:\n\n");
StringBuilder text =
new StringBuilder ("Objects with property " + id + " set:\n\n");
for (ZObject o : list)
{
ZObject.Property p = o.getProperty (id);
text.append (String.format ("%3d %-29s%s%n", o.id, o.name, p.toString ().substring (7)));
text.append (String.format ("%3d %-29s%s%n", o.id, o.getName (),
p.toString ().substring (7)));
}
if (text.length () > 0)
text.deleteCharAt (text.length () - 1);
@ -86,7 +88,8 @@ class PropertyManager extends AbstractFile
@Override
public String toString ()
{
return String.format (" %2d %-6s %3d", id, header.propertyNames[id], list.size ());
return String.format (" %2d %-6s %3d", id, header.propertyNames[id],
list.size ());
}
}
}

View File

@ -60,12 +60,12 @@ class PascalCodeObject implements AppleFileSource
@Override
public String getUniqueName ()
{
return segment.name; // this should be fileName/segmentName
return segment.getName (); // this should be fileName/segmentName
}
@Override
public String toString ()
{
return segment.name;
return segment.getName ();
}
}

View File

@ -5,12 +5,12 @@ class Pi extends Function
Pi (Sheet parent, String text)
{
super (parent, text);
value = Math.PI;
}
@Override
public Value calculate ()
{
value = 3.1415926536;
return this;
}
}

View File

@ -283,7 +283,7 @@ class Character extends AbstractFile
@Override
public String toString ()
{
return String.format ("%s%-15s (%d)", equipped ? "*" : " ", item.name,
return String.format ("%s%-15s (%d)", equipped ? "*" : " ", item.getName (),
item.getCost ());
}
}

View File

@ -130,7 +130,8 @@ class MazeCell
private void drawEast (Graphics2D g, int x, int y)
{
g.drawLine (x + cellSize.width - 1, y + 1, x + cellSize.width - 1, y + cellSize.height - 1);
g.drawLine (x + cellSize.width - 1, y + 1, x + cellSize.width - 1,
y + cellSize.height - 1);
}
private void drawNorth (Graphics2D g, int x, int y)
@ -140,7 +141,8 @@ class MazeCell
private void drawSouth (Graphics2D g, int x, int y)
{
g.drawLine (x + 1, y + cellSize.height - 1, x + cellSize.width - 1, y + cellSize.height - 1);
g.drawLine (x + 1, y + cellSize.height - 1, x + cellSize.width - 1,
y + cellSize.height - 1);
}
public void drawStairsUp (Graphics2D g, int x, int y)
@ -308,13 +310,13 @@ class MazeCell
if (itemRequired != null)
{
sign.append ("&nbsp;<b>Requires: ");
sign.append (itemRequired.name + "&nbsp;</b>");
sign.append (itemRequired.getName () + "&nbsp;</b>");
}
if (itemObtained != null)
{
sign.append ("&nbsp;<b>Obtain: ");
sign.append (itemObtained.name + "&nbsp;</b>");
sign.append (itemObtained.getName () + "&nbsp;</b>");
}
sign.append ("</pre></html>");
return sign.toString ();

View File

@ -126,9 +126,10 @@ class Reward extends AbstractFile
String lineTitle = title ? "Items ..........." : "";
title = false;
for (int j = 0; j < lineItem.length; j++)
lineItem[j] = i + j <= max ? items.get (i + j).name : "";
text.append (String.format ("%-17s %-16s %-16s %-16s %-16s%n", lineTitle, lineItem[0],
lineItem[1], lineItem[2], lineItem[3]));
lineItem[j] = i + j <= max ? items.get (i + j).getName () : "";
text.append (String.format ("%-17s %-16s %-16s %-16s %-16s%n", lineTitle,
lineItem[0], lineItem[1], lineItem[2],
lineItem[3]));
}
break;
default:

View File

@ -9,7 +9,11 @@ import javax.swing.tree.DefaultTreeModel;
import com.bytezone.diskbrowser.applefile.AbstractFile;
import com.bytezone.diskbrowser.applefile.AppleFileSource;
import com.bytezone.diskbrowser.disk.*;
import com.bytezone.diskbrowser.disk.DefaultAppleFileSource;
import com.bytezone.diskbrowser.disk.DefaultDataSource;
import com.bytezone.diskbrowser.disk.Disk;
import com.bytezone.diskbrowser.disk.DiskAddress;
import com.bytezone.diskbrowser.disk.SectorType;
import com.bytezone.diskbrowser.gui.DataSource;
import com.bytezone.diskbrowser.pascal.PascalDisk;
import com.bytezone.diskbrowser.utilities.HexFormatter;
@ -93,7 +97,8 @@ public class WizardryScenarioDisk extends PascalDisk
extractMonsters (linkNode ("Monsters", "Monsters string", dataNode), sectors);
extractCharacters (linkNode ("Characters", "Characters string", dataNode), sectors);
extractImages (linkNode ("Images", "Images string", dataNode), sectors);
extractExperienceLevels (linkNode ("Experience", "Experience string", dataNode), sectors);
extractExperienceLevels (linkNode ("Experience", "Experience string", dataNode),
sectors);
// node = linkNode ("Spells", "Spells string", dataNode);
node = null;
extractSpells (node, sectors);
@ -189,8 +194,8 @@ public class WizardryScenarioDisk extends PascalDisk
dds.text = text.toString ();
}
private int addReward (byte[] buffer, List<DiskAddress> blocks, DefaultMutableTreeNode node,
int seq)
private int addReward (byte[] buffer, List<DiskAddress> blocks,
DefaultMutableTreeNode node, int seq)
{
int recLen = 168;
for (int ptr = 0; ptr < 1008; ptr += recLen)
@ -237,7 +242,8 @@ public class WizardryScenarioDisk extends PascalDisk
text.append (String.format (" %2d %2d %2d %2d %2d %2d", att.strength,
att.intelligence, att.piety, att.vitality, att.agility,
att.luck));
text.append (String.format (" %5s %s%n", stats.status, ch.isOut () ? "* OUT *" : ""));
text.append (String.format (" %5s %s%n", stats.status,
ch.isOut () ? "* OUT *" : ""));
}
DefaultAppleFileSource afs = (DefaultAppleFileSource) node.getUserObject ();
@ -352,7 +358,8 @@ public class WizardryScenarioDisk extends PascalDisk
dds.text = text.toString ();
}
private void addItems (byte[] buffer, List<DiskAddress> blocks, DefaultMutableTreeNode node)
private void addItems (byte[] buffer, List<DiskAddress> blocks,
DefaultMutableTreeNode node)
{
int recLen = 78;
for (int ptr = 0; ptr < 1014; ptr += recLen)
@ -493,7 +500,7 @@ public class WizardryScenarioDisk extends PascalDisk
StringBuilder text = new StringBuilder ();
for (MazeLevel level : levels)
text.append (level.name + "\n");
text.append (level.getName () + "\n");
DefaultAppleFileSource afs = (DefaultAppleFileSource) node.getUserObject ();
afs.setSectors (nodeSectors);
@ -524,16 +531,15 @@ public class WizardryScenarioDisk extends PascalDisk
break;
}
AbstractImage mi =
scenarioHeader.scenarioID < 3 ? new Image (name, buffer) : new ImageV2 (name,
exactBuffer);
AbstractImage mi = scenarioHeader.scenarioID < 3 ? new Image (name, buffer)
: new ImageV2 (name, exactBuffer);
images.add (mi);
addToNode (mi, node, da, imageSector);
}
StringBuilder text = new StringBuilder ();
for (AbstractImage image : images)
text.append (image.name + "\n");
text.append (image.getName () + "\n");
DefaultAppleFileSource afs = (DefaultAppleFileSource) node.getUserObject ();
afs.setSectors (nodeSectors);
@ -541,8 +547,8 @@ public class WizardryScenarioDisk extends PascalDisk
dds.text = text.toString ();
}
private void
extractExperienceLevels (DefaultMutableTreeNode node, List<DiskAddress> sectors)
private void extractExperienceLevels (DefaultMutableTreeNode node,
List<DiskAddress> sectors)
{
List<DiskAddress> nodeSectors = new ArrayList<DiskAddress> ();
ScenarioData sd = scenarioHeader.data.get (Header.EXPERIENCE_AREA);
@ -583,13 +589,15 @@ public class WizardryScenarioDisk extends PascalDisk
private void addToNode (AbstractFile af, DefaultMutableTreeNode node,
List<DiskAddress> blocks, SectorType type)
{
DefaultAppleFileSource dafs = new DefaultAppleFileSource (af.name, af, this, blocks);
DefaultAppleFileSource dafs =
new DefaultAppleFileSource (af.getName (), af, this, blocks);
DefaultMutableTreeNode childNode = new DefaultMutableTreeNode (dafs);
node.add (childNode);
childNode.setAllowsChildren (false);
}
private List<DiskAddress> getTwoBlocks (ScenarioData sd, int i, List<DiskAddress> sectors)
private List<DiskAddress> getTwoBlocks (ScenarioData sd, int i,
List<DiskAddress> sectors)
{
ArrayList<DiskAddress> blocks = new ArrayList<DiskAddress> (2);
blocks.add (sectors.get (sd.dataOffset + i * 2));