This commit is contained in:
Denis Molony
2017-03-13 03:47:11 +11:00
parent 6f9558674f
commit 4865246924
4 changed files with 128 additions and 69 deletions

View File

@@ -22,7 +22,7 @@ import com.bytezone.diskbrowser.wizardry.WizardryScenarioDisk;
public class DiskFactory public class DiskFactory
{ {
private static boolean debug = false; private static boolean debug = true;
private DiskFactory () private DiskFactory ()
{ {
@@ -36,7 +36,7 @@ public class DiskFactory
public static FormattedDisk createDisk (String path) public static FormattedDisk createDisk (String path)
{ {
if (debug) if (debug)
System.out.println ("Factory : " + path); System.out.println ("\nFactory : " + path);
File file = new File (path); File file = new File (path);
if (!file.exists ()) if (!file.exists ())
@@ -48,6 +48,8 @@ public class DiskFactory
if (suffix.equals ("gz")) if (suffix.equals ("gz"))
{ {
if (debug)
System.out.println (" ** gzip **");
try try
{ {
InputStream in = new GZIPInputStream (new FileInputStream (path)); InputStream in = new GZIPInputStream (new FileInputStream (path));
@@ -76,6 +78,8 @@ public class DiskFactory
if (suffix.equals ("sdk")) if (suffix.equals ("sdk"))
{ {
if (debug)
System.out.println (" ** sdk **");
try try
{ {
NuFX nuFX = new NuFX (file); NuFX nuFX = new NuFX (file);
@@ -104,6 +108,8 @@ public class DiskFactory
if (suffix.equals ("hdv")) if (suffix.equals ("hdv"))
{ {
if (debug)
System.out.println (" ** hdv **");
ProdosDisk prodosDisk = checkHardDisk (file); ProdosDisk prodosDisk = checkHardDisk (file);
if (prodosDisk != null) if (prodosDisk != null)
return prodosDisk; return prodosDisk;
@@ -118,6 +124,8 @@ public class DiskFactory
if (suffix.equals ("2mg")) if (suffix.equals ("2mg"))
{ {
if (debug)
System.out.println (" ** 2mg **");
disk2 = check2mgDisk (file); disk2 = check2mgDisk (file);
if (disk2 != null) if (disk2 != null)
return disk2; return disk2;
@@ -129,7 +137,7 @@ public class DiskFactory
if (((suffix.equals ("po") || suffix.equals ("dsk")) && file.length () > 143360)) if (((suffix.equals ("po") || suffix.equals ("dsk")) && file.length () > 143360))
{ {
if (debug) if (debug)
System.out.println ("Checking po or dsk hard drive: " + file.length ()); System.out.println (" Checking po or dsk hard drive: " + file.length ());
disk = checkHardDisk (file); disk = checkHardDisk (file);
if (disk != null) if (disk != null)
@@ -140,25 +148,27 @@ public class DiskFactory
} }
if (debug) if (debug)
System.out.println ("Creating a data disk from bad length"); System.out.println (" Creating a data disk from bad length");
try try
{ {
AppleDisk appleDisk = new AppleDisk (file, (int) file.length () / 4096, 8); AppleDisk appleDisk = new AppleDisk (file, (int) file.length () / 4096, 8);
if (debug) if (debug)
System.out.println ("created"); System.out.println (" created data usk");
return new DataDisk (appleDisk); return new DataDisk (appleDisk);
} }
catch (FileFormatException e) catch (FileFormatException e)
{ {
if (debug) if (debug)
System.out.println ("Creating AppleDisk failed"); System.out.println (" Creating AppleDisk failed");
return null; return null;
} }
} }
if (suffix.equals ("v2d")) if (suffix.equals ("v2d"))
{ {
if (debug)
System.out.println (" ** v2d **");
V2dDisk v2dDisk = new V2dDisk (file); V2dDisk v2dDisk = new V2dDisk (file);
AppleDisk appleDisk16 = new AppleDisk (v2dDisk); AppleDisk appleDisk16 = new AppleDisk (v2dDisk);
disk = checkDos (appleDisk16); disk = checkDos (appleDisk16);
@@ -167,6 +177,8 @@ public class DiskFactory
if (suffix.equals ("nib")) if (suffix.equals ("nib"))
{ {
if (debug)
System.out.println (" ** nib **");
NibDisk nibDisk = new NibDisk (file); NibDisk nibDisk = new NibDisk (file);
AppleDisk appleDisk16 = new AppleDisk (nibDisk); AppleDisk appleDisk16 = new AppleDisk (nibDisk);
disk = checkDos (appleDisk16); disk = checkDos (appleDisk16);
@@ -177,6 +189,8 @@ public class DiskFactory
if (length == 116480) // 13 sector disk if (length == 116480) // 13 sector disk
{ {
if (debug)
System.out.println (" ** 13 sector **");
if (!suffix.equals ("d13")) if (!suffix.equals ("d13"))
System.out.printf ("%s should have a d13 suffix%n", file.getName ()); System.out.printf ("%s should have a d13 suffix%n", file.getName ());
@@ -192,38 +206,75 @@ public class DiskFactory
return null; return null;
} }
AppleDisk appleDisk16 = new AppleDisk (file, 35, 16); AppleDisk appleDisk256 = new AppleDisk (file, 35, 16);
AppleDisk appleDisk8 = new AppleDisk (file, 35, 8); AppleDisk appleDisk512 = new AppleDisk (file, 35, 8);
if (true) if (true)
{ {
long checksum = appleDisk16.getBootChecksum (); // if (debug)
// System.out.println (" trying checksums");
long checksum = appleDisk256.getBootChecksum ();
if (checksum == 3176296590L || checksum == 108825457L || checksum == 1439356606L if (checksum == 3176296590L //
|| checksum == 1550012074L || checksum == 1614602459L || checksum == 940889336L || checksum == 108825457L //
|| checksum == 990032697 || checksum == 2936955085L || checksum == 1348415927L || checksum == 1439356606L //
|| checksum == 3340889101L || checksum == 18315788L || checksum == 993895235L) || checksum == 1550012074L //
|| checksum == 1614602459L //
|| checksum == 940889336L //
|| checksum == 2936955085L //
|| checksum == 1348415927L //
|| checksum == 3340889101L //
|| checksum == 18315788L //
|| checksum == 993895235L //
|| checksum == 2378342794L) // LazerPascal1.dsk
{ {
disk = checkDos (appleDisk16); if (debug)
disk2 = checkProdos (appleDisk8); System.out.println (" known DOS checksum : " + checksum);
if (disk2 != null && disk != null) disk = checkDos (appleDisk256);
disk2 = checkProdos (appleDisk512); // no need for this
if (disk2 != null && disk != null) // should be impossible
{
if (debug)
System.out.println (" --> Dual dos/prodos 1");
System.out.println ("** impossible **");
disk = new DualDosDisk (disk, disk2); disk = new DualDosDisk (disk, disk2);
}
} }
else if (checksum == 1737448647L || checksum == 170399908L) else if (checksum == 1737448647L //
|| checksum == 170399908L //
|| checksum == 990032697) // Apple Assembly Line
{ {
disk = checkProdos (appleDisk8); if (debug)
disk2 = checkDos (appleDisk16); System.out.println (" known PRODOS checksum : " + checksum);
disk = checkProdos (appleDisk512);
disk2 = checkDos (appleDisk256);
if (disk2 != null && disk != null) if (disk2 != null && disk != null)
{
if (debug)
System.out.println (" --> Dual prodos/dos 2");
disk = new DualDosDisk (disk, disk2); disk = new DualDosDisk (disk, disk2);
}
} }
else if (checksum == 2803644711L || checksum == 3317783349L else if (checksum == 2803644711L // Apple Pascal disk 0
|| checksum == 1728863694L || checksum == 198094178L) || checksum == 3317783349L //
|| checksum == 1728863694L // Wizardry_I_boot.dsk
|| checksum == 227968344L // wizardry_I/australia16.dsk
|| checksum == 198094178L //
|| checksum == 227968344L) // lauren.dsk
{ {
// disk = checkPascalDisk (file); if (debug)
disk = checkPascalDisk (appleDisk8); System.out.println (" known PASCAL checksum : " + checksum);
disk = checkPascalDisk (appleDisk512);
} }
else if (checksum == 3028642627L || checksum == 2070151659L) else if (checksum == 3028642627L //
disk = checkInfocomDisk (appleDisk16); || checksum == 2070151659L) // Enchanter
{
if (debug)
System.out.println (" known INFOCOM checksum : " + checksum);
disk = checkInfocomDisk (appleDisk256);
}
else if (debug)
System.out.println (" unknown checksum : " + checksum);
// else if (checksum == 1212926910L || checksum == 1365043894L // else if (checksum == 1212926910L || checksum == 1365043894L
// || checksum == 2128073918L) // || checksum == 2128073918L)
@@ -243,43 +294,48 @@ public class DiskFactory
System.out.println ("Unknown checksum : " + checksum + " : " + path); System.out.println ("Unknown checksum : " + checksum + " : " + path);
} }
if (debug)
System.out.println (" checksum no help");
if (debug)
System.out.println (" Suffix : " + suffix);
if (suffix.equals ("dsk") || suffix.equals ("do")) if (suffix.equals ("dsk") || suffix.equals ("do"))
{ {
disk = checkDos (appleDisk16); disk = checkDos (appleDisk256);
if (disk == null) if (disk == null)
disk = checkProdos (appleDisk8); disk = checkProdos (appleDisk512);
else else
{ {
if (debug) if (debug)
System.out.println ("Checking DualDos disk"); System.out.println ("Checking DualDos disk");
disk2 = checkProdos (appleDisk8); disk2 = checkProdos (appleDisk512);
if (disk2 != null) if (disk2 != null)
disk = new DualDosDisk (disk, disk2); disk = new DualDosDisk (disk, disk2);
} }
} }
else if (suffix.equals ("po")) else if (suffix.equals ("po"))
{ {
disk = checkProdos (appleDisk8); disk = checkProdos (appleDisk512);
if (disk == null) if (disk == null)
disk = checkDos (appleDisk16); disk = checkDos (appleDisk256);
} }
if (disk == null) if (disk == null)
disk = checkPascalDisk (appleDisk8); disk = checkPascalDisk (appleDisk512);
if (disk == null) if (disk == null)
disk = checkCPMDisk (appleDisk16); disk = checkCPMDisk (appleDisk256);
if (disk == null) if (disk == null)
{ {
disk2 = checkInfocomDisk (appleDisk16); disk2 = checkInfocomDisk (appleDisk256);
if (disk2 != null) if (disk2 != null)
disk = disk2; disk = disk2;
} }
if (disk == null) if (disk == null)
disk = new DataDisk (appleDisk16); disk = new DataDisk (appleDisk256);
if (debug) if (debug)
System.out.println ( System.out.println (
@@ -299,13 +355,17 @@ public class DiskFactory
try try
{ {
if (DosDisk.isCorrectFormat (disk)) if (DosDisk.isCorrectFormat (disk))
{
if (debug)
System.out.println (" --> DOS");
return new DosDisk (disk); return new DosDisk (disk);
}
} }
catch (Exception e) catch (Exception e)
{ {
} }
if (debug) if (debug)
System.out.println ("Not a DOS disk"); System.out.println (" not a DOS disk");
return null; return null;
} }
@@ -317,13 +377,17 @@ public class DiskFactory
try try
{ {
if (ProdosDisk.isCorrectFormat (disk)) if (ProdosDisk.isCorrectFormat (disk))
{
if (debug)
System.out.println (" --> PRODOS");
return new ProdosDisk (disk); return new ProdosDisk (disk);
}
} }
catch (Exception e) catch (Exception e)
{ {
} }
if (debug) if (debug)
System.out.println ("Not a Prodos disk"); System.out.println (" not a Prodos disk");
return null; return null;
} }
@@ -353,10 +417,7 @@ public class DiskFactory
if (ProdosDisk.isCorrectFormat (disk)) if (ProdosDisk.isCorrectFormat (disk))
{ {
if (debug) if (debug)
{ System.out.println (" --> PRODOS hard disk");
System.out.println ("Yay, it's a prodos hard disk");
System.out.println (disk);
}
return new ProdosDisk (disk); return new ProdosDisk (disk);
} }
} }
@@ -366,7 +427,7 @@ public class DiskFactory
} }
if (debug) if (debug)
System.out.println ("Not a Prodos hard disk\n"); System.out.println (" not a Prodos hard disk\n");
return null; return null;
} }
@@ -494,7 +555,11 @@ public class DiskFactory
System.out.println ("Checking Infocom disk"); System.out.println ("Checking Infocom disk");
if (InfocomDisk.isCorrectFormat (disk)) if (InfocomDisk.isCorrectFormat (disk))
{
if (debug)
System.out.println (" --> INFOCOM");
return new InfocomDisk (disk); return new InfocomDisk (disk);
}
if (debug) if (debug)
System.out.println ("Not an InfocomDisk disk"); System.out.println ("Not an InfocomDisk disk");

View File

@@ -137,7 +137,8 @@ class Cell extends AbstractValue implements Comparable<Cell>
switch (cellType) switch (cellType)
{ {
case LABEL: case LABEL:
if (fmtChar == ' ') // if (fmtChar == ' ' || fmtChar == 'I' || fmtChar == '$')
if (fmtChar != 'R')
fmtChar = 'L'; fmtChar = 'L';
return Format.justify (label, colWidth, fmtChar); return Format.justify (label, colWidth, fmtChar);

View File

@@ -2,7 +2,9 @@ package com.bytezone.diskbrowser.visicalc;
public class Format public class Format
{ {
// private static final DecimalFormat nf = new DecimalFormat ("#####0.00"); private static final String OVERFLOW = ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
private static final String HISTOGRAM = "***********************************";
private static final String UNKNOWN = "???????????????????????????????????";
private Format () private Format ()
{ {
@@ -19,8 +21,8 @@ public class Format
{ {
case 'L': case 'L':
case 'R': case 'R':
case 'G':
case ' ': case ' ':
// this could be improved
String numberFormat = String.format ("%%%d.7f", colWidth + 8); String numberFormat = String.format ("%%%d.7f", colWidth + 8);
String val = String.format (numberFormat, actualValue); String val = String.format (numberFormat, actualValue);
@@ -33,11 +35,8 @@ public class Format
val = val.substring (1); val = val.substring (1);
if (val.length () > colWidth && val.indexOf ('.') >= 0) if (val.length () > colWidth && val.indexOf ('.') >= 0)
{
val = val.substring (0, colWidth); val = val.substring (0, colWidth);
}
// System.out.printf ("len:%d fmt: %s%n", val.length (), formatChar);
if (formatChar == 'L') if (formatChar == 'L')
{ {
String leftFormat = String.format ("%%-%ds", colWidth); String leftFormat = String.format ("%%-%ds", colWidth);
@@ -50,36 +49,33 @@ public class Format
} }
if (val.length () > colWidth) if (val.length () > colWidth)
return ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>".substring (0, colWidth); return OVERFLOW.substring (0, colWidth);
return val; return val;
case 'I': case 'I':
String integerFormat = String.format ("%%%d.0f", colWidth); String integerFormat = String.format ("%%%dd", colWidth);
String result = String.format (integerFormat, actualValue); String result = String.format (integerFormat, (int) actualValue);
if (result.length () > colWidth) if (result.length () > colWidth)
return ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>".substring (0, colWidth); return OVERFLOW.substring (0, colWidth);
return result; return result;
case '$': case '$':
String currencyFormat = String.format ("%%%d.%df", colWidth + 3, 2); String currencyFormat = String.format ("%%%d.2f", colWidth + 3);
result = String.format (currencyFormat, actualValue).trim (); result = String.format (currencyFormat, actualValue).trim ();
String rightFormat = String.format ("%%%ds", colWidth); String rightFormat = String.format ("%%%ds", colWidth);
val = String.format (rightFormat, result); val = String.format (rightFormat, result);
// System.out.println (result);
// System.out.println (val);
if (result.length () > colWidth) if (result.length () > colWidth)
return ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>".substring (0, colWidth); return OVERFLOW.substring (0, colWidth);
return val; return val;
case '*': case '*':
String graphFormat = String.format ("%%-%d.%ds", colWidth, colWidth); String graphFormat = String.format ("%%-%d.%ds", colWidth, colWidth);
// this is not finished return String.format (graphFormat, HISTOGRAM.substring (0, (int) actualValue));
return String.format (graphFormat, "********************");
default: default:
System.out.printf ("[%s]%n", formatChar); System.out.printf ("[%s]%n", formatChar);
return "??????????????????????".substring (0, colWidth); return UNKNOWN.substring (0, colWidth);
} }
} }

View File

@@ -165,11 +165,8 @@ public class Sheet
} }
// might have to keep recalculating until nothing changes?? // might have to keep recalculating until nothing changes??
if (recalculation == 'A') // auto calculate (recalculationOrder);
{ calculate (recalculationOrder);
calculate (recalculationOrder);
calculate (recalculationOrder);
}
} }
private void calculate (char order) private void calculate (char order)
@@ -363,16 +360,16 @@ public class Sheet
heading.append (String.format (fmt, underline)); heading.append (String.format (fmt, underline));
} }
text.append (String.format ("Global format : %s%n", globalFormat)); text.append (String.format ("Global format : %s%n", globalFormat));
text.append (String.format ("Column width : %d%n", columnWidth)); text.append (String.format ("Column width : %d%n", columnWidth));
text.append (String.format ("Recalculation order : %s%n", text.append (String.format ("Recalc order : %s%n",
recalculationOrder == 'R' ? "Row" : "Column")); recalculationOrder == 'R' ? "Row" : "Column"));
text.append (String.format ("Recalculation : %s%n", text.append (String.format ("Recalculation : %s%n",
recalculation == 'A' ? "Automatic" : "Manual")); recalculation == 'A' ? "Automatic" : "Manual"));
text.append (String.format ("Cells : %d%n", size ())); text.append (String.format ("Cells : %d%n", size ()));
if (size () > 0) if (size () > 0)
text.append (String.format ("Range : %s:%s%n%n", text.append (String.format ("Range : %s:%s%n%n",
Address.getCellName (minRow + 1, minColumn), Address.getCellName (minRow + 1, minColumn),
Address.getCellName (maxRow + 1, maxColumn))); Address.getCellName (maxRow + 1, maxColumn)));
else else