refactoring

This commit is contained in:
Denis Molony 2016-09-18 20:06:26 +10:00
parent c573e86f2b
commit f76720ef60
6 changed files with 153 additions and 68 deletions

View File

@ -127,18 +127,24 @@ class MazeLevel extends AbstractFile
for (MazeAddress address : messageList)
{
Message message = getMessage (address.row);
if (message != null)
{
text.append (String.format ("%nMessage: %04X (%d)%n", address.row, address.row));
text.append (message.getText ());
text.append ("\n");
}
}
for (MazeAddress address : monsterList)
{
Monster monster = getMonster (address.column);
if (monster != null)
{
text.append (String.format ("%nMonster: %04X%n", address.column));
text.append (monster.getText ());
text.append ("\n");
}
}
return text.toString ();
}

View File

@ -5,7 +5,7 @@ import java.awt.image.DataBuffer;
public class Wiz4Image extends AbstractImage
{
public Wiz4Image (String name, byte[] buffer, int rows, int cols) // 5, 6
public Wiz4Image (String name, byte[] buffer, int offset, int rows, int cols) // 5, 6
{
super (name, buffer);
@ -18,7 +18,7 @@ public class Wiz4Image extends AbstractImage
for (int line = 0; line < 8; line++)
for (int col = 0; col < cols; col++)
{
byte b = buffer[row * rowSize + col * 8 + line];
byte b = buffer[offset + row * rowSize + col * 8 + line];
for (int bit = 0; bit < 7; bit++)
{
if ((b & 0x01) == 0x01)

View File

@ -0,0 +1,52 @@
package com.bytezone.diskbrowser.wizardry;
import java.util.ArrayList;
import java.util.List;
import com.bytezone.diskbrowser.applefile.AbstractFile;
import com.bytezone.diskbrowser.utilities.HexFormatter;
public class Wiz4Monsters extends AbstractFile
{
final List<Wiz4Image> images = new ArrayList<Wiz4Image> ();
final List<Integer> blocks = new ArrayList<Integer> ();
public Wiz4Monsters (String name, byte[] buffer)
{
super (name, buffer);
int count = 0;
for (int block = 0; block < 24; block++)
{
int ptr = block * 512;
for (int pic = 0; pic < 2; pic++)
{
byte[] data = new byte[240];
System.arraycopy (buffer, ptr + pic * 256, data, 0, data.length);
Wiz4Image image = new Wiz4Image ("Image " + count++, data, 0, 5, 6);
images.add (image);
blocks.add (block);
}
}
}
@Override
public String getText ()
{
StringBuilder text = new StringBuilder ();
int count = 1;
for (int block = 0; block < 24; block++)
{
int ptr = block * 512;
for (int pic = 0; pic < 2; pic++)
{
text.append (String.format ("%3d : %s%n", count,
HexFormatter.getHexString (buffer, ptr + pic * 256, 240)));
count++;
}
}
return text.toString ();
}
}

View File

@ -9,20 +9,40 @@ import com.bytezone.diskbrowser.utilities.HexFormatter;
public class Wiz5Monsters extends AbstractFile
{
List<Wiz4Image> images = new ArrayList<Wiz4Image> ();
List<Monster> monsters = new ArrayList<Monster> ();
public Wiz5Monsters (String name, byte[] buffer)
{
super (name, buffer);
for (int i = 0; i < 10; i++)
int ptr = 0;
Monster monster = null;
while (buffer[ptr] != 0)
{
int ptr = buffer[i] * 512;
byte[] data = new byte[512];
System.arraycopy (buffer, ptr, data, 0, data.length);
Wiz4Image image = new Wiz4Image ("Image " + i, data, 10, 6); // no good
images.add (image);
int val1 = buffer[ptr] & 0xFF;
int val2 = Utility.getWord (buffer, ptr * 2 + 256);
int offset = val1 * 512 + val2;
if (monster != null)
fillMonster (offset, monster, ptr);
monster = new Monster ();
monster.offset = offset; // don't know the length yet
monsters.add (monster);
ptr++;
}
fillMonster (buffer.length, monster, ptr);
}
private void fillMonster (int offset, Monster monster, int ptr)
{
int len = offset - monster.offset;
monster.buffer = new byte[len];
System.arraycopy (buffer, monster.offset, monster.buffer, 0, len);
monster.image = new Wiz4Image ("Image " + ptr, monster.buffer, 3, 10, 6);
}
@Override
@ -30,17 +50,22 @@ public class Wiz5Monsters extends AbstractFile
{
StringBuilder text = new StringBuilder ();
int ptr = 0;
while (buffer[ptr] != 0)
{
int val1 = buffer[ptr] & 0xFF;
int val2 = Utility.getWord (buffer, ptr * 2 + 256);
text.append (String.format ("%3d %02X %04X :", ptr, val1, val2));
String line = HexFormatter.getHexString (buffer, val1 * 512, 512);
text.append (line);
text.append ("\n");
ptr++;
}
int count = 0;
for (Monster monster : monsters)
text.append (String.format ("%02X : %02X %04X : %s%n", ++count,
monster.offset / 512, monster.offset % 512,
HexFormatter.getHexString (buffer, monster.offset, monster.buffer.length)));
if (text.length () > 0)
text.deleteCharAt (text.length () - 1);
return text.toString ();
}
class Monster
{
int offset;
Wiz4Image image;
byte[] buffer;
}
}

View File

@ -117,7 +117,6 @@ public class Wizardry4BootDisk extends PascalDisk
fileEntry = (FileEntry) monstersNode.getUserObject ();
if (fileEntry != null)
{
fileEntry.setFile (null);
monstersNode.setAllowsChildren (true);
linkMonsterImages4 (monstersNode, fileEntry);
}
@ -128,17 +127,42 @@ public class Wizardry4BootDisk extends PascalDisk
fileEntry = (FileEntry) monstersNode.getUserObject ();
if (fileEntry != null)
{
Wiz5Monsters w5monsters =
new Wiz5Monsters ("monsters", fileEntry.getDataSource ().buffer);
fileEntry.setFile (w5monsters);
monstersNode.setAllowsChildren (true);
for (Wiz4Image image : w5monsters.images)
linkMonsterImages5 (monstersNode, fileEntry);
}
}
}
private void linkMonsterImages4 (DefaultMutableTreeNode monstersNode,
FileEntry fileEntry)
{
fileEntry.setFile (null);
List<DiskAddress> pictureBlocks = fileEntry.getSectors ();
Wiz4Monsters w4monsters =
new Wiz4Monsters ("monsters", fileEntry.getDataSource ().buffer);
fileEntry.setFile (w4monsters);
int count = 0;
for (Wiz4Image image : w4monsters.images)
{
List<DiskAddress> monsterBlocks = new ArrayList<DiskAddress> ();
// monsterBlocks.add (pictureBlocks.get (block));
monsterBlocks.add (pictureBlocks.get (w4monsters.blocks.get (count++)));
addToNode (image, monstersNode, monsterBlocks);
}
}
private void linkMonsterImages5 (DefaultMutableTreeNode monstersNode,
FileEntry fileEntry)
{
Wiz5Monsters w5monsters =
new Wiz5Monsters ("monsters", fileEntry.getDataSource ().buffer);
fileEntry.setFile (w5monsters);
for (Wiz5Monsters.Monster monster : w5monsters.monsters)
{
Wiz4Image image = monster.image;
List<DiskAddress> monsterBlocks = new ArrayList<DiskAddress> ();
// monsterBlocks.add (pictureBlocks.get (block));
addToNode (image, monstersNode, monsterBlocks);
}
}
@ -282,28 +306,6 @@ public class Wizardry4BootDisk extends PascalDisk
afs.setSectors (allOracleBlocks);
}
private void linkMonsterImages4 (DefaultMutableTreeNode monstersNode,
FileEntry fileEntry)
{
byte[] pictureBuffer = fileEntry.getDataSource ().buffer;
List<DiskAddress> pictureBlocks = fileEntry.getSectors ();
int count = 0;
for (int block = 0; block < 24; block++)
{
int ptr = block * 512;
for (int pic = 0; pic < 2; pic++)
{
byte[] buffer = new byte[240];
System.arraycopy (pictureBuffer, ptr + pic * 256, buffer, 0, buffer.length);
Wiz4Image image = new Wiz4Image ("Image " + count++, buffer, 5, 6);
List<DiskAddress> monsterBlocks = new ArrayList<DiskAddress> ();
monsterBlocks.add (pictureBlocks.get (block));
addToNode (image, monstersNode, monsterBlocks);
}
}
}
private void addToNode (AbstractFile af, DefaultMutableTreeNode node,
List<DiskAddress> blocks)
{