From 9b2e621ecd033426af36f50e964a8f964d707205 Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Sat, 27 Feb 2016 10:10:00 +1100 Subject: [PATCH] read only and system file --- .../diskbrowser/cpm/CPMCatalogSector.java | 23 ++++++++++++- src/com/bytezone/diskbrowser/cpm/CPMDisk.java | 4 +-- .../diskbrowser/cpm/DirectoryEntry.java | 32 ++++++++++++++++--- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/src/com/bytezone/diskbrowser/cpm/CPMCatalogSector.java b/src/com/bytezone/diskbrowser/cpm/CPMCatalogSector.java index 9e47fb2..849c10c 100644 --- a/src/com/bytezone/diskbrowser/cpm/CPMCatalogSector.java +++ b/src/com/bytezone/diskbrowser/cpm/CPMCatalogSector.java @@ -22,10 +22,31 @@ public class CPMCatalogSector extends AbstractSector if (buffer[i] == (byte) 0xE5) break; + boolean readOnly = (buffer[i + 9] & 0x80) != 0; + boolean systemFile = (buffer[i + 10] & 0x80) != 0; + String type; + String extra; + + if (readOnly || systemFile) + { + byte[] typeBuffer = new byte[3]; + typeBuffer[0] = (byte) (buffer[i + 9] & 0x7F); + typeBuffer[1] = (byte) (buffer[i + 10] & 0x7F); + typeBuffer[2] = buffer[i + 11]; + type = new String (typeBuffer).trim (); + extra = String.format (" (%s%s)", readOnly ? "read only" : "", + systemFile ? "system file" : ""); + } + else + { + type = new String (buffer, i + 9, 3).trim (); + extra = ""; + } + addText (text, buffer, i, 1, "User number"); addText (text, buffer, i + 1, 4, "File name : " + new String (buffer, i + 1, 8)); addText (text, buffer, i + 5, 4, ""); - addText (text, buffer, i + 9, 3, "File type : " + new String (buffer, i + 9, 3)); + addText (text, buffer, i + 9, 3, "File type : " + type + extra); addText (text, buffer, i + 12, 1, "Extent counter LO"); addText (text, buffer, i + 13, 1, "Reserved"); addText (text, buffer, i + 14, 1, "Extent counter HI"); diff --git a/src/com/bytezone/diskbrowser/cpm/CPMDisk.java b/src/com/bytezone/diskbrowser/cpm/CPMDisk.java index 207a613..dc4f741 100644 --- a/src/com/bytezone/diskbrowser/cpm/CPMDisk.java +++ b/src/com/bytezone/diskbrowser/cpm/CPMDisk.java @@ -134,11 +134,11 @@ public class CPMDisk extends AbstractFormattedDisk { String newLine = String.format ("%n"); String line = - "---- --------- --- -- -- -- -- ----------------------------" + "---- --------- --- - - -- -- -- -- ----------------------------" + "-------------------" + newLine; StringBuilder text = new StringBuilder (); text.append (String.format ("Disk : %s%n%n", getAbsolutePath ())); - text.append ("User Name Typ Ex S2 S1 RC Blocks" + newLine); + text.append ("User Name Typ R S Ex S2 S1 RC Blocks" + newLine); text.append (line); for (AppleFileSource entry : fileEntries) diff --git a/src/com/bytezone/diskbrowser/cpm/DirectoryEntry.java b/src/com/bytezone/diskbrowser/cpm/DirectoryEntry.java index b5ed6d8..0c9a4c4 100644 --- a/src/com/bytezone/diskbrowser/cpm/DirectoryEntry.java +++ b/src/com/bytezone/diskbrowser/cpm/DirectoryEntry.java @@ -28,15 +28,30 @@ public class DirectoryEntry implements AppleFileSource private final List entries = new ArrayList (); private final List blocks = new ArrayList (); private DataSource appleFile; + private final boolean readOnly; + private final boolean systemFile; public DirectoryEntry (CPMDisk parent, byte[] buffer, int offset) { this.parent = parent; disk = parent.getDisk (); + readOnly = (buffer[offset + 9] & 0x80) != 0; + systemFile = (buffer[offset + 10] & 0x80) != 0; + + if (readOnly || systemFile) + { + byte[] typeBuffer = new byte[3]; + typeBuffer[0] = (byte) (buffer[offset + 9] & 0x7F); + typeBuffer[1] = (byte) (buffer[offset + 10] & 0x7F); + typeBuffer[2] = buffer[offset + 11]; + type = new String (typeBuffer).trim (); + } + else + type = new String (buffer, offset + 9, 3).trim (); + userNumber = buffer[offset] & 0xFF; name = new String (buffer, offset + 1, 8).trim (); - type = new String (buffer, offset + 9, 3).trim (); ex = buffer[offset + 12] & 0xFF; s2 = buffer[offset + 13] & 0xFF; s1 = buffer[offset + 14] & 0xFF; @@ -100,8 +115,12 @@ public class DirectoryEntry implements AppleFileSource String bytes = HexFormatter.getHexString (blockList, 0, 16); bytes = bytes.replaceAll ("00", " "); - String text = String.format ("%3d %-8s %-3s %02X %02X %02X %02X %s", - userNumber, name, type, ex, s2, s1, rc, bytes); + char ro = readOnly ? '*' : ' '; + char sf = systemFile ? '*' : ' '; + + String text = + String.format ("%3d %-8s %-3s %s %s %02X %02X %02X %02X %s", + userNumber, name, type, ro, sf, ex, s2, s1, rc, bytes); for (DirectoryEntry entry : entries) text = text + "\n" + entry.line (); @@ -170,7 +189,12 @@ public class DirectoryEntry implements AppleFileSource ++count; } - if ("ASM".equals (type) || "DOC".equals (type) || "TXT".equals (type) || count > 0) + if ("COM".equals (type)) + appleFile = new DefaultAppleFile (name, exactBuffer, "COM File"); + else if ("DVR".equals (type)) + appleFile = new DefaultAppleFile (name, exactBuffer, "DVR File"); + else if ("ASM".equals (type) || "DOC".equals (type) || "TXT".equals (type) + || count > 2) appleFile = new CPMTextFile (name, exactBuffer); else appleFile = new DefaultAppleFile (name, exactBuffer, "CPM File : " + type);