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;
// insert spaces before '=' until it lines up with the other assignment lines
while (alignEqualsPos-- > equalsPosition)
line.insert (equalsPosition, ' ');
while (alignEqualsPos-- > subline.equalsPosition)
line.insert (subline.equalsPosition, ' ');
if (line.charAt (line.length () - 1) == ':')
while (targetLength++ <= targetLength)
while (targetLength++ <= this.targetLength)
line.append (" ");
return line.toString ();
}
// ---------------------------------------------------------------------------------//
private StringBuilder toStringBuilder (SubLine subline)
static StringBuilder toStringBuilder (SubLine subline)
// ---------------------------------------------------------------------------------//
{
StringBuilder line = new StringBuilder ();
@ -103,4 +103,21 @@ class Alignment implements ApplesoftConstants
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)
if (buffer[p] == TOKEN_EQUALS)
{
String expandedLine = toString ();
// String expandedLine = toString ();
String expandedLine = Alignment.toStringBuilder (this).toString ();
equalsPosition = expandedLine.indexOf ('=');
endPosition = expandedLine.length ();
if (expandedLine.endsWith (":"))

View File

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

View File

@ -24,6 +24,9 @@ public class Prefix2mg
int creatorOffset;
int creatorLength;
boolean flagsLocked;
int flagsVolume;
// ---------------------------------------------------------------------------------//
public Prefix2mg (byte[] buffer)
// ---------------------------------------------------------------------------------//
@ -42,6 +45,12 @@ public class Prefix2mg
creatorOffset = Utility.getLong (buffer, 0x28);
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
System.out.println (this);
}
@ -59,6 +68,8 @@ public class Prefix2mg
text.append (String.format ("Version : %d%n", version));
text.append (String.format ("Format : %02X%n", format));
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 ("Offset : %,d%n", offset));
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
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;
}
int catalogBlockNo = createPath (subdirectories);
// check that the file doesn't already exist
Optional<FileEntry> fileEntryOpt = searchDirectory (catalogBlockNo, fileName);
@ -176,7 +163,7 @@ public class ProdosDisk
}
// create a file entry in the current catalog block
fileEntry = findFreeSlot (catalogBlockNo);
FileEntry fileEntry = findFreeSlot (catalogBlockNo);
if (fileEntry != null)
{
@ -204,6 +191,30 @@ public class ProdosDisk
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)
throws DiskFullException

View File

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

View File

@ -453,6 +453,9 @@ public class Utility
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++)
if (buffer[ptr + i] != magic[i])
return false;