ScummVM API documentation
uc_machine.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef ULTIMA8_USECODE_UCMACHINE_H
23 #define ULTIMA8_USECODE_UCMACHINE_H
24 
25 #include "ultima/ultima8/misc/common_types.h"
26 #include "ultima/shared/std/string.h"
27 #include "ultima/shared/std/containers.h"
28 #include "ultima/ultima8/usecode/intrinsics.h"
29 
30 namespace Ultima {
31 namespace Ultima8 {
32 
33 class Debugger;
34 class Process;
35 class UCProcess;
36 class ConvertUsecode;
37 class GlobalStorage;
38 class UCList;
39 class idMan;
40 
41 class UCMachine {
42  friend class Debugger;
43 public:
44  UCMachine(const Intrinsic *iset, unsigned int icount);
45  ~UCMachine();
46 
47  static UCMachine *get_instance() {
48  return _ucMachine;
49  }
50 
51  void reset();
52 
53  void execProcess(UCProcess *proc);
54 
55  const Std::string &getString(uint16 str) const;
56  UCList *getList(uint16 l);
57 
58  void freeString(uint16 s);
59  void freeStringList(uint16 l);
60  void freeList(uint16 l);
61 
62  uint16 duplicateString(uint16 str);
63 
64  void usecodeStats() const;
65 
66  static uint32 listToPtr(uint16 l);
67  static uint32 stringToPtr(uint16 s);
68  static uint32 stackToPtr(uint16 pid, uint16 offset);
69  static uint32 globalToPtr(uint16 offset);
70  static uint32 objectToPtr(uint16 objID);
71 
72  static uint16 ptrToObject(uint32 ptr);
73 
74  bool assignPointer(uint32 ptr, const uint8 *data, uint32 size);
75  bool dereferencePointer(uint32 ptr, uint8 *data, uint32 size);
76 
77  void saveGlobals(Common::WriteStream *ws) const;
78  void saveStrings(Common::WriteStream *ws) const;
79  void saveLists(Common::WriteStream *ws) const;
80 
81  bool loadGlobals(Common::ReadStream *rs, uint32 version);
82  bool loadStrings(Common::ReadStream *rs, uint32 version);
83  bool loadLists(Common::ReadStream *rs, uint32 version);
84 
85  INTRINSIC(I_true);
86  INTRINSIC(I_false);
87  INTRINSIC(I_dummyProcess);
88  INTRINSIC(I_getName);
89  INTRINSIC(I_urandom);
90  INTRINSIC(I_rndRange);
91  INTRINSIC(I_numToStr);
92 
93 protected:
94  void loadIntrinsics(const Intrinsic *i, unsigned int icount);
95 
96 private:
97  ConvertUsecode *_convUse;
98  const Intrinsic *_intrinsics;
99  unsigned int _intrinsicCount;
100 
101  GlobalStorage *_globals;
102 
105 
106  // Add a string to the list (copies the string)
107  uint16 assignString(const char *str);
108  uint16 assignList(UCList *l);
109 
110  idMan *_listIDs;
111  idMan *_stringIDs;
112 
113  static UCMachine *_ucMachine;
114 
115  // tracing
116  bool _tracingEnabled;
117  bool _traceAll;
118  Std::set<ObjId> _traceObjIDs;
119  Std::set<ProcId> _tracePIDs;
120  Std::set<uint16> _traceClasses;
121 
122  inline bool trace_show(ProcId pid, ObjId objid, uint16 ucclass) {
123  if (!_tracingEnabled) return false;
124  if (_traceAll) return true;
125  if (_traceObjIDs.find(objid) != _traceObjIDs.end()) return true;
126  if (_tracePIDs.find(pid) != _tracePIDs.end()) return true;
127  if (_traceClasses.find(ucclass) != _traceClasses.end()) return true;
128  return false;
129  }
130 
131 };
132 
133 } // End of namespace Ultima8
134 } // End of namespace Ultima
135 
136 #endif
Definition: uc_process.h:34
Definition: stream.h:77
Definition: convert_usecode.h:28
Definition: detection.h:27
Definition: uc_machine.h:41
iterator find(const T item)
Definition: containers.h:172
Definition: hashmap.h:85
Definition: string.h:30
Definition: uc_list.h:41
Definition: global_storage.h:32
Definition: id_man.h:43
Definition: stream.h:385
Definition: debugger.h:37