| 1 | //============================================================================ | 
|---|
| 2 | // | 
|---|
| 3 | //   SSSS    tt          lll  lll | 
|---|
| 4 | //  SS  SS   tt           ll   ll | 
|---|
| 5 | //  SS     tttttt  eeee   ll   ll   aaaa | 
|---|
| 6 | //   SSSS    tt   ee  ee  ll   ll      aa | 
|---|
| 7 | //      SS   tt   eeeeee  ll   ll   aaaaa  --  "An Atari 2600 VCS Emulator" | 
|---|
| 8 | //  SS  SS   tt   ee      ll   ll  aa  aa | 
|---|
| 9 | //   SSSS     ttt  eeeee llll llll  aaaaa | 
|---|
| 10 | // | 
|---|
| 11 | // Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony | 
|---|
| 12 | // and the Stella Team | 
|---|
| 13 | // | 
|---|
| 14 | // See the file "License.txt" for information on usage and redistribution of | 
|---|
| 15 | // this file, and for a DISCLAIMER OF ALL WARRANTIES. | 
|---|
| 16 | //============================================================================ | 
|---|
| 17 |  | 
|---|
| 18 | #ifndef BANKSWITCH_HXX | 
|---|
| 19 | #define BANKSWITCH_HXX | 
|---|
| 20 |  | 
|---|
| 21 | #include <map> | 
|---|
| 22 |  | 
|---|
| 23 | #include "FSNode.hxx" | 
|---|
| 24 | #include "bspf.hxx" | 
|---|
| 25 |  | 
|---|
| 26 | /** | 
|---|
| 27 | This class contains all information about the bankswitch schemes supported | 
|---|
| 28 | by Stella, as well as convenience functions to map from scheme type to | 
|---|
| 29 | readable string, and vice-versa. | 
|---|
| 30 |  | 
|---|
| 31 | It also includes all logic that determines what a 'valid' rom filename is. | 
|---|
| 32 | That is, all extensions that represent valid schemes. | 
|---|
| 33 |  | 
|---|
| 34 | @author  Stephen Anthony | 
|---|
| 35 | */ | 
|---|
| 36 | class Bankswitch | 
|---|
| 37 | { | 
|---|
| 38 | public: | 
|---|
| 39 | // Currently supported bankswitch schemes | 
|---|
| 40 | enum class Type { | 
|---|
| 41 | _AUTO,  _0840,    _2IN1,  _4IN1,   _8IN1,   _16IN1, _32IN1, | 
|---|
| 42 | _64IN1, _128IN1,  _2K,    _3E,     _3EP,    _3F,    _4A50, | 
|---|
| 43 | _4K,    _4KSC,    _AR,    _BF,     _BFSC,   _BUS,   _CDF, | 
|---|
| 44 | _CM,    _CTY,     _CV,    _CVP,    _DASH,   _DF,    _DFSC, | 
|---|
| 45 | _DPC,   _DPCP,    _E0,    _E7,     _E78K,   _EF,    _EFSC, | 
|---|
| 46 | _F0,    _F4,      _F4SC,  _F6,     _F6SC,   _F8,    _F8SC, | 
|---|
| 47 | _FA,    _FA2,     _FC,    _FE,     _MDM,    _SB,    _UA, | 
|---|
| 48 | _UASW,  _WD,    _WDSW,    _X07, | 
|---|
| 49 | #ifdef CUSTOM_ARM | 
|---|
| 50 | _CUSTOM, | 
|---|
| 51 | #endif | 
|---|
| 52 | NumSchemes | 
|---|
| 53 | }; | 
|---|
| 54 |  | 
|---|
| 55 | // Info about the various bankswitch schemes, useful for displaying | 
|---|
| 56 | // in GUI dropdown boxes, etc | 
|---|
| 57 | struct Description { | 
|---|
| 58 | const char* const name; | 
|---|
| 59 | const char* const desc; | 
|---|
| 60 | }; | 
|---|
| 61 | static Description BSList[int(Type::NumSchemes)]; | 
|---|
| 62 |  | 
|---|
| 63 | public: | 
|---|
| 64 | // Convert BSType enum to string | 
|---|
| 65 | static string typeToName(Bankswitch::Type type); | 
|---|
| 66 |  | 
|---|
| 67 | // Convert string to BSType enum | 
|---|
| 68 | static Bankswitch::Type nameToType(const string& name); | 
|---|
| 69 |  | 
|---|
| 70 | // Determine bankswitch type by filename extension | 
|---|
| 71 | // Use '_AUTO' if unknown | 
|---|
| 72 | static Bankswitch::Type typeFromExtension(const FilesystemNode& file); | 
|---|
| 73 |  | 
|---|
| 74 | /** | 
|---|
| 75 | Is this a valid ROM filename (does it have a valid extension?). | 
|---|
| 76 |  | 
|---|
| 77 | @param name  Filename of potential ROM file | 
|---|
| 78 | @param ext   The extension extracted from the given file | 
|---|
| 79 | */ | 
|---|
| 80 | static bool isValidRomName(const string& name, string& ext); | 
|---|
| 81 |  | 
|---|
| 82 | /** | 
|---|
| 83 | Convenience functions for different parameter types. | 
|---|
| 84 | */ | 
|---|
| 85 | static bool isValidRomName(const FilesystemNode& name, string& ext); | 
|---|
| 86 | static bool isValidRomName(const FilesystemNode& name); | 
|---|
| 87 | static bool isValidRomName(const string& name); | 
|---|
| 88 |  | 
|---|
| 89 | private: | 
|---|
| 90 | struct TypeComparator { | 
|---|
| 91 | bool operator() (const string& a, const string& b) const { | 
|---|
| 92 | return BSPF::compareIgnoreCase(a, b) < 0; | 
|---|
| 93 | } | 
|---|
| 94 | }; | 
|---|
| 95 | using ExtensionMap = std::map<string, Bankswitch::Type, TypeComparator>; | 
|---|
| 96 | static ExtensionMap ourExtensions; | 
|---|
| 97 |  | 
|---|
| 98 | using NameToTypeMap = std::map<string, Bankswitch::Type, TypeComparator>; | 
|---|
| 99 | static NameToTypeMap ourNameToTypes; | 
|---|
| 100 |  | 
|---|
| 101 | private: | 
|---|
| 102 | // Following constructors and assignment operators not supported | 
|---|
| 103 | Bankswitch() = delete; | 
|---|
| 104 | Bankswitch(const Bankswitch&) = delete; | 
|---|
| 105 | Bankswitch(Bankswitch&&) = delete; | 
|---|
| 106 | Bankswitch& operator=(const Bankswitch&) = delete; | 
|---|
| 107 | Bankswitch& operator=(Bankswitch&&) = delete; | 
|---|
| 108 | }; | 
|---|
| 109 |  | 
|---|
| 110 | #endif | 
|---|
| 111 |  | 
|---|