From 74ea705347483b814c11ba88d569dc2dd8d641e2 Mon Sep 17 00:00:00 2001 From: Rob McMullen Date: Wed, 20 Jul 2016 08:13:44 -0700 Subject: [PATCH] Initial DOS 3.3 detection --- atrcopy/dos33.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++ atrcopy/parsers.py | 13 +++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 atrcopy/dos33.py diff --git a/atrcopy/dos33.py b/atrcopy/dos33.py new file mode 100644 index 0000000..133c6bd --- /dev/null +++ b/atrcopy/dos33.py @@ -0,0 +1,52 @@ +import numpy as np + +from errors import * +from diskimages import DiskImageBase +from segments import DefaultSegment, EmptySegment, ObjSegment, RawSectorsSegment, SegmentSaver + +import logging +log = logging.getLogger(__name__) + + +class Dos33Header(object): + file_format = "DOS 3.3" + + def __init__(self): + self.header_offset = 0 + self.image_size = 143360 + self.max_sectors = 35 * 16 + self.sector_size = 256 + + def __str__(self): + return "%s Disk Image (size=%d (%dx%db)" % (self.file_format, self.image_size, self.max_sectors, self.sector_size) + + def __len__(self): + return 0 + + def to_array(self): + raw = np.zeros([0], dtype=np.uint8) + return raw + + def check_size(self, size): + if size != self.image_size: + raise InvalidDiskImage("Incorrect size for DOS 3.3 image") + + def strict_check(self, image): + size = len(image) + if size in [143360]: + return + raise InvalidDiskImage("Incorrect size for DOS 3.3 image") + + +class Dos33DiskImage(DiskImageBase): + def __init__(self, rawdata, filename=""): + DiskImageBase.__init__(self, rawdata, filename) + + def __str__(self): + return str(self.header) + + def read_header(self): + self.header = Dos33Header() + + def get_boot_segments(self): + return [] diff --git a/atrcopy/parsers.py b/atrcopy/parsers.py index b280784..08a6e6d 100644 --- a/atrcopy/parsers.py +++ b/atrcopy/parsers.py @@ -7,6 +7,7 @@ from ataridos import AtariDosDiskImage, AtariDosFile from spartados import SpartaDosDiskImage from cartridge import AtariCartImage, get_known_carts from mame import MameZipImage +from dos33 import Dos33DiskImage from errors import * @@ -90,6 +91,11 @@ class MameZipParser(SegmentParser): image_type = MameZipImage +class Dos33SegmentParser(SegmentParser): + menu_name = "DOS 3.3 Disk Image" + image_type = Dos33DiskImage + + def guess_parser_for_mime(mime, r): parsers = mime_parsers[mime] found = None @@ -130,6 +136,9 @@ mime_parsers = { "application/vnd.mame_rom": [ MameZipParser, ], + "application/vnd.apple2.dsk": [ + Dos33SegmentParser, + ], } mime_parse_order = [ @@ -137,12 +146,14 @@ mime_parse_order = [ "application/vnd.atari8bit.xex", "CARTS", # Will get filled in below "application/vnd.mame_rom", + "application/vnd.apple2.dsk", ] pretty_mime = { "application/vnd.atari8bit.atr": "Atari 8-bit Disk Image", "application/vnd.atari8bit.xex": "Atari 8-bit Executable", - "application/vnd.mame_rom": "MAME" + "application/vnd.mame_rom": "MAME", + "application/vnd.apple2.dsk": "Apple ][ Disk Image", } grouped_carts = get_known_carts()