dmolony-DiskBrowser/src/com/bytezone/diskbrowser/disk/AppleDiskAddress.java

87 lines
1.6 KiB
Java
Raw Normal View History

2015-06-01 09:35:51 +00:00
package com.bytezone.diskbrowser.disk;
public class AppleDiskAddress implements DiskAddress
{
private final int block;
private final int track;
private final int sector;
public final Disk owner;
2019-07-31 00:01:49 +00:00
2019-01-25 04:57:15 +00:00
private boolean zeroFlag;
2015-06-01 09:35:51 +00:00
2016-07-17 22:35:18 +00:00
public AppleDiskAddress (Disk owner, int block)
2015-06-01 09:35:51 +00:00
{
this.owner = owner;
this.block = block;
int sectorsPerTrack = owner.getSectorsPerTrack ();
2019-08-25 04:16:36 +00:00
if (sectorsPerTrack == 0)
{
track = 0;
sector = 0;
}
else
{
track = block / sectorsPerTrack;
sector = block % sectorsPerTrack;
}
2015-06-01 09:35:51 +00:00
}
2016-07-17 22:35:18 +00:00
public AppleDiskAddress (Disk owner, int track, int sector)
2015-06-01 09:35:51 +00:00
{
this.owner = owner;
2019-01-25 04:57:15 +00:00
zeroFlag = (track & 0x40) != 0;
this.track = track & 0x3F;
this.sector = sector & 0x1F;
this.block = this.track * owner.getSectorsPerTrack () + this.sector;
2015-06-01 09:35:51 +00:00
}
2019-01-25 04:57:15 +00:00
public boolean zeroFlag ()
2015-06-01 09:35:51 +00:00
{
2019-01-25 04:57:15 +00:00
return zeroFlag;
2015-06-01 09:35:51 +00:00
}
2016-03-24 00:17:09 +00:00
@Override
2015-06-01 09:35:51 +00:00
public int compareTo (DiskAddress that)
{
return this.block - that.getBlock ();
}
2016-07-17 22:42:44 +00:00
@Override
public boolean matches (DiskAddress that)
{
2019-01-25 06:06:31 +00:00
if (that == null)
return false;
return this.block == that.getBlock ();
2016-07-17 22:42:44 +00:00
}
2016-03-24 00:17:09 +00:00
@Override
2015-06-01 09:35:51 +00:00
public int getBlock ()
{
return block;
}
2016-03-24 00:17:09 +00:00
@Override
2015-06-01 09:35:51 +00:00
public int getSector ()
{
return sector;
}
2016-03-24 00:17:09 +00:00
@Override
2015-06-01 09:35:51 +00:00
public int getTrack ()
{
return track;
}
2016-03-24 00:17:09 +00:00
@Override
2015-06-01 09:35:51 +00:00
public Disk getDisk ()
{
return owner;
}
2019-01-25 04:57:15 +00:00
@Override
public String toString ()
{
return String.format ("[Block=%3d, Track=%2d, Sector=%2d, Zero=%s]", block, track,
sector, zeroFlag);
}
2015-06-01 09:35:51 +00:00
}