mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2024-06-02 12:41:32 +00:00
Don't assume a Pascal disk is in ProDOS order when writing text files.
This commit is contained in:
parent
0f7f950eaa
commit
9c262548b1
|
@ -55,7 +55,7 @@ public class PascalFileEntry implements FileEntry {
|
||||||
private PascalFormatDisk disk;
|
private PascalFormatDisk disk;
|
||||||
private int index = 0;
|
private int index = 0;
|
||||||
private boolean deleted = false;
|
private boolean deleted = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for PascalFileEntry.
|
* Constructor for PascalFileEntry.
|
||||||
*/
|
*/
|
||||||
|
@ -64,7 +64,7 @@ public class PascalFileEntry implements FileEntry {
|
||||||
this.fileEntry = fileEntry;
|
this.fileEntry = fileEntry;
|
||||||
this.disk = disk;
|
this.disk = disk;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the block number of the file's 1st block.
|
* Get the block number of the file's 1st block.
|
||||||
*/
|
*/
|
||||||
|
@ -92,7 +92,7 @@ public class PascalFileEntry implements FileEntry {
|
||||||
public void setLastBlock(int last) {
|
public void setLastBlock(int last) {
|
||||||
AppleUtil.setWordValue(fileEntry, 2, last);
|
AppleUtil.setWordValue(fileEntry, 2, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the name of this file.
|
* Return the name of this file.
|
||||||
*/
|
*/
|
||||||
|
@ -106,7 +106,7 @@ public class PascalFileEntry implements FileEntry {
|
||||||
public void setFilename(String filename) {
|
public void setFilename(String filename) {
|
||||||
AppleUtil.setPascalString(fileEntry, 6, filename.toUpperCase(), 15);
|
AppleUtil.setPascalString(fileEntry, 6, filename.toUpperCase(), 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the maximum filename length.
|
* Return the maximum filename length.
|
||||||
*/
|
*/
|
||||||
|
@ -148,7 +148,7 @@ public class PascalFileEntry implements FileEntry {
|
||||||
AppleUtil.setWordValue(fileEntry, 4, 0);
|
AppleUtil.setWordValue(fileEntry, 4, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Identify if this file is locked
|
* Identify if this file is locked
|
||||||
*/
|
*/
|
||||||
|
@ -162,21 +162,21 @@ public class PascalFileEntry implements FileEntry {
|
||||||
public void setLocked(boolean lock) {
|
public void setLocked(boolean lock) {
|
||||||
// Not applicable to UCSD file system
|
// Not applicable to UCSD file system
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of bytes used in files last block.
|
* Get the number of bytes used in files last block.
|
||||||
*/
|
*/
|
||||||
public int getBytesUsedInLastBlock() {
|
public int getBytesUsedInLastBlock() {
|
||||||
return AppleUtil.getWordValue(fileEntry, 22);
|
return AppleUtil.getWordValue(fileEntry, 22);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the number of bytes used in files last block.
|
* Set the number of bytes used in files last block.
|
||||||
*/
|
*/
|
||||||
public void setBytesUsedInLastBlock(int value) {
|
public void setBytesUsedInLastBlock(int value) {
|
||||||
AppleUtil.setWordValue(fileEntry, 22, value);
|
AppleUtil.setWordValue(fileEntry, 22, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compute the size of this file (in bytes).
|
* Compute the size of this file (in bytes).
|
||||||
*/
|
*/
|
||||||
|
@ -184,21 +184,21 @@ public class PascalFileEntry implements FileEntry {
|
||||||
int blocks = getBlocksUsed() - 1;
|
int blocks = getBlocksUsed() - 1;
|
||||||
return blocks*Disk.BLOCK_SIZE + getBytesUsedInLastBlock();
|
return blocks*Disk.BLOCK_SIZE + getBytesUsedInLastBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compute the blocks used.
|
* Compute the blocks used.
|
||||||
*/
|
*/
|
||||||
public int getBlocksUsed() {
|
public int getBlocksUsed() {
|
||||||
return AppleUtil.getWordValue(fileEntry, 2) - AppleUtil.getWordValue(fileEntry, 0);
|
return AppleUtil.getWordValue(fileEntry, 2) - AppleUtil.getWordValue(fileEntry, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pascal does not support directories.
|
* Pascal does not support directories.
|
||||||
*/
|
*/
|
||||||
public boolean isDirectory() {
|
public boolean isDirectory() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the list of files in this directory.
|
* Retrieve the list of files in this directory.
|
||||||
* Always returns null, as Pascal does not support directories.
|
* Always returns null, as Pascal does not support directories.
|
||||||
|
@ -206,7 +206,7 @@ public class PascalFileEntry implements FileEntry {
|
||||||
public List getFiles() {
|
public List getFiles() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pascal file entries are removed upon deletion,
|
* Pascal file entries are removed upon deletion,
|
||||||
* so a file entry need not be marked as deleted.
|
* so a file entry need not be marked as deleted.
|
||||||
|
@ -241,7 +241,7 @@ public class PascalFileEntry implements FileEntry {
|
||||||
deleted = true;
|
deleted = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the file modification date.
|
* Get the file modification date.
|
||||||
*/
|
*/
|
||||||
|
@ -383,23 +383,46 @@ public class PascalFileEntry implements FileEntry {
|
||||||
int last = getLastBlock();
|
int last = getLastBlock();
|
||||||
if (fileEntry[4] == 3) { // text
|
if (fileEntry[4] == 3) { // text
|
||||||
data = filterText(data);
|
data = filterText(data);
|
||||||
byte[] buf = new byte[1024];
|
byte[] buf1 = new byte[512];
|
||||||
|
byte[] buf2 = new byte[512];
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int pages = 0;
|
int pages = 0;
|
||||||
disk.writeBlock(first, buf); pages++;
|
disk.writeBlock(first, buf1);
|
||||||
|
disk.writeBlock(first+1,buf2);
|
||||||
|
pages++;
|
||||||
while (offset + 1023 < data.length) {
|
while (offset + 1023 < data.length) {
|
||||||
if ((pages * 2) > (last - first - 2)) {
|
if ((pages * 2) > (last - first - 2)) {
|
||||||
storageError(textBundle.get("PascalFileEntry.NotEnoughRoom")); //$NON-NLS-1$
|
storageError(textBundle.get("PascalFileEntry.NotEnoughRoom")); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
int crPtr = findEOL(data, offset);
|
int crPtr = findEOL(data, offset);
|
||||||
System.arraycopy(data, offset, buf, 0, crPtr - offset + 1);
|
System.arraycopy(data, offset, buf1, 0, crPtr - offset + 1 - 512);
|
||||||
disk.writeBlock(first + pages * 2, buf); pages++;
|
System.arraycopy(data, offset+512, buf2, 0, crPtr - offset + 1 - 512);
|
||||||
Arrays.fill(buf, (byte) 0);
|
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;
|
offset = crPtr + 1;
|
||||||
}
|
}
|
||||||
if (offset < data.length) {
|
if (offset < data.length) {
|
||||||
System.arraycopy(data, offset, buf, 0, data.length - offset);
|
int len1 = data.length - offset;
|
||||||
disk.writeBlock(first + pages * 2, buf); pages++;
|
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);
|
setLastBlock(first + pages * 2);
|
||||||
setBytesUsedInLastBlock(512);
|
setBytesUsedInLastBlock(512);
|
||||||
|
@ -432,7 +455,7 @@ public class PascalFileEntry implements FileEntry {
|
||||||
disk.putDirectory(dir);
|
disk.putDirectory(dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the suggested FileFilter. This appears to be operating system
|
* Get the suggested FileFilter. This appears to be operating system
|
||||||
* specific, so each operating system needs to implement some manner
|
* specific, so each operating system needs to implement some manner
|
||||||
|
@ -478,7 +501,7 @@ public class PascalFileEntry implements FileEntry {
|
||||||
public boolean needsAddress() {
|
public boolean needsAddress() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the address that this file loads at.
|
* Set the address that this file loads at.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user