From b4bf541eecfa1a62a94c725de58803c98ecf209d Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 23 Nov 2020 21:42:18 -0500 Subject: [PATCH] Adds boilerplate route into a 2MG-handling class. --- Analyser/Static/StaticAnalyser.cpp | 19 ++++++++-- .../Clock Signal.xcodeproj/project.pbxproj | 8 +++++ OSBindings/Mac/Clock Signal/Info.plist | 22 ++++++++++++ Storage/Disk/DiskImage/Formats/2MG.cpp | 17 +++++++++ Storage/Disk/DiskImage/Formats/2MG.hpp | 35 +++++++++++++++++++ 5 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 Storage/Disk/DiskImage/Formats/2MG.cpp create mode 100644 Storage/Disk/DiskImage/Formats/2MG.hpp diff --git a/Analyser/Static/StaticAnalyser.cpp b/Analyser/Static/StaticAnalyser.cpp index a08f5039e..27f4c3dee 100644 --- a/Analyser/Static/StaticAnalyser.cpp +++ b/Analyser/Static/StaticAnalyser.cpp @@ -34,6 +34,7 @@ #include "../../Storage/Cartridge/Formats/PRG.hpp" // Disks +#include "../../Storage/Disk/DiskImage/Formats/2MG.hpp" #include "../../Storage/Disk/DiskImage/Formats/AcornADF.hpp" #include "../../Storage/Disk/DiskImage/Formats/AppleDSK.hpp" #include "../../Storage/Disk/DiskImage/Formats/CPCDSK.hpp" @@ -79,11 +80,14 @@ static Media GetMediaAndPlatforms(const std::string &file_name, TargetPlatform:: std::string extension = file_name.substr(final_dot + 1); std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower); -#define Insert(list, class, platforms, ...) \ - list.emplace_back(new Storage::class(__VA_ARGS__));\ +#define InsertInstance(list, instance, platforms) \ + list.emplace_back(instance);\ potential_platforms |= platforms;\ TargetPlatform::TypeDistinguisher *distinguisher = dynamic_cast(list.back().get());\ - if(distinguisher) potential_platforms &= distinguisher->target_platform_type(); + if(distinguisher) potential_platforms &= distinguisher->target_platform_type(); \ + +#define Insert(list, class, platforms, ...) \ + InsertInstance(list, new Storage::class(__VA_ARGS__), platforms); #define TryInsert(list, class, platforms, ...) \ try {\ @@ -95,6 +99,14 @@ static Media GetMediaAndPlatforms(const std::string &file_name, TargetPlatform:: TryInsert(list, class, platforms, file_name) \ } + // 2MG + if(extension == "2mg") { + // 2MG uses a factory method; defer to it. + try { + InsertInstance(result.disks, Storage::Disk::Disk2MG::open(file_name), TargetPlatform::DiskII) + } catch(...) {} + } + Format("80", result.tapes, Tape::ZX80O81P, TargetPlatform::ZX8081) // 80 Format("81", result.tapes, Tape::ZX80O81P, TargetPlatform::ZX8081) // 81 Format("a26", result.cartridges, Cartridge::BinaryDump, TargetPlatform::Atari2600) // A26 @@ -169,6 +181,7 @@ static Media GetMediaAndPlatforms(const std::string &file_name, TargetPlatform:: #undef Format #undef Insert #undef TryInsert +#undef InsertInstance return result; } diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 1622dc329..dbbea215f 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -396,6 +396,8 @@ 4B7F1897215486A200388727 /* StaticAnalyser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B7F1896215486A100388727 /* StaticAnalyser.cpp */; }; 4B7F1898215486A200388727 /* StaticAnalyser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B7F1896215486A100388727 /* StaticAnalyser.cpp */; }; 4B80CD6F2568A82C00176FCC /* DiskIIDrive.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B80CD6D2568A82600176FCC /* DiskIIDrive.cpp */; }; + 4B80CD76256CA16400176FCC /* 2MG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B80CD74256CA15E00176FCC /* 2MG.cpp */; }; + 4B80CD77256CA16600176FCC /* 2MG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B80CD74256CA15E00176FCC /* 2MG.cpp */; }; 4B8318B022D3E531006DB630 /* AppleII.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BCE0050227CE8CA000CA200 /* AppleII.cpp */; }; 4B8318B122D3E53A006DB630 /* DiskIICard.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BCE004E227CE8CA000CA200 /* DiskIICard.cpp */; }; 4B8318B222D3E53C006DB630 /* Video.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BCE004D227CE8CA000CA200 /* Video.cpp */; }; @@ -1306,6 +1308,8 @@ 4B80214322EE7C3E00068002 /* JustInTime.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = JustInTime.hpp; sourceTree = ""; }; 4B80CD6D2568A82600176FCC /* DiskIIDrive.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DiskIIDrive.cpp; sourceTree = ""; }; 4B80CD6E2568A82900176FCC /* DiskIIDrive.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = DiskIIDrive.hpp; sourceTree = ""; }; + 4B80CD74256CA15E00176FCC /* 2MG.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = 2MG.cpp; sourceTree = ""; }; + 4B80CD75256CA15E00176FCC /* 2MG.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = 2MG.hpp; sourceTree = ""; }; 4B8334811F5D9FF70097E338 /* PartialMachineCycle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PartialMachineCycle.cpp; sourceTree = ""; }; 4B8334831F5DA0360097E338 /* Z80Storage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Z80Storage.cpp; sourceTree = ""; }; 4B8334851F5DA3780097E338 /* 6502Storage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = 6502Storage.cpp; sourceTree = ""; }; @@ -2550,6 +2554,8 @@ 4B7BA03223C58B1E00B98D9E /* STX.hpp */, 4B6ED2EF208E2F8A0047B343 /* WOZ.hpp */, 4BFDD7891F7F2DB4008579B9 /* Utility */, + 4B80CD74256CA15E00176FCC /* 2MG.cpp */, + 4B80CD75256CA15E00176FCC /* 2MG.hpp */, ); path = Formats; sourceTree = ""; @@ -4969,6 +4975,7 @@ 4B055AB71FAE860F0060FFFF /* TZX.cpp in Sources */, 4B2BF19123DCC6A200C3AD60 /* BD500.cpp in Sources */, 4B055ADA1FAE9B460060FFFF /* 1770.cpp in Sources */, + 4B80CD77256CA16600176FCC /* 2MG.cpp in Sources */, 4B055ADC1FAE9B460060FFFF /* AY38910.cpp in Sources */, 4B055AD71FAE9B180060FFFF /* Keyboard.cpp in Sources */, 4BD67DCC209BE4D700AB2146 /* StaticAnalyser.cpp in Sources */, @@ -5146,6 +5153,7 @@ 4B4518A01F75FD1C00926311 /* CPCDSK.cpp in Sources */, 4B0CCC451C62D0B3001CAC5F /* CRT.cpp in Sources */, 4BC23A2C2467600F001A6030 /* OPLL.cpp in Sources */, + 4B80CD76256CA16400176FCC /* 2MG.cpp in Sources */, 4B8DF505254E3C9D00F3433C /* ADB.cpp in Sources */, 4B322E041F5A2E3C004EB04C /* Z80Base.cpp in Sources */, 4B0ACC2623775819008902D0 /* AtariST.cpp in Sources */, diff --git a/OSBindings/Mac/Clock Signal/Info.plist b/OSBindings/Mac/Clock Signal/Info.plist index 7f07c53ec..c2e83fce3 100644 --- a/OSBindings/Mac/Clock Signal/Info.plist +++ b/OSBindings/Mac/Clock Signal/Info.plist @@ -552,6 +552,28 @@ NSDocumentClass $(PRODUCT_MODULE_NAME).MachineDocument + + CFBundleTypeExtensions + + 2mg + + CFBundleTypeIconFile + floppy35.png + CFBundleTypeName + Apple 2MG Disk Image + CFBundleTypeOSTypes + + ???? + + CFBundleTypeRole + Editor + LSHandlerRank + Owner + LSTypeIsPackage + + NSDocumentClass + $(PRODUCT_MODULE_NAME).MachineDocument + CFBundleExecutable $(EXECUTABLE_NAME) diff --git a/Storage/Disk/DiskImage/Formats/2MG.cpp b/Storage/Disk/DiskImage/Formats/2MG.cpp new file mode 100644 index 000000000..b54130721 --- /dev/null +++ b/Storage/Disk/DiskImage/Formats/2MG.cpp @@ -0,0 +1,17 @@ +// +// 2MG.cpp +// Clock Signal +// +// Created by Thomas Harte on 23/11/2020. +// Copyright © 2020 Thomas Harte. All rights reserved. +// + +#include "2MG.hpp" + +using namespace Storage::Disk; + +DiskImageHolderBase *Disk2MG::open(const std::string &file_name) { + (void)file_name; + throw Error::InvalidFormat; + return nullptr; +} diff --git a/Storage/Disk/DiskImage/Formats/2MG.hpp b/Storage/Disk/DiskImage/Formats/2MG.hpp new file mode 100644 index 000000000..8b37112a2 --- /dev/null +++ b/Storage/Disk/DiskImage/Formats/2MG.hpp @@ -0,0 +1,35 @@ +// +// 2MG.hpp +// Clock Signal +// +// Created by Thomas Harte on 23/11/2020. +// Copyright © 2020 Thomas Harte. All rights reserved. +// + +#ifndef _MG_hpp +#define _MG_hpp + +#include "../DiskImage.hpp" +#include "../../../FileHolder.hpp" + +namespace Storage { +namespace Disk { + +/*! + 2MG is slightly special because it's just a container format; there's a brief header and then + the contents are some other file format — either MacintoshIMG or AppleDSK. + + Therefore it supplies a factory method and will actually return one of those. + + TODO: should I generalise on factory methods? Is this likely to occur again? +*/ + +class Disk2MG { + public: + static DiskImageHolderBase *open(const std::string &file_name); +}; + +} +} + +#endif /* _MG_hpp */