From 13a45cd9bf84215c4061486bec02b98c0a4547a0 Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Tue, 1 Dec 2020 21:02:01 +1000 Subject: [PATCH] improved text preferences --- .../applefile/ApplesoftBasicProgram.java | 16 +++---- .../diskbrowser/applefile/BasicTextFile.java | 44 +++++++++++++++---- .../diskbrowser/applefile/DosMasterFile.java | 4 -- .../diskbrowser/disk/DiskFactory.java | 13 ++++++ .../diskbrowser/prodos/FileEntry.java | 5 ++- .../prodos/VolumeDirectoryHeader.java | 14 ++---- 6 files changed, 63 insertions(+), 33 deletions(-) diff --git a/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java b/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java index 1f7ba77..d44e015 100644 --- a/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java +++ b/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java @@ -543,7 +543,7 @@ public class ApplesoftBasicProgram extends BasicProgram int linePtr; int length; - public SourceLine (int ptr) + SourceLine (int ptr) { linePtr = ptr; // lineNumber = Utility.intValue (buffer[ptr + 2], buffer[ptr + 3]); @@ -630,7 +630,7 @@ public class ApplesoftBasicProgram extends BasicProgram // used for aligning the equals sign int assignEqualPos; - public SubLine (SourceLine parent, int startPtr, int length) + SubLine (SourceLine parent, int startPtr, int length) { this.parent = parent; this.startPtr = startPtr; @@ -738,22 +738,22 @@ public class ApplesoftBasicProgram extends BasicProgram return is (TOKEN_REM) && !isFirst (); } - public boolean isFirst () + boolean isFirst () { return (parent.linePtr + 4) == startPtr; } - public boolean is (byte token) + boolean is (byte token) { return buffer[startPtr] == token; } - public boolean isEmpty () + boolean isEmpty () { return length == 1 && buffer[startPtr] == 0; } - public boolean containsToken () + boolean containsToken () { // ignore first byte, check the rest for tokens for (int p = startPtr + 1, max = startPtr + length; p < max; p++) @@ -763,7 +763,7 @@ public class ApplesoftBasicProgram extends BasicProgram return false; } - public boolean containsControlChars () + boolean containsControlChars () { for (int p = startPtr + 1, max = startPtr + length; p < max; p++) { @@ -778,7 +778,7 @@ public class ApplesoftBasicProgram extends BasicProgram return false; } - public void addFormattedRem (StringBuilder text) + void addFormattedRem (StringBuilder text) { int ptr = startPtr + 1; int max = startPtr + length - 2; diff --git a/src/com/bytezone/diskbrowser/applefile/BasicTextFile.java b/src/com/bytezone/diskbrowser/applefile/BasicTextFile.java index bce81df..5613b40 100755 --- a/src/com/bytezone/diskbrowser/applefile/BasicTextFile.java +++ b/src/com/bytezone/diskbrowser/applefile/BasicTextFile.java @@ -92,9 +92,17 @@ public class BasicTextFile extends TextFile if (recordLength == 0) return unknownLength (text); - text.append ("Offset Record# Text values\n"); - text.append ( - "------ ------- -------------------------------------------------------\n"); + if (textPreferences.showTextOffsets) + { + text.append (" Offset Record# Text values\n"); + text.append ( + "---------- ------- -------------------------------------------------------\n"); + } + else + { + text.append ("Text values\n"); + text.append ("-------------------------------------------------------\n"); + } return knownLength (text, 0).toString (); } @@ -102,9 +110,17 @@ public class BasicTextFile extends TextFile private String treeFileText (StringBuilder text) // ---------------------------------------------------------------------------------// { - text.append (" Offset Record# Text values\n"); - text.append ( - "---------- ------- -------------------------------------------------------\n"); + if (textPreferences.showTextOffsets) + { + text.append (" Offset Record# Text values\n"); + text.append ( + "---------- ------- -------------------------------------------------------\n"); + } + else + { + text.append ("Text values\n"); + text.append ("-------------------------------------------------------\n"); + } for (TextBuffer tb : buffers) { buffer = tb.buffer; @@ -135,9 +151,19 @@ public class BasicTextFile extends TextFile bytes--; String line = HexFormatter.getString (buffer, ptr, bytes); - line = line.replaceAll ("\\n", "\n "); - text.append ( - String.format ("%,10d %,8d %s%n", recNo * recordLength, recNo++, line)); + + if (textPreferences.showTextOffsets) + { + line = line.replaceAll ("\\n", "\n "); + text.append ( + String.format ("%,10d %,8d %s%n", recNo * recordLength, recNo++, line)); + } + else + { + line = line.replaceAll ("\\n", "\n "); + text.append (String.format ("%s%n", line)); + recNo++; + } } return text; diff --git a/src/com/bytezone/diskbrowser/applefile/DosMasterFile.java b/src/com/bytezone/diskbrowser/applefile/DosMasterFile.java index 4478725..87cd84d 100644 --- a/src/com/bytezone/diskbrowser/applefile/DosMasterFile.java +++ b/src/com/bytezone/diskbrowser/applefile/DosMasterFile.java @@ -30,7 +30,6 @@ public class DosMasterFile extends AbstractFile public static boolean isDos33 (ProdosDisk parentDisk, byte[] buffer) // ---------------------------------------------------------------------------------// { - // System.out.println (HexFormatter.format (buffer, 0x38, 0x30, 0x38)); System.out.printf ("%nHighest Block: %04X (%<,d)%n", parentDisk.getDisk ().getTotalBlocks () - 1); @@ -106,9 +105,6 @@ public class DosMasterFile extends AbstractFile daList.add (disk.getDiskAddress (block)); byte[] diskBuffer = disk.readBlocks (daList); - // System.out.println (HexFormatter.format (diskBuffer)); - // System.out.printf ("Buffer: %,d%n", diskBuffer.length); - // System.out.printf ("Blocks: %,d x 2 = %,d%n", daList.size (), daList.size () * 2); if (false) createDisk (String.format ("%sVol%03d.dsk", base, volNo), diskBuffer); diff --git a/src/com/bytezone/diskbrowser/disk/DiskFactory.java b/src/com/bytezone/diskbrowser/disk/DiskFactory.java index 199bfa3..285f739 100755 --- a/src/com/bytezone/diskbrowser/disk/DiskFactory.java +++ b/src/com/bytezone/diskbrowser/disk/DiskFactory.java @@ -478,12 +478,25 @@ public class DiskFactory disk2 = checkProdos (appleDisk512); if (disk2 != null) + { disk = new DualDosDisk (disk, disk2); + return disk; + } AppleDisk appleDisk = new AppleDisk (file, 35, 16); disk2 = checkCPMDisk (appleDisk); if (disk2 != null) + { disk = new DualDosDisk (disk, disk2); + return disk; + } + + disk2 = checkPascalDisk (appleDisk512); + if (disk2 != null) + { + disk = new DualDosDisk (disk, disk2); + return disk; + } } } else if (suffix.equals ("po")) diff --git a/src/com/bytezone/diskbrowser/prodos/FileEntry.java b/src/com/bytezone/diskbrowser/prodos/FileEntry.java index 2d4bf27..0c721f0 100755 --- a/src/com/bytezone/diskbrowser/prodos/FileEntry.java +++ b/src/com/bytezone/diskbrowser/prodos/FileEntry.java @@ -7,6 +7,7 @@ import java.util.List; import com.bytezone.diskbrowser.applefile.ApplesoftBasicProgram; import com.bytezone.diskbrowser.applefile.AssemblerProgram; import com.bytezone.diskbrowser.applefile.BasicProgramGS; +import com.bytezone.diskbrowser.applefile.BasicTextFile; import com.bytezone.diskbrowser.applefile.CharacterRom; import com.bytezone.diskbrowser.applefile.DefaultAppleFile; import com.bytezone.diskbrowser.applefile.DeviceDriver; @@ -35,7 +36,6 @@ import com.bytezone.diskbrowser.applefile.ShapeTable; import com.bytezone.diskbrowser.applefile.SimpleText; import com.bytezone.diskbrowser.applefile.StoredVariables; import com.bytezone.diskbrowser.applefile.TextBuffer; -import com.bytezone.diskbrowser.applefile.BasicTextFile; import com.bytezone.diskbrowser.appleworks.AppleworksADBFile; import com.bytezone.diskbrowser.appleworks.AppleworksSSFile; import com.bytezone.diskbrowser.appleworks.AppleworksWPFile; @@ -222,7 +222,7 @@ class FileEntry extends CatalogEntry implements ProdosConstants parentDisk.setSectorType (keyPtr, parentDisk.masterIndexSector); indexBlocks.add (disk.getDiskAddress (keyPtr)); - byte[] buffer = disk.readBlock (keyPtr); // master index + byte[] buffer = disk.readBlock (keyPtr); // master index int highest = 0x80; while (highest-- > 0) // decrement after test @@ -272,6 +272,7 @@ class FileEntry extends CatalogEntry implements ProdosConstants byte[] buffer = getBuffer (); byte[] exactBuffer = getExactBuffer (buffer); + // System.out.printf ("Name: %s, EOF: %04X%n", name, endOfFile); try { diff --git a/src/com/bytezone/diskbrowser/prodos/VolumeDirectoryHeader.java b/src/com/bytezone/diskbrowser/prodos/VolumeDirectoryHeader.java index 58813fb..46adda3 100755 --- a/src/com/bytezone/diskbrowser/prodos/VolumeDirectoryHeader.java +++ b/src/com/bytezone/diskbrowser/prodos/VolumeDirectoryHeader.java @@ -44,7 +44,6 @@ class VolumeDirectoryHeader extends DirectoryHeader } while (block > 0); // convert the Free Sector Table - // int bitMapBytes = totalBlocks / 8; // one bit per block int bitMapBytes = (totalBlocks - 1) / 8 + 1; // one bit per block byte[] buffer = new byte[bitMapBytes]; int bitMapBlocks = (bitMapBytes - 1) / disk.getBlocksPerTrack () + 1; @@ -77,19 +76,14 @@ class VolumeDirectoryHeader extends DirectoryHeader byte b = buffer[i]; for (int j = 0; j < 8; j++) { - if ((b & 0x80) == 0x80) - { + boolean free = (b & 0x80) != 0; + if (free) freeBlocks++; - parentDisk.setSectorFree (block++, true); - } - else - { - usedBlocks++; - parentDisk.setSectorFree (block++, false); - } + parentDisk.setSectorFree (block++, free); b <<= 1; } } + usedBlocks = totalBlocks - freeBlocks; // totalBlocks may not be a multiple of 8 } // ---------------------------------------------------------------------------------//