align text records

This commit is contained in:
Denis Molony 2017-07-09 19:26:13 +10:00
parent 030121f12c
commit d97ba0393b
3 changed files with 41 additions and 32 deletions

View File

@ -248,7 +248,7 @@ public class IntegerBasicProgram extends AbstractFile
}
/*
* To find integer basic in memory:
* $CA $CB contain the starting address
* $CA $CB contain the starting address ($9464)
* http://www.easy68k.com/paulrsm/6502/INTLST.TXT
*/

View File

@ -5,39 +5,44 @@ import com.bytezone.diskbrowser.utilities.HexFormatter;
// only used by Prodos text files - note the fixed block size of 512 - bad!
public class TextBuffer
{
public final byte[] buffer;
public final int reclen;
public final int firstRecNo;
public final byte[] buffer;
public final int reclen;
public final int firstRecNo;
public TextBuffer (byte[] tempBuffer, int reclen, int firstBlock)
{
this.reclen = reclen;
public TextBuffer (byte[] tempBuffer, int reclen, int firstBlock)
{
this.reclen = reclen;
// calculate recNo of first full record
int firstByte = firstBlock * 512; // logical byte #
int rem = firstByte % reclen;
firstRecNo = firstByte / reclen + (rem > 0 ? 1 : 0);
int offset = (rem > 0) ? reclen - rem : 0;
// calculate recNo of first full record
int firstByte = firstBlock * 512; // logical byte #
int rem = firstByte % reclen;
firstRecNo = firstByte / reclen + (rem > 0 ? 1 : 0);
int offset = (rem > 0) ? reclen - rem : 0;
int availableBytes = tempBuffer.length - offset;
int totalRecords = (availableBytes - 1) / reclen + 1;
int availableBytes = tempBuffer.length - offset;
int totalRecords = (availableBytes - 1) / reclen + 1;
// should check whether the two buffers are identical, and maybe skip this
// step
buffer = new byte[totalRecords * reclen];
int copyBytes = Math.min (availableBytes, buffer.length);
System.arraycopy (tempBuffer, offset, buffer, 0, copyBytes);
}
// should check whether the two buffers are identical, and maybe skip this
// step
buffer = new byte[totalRecords * reclen];
int copyBytes = Math.min (availableBytes, buffer.length);
@Override
public String toString ()
{
StringBuilder text = new StringBuilder ();
if (copyBytes < 0)
System.out.printf ("offset %d len %d copy %d%n", offset, buffer.length,
copyBytes);
else
System.arraycopy (tempBuffer, offset, buffer, 0, copyBytes);
}
text.append ("Record length : " + reclen + "\n");
text.append ("First record : " + firstRecNo + "\n\n");
text.append (HexFormatter.format (buffer, 0, buffer.length) + "\n");
@Override
public String toString ()
{
StringBuilder text = new StringBuilder ();
return text.toString ();
}
text.append ("Record length : " + reclen + "\n");
text.append ("First record : " + firstRecNo + "\n\n");
text.append (HexFormatter.format (buffer, 0, buffer.length) + "\n");
return text.toString ();
}
}

View File

@ -88,7 +88,7 @@ public class TextFile extends AbstractFile
for (TextBuffer tb : buffers)
{
buffer = tb.buffer;
knownLength (text, tb.firstRecNo);
text = knownLength (text, tb.firstRecNo);
}
return text.toString ();
}
@ -102,6 +102,7 @@ public class TextFile extends AbstractFile
recNo++;
continue;
}
int len = buffer.length - ptr;
int bytes = len < recordLength ? len : recordLength;
@ -111,9 +112,12 @@ public class TextFile extends AbstractFile
if ((buffer[ptr + bytes - 1] & 0x7F) == 0x0D) // ignore CR
bytes--;
text.append (String.format ("%,10d %,8d %s%n", recNo * recordLength, recNo++,
HexFormatter.getString (buffer, ptr, bytes)));
String line = HexFormatter.getString (buffer, ptr, bytes);
line = line.replaceAll ("\\n", "\n ");
text.append (
String.format ("%,10d %,8d %s%n", recNo * recordLength, recNo++, line));
}
return text;
}