mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-11-26 23:51:57 +00:00
visicalc numeric formats
This commit is contained in:
parent
4865246924
commit
7381d8e66b
@ -22,7 +22,7 @@ import com.bytezone.diskbrowser.wizardry.WizardryScenarioDisk;
|
|||||||
|
|
||||||
public class DiskFactory
|
public class DiskFactory
|
||||||
{
|
{
|
||||||
private static boolean debug = true;
|
private static boolean debug = false;
|
||||||
|
|
||||||
private DiskFactory ()
|
private DiskFactory ()
|
||||||
{
|
{
|
||||||
@ -211,11 +211,15 @@ public class DiskFactory
|
|||||||
|
|
||||||
if (true)
|
if (true)
|
||||||
{
|
{
|
||||||
// if (debug)
|
|
||||||
// System.out.println (" trying checksums");
|
|
||||||
long checksum = appleDisk256.getBootChecksum ();
|
long checksum = appleDisk256.getBootChecksum ();
|
||||||
|
|
||||||
if (checksum == 3176296590L //
|
if (checksum == 227968344L) // empty boot sector
|
||||||
|
{
|
||||||
|
// could be wizardry data, visialc data ...
|
||||||
|
if (debug)
|
||||||
|
System.out.println (" empty sector checksum : " + checksum);
|
||||||
|
}
|
||||||
|
else if (checksum == 3176296590L //
|
||||||
|| checksum == 108825457L //
|
|| checksum == 108825457L //
|
||||||
|| checksum == 1439356606L //
|
|| checksum == 1439356606L //
|
||||||
|| checksum == 1550012074L //
|
|| checksum == 1550012074L //
|
||||||
@ -258,9 +262,7 @@ public class DiskFactory
|
|||||||
else if (checksum == 2803644711L // Apple Pascal disk 0
|
else if (checksum == 2803644711L // Apple Pascal disk 0
|
||||||
|| checksum == 3317783349L //
|
|| checksum == 3317783349L //
|
||||||
|| checksum == 1728863694L // Wizardry_I_boot.dsk
|
|| checksum == 1728863694L // Wizardry_I_boot.dsk
|
||||||
|| checksum == 227968344L // wizardry_I/australia16.dsk
|
|| checksum == 198094178L) //
|
||||||
|| checksum == 198094178L //
|
|
||||||
|| checksum == 227968344L) // lauren.dsk
|
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
System.out.println (" known PASCAL checksum : " + checksum);
|
System.out.println (" known PASCAL checksum : " + checksum);
|
||||||
|
@ -264,12 +264,12 @@ public class DosDisk extends AbstractFormattedDisk
|
|||||||
if (buffer[53] != 16 && buffer[53] != 13) // tracks per sector
|
if (buffer[53] != 16 && buffer[53] != 13) // tracks per sector
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (buffer[49] < -1 || buffer[49] > 1) // direction of next file save
|
// if (buffer[49] < -1 || buffer[49] > 1) // direction of next file save
|
||||||
{
|
// {
|
||||||
System.out.println ("Bad direction : " + buffer[49]);
|
// System.out.println ("Bad direction : " + buffer[49]);
|
||||||
// Visicalc data disk had 0xF8
|
// // Visicalc data disk had 0xF8
|
||||||
// return 0;
|
// // return 0;
|
||||||
}
|
// }
|
||||||
|
|
||||||
int version = buffer[3];
|
int version = buffer[3];
|
||||||
if (version < -1 || version > 4)
|
if (version < -1 || version > 4)
|
||||||
|
@ -173,9 +173,8 @@ class Cell extends AbstractValue implements Comparable<Cell>
|
|||||||
@Override
|
@Override
|
||||||
public ValueType getValueType ()
|
public ValueType getValueType ()
|
||||||
{
|
{
|
||||||
if (cellType == CellType.EMPTY)
|
if (cellType == CellType.EMPTY || cellType == CellType.LABEL
|
||||||
return ValueType.NA;
|
|| cellType == CellType.REPEATING_CHARACTER)
|
||||||
if (cellType == CellType.LABEL || cellType == CellType.REPEATING_CHARACTER)
|
|
||||||
return ValueType.VALUE;
|
return ValueType.VALUE;
|
||||||
|
|
||||||
return value.getValueType ();
|
return value.getValueType ();
|
||||||
|
@ -7,10 +7,4 @@ class Error extends Function
|
|||||||
super (parent, text);
|
super (parent, text);
|
||||||
valueType = ValueType.ERROR;
|
valueType = ValueType.ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getValue ()
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -157,13 +157,13 @@ class Expression extends AbstractValue implements Iterable<Value>
|
|||||||
thisValue.calculate ();
|
thisValue.calculate ();
|
||||||
|
|
||||||
value = 0;
|
value = 0;
|
||||||
if (thisValue.isValueType (ValueType.ERROR))
|
if (!thisValue.isValueType (ValueType.VALUE))
|
||||||
{
|
{
|
||||||
valueType = thisValue.getValueType ();
|
valueType = thisValue.getValueType ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = thisValue.getValue (); // NA returns zero
|
value = thisValue.getValue ();
|
||||||
|
|
||||||
String sign = signs.get (0);
|
String sign = signs.get (0);
|
||||||
if (sign.equals ("(-)"))
|
if (sign.equals ("(-)"))
|
||||||
@ -174,13 +174,13 @@ class Expression extends AbstractValue implements Iterable<Value>
|
|||||||
thisValue = values.get (i);
|
thisValue = values.get (i);
|
||||||
thisValue.calculate ();
|
thisValue.calculate ();
|
||||||
|
|
||||||
if (thisValue.isValueType (ValueType.ERROR))
|
if (!thisValue.isValueType (ValueType.VALUE))
|
||||||
{
|
{
|
||||||
valueType = thisValue.getValueType ();
|
valueType = thisValue.getValueType ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double nextValue = thisValue.getValue (); // NA returns zero
|
double nextValue = thisValue.getValue ();
|
||||||
|
|
||||||
sign = signs.get (i);
|
sign = signs.get (i);
|
||||||
if (sign.equals ("(-)"))
|
if (sign.equals ("(-)"))
|
||||||
|
@ -17,18 +17,33 @@ public class Format
|
|||||||
if (actualValue == -0.0)
|
if (actualValue == -0.0)
|
||||||
actualValue = 0;
|
actualValue = 0;
|
||||||
|
|
||||||
|
String valueText = String.valueOf ((int) actualValue);
|
||||||
|
if (valueText.startsWith ("0"))
|
||||||
|
valueText = valueText.substring (1);
|
||||||
|
int digits = valueText.length ();
|
||||||
|
if (digits > colWidth)
|
||||||
|
return OVERFLOW.substring (0, colWidth);
|
||||||
|
|
||||||
switch (formatChar)
|
switch (formatChar)
|
||||||
{
|
{
|
||||||
case 'L':
|
case 'L':
|
||||||
case 'R':
|
case 'R':
|
||||||
case 'G':
|
case 'G':
|
||||||
case ' ':
|
case ' ':
|
||||||
String numberFormat = String.format ("%%%d.7f", colWidth + 8);
|
int precision = colWidth - (digits + 1);
|
||||||
|
if (digits == 0)
|
||||||
|
precision = colWidth - 1;
|
||||||
|
if (precision < 0)
|
||||||
|
precision = 0;
|
||||||
|
String numberFormat = String.format ("%%%d.%df", colWidth, precision);
|
||||||
String val = String.format (numberFormat, actualValue);
|
String val = String.format (numberFormat, actualValue);
|
||||||
|
// System.out.printf ("%s %2d %2d %s %15.8f %s : ", formatChar, colWidth,
|
||||||
|
// digits, numberFormat, actualValue, val);
|
||||||
|
|
||||||
val = val.trim ();
|
val = val.trim ();
|
||||||
while (val.endsWith ("0"))
|
if (val.indexOf ('.') >= 0)
|
||||||
val = val.substring (0, val.length () - 1);
|
while (val.endsWith ("0"))
|
||||||
|
val = val.substring (0, val.length () - 1);
|
||||||
if (val.endsWith ("."))
|
if (val.endsWith ("."))
|
||||||
val = val.substring (0, val.length () - 1);
|
val = val.substring (0, val.length () - 1);
|
||||||
if (val.startsWith ("0."))
|
if (val.startsWith ("0."))
|
||||||
@ -48,14 +63,16 @@ public class Format
|
|||||||
val = String.format (rightFormat, val);
|
val = String.format (rightFormat, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// System.out.printf ("[%s]%n", val);
|
||||||
|
|
||||||
if (val.length () > colWidth)
|
if (val.length () > colWidth)
|
||||||
return OVERFLOW.substring (0, colWidth);
|
return OVERFLOW.substring (0, colWidth);
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
|
|
||||||
case 'I':
|
case 'I':
|
||||||
String integerFormat = String.format ("%%%dd", colWidth);
|
String integerFormat = String.format ("%%%d.0f", colWidth);
|
||||||
String result = String.format (integerFormat, (int) actualValue);
|
String result = String.format (integerFormat, actualValue);
|
||||||
if (result.length () > colWidth)
|
if (result.length () > colWidth)
|
||||||
return OVERFLOW.substring (0, colWidth);
|
return OVERFLOW.substring (0, colWidth);
|
||||||
return result;
|
return result;
|
||||||
|
@ -2,22 +2,20 @@ package com.bytezone.diskbrowser.visicalc;
|
|||||||
|
|
||||||
class IsError extends Function
|
class IsError extends Function
|
||||||
{
|
{
|
||||||
Cell cell;
|
Value expression;
|
||||||
|
|
||||||
public IsError (Sheet parent, String text)
|
public IsError (Sheet parent, String text)
|
||||||
{
|
{
|
||||||
super (parent, text);
|
super (parent, text);
|
||||||
|
|
||||||
cell = parent.getCell (functionText);
|
expression = new Expression (parent, functionText).reduce ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public void calculate ()
|
||||||
{
|
{
|
||||||
// if (cell == null)
|
expression.calculate ();
|
||||||
// cell = parent.getCell (functionText);
|
value = expression.isValueType (ValueType.ERROR) ? 1 : 0;
|
||||||
|
|
||||||
value = cell == null ? 1 : cell.isValueType (ValueType.ERROR) ? 1 : 0;
|
|
||||||
valueType = ValueType.VALUE;
|
valueType = ValueType.VALUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,11 +14,8 @@ public class IsNa extends Function
|
|||||||
@Override
|
@Override
|
||||||
public void calculate ()
|
public void calculate ()
|
||||||
{
|
{
|
||||||
// if (expression == null)
|
|
||||||
// expression = new Expression (parent, functionText);
|
|
||||||
|
|
||||||
expression.calculate ();
|
expression.calculate ();
|
||||||
value = expression.getValue ();
|
value = expression.isValueType (ValueType.NA) ? 1 : 0;
|
||||||
valueType = expression.getValueType ();
|
valueType = expression.getValueType ();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -30,6 +30,7 @@ class Lookup extends Function
|
|||||||
if (!source.isValueType (ValueType.VALUE))
|
if (!source.isValueType (ValueType.VALUE))
|
||||||
{
|
{
|
||||||
valueType = source.getValueType ();
|
valueType = source.getValueType ();
|
||||||
|
// valueType = ValueType.NA;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,15 +46,23 @@ class Lookup extends Function
|
|||||||
for (Address address : range)
|
for (Address address : range)
|
||||||
{
|
{
|
||||||
Cell cell = parent.getCell (address);
|
Cell cell = parent.getCell (address);
|
||||||
if (cell.isValueType (ValueType.NA))
|
// if (cell.isValueType (ValueType.NA))
|
||||||
continue;
|
// {
|
||||||
|
// // System.out.println ("NA1");
|
||||||
|
// break;
|
||||||
|
// // continue;
|
||||||
|
// }
|
||||||
if (cell.getValue () > sourceValue) // past the value
|
if (cell.getValue () > sourceValue) // past the value
|
||||||
break;
|
break;
|
||||||
target = address;
|
target = address;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target == null)
|
if (target == null)
|
||||||
|
{
|
||||||
valueType = ValueType.NA;
|
valueType = ValueType.NA;
|
||||||
|
// System.out.println ("NA2");
|
||||||
|
value = 0;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Address adjacentAddress =
|
Address adjacentAddress =
|
||||||
|
@ -7,10 +7,4 @@ public class Na extends Function
|
|||||||
super (parent, text);
|
super (parent, text);
|
||||||
valueType = ValueType.NA;
|
valueType = ValueType.NA;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getValue ()
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user