DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
include/setup.h
00001 /*
00002  *  Copyright (C) 2002-2013  The DOSBox Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 
00020 #ifndef DOSBOX_SETUP_H
00021 #define DOSBOX_SETUP_H
00022 
00023 #ifdef _MSC_VER
00024 //#pragma warning ( disable : 4786 )
00025 //#pragma warning ( disable : 4290 )
00026 #endif
00027 
00028 
00029 #ifndef CH_LIST
00030 #define CH_LIST
00031 #include <list>
00032 #endif
00033 
00034 #ifndef CH_VECTOR
00035 #define CH_VECTOR
00036 #include <vector>
00037 #endif
00038 
00039 #ifndef CH_STRING
00040 #define CH_STRING
00041 #include <string>
00042 #endif
00043 
00044 #ifndef CH_CSTDIO
00045 #define CH_CSTDIO
00046 #include <cstdio>
00047 #endif
00048 
00049 
00050 class Hex {
00051 private:
00052         int _hex;
00053 public:
00054         Hex(int in):_hex(in) { };
00055         Hex():_hex(0) { };
00056         bool operator==(Hex const& other) {return _hex == other._hex;}
00057         operator int () const { return _hex; }
00058    
00059 };
00060 
00061 class Value {
00062 /* 
00063  * Multitype storage container that is aware of the currently stored type in it.
00064  * Value st = "hello";
00065  * Value in = 1;
00066  * st = 12 //Exception
00067  * in = 12 //works
00068  */
00069 private:
00070         Hex _hex;
00071         bool _bool;
00072         int _int;
00073         std::string* _string;
00074         double _double;
00075 public:
00076         class WrongType { }; // Conversion error class
00077         enum Etype { V_NONE, V_HEX, V_BOOL, V_INT, V_STRING, V_DOUBLE,V_CURRENT} type;
00078         
00079         /* Constructors */
00080         Value()                      :_string(0),   type(V_NONE)                  { };
00081         Value(Hex in)                :_hex(in),     type(V_HEX)                   { };
00082         Value(int in)                :_int(in),     type(V_INT)                   { };
00083         Value(bool in)               :_bool(in),    type(V_BOOL)                  { };
00084         Value(double in)             :_double(in),  type(V_DOUBLE)                { };
00085         Value(std::string const& in) :_string(new std::string(in)),type(V_STRING) { };
00086         Value(char const * const in) :_string(new std::string(in)),type(V_STRING) { };
00087         Value(Value const& in):_string(0) {plaincopy(in);}
00088         ~Value() { destroy();};
00089         Value(std::string const& in,Etype _t) :_hex(0),_bool(false),_int(0),_string(0),_double(0),type(V_NONE) {SetValue(in,_t);}
00090 
00091         /* Assigment operators */
00092         Value& operator= (Hex in)                { return copy(Value(in));}
00093         Value& operator= (int in)                { return copy(Value(in));}
00094         Value& operator= (bool in)               { return copy(Value(in));}
00095         Value& operator= (double in)             { return copy(Value(in));}
00096         Value& operator= (std::string const& in) { return copy(Value(in));}
00097         Value& operator= (char const * const in) { return copy(Value(in));}
00098         Value& operator= (Value const& in)       { return copy(Value(in));}
00099 
00100         bool operator== (Value const & other);
00101         operator bool () const;
00102         operator Hex () const;
00103         operator int () const;
00104         operator double () const;
00105         operator char const* () const;
00106         bool SetValue(std::string const& in,Etype _type = V_CURRENT);
00107         std::string ToString() const;
00108 
00109 private:
00110         void destroy();
00111         Value& copy(Value const& in);
00112         void plaincopy(Value const& in);
00113         bool set_hex(std::string const& in);
00114         bool set_int(std::string const&in);
00115         bool set_bool(std::string const& in);
00116         void set_string(std::string const& in);
00117         bool set_double(std::string const& in);
00118 };
00119 
00120 class Property {
00121 public:
00122         struct Changeable { enum Value {Always, WhenIdle,OnlyAtStart};};
00123         const std::string propname;
00124 
00125         Property(std::string const& _propname, Changeable::Value when):propname(_propname),is_modified(false),change(when) { use_global_config_str=false; }
00126         void Set_values(const char * const * in);
00127         void Set_help(std::string const& str);
00128         char const* Get_help();
00129         virtual bool SetValue(std::string const& str)=0;
00130         Value const& GetValue() const { return value;}
00131         Value const& Get_Default_Value() const { return default_value; }
00132         //CheckValue returns true  if value is in suggested_values;
00133         //Type specific properties are encouraged to override this and check for type
00134         //specific features.
00135         virtual bool CheckValue(Value const& in, bool warn);
00136         //Set interval value to in or default if in is invalid. force always sets the value.
00137         bool SetVal(Value const& in, bool forced,bool warn=true,bool init=false) {
00138                 if(forced || CheckValue(in,warn)) {value = in; is_modified = !init; return true;} else { value = default_value; is_modified = false; return false;}}
00139         virtual ~Property(){ } 
00140         virtual const std::vector<Value>& GetValues() const;
00141         Value::Etype Get_type(){return default_value.type;}
00142         Changeable::Value getChange() {return change;}
00143         bool modified() const { return is_modified; };
00144 
00145 protected:
00146         Value value;
00147         bool is_modified;
00148         std::vector<Value> suggested_values;
00149         typedef std::vector<Value>::iterator iter;
00150         Value default_value;
00151         const Changeable::Value change;
00152         bool use_global_config_str;
00153         std::string help_string;
00154 };
00155 
00156 class Prop_int:public Property {
00157 public:
00158         Prop_int(std::string const& _propname,Changeable::Value when, int _value)
00159                 :Property(_propname,when) { 
00160                 default_value = value = _value;
00161                 min = max = -1;
00162         }
00163         Prop_int(std::string const&  _propname,Changeable::Value when, int _min,int _max,int _value)
00164                 :Property(_propname,when) { 
00165                 default_value = value = _value;
00166                 min = _min;
00167                 max = _max;
00168         }
00169         int getMin() { return min;}
00170         int getMax() { return max;}
00171         void SetMinMax(Value const& min,Value const& max) {this->min = min; this->max=max;}
00172         bool SetValue(std::string const& in);
00173         virtual ~Prop_int(){ }
00174         virtual bool CheckValue(Value const& in, bool warn);
00175 private:
00176         Value min,max;
00177 };
00178 
00179 class Prop_double:public Property {
00180 public:
00181         Prop_double(std::string const & _propname, Changeable::Value when, double _value)
00182                 :Property(_propname,when){
00183                 default_value = value = _value;
00184         }
00185         bool SetValue(std::string const& input);
00186         virtual ~Prop_double(){ }
00187 };
00188 
00189 class Prop_bool:public Property {
00190 public:
00191         Prop_bool(std::string const& _propname, Changeable::Value when, bool _value)
00192                 :Property(_propname,when) { 
00193                 default_value = value = _value;
00194         }
00195         bool SetValue(std::string const& in);
00196         virtual ~Prop_bool(){ }
00197 };
00198 
00199 class Prop_string:public Property{
00200 public:
00201         Prop_string(std::string const& _propname, Changeable::Value when, char const * const _value)
00202                 :Property(_propname,when) { 
00203                 default_value = value = _value;
00204         }
00205         bool SetValue(std::string const& in);
00206         virtual bool CheckValue(Value const& in, bool warn);
00207         virtual ~Prop_string(){ }
00208 };
00209 class Prop_path:public Prop_string{
00210 public:
00211         std::string realpath;
00212         Prop_path(std::string const& _propname, Changeable::Value when, char const * const _value)
00213                 :Prop_string(_propname,when,_value) { 
00214                 default_value = value = _value;
00215                 realpath = _value;
00216         }
00217         bool SetValue(std::string const& in);
00218         virtual ~Prop_path(){ }
00219 };
00220 
00221 class Prop_hex:public Property {
00222 public:
00223         Prop_hex(std::string const& _propname, Changeable::Value when, Hex _value)
00224                 :Property(_propname,when) { 
00225                 default_value = value = _value;
00226         }
00227         bool SetValue(std::string const& in);
00228         virtual ~Prop_hex(){ }
00229 };
00230 
00231 class Section;
00232 
00233 typedef void (*SectionFunction)(Section*);
00234 
00235 /* Wrapper class around startup and shutdown functions. the variable
00236  * canchange indicates it can be called on configuration changes */
00237 struct Function_wrapper {
00238         SectionFunction function;
00239         bool canchange;
00240         std::string name;
00241         Function_wrapper(SectionFunction const _fun,bool _ch,const char *_name) {
00242                 function=_fun;
00243                 canchange=_ch;
00244                 if (_name != NULL) name = _name;
00245         }
00246 };
00247 
00248 #define NO_SUCH_PROPERTY "PROP_NOT_EXIST"
00249 class Section {
00250 private:
00251         std::string sectionname;
00252 public:
00253         Section(std::string const& _sectionname):sectionname(_sectionname) {  }
00254 
00255         const char* GetName() const {return sectionname.c_str();}
00256 
00257         virtual std::string GetPropValue(std::string const& _property) const =0;
00258         virtual bool HandleInputline(std::string const& _line)=0;
00259         virtual void PrintData(FILE* outfile,bool everything=false) = 0;
00260         virtual ~Section() { /*Children must call executedestroy ! */ }
00261 
00262         std::list<SectionFunction> onpropchange;
00263 };
00264 
00265 /* list of functions to call (in list order) when DOSBox-X exits.
00266  * use AddExitFunction() to add your function.
00267  * NOTE: AddExitFunction() adds your function to the back of the list,
00268  *       First-In-Last-Out order, so that exit callbacks added by init
00269  *       code are called in the opposite order from initialization
00270  *       (i.e. we want high-level stuff to cleanup first and low level
00271  *       stuff like logging to cleanup last). */
00272 extern std::list<Function_wrapper> exitfunctions;
00273 void AddExitFunction(SectionFunction func,const char *funcname,bool canchange=false);
00274 
00275 /* for use with AddExitFunction and a name of a function.
00276  * this turns it into function pointer and function name. it turns one param into two. */
00277 #define AddExitFunctionFuncPair(x) &x, #x
00278 
00279 /* array of list of functions to call for various virtual machine events */
00280 enum vm_event {
00281         VM_EVENT_POWERON=0,                     // emulation has started to power on hardware. it is safe to connect I/O, memory, IRQ resources, etc. to the bus. BIOS not initialized yet.
00282         VM_EVENT_RESET,                         // reset signal (at the hardware level), whether by the keyboard controller, reset button, etc.
00283         VM_EVENT_RESET_END,                     // reset signal switched off, permitting the system to begin booting.
00284         VM_EVENT_BIOS_INIT,                     // BIOS is going to reinitialize the system (after reset)
00285         VM_EVENT_BIOS_BOOT,                     // BIOS in the boot stage. usually leads to DOS kernel init or guest OS boot.
00286 
00287         VM_EVENT_GUEST_OS_BOOT=5,               // BIOS or DOS kernel (BOOT command) is running a guest OS. just after loading boot sector into memory but before executing it.
00288         VM_EVENT_DOS_BOOT,                      // emulation has decided to boot the built-in DOS kernel. just prior to starting the DOS kernel.
00289         VM_EVENT_DOS_INIT_KERNEL_READY,         // DOS kernel init. Prior to CONFIG.SYS handling.
00290         VM_EVENT_DOS_INIT_CONFIG_SYS_DONE,      // DOS kernel init. After CONFIG.SYS handling, all devices inited.
00291         VM_EVENT_DOS_INIT_SHELL_READY,          // DOS kernel init. After COMMAND.COM initialization, before AUTOEXEC.BAT execution.
00292 
00293         VM_EVENT_DOS_INIT_AUTOEXEC_BAT_DONE=10, // DOS kernel init. COMMAND.COM just finished AUTOEXEC.BAT.
00294         VM_EVENT_DOS_INIT_AT_PROMPT,            // DOS kernel init complete. After this event, the user is immediately given the DOS prompt.
00295         VM_EVENT_DOS_EXIT_BEGIN,                // DOS kernel is just starting to exit (user used BOOT command)
00296         VM_EVENT_DOS_EXIT_KERNEL,               // DOS kernel has just finished exiting
00297         VM_EVENT_DOS_EXIT_REBOOT_BEGIN,         // DOS kernel is just starting to exit (hard reset, outside of DOS's control)
00298 
00299         VM_EVENT_DOS_EXIT_REBOOT_KERNEL=15,     // DOS kernel has just finished exiting (hard reset)
00300     VM_EVENT_DOS_SURPRISE_REBOOT,       // DOS kernel asked to boot, when apparently having never been shut down (jmp to FFFF:0000)
00301 
00302         VM_EVENT_MAX
00303 };
00304 
00305 class VMDispatchState {
00306 public:
00307         VMDispatchState() : current_event(VM_EVENT_MAX), event_in_progress(false) { }
00308         void begin_event(enum vm_event event) {
00309                 event_in_progress = true;
00310                 current_event = event;
00311         }
00312         void end_event() {
00313                 event_in_progress = false;
00314         }
00315 public:
00316         enum vm_event                   current_event;
00317         bool                            event_in_progress;
00318 };
00319 
00320 extern VMDispatchState vm_dispatch_state;
00321 
00322 const char *GetVMEventName(enum vm_event event);
00323 
00324 extern std::list<Function_wrapper> vm_event_functions[VM_EVENT_MAX];
00325 void AddVMEventFunction(enum vm_event event,SectionFunction func,const char *name,bool canchange=false);
00326 void DispatchVMEvent(enum vm_event event);
00327 
00328 /* for use with AddExitFunction and a name of a function.
00329  * this turns it into function pointer and function name. it turns one param into two. */
00330 #define AddVMEventFunctionFuncPair(x) &x, #x
00331 
00332 class Prop_multival;
00333 class Prop_multival_remain;
00334 class Section_prop:public Section {
00335 private:
00336         std::list<Property*> properties;
00337         typedef std::list<Property*>::iterator it;
00338         typedef std::list<Property*>::const_iterator const_it;
00339 
00340 public:
00341         Section_prop(std::string const&  _sectionname):Section(_sectionname){}
00342         Prop_int* Add_int(std::string const& _propname, Property::Changeable::Value when, int _value=0);
00343         Prop_string* Add_string(std::string const& _propname, Property::Changeable::Value when, char const * const _value=NULL);
00344         Prop_path* Add_path(std::string const& _propname, Property::Changeable::Value when, char const * const _value=NULL);
00345         Prop_bool*  Add_bool(std::string const& _propname, Property::Changeable::Value when, bool _value=false);
00346         Prop_hex* Add_hex(std::string const& _propname, Property::Changeable::Value when, Hex _value=0);
00347         Prop_double* Add_double(std::string const& _propname, Property::Changeable::Value when, double _value=0.0);   
00348         Prop_multival *Add_multi(std::string const& _propname, Property::Changeable::Value when,std::string const& sep);
00349         Prop_multival_remain *Add_multiremain(std::string const& _propname, Property::Changeable::Value when,std::string const& sep);
00350 
00351         Property* Get_prop(int index);
00352         int Get_int(std::string const& _propname) const;
00353         const char* Get_string(std::string const& _propname) const;
00354         bool Get_bool(std::string const& _propname) const;
00355         Hex Get_hex(std::string const& _propname) const;
00356         double Get_double(std::string const& _propname) const;
00357         Prop_path* Get_path(std::string const& _propname) const;
00358         Prop_multival* Get_multival(std::string const& _propname) const;
00359         Prop_multival_remain* Get_multivalremain(std::string const& _propname) const;
00360         virtual bool HandleInputline(std::string const& gegevens);
00361         virtual void PrintData(FILE* outfile,bool everything=false);
00362         virtual std::string GetPropValue(std::string const& _property) const;
00363         virtual ~Section_prop();
00364 };
00365 
00366 class Prop_multival:public Property{
00367 protected:
00368         Section_prop* section;
00369         std::string seperator;
00370         void make_default_value();
00371 public:
00372         Prop_multival(std::string const& _propname, Changeable::Value when,std::string const& sep):Property(_propname,when), section(new Section_prop("")),seperator(sep) {
00373                 default_value = value = "";
00374         }
00375         Section_prop *GetSection() { return section; }
00376         const Section_prop *GetSection() const { return section; }
00377         virtual bool SetValue(std::string const& input,bool init);
00378         virtual bool SetValue(std::string const& input) { return SetValue(input,/*init*/false); };
00379         virtual const std::vector<Value>& GetValues() const;
00380         virtual ~Prop_multival() { if (section != NULL) { delete section; } }
00381 }; //value bevat totale string. setvalue zet elk van de sub properties en checked die.
00382 
00383 class Prop_multival_remain:public Prop_multival{
00384 public:
00385         Prop_multival_remain(std::string const& _propname, Changeable::Value when,std::string const& sep):Prop_multival(_propname,when,sep){ }
00386 
00387         virtual bool SetValue(std::string const& input,bool init);
00388         virtual bool SetValue(std::string const& input) { return SetValue(input,/*init*/false); };
00389 };
00390 
00391    
00392 class Section_line: public Section{
00393 public:
00394         Section_line(std::string const& _sectionname):Section(_sectionname){}
00395         virtual ~Section_line() { };
00396         virtual bool HandleInputline(std::string const& gegevens);
00397         virtual void PrintData(FILE* outfile,bool everything=false);
00398         virtual std::string GetPropValue(std::string const& _property) const;
00399         std::string data;
00400 };
00401 
00402 class Module_base {
00403         /* Base for all hardware and software "devices" */
00404 protected:
00405         Section* m_configuration;
00406 public:
00407         Module_base(Section* configuration){m_configuration=configuration;};
00408 //      Module_base(Section* configuration, SaveState* state) {};
00409         virtual ~Module_base(){/*LOG_MSG("executed")*/;};//Destructors are required
00410         /* Returns true if succesful.*/
00411         virtual bool Change_Config(Section* /*newconfig*/) {return false;} ;
00412 };
00413 #endif