From 98a5d273d180c32a0e6be6de4fe9cb8c05e10041 Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Sat, 20 Feb 2016 20:48:47 +1100 Subject: [PATCH] tidying --- .../applefile/AssemblerProgram.java | 9 +- .../diskbrowser/applefile/HiResImage.java | 112 ++++++++++++++---- .../diskbrowser/disk/DiskFactory.java | 21 ++-- .../diskbrowser/dos/AbstractCatalogEntry.java | 7 +- .../diskbrowser/prodos/ProdosDisk.java | 20 ++-- 5 files changed, 123 insertions(+), 46 deletions(-) diff --git a/src/com/bytezone/diskbrowser/applefile/AssemblerProgram.java b/src/com/bytezone/diskbrowser/applefile/AssemblerProgram.java index c8f2435..4a1b52e 100755 --- a/src/com/bytezone/diskbrowser/applefile/AssemblerProgram.java +++ b/src/com/bytezone/diskbrowser/applefile/AssemblerProgram.java @@ -38,8 +38,13 @@ public class AssemblerProgram extends AbstractFile public void setExtraBuffer (byte[] fullBuffer, int offset, int length) { - this.extraBuffer = new byte[length]; - System.arraycopy (fullBuffer, offset, extraBuffer, 0, length); + if (length >= 0) + { + this.extraBuffer = new byte[length]; + System.arraycopy (fullBuffer, offset, extraBuffer, 0, length); + } + else + System.out.println ("Invalid length in setExtraBuffer() : " + length); } @Override diff --git a/src/com/bytezone/diskbrowser/applefile/HiResImage.java b/src/com/bytezone/diskbrowser/applefile/HiResImage.java index b927dbf..308b0a9 100755 --- a/src/com/bytezone/diskbrowser/applefile/HiResImage.java +++ b/src/com/bytezone/diskbrowser/applefile/HiResImage.java @@ -11,6 +11,9 @@ import com.bytezone.diskbrowser.HexFormatter; public class HiResImage extends AbstractFile { + private static final int[][] colours = { { 0x000000, 0xBB66FF, 0x00FF00, 0xFFFFFF }, + { 0x000000, 0x0000FF, 0xFF0000, 0xFFFFFF } }; + int fileType; int auxType; byte[] unpackedBuffer; @@ -88,12 +91,76 @@ public class HiResImage extends AbstractFile image = new BufferedImage (280, rows, BufferedImage.TYPE_INT_RGB); DataBuffer db = image.getRaster ().getDataBuffer (); + int[][] colours = { { 0xBB66FF, 0x00FF00 }, { 0x0000FF, 0xFF0000 } }; int element = 0; int[] line = new int[280]; int linePtr = 0; + for (int z = 0; z < rows / 192; z++) + { + int zz = z * 0x2000; + for (int i = 0; i < 3; i++) + { + int ii = zz + i * 0x28; + for (int j = 0; j < 8; j++) + { + int jj = ii + j * 0x80; + for (int k = 0; k < 8; k++) + { + int base = jj + k * 0x400; + int max = Math.min (base + 40, buffer.length); + + for (int ptr = base; ptr < max; ptr++) + { + int colourBit = (buffer[ptr] & 0x80) >> 7; + int value = buffer[ptr] & 0x7F; + + for (int px = 0; px < 7; px++) + { + int val = (value >> px) & 0x01; + int column = (ptr + px) % 2; + line[linePtr++] = val == 0 ? 0 : colours[colourBit][column]; + } + } + + // convert ALL consecutive ON pixels to white + for (int x = 0; x < line.length - 1; x++) + if (line[x] != 0 && line[x + 1] != 0) + line[x] = line[x + 1] = 0xFFFFFF; + + // convert single coloured pixels to double - this can be ugly + if (false) + { + for (int x = 0; x < line.length - 1; x += 2) + if (line[x] != 0 && line[x] != 0xFFFFFF && line[x + 1] == 0) + line[x + 1] = line[x]; + else if (line[x] == 0 && line[x + 1] != 0 && line[x + 1] != 0xFFFFFF) + line[x] = line[x + 1]; + } + + for (int pixel : line) + db.setElem (element++, pixel); + linePtr = 0; + } + } + } + + } + } + + private void drawSolidColour (byte[] buffer) + { + int rows = buffer.length <= 8192 ? 192 : 384; + image = new BufferedImage (280, rows, BufferedImage.TYPE_INT_RGB); + + DataBuffer db = image.getRaster ().getDataBuffer (); + int[][] colours = { { 0x000000, 0xBB66FF, 0x00FF00, 0xFFFFFF }, + { 0x000000, 0x0000FF, 0xFF0000, 0xFFFFFF } }; + + int element = 0; + for (int z = 0; z < rows / 192; z++) for (int i = 0; i < 3; i++) for (int j = 0; j < 8; j++) @@ -102,40 +169,33 @@ public class HiResImage extends AbstractFile int base = i * 0x28 + j * 0x80 + k * 0x400 + z * 0x2000; int max = Math.min (base + 40, buffer.length); - for (int ptr = base; ptr < max; ptr++) + for (int ptr = base; ptr < max; ptr += 2) { - int colourBit = buffer[ptr] & 0x80; - int value = buffer[ptr] & 0x7F; + int colourBit1 = (buffer[ptr] & 0x80) >> 7; + int colourBit2 = (buffer[ptr + 1] & 0x80) >> 7; + + int value = ((buffer[ptr + 1] & 0x7F) << 7) + (buffer[ptr] & 0x7F); for (int px = 0; px < 7; px++) - line[linePtr++] = - getColour ((value >> px) & 0x01, (ptr + px) % 2, colourBit); - } - - for (int x = 1; x < line.length; x++) - if (line[x] != 0 && line[x - 1] != 0) { - line[x] = 0xFFFFFF; // white - line[x - 1] = 0xFFFFFF; // white + int val = value & 0x03; + value >>= 2; + int colour = 0; + + if (px <= 2) + colour = colours[colourBit1][val]; + else if (px == 3) + colour = colours[val >= 2 ? colourBit1 : colourBit2][val]; + else + colour = colours[colourBit2][val]; + + db.setElem (element++, colour); + db.setElem (element++, colour); } - - for (int pixel : line) - db.setElem (element++, pixel); - linePtr = 0; + } } } - private int getColour (int val, int column, int colourBit) - { - if (val == 0) - return 0; // black - - if (column == 0) - return colourBit == 0 ? 0xBB66FF : 0x0000FF; // violet / blue - else - return colourBit == 0 ? 0x00FF00 : 0xFF0000; // green / red - } - private void makeScreen2 (byte[] buffer) { // System.out.println (HexFormatter.format (buffer, 32000, 640)); diff --git a/src/com/bytezone/diskbrowser/disk/DiskFactory.java b/src/com/bytezone/diskbrowser/disk/DiskFactory.java index 85f6584..c87922a 100755 --- a/src/com/bytezone/diskbrowser/disk/DiskFactory.java +++ b/src/com/bytezone/diskbrowser/disk/DiskFactory.java @@ -1,6 +1,10 @@ package com.bytezone.diskbrowser.disk; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; import java.nio.file.Path; import java.nio.file.Paths; import java.util.zip.GZIPInputStream; @@ -115,7 +119,8 @@ public class DiskFactory long length = file.length (); if (length != 143360 && length != 116480) { - System.out.println ("invalid file length : " + file.length ()); + System.out.printf ("%s: invalid file length : %,d%n", file.getName (), + file.length ()); return null; } @@ -126,9 +131,9 @@ public class DiskFactory long checksum = appleDisk.getBootChecksum (); if (checksum == 3176296590L || checksum == 108825457L || checksum == 1439356606L - || checksum == 1550012074L || checksum == 1614602459L || checksum == 940889336L - || checksum == 990032697 || checksum == 2936955085L || checksum == 1348415927L - || checksum == 3340889101L || checksum == 18315788L || checksum == 993895235L) + || checksum == 1550012074L || checksum == 1614602459L || checksum == 940889336L + || checksum == 990032697 || checksum == 2936955085L || checksum == 1348415927L + || checksum == 3340889101L || checksum == 18315788L || checksum == 993895235L) { disk = checkDos (file); disk2 = checkProdos (file); @@ -144,8 +149,8 @@ public class DiskFactory disk = new DualDosDisk (disk, disk2); } - else if (checksum == 2803644711L || checksum == 3317783349L || checksum == 1728863694L - || checksum == 198094178L) + else if (checksum == 2803644711L || checksum == 3317783349L + || checksum == 1728863694L || checksum == 198094178L) disk = checkPascalDisk (file); else if (checksum == 3028642627L || checksum == 2070151659L) @@ -202,7 +207,7 @@ public class DiskFactory if (debug) System.out.println (" Factory creating disk : " - + disk.getDisk ().getFile ().getAbsolutePath ()); + + disk.getDisk ().getFile ().getAbsolutePath ()); if (disk != null && compressed) disk.setOriginalPath (p); diff --git a/src/com/bytezone/diskbrowser/dos/AbstractCatalogEntry.java b/src/com/bytezone/diskbrowser/dos/AbstractCatalogEntry.java index abc14b1..6ac5780 100644 --- a/src/com/bytezone/diskbrowser/dos/AbstractCatalogEntry.java +++ b/src/com/bytezone/diskbrowser/dos/AbstractCatalogEntry.java @@ -216,10 +216,11 @@ abstract class AbstractCatalogEntry implements AppleFileSource else { appleFile = new AssemblerProgram (name, exactBuffer, loadAddress); - if (exactBuffer.length < buffer.length + 4) + // System.out.printf ("%d %d%n", exactBuffer.length, reportedLength); + if ((exactBuffer.length + 4) < buffer.length) ((AssemblerProgram) appleFile) - .setExtraBuffer (buffer, reportedLength + 4, - buffer.length - reportedLength - 4); + .setExtraBuffer (buffer, exactBuffer.length + 4, + buffer.length - (exactBuffer.length + 4)); } } break; diff --git a/src/com/bytezone/diskbrowser/prodos/ProdosDisk.java b/src/com/bytezone/diskbrowser/prodos/ProdosDisk.java index 7c70d7b..74c527b 100755 --- a/src/com/bytezone/diskbrowser/prodos/ProdosDisk.java +++ b/src/com/bytezone/diskbrowser/prodos/ProdosDisk.java @@ -73,7 +73,7 @@ public class ProdosDisk extends AbstractFormattedDisk } private void processDirectoryBlock (int block, FileEntry parent, - DefaultMutableTreeNode parentNode) + DefaultMutableTreeNode parentNode) { DirectoryHeader localHeader = null; SectorType currentSectorType = null; @@ -83,8 +83,9 @@ public class ProdosDisk extends AbstractFormattedDisk byte[] sectorBuffer = disk.readSector (block); sectorTypes[block] = currentSectorType; - for (int ptr = 4, max = disk.getBlockSize () - ProdosConstants.ENTRY_SIZE; ptr < max; ptr += - ProdosConstants.ENTRY_SIZE) + for (int ptr = 4, max = + disk.getBlockSize () - ProdosConstants.ENTRY_SIZE; ptr < max; ptr += + ProdosConstants.ENTRY_SIZE) { int storageType = (sectorBuffer[ptr] & 0xF0) >> 4; if (storageType == 0) // deleted or unused @@ -154,7 +155,12 @@ public class ProdosDisk extends AbstractFormattedDisk { byte[] buffer = disk.readSector (2); // Prodos KEY BLOCK if (debug) + { System.out.println (HexFormatter.format (buffer)); + System.out.printf ("Entry length : %02X%n", buffer[0x23]); + System.out.printf ("Entry per block: %02X%n", buffer[0x24]); + System.out.printf ("Bit map block : %02X%02X%n", buffer[0x27], buffer[0x28]); + } // check entry length and entries per block if (buffer[0x23] != 0x27 || buffer[0x24] != 0x0D) @@ -175,7 +181,8 @@ public class ProdosDisk extends AbstractFormattedDisk @Override public AppleFileSource getCatalog () { - return new DefaultAppleFileSource ("Catalog", headerEntries.get (0).getDataSource (), this); + return new DefaultAppleFileSource ("Catalog", headerEntries.get (0).getDataSource (), + this); } @Override @@ -185,9 +192,8 @@ public class ProdosDisk extends AbstractFormattedDisk String newLine = String.format ("%n"); VolumeDirectoryHeader volumeDirectory = (VolumeDirectoryHeader) headerEntries.get (0); - String timeC = - volumeDirectory.created == null ? "" : df - .format (volumeDirectory.created.getTime ()); + String timeC = volumeDirectory.created == null ? "" + : df.format (volumeDirectory.created.getTime ()); text.append ("Volume name : " + volumeDirectory.name + newLine); text.append ("Creation date : " + timeC + newLine); text.append ("ProDOS version : " + volumeDirectory.version + newLine);