mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2026-04-25 20:18:05 +00:00
Reengage LastBlock/BytesUsed on full last block; comment what is less obvious
This commit is contained in:
+9
-6
@@ -387,31 +387,34 @@ public class PascalFileEntry implements FileEntry {
|
||||
byte[] buf2 = new byte[512];
|
||||
int offset = 0;
|
||||
int pages = 0;
|
||||
disk.writeBlock(first, buf1); // First two blocks (first page) is ignored by Pascal text
|
||||
disk.writeBlock(first, buf1); // First two blocks (first page) is ignored by Pascal text
|
||||
disk.writeBlock(first+1,buf2); // ...so write a page of zeroes
|
||||
pages++;
|
||||
while (offset + 1023 < data.length) { // We have at least one full page of data (1024 bytes)
|
||||
if ((pages * 2) > (last - first - 2)) {
|
||||
storageError(textBundle.get("PascalFileEntry.NotEnoughRoom")); //$NON-NLS-1$
|
||||
}
|
||||
int crPtr = findEOL(data, offset);
|
||||
int crPtr = findEOL(data, offset); // Copy to last CR & we'll zero-pad to end of page
|
||||
System.arraycopy(data, offset, buf1, 0, 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++;
|
||||
System.out.println("BYTES: " + data.length + "\tCR:" + crPtr + "\tOFFSET:" + offset + "\tPAGES:" +
|
||||
pages);
|
||||
Arrays.fill(buf1, (byte) 0);
|
||||
Arrays.fill(buf2, (byte) 0);
|
||||
offset = crPtr + 1;
|
||||
}
|
||||
if (offset < data.length) { // We have less than a full page of data left over
|
||||
System.out.println("BYTES: " + data.length + "\tOFFSET:" + offset + "\tPAGES:" + pages);
|
||||
int len1 = data.length - offset;
|
||||
int len2 = 0;
|
||||
if (len1 > 512) { // That final page spans both blocks
|
||||
len2 = len1 - 512; // Second block gets the remainder of the partial page length minus 512 bytes
|
||||
len1 = 512; // The first block will write the first 512 bytes
|
||||
}
|
||||
System.out.println("Writing final data block with padding: " + (1024-len1-len2));
|
||||
System.out.println("Writing final data block (" + len1 + ":" + len2 + ") with padding: " + (1024-len1-len2));
|
||||
System.arraycopy(data, offset, buf1, 0, len1);
|
||||
disk.writeBlock(first + (pages * 2), buf1); // Copy out the first block
|
||||
if (len2 > 0) {
|
||||
@@ -422,11 +425,11 @@ public class PascalFileEntry implements FileEntry {
|
||||
setBytesUsedInLastBlock(len2); // The second block holds the last byte
|
||||
setLastBlock(first + (pages * 2) + 2); // Final block +1... i.e. pages++
|
||||
} else { // The last page was completely full, so the last byte used in the last block is 512
|
||||
// FIXME: Verify that we need a fully padded block when finishing on a boundary
|
||||
System.out.println("Text data at page boundary: no padding.");
|
||||
// FIXME: setLastBlock(first + pages * 2);
|
||||
// FIXME: setBytesUsedInLastBlock(512);
|
||||
setLastBlock(first + pages * 2);
|
||||
setBytesUsedInLastBlock(512);
|
||||
}
|
||||
|
||||
} else { // data or code
|
||||
if (data.length > (last - first) * 512) {
|
||||
storageError(textBundle.get("PascalFileEntry.NotEnoughRoom")); //$NON-NLS-1$
|
||||
|
||||
Reference in New Issue
Block a user