mirror of
https://github.com/robmcmullen/atrcopy.git
synced 2024-11-25 16:32:07 +00:00
Added pretty printing of VTOC by track
* changed VTOC, Directory classes to keep pointer to header, not just sector sizes
This commit is contained in:
parent
151cf06115
commit
4d1f17677d
@ -30,11 +30,11 @@ class AtariDosVTOC(VTOC):
|
||||
def parse_segments(self, segments):
|
||||
self.vtoc1 = segments[0].data
|
||||
bits = np.unpackbits(self.vtoc1[0x0a:0x64])
|
||||
log.debug("vtoc before: %s" % bits)
|
||||
self.sector_map[0:720] = bits
|
||||
log.debug("vtoc before:\n%s" % str(self))
|
||||
|
||||
def calc_bitmap(self):
|
||||
log.debug("vtoc after: %s" % self.sector_map[0:720])
|
||||
log.debug("vtoc after:\n%s" % str(self))
|
||||
packed = np.packbits(self.sector_map[0:720])
|
||||
self.vtoc1[0x0a:0x64] = packed
|
||||
s = WriteableSector(self.sector_size, self.vtoc1)
|
||||
@ -175,7 +175,7 @@ class AtariDosDirent(object):
|
||||
return True
|
||||
|
||||
def get_sectors_in_vtoc(self, image):
|
||||
sector_list = BaseSectorList(image.header.sector_size)
|
||||
sector_list = BaseSectorList(image.header)
|
||||
self.start_read(image)
|
||||
while True:
|
||||
sector = WriteableSector(image.header.sector_size, None, self.current_sector)
|
||||
|
@ -387,7 +387,7 @@ class DiskImageBase(object):
|
||||
try:
|
||||
vtoc_segments = self.get_vtoc_segments()
|
||||
vtoc = self.vtoc_class(self.header, vtoc_segments)
|
||||
for sector_num, pos, size in vtoc.iter_free_sectors(self.header):
|
||||
for sector_num, pos, size in vtoc.iter_free_sectors():
|
||||
log.debug("shredding: sector %s at %d, fill value=%d" % (sector_num, pos, fill_value))
|
||||
self.bytes[pos:pos + size] = fill_value
|
||||
except AtrError:
|
||||
|
@ -92,10 +92,10 @@ class Dos33VTOC(VTOC):
|
||||
# so we need to reorder them using numpy's indexing before stuffing
|
||||
# them into the sector map
|
||||
self.sector_map[0:self.max_sectors] = bits[self.vtoc_bit_reorder_index]
|
||||
log.debug("vtoc before: %s (%d free)" % (self.sector_map[0:35*16], self.num_free_sectors))
|
||||
log.debug("vtoc before:\n%s" % str(self))
|
||||
|
||||
def calc_bitmap(self):
|
||||
log.debug("vtoc after: %s (%d free)" % (self.sector_map[0:35*16], self.num_free_sectors))
|
||||
log.debug("vtoc after:\n%s" % str(self))
|
||||
|
||||
# reverse the process from above, so swap the order of every 16 bits,
|
||||
# turn them into bytes, then stuff them back into the vtoc. The bit
|
||||
@ -251,7 +251,7 @@ class Dos33Dirent(object):
|
||||
def add_metadata_sectors(self, vtoc, sector_list, header):
|
||||
"""Add track/sector list
|
||||
"""
|
||||
tslist = BaseSectorList(header.sector_size)
|
||||
tslist = BaseSectorList(header)
|
||||
for start in range(0, len(sector_list), header.ts_pairs):
|
||||
end = min(start + header.ts_pairs, len(sector_list))
|
||||
log.debug("ts: %d-%d" % (start, end))
|
||||
@ -277,7 +277,7 @@ class Dos33Dirent(object):
|
||||
return True
|
||||
|
||||
def get_track_sector_list(self, image):
|
||||
tslist = BaseSectorList(image.header.sector_size)
|
||||
tslist = BaseSectorList(image.header)
|
||||
sector_num = image.header.sector_from_track(self.track, self.sector)
|
||||
sector_map = []
|
||||
while sector_num > 0:
|
||||
|
@ -93,8 +93,9 @@ class WriteableSector(object):
|
||||
|
||||
|
||||
class BaseSectorList(object):
|
||||
def __init__(self, sector_size):
|
||||
self.sector_size = sector_size
|
||||
def __init__(self, header):
|
||||
self.header = header
|
||||
self.sector_size = header.sector_size
|
||||
self.sectors = []
|
||||
|
||||
def __len__(self):
|
||||
@ -134,7 +135,7 @@ class BaseSectorList(object):
|
||||
|
||||
class Directory(BaseSectorList):
|
||||
def __init__(self, header, num_dirents=-1, sector_class=WriteableSector):
|
||||
BaseSectorList.__init__(self, header.sector_size)
|
||||
BaseSectorList.__init__(self, header)
|
||||
self.sector_class = sector_class
|
||||
self.num_dirents = num_dirents
|
||||
# number of dirents may be unlimited, so use a dict instead of a list
|
||||
@ -236,20 +237,23 @@ class Directory(BaseSectorList):
|
||||
|
||||
class VTOC(BaseSectorList):
|
||||
def __init__(self, header, segments=None):
|
||||
BaseSectorList.__init__(self, header.sector_size)
|
||||
BaseSectorList.__init__(self, header)
|
||||
|
||||
# sector map: 1 is free, 0 is allocated
|
||||
self.sector_map = np.zeros([1280], dtype=np.uint8)
|
||||
if segments is not None:
|
||||
self.parse_segments(segments)
|
||||
|
||||
def __str__(self):
|
||||
return "%s\n (%d free)" % ("\n".join(["track %02d: %s" % (i, line) for i, line in enumerate(str(self.sector_map[0:self.header.tracks_per_disk*self.header.sectors_per_track].reshape([self.header.tracks_per_disk,self.header.sectors_per_track])).splitlines())]), self.num_free_sectors)
|
||||
|
||||
@property
|
||||
def num_free_sectors(self):
|
||||
free = np.where(self.sector_map == 1)[0]
|
||||
return len(free)
|
||||
|
||||
def iter_free_sectors(self, header):
|
||||
for i, pos, size in header.iter_sectors():
|
||||
def iter_free_sectors(self):
|
||||
for i, pos, size in self.header.iter_sectors():
|
||||
if self.sector_map[i] == 1:
|
||||
yield i, pos, size
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user