Clean up final-block processing, add some more comments about the Pascal text format
This commit is contained in:
parent
2acb66bc76
commit
e790a01ccf
|
@ -387,10 +387,10 @@ public class PascalFileEntry implements FileEntry {
|
|||
byte[] buf2 = new byte[512];
|
||||
int offset = 0;
|
||||
int pages = 0;
|
||||
disk.writeBlock(first, buf1);
|
||||
disk.writeBlock(first+1,buf2);
|
||||
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 a full page of data (1024 bytes)
|
||||
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$
|
||||
}
|
||||
|
@ -404,28 +404,30 @@ public class PascalFileEntry implements FileEntry {
|
|||
Arrays.fill(buf2, (byte) 0);
|
||||
offset = crPtr + 1;
|
||||
}
|
||||
if (offset < data.length) { // We have less than a page of data left over
|
||||
if (offset < data.length) { // We have less than a full page of data left over
|
||||
int len1 = data.length - offset;
|
||||
int len2 = 0;
|
||||
if (len1 > 512)
|
||||
{ // That final page spans both blocks
|
||||
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.arraycopy(data, offset, buf1, 0, len1);
|
||||
if (len2 > 0)
|
||||
{
|
||||
disk.writeBlock(first + (pages * 2), buf1); // Copy out the first block
|
||||
if (len2 > 0) {
|
||||
System.arraycopy(data, offset+512, buf2, 0, len2);
|
||||
disk.writeBlock(first + (pages * 2) + 1, buf2); // Copy out second block
|
||||
setBytesUsedInLastBlock(len2); // The second block holds the last byte
|
||||
setLastBlock(first + (pages * 2) + 2); // Final block +1... i.e. pages++
|
||||
}
|
||||
disk.writeBlock(first + (pages * 2), buf1); // Copy out the first block
|
||||
if (len2 > 0)
|
||||
{ // Copy out the second block, if needed
|
||||
disk.writeBlock(first + (pages * 2) + 1, buf2);
|
||||
else { // The first block holds the last byte
|
||||
setBytesUsedInLastBlock(len1);
|
||||
setLastBlock(first + pages * 2 + 1); // Final block +1... i.e. pages++ -1
|
||||
}
|
||||
pages++;
|
||||
}
|
||||
setLastBlock(first + pages * 2);
|
||||
setBytesUsedInLastBlock(512);
|
||||
else { // The last page was completely full, so the last byte used in the last block is 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$
|
||||
|
|
Loading…
Reference in New Issue