From 4514e461614d47d0746318405c1effeeab12bc93 Mon Sep 17 00:00:00 2001 From: Rob McMullen Date: Thu, 23 Feb 2017 15:34:56 -0800 Subject: [PATCH] Fixed parsing of disk images broken after recent rearrangement of classes --- atrcopy/__init__.py | 3 +-- atrcopy/ataridos.py | 28 ++++++++++++++++++++++++++++ atrcopy/diskimages.py | 31 +------------------------------ atrcopy/kboot.py | 5 ++--- atrcopy/parsers.py | 4 ++-- atrcopy/spartados.py | 7 +++---- 6 files changed, 37 insertions(+), 41 deletions(-) diff --git a/atrcopy/__init__.py b/atrcopy/__init__.py index 495ff5d..b8fcdad 100644 --- a/atrcopy/__init__.py +++ b/atrcopy/__init__.py @@ -8,9 +8,8 @@ except ImportError: raise RuntimeError("atrcopy %s requires numpy" % __version__) from errors import * -from ataridos import AtrHeader, AtariDosDiskImage, AtariDosFile, get_xex, add_atr_header +from ataridos import AtrHeader, AtariDosDiskImage, BootDiskImage, AtariDosFile, get_xex, add_atr_header from dos33 import Dos33DiskImage -from diskimages import BootDiskImage from kboot import KBootImage, add_xexboot_header from segments import SegmentData, SegmentSaver, DefaultSegment, EmptySegment, ObjSegment, RawSectorsSegment, user_bit_mask, match_bit_mask, comment_bit_mask, data_style, selected_bit_mask, diff_bit_mask, not_user_bit_mask, interleave_segments from spartados import SpartaDosDiskImage diff --git a/atrcopy/ataridos.py b/atrcopy/ataridos.py index 696079e..9385bed 100644 --- a/atrcopy/ataridos.py +++ b/atrcopy/ataridos.py @@ -614,6 +614,34 @@ class AtariDosDiskImage(DiskImageBase): return segments_out +class BootDiskImage(AtariDosDiskImage): + def __str__(self): + return "%s Boot Disk" % (self.header) + + def check_size(self): + if self.header is None: + return + start, size = self.header.get_pos(1) + b = self.bytes + i = self.header.header_offset + flag = b[i:i + 2].view(dtype=' max_sectors or nsec < 1: + raise InvalidDiskImage("Number of boot sectors out of range") + if bload < 0x200 or bload > (0xc000 - (nsec * self.header.sector_size)): + raise InvalidDiskImage("Bad boot load address") + + def get_xex(segments, runaddr): total = 2 for s in segments: diff --git a/atrcopy/diskimages.py b/atrcopy/diskimages.py index 0968a0a..b51b8ce 100644 --- a/atrcopy/diskimages.py +++ b/atrcopy/diskimages.py @@ -189,7 +189,7 @@ class DiskImageBase(object): raise InvalidDiskImage("Invalid directory entries; may be boot disk") def read_header(self): - raise NotImplementedError + return BaseHeader() def check_size(self): pass @@ -373,32 +373,3 @@ class DiskImageBase(object): raise finally: self.get_metadata() - - - -class BootDiskImage(DiskImageBase): - def __str__(self): - return "%s Boot Disk" % (self.header) - - def check_size(self): - if self.header is None: - return - start, size = self.header.get_pos(1) - b = self.bytes - i = self.header.header_offset - flag = b[i:i + 2].view(dtype=' max_sectors or nsec < 1: - raise InvalidDiskImage("Number of boot sectors out of range") - if bload < 0x200 or bload > (0xc000 - (nsec * self.header.sector_size)): - raise InvalidDiskImage("Bad boot load address") diff --git a/atrcopy/kboot.py b/atrcopy/kboot.py index 133474b..42a8a9f 100644 --- a/atrcopy/kboot.py +++ b/atrcopy/kboot.py @@ -1,8 +1,7 @@ import numpy as np from errors import * -from ataridos import AtariDosDirent, XexSegment -from diskimages import DiskImageBase +from ataridos import AtariDosDirent, AtariDosDiskImage, XexSegment class KBootDirent(AtariDosDirent): @@ -35,7 +34,7 @@ class KBootDirent(AtariDosDirent): return raw[0:num_bytes], num_bytes -class KBootImage(DiskImageBase): +class KBootImage(AtariDosDiskImage): def __str__(self): return "%s KBoot Format: %d byte executable" % (self.header, self.files[0].exe_size) diff --git a/atrcopy/parsers.py b/atrcopy/parsers.py index 11f4d17..ac2bcf4 100644 --- a/atrcopy/parsers.py +++ b/atrcopy/parsers.py @@ -1,9 +1,8 @@ import numpy as np from segments import SegmentData, DefaultSegment -from diskimages import BootDiskImage from kboot import KBootImage -from ataridos import AtariDosDiskImage, AtariDosFile +from ataridos import AtariDosDiskImage, BootDiskImage, AtariDosFile from spartados import SpartaDosDiskImage from cartridge import AtariCartImage, get_known_carts from mame import MameZipImage @@ -35,6 +34,7 @@ class SegmentParser(object): self.segments.extend(self.image.segments) def get_image(self, r): + print self.image_type return self.image_type(r) def check_image(self): diff --git a/atrcopy/spartados.py b/atrcopy/spartados.py index 509faa5..1256074 100644 --- a/atrcopy/spartados.py +++ b/atrcopy/spartados.py @@ -1,8 +1,7 @@ import numpy as np from errors import * -from ataridos import AtariDosDirent, XexSegment -from diskimages import DiskImageBase +from ataridos import AtariDosDirent, AtariDosDiskImage, XexSegment from segments import DefaultSegment, EmptySegment, ObjSegment, RawSectorsSegment, SegmentSaver import logging @@ -107,14 +106,14 @@ class SpartaDosDirent(AtariDosDirent): return raw[0:num_data_bytes], sector == 0, pos, num_data_bytes -class SpartaDosDiskImage(DiskImageBase): +class SpartaDosDiskImage(AtariDosDiskImage): def __init__(self, *args, **kwargs): self.first_bitmap = 0 self.num_bitmap = 0 self.root_dir = 0 self.root_dir_dirent = None self.fs_version = 0 - DiskImageBase.__init__(self, *args, **kwargs) + AtariDosDiskImage.__init__(self, *args, **kwargs) def __str__(self): return "%s Sparta DOS Format: %d usable sectors (%d free), %d files" % (self.header, self.total_sectors, self.unused_sectors, len(self.files))