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/ultima8/misc/set.h"
27 #include "ultima/shared/std/string.h"
28 #include "ultima/shared/std/containers.h"
29 #include "ultima/ultima8/usecode/intrinsics.h"
30 
31 namespace Ultima {
32 namespace Ultima8 {
33 
34 class Debugger;
35 class Process;
36 class UCProcess;
37 class ConvertUsecode;
38 class GlobalStorage;
39 class UCList;
40 class idMan;
41 
42 class UCMachine {
43  friend class Debugger;
44 public:
45  UCMachine(const Intrinsic *iset, unsigned int icount);
46  ~UCMachine();
47 
48  static UCMachine *get_instance() {
49  return _ucMachine;
50  }
51 
52  void reset();
53 
54  void execProcess(UCProcess *proc);
55 
56  const Std::string &getString(uint16 str) const;
57  UCList *getList(uint16 l);
58 
59  void freeString(uint16 s);
60  void freeStringList(uint16 l);
61  void freeList(uint16 l);
62 
63  uint16 duplicateString(uint16 str);
64 
65  void usecodeStats() const;
66 
67  static uint32 listToPtr(uint16 l);
68  static uint32 stringToPtr(uint16 s);
69  static uint32 stackToPtr(uint16 pid, uint16 offset);
70  static uint32 globalToPtr(uint16 offset);
71  static uint32 objectToPtr(uint16 objID);
72 
73  static uint16 ptrToObject(uint32 ptr);
74 
75  bool assignPointer(uint32 ptr, const uint8 *data, uint32 size);
76  bool dereferencePointer(uint32 ptr, uint8 *data, uint32 size);
77 
78  void saveGlobals(Common::WriteStream *ws) const;
79  void saveStrings(Common::WriteStream *ws) const;
80  void saveLists(Common::WriteStream *ws) const;
81 
82  bool loadGlobals(Common::ReadStream *rs, uint32 version);
83  bool loadStrings(Common::ReadStream *rs, uint32 version);
84  bool loadLists(Common::ReadStream *rs, uint32 version);
85 
86  INTRINSIC(I_true);
87  INTRINSIC(I_false);
88  INTRINSIC(I_dummyProcess);
89  INTRINSIC(I_getName);
90  INTRINSIC(I_urandom);
91  INTRINSIC(I_rndRange);
92  INTRINSIC(I_numToStr);
93 
94 protected:
95  void loadIntrinsics(const Intrinsic *i, unsigned int icount);
96 
97 private:
98  ConvertUsecode *_convUse;
99  const Intrinsic *_intrinsics;
100  unsigned int _intrinsicCount;
101 
102  GlobalStorage *_globals;
103 
106 
107  // Add a string to the list (copies the string)
108  uint16 assignString(const char *str);
109  uint16 assignList(UCList *l);
110 
111  idMan *_listIDs;
112  idMan *_stringIDs;
113 
114  static UCMachine *_ucMachine;
115 
116  // tracing
117  bool _tracingEnabled;
118  bool _traceAll;
119  Set<ObjId> _traceObjIDs;
120  Set<ProcId> _tracePIDs;
121  Set<uint16> _traceClasses;
122 
123  inline bool trace_show(ProcId pid, ObjId objid, uint16 ucclass) {
124  if (!_tracingEnabled) return false;
125  if (_traceAll) return true;
126  if (_traceObjIDs.find(objid) != _traceObjIDs.end()) return true;
127  if (_tracePIDs.find(pid) != _tracePIDs.end()) return true;
128  if (_traceClasses.find(ucclass) != _traceClasses.end()) return true;
129  return false;
130  }
131 
132 };
133 
134 } // End of namespace Ultima8
135 } // End of namespace Ultima
136 
137 #endif
Definition: uc_process.h:34
Definition: stream.h:77
Definition: convert_usecode.h:28
iterator find(const T item)
Definition: set.h:84
Definition: detection.h:27
Definition: uc_machine.h:42
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