bad length .po file

This commit is contained in:
Denis Molony 2020-01-25 16:34:41 +10:00
parent ea345993f3
commit befdf002f1
5 changed files with 66 additions and 44 deletions

View File

@ -106,7 +106,6 @@ public class AppleDisk implements Disk
byte[] buffer = getPrefix (file); // HDV could be a 2mg byte[] buffer = getPrefix (file); // HDV could be a 2mg
String prefix = new String (buffer, 0, 4); String prefix = new String (buffer, 0, 4);
// int skip = 0;
if (suffix.equalsIgnoreCase ("2mg") || "2IMG".equals (prefix)) if (suffix.equalsIgnoreCase ("2mg") || "2IMG".equals (prefix))
{ {
@ -162,7 +161,8 @@ public class AppleDisk implements Disk
this.trackSize = sectors * sectorSize; this.trackSize = sectors * sectorSize;
} }
} }
else if (suffix.equalsIgnoreCase ("HDV")) else if (suffix.equalsIgnoreCase ("HDV")
|| (suffix.equalsIgnoreCase ("po") && tracks > 50)) // ULTIMATE APPLE1 CFFA 3.5.po
{ {
//this.blocks = (int) file.length () / 4096 * 8; // reduce blocks to a multiple of 8 //this.blocks = (int) file.length () / 4096 * 8; // reduce blocks to a multiple of 8
this.blocks = tracks * sectors; this.blocks = tracks * sectors;

View File

@ -202,7 +202,7 @@ public class DiskFactory
} }
if (debug) if (debug)
System.out.println (" Checking po or dsk hard drive: " + file.length ()); System.out.printf (" Checking po or dsk hard drive: %,d%n", file.length ());
disk = checkHardDisk (file); disk = checkHardDisk (file);
if (disk != null) if (disk != null)
@ -232,7 +232,7 @@ public class DiskFactory
{ {
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 data usk"); System.out.println (" created data disk");
return new DataDisk (appleDisk); return new DataDisk (appleDisk);
} }
catch (FileFormatException e) catch (FileFormatException e)

View File

@ -228,16 +228,16 @@ class CodeManager extends AbstractFile
} }
// try to create a new Routine // try to create a new Routine
Routine r = new Routine (address, header, caller); Routine routine = new Routine (address, header, caller);
if (!r.isValid ()) if (!routine.isValid ())
return null; return null;
// recursively add all routines called by this one // recursively add all routines called by this one
routines.put (address, r); routines.put (address, routine);
for (int ptr : r.calls) for (int ptr : routine.calls)
addRoutine (ptr, address); addRoutine (ptr, address);
return r; return routine;
} }
Routine getRoutine (int address) Routine getRoutine (int address)

View File

@ -17,7 +17,7 @@ class Instruction
enum OperandType enum OperandType
{ {
VAR_SP, VAR_LOCAL, VAR_GLOBAL, BYTE, WORD, ARG_BRANCH, ARG_STRING VAR_SP, VAR_LOCAL, VAR_GLOBAL, BYTE, WORD, ARG_BRANCH, ARG_STRING, OBJECT
} }
static final String[] name2OP = static final String[] name2OP =
@ -142,7 +142,7 @@ class Instruction
{ {
int opcodeNumber; int opcodeNumber;
int opcodeLength; int opcodeLength;
List<Operand> operands; List<Operand> operands = new ArrayList<> ();
int totalOperandLength; int totalOperandLength;
ArgumentBranch branch; ArgumentBranch branch;
ArgumentString string; ArgumentString string;
@ -151,11 +151,6 @@ class Instruction
int jumpTarget; int jumpTarget;
int callTarget; int callTarget;
Opcode ()
{
operands = new ArrayList<Operand> ();
}
@Override @Override
public String toString () public String toString ()
{ {
@ -174,7 +169,7 @@ class Instruction
text.append (op + ", "); text.append (op + ", ");
if (operands.size () > 1) if (operands.size () > 1)
text.delete (text.length () - 2, text.length ()); text.delete (text.length () - 2, text.length ());
text.append (") --> " + store); text.append (") -> " + store);
} }
else else
{ {
@ -183,7 +178,7 @@ class Instruction
if (branch != null) if (branch != null)
text.append (branch); text.append (branch);
if (store != null) if (store != null)
text.append (" --> " + store); text.append (" -> " + store);
if (string != null) if (string != null)
text.append (" \"" + string + "\""); text.append (" \"" + string + "\"");
} }
@ -360,8 +355,17 @@ class Instruction
opcodeNumber = buffer[ptr] & 0x1F; opcodeNumber = buffer[ptr] & 0x1F;
boolean bit1 = ((buffer[ptr] & 0x40) == 0x40); boolean bit1 = ((buffer[ptr] & 0x40) == 0x40);
boolean bit2 = ((buffer[ptr] & 0x20) == 0x20); boolean bit2 = ((buffer[ptr] & 0x20) == 0x20);
addOperand (buffer, ptr + 1, bit1);
addOperand (buffer, ptr + 1, bit2); if (opcodeNumber == 0x0D) // store (variable) value
{
addOperand (buffer, ptr + 1, true); // always a variable
addOperand (buffer, ptr + 1, bit2);
}
else
{
addOperand (buffer, ptr + 1, bit1);
addOperand (buffer, ptr + 1, bit2);
}
setArguments (buffer); setArguments (buffer);
} }
@ -389,11 +393,17 @@ class Instruction
if (opcodeNumber == 0 || opcodeNumber == 7) if (opcodeNumber == 0 || opcodeNumber == 7)
setStore (buffer); setStore (buffer);
if (opcodeNumber == 0) if (opcodeNumber == 0) // call routine
{ {
isCall = true; isCall = true;
callTarget = operands.get (0).value * 2; callTarget = operands.get (0).value * 2;
} }
if (opcodeNumber == 3) // put prop object propertyValue
{
// first parameter is the object id
operands.get (0).operandType = OperandType.OBJECT;
}
} }
@Override @Override
@ -408,6 +418,34 @@ class Instruction
int length; int length;
int value; int value;
OperandType operandType; OperandType operandType;
@Override
public String toString ()
{
switch (operandType)
{
case VAR_SP:
return ("(SP)");
case VAR_LOCAL:
return (String.format ("L%02X", value - 1));
case VAR_GLOBAL:
return String.format ("G%02X", (value - 16));
case BYTE:
return String.format ("#%02X", value);
case WORD:
return String.format ("#%04X", value);
case OBJECT:
return "\"" + header.objectManager.getObject (value - 1).getName () + "\"";
default:
return "*** Illegal ***";
}
}
} }
class OperandWord extends Operand class OperandWord extends Operand
@ -418,12 +456,6 @@ class Instruction
length = 2; length = 2;
operandType = OperandType.WORD; operandType = OperandType.WORD;
} }
@Override
public String toString ()
{
return String.format ("#%04X", value);
}
} }
class OperandByte extends Operand class OperandByte extends Operand
@ -434,12 +466,6 @@ class Instruction
length = 1; length = 1;
operandType = OperandType.BYTE; operandType = OperandType.BYTE;
} }
@Override
public String toString ()
{
return String.format ("#%02X", value);
}
} }
class OperandVariable extends Operand class OperandVariable extends Operand
@ -456,16 +482,6 @@ class Instruction
else else
operandType = OperandType.VAR_GLOBAL; operandType = OperandType.VAR_GLOBAL;
} }
@Override
public String toString ()
{
if (operandType == OperandType.VAR_SP)
return ("(SP)");
if (operandType == OperandType.VAR_LOCAL)
return (String.format ("L%02X", value));
return String.format ("G%02X", (value - 16));
}
} }
class ArgumentBranch extends Operand class ArgumentBranch extends Operand

View File

@ -12,7 +12,13 @@ import javax.swing.tree.DefaultTreeModel;
import com.bytezone.diskbrowser.applefile.AppleFileSource; import com.bytezone.diskbrowser.applefile.AppleFileSource;
import com.bytezone.diskbrowser.applefile.BootSector; import com.bytezone.diskbrowser.applefile.BootSector;
import com.bytezone.diskbrowser.disk.*; import com.bytezone.diskbrowser.disk.AbstractFormattedDisk;
import com.bytezone.diskbrowser.disk.AppleDisk;
import com.bytezone.diskbrowser.disk.DefaultAppleFileSource;
import com.bytezone.diskbrowser.disk.DefaultSector;
import com.bytezone.diskbrowser.disk.Disk;
import com.bytezone.diskbrowser.disk.DiskAddress;
import com.bytezone.diskbrowser.disk.SectorType;
import com.bytezone.diskbrowser.gui.DataSource; import com.bytezone.diskbrowser.gui.DataSource;
import com.bytezone.diskbrowser.gui.ProdosPreferences; import com.bytezone.diskbrowser.gui.ProdosPreferences;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;