applesoft alignment bug

This commit is contained in:
Denis Molony 2021-05-06 08:12:46 +10:00
parent 7ec277e0a3
commit c3ee00673d
7 changed files with 71 additions and 27 deletions

View File

@ -59,18 +59,18 @@ class Alignment implements ApplesoftConstants
int targetLength = subline.endPosition - equalsPosition; int targetLength = subline.endPosition - equalsPosition;
// insert spaces before '=' until it lines up with the other assignment lines // insert spaces before '=' until it lines up with the other assignment lines
while (alignEqualsPos-- > equalsPosition) while (alignEqualsPos-- > subline.equalsPosition)
line.insert (equalsPosition, ' '); line.insert (subline.equalsPosition, ' ');
if (line.charAt (line.length () - 1) == ':') if (line.charAt (line.length () - 1) == ':')
while (targetLength++ <= targetLength) while (targetLength++ <= this.targetLength)
line.append (" "); line.append (" ");
return line.toString (); return line.toString ();
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
private StringBuilder toStringBuilder (SubLine subline) static StringBuilder toStringBuilder (SubLine subline)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
StringBuilder line = new StringBuilder (); StringBuilder line = new StringBuilder ();
@ -103,4 +103,21 @@ class Alignment implements ApplesoftConstants
return line; return line;
} }
// ---------------------------------------------------------------------------------//
@Override
public String toString ()
// ---------------------------------------------------------------------------------//
{
StringBuilder text = new StringBuilder ();
text.append (String.format ("Equals position ..... %d%n", equalsPosition));
text.append (String.format ("Target length ....... %d%n", targetLength));
text.append (
String.format ("First subline ....... %s%n", toStringBuilder (firstSubLine)));
text.append (
String.format ("Last subline ........ %s", toStringBuilder (lastSubLine)));
return text.toString ();
}
} }

View File

@ -465,7 +465,8 @@ public class SubLine implements ApplesoftConstants
while (++p < max) while (++p < max)
if (buffer[p] == TOKEN_EQUALS) if (buffer[p] == TOKEN_EQUALS)
{ {
String expandedLine = toString (); // String expandedLine = toString ();
String expandedLine = Alignment.toStringBuilder (this).toString ();
equalsPosition = expandedLine.indexOf ('='); equalsPosition = expandedLine.indexOf ('=');
endPosition = expandedLine.length (); endPosition = expandedLine.length ();
if (expandedLine.endsWith (":")) if (expandedLine.endsWith (":"))

View File

@ -258,6 +258,7 @@ public class UserBasicFormatter extends BasicFormatter
.size (); i++) .size (); i++)
{ {
boolean precededByIf = false; boolean precededByIf = false;
for (SubLine subline : sourceLines.get (i).sublines) for (SubLine subline : sourceLines.get (i).sublines)
{ {
if (started) if (started)

View File

@ -24,6 +24,9 @@ public class Prefix2mg
int creatorOffset; int creatorOffset;
int creatorLength; int creatorLength;
boolean flagsLocked;
int flagsVolume;
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
public Prefix2mg (byte[] buffer) public Prefix2mg (byte[] buffer)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
@ -42,6 +45,12 @@ public class Prefix2mg
creatorOffset = Utility.getLong (buffer, 0x28); creatorOffset = Utility.getLong (buffer, 0x28);
creatorLength = Utility.getLong (buffer, 0x2C); creatorLength = Utility.getLong (buffer, 0x2C);
flagsLocked = (flags & 0x80000000) != 0;
if ((flags & 0x0100) != 0)
flagsVolume = flags & 0xFF;
if (format == 0 && flagsVolume == 0)
flagsVolume = 254;
// see /Asimov disks/images/gs/os/prodos16/ProDOS 16v1_3.2mg // see /Asimov disks/images/gs/os/prodos16/ProDOS 16v1_3.2mg
System.out.println (this); System.out.println (this);
} }
@ -59,6 +68,8 @@ public class Prefix2mg
text.append (String.format ("Version : %d%n", version)); text.append (String.format ("Version : %d%n", version));
text.append (String.format ("Format : %02X%n", format)); text.append (String.format ("Format : %02X%n", format));
text.append (String.format ("Flags : %,d%n", flags)); text.append (String.format ("Flags : %,d%n", flags));
text.append (String.format ("Locked : %s%n", flagsLocked));
text.append (String.format ("DOS Volume : %,d%n", flagsVolume));
text.append (String.format ("Blocks : %,d%n", blocks)); text.append (String.format ("Blocks : %,d%n", blocks));
text.append (String.format ("Offset : %,d%n", offset)); text.append (String.format ("Offset : %,d%n", offset));
text.append (String.format ("Length : %08X (%<,d)%n", length)); text.append (String.format ("Length : %08X (%<,d)%n", length));

View File

@ -151,20 +151,7 @@ public class ProdosDisk
} }
// search for each subdirectory, create any that don't exist // search for each subdirectory, create any that don't exist
int catalogBlockNo = 2; int catalogBlockNo = createPath (subdirectories);
FileEntry fileEntry = null;
for (int i = 0; i < subdirectories.length; i++)
{
Optional<FileEntry> fileEntryOpt =
searchDirectory (catalogBlockNo, subdirectories[i]);
if (fileEntryOpt.isEmpty ())
fileEntry = createSubdirectory (catalogBlockNo, subdirectories[i]);
else
fileEntry = fileEntryOpt.get ();
catalogBlockNo = fileEntry.keyPointer;
}
// check that the file doesn't already exist // check that the file doesn't already exist
Optional<FileEntry> fileEntryOpt = searchDirectory (catalogBlockNo, fileName); Optional<FileEntry> fileEntryOpt = searchDirectory (catalogBlockNo, fileName);
@ -176,7 +163,7 @@ public class ProdosDisk
} }
// create a file entry in the current catalog block // create a file entry in the current catalog block
fileEntry = findFreeSlot (catalogBlockNo); FileEntry fileEntry = findFreeSlot (catalogBlockNo);
if (fileEntry != null) if (fileEntry != null)
{ {
@ -204,6 +191,30 @@ public class ProdosDisk
return fileEntry; return fileEntry;
} }
// ---------------------------------------------------------------------------------//
private int createPath (String[] subdirectories)
throws DiskFullException, VolumeCatalogFullException
// ---------------------------------------------------------------------------------//
{
// search for each subdirectory, create any that don't exist
int catalogBlockNo = 2;
FileEntry fileEntry = null;
for (int i = 0; i < subdirectories.length; i++)
{
Optional<FileEntry> fileEntryOpt =
searchDirectory (catalogBlockNo, subdirectories[i]);
if (fileEntryOpt.isEmpty ())
fileEntry = createSubdirectory (catalogBlockNo, subdirectories[i]);
else
fileEntry = fileEntryOpt.get ();
catalogBlockNo = fileEntry.keyPointer;
}
return catalogBlockNo;
}
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
public void addResourceFork (FileEntry fileEntry, byte[] fileBuffer, int eof) public void addResourceFork (FileEntry fileEntry, byte[] fileBuffer, int eof)
throws DiskFullException throws DiskFullException

View File

@ -29,13 +29,13 @@ class MasterHeader
{ {
if (Utility.isMagic (buffer, ptr, NuFile)) if (Utility.isMagic (buffer, ptr, NuFile))
break; break;
if (Utility.isMagic (buffer, 0x2000, NuFile)) // if (Utility.isMagic (buffer, 0x2000, NuFile))
{ // {
System.out.println ("found it"); // System.out.println ("found it");
ptr = 0x2000; // ptr = 0x2000;
bin2 = true; // bin2 = true;
break; // break;
} // }
if (isBin2 (buffer, ptr)) if (isBin2 (buffer, ptr))
{ {

View File

@ -453,6 +453,9 @@ public class Utility
static boolean isMagic (byte[] buffer, int ptr, byte[] magic) static boolean isMagic (byte[] buffer, int ptr, byte[] magic)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
if (ptr + magic.length >= buffer.length)
return false;
for (int i = 0; i < magic.length; i++) for (int i = 0; i < magic.length; i++)
if (buffer[ptr + i] != magic[i]) if (buffer[ptr + i] != magic[i])
return false; return false;