ScummVM API documentation
seg_manager.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 SCI_ENGINE_SEG_MANAGER_H
23#define SCI_ENGINE_SEG_MANAGER_H
24
25#include "common/scummsys.h"
26#include "common/serializer.h"
27#include "sci/engine/script.h"
28#include "sci/engine/vm.h"
29#include "sci/engine/vm_types.h"
30#include "sci/engine/segment.h"
31#ifdef ENABLE_SCI32
32#include "sci/graphics/celobj32.h" // kLowResX, kLowResY
33#endif
34
35namespace Sci {
36
44};
45
46class Script;
47
49 friend class Console;
50public:
54 SegManager(ResourceManager *resMan, ScriptPatcher *scriptPatcher);
55
59 ~SegManager() override;
60
61 void resetSegMan();
62
63 void saveLoadWithSerializer(Common::Serializer &ser) override;
64
65 // 1. Scripts
66
73 Script *allocateScript(int script_nr, SegmentId &seg_id);
74
75 // The script must then be initialized; see section (1b.), below.
76
81 void deallocateScript(int script_nr);
82
87
93 SegmentId getScriptSegment(int script_nr) const;
94
103 SegmentId getScriptSegment(int script_nr, ScriptLoadType load, bool applyScriptPatches = true);
104
115 int instantiateScript(int script_nr, bool applyScriptPatches = true);
116
124 void uninstantiateScript(int script_nr);
125
126private:
127 void uninstantiateScriptSci0(int script_nr);
128
129public:
130 // TODO: document this
131 reg_t getClassAddress(int classnr, ScriptLoadType lock, uint16 callerSegment, bool applyScriptPatches = true);
132
140 Script *getScript(SegmentId seg);
141
142
150 Script *getScriptIfLoaded(SegmentId seg) const;
151
152 // 2. Clones
153
160
165
166 // 4. Stack
167
174
175
176 // 5. System Strings
177
182
183
184 // 6, 7. Lists and Nodes
185
192
199
207
214
220 Node *lookupNode(reg_t addr, bool stopOnDiscarded = true);
221
222
223 // 8. Hunk Memory
224
232 reg_t allocateHunkEntry(const char *hunk_type, int size);
233
239
245
246 // 9. Dynamic Memory
247
256 byte *allocDynmem(int size, const char *description, reg_t *addr);
257
262 bool freeDynmem(reg_t addr);
263
264
265 // Generic Operations on Segments and Addresses
266
273
281 byte *derefBulkPtr(reg_t pointer, int entries);
282
291 reg_t *derefRegPtr(reg_t pointer, int entries);
292
300 char *derefString(reg_t pointer, int entries = 0);
301
310
311
317 void strcpy_(reg_t dest, reg_t src);
318
324 void strcpy_(reg_t dest, const char *src);
325
332 void strncpy(reg_t dest, reg_t src, size_t n);
333
340 void strncpy(reg_t dest, const char *src, size_t n);
341
347 void memcpy(reg_t dest, reg_t src, size_t n);
348
354 void memcpy(reg_t dest, const byte* src, size_t n);
355
361 void memcpy(byte *dest, reg_t src, size_t n);
362
367 size_t strlen(reg_t str);
368
374 SegmentId findSegmentByType(int type) const;
375
376 // TODO: document this
377 SegmentObj *getSegmentObj(SegmentId seg) const;
378
379 // TODO: document this
380 SegmentType getSegmentType(SegmentId seg) const;
381
382 // TODO: document this
383 SegmentObj *getSegment(SegmentId seg, SegmentType type) const;
384
390 Object *getObject(reg_t pos) const;
391
397 bool isObject(reg_t obj) const { return getObject(obj) != NULL; }
398
399 // TODO: document this
400 bool isHeapObject(reg_t pos) const;
401
410 const char *getObjectName(reg_t pos);
411
416
428 reg_t findObjectByName(const Common::String &name, int index = -1);
429
434
435 uint32 classTableSize() const { return _classTable.size(); }
436 Class getClass(int index) const { return _classTable[index]; }
437 void setClassOffset(int index, reg_t offset) { _classTable[index].reg = offset; }
438 void resizeClassTable(uint32 size) { _classTable.resize(size); }
439
440 reg_t getSaveDirPtr() const { return _saveDirPtr; }
441 reg_t getParserPtr() const { return _parserPtr; }
442
443#ifdef ENABLE_SCI32
444 bool isValidAddr(reg_t reg, SegmentType expected) const {
445 SegmentObj *mobj = getSegmentObj(reg.getSegment());
446 return (mobj &&
447 mobj->getType() == expected &&
448 mobj->isValidOffset(reg.getOffset()));
449 }
450
451 SciArray *allocateArray(SciArrayType type, uint16 size, reg_t *addr);
452 SciArray *lookupArray(reg_t addr);
453 void freeArray(reg_t addr);
454 bool isArray(reg_t addr) const;
455
456 SciBitmap *allocateBitmap(reg_t *addr, const int16 width, const int16 height, const uint8 skipColor = kDefaultSkipColor, const int16 originX = 0, const int16 originY = 0, const int16 xResolution = kLowResX, const int16 yResolution = kLowResY, const uint32 paletteSize = 0, const bool remap = false, const bool gc = true);
457 SciBitmap *lookupBitmap(reg_t addr);
458 void freeBitmap(reg_t addr);
459#endif
460
461 const Common::Array<SegmentObj *> &getSegments() const { return _heap; }
462
463private:
465 Common::Array<Class> _classTable;
468
469 ResourceManager *_resMan;
470 ScriptPatcher *_scriptPatcher;
471
472 SegmentId _clonesSegId;
473 SegmentId _listsSegId;
474 SegmentId _nodesSegId;
475 SegmentId _hunksSegId;
476
477 // Statically allocated memory for system strings
478 reg_t _saveDirPtr;
479 reg_t _parserPtr;
480
481#ifdef ENABLE_SCI32
482 SegmentId _arraysSegId;
483 SegmentId _bitmapSegId;
484#endif
485
486public:
487 SegmentId allocSegment(SegmentObj *mobj);
488
489private:
490 void deallocate(SegmentId seg);
491 void createClassTable();
492
493 SegmentId findFreeSegment() const;
494
505 SegmentId getActualSegment(SegmentId seg) const;
506};
507
508} // End of namespace Sci
509
510#endif // SCI_ENGINE_SEG_MANAGER_H
Definition: serializer.h:352
Definition: serializer.h:80
Definition: str.h:59
Definition: console.h:36
Definition: object.h:69
Definition: resource.h:327
Definition: script.h:71
Definition: script_patches.h:91
Definition: seg_manager.h:48
SegmentId findSegmentByType(int type) const
const char * getObjectName(reg_t pos)
void memcpy(byte *dest, reg_t src, size_t n)
byte * derefBulkPtr(reg_t pointer, int entries)
Node * allocateNode(reg_t *addr)
reg_t allocateHunkEntry(const char *hunk_type, int size)
Script * getScriptIfLoaded(SegmentId seg) const
reg_t newNode(reg_t value, reg_t key)
char * derefString(reg_t pointer, int entries=0)
Script * getScript(SegmentId seg)
Script * allocateScript(int script_nr, SegmentId &seg_id)
SegmentId getScriptSegment(int script_nr) const
~SegManager() override
List * allocateList(reg_t *addr)
void freeHunkEntry(reg_t addr)
reg_t * derefRegPtr(reg_t pointer, int entries)
size_t strlen(reg_t str)
bool freeDynmem(reg_t addr)
void strncpy(reg_t dest, reg_t src, size_t n)
void initSysStrings()
Clone * allocateClone(reg_t *addr)
List * lookupList(reg_t addr)
void strncpy(reg_t dest, const char *src, size_t n)
SegmentRef dereference(reg_t pointer)
SegmentId getScriptSegment(int script_nr, ScriptLoadType load, bool applyScriptPatches=true)
void memcpy(reg_t dest, const byte *src, size_t n)
void reconstructStack(EngineState *s)
SegManager(ResourceManager *resMan, ScriptPatcher *scriptPatcher)
Common::String getString(reg_t pointer)
void strcpy_(reg_t dest, const char *src)
byte * getHunkPointer(reg_t addr)
byte * allocDynmem(int size, const char *description, reg_t *addr)
void memcpy(reg_t dest, reg_t src, size_t n)
int instantiateScript(int script_nr, bool applyScriptPatches=true)
Common::Array< reg_t > findObjectsByName(const Common::String &name)
void reconstructClones()
reg_t findObjectByName(const Common::String &name, int index=-1)
Common::Array< reg_t > findObjectsBySuperClass(const Common::String &superClassName)
void strcpy_(reg_t dest, reg_t src)
bool isObject(reg_t obj) const
Definition: seg_manager.h:397
void deallocateScript(int script_nr)
Node * lookupNode(reg_t addr, bool stopOnDiscarded=true)
void uninstantiateScript(int script_nr)
DataStack * allocateStack(int size)
Object * getObject(reg_t pos) const
Definition: console.h:28
ScriptLoadType
Definition: seg_manager.h:40
@ SCRIPT_GET_LOAD
Definition: seg_manager.h:42
@ SCRIPT_GET_LOCK
Definition: seg_manager.h:43
@ SCRIPT_GET_DONT_LOAD
Definition: seg_manager.h:41
Definition: vm.h:59
Definition: segment.h:165
Definition: state.h:100
Definition: segment.h:202
Definition: segment.h:195
Definition: segment.h:82
Definition: segment.h:37
Definition: vm_types.h:39