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.
|
|
|
|
|
|
|
|
* 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.
|
|
|
|
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
2009-02-16 09:23:58 +00:00
|
|
|
|
2009-02-24 15:33:40 +00:00
|
|
|
#ifndef SCI_ENGINE_SEG_MANAGER_H
|
|
|
|
#define SCI_ENGINE_SEG_MANAGER_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"
|
2009-02-24 05:56:26 +00:00
|
|
|
#include "sci/engine/vm.h"
|
2009-02-16 09:23:58 +00:00
|
|
|
|
2009-02-21 10:23:36 +00:00
|
|
|
namespace Sci {
|
|
|
|
|
2009-02-20 22:29:49 +00:00
|
|
|
// SCRIPT_ID must be 0
|
2009-02-21 23:27:24 +00:00
|
|
|
enum idFlag {
|
2009-02-20 22:29:49 +00:00
|
|
|
SCRIPT_ID,
|
|
|
|
SEG_ID
|
2009-02-21 23:27:24 +00:00
|
|
|
};
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2009-05-03 22:46:11 +00:00
|
|
|
#define GET_SEGMENT(mgr, index, rtype) (((index) > 0 && (int)(mgr)._heap.size() > index) ? \
|
|
|
|
(((mgr)._heap[index] && (mgr)._heap[index]->getType() == rtype)? (mgr)._heap[index] : NULL) : NULL)
|
2009-02-16 09:23:58 +00:00
|
|
|
|
2009-05-03 22:46:11 +00:00
|
|
|
#define GET_SEGMENT_ANY(mgr, index) (((index) > 0 && (int)(mgr)._heap.size() > index) ? \
|
|
|
|
(((mgr)._heap[index])? (mgr)._heap[index] : NULL) : NULL)
|
2009-02-16 09:23:58 +00:00
|
|
|
|
2009-05-03 22:46:11 +00:00
|
|
|
#define GET_OBJECT_SEGMENT(mgr, index) (((index) > 0 && (int)(mgr)._heap.size() > index) ? \
|
|
|
|
(((mgr)._heap[index] && ((mgr)._heap[index]->getType() == MEM_OBJ_SCRIPT || (mgr)._heap[index]->getType() == MEM_OBJ_CLONES))? (mgr)._heap[index] \
|
2009-05-03 11:07:07 +00:00
|
|
|
: NULL): NULL)
|
2009-02-16 09:23:58 +00:00
|
|
|
|
2009-05-03 09:25:15 +00:00
|
|
|
class SegManager : public Common::Serializable {
|
2009-02-21 23:27:24 +00:00
|
|
|
public:
|
|
|
|
// Initialize the segment manager
|
|
|
|
SegManager(bool sci1_1);
|
|
|
|
|
|
|
|
// Deallocate all memory associated with the segment manager
|
|
|
|
~SegManager();
|
|
|
|
|
2009-05-03 09:25:15 +00:00
|
|
|
virtual void saveLoadWithSerializer(Common::Serializer &ser);
|
|
|
|
|
2009-02-21 23:27:24 +00:00
|
|
|
// 1. Scripts
|
|
|
|
|
|
|
|
// Allocate a script into the segment manager
|
|
|
|
// Parameters: (int) script_nr: number of the script to load
|
|
|
|
// (state_t *) s: The state containing resource manager handlers to load the
|
|
|
|
// script data
|
|
|
|
// Returns : (int) 0 on failure, 1 on success
|
|
|
|
// (int) *seg_id: The segment ID of the newly allocated segment, on success
|
2009-05-03 22:47:04 +00:00
|
|
|
Script *allocateScript(EngineState *s, int script_nr, int* seg_id);
|
2009-02-21 23:27:24 +00:00
|
|
|
|
|
|
|
// The script must then be initialised; see section (1b.), below.
|
|
|
|
|
|
|
|
// Forcefully deallocate a previously allocated script
|
|
|
|
// Parameters: (int) script_nr: number of the script to deallocate
|
|
|
|
// Returns : (int) 1 on success, 0 on failure
|
|
|
|
int deallocateScript(int script_nr);
|
|
|
|
|
|
|
|
// Determines whether a script has been loaded yet
|
|
|
|
// Parameters: (int) id: number of the script or ID of the script segment to check for
|
|
|
|
// (idFlag) flag: Whether to address the script by script number (SCRIPT_ID) or
|
|
|
|
// by its segment (SEG_ID). SEG_ID is faster than SCRIPT_ID,
|
|
|
|
// but less convenient.
|
|
|
|
int scriptIsLoaded(int id, idFlag flag);
|
|
|
|
|
|
|
|
// Validate whether the specified public function is exported by the script in the specified segment
|
|
|
|
// Parameters: (int) pubfunct: Index of the function to validate
|
|
|
|
// (int) seg: Segment ID of the script the check is to be performed for
|
|
|
|
// Returns : (uint16) 0 if the public function is invalid, its offset into the script's segment
|
|
|
|
// otherwise
|
|
|
|
uint16 validateExportFunc(int pubfunct, int seg);
|
|
|
|
|
|
|
|
// Get the segment ID associated with a script number
|
|
|
|
// Parameters: (int) script_nr: Number of the script to look up
|
|
|
|
// Returns : (int) The associated segment ID, or -1 if no matching segment exists
|
2009-03-17 16:08:25 +00:00
|
|
|
int segGet(int script_nr) const;
|
2009-02-21 23:27:24 +00:00
|
|
|
|
2009-05-03 09:20:21 +00:00
|
|
|
Script *getScript(int id, idFlag flag);
|
|
|
|
|
2009-02-21 23:27:24 +00:00
|
|
|
|
|
|
|
// script lock operations
|
|
|
|
|
|
|
|
// Increments the number of lockers of the script in question by one
|
|
|
|
// Parameters: (int) id: ID of the script or script segment to modify
|
|
|
|
// (idFlag) flag: Whether to address the script by script number (SCRIPT_ID) or
|
|
|
|
// by its segment (SEG_ID). SEG_ID is faster than SCRIPT_ID,
|
|
|
|
// but less convenient.
|
|
|
|
void incrementLockers(int id, idFlag flag);
|
|
|
|
|
|
|
|
// Decrements the number of lockers of the script in question by one
|
|
|
|
// Parameters: (int) id: ID of the script or script segment to modify
|
|
|
|
// (idFlag) flag: Whether to address the script by script number (SCRIPT_ID) or
|
|
|
|
// by its segment (SEG_ID). SEG_ID is faster than SCRIPT_ID,
|
|
|
|
// but less convenient.
|
|
|
|
void decrementLockers(int id, idFlag flag);
|
|
|
|
|
|
|
|
// Retrieves the number of locks held on this script
|
|
|
|
// Parameters: (int) id: ID of the script or script segment to read from
|
|
|
|
// (idFlag) flag: Whether to address the script by script number (SCRIPT_ID) or
|
|
|
|
// by its segment (SEG_ID). SEG_ID is faster than SCRIPT_ID,
|
|
|
|
// but less convenient.
|
|
|
|
// Returns : (int) The number of locks held on the previously identified script
|
|
|
|
int getLockers(int id, idFlag flag);
|
|
|
|
|
|
|
|
// Sets the number of locks held on the specified script
|
|
|
|
// Parameters: (int) id: ID of the script or script segment to modify
|
|
|
|
// (idFlag) flag: Whether to address the script by script number (SCRIPT_ID) or
|
|
|
|
// by its segment (SEG_ID). SEG_ID is faster than SCRIPT_ID,
|
|
|
|
// but less convenient.
|
|
|
|
void setLockers(int lockers, int id, idFlag flag);
|
|
|
|
|
|
|
|
// Retrieves a pointer to the synonyms associated with the specified script
|
|
|
|
// Parameters: (int) id: ID of the script or script segment to read from
|
|
|
|
// (idFlag) flag: Whether to address the script by script number (SCRIPT_ID) or
|
|
|
|
// by its segment (SEG_ID). SEG_ID is faster than SCRIPT_ID,
|
|
|
|
// but less convenient.
|
|
|
|
// Returns : (byte *) Pointer to the synonyms, in non-parsed format.
|
|
|
|
// A dynamic failure is issued if the specified ID does not reference a proper script.
|
|
|
|
byte *getSynonyms(int id, idFlag flag);
|
|
|
|
|
|
|
|
// Retrieves the number of synonyms associated with the specified script
|
|
|
|
// Parameters: (int) id: ID of the script or script segment to read from
|
|
|
|
// (idFlag) flag: Whether to address the script by script number (SCRIPT_ID) or
|
|
|
|
// by its segment (SEG_ID). SEG_ID is faster than SCRIPT_ID,
|
|
|
|
// but less convenient.
|
|
|
|
// Returns : (int) The number of synonyms associated with the specified script
|
|
|
|
// A dynamic failure is issued if the specified ID does not reference a proper script.
|
|
|
|
int getSynonymsNr(int id, idFlag flag);
|
|
|
|
|
|
|
|
|
2009-02-22 13:11:43 +00:00
|
|
|
// 1b. Script Initialisation
|
2009-02-21 23:27:24 +00:00
|
|
|
|
2009-02-22 13:11:43 +00:00
|
|
|
// The set of functions below are intended
|
|
|
|
// to be used during script instantiation,
|
|
|
|
// i.e. loading and linking.
|
2009-02-21 23:27:24 +00:00
|
|
|
|
|
|
|
// Initializes a script's local variable block
|
2009-02-28 11:12:59 +00:00
|
|
|
// Parameters: (SegmentId) seg: Segment containing the script to initialize
|
2009-02-21 23:27:24 +00:00
|
|
|
// (int) nr: Number of local variables to allocate
|
|
|
|
// All variables are initialized to zero.
|
2009-02-28 11:12:59 +00:00
|
|
|
void scriptInitialiseLocalsZero(SegmentId seg, int nr);
|
2009-02-21 23:27:24 +00:00
|
|
|
|
|
|
|
// Initializes a script's local variable block according to a prototype
|
|
|
|
// Parameters: (reg_t) location: Location to initialize from
|
|
|
|
void scriptInitialiseLocals(reg_t location);
|
|
|
|
|
|
|
|
// Initializes an object within the segment manager
|
|
|
|
// Parameters: (reg_t) obj_pos: Location (segment, offset) of the object
|
2009-02-28 11:12:59 +00:00
|
|
|
// Returns : (Object *) A newly created Object describing the object
|
2009-02-21 23:27:24 +00:00
|
|
|
// obj_pos must point to the beginning of the script/class block (as opposed
|
|
|
|
// to what the VM considers to be the object location)
|
2009-02-28 11:12:59 +00:00
|
|
|
// The corresponding Object is stored within the relevant script.
|
|
|
|
Object *scriptObjInit(EngineState *s, reg_t obj_pos);
|
2009-02-21 23:27:24 +00:00
|
|
|
|
|
|
|
// Informs the segment manager that a code block must be relocated
|
|
|
|
// Parameters: (reg_t) location: Start of block to relocate
|
|
|
|
void scriptAddCodeBlock(reg_t location);
|
|
|
|
|
|
|
|
// Tells the segment manager whether exports are wide (32-bit) or not.
|
2009-02-22 13:11:43 +00:00
|
|
|
// Parameters: (int) flag: 1 if exports are wide, 0 otherwise
|
2009-02-21 23:27:24 +00:00
|
|
|
void setExportWidth(int flag);
|
|
|
|
|
|
|
|
// Processes a relocation block witin a script
|
|
|
|
// Parameters: (reg_t) obj_pos: Location (segment, offset) of the block
|
2009-02-28 11:12:59 +00:00
|
|
|
// Returns : (Object *) Location of the relocation block
|
2009-02-21 23:27:24 +00:00
|
|
|
// This function is idempotent, but it must only be called after all
|
|
|
|
// objects have been instantiated, or a run-time error will occur.
|
|
|
|
void scriptRelocate(reg_t block);
|
|
|
|
|
|
|
|
// Sets the script-relative offset of the exports table
|
|
|
|
// Parameters: (int) offset: The script-relative exports table offset
|
|
|
|
// (int) id: ID of the script or script segment to write to
|
|
|
|
// (idFlag) flag: Whether to address the script by script number (SCRIPT_ID) or
|
|
|
|
// by its segment (SEG_ID). SEG_ID is faster than SCRIPT_ID,
|
|
|
|
// but less convenient.
|
|
|
|
// A dynamic failure is issued if the specified ID does not reference a proper script.
|
|
|
|
void setExportTableOffset(int offset, int id, idFlag flag);
|
|
|
|
|
|
|
|
// Sets the script-relative offset of the synonyms associated with the specified script
|
|
|
|
// Parameters: (int) offset: The script-relative offset of the synonyms block
|
|
|
|
// (int) id: ID of the script or script segment to write to
|
|
|
|
// (idFlag) flag: Whether to address the script by script number (SCRIPT_ID) or
|
|
|
|
// by its segment (SEG_ID). SEG_ID is faster than SCRIPT_ID,
|
|
|
|
// but less convenient.
|
|
|
|
// A dynamic failure is issued if the specified ID does not reference a proper script.
|
|
|
|
void setSynonymsOffset(int offset, int id, idFlag flag);
|
|
|
|
|
|
|
|
// Sets the number of synonyms associated with the specified script
|
|
|
|
// Parameters: (int) nr: The number of synonyms, as to be stored within the script
|
|
|
|
// (int) id: ID of the script or script segment to write to
|
|
|
|
// (idFlag) flag: Whether to address the script by script number (SCRIPT_ID) or
|
|
|
|
// by its segment (SEG_ID). SEG_ID is faster than SCRIPT_ID,
|
|
|
|
// but less convenient.
|
|
|
|
// A dynamic failure is issued if the specified ID does not reference a proper script.
|
|
|
|
void setSynonymsNr(int nr, int id, idFlag flag);
|
|
|
|
|
|
|
|
// Marks the script identified by its script number as deleted
|
|
|
|
// Parameters: (int) script_nr: Script number to mark as deleted
|
|
|
|
// This will not actually delete the script. If references remain present on the
|
|
|
|
// heap or the stack, the script will stay in memory in a quasi-deleted state until
|
|
|
|
// either unreachable (resulting in its eventual deletion) or reloaded (resulting
|
|
|
|
// in its data being updated).
|
|
|
|
void markScriptDeleted(int script_nr);
|
|
|
|
|
|
|
|
// Marks the script identified by its script number as not deleted
|
|
|
|
// Parameters: (int) script_nr: Script number to mark as not deleted
|
|
|
|
void unmarkScriptDeleted(int script_nr);
|
|
|
|
|
|
|
|
// Determines whether the script referenced by the indicated segment is marked as being deleted.
|
2009-02-28 11:12:59 +00:00
|
|
|
// Parameters: (SegmentId) Segment ID of the script to investigate
|
2009-02-21 23:27:24 +00:00
|
|
|
// Returns : (int) 1 iff seg points to a script and the segment is deleted, 0 otherwise
|
|
|
|
// Will return 0 when applied to an invalid or non-script seg.
|
2009-02-28 11:12:59 +00:00
|
|
|
int scriptIsMarkedAsDeleted(SegmentId seg);
|
2009-02-21 23:27:24 +00:00
|
|
|
|
|
|
|
|
2009-02-22 13:11:43 +00:00
|
|
|
// 2. Clones
|
2009-02-21 23:27:24 +00:00
|
|
|
|
|
|
|
// Allocate a fresh clone
|
2009-02-28 11:12:59 +00:00
|
|
|
// Returns : (Clone*): Reference to the memory allocated for the clone
|
2009-02-21 23:27:24 +00:00
|
|
|
// (reg_t) *addr: The offset of the freshly allocated clone
|
2009-02-28 11:12:59 +00:00
|
|
|
Clone *alloc_Clone(reg_t *addr);
|
2009-02-21 23:27:24 +00:00
|
|
|
|
|
|
|
|
2009-02-22 13:11:43 +00:00
|
|
|
// 3. Objects (static, from Scripts, and dynmic, from Clones)
|
2009-02-21 23:27:24 +00:00
|
|
|
|
2009-02-22 13:11:43 +00:00
|
|
|
// Not all of these functions are fully operational for clones ATM
|
2009-02-21 23:27:24 +00:00
|
|
|
|
|
|
|
// Retrieves a 16 bit value from within a script's heap representation
|
|
|
|
// Parameters: (reg_t) reg: The address to read from
|
|
|
|
// Returns : (int16) The value read from the specified location
|
|
|
|
int16 getHeap(reg_t reg);
|
|
|
|
|
|
|
|
// Copies a byte string into a script's heap representation
|
|
|
|
// Parameters: (int) dst: The script-relative offset of the destination area
|
|
|
|
// (const void *) src: Pointer to the data source location
|
|
|
|
// (size_t) n: Number of bytes to copy
|
|
|
|
// (int) id: ID of the script or script segment to write to
|
|
|
|
// (idFlag) flag: Whether to address the script by script number (SCRIPT_ID) or
|
|
|
|
// by its segment (SEG_ID). SEG_ID is faster than SCRIPT_ID,
|
|
|
|
// but less convenient.
|
|
|
|
// A dynamic failure is issued if the specified ID does not reference a proper script.
|
2009-05-03 09:20:21 +00:00
|
|
|
void mcpyInOut(int dst, const void *src, size_t n, int id, idFlag flag);
|
2009-02-21 23:27:24 +00:00
|
|
|
|
|
|
|
|
2009-02-22 13:11:43 +00:00
|
|
|
// 4. Stack
|
2009-02-21 23:27:24 +00:00
|
|
|
|
|
|
|
// Allocates a data stack
|
|
|
|
// Parameters: (int) size: Number of stack entries to reserve
|
2009-05-08 09:53:31 +00:00
|
|
|
// Returns : (DataStack *): The physical stack
|
2009-02-28 11:12:59 +00:00
|
|
|
// (SegmentId) segid: Segment ID of the 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
|
|
|
|
|
|
|
// Allocates a system string table
|
2009-05-08 09:53:31 +00:00
|
|
|
// Returns : (DataStack *): The physical stack
|
2009-02-28 11:12:59 +00:00
|
|
|
// (SegmentId) segid: Segment ID of the stack
|
|
|
|
// See also sys_string_acquire();
|
|
|
|
SystemStrings *allocateSysStrings(SegmentId *segid);
|
2009-02-21 23:27:24 +00:00
|
|
|
|
|
|
|
|
2009-03-10 14:52:02 +00:00
|
|
|
// 5. System Strings
|
|
|
|
|
|
|
|
// Allocates a string fragments segment
|
|
|
|
// Returns : (SegmentId): Segment ID to use for string fragments
|
|
|
|
// See also stringfrag.h
|
|
|
|
SegmentId allocateStringFrags();
|
|
|
|
|
|
|
|
|
2009-02-22 13:11:43 +00:00
|
|
|
// 6, 7. Lists and Nodes
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2009-02-21 23:27:24 +00:00
|
|
|
// Allocate a fresh list
|
|
|
|
// Returns : (listY_t*): Reference to the memory allocated for the list
|
|
|
|
// (reg_t) *addr: The offset of the freshly allocated list
|
2009-02-28 11:12:59 +00:00
|
|
|
List *alloc_List(reg_t *addr);
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2009-02-21 23:27:24 +00:00
|
|
|
// Allocate a fresh node
|
|
|
|
// Returns : (node_t*): Reference to the memory allocated for the node
|
|
|
|
// (reg_t) *addr: The offset of the freshly allocated node
|
2009-02-28 11:12:59 +00:00
|
|
|
Node *alloc_Node(reg_t *addr);
|
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-02-21 23:27:24 +00:00
|
|
|
// Allocate a fresh chunk of the hunk
|
|
|
|
// Parameters: (int) size: Number of bytes to allocate for the hunk entry
|
|
|
|
// (const char *) hunk_type: A descriptive string for the hunk entry,
|
|
|
|
// for debugging purposes
|
2009-02-28 11:12:59 +00:00
|
|
|
// Returns : (Hunk *): Reference to the memory allocated for the hunk piece
|
2009-02-21 23:27:24 +00:00
|
|
|
// (reg_t) *addr: The offset of the freshly allocated hunk entry
|
2009-02-28 11:12:59 +00:00
|
|
|
Hunk *alloc_hunk_entry(const char *hunk_type, int size, reg_t *addr);
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2009-02-21 23:27:24 +00:00
|
|
|
// Deallocates a hunk entry
|
|
|
|
// Parameters: (reg_t) addr: Offset of the hunk entry to delete
|
|
|
|
void free_hunk_entry(reg_t addr);
|
2009-02-20 22:29:49 +00:00
|
|
|
|
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-02-21 23:27:24 +00:00
|
|
|
// Allocate some dynamic memory
|
|
|
|
// Parameters: (int) size: Number of bytes to allocate
|
|
|
|
// (const char_ *) description: A descriptive string,
|
|
|
|
// for debugging purposes
|
|
|
|
// Returns : (unsigned char*): Raw pointer into the allocated dynamic memory
|
|
|
|
// (reg_t) *addr: The offset of the freshly allocated X
|
|
|
|
unsigned char *allocDynmem(int size, const char *description, reg_t *addr);
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2009-02-21 23:27:24 +00:00
|
|
|
// Deallocates a piece of dynamic memory
|
|
|
|
// Parameters: (reg_t) addr: Offset of the dynmem chunk to free
|
|
|
|
int freeDynmem(reg_t addr);
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2009-02-21 23:27:24 +00:00
|
|
|
// Gets the description of a dynmem segment
|
|
|
|
// Parameters: (reg_t) addr: Segment to describe
|
|
|
|
// Returns : (const char *): Pointer to the descriptive string set in
|
|
|
|
// allocDynmem
|
|
|
|
const char *getDescription(reg_t addr);
|
2009-02-20 22:29:49 +00:00
|
|
|
|
|
|
|
|
2009-02-22 13:11:43 +00:00
|
|
|
// 10. Reserved segments
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2009-02-21 23:27:24 +00:00
|
|
|
// Reserves a special-purpose segment
|
|
|
|
// Parameters: (char *) name: A string name identifying the segment (the string is cloned and retained)
|
|
|
|
// Returns : A fresh segment ID for the segment in question
|
|
|
|
// Reserved segments are never used by the segment manager. They can be used to tag special-purpose addresses.
|
|
|
|
// Segment 0 is implicitly reserved for numbers.
|
2009-02-28 11:12:59 +00:00
|
|
|
//SegmentId sm_allocate_reserved_segment(char *name);
|
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-02-21 23:27:24 +00:00
|
|
|
// Dereferences a raw memory pointer
|
|
|
|
// Parameters: (reg_t) reg: The reference to dereference
|
|
|
|
// Returns : (byte *) The data block referenced
|
|
|
|
// (int) size: (optionally) the theoretical maximum size of it
|
|
|
|
byte *dereference(reg_t reg, int *size);
|
2009-02-16 09:23:58 +00:00
|
|
|
|
2009-02-20 22:29:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2009-02-21 23:27:24 +00:00
|
|
|
void heapRelocate(EngineState *s, reg_t block);
|
|
|
|
void scriptRelocateExportsSci11(int seg);
|
|
|
|
void scriptInitialiseObjectsSci11(EngineState *s, int seg);
|
|
|
|
int scriptMarkedDeleted(int script_nr);
|
2009-05-03 09:21:08 +00:00
|
|
|
int initialiseScript(Script &scr, EngineState *s, int script_nr);
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2009-05-03 09:25:15 +00:00
|
|
|
private:
|
2009-02-24 02:59:50 +00:00
|
|
|
IntMapper *id_seg_map; // id - script id; seg - index of heap
|
2009-05-03 09:25:15 +00:00
|
|
|
public: // TODO: make private
|
2009-05-03 22:46:11 +00:00
|
|
|
Common::Array<MemObject *> _heap;
|
2009-02-21 23:27:24 +00:00
|
|
|
int reserved_id;
|
|
|
|
int exports_wide;
|
|
|
|
bool isSci1_1;
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2009-02-21 23:27:24 +00:00
|
|
|
int gc_mark_bits;
|
|
|
|
// For standard Mark&Sweep:
|
|
|
|
// 1 or 0, depending on what unreachable/freshly allocated
|
|
|
|
// memory is tagged as
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
SegmentId Clones_seg_id; // ID of the (a) clones segment
|
|
|
|
SegmentId Lists_seg_id; // ID of the (a) list segment
|
|
|
|
SegmentId Nodes_seg_id; // ID of the (a) node segment
|
|
|
|
SegmentId Hunks_seg_id; // ID of the (a) hunk segment
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2009-02-21 23:27:24 +00:00
|
|
|
private:
|
2009-05-03 22:46:38 +00:00
|
|
|
MemObject *allocNonscriptSegment(MemObjectType type, SegmentId *segid);
|
2009-02-28 11:12:59 +00:00
|
|
|
LocalVariables *allocLocalsSegment(Script *scr, int count);
|
2009-05-03 22:46:38 +00:00
|
|
|
MemObject *memObjAllocate(SegmentId segid, int hash_id, MemObjectType type);
|
2009-02-21 23:27:24 +00:00
|
|
|
int deallocate(int seg, bool recursive);
|
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
Hunk *alloc_Hunk(reg_t *);
|
2009-02-21 23:27:24 +00:00
|
|
|
|
2009-03-12 03:26:47 +00:00
|
|
|
int relocateLocal(Script *scr, SegmentId segment, int location);
|
2009-05-12 23:30:42 +00:00
|
|
|
int relocateBlock(Common::Array<reg_t> &block, int block_location, SegmentId segment, int location);
|
2009-03-12 03:26:47 +00:00
|
|
|
int relocateObject(Object *obj, SegmentId segment, int location);
|
2009-02-21 23:27:24 +00:00
|
|
|
|
2009-03-12 03:26:47 +00:00
|
|
|
int findFreeId(int *id);
|
2009-05-03 09:21:08 +00:00
|
|
|
static void setScriptSize(Script &scr, EngineState *s, int script_nr);
|
2009-02-28 11:12:59 +00:00
|
|
|
Object *scriptObjInit0(EngineState *s, reg_t obj_pos);
|
|
|
|
Object *scriptObjInit11(EngineState *s, reg_t obj_pos);
|
2009-02-21 23:27:24 +00:00
|
|
|
|
|
|
|
/* Check segment validity
|
|
|
|
** Parameters: (int) seg: The segment to validate
|
|
|
|
** Returns : (bool) false if 'seg' is an invalid segment
|
|
|
|
** true if 'seg' is a valid segment
|
|
|
|
*/
|
|
|
|
bool check(int seg);
|
|
|
|
|
|
|
|
void dbgPrint(const char* msg, void *i); // for debug only
|
|
|
|
|
|
|
|
// Perform garbage collection
|
|
|
|
// Parameters: (EngineState *) s: The state to operate on
|
|
|
|
// Effects : Unreachable objects in 's' are deallocated
|
|
|
|
//void sm_gc(EngineState *s);
|
|
|
|
};
|
2009-02-20 22:29:49 +00:00
|
|
|
|
2009-02-21 10:23:36 +00:00
|
|
|
} // End of namespace Sci
|
|
|
|
|
2009-02-24 15:33:40 +00:00
|
|
|
#endif // SCI_ENGINE_SEG_MANAGER
|