diff --git a/Analyser/Static/Commodore/StaticAnalyser.cpp b/Analyser/Static/Commodore/StaticAnalyser.cpp index c66d4201a..5a5f41c78 100644 --- a/Analyser/Static/Commodore/StaticAnalyser.cpp +++ b/Analyser/Static/Commodore/StaticAnalyser.cpp @@ -14,6 +14,7 @@ #include "Target.hpp" #include "../../../Storage/Cartridge/Encodings/CommodoreROM.hpp" +#include #include using namespace Analyser::Static::Commodore; @@ -39,7 +40,7 @@ static std::vector> return vic20_cartridges; } -void Analyser::Static::Commodore::AddTargets(const Media &media, std::vector> &destination) { +void Analyser::Static::Commodore::AddTargets(const Media &media, std::vector> &destination, const std::string &file_name) { std::unique_ptr target(new Target); target->machine = Machine::Vic20; // TODO: machine estimation target->confidence = 0.5; // TODO: a proper estimation @@ -140,6 +141,14 @@ void Analyser::Static::Commodore::AddTargets(const Media &media, std::vectormedia.empty()) + if(!target->media.empty()) { + // Inspect filename for a region hint. + std::string lowercase_name = file_name; + std::transform(lowercase_name.begin(), lowercase_name.end(), lowercase_name.begin(), ::tolower); + if(lowercase_name.find("ntsc") != std::string::npos) { + target->region = Analyser::Static::Commodore::Target::Region::American; + } + destination.push_back(std::move(target)); + } } diff --git a/Analyser/Static/Commodore/StaticAnalyser.hpp b/Analyser/Static/Commodore/StaticAnalyser.hpp index a318cd16e..9549e97c5 100644 --- a/Analyser/Static/Commodore/StaticAnalyser.hpp +++ b/Analyser/Static/Commodore/StaticAnalyser.hpp @@ -10,12 +10,13 @@ #define StaticAnalyser_Commodore_StaticAnalyser_hpp #include "../StaticAnalyser.hpp" +#include namespace Analyser { namespace Static { namespace Commodore { -void AddTargets(const Media &media, std::vector> &destination); +void AddTargets(const Media &media, std::vector> &destination, const std::string &file_name); } } diff --git a/Analyser/Static/StaticAnalyser.cpp b/Analyser/Static/StaticAnalyser.cpp index 0a46ddcb1..f97db90f6 100644 --- a/Analyser/Static/StaticAnalyser.cpp +++ b/Analyser/Static/StaticAnalyser.cpp @@ -52,21 +52,16 @@ using namespace Analyser::Static; -static Media GetMediaAndPlatforms(const char *file_name, TargetPlatform::IntType &potential_platforms) { +static Media GetMediaAndPlatforms(const std::string &file_name, TargetPlatform::IntType &potential_platforms) { + Media result; + // Get the extension, if any; it will be assumed that extensions are reliable, so an extension is a broad-phase // test as to file format. - const char *mixed_case_extension = strrchr(file_name, '.'); - char *lowercase_extension = nullptr; - if(mixed_case_extension) { - lowercase_extension = strdup(mixed_case_extension+1); - char *parser = lowercase_extension; - while(*parser) { - *parser = (char)tolower(*parser); - parser++; - } - } + std::string::size_type final_dot = file_name.find_last_of("."); + if(final_dot == std::string::npos) return result; + std::string extension = file_name.substr(final_dot + 1); + std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower); - Media result; #define Insert(list, class, platforms) \ list.emplace_back(new Storage::class(file_name));\ potential_platforms |= platforms;\ @@ -78,78 +73,72 @@ static Media GetMediaAndPlatforms(const char *file_name, TargetPlatform::IntType Insert(list, class, platforms) \ } catch(...) {} -#define Format(extension, list, class, platforms) \ - if(!std::strcmp(lowercase_extension, extension)) { \ +#define Format(ext, list, class, platforms) \ + if(extension == ext) { \ TryInsert(list, class, platforms) \ } - if(lowercase_extension) { - 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 - Format("adf", result.disks, Disk::DiskImageHolder, TargetPlatform::Acorn) // ADF - Format("bin", result.cartridges, Cartridge::BinaryDump, TargetPlatform::AllCartridge) // BIN - Format("cas", result.tapes, Tape::CAS, TargetPlatform::MSX) // CAS - Format("cdt", result.tapes, Tape::TZX, TargetPlatform::AmstradCPC) // CDT - Format("col", result.cartridges, Cartridge::BinaryDump, TargetPlatform::ColecoVision) // COL - Format("csw", result.tapes, Tape::CSW, TargetPlatform::AllTape) // CSW - Format("d64", result.disks, Disk::DiskImageHolder, TargetPlatform::Commodore) // D64 - Format("dmk", result.disks, Disk::DiskImageHolder, TargetPlatform::MSX) // DMK - Format("dsd", result.disks, Disk::DiskImageHolder, TargetPlatform::Acorn) // DSD - Format("dsk", result.disks, Disk::DiskImageHolder, TargetPlatform::AmstradCPC) // DSK (Amstrad CPC) - Format("dsk", result.disks, Disk::DiskImageHolder, TargetPlatform::MSX) // DSK (MSX) - Format("dsk", result.disks, Disk::DiskImageHolder, TargetPlatform::Oric) // DSK (Oric) - Format("g64", result.disks, Disk::DiskImageHolder, TargetPlatform::Commodore) // G64 - Format( "hfe", - result.disks, - Disk::DiskImageHolder, - TargetPlatform::Acorn | TargetPlatform::AmstradCPC | TargetPlatform::Commodore | TargetPlatform::Oric) - // HFE (TODO: switch to AllDisk once the MSX stops being so greedy) - Format("o", result.tapes, Tape::ZX80O81P, TargetPlatform::ZX8081) // O - Format("p", result.tapes, Tape::ZX80O81P, TargetPlatform::ZX8081) // P - Format("p81", result.tapes, Tape::ZX80O81P, TargetPlatform::ZX8081) // P81 + 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 + Format("adf", result.disks, Disk::DiskImageHolder, TargetPlatform::Acorn) // ADF + Format("bin", result.cartridges, Cartridge::BinaryDump, TargetPlatform::AllCartridge) // BIN + Format("cas", result.tapes, Tape::CAS, TargetPlatform::MSX) // CAS + Format("cdt", result.tapes, Tape::TZX, TargetPlatform::AmstradCPC) // CDT + Format("col", result.cartridges, Cartridge::BinaryDump, TargetPlatform::ColecoVision) // COL + Format("csw", result.tapes, Tape::CSW, TargetPlatform::AllTape) // CSW + Format("d64", result.disks, Disk::DiskImageHolder, TargetPlatform::Commodore) // D64 + Format("dmk", result.disks, Disk::DiskImageHolder, TargetPlatform::MSX) // DMK + Format("dsd", result.disks, Disk::DiskImageHolder, TargetPlatform::Acorn) // DSD + Format("dsk", result.disks, Disk::DiskImageHolder, TargetPlatform::AmstradCPC) // DSK (Amstrad CPC) + Format("dsk", result.disks, Disk::DiskImageHolder, TargetPlatform::MSX) // DSK (MSX) + Format("dsk", result.disks, Disk::DiskImageHolder, TargetPlatform::Oric) // DSK (Oric) + Format("g64", result.disks, Disk::DiskImageHolder, TargetPlatform::Commodore) // G64 + Format( "hfe", + result.disks, + Disk::DiskImageHolder, + TargetPlatform::Acorn | TargetPlatform::AmstradCPC | TargetPlatform::Commodore | TargetPlatform::Oric) + // HFE (TODO: switch to AllDisk once the MSX stops being so greedy) + Format("o", result.tapes, Tape::ZX80O81P, TargetPlatform::ZX8081) // O + Format("p", result.tapes, Tape::ZX80O81P, TargetPlatform::ZX8081) // P + Format("p81", result.tapes, Tape::ZX80O81P, TargetPlatform::ZX8081) // P81 - // PRG - if(!std::strcmp(lowercase_extension, "prg")) { - // try instantiating as a ROM; failing that accept as a tape + // PRG + if(extension == "prg") { + // try instantiating as a ROM; failing that accept as a tape + try { + Insert(result.cartridges, Cartridge::PRG, TargetPlatform::Commodore) + } catch(...) { try { - Insert(result.cartridges, Cartridge::PRG, TargetPlatform::Commodore) - } catch(...) { - try { - Insert(result.tapes, Tape::PRG, TargetPlatform::Commodore) - } catch(...) {} - } + Insert(result.tapes, Tape::PRG, TargetPlatform::Commodore) + } catch(...) {} } + } - Format( "rom", - result.cartridges, - Cartridge::BinaryDump, - TargetPlatform::AcornElectron | TargetPlatform::ColecoVision | TargetPlatform::MSX) // ROM - Format("ssd", result.disks, Disk::DiskImageHolder, TargetPlatform::Acorn) // SSD - Format("tap", result.tapes, Tape::CommodoreTAP, TargetPlatform::Commodore) // TAP (Commodore) - Format("tap", result.tapes, Tape::OricTAP, TargetPlatform::Oric) // TAP (Oric) - Format("tsx", result.tapes, Tape::TZX, TargetPlatform::MSX) // TSX - Format("tzx", result.tapes, Tape::TZX, TargetPlatform::ZX8081) // TZX - Format("uef", result.tapes, Tape::UEF, TargetPlatform::Acorn) // UEF (tape) + Format( "rom", + result.cartridges, + Cartridge::BinaryDump, + TargetPlatform::AcornElectron | TargetPlatform::ColecoVision | TargetPlatform::MSX) // ROM + Format("ssd", result.disks, Disk::DiskImageHolder, TargetPlatform::Acorn) // SSD + Format("tap", result.tapes, Tape::CommodoreTAP, TargetPlatform::Commodore) // TAP (Commodore) + Format("tap", result.tapes, Tape::OricTAP, TargetPlatform::Oric) // TAP (Oric) + Format("tsx", result.tapes, Tape::TZX, TargetPlatform::MSX) // TSX + Format("tzx", result.tapes, Tape::TZX, TargetPlatform::ZX8081) // TZX + Format("uef", result.tapes, Tape::UEF, TargetPlatform::Acorn) // UEF (tape) #undef Format #undef Insert #undef TryInsert - // Filter potential platforms as per file preferences, if any. - - free(lowercase_extension); - } - return result; } -Media Analyser::Static::GetMedia(const char *file_name) { +Media Analyser::Static::GetMedia(const std::string &file_name) { TargetPlatform::IntType throwaway; return GetMediaAndPlatforms(file_name, throwaway); } -std::vector> Analyser::Static::GetTargets(const char *file_name) { +std::vector> Analyser::Static::GetTargets(const std::string &file_name) { std::vector> targets; // Collect all disks, tapes and ROMs as can be extrapolated from this file, forming the @@ -163,7 +152,7 @@ std::vector> Analyser::Static::GetTargets(const char *fi if(potential_platforms & TargetPlatform::AmstradCPC) AmstradCPC::AddTargets(media, targets); if(potential_platforms & TargetPlatform::Atari2600) Atari::AddTargets(media, targets); if(potential_platforms & TargetPlatform::ColecoVision) Coleco::AddTargets(media, targets); - if(potential_platforms & TargetPlatform::Commodore) Commodore::AddTargets(media, targets); + if(potential_platforms & TargetPlatform::Commodore) Commodore::AddTargets(media, targets, file_name); if(potential_platforms & TargetPlatform::MSX) MSX::AddTargets(media, targets); if(potential_platforms & TargetPlatform::Oric) Oric::AddTargets(media, targets); if(potential_platforms & TargetPlatform::ZX8081) ZX8081::AddTargets(media, targets, potential_platforms); diff --git a/Analyser/Static/StaticAnalyser.hpp b/Analyser/Static/StaticAnalyser.hpp index acfccc507..64ea0196e 100644 --- a/Analyser/Static/StaticAnalyser.hpp +++ b/Analyser/Static/StaticAnalyser.hpp @@ -53,12 +53,12 @@ struct Target { @returns The list of potential targets, sorted from most to least probable. */ -std::vector> GetTargets(const char *file_name); +std::vector> GetTargets(const std::string &file_name); /*! Inspects the supplied file and determines the media included. */ -Media GetMedia(const char *file_name); +Media GetMedia(const std::string &file_name); } } diff --git a/Analyser/Static/ZX8081/StaticAnalyser.cpp b/Analyser/Static/ZX8081/StaticAnalyser.cpp index a405bf8bf..06727de52 100644 --- a/Analyser/Static/ZX8081/StaticAnalyser.cpp +++ b/Analyser/Static/ZX8081/StaticAnalyser.cpp @@ -44,7 +44,7 @@ void Analyser::Static::ZX8081::AddTargets(const Media &media, std::vectoris_ZX81 = false; break; - case TargetPlatform::ZX81: target->is_ZX81 = true; break; + case TargetPlatform::ZX81: target->is_ZX81 = true; break; } /*if(files.front().data.size() > 16384) { diff --git a/OSBindings/SDL/main.cpp b/OSBindings/SDL/main.cpp index bdd334c4e..30656916b 100644 --- a/OSBindings/SDL/main.cpp +++ b/OSBindings/SDL/main.cpp @@ -239,7 +239,7 @@ int main(int argc, char *argv[]) { } // Determine the machine for the supplied file. - std::vector> targets = Analyser::Static::GetTargets(arguments.file_name.c_str()); + std::vector> targets = Analyser::Static::GetTargets(arguments.file_name); if(targets.empty()) { std::cerr << "Cannot open " << arguments.file_name << "; no target machine found" << std::endl; return -1; diff --git a/Storage/Cartridge/Formats/BinaryDump.cpp b/Storage/Cartridge/Formats/BinaryDump.cpp index fb4e76d8f..1fced44a2 100644 --- a/Storage/Cartridge/Formats/BinaryDump.cpp +++ b/Storage/Cartridge/Formats/BinaryDump.cpp @@ -13,13 +13,13 @@ using namespace Storage::Cartridge; -BinaryDump::BinaryDump(const char *file_name) { +BinaryDump::BinaryDump(const std::string &file_name) { // the file should be exactly 16 kb struct stat file_stats; - stat(file_name, &file_stats); + stat(file_name.c_str(), &file_stats); // grab contents - FILE *file = std::fopen(file_name, "rb"); + FILE *file = std::fopen(file_name.c_str(), "rb"); if(!file) throw ErrorNotAccessible; std::size_t data_length = static_cast(file_stats.st_size); std::vector contents(data_length); diff --git a/Storage/Cartridge/Formats/BinaryDump.hpp b/Storage/Cartridge/Formats/BinaryDump.hpp index b9d65a390..1b7c03747 100644 --- a/Storage/Cartridge/Formats/BinaryDump.hpp +++ b/Storage/Cartridge/Formats/BinaryDump.hpp @@ -11,12 +11,14 @@ #include "../Cartridge.hpp" +#include + namespace Storage { namespace Cartridge { class BinaryDump : public Cartridge { public: - BinaryDump(const char *file_name); + BinaryDump(const std::string &file_name); enum { ErrorNotAccessible diff --git a/Storage/Cartridge/Formats/PRG.cpp b/Storage/Cartridge/Formats/PRG.cpp index 165437c9f..6dfd75dfa 100644 --- a/Storage/Cartridge/Formats/PRG.cpp +++ b/Storage/Cartridge/Formats/PRG.cpp @@ -15,16 +15,16 @@ using namespace Storage::Cartridge; -PRG::PRG(const char *file_name) { +PRG::PRG(const std::string &file_name) { struct stat file_stats; - stat(file_name, &file_stats); + stat(file_name.c_str(), &file_stats); // accept only files sized less than 8kb if(file_stats.st_size > 0x2000 + 2) throw ErrorNotROM; // get the loading address, and the rest of the contents - FILE *file = std::fopen(file_name, "rb"); + FILE *file = std::fopen(file_name.c_str(), "rb"); int loading_address = fgetc(file); loading_address |= fgetc(file) << 8; diff --git a/Storage/Cartridge/Formats/PRG.hpp b/Storage/Cartridge/Formats/PRG.hpp index 00722d8e2..3dc52fbbc 100644 --- a/Storage/Cartridge/Formats/PRG.hpp +++ b/Storage/Cartridge/Formats/PRG.hpp @@ -11,12 +11,14 @@ #include "../Cartridge.hpp" +#include + namespace Storage { namespace Cartridge { class PRG : public Cartridge { public: - PRG(const char *file_name); + PRG(const std::string &file_name); enum { ErrorNotROM diff --git a/Storage/Disk/DiskImage/Formats/AcornADF.cpp b/Storage/Disk/DiskImage/Formats/AcornADF.cpp index 3ec74dbce..653b10bd2 100644 --- a/Storage/Disk/DiskImage/Formats/AcornADF.cpp +++ b/Storage/Disk/DiskImage/Formats/AcornADF.cpp @@ -17,7 +17,7 @@ namespace { using namespace Storage::Disk; -AcornADF::AcornADF(const char *file_name) : MFMSectorDump(file_name) { +AcornADF::AcornADF(const std::string &file_name) : MFMSectorDump(file_name) { // very loose validation: the file needs to be a multiple of 256 bytes // and not ungainly large if(file_.stats().st_size % static_cast(128 << sector_size)) throw ErrorNotAcornADF; diff --git a/Storage/Disk/DiskImage/Formats/AcornADF.hpp b/Storage/Disk/DiskImage/Formats/AcornADF.hpp index 4cd4466fa..7cd115308 100644 --- a/Storage/Disk/DiskImage/Formats/AcornADF.hpp +++ b/Storage/Disk/DiskImage/Formats/AcornADF.hpp @@ -11,6 +11,8 @@ #include "MFMSectorDump.hpp" +#include + namespace Storage { namespace Disk { @@ -25,7 +27,7 @@ class AcornADF: public MFMSectorDump { @throws ErrorCantOpen if this file can't be opened. @throws ErrorNotAcornADF if the file doesn't appear to contain an Acorn .ADF format image. */ - AcornADF(const char *file_name); + AcornADF(const std::string &file_name); enum { ErrorNotAcornADF, diff --git a/Storage/Disk/DiskImage/Formats/CPCDSK.cpp b/Storage/Disk/DiskImage/Formats/CPCDSK.cpp index 5d972926a..2fa9f5751 100644 --- a/Storage/Disk/DiskImage/Formats/CPCDSK.cpp +++ b/Storage/Disk/DiskImage/Formats/CPCDSK.cpp @@ -17,7 +17,7 @@ using namespace Storage::Disk; -CPCDSK::CPCDSK(const char *file_name) : +CPCDSK::CPCDSK(const std::string &file_name) : file_name_(file_name), is_extended_(false) { FileHolder file(file_name); diff --git a/Storage/Disk/DiskImage/Formats/CPCDSK.hpp b/Storage/Disk/DiskImage/Formats/CPCDSK.hpp index e689d765c..5d19db4dc 100644 --- a/Storage/Disk/DiskImage/Formats/CPCDSK.hpp +++ b/Storage/Disk/DiskImage/Formats/CPCDSK.hpp @@ -13,6 +13,7 @@ #include "../../../FileHolder.hpp" #include "../../Encodings/MFM/Sector.hpp" +#include #include namespace Storage { @@ -29,7 +30,7 @@ class CPCDSK: public DiskImage { @throws ErrorCantOpen if this file can't be opened. @throws ErrorNotAcornADF if the file doesn't appear to contain an Acorn .ADF format image. */ - CPCDSK(const char *file_name); + CPCDSK(const std::string &file_name); enum { ErrorNotCPCDSK, diff --git a/Storage/Disk/DiskImage/Formats/D64.cpp b/Storage/Disk/DiskImage/Formats/D64.cpp index e16fe4cf6..8522b7319 100644 --- a/Storage/Disk/DiskImage/Formats/D64.cpp +++ b/Storage/Disk/DiskImage/Formats/D64.cpp @@ -17,7 +17,7 @@ using namespace Storage::Disk; -D64::D64(const char *file_name) : +D64::D64(const std::string &file_name) : file_(file_name) { // in D64, this is it for validation without imposing potential false-negative tests — check that // the file size appears to be correct. Stone-age stuff. @@ -29,10 +29,9 @@ D64::D64(const char *file_name) : // then, ostensibly, this is a valid file. Hmmm. Pick a disk ID as a function of the file_name, // being the most stable thing available disk_id_ = 0; - while(*file_name) { - disk_id_ ^= file_name[0]; + for(const auto &character: file_name) { + disk_id_ ^= character; disk_id_ = static_cast((disk_id_ << 2) ^ (disk_id_ >> 13)); - file_name++; } } diff --git a/Storage/Disk/DiskImage/Formats/D64.hpp b/Storage/Disk/DiskImage/Formats/D64.hpp index ea835d3dd..d395ecd15 100644 --- a/Storage/Disk/DiskImage/Formats/D64.hpp +++ b/Storage/Disk/DiskImage/Formats/D64.hpp @@ -26,7 +26,7 @@ class D64: public DiskImage { @throws ErrorCantOpen if this file can't be opened. @throws ErrorNotD64 if the file doesn't appear to contain a .D64 format image. */ - D64(const char *file_name); + D64(const std::string &file_name); enum { ErrorNotD64, diff --git a/Storage/Disk/DiskImage/Formats/DMK.cpp b/Storage/Disk/DiskImage/Formats/DMK.cpp index 39eac8df1..13a1af8c6 100644 --- a/Storage/Disk/DiskImage/Formats/DMK.cpp +++ b/Storage/Disk/DiskImage/Formats/DMK.cpp @@ -32,7 +32,7 @@ std::unique_ptr new_encoder(Storage::Disk::PCM } -DMK::DMK(const char *file_name) : +DMK::DMK(const std::string &file_name) : file_(file_name) { // Determine whether this DMK represents a read-only disk (whether intentionally, // or by virtue of placement). diff --git a/Storage/Disk/DiskImage/Formats/DMK.hpp b/Storage/Disk/DiskImage/Formats/DMK.hpp index ce16ae7ee..e0b616829 100644 --- a/Storage/Disk/DiskImage/Formats/DMK.hpp +++ b/Storage/Disk/DiskImage/Formats/DMK.hpp @@ -12,6 +12,8 @@ #include "../DiskImage.hpp" #include "../../../FileHolder.hpp" +#include + namespace Storage { namespace Disk { @@ -26,7 +28,7 @@ class DMK: public DiskImage { @throws ErrorNotDMK if this file doesn't appear to be a DMK. */ - DMK(const char *file_name); + DMK(const std::string &file_name); enum { ErrorNotDMK diff --git a/Storage/Disk/DiskImage/Formats/G64.cpp b/Storage/Disk/DiskImage/Formats/G64.cpp index ade35d6b9..c80460c88 100644 --- a/Storage/Disk/DiskImage/Formats/G64.cpp +++ b/Storage/Disk/DiskImage/Formats/G64.cpp @@ -16,7 +16,7 @@ using namespace Storage::Disk; -G64::G64(const char *file_name) : +G64::G64(const std::string &file_name) : file_(file_name) { // read and check the file signature if(!file_.check_signature("GCR-1541")) throw ErrorNotG64; diff --git a/Storage/Disk/DiskImage/Formats/G64.hpp b/Storage/Disk/DiskImage/Formats/G64.hpp index a48ea2511..c10ef7e04 100644 --- a/Storage/Disk/DiskImage/Formats/G64.hpp +++ b/Storage/Disk/DiskImage/Formats/G64.hpp @@ -12,6 +12,8 @@ #include "../DiskImage.hpp" #include "../../../FileHolder.hpp" +#include + namespace Storage { namespace Disk { @@ -27,7 +29,7 @@ class G64: public DiskImage { @throws ErrorNotG64 if the file doesn't appear to contain a .G64 format image. @throws ErrorUnknownVersion if this file appears to be a .G64 but has an unrecognised version number. */ - G64(const char *file_name); + G64(const std::string &file_name); enum { ErrorCantOpen, diff --git a/Storage/Disk/DiskImage/Formats/HFE.cpp b/Storage/Disk/DiskImage/Formats/HFE.cpp index d9a141da6..14e0c0004 100644 --- a/Storage/Disk/DiskImage/Formats/HFE.cpp +++ b/Storage/Disk/DiskImage/Formats/HFE.cpp @@ -14,7 +14,7 @@ using namespace Storage::Disk; -HFE::HFE(const char *file_name) : +HFE::HFE(const std::string &file_name) : file_(file_name) { if(!file_.check_signature("HXCPICFE")) throw ErrorNotHFE; diff --git a/Storage/Disk/DiskImage/Formats/HFE.hpp b/Storage/Disk/DiskImage/Formats/HFE.hpp index 0442ea39a..ab1a274b9 100644 --- a/Storage/Disk/DiskImage/Formats/HFE.hpp +++ b/Storage/Disk/DiskImage/Formats/HFE.hpp @@ -12,6 +12,8 @@ #include "../DiskImage.hpp" #include "../../../FileHolder.hpp" +#include + namespace Storage { namespace Disk { @@ -26,7 +28,7 @@ class HFE: public DiskImage { @throws ErrorCantOpen if this file can't be opened. @throws ErrorNotSSD if the file doesn't appear to contain a .SSD format image. */ - HFE(const char *file_name); + HFE(const std::string &file_name); ~HFE(); enum { diff --git a/Storage/Disk/DiskImage/Formats/MFMSectorDump.cpp b/Storage/Disk/DiskImage/Formats/MFMSectorDump.cpp index 1bdd1e5d6..b83f4a697 100644 --- a/Storage/Disk/DiskImage/Formats/MFMSectorDump.cpp +++ b/Storage/Disk/DiskImage/Formats/MFMSectorDump.cpp @@ -12,7 +12,7 @@ using namespace Storage::Disk; -MFMSectorDump::MFMSectorDump(const char *file_name) : file_(file_name) {} +MFMSectorDump::MFMSectorDump(const std::string &file_name) : file_(file_name) {} void MFMSectorDump::set_geometry(int sectors_per_track, uint8_t sector_size, uint8_t first_sector, bool is_double_density) { sectors_per_track_ = sectors_per_track; diff --git a/Storage/Disk/DiskImage/Formats/MFMSectorDump.hpp b/Storage/Disk/DiskImage/Formats/MFMSectorDump.hpp index ddb43cfa1..14b5d6803 100644 --- a/Storage/Disk/DiskImage/Formats/MFMSectorDump.hpp +++ b/Storage/Disk/DiskImage/Formats/MFMSectorDump.hpp @@ -12,6 +12,8 @@ #include "../DiskImage.hpp" #include "../../../FileHolder.hpp" +#include + namespace Storage { namespace Disk { @@ -20,7 +22,7 @@ namespace Disk { */ class MFMSectorDump: public DiskImage { public: - MFMSectorDump(const char *file_name); + MFMSectorDump(const std::string &file_name); void set_geometry(int sectors_per_track, uint8_t sector_size, uint8_t first_sector, bool is_double_density); bool get_is_read_only() override; diff --git a/Storage/Disk/DiskImage/Formats/MSXDSK.cpp b/Storage/Disk/DiskImage/Formats/MSXDSK.cpp index c4b0fe85a..9fefffffd 100644 --- a/Storage/Disk/DiskImage/Formats/MSXDSK.cpp +++ b/Storage/Disk/DiskImage/Formats/MSXDSK.cpp @@ -17,7 +17,7 @@ namespace { using namespace Storage::Disk; -MSXDSK::MSXDSK(const char *file_name) : +MSXDSK::MSXDSK(const std::string &file_name) : MFMSectorDump(file_name) { // The only sanity check here is whether a sensible // geometry can be guessed. diff --git a/Storage/Disk/DiskImage/Formats/MSXDSK.hpp b/Storage/Disk/DiskImage/Formats/MSXDSK.hpp index ae64158e4..0b6fba53c 100644 --- a/Storage/Disk/DiskImage/Formats/MSXDSK.hpp +++ b/Storage/Disk/DiskImage/Formats/MSXDSK.hpp @@ -11,6 +11,8 @@ #include "MFMSectorDump.hpp" +#include + namespace Storage { namespace Disk { @@ -20,7 +22,7 @@ namespace Disk { */ class MSXDSK: public MFMSectorDump { public: - MSXDSK(const char *file_name); + MSXDSK(const std::string &file_name); enum { ErrorNotMSXDSK, diff --git a/Storage/Disk/DiskImage/Formats/OricMFMDSK.cpp b/Storage/Disk/DiskImage/Formats/OricMFMDSK.cpp index e638caf10..d43700067 100644 --- a/Storage/Disk/DiskImage/Formats/OricMFMDSK.cpp +++ b/Storage/Disk/DiskImage/Formats/OricMFMDSK.cpp @@ -16,7 +16,7 @@ using namespace Storage::Disk; -OricMFMDSK::OricMFMDSK(const char *file_name) : +OricMFMDSK::OricMFMDSK(const std::string &file_name) : file_(file_name) { if(!file_.check_signature("MFM_DISK")) throw ErrorNotOricMFMDSK; diff --git a/Storage/Disk/DiskImage/Formats/OricMFMDSK.hpp b/Storage/Disk/DiskImage/Formats/OricMFMDSK.hpp index 0e00eb31f..c6b6d60be 100644 --- a/Storage/Disk/DiskImage/Formats/OricMFMDSK.hpp +++ b/Storage/Disk/DiskImage/Formats/OricMFMDSK.hpp @@ -12,6 +12,8 @@ #include "../DiskImage.hpp" #include "../../../FileHolder.hpp" +#include + namespace Storage { namespace Disk { @@ -25,7 +27,7 @@ class OricMFMDSK: public DiskImage { @throws ErrorNotOricMFMDSK if the file doesn't appear to contain an Oric MFM format image. */ - OricMFMDSK(const char *file_name); + OricMFMDSK(const std::string &file_name); enum { ErrorNotOricMFMDSK, diff --git a/Storage/Disk/DiskImage/Formats/SSD.cpp b/Storage/Disk/DiskImage/Formats/SSD.cpp index 31acee2c8..280521d7d 100644 --- a/Storage/Disk/DiskImage/Formats/SSD.cpp +++ b/Storage/Disk/DiskImage/Formats/SSD.cpp @@ -19,7 +19,7 @@ namespace { using namespace Storage::Disk; -SSD::SSD(const char *file_name) : MFMSectorDump(file_name) { +SSD::SSD(const std::string &file_name) : MFMSectorDump(file_name) { // very loose validation: the file needs to be a multiple of 256 bytes // and not ungainly large @@ -28,7 +28,7 @@ SSD::SSD(const char *file_name) : MFMSectorDump(file_name) { if(file_.stats().st_size > 800*256) throw ErrorNotSSD; // this has two heads if the suffix is .dsd, one if it's .ssd - head_count_ = (tolower(file_name[std::strlen(file_name) - 3]) == 'd') ? 2 : 1; + head_count_ = (tolower(file_name[file_name.size() - 3]) == 'd') ? 2 : 1; track_count_ = static_cast(file_.stats().st_size / (256 * 10)); if(track_count_ < 40) track_count_ = 40; else if(track_count_ < 80) track_count_ = 80; diff --git a/Storage/Disk/DiskImage/Formats/SSD.hpp b/Storage/Disk/DiskImage/Formats/SSD.hpp index 901595ca5..58f67027c 100644 --- a/Storage/Disk/DiskImage/Formats/SSD.hpp +++ b/Storage/Disk/DiskImage/Formats/SSD.hpp @@ -25,7 +25,7 @@ class SSD: public MFMSectorDump { @throws ErrorCantOpen if this file can't be opened. @throws ErrorNotSSD if the file doesn't appear to contain a .SSD format image. */ - SSD(const char *file_name); + SSD(const std::string &file_name); enum { ErrorNotSSD, diff --git a/Storage/Tape/Formats/CAS.cpp b/Storage/Tape/Formats/CAS.cpp index cc6872acb..6c75d6a66 100644 --- a/Storage/Tape/Formats/CAS.cpp +++ b/Storage/Tape/Formats/CAS.cpp @@ -17,7 +17,7 @@ namespace { const uint8_t header_signature[8] = {0x1f, 0xa6, 0xde, 0xba, 0xcc, 0x13, 0x7d, 0x74}; } -CAS::CAS(const char *file_name) { +CAS::CAS(const std::string &file_name) { Storage::FileHolder file(file_name); uint8_t lookahead[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; diff --git a/Storage/Tape/Formats/CAS.hpp b/Storage/Tape/Formats/CAS.hpp index fbd7e3a5f..94d9bd676 100644 --- a/Storage/Tape/Formats/CAS.hpp +++ b/Storage/Tape/Formats/CAS.hpp @@ -13,6 +13,7 @@ #include "../../FileHolder.hpp" #include +#include #include namespace Storage { @@ -28,7 +29,7 @@ class CAS: public Tape { @throws ErrorNotCAS if this file could not be opened and recognised as a valid CAS file. */ - CAS(const char *file_name); + CAS(const std::string &file_name); enum { ErrorNotCAS diff --git a/Storage/Tape/Formats/CSW.cpp b/Storage/Tape/Formats/CSW.cpp index 10d7d6402..1662a4481 100644 --- a/Storage/Tape/Formats/CSW.cpp +++ b/Storage/Tape/Formats/CSW.cpp @@ -12,7 +12,7 @@ using namespace Storage::Tape; -CSW::CSW(const char *file_name) : +CSW::CSW(const std::string &file_name) : source_data_pointer_(0) { Storage::FileHolder file(file_name); if(file.stats().st_size < 0x20) throw ErrorNotCSW; diff --git a/Storage/Tape/Formats/CSW.hpp b/Storage/Tape/Formats/CSW.hpp index fd1e0d179..21fcfdc17 100644 --- a/Storage/Tape/Formats/CSW.hpp +++ b/Storage/Tape/Formats/CSW.hpp @@ -12,8 +12,9 @@ #include "../Tape.hpp" #include "../../FileHolder.hpp" -#include +#include #include +#include namespace Storage { namespace Tape { @@ -28,7 +29,7 @@ class CSW: public Tape { @throws ErrorNotCSW if this file could not be opened and recognised as a valid CSW file. */ - CSW(const char *file_name); + CSW(const std::string &file_name); enum class CompressionType { RLE, diff --git a/Storage/Tape/Formats/CommodoreTAP.cpp b/Storage/Tape/Formats/CommodoreTAP.cpp index 74c7747fb..e38197e10 100644 --- a/Storage/Tape/Formats/CommodoreTAP.cpp +++ b/Storage/Tape/Formats/CommodoreTAP.cpp @@ -12,7 +12,7 @@ using namespace Storage::Tape; -CommodoreTAP::CommodoreTAP(const char *file_name) : +CommodoreTAP::CommodoreTAP(const std::string &file_name) : file_(file_name) { if(!file_.check_signature("C64-TAPE-RAW")) diff --git a/Storage/Tape/Formats/CommodoreTAP.hpp b/Storage/Tape/Formats/CommodoreTAP.hpp index ac3e637f1..8da500ab0 100644 --- a/Storage/Tape/Formats/CommodoreTAP.hpp +++ b/Storage/Tape/Formats/CommodoreTAP.hpp @@ -11,7 +11,9 @@ #include "../Tape.hpp" #include "../../FileHolder.hpp" + #include +#include namespace Storage { namespace Tape { @@ -26,7 +28,7 @@ class CommodoreTAP: public Tape { @throws ErrorNotCommodoreTAP if this file could not be opened and recognised as a valid Commodore-format TAP. */ - CommodoreTAP(const char *file_name); + CommodoreTAP(const std::string &file_name); enum { ErrorNotCommodoreTAP diff --git a/Storage/Tape/Formats/OricTAP.cpp b/Storage/Tape/Formats/OricTAP.cpp index b5f6e8825..df7574f48 100644 --- a/Storage/Tape/Formats/OricTAP.cpp +++ b/Storage/Tape/Formats/OricTAP.cpp @@ -12,7 +12,7 @@ using namespace Storage::Tape; -OricTAP::OricTAP(const char *file_name) : +OricTAP::OricTAP(const std::string &file_name) : file_(file_name) { // check the file signature diff --git a/Storage/Tape/Formats/OricTAP.hpp b/Storage/Tape/Formats/OricTAP.hpp index 5e1214ce9..eabea004f 100644 --- a/Storage/Tape/Formats/OricTAP.hpp +++ b/Storage/Tape/Formats/OricTAP.hpp @@ -11,7 +11,9 @@ #include "../Tape.hpp" #include "../../FileHolder.hpp" + #include +#include namespace Storage { namespace Tape { @@ -26,7 +28,7 @@ class OricTAP: public Tape { @throws ErrorNotOricTAP if this file could not be opened and recognised as a valid Oric-format TAP. */ - OricTAP(const char *file_name); + OricTAP(const std::string &file_name); enum { ErrorNotOricTAP diff --git a/Storage/Tape/Formats/TZX.cpp b/Storage/Tape/Formats/TZX.cpp index d9641004b..2695fae19 100644 --- a/Storage/Tape/Formats/TZX.cpp +++ b/Storage/Tape/Formats/TZX.cpp @@ -17,7 +17,7 @@ const unsigned int StandardTZXClock = 3500000; const unsigned int TZXClockMSMultiplier = 3500; } -TZX::TZX(const char *file_name) : +TZX::TZX(const std::string &file_name) : file_(file_name), current_level_(false) { diff --git a/Storage/Tape/Formats/TZX.hpp b/Storage/Tape/Formats/TZX.hpp index fb459a035..46ed24030 100644 --- a/Storage/Tape/Formats/TZX.hpp +++ b/Storage/Tape/Formats/TZX.hpp @@ -12,6 +12,8 @@ #include "../PulseQueuedTape.hpp" #include "../../FileHolder.hpp" +#include + namespace Storage { namespace Tape { @@ -25,7 +27,7 @@ class TZX: public PulseQueuedTape { @throws ErrorNotTZX if this file could not be opened and recognised as a valid TZX file. */ - TZX(const char *file_name); + TZX(const std::string &file_name); enum { ErrorNotTZX diff --git a/Storage/Tape/Formats/TapePRG.cpp b/Storage/Tape/Formats/TapePRG.cpp index e1131fa8d..f5916a203 100644 --- a/Storage/Tape/Formats/TapePRG.cpp +++ b/Storage/Tape/Formats/TapePRG.cpp @@ -48,7 +48,7 @@ using namespace Storage::Tape; -PRG::PRG(const char *file_name) : +PRG::PRG(const std::string &file_name) : file_(file_name) { // There's really no way to validate other than that if this file is larger than 64kb, diff --git a/Storage/Tape/Formats/TapePRG.hpp b/Storage/Tape/Formats/TapePRG.hpp index 907f09a3b..99e8e6285 100644 --- a/Storage/Tape/Formats/TapePRG.hpp +++ b/Storage/Tape/Formats/TapePRG.hpp @@ -11,7 +11,9 @@ #include "../Tape.hpp" #include "../../FileHolder.hpp" + #include +#include namespace Storage { namespace Tape { @@ -27,7 +29,7 @@ class PRG: public Tape { @param file_name The name of the file to load. @throws ErrorBadFormat if this file could not be opened and recognised as the specified type. */ - PRG(const char *file_name); + PRG(const std::string &file_name); enum { ErrorBadFormat diff --git a/Storage/Tape/Formats/TapeUEF.cpp b/Storage/Tape/Formats/TapeUEF.cpp index 8f06fc129..064eaf5bf 100644 --- a/Storage/Tape/Formats/TapeUEF.cpp +++ b/Storage/Tape/Formats/TapeUEF.cpp @@ -68,8 +68,8 @@ static int gzget32(gzFile file) { using namespace Storage::Tape; -UEF::UEF(const char *file_name) { - file_ = gzopen(file_name, "rb"); +UEF::UEF(const std::string &file_name) { + file_ = gzopen(file_name.c_str(), "rb"); char identifier[10]; int bytes_read = gzread(file_, identifier, 10); diff --git a/Storage/Tape/Formats/TapeUEF.hpp b/Storage/Tape/Formats/TapeUEF.hpp index 989846261..938720f22 100644 --- a/Storage/Tape/Formats/TapeUEF.hpp +++ b/Storage/Tape/Formats/TapeUEF.hpp @@ -13,8 +13,9 @@ #include "../../TargetPlatforms.hpp" -#include #include +#include +#include namespace Storage { namespace Tape { @@ -29,7 +30,7 @@ class UEF : public PulseQueuedTape, public TargetPlatform::TypeDistinguisher { @throws ErrorNotUEF if this file could not be opened and recognised as a valid UEF. */ - UEF(const char *file_name); + UEF(const std::string &file_name); ~UEF(); enum { diff --git a/Storage/Tape/Formats/ZX80O81P.cpp b/Storage/Tape/Formats/ZX80O81P.cpp index b81b5af63..1b1cd0831 100644 --- a/Storage/Tape/Formats/ZX80O81P.cpp +++ b/Storage/Tape/Formats/ZX80O81P.cpp @@ -11,7 +11,7 @@ using namespace Storage::Tape; -ZX80O81P::ZX80O81P(const char *file_name) { +ZX80O81P::ZX80O81P(const std::string &file_name) { Storage::FileHolder file(file_name); // Grab the actual file contents diff --git a/Storage/Tape/Formats/ZX80O81P.hpp b/Storage/Tape/Formats/ZX80O81P.hpp index 96ec960f6..060a01c53 100644 --- a/Storage/Tape/Formats/ZX80O81P.hpp +++ b/Storage/Tape/Formats/ZX80O81P.hpp @@ -15,6 +15,7 @@ #include "../../TargetPlatforms.hpp" #include +#include #include namespace Storage { @@ -30,7 +31,7 @@ class ZX80O81P: public Tape, public TargetPlatform::TypeDistinguisher { @throws ErrorNotZX80O81P if this file could not be opened and recognised as a valid ZX80-format .O. */ - ZX80O81P(const char *file_name); + ZX80O81P(const std::string &file_name); enum { ErrorNotZX80O81P