dmolony-DiskBrowser/src/com/bytezone/diskbrowser/pascal/PascalCodeObject.java

88 lines
3.0 KiB
Java
Raw Permalink Normal View History

2016-02-25 09:23:08 +00:00
package com.bytezone.diskbrowser.pascal;
import java.util.ArrayList;
import java.util.List;
import com.bytezone.diskbrowser.applefile.AbstractFile;
import com.bytezone.diskbrowser.applefile.AppleFileSource;
import com.bytezone.diskbrowser.applefile.PascalSegment;
import com.bytezone.diskbrowser.disk.Disk;
import com.bytezone.diskbrowser.disk.DiskAddress;
import com.bytezone.diskbrowser.disk.FormattedDisk;
import com.bytezone.diskbrowser.gui.DataSource;
2020-02-09 13:13:33 +00:00
// -----------------------------------------------------------------------------------//
2016-02-25 09:23:08 +00:00
class PascalCodeObject implements AppleFileSource
2020-02-09 13:13:33 +00:00
// -----------------------------------------------------------------------------------//
2016-02-25 09:23:08 +00:00
{
private final PascalDisk parent;
private final AbstractFile segment;
2019-11-01 03:30:19 +00:00
private final List<DiskAddress> blocks = new ArrayList<> ();
2016-02-25 09:23:08 +00:00
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
PascalCodeObject (PascalDisk parent, PascalSegment segment, int firstBlock)
// ---------------------------------------------------------------------------------//
2016-02-25 09:23:08 +00:00
{
this.parent = parent;
this.segment = segment;
int lo = firstBlock + segment.blockNo;
int hi = lo + (segment.size - 1) / 512;
Disk disk = parent.getDisk ();
2016-08-08 04:53:29 +00:00
int max = Math.min (hi, 279);
for (int i = lo; i <= max; i++)
2016-02-25 09:23:08 +00:00
blocks.add (disk.getDiskAddress (i));
}
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
2016-02-25 09:23:08 +00:00
@Override
public DataSource getDataSource ()
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
2016-02-25 09:23:08 +00:00
{
return segment;
}
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
2016-02-25 09:23:08 +00:00
@Override
public FormattedDisk getFormattedDisk ()
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
2016-02-25 09:23:08 +00:00
{
return parent;
}
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
2016-02-25 09:23:08 +00:00
@Override
public List<DiskAddress> getSectors ()
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
2016-02-25 09:23:08 +00:00
{
return blocks;
}
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
2016-02-25 21:49:22 +00:00
@Override
public boolean contains (DiskAddress da)
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
2016-02-25 21:49:22 +00:00
{
for (DiskAddress sector : blocks)
if (sector.matches (da))
2016-02-25 21:49:22 +00:00
return true;
2022-03-28 03:55:49 +00:00
2016-02-25 21:49:22 +00:00
return false;
}
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
2016-02-25 09:23:08 +00:00
@Override
public String getUniqueName ()
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
2016-02-25 09:23:08 +00:00
{
2016-08-04 12:00:53 +00:00
return segment.getName (); // this should be fileName/segmentName
2016-02-25 09:23:08 +00:00
}
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
2016-02-25 09:23:08 +00:00
@Override
public String toString ()
2020-02-09 13:13:33 +00:00
// ---------------------------------------------------------------------------------//
2016-02-25 09:23:08 +00:00
{
2016-03-23 23:37:59 +00:00
return segment.getName ();
2016-02-25 09:23:08 +00:00
}
}