Don't assume a Pascal disk is in ProDOS order when writing text files.

This commit is contained in:
2011-10-15 07:10:11 +00:00
parent 0f7f950eaa
commit 9c262548b1

View File

@ -383,23 +383,46 @@ public class PascalFileEntry implements FileEntry {
int last = getLastBlock();
if (fileEntry[4] == 3) { // text
data = filterText(data);
byte[] buf = new byte[1024];
byte[] buf1 = new byte[512];
byte[] buf2 = new byte[512];
int offset = 0;
int pages = 0;
disk.writeBlock(first, buf); pages++;
disk.writeBlock(first, buf1);
disk.writeBlock(first+1,buf2);
pages++;
while (offset + 1023 < data.length) {
if ((pages * 2) > (last - first - 2)) {
storageError(textBundle.get("PascalFileEntry.NotEnoughRoom")); //$NON-NLS-1$
}
int crPtr = findEOL(data, offset);
System.arraycopy(data, offset, buf, 0, crPtr - offset + 1);
disk.writeBlock(first + pages * 2, buf); pages++;
Arrays.fill(buf, (byte) 0);
System.arraycopy(data, offset, buf1, 0, crPtr - offset + 1 - 512);
System.arraycopy(data, offset+512, buf2, 0, crPtr - offset + 1 - 512);
disk.writeBlock(first + (pages * 2), buf1);
disk.writeBlock(first + (pages * 2) + 1, buf2);
pages++;
Arrays.fill(buf1, (byte) 0);
Arrays.fill(buf2, (byte) 0);
offset = crPtr + 1;
}
if (offset < data.length) {
System.arraycopy(data, offset, buf, 0, data.length - offset);
disk.writeBlock(first + pages * 2, buf); pages++;
int len1 = data.length - offset;
int len2 = 0;
if (len1 > 512)
{
len2 = 512 - len1;
len1 = 512;
}
System.arraycopy(data, offset, buf1, 0, len1);
if (len2 > 0)
{
System.arraycopy(data, offset+512, buf2, 0, len2);
}
disk.writeBlock(first + (pages * 2), buf1);
if (len2 > 0)
{
disk.writeBlock(first + (pages * 2) + 1, buf2);
}
pages++;
}
setLastBlock(first + pages * 2);
setBytesUsedInLastBlock(512);