DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
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                 min = max = -1.0;
00185         }
00186         Prop_double(std::string const & propname, Changeable::Value when, double _value, double _min, double _max)
00187                 :Property(propname, when)
00188         {
00189                 default_value = value = _value;
00190                 min = _min;
00191                 max = _max;
00192         }
00193         double getMin() const { return min; }
00194         double getMax() const { return max; }
00195         void SetMinMax(Value const& min, Value const& max) { this->min = min; this->max = max; }
00196         bool SetValue(std::string const& input);
00197         virtual ~Prop_double(){ }
00198         virtual bool CheckValue(Value const& in, bool warn);
00199 private:
00200         Value min, max;
00201 };
00202 
00203 class Prop_bool:public Property {
00204 public:
00205         Prop_bool(std::string const& _propname, Changeable::Value when, bool _value)
00206                 :Property(_propname,when) { 
00207                 default_value = value = _value;
00208         }
00209         bool SetValue(std::string const& in);
00210         virtual ~Prop_bool(){ }
00211 };
00212 
00213 class Prop_string:public Property{
00214 public:
00215         Prop_string(std::string const& _propname, Changeable::Value when, char const * const _value)
00216                 :Property(_propname,when) { 
00217                 default_value = value = _value;
00218         }
00219         bool SetValue(std::string const& in);
00220         virtual bool CheckValue(Value const& in, bool warn);
00221         virtual ~Prop_string(){ }
00222 };
00223 class Prop_path:public Prop_string{
00224 public:
00225         std::string realpath;
00226         Prop_path(std::string const& _propname, Changeable::Value when, char const * const _value)
00227                 :Prop_string(_propname,when,_value) { 
00228                 default_value = value = _value;
00229                 realpath = _value;
00230         }
00231         bool SetValue(std::string const& in);
00232         virtual ~Prop_path(){ }
00233 };
00234 
00235 class Prop_hex:public Property {
00236 public:
00237         Prop_hex(std::string const& _propname, Changeable::Value when, Hex _value)
00238                 :Property(_propname,when) { 
00239                 default_value = value = _value;
00240         }
00241         bool SetValue(std::string const& in);
00242         virtual ~Prop_hex(){ }
00243 };
00244 
00245 class Section;
00246 
00247 typedef void (*SectionFunction)(Section*);
00248 
00249 /* Wrapper class around startup and shutdown functions. the variable
00250  * canchange indicates it can be called on configuration changes */
00251 struct Function_wrapper {
00252         SectionFunction function;
00253         bool canchange;
00254         std::string name;
00255         Function_wrapper(SectionFunction const _fun,bool _ch,const char *_name) {
00256                 function=_fun;
00257                 canchange=_ch;
00258                 if (_name != NULL) name = _name;
00259         }
00260 };
00261 
00262 #define NO_SUCH_PROPERTY "PROP_NOT_EXIST"
00263 class Section {
00264 private:
00265         std::string sectionname;
00266 public:
00267         Section(std::string const& _sectionname):sectionname(_sectionname) {  }
00268 
00269         const char* GetName() const {return sectionname.c_str();}
00270 
00271         virtual std::string GetPropValue(std::string const& _property) const =0;
00272         virtual bool HandleInputline(std::string const& _line)=0;
00273         virtual void PrintData(FILE* outfile,bool everything=false) = 0;
00274         virtual ~Section() { /*Children must call executedestroy ! */ }
00275 
00276         std::list<SectionFunction> onpropchange;
00277 };
00278 
00279 /* list of functions to call (in list order) when DOSBox-X exits.
00280  * use AddExitFunction() to add your function.
00281  * NOTE: AddExitFunction() adds your function to the back of the list,
00282  *       First-In-Last-Out order, so that exit callbacks added by init
00283  *       code are called in the opposite order from initialization
00284  *       (i.e. we want high-level stuff to cleanup first and low level
00285  *       stuff like logging to cleanup last). */
00286 extern std::list<Function_wrapper> exitfunctions;
00287 void AddExitFunction(SectionFunction func,const char *funcname,bool canchange=false);
00288 
00289 /* for use with AddExitFunction and a name of a function.
00290  * this turns it into function pointer and function name. it turns one param into two. */
00291 #define AddExitFunctionFuncPair(x) &x, #x
00292 
00293 /* array of list of functions to call for various virtual machine events */
00294 enum vm_event {
00295         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.
00296         VM_EVENT_RESET,                         // reset signal (at the hardware level), whether by the keyboard controller, reset button, etc.
00297         VM_EVENT_RESET_END,                     // reset signal switched off, permitting the system to begin booting.
00298         VM_EVENT_BIOS_INIT,                     // BIOS is going to reinitialize the system (after reset)
00299         VM_EVENT_BIOS_BOOT,                     // BIOS in the boot stage. usually leads to DOS kernel init or guest OS boot.
00300 
00301         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.
00302         VM_EVENT_DOS_BOOT,                      // emulation has decided to boot the built-in DOS kernel. just prior to starting the DOS kernel.
00303         VM_EVENT_DOS_INIT_KERNEL_READY,         // DOS kernel init. Prior to CONFIG.SYS handling.
00304         VM_EVENT_DOS_INIT_CONFIG_SYS_DONE,      // DOS kernel init. After CONFIG.SYS handling, all devices inited.
00305         VM_EVENT_DOS_INIT_SHELL_READY,          // DOS kernel init. After COMMAND.COM initialization, before AUTOEXEC.BAT execution.
00306 
00307         VM_EVENT_DOS_INIT_AUTOEXEC_BAT_DONE=10, // DOS kernel init. COMMAND.COM just finished AUTOEXEC.BAT.
00308         VM_EVENT_DOS_INIT_AT_PROMPT,            // DOS kernel init complete. After this event, the user is immediately given the DOS prompt.
00309         VM_EVENT_DOS_EXIT_BEGIN,                // DOS kernel is just starting to exit (user used BOOT command)
00310         VM_EVENT_DOS_EXIT_KERNEL,               // DOS kernel has just finished exiting
00311         VM_EVENT_DOS_EXIT_REBOOT_BEGIN,         // DOS kernel is just starting to exit (hard reset, outside of DOS's control)
00312 
00313         VM_EVENT_DOS_EXIT_REBOOT_KERNEL=15,     // DOS kernel has just finished exiting (hard reset)
00314     VM_EVENT_DOS_SURPRISE_REBOOT,       // DOS kernel asked to boot, when apparently having never been shut down (jmp to FFFF:0000)
00315     VM_EVENT_SAVE_STATE,            // Save state in progress. Callback handler should refer to global object to write it's state to.
00316     VM_EVENT_LOAD_STATE,            // Loading a save state in progress. Callback handler should refer to global object to read state from.
00317 
00318         VM_EVENT_MAX
00319 };
00320 
00321 class VMDispatchState {
00322 public:
00323         VMDispatchState() : current_event(VM_EVENT_MAX), event_in_progress(false) { }
00324         void begin_event(enum vm_event event) {
00325                 event_in_progress = true;
00326                 current_event = event;
00327         }
00328         void end_event() {
00329                 event_in_progress = false;
00330         }
00331 public:
00332         enum vm_event                   current_event;
00333         bool                            event_in_progress;
00334 };
00335 
00336 extern VMDispatchState vm_dispatch_state;
00337 
00338 const char *GetVMEventName(enum vm_event event);
00339 
00340 extern std::list<Function_wrapper> vm_event_functions[VM_EVENT_MAX];
00341 void AddVMEventFunction(enum vm_event event,SectionFunction func,const char *name,bool canchange=false);
00342 void DispatchVMEvent(enum vm_event event);
00343 
00344 /* for use with AddExitFunction and a name of a function.
00345  * this turns it into function pointer and function name. it turns one param into two. */
00346 #define AddVMEventFunctionFuncPair(x) &x, #x
00347 
00348 class Prop_multival;
00349 class Prop_multival_remain;
00350 class Section_prop:public Section {
00351 private:
00352         std::list<Property*> properties;
00353         typedef std::list<Property*>::iterator it;
00354         typedef std::list<Property*>::const_iterator const_it;
00355 
00356 public:
00357         Section_prop(std::string const&  _sectionname):Section(_sectionname){}
00358         Prop_int* Add_int(std::string const& _propname, Property::Changeable::Value when, int _value=0);
00359         Prop_string* Add_string(std::string const& _propname, Property::Changeable::Value when, char const * const _value=NULL);
00360         Prop_path* Add_path(std::string const& _propname, Property::Changeable::Value when, char const * const _value=NULL);
00361         Prop_bool*  Add_bool(std::string const& _propname, Property::Changeable::Value when, bool _value=false);
00362         Prop_hex* Add_hex(std::string const& _propname, Property::Changeable::Value when, Hex _value=0);
00363         Prop_double* Add_double(std::string const& _propname, Property::Changeable::Value when, double _value=0.0);   
00364         Prop_multival *Add_multi(std::string const& _propname, Property::Changeable::Value when,std::string const& sep);
00365         Prop_multival_remain *Add_multiremain(std::string const& _propname, Property::Changeable::Value when,std::string const& sep);
00366 
00367         Property* Get_prop(int index);
00368         int Get_int(std::string const& _propname) const;
00369         const char* Get_string(std::string const& _propname) const;
00370         bool Get_bool(std::string const& _propname) const;
00371         Hex Get_hex(std::string const& _propname) const;
00372         double Get_double(std::string const& _propname) const;
00373         Prop_path* Get_path(std::string const& _propname) const;
00374         Prop_multival* Get_multival(std::string const& _propname) const;
00375         Prop_multival_remain* Get_multivalremain(std::string const& _propname) const;
00376         virtual bool HandleInputline(std::string const& gegevens);
00377         virtual void PrintData(FILE* outfile,bool everything=false);
00378         virtual std::string GetPropValue(std::string const& _property) const;
00379         virtual ~Section_prop();
00380 };
00381 
00382 class Prop_multival:public Property{
00383 protected:
00384         Section_prop* section;
00385         std::string seperator;
00386         void make_default_value();
00387 public:
00388         Prop_multival(std::string const& _propname, Changeable::Value when,std::string const& sep):Property(_propname,when), section(new Section_prop("")),seperator(sep) {
00389                 default_value = value = "";
00390         }
00391         Section_prop *GetSection() { return section; }
00392         const Section_prop *GetSection() const { return section; }
00393         virtual bool SetValue(std::string const& input,bool init);
00394         virtual bool SetValue(std::string const& input) { return SetValue(input,/*init*/false); };
00395         virtual const std::vector<Value>& GetValues() const;
00396         virtual ~Prop_multival() { if (section != NULL) { delete section; } }
00397 }; //value bevat totale string. setvalue zet elk van de sub properties en checked die.
00398 
00399 class Prop_multival_remain:public Prop_multival{
00400 public:
00401         Prop_multival_remain(std::string const& _propname, Changeable::Value when,std::string const& sep):Prop_multival(_propname,when,sep){ }
00402 
00403         virtual bool SetValue(std::string const& input,bool init);
00404         virtual bool SetValue(std::string const& input) { return SetValue(input,/*init*/false); };
00405 };
00406 
00407    
00408 class Section_line: public Section{
00409 public:
00410         Section_line(std::string const& _sectionname):Section(_sectionname){}
00411         virtual ~Section_line() { };
00412         virtual bool HandleInputline(std::string const& gegevens);
00413         virtual void PrintData(FILE* outfile,bool everything=false);
00414         virtual std::string GetPropValue(std::string const& _property) const;
00415         std::string data;
00416 };
00417 
00418 class Module_base {
00419         /* Base for all hardware and software "devices" */
00420 protected:
00421         Section* m_configuration;
00422 public:
00423         Module_base(Section* configuration){m_configuration=configuration;};
00424 //      Module_base(Section* configuration, SaveState* state) {};
00425         virtual ~Module_base(){/*LOG_MSG("executed")*/;};//Destructors are required
00426         /* Returns true if succesful.*/
00427         virtual bool Change_Config(Section* /*newconfig*/) {return false;} ;
00428 };
00429 #endif