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

View File

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

View File

@ -2,7 +2,9 @@ package com.bytezone.diskbrowser.visicalc;
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 ()
{
@ -19,8 +21,8 @@ public class Format
{
case 'L':
case 'R':
case 'G':
case ' ':
// this could be improved
String numberFormat = String.format ("%%%d.7f", colWidth + 8);
String val = String.format (numberFormat, actualValue);
@ -33,11 +35,8 @@ public class Format
val = val.substring (1);
if (val.length () > colWidth && val.indexOf ('.') >= 0)
{
val = val.substring (0, colWidth);
}
// System.out.printf ("len:%d fmt: %s%n", val.length (), formatChar);
if (formatChar == 'L')
{
String leftFormat = String.format ("%%-%ds", colWidth);
@ -50,36 +49,33 @@ public class Format
}
if (val.length () > colWidth)
return ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>".substring (0, colWidth);
return OVERFLOW.substring (0, colWidth);
return val;
case 'I':
String integerFormat = String.format ("%%%d.0f", colWidth);
String result = String.format (integerFormat, actualValue);
String integerFormat = String.format ("%%%dd", colWidth);
String result = String.format (integerFormat, (int) actualValue);
if (result.length () > colWidth)
return ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>".substring (0, colWidth);
return OVERFLOW.substring (0, colWidth);
return result;
case '$':
String currencyFormat = String.format ("%%%d.%df", colWidth + 3, 2);
String currencyFormat = String.format ("%%%d.2f", colWidth + 3);
result = String.format (currencyFormat, actualValue).trim ();
String rightFormat = String.format ("%%%ds", colWidth);
val = String.format (rightFormat, result);
// System.out.println (result);
// System.out.println (val);
if (result.length () > colWidth)
return ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>".substring (0, colWidth);
return OVERFLOW.substring (0, colWidth);
return val;
case '*':
String graphFormat = String.format ("%%-%d.%ds", colWidth, colWidth);
// this is not finished
return String.format (graphFormat, "********************");
return String.format (graphFormat, HISTOGRAM.substring (0, (int) actualValue));
default:
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??
if (recalculation == 'A') // auto
{
calculate (recalculationOrder);
calculate (recalculationOrder);
}
calculate (recalculationOrder);
calculate (recalculationOrder);
}
private void calculate (char order)
@ -363,16 +360,16 @@ public class Sheet
heading.append (String.format (fmt, underline));
}
text.append (String.format ("Global format : %s%n", globalFormat));
text.append (String.format ("Column width : %d%n", columnWidth));
text.append (String.format ("Recalculation order : %s%n",
text.append (String.format ("Global format : %s%n", globalFormat));
text.append (String.format ("Column width : %d%n", columnWidth));
text.append (String.format ("Recalc order : %s%n",
recalculationOrder == 'R' ? "Row" : "Column"));
text.append (String.format ("Recalculation : %s%n",
text.append (String.format ("Recalculation : %s%n",
recalculation == 'A' ? "Automatic" : "Manual"));
text.append (String.format ("Cells : %d%n", size ()));
text.append (String.format ("Cells : %d%n", size ()));
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 (maxRow + 1, maxColumn)));
else