image experiments

This commit is contained in:
Denis Molony 2016-09-19 15:18:10 +10:00
parent f76720ef60
commit 9cfb15f01a
4 changed files with 121 additions and 33 deletions

View File

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

View File

@ -23,7 +23,7 @@ public class Wiz4Monsters extends AbstractFile
{
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);
Wiz4Image image = new Wiz4Image ("Image " + count++, data, 5, 6);
images.add (image);
blocks.add (block);
}

View File

@ -15,34 +15,46 @@ public class Wiz5Monsters extends AbstractFile
{
super (name, buffer);
int ptr = 0;
Monster monster = null;
while (buffer[ptr] != 0)
{
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
int p = 0;
int nextBlock = buffer[0] & 0xFF;
int nextOffset = Utility.getWord (buffer, 256);
Monster monster = new Monster (1, nextBlock * 512 + nextOffset);
monsters.add (monster);
boolean createMonster = false;
ptr++;
}
fillMonster (buffer.length, monster, ptr);
}
private void fillMonster (int offset, Monster monster, int ptr)
while (nextBlock > 0)
{
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);
int firstBlock = nextBlock;
int firstOffset = nextOffset;
int ndx = nextBlock * 512 + nextOffset;
if (buffer[ndx] == (byte) 0)
{
nextBlock = buffer[++p] & 0xFF;
nextOffset = Utility.getWord (buffer, p * 2 + 256);
createMonster = true;
}
else
{
nextBlock = buffer[ndx] & 0xFF;
nextOffset = Utility.getWord (buffer, ndx + 1);
}
int length = nextOffset > 0 ? nextOffset : 512 - firstOffset;
Buffer monsterBuffer = new Buffer (firstBlock, firstOffset, length);
monster.buffers.add (monsterBuffer);
// System.out.println (monsterBuffer);
if (createMonster && nextBlock > 0)
{
createMonster = false;
monster = new Monster (p + 1, nextBlock * 512 + nextOffset);
monsters.add (monster);
}
}
}
@Override
@ -50,11 +62,17 @@ public class Wiz5Monsters extends AbstractFile
{
StringBuilder text = new StringBuilder ();
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)));
{
text.append (
String.format ("%02X : %02X %04X : %s%n", monster.id, monster.offset / 512,
monster.offset % 512, monster.buffers.get (0).toHexString ()));
for (int i = 1; i < monster.buffers.size (); i++)
{
Buffer monsterBuffer = monster.buffers.get (i);
text.append (String.format (" : %s%n", monsterBuffer.toHexString ()));
}
}
if (text.length () > 0)
text.deleteCharAt (text.length () - 1);
@ -64,8 +82,79 @@ public class Wiz5Monsters extends AbstractFile
class Monster
{
int id;
int offset;
int length;
Wiz4Image image;
byte[] buffer;
byte[] data;
List<Buffer> buffers = new ArrayList<Buffer> ();
public Monster (int id, int offset)
{
this.id = id;
this.offset = offset;
}
public Wiz4Image getImage ()
{
if (image == null)
{
length = 0;
for (Buffer monsterBuffer : buffers)
length += monsterBuffer.length - 3;
data = new byte[length];
int ptr = 0;
for (Buffer monsterBuffer : buffers)
{
int offset = monsterBuffer.block * 512 + monsterBuffer.offset + 3;
System.arraycopy (buffer, offset, data, ptr, monsterBuffer.length - 3);
ptr += monsterBuffer.length - 3;
}
image = new Wiz4Image ("Image " + id, data, 8, 8);
}
return image;
}
@Override
public String toString ()
{
StringBuilder text = new StringBuilder ();
for (Buffer monsterBuffer : buffers)
{
text.append (monsterBuffer);
text.append ("\n");
}
return text.toString ();
}
}
class Buffer
{
int block;
int offset;
int length;
public Buffer (int block, int offset, int length)
{
this.block = block;
this.offset = offset;
this.length = length;
}
public String toHexString ()
{
return HexFormatter.getHexString (buffer, block * 512 + offset, length);
}
@Override
public String toString ()
{
return (HexFormatter.format (buffer, block * 512 + offset, length));
}
}
}

View File

@ -20,7 +20,7 @@ import com.bytezone.diskbrowser.wizardry.Header.ScenarioData;
public class Wizardry4BootDisk extends PascalDisk
{
public Header scenarioHeader;
private final List<AppleDisk> disks = new ArrayList<AppleDisk> ();
// private final List<AppleDisk> disks = new ArrayList<AppleDisk> ();
private Relocator relocator;
private MessageBlock messageBlock;
private Huffman huffman;
@ -159,10 +159,9 @@ public class Wizardry4BootDisk extends PascalDisk
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);
addToNode (monster.getImage (), monstersNode, monsterBlocks);
}
}