display missing woz sectors

This commit is contained in:
Denis Molony 2019-07-31 10:01:49 +10:00
parent e1d1e0408a
commit cb6d56cd55
6 changed files with 77 additions and 18 deletions

View File

@ -15,9 +15,10 @@ import java.util.zip.Checksum;
import com.bytezone.common.Utility;
import com.bytezone.diskbrowser.applefile.AppleFileSource;
import com.bytezone.diskbrowser.nib.WozFile;
import com.bytezone.diskbrowser.nib.NibFile;
import com.bytezone.diskbrowser.nib.V2dFile;
import com.bytezone.diskbrowser.nib.WozFile;
import com.bytezone.diskbrowser.nib.WozFile.Sector;
import com.bytezone.diskbrowser.nib.WozFileOld;
import com.bytezone.diskbrowser.utilities.FileFormatException;
import com.bytezone.diskbrowser.utilities.HexFormatter;
@ -77,6 +78,7 @@ public class AppleDisk implements Disk
// DFB 06,04,02,15 ;12->06,13->04,14->02,15->15
private boolean[] hasData;
private boolean[] isMissing;
private byte emptyByte = 0;
private ActionListener actionListenerList;
@ -194,6 +196,7 @@ public class AppleDisk implements Disk
diskBuffer = new byte[blocks * sectorSize];
hasData = new boolean[blocks];
isMissing = new boolean[blocks];
if (debug)
{
@ -229,6 +232,7 @@ public class AppleDisk implements Disk
sectorSize = trackSize / sectors;
blocks = tracks * sectors;
hasData = new boolean[blocks];
isMissing = new boolean[blocks];
checkSectorsForData ();
}
@ -261,6 +265,7 @@ public class AppleDisk implements Disk
blocks = tracks * sectors;
hasData = new boolean[blocks];
isMissing = new boolean[blocks];
checkSectorsForData ();
}
@ -285,8 +290,12 @@ public class AppleDisk implements Disk
blocks = tracks * sectors;
hasData = new boolean[blocks];
isMissing = new boolean[blocks];
checkSectorsForData ();
for (Sector sector : wozFile.getBadSectors ())
isMissing[sector.trackNo * sectors + sector.sectorNo] = true;
}
private byte[] getPrefix (File path)
@ -411,6 +420,24 @@ public class AppleDisk implements Disk
return !hasData[getDiskAddress (track, sector).getBlock ()];
}
@Override
public boolean isSectorMissing (DiskAddress da)
{
return isMissing[da.getBlock ()];
}
@Override
public boolean isSectorMissing (int block)
{
return isMissing[block];
}
@Override
public boolean isSectorMissing (int track, int sector)
{
return isMissing[getDiskAddress (track, sector).getBlock ()];
}
@Override
public File getFile ()
{
@ -495,9 +522,6 @@ public class AppleDisk implements Disk
@Override
public DiskAddress getDiskAddress (int track, int sector)
{
// track &= 0x3F;
// sector &= 0x1F;
if (!isValidAddress (track, sector))
{
System.out.println ("Invalid block : " + track + "/" + sector);

View File

@ -6,6 +6,7 @@ public class AppleDiskAddress implements DiskAddress
private final int track;
private final int sector;
public final Disk owner;
private boolean zeroFlag;
public AppleDiskAddress (Disk owner, int block)
@ -42,8 +43,6 @@ public class AppleDiskAddress implements DiskAddress
{
if (that == null)
return false;
// if (zeroFlag != ((AppleDiskAddress) that).zeroFlag)
// return false;
return this.block == that.getBlock ();
}

View File

@ -48,6 +48,12 @@ public interface Disk extends Iterable<DiskAddress>
public boolean isSectorEmpty (DiskAddress da);
public boolean isSectorMissing (int block);
public boolean isSectorMissing (int track, int sector);
public boolean isSectorMissing (DiskAddress da);
public boolean isValidAddress (int block);
public boolean isValidAddress (int track, int sector);

View File

@ -235,20 +235,20 @@ public class DiskFactory
try
{
// WozFileOld wozDisk = new WozFileOld (file);
WozFile wozDisk = new WozFile (file);
if (wozDisk.getSectorsPerTrack () == 13)
WozFile wozFile = new WozFile (file);
if (wozFile.getSectorsPerTrack () == 13)
{
AppleDisk appleDisk = new AppleDisk (wozDisk, 35, 13);
AppleDisk appleDisk = new AppleDisk (wozFile, 35, 13);
disk = checkDos (appleDisk);
return disk == null ? new DataDisk (appleDisk) : disk;
}
if (wozDisk.getSectorsPerTrack () == 16)
if (wozFile.getSectorsPerTrack () == 16)
{
AppleDisk appleDisk256 = new AppleDisk (wozDisk, 35, 16);
AppleDisk appleDisk256 = new AppleDisk (wozFile, 35, 16);
disk = checkDos (appleDisk256);
if (disk == null)
disk = checkProdos (new AppleDisk (wozDisk, 35, 8));
disk = checkProdos (new AppleDisk (wozFile, 35, 8));
if (disk == null)
disk = new DataDisk (appleDisk256);
}
@ -708,4 +708,9 @@ public class DiskFactory
return null;
}
private static void checkMissingSectors (AppleDisk disk, WozFile wozFile)
{
}
}

View File

@ -24,6 +24,8 @@ class DiskLayoutImage extends DiskPanel implements Scrollable, RedoListener
private static final Cursor crosshairCursor = new Cursor (Cursor.CROSSHAIR_CURSOR);
private static final Color[] lightColors =
{ Color.WHITE, Color.YELLOW, Color.PINK, Color.CYAN, Color.ORANGE, Color.GREEN };
private static Stroke missingStroke =
new BasicStroke ((float) 3.0, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
private boolean showFreeSectors;
private final DiskLayoutSelection selectionHandler = new DiskLayoutSelection ();
@ -124,14 +126,15 @@ class DiskLayoutImage extends DiskPanel implements Scrollable, RedoListener
DiskAddress da = d.getDiskAddress (blockNo);
boolean free = showFreeSectors && formattedDisk.isSectorFree (da);
boolean selected = selectionHandler.isSelected (da);
drawBlock ((Graphics2D) g, type, x, y, free, selected);
boolean missing = d.isSectorMissing (da);
drawBlock ((Graphics2D) g, type, x, y, free, selected, missing);
}
}
}
}
private void drawBlock (Graphics2D g, SectorType type, int x, int y, boolean flagFree,
boolean selected)
boolean selected, boolean missing)
{
g.setColor (type.colour);
g.fillRect (x + 1, y + 1, blockWidth - 1, blockHeight - 1);
@ -146,6 +149,14 @@ class DiskLayoutImage extends DiskPanel implements Scrollable, RedoListener
if (selected)
g.fillOval (x + centerOffset, y + 6, 3, 3);
}
if (missing)
{
g.setColor (Color.black);
g.setStroke (missingStroke);
g.drawLine (x + 5, y + 5, x + 11, y + 11);
g.drawLine (x + 5, y + 11, x + 11, y + 5);
}
}
private Color getContrastColor (SectorType type)
@ -159,7 +170,7 @@ class DiskLayoutImage extends DiskPanel implements Scrollable, RedoListener
@Override
public Dimension getPreferredScrollableViewportSize ()
{
return new Dimension (240 + 1, 525 + 1); // floppy disk size
return new Dimension (240 + 1, 525 + 1); // floppy disk size
}
@Override

View File

@ -39,6 +39,7 @@ public class WozFile
private final byte[] diskBuffer;
private final boolean debug = false;
List<Sector> badSectors = new ArrayList<> ();
// ---------------------------------------------------------------------------------//
public WozFile (File file) throws DiskNibbleException
@ -117,6 +118,13 @@ public class WozFile
return diskSectors;
}
// ---------------------------------------------------------------------------------//
public List<Sector> getBadSectors ()
// ---------------------------------------------------------------------------------//
{
return badSectors;
}
// ---------------------------------------------------------------------------------//
private void info (byte[] buffer, int ptr)
// ---------------------------------------------------------------------------------//
@ -310,7 +318,7 @@ public class WozFile
{
int trackNo;
int startingBlock;
int blockCount;
int blockCount; // WOZ2 - not needed
int bitCount;
int bytesUsed; // WOZ1 - not needed
@ -379,6 +387,9 @@ public class WozFile
if (sectors.size () > 0)
checkDuplicates (sector);
sectors.add (sector);
if (sector.dataOffset < 0)
badSectors.add (sector);
}
}
@ -503,11 +514,11 @@ public class WozFile
}
// ---------------------------------------------------------------------------------//
class Sector
public class Sector
// ---------------------------------------------------------------------------------//
{
Track track;
int trackNo, sectorNo, volume, checksum;
public final int trackNo, sectorNo, volume, checksum;
int addressOffset, dataOffset;
// ---------------------------------------------------------------------------------//
@ -521,6 +532,9 @@ public class WozFile
sectorNo = decode4and4 (track.newBuffer, addressOffset + 7);
checksum = decode4and4 (track.newBuffer, addressOffset + 9);
// int epiloguePtr = track.findNext (epilogue, addressOffset + 11);
// assert epiloguePtr == addressOffset + 11;
this.addressOffset = addressOffset;
dataOffset = track.findNext (dataPrologue, addressOffset + 11);
if (dataOffset > addressOffset + 200)