2021-10-23 19:00:31 +00:00
|
|
|
/*
|
|
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
2023-06-18 21:15:08 +00:00
|
|
|
Copyright (C) 2018-23 divingkatae and maximum
|
2021-10-23 19:00:31 +00:00
|
|
|
(theweirdo) spatium
|
|
|
|
|
|
|
|
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-08-22 18:05:08 +00:00
|
|
|
#include <cinttypes>
|
2022-02-16 23:50:37 +00:00
|
|
|
#include <limits>
|
2020-08-22 18:05:08 +00:00
|
|
|
#include <map>
|
2022-02-16 23:50:37 +00:00
|
|
|
#include <string>
|
2020-10-09 13:58:47 +00:00
|
|
|
#include <vector>
|
2023-11-03 07:21:33 +00:00
|
|
|
#include <memory>
|
2020-08-22 18:05:08 +00:00
|
|
|
|
2020-08-26 03:07:02 +00:00
|
|
|
#ifndef MACHINE_PROPERTIES_H
|
|
|
|
#define MACHINE_PROPERTIES_H
|
2020-10-06 09:01:13 +00:00
|
|
|
|
2020-08-22 18:05:08 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2020-10-06 09:01:13 +00:00
|
|
|
/** Property types. */
|
|
|
|
enum PropType : int {
|
|
|
|
PROP_TYPE_UNKNOWN = 0,
|
|
|
|
PROP_TYPE_STRING = 1,
|
|
|
|
PROP_TYPE_INTEGER = 2,
|
2022-07-19 21:45:41 +00:00
|
|
|
PROP_TYPE_BINARY = 3, // binary aka on/off switch
|
2020-10-06 09:01:13 +00:00
|
|
|
};
|
|
|
|
|
2020-10-09 13:58:47 +00:00
|
|
|
/** Check types for property values. */
|
|
|
|
enum CheckType : int {
|
|
|
|
CHECK_TYPE_NONE = 0,
|
|
|
|
CHECK_TYPE_RANGE = 1,
|
2020-10-14 14:19:11 +00:00
|
|
|
CHECK_TYPE_LIST = 2,
|
2020-10-09 13:58:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Abstract base class for properties. */
|
2020-10-06 09:01:13 +00:00
|
|
|
class BasicProperty {
|
2020-08-22 18:05:08 +00:00
|
|
|
public:
|
2020-10-06 09:01:13 +00:00
|
|
|
BasicProperty(PropType type, string val) {
|
|
|
|
this->type = type;
|
|
|
|
set_string(val);
|
2020-08-22 18:05:08 +00:00
|
|
|
}
|
|
|
|
|
2020-10-06 09:01:13 +00:00
|
|
|
virtual ~BasicProperty() = default;
|
|
|
|
|
2020-10-09 13:58:47 +00:00
|
|
|
/* Clone method for copying derived property objects. */
|
2020-10-06 09:01:13 +00:00
|
|
|
virtual BasicProperty* clone() const = 0;
|
|
|
|
|
2021-12-05 18:16:39 +00:00
|
|
|
virtual string get_string() {
|
2020-10-06 09:01:13 +00:00
|
|
|
return this->val;
|
2020-09-20 21:25:29 +00:00
|
|
|
}
|
|
|
|
|
2021-12-05 18:16:39 +00:00
|
|
|
virtual void set_string(string str) {
|
2020-10-06 09:01:13 +00:00
|
|
|
this->val = str;
|
2020-08-22 18:05:08 +00:00
|
|
|
}
|
|
|
|
|
2021-12-05 18:16:39 +00:00
|
|
|
virtual PropType get_type() {
|
2020-10-06 09:01:13 +00:00
|
|
|
return this->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
PropType type;
|
|
|
|
string val;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-10-09 13:58:47 +00:00
|
|
|
/** Property class that holds a string value. */
|
2020-10-06 09:01:13 +00:00
|
|
|
class StrProperty : public BasicProperty {
|
|
|
|
public:
|
|
|
|
StrProperty(string str)
|
2021-12-05 18:16:39 +00:00
|
|
|
: BasicProperty(PROP_TYPE_STRING, str)
|
|
|
|
{
|
|
|
|
this->check_type = CHECK_TYPE_NONE;
|
|
|
|
this->vec.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* construct a string property with a list of valid values. */
|
|
|
|
StrProperty(string str, vector<string> vec)
|
|
|
|
: BasicProperty(PROP_TYPE_STRING, str)
|
|
|
|
{
|
|
|
|
this->check_type = CHECK_TYPE_LIST;
|
|
|
|
this->vec = vec;
|
|
|
|
}
|
2020-10-06 09:01:13 +00:00
|
|
|
|
|
|
|
BasicProperty* clone() const { return new StrProperty(*this); }
|
2021-12-05 18:16:39 +00:00
|
|
|
|
|
|
|
/* override BasicProperty::set_string() and perform checks */
|
|
|
|
void set_string(string str);
|
|
|
|
|
|
|
|
string get_valid_values_as_str();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool check_val(string str);
|
|
|
|
|
|
|
|
private:
|
|
|
|
CheckType check_type;
|
|
|
|
vector<string> vec;
|
2020-09-20 21:25:29 +00:00
|
|
|
};
|
|
|
|
|
2020-10-09 13:58:47 +00:00
|
|
|
/** Property class that holds an integer value. */
|
2020-10-06 09:01:13 +00:00
|
|
|
class IntProperty : public BasicProperty {
|
2020-09-20 21:25:29 +00:00
|
|
|
public:
|
2020-10-09 13:58:47 +00:00
|
|
|
/* construct an integer property without value check. */
|
|
|
|
IntProperty(uint32_t val)
|
|
|
|
: BasicProperty(PROP_TYPE_INTEGER, to_string(val))
|
2020-10-06 09:01:13 +00:00
|
|
|
{
|
2020-10-09 13:58:47 +00:00
|
|
|
this->int_val = val;
|
|
|
|
this->min = std::numeric_limits<uint32_t>::min();
|
|
|
|
this->max = std::numeric_limits<uint32_t>::max();
|
|
|
|
this->check_type = CHECK_TYPE_NONE;
|
|
|
|
this->vec.clear();
|
2020-09-20 21:25:29 +00:00
|
|
|
}
|
|
|
|
|
2020-10-09 13:58:47 +00:00
|
|
|
/* construct an integer property with a predefined range. */
|
|
|
|
IntProperty(uint32_t val, uint32_t min, uint32_t max)
|
|
|
|
: BasicProperty(PROP_TYPE_INTEGER, to_string(val))
|
2020-10-06 09:01:13 +00:00
|
|
|
{
|
2020-10-09 13:58:47 +00:00
|
|
|
this->int_val = val;
|
|
|
|
this->min = min;
|
|
|
|
this->max = max;
|
|
|
|
this->check_type = CHECK_TYPE_RANGE;
|
|
|
|
this->vec.clear();
|
|
|
|
}
|
2020-10-06 09:01:13 +00:00
|
|
|
|
2020-10-09 13:58:47 +00:00
|
|
|
/* construct an integer property with a list of valid values. */
|
|
|
|
IntProperty(uint32_t val, vector<uint32_t> vec)
|
|
|
|
: BasicProperty(PROP_TYPE_INTEGER, to_string(val))
|
|
|
|
{
|
|
|
|
this->int_val = val;
|
|
|
|
this->min = std::numeric_limits<uint32_t>::min();
|
|
|
|
this->max = std::numeric_limits<uint32_t>::max();
|
2020-10-14 14:19:11 +00:00
|
|
|
this->check_type = CHECK_TYPE_LIST;
|
2020-10-09 13:58:47 +00:00
|
|
|
this->vec = vec;
|
2020-09-20 21:25:29 +00:00
|
|
|
}
|
|
|
|
|
2020-10-06 09:01:13 +00:00
|
|
|
BasicProperty* clone() const { return new IntProperty(*this); }
|
|
|
|
|
2021-12-05 18:16:39 +00:00
|
|
|
uint32_t get_int();
|
2020-09-20 21:25:29 +00:00
|
|
|
|
2021-12-05 18:16:39 +00:00
|
|
|
string get_valid_values_as_str();
|
2020-10-14 14:19:11 +00:00
|
|
|
|
2020-10-09 13:58:47 +00:00
|
|
|
protected:
|
2021-12-05 18:16:39 +00:00
|
|
|
bool check_val(uint32_t val);
|
2020-10-09 13:58:47 +00:00
|
|
|
|
2020-09-20 21:25:29 +00:00
|
|
|
private:
|
2020-10-09 13:58:47 +00:00
|
|
|
uint32_t int_val;
|
|
|
|
CheckType check_type;
|
|
|
|
uint32_t min;
|
|
|
|
uint32_t max;
|
|
|
|
vector<uint32_t> vec;
|
2020-08-22 18:05:08 +00:00
|
|
|
};
|
|
|
|
|
2022-07-19 21:45:41 +00:00
|
|
|
/** Property class that holds a binary value. */
|
|
|
|
class BinProperty : public BasicProperty {
|
|
|
|
public:
|
|
|
|
BinProperty(int val)
|
|
|
|
: BasicProperty(PROP_TYPE_BINARY, (val & 1) ? "on" : "off")
|
|
|
|
{
|
|
|
|
this->bin_val = val & 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
BasicProperty* clone() const { return new BinProperty(*this); }
|
|
|
|
|
|
|
|
// override BasicProperty::set_string() and perform checks
|
|
|
|
void set_string(string str);
|
|
|
|
|
|
|
|
string get_valid_values_as_str() {
|
|
|
|
return string("on, off, ON, OFF");
|
|
|
|
};
|
|
|
|
|
|
|
|
int get_val() { return this->bin_val; };
|
|
|
|
|
|
|
|
private:
|
|
|
|
int bin_val;
|
|
|
|
};
|
|
|
|
|
2023-06-18 21:15:08 +00:00
|
|
|
void parse_device_path(string dev_path, string& bus_id, uint32_t& dev_num);
|
|
|
|
|
2020-10-09 13:58:47 +00:00
|
|
|
/** Special map type for specifying machine presets. */
|
2020-10-06 09:01:13 +00:00
|
|
|
typedef map<string, BasicProperty*> PropMap;
|
|
|
|
|
2020-10-09 13:58:47 +00:00
|
|
|
/** Global map that holds settings for the running machine. */
|
2020-10-06 09:01:13 +00:00
|
|
|
extern map<string, unique_ptr<BasicProperty>> gMachineSettings;
|
|
|
|
|
2020-10-09 13:58:47 +00:00
|
|
|
/** Conveniency macros to hide complex casts. */
|
|
|
|
#define GET_STR_PROP(name) \
|
|
|
|
dynamic_cast<StrProperty*>(gMachineSettings.at(name).get())->get_string()
|
|
|
|
|
2020-10-06 09:01:13 +00:00
|
|
|
#define GET_INT_PROP(name) \
|
|
|
|
dynamic_cast<IntProperty*>(gMachineSettings.at(name).get())->get_int()
|
|
|
|
|
2022-07-19 21:45:41 +00:00
|
|
|
#define GET_BIN_PROP(name) \
|
|
|
|
dynamic_cast<BinProperty*>(gMachineSettings.at(name).get())->get_val()
|
|
|
|
|
2023-06-18 21:15:08 +00:00
|
|
|
#endif // MACHINE_PROPERTIES_H
|