Further expansion of CP/M disk support.

This commit is contained in:
Robert Greene 2003-12-22 07:12:58 +00:00
parent 01a1917d15
commit d1f9e3a395
2 changed files with 162 additions and 21 deletions

View File

@ -6,6 +6,8 @@ import com.webcodepro.applecommander.storage.FileFilter;
import com.webcodepro.applecommander.storage.FormattedDisk;
import com.webcodepro.applecommander.util.AppleUtil;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
/**
@ -21,26 +23,34 @@ public class CpmFileEntry implements FileEntry {
*/
private CpmFormatDisk disk;
/**
* The offset into the block that the FileEntry is at.
* The offset(s) into the block that the FileEntry is at.
*/
private int offset;
private List offsets = new ArrayList();
/**
* Construct a CP/M file entry.
*/
public CpmFileEntry(CpmFormatDisk disk, int offset) {
this.disk = disk;
this.offset = offset;
addOffset(offset);
}
/**
* Add another directory offset to this file entry.
*/
public void addOffset(int offset) {
offsets.add(new Integer(offset));
}
/**
* Read the fileEntry bytes from the disk image.
*/
protected byte[] readFileEntry() {
protected byte[] readFileEntry(int number) {
byte[] data = new byte[2048];
System.arraycopy(disk.readCpmBlock(0), 0, data, 0, 1024);
System.arraycopy(disk.readCpmBlock(1), 0, data, 1024, 1024);
byte[] entry = new byte[ENTRY_LENGTH];
int offset = ((Integer)offsets.get(number)).intValue();
System.arraycopy(data, offset, entry, 0, ENTRY_LENGTH);
return entry;
}
@ -50,7 +60,7 @@ public class CpmFileEntry implements FileEntry {
* @see com.webcodepro.applecommander.storage.FileEntry#getFilename()
*/
public String getFilename() {
return AppleUtil.getString(readFileEntry(), 1, 8).trim();
return AppleUtil.getString(readFileEntry(0), 1, 8).trim();
}
/**
@ -66,7 +76,7 @@ public class CpmFileEntry implements FileEntry {
* @see com.webcodepro.applecommander.storage.FileEntry#getFiletype()
*/
public String getFiletype() {
return AppleUtil.getString(readFileEntry(), 9, 3).trim();
return AppleUtil.getString(readFileEntry(0), 9, 3).trim();
}
/**
@ -82,7 +92,31 @@ public class CpmFileEntry implements FileEntry {
* @see com.webcodepro.applecommander.storage.FileEntry#isLocked()
*/
public boolean isLocked() {
return AppleUtil.isBitSet(readFileEntry()[0x9], 8);
return AppleUtil.isBitSet(getFileTypeT1(0), 7);
}
/**
* Read the file type T1 entry. This is the 1st character of the
* file type and the high bit indicates read-only.
*/
public byte getFileTypeT1(int entryNumber) {
return readFileEntry(entryNumber)[0x9];
}
/**
* Read the file type T2 entry. This is the 2nd character of the
* file type and the high bit indicates a system or hidden file.
*/
public byte getFileTypeT2(int entryNumber) {
return readFileEntry(entryNumber)[0xa];
}
/**
* Read the file type T3 entry. This is the 3rd character of the
* file type and the high bit is the backup bit (CP/M 3.1 and later).
*/
public byte getFileTypeT3(int entryNumber) {
return readFileEntry(entryNumber)[0xb];
}
/**
@ -92,13 +126,41 @@ public class CpmFileEntry implements FileEntry {
// TODO Auto-generated method stub
}
/**
* Read the extent number, low byte.
*/
public int getExtentCounterLow(int entryNumber) {
return AppleUtil.getUnsignedByte(readFileEntry(entryNumber)[0xc]);
}
/**
* Compute the size of this file (in bytes).
* @see com.webcodepro.applecommander.storage.FileEntry#getSize()
*/
public int getSize() {
// TODO Auto-generated method stub
return 0;
int entry = -1;
// Locate largest extent number:
for (int i=0; i<offsets.size(); i++) {
if (entry < 0) {
entry = i;
} else {
int currentExtent = getExtentCounterLow(entry);
int thisExtent = getExtentCounterLow(i);
if (thisExtent > currentExtent) entry = i;
}
}
// Compute file size:
return getExtentCounterLow(entry) * 16384 +
getNumberOfRecordsUsed(entry) * 128;
}
/**
* Return the number of records used in this extent, low byte.
* 1 record = 128 bytes.
*/
public int getNumberOfRecordsUsed(int entryNumber) {
return AppleUtil.getUnsignedByte(readFileEntry(entryNumber)[0xf]);
}
/**
@ -114,7 +176,17 @@ public class CpmFileEntry implements FileEntry {
* @see com.webcodepro.applecommander.storage.FileEntry#isDeleted()
*/
public boolean isDeleted() {
return 0xe5 == AppleUtil.getUnsignedByte(readFileEntry()[0]);
return 0xe5 == getUserNumber(0);
}
/**
* Return the user number (UU). 0-15 on Apple CP/M (can range to 31
* on some systems). The user number allows multiple files with the
* same name to coexist on the disk. Apparantly, this is used in
* conjunction with deleted files.
*/
public int getUserNumber(int entryNumber) {
return AppleUtil.getUnsignedByte(readFileEntry(entryNumber)[0x0]);
}
/**
@ -126,11 +198,35 @@ public class CpmFileEntry implements FileEntry {
}
/**
* @see com.webcodepro.applecommander.storage.FileEntry#getFileColumnData(int)
* Get the standard file column header information.
* This default implementation is intended only for standard mode.
* displayMode is specified in FormattedDisk.
*/
public List getFileColumnData(int displayMode) {
// TODO Auto-generated method stub
return null;
NumberFormat numberFormat = NumberFormat.getNumberInstance();
List list = new ArrayList();
switch (displayMode) {
case FormattedDisk.FILE_DISPLAY_NATIVE:
list.add(getFilename());
list.add(getFiletype());
break;
case FormattedDisk.FILE_DISPLAY_DETAIL:
list.add(getFilename());
list.add(getFiletype());
list.add(numberFormat.format(getSize()));
list.add("0x" + AppleUtil.getFormattedByte(getUserNumber(0)));
list.add(isDeleted() ? "Deleted" : "");
list.add(isLocked() ? "Locked" : "");
break;
default: // FILE_DISPLAY_STANDARD
list.add(getFilename());
list.add(getFiletype());
list.add(numberFormat.format(getSize()));
list.add(isLocked() ? "Locked" : "");
break;
}
return list;
}
/**
@ -202,7 +298,7 @@ public class CpmFileEntry implements FileEntry {
* An empty file entry contains all 0xE5.
*/
public boolean isEmpty() {
byte[] data = readFileEntry();
byte[] data = readFileEntry(0);
for (int i=0; i<ENTRY_LENGTH; i++) {
int byt = AppleUtil.getUnsignedByte(data[i]);
if (byt != 0xE5) return false;

View File

@ -25,7 +25,9 @@ import com.webcodepro.applecommander.storage.FormattedDisk;
import com.webcodepro.applecommander.storage.FormattedDisk.DiskUsage;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Manages a disk that is in the Apple CP/M format.
@ -73,19 +75,22 @@ public class CpmFormatDisk extends FormattedDisk {
}
/**
* Get suggested dimensions for display of bitmap.
* Typically, this will be only used for 5.25" floppies.
* This can return null if there is no suggestion.
* @see com.webcodepro.applecommander.storage.FormattedDisk#getBitmapDimensions()
*/
public int[] getBitmapDimensions() {
// TODO Auto-generated method stub
return null;
}
/**
* Get the length of the bitmap.
* This is hard-coded to 128 (0x80).
* @see com.webcodepro.applecommander.storage.FormattedDisk#getBitmapLength()
*/
public int getBitmapLength() {
// TODO Auto-generated method stub
return 0;
return 0x80;
}
/**
@ -206,10 +211,22 @@ public class CpmFormatDisk extends FormattedDisk {
*/
public List getFiles() {
List files = new ArrayList();
Map index = new HashMap();
for (int i=0; i<64; i++) {
CpmFileEntry fileEntry = new CpmFileEntry(this, i*CpmFileEntry.ENTRY_LENGTH);
int offset = i*CpmFileEntry.ENTRY_LENGTH;
CpmFileEntry fileEntry = new CpmFileEntry(this, offset);
if (!fileEntry.isEmpty()) {
files.add(fileEntry);
// Files are unique by name, type, and user number.
String key = fileEntry.getFilename().trim() + "."
+ fileEntry.getFiletype().trim() + ":"
+ fileEntry.getUserNumber(0);
if (index.containsKey(key)) {
fileEntry = (CpmFileEntry) index.get(key);
fileEntry.addOffset(offset);
} else {
files.add(fileEntry);
index.put(key, fileEntry);
}
}
}
return files;
@ -248,14 +265,42 @@ public class CpmFormatDisk extends FormattedDisk {
* One block should be the entire directory...
*/
public byte[] readCpmBlock(int block) {
int[] sectorSkew = { 0x0, 0x6, 0xc, 0x3, 0x9, 0xf, 0xe, 0x5,
0xb, 0x2, 0x8, 0x7, 0xd, 0x4, 0xa, 0x1 };
byte[] data = new byte[1024];
int track = 3 + (block / 4);
int sector = block % 4;
int sector = (block % 4) * 4;
for (int i=0; i<4; i++) {
System.arraycopy(readSector(track, sector+i),
System.arraycopy(readSector(track, sectorSkew[sector+i]),
0, data, i*SECTOR_SIZE, SECTOR_SIZE);
}
return data;
}
/**
* Get the standard file column header information.
* This default implementation is intended only for standard mode.
*/
public List getFileColumnHeaders(int displayMode) {
List list = new ArrayList();
switch (displayMode) {
case FILE_DISPLAY_NATIVE:
list.add(new FileColumnHeader("Name", 8, FileColumnHeader.ALIGN_LEFT));
list.add(new FileColumnHeader("Type", 3, FileColumnHeader.ALIGN_LEFT));
break;
case FILE_DISPLAY_DETAIL:
list.add(new FileColumnHeader("Name", 8, FileColumnHeader.ALIGN_LEFT));
list.add(new FileColumnHeader("Type", 3, FileColumnHeader.ALIGN_LEFT));
list.add(new FileColumnHeader("Size (bytes)", 6, FileColumnHeader.ALIGN_RIGHT));
list.add(new FileColumnHeader("User#", 4, FileColumnHeader.ALIGN_RIGHT));
list.add(new FileColumnHeader("Deleted?", 7, FileColumnHeader.ALIGN_CENTER));
list.add(new FileColumnHeader("Locked?", 6, FileColumnHeader.ALIGN_CENTER));
break;
default: // FILE_DISPLAY_STANDARD
list.addAll(super.getFileColumnHeaders(displayMode));
break;
}
return list;
}
}