2009-02-17 15:02:16 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2014-02-18 02:34:24 +01:00
|
|
|
*
|
2009-02-17 15:02:16 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2014-02-18 02:34:24 +01:00
|
|
|
*
|
2009-02-17 15:02:16 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
2009-02-16 09:23:58 +00:00
|
|
|
|
2009-09-17 13:22:46 +00:00
|
|
|
#ifndef SCI_ENGINE_SEGMAN_H
|
|
|
|
#define SCI_ENGINE_SEGMAN_H
|
2009-02-16 09:23:58 +00:00
|
|
|
|
2009-05-03 09:25:15 +00:00
|
|
|
#include "common/scummsys.h"
|
|
|
|
#include "common/serializer.h"
|
2010-06-27 20:38:43 +00:00
|
|
|
#include "sci/engine/script.h"
|
2009-02-24 05:56:26 +00:00
|
|
|
#include "sci/engine/vm.h"
|
2010-06-27 20:38:43 +00:00
|
|
|
#include "sci/engine/vm_types.h"
|
2009-09-17 13:22:46 +00:00
|
|
|
#include "sci/engine/segment.h"
|
2009-02-16 09:23:58 +00:00
|
|
|
|
2009-02-21 10:23:36 +00:00
|
|
|
namespace Sci {
|
|
|
|
|
2009-08-17 05:55:21 +00:00
|
|
|
/**
|
2009-09-06 12:58:16 +00:00
|
|
|
* Parameters for getScriptSegment().
|
2009-08-17 05:55:21 +00:00
|
|
|
*/
|
2009-09-06 12:58:16 +00:00
|
|
|
enum ScriptLoadType {
|
2009-08-17 05:55:21 +00:00
|
|
|
SCRIPT_GET_DONT_LOAD = 0, /**< Fail if not loaded */
|
|
|
|
SCRIPT_GET_LOAD = 1, /**< Load, if neccessary */
|
|
|
|
SCRIPT_GET_LOCK = 3 /**< Load, if neccessary, and lock */
|
2009-09-06 12:58:16 +00:00
|
|
|
};
|
2009-08-17 05:55:21 +00:00
|
|
|
|
2010-06-27 20:38:43 +00:00
|
|
|
class Script;
|
2009-08-17 05:55:21 +00:00
|
|
|
|
2009-05-03 09:25:15 +00:00
|
|
|
class SegManager : public Common::Serializable {
|
2009-09-16 23:55:11 +00:00
|
|
|
friend class Console;
|
2009-02-21 23:27:24 +00:00
|
|
|
public:
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
2009-09-06 12:58:16 +00:00
|
|
|
* Initialize the segment manager.
|
2009-06-18 22:09:57 +00:00
|
|
|
*/
|
2013-12-04 20:42:16 +01:00
|
|
|
SegManager(ResourceManager *resMan, ScriptPatcher *scriptPatcher);
|
2009-02-21 23:27:24 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
2009-09-06 12:58:16 +00:00
|
|
|
* Deallocate all memory associated with the segment manager.
|
2009-06-18 22:09:57 +00:00
|
|
|
*/
|
2009-02-21 23:27:24 +00:00
|
|
|
~SegManager();
|
|
|
|
|
2009-11-04 14:22:17 +00:00
|
|
|
void resetSegMan();
|
|
|
|
|
2009-05-03 09:25:15 +00:00
|
|
|
virtual void saveLoadWithSerializer(Common::Serializer &ser);
|
|
|
|
|
2009-02-21 23:27:24 +00:00
|
|
|
// 1. Scripts
|
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
2009-09-06 12:58:16 +00:00
|
|
|
* Allocate a script into the segment manager.
|
2009-06-18 22:09:57 +00:00
|
|
|
* @param script_nr The number of the script to load
|
|
|
|
* @param seg_id The segment ID of the newly allocated segment,
|
|
|
|
* on success
|
|
|
|
* @return 0 on failure, 1 on success
|
|
|
|
*/
|
2009-08-17 05:55:21 +00:00
|
|
|
Script *allocateScript(int script_nr, SegmentId *seg_id);
|
2009-02-21 23:27:24 +00:00
|
|
|
|
2011-05-25 11:17:11 -04:00
|
|
|
// The script must then be initialized; see section (1b.), below.
|
2009-02-21 23:27:24 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
2009-09-06 12:58:16 +00:00
|
|
|
* Forcefully deallocate a previously allocated script.
|
2009-06-18 22:09:57 +00:00
|
|
|
* @param script_nr number of the script to deallocate
|
|
|
|
*/
|
2009-09-17 00:44:22 +00:00
|
|
|
void deallocateScript(int script_nr);
|
2009-02-21 23:27:24 +00:00
|
|
|
|
2010-06-08 13:16:30 +00:00
|
|
|
/**
|
|
|
|
* Reconstructs the stack. Used when restoring saved games
|
|
|
|
*/
|
|
|
|
void reconstructStack(EngineState *s);
|
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
2009-09-06 12:58:16 +00:00
|
|
|
* Determines the segment occupied by a certain script, if any.
|
2009-06-18 22:09:57 +00:00
|
|
|
* @param script_nr Number of the script to look up
|
2009-09-17 00:46:01 +00:00
|
|
|
* @return The script's segment ID, or 0 on failure
|
2009-06-18 22:09:57 +00:00
|
|
|
*/
|
2009-09-06 12:58:16 +00:00
|
|
|
SegmentId getScriptSegment(int script_nr) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines the segment occupied by a certain script. Optionally
|
|
|
|
* load it, or load & lock it.
|
|
|
|
* @param[in] script_nr Number of the script to look up
|
|
|
|
* @param[in] load flag determining whether to load/lock the script
|
2009-09-17 00:46:01 +00:00
|
|
|
* @return The script's segment ID, or 0 on failure
|
2009-09-06 12:58:16 +00:00
|
|
|
*/
|
|
|
|
SegmentId getScriptSegment(int script_nr, ScriptLoadType load);
|
|
|
|
|
2010-06-27 21:18:19 +00:00
|
|
|
/**
|
|
|
|
* Makes sure that a script and its superclasses get loaded to the heap.
|
|
|
|
* If the script already has been loaded, only the number of lockers is
|
|
|
|
* increased. All scripts containing superclasses of this script are loaded
|
|
|
|
* recursively as well, unless 'recursive' is set to zero. The
|
|
|
|
* complementary function is "uninstantiateScript()" below.
|
|
|
|
* @param[in] script_nr The script number to load
|
|
|
|
* @return The script's segment ID or 0 if out of heap
|
|
|
|
*/
|
|
|
|
int instantiateScript(int script_nr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decreases the numer of lockers of a script and unloads it if that number
|
|
|
|
* reaches zero.
|
|
|
|
* This function will recursively unload scripts containing its
|
|
|
|
* superclasses, if those aren't locked by other scripts as well.
|
|
|
|
* @param[in] script_nr The script number that is requestet to be unloaded
|
|
|
|
*/
|
|
|
|
void uninstantiateScript(int script_nr);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void uninstantiateScriptSci0(int script_nr);
|
|
|
|
|
|
|
|
public:
|
2009-09-06 12:58:16 +00:00
|
|
|
// TODO: document this
|
2012-06-15 22:24:35 +03:00
|
|
|
reg_t getClassAddress(int classnr, ScriptLoadType lock, uint16 callerSegment);
|
2009-02-21 23:27:24 +00:00
|
|
|
|
2009-05-15 09:27:39 +00:00
|
|
|
/**
|
2009-06-18 22:09:57 +00:00
|
|
|
* Return a pointer to the specified script.
|
2010-01-25 01:39:44 +00:00
|
|
|
* If the id is invalid, does not refer to a script or the script is
|
2009-06-18 22:09:57 +00:00
|
|
|
* not loaded, this will invoke error().
|
2009-05-15 09:28:31 +00:00
|
|
|
* @param seg ID of the script segment to check for
|
2009-06-18 22:09:57 +00:00
|
|
|
* @return A pointer to the Script object
|
2009-05-15 09:27:39 +00:00
|
|
|
*/
|
2009-05-18 12:34:56 +00:00
|
|
|
Script *getScript(SegmentId seg);
|
2009-05-03 09:20:21 +00:00
|
|
|
|
2009-09-07 06:07:18 +00:00
|
|
|
|
2009-05-15 09:27:39 +00:00
|
|
|
/**
|
2009-06-18 22:09:57 +00:00
|
|
|
* Return a pointer to the specified script.
|
2010-01-25 01:39:44 +00:00
|
|
|
* If the id is invalid, does not refer to a script, or
|
2009-06-18 22:09:57 +00:00
|
|
|
* the script is not loaded, this will return NULL
|
2009-05-15 09:28:31 +00:00
|
|
|
* @param seg ID of the script segment to check for
|
2009-06-18 22:09:57 +00:00
|
|
|
* @return A pointer to the Script object, or NULL
|
2009-05-15 09:27:39 +00:00
|
|
|
*/
|
2010-06-28 12:28:12 +00:00
|
|
|
Script *getScriptIfLoaded(SegmentId seg) const;
|
2009-05-15 09:27:39 +00:00
|
|
|
|
2009-02-22 13:11:43 +00:00
|
|
|
// 2. Clones
|
2009-02-21 23:27:24 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* Allocate a fresh clone
|
|
|
|
* @param addr The offset of the freshly allocated clone
|
|
|
|
* @return Reference to the memory allocated for the clone
|
|
|
|
*/
|
2009-09-04 07:17:34 +00:00
|
|
|
Clone *allocateClone(reg_t *addr);
|
2009-02-21 23:27:24 +00:00
|
|
|
|
2009-09-04 07:17:34 +00:00
|
|
|
/**
|
|
|
|
* Reconstructs clones. Used when restoring saved games
|
|
|
|
*/
|
|
|
|
void reconstructClones();
|
|
|
|
|
2009-02-22 13:11:43 +00:00
|
|
|
// 4. Stack
|
2009-02-21 23:27:24 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* Allocates a data stack
|
|
|
|
* @param size Number of stack entries to reserve
|
|
|
|
* @param segid Segment ID of the stack
|
|
|
|
* @return The physical stack
|
|
|
|
*/
|
2009-05-08 09:53:31 +00:00
|
|
|
DataStack *allocateStack(int size, SegmentId *segid);
|
2009-02-21 23:27:24 +00:00
|
|
|
|
|
|
|
|
2009-02-22 13:11:43 +00:00
|
|
|
// 5. System Strings
|
2009-02-21 23:27:24 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
2010-06-01 14:41:48 +00:00
|
|
|
* Initializes the system string table.
|
2010-01-25 01:39:44 +00:00
|
|
|
*/
|
2010-06-01 14:41:48 +00:00
|
|
|
void initSysStrings();
|
2009-02-21 23:27:24 +00:00
|
|
|
|
|
|
|
|
2009-02-22 13:11:43 +00:00
|
|
|
// 6, 7. Lists and Nodes
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* Allocate a fresh list
|
|
|
|
* @param[in] addr The offset of the freshly allocated list
|
|
|
|
* @return Reference to the memory allocated for the list
|
|
|
|
*/
|
2009-09-12 00:10:07 +00:00
|
|
|
List *allocateList(reg_t *addr);
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* Allocate a fresh node
|
|
|
|
* @param[in] addr The offset of the freshly allocated node
|
|
|
|
* @return Reference to the memory allocated for the node
|
|
|
|
*/
|
2009-09-12 00:10:07 +00:00
|
|
|
Node *allocateNode(reg_t *addr);
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2010-05-26 22:05:51 +00:00
|
|
|
/**
|
|
|
|
* Allocate and initialize a new list node.
|
|
|
|
* @param[in] value The value to set the node to
|
|
|
|
* @param[in] key The key to set
|
|
|
|
* @return Pointer to the newly initialized list node
|
|
|
|
*/
|
|
|
|
reg_t newNode(reg_t value, reg_t key);
|
|
|
|
|
2009-10-07 23:34:24 +00:00
|
|
|
/**
|
|
|
|
* Resolves a list pointer to a list.
|
|
|
|
* @param addr The address to resolve
|
|
|
|
* @return The list referenced, or NULL on error
|
|
|
|
*/
|
|
|
|
List *lookupList(reg_t addr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolves an address into a list node.
|
|
|
|
* @param addr The address to resolve
|
|
|
|
* @return The list node referenced, or NULL on error
|
|
|
|
*/
|
2010-07-22 17:25:21 +00:00
|
|
|
Node *lookupNode(reg_t addr, bool stopOnDiscarded = true);
|
2009-10-07 23:34:24 +00:00
|
|
|
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2009-02-21 23:27:24 +00:00
|
|
|
// 8. Hunk Memory
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* Allocate a fresh chunk of the hunk
|
|
|
|
* @param[in] size Number of bytes to allocate for the hunk entry
|
2010-01-25 01:39:44 +00:00
|
|
|
* @param[in] hunk_type A descriptive string for the hunk entry, for
|
2013-11-23 11:02:24 +01:00
|
|
|
* debugging purposes
|
2010-05-18 13:05:09 +00:00
|
|
|
* @return The offset of the freshly allocated hunk entry
|
2009-06-18 22:09:57 +00:00
|
|
|
*/
|
2010-05-18 13:05:09 +00:00
|
|
|
reg_t allocateHunkEntry(const char *hunk_type, int size);
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* Deallocates a hunk entry
|
|
|
|
* @param[in] addr Offset of the hunk entry to delete
|
|
|
|
*/
|
2009-09-12 00:10:07 +00:00
|
|
|
void freeHunkEntry(reg_t addr);
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2010-05-18 13:05:09 +00:00
|
|
|
/**
|
|
|
|
* Gets a pointer to the hunk memory referenced by a specified handle
|
|
|
|
* @param[in] addr Offset of the hunk entry
|
|
|
|
*/
|
|
|
|
byte *getHunkPointer(reg_t addr);
|
2009-02-22 12:18:22 +00:00
|
|
|
|
2009-02-21 23:27:24 +00:00
|
|
|
// 9. Dynamic Memory
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* Allocate some dynamic memory
|
|
|
|
* @param[in] size Number of bytes to allocate
|
|
|
|
* @param[in] description A descriptive string for debugging purposes
|
|
|
|
* @param[out] addr The offset of the freshly allocated X
|
2010-01-25 01:39:44 +00:00
|
|
|
* @return Raw pointer into the allocated dynamic
|
2009-06-18 22:09:57 +00:00
|
|
|
* memory
|
|
|
|
*/
|
2009-09-06 12:58:43 +00:00
|
|
|
byte *allocDynmem(int size, const char *description, reg_t *addr);
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* Deallocates a piece of dynamic memory
|
|
|
|
* @param[in] addr Offset of the dynmem chunk to free
|
|
|
|
*/
|
2010-08-01 11:10:14 +00:00
|
|
|
bool freeDynmem(reg_t addr);
|
2009-02-20 22:29:49 +00:00
|
|
|
|
|
|
|
|
2009-02-22 13:11:43 +00:00
|
|
|
// Generic Operations on Segments and Addresses
|
2009-02-16 09:23:58 +00:00
|
|
|
|
2009-06-18 22:09:57 +00:00
|
|
|
/**
|
|
|
|
* Dereferences a raw memory pointer
|
|
|
|
* @param[in] reg The reference to dereference
|
|
|
|
* @return The data block referenced
|
|
|
|
*/
|
2009-09-22 00:36:24 +00:00
|
|
|
SegmentRef dereference(reg_t pointer);
|
2009-02-16 09:23:58 +00:00
|
|
|
|
2009-09-14 13:13:20 +00:00
|
|
|
/**
|
|
|
|
* Dereferences a heap pointer pointing to raw memory.
|
|
|
|
* @param pointer The pointer to dereference
|
|
|
|
* @parm entries The number of values expected (for checkingO
|
|
|
|
* @return A physical reference to the address pointed to, or NULL on error or
|
|
|
|
* if not enough entries were available.
|
|
|
|
*/
|
2009-09-14 13:27:09 +00:00
|
|
|
byte *derefBulkPtr(reg_t pointer, int entries);
|
2009-09-14 13:13:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Dereferences a heap pointer pointing to a (list of) register(s).
|
|
|
|
* Ensures alignedness of data.
|
|
|
|
* @param pointer The pointer to dereference
|
|
|
|
* @parm entries The number of values expected (for checking)
|
|
|
|
* @return A physical reference to the address pointed to, or NULL on error or
|
|
|
|
* if not enough entries were available.
|
|
|
|
*/
|
2009-09-14 13:27:09 +00:00
|
|
|
reg_t *derefRegPtr(reg_t pointer, int entries);
|
2009-09-14 13:13:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Dereferences a heap pointer pointing to raw memory.
|
|
|
|
* @param pointer The pointer to dereference
|
|
|
|
* @parm entries The number of values expected (for checking)
|
|
|
|
* @return A physical reference to the address pointed to, or NULL on error or
|
|
|
|
* if not enough entries were available.
|
|
|
|
*/
|
2009-09-14 13:27:09 +00:00
|
|
|
char *derefString(reg_t pointer, int entries = 0);
|
2009-09-14 13:13:20 +00:00
|
|
|
|
2009-09-27 01:49:56 +00:00
|
|
|
/**
|
|
|
|
* Return the string referenced by pointer.
|
|
|
|
* pointer can point to either a raw or non-raw segment.
|
|
|
|
* @param pointer The pointer to dereference
|
|
|
|
* @parm entries The number of values expected (for checking)
|
|
|
|
* @return The string referenced, or an empty string if not enough
|
|
|
|
* entries were available.
|
|
|
|
*/
|
|
|
|
Common::String getString(reg_t pointer, int entries = 0);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies a string from src to dest.
|
|
|
|
* src and dest can point to raw and non-raw segments.
|
|
|
|
* Conversion is performed as required.
|
|
|
|
*/
|
|
|
|
void strcpy(reg_t dest, reg_t src);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies a string from src to dest.
|
|
|
|
* dest can point to a raw or non-raw segment.
|
|
|
|
* Conversion is performed as required.
|
|
|
|
*/
|
|
|
|
void strcpy(reg_t dest, const char *src);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies a string from src to dest.
|
|
|
|
* src and dest can point to raw and non-raw segments.
|
|
|
|
* Conversion is performed as required. At most n characters are copied.
|
|
|
|
* TODO: determine if dest should always be null-terminated.
|
|
|
|
*/
|
|
|
|
void strncpy(reg_t dest, reg_t src, size_t n);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies a string from src to dest.
|
|
|
|
* dest can point to a raw or non-raw segment.
|
|
|
|
* Conversion is performed as required. At most n characters are copied.
|
|
|
|
* TODO: determine if dest should always be null-terminated.
|
|
|
|
*/
|
|
|
|
void strncpy(reg_t dest, const char *src, size_t n);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies n bytes of data from src to dest.
|
|
|
|
* src and dest can point to raw and non-raw segments.
|
|
|
|
* Conversion is performed as required.
|
|
|
|
*/
|
|
|
|
void memcpy(reg_t dest, reg_t src, size_t n);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies n bytes of data from src to dest.
|
|
|
|
* dest can point to a raw or non-raw segment.
|
|
|
|
* Conversion is performed as required.
|
|
|
|
*/
|
|
|
|
void memcpy(reg_t dest, const byte* src, size_t n);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies n bytes of data from src to dest.
|
|
|
|
* src can point to raw and non-raw segments.
|
|
|
|
* Conversion is performed as required.
|
|
|
|
*/
|
|
|
|
void memcpy(byte *dest, reg_t src, size_t n);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine length of string at str.
|
|
|
|
* str can point to a raw or non-raw segment.
|
|
|
|
*/
|
|
|
|
size_t strlen(reg_t str);
|
|
|
|
|
2009-09-07 06:07:18 +00:00
|
|
|
/**
|
|
|
|
* Finds a unique segment by type
|
|
|
|
* @param type The type of the segment to find
|
|
|
|
* @return The segment number, or -1 if the segment wasn't found
|
|
|
|
*/
|
2010-06-28 12:28:12 +00:00
|
|
|
SegmentId findSegmentByType(int type) const;
|
2009-09-07 06:07:18 +00:00
|
|
|
|
|
|
|
// TODO: document this
|
2010-06-28 12:28:12 +00:00
|
|
|
SegmentObj *getSegmentObj(SegmentId seg) const;
|
2009-09-07 06:07:18 +00:00
|
|
|
|
|
|
|
// TODO: document this
|
2010-06-28 12:28:12 +00:00
|
|
|
SegmentType getSegmentType(SegmentId seg) const;
|
2009-09-07 06:07:18 +00:00
|
|
|
|
2010-05-18 13:05:09 +00:00
|
|
|
// TODO: document this
|
2010-06-28 12:28:12 +00:00
|
|
|
SegmentObj *getSegment(SegmentId seg, SegmentType type) const;
|
2010-05-18 13:05:09 +00:00
|
|
|
|
2009-09-12 00:10:07 +00:00
|
|
|
/**
|
|
|
|
* Retrieves an object from the specified location
|
|
|
|
* @param[in] offset Location (segment, offset) of the object
|
|
|
|
* @return The object in question, or NULL if there is none
|
|
|
|
*/
|
2010-06-28 12:28:12 +00:00
|
|
|
Object *getObject(reg_t pos) const;
|
2009-09-12 00:10:07 +00:00
|
|
|
|
2009-09-12 17:42:04 +00:00
|
|
|
/**
|
|
|
|
* Checks whether a heap address contains an object
|
|
|
|
* @parm obj The address to check
|
|
|
|
* @return True if it is an object, false otherwise
|
|
|
|
*/
|
2010-06-28 12:28:12 +00:00
|
|
|
bool isObject(reg_t obj) const { return getObject(obj) != NULL; }
|
2009-09-12 17:42:04 +00:00
|
|
|
|
2009-09-17 00:44:22 +00:00
|
|
|
// TODO: document this
|
2010-06-28 12:28:12 +00:00
|
|
|
bool isHeapObject(reg_t pos) const;
|
2009-09-17 00:44:22 +00:00
|
|
|
|
2009-09-12 00:10:07 +00:00
|
|
|
/**
|
|
|
|
* Determines the name of an object
|
|
|
|
* @param[in] pos Location (segment, offset) of the object
|
|
|
|
* @return A name for that object, or a string describing an error
|
2010-06-15 12:33:20 +00:00
|
|
|
* that occurred while looking it up. The string is stored
|
2009-09-12 00:10:07 +00:00
|
|
|
* in a static buffer and need not be freed (neither may
|
|
|
|
* it be modified).
|
|
|
|
*/
|
|
|
|
const char *getObjectName(reg_t pos);
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2009-10-04 18:36:58 +00:00
|
|
|
/**
|
|
|
|
* Find the address of an object by its name. In case multiple objects
|
|
|
|
* with the same name occur, the optional index parameter can be used
|
|
|
|
* to distinguish between them. If index is -1, then if there is a
|
|
|
|
* unique object with the specified name, its address is returned;
|
|
|
|
* if there are multiple matches, or none, then NULL_REG is returned.
|
|
|
|
*
|
|
|
|
* @param name the name of the object we are looking for
|
|
|
|
* @param index the index of the object in case there are multiple
|
|
|
|
* @return the address of the object, or NULL_REG
|
|
|
|
*/
|
|
|
|
reg_t findObjectByName(const Common::String &name, int index = -1);
|
|
|
|
|
2010-07-01 16:05:29 +00:00
|
|
|
uint32 classTableSize() const { return _classTable.size(); }
|
|
|
|
Class getClass(int index) const { return _classTable[index]; }
|
2010-05-29 23:56:37 +00:00
|
|
|
void setClassOffset(int index, reg_t offset) { _classTable[index].reg = offset; }
|
|
|
|
void resizeClassTable(uint32 size) { _classTable.resize(size); }
|
|
|
|
|
2010-12-07 00:47:05 +00:00
|
|
|
reg_t getSaveDirPtr() const { return _saveDirPtr; }
|
|
|
|
reg_t getParserPtr() const { return _parserPtr; }
|
2010-07-01 16:04:48 +00:00
|
|
|
|
2009-12-21 14:32:54 +00:00
|
|
|
#ifdef ENABLE_SCI32
|
|
|
|
SciArray<reg_t> *allocateArray(reg_t *addr);
|
|
|
|
SciArray<reg_t> *lookupArray(reg_t addr);
|
|
|
|
void freeArray(reg_t addr);
|
|
|
|
SciString *allocateString(reg_t *addr);
|
|
|
|
SciString *lookupString(reg_t addr);
|
|
|
|
void freeString(reg_t addr);
|
2010-07-01 16:04:29 +00:00
|
|
|
SegmentId getStringSegmentId() { return _stringSegId; }
|
2009-12-21 14:32:54 +00:00
|
|
|
#endif
|
2009-09-16 23:55:11 +00:00
|
|
|
|
2010-07-01 16:05:29 +00:00
|
|
|
const Common::Array<SegmentObj *> &getSegments() const { return _heap; }
|
|
|
|
|
2009-05-03 09:25:15 +00:00
|
|
|
private:
|
2010-07-01 16:05:29 +00:00
|
|
|
Common::Array<SegmentObj *> _heap;
|
2010-07-01 16:05:10 +00:00
|
|
|
Common::Array<Class> _classTable; /**< Table of all classes */
|
2009-09-06 13:00:30 +00:00
|
|
|
/** Map script ids to segment ids. */
|
|
|
|
Common::HashMap<int, SegmentId> _scriptSegMap;
|
|
|
|
|
2009-09-02 12:02:37 +00:00
|
|
|
ResourceManager *_resMan;
|
2013-12-04 20:42:16 +01:00
|
|
|
ScriptPatcher *_scriptPatcher;
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2010-07-01 16:04:29 +00:00
|
|
|
SegmentId _clonesSegId; ///< ID of the (a) clones segment
|
|
|
|
SegmentId _listsSegId; ///< ID of the (a) list segment
|
|
|
|
SegmentId _nodesSegId; ///< ID of the (a) node segment
|
|
|
|
SegmentId _hunksSegId; ///< ID of the (a) hunk segment
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2010-12-07 00:47:05 +00:00
|
|
|
// Statically allocated memory for system strings
|
|
|
|
reg_t _saveDirPtr;
|
|
|
|
reg_t _parserPtr;
|
2010-06-01 14:41:48 +00:00
|
|
|
|
2009-12-21 14:32:54 +00:00
|
|
|
#ifdef ENABLE_SCI32
|
2010-07-01 16:04:29 +00:00
|
|
|
SegmentId _arraysSegId;
|
|
|
|
SegmentId _stringSegId;
|
2009-12-21 14:32:54 +00:00
|
|
|
#endif
|
|
|
|
|
2011-11-05 02:53:08 +02:00
|
|
|
public:
|
2009-09-22 00:35:46 +00:00
|
|
|
SegmentObj *allocSegment(SegmentObj *mem, SegmentId *segid);
|
2011-11-05 02:53:08 +02:00
|
|
|
|
|
|
|
private:
|
2011-03-09 23:33:26 +02:00
|
|
|
void deallocate(SegmentId seg);
|
2009-11-04 14:22:17 +00:00
|
|
|
void createClassTable();
|
2009-02-21 23:27:24 +00:00
|
|
|
|
2009-09-06 13:00:30 +00:00
|
|
|
SegmentId findFreeSegment() const;
|
2009-02-21 23:27:24 +00:00
|
|
|
};
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2009-02-21 10:23:36 +00:00
|
|
|
} // End of namespace Sci
|
|
|
|
|
2010-02-03 01:34:15 +00:00
|
|
|
#endif // SCI_ENGINE_SEGMAN_H
|