/* * AppleCommander - An Apple ][ image utility. * Copyright (C) 2003 by Robert Greene * robgreene at users.sourceforge.net * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package com.webcodepro.applecommander.storage.os.cpm; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.StringTokenizer; import com.webcodepro.applecommander.storage.DirectoryEntry; import com.webcodepro.applecommander.storage.DiskFullException; import com.webcodepro.applecommander.storage.FileEntry; import com.webcodepro.applecommander.storage.FormattedDisk; import com.webcodepro.applecommander.storage.StorageBundle; import com.webcodepro.applecommander.storage.physical.ImageOrder; import com.webcodepro.applecommander.util.AppleUtil; import com.webcodepro.applecommander.util.TextBundle; /** * Manages a disk that is in the Apple CP/M format. *
* @author Rob Greene
*/
public class CpmFormatDisk extends FormattedDisk {
private TextBundle textBundle = StorageBundle.getInstance();
/**
* The size of the CP/M sector. Assumed to be 128.
*/
public static final int CPM_SECTORSIZE = 128;
/**
* The size of a CP/M block. Assumed to be 1K.
*/
public static final int CPM_BLOCKSIZE = 1024;
/**
* The number of CP/M sectors per CP/M block.
*/
public static final int CPM_SECTORS_PER_CPM_BLOCK =
CPM_BLOCKSIZE / CPM_SECTORSIZE;
/**
* The number of CP/M blocks per physical track.
*/
public static final int CPM_BLOCKS_PER_TRACK = 4;
/**
* The number of physical sectors per CP/M block.
*/
public static final int PHYSICAL_SECTORS_PER_BLOCK = 4;
/**
* The track number which CP/M block #0 resides at.
* (The other tracks are boot-related and not available.)
*/
public static final int PHYSICAL_BLOCK_TRACK_START = 3;
/**
* The sector skew of the CP/M disk image.
*/
public static final int[] sectorSkew = {
0x0, 0x6, 0xc, 0x3, 0x9, 0xf, 0xe, 0x5,
0xb, 0x2, 0x8, 0x7, 0xd, 0x4, 0xa, 0x1 };
/**
* Manage CP/M disk usage.
*/
public class CpmDiskUsage implements DiskUsage {
int block = -1;
boolean[] usage = null;
public CpmDiskUsage(boolean[] usage) {
this.usage = usage;
}
public boolean hasNext() {
return block < usage.length-1;
}
public void next() {
block++;
}
public boolean isFree() {
return !isUsed();
}
public boolean isUsed() {
return usage[block];
}
}
/**
* Construct a CP/M formatted disk.
*/
public CpmFormatDisk(String filename, ImageOrder imageOrder) {
super(filename, imageOrder);
}
/**
* Create a CpmFormatDisk. All CP/M disk images are expected to
* be 140K in size.
*/
public static CpmFormatDisk[] create(String filename, ImageOrder imageOrder) {
CpmFormatDisk disk = new CpmFormatDisk(filename, imageOrder);
disk.format();
return new CpmFormatDisk[] { disk };
}
/**
* There apparantly is no corresponding CP/M disk name.
* @see com.webcodepro.applecommander.storage.FormattedDisk#getDiskName()
*/
public String getDiskName() {
return textBundle.get("CpmFormatDisk.DiskName"); //$NON-NLS-1$
}
/**
* Identify the operating system format of this disk.
* @see com.webcodepro.applecommander.storage.FormattedDisk#getFormat()
*/
public String getFormat() {
return textBundle.get("CpmFormatDisk.Cpm"); //$NON-NLS-1$
}
/**
* Return the amount of free space in bytes.
* @see com.webcodepro.applecommander.storage.FormattedDisk#getFreeSpace()
*/
public int getFreeSpace() {
return getPhysicalSize() - getUsedSpace();
}
/**
* Return the amount of used space in bytes.
* @see com.webcodepro.applecommander.storage.FormattedDisk#getUsedSpace()
*/
public int getUsedSpace() {
int blocksUsed = getBlocksUsed();
return blocksUsed * CPM_BLOCKSIZE +
PHYSICAL_BLOCK_TRACK_START * CPM_BLOCKS_PER_TRACK * CPM_BLOCKSIZE;
}
/**
* Compute the number of CP/M blocks that are currently used.
*/
public int getBlocksUsed() {
List files = getFiles();
int blocksUsed = 0;
for (int i=0; i
* Note: Assumes that this is a 140K CP/M disk of 35 tracks and
* 16 physical sectors.
* @see com.webcodepro.applecommander.storage.FormattedDisk#format()
*/
public void format() {
getImageOrder().format();
byte[] sectorData = new byte[SECTOR_SIZE];
for (int i=0; i