From 501e4bb91a9f1bf91e6632dc158ee343dc1e069e Mon Sep 17 00:00:00 2001 From: Jordi Vilalta Prat Date: Sat, 28 Feb 2009 11:12:59 +0000 Subject: SCI: Renamed some kernel types and general cleanup svn-id: r38961 --- engines/sci/engine/game.cpp | 18 +- engines/sci/engine/gc.cpp | 8 +- engines/sci/engine/heap.cpp | 286 ------ engines/sci/engine/heap.h | 115 --- engines/sci/engine/heapmgr.h | 38 +- engines/sci/engine/kernel.cpp | 8 +- engines/sci/engine/kernel.h | 24 +- engines/sci/engine/kgraphics.cpp | 30 +- engines/sci/engine/klists.cpp | 78 +- engines/sci/engine/kmovement.cpp | 4 +- engines/sci/engine/kpathing.cpp | 12 +- engines/sci/engine/kscripts.cpp | 37 +- engines/sci/engine/kstring.cpp | 12 +- engines/sci/engine/message.cpp | 38 +- engines/sci/engine/message.h | 32 +- engines/sci/engine/savegame.cfsml | 133 ++- engines/sci/engine/savegame.cpp | 1835 +++++++++++++++++----------------- engines/sci/engine/script.h | 3 + engines/sci/engine/scriptconsole.cpp | 6 +- engines/sci/engine/scriptdebug.cpp | 118 +-- engines/sci/engine/seg_manager.cpp | 280 +++--- engines/sci/engine/seg_manager.h | 103 +- engines/sci/engine/state.h | 20 +- engines/sci/engine/vm.cpp | 126 +-- engines/sci/engine/vm.h | 274 ++--- engines/sci/engine/vm_types.h | 9 +- 26 files changed, 1627 insertions(+), 2020 deletions(-) delete mode 100644 engines/sci/engine/heap.cpp delete mode 100644 engines/sci/engine/heap.h diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index 04a410d51b..20ff91b476 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -37,7 +37,7 @@ namespace Sci { // Structures and data from vm.c: -extern calls_struct_t *send_calls; +extern CallsStruct *send_calls; extern int send_calls_allocated; extern int bp_flag; @@ -314,7 +314,7 @@ int create_class_table_sci11(EngineState *s) { else s->classtable_size = vocab996->size >> 2; - s->classtable = (class_t*)sci_calloc(sizeof(class_t), s->classtable_size); + s->classtable = (Class*)sci_calloc(sizeof(Class), s->classtable_size); for (scriptnr = 0; scriptnr < 1000; scriptnr++) { resource_t *heap = scir_find_resource(s->resmgr, sci_heap, scriptnr, 0); @@ -335,9 +335,9 @@ int create_class_table_sci11(EngineState *s) { return 1; } - s->classtable = (class_t*)sci_realloc(s->classtable, sizeof(class_t) * (classnr + 1)); + s->classtable = (Class*)sci_realloc(s->classtable, sizeof(Class) * (classnr + 1)); // Clear after resize - memset(&(s->classtable[s->classtable_size]), 0, sizeof(class_t) * (1 + classnr - s->classtable_size)); + memset(&(s->classtable[s->classtable_size]), 0, sizeof(Class) * (1 + classnr - s->classtable_size)); s->classtable_size = classnr + 1; // Adjust maximum number of entries } @@ -369,7 +369,7 @@ static int create_class_table_sci0(EngineState *s) { else s->classtable_size = vocab996->size >> 2; - s->classtable = (class_t*)sci_calloc(sizeof(class_t), s->classtable_size); + s->classtable = (Class*)sci_calloc(sizeof(Class), s->classtable_size); for (scriptnr = 0; scriptnr < 1000; scriptnr++) { int objtype = 0; @@ -409,9 +409,9 @@ static int create_class_table_sci0(EngineState *s) { return 1; } - s->classtable = (class_t*)sci_realloc(s->classtable, sizeof(class_t) * (classnr + 1)); + s->classtable = (Class*)sci_realloc(s->classtable, sizeof(Class) * (classnr + 1)); // Clear after resize - memset(&(s->classtable[s->classtable_size]), 0, sizeof(class_t) * (1 + classnr - s->classtable_size)); + memset(&(s->classtable[s->classtable_size]), 0, sizeof(Class) * (1 + classnr - s->classtable_size)); s->classtable_size = classnr + 1; // Adjust maximum number of entries } @@ -559,7 +559,7 @@ void script_free_engine(EngineState *s) { } void script_free_breakpoints(EngineState *s) { - breakpoint_t *bp, *bp_next; + Breakpoint *bp, *bp_next; // Free breakpoint list bp = s->bp_list; @@ -602,7 +602,7 @@ int game_init(EngineState *s) { if (!send_calls_allocated) { send_calls_allocated = 16; - send_calls = (calls_struct_t*)sci_calloc(sizeof(calls_struct_t), send_calls_allocated); + send_calls = (CallsStruct*)sci_calloc(sizeof(CallsStruct), send_calls_allocated); } if (s->gfx_state && _reset_graphics_input(s)) diff --git a/engines/sci/engine/gc.cpp b/engines/sci/engine/gc.cpp index 531ecf8d19..ae0b9fefed 100644 --- a/engines/sci/engine/gc.cpp +++ b/engines/sci/engine/gc.cpp @@ -153,7 +153,7 @@ reg_t_hash_map *find_all_used_references(EngineState *s) { // Init: Value Stack // We do this one by hand since the stack doesn't know the current execution stack { - exec_stack_t *xs = s->execution_stack + s->execution_stack_pos; + ExecStack *xs = s->execution_stack + s->execution_stack_pos; reg_t *pos; for (pos = s->stack_base; pos < xs->sp; pos++) @@ -165,7 +165,7 @@ reg_t_hash_map *find_all_used_references(EngineState *s) { // Init: Execution Stack for (i = 0; i <= s->execution_stack_pos; i++) { - exec_stack_t *es = s->execution_stack + i; + ExecStack *es = s->execution_stack + i; if (es->type != EXEC_STACK_TYPE_KERNEL) { worklist_push(&worklist, nonnormal_map, es->objp); @@ -182,7 +182,7 @@ reg_t_hash_map *find_all_used_references(EngineState *s) { for (i = 1; i < sm->heap_size; i++) if (interfaces[i] && interfaces[i]->getType() == MEM_OBJ_SCRIPT) { - script_t *script = &(interfaces[i]->getMobj()->data.script); + Script *script = &(interfaces[i]->getMobj()->data.script); if (script->lockers) { // Explicitly loaded? int obj_nr; @@ -192,7 +192,7 @@ reg_t_hash_map *find_all_used_references(EngineState *s) { // All objects (may be classes, may be indirectly reachable) for (obj_nr = 0; obj_nr < script->objects_nr; obj_nr++) { - object_t *obj = script->objects + obj_nr; + Object *obj = script->objects + obj_nr; worklist_push(&worklist, nonnormal_map, obj->pos); } } diff --git a/engines/sci/engine/heap.cpp b/engines/sci/engine/heap.cpp deleted file mode 100644 index 5907582e37..0000000000 --- a/engines/sci/engine/heap.cpp +++ /dev/null @@ -1,286 +0,0 @@ -/* 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$ - * - */ - -#include "sci/engine/state.h" -#include "sci/scicore/sciconsole.h" -#include "sci/engine/heap.h" - -namespace Sci { - -#define assert_in_range(pos) assert(pos >= 1000 && pos <= 0xffff) - -static void set_size(heap_t *h, int block_pos, int size) { - assert_in_range(block_pos); - assert(size <= 0xffff - 1000); - putInt16(h->start + block_pos, size); -} - -static void set_next(heap_t *h, int block_pos, int next) { - assert_in_range(block_pos); - assert_in_range(next); - putInt16(h->start + block_pos + 2, next); -} - - -static unsigned int get_size(heap_t *h, int block_pos) { - assert_in_range(block_pos); - return (uint16)getInt16(h->start + block_pos); -} - -static unsigned int get_next(heap_t *h, int block_pos) { - assert_in_range(block_pos); - return (uint16)getInt16(h->start + block_pos + 2); -} - -// Allocates a new heap -heap_t *heap_new() { - heap_t *h; - - if ((h = (heap_t*)sci_malloc(sizeof(heap_t))) == 0) - return 0; - - if ((h->start = (byte *)sci_calloc(SCI_HEAP_SIZE, 1)) == 0) { - free(h); - return 0; - } - - h->base = h->start + 1000; - h->first_free = 1000; - h->old_ff = -1; - set_size(h, 1000, 0xffff - 1000); - set_next(h, 1000, 0xffff); - - return h; -} - -// Deletes a heap -void heap_del(heap_t *h) { - free(h->start); - free(h); -} - -int heap_meminfo(heap_t *h) { - heap_ptr current = h->first_free; - int total = 0; - - while (current != 0xffff) { - total += get_size(h, current); - current = get_next(h, current); - } - - return total; -} - - -int heap_largest(heap_t *h) { - int current = h->first_free; - int best_pos = -1, best_size = 0; - - while (current != 0xffff) { - int size = get_size(h, current); - int next = get_next(h, current); - - if (size > best_size) { - best_pos = current; - best_size = size; - } - - current = next; - } - - return best_size; -} - -heap_ptr heap_allocate(heap_t *h, int size) { - unsigned int previous = h->first_free; - unsigned int current = previous; - - if (!size) { - fprintf(stderr, "Warning: heap_alloc'd zero bytes!\n"); - size += 2; - } - - size += 2 + (size & 1); - - while (current < 0xffff) { - int block_size = get_size(h, current); - int next = get_next(h, current); - - // Is this block large enough? - if (block_size >= size) { - // Swallow the block whole - if (block_size <= size + 4) { - size = block_size; - set_next(h, previous, next); - } else { - // Split the block - int rest = current + size; - - set_next(h, previous, rest); - set_size(h, rest, block_size - size); - set_next(h, rest, next); - next = rest; - } - set_size(h, current, size); - if (current == h->first_free) h->first_free = next; - return current; - } - previous = current; - current = next; - } - - // No large enough block was found. - return 0; -} - -void heap_free(heap_t *h, unsigned int m) { - unsigned int previous, next; - assert_in_range(m); - previous = next = h->first_free; - - // Find the previous and next blocks - while (next < m) { - previous = next; - assert(previous < 0xffff); - next = get_next(h, previous); - if (next <= previous) { - sciprintf("Heap corrupt. Aborting heap_free()...\n"); - return; - } - } - - if (h->first_free > m) - h->first_free = m; // Guarantee that first_free is correct - - if (previous == next) { - if (m < previous) { - h->first_free = m; - if (m + get_size(h, m) == previous) { - set_size(h, m, get_size(h, m) + get_size(h, previous)); - set_next(h, m, get_next(h, previous)); - } else - set_next(h, m, previous); - } else { - if (previous + get_size(h, previous) == m) { - set_size(h, previous, get_size(h, previous) + get_size(h, m)); - set_next(h, previous, 0xffff); - } else { - set_next(h, previous, m); - set_next(h, m, next); - } - } - } else { - set_next(h, previous, m); - set_next(h, m, next); - - // Try to merge with previous - if (previous + get_size(h, previous) == m) { - set_size(h, previous, get_size(h, previous) + get_size(h, m)); - set_next(h, previous, next); - m = previous; - } - - // Try to merge with next - if (m + get_size(h, m) == next) { - set_size(h, m, get_size(h, m) + get_size(h, next)); - set_next(h, m, get_next(h, next)); - } - } -} - -void save_ff(heap_t *h) { - h->old_ff = h->first_free; -} - -void restore_ff(heap_t *h) { - h->first_free = h->old_ff; - set_size(h, h->first_free, 0xffff - h->first_free); - set_next(h, h->first_free, 0xffff); -} - -void heap_dump_free(heap_t *h) { - int freedomseeker; - - printf("\tfirst_free= %#x (oldff= %#x)\n\tFree Blocks:\n", h->first_free, h->old_ff); - - freedomseeker = h->first_free; - while (freedomseeker != 0xffff) { - printf("\t %#04x: size: %#04x\n", freedomseeker, get_size(h, freedomseeker)); - freedomseeker = get_next(h, freedomseeker); - } -} - -void heap_dump_all(heap_t *h) { - int seeker = 1000; - int free_seeker = h->first_free; - - while (seeker < 0xffff) { - int is_free = (seeker == free_seeker); - int size = get_size(h, seeker); - - if (is_free) - free_seeker = get_next(h, free_seeker); - - printf("%04x\t%d\t%s\n", seeker, size, is_free ? "FREE" : ""); - seeker += size; - } -} - -#if 0 -int main(int argc, char **argv) { - heap_t *h = heap_new(); - int a, b, c, d, e; - - printf("Running heap tests:\nHeap initialization:\n"); - heap_dump_free(h); - - printf("[a] Allocating 0x1: position is %#x\n", a = heap_allocate(h, 1)); - heap_dump_free(h); - - printf("[b] Allocating 0x10: position is %#x\n", b = heap_allocate(h, 0x10)); - printf("[c] Allocating 0x10: position is %#x\n", c = heap_allocate(h, 0x10)); - printf("[d] Allocating 0x10: position is %#x\n", d = heap_allocate(h, 0x10)); - printf("[e] Allocating 0x1000: position is %#x\n", e = heap_allocate(h, 0x1000)); - heap_dump_free(h); - - printf("Freeing [b]:\n"); - heap_free(h, b); - heap_dump_free(h); - - printf("Freeing [d]:\n"); - heap_free(h, d); - heap_dump_free(h); - - printf("Freeing [c]:\n"); - heap_free(h, c); - heap_dump_free(h); - - heap_del(h); - - return 0; -} -#endif - -} // End of namespace Sci diff --git a/engines/sci/engine/heap.h b/engines/sci/engine/heap.h deleted file mode 100644 index f826c6e8a1..0000000000 --- a/engines/sci/engine/heap.h +++ /dev/null @@ -1,115 +0,0 @@ -/* 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$ - * - */ - -#ifndef SCI_ENGINE_HEAP_H -#define SCI_ENGINE_HEAP_H - -#include "sci/tools.h" - -namespace Sci { - -#define SCI_HEAP_SIZE 0x10000 - -typedef uint16 heap_ptr; - -struct heap_t { - byte *start; - byte *base; - unsigned int first_free; - int old_ff; -}; - -heap_t *heap_new(); -/* Allocates a new heap. -** Parameters: (void) -** Returns : (heap_t *) A new 0xffff-sized heap -*/ - -void heap_del(heap_t *h); -/* Frees an allocated heap -** Parameters: (heap_t *) h: The heap to unallocate -** Returns : (void) -*/ - -int heap_meminfo(heap_t *h); -/* Returns the total number of free bytes on the heap -** Parameters: (heap_t *) h: The heap to check -** Returns : (int) The total free space in bytes -*/ - -int heap_largest(heap_t *h); -/* Returns the block size of the largest free block on the heap -** Parameters: (heap_t *) h: The heap to check -** Returns : (int) The size of the largest free block -*/ - -heap_ptr heap_allocate(heap_t *h, int size); -/* Allocates memory on a heap. -** Parameters: (heap_t *) h: The heap to work with -** (int) size: The block size to allocate -** Returns : (heap_ptr): The heap pointer to the new block, or 0 on failure -*/ - -void heap_free(heap_t *h, unsigned int m); -/* Frees allocated heap memory. -** Parameters: (heap_t *) h: The heap to work with -** (int) m: The handle at which memory is to be unallocated -** Returns : (void) -** This function automatically prevents fragmentation from happening. -*/ - -void save_ff(heap_t *h); -/* Stores the current first free position -** Parameters: (heap_t *) h: The heap which is to be manipulated -** Returns : (void) -** This function can be used to save the heap state for later restoration (see -** the next function) -*/ - -void restore_ff(heap_t *h); -/* Restores the first free heap state -** Parameters: (heap_t *) h: The heap to restore -** Returns : (void) -** Restoring the first free state will reset the heap to the position stored -** when save_ff() was called, if and only if none of the blocks allocated before -** save_ff() was called was ever freed ("ever" includes "before save_ff() was -** called"). -*/ - -void heap_dump_free(heap_t *h); -/* Dumps debugging information about the stack -** Parameters: (heap_t *) h: The heap to check -** Returns : (void) -*/ - -void heap_dump_all(heap_t *h); -/* Dumps all allocated/unallocated zones on the heap -** Parameters: (heap_t *) h: The heap to check -** Returns : (void) -*/ - -} // End of namespace Sci - -#endif // SCI_ENGINE_HEAP_H diff --git a/engines/sci/engine/heapmgr.h b/engines/sci/engine/heapmgr.h index 70e963ce80..f907e75afc 100644 --- a/engines/sci/engine/heapmgr.h +++ b/engines/sci/engine/heapmgr.h @@ -40,37 +40,37 @@ namespace Sci { #define ENTRY_IS_VALID(t, i) ((i == 0 || i > 0) && (i) < (t)->max_entry && (t)->table[(i)].next_free == (i)) #define DECLARE_HEAPENTRY(ENTRY) \ -typedef struct { \ +struct ENTRY##Entry { \ int next_free; /* Only used for free entries */ \ - ENTRY##_t entry; \ -} ENTRY##_entry_t; \ + ENTRY entry; \ +}; \ \ -typedef struct { \ +struct ENTRY##Table { \ int entries_nr; /* Number of entries allocated */ \ int first_free; /* Beginning of a singly linked list for entries */ \ int entries_used; /* Statistical information */ \ int max_entry; /* Highest entry used */ \ - ENTRY##_entry_t *table; \ -} ENTRY##_table_t; \ + ENTRY##Entry *table; \ +}; \ \ -void init_##ENTRY##_table(ENTRY##_table_t *table); \ -int alloc_##ENTRY##_entry(ENTRY##_table_t *table); \ -void free_##ENTRY##_entry(ENTRY##_table_t *table, int index); +void init_##ENTRY##_table(ENTRY##Table *table); \ +int alloc_##ENTRY##_entry(ENTRY##Table *table); \ +void free_##ENTRY##_entry(ENTRY##Table *table, int index); #define DEFINE_HEAPENTRY_WITH_CLEANUP(ENTRY, INITIAL, INCREMENT, CLEANUP_FN) \ -void init_##ENTRY##_table(ENTRY##_table_t *table) { \ +void init_##ENTRY##_table(ENTRY##Table *table) { \ table->entries_nr = INITIAL; \ table->max_entry = 0; \ table->entries_used = 0; \ table->first_free = HEAPENTRY_INVALID; \ - table->table = (ENTRY##_entry_t *)sci_malloc(sizeof(ENTRY##_entry_t) * INITIAL);\ - memset(table->table, 0, sizeof(ENTRY##_entry_t) * INITIAL); \ + table->table = (ENTRY##Entry *)sci_malloc(sizeof(ENTRY##Entry) * INITIAL);\ + memset(table->table, 0, sizeof(ENTRY##Entry) * INITIAL); \ } \ \ -void free_##ENTRY##_entry(ENTRY##_table_t *table, int index) { \ - ENTRY##_entry_t *e = table->table + index; \ +void free_##ENTRY##_entry(ENTRY##Table *table, int index) { \ + ENTRY##Entry *e = table->table + index; \ \ if (index < 0 || index >= table->max_entry) { \ fprintf(stderr, "heapmgr: Attempt to release" \ @@ -84,7 +84,7 @@ void free_##ENTRY##_entry(ENTRY##_table_t *table, int index) { \ table->entries_used--; \ } \ \ -int alloc_##ENTRY##_entry(ENTRY##_table_t *table) { \ +int alloc_##ENTRY##_entry(ENTRY##Table *table) { \ table->entries_used++; \ if (table->first_free != HEAPENTRY_INVALID) { \ int oldff = table->first_free; \ @@ -96,11 +96,11 @@ int alloc_##ENTRY##_entry(ENTRY##_table_t *table) { \ if (table->max_entry == table->entries_nr) { \ table->entries_nr += INCREMENT; \ \ - table->table = (ENTRY##_entry_t*)sci_realloc(table->table,\ - sizeof(ENTRY##_entry_t) * table->entries_nr); \ - memset(&table->table[table->entries_nr-INCREMENT], 0, INCREMENT*sizeof(ENTRY##_entry_t)); \ + table->table = (ENTRY##Entry *)sci_realloc(table->table,\ + sizeof(ENTRY##Entry) * table->entries_nr);\ + memset(&table->table[table->entries_nr-INCREMENT], 0, INCREMENT * sizeof(ENTRY##Entry));\ } \ - table->table[table->max_entry].next_free = table->max_entry; /* Tag as 'valid' */ \ + table->table[table->max_entry].next_free = table->max_entry; /* Tag as 'valid' */\ return table->max_entry++; \ } \ } diff --git a/engines/sci/engine/kernel.cpp b/engines/sci/engine/kernel.cpp index 4d66d07ba7..0d70be21a4 100644 --- a/engines/sci/engine/kernel.cpp +++ b/engines/sci/engine/kernel.cpp @@ -191,7 +191,7 @@ static int sci_max_allowed_unknown_kernel_functions[] = { #define DEFUN(nm, cname, sig) {KF_NEW, nm, {cname, sig, NULL}} #define NOFUN(nm) {KF_NONE, nm, {NULL, NULL, NULL}} -sci_kernel_function_t kfunct_mappers[] = { +SciKernelFunction kfunct_mappers[] = { /*00*/ DEFUN("Load", kLoad, "iii*"), /*01*/ DEFUN("UnLoad", kUnLoad, "i.*"), /*02*/ DEFUN("ScriptID", kScriptID, "Ioi*"), @@ -379,8 +379,8 @@ int has_kernel_function(EngineState *s, const char *kname) { // Returns a pointer to the memory indicated by the specified handle byte *kmem(EngineState *s, reg_t handle) { - mem_obj_t *mobj = GET_SEGMENT(*s->seg_manager, handle.segment, MEM_OBJ_HUNK); - hunk_table_t *ht = &(mobj->data.hunks); + MemObject *mobj = GET_SEGMENT(*s->seg_manager, handle.segment, MEM_OBJ_HUNK); + HunkTable *ht = &(mobj->data.hunks); if (!mobj || !ENTRY_IS_VALID(ht, handle.offset)) { SCIkwarn(SCIkERROR, "Error: kmem() with invalid handle\n"); @@ -808,7 +808,7 @@ void free_kfunct_tables(EngineState *s) { } int determine_reg_type(EngineState *s, reg_t reg, int allow_invalid) { - mem_obj_t *mobj; + MemObject *mobj; if (!reg.segment) { if (!reg.offset) diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h index a9f21dfa18..8e7c8b7b8e 100644 --- a/engines/sci/engine/kernel.h +++ b/engines/sci/engine/kernel.h @@ -35,8 +35,8 @@ namespace Sci { -struct node_t; // from vm.h -struct list_t; // from vm.h +struct Node; // from vm.h +struct List; // from vm.h extern int _kdebug_cheap_event_hack; extern int _kdebug_cheap_soundcue_hack; @@ -86,10 +86,10 @@ struct abs_rect_t { */ -reg_t read_selector(EngineState *s, reg_t object, selector_t selector_id, const char *fname, int line); -void write_selector(EngineState *s, reg_t object, selector_t selector_id, reg_t value, const char *fname, int line); +reg_t read_selector(EngineState *s, reg_t object, Selector selector_id, const char *fname, int line); +void write_selector(EngineState *s, reg_t object, Selector selector_id, reg_t value, const char *fname, int line); int invoke_selector(EngineState *s, reg_t object, int selector_id, int noinvalid, int kfunct, - stack_ptr_t k_argp, int k_argc, const char *fname, int line, int argc, ...); + StackPtr k_argp, int k_argc, const char *fname, int line, int argc, ...); /******************** Text functionality ********************/ @@ -132,7 +132,7 @@ bool is_object(EngineState *s, reg_t obj); /* Checks whether a heap address contains an object ** Parameters: (EngineState *) s: The current state ** (reg_t) obj: The address to check -** Returns : (int) 1 if it is an object, 0 otherwise +** Returns : (bool) true if it is an object, false otherwise */ /******************** Kernel function parameter macros ********************/ @@ -243,23 +243,23 @@ void process_sound_events(EngineState *s); /* Get all sound events, apply their #define LOOKUP_NODE(addr) lookup_node(s, (addr), __FILE__, __LINE__) #define LOOKUP_LIST(addr) lookup_list(s, addr, __FILE__, __LINE__) -node_t *lookup_node(EngineState *s, reg_t addr, const char *file, int line); +Node *lookup_node(EngineState *s, reg_t addr, const char *file, int line); /* Resolves an address into a list node ** Parameters: (EngineState *) s: The state to operate on ** (reg_t) addr: The address to resolve ** (const char *) file: The file the function was called from ** (int) line: The line number the function was called from -** Returns : (node_t *) The list node referenced, or NULL on error +** Returns : (Node *) The list node referenced, or NULL on error */ -list_t *lookup_list(EngineState *s, reg_t addr, const char *file, int line); +List *lookup_list(EngineState *s, reg_t addr, const char *file, int line); /* Resolves a list pointer to a list ** Parameters: (EngineState *) s: The state to operate on ** (reg_t) addr: The address to resolve ** (const char *) file: The file the function was called from ** (int) line: The line number the function was called from -** Returns : (list_t *) The list referenced, or NULL on error +** Returns : (List *) The list referenced, or NULL on error */ @@ -320,13 +320,13 @@ struct kfunct_sig_pair_t { #define KF_NONE -1 /* No mapping, but name is known */ #define KF_TERMINATOR -42 /* terminates kfunct_mappers */ -struct sci_kernel_function_t { +struct SciKernelFunction { int type; /* KF_* */ const char *name; kfunct_sig_pair_t sig_pair; }; -extern sci_kernel_function_t kfunct_mappers[]; +extern SciKernelFunction kfunct_mappers[]; } // End of namespace Sci diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp index 4869cddc48..b90153e98d 100644 --- a/engines/sci/engine/kgraphics.cpp +++ b/engines/sci/engine/kgraphics.cpp @@ -445,7 +445,7 @@ void _k_redraw_box(EngineState *s, int x1, int y1, int x2, int y2) { sciprintf("_k_redraw_box(): Unimplemented!\n"); #if 0 int i; - view_object_t *list = s->dyn_views; + ViewObject *list = s->dyn_views; sciprintf("Reanimating views\n", s->dyn_views_nr); @@ -777,7 +777,7 @@ static int collides_with(EngineState *s, abs_rect_t area, reg_t other_obj, int u reg_t kCanBeHere(EngineState *s, int funct_nr, int argc, reg_t * argv) { reg_t obj = argv[0]; reg_t cliplist_ref = KP_ALT(1, NULL_REG); - list_t *cliplist = NULL; + List *cliplist = NULL; gfxw_port_t *port = s->picture_port; uint16 signal; int retval; @@ -838,7 +838,7 @@ reg_t kCanBeHere(EngineState *s, int funct_nr, int argc, reg_t * argv) { cliplist = LOOKUP_LIST(cliplist_ref); if (cliplist) { - node_t *node = LOOKUP_NODE(cliplist->first); + Node *node = LOOKUP_NODE(cliplist->first); retval = 0; // Assume that we Can'tBeHere... @@ -984,7 +984,7 @@ reg_t kOnControl(EngineState *s, int funct_nr, int argc, reg_t *argv) { return make_reg(0, gfxop_scan_bitmask(s->gfx_state, gfx_rect(xstart, ystart + 10, xlen, ylen), map)); } -void _k_view_list_free_backgrounds(EngineState *s, view_object_t *list, int list_nr); +void _k_view_list_free_backgrounds(EngineState *s, ViewObject *list, int list_nr); int sci01_priority_table_flags = 0; @@ -1149,7 +1149,7 @@ abs_rect_t set_base(EngineState *s, reg_t object) { void _k_base_setter(EngineState *s, reg_t object) { abs_rect_t absrect = set_base(s, object); - if (lookup_selector(s, object, s->selector_map.brLeft, NULL, NULL) != SELECTOR_VARIABLE) + if (lookup_selector(s, object, s->selector_map.brLeft, NULL, NULL) != kSelectorVariable) return; // non-fatal if (s->version <= SCI_VERSION_LTU_BASE_OB1) @@ -1248,7 +1248,7 @@ abs_rect_t get_nsrect(EngineState *s, reg_t object, byte clip) { static void _k_set_now_seen(EngineState *s, reg_t object) { abs_rect_t absrect = get_nsrect(s, object, 0); - if (lookup_selector(s, object, s->selector_map.nsTop, NULL, NULL) != SELECTOR_VARIABLE) { + if (lookup_selector(s, object, s->selector_map.nsTop, NULL, NULL) != kSelectorVariable) { return; } // This isn't fatal @@ -1703,7 +1703,7 @@ static void _k_view_list_do_postdraw(EngineState *s, gfxw_list_t *list) { * if ((widget->signal & (_K_VIEW_SIG_FLAG_FREESCI_PRIVATE | _K_VIEW_SIG_FLAG_REMOVE | _K_VIEW_SIG_FLAG_NO_UPDATE)) == _K_VIEW_SIG_FLAG_FREESCI_PRIVATE) { */ if ((widget->signal & (_K_VIEW_SIG_FLAG_REMOVE | _K_VIEW_SIG_FLAG_NO_UPDATE)) == 0) { - int has_nsrect = lookup_selector(s, obj, s->selector_map.nsBottom, NULL, NULL) == SELECTOR_VARIABLE; + int has_nsrect = lookup_selector(s, obj, s->selector_map.nsBottom, NULL, NULL) == kSelectorVariable; if (has_nsrect) { int temp; @@ -1761,7 +1761,7 @@ void _k_view_list_mark_free(EngineState *s, reg_t off) { static int _k_animate_ran = 0; -int _k_view_list_dispose_loop(EngineState *s, list_t *list, gfxw_dyn_view_t *widget, int funct_nr, int argc, reg_t *argv) { +int _k_view_list_dispose_loop(EngineState *s, List *list, gfxw_dyn_view_t *widget, int funct_nr, int argc, reg_t *argv) { // disposes all list members flagged for disposal; funct_nr is the invoking kfunction // returns non-zero IFF views were dropped int signal; @@ -1899,14 +1899,14 @@ static gfxw_dyn_view_t *_k_make_dynview_obj(EngineState *s, reg_t obj, int optio PUT_SEL32V(obj, cel, cel); } - if (lookup_selector(s, obj, s->selector_map.underBits, &(under_bitsp), NULL) != SELECTOR_VARIABLE) { + if (lookup_selector(s, obj, s->selector_map.underBits, &(under_bitsp), NULL) != kSelectorVariable) { under_bitsp = NULL; under_bits = NULL_REG; SCIkdebug(SCIkGRAPHICS, "Object at "PREG" has no underBits\n", PRINT_REG(obj)); } else under_bits = *((reg_t *)under_bitsp); - if (lookup_selector(s, obj, s->selector_map.signal, &(signalp), NULL) != SELECTOR_VARIABLE) { + if (lookup_selector(s, obj, s->selector_map.signal, &(signalp), NULL) != kSelectorVariable) { signalp = NULL; signal = 0; SCIkdebug(SCIkGRAPHICS, "Object at "PREG" has no signal selector\n", PRINT_REG(obj)); @@ -1929,12 +1929,12 @@ static gfxw_dyn_view_t *_k_make_dynview_obj(EngineState *s, reg_t obj, int optio } } -static void _k_make_view_list(EngineState *s, gfxw_list_t **widget_list, list_t *list, int options, int funct_nr, int argc, reg_t *argv) { +static void _k_make_view_list(EngineState *s, gfxw_list_t **widget_list, List *list, int options, int funct_nr, int argc, reg_t *argv) { /* Creates a view_list from a node list in heap space. Returns the list, stores the ** number of list entries in *list_nr. Calls doit for each entry if cycle is set. ** argc, argv, funct_nr should be the same as in the calling kernel function. */ - node_t *node; + Node *node; int sequence_nr = 0; gfxw_dyn_view_t *widget; @@ -1995,7 +1995,7 @@ static void _k_prepare_view_list(EngineState *s, gfxw_list_t *list, int options) while (view) { reg_t obj = make_reg(view->ID, view->subID); int priority, _priority; - int has_nsrect = (view->ID <= 0) ? 0 : lookup_selector(s, obj, s->selector_map.nsBottom, NULL, NULL) == SELECTOR_VARIABLE; + int has_nsrect = (view->ID <= 0) ? 0 : lookup_selector(s, obj, s->selector_map.nsBottom, NULL, NULL) == kSelectorVariable; int oldsignal = view->signal; _k_set_now_seen(s, obj); @@ -2276,7 +2276,7 @@ reg_t kAddToPic(EngineState *s, int funct_nr, int argc, reg_t *argv) { ADD_TO_CURRENT_PICTURE_PORT(gfxw_picviewize_dynview((gfxw_dyn_view_t *) widget)); } } else { - list_t *list; + List *list; if (!list_ref.segment) { warning("Attempt to AddToPic single non-list: "PREG"", PRINT_REG(list_ref)); @@ -2923,7 +2923,7 @@ reg_t kAnimate(EngineState *s, int funct_nr, int argc, reg_t *argv) { // Animations are supposed to take a maximum of s->animation_delay milliseconds. reg_t cast_list_ref = KP_ALT(0, NULL_REG); int cycle = (KP_ALT(1, NULL_REG)).offset; - list_t *cast_list = NULL; + List *cast_list = NULL; int open_animation = 0; process_sound_events(s); // Take care of incoming events (kAnimate is called semi-regularly) diff --git a/engines/sci/engine/klists.cpp b/engines/sci/engine/klists.cpp index 563099d609..ecfd64a88d 100644 --- a/engines/sci/engine/klists.cpp +++ b/engines/sci/engine/klists.cpp @@ -33,9 +33,9 @@ namespace Sci { # define LOOKUP_NODE(addr) inline_lookup_node(s, (addr), __FILE__, __LINE__) #endif -inline node_t *inline_lookup_node(EngineState *s, reg_t addr, const char *file, int line) { - mem_obj_t *mobj; - node_table_t *nt; +inline Node *inline_lookup_node(EngineState *s, reg_t addr, const char *file, int line) { + MemObject *mobj; + NodeTable *nt; if (!addr.offset && !addr.segment) return NULL; // Non-error null @@ -58,15 +58,15 @@ inline node_t *inline_lookup_node(EngineState *s, reg_t addr, const char *file, return &(nt->table[addr.offset].entry); } -node_t *lookup_node(EngineState *s, reg_t addr, const char *file, int line) { +Node *lookup_node(EngineState *s, reg_t addr, const char *file, int line) { return inline_lookup_node(s, addr, file, line); } #define LOOKUP_NULL_LIST(addr) _lookup_list(s, addr, __FILE__, __LINE__, 1) -inline list_t *_lookup_list(EngineState *s, reg_t addr, const char *file, int line, int may_be_null) { - mem_obj_t *mobj; - list_table_t *lt; +inline List *_lookup_list(EngineState *s, reg_t addr, const char *file, int line, int may_be_null) { + MemObject *mobj; + ListTable *lt; if (may_be_null && !addr.segment && !addr.offset) return NULL; @@ -90,7 +90,7 @@ inline list_t *_lookup_list(EngineState *s, reg_t addr, const char *file, int li return &(lt->table[addr.offset].entry); } -list_t *lookup_list(EngineState *s, reg_t addr, const char *file, int line) { +List *lookup_list(EngineState *s, reg_t addr, const char *file, int line) { return _lookup_list(s, addr, file, line, 0); } @@ -106,7 +106,7 @@ static inline int sane_nodep(EngineState *s, reg_t addr) { reg_t prev = addr; do { - node_t *node = LOOKUP_NODE(addr); + Node *node = LOOKUP_NODE(addr); if (!node) return 0; @@ -123,7 +123,7 @@ static inline int sane_nodep(EngineState *s, reg_t addr) { } int sane_listp(EngineState *s, reg_t addr) { - list_t *l = LOOKUP_LIST(addr); + List *l = LOOKUP_LIST(addr); int empties = 0; if (IS_NULL_REG(l->first)) @@ -136,7 +136,7 @@ int sane_listp(EngineState *s, reg_t addr) { return 0; if (!empties) { - node_t *node_a, *node_z; + Node *node_a, *node_z; node_a = LOOKUP_NODE(l->first); node_z = LOOKUP_NODE(l->last); @@ -159,8 +159,8 @@ int sane_listp(EngineState *s, reg_t addr) { reg_t kNewList(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t listbase; - list_t *l; - l = s->seg_manager->alloc_list(&listbase); + List *l; + l = s->seg_manager->alloc_List(&listbase); l->first = l->last = NULL_REG; SCIkdebug(SCIkNODES, "New listbase at "PREG"\n", PRINT_REG(listbase)); @@ -168,7 +168,7 @@ reg_t kNewList(EngineState *s, int funct_nr, int argc, reg_t *argv) { } reg_t kDisposeList(EngineState *s, int funct_nr, int argc, reg_t *argv) { - list_t *l = LOOKUP_LIST(argv[0]); + List *l = LOOKUP_LIST(argv[0]); if (!l) { SCIkwarn(SCIkERROR, "Attempt to dispose non-list at "PREG"!\n", PRINT_REG(argv[0])); @@ -182,8 +182,8 @@ reg_t kDisposeList(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t n_addr = l->first; while (!IS_NULL_REG(n_addr)) { // Free all nodes - node_t *n = LOOKUP_NODE(n_addr); - s->seg_manager->free_node(n_addr); + Node *n = LOOKUP_NODE(n_addr); + s->seg_manager->free_Node(n_addr); n_addr = n->succ; } } @@ -195,7 +195,7 @@ reg_t kDisposeList(EngineState *s, int funct_nr, int argc, reg_t *argv) { inline reg_t _k_new_node(EngineState *s, reg_t value, reg_t key) { reg_t nodebase; - node_t *n = s->seg_manager->alloc_node(&nodebase); + Node *n = s->seg_manager->alloc_Node(&nodebase); if (!n) { KERNEL_OOPS("Out of memory while creating a node"); @@ -218,7 +218,7 @@ reg_t kNewNode(EngineState *s, int funct_nr, int argc, reg_t *argv) { } reg_t kFirstNode(EngineState *s, int funct_nr, int argc, reg_t *argv) { - list_t *l = LOOKUP_NULL_LIST(argv[0]); + List *l = LOOKUP_NULL_LIST(argv[0]); if (l && !sane_listp(s, argv[0])) SCIkwarn(SCIkERROR, "List at "PREG" is not sane anymore!\n", PRINT_REG(argv[0])); @@ -230,7 +230,7 @@ reg_t kFirstNode(EngineState *s, int funct_nr, int argc, reg_t *argv) { } reg_t kLastNode(EngineState *s, int funct_nr, int argc, reg_t *argv) { - list_t *l = LOOKUP_LIST(argv[0]); + List *l = LOOKUP_LIST(argv[0]); if (l && !sane_listp(s, argv[0])) SCIkwarn(SCIkERROR, "List at "PREG" is not sane anymore!\n", PRINT_REG(argv[0])); @@ -242,7 +242,7 @@ reg_t kLastNode(EngineState *s, int funct_nr, int argc, reg_t *argv) { } reg_t kEmptyList(EngineState *s, int funct_nr, int argc, reg_t *argv) { - list_t *l = LOOKUP_LIST(argv[0]); + List *l = LOOKUP_LIST(argv[0]); if (!l || !sane_listp(s, argv[0])) SCIkwarn(SCIkERROR, "List at "PREG" is invalid or not sane anymore!\n", PRINT_REG(argv[0])); @@ -251,8 +251,8 @@ reg_t kEmptyList(EngineState *s, int funct_nr, int argc, reg_t *argv) { } inline void _k_add_to_front(EngineState *s, reg_t listbase, reg_t nodebase) { - list_t *l = LOOKUP_LIST(listbase); - node_t *new_n = LOOKUP_NODE(nodebase); + List *l = LOOKUP_LIST(listbase); + Node *new_n = LOOKUP_NODE(nodebase); SCIkdebug(SCIkNODES, "Adding node "PREG" to end of list "PREG"\n", PRINT_REG(nodebase), PRINT_REG(listbase)); @@ -267,15 +267,15 @@ inline void _k_add_to_front(EngineState *s, reg_t listbase, reg_t nodebase) { if (IS_NULL_REG(l->first)) l->last = nodebase; else { - node_t *old_n = LOOKUP_NODE(l->first); + Node *old_n = LOOKUP_NODE(l->first); old_n->pred = nodebase; } l->first = nodebase; } inline void _k_add_to_end(EngineState *s, reg_t listbase, reg_t nodebase) { - list_t *l = LOOKUP_LIST(listbase); - node_t *new_n = LOOKUP_NODE(nodebase); + List *l = LOOKUP_LIST(listbase); + Node *new_n = LOOKUP_NODE(nodebase); SCIkdebug(SCIkNODES, "Adding node "PREG" to end of list "PREG"\n", PRINT_REG(nodebase), PRINT_REG(listbase)); @@ -290,14 +290,14 @@ inline void _k_add_to_end(EngineState *s, reg_t listbase, reg_t nodebase) { if (IS_NULL_REG(l->last)) l->first = nodebase; else { - node_t *old_n = LOOKUP_NODE(l->last); + Node *old_n = LOOKUP_NODE(l->last); old_n->succ = nodebase; } l->last = nodebase; } reg_t kNextNode(EngineState *s, int funct_nr, int argc, reg_t *argv) { - node_t *n = LOOKUP_NODE(argv[0]); + Node *n = LOOKUP_NODE(argv[0]); if (!sane_nodep(s, argv[0])) { SCIkwarn(SCIkERROR, "List node at "PREG" is not sane anymore!\n", PRINT_REG(argv[0])); script_error_flag = script_debug_flag = 0; @@ -308,7 +308,7 @@ reg_t kNextNode(EngineState *s, int funct_nr, int argc, reg_t *argv) { } reg_t kPrevNode(EngineState *s, int funct_nr, int argc, reg_t *argv) { - node_t *n = LOOKUP_NODE(argv[0]); + Node *n = LOOKUP_NODE(argv[0]); if (!sane_nodep(s, argv[0])) SCIkwarn(SCIkERROR, "List node at "PREG" is not sane anymore!\n", PRINT_REG(argv[0])); @@ -316,7 +316,7 @@ reg_t kPrevNode(EngineState *s, int funct_nr, int argc, reg_t *argv) { } reg_t kNodeValue(EngineState *s, int funct_nr, int argc, reg_t *argv) { - node_t *n = LOOKUP_NODE(argv[0]); + Node *n = LOOKUP_NODE(argv[0]); if (!sane_nodep(s, argv[0])) { SCIkwarn(SCIkERROR, "List node at "PREG" is not sane!\n", PRINT_REG(argv[0])); script_debug_flag = script_error_flag = 0; @@ -332,9 +332,9 @@ reg_t kAddToFront(EngineState *s, int funct_nr, int argc, reg_t *argv) { } reg_t kAddAfter(EngineState *s, int funct_nr, int argc, reg_t *argv) { - list_t *l = LOOKUP_LIST(argv[0]); - node_t *firstnode = IS_NULL_REG(argv[1]) ? NULL : LOOKUP_NODE(argv[1]); - node_t *newnode = LOOKUP_NODE(argv[2]); + List *l = LOOKUP_LIST(argv[0]); + Node *firstnode = IS_NULL_REG(argv[1]) ? NULL : LOOKUP_NODE(argv[1]); + Node *newnode = LOOKUP_NODE(argv[2]); if (!l || !sane_listp(s, argv[0])) SCIkwarn(SCIkERROR, "List at "PREG" is not sane anymore!\n", PRINT_REG(argv[0])); @@ -390,7 +390,7 @@ reg_t kFindKey(EngineState *s, int funct_nr, int argc, reg_t *argv) { SCIkdebug(SCIkNODES, "First node at "PREG"\n", PRINT_REG(node_pos)); while (!IS_NULL_REG(node_pos)) { - node_t *n = LOOKUP_NODE(node_pos); + Node *n = LOOKUP_NODE(node_pos); if (REG_EQ(n->key, key)) { SCIkdebug(SCIkNODES, " Found key at "PREG"\n", PRINT_REG(node_pos)); return node_pos; @@ -406,8 +406,8 @@ reg_t kFindKey(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t kDeleteKey(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t node_pos = kFindKey(s, funct_nr, 2, argv); - node_t *n; - list_t *l = LOOKUP_LIST(argv[0]); + Node *n; + List *l = LOOKUP_LIST(argv[0]); if (IS_NULL_REG(node_pos)) return NULL_REG; // Signal falure @@ -423,7 +423,7 @@ reg_t kDeleteKey(EngineState *s, int funct_nr, int argc, reg_t *argv) { if (!IS_NULL_REG(n->succ)) LOOKUP_NODE(n->succ)->pred = n->pred; - //s->seg_manager->free_node(node_pos); + //s->seg_manager->free_Node(node_pos); return make_reg(0, 1); // Signal success } @@ -459,14 +459,14 @@ reg_t kSort(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t input_data = GET_SEL32(source, elements); reg_t output_data = GET_SEL32(dest, elements); - list_t *list; - node_t *node; + List *list; + Node *node; if (!input_size) return s->r_acc; if (IS_NULL_REG(output_data)) { - list = s->seg_manager->alloc_list(&output_data); + list = s->seg_manager->alloc_List(&output_data); list->first = list->last = NULL_REG; PUT_SEL32(dest, elements, output_data); } diff --git a/engines/sci/engine/kmovement.cpp b/engines/sci/engine/kmovement.cpp index 54f7bf14b2..1af9f779ba 100644 --- a/engines/sci/engine/kmovement.cpp +++ b/engines/sci/engine/kmovement.cpp @@ -255,7 +255,7 @@ static void bresenham_autodetect(EngineState *s) { reg_t motion_class; if (!parse_reg_t(s, "?Motion", &motion_class)) { - object_t *obj = obj_get(s, motion_class); + Object *obj = obj_get(s, motion_class); reg_t fptr; byte *buf; @@ -265,7 +265,7 @@ static void bresenham_autodetect(EngineState *s) { return; } - if (lookup_selector(s, motion_class, s->selector_map.doit, NULL, &fptr) != SELECTOR_METHOD) { + if (lookup_selector(s, motion_class, s->selector_map.doit, NULL, &fptr) != kSelectorMethod) { warning("bresenham_autodetect failed"); handle_movecnt = INCREMENT_MOVECNT; // Most games do this, so best guess return; diff --git a/engines/sci/engine/kpathing.cpp b/engines/sci/engine/kpathing.cpp index 231200f5c2..95b65babb7 100644 --- a/engines/sci/engine/kpathing.cpp +++ b/engines/sci/engine/kpathing.cpp @@ -351,8 +351,8 @@ static void draw_polygon(EngineState *s, reg_t polygon) { } static void draw_input(EngineState *s, reg_t poly_list, Common::Point start, Common::Point end, int opt) { - list_t *list; - node_t *node; + List *list; + Node *node; draw_point(s, start, 1); draw_point(s, end, 0); @@ -396,8 +396,8 @@ static void print_polygon(EngineState *s, reg_t polygon) { } static void print_input(EngineState *s, reg_t poly_list, Common::Point start, Common::Point end, int opt) { - list_t *list; - node_t *node; + List *list; + Node *node; sciprintf("Start point: (%i, %i)\n", start.x, start.y); sciprintf("End point: (%i, %i)\n", end.x, end.y); @@ -1224,8 +1224,8 @@ static PathfindingState *convert_polygon_set(EngineState *s, reg_t poly_list, Co // Convert all polygons if (poly_list.segment) { - list_t *list = LOOKUP_LIST(poly_list); - node_t *node = LOOKUP_NODE(list->first); + List *list = LOOKUP_LIST(poly_list); + Node *node = LOOKUP_NODE(list->first); while (node) { polygon = convert_polygon(s, node->value); diff --git a/engines/sci/engine/kscripts.cpp b/engines/sci/engine/kscripts.cpp index d2f7256c79..805a979701 100644 --- a/engines/sci/engine/kscripts.cpp +++ b/engines/sci/engine/kscripts.cpp @@ -30,16 +30,16 @@ namespace Sci { -reg_t read_selector(EngineState *s, reg_t object, selector_t selector_id, const char *file, int line) { +reg_t read_selector(EngineState *s, reg_t object, Selector selector_id, const char *file, int line) { reg_t *address; - if (lookup_selector(s, object, selector_id, &address, NULL) != SELECTOR_VARIABLE) + if (lookup_selector(s, object, selector_id, &address, NULL) != kSelectorVariable) return NULL_REG; else return *address; } -void write_selector(EngineState *s, reg_t object, selector_t selector_id, reg_t value, const char *fname, int line) { +void write_selector(EngineState *s, reg_t object, Selector selector_id, reg_t value, const char *fname, int line) { reg_t *address; if ((selector_id < 0) || (selector_id > (int)s->_selectorNames.size())) { @@ -48,7 +48,7 @@ void write_selector(EngineState *s, reg_t object, selector_t selector_id, reg_t return; } - if (lookup_selector(s, object, selector_id, &address, NULL) != SELECTOR_VARIABLE) + if (lookup_selector(s, object, selector_id, &address, NULL) != kSelectorVariable) warning("Selector '%s' of object at "PREG" could not be" " written to (%s L%d)", s->_selectorNames[selector_id].c_str(), PRINT_REG(object), fname, line); else @@ -56,29 +56,30 @@ void write_selector(EngineState *s, reg_t object, selector_t selector_id, reg_t } int invoke_selector(EngineState *s, reg_t object, int selector_id, int noinvalid, int kfunct, - stack_ptr_t k_argp, int k_argc, const char *fname, int line, int argc, ...) { + StackPtr k_argp, int k_argc, const char *fname, int line, int argc, ...) { va_list argp; int i; int framesize = 2 + 1 * argc; reg_t address; int slc_type; - stack_ptr_t stackframe = k_argp + k_argc; + StackPtr stackframe = k_argp + k_argc; - exec_stack_t *xstack; // Execution stack + // Execution stack + ExecStack *xstack; stackframe[0] = make_reg(0, selector_id); // The selector we want to call stackframe[1] = make_reg(0, argc); // Argument count slc_type = lookup_selector(s, object, selector_id, NULL, &address); - if (slc_type == SELECTOR_NONE) { + if (slc_type == kSelectorNone) { SCIkwarn(SCIkERROR, "Selector '%s' of object at "PREG" could not be invoked (%s L%d)\n", s->_selectorNames[selector_id].c_str(), PRINT_REG(object), fname, line); if (noinvalid == 0) KERNEL_OOPS("Not recoverable: VM was halted\n"); return 1; } - if (slc_type == SELECTOR_VARIABLE) // Swallow silently + if (slc_type == kSelectorVariable) // Swallow silently return 0; va_start(argp, argc); @@ -155,9 +156,9 @@ reg_t kUnLoad(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t kClone(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t parent_addr = argv[0]; - object_t *parent_obj = obj_get(s, parent_addr); + Object *parent_obj = obj_get(s, parent_addr); reg_t clone_addr; - clone_t *clone_obj; // same as object_t* + Clone *clone_obj; // same as Object* int varblock_size; if (!parent_obj) { @@ -167,14 +168,14 @@ reg_t kClone(EngineState *s, int funct_nr, int argc, reg_t *argv) { SCIkdebug(SCIkMEM, "Attempting to clone from "PREG"\n", PRINT_REG(parent_addr)); - clone_obj = s->seg_manager->alloc_clone(&clone_addr); + clone_obj = s->seg_manager->alloc_Clone(&clone_addr); if (!clone_obj) { SCIkwarn(SCIkERROR, "Cloning "PREG" failed-- internal error!\n", PRINT_REG(parent_addr)); return NULL_REG; } - memcpy(clone_obj, parent_obj, sizeof(clone_t)); + memcpy(clone_obj, parent_obj, sizeof(Clone)); clone_obj->flags = 0; varblock_size = parent_obj->variables_nr * sizeof(reg_t); clone_obj->variables = (reg_t*)sci_malloc(varblock_size); @@ -195,7 +196,7 @@ extern void _k_view_list_mark_free(EngineState *s, reg_t off); reg_t kDisposeClone(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t victim_addr = argv[0]; - clone_t *victim_obj = obj_get(s, victim_addr); + Clone *victim_obj = obj_get(s, victim_addr); uint16 underBits; if (!victim_obj) { @@ -235,8 +236,8 @@ reg_t kScriptID(EngineState *s, int funct_nr, int argc, reg_t *argv) { int script = KP_UINT(argv[0]); int index = KP_UINT(KP_ALT(1, NULL_REG)); - seg_id_t scriptid = script_get_segment(s, script, SCRIPT_GET_LOAD); - script_t *scr; + SegmentId scriptid = script_get_segment(s, script, SCRIPT_GET_LOAD); + Script *scr; if (argv[0].segment) return argv[0]; @@ -279,7 +280,7 @@ reg_t kDisposeScript(EngineState *s, int funct_nr, int argc, reg_t *argv) { } int is_heap_object(EngineState *s, reg_t pos) { - object_t *obj = obj_get(s, pos); + Object *obj = obj_get(s, pos); return (obj != NULL && (!(obj->flags & OBJECT_FLAG_FREED)) && (!s->seg_manager->scriptIsMarkedAsDeleted(pos.segment))); } @@ -294,7 +295,7 @@ reg_t kRespondsTo(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t obj = argv[0]; int selector = KP_UINT(argv[1]); - return make_reg(0, is_heap_object(s, obj) && lookup_selector(s, obj, selector, NULL, NULL) != SELECTOR_NONE); + return make_reg(0, is_heap_object(s, obj) && lookup_selector(s, obj, selector, NULL, NULL) != kSelectorNone); } } // End of namespace Sci diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index 4b001b9782..ee1d02616e 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -78,7 +78,7 @@ char *kernel_lookup_text(EngineState *s, reg_t address, int index) { /**********/ #ifdef SCI_SIMPLE_SAID_CODE -int vocab_match_simple(EngineState *s, heap_ptr addr) { +int vocab_match_simple(EngineState *s, HeapPtr addr) { int nextitem; int listpos = 0; @@ -182,8 +182,8 @@ reg_t kSaid(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t kSetSynonyms(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t object = argv[0]; - list_t *list; - node_t *node; + List *list; + Node *node; int script; int synpos = 0; @@ -733,7 +733,7 @@ reg_t kGetFarText(EngineState *s, int funct_nr, int argc, reg_t *argv) { #define DUMMY_MESSAGE "No MESSAGE support in FreeSCI yet" -static message_state_t state; +static MessageState state; reg_t kMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) { if (!state.initialized) @@ -742,7 +742,7 @@ reg_t kMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) { switch (UKPV(0)) { case 0 : { char *buffer = argc == 7 ? kernel_dereference_char_pointer(s, argv[6], 0) : NULL; - message_tuple_t tuple; + MessageTuple tuple; int module = UKPV(1); tuple.noun = UKPV(2); @@ -772,7 +772,7 @@ reg_t kMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) { } } case 2 : { - message_tuple_t tuple; + MessageTuple tuple; int module = UKPV(1); tuple.noun = UKPV(2); tuple.verb = UKPV(3); diff --git a/engines/sci/engine/message.cpp b/engines/sci/engine/message.cpp index 4f539b270a..a8f8eed6ec 100644 --- a/engines/sci/engine/message.cpp +++ b/engines/sci/engine/message.cpp @@ -30,7 +30,7 @@ namespace Sci { #if 0 // Unreferenced - removed -static int get_talker_trivial(index_record_cursor_t *cursor) { +static int get_talker_trivial(IndexRecordCursor *cursor) { return -1; } #endif @@ -39,7 +39,7 @@ static int get_talker_trivial(index_record_cursor_t *cursor) { #if 0 // Unreferenced - removed -static void index_record_parse_2101(index_record_cursor_t *cursor, message_tuple_t *t) { +static void index_record_parse_2101(IndexRecordCursor *cursor, MessageTuple *t) { int noun = *(cursor->index_record + 0); int verb = *(cursor->index_record + 1); @@ -51,7 +51,7 @@ static void index_record_parse_2101(index_record_cursor_t *cursor, message_tuple #if 0 // Unreferenced - removed -static void index_record_get_text_2101(index_record_cursor_t *cursor, char *buffer, int buffer_size) { +static void index_record_get_text_2101(IndexRecordCursor *cursor, char *buffer, int buffer_size) { int offset = getUInt16(cursor->index_record + 2); char *stringptr = (char *)cursor->resource_beginning + offset; @@ -68,7 +68,7 @@ static int header_get_index_record_count_2101(byte *header) { // Version 3.411 and later code ahead -static void index_record_parse_3411(index_record_cursor_t *cursor, message_tuple_t *t) { +static void index_record_parse_3411(IndexRecordCursor *cursor, MessageTuple *t) { int noun = *(cursor->index_record + 0); int verb = *(cursor->index_record + 1); int cond = *(cursor->index_record + 2); @@ -80,11 +80,11 @@ static void index_record_parse_3411(index_record_cursor_t *cursor, message_tuple t->seq = seq; } -static int index_record_get_talker_3411(index_record_cursor_t *cursor) { +static int index_record_get_talker_3411(IndexRecordCursor *cursor) { return *(cursor->index_record + 4); } -static void index_record_get_text_3411(index_record_cursor_t *cursor, char *buffer, int buffer_size) { +static void index_record_get_text_3411(IndexRecordCursor *cursor, char *buffer, int buffer_size) { int offset = getUInt16(cursor->index_record + 5); char *stringptr = (char *)cursor->resource_beginning + offset; @@ -97,17 +97,17 @@ static int header_get_index_record_count_3411(byte *header) { // Generic code from here on -static int four_tuple_match(message_tuple_t *t1, message_tuple_t *t2) { +static int four_tuple_match(MessageTuple *t1, MessageTuple *t2) { return t1->noun == t2->noun && t1->verb == t2->verb && t1->cond == t2->cond && t1->seq == t2->seq; } -static void index_record_cursor_initialize(message_state_t *state, index_record_cursor_t *cursor) { +static void index_record_cursor_initialize(MessageState *state, IndexRecordCursor *cursor) { cursor->resource_beginning = state->current_res->data; cursor->index_record = state->index_records; cursor->index = 1; } -static int index_record_next(message_state_t *state, index_record_cursor_t *cursor) { +static int index_record_next(MessageState *state, IndexRecordCursor *cursor) { if (cursor->index == state->record_count) return 0; cursor->index_record += state->handler->index_record_size; @@ -115,8 +115,8 @@ static int index_record_next(message_state_t *state, index_record_cursor_t *curs return 1; } -static int index_record_find(message_state_t *state, message_tuple_t *t, index_record_cursor_t *cursor) { - message_tuple_t looking_at; +static int index_record_find(MessageState *state, MessageTuple *t, IndexRecordCursor *cursor) { + MessageTuple looking_at; int found = 0; index_record_cursor_initialize(state, cursor); @@ -132,31 +132,31 @@ static int index_record_find(message_state_t *state, message_tuple_t *t, index_r return found; } -int message_get_specific(message_state_t *state, message_tuple_t *t) { +int message_get_specific(MessageState *state, MessageTuple *t) { return index_record_find(state, t, &state->engine_cursor); } -int message_get_next(message_state_t *state) { +int message_get_next(MessageState *state) { return index_record_next(state, &state->engine_cursor); } -int message_get_talker(message_state_t *state) { +int message_get_talker(MessageState *state) { return state->handler->get_talker(&state->engine_cursor); } -int message_get_text(message_state_t *state, char *buffer, int length) { +int message_get_text(MessageState *state, char *buffer, int length) { state->handler->get_text(&state->engine_cursor, buffer, length); return strlen(buffer); } -int message_get_length(message_state_t *state) { +int message_get_length(MessageState *state) { char buffer[500]; state->handler->get_text(&state->engine_cursor, buffer, sizeof(buffer)); return strlen(buffer); } -int message_state_load_res(message_state_t *state, int module) { +int message_state_load_res(MessageState *state, int module) { if (state->module == module) return 1; @@ -175,7 +175,7 @@ int message_state_load_res(message_state_t *state, int module) { return 1; } -static message_handler_t fixed_handler = { +static MessageHandler fixed_handler = { 3411, index_record_parse_3411, index_record_get_talker_3411, @@ -185,7 +185,7 @@ static message_handler_t fixed_handler = { 11 }; -void message_state_initialize(ResourceManager *resmgr, message_state_t *state) { +void message_state_initialize(ResourceManager *resmgr, MessageState *state) { //resource_t *tester = scir_find_resource(resmgr, sci_message, 0, 0); //int version; diff --git a/engines/sci/engine/message.h b/engines/sci/engine/message.h index dd41b5a7f9..86ac5c752e 100644 --- a/engines/sci/engine/message.h +++ b/engines/sci/engine/message.h @@ -30,26 +30,26 @@ namespace Sci { -struct message_tuple_t { +struct MessageTuple { int noun; int verb; int cond; int seq; }; -struct index_record_cursor_t { +struct IndexRecordCursor { byte *index_record; int index; byte *resource_beginning; }; typedef int index_record_size_t(); -typedef void parse_index_record_t(index_record_cursor_t *index_record, message_tuple_t *t); -typedef int get_talker_t(index_record_cursor_t *cursor); -typedef void get_text_t(index_record_cursor_t *cursor, char *buffer, int buffer_size); +typedef void parse_index_record_t(IndexRecordCursor *index_record, MessageTuple *t); +typedef int get_talker_t(IndexRecordCursor *cursor); +typedef void get_text_t(IndexRecordCursor *cursor, char *buffer, int buffer_size); typedef int index_record_count_t(byte *header); -struct message_handler_t { +struct MessageHandler { int version_id; parse_index_record_t *parse; get_talker_t *get_talker; @@ -60,24 +60,24 @@ struct message_handler_t { int index_record_size; }; -struct message_state_t { +struct MessageState { int initialized; - message_handler_t *handler; + MessageHandler *handler; ResourceManager *resmgr; resource_t *current_res; int module; int record_count; byte *index_records; - index_record_cursor_t engine_cursor; + IndexRecordCursor engine_cursor; }; -int message_get_specific(message_state_t *state, message_tuple_t *t); -int message_get_next(message_state_t *state); -int message_get_talker(message_state_t *state); -int message_get_length(message_state_t *state); -int message_get_text(message_state_t *state, char *buffer, int length); -int message_state_load_res(message_state_t *state, int module); -void message_state_initialize(ResourceManager *resmgr, message_state_t *state); +int message_get_specific(MessageState *state, MessageTuple *t); +int message_get_next(MessageState *state); +int message_get_talker(MessageState *state); +int message_get_length(MessageState *state); +int message_get_text(MessageState *state, char *buffer, int length); +int message_state_load_res(MessageState *state, int module); +void message_state_initialize(ResourceManager *resmgr, MessageState *state); } // End of namespace Sci diff --git a/engines/sci/engine/savegame.cfsml b/engines/sci/engine/savegame.cfsml index 53983f5cca..66eec5aed9 100644 --- a/engines/sci/engine/savegame.cfsml +++ b/engines/sci/engine/savegame.cfsml @@ -37,7 +37,6 @@ #include "sci/gfx/menubar.h" #include "sci/sfx/sfx_engine.h" #include "sci/engine/state.h" -#include "sci/engine/heap.h" #include "sci/engine/intmap.h" #ifdef _WIN32 @@ -196,8 +195,8 @@ int read_CommonString(Common::SeekableReadStream *fh, Common::String *string, co void write_menubar_tp(Common::WriteStream *fh, const menubar_t * const *foo); int read_menubar_tp(Common::SeekableReadStream *fh, menubar_t **foo, const char *lastval, int *line, int *hiteof); -void write_mem_obj_tp(Common::WriteStream *fh, const mem_obj_t * const *foo); -int read_mem_obj_tp(Common::SeekableReadStream *fh, mem_obj_t **foo, const char *lastval, int *line, int *hiteof); +void write_MemObjPtr(Common::WriteStream *fh, const MemObject * const *foo); +int read_MemObjPtr(Common::SeekableReadStream *fh, MemObject **foo, const char *lastval, int *line, int *hiteof); void write_songlib_t(Common::WriteStream *fh, songlib_t const *foo); int read_songlib_t(Common::SeekableReadStream *fh, songlib_t *foo, const char *lastval, int *line, int *hiteof); @@ -213,7 +212,7 @@ int read_IntMapperNodePtr(Common::SeekableReadStream *fh, IntMapper::Node **foo, void write_SegManagerPtr(Common::WriteStream *fh, const SegManager * const *foo); int read_SegManagerPtr(Common::SeekableReadStream *fh, SegManager **foo, const char *lastval, int *line, int *hiteof); -typedef mem_obj_t *mem_obj_ptr; +typedef MemObject *mem_obj_ptr; // Unused types /* @@ -231,11 +230,11 @@ RECORD synonym_t "synonym_t" { TYPE bool "bool" LIKE int; TYPE byte "byte" LIKE int; TYPE Common::String ""Common::String" USING write_CommonString read_CommonString; -TYPE seg_id_t "seg_id_t" LIKE int; +TYPE SegmentId "SegmentId" LIKE int; TYPE sci_version_t "sci_version_t" USING write_sci_version read_sci_version; TYPE menubar_tp "menubar_t *" USING write_menubar_tp read_menubar_tp; -TYPE mem_obj_t "mem_obj_t" USING write_mem_obj_t read_mem_obj_t; -TYPE mem_obj_ptr "mem_obj_t *" USING write_mem_obj_tp read_mem_obj_tp; +TYPE MemObject "MemObject" USING write_MemObject read_MemObject; +TYPE mem_obj_ptr "MemObject *" USING write_MemObjPtr read_MemObjPtr; TYPE reg_t "reg_t" USING write_reg_t read_reg_t; TYPE size_t "size_t" LIKE int; TYPE IntMapperPtr "IntMapper *" USING write_IntMapperPtr read_IntMapperPtr; @@ -298,12 +297,12 @@ RECORD SegManager "SegManager" { int exports_wide; int gc_mark_bits; size_t mem_allocated; - seg_id_t clones_seg_id; - seg_id_t lists_seg_id; - seg_id_t nodes_seg_id; + SegmentId Clones_seg_id; + SegmentId Lists_seg_id; + SegmentId Nodes_seg_id; } -RECORD class_t "class_t" { +RECORD Class "Class" { int script; reg_t reg; } @@ -331,17 +330,17 @@ RECORD EngineState "EngineState" { int status_bar_background; SegManagerPtr seg_manager; int classtable_size; - class_t classtable[DYNAMIC classtable_size]; + Class classtable[DYNAMIC classtable_size]; sfx_state_t sound; } -RECORD local_variables_t "local_variables_t" { +RECORD LocalVariables "LocalVariables" { int script_id; int nr; reg_t locals[DYNAMIC nr]; } -RECORD object_t "object_t" { +RECORD Object "Object" { int flags; reg_t pos; int variables_nr; @@ -350,7 +349,7 @@ RECORD object_t "object_t" { reg_t variables[DYNAMIC variables_nr]; } -RECORD clone_t "clone_t" { +RECORD Clone "Clone" { int flags; reg_t pos; int variables_nr; @@ -359,58 +358,58 @@ RECORD clone_t "clone_t" { reg_t variables[DYNAMIC variables_nr]; } -RECORD list_t "list_t" { +RECORD List "List" { reg_t first; reg_t last; } -RECORD node_t "node_t" { +RECORD Node "Node" { reg_t pred; reg_t succ; reg_t key; reg_t value; } -RECORD clone_entry_t "clone_entry_t" { +RECORD CloneEntry "CloneEntry" { int next_free; - clone_t entry; + Clone entry; } -RECORD clone_table_t "clone_table_t" { +RECORD CloneTable "CloneTable" { int entries_nr; int first_free; int entries_used; int max_entry; - clone_entry_t table[DYNAMIC entries_nr]; + CloneEntry table[DYNAMIC entries_nr]; } -RECORD list_entry_t "list_entry_t" { +RECORD ListEntry "ListEntry" { int next_free; - list_t entry; + List entry; } -RECORD list_table_t "list_table_t" { +RECORD ListTable "ListTable" { int entries_nr; int first_free; int entries_used; int max_entry; - list_entry_t table[DYNAMIC entries_nr]; + ListEntry table[DYNAMIC entries_nr]; } -RECORD node_entry_t "node_entry_t" { +RECORD NodeEntry "NodeEntry" { int next_free; - node_t entry; + Node entry; } -RECORD node_table_t "node_table_t" { +RECORD NodeTable "NodeTable" { int entries_nr; int first_free; int entries_used; int max_entry; - node_entry_t table[DYNAMIC entries_nr]; + NodeEntry table[DYNAMIC entries_nr]; } -RECORD script_t "script_t" { +RECORD Script "Script" { int nr; size_t buf_size; @@ -423,7 +422,7 @@ RECORD script_t "script_t" { int lockers; int objects_allocated; int objects_nr; - object_t objects[DYNAMIC objects_allocated]; + Object objects[DYNAMIC objects_allocated]; int locals_offset; int locals_segment; @@ -441,7 +440,7 @@ RECORD SystemStrings "SystemStrings" { SystemString strings[STATIC SYS_STRINGS_MAX]; } -RECORD dynmem_t "dynmem_t" { +RECORD DynMem "DynMem" { int size; string description; byte buf[DYNAMIC size]; @@ -613,18 +612,18 @@ int mem_obj_string_to_enum(const char *str) { return -1; } -void write_mem_obj_t(Common::WriteStream *fh, mem_obj_t const *foo) { +void write_MemObject(Common::WriteStream *fh, MemObject const *foo) { WSprintf(fh, "%s\n", mem_obj_string_names[foo->type].name); %CFSMLWRITE int &foo->segmgr_id INTO fh; switch (foo->type) { case MEM_OBJ_SCRIPT: - %CFSMLWRITE script_t &foo->data.script INTO fh; + %CFSMLWRITE Script &foo->data.script INTO fh; break; case MEM_OBJ_CLONES: - %CFSMLWRITE clone_table_t &foo->data.clones INTO fh; + %CFSMLWRITE CloneTable &foo->data.clones INTO fh; break; case MEM_OBJ_LOCALS: - %CFSMLWRITE local_variables_t &foo->data.locals INTO fh; + %CFSMLWRITE LocalVariables &foo->data.locals INTO fh; break; case MEM_OBJ_SYS_STRINGS: %CFSMLWRITE SystemStrings &foo->data.sys_strings INTO fh; @@ -635,55 +634,55 @@ void write_mem_obj_t(Common::WriteStream *fh, mem_obj_t const *foo) { case MEM_OBJ_HUNK: break; case MEM_OBJ_LISTS: - %CFSMLWRITE list_table_t &foo->data.lists INTO fh; + %CFSMLWRITE ListTable &foo->data.lists INTO fh; break; case MEM_OBJ_NODES: - %CFSMLWRITE node_table_t &foo->data.nodes INTO fh; + %CFSMLWRITE NodeTable &foo->data.nodes INTO fh; break; case MEM_OBJ_DYNMEM: - %CFSMLWRITE dynmem_t &foo->data.dynmem INTO fh; + %CFSMLWRITE DynMem &foo->data.dynmem INTO fh; break; default: break; } } -int read_mem_obj_t(Common::SeekableReadStream *fh, mem_obj_t *foo, const char *lastval, int *line, int *hiteof) { +int read_MemObject(Common::SeekableReadStream *fh, MemObject *foo, const char *lastval, int *line, int *hiteof) { foo->type = (memObjType)mem_obj_string_to_enum(lastval); if (foo->type < 0) { - sciprintf("Unknown mem_obj_t type %s on line %d\n", lastval, *line); + sciprintf("Unknown MemObject type %s on line %d\n", lastval, *line); return 1; } %CFSMLREAD int &foo->segmgr_id FROM fh ERRVAR *hiteof LINECOUNTER *line; switch (foo->type) { case MEM_OBJ_SCRIPT: - %CFSMLREAD script_t &foo->data.script FROM fh ERRVAR *hiteof LINECOUNTER *line; + %CFSMLREAD Script &foo->data.script FROM fh ERRVAR *hiteof LINECOUNTER *line; break; case MEM_OBJ_CLONES: - %CFSMLREAD clone_table_t &foo->data.clones FROM fh ERRVAR *hiteof LINECOUNTER *line; + %CFSMLREAD CloneTable &foo->data.clones FROM fh ERRVAR *hiteof LINECOUNTER *line; break; case MEM_OBJ_LOCALS: - %CFSMLREAD local_variables_t &foo->data.locals FROM fh ERRVAR *hiteof LINECOUNTER *line; + %CFSMLREAD LocalVariables &foo->data.locals FROM fh ERRVAR *hiteof LINECOUNTER *line; break; case MEM_OBJ_SYS_STRINGS: %CFSMLREAD SystemStrings &foo->data.sys_strings FROM fh ERRVAR *hiteof LINECOUNTER *line; break; case MEM_OBJ_LISTS: - %CFSMLREAD list_table_t &foo->data.lists FROM fh ERRVAR *hiteof LINECOUNTER *line; + %CFSMLREAD ListTable &foo->data.lists FROM fh ERRVAR *hiteof LINECOUNTER *line; break; case MEM_OBJ_NODES: - %CFSMLREAD node_table_t &foo->data.nodes FROM fh ERRVAR *hiteof LINECOUNTER *line; + %CFSMLREAD NodeTable &foo->data.nodes FROM fh ERRVAR *hiteof LINECOUNTER *line; break; case MEM_OBJ_STACK: %CFSMLREAD int &foo->data.stack.nr FROM fh ERRVAR *hiteof LINECOUNTER *line; foo->data.stack.entries = (reg_t *)sci_calloc(foo->data.stack.nr, sizeof(reg_t)); break; case MEM_OBJ_HUNK: - init_hunk_table(&foo->data.hunks); + init_Hunk_table(&foo->data.hunks); break; case MEM_OBJ_DYNMEM: - %CFSMLREAD dynmem_t &foo->data.dynmem FROM fh ERRVAR *hiteof LINECOUNTER *line; + %CFSMLREAD DynMem &foo->data.dynmem FROM fh ERRVAR *hiteof LINECOUNTER *line; break; default: break; @@ -692,20 +691,20 @@ int read_mem_obj_t(Common::SeekableReadStream *fh, mem_obj_t *foo, const char *l return *hiteof; } -void write_mem_obj_tp(Common::WriteStream *fh, const mem_obj_t * const *foo) { +void write_MemObjPtr(Common::WriteStream *fh, const MemObject * const *foo) { if (*foo) { - %CFSMLWRITE mem_obj_t (*foo) INTO fh; + %CFSMLWRITE MemObject (*foo) INTO fh; } else { // Nothing to write WSprintf(fh, "\\null\\"); } } -int read_mem_obj_tp(Common::SeekableReadStream *fh, mem_obj_t **foo, const char *lastval, int *line, int *hiteof) { +int read_MemObjPtr(Common::SeekableReadStream *fh, MemObject **foo, const char *lastval, int *line, int *hiteof) { if (lastval[0] == '\\') { *foo = NULL; // No menu bar } else { - *foo = (mem_obj_t *)sci_malloc(sizeof(mem_obj_t)); - %CFSMLREAD mem_obj_t (*foo) FROM fh ERRVAR *hiteof FIRSTTOKEN lastval LINECOUNTER *line; + *foo = (MemObject *)sci_malloc(sizeof(MemObject)); + %CFSMLREAD MemObject (*foo) FROM fh ERRVAR *hiteof FIRSTTOKEN lastval LINECOUNTER *line; return *hiteof; } return 0; @@ -793,7 +792,7 @@ int gamestate_save(EngineState *s, Common::WriteStream *fh, const char* savename return 0; } -static seg_id_t find_unique_seg_by_type(SegManager *self, int type) { +static SegmentId find_unique_seg_by_type(SegManager *self, int type) { int i; for (i = 0; i < self->heap_size; i++) @@ -822,7 +821,7 @@ static byte *find_unique_script_block(EngineState *s, byte *buf, int type) { } static void reconstruct_stack(EngineState *retval) { - seg_id_t stack_seg = find_unique_seg_by_type(retval->seg_manager, MEM_OBJ_STACK); + SegmentId stack_seg = find_unique_seg_by_type(retval->seg_manager, MEM_OBJ_STACK); dstack_t *stack = &(retval->seg_manager->heap[stack_seg]->data.stack); retval->stack_segment = stack_seg; @@ -830,10 +829,10 @@ static void reconstruct_stack(EngineState *retval) { retval->stack_top = retval->stack_base + VM_STACK_SIZE; } -static int clone_entry_used(clone_table_t *table, int n) { +static int clone_entry_used(CloneTable *table, int n) { int backup; int seeker = table->first_free; - clone_entry_t *entries = table->table; + CloneEntry *entries = table->table; if (seeker == HEAPENTRY_INVALID) return 1; @@ -846,9 +845,9 @@ static int clone_entry_used(clone_table_t *table, int n) { return 1; } -static void load_script(EngineState *s, seg_id_t seg) { +static void load_script(EngineState *s, SegmentId seg) { resource_t *script, *heap = NULL; - script_t *scr = &(s->seg_manager->heap[seg]->data.script); + Script *scr = &(s->seg_manager->heap[seg]->data.script); scr->buf = (byte *)malloc(scr->buf_size); @@ -869,14 +868,14 @@ static void load_script(EngineState *s, seg_id_t seg) { static void reconstruct_scripts(EngineState *s, SegManager *self) { int i; - mem_obj_t *mobj; + MemObject *mobj; for (i = 0; i < self->heap_size; i++) { if (self->heap[i]) { mobj = self->heap[i]; switch (mobj->type) { case MEM_OBJ_SCRIPT: { int j; - script_t *scr = &mobj->data.script; + Script *scr = &mobj->data.script; load_script(s, i); scr->locals_block = scr->locals_segment == 0 ? NULL : &s->seg_manager->heap[scr->locals_segment]->data.locals; @@ -908,7 +907,7 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) { switch (mobj->type) { case MEM_OBJ_SCRIPT: { int j; - script_t *scr = &mobj->data.script; + Script *scr = &mobj->data.script; for (j = 0; j < scr->objects_nr; j++) { byte *data = scr->buf + scr->objects[j].pos.offset; @@ -921,7 +920,7 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) { scr->objects[j].base_vars = prop_area; } else { int funct_area = getUInt16( data + SCRIPT_FUNCTAREAPTR_OFFSET ); - object_t *base_obj; + Object *base_obj; base_obj = obj_get(s, scr->objects[j].variables[SCRIPT_SPECIES_SELECTOR]); @@ -948,7 +947,7 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) { void reconstruct_clones(EngineState *s, SegManager *self) { int i; - mem_obj_t *mobj; + MemObject *mobj; for (i = 0; i < self->heap_size; i++) { if (self->heap[i]) { @@ -956,7 +955,7 @@ void reconstruct_clones(EngineState *s, SegManager *self) { switch (mobj->type) { case MEM_OBJ_CLONES: { int j; - clone_entry_t *seeker = mobj->data.clones.table; + CloneEntry *seeker = mobj->data.clones.table; sciprintf("Free list: "); for (j = mobj->data.clones.first_free; j != HEAPENTRY_INVALID; j = mobj->data.clones.table[j].next_free) { @@ -972,7 +971,7 @@ void reconstruct_clones(EngineState *s, SegManager *self) { sciprintf("\n"); for (j = 0; j < mobj->data.clones.max_entry; j++) { - object_t *base_obj; + Object *base_obj; if (!clone_entry_used(&mobj->data.clones, j)) { seeker++; @@ -1119,7 +1118,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { retval->save_dir_copy = make_reg(s->sys_strings_segment, SYS_STRING_SAVEDIR); retval->save_dir_edit_offset = 0; retval->sys_strings_segment = find_unique_seg_by_type(retval->seg_manager, MEM_OBJ_SYS_STRINGS); - retval->sys_strings = &(((mem_obj_t *)(GET_SEGMENT(*retval->seg_manager, retval->sys_strings_segment, MEM_OBJ_SYS_STRINGS)))->data.sys_strings); + retval->sys_strings = &(((MemObject *)(GET_SEGMENT(*retval->seg_manager, retval->sys_strings_segment, MEM_OBJ_SYS_STRINGS)))->data.sys_strings); // Restore system strings SystemString *str; diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index f51d2c25f3..c6d2086436 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -37,7 +37,6 @@ #include "sci/gfx/menubar.h" #include "sci/sfx/sfx_engine.h" #include "sci/engine/state.h" -#include "sci/engine/heap.h" #include "sci/engine/intmap.h" #ifdef _WIN32 @@ -196,8 +195,8 @@ int read_CommonString(Common::SeekableReadStream *fh, Common::String *string, co void write_menubar_tp(Common::WriteStream *fh, const menubar_t * const *foo); int read_menubar_tp(Common::SeekableReadStream *fh, menubar_t **foo, const char *lastval, int *line, int *hiteof); -void write_mem_obj_tp(Common::WriteStream *fh, const mem_obj_t * const *foo); -int read_mem_obj_tp(Common::SeekableReadStream *fh, mem_obj_t **foo, const char *lastval, int *line, int *hiteof); +void write_MemObjPtr(Common::WriteStream *fh, const MemObject * const *foo); +int read_MemObjPtr(Common::SeekableReadStream *fh, MemObject **foo, const char *lastval, int *line, int *hiteof); void write_songlib_t(Common::WriteStream *fh, songlib_t const *foo); int read_songlib_t(Common::SeekableReadStream *fh, songlib_t *foo, const char *lastval, int *line, int *hiteof); @@ -213,7 +212,7 @@ int read_IntMapperNodePtr(Common::SeekableReadStream *fh, IntMapper::Node **foo, void write_SegManagerPtr(Common::WriteStream *fh, const SegManager * const *foo); int read_SegManagerPtr(Common::SeekableReadStream *fh, SegManager **foo, const char *lastval, int *line, int *hiteof); -typedef mem_obj_t *mem_obj_ptr; +typedef MemObject *mem_obj_ptr; // Unused types /* @@ -453,14 +452,6 @@ static char *_cfsml_get_value(Common::SeekableReadStream *fd, int *line, int *hi static void _cfsml_write_sfx_state_t(Common::WriteStream *fh, sfx_state_t const * save_struc); static int _cfsml_read_sfx_state_t(Common::SeekableReadStream *fh, sfx_state_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 383 "engines/sci/engine/savegame.cfsml" -static void _cfsml_write_clone_entry_t(Common::WriteStream *fh, clone_entry_t const * save_struc); -static int _cfsml_read_clone_entry_t(Common::SeekableReadStream *fh, clone_entry_t* save_struc, const char *lastval, int *line, int *hiteof); - -#line 383 "engines/sci/engine/savegame.cfsml" -static void _cfsml_write_object_t(Common::WriteStream *fh, object_t const * save_struc); -static int _cfsml_read_object_t(Common::SeekableReadStream *fh, object_t* save_struc, const char *lastval, int *line, int *hiteof); - #line 383 "engines/sci/engine/savegame.cfsml" static void _cfsml_write_string(Common::WriteStream *fh, const char * const * save_struc); static int _cfsml_read_string(Common::SeekableReadStream *fh, char ** save_struc, const char *lastval, int *line, int *hiteof); @@ -469,13 +460,21 @@ static int _cfsml_read_string(Common::SeekableReadStream *fh, char ** save_struc static void _cfsml_write_menubar_t(Common::WriteStream *fh, menubar_t const * save_struc); static int _cfsml_read_menubar_t(Common::SeekableReadStream *fh, menubar_t* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "engines/sci/engine/savegame.cfsml" +static void _cfsml_write_CloneTable(Common::WriteStream *fh, CloneTable const * save_struc); +static int _cfsml_read_CloneTable(Common::SeekableReadStream *fh, CloneTable* save_struc, const char *lastval, int *line, int *hiteof); + #line 383 "engines/sci/engine/savegame.cfsml" static void _cfsml_write_size_t(Common::WriteStream *fh, size_t const * save_struc); static int _cfsml_read_size_t(Common::SeekableReadStream *fh, size_t* save_struc, const char *lastval, int *line, int *hiteof); #line 383 "engines/sci/engine/savegame.cfsml" -static void _cfsml_write_list_entry_t(Common::WriteStream *fh, list_entry_t const * save_struc); -static int _cfsml_read_list_entry_t(Common::SeekableReadStream *fh, list_entry_t* save_struc, const char *lastval, int *line, int *hiteof); +static void _cfsml_write_SegmentId(Common::WriteStream *fh, SegmentId const * save_struc); +static int _cfsml_read_SegmentId(Common::SeekableReadStream *fh, SegmentId* save_struc, const char *lastval, int *line, int *hiteof); + +#line 383 "engines/sci/engine/savegame.cfsml" +static void _cfsml_write_Node(Common::WriteStream *fh, Node const * save_struc); +static int _cfsml_read_Node(Common::SeekableReadStream *fh, Node* save_struc, const char *lastval, int *line, int *hiteof); #line 383 "engines/sci/engine/savegame.cfsml" static void _cfsml_write_SegManager(Common::WriteStream *fh, SegManager const * save_struc); @@ -489,29 +488,13 @@ static int _cfsml_read_song_t(Common::SeekableReadStream *fh, song_t* save_struc static void _cfsml_write_menu_item_t(Common::WriteStream *fh, menu_item_t const * save_struc); static int _cfsml_read_menu_item_t(Common::SeekableReadStream *fh, menu_item_t* save_struc, const char *lastval, int *line, int *hiteof); -#line 383 "engines/sci/engine/savegame.cfsml" -static void _cfsml_write_node_entry_t(Common::WriteStream *fh, node_entry_t const * save_struc); -static int _cfsml_read_node_entry_t(Common::SeekableReadStream *fh, node_entry_t* save_struc, const char *lastval, int *line, int *hiteof); - -#line 383 "engines/sci/engine/savegame.cfsml" -static void _cfsml_write_seg_id_t(Common::WriteStream *fh, seg_id_t const * save_struc); -static int _cfsml_read_seg_id_t(Common::SeekableReadStream *fh, seg_id_t* save_struc, const char *lastval, int *line, int *hiteof); - -#line 383 "engines/sci/engine/savegame.cfsml" -static void _cfsml_write_dynmem_t(Common::WriteStream *fh, dynmem_t const * save_struc); -static int _cfsml_read_dynmem_t(Common::SeekableReadStream *fh, dynmem_t* save_struc, const char *lastval, int *line, int *hiteof); - -#line 383 "engines/sci/engine/savegame.cfsml" -static void _cfsml_write_local_variables_t(Common::WriteStream *fh, local_variables_t const * save_struc); -static int _cfsml_read_local_variables_t(Common::SeekableReadStream *fh, local_variables_t* save_struc, const char *lastval, int *line, int *hiteof); - #line 383 "engines/sci/engine/savegame.cfsml" static void _cfsml_write_bool(Common::WriteStream *fh, bool const * save_struc); static int _cfsml_read_bool(Common::SeekableReadStream *fh, bool* save_struc, const char *lastval, int *line, int *hiteof); #line 383 "engines/sci/engine/savegame.cfsml" -static void _cfsml_write_node_table_t(Common::WriteStream *fh, node_table_t const * save_struc); -static int _cfsml_read_node_table_t(Common::SeekableReadStream *fh, node_table_t* save_struc, const char *lastval, int *line, int *hiteof); +static void _cfsml_write_NodeTable(Common::WriteStream *fh, NodeTable const * save_struc); +static int _cfsml_read_NodeTable(Common::SeekableReadStream *fh, NodeTable* save_struc, const char *lastval, int *line, int *hiteof); #line 383 "engines/sci/engine/savegame.cfsml" static void _cfsml_write_SystemString(Common::WriteStream *fh, SystemString const * save_struc); @@ -522,24 +505,28 @@ static void _cfsml_write_byte(Common::WriteStream *fh, byte const * save_struc); static int _cfsml_read_byte(Common::SeekableReadStream *fh, byte* save_struc, const char *lastval, int *line, int *hiteof); #line 383 "engines/sci/engine/savegame.cfsml" -static void _cfsml_write_node_t(Common::WriteStream *fh, node_t const * save_struc); -static int _cfsml_read_node_t(Common::SeekableReadStream *fh, node_t* save_struc, const char *lastval, int *line, int *hiteof); +static void _cfsml_write_ListTable(Common::WriteStream *fh, ListTable const * save_struc); +static int _cfsml_read_ListTable(Common::SeekableReadStream *fh, ListTable* save_struc, const char *lastval, int *line, int *hiteof); + +#line 383 "engines/sci/engine/savegame.cfsml" +static void _cfsml_write_Class(Common::WriteStream *fh, Class const * save_struc); +static int _cfsml_read_Class(Common::SeekableReadStream *fh, Class* save_struc, const char *lastval, int *line, int *hiteof); #line 383 "engines/sci/engine/savegame.cfsml" static void _cfsml_write_SystemStrings(Common::WriteStream *fh, SystemStrings const * save_struc); static int _cfsml_read_SystemStrings(Common::SeekableReadStream *fh, SystemStrings* save_struc, const char *lastval, int *line, int *hiteof); #line 383 "engines/sci/engine/savegame.cfsml" -static void _cfsml_write_list_table_t(Common::WriteStream *fh, list_table_t const * save_struc); -static int _cfsml_read_list_table_t(Common::SeekableReadStream *fh, list_table_t* save_struc, const char *lastval, int *line, int *hiteof); +static void _cfsml_write_song_handle_t(Common::WriteStream *fh, song_handle_t const * save_struc); +static int _cfsml_read_song_handle_t(Common::SeekableReadStream *fh, song_handle_t* save_struc, const char *lastval, int *line, int *hiteof); #line 383 "engines/sci/engine/savegame.cfsml" -static void _cfsml_write_class_t(Common::WriteStream *fh, class_t const * save_struc); -static int _cfsml_read_class_t(Common::SeekableReadStream *fh, class_t* save_struc, const char *lastval, int *line, int *hiteof); +static void _cfsml_write_List(Common::WriteStream *fh, List const * save_struc); +static int _cfsml_read_List(Common::SeekableReadStream *fh, List* save_struc, const char *lastval, int *line, int *hiteof); #line 383 "engines/sci/engine/savegame.cfsml" -static void _cfsml_write_song_handle_t(Common::WriteStream *fh, song_handle_t const * save_struc); -static int _cfsml_read_song_handle_t(Common::SeekableReadStream *fh, song_handle_t* save_struc, const char *lastval, int *line, int *hiteof); +static void _cfsml_write_NodeEntry(Common::WriteStream *fh, NodeEntry const * save_struc); +static int _cfsml_read_NodeEntry(Common::SeekableReadStream *fh, NodeEntry* save_struc, const char *lastval, int *line, int *hiteof); #line 383 "engines/sci/engine/savegame.cfsml" static void _cfsml_write_int(Common::WriteStream *fh, int const * save_struc); @@ -549,10 +536,18 @@ static int _cfsml_read_int(Common::SeekableReadStream *fh, int* save_struc, cons static void _cfsml_write_EngineState(Common::WriteStream *fh, EngineState const * save_struc); static int _cfsml_read_EngineState(Common::SeekableReadStream *fh, EngineState* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "engines/sci/engine/savegame.cfsml" +static void _cfsml_write_CloneEntry(Common::WriteStream *fh, CloneEntry const * save_struc); +static int _cfsml_read_CloneEntry(Common::SeekableReadStream *fh, CloneEntry* save_struc, const char *lastval, int *line, int *hiteof); + #line 383 "engines/sci/engine/savegame.cfsml" static void _cfsml_write_SavegameMetadata(Common::WriteStream *fh, SavegameMetadata const * save_struc); static int _cfsml_read_SavegameMetadata(Common::SeekableReadStream *fh, SavegameMetadata* save_struc, const char *lastval, int *line, int *hiteof); +#line 383 "engines/sci/engine/savegame.cfsml" +static void _cfsml_write_LocalVariables(Common::WriteStream *fh, LocalVariables const * save_struc); +static int _cfsml_read_LocalVariables(Common::SeekableReadStream *fh, LocalVariables* save_struc, const char *lastval, int *line, int *hiteof); + #line 383 "engines/sci/engine/savegame.cfsml" static void _cfsml_write_IntMapper(Common::WriteStream *fh, IntMapper const * save_struc); static int _cfsml_read_IntMapper(Common::SeekableReadStream *fh, IntMapper* save_struc, const char *lastval, int *line, int *hiteof); @@ -562,20 +557,24 @@ static void _cfsml_write_menu_t(Common::WriteStream *fh, menu_t const * save_str static int _cfsml_read_menu_t(Common::SeekableReadStream *fh, menu_t* save_struc, const char *lastval, int *line, int *hiteof); #line 383 "engines/sci/engine/savegame.cfsml" -static void _cfsml_write_clone_table_t(Common::WriteStream *fh, clone_table_t const * save_struc); -static int _cfsml_read_clone_table_t(Common::SeekableReadStream *fh, clone_table_t* save_struc, const char *lastval, int *line, int *hiteof); +static void _cfsml_write_Object(Common::WriteStream *fh, Object const * save_struc); +static int _cfsml_read_Object(Common::SeekableReadStream *fh, Object* save_struc, const char *lastval, int *line, int *hiteof); + +#line 383 "engines/sci/engine/savegame.cfsml" +static void _cfsml_write_ListEntry(Common::WriteStream *fh, ListEntry const * save_struc); +static int _cfsml_read_ListEntry(Common::SeekableReadStream *fh, ListEntry* save_struc, const char *lastval, int *line, int *hiteof); #line 383 "engines/sci/engine/savegame.cfsml" -static void _cfsml_write_list_t(Common::WriteStream *fh, list_t const * save_struc); -static int _cfsml_read_list_t(Common::SeekableReadStream *fh, list_t* save_struc, const char *lastval, int *line, int *hiteof); +static void _cfsml_write_Clone(Common::WriteStream *fh, Clone const * save_struc); +static int _cfsml_read_Clone(Common::SeekableReadStream *fh, Clone* save_struc, const char *lastval, int *line, int *hiteof); #line 383 "engines/sci/engine/savegame.cfsml" -static void _cfsml_write_clone_t(Common::WriteStream *fh, clone_t const * save_struc); -static int _cfsml_read_clone_t(Common::SeekableReadStream *fh, clone_t* save_struc, const char *lastval, int *line, int *hiteof); +static void _cfsml_write_DynMem(Common::WriteStream *fh, DynMem const * save_struc); +static int _cfsml_read_DynMem(Common::SeekableReadStream *fh, DynMem* save_struc, const char *lastval, int *line, int *hiteof); #line 383 "engines/sci/engine/savegame.cfsml" -static void _cfsml_write_script_t(Common::WriteStream *fh, script_t const * save_struc); -static int _cfsml_read_script_t(Common::SeekableReadStream *fh, script_t* save_struc, const char *lastval, int *line, int *hiteof); +static void _cfsml_write_Script(Common::WriteStream *fh, Script const * save_struc); +static int _cfsml_read_Script(Common::SeekableReadStream *fh, Script* save_struc, const char *lastval, int *line, int *hiteof); #line 396 "engines/sci/engine/savegame.cfsml" static void @@ -644,29 +643,79 @@ _cfsml_read_sfx_state_t(Common::SeekableReadStream *fh, sfx_state_t* save_struc, #line 396 "engines/sci/engine/savegame.cfsml" static void -_cfsml_write_clone_entry_t(Common::WriteStream *fh, clone_entry_t const * save_struc) +_cfsml_write_string(Common::WriteStream *fh, const char * const * save_struc) +{ +#line 403 "engines/sci/engine/savegame.cfsml" + if (!(*save_struc)) + WSprintf(fh, "\\null\\"); + else { + char *token = _cfsml_mangle_string((const char *) *save_struc); + WSprintf(fh, "\"%s\"", token); + free(token); + } +} + +#line 487 "engines/sci/engine/savegame.cfsml" +static int +_cfsml_read_string(Common::SeekableReadStream *fh, char ** save_struc, const char *lastval, int *line, int *hiteof) +{ +#line 520 "engines/sci/engine/savegame.cfsml" + + if (strcmp(lastval, "\\null\\")) { // null pointer? + unsigned int length = strlen(lastval); + if (*lastval == '"') { // Quoted string? + while (lastval[length] != '"') + --length; + + if (!length) { // No matching double-quotes? + _cfsml_error("Unbalanced quotes at line %d\n", *line); + return CFSML_FAILURE; + } + + lastval++; // ...and skip the opening quotes locally + length--; + } + *save_struc = _cfsml_unmangle_string(lastval, length); + _cfsml_register_pointer(*save_struc); + return CFSML_SUCCESS; + } else { + *save_struc = NULL; + return CFSML_SUCCESS; + } +} + +#line 396 "engines/sci/engine/savegame.cfsml" +static void +_cfsml_write_menubar_t(Common::WriteStream *fh, menubar_t const * save_struc) { #line 413 "engines/sci/engine/savegame.cfsml" WSprintf(fh, "{\n"); - WSprintf(fh, "next_free = "); - _cfsml_write_int(fh, (int const *) &(save_struc->next_free)); - WSprintf(fh, "\n"); - WSprintf(fh, "entry = "); - _cfsml_write_clone_t(fh, (clone_t const *) &(save_struc->entry)); + WSprintf(fh, "menus = "); + int min, max; + min = max = save_struc->menus_nr; + if (!save_struc->menus) + min = max = 0; /* Don't write if it points to NULL */ +#line 440 "engines/sci/engine/savegame.cfsml" + WSprintf(fh, "[%d][\n", max); + for (int i = 0; i < min; i++) { + _cfsml_write_menu_t(fh, &(save_struc->menus[i])); + WSprintf(fh, "\n"); + } + WSprintf(fh, "]"); WSprintf(fh, "\n"); WSprintf(fh, "}"); } #line 487 "engines/sci/engine/savegame.cfsml" static int -_cfsml_read_clone_entry_t(Common::SeekableReadStream *fh, clone_entry_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_menubar_t(Common::SeekableReadStream *fh, menubar_t* save_struc, const char *lastval, int *line, int *hiteof) { #line 542 "engines/sci/engine/savegame.cfsml" char *token; int assignment, closed; if (strcmp(lastval, "{")) { - _cfsml_error("Reading record clone_entry_t; expected opening braces in line %d, got \"%s\"\n", *line, lastval); + _cfsml_error("Reading record menubar_t; expected opening braces in line %d, got \"%s\"\n", *line, lastval); return CFSML_FAILURE; }; closed = 0; @@ -693,23 +742,54 @@ _cfsml_read_clone_entry_t(Common::SeekableReadStream *fh, clone_entry_t* save_st _cfsml_error("Expected token at line %d\n", *line); return CFSML_FAILURE; } - if (!strcmp(token, "next_free")) { -#line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_int(fh, (int*) &(save_struc->next_free), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_int() for next_free at line %d\n", *line); + if (!strcmp(token, "menus")) { +#line 605 "engines/sci/engine/savegame.cfsml" + if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { + _cfsml_error("Opening brackets expected at line %d\n", *line); + return CFSML_FAILURE; + } + int max,done,i; +#line 616 "engines/sci/engine/savegame.cfsml" + // Prepare to restore dynamic array + max = strtol(value + 1, NULL, 0); + if (max < 0) { + _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line); + return CFSML_FAILURE; + } + + if (max) { + save_struc->menus = (menu_t *)sci_malloc(max * sizeof(menu_t)); +#ifdef SATISFY_PURIFY + memset(save_struc->menus, 0, max * sizeof(menu_t)); +#endif + _cfsml_register_pointer(save_struc->menus); + } else + save_struc->menus = NULL; +#line 640 "engines/sci/engine/savegame.cfsml" + done = i = 0; + do { + if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) { +#line 648 "engines/sci/engine/savegame.cfsml" + _cfsml_error("Token expected at line %d\n", *line); + return 1; + } + if (strcmp(value, "]")) { + if (i == max) { + _cfsml_error("More elements than space available (%d) in '%s' at line %d\n", max, token, *line); return CFSML_FAILURE; } - } else - if (!strcmp(token, "entry")) { -#line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_clone_t(fh, (clone_t*) &(save_struc->entry), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_clone_t() for entry at line %d\n", *line); + if (_cfsml_read_menu_t(fh, &(save_struc->menus[i++]), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_menu_t() for menus[i++] at line %d\n", *line); return CFSML_FAILURE; } } else + done = 1; + } while (!done); + save_struc->menus_nr = max ; // Set array size accordingly + } else #line 700 "engines/sci/engine/savegame.cfsml" { - _cfsml_error("clone_entry_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); + _cfsml_error("menubar_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; } } @@ -719,34 +799,31 @@ _cfsml_read_clone_entry_t(Common::SeekableReadStream *fh, clone_entry_t* save_st #line 396 "engines/sci/engine/savegame.cfsml" static void -_cfsml_write_object_t(Common::WriteStream *fh, object_t const * save_struc) +_cfsml_write_CloneTable(Common::WriteStream *fh, CloneTable const * save_struc) { #line 413 "engines/sci/engine/savegame.cfsml" WSprintf(fh, "{\n"); - WSprintf(fh, "flags = "); - _cfsml_write_int(fh, (int const *) &(save_struc->flags)); - WSprintf(fh, "\n"); - WSprintf(fh, "pos = "); - write_reg_t(fh, (reg_t const *) &(save_struc->pos)); + WSprintf(fh, "entries_nr = "); + _cfsml_write_int(fh, (int const *) &(save_struc->entries_nr)); WSprintf(fh, "\n"); - WSprintf(fh, "variables_nr = "); - _cfsml_write_int(fh, (int const *) &(save_struc->variables_nr)); + WSprintf(fh, "first_free = "); + _cfsml_write_int(fh, (int const *) &(save_struc->first_free)); WSprintf(fh, "\n"); - WSprintf(fh, "variable_names_nr = "); - _cfsml_write_int(fh, (int const *) &(save_struc->variable_names_nr)); + WSprintf(fh, "entries_used = "); + _cfsml_write_int(fh, (int const *) &(save_struc->entries_used)); WSprintf(fh, "\n"); - WSprintf(fh, "methods_nr = "); - _cfsml_write_int(fh, (int const *) &(save_struc->methods_nr)); + WSprintf(fh, "max_entry = "); + _cfsml_write_int(fh, (int const *) &(save_struc->max_entry)); WSprintf(fh, "\n"); - WSprintf(fh, "variables = "); + WSprintf(fh, "table = "); int min, max; - min = max = save_struc->variables_nr; - if (!save_struc->variables) + min = max = save_struc->entries_nr; + if (!save_struc->table) min = max = 0; /* Don't write if it points to NULL */ #line 440 "engines/sci/engine/savegame.cfsml" WSprintf(fh, "[%d][\n", max); for (int i = 0; i < min; i++) { - write_reg_t(fh, &(save_struc->variables[i])); + _cfsml_write_CloneEntry(fh, &(save_struc->table[i])); WSprintf(fh, "\n"); } WSprintf(fh, "]"); @@ -756,14 +833,14 @@ _cfsml_write_object_t(Common::WriteStream *fh, object_t const * save_struc) #line 487 "engines/sci/engine/savegame.cfsml" static int -_cfsml_read_object_t(Common::SeekableReadStream *fh, object_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_CloneTable(Common::SeekableReadStream *fh, CloneTable* save_struc, const char *lastval, int *line, int *hiteof) { #line 542 "engines/sci/engine/savegame.cfsml" char *token; int assignment, closed; if (strcmp(lastval, "{")) { - _cfsml_error("Reading record object_t; expected opening braces in line %d, got \"%s\"\n", *line, lastval); + _cfsml_error("Reading record CloneTable; expected opening braces in line %d, got \"%s\"\n", *line, lastval); return CFSML_FAILURE; }; closed = 0; @@ -790,42 +867,35 @@ _cfsml_read_object_t(Common::SeekableReadStream *fh, object_t* save_struc, const _cfsml_error("Expected token at line %d\n", *line); return CFSML_FAILURE; } - if (!strcmp(token, "flags")) { -#line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_int(fh, (int*) &(save_struc->flags), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_int() for flags at line %d\n", *line); - return CFSML_FAILURE; - } - } else - if (!strcmp(token, "pos")) { + if (!strcmp(token, "entries_nr")) { #line 691 "engines/sci/engine/savegame.cfsml" - if (read_reg_t(fh, (reg_t*) &(save_struc->pos), value, line, hiteof)) { - _cfsml_error("Token expected by read_reg_t() for pos at line %d\n", *line); + if (_cfsml_read_int(fh, (int*) &(save_struc->entries_nr), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for entries_nr at line %d\n", *line); return CFSML_FAILURE; } } else - if (!strcmp(token, "variables_nr")) { + if (!strcmp(token, "first_free")) { #line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_int(fh, (int*) &(save_struc->variables_nr), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_int() for variables_nr at line %d\n", *line); + if (_cfsml_read_int(fh, (int*) &(save_struc->first_free), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for first_free at line %d\n", *line); return CFSML_FAILURE; } } else - if (!strcmp(token, "variable_names_nr")) { + if (!strcmp(token, "entries_used")) { #line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_int(fh, (int*) &(save_struc->variable_names_nr), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_int() for variable_names_nr at line %d\n", *line); + if (_cfsml_read_int(fh, (int*) &(save_struc->entries_used), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for entries_used at line %d\n", *line); return CFSML_FAILURE; } } else - if (!strcmp(token, "methods_nr")) { + if (!strcmp(token, "max_entry")) { #line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_int(fh, (int*) &(save_struc->methods_nr), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_int() for methods_nr at line %d\n", *line); + if (_cfsml_read_int(fh, (int*) &(save_struc->max_entry), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for max_entry at line %d\n", *line); return CFSML_FAILURE; } } else - if (!strcmp(token, "variables")) { + if (!strcmp(token, "table")) { #line 605 "engines/sci/engine/savegame.cfsml" if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { _cfsml_error("Opening brackets expected at line %d\n", *line); @@ -841,13 +911,13 @@ _cfsml_read_object_t(Common::SeekableReadStream *fh, object_t* save_struc, const } if (max) { - save_struc->variables = (reg_t *)sci_malloc(max * sizeof(reg_t)); + save_struc->table = (CloneEntry *)sci_malloc(max * sizeof(CloneEntry)); #ifdef SATISFY_PURIFY - memset(save_struc->variables, 0, max * sizeof(reg_t)); + memset(save_struc->table, 0, max * sizeof(CloneEntry)); #endif - _cfsml_register_pointer(save_struc->variables); + _cfsml_register_pointer(save_struc->table); } else - save_struc->variables = NULL; + save_struc->table = NULL; #line 640 "engines/sci/engine/savegame.cfsml" done = i = 0; do { @@ -861,18 +931,18 @@ _cfsml_read_object_t(Common::SeekableReadStream *fh, object_t* save_struc, const _cfsml_error("More elements than space available (%d) in '%s' at line %d\n", max, token, *line); return CFSML_FAILURE; } - if (read_reg_t(fh, &(save_struc->variables[i++]), value, line, hiteof)) { - _cfsml_error("Token expected by read_reg_t() for variables[i++] at line %d\n", *line); + if (_cfsml_read_CloneEntry(fh, &(save_struc->table[i++]), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_CloneEntry() for table[i++] at line %d\n", *line); return CFSML_FAILURE; } } else done = 1; } while (!done); - save_struc->variables_nr = max ; // Set array size accordingly + save_struc->entries_nr = max ; // Set array size accordingly } else #line 700 "engines/sci/engine/savegame.cfsml" { - _cfsml_error("object_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); + _cfsml_error("CloneTable: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; } } @@ -882,170 +952,40 @@ _cfsml_read_object_t(Common::SeekableReadStream *fh, object_t* save_struc, const #line 396 "engines/sci/engine/savegame.cfsml" static void -_cfsml_write_string(Common::WriteStream *fh, const char * const * save_struc) +_cfsml_write_size_t(Common::WriteStream *fh, size_t const * save_struc) { -#line 403 "engines/sci/engine/savegame.cfsml" - if (!(*save_struc)) - WSprintf(fh, "\\null\\"); - else { - char *token = _cfsml_mangle_string((const char *) *save_struc); - WSprintf(fh, "\"%s\"", token); - free(token); - } + WSprintf(fh, "%li", (long)*save_struc); } #line 487 "engines/sci/engine/savegame.cfsml" static int -_cfsml_read_string(Common::SeekableReadStream *fh, char ** save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_size_t(Common::SeekableReadStream *fh, size_t* save_struc, const char *lastval, int *line, int *hiteof) { -#line 520 "engines/sci/engine/savegame.cfsml" - - if (strcmp(lastval, "\\null\\")) { // null pointer? - unsigned int length = strlen(lastval); - if (*lastval == '"') { // Quoted string? - while (lastval[length] != '"') - --length; - - if (!length) { // No matching double-quotes? - _cfsml_error("Unbalanced quotes at line %d\n", *line); - return CFSML_FAILURE; - } +#line 507 "engines/sci/engine/savegame.cfsml" + char *token; - lastval++; // ...and skip the opening quotes locally - length--; - } - *save_struc = _cfsml_unmangle_string(lastval, length); - _cfsml_register_pointer(*save_struc); - return CFSML_SUCCESS; - } else { - *save_struc = NULL; - return CFSML_SUCCESS; + *save_struc = strtol(lastval, &token, 0); + if ((*save_struc == 0) && (token == lastval)) { + _cfsml_error("strtol failed at line %d\n", *line); + return CFSML_FAILURE; + } + if (*token != 0) { + _cfsml_error("Non-integer encountered while parsing int value at line %d\n", *line); + return CFSML_FAILURE; } + return CFSML_SUCCESS; } #line 396 "engines/sci/engine/savegame.cfsml" static void -_cfsml_write_menubar_t(Common::WriteStream *fh, menubar_t const * save_struc) -{ -#line 413 "engines/sci/engine/savegame.cfsml" - WSprintf(fh, "{\n"); - WSprintf(fh, "menus = "); - int min, max; - min = max = save_struc->menus_nr; - if (!save_struc->menus) - min = max = 0; /* Don't write if it points to NULL */ -#line 440 "engines/sci/engine/savegame.cfsml" - WSprintf(fh, "[%d][\n", max); - for (int i = 0; i < min; i++) { - _cfsml_write_menu_t(fh, &(save_struc->menus[i])); - WSprintf(fh, "\n"); - } - WSprintf(fh, "]"); - WSprintf(fh, "\n"); - WSprintf(fh, "}"); -} - -#line 487 "engines/sci/engine/savegame.cfsml" -static int -_cfsml_read_menubar_t(Common::SeekableReadStream *fh, menubar_t* save_struc, const char *lastval, int *line, int *hiteof) -{ -#line 542 "engines/sci/engine/savegame.cfsml" - char *token; - int assignment, closed; - - if (strcmp(lastval, "{")) { - _cfsml_error("Reading record menubar_t; expected opening braces in line %d, got \"%s\"\n", *line, lastval); - return CFSML_FAILURE; - }; - closed = 0; - do { - const char *value; - token = _cfsml_get_identifier(fh, line, hiteof, &assignment); - - if (!token) { - _cfsml_error("Expected token at line %d\n", *line); - return CFSML_FAILURE; - } - if (!assignment) { - if (!strcmp(token, "}")) - closed = 1; - else { - _cfsml_error("Expected assignment or closing braces in line %d\n", *line); - return CFSML_FAILURE; - } - } else { - value = ""; - while (!value || !strcmp(value, "")) - value = _cfsml_get_value(fh, line, hiteof); - if (!value) { - _cfsml_error("Expected token at line %d\n", *line); - return CFSML_FAILURE; - } - if (!strcmp(token, "menus")) { -#line 605 "engines/sci/engine/savegame.cfsml" - if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { - _cfsml_error("Opening brackets expected at line %d\n", *line); - return CFSML_FAILURE; - } - int max,done,i; -#line 616 "engines/sci/engine/savegame.cfsml" - // Prepare to restore dynamic array - max = strtol(value + 1, NULL, 0); - if (max < 0) { - _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line); - return CFSML_FAILURE; - } - - if (max) { - save_struc->menus = (menu_t *)sci_malloc(max * sizeof(menu_t)); -#ifdef SATISFY_PURIFY - memset(save_struc->menus, 0, max * sizeof(menu_t)); -#endif - _cfsml_register_pointer(save_struc->menus); - } else - save_struc->menus = NULL; -#line 640 "engines/sci/engine/savegame.cfsml" - done = i = 0; - do { - if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) { -#line 648 "engines/sci/engine/savegame.cfsml" - _cfsml_error("Token expected at line %d\n", *line); - return 1; - } - if (strcmp(value, "]")) { - if (i == max) { - _cfsml_error("More elements than space available (%d) in '%s' at line %d\n", max, token, *line); - return CFSML_FAILURE; - } - if (_cfsml_read_menu_t(fh, &(save_struc->menus[i++]), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_menu_t() for menus[i++] at line %d\n", *line); - return CFSML_FAILURE; - } - } else - done = 1; - } while (!done); - save_struc->menus_nr = max ; // Set array size accordingly - } else -#line 700 "engines/sci/engine/savegame.cfsml" - { - _cfsml_error("menubar_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); - return CFSML_FAILURE; - } - } - } while (!closed); // Until closing braces are hit - return CFSML_SUCCESS; -} - -#line 396 "engines/sci/engine/savegame.cfsml" -static void -_cfsml_write_size_t(Common::WriteStream *fh, size_t const * save_struc) +_cfsml_write_SegmentId(Common::WriteStream *fh, SegmentId const * save_struc) { WSprintf(fh, "%li", (long)*save_struc); } #line 487 "engines/sci/engine/savegame.cfsml" static int -_cfsml_read_size_t(Common::SeekableReadStream *fh, size_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_SegmentId(Common::SeekableReadStream *fh, SegmentId* save_struc, const char *lastval, int *line, int *hiteof) { #line 507 "engines/sci/engine/savegame.cfsml" char *token; @@ -1064,29 +1004,35 @@ _cfsml_read_size_t(Common::SeekableReadStream *fh, size_t* save_struc, const cha #line 396 "engines/sci/engine/savegame.cfsml" static void -_cfsml_write_list_entry_t(Common::WriteStream *fh, list_entry_t const * save_struc) +_cfsml_write_Node(Common::WriteStream *fh, Node const * save_struc) { #line 413 "engines/sci/engine/savegame.cfsml" WSprintf(fh, "{\n"); - WSprintf(fh, "next_free = "); - _cfsml_write_int(fh, (int const *) &(save_struc->next_free)); + WSprintf(fh, "pred = "); + write_reg_t(fh, (reg_t const *) &(save_struc->pred)); WSprintf(fh, "\n"); - WSprintf(fh, "entry = "); - _cfsml_write_list_t(fh, (list_t const *) &(save_struc->entry)); + WSprintf(fh, "succ = "); + write_reg_t(fh, (reg_t const *) &(save_struc->succ)); + WSprintf(fh, "\n"); + WSprintf(fh, "key = "); + write_reg_t(fh, (reg_t const *) &(save_struc->key)); + WSprintf(fh, "\n"); + WSprintf(fh, "value = "); + write_reg_t(fh, (reg_t const *) &(save_struc->value)); WSprintf(fh, "\n"); WSprintf(fh, "}"); } #line 487 "engines/sci/engine/savegame.cfsml" static int -_cfsml_read_list_entry_t(Common::SeekableReadStream *fh, list_entry_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_Node(Common::SeekableReadStream *fh, Node* save_struc, const char *lastval, int *line, int *hiteof) { #line 542 "engines/sci/engine/savegame.cfsml" char *token; int assignment, closed; if (strcmp(lastval, "{")) { - _cfsml_error("Reading record list_entry_t; expected opening braces in line %d, got \"%s\"\n", *line, lastval); + _cfsml_error("Reading record Node; expected opening braces in line %d, got \"%s\"\n", *line, lastval); return CFSML_FAILURE; }; closed = 0; @@ -1113,23 +1059,37 @@ _cfsml_read_list_entry_t(Common::SeekableReadStream *fh, list_entry_t* save_stru _cfsml_error("Expected token at line %d\n", *line); return CFSML_FAILURE; } - if (!strcmp(token, "next_free")) { + if (!strcmp(token, "pred")) { #line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_int(fh, (int*) &(save_struc->next_free), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_int() for next_free at line %d\n", *line); + if (read_reg_t(fh, (reg_t*) &(save_struc->pred), value, line, hiteof)) { + _cfsml_error("Token expected by read_reg_t() for pred at line %d\n", *line); return CFSML_FAILURE; } } else - if (!strcmp(token, "entry")) { + if (!strcmp(token, "succ")) { +#line 691 "engines/sci/engine/savegame.cfsml" + if (read_reg_t(fh, (reg_t*) &(save_struc->succ), value, line, hiteof)) { + _cfsml_error("Token expected by read_reg_t() for succ at line %d\n", *line); + return CFSML_FAILURE; + } + } else + if (!strcmp(token, "key")) { +#line 691 "engines/sci/engine/savegame.cfsml" + if (read_reg_t(fh, (reg_t*) &(save_struc->key), value, line, hiteof)) { + _cfsml_error("Token expected by read_reg_t() for key at line %d\n", *line); + return CFSML_FAILURE; + } + } else + if (!strcmp(token, "value")) { #line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_list_t(fh, (list_t*) &(save_struc->entry), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_list_t() for entry at line %d\n", *line); + if (read_reg_t(fh, (reg_t*) &(save_struc->value), value, line, hiteof)) { + _cfsml_error("Token expected by read_reg_t() for value at line %d\n", *line); return CFSML_FAILURE; } } else #line 700 "engines/sci/engine/savegame.cfsml" { - _cfsml_error("list_entry_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); + _cfsml_error("Node: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; } } @@ -1154,7 +1114,7 @@ _cfsml_write_SegManager(Common::WriteStream *fh, SegManager const * save_struc) #line 440 "engines/sci/engine/savegame.cfsml" WSprintf(fh, "[%d][\n", max); for (int i = 0; i < min; i++) { - write_mem_obj_tp(fh, &(save_struc->heap[i])); + write_MemObjPtr(fh, &(save_struc->heap[i])); WSprintf(fh, "\n"); } WSprintf(fh, "]"); @@ -1174,14 +1134,14 @@ _cfsml_write_SegManager(Common::WriteStream *fh, SegManager const * save_struc) WSprintf(fh, "mem_allocated = "); _cfsml_write_size_t(fh, (size_t const *) &(save_struc->mem_allocated)); WSprintf(fh, "\n"); - WSprintf(fh, "clones_seg_id = "); - _cfsml_write_seg_id_t(fh, (seg_id_t const *) &(save_struc->clones_seg_id)); + WSprintf(fh, "Clones_seg_id = "); + _cfsml_write_SegmentId(fh, (SegmentId const *) &(save_struc->Clones_seg_id)); WSprintf(fh, "\n"); - WSprintf(fh, "lists_seg_id = "); - _cfsml_write_seg_id_t(fh, (seg_id_t const *) &(save_struc->lists_seg_id)); + WSprintf(fh, "Lists_seg_id = "); + _cfsml_write_SegmentId(fh, (SegmentId const *) &(save_struc->Lists_seg_id)); WSprintf(fh, "\n"); - WSprintf(fh, "nodes_seg_id = "); - _cfsml_write_seg_id_t(fh, (seg_id_t const *) &(save_struc->nodes_seg_id)); + WSprintf(fh, "Nodes_seg_id = "); + _cfsml_write_SegmentId(fh, (SegmentId const *) &(save_struc->Nodes_seg_id)); WSprintf(fh, "\n"); WSprintf(fh, "}"); } @@ -1265,8 +1225,8 @@ _cfsml_read_SegManager(Common::SeekableReadStream *fh, SegManager* save_struc, c _cfsml_error("More elements than space available (%d) in '%s' at line %d\n", max, token, *line); return CFSML_FAILURE; } - if (read_mem_obj_tp(fh, &(save_struc->heap[i++]), value, line, hiteof)) { - _cfsml_error("Token expected by read_mem_obj_tp() for heap[i++] at line %d\n", *line); + if (read_MemObjPtr(fh, &(save_struc->heap[i++]), value, line, hiteof)) { + _cfsml_error("Token expected by read_MemObjPtr() for heap[i++] at line %d\n", *line); return CFSML_FAILURE; } } else @@ -1309,24 +1269,24 @@ _cfsml_read_SegManager(Common::SeekableReadStream *fh, SegManager* save_struc, c return CFSML_FAILURE; } } else - if (!strcmp(token, "clones_seg_id")) { + if (!strcmp(token, "Clones_seg_id")) { #line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_seg_id_t(fh, (seg_id_t*) &(save_struc->clones_seg_id), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_seg_id_t() for clones_seg_id at line %d\n", *line); + if (_cfsml_read_SegmentId(fh, (SegmentId*) &(save_struc->Clones_seg_id), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_SegmentId() for Clones_seg_id at line %d\n", *line); return CFSML_FAILURE; } } else - if (!strcmp(token, "lists_seg_id")) { + if (!strcmp(token, "Lists_seg_id")) { #line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_seg_id_t(fh, (seg_id_t*) &(save_struc->lists_seg_id), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_seg_id_t() for lists_seg_id at line %d\n", *line); + if (_cfsml_read_SegmentId(fh, (SegmentId*) &(save_struc->Lists_seg_id), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_SegmentId() for Lists_seg_id at line %d\n", *line); return CFSML_FAILURE; } } else - if (!strcmp(token, "nodes_seg_id")) { + if (!strcmp(token, "Nodes_seg_id")) { #line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_seg_id_t(fh, (seg_id_t*) &(save_struc->nodes_seg_id), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_seg_id_t() for nodes_seg_id at line %d\n", *line); + if (_cfsml_read_SegmentId(fh, (SegmentId*) &(save_struc->Nodes_seg_id), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_SegmentId() for Nodes_seg_id at line %d\n", *line); return CFSML_FAILURE; } } else @@ -1683,89 +1643,14 @@ _cfsml_read_menu_item_t(Common::SeekableReadStream *fh, menu_item_t* save_struc, #line 396 "engines/sci/engine/savegame.cfsml" static void -_cfsml_write_node_entry_t(Common::WriteStream *fh, node_entry_t const * save_struc) -{ -#line 413 "engines/sci/engine/savegame.cfsml" - WSprintf(fh, "{\n"); - WSprintf(fh, "next_free = "); - _cfsml_write_int(fh, (int const *) &(save_struc->next_free)); - WSprintf(fh, "\n"); - WSprintf(fh, "entry = "); - _cfsml_write_node_t(fh, (node_t const *) &(save_struc->entry)); - WSprintf(fh, "\n"); - WSprintf(fh, "}"); -} - -#line 487 "engines/sci/engine/savegame.cfsml" -static int -_cfsml_read_node_entry_t(Common::SeekableReadStream *fh, node_entry_t* save_struc, const char *lastval, int *line, int *hiteof) -{ -#line 542 "engines/sci/engine/savegame.cfsml" - char *token; - int assignment, closed; - - if (strcmp(lastval, "{")) { - _cfsml_error("Reading record node_entry_t; expected opening braces in line %d, got \"%s\"\n", *line, lastval); - return CFSML_FAILURE; - }; - closed = 0; - do { - const char *value; - token = _cfsml_get_identifier(fh, line, hiteof, &assignment); - - if (!token) { - _cfsml_error("Expected token at line %d\n", *line); - return CFSML_FAILURE; - } - if (!assignment) { - if (!strcmp(token, "}")) - closed = 1; - else { - _cfsml_error("Expected assignment or closing braces in line %d\n", *line); - return CFSML_FAILURE; - } - } else { - value = ""; - while (!value || !strcmp(value, "")) - value = _cfsml_get_value(fh, line, hiteof); - if (!value) { - _cfsml_error("Expected token at line %d\n", *line); - return CFSML_FAILURE; - } - if (!strcmp(token, "next_free")) { -#line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_int(fh, (int*) &(save_struc->next_free), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_int() for next_free at line %d\n", *line); - return CFSML_FAILURE; - } - } else - if (!strcmp(token, "entry")) { -#line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_node_t(fh, (node_t*) &(save_struc->entry), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_node_t() for entry at line %d\n", *line); - return CFSML_FAILURE; - } - } else -#line 700 "engines/sci/engine/savegame.cfsml" - { - _cfsml_error("node_entry_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); - return CFSML_FAILURE; - } - } - } while (!closed); // Until closing braces are hit - return CFSML_SUCCESS; -} - -#line 396 "engines/sci/engine/savegame.cfsml" -static void -_cfsml_write_seg_id_t(Common::WriteStream *fh, seg_id_t const * save_struc) +_cfsml_write_bool(Common::WriteStream *fh, bool const * save_struc) { WSprintf(fh, "%li", (long)*save_struc); } #line 487 "engines/sci/engine/savegame.cfsml" static int -_cfsml_read_seg_id_t(Common::SeekableReadStream *fh, seg_id_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_bool(Common::SeekableReadStream *fh, bool* save_struc, const char *lastval, int *line, int *hiteof) { #line 507 "engines/sci/engine/savegame.cfsml" char *token; @@ -1784,25 +1669,31 @@ _cfsml_read_seg_id_t(Common::SeekableReadStream *fh, seg_id_t* save_struc, const #line 396 "engines/sci/engine/savegame.cfsml" static void -_cfsml_write_dynmem_t(Common::WriteStream *fh, dynmem_t const * save_struc) +_cfsml_write_NodeTable(Common::WriteStream *fh, NodeTable const * save_struc) { #line 413 "engines/sci/engine/savegame.cfsml" WSprintf(fh, "{\n"); - WSprintf(fh, "size = "); - _cfsml_write_int(fh, (int const *) &(save_struc->size)); + WSprintf(fh, "entries_nr = "); + _cfsml_write_int(fh, (int const *) &(save_struc->entries_nr)); WSprintf(fh, "\n"); - WSprintf(fh, "description = "); - _cfsml_write_string(fh, (const char * const *) &(save_struc->description)); + WSprintf(fh, "first_free = "); + _cfsml_write_int(fh, (int const *) &(save_struc->first_free)); WSprintf(fh, "\n"); - WSprintf(fh, "buf = "); + WSprintf(fh, "entries_used = "); + _cfsml_write_int(fh, (int const *) &(save_struc->entries_used)); + WSprintf(fh, "\n"); + WSprintf(fh, "max_entry = "); + _cfsml_write_int(fh, (int const *) &(save_struc->max_entry)); + WSprintf(fh, "\n"); + WSprintf(fh, "table = "); int min, max; - min = max = save_struc->size; - if (!save_struc->buf) + min = max = save_struc->entries_nr; + if (!save_struc->table) min = max = 0; /* Don't write if it points to NULL */ #line 440 "engines/sci/engine/savegame.cfsml" WSprintf(fh, "[%d][\n", max); for (int i = 0; i < min; i++) { - _cfsml_write_byte(fh, &(save_struc->buf[i])); + _cfsml_write_NodeEntry(fh, &(save_struc->table[i])); WSprintf(fh, "\n"); } WSprintf(fh, "]"); @@ -1812,14 +1703,14 @@ _cfsml_write_dynmem_t(Common::WriteStream *fh, dynmem_t const * save_struc) #line 487 "engines/sci/engine/savegame.cfsml" static int -_cfsml_read_dynmem_t(Common::SeekableReadStream *fh, dynmem_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_NodeTable(Common::SeekableReadStream *fh, NodeTable* save_struc, const char *lastval, int *line, int *hiteof) { #line 542 "engines/sci/engine/savegame.cfsml" char *token; int assignment, closed; if (strcmp(lastval, "{")) { - _cfsml_error("Reading record dynmem_t; expected opening braces in line %d, got \"%s\"\n", *line, lastval); + _cfsml_error("Reading record NodeTable; expected opening braces in line %d, got \"%s\"\n", *line, lastval); return CFSML_FAILURE; }; closed = 0; @@ -1846,25 +1737,39 @@ _cfsml_read_dynmem_t(Common::SeekableReadStream *fh, dynmem_t* save_struc, const _cfsml_error("Expected token at line %d\n", *line); return CFSML_FAILURE; } - if (!strcmp(token, "size")) { + if (!strcmp(token, "entries_nr")) { #line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_int(fh, (int*) &(save_struc->size), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_int() for size at line %d\n", *line); + if (_cfsml_read_int(fh, (int*) &(save_struc->entries_nr), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for entries_nr at line %d\n", *line); return CFSML_FAILURE; } } else - if (!strcmp(token, "description")) { + if (!strcmp(token, "first_free")) { #line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_string(fh, (char **) &(save_struc->description), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_string() for description at line %d\n", *line); + if (_cfsml_read_int(fh, (int*) &(save_struc->first_free), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for first_free at line %d\n", *line); return CFSML_FAILURE; } } else - if (!strcmp(token, "buf")) { -#line 605 "engines/sci/engine/savegame.cfsml" - if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { - _cfsml_error("Opening brackets expected at line %d\n", *line); - return CFSML_FAILURE; + if (!strcmp(token, "entries_used")) { +#line 691 "engines/sci/engine/savegame.cfsml" + if (_cfsml_read_int(fh, (int*) &(save_struc->entries_used), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for entries_used at line %d\n", *line); + return CFSML_FAILURE; + } + } else + if (!strcmp(token, "max_entry")) { +#line 691 "engines/sci/engine/savegame.cfsml" + if (_cfsml_read_int(fh, (int*) &(save_struc->max_entry), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for max_entry at line %d\n", *line); + return CFSML_FAILURE; + } + } else + if (!strcmp(token, "table")) { +#line 605 "engines/sci/engine/savegame.cfsml" + if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { + _cfsml_error("Opening brackets expected at line %d\n", *line); + return CFSML_FAILURE; } int max,done,i; #line 616 "engines/sci/engine/savegame.cfsml" @@ -1876,13 +1781,13 @@ _cfsml_read_dynmem_t(Common::SeekableReadStream *fh, dynmem_t* save_struc, const } if (max) { - save_struc->buf = (byte *)sci_malloc(max * sizeof(byte)); + save_struc->table = (NodeEntry *)sci_malloc(max * sizeof(NodeEntry)); #ifdef SATISFY_PURIFY - memset(save_struc->buf, 0, max * sizeof(byte)); + memset(save_struc->table, 0, max * sizeof(NodeEntry)); #endif - _cfsml_register_pointer(save_struc->buf); + _cfsml_register_pointer(save_struc->table); } else - save_struc->buf = NULL; + save_struc->table = NULL; #line 640 "engines/sci/engine/savegame.cfsml" done = i = 0; do { @@ -1896,18 +1801,18 @@ _cfsml_read_dynmem_t(Common::SeekableReadStream *fh, dynmem_t* save_struc, const _cfsml_error("More elements than space available (%d) in '%s' at line %d\n", max, token, *line); return CFSML_FAILURE; } - if (_cfsml_read_byte(fh, &(save_struc->buf[i++]), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_byte() for buf[i++] at line %d\n", *line); + if (_cfsml_read_NodeEntry(fh, &(save_struc->table[i++]), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_NodeEntry() for table[i++] at line %d\n", *line); return CFSML_FAILURE; } } else done = 1; } while (!done); - save_struc->size = max ; // Set array size accordingly + save_struc->entries_nr = max ; // Set array size accordingly } else #line 700 "engines/sci/engine/savegame.cfsml" { - _cfsml_error("dynmem_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); + _cfsml_error("NodeTable: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; } } @@ -1917,42 +1822,32 @@ _cfsml_read_dynmem_t(Common::SeekableReadStream *fh, dynmem_t* save_struc, const #line 396 "engines/sci/engine/savegame.cfsml" static void -_cfsml_write_local_variables_t(Common::WriteStream *fh, local_variables_t const * save_struc) +_cfsml_write_SystemString(Common::WriteStream *fh, SystemString const * save_struc) { #line 413 "engines/sci/engine/savegame.cfsml" WSprintf(fh, "{\n"); - WSprintf(fh, "script_id = "); - _cfsml_write_int(fh, (int const *) &(save_struc->script_id)); + WSprintf(fh, "name = "); + _cfsml_write_string(fh, (const char * const *) &(save_struc->name)); WSprintf(fh, "\n"); - WSprintf(fh, "nr = "); - _cfsml_write_int(fh, (int const *) &(save_struc->nr)); + WSprintf(fh, "max_size = "); + _cfsml_write_int(fh, (int const *) &(save_struc->max_size)); WSprintf(fh, "\n"); - WSprintf(fh, "locals = "); - int min, max; - min = max = save_struc->nr; - if (!save_struc->locals) - min = max = 0; /* Don't write if it points to NULL */ -#line 440 "engines/sci/engine/savegame.cfsml" - WSprintf(fh, "[%d][\n", max); - for (int i = 0; i < min; i++) { - write_reg_t(fh, &(save_struc->locals[i])); - WSprintf(fh, "\n"); - } - WSprintf(fh, "]"); + WSprintf(fh, "value = "); + _cfsml_write_string(fh, (const char * const *) &(save_struc->value)); WSprintf(fh, "\n"); WSprintf(fh, "}"); } #line 487 "engines/sci/engine/savegame.cfsml" static int -_cfsml_read_local_variables_t(Common::SeekableReadStream *fh, local_variables_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_SystemString(Common::SeekableReadStream *fh, SystemString* save_struc, const char *lastval, int *line, int *hiteof) { #line 542 "engines/sci/engine/savegame.cfsml" char *token; int assignment, closed; if (strcmp(lastval, "{")) { - _cfsml_error("Reading record local_variables_t; expected opening braces in line %d, got \"%s\"\n", *line, lastval); + _cfsml_error("Reading record SystemString; expected opening braces in line %d, got \"%s\"\n", *line, lastval); return CFSML_FAILURE; }; closed = 0; @@ -1979,68 +1874,30 @@ _cfsml_read_local_variables_t(Common::SeekableReadStream *fh, local_variables_t* _cfsml_error("Expected token at line %d\n", *line); return CFSML_FAILURE; } - if (!strcmp(token, "script_id")) { + if (!strcmp(token, "name")) { #line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_int(fh, (int*) &(save_struc->script_id), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_int() for script_id at line %d\n", *line); + if (_cfsml_read_string(fh, (char **) &(save_struc->name), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_string() for name at line %d\n", *line); return CFSML_FAILURE; } } else - if (!strcmp(token, "nr")) { + if (!strcmp(token, "max_size")) { #line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_int(fh, (int*) &(save_struc->nr), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_int() for nr at line %d\n", *line); + if (_cfsml_read_int(fh, (int*) &(save_struc->max_size), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for max_size at line %d\n", *line); return CFSML_FAILURE; } } else - if (!strcmp(token, "locals")) { -#line 605 "engines/sci/engine/savegame.cfsml" - if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { - _cfsml_error("Opening brackets expected at line %d\n", *line); - return CFSML_FAILURE; - } - int max,done,i; -#line 616 "engines/sci/engine/savegame.cfsml" - // Prepare to restore dynamic array - max = strtol(value + 1, NULL, 0); - if (max < 0) { - _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line); - return CFSML_FAILURE; - } - - if (max) { - save_struc->locals = (reg_t *)sci_malloc(max * sizeof(reg_t)); -#ifdef SATISFY_PURIFY - memset(save_struc->locals, 0, max * sizeof(reg_t)); -#endif - _cfsml_register_pointer(save_struc->locals); - } else - save_struc->locals = NULL; -#line 640 "engines/sci/engine/savegame.cfsml" - done = i = 0; - do { - if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) { -#line 648 "engines/sci/engine/savegame.cfsml" - _cfsml_error("Token expected at line %d\n", *line); - return 1; - } - if (strcmp(value, "]")) { - if (i == max) { - _cfsml_error("More elements than space available (%d) in '%s' at line %d\n", max, token, *line); - return CFSML_FAILURE; - } - if (read_reg_t(fh, &(save_struc->locals[i++]), value, line, hiteof)) { - _cfsml_error("Token expected by read_reg_t() for locals[i++] at line %d\n", *line); + if (!strcmp(token, "value")) { +#line 691 "engines/sci/engine/savegame.cfsml" + if (_cfsml_read_string(fh, (char **) &(save_struc->value), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_string() for value at line %d\n", *line); return CFSML_FAILURE; } } else - done = 1; - } while (!done); - save_struc->nr = max ; // Set array size accordingly - } else #line 700 "engines/sci/engine/savegame.cfsml" { - _cfsml_error("local_variables_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); + _cfsml_error("SystemString: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; } } @@ -2050,14 +1907,14 @@ _cfsml_read_local_variables_t(Common::SeekableReadStream *fh, local_variables_t* #line 396 "engines/sci/engine/savegame.cfsml" static void -_cfsml_write_bool(Common::WriteStream *fh, bool const * save_struc) +_cfsml_write_byte(Common::WriteStream *fh, byte const * save_struc) { WSprintf(fh, "%li", (long)*save_struc); } #line 487 "engines/sci/engine/savegame.cfsml" static int -_cfsml_read_bool(Common::SeekableReadStream *fh, bool* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_byte(Common::SeekableReadStream *fh, byte* save_struc, const char *lastval, int *line, int *hiteof) { #line 507 "engines/sci/engine/savegame.cfsml" char *token; @@ -2076,7 +1933,7 @@ _cfsml_read_bool(Common::SeekableReadStream *fh, bool* save_struc, const char *l #line 396 "engines/sci/engine/savegame.cfsml" static void -_cfsml_write_node_table_t(Common::WriteStream *fh, node_table_t const * save_struc) +_cfsml_write_ListTable(Common::WriteStream *fh, ListTable const * save_struc) { #line 413 "engines/sci/engine/savegame.cfsml" WSprintf(fh, "{\n"); @@ -2100,7 +1957,7 @@ _cfsml_write_node_table_t(Common::WriteStream *fh, node_table_t const * save_str #line 440 "engines/sci/engine/savegame.cfsml" WSprintf(fh, "[%d][\n", max); for (int i = 0; i < min; i++) { - _cfsml_write_node_entry_t(fh, &(save_struc->table[i])); + _cfsml_write_ListEntry(fh, &(save_struc->table[i])); WSprintf(fh, "\n"); } WSprintf(fh, "]"); @@ -2110,14 +1967,14 @@ _cfsml_write_node_table_t(Common::WriteStream *fh, node_table_t const * save_str #line 487 "engines/sci/engine/savegame.cfsml" static int -_cfsml_read_node_table_t(Common::SeekableReadStream *fh, node_table_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_ListTable(Common::SeekableReadStream *fh, ListTable* save_struc, const char *lastval, int *line, int *hiteof) { #line 542 "engines/sci/engine/savegame.cfsml" char *token; int assignment, closed; if (strcmp(lastval, "{")) { - _cfsml_error("Reading record node_table_t; expected opening braces in line %d, got \"%s\"\n", *line, lastval); + _cfsml_error("Reading record ListTable; expected opening braces in line %d, got \"%s\"\n", *line, lastval); return CFSML_FAILURE; }; closed = 0; @@ -2188,9 +2045,9 @@ _cfsml_read_node_table_t(Common::SeekableReadStream *fh, node_table_t* save_stru } if (max) { - save_struc->table = (node_entry_t *)sci_malloc(max * sizeof(node_entry_t)); + save_struc->table = (ListEntry *)sci_malloc(max * sizeof(ListEntry)); #ifdef SATISFY_PURIFY - memset(save_struc->table, 0, max * sizeof(node_entry_t)); + memset(save_struc->table, 0, max * sizeof(ListEntry)); #endif _cfsml_register_pointer(save_struc->table); } else @@ -2208,8 +2065,8 @@ _cfsml_read_node_table_t(Common::SeekableReadStream *fh, node_table_t* save_stru _cfsml_error("More elements than space available (%d) in '%s' at line %d\n", max, token, *line); return CFSML_FAILURE; } - if (_cfsml_read_node_entry_t(fh, &(save_struc->table[i++]), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_node_entry_t() for table[i++] at line %d\n", *line); + if (_cfsml_read_ListEntry(fh, &(save_struc->table[i++]), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_ListEntry() for table[i++] at line %d\n", *line); return CFSML_FAILURE; } } else @@ -2219,7 +2076,7 @@ _cfsml_read_node_table_t(Common::SeekableReadStream *fh, node_table_t* save_stru } else #line 700 "engines/sci/engine/savegame.cfsml" { - _cfsml_error("node_table_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); + _cfsml_error("ListTable: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; } } @@ -2229,146 +2086,29 @@ _cfsml_read_node_table_t(Common::SeekableReadStream *fh, node_table_t* save_stru #line 396 "engines/sci/engine/savegame.cfsml" static void -_cfsml_write_SystemString(Common::WriteStream *fh, SystemString const * save_struc) +_cfsml_write_Class(Common::WriteStream *fh, Class const * save_struc) { #line 413 "engines/sci/engine/savegame.cfsml" WSprintf(fh, "{\n"); - WSprintf(fh, "name = "); - _cfsml_write_string(fh, (const char * const *) &(save_struc->name)); - WSprintf(fh, "\n"); - WSprintf(fh, "max_size = "); - _cfsml_write_int(fh, (int const *) &(save_struc->max_size)); - WSprintf(fh, "\n"); - WSprintf(fh, "value = "); - _cfsml_write_string(fh, (const char * const *) &(save_struc->value)); - WSprintf(fh, "\n"); - WSprintf(fh, "}"); -} - -#line 487 "engines/sci/engine/savegame.cfsml" -static int -_cfsml_read_SystemString(Common::SeekableReadStream *fh, SystemString* save_struc, const char *lastval, int *line, int *hiteof) -{ -#line 542 "engines/sci/engine/savegame.cfsml" - char *token; - int assignment, closed; - - if (strcmp(lastval, "{")) { - _cfsml_error("Reading record SystemString; expected opening braces in line %d, got \"%s\"\n", *line, lastval); - return CFSML_FAILURE; - }; - closed = 0; - do { - const char *value; - token = _cfsml_get_identifier(fh, line, hiteof, &assignment); - - if (!token) { - _cfsml_error("Expected token at line %d\n", *line); - return CFSML_FAILURE; - } - if (!assignment) { - if (!strcmp(token, "}")) - closed = 1; - else { - _cfsml_error("Expected assignment or closing braces in line %d\n", *line); - return CFSML_FAILURE; - } - } else { - value = ""; - while (!value || !strcmp(value, "")) - value = _cfsml_get_value(fh, line, hiteof); - if (!value) { - _cfsml_error("Expected token at line %d\n", *line); - return CFSML_FAILURE; - } - if (!strcmp(token, "name")) { -#line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_string(fh, (char **) &(save_struc->name), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_string() for name at line %d\n", *line); - return CFSML_FAILURE; - } - } else - if (!strcmp(token, "max_size")) { -#line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_int(fh, (int*) &(save_struc->max_size), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_int() for max_size at line %d\n", *line); - return CFSML_FAILURE; - } - } else - if (!strcmp(token, "value")) { -#line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_string(fh, (char **) &(save_struc->value), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_string() for value at line %d\n", *line); - return CFSML_FAILURE; - } - } else -#line 700 "engines/sci/engine/savegame.cfsml" - { - _cfsml_error("SystemString: Assignment to invalid identifier '%s' in line %d\n", token, *line); - return CFSML_FAILURE; - } - } - } while (!closed); // Until closing braces are hit - return CFSML_SUCCESS; -} - -#line 396 "engines/sci/engine/savegame.cfsml" -static void -_cfsml_write_byte(Common::WriteStream *fh, byte const * save_struc) -{ - WSprintf(fh, "%li", (long)*save_struc); -} - -#line 487 "engines/sci/engine/savegame.cfsml" -static int -_cfsml_read_byte(Common::SeekableReadStream *fh, byte* save_struc, const char *lastval, int *line, int *hiteof) -{ -#line 507 "engines/sci/engine/savegame.cfsml" - char *token; - - *save_struc = strtol(lastval, &token, 0); - if ((*save_struc == 0) && (token == lastval)) { - _cfsml_error("strtol failed at line %d\n", *line); - return CFSML_FAILURE; - } - if (*token != 0) { - _cfsml_error("Non-integer encountered while parsing int value at line %d\n", *line); - return CFSML_FAILURE; - } - return CFSML_SUCCESS; -} - -#line 396 "engines/sci/engine/savegame.cfsml" -static void -_cfsml_write_node_t(Common::WriteStream *fh, node_t const * save_struc) -{ -#line 413 "engines/sci/engine/savegame.cfsml" - WSprintf(fh, "{\n"); - WSprintf(fh, "pred = "); - write_reg_t(fh, (reg_t const *) &(save_struc->pred)); - WSprintf(fh, "\n"); - WSprintf(fh, "succ = "); - write_reg_t(fh, (reg_t const *) &(save_struc->succ)); - WSprintf(fh, "\n"); - WSprintf(fh, "key = "); - write_reg_t(fh, (reg_t const *) &(save_struc->key)); + WSprintf(fh, "script = "); + _cfsml_write_int(fh, (int const *) &(save_struc->script)); WSprintf(fh, "\n"); - WSprintf(fh, "value = "); - write_reg_t(fh, (reg_t const *) &(save_struc->value)); + WSprintf(fh, "reg = "); + write_reg_t(fh, (reg_t const *) &(save_struc->reg)); WSprintf(fh, "\n"); WSprintf(fh, "}"); } #line 487 "engines/sci/engine/savegame.cfsml" static int -_cfsml_read_node_t(Common::SeekableReadStream *fh, node_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_Class(Common::SeekableReadStream *fh, Class* save_struc, const char *lastval, int *line, int *hiteof) { #line 542 "engines/sci/engine/savegame.cfsml" char *token; int assignment, closed; if (strcmp(lastval, "{")) { - _cfsml_error("Reading record node_t; expected opening braces in line %d, got \"%s\"\n", *line, lastval); + _cfsml_error("Reading record Class; expected opening braces in line %d, got \"%s\"\n", *line, lastval); return CFSML_FAILURE; }; closed = 0; @@ -2395,37 +2135,23 @@ _cfsml_read_node_t(Common::SeekableReadStream *fh, node_t* save_struc, const cha _cfsml_error("Expected token at line %d\n", *line); return CFSML_FAILURE; } - if (!strcmp(token, "pred")) { -#line 691 "engines/sci/engine/savegame.cfsml" - if (read_reg_t(fh, (reg_t*) &(save_struc->pred), value, line, hiteof)) { - _cfsml_error("Token expected by read_reg_t() for pred at line %d\n", *line); - return CFSML_FAILURE; - } - } else - if (!strcmp(token, "succ")) { -#line 691 "engines/sci/engine/savegame.cfsml" - if (read_reg_t(fh, (reg_t*) &(save_struc->succ), value, line, hiteof)) { - _cfsml_error("Token expected by read_reg_t() for succ at line %d\n", *line); - return CFSML_FAILURE; - } - } else - if (!strcmp(token, "key")) { + if (!strcmp(token, "script")) { #line 691 "engines/sci/engine/savegame.cfsml" - if (read_reg_t(fh, (reg_t*) &(save_struc->key), value, line, hiteof)) { - _cfsml_error("Token expected by read_reg_t() for key at line %d\n", *line); + if (_cfsml_read_int(fh, (int*) &(save_struc->script), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for script at line %d\n", *line); return CFSML_FAILURE; } } else - if (!strcmp(token, "value")) { + if (!strcmp(token, "reg")) { #line 691 "engines/sci/engine/savegame.cfsml" - if (read_reg_t(fh, (reg_t*) &(save_struc->value), value, line, hiteof)) { - _cfsml_error("Token expected by read_reg_t() for value at line %d\n", *line); + if (read_reg_t(fh, (reg_t*) &(save_struc->reg), value, line, hiteof)) { + _cfsml_error("Token expected by read_reg_t() for reg at line %d\n", *line); return CFSML_FAILURE; } } else #line 700 "engines/sci/engine/savegame.cfsml" { - _cfsml_error("node_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); + _cfsml_error("Class: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; } } @@ -2531,48 +2257,55 @@ _cfsml_read_SystemStrings(Common::SeekableReadStream *fh, SystemStrings* save_st #line 396 "engines/sci/engine/savegame.cfsml" static void -_cfsml_write_list_table_t(Common::WriteStream *fh, list_table_t const * save_struc) +_cfsml_write_song_handle_t(Common::WriteStream *fh, song_handle_t const * save_struc) +{ + WSprintf(fh, "%li", (long)*save_struc); +} + +#line 487 "engines/sci/engine/savegame.cfsml" +static int +_cfsml_read_song_handle_t(Common::SeekableReadStream *fh, song_handle_t* save_struc, const char *lastval, int *line, int *hiteof) +{ +#line 507 "engines/sci/engine/savegame.cfsml" + char *token; + + *save_struc = strtol(lastval, &token, 0); + if ((*save_struc == 0) && (token == lastval)) { + _cfsml_error("strtol failed at line %d\n", *line); + return CFSML_FAILURE; + } + if (*token != 0) { + _cfsml_error("Non-integer encountered while parsing int value at line %d\n", *line); + return CFSML_FAILURE; + } + return CFSML_SUCCESS; +} + +#line 396 "engines/sci/engine/savegame.cfsml" +static void +_cfsml_write_List(Common::WriteStream *fh, List const * save_struc) { #line 413 "engines/sci/engine/savegame.cfsml" WSprintf(fh, "{\n"); - WSprintf(fh, "entries_nr = "); - _cfsml_write_int(fh, (int const *) &(save_struc->entries_nr)); - WSprintf(fh, "\n"); - WSprintf(fh, "first_free = "); - _cfsml_write_int(fh, (int const *) &(save_struc->first_free)); - WSprintf(fh, "\n"); - WSprintf(fh, "entries_used = "); - _cfsml_write_int(fh, (int const *) &(save_struc->entries_used)); - WSprintf(fh, "\n"); - WSprintf(fh, "max_entry = "); - _cfsml_write_int(fh, (int const *) &(save_struc->max_entry)); + WSprintf(fh, "first = "); + write_reg_t(fh, (reg_t const *) &(save_struc->first)); WSprintf(fh, "\n"); - WSprintf(fh, "table = "); - int min, max; - min = max = save_struc->entries_nr; - if (!save_struc->table) - min = max = 0; /* Don't write if it points to NULL */ -#line 440 "engines/sci/engine/savegame.cfsml" - WSprintf(fh, "[%d][\n", max); - for (int i = 0; i < min; i++) { - _cfsml_write_list_entry_t(fh, &(save_struc->table[i])); - WSprintf(fh, "\n"); - } - WSprintf(fh, "]"); + WSprintf(fh, "last = "); + write_reg_t(fh, (reg_t const *) &(save_struc->last)); WSprintf(fh, "\n"); WSprintf(fh, "}"); } #line 487 "engines/sci/engine/savegame.cfsml" static int -_cfsml_read_list_table_t(Common::SeekableReadStream *fh, list_table_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_List(Common::SeekableReadStream *fh, List* save_struc, const char *lastval, int *line, int *hiteof) { #line 542 "engines/sci/engine/savegame.cfsml" char *token; int assignment, closed; if (strcmp(lastval, "{")) { - _cfsml_error("Reading record list_table_t; expected opening braces in line %d, got \"%s\"\n", *line, lastval); + _cfsml_error("Reading record List; expected opening braces in line %d, got \"%s\"\n", *line, lastval); return CFSML_FAILURE; }; closed = 0; @@ -2596,85 +2329,26 @@ _cfsml_read_list_table_t(Common::SeekableReadStream *fh, list_table_t* save_stru while (!value || !strcmp(value, "")) value = _cfsml_get_value(fh, line, hiteof); if (!value) { - _cfsml_error("Expected token at line %d\n", *line); - return CFSML_FAILURE; - } - if (!strcmp(token, "entries_nr")) { -#line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_int(fh, (int*) &(save_struc->entries_nr), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_int() for entries_nr at line %d\n", *line); - return CFSML_FAILURE; - } - } else - if (!strcmp(token, "first_free")) { -#line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_int(fh, (int*) &(save_struc->first_free), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_int() for first_free at line %d\n", *line); - return CFSML_FAILURE; - } - } else - if (!strcmp(token, "entries_used")) { -#line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_int(fh, (int*) &(save_struc->entries_used), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_int() for entries_used at line %d\n", *line); - return CFSML_FAILURE; - } - } else - if (!strcmp(token, "max_entry")) { -#line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_int(fh, (int*) &(save_struc->max_entry), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_int() for max_entry at line %d\n", *line); - return CFSML_FAILURE; - } - } else - if (!strcmp(token, "table")) { -#line 605 "engines/sci/engine/savegame.cfsml" - if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { - _cfsml_error("Opening brackets expected at line %d\n", *line); - return CFSML_FAILURE; - } - int max,done,i; -#line 616 "engines/sci/engine/savegame.cfsml" - // Prepare to restore dynamic array - max = strtol(value + 1, NULL, 0); - if (max < 0) { - _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line); - return CFSML_FAILURE; - } - - if (max) { - save_struc->table = (list_entry_t *)sci_malloc(max * sizeof(list_entry_t)); -#ifdef SATISFY_PURIFY - memset(save_struc->table, 0, max * sizeof(list_entry_t)); -#endif - _cfsml_register_pointer(save_struc->table); - } else - save_struc->table = NULL; -#line 640 "engines/sci/engine/savegame.cfsml" - done = i = 0; - do { - if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) { -#line 648 "engines/sci/engine/savegame.cfsml" - _cfsml_error("Token expected at line %d\n", *line); - return 1; + _cfsml_error("Expected token at line %d\n", *line); + return CFSML_FAILURE; } - if (strcmp(value, "]")) { - if (i == max) { - _cfsml_error("More elements than space available (%d) in '%s' at line %d\n", max, token, *line); + if (!strcmp(token, "first")) { +#line 691 "engines/sci/engine/savegame.cfsml" + if (read_reg_t(fh, (reg_t*) &(save_struc->first), value, line, hiteof)) { + _cfsml_error("Token expected by read_reg_t() for first at line %d\n", *line); return CFSML_FAILURE; } - if (_cfsml_read_list_entry_t(fh, &(save_struc->table[i++]), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_list_entry_t() for table[i++] at line %d\n", *line); + } else + if (!strcmp(token, "last")) { +#line 691 "engines/sci/engine/savegame.cfsml" + if (read_reg_t(fh, (reg_t*) &(save_struc->last), value, line, hiteof)) { + _cfsml_error("Token expected by read_reg_t() for last at line %d\n", *line); return CFSML_FAILURE; } } else - done = 1; - } while (!done); - save_struc->entries_nr = max ; // Set array size accordingly - } else #line 700 "engines/sci/engine/savegame.cfsml" { - _cfsml_error("list_table_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); + _cfsml_error("List: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; } } @@ -2684,29 +2358,29 @@ _cfsml_read_list_table_t(Common::SeekableReadStream *fh, list_table_t* save_stru #line 396 "engines/sci/engine/savegame.cfsml" static void -_cfsml_write_class_t(Common::WriteStream *fh, class_t const * save_struc) +_cfsml_write_NodeEntry(Common::WriteStream *fh, NodeEntry const * save_struc) { #line 413 "engines/sci/engine/savegame.cfsml" WSprintf(fh, "{\n"); - WSprintf(fh, "script = "); - _cfsml_write_int(fh, (int const *) &(save_struc->script)); + WSprintf(fh, "next_free = "); + _cfsml_write_int(fh, (int const *) &(save_struc->next_free)); WSprintf(fh, "\n"); - WSprintf(fh, "reg = "); - write_reg_t(fh, (reg_t const *) &(save_struc->reg)); + WSprintf(fh, "entry = "); + _cfsml_write_Node(fh, (Node const *) &(save_struc->entry)); WSprintf(fh, "\n"); WSprintf(fh, "}"); } #line 487 "engines/sci/engine/savegame.cfsml" static int -_cfsml_read_class_t(Common::SeekableReadStream *fh, class_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_NodeEntry(Common::SeekableReadStream *fh, NodeEntry* save_struc, const char *lastval, int *line, int *hiteof) { #line 542 "engines/sci/engine/savegame.cfsml" char *token; int assignment, closed; if (strcmp(lastval, "{")) { - _cfsml_error("Reading record class_t; expected opening braces in line %d, got \"%s\"\n", *line, lastval); + _cfsml_error("Reading record NodeEntry; expected opening braces in line %d, got \"%s\"\n", *line, lastval); return CFSML_FAILURE; }; closed = 0; @@ -2733,23 +2407,23 @@ _cfsml_read_class_t(Common::SeekableReadStream *fh, class_t* save_struc, const c _cfsml_error("Expected token at line %d\n", *line); return CFSML_FAILURE; } - if (!strcmp(token, "script")) { + if (!strcmp(token, "next_free")) { #line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_int(fh, (int*) &(save_struc->script), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_int() for script at line %d\n", *line); + if (_cfsml_read_int(fh, (int*) &(save_struc->next_free), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for next_free at line %d\n", *line); return CFSML_FAILURE; } } else - if (!strcmp(token, "reg")) { + if (!strcmp(token, "entry")) { #line 691 "engines/sci/engine/savegame.cfsml" - if (read_reg_t(fh, (reg_t*) &(save_struc->reg), value, line, hiteof)) { - _cfsml_error("Token expected by read_reg_t() for reg at line %d\n", *line); + if (_cfsml_read_Node(fh, (Node*) &(save_struc->entry), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_Node() for entry at line %d\n", *line); return CFSML_FAILURE; } } else #line 700 "engines/sci/engine/savegame.cfsml" { - _cfsml_error("class_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); + _cfsml_error("NodeEntry: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; } } @@ -2757,32 +2431,6 @@ _cfsml_read_class_t(Common::SeekableReadStream *fh, class_t* save_struc, const c return CFSML_SUCCESS; } -#line 396 "engines/sci/engine/savegame.cfsml" -static void -_cfsml_write_song_handle_t(Common::WriteStream *fh, song_handle_t const * save_struc) -{ - WSprintf(fh, "%li", (long)*save_struc); -} - -#line 487 "engines/sci/engine/savegame.cfsml" -static int -_cfsml_read_song_handle_t(Common::SeekableReadStream *fh, song_handle_t* save_struc, const char *lastval, int *line, int *hiteof) -{ -#line 507 "engines/sci/engine/savegame.cfsml" - char *token; - - *save_struc = strtol(lastval, &token, 0); - if ((*save_struc == 0) && (token == lastval)) { - _cfsml_error("strtol failed at line %d\n", *line); - return CFSML_FAILURE; - } - if (*token != 0) { - _cfsml_error("Non-integer encountered while parsing int value at line %d\n", *line); - return CFSML_FAILURE; - } - return CFSML_SUCCESS; -} - #line 396 "engines/sci/engine/savegame.cfsml" static void _cfsml_write_int(Common::WriteStream *fh, int const * save_struc) @@ -2847,7 +2495,7 @@ _cfsml_write_EngineState(Common::WriteStream *fh, EngineState const * save_struc #line 440 "engines/sci/engine/savegame.cfsml" WSprintf(fh, "[%d][\n", max); for (int i = 0; i < min; i++) { - _cfsml_write_class_t(fh, &(save_struc->classtable[i])); + _cfsml_write_Class(fh, &(save_struc->classtable[i])); WSprintf(fh, "\n"); } WSprintf(fh, "]"); @@ -2966,9 +2614,9 @@ _cfsml_read_EngineState(Common::SeekableReadStream *fh, EngineState* save_struc, } if (max) { - save_struc->classtable = (class_t *)sci_malloc(max * sizeof(class_t)); + save_struc->classtable = (Class *)sci_malloc(max * sizeof(Class)); #ifdef SATISFY_PURIFY - memset(save_struc->classtable, 0, max * sizeof(class_t)); + memset(save_struc->classtable, 0, max * sizeof(Class)); #endif _cfsml_register_pointer(save_struc->classtable); } else @@ -2986,8 +2634,8 @@ _cfsml_read_EngineState(Common::SeekableReadStream *fh, EngineState* save_struc, _cfsml_error("More elements than space available (%d) in '%s' at line %d\n", max, token, *line); return CFSML_FAILURE; } - if (_cfsml_read_class_t(fh, &(save_struc->classtable[i++]), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_class_t() for classtable[i++] at line %d\n", *line); + if (_cfsml_read_Class(fh, &(save_struc->classtable[i++]), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_Class() for classtable[i++] at line %d\n", *line); return CFSML_FAILURE; } } else @@ -3012,6 +2660,81 @@ _cfsml_read_EngineState(Common::SeekableReadStream *fh, EngineState* save_struc, return CFSML_SUCCESS; } +#line 396 "engines/sci/engine/savegame.cfsml" +static void +_cfsml_write_CloneEntry(Common::WriteStream *fh, CloneEntry const * save_struc) +{ +#line 413 "engines/sci/engine/savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "next_free = "); + _cfsml_write_int(fh, (int const *) &(save_struc->next_free)); + WSprintf(fh, "\n"); + WSprintf(fh, "entry = "); + _cfsml_write_Clone(fh, (Clone const *) &(save_struc->entry)); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); +} + +#line 487 "engines/sci/engine/savegame.cfsml" +static int +_cfsml_read_CloneEntry(Common::SeekableReadStream *fh, CloneEntry* save_struc, const char *lastval, int *line, int *hiteof) +{ +#line 542 "engines/sci/engine/savegame.cfsml" + char *token; + int assignment, closed; + + if (strcmp(lastval, "{")) { + _cfsml_error("Reading record CloneEntry; expected opening braces in line %d, got \"%s\"\n", *line, lastval); + return CFSML_FAILURE; + }; + closed = 0; + do { + const char *value; + token = _cfsml_get_identifier(fh, line, hiteof, &assignment); + + if (!token) { + _cfsml_error("Expected token at line %d\n", *line); + return CFSML_FAILURE; + } + if (!assignment) { + if (!strcmp(token, "}")) + closed = 1; + else { + _cfsml_error("Expected assignment or closing braces in line %d\n", *line); + return CFSML_FAILURE; + } + } else { + value = ""; + while (!value || !strcmp(value, "")) + value = _cfsml_get_value(fh, line, hiteof); + if (!value) { + _cfsml_error("Expected token at line %d\n", *line); + return CFSML_FAILURE; + } + if (!strcmp(token, "next_free")) { +#line 691 "engines/sci/engine/savegame.cfsml" + if (_cfsml_read_int(fh, (int*) &(save_struc->next_free), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for next_free at line %d\n", *line); + return CFSML_FAILURE; + } + } else + if (!strcmp(token, "entry")) { +#line 691 "engines/sci/engine/savegame.cfsml" + if (_cfsml_read_Clone(fh, (Clone*) &(save_struc->entry), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_Clone() for entry at line %d\n", *line); + return CFSML_FAILURE; + } + } else +#line 700 "engines/sci/engine/savegame.cfsml" + { + _cfsml_error("CloneEntry: Assignment to invalid identifier '%s' in line %d\n", token, *line); + return CFSML_FAILURE; + } + } + } while (!closed); // Until closing braces are hit + return CFSML_SUCCESS; +} + #line 396 "engines/sci/engine/savegame.cfsml" static void _cfsml_write_SavegameMetadata(Common::WriteStream *fh, SavegameMetadata const * save_struc) @@ -3096,30 +2819,163 @@ _cfsml_read_SavegameMetadata(Common::SeekableReadStream *fh, SavegameMetadata* s return CFSML_FAILURE; } } else - if (!strcmp(token, "version")) { -#line 691 "engines/sci/engine/savegame.cfsml" - if (read_sci_version(fh, (sci_version_t*) &(save_struc->version), value, line, hiteof)) { - _cfsml_error("Token expected by read_sci_version() for version at line %d\n", *line); + if (!strcmp(token, "version")) { +#line 691 "engines/sci/engine/savegame.cfsml" + if (read_sci_version(fh, (sci_version_t*) &(save_struc->version), value, line, hiteof)) { + _cfsml_error("Token expected by read_sci_version() for version at line %d\n", *line); + return CFSML_FAILURE; + } + } else + if (!strcmp(token, "savegame_date")) { +#line 691 "engines/sci/engine/savegame.cfsml" + if (_cfsml_read_int(fh, (int*) &(save_struc->savegame_date), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for savegame_date at line %d\n", *line); + return CFSML_FAILURE; + } + } else + if (!strcmp(token, "savegame_time")) { +#line 691 "engines/sci/engine/savegame.cfsml" + if (_cfsml_read_int(fh, (int*) &(save_struc->savegame_time), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for savegame_time at line %d\n", *line); + return CFSML_FAILURE; + } + } else +#line 700 "engines/sci/engine/savegame.cfsml" + { + _cfsml_error("SavegameMetadata: Assignment to invalid identifier '%s' in line %d\n", token, *line); + return CFSML_FAILURE; + } + } + } while (!closed); // Until closing braces are hit + return CFSML_SUCCESS; +} + +#line 396 "engines/sci/engine/savegame.cfsml" +static void +_cfsml_write_LocalVariables(Common::WriteStream *fh, LocalVariables const * save_struc) +{ +#line 413 "engines/sci/engine/savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "script_id = "); + _cfsml_write_int(fh, (int const *) &(save_struc->script_id)); + WSprintf(fh, "\n"); + WSprintf(fh, "nr = "); + _cfsml_write_int(fh, (int const *) &(save_struc->nr)); + WSprintf(fh, "\n"); + WSprintf(fh, "locals = "); + int min, max; + min = max = save_struc->nr; + if (!save_struc->locals) + min = max = 0; /* Don't write if it points to NULL */ +#line 440 "engines/sci/engine/savegame.cfsml" + WSprintf(fh, "[%d][\n", max); + for (int i = 0; i < min; i++) { + write_reg_t(fh, &(save_struc->locals[i])); + WSprintf(fh, "\n"); + } + WSprintf(fh, "]"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); +} + +#line 487 "engines/sci/engine/savegame.cfsml" +static int +_cfsml_read_LocalVariables(Common::SeekableReadStream *fh, LocalVariables* save_struc, const char *lastval, int *line, int *hiteof) +{ +#line 542 "engines/sci/engine/savegame.cfsml" + char *token; + int assignment, closed; + + if (strcmp(lastval, "{")) { + _cfsml_error("Reading record LocalVariables; expected opening braces in line %d, got \"%s\"\n", *line, lastval); + return CFSML_FAILURE; + }; + closed = 0; + do { + const char *value; + token = _cfsml_get_identifier(fh, line, hiteof, &assignment); + + if (!token) { + _cfsml_error("Expected token at line %d\n", *line); + return CFSML_FAILURE; + } + if (!assignment) { + if (!strcmp(token, "}")) + closed = 1; + else { + _cfsml_error("Expected assignment or closing braces in line %d\n", *line); + return CFSML_FAILURE; + } + } else { + value = ""; + while (!value || !strcmp(value, "")) + value = _cfsml_get_value(fh, line, hiteof); + if (!value) { + _cfsml_error("Expected token at line %d\n", *line); + return CFSML_FAILURE; + } + if (!strcmp(token, "script_id")) { +#line 691 "engines/sci/engine/savegame.cfsml" + if (_cfsml_read_int(fh, (int*) &(save_struc->script_id), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for script_id at line %d\n", *line); + return CFSML_FAILURE; + } + } else + if (!strcmp(token, "nr")) { +#line 691 "engines/sci/engine/savegame.cfsml" + if (_cfsml_read_int(fh, (int*) &(save_struc->nr), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for nr at line %d\n", *line); + return CFSML_FAILURE; + } + } else + if (!strcmp(token, "locals")) { +#line 605 "engines/sci/engine/savegame.cfsml" + if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { + _cfsml_error("Opening brackets expected at line %d\n", *line); + return CFSML_FAILURE; + } + int max,done,i; +#line 616 "engines/sci/engine/savegame.cfsml" + // Prepare to restore dynamic array + max = strtol(value + 1, NULL, 0); + if (max < 0) { + _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line); + return CFSML_FAILURE; + } + + if (max) { + save_struc->locals = (reg_t *)sci_malloc(max * sizeof(reg_t)); +#ifdef SATISFY_PURIFY + memset(save_struc->locals, 0, max * sizeof(reg_t)); +#endif + _cfsml_register_pointer(save_struc->locals); + } else + save_struc->locals = NULL; +#line 640 "engines/sci/engine/savegame.cfsml" + done = i = 0; + do { + if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) { +#line 648 "engines/sci/engine/savegame.cfsml" + _cfsml_error("Token expected at line %d\n", *line); + return 1; + } + if (strcmp(value, "]")) { + if (i == max) { + _cfsml_error("More elements than space available (%d) in '%s' at line %d\n", max, token, *line); return CFSML_FAILURE; } - } else - if (!strcmp(token, "savegame_date")) { -#line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_int(fh, (int*) &(save_struc->savegame_date), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_int() for savegame_date at line %d\n", *line); + if (read_reg_t(fh, &(save_struc->locals[i++]), value, line, hiteof)) { + _cfsml_error("Token expected by read_reg_t() for locals[i++] at line %d\n", *line); return CFSML_FAILURE; } } else - if (!strcmp(token, "savegame_time")) { -#line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_int(fh, (int*) &(save_struc->savegame_time), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_int() for savegame_time at line %d\n", *line); - return CFSML_FAILURE; - } + done = 1; + } while (!done); + save_struc->nr = max ; // Set array size accordingly } else #line 700 "engines/sci/engine/savegame.cfsml" { - _cfsml_error("SavegameMetadata: Assignment to invalid identifier '%s' in line %d\n", token, *line); + _cfsml_error("LocalVariables: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; } } @@ -3378,31 +3234,34 @@ _cfsml_read_menu_t(Common::SeekableReadStream *fh, menu_t* save_struc, const cha #line 396 "engines/sci/engine/savegame.cfsml" static void -_cfsml_write_clone_table_t(Common::WriteStream *fh, clone_table_t const * save_struc) +_cfsml_write_Object(Common::WriteStream *fh, Object const * save_struc) { #line 413 "engines/sci/engine/savegame.cfsml" WSprintf(fh, "{\n"); - WSprintf(fh, "entries_nr = "); - _cfsml_write_int(fh, (int const *) &(save_struc->entries_nr)); + WSprintf(fh, "flags = "); + _cfsml_write_int(fh, (int const *) &(save_struc->flags)); WSprintf(fh, "\n"); - WSprintf(fh, "first_free = "); - _cfsml_write_int(fh, (int const *) &(save_struc->first_free)); + WSprintf(fh, "pos = "); + write_reg_t(fh, (reg_t const *) &(save_struc->pos)); WSprintf(fh, "\n"); - WSprintf(fh, "entries_used = "); - _cfsml_write_int(fh, (int const *) &(save_struc->entries_used)); + WSprintf(fh, "variables_nr = "); + _cfsml_write_int(fh, (int const *) &(save_struc->variables_nr)); WSprintf(fh, "\n"); - WSprintf(fh, "max_entry = "); - _cfsml_write_int(fh, (int const *) &(save_struc->max_entry)); + WSprintf(fh, "variable_names_nr = "); + _cfsml_write_int(fh, (int const *) &(save_struc->variable_names_nr)); WSprintf(fh, "\n"); - WSprintf(fh, "table = "); + WSprintf(fh, "methods_nr = "); + _cfsml_write_int(fh, (int const *) &(save_struc->methods_nr)); + WSprintf(fh, "\n"); + WSprintf(fh, "variables = "); int min, max; - min = max = save_struc->entries_nr; - if (!save_struc->table) + min = max = save_struc->variables_nr; + if (!save_struc->variables) min = max = 0; /* Don't write if it points to NULL */ #line 440 "engines/sci/engine/savegame.cfsml" WSprintf(fh, "[%d][\n", max); for (int i = 0; i < min; i++) { - _cfsml_write_clone_entry_t(fh, &(save_struc->table[i])); + write_reg_t(fh, &(save_struc->variables[i])); WSprintf(fh, "\n"); } WSprintf(fh, "]"); @@ -3412,14 +3271,14 @@ _cfsml_write_clone_table_t(Common::WriteStream *fh, clone_table_t const * save_s #line 487 "engines/sci/engine/savegame.cfsml" static int -_cfsml_read_clone_table_t(Common::SeekableReadStream *fh, clone_table_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_Object(Common::SeekableReadStream *fh, Object* save_struc, const char *lastval, int *line, int *hiteof) { #line 542 "engines/sci/engine/savegame.cfsml" char *token; int assignment, closed; if (strcmp(lastval, "{")) { - _cfsml_error("Reading record clone_table_t; expected opening braces in line %d, got \"%s\"\n", *line, lastval); + _cfsml_error("Reading record Object; expected opening braces in line %d, got \"%s\"\n", *line, lastval); return CFSML_FAILURE; }; closed = 0; @@ -3446,35 +3305,42 @@ _cfsml_read_clone_table_t(Common::SeekableReadStream *fh, clone_table_t* save_st _cfsml_error("Expected token at line %d\n", *line); return CFSML_FAILURE; } - if (!strcmp(token, "entries_nr")) { + if (!strcmp(token, "flags")) { #line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_int(fh, (int*) &(save_struc->entries_nr), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_int() for entries_nr at line %d\n", *line); + if (_cfsml_read_int(fh, (int*) &(save_struc->flags), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for flags at line %d\n", *line); return CFSML_FAILURE; } } else - if (!strcmp(token, "first_free")) { + if (!strcmp(token, "pos")) { #line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_int(fh, (int*) &(save_struc->first_free), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_int() for first_free at line %d\n", *line); + if (read_reg_t(fh, (reg_t*) &(save_struc->pos), value, line, hiteof)) { + _cfsml_error("Token expected by read_reg_t() for pos at line %d\n", *line); return CFSML_FAILURE; } } else - if (!strcmp(token, "entries_used")) { + if (!strcmp(token, "variables_nr")) { #line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_int(fh, (int*) &(save_struc->entries_used), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_int() for entries_used at line %d\n", *line); + if (_cfsml_read_int(fh, (int*) &(save_struc->variables_nr), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for variables_nr at line %d\n", *line); return CFSML_FAILURE; } } else - if (!strcmp(token, "max_entry")) { + if (!strcmp(token, "variable_names_nr")) { #line 691 "engines/sci/engine/savegame.cfsml" - if (_cfsml_read_int(fh, (int*) &(save_struc->max_entry), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_int() for max_entry at line %d\n", *line); + if (_cfsml_read_int(fh, (int*) &(save_struc->variable_names_nr), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for variable_names_nr at line %d\n", *line); return CFSML_FAILURE; } } else - if (!strcmp(token, "table")) { + if (!strcmp(token, "methods_nr")) { +#line 691 "engines/sci/engine/savegame.cfsml" + if (_cfsml_read_int(fh, (int*) &(save_struc->methods_nr), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for methods_nr at line %d\n", *line); + return CFSML_FAILURE; + } + } else + if (!strcmp(token, "variables")) { #line 605 "engines/sci/engine/savegame.cfsml" if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { _cfsml_error("Opening brackets expected at line %d\n", *line); @@ -3490,13 +3356,13 @@ _cfsml_read_clone_table_t(Common::SeekableReadStream *fh, clone_table_t* save_st } if (max) { - save_struc->table = (clone_entry_t *)sci_malloc(max * sizeof(clone_entry_t)); + save_struc->variables = (reg_t *)sci_malloc(max * sizeof(reg_t)); #ifdef SATISFY_PURIFY - memset(save_struc->table, 0, max * sizeof(clone_entry_t)); + memset(save_struc->variables, 0, max * sizeof(reg_t)); #endif - _cfsml_register_pointer(save_struc->table); + _cfsml_register_pointer(save_struc->variables); } else - save_struc->table = NULL; + save_struc->variables = NULL; #line 640 "engines/sci/engine/savegame.cfsml" done = i = 0; do { @@ -3510,18 +3376,18 @@ _cfsml_read_clone_table_t(Common::SeekableReadStream *fh, clone_table_t* save_st _cfsml_error("More elements than space available (%d) in '%s' at line %d\n", max, token, *line); return CFSML_FAILURE; } - if (_cfsml_read_clone_entry_t(fh, &(save_struc->table[i++]), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_clone_entry_t() for table[i++] at line %d\n", *line); + if (read_reg_t(fh, &(save_struc->variables[i++]), value, line, hiteof)) { + _cfsml_error("Token expected by read_reg_t() for variables[i++] at line %d\n", *line); return CFSML_FAILURE; } } else done = 1; } while (!done); - save_struc->entries_nr = max ; // Set array size accordingly + save_struc->variables_nr = max ; // Set array size accordingly } else #line 700 "engines/sci/engine/savegame.cfsml" { - _cfsml_error("clone_table_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); + _cfsml_error("Object: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; } } @@ -3531,29 +3397,29 @@ _cfsml_read_clone_table_t(Common::SeekableReadStream *fh, clone_table_t* save_st #line 396 "engines/sci/engine/savegame.cfsml" static void -_cfsml_write_list_t(Common::WriteStream *fh, list_t const * save_struc) +_cfsml_write_ListEntry(Common::WriteStream *fh, ListEntry const * save_struc) { #line 413 "engines/sci/engine/savegame.cfsml" WSprintf(fh, "{\n"); - WSprintf(fh, "first = "); - write_reg_t(fh, (reg_t const *) &(save_struc->first)); + WSprintf(fh, "next_free = "); + _cfsml_write_int(fh, (int const *) &(save_struc->next_free)); WSprintf(fh, "\n"); - WSprintf(fh, "last = "); - write_reg_t(fh, (reg_t const *) &(save_struc->last)); + WSprintf(fh, "entry = "); + _cfsml_write_List(fh, (List const *) &(save_struc->entry)); WSprintf(fh, "\n"); WSprintf(fh, "}"); } #line 487 "engines/sci/engine/savegame.cfsml" static int -_cfsml_read_list_t(Common::SeekableReadStream *fh, list_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_ListEntry(Common::SeekableReadStream *fh, ListEntry* save_struc, const char *lastval, int *line, int *hiteof) { #line 542 "engines/sci/engine/savegame.cfsml" char *token; int assignment, closed; if (strcmp(lastval, "{")) { - _cfsml_error("Reading record list_t; expected opening braces in line %d, got \"%s\"\n", *line, lastval); + _cfsml_error("Reading record ListEntry; expected opening braces in line %d, got \"%s\"\n", *line, lastval); return CFSML_FAILURE; }; closed = 0; @@ -3580,23 +3446,23 @@ _cfsml_read_list_t(Common::SeekableReadStream *fh, list_t* save_struc, const cha _cfsml_error("Expected token at line %d\n", *line); return CFSML_FAILURE; } - if (!strcmp(token, "first")) { + if (!strcmp(token, "next_free")) { #line 691 "engines/sci/engine/savegame.cfsml" - if (read_reg_t(fh, (reg_t*) &(save_struc->first), value, line, hiteof)) { - _cfsml_error("Token expected by read_reg_t() for first at line %d\n", *line); + if (_cfsml_read_int(fh, (int*) &(save_struc->next_free), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for next_free at line %d\n", *line); return CFSML_FAILURE; } } else - if (!strcmp(token, "last")) { + if (!strcmp(token, "entry")) { #line 691 "engines/sci/engine/savegame.cfsml" - if (read_reg_t(fh, (reg_t*) &(save_struc->last), value, line, hiteof)) { - _cfsml_error("Token expected by read_reg_t() for last at line %d\n", *line); + if (_cfsml_read_List(fh, (List*) &(save_struc->entry), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_List() for entry at line %d\n", *line); return CFSML_FAILURE; } } else #line 700 "engines/sci/engine/savegame.cfsml" { - _cfsml_error("list_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); + _cfsml_error("ListEntry: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; } } @@ -3606,7 +3472,7 @@ _cfsml_read_list_t(Common::SeekableReadStream *fh, list_t* save_struc, const cha #line 396 "engines/sci/engine/savegame.cfsml" static void -_cfsml_write_clone_t(Common::WriteStream *fh, clone_t const * save_struc) +_cfsml_write_Clone(Common::WriteStream *fh, Clone const * save_struc) { #line 413 "engines/sci/engine/savegame.cfsml" WSprintf(fh, "{\n"); @@ -3643,14 +3509,14 @@ _cfsml_write_clone_t(Common::WriteStream *fh, clone_t const * save_struc) #line 487 "engines/sci/engine/savegame.cfsml" static int -_cfsml_read_clone_t(Common::SeekableReadStream *fh, clone_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_Clone(Common::SeekableReadStream *fh, Clone* save_struc, const char *lastval, int *line, int *hiteof) { #line 542 "engines/sci/engine/savegame.cfsml" char *token; int assignment, closed; if (strcmp(lastval, "{")) { - _cfsml_error("Reading record clone_t; expected opening braces in line %d, got \"%s\"\n", *line, lastval); + _cfsml_error("Reading record Clone; expected opening braces in line %d, got \"%s\"\n", *line, lastval); return CFSML_FAILURE; }; closed = 0; @@ -3759,7 +3625,140 @@ _cfsml_read_clone_t(Common::SeekableReadStream *fh, clone_t* save_struc, const c } else #line 700 "engines/sci/engine/savegame.cfsml" { - _cfsml_error("clone_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); + _cfsml_error("Clone: Assignment to invalid identifier '%s' in line %d\n", token, *line); + return CFSML_FAILURE; + } + } + } while (!closed); // Until closing braces are hit + return CFSML_SUCCESS; +} + +#line 396 "engines/sci/engine/savegame.cfsml" +static void +_cfsml_write_DynMem(Common::WriteStream *fh, DynMem const * save_struc) +{ +#line 413 "engines/sci/engine/savegame.cfsml" + WSprintf(fh, "{\n"); + WSprintf(fh, "size = "); + _cfsml_write_int(fh, (int const *) &(save_struc->size)); + WSprintf(fh, "\n"); + WSprintf(fh, "description = "); + _cfsml_write_string(fh, (const char * const *) &(save_struc->description)); + WSprintf(fh, "\n"); + WSprintf(fh, "buf = "); + int min, max; + min = max = save_struc->size; + if (!save_struc->buf) + min = max = 0; /* Don't write if it points to NULL */ +#line 440 "engines/sci/engine/savegame.cfsml" + WSprintf(fh, "[%d][\n", max); + for (int i = 0; i < min; i++) { + _cfsml_write_byte(fh, &(save_struc->buf[i])); + WSprintf(fh, "\n"); + } + WSprintf(fh, "]"); + WSprintf(fh, "\n"); + WSprintf(fh, "}"); +} + +#line 487 "engines/sci/engine/savegame.cfsml" +static int +_cfsml_read_DynMem(Common::SeekableReadStream *fh, DynMem* save_struc, const char *lastval, int *line, int *hiteof) +{ +#line 542 "engines/sci/engine/savegame.cfsml" + char *token; + int assignment, closed; + + if (strcmp(lastval, "{")) { + _cfsml_error("Reading record DynMem; expected opening braces in line %d, got \"%s\"\n", *line, lastval); + return CFSML_FAILURE; + }; + closed = 0; + do { + const char *value; + token = _cfsml_get_identifier(fh, line, hiteof, &assignment); + + if (!token) { + _cfsml_error("Expected token at line %d\n", *line); + return CFSML_FAILURE; + } + if (!assignment) { + if (!strcmp(token, "}")) + closed = 1; + else { + _cfsml_error("Expected assignment or closing braces in line %d\n", *line); + return CFSML_FAILURE; + } + } else { + value = ""; + while (!value || !strcmp(value, "")) + value = _cfsml_get_value(fh, line, hiteof); + if (!value) { + _cfsml_error("Expected token at line %d\n", *line); + return CFSML_FAILURE; + } + if (!strcmp(token, "size")) { +#line 691 "engines/sci/engine/savegame.cfsml" + if (_cfsml_read_int(fh, (int*) &(save_struc->size), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_int() for size at line %d\n", *line); + return CFSML_FAILURE; + } + } else + if (!strcmp(token, "description")) { +#line 691 "engines/sci/engine/savegame.cfsml" + if (_cfsml_read_string(fh, (char **) &(save_struc->description), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_string() for description at line %d\n", *line); + return CFSML_FAILURE; + } + } else + if (!strcmp(token, "buf")) { +#line 605 "engines/sci/engine/savegame.cfsml" + if ((value[0] != '[') || (value[strlen(value) - 1] != '[')) { + _cfsml_error("Opening brackets expected at line %d\n", *line); + return CFSML_FAILURE; + } + int max,done,i; +#line 616 "engines/sci/engine/savegame.cfsml" + // Prepare to restore dynamic array + max = strtol(value + 1, NULL, 0); + if (max < 0) { + _cfsml_error("Invalid number of elements to allocate for dynamic array '%s' at line %d\n", token, *line); + return CFSML_FAILURE; + } + + if (max) { + save_struc->buf = (byte *)sci_malloc(max * sizeof(byte)); +#ifdef SATISFY_PURIFY + memset(save_struc->buf, 0, max * sizeof(byte)); +#endif + _cfsml_register_pointer(save_struc->buf); + } else + save_struc->buf = NULL; +#line 640 "engines/sci/engine/savegame.cfsml" + done = i = 0; + do { + if (!(value = _cfsml_get_identifier(fh, line, hiteof, NULL))) { +#line 648 "engines/sci/engine/savegame.cfsml" + _cfsml_error("Token expected at line %d\n", *line); + return 1; + } + if (strcmp(value, "]")) { + if (i == max) { + _cfsml_error("More elements than space available (%d) in '%s' at line %d\n", max, token, *line); + return CFSML_FAILURE; + } + if (_cfsml_read_byte(fh, &(save_struc->buf[i++]), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_byte() for buf[i++] at line %d\n", *line); + return CFSML_FAILURE; + } + } else + done = 1; + } while (!done); + save_struc->size = max ; // Set array size accordingly + } else +#line 700 "engines/sci/engine/savegame.cfsml" + { + _cfsml_error("DynMem: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; } } @@ -3769,7 +3768,7 @@ _cfsml_read_clone_t(Common::SeekableReadStream *fh, clone_t* save_struc, const c #line 396 "engines/sci/engine/savegame.cfsml" static void -_cfsml_write_script_t(Common::WriteStream *fh, script_t const * save_struc) +_cfsml_write_Script(Common::WriteStream *fh, Script const * save_struc) { #line 413 "engines/sci/engine/savegame.cfsml" WSprintf(fh, "{\n"); @@ -3811,7 +3810,7 @@ _cfsml_write_script_t(Common::WriteStream *fh, script_t const * save_struc) #line 440 "engines/sci/engine/savegame.cfsml" WSprintf(fh, "[%d][\n", max); for (int i = 0; i < min; i++) { - _cfsml_write_object_t(fh, &(save_struc->objects[i])); + _cfsml_write_Object(fh, &(save_struc->objects[i])); WSprintf(fh, "\n"); } WSprintf(fh, "]"); @@ -3830,14 +3829,14 @@ _cfsml_write_script_t(Common::WriteStream *fh, script_t const * save_struc) #line 487 "engines/sci/engine/savegame.cfsml" static int -_cfsml_read_script_t(Common::SeekableReadStream *fh, script_t* save_struc, const char *lastval, int *line, int *hiteof) +_cfsml_read_Script(Common::SeekableReadStream *fh, Script* save_struc, const char *lastval, int *line, int *hiteof) { #line 542 "engines/sci/engine/savegame.cfsml" char *token; int assignment, closed; if (strcmp(lastval, "{")) { - _cfsml_error("Reading record script_t; expected opening braces in line %d, got \"%s\"\n", *line, lastval); + _cfsml_error("Reading record Script; expected opening braces in line %d, got \"%s\"\n", *line, lastval); return CFSML_FAILURE; }; closed = 0; @@ -3950,9 +3949,9 @@ _cfsml_read_script_t(Common::SeekableReadStream *fh, script_t* save_struc, const } if (max) { - save_struc->objects = (object_t *)sci_malloc(max * sizeof(object_t)); + save_struc->objects = (Object *)sci_malloc(max * sizeof(Object)); #ifdef SATISFY_PURIFY - memset(save_struc->objects, 0, max * sizeof(object_t)); + memset(save_struc->objects, 0, max * sizeof(Object)); #endif _cfsml_register_pointer(save_struc->objects); } else @@ -3970,8 +3969,8 @@ _cfsml_read_script_t(Common::SeekableReadStream *fh, script_t* save_struc, const _cfsml_error("More elements than space available (%d) in '%s' at line %d\n", max, token, *line); return CFSML_FAILURE; } - if (_cfsml_read_object_t(fh, &(save_struc->objects[i++]), value, line, hiteof)) { - _cfsml_error("Token expected by _cfsml_read_object_t() for objects[i++] at line %d\n", *line); + if (_cfsml_read_Object(fh, &(save_struc->objects[i++]), value, line, hiteof)) { + _cfsml_error("Token expected by _cfsml_read_Object() for objects[i++] at line %d\n", *line); return CFSML_FAILURE; } } else @@ -4002,7 +4001,7 @@ _cfsml_read_script_t(Common::SeekableReadStream *fh, script_t* save_struc, const } else #line 700 "engines/sci/engine/savegame.cfsml" { - _cfsml_error("script_t: Assignment to invalid identifier '%s' in line %d\n", token, *line); + _cfsml_error("Script: Assignment to invalid identifier '%s' in line %d\n", token, *line); return CFSML_FAILURE; } } @@ -4013,7 +4012,7 @@ _cfsml_read_script_t(Common::SeekableReadStream *fh, script_t* save_struc, const // Auto-generated CFSML declaration and function block ends here // Auto-generation performed by cfsml.pl 0.8.2 -#line 451 "engines/sci/engine/savegame.cfsml" +#line 450 "engines/sci/engine/savegame.cfsml" void write_songlib_t(Common::WriteStream *fh, songlib_t const *songlib) { song_t *seeker = *(songlib->lib); @@ -4030,7 +4029,7 @@ void write_songlib_t(Common::WriteStream *fh, songlib_t const *songlib) { _cfsml_write_song_t(fh, seeker); WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 463 "engines/sci/engine/savegame.cfsml" +#line 462 "engines/sci/engine/savegame.cfsml" seeker = seeker->next; } WSprintf(fh, "]\n"); @@ -4078,7 +4077,7 @@ int read_songlib_t(Common::SeekableReadStream *fh, songlib_t *songlib, const cha } } // End of auto-generated CFSML data reader code -#line 487 "engines/sci/engine/savegame.cfsml" +#line 486 "engines/sci/engine/savegame.cfsml" song_lib_add(*songlib, newsong); } l = fh->readLine(); // "]" @@ -4093,7 +4092,7 @@ void write_song_tp(Common::WriteStream *fh, const song_t * const *foo) { _cfsml_write_song_t(fh, *foo); WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 497 "engines/sci/engine/savegame.cfsml" +#line 496 "engines/sci/engine/savegame.cfsml" } song_iterator_t *build_iterator(EngineState *s, int song_nr, int type, songit_id_t id); @@ -4127,7 +4126,7 @@ int read_song_tp(Common::SeekableReadStream *fh, song_t **foo, const char *lastv } } // End of auto-generated CFSML data reader code -#line 507 "engines/sci/engine/savegame.cfsml" +#line 506 "engines/sci/engine/savegame.cfsml" (*foo)->delay = 0; (*foo)->it = NULL; (*foo)->next_playing = (*foo)->next_stopping = (*foo)->next = NULL; @@ -4140,7 +4139,7 @@ void write_IntMapperPtr(Common::WriteStream *fh, const IntMapper * const *foo) { _cfsml_write_IntMapper(fh, *foo); WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 515 "engines/sci/engine/savegame.cfsml" +#line 514 "engines/sci/engine/savegame.cfsml" } int read_IntMapperPtr(Common::SeekableReadStream *fh, IntMapper **foo, const char *lastval, int *line, int *hiteof) { @@ -4169,7 +4168,7 @@ int read_IntMapperPtr(Common::SeekableReadStream *fh, IntMapper **foo, const cha } } // End of auto-generated CFSML data reader code -#line 520 "engines/sci/engine/savegame.cfsml" +#line 519 "engines/sci/engine/savegame.cfsml" (*foo)->holes = NULL; return 0; } @@ -4185,7 +4184,7 @@ void write_IntMapperNodePtr(Common::WriteStream *fh, const IntMapper::Node * con write_IntMapperNodePtr(fh, &((*foo)->next)); WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 531 "engines/sci/engine/savegame.cfsml" +#line 530 "engines/sci/engine/savegame.cfsml" } else WSprintf(fh, "L"); WSprintf(fh, "]"); @@ -4233,7 +4232,7 @@ void write_menubar_tp(Common::WriteStream *fh, const menubar_t * const *foo) { _cfsml_write_menubar_t(fh, (*foo)); WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 574 "engines/sci/engine/savegame.cfsml" +#line 573 "engines/sci/engine/savegame.cfsml" } else { // Nothing to write WSprintf(fh, "\\null\\"); } @@ -4269,7 +4268,7 @@ int read_menubar_tp(Common::SeekableReadStream *fh, menubar_t **foo, const char } } // End of auto-generated CFSML data reader code -#line 586 "engines/sci/engine/savegame.cfsml" +#line 585 "engines/sci/engine/savegame.cfsml" } return *hiteof; } @@ -4300,38 +4299,38 @@ int mem_obj_string_to_enum(const char *str) { return -1; } -void write_mem_obj_t(Common::WriteStream *fh, mem_obj_t const *foo) { +void write_MemObject(Common::WriteStream *fh, MemObject const *foo) { WSprintf(fh, "%s\n", mem_obj_string_names[foo->type].name); #line 822 "engines/sci/engine/savegame.cfsml" // Auto-generated CFSML data writer code _cfsml_write_int(fh, &foo->segmgr_id); WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 619 "engines/sci/engine/savegame.cfsml" +#line 618 "engines/sci/engine/savegame.cfsml" switch (foo->type) { case MEM_OBJ_SCRIPT: #line 822 "engines/sci/engine/savegame.cfsml" // Auto-generated CFSML data writer code - _cfsml_write_script_t(fh, &foo->data.script); + _cfsml_write_Script(fh, &foo->data.script); WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 622 "engines/sci/engine/savegame.cfsml" +#line 621 "engines/sci/engine/savegame.cfsml" break; case MEM_OBJ_CLONES: #line 822 "engines/sci/engine/savegame.cfsml" // Auto-generated CFSML data writer code - _cfsml_write_clone_table_t(fh, &foo->data.clones); + _cfsml_write_CloneTable(fh, &foo->data.clones); WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 625 "engines/sci/engine/savegame.cfsml" +#line 624 "engines/sci/engine/savegame.cfsml" break; case MEM_OBJ_LOCALS: #line 822 "engines/sci/engine/savegame.cfsml" // Auto-generated CFSML data writer code - _cfsml_write_local_variables_t(fh, &foo->data.locals); + _cfsml_write_LocalVariables(fh, &foo->data.locals); WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 628 "engines/sci/engine/savegame.cfsml" +#line 627 "engines/sci/engine/savegame.cfsml" break; case MEM_OBJ_SYS_STRINGS: #line 822 "engines/sci/engine/savegame.cfsml" @@ -4339,7 +4338,7 @@ void write_mem_obj_t(Common::WriteStream *fh, mem_obj_t const *foo) { _cfsml_write_SystemStrings(fh, &foo->data.sys_strings); WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 631 "engines/sci/engine/savegame.cfsml" +#line 630 "engines/sci/engine/savegame.cfsml" break; case MEM_OBJ_STACK: #line 822 "engines/sci/engine/savegame.cfsml" @@ -4347,43 +4346,43 @@ void write_mem_obj_t(Common::WriteStream *fh, mem_obj_t const *foo) { _cfsml_write_int(fh, &foo->data.stack.nr); WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 634 "engines/sci/engine/savegame.cfsml" +#line 633 "engines/sci/engine/savegame.cfsml" break; case MEM_OBJ_HUNK: break; case MEM_OBJ_LISTS: #line 822 "engines/sci/engine/savegame.cfsml" // Auto-generated CFSML data writer code - _cfsml_write_list_table_t(fh, &foo->data.lists); + _cfsml_write_ListTable(fh, &foo->data.lists); WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 639 "engines/sci/engine/savegame.cfsml" +#line 638 "engines/sci/engine/savegame.cfsml" break; case MEM_OBJ_NODES: #line 822 "engines/sci/engine/savegame.cfsml" // Auto-generated CFSML data writer code - _cfsml_write_node_table_t(fh, &foo->data.nodes); + _cfsml_write_NodeTable(fh, &foo->data.nodes); WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 642 "engines/sci/engine/savegame.cfsml" +#line 641 "engines/sci/engine/savegame.cfsml" break; case MEM_OBJ_DYNMEM: #line 822 "engines/sci/engine/savegame.cfsml" // Auto-generated CFSML data writer code - _cfsml_write_dynmem_t(fh, &foo->data.dynmem); + _cfsml_write_DynMem(fh, &foo->data.dynmem); WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 645 "engines/sci/engine/savegame.cfsml" +#line 644 "engines/sci/engine/savegame.cfsml" break; default: break; } } -int read_mem_obj_t(Common::SeekableReadStream *fh, mem_obj_t *foo, const char *lastval, int *line, int *hiteof) { +int read_MemObject(Common::SeekableReadStream *fh, MemObject *foo, const char *lastval, int *line, int *hiteof) { foo->type = (memObjType)mem_obj_string_to_enum(lastval); if (foo->type < 0) { - sciprintf("Unknown mem_obj_t type %s on line %d\n", lastval, *line); + sciprintf("Unknown MemObject type %s on line %d\n", lastval, *line); return 1; } @@ -4413,7 +4412,7 @@ int read_mem_obj_t(Common::SeekableReadStream *fh, mem_obj_t *foo, const char *l } } // End of auto-generated CFSML data reader code -#line 659 "engines/sci/engine/savegame.cfsml" +#line 658 "engines/sci/engine/savegame.cfsml" switch (foo->type) { case MEM_OBJ_SCRIPT: // Auto-generated CFSML data reader code @@ -4427,7 +4426,7 @@ int read_mem_obj_t(Common::SeekableReadStream *fh, mem_obj_t *foo, const char *l _cfsml_error = CFSML_FAILURE; } else { #line 792 "engines/sci/engine/savegame.cfsml" - _cfsml_error = _cfsml_read_script_t(fh, &foo->data.script, _cfsml_inp, &(*line), &_cfsml_eof); + _cfsml_error = _cfsml_read_Script(fh, &foo->data.script, _cfsml_inp, &(*line), &_cfsml_eof); } #line 797 "engines/sci/engine/savegame.cfsml" *hiteof = _cfsml_error; @@ -4442,7 +4441,7 @@ int read_mem_obj_t(Common::SeekableReadStream *fh, mem_obj_t *foo, const char *l } } // End of auto-generated CFSML data reader code -#line 662 "engines/sci/engine/savegame.cfsml" +#line 661 "engines/sci/engine/savegame.cfsml" break; case MEM_OBJ_CLONES: // Auto-generated CFSML data reader code @@ -4456,7 +4455,7 @@ int read_mem_obj_t(Common::SeekableReadStream *fh, mem_obj_t *foo, const char *l _cfsml_error = CFSML_FAILURE; } else { #line 792 "engines/sci/engine/savegame.cfsml" - _cfsml_error = _cfsml_read_clone_table_t(fh, &foo->data.clones, _cfsml_inp, &(*line), &_cfsml_eof); + _cfsml_error = _cfsml_read_CloneTable(fh, &foo->data.clones, _cfsml_inp, &(*line), &_cfsml_eof); } #line 797 "engines/sci/engine/savegame.cfsml" *hiteof = _cfsml_error; @@ -4471,7 +4470,7 @@ int read_mem_obj_t(Common::SeekableReadStream *fh, mem_obj_t *foo, const char *l } } // End of auto-generated CFSML data reader code -#line 665 "engines/sci/engine/savegame.cfsml" +#line 664 "engines/sci/engine/savegame.cfsml" break; case MEM_OBJ_LOCALS: // Auto-generated CFSML data reader code @@ -4485,7 +4484,7 @@ int read_mem_obj_t(Common::SeekableReadStream *fh, mem_obj_t *foo, const char *l _cfsml_error = CFSML_FAILURE; } else { #line 792 "engines/sci/engine/savegame.cfsml" - _cfsml_error = _cfsml_read_local_variables_t(fh, &foo->data.locals, _cfsml_inp, &(*line), &_cfsml_eof); + _cfsml_error = _cfsml_read_LocalVariables(fh, &foo->data.locals, _cfsml_inp, &(*line), &_cfsml_eof); } #line 797 "engines/sci/engine/savegame.cfsml" *hiteof = _cfsml_error; @@ -4500,7 +4499,7 @@ int read_mem_obj_t(Common::SeekableReadStream *fh, mem_obj_t *foo, const char *l } } // End of auto-generated CFSML data reader code -#line 668 "engines/sci/engine/savegame.cfsml" +#line 667 "engines/sci/engine/savegame.cfsml" break; case MEM_OBJ_SYS_STRINGS: // Auto-generated CFSML data reader code @@ -4529,7 +4528,7 @@ int read_mem_obj_t(Common::SeekableReadStream *fh, mem_obj_t *foo, const char *l } } // End of auto-generated CFSML data reader code -#line 671 "engines/sci/engine/savegame.cfsml" +#line 670 "engines/sci/engine/savegame.cfsml" break; case MEM_OBJ_LISTS: // Auto-generated CFSML data reader code @@ -4543,7 +4542,7 @@ int read_mem_obj_t(Common::SeekableReadStream *fh, mem_obj_t *foo, const char *l _cfsml_error = CFSML_FAILURE; } else { #line 792 "engines/sci/engine/savegame.cfsml" - _cfsml_error = _cfsml_read_list_table_t(fh, &foo->data.lists, _cfsml_inp, &(*line), &_cfsml_eof); + _cfsml_error = _cfsml_read_ListTable(fh, &foo->data.lists, _cfsml_inp, &(*line), &_cfsml_eof); } #line 797 "engines/sci/engine/savegame.cfsml" *hiteof = _cfsml_error; @@ -4558,7 +4557,7 @@ int read_mem_obj_t(Common::SeekableReadStream *fh, mem_obj_t *foo, const char *l } } // End of auto-generated CFSML data reader code -#line 674 "engines/sci/engine/savegame.cfsml" +#line 673 "engines/sci/engine/savegame.cfsml" break; case MEM_OBJ_NODES: // Auto-generated CFSML data reader code @@ -4572,7 +4571,7 @@ int read_mem_obj_t(Common::SeekableReadStream *fh, mem_obj_t *foo, const char *l _cfsml_error = CFSML_FAILURE; } else { #line 792 "engines/sci/engine/savegame.cfsml" - _cfsml_error = _cfsml_read_node_table_t(fh, &foo->data.nodes, _cfsml_inp, &(*line), &_cfsml_eof); + _cfsml_error = _cfsml_read_NodeTable(fh, &foo->data.nodes, _cfsml_inp, &(*line), &_cfsml_eof); } #line 797 "engines/sci/engine/savegame.cfsml" *hiteof = _cfsml_error; @@ -4587,7 +4586,7 @@ int read_mem_obj_t(Common::SeekableReadStream *fh, mem_obj_t *foo, const char *l } } // End of auto-generated CFSML data reader code -#line 677 "engines/sci/engine/savegame.cfsml" +#line 676 "engines/sci/engine/savegame.cfsml" break; case MEM_OBJ_STACK: // Auto-generated CFSML data reader code @@ -4616,11 +4615,11 @@ int read_mem_obj_t(Common::SeekableReadStream *fh, mem_obj_t *foo, const char *l } } // End of auto-generated CFSML data reader code -#line 680 "engines/sci/engine/savegame.cfsml" +#line 679 "engines/sci/engine/savegame.cfsml" foo->data.stack.entries = (reg_t *)sci_calloc(foo->data.stack.nr, sizeof(reg_t)); break; case MEM_OBJ_HUNK: - init_hunk_table(&foo->data.hunks); + init_Hunk_table(&foo->data.hunks); break; case MEM_OBJ_DYNMEM: // Auto-generated CFSML data reader code @@ -4634,7 +4633,7 @@ int read_mem_obj_t(Common::SeekableReadStream *fh, mem_obj_t *foo, const char *l _cfsml_error = CFSML_FAILURE; } else { #line 792 "engines/sci/engine/savegame.cfsml" - _cfsml_error = _cfsml_read_dynmem_t(fh, &foo->data.dynmem, _cfsml_inp, &(*line), &_cfsml_eof); + _cfsml_error = _cfsml_read_DynMem(fh, &foo->data.dynmem, _cfsml_inp, &(*line), &_cfsml_eof); } #line 797 "engines/sci/engine/savegame.cfsml" *hiteof = _cfsml_error; @@ -4649,7 +4648,7 @@ int read_mem_obj_t(Common::SeekableReadStream *fh, mem_obj_t *foo, const char *l } } // End of auto-generated CFSML data reader code -#line 687 "engines/sci/engine/savegame.cfsml" +#line 686 "engines/sci/engine/savegame.cfsml" break; default: break; @@ -4658,24 +4657,24 @@ int read_mem_obj_t(Common::SeekableReadStream *fh, mem_obj_t *foo, const char *l return *hiteof; } -void write_mem_obj_tp(Common::WriteStream *fh, const mem_obj_t * const *foo) { +void write_MemObjPtr(Common::WriteStream *fh, const MemObject * const *foo) { if (*foo) { #line 822 "engines/sci/engine/savegame.cfsml" // Auto-generated CFSML data writer code - write_mem_obj_t(fh, (*foo)); + write_MemObject(fh, (*foo)); WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 698 "engines/sci/engine/savegame.cfsml" +#line 697 "engines/sci/engine/savegame.cfsml" } else { // Nothing to write WSprintf(fh, "\\null\\"); } } -int read_mem_obj_tp(Common::SeekableReadStream *fh, mem_obj_t **foo, const char *lastval, int *line, int *hiteof) { +int read_MemObjPtr(Common::SeekableReadStream *fh, MemObject **foo, const char *lastval, int *line, int *hiteof) { if (lastval[0] == '\\') { *foo = NULL; // No menu bar } else { - *foo = (mem_obj_t *)sci_malloc(sizeof(mem_obj_t)); + *foo = (MemObject *)sci_malloc(sizeof(MemObject)); // Auto-generated CFSML data reader code #line 766 "engines/sci/engine/savegame.cfsml" { @@ -4685,7 +4684,7 @@ int read_mem_obj_tp(Common::SeekableReadStream *fh, mem_obj_t **foo, const char const char *_cfsml_inp = lastval; { #line 792 "engines/sci/engine/savegame.cfsml" - _cfsml_error = read_mem_obj_t(fh, (*foo), _cfsml_inp, &(*line), &_cfsml_eof); + _cfsml_error = read_MemObject(fh, (*foo), _cfsml_inp, &(*line), &_cfsml_eof); } #line 797 "engines/sci/engine/savegame.cfsml" *hiteof = _cfsml_error; @@ -4700,7 +4699,7 @@ int read_mem_obj_tp(Common::SeekableReadStream *fh, mem_obj_t **foo, const char } } // End of auto-generated CFSML data reader code -#line 709 "engines/sci/engine/savegame.cfsml" +#line 708 "engines/sci/engine/savegame.cfsml" return *hiteof; } return 0; @@ -4714,7 +4713,7 @@ void write_CommonString(Common::WriteStream *fh, Common::String const *string) _cfsml_write_string(fh, (&t)); WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 718 "engines/sci/engine/savegame.cfsml" +#line 717 "engines/sci/engine/savegame.cfsml" } int read_CommonString(Common::SeekableReadStream *fh, Common::String *string, const char *lastval, int *line, int *hiteof) @@ -4749,7 +4748,7 @@ int read_CommonString(Common::SeekableReadStream *fh, Common::String *string, co } } // End of auto-generated CFSML data reader code -#line 725 "engines/sci/engine/savegame.cfsml" +#line 724 "engines/sci/engine/savegame.cfsml" if (*hiteof) return *hiteof; *string = t; free(t); @@ -4762,13 +4761,13 @@ void write_SegManagerPtr(Common::WriteStream *fh, const SegManager * const *foo) _cfsml_write_bool(fh, &((*foo)->isSci1_1)); WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 733 "engines/sci/engine/savegame.cfsml" +#line 732 "engines/sci/engine/savegame.cfsml" #line 822 "engines/sci/engine/savegame.cfsml" // Auto-generated CFSML data writer code _cfsml_write_SegManager(fh, *foo); WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 734 "engines/sci/engine/savegame.cfsml" +#line 733 "engines/sci/engine/savegame.cfsml" } int read_SegManagerPtr(Common::SeekableReadStream *fh, SegManager **foo, const char *lastval, int *line, int *hiteof) { @@ -4799,7 +4798,7 @@ int read_SegManagerPtr(Common::SeekableReadStream *fh, SegManager **foo, const c } } // End of auto-generated CFSML data reader code -#line 741 "engines/sci/engine/savegame.cfsml" +#line 740 "engines/sci/engine/savegame.cfsml" *foo = new SegManager(sci11); token = _cfsml_get_identifier(fh, line, hiteof, &assignment); // Auto-generated CFSML data reader code @@ -4826,7 +4825,7 @@ int read_SegManagerPtr(Common::SeekableReadStream *fh, SegManager **foo, const c } } // End of auto-generated CFSML data reader code -#line 744 "engines/sci/engine/savegame.cfsml" +#line 743 "engines/sci/engine/savegame.cfsml" return 0; } @@ -4876,20 +4875,20 @@ int gamestate_save(EngineState *s, Common::WriteStream *fh, const char* savename _cfsml_write_SavegameMetadata(fh, (&meta)); WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 789 "engines/sci/engine/savegame.cfsml" +#line 788 "engines/sci/engine/savegame.cfsml" #line 822 "engines/sci/engine/savegame.cfsml" // Auto-generated CFSML data writer code _cfsml_write_EngineState(fh, s); WSprintf(fh, "\n"); // End of auto-generated CFSML data writer code -#line 790 "engines/sci/engine/savegame.cfsml" +#line 789 "engines/sci/engine/savegame.cfsml" _gamestate_unfrob(s); return 0; } -static seg_id_t find_unique_seg_by_type(SegManager *self, int type) { +static SegmentId find_unique_seg_by_type(SegManager *self, int type) { int i; for (i = 0; i < self->heap_size; i++) @@ -4918,7 +4917,7 @@ static byte *find_unique_script_block(EngineState *s, byte *buf, int type) { } static void reconstruct_stack(EngineState *retval) { - seg_id_t stack_seg = find_unique_seg_by_type(retval->seg_manager, MEM_OBJ_STACK); + SegmentId stack_seg = find_unique_seg_by_type(retval->seg_manager, MEM_OBJ_STACK); dstack_t *stack = &(retval->seg_manager->heap[stack_seg]->data.stack); retval->stack_segment = stack_seg; @@ -4926,10 +4925,10 @@ static void reconstruct_stack(EngineState *retval) { retval->stack_top = retval->stack_base + VM_STACK_SIZE; } -static int clone_entry_used(clone_table_t *table, int n) { +static int clone_entry_used(CloneTable *table, int n) { int backup; int seeker = table->first_free; - clone_entry_t *entries = table->table; + CloneEntry *entries = table->table; if (seeker == HEAPENTRY_INVALID) return 1; @@ -4942,9 +4941,9 @@ static int clone_entry_used(clone_table_t *table, int n) { return 1; } -static void load_script(EngineState *s, seg_id_t seg) { +static void load_script(EngineState *s, SegmentId seg) { resource_t *script, *heap = NULL; - script_t *scr = &(s->seg_manager->heap[seg]->data.script); + Script *scr = &(s->seg_manager->heap[seg]->data.script); scr->buf = (byte *)malloc(scr->buf_size); @@ -4965,14 +4964,14 @@ static void load_script(EngineState *s, seg_id_t seg) { static void reconstruct_scripts(EngineState *s, SegManager *self) { int i; - mem_obj_t *mobj; + MemObject *mobj; for (i = 0; i < self->heap_size; i++) { if (self->heap[i]) { mobj = self->heap[i]; switch (mobj->type) { case MEM_OBJ_SCRIPT: { int j; - script_t *scr = &mobj->data.script; + Script *scr = &mobj->data.script; load_script(s, i); scr->locals_block = scr->locals_segment == 0 ? NULL : &s->seg_manager->heap[scr->locals_segment]->data.locals; @@ -5004,7 +5003,7 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) { switch (mobj->type) { case MEM_OBJ_SCRIPT: { int j; - script_t *scr = &mobj->data.script; + Script *scr = &mobj->data.script; for (j = 0; j < scr->objects_nr; j++) { byte *data = scr->buf + scr->objects[j].pos.offset; @@ -5017,7 +5016,7 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) { scr->objects[j].base_vars = prop_area; } else { int funct_area = getUInt16( data + SCRIPT_FUNCTAREAPTR_OFFSET ); - object_t *base_obj; + Object *base_obj; base_obj = obj_get(s, scr->objects[j].variables[SCRIPT_SPECIES_SELECTOR]); @@ -5044,7 +5043,7 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) { void reconstruct_clones(EngineState *s, SegManager *self) { int i; - mem_obj_t *mobj; + MemObject *mobj; for (i = 0; i < self->heap_size; i++) { if (self->heap[i]) { @@ -5052,7 +5051,7 @@ void reconstruct_clones(EngineState *s, SegManager *self) { switch (mobj->type) { case MEM_OBJ_CLONES: { int j; - clone_entry_t *seeker = mobj->data.clones.table; + CloneEntry *seeker = mobj->data.clones.table; sciprintf("Free list: "); for (j = mobj->data.clones.first_free; j != HEAPENTRY_INVALID; j = mobj->data.clones.table[j].next_free) { @@ -5068,7 +5067,7 @@ void reconstruct_clones(EngineState *s, SegManager *self) { sciprintf("\n"); for (j = 0; j < mobj->data.clones.max_entry; j++) { - object_t *base_obj; + Object *base_obj; if (!clone_entry_used(&mobj->data.clones, j)) { seeker++; @@ -5190,7 +5189,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { } } // End of auto-generated CFSML data reader code -#line 1066 "engines/sci/engine/savegame.cfsml" +#line 1065 "engines/sci/engine/savegame.cfsml" if (read_eof) return false; @@ -5246,7 +5245,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { } } // End of auto-generated CFSML data reader code -#line 1090 "engines/sci/engine/savegame.cfsml" +#line 1089 "engines/sci/engine/savegame.cfsml" sfx_exit(&s->sound); _gamestate_unfrob(retval); @@ -5279,7 +5278,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { retval->save_dir_copy = make_reg(s->sys_strings_segment, SYS_STRING_SAVEDIR); retval->save_dir_edit_offset = 0; retval->sys_strings_segment = find_unique_seg_by_type(retval->seg_manager, MEM_OBJ_SYS_STRINGS); - retval->sys_strings = &(((mem_obj_t *)(GET_SEGMENT(*retval->seg_manager, retval->sys_strings_segment, MEM_OBJ_SYS_STRINGS)))->data.sys_strings); + retval->sys_strings = &(((MemObject *)(GET_SEGMENT(*retval->seg_manager, retval->sys_strings_segment, MEM_OBJ_SYS_STRINGS)))->data.sys_strings); // Restore system strings SystemString *str; @@ -5384,7 +5383,7 @@ bool get_savegame_metadata(Common::SeekableReadStream* stream, SavegameMetadata* } } // End of auto-generated CFSML data reader code -#line 1196 "engines/sci/engine/savegame.cfsml" +#line 1195 "engines/sci/engine/savegame.cfsml" if (read_eof) return false; diff --git a/engines/sci/engine/script.h b/engines/sci/engine/script.h index d30a0cd41b..fcc2f843f9 100644 --- a/engines/sci/engine/script.h +++ b/engines/sci/engine/script.h @@ -37,11 +37,14 @@ struct ResourceManager; #define SCI_SCRIPTS_NR 1000 +#if 0 +// Unreferenced struct script_opcode { unsigned opcode; int arg1, arg2, arg3; int pos, size; }; +#endif enum script_object_types { diff --git a/engines/sci/engine/scriptconsole.cpp b/engines/sci/engine/scriptconsole.cpp index 9a99685677..68146afc24 100644 --- a/engines/sci/engine/scriptconsole.cpp +++ b/engines/sci/engine/scriptconsole.cpp @@ -208,7 +208,7 @@ void con_init() { } } -static inline int clone_is_used(clone_table_t *t, int idx) { +static inline int clone_is_used(CloneTable *t, int idx) { return ENTRY_IS_VALID(t, idx); } @@ -306,7 +306,7 @@ int parse_reg_t(EngineState *s, const char *str, reg_t *dest) { // Returns 0 on // Now all values are available; iterate over all objects. for (i = 0; i < s->seg_manager->heap_size; i++) { - mem_obj_t *mobj = s->seg_manager->heap[i]; + MemObject *mobj = s->seg_manager->heap[i]; int idx = 0; int max_index = 0; @@ -319,7 +319,7 @@ int parse_reg_t(EngineState *s, const char *str, reg_t *dest) { // Returns 0 on while (idx < max_index) { int valid = 1; - object_t *obj = NULL; + Object *obj = NULL; reg_t objpos; objpos.offset = 0; objpos.segment = i; diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index b84e703c47..9307bc0b09 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -61,11 +61,11 @@ reg_t _debug_seek_reg = NULL_REG; // Used for special seeks(2) #define _DEBUG_SEEK_GLOBAL 6 // Step forward until one specified global variable is modified static reg_t *p_pc; -static stack_ptr_t *p_sp; -static stack_ptr_t *p_pp; +static StackPtr *p_sp; +static StackPtr *p_pp; static reg_t *p_objp; static int *p_restadjust; -static seg_id_t *p_var_segs; +static SegmentId *p_var_segs; static reg_t **p_vars; static reg_t **p_var_base; static int *p_var_max; // May be NULL even in valid state! @@ -279,7 +279,7 @@ int c_segtable(EngineState *s) { sciprintf(" ---- segment table ----\n"); for (i = 0; i < s->seg_manager->heap_size; i++) { - mem_obj_t *mobj = s->seg_manager->heap[i]; + MemObject *mobj = s->seg_manager->heap[i]; if (mobj && mobj->type) { sciprintf(" [%04x] ", i); @@ -333,20 +333,20 @@ int c_segtable(EngineState *s) { return 0; } -static void print_obj_head(EngineState *s, object_t *obj) { +static void print_obj_head(EngineState *s, Object *obj) { sciprintf(PREG" %s : %3d vars, %3d methods\n", PRINT_REG(obj->pos), obj_get_name(s, obj->pos), obj->variables_nr, obj->methods_nr); } -static void print_list(EngineState *s, list_t *l) { +static void print_list(EngineState *s, List *l) { reg_t pos = l->first; reg_t my_prev = NULL_REG; sciprintf("\t<\n"); while (!IS_NULL_REG(pos)) { - node_t *node; - mem_obj_t *mobj = GET_SEGMENT(*s->seg_manager, pos.segment, MEM_OBJ_NODES); + Node *node; + MemObject *mobj = GET_SEGMENT(*s->seg_manager, pos.segment, MEM_OBJ_NODES); if (!mobj || !ENTRY_IS_VALID(&(mobj->data.nodes), pos.offset)) { sciprintf(" WARNING: "PREG": Doesn't contain list node!\n", @@ -372,12 +372,12 @@ static void print_list(EngineState *s, list_t *l) { sciprintf("\t>\n"); } -static void _c_single_seg_info(EngineState *s, mem_obj_t *mobj) { +static void _c_single_seg_info(EngineState *s, MemObject *mobj) { switch (mobj->type) { case MEM_OBJ_SCRIPT: { int i; - script_t *scr = &(mobj->data.script); + Script *scr = &(mobj->data.script); sciprintf("script.%03d locked by %d, bufsize=%d (%x)\n", scr->nr, scr->lockers, (uint)scr->buf_size, (uint)scr->buf_size); if (scr->export_table) sciprintf(" Exports: %4d at %d\n", scr->exports_nr, (int)(((byte *)scr->export_table) - ((byte *)scr->buf))); @@ -400,7 +400,7 @@ static void _c_single_seg_info(EngineState *s, mem_obj_t *mobj) { break; case MEM_OBJ_LOCALS: { - local_variables_t *locals = &(mobj->data.locals); + LocalVariables *locals = &(mobj->data.locals); sciprintf("locals for script.%03d\n", locals->script_id); sciprintf(" %d (0x%x) locals\n", locals->nr, locals->nr); } @@ -426,7 +426,7 @@ static void _c_single_seg_info(EngineState *s, mem_obj_t *mobj) { case MEM_OBJ_CLONES: { int i = 0; - clone_table_t *ct = &(mobj->data.clones); + CloneTable *ct = &(mobj->data.clones); sciprintf("clones\n"); @@ -440,7 +440,7 @@ static void _c_single_seg_info(EngineState *s, mem_obj_t *mobj) { case MEM_OBJ_LISTS: { int i = 0; - list_table_t *lt = &(mobj->data.lists); + ListTable *lt = &(mobj->data.lists); sciprintf("lists\n"); for (i = 0; i < lt->max_entry; i++) @@ -458,7 +458,7 @@ static void _c_single_seg_info(EngineState *s, mem_obj_t *mobj) { case MEM_OBJ_HUNK: { int i; - hunk_table_t *ht = &(mobj->data.hunks); + HunkTable *ht = &(mobj->data.hunks); sciprintf("hunk (total %d)\n", mobj->data.hunks.entries_used); for (i = 0; i < ht->max_entry; i++) @@ -483,11 +483,11 @@ static void _c_single_seg_info(EngineState *s, mem_obj_t *mobj) { } static int show_node(EngineState *s, reg_t addr) { - mem_obj_t *mobj = GET_SEGMENT(*s->seg_manager, addr.segment, MEM_OBJ_LISTS); + MemObject *mobj = GET_SEGMENT(*s->seg_manager, addr.segment, MEM_OBJ_LISTS); if (mobj) { - list_table_t *lt = &(mobj->data.lists); - list_t *list; + ListTable *lt = &(mobj->data.lists); + List *list; if (!ENTRY_IS_VALID(lt, addr.offset)) { sciprintf("Address does not contain a list\n"); @@ -498,8 +498,8 @@ static int show_node(EngineState *s, reg_t addr) { sciprintf(PREG" : first x last = ("PREG", "PREG")\n", PRINT_REG(addr), PRINT_REG(list->first), PRINT_REG(list->last)); } else { - node_table_t *nt; - node_t *node; + NodeTable *nt; + Node *node; mobj = GET_SEGMENT(*s->seg_manager, addr.segment, MEM_OBJ_NODES); if (!mobj) { @@ -566,7 +566,7 @@ static int c_vr(EngineState *s) { break; case KSIG_LIST: { - list_t *l = LOOKUP_LIST(reg); + List *l = LOOKUP_LIST(reg); sciprintf("list\n"); @@ -675,7 +675,7 @@ int c_seginfo(EngineState *s) { } int c_debuginfo(EngineState *s) { - exec_stack_t *eframe = NULL; + ExecStack *eframe = NULL; if (!_debugstate_valid) { sciprintf("Not in debug state\n"); @@ -1149,7 +1149,7 @@ int c_restart_game(EngineState *s) { int c_stack(EngineState *s) { int i; - exec_stack_t *xs; + ExecStack *xs; if (!s) { sciprintf("Not in debug state\n"); @@ -1181,7 +1181,7 @@ const char *selector_name(EngineState *s, int selector) { } int prop_ofs_to_id(EngineState *s, int prop_ofs, reg_t objp) { - object_t *obj = obj_get(s, objp); + Object *obj = obj_get(s, objp); byte *selectoroffset; int selectors; @@ -1213,8 +1213,8 @@ int prop_ofs_to_id(EngineState *s, int prop_ofs, reg_t objp) { reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecode) { // Disassembles one command from the heap, returns address of next command or 0 if a ret was encountered. - mem_obj_t *memobj = GET_SEGMENT(*s->seg_manager, pos.segment, MEM_OBJ_SCRIPT); - script_t *script_entity = NULL; + MemObject *memobj = GET_SEGMENT(*s->seg_manager, pos.segment, MEM_OBJ_SCRIPT); + Script *script_entity = NULL; byte *scr; int scr_size; reg_t retval = make_reg(pos.segment, pos.offset + 1); @@ -1426,15 +1426,15 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod sciprintf(" %s::%s[", name, (selector > s->_selectorNames.size()) ? "" : selector_name(s, selector)); switch (lookup_selector(s, called_obj_addr, selector, &val_ref, &fun_ref)) { - case SELECTOR_METHOD: + case kSelectorMethod: sciprintf("FUNCT"); argc += restmod; restmod = 0; break; - case SELECTOR_VARIABLE: + case kSelectorVariable: sciprintf("VAR"); break; - case SELECTOR_NONE: + case kSelectorNone: sciprintf("INVALID"); break; } @@ -1540,7 +1540,7 @@ static int c_backtrace(EngineState *s) { sciprintf("Call stack (current base: 0x%x):\n", s->execution_stack_base); for (i = 0; i <= s->execution_stack_pos; i++) { - exec_stack_t *call = &(s->execution_stack[i]); + ExecStack *call = &(s->execution_stack[i]); const char *objname = obj_get_name(s, call->sendp); int paramc, totalparamc; @@ -1929,7 +1929,7 @@ static int c_gfx_draw_viewobj(EngineState *s) { #warning "Re-implement con:gfx_draw_viewobj" #endif #if 0 - heap_ptr pos = (heap_ptr)(cmd_params[0].val); + HeapPtr pos = (HeapPtr)(cmd_params[0].val); int is_view; int x, y, priority; int nsLeft, nsRight, nsBottom, nsTop; @@ -1951,10 +1951,10 @@ static int c_gfx_draw_viewobj(EngineState *s) { } - is_view = (lookup_selector(s, pos, s->selector_map.x, NULL) == SELECTOR_VARIABLE) && - (lookup_selector(s, pos, s->selector_map.brLeft, NULL) == SELECTOR_VARIABLE) && - (lookup_selector(s, pos, s->selector_map.signal, NULL) == SELECTOR_VARIABLE) && - (lookup_selector(s, pos, s->selector_map.nsTop, NULL) == SELECTOR_VARIABLE); + is_view = (lookup_selector(s, pos, s->selector_map.x, NULL) == kSelectorVariable) && + (lookup_selector(s, pos, s->selector_map.brLeft, NULL) == kSelectorVariable) && + (lookup_selector(s, pos, s->selector_map.signal, NULL) == kSelectorVariable) && + (lookup_selector(s, pos, s->selector_map.nsTop, NULL) == kSelectorVariable); if (!is_view) { sciprintf("Not a dynamic View object.\n"); @@ -2051,7 +2051,7 @@ static int c_disasm_addr(EngineState *s) { } static int c_disasm(EngineState *s) { - object_t *obj = obj_get(s, cmd_params[0].reg); + Object *obj = obj_get(s, cmd_params[0].reg); int selector_id = script_find_selector(s, cmd_params[1].str); reg_t addr; @@ -2065,7 +2065,7 @@ static int c_disasm(EngineState *s) { return 1; } - if (lookup_selector(s, cmd_params[0].reg, selector_id, NULL, &addr) != SELECTOR_METHOD) { + if (lookup_selector(s, cmd_params[0].reg, selector_id, NULL, &addr) != kSelectorMethod) { sciprintf("Not a method."); return 1; } @@ -2148,11 +2148,11 @@ static int c_set_acc(EngineState *s) { static int c_send(EngineState *s) { reg_t object = cmd_params[0].reg; char *selector_name = cmd_params[1].str; - stack_ptr_t stackframe = s->execution_stack->sp; + StackPtr stackframe = s->execution_stack->sp; int selector_id; - unsigned int i, selector_type; - exec_stack_t *xstack; - object_t *o; + unsigned int i; + ExecStack *xstack; + Object *o; reg_t *vptr; reg_t fptr; @@ -2169,9 +2169,9 @@ static int c_send(EngineState *s) { return 1; } - selector_type = lookup_selector(s, object, selector_id, &vptr, &fptr); + SelectorType selector_type = lookup_selector(s, object, selector_id, &vptr, &fptr); - if (selector_type == SELECTOR_NONE) { + if (selector_type == kSelectorNone) { sciprintf("Object does not support selector: \"%s\"\n", selector_name); return 1; } @@ -2185,7 +2185,7 @@ static int c_send(EngineState *s) { xstack = add_exec_stack_entry(s, fptr, s->execution_stack->sp + cmd_paramlength, object, cmd_paramlength - 2, s->execution_stack->sp - 1, 0, object, s->execution_stack_pos, SCI_XS_CALLEE_LOCALS); xstack->selector = selector_id; - xstack->type = selector_type == SELECTOR_VARIABLE ? EXEC_STACK_TYPE_VARSELECTOR : EXEC_STACK_TYPE_CALL; + xstack->type = selector_type == kSelectorVariable ? EXEC_STACK_TYPE_VARSELECTOR : EXEC_STACK_TYPE_CALL; // Now commit the actual function: xstack = send_selector(s, object, object, stackframe, cmd_paramlength - 2, stackframe); @@ -2456,7 +2456,7 @@ int c_simsoundcue(EngineState *s) { #ifdef __GNUC__ #warning "Re-implement viewobjinfo" #endif -static void viewobjinfo(EngineState *s, heap_ptr pos) { +static void viewobjinfo(EngineState *s, HeapPtr pos) { char *signals[16] = { "stop_update", "updated", @@ -2485,7 +2485,7 @@ static void viewobjinfo(EngineState *s, heap_ptr pos) { int have_rects = 0; abs_rect_t nsrect, nsrect_clipped, brrect; - if (lookup_selector(s, pos, s->selector_map.nsBottom, NULL) == SELECTOR_VARIABLE) { + if (lookup_selector(s, pos, s->selector_map.nsBottom, NULL) == kSelectorVariable) { GETRECT(nsLeft, nsRight, nsBottom, nsTop); GETRECT(lsLeft, lsRight, lsBottom, lsTop); GETRECT(brLeft, brRight, brBottom, brTop); @@ -2532,8 +2532,8 @@ static void viewobjinfo(EngineState *s, heap_ptr pos) { #undef GETRECT int objinfo(EngineState *s, reg_t pos) { - object_t *obj = obj_get(s, pos); - object_t *var_container = obj; + Object *obj = obj_get(s, pos); + Object *var_container = obj; int i; sciprintf("["PREG"]: ", PRINT_REG(pos)); @@ -2587,17 +2587,17 @@ int c_shownode(EngineState *s) { // Breakpoint commands -static breakpoint_t *bp_alloc(EngineState *s) { - breakpoint_t *bp; +static Breakpoint *bp_alloc(EngineState *s) { + Breakpoint *bp; if (s->bp_list) { bp = s->bp_list; while (bp->next) bp = bp->next; - bp->next = (breakpoint_t *)sci_malloc(sizeof(breakpoint_t)); + bp->next = (Breakpoint *)sci_malloc(sizeof(Breakpoint)); bp = bp->next; } else { - s->bp_list = (breakpoint_t *)sci_malloc(sizeof(breakpoint_t)); + s->bp_list = (Breakpoint *)sci_malloc(sizeof(Breakpoint)); bp = s->bp_list; } @@ -2607,7 +2607,7 @@ static breakpoint_t *bp_alloc(EngineState *s) { } int c_bpx(EngineState *s) { - breakpoint_t *bp; + Breakpoint *bp; /* Note: We can set a breakpoint on a method that has not been loaded yet. Thus, we can't check whether the command argument is a valid method name. @@ -2624,7 +2624,7 @@ int c_bpx(EngineState *s) { } int c_bpe(EngineState *s) { - breakpoint_t *bp; + Breakpoint *bp; bp = bp_alloc(s); @@ -2636,7 +2636,7 @@ int c_bpe(EngineState *s) { } int c_bplist(EngineState *s) { - breakpoint_t *bp; + Breakpoint *bp; int i = 0; int bpdata; @@ -2661,7 +2661,7 @@ int c_bplist(EngineState *s) { } int c_bpdel(EngineState *s) { - breakpoint_t *bp, *bp_next, *bp_prev; + Breakpoint *bp, *bp_next, *bp_prev; int i = 0, found = 0; int type; @@ -2861,8 +2861,8 @@ static int c_gc_list_reachable(EngineState *s) { return 0; } -void script_debug(EngineState *s, reg_t *pc, stack_ptr_t *sp, stack_ptr_t *pp, reg_t *objp, int *restadjust, - seg_id_t *segids, reg_t **variables, reg_t **variables_base, int *variables_nr, int bp) { +void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *objp, int *restadjust, + SegmentId *segids, reg_t **variables, reg_t **variables_base, int *variables_nr, int bp) { // Do we support a separate console? if (sci_debug_flags & _DEBUG_FLAG_LOGGING) { @@ -2891,10 +2891,10 @@ void script_debug(EngineState *s, reg_t *pc, stack_ptr_t *sp, stack_ptr_t *pp, r } if (_debug_seeking && !bp) { // Are we looking for something special? - mem_obj_t *memobj = GET_SEGMENT(*s->seg_manager, pc->segment, MEM_OBJ_SCRIPT); + MemObject *memobj = GET_SEGMENT(*s->seg_manager, pc->segment, MEM_OBJ_SCRIPT); if (memobj) { - script_t *scr = &(memobj->data.script); + Script *scr = &(memobj->data.script); byte *code_buf = scr->buf; int code_buf_size = scr->buf_size; int opcode = pc->offset >= code_buf_size ? 0 : code_buf[pc->offset]; diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp index 977e3f808d..ec551fd672 100644 --- a/engines/sci/engine/seg_manager.cpp +++ b/engines/sci/engine/seg_manager.cpp @@ -69,7 +69,7 @@ inline int SegManager::findFreeId(int *id) { return retval; } -mem_obj_t *SegManager::allocNonscriptSegment(memObjType type, seg_id_t *segid) { +MemObject *SegManager::allocNonscriptSegment(memObjType type, SegmentId *segid) { // Allocates a non-script segment int id; @@ -89,12 +89,12 @@ SegManager::SegManager(bool sci1_1) { reserved_id--; // reserved_id runs in the reversed direction to make sure no one will use it. heap_size = DEFAULT_SCRIPTS; - heap = (mem_obj_t **)sci_calloc(heap_size, sizeof(mem_obj_t *)); + heap = (MemObject **)sci_calloc(heap_size, sizeof(MemObject *)); - clones_seg_id = 0; - lists_seg_id = 0; - nodes_seg_id = 0; - hunks_seg_id = 0; + Clones_seg_id = 0; + Lists_seg_id = 0; + Nodes_seg_id = 0; + Hunks_seg_id = 0; exports_wide = 0; isSci1_1 = sci1_1; @@ -129,10 +129,10 @@ SegManager::~SegManager() { // Returns : 0 - allocation failure // 1 - allocated successfully // seg_id - allocated segment id -mem_obj_t *SegManager::allocateScript(EngineState *s, int script_nr, int* seg_id) { +MemObject *SegManager::allocateScript(EngineState *s, int script_nr, int* seg_id) { int seg; bool was_added; - mem_obj_t* mem; + MemObject* mem; seg = id_seg_map->checkKey(script_nr, true, &was_added); if (!was_added) { @@ -140,7 +140,7 @@ mem_obj_t *SegManager::allocateScript(EngineState *s, int script_nr, int* seg_id return heap[*seg_id]; } - // allocate the mem_obj_t + // allocate the MemObject mem = memObjAllocate(seg, script_nr, MEM_OBJ_SCRIPT); if (!mem) { sciprintf("%s, %d, Not enough memory, ", __FILE__, __LINE__); @@ -151,7 +151,7 @@ mem_obj_t *SegManager::allocateScript(EngineState *s, int script_nr, int* seg_id return mem; } -void SegManager::setScriptSize(mem_obj_t *mem, EngineState *s, int script_nr) { +void SegManager::setScriptSize(MemObject *mem, EngineState *s, int script_nr) { resource_t *script = scir_find_resource(s->resmgr, sci_script, script_nr, 0); resource_t *heap = scir_find_resource(s->resmgr, sci_heap, script_nr, 0); @@ -187,9 +187,9 @@ void SegManager::setScriptSize(mem_obj_t *mem, EngineState *s, int script_nr) { } } -int SegManager::initialiseScript(mem_obj_t *mem, EngineState *s, int script_nr) { +int SegManager::initialiseScript(MemObject *mem, EngineState *s, int script_nr) { // allocate the script.buf - script_t *scr; + Script *scr; setScriptSize(mem, s, script_nr); mem->data.script.buf = (byte*) sci_malloc(mem->data.script.buf_size); @@ -230,7 +230,7 @@ int SegManager::initialiseScript(mem_obj_t *mem, EngineState *s, int script_nr) } int SegManager::deallocate(int seg, bool recursive) { - mem_obj_t *mobj; + MemObject *mobj; VERIFY(check(seg), "invalid seg id"); int i; @@ -311,7 +311,7 @@ int SegManager::deallocate(int seg, bool recursive) { } int SegManager::scriptMarkedDeleted(int script_nr) { - script_t *scr; + Script *scr; int seg = segGet(script_nr); VERIFY(check(seg), "invalid seg id"); @@ -320,7 +320,7 @@ int SegManager::scriptMarkedDeleted(int script_nr) { } void SegManager::markScriptDeleted(int script_nr) { - script_t *scr; + Script *scr; int seg = segGet(script_nr); VERIFY(check(seg), "invalid seg id"); @@ -329,7 +329,7 @@ void SegManager::markScriptDeleted(int script_nr) { } void SegManager::unmarkScriptDeleted(int script_nr) { - script_t *scr; + Script *scr; int seg = segGet(script_nr); VERIFY(check(seg), "invalid seg id"); @@ -337,8 +337,8 @@ void SegManager::unmarkScriptDeleted(int script_nr) { scr->marked_as_deleted = 0; } -int SegManager::scriptIsMarkedAsDeleted(seg_id_t seg) { - script_t *scr; +int SegManager::scriptIsMarkedAsDeleted(SegmentId seg) { + Script *scr; if (!check(seg)) return 0; @@ -360,8 +360,8 @@ int SegManager::deallocateScript(int script_nr) { return 1; } -mem_obj_t *SegManager::memObjAllocate(seg_id_t segid, int hash_id, memObjType type) { - mem_obj_t *mem = (mem_obj_t *)sci_calloc(sizeof(mem_obj_t), 1); +MemObject *SegManager::memObjAllocate(SegmentId segid, int hash_id, memObjType type) { + MemObject *mem = (MemObject *)sci_calloc(sizeof(MemObject), 1); if (!mem) { sciprintf("SegManager: invalid mem_obj "); return NULL; @@ -376,15 +376,15 @@ mem_obj_t *SegManager::memObjAllocate(seg_id_t segid, int hash_id, memObjType ty return NULL; } heap_size *= 2; - temp = sci_realloc((void *)heap, heap_size * sizeof(mem_obj_t *)); + temp = sci_realloc((void *)heap, heap_size * sizeof(MemObject *)); if (!temp) { sciprintf("SegManager: Not enough memory space for script size"); return NULL; } - heap = (mem_obj_t **)temp; + heap = (MemObject **)temp; // Clear pointers - memset(heap + oldhs, 0, sizeof(mem_obj_t *) * (heap_size - oldhs)); + memset(heap + oldhs, 0, sizeof(MemObject *) * (heap_size - oldhs)); } mem->segmgr_id = hash_id; @@ -396,14 +396,14 @@ mem_obj_t *SegManager::memObjAllocate(seg_id_t segid, int hash_id, memObjType ty } /* No longer in use? -void SegManager::sm_object_init(object_t *object) { +void SegManager::sm_object_init(Object *object) { if (!object) return; object->variables_nr = 0; object->variables = NULL; };*/ -void SegManager::freeScript(mem_obj_t *mem) { +void SegManager::freeScript(MemObject *mem) { if (!mem) return; if (mem->data.script.buf) { @@ -415,7 +415,7 @@ void SegManager::freeScript(mem_obj_t *mem) { int i; for (i = 0; i < mem->data.script.objects_nr; i++) { - object_t* object = &mem->data.script.objects[i]; + Object* object = &mem->data.script.objects[i]; if (object->variables) { free(object->variables); object->variables = NULL; @@ -435,7 +435,7 @@ void SegManager::freeScript(mem_obj_t *mem) { #if 0 // Unreferenced - removed static void SegManager::sm_mset(int offset, int c, size_t n, int id, int flag) { - mem_obj_t *mem_obj; + MemObject *mem_obj; GET_SEGID(); mem_obj = heap[id]; switch (mem_obj->type) { @@ -457,7 +457,7 @@ static void SegManager::sm_mset(int offset, int c, size_t n, int id, int flag) { #if 0 // Unreferenced - removed static void SegManager::sm_mcpy_in_in(int dst, const int src, size_t n, int id, int flag) { - mem_obj_t *mem_obj; + MemObject *mem_obj; GET_SEGID(); mem_obj = heap[id]; switch (mem_obj->type) { @@ -477,7 +477,7 @@ static void SegManager::sm_mcpy_in_in(int dst, const int src, size_t n, int id, #endif void SegManager::mcpyInOut(int dst, const void *src, size_t n, int id, int flag) { - mem_obj_t *mem_obj; + MemObject *mem_obj; GET_SEGID(); mem_obj = heap[id]; switch (mem_obj->type) { @@ -498,7 +498,7 @@ void SegManager::mcpyInOut(int dst, const void *src, size_t n, int id, int flag) #if 0 // Unreferenced - removed static void SegManager::sm_mcpy_out_in(void *dst, const int src, size_t n, int id, int flag) { - mem_obj_t *mem_obj; + MemObject *mem_obj; GET_SEGID(); mem_obj = heap[id]; switch (mem_obj->type) { @@ -518,7 +518,7 @@ static void SegManager::sm_mcpy_out_in(void *dst, const int src, size_t n, int i #endif int16 SegManager::getHeap(reg_t reg) { - mem_obj_t *mem_obj; + MemObject *mem_obj; memObjType mem_type; VERIFY(check(reg.segment), "Invalid seg id"); @@ -542,7 +542,7 @@ int16 SegManager::getHeap(reg_t reg) { #if 0 // Unreferenced - removed void SegManager::sm_put_heap(reg_t reg, int16 value) { - mem_obj_t *mem_obj; + MemObject *mem_obj; memObjType mem_type; VERIFY(check(reg.segment), "Invalid seg id"); @@ -624,7 +624,7 @@ void SegManager::setLockers(int lockers, int id, idFlag flag) { } void SegManager::setExportTableOffset(int offset, int id, idFlag flag) { - script_t *scr = &(heap[id]->data.script); + Script *scr = &(heap[id]->data.script); GET_SEGID(); if (offset) { @@ -703,7 +703,7 @@ static int SegManager::sm_get_heappos(int id, int flag) { #if 0 // Unreferenced - removed static void SegManager::sm_set_variables(reg_t reg, int obj_index, reg_t variable_reg, int variable_index) { - script_t *script; + Script *script; VERIFY(check(reg.segment), "invalid seg id"); VERIFY(heap[reg.segment], "invalid mem"); @@ -717,7 +717,7 @@ static void SegManager::sm_set_variables(reg_t reg, int obj_index, reg_t variabl } #endif -inline int SegManager::relocateBlock(reg_t *block, int block_location, int block_items, seg_id_t segment, int location) { +inline int SegManager::relocateBlock(reg_t *block, int block_location, int block_items, SegmentId segment, int location) { int rel = location - block_location; int index; @@ -740,20 +740,20 @@ inline int SegManager::relocateBlock(reg_t *block, int block_location, int block return 1; } -inline int SegManager::relocateLocal(script_t *scr, seg_id_t segment, int location) { +inline int SegManager::relocateLocal(Script *scr, SegmentId segment, int location) { if (scr->locals_block) return relocateBlock(scr->locals_block->locals, scr->locals_offset, scr->locals_block->nr, segment, location); else return 0; // No hands, no cookies } -inline int SegManager::relocateObject(object_t *obj, seg_id_t segment, int location) { +inline int SegManager::relocateObject(Object *obj, SegmentId segment, int location) { return relocateBlock(obj->variables, obj->pos.offset, obj->variables_nr, segment, location); } void SegManager::scriptAddCodeBlock(reg_t location) { - mem_obj_t *mobj = heap[location.segment]; - script_t *scr; + MemObject *mobj = heap[location.segment]; + Script *scr; int index; VERIFY(!(location.segment >= heap_size || mobj->type != MEM_OBJ_SCRIPT), "Attempt to add a code block to non-script\n"); @@ -762,7 +762,7 @@ void SegManager::scriptAddCodeBlock(reg_t location) { if (++scr->code_blocks_nr > scr->code_blocks_allocated) { scr->code_blocks_allocated += DEFAULT_OBJECTS_INCREMENT; - scr->code = (code_block_t *)sci_realloc(scr->code, scr->code_blocks_allocated * sizeof(code_block_t)); + scr->code = (CodeBlock *)sci_realloc(scr->code, scr->code_blocks_allocated * sizeof(CodeBlock)); } index = scr->code_blocks_nr - 1; @@ -771,8 +771,8 @@ void SegManager::scriptAddCodeBlock(reg_t location) { } void SegManager::scriptRelocate(reg_t block) { - mem_obj_t *mobj = heap[block.segment]; - script_t *scr; + MemObject *mobj = heap[block.segment]; + Script *scr; int count; int i; @@ -823,8 +823,8 @@ void SegManager::scriptRelocate(reg_t block) { } void SegManager::heapRelocate(EngineState *s, reg_t block) { - mem_obj_t *mobj = heap[block.segment]; - script_t *scr; + MemObject *mobj = heap[block.segment]; + Script *scr; int count; int i; @@ -871,10 +871,10 @@ void SegManager::heapRelocate(EngineState *s, reg_t block) { reg_t get_class_address(EngineState *s, int classnr, int lock, reg_t caller); -object_t *SegManager::scriptObjInit0(EngineState *s, reg_t obj_pos) { - mem_obj_t *mobj = heap[obj_pos.segment]; - script_t *scr; - object_t *obj; +Object *SegManager::scriptObjInit0(EngineState *s, reg_t obj_pos) { + MemObject *mobj = heap[obj_pos.segment]; + Script *scr; + Object *obj; int id; unsigned int base = obj_pos.offset - SCRIPT_OBJECT_MAGIC_OFFSET; reg_t temp; @@ -887,11 +887,11 @@ object_t *SegManager::scriptObjInit0(EngineState *s, reg_t obj_pos) { if (!scr->objects) { scr->objects_allocated = DEFAULT_OBJECTS; - scr->objects = (object_t *)sci_malloc(sizeof(object_t) * scr->objects_allocated); + scr->objects = (Object *)sci_malloc(sizeof(Object) * scr->objects_allocated); } if (scr->objects_nr == scr->objects_allocated) { scr->objects_allocated += DEFAULT_OBJECTS_INCREMENT; - scr->objects = (object_t *)sci_realloc(scr->objects, sizeof(object_t) * scr->objects_allocated); + scr->objects = (Object *)sci_realloc(scr->objects, sizeof(Object) * scr->objects_allocated); } temp = make_reg(obj_pos.segment, base); @@ -939,10 +939,10 @@ object_t *SegManager::scriptObjInit0(EngineState *s, reg_t obj_pos) { return obj; } -object_t *SegManager::scriptObjInit11(EngineState *s, reg_t obj_pos) { - mem_obj_t *mobj = heap[obj_pos.segment]; - script_t *scr; - object_t *obj; +Object *SegManager::scriptObjInit11(EngineState *s, reg_t obj_pos) { + MemObject *mobj = heap[obj_pos.segment]; + Script *scr; + Object *obj; int id; int base = obj_pos.offset; @@ -954,11 +954,11 @@ object_t *SegManager::scriptObjInit11(EngineState *s, reg_t obj_pos) { if (!scr->objects) { scr->objects_allocated = DEFAULT_OBJECTS; - scr->objects = (object_t *)sci_malloc(sizeof(object_t) * scr->objects_allocated); + scr->objects = (Object *)sci_malloc(sizeof(Object) * scr->objects_allocated); } if (scr->objects_nr == scr->objects_allocated) { scr->objects_allocated += DEFAULT_OBJECTS_INCREMENT; - scr->objects = (object_t *)sci_realloc(scr->objects, sizeof(object_t) * scr->objects_allocated); + scr->objects = (Object *)sci_realloc(scr->objects, sizeof(Object) * scr->objects_allocated); } id = scr->obj_indices->checkKey(obj_pos.offset, true); @@ -1006,21 +1006,21 @@ object_t *SegManager::scriptObjInit11(EngineState *s, reg_t obj_pos) { return obj; } -object_t *SegManager::scriptObjInit(EngineState *s, reg_t obj_pos) { +Object *SegManager::scriptObjInit(EngineState *s, reg_t obj_pos) { if (!isSci1_1) return scriptObjInit0(s, obj_pos); else return scriptObjInit11(s, obj_pos); } -local_variables_t *SegManager::allocLocalsSegment(script_t *scr, int count) { +LocalVariables *SegManager::allocLocalsSegment(Script *scr, int count) { if (!count) { // No locals scr->locals_segment = 0; scr->locals_block = NULL; return NULL; } else { - mem_obj_t *mobj; - local_variables_t *locals; + MemObject *mobj; + LocalVariables *locals; if (scr->locals_segment) { mobj = heap[scr->locals_segment]; @@ -1039,9 +1039,9 @@ local_variables_t *SegManager::allocLocalsSegment(script_t *scr, int count) { } } -void SegManager::scriptInitialiseLocalsZero(seg_id_t seg, int count) { - mem_obj_t *mobj = heap[seg]; - script_t *scr; +void SegManager::scriptInitialiseLocalsZero(SegmentId seg, int count) { + MemObject *mobj = heap[seg]; + Script *scr; VERIFY(!(seg >= heap_size || mobj->type != MEM_OBJ_SCRIPT), "Attempt to initialize locals in non-script\n"); @@ -1053,10 +1053,10 @@ void SegManager::scriptInitialiseLocalsZero(seg_id_t seg, int count) { } void SegManager::scriptInitialiseLocals(reg_t location) { - mem_obj_t *mobj = heap[location.segment]; + MemObject *mobj = heap[location.segment]; unsigned int count; - script_t *scr; - local_variables_t *locals; + Script *scr; + LocalVariables *locals; VERIFY(!(location.segment >= heap_size || mobj->type != MEM_OBJ_SCRIPT), "Attempt to initialize locals in non-script\n"); @@ -1088,8 +1088,8 @@ void SegManager::scriptInitialiseLocals(reg_t location) { } void SegManager::scriptRelocateExportsSci11(int seg) { - mem_obj_t *mobj = heap[seg]; - script_t *scr; + MemObject *mobj = heap[seg]; + Script *scr; int i; int location; @@ -1111,8 +1111,8 @@ void SegManager::scriptRelocateExportsSci11(int seg) { } void SegManager::scriptInitialiseObjectsSci11(EngineState *s, int seg) { - mem_obj_t *mobj = heap[seg]; - script_t *scr; + MemObject *mobj = heap[seg]; + Script *scr; byte *seeker; VERIFY(!(seg >= heap_size || mobj->type != MEM_OBJ_SCRIPT), "Attempt to relocate exports in non-script\n"); @@ -1142,7 +1142,7 @@ void SegManager::scriptInitialiseObjectsSci11(EngineState *s, int seg) { seeker = scr->heap_start + 4 + getUInt16(scr->heap_start + 2) * 2; while (getUInt16(seeker) == SCRIPT_OBJECT_MAGIC_NUMBER) { reg_t reg; - object_t *obj; + Object *obj; reg.segment = seg; reg.offset = seeker - scr->buf; @@ -1164,16 +1164,16 @@ void SegManager::scriptInitialiseObjectsSci11(EngineState *s, int seg) { } } -void SegManager::scriptFreeUnusedObjects(seg_id_t seg) { - mem_obj_t *mobj = heap[seg]; - script_t *scr; +void SegManager::scriptFreeUnusedObjects(SegmentId seg) { + MemObject *mobj = heap[seg]; + Script *scr; VERIFY(!(seg >= heap_size || mobj->type != MEM_OBJ_SCRIPT), "Attempt to free unused objects in non-script\n"); scr = &(mobj->data.script); if (scr->objects_allocated > scr->objects_nr) { if (scr->objects_nr) - scr->objects = (object_t*)sci_realloc(scr->objects, sizeof(object_t) * scr->objects_nr); + scr->objects = (Object *)sci_realloc(scr->objects, sizeof(Object) * scr->objects_nr); else { if (scr->objects_allocated) free(scr->objects); @@ -1196,8 +1196,8 @@ static inline char *SegManager::dynprintf(char *msg, ...) { } */ -dstack_t *SegManager::allocateStack(int size, seg_id_t *segid) { - mem_obj_t *memobj = allocNonscriptSegment(MEM_OBJ_STACK, segid); +dstack_t *SegManager::allocateStack(int size, SegmentId *segid) { + MemObject *memobj = allocNonscriptSegment(MEM_OBJ_STACK, segid); dstack_t *retval = &(memobj->data.stack); retval->entries = (reg_t*)sci_calloc(size, sizeof(reg_t)); @@ -1206,8 +1206,8 @@ dstack_t *SegManager::allocateStack(int size, seg_id_t *segid) { return retval; } -SystemStrings *SegManager::allocateSysStrings(seg_id_t *segid) { - mem_obj_t *memobj = allocNonscriptSegment(MEM_OBJ_SYS_STRINGS, segid); +SystemStrings *SegManager::allocateSysStrings(SegmentId *segid) { + MemObject *memobj = allocNonscriptSegment(MEM_OBJ_SYS_STRINGS, segid); SystemStrings *retval = &(memobj->data.sys_strings); memset(retval, 0, sizeof(SystemString)*SYS_STRINGS_MAX); @@ -1217,9 +1217,9 @@ SystemStrings *SegManager::allocateSysStrings(seg_id_t *segid) { #if 0 // Unreferenced - removed -seg_id_t SegManager::sm_allocate_reserved_segment(char *src_name) { - seg_id_t segid; - mem_obj_t *memobj = allocNonscriptSegment(MEM_OBJ_RESERVED, &segid); +SegmentId SegManager::sm_allocate_reserved_segment(char *src_name) { + SegmentId segid; + MemObject *memobj = allocNonscriptSegment(MEM_OBJ_RESERVED, &segid); char *name = sci_strdup(src_name); memobj->data.reserved = name; @@ -1229,7 +1229,7 @@ seg_id_t SegManager::sm_allocate_reserved_segment(char *src_name) { #endif uint16 SegManager::validateExportFunc(int pubfunct, int seg) { - script_t* script; + Script* script; uint16 offset; VERIFY(check(seg), "invalid seg id"); VERIFY(heap[seg]->type == MEM_OBJ_SCRIPT, "Can only validate exports on scripts"); @@ -1249,11 +1249,11 @@ uint16 SegManager::validateExportFunc(int pubfunct, int seg) { } void SegManager::free_hunk_entry(reg_t addr) { - free_hunk(addr); + free_Hunk(addr); } -hunk_t *SegManager::alloc_hunk_entry(const char *hunk_type, int size, reg_t *reg) { - hunk_t *h = alloc_hunk(reg); +Hunk *SegManager::alloc_hunk_entry(const char *hunk_type, int size, reg_t *reg) { + Hunk *h = alloc_Hunk(reg); if (!h) return NULL; @@ -1265,25 +1265,25 @@ hunk_t *SegManager::alloc_hunk_entry(const char *hunk_type, int size, reg_t *reg return h; } -void _clone_cleanup(clone_t *clone) { +void _clone_cleanup(Clone *clone) { if (clone->variables) free(clone->variables); // Free the dynamically allocated memory part } -void _hunk_cleanup(hunk_t *hunk) { +void _hunk_cleanup(Hunk *hunk) { if (hunk->mem) free(hunk->mem); } -DEFINE_HEAPENTRY(list, 8, 4) -DEFINE_HEAPENTRY(node, 32, 16) -DEFINE_HEAPENTRY_WITH_CLEANUP(clone, 16, 4, _clone_cleanup) -DEFINE_HEAPENTRY_WITH_CLEANUP(hunk, 4, 4, _hunk_cleanup) +DEFINE_HEAPENTRY(List, 8, 4) +DEFINE_HEAPENTRY(Node, 32, 16) +DEFINE_HEAPENTRY_WITH_CLEANUP(Clone, 16, 4, _clone_cleanup) +DEFINE_HEAPENTRY_WITH_CLEANUP(Hunk, 4, 4, _hunk_cleanup) #define DEFINE_ALLOC_DEALLOC(TYPE, SEGTYPE, PLURAL) \ -TYPE##_t *SegManager::alloc_##TYPE(reg_t *addr) { \ - mem_obj_t *mobj; \ - TYPE##_table_t *table; \ +TYPE *SegManager::alloc_##TYPE(reg_t *addr) { \ + MemObject *mobj; \ + TYPE##Table *table; \ int offset; \ \ if (!TYPE##s_seg_id) { \ @@ -1300,7 +1300,7 @@ TYPE##_t *SegManager::alloc_##TYPE(reg_t *addr) { \ } \ \ void SegManager::free_##TYPE(reg_t addr) { \ - mem_obj_t *mobj = GET_SEGMENT(*this, addr.segment, SEGTYPE); \ + MemObject *mobj = GET_SEGMENT(*this, addr.segment, SEGTYPE); \ \ if (!mobj) { \ sciprintf("Attempt to free " #TYPE " from address "PREG": Invalid segment type\n", PRINT_REG(addr)); \ @@ -1310,13 +1310,13 @@ void SegManager::free_##TYPE(reg_t addr) { \ Sci::free_##TYPE##_entry(&(mobj->data.PLURAL), addr.offset); \ } -DEFINE_ALLOC_DEALLOC(clone, MEM_OBJ_CLONES, clones) -DEFINE_ALLOC_DEALLOC(list, MEM_OBJ_LISTS, lists) -DEFINE_ALLOC_DEALLOC(node, MEM_OBJ_NODES, nodes) -DEFINE_ALLOC_DEALLOC(hunk, MEM_OBJ_HUNK, hunks) +DEFINE_ALLOC_DEALLOC(Clone, MEM_OBJ_CLONES, clones) +DEFINE_ALLOC_DEALLOC(List, MEM_OBJ_LISTS, lists) +DEFINE_ALLOC_DEALLOC(Node, MEM_OBJ_NODES, nodes) +DEFINE_ALLOC_DEALLOC(Hunk, MEM_OBJ_HUNK, hunks) byte *SegManager::dereference(reg_t pointer, int *size) { - mem_obj_t *mobj; + MemObject *mobj; byte *base = NULL; int count; @@ -1388,8 +1388,8 @@ byte *SegManager::dereference(reg_t pointer, int *size) { } unsigned char *SegManager::allocDynmem(int size, const char *descr, reg_t *addr) { - seg_id_t seg; - mem_obj_t *mobj = allocNonscriptSegment(MEM_OBJ_DYNMEM, &seg); + SegmentId seg; + MemObject *mobj = allocNonscriptSegment(MEM_OBJ_DYNMEM, &seg); *addr = make_reg(seg, 0); mobj->data.dynmem.size = size; @@ -1405,7 +1405,7 @@ unsigned char *SegManager::allocDynmem(int size, const char *descr, reg_t *addr) } const char *SegManager::getDescription(reg_t addr) { - mem_obj_t *mobj = heap[addr.segment]; + MemObject *mobj = heap[addr.segment]; if (addr.segment >= heap_size) return ""; @@ -1437,9 +1437,9 @@ void SegManager::dbgPrint(const char* msg, void *i) { // ------------------- Segment interface ------------------ -SegInterface::SegInterface(SegManager *segmgr, mem_obj_t *mobj, seg_id_t segId, memObjType typeId) : +SegInterface::SegInterface(SegManager *segmgr, MemObject *mobj, SegmentId segId, memObjType typeId) : _segmgr(segmgr), _mobj(mobj), _segId(segId), _typeId(typeId) { - VERIFY(_mobj->type == _typeId, "Invalid mem_obj_t type"); + VERIFY(_mobj->type == _typeId, "Invalid MemObject type"); } reg_t SegInterface::findCanonicAddress(reg_t addr) { @@ -1459,7 +1459,7 @@ void SegInterface::listAllOutgoingReferences(EngineState *s, reg_t object, void //-------------------- base -------------------- class SegInterfaceBase : public SegInterface { protected: - SegInterfaceBase(SegManager *segmgr, mem_obj_t *mobj, seg_id_t segId, memObjType typeId) : + SegInterfaceBase(SegManager *segmgr, MemObject *mobj, SegmentId segId, memObjType typeId) : SegInterface(segmgr, mobj, segId, typeId) {} public: reg_t findCanonicAddress(reg_t addr); @@ -1479,14 +1479,14 @@ void SegInterfaceBase::listAllDeallocatable(void *param, void (*note)(void *para //-------------------- script -------------------- class SegInterfaceScript : public SegInterfaceBase { public: - SegInterfaceScript(SegManager *segmgr, mem_obj_t *mobj, seg_id_t segId) : + SegInterfaceScript(SegManager *segmgr, MemObject *mobj, SegmentId segId) : SegInterfaceBase(segmgr, mobj, segId, MEM_OBJ_SCRIPT) {} void freeAtAddress(reg_t addr); void listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, void (*note)(void *param, reg_t addr)); }; void SegInterfaceScript::freeAtAddress(reg_t addr) { - script_t *script = &(_mobj->data.script); + Script *script = &(_mobj->data.script); /* sciprintf("[GC] Freeing script "PREG"\n", PRINT_REG(addr)); if (script->locals_segment) @@ -1498,12 +1498,12 @@ void SegInterfaceScript::freeAtAddress(reg_t addr) { } void SegInterfaceScript::listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, void (*note)(void *param, reg_t addr)) { - script_t *script = &(_mobj->data.script); + Script *script = &(_mobj->data.script); if (addr.offset <= script->buf_size && addr.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET && RAW_IS_OBJECT(script->buf + addr.offset)) { int idx = RAW_GET_CLASS_INDEX(script, addr); if (idx >= 0 && idx < script->objects_nr) { - object_t *obj = script->objects + idx; + Object *obj = script->objects + idx; int i; // Note all local variables, if we have a local variable environment @@ -1523,7 +1523,7 @@ void SegInterfaceScript::listAllOutgoingReferences(EngineState *s, reg_t addr, v #define LIST_ALL_DEALLOCATABLE(kind, kind_field) \ - kind##_table_t * table = &(_mobj->data.kind_field); \ + kind##Table * table = &(_mobj->data.kind_field); \ int i; \ \ for (i = 0; i < table->max_entry; i++) \ @@ -1534,7 +1534,7 @@ void SegInterfaceScript::listAllOutgoingReferences(EngineState *s, reg_t addr, v //-------------------- clones -------------------- class SegInterfaceClones : public SegInterface { public: - SegInterfaceClones(SegManager *segmgr, mem_obj_t *mobj, seg_id_t segId) : + SegInterfaceClones(SegManager *segmgr, MemObject *mobj, SegmentId segId) : SegInterface(segmgr, mobj, segId, MEM_OBJ_CLONES) {} void freeAtAddress(reg_t addr); void listAllDeallocatable(void *param, void (*note)(void *param, reg_t addr)); @@ -1542,12 +1542,12 @@ public: }; void SegInterfaceClones::listAllDeallocatable(void *param, void (*note)(void *param, reg_t addr)) { - LIST_ALL_DEALLOCATABLE(clone, clones); + LIST_ALL_DEALLOCATABLE(Clone, clones); } void SegInterfaceClones::listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, void (*note)(void *param, reg_t addr)) { - clone_table_t *clone_table = &(_mobj->data.clones); - clone_t *clone; + CloneTable *clone_table = &(_mobj->data.clones); + Clone *clone; int i; assert(addr.segment == _segId); @@ -1570,7 +1570,7 @@ void SegInterfaceClones::listAllOutgoingReferences(EngineState *s, reg_t addr, v } void SegInterfaceClones::freeAtAddress(reg_t addr) { - object_t *victim_obj; + Object *victim_obj; assert(addr.segment == _segId); @@ -1590,14 +1590,14 @@ void SegInterfaceClones::freeAtAddress(reg_t addr) { */ free(victim_obj->variables); victim_obj->variables = NULL; - _segmgr->free_clone(addr); + _segmgr->free_Clone(addr); } //-------------------- locals -------------------- class SegInterfaceLocals : public SegInterface { public: - SegInterfaceLocals(SegManager *segmgr, mem_obj_t *mobj, seg_id_t segId) : + SegInterfaceLocals(SegManager *segmgr, MemObject *mobj, SegmentId segId) : SegInterface(segmgr, mobj, segId, MEM_OBJ_LOCALS) {} reg_t findCanonicAddress(reg_t addr); void freeAtAddress(reg_t addr); @@ -1605,9 +1605,9 @@ public: }; reg_t SegInterfaceLocals::findCanonicAddress(reg_t addr) { - local_variables_t *locals = &(_mobj->data.locals); + LocalVariables *locals = &(_mobj->data.locals); // Reference the owning script - seg_id_t owner_seg = _segmgr->segGet(locals->script_id); + SegmentId owner_seg = _segmgr->segGet(locals->script_id); assert(owner_seg >= 0); @@ -1620,7 +1620,7 @@ void SegInterfaceLocals::freeAtAddress(reg_t sub_addr) { } void SegInterfaceLocals::listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, void (*note)(void*param, reg_t addr)) { - local_variables_t *locals = &(_mobj->data.locals); + LocalVariables *locals = &(_mobj->data.locals); int i; assert(addr.segment == _segId); @@ -1633,7 +1633,7 @@ void SegInterfaceLocals::listAllOutgoingReferences(EngineState *s, reg_t addr, v //-------------------- stack -------------------- class SegInterfaceStack : public SegInterface { public: - SegInterfaceStack(SegManager *segmgr, mem_obj_t *mobj, seg_id_t segId) : + SegInterfaceStack(SegManager *segmgr, MemObject *mobj, SegmentId segId) : SegInterface(segmgr, mobj, segId, MEM_OBJ_STACK) {} reg_t findCanonicAddress(reg_t addr); void listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, void (*note)(void *param, reg_t addr)); @@ -1656,7 +1656,7 @@ void SegInterfaceStack::listAllOutgoingReferences(EngineState *s, reg_t addr, vo //-------------------- system strings -------------------- class SegInterfaceSysStrings : public SegInterface { public: - SegInterfaceSysStrings(SegManager *segmgr, mem_obj_t *mobj, seg_id_t segId) : + SegInterfaceSysStrings(SegManager *segmgr, MemObject *mobj, SegmentId segId) : SegInterface(segmgr, mobj, segId, MEM_OBJ_SYS_STRINGS) {} }; @@ -1664,7 +1664,7 @@ public: //-------------------- lists -------------------- class SegInterfaceLists : public SegInterface { public: - SegInterfaceLists(SegManager *segmgr, mem_obj_t *mobj, seg_id_t segId) : + SegInterfaceLists(SegManager *segmgr, MemObject *mobj, SegmentId segId) : SegInterface(segmgr, mobj, segId, MEM_OBJ_LISTS) {} void freeAtAddress(reg_t addr); void listAllDeallocatable(void *param, void (*note)(void *param, reg_t addr)); @@ -1672,16 +1672,16 @@ public: }; void SegInterfaceLists::freeAtAddress(reg_t sub_addr) { - _segmgr->free_list(sub_addr); + _segmgr->free_List(sub_addr); } void SegInterfaceLists::listAllDeallocatable(void *param, void (*note)(void*param, reg_t addr)) { - LIST_ALL_DEALLOCATABLE(list, lists); + LIST_ALL_DEALLOCATABLE(List, lists); } void SegInterfaceLists::listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, void (*note)(void*param, reg_t addr)) { - list_table_t *table = &(_mobj->data.lists); - list_t *list = &(table->table[addr.offset].entry); + ListTable *table = &(_mobj->data.lists); + List *list = &(table->table[addr.offset].entry); if (!ENTRY_IS_VALID(table, addr.offset)) { fprintf(stderr, "Invalid list referenced for outgoing references: "PREG"\n", PRINT_REG(addr)); @@ -1698,7 +1698,7 @@ void SegInterfaceLists::listAllOutgoingReferences(EngineState *s, reg_t addr, vo //-------------------- nodes -------------------- class SegInterfaceNodes : public SegInterface { public: - SegInterfaceNodes(SegManager *segmgr, mem_obj_t *mobj, seg_id_t segId) : + SegInterfaceNodes(SegManager *segmgr, MemObject *mobj, SegmentId segId) : SegInterface(segmgr, mobj, segId, MEM_OBJ_NODES) {} void freeAtAddress(reg_t addr); void listAllDeallocatable(void *param, void (*note)(void *param, reg_t addr)); @@ -1706,16 +1706,16 @@ public: }; void SegInterfaceNodes::freeAtAddress(reg_t sub_addr) { - _segmgr->free_node(sub_addr); + _segmgr->free_Node(sub_addr); } void SegInterfaceNodes::listAllDeallocatable(void *param, void (*note)(void*param, reg_t addr)) { - LIST_ALL_DEALLOCATABLE(node, nodes); + LIST_ALL_DEALLOCATABLE(Node, nodes); } void SegInterfaceNodes::listAllOutgoingReferences(EngineState *s, reg_t addr, void *param, void (*note)(void*param, reg_t addr)) { - node_table_t *table = &(_mobj->data.nodes); - node_t *node = &(table->table[addr.offset].entry); + NodeTable *table = &(_mobj->data.nodes); + Node *node = &(table->table[addr.offset].entry); if (!ENTRY_IS_VALID(table, addr.offset)) { fprintf(stderr, "Invalid node referenced for outgoing references: "PREG"\n", PRINT_REG(addr)); @@ -1734,7 +1734,7 @@ void SegInterfaceNodes::listAllOutgoingReferences(EngineState *s, reg_t addr, vo //-------------------- hunk -------------------- class SegInterfaceHunk : public SegInterface { public: - SegInterfaceHunk(SegManager *segmgr, mem_obj_t *mobj, seg_id_t segId) : + SegInterfaceHunk(SegManager *segmgr, MemObject *mobj, SegmentId segId) : SegInterface(segmgr, mobj, segId, MEM_OBJ_HUNK) {} void freeAtAddress(reg_t addr); void listAllDeallocatable(void *param, void (*note)(void *param, reg_t addr)); @@ -1746,14 +1746,14 @@ void SegInterfaceHunk::freeAtAddress(reg_t sub_addr) { } void SegInterfaceHunk::listAllDeallocatable(void *param, void (*note)(void*param, reg_t addr)) { - LIST_ALL_DEALLOCATABLE(hunk, hunks); + LIST_ALL_DEALLOCATABLE(Hunk, hunks); } //-------------------- dynamic memory -------------------- class SegInterfaceDynMem : public SegInterfaceBase { public: - SegInterfaceDynMem(SegManager *segmgr, mem_obj_t *mobj, seg_id_t segId) : + SegInterfaceDynMem(SegManager *segmgr, MemObject *mobj, SegmentId segId) : SegInterfaceBase(segmgr, mobj, segId, MEM_OBJ_DYNMEM) {} void freeAtAddress(reg_t addr); }; @@ -1767,17 +1767,17 @@ void SegInterfaceDynMem::freeAtAddress(reg_t sub_addr) { //-------------------- reserved -------------------- class SegInterfaceReserved : public SegInterface { public: - SegInterfaceReserved(SegManager *segmgr, mem_obj_t *mobj, seg_id_t segId) : + SegInterfaceReserved(SegManager *segmgr, MemObject *mobj, SegmentId segId) : SegInterface(segmgr, mobj, segId, MEM_OBJ_RESERVED) {} }; -SegInterface *SegManager::getSegInterface(seg_id_t segid) { +SegInterface *SegManager::getSegInterface(SegmentId segid) { if (!check(segid)) return NULL; // Invalid segment SegInterface *retval = NULL; - mem_obj_t *mobj = heap[segid]; + MemObject *mobj = heap[segid]; switch (mobj->type) { case MEM_OBJ_SCRIPT: retval = new SegInterfaceScript(this, mobj, segid); diff --git a/engines/sci/engine/seg_manager.h b/engines/sci/engine/seg_manager.h index 0dc4b3755b..1a4f9c53c6 100644 --- a/engines/sci/engine/seg_manager.h +++ b/engines/sci/engine/seg_manager.h @@ -69,7 +69,7 @@ public: // 1. Scripts - void freeScript(mem_obj_t* mem); + void freeScript(MemObject* mem); // Allocate a script into the segment manager // Parameters: (int) script_nr: number of the script to load @@ -77,7 +77,7 @@ public: // script data // Returns : (int) 0 on failure, 1 on success // (int) *seg_id: The segment ID of the newly allocated segment, on success - mem_obj_t *allocateScript(EngineState *s, int script_nr, int* seg_id); + MemObject *allocateScript(EngineState *s, int script_nr, int* seg_id); // The script must then be initialised; see section (1b.), below. @@ -164,10 +164,10 @@ public: // i.e. loading and linking. // Initializes a script's local variable block - // Parameters: (seg_id_t) seg: Segment containing the script to initialize + // Parameters: (SegmentId) seg: Segment containing the script to initialize // (int) nr: Number of local variables to allocate // All variables are initialized to zero. - void scriptInitialiseLocalsZero(seg_id_t seg, int nr); + void scriptInitialiseLocalsZero(SegmentId seg, int nr); // Initializes a script's local variable block according to a prototype // Parameters: (reg_t) location: Location to initialize from @@ -175,11 +175,11 @@ public: // Initializes an object within the segment manager // Parameters: (reg_t) obj_pos: Location (segment, offset) of the object - // Returns : (object_t *) A newly created object_t describing the object + // Returns : (Object *) A newly created Object describing the object // obj_pos must point to the beginning of the script/class block (as opposed // to what the VM considers to be the object location) - // The corresponding object_t is stored within the relevant script. - object_t *scriptObjInit(EngineState *s, reg_t obj_pos); + // The corresponding Object is stored within the relevant script. + Object *scriptObjInit(EngineState *s, reg_t obj_pos); // Informs the segment manager that a code block must be relocated // Parameters: (reg_t) location: Start of block to relocate @@ -191,16 +191,16 @@ public: // Processes a relocation block witin a script // Parameters: (reg_t) obj_pos: Location (segment, offset) of the block - // Returns : (object_t *) Location of the relocation block + // Returns : (Object *) Location of the relocation block // 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); // Deallocates all unused but allocated entries for objects - // Parameters: (seg_id_t) segid: segment of the script to prune in this way + // Parameters: (SegmentId) segid: segment of the script to prune in this way // These entries are created during script instantiation; deallocating them // frees up some additional memory. - void scriptFreeUnusedObjects(seg_id_t segid); + void scriptFreeUnusedObjects(SegmentId segid); // Sets the script-relative offset of the exports table // Parameters: (int) offset: The script-relative exports table offset @@ -242,22 +242,22 @@ public: void unmarkScriptDeleted(int script_nr); // Determines whether the script referenced by the indicated segment is marked as being deleted. - // Parameters: (seg_id_t) Segment ID of the script to investigate + // Parameters: (SegmentId) Segment ID of the script to investigate // 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. - int scriptIsMarkedAsDeleted(seg_id_t seg); + int scriptIsMarkedAsDeleted(SegmentId seg); // 2. Clones // Allocate a fresh clone - // Returns : (clone_t*): Reference to the memory allocated for the clone + // Returns : (Clone*): Reference to the memory allocated for the clone // (reg_t) *addr: The offset of the freshly allocated clone - clone_t *alloc_clone(reg_t *addr); + Clone *alloc_Clone(reg_t *addr); - // Deallocates a clone - // Parameters: (reg_t) addr: Offset of the clone scheduled for termination - void free_clone(reg_t addr); + // Deallocates a Clone + // Parameters: (reg_t) addr: Offset of the Clone scheduled for termination + void free_Clone(reg_t addr); // 3. Objects (static, from Scripts, and dynmic, from Clones) @@ -291,16 +291,17 @@ public: // Allocates a data stack // Parameters: (int) size: Number of stack entries to reserve // Returns : (dstack_t *): The physical stack - // (seg_id_t) segid: Segment ID of the stack - dstack_t *allocateStack(int size, seg_id_t *segid); + // (SegmentId) segid: Segment ID of the stack + dstack_t *allocateStack(int size, SegmentId *segid); // 5. System Strings // Allocates a system string table // Returns : (dstack_t *): The physical stack - // (seg_id_t) segid: Segment ID of the stack - SystemStrings *allocateSysStrings(seg_id_t *segid); + // (SegmentId) segid: Segment ID of the stack + // See also sys_string_acquire(); + SystemStrings *allocateSysStrings(SegmentId *segid); // 6, 7. Lists and Nodes @@ -308,20 +309,20 @@ public: // 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 - list_t *alloc_list(reg_t *addr); + List *alloc_List(reg_t *addr); // Deallocates a list // Parameters: (reg_t) addr: Offset of the list scheduled for termination - void free_list(reg_t addr); + void free_List(reg_t addr); // 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 - node_t *alloc_node(reg_t *addr); + Node *alloc_Node(reg_t *addr); // Deallocates a list node // Parameters: (reg_t) addr: Offset of the node scheduled for termination - void free_node(reg_t addr); + void free_Node(reg_t addr); // 8. Hunk Memory @@ -330,9 +331,9 @@ public: // 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 - // Returns : (hunk_t*): Reference to the memory allocated for the hunk piece + // Returns : (Hunk *): Reference to the memory allocated for the hunk piece // (reg_t) *addr: The offset of the freshly allocated hunk entry - hunk_t *alloc_hunk_entry(const char *hunk_type, int size, reg_t *addr); + Hunk *alloc_hunk_entry(const char *hunk_type, int size, reg_t *addr); // Deallocates a hunk entry // Parameters: (reg_t) addr: Offset of the hunk entry to delete @@ -367,7 +368,7 @@ public: // 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. - //seg_id_t sm_allocate_reserved_segment(char *name); + //SegmentId sm_allocate_reserved_segment(char *name); // Generic Operations on Segments and Addresses @@ -382,21 +383,21 @@ public: // Segment Interface // Retrieves the segment interface to the specified segment - // Parameters: (seg_id_t) segid: ID of the segment to look up + // Parameters: (SegmentId) segid: ID of the segment to look up // Returns : (SegInterface *): An interface to the specified segment ID, or NULL on error // The returned interface must be deleted after use - SegInterface *getSegInterface(seg_id_t segid); + SegInterface *getSegInterface(SegmentId segid); void heapRelocate(EngineState *s, reg_t block); void scriptRelocateExportsSci11(int seg); void scriptInitialiseObjectsSci11(EngineState *s, int seg); int scriptMarkedDeleted(int script_nr); - int initialiseScript(mem_obj_t *mem, EngineState *s, int script_nr); + int initialiseScript(MemObject *mem, EngineState *s, int script_nr); public: // TODO: make private IntMapper *id_seg_map; // id - script id; seg - index of heap - mem_obj_t **heap; + MemObject **heap; int heap_size; // size of the heap int reserved_id; int exports_wide; @@ -408,28 +409,28 @@ public: // TODO: make private // memory is tagged as size_t mem_allocated; // Total amount of memory allocated - seg_id_t clones_seg_id; // ID of the (a) clones segment - seg_id_t lists_seg_id; // ID of the (a) list segment - seg_id_t nodes_seg_id; // ID of the (a) node segment - seg_id_t hunks_seg_id; // ID of the (a) hunk segment + 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 private: - mem_obj_t *allocNonscriptSegment(memObjType type, seg_id_t *segid); - local_variables_t *allocLocalsSegment(script_t *scr, int count); - mem_obj_t *memObjAllocate(seg_id_t segid, int hash_id, memObjType type); + MemObject *allocNonscriptSegment(memObjType type, SegmentId *segid); + LocalVariables *allocLocalsSegment(Script *scr, int count); + MemObject *memObjAllocate(SegmentId segid, int hash_id, memObjType type); int deallocate(int seg, bool recursive); - hunk_t *alloc_hunk(reg_t *); - void free_hunk(reg_t addr); + Hunk *alloc_Hunk(reg_t *); + void free_Hunk(reg_t addr); - inline int relocateLocal(script_t *scr, seg_id_t segment, int location); - inline int relocateBlock(reg_t *block, int block_location, int block_items, seg_id_t segment, int location); - inline int relocateObject(object_t *obj, seg_id_t segment, int location); + inline int relocateLocal(Script *scr, SegmentId segment, int location); + inline int relocateBlock(reg_t *block, int block_location, int block_items, SegmentId segment, int location); + inline int relocateObject(Object *obj, SegmentId segment, int location); inline int findFreeId(int *id); - static void setScriptSize(mem_obj_t *mem, EngineState *s, int script_nr); - object_t *scriptObjInit0(EngineState *s, reg_t obj_pos); - object_t *scriptObjInit11(EngineState *s, reg_t obj_pos); + static void setScriptSize(MemObject *mem, EngineState *s, int script_nr); + Object *scriptObjInit0(EngineState *s, reg_t obj_pos); + Object *scriptObjInit11(EngineState *s, reg_t obj_pos); /* Check segment validity ** Parameters: (int) seg: The segment to validate @@ -451,7 +452,7 @@ private: class SegInterface { protected: - SegInterface(SegManager *segmgr, mem_obj_t *mobj, seg_id_t segId, memObjType typeId); + SegInterface(SegManager *segmgr, MemObject *mobj, SegmentId segId, memObjType typeId); public: // Deallocates the segment interface @@ -481,15 +482,15 @@ public: virtual void listAllOutgoingReferences(EngineState *s, reg_t object, void *param, void (*note)(void *param, reg_t addr)); // Get the memory object - mem_obj_t *getMobj() { return _mobj; } + MemObject *getMobj() { return _mobj; } // Get the segment type memObjType getType() { return _typeId; } protected: SegManager *_segmgr; - mem_obj_t *_mobj; - seg_id_t _segId; + MemObject *_mobj; + SegmentId _segId; private: memObjType _typeId; // Segment type diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h index 55f4c667ea..0d18812e03 100644 --- a/engines/sci/engine/state.h +++ b/engines/sci/engine/state.h @@ -207,7 +207,7 @@ struct EngineState { /* VM Information */ - exec_stack_t *execution_stack; /* The execution stack */ + ExecStack *execution_stack; /* The execution stack */ int execution_stack_size; /* Number of stack frames allocated */ int execution_stack_pos; /* Position on the execution stack */ int execution_stack_base; /* When called from kernel functions, the vm @@ -223,25 +223,25 @@ struct EngineState { unsigned int r_amp_rest; /* &rest register (only used for save games) */ reg_t r_prev; /* previous comparison result */ - seg_id_t stack_segment; /* Heap area for the stack to use */ - stack_ptr_t stack_base; /* Pointer to the least stack element */ - stack_ptr_t stack_top; /* First invalid stack element */ + SegmentId stack_segment; /* Heap area for the stack to use */ + StackPtr stack_base; /* Pointer to the least stack element */ + StackPtr stack_top; /* First invalid stack element */ - seg_id_t parser_segment; /* A heap area used by the parser for error reporting */ + SegmentId parser_segment; /* A heap area used by the parser for error reporting */ reg_t parser_base; /* Base address for the parser error reporting mechanism */ reg_t parser_event; /* The event passed to Parse() and later used by Said() */ - seg_id_t script_000_segment; - script_t *script_000; /* script 000, e.g. for globals */ + SegmentId script_000_segment; + Script *script_000; /* script 000, e.g. for globals */ int parser_lastmatch_word; /* Position of the input word the parser last matched on, or SAID_NO_MATCH */ /* Debugger data: */ - breakpoint_t *bp_list; /* List of breakpoints */ + Breakpoint *bp_list; /* List of breakpoints */ int have_bp; /* Bit mask specifying which types of breakpoints are used in bp_list */ unsigned int debug_mode; /* Contains flags for the various debug modes */ /* System strings */ - seg_id_t sys_strings_segment; + SegmentId sys_strings_segment; SystemStrings *sys_strings; /* Parser data: */ @@ -262,7 +262,7 @@ struct EngineState { reg_t game_obj; /* Pointer to the game object */ int classtable_size; /* Number of classes in the table- for debugging */ - class_t *classtable; /* Table of all classes */ + Class *classtable; /* Table of all classes */ SegManager *seg_manager; int gc_countdown; /* Number of kernel calls until next gc */ diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index 89077cf35e..7ce8bf0f08 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -56,7 +56,7 @@ extern int _debug_seeking; extern int _weak_validations; -calls_struct_t *send_calls = NULL; +CallsStruct *send_calls = NULL; int send_calls_allocated = 0; int bp_flag = 0; static reg_t _dummy_register; @@ -65,7 +65,7 @@ static reg_t _dummy_register; #ifndef DISABLE_VALIDATIONS -static inline reg_t &validate_property(object_t *obj, int index) { +static inline reg_t &validate_property(Object *obj, int index) { if (!obj) { if (sci_debug_flags & 4) sciprintf("[VM] Sending to disposed object!\n"); @@ -85,7 +85,7 @@ static inline reg_t &validate_property(object_t *obj, int index) { return obj->variables[index]; } -static inline stack_ptr_t validate_stack_addr(EngineState *s, stack_ptr_t sp) { +static inline StackPtr validate_stack_addr(EngineState *s, StackPtr sp) { if (sp >= s->stack_base && sp < s->stack_top) return sp; @@ -200,7 +200,7 @@ int script_error(EngineState *s, const char *file, int line, const char *reason) #define CORE_ERROR(area, msg) script_error(s, "[" area "] " __FILE__, __LINE__, msg) reg_t get_class_address(EngineState *s, int classnr, int lock, reg_t caller) { - class_t *the_class = s->classtable + classnr; + Class *the_class = s->classtable + classnr; if (NULL == s) { sciprintf("vm.c: get_class_address(): NULL passed for \"s\"\n"); @@ -252,7 +252,7 @@ reg_t get_class_address(EngineState *s, int classnr, int lock, reg_t caller) { #define OBJ_SUPERCLASS(s, reg) SEG_GET_HEAP(s, make_reg(reg.segment, reg.offset + SCRIPT_SUPERCLASS_OFFSET)) // Returns an object's superclass -inline exec_stack_t *execute_method(EngineState *s, uint16 script, uint16 pubfunct, stack_ptr_t sp, reg_t calling_obj, uint16 argc, stack_ptr_t argp) { +inline ExecStack *execute_method(EngineState *s, uint16 script, uint16 pubfunct, StackPtr sp, reg_t calling_obj, uint16 argc, StackPtr argp) { int seg; uint16 temp; @@ -273,7 +273,7 @@ inline exec_stack_t *execute_method(EngineState *s, uint16 script, uint16 pubfun // Check if a breakpoint is set on this method if (s->have_bp & BREAK_EXPORT) { - breakpoint_t *bp; + Breakpoint *bp; uint32 bpaddress; bpaddress = (script << 16 | pubfunct); @@ -311,7 +311,7 @@ static void _exec_varselectors(EngineState *s) { } } -exec_stack_t *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, stack_ptr_t sp, int framesize, stack_ptr_t argp) { +ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPtr sp, int framesize, StackPtr argp) { // send_obj and work_obj are equal for anything but 'super' // Returns a pointer to the TOS exec_stack element #ifdef VM_DEBUG_SEND @@ -322,15 +322,15 @@ exec_stack_t *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, stac int selector; int argc; int origin = s->execution_stack_pos; // Origin: Used for debugging - exec_stack_t *retval = s->execution_stack + s->execution_stack_pos; + ExecStack *retval = s->execution_stack + s->execution_stack_pos; int print_send_action = 0; - // We return a pointer to the new active exec_stack_t + // We return a pointer to the new active ExecStack // The selector calls we catch are stored below: int send_calls_nr = -1; if (NULL == s) { - sciprintf("vm.c: exec_stack_t(): NULL passed for \"s\"\n"); + sciprintf("vm.c: ExecStack(): NULL passed for \"s\"\n"); return NULL; } @@ -345,7 +345,7 @@ exec_stack_t *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, stac // Check if a breakpoint is set on this method if (s->have_bp & BREAK_SELECTOR) { - breakpoint_t *bp; + Breakpoint *bp; char method_name [256]; sprintf(method_name, "%s::%s", obj_get_name(s, send_obj), s->_selectorNames[selector].c_str()); @@ -372,17 +372,17 @@ exec_stack_t *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, stac if (++send_calls_nr == (send_calls_allocated - 1)) { send_calls_allocated *= 2; - send_calls = (calls_struct_t *)sci_realloc(send_calls, sizeof(calls_struct_t) * send_calls_allocated); + send_calls = (CallsStruct *)sci_realloc(send_calls, sizeof(CallsStruct) * send_calls_allocated); } switch (lookup_selector(s, send_obj, selector, &varp, &funcp)) { - case SELECTOR_NONE: + case kSelectorNone: sciprintf("Send to invalid selector 0x%x of object at "PREG"\n", 0xffff & selector, PRINT_REG(send_obj)); script_error_flag = script_debug_flag = 1; --send_calls_nr; break; - case SELECTOR_VARIABLE: + case kSelectorVariable: #ifdef VM_DEBUG_SEND sciprintf("Varselector: "); @@ -428,7 +428,7 @@ exec_stack_t *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, stac } break; - case SELECTOR_METHOD: + case kSelectorMethod: #ifdef VM_DEBUG_SEND sciprintf("Funcselector("); @@ -475,8 +475,8 @@ exec_stack_t *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, stac return retval; } -exec_stack_t *add_exec_stack_varselector(EngineState *s, reg_t objp, int argc, stack_ptr_t argp, selector_t selector, reg_t *address, int origin) { - exec_stack_t *xstack = add_exec_stack_entry(s, NULL_REG, address, objp, argc, argp, selector, objp, origin, SCI_XS_CALLEE_LOCALS); +ExecStack *add_exec_stack_varselector(EngineState *s, reg_t objp, int argc, StackPtr argp, Selector selector, reg_t *address, int origin) { + ExecStack *xstack = add_exec_stack_entry(s, NULL_REG, address, objp, argc, argp, selector, objp, origin, SCI_XS_CALLEE_LOCALS); // Store selector address in sp xstack->addr.varp = address; @@ -485,17 +485,17 @@ exec_stack_t *add_exec_stack_varselector(EngineState *s, reg_t objp, int argc, s return xstack; } -exec_stack_t *add_exec_stack_entry(EngineState *s, reg_t pc, stack_ptr_t sp, reg_t objp, int argc, - stack_ptr_t argp, selector_t selector, reg_t sendp, int origin, seg_id_t locals_segment) { +ExecStack *add_exec_stack_entry(EngineState *s, reg_t pc, StackPtr sp, reg_t objp, int argc, + StackPtr argp, Selector selector, reg_t sendp, int origin, SegmentId locals_segment) { // Returns new TOS element for the execution stack // locals_segment may be -1 if derived from the called object - exec_stack_t *xstack = NULL; + ExecStack *xstack = NULL; if (!s->execution_stack) - s->execution_stack = (exec_stack_t *)sci_malloc(sizeof(exec_stack_t) * (s->execution_stack_size = 16)); + s->execution_stack = (ExecStack *)sci_malloc(sizeof(ExecStack) * (s->execution_stack_size = 16)); if (++(s->execution_stack_pos) == s->execution_stack_size) // Out of stack space? - s->execution_stack = (exec_stack_t*)sci_realloc(s->execution_stack, sizeof(exec_stack_t) * (s->execution_stack_size += 8)); + s->execution_stack = (ExecStack*)sci_realloc(s->execution_stack, sizeof(ExecStack) * (s->execution_stack_size += 8)); //sciprintf("Exec stack: [%d/%d], origin %d, at %p\n", s->execution_stack_pos, s->execution_stack_size, origin, s->execution_stack); @@ -534,8 +534,8 @@ void vm_handle_fatal_error(EngineState *s, int line, const char *file) { error("Could not recover, exitting...\n"); } -static inline script_t *script_locate_by_segment(EngineState *s, seg_id_t seg) { - mem_obj_t *memobj = GET_SEGMENT(*s->seg_manager, seg, MEM_OBJ_SCRIPT); +static inline Script *script_locate_by_segment(EngineState *s, SegmentId seg) { + MemObject *memobj = GET_SEGMENT(*s->seg_manager, seg, MEM_OBJ_SCRIPT); if (memobj) return &(memobj->data.script); @@ -543,7 +543,7 @@ static inline script_t *script_locate_by_segment(EngineState *s, seg_id_t seg) { } static reg_t pointer_add(EngineState *s, reg_t base, int offset) { - mem_obj_t *mobj = GET_SEGMENT_ANY(*s->seg_manager, base.segment); + MemObject *mobj = GET_SEGMENT_ANY(*s->seg_manager, base.segment); if (!mobj) { script_debug_flag = script_error_flag = 1; @@ -583,7 +583,7 @@ static byte _fake_return_buffer[2] = {op_ret << 1, op_ret << 1}; void run_vm(EngineState *s, int restoring) { reg_t *variables[4]; // global, local, temp, param, as immediate pointers reg_t *variables_base[4]; // Used for referencing VM ops - seg_id_t variables_seg[4]; // Same as above, contains segment IDs + SegmentId variables_seg[4]; // Same as above, contains segment IDs #ifndef DISABLE_VALIDATIONS int variables_max[4]; // Max. values for all variables unsigned int code_buf_size = 0 ; // (Avoid spurious warning) @@ -591,16 +591,16 @@ void run_vm(EngineState *s, int restoring) { int temp; int16 aux_acc; // Auxiliary 16 bit accumulator reg_t r_temp; // Temporary register - stack_ptr_t s_temp; // Temporary stack pointer + StackPtr s_temp; // Temporary stack pointer int16 opparams[4]; // opcode parameters int restadjust = s->r_amp_rest; // &rest adjusts the parameter count by this value // Current execution data: - exec_stack_t *xs = s->execution_stack + s->execution_stack_pos; - exec_stack_t *xs_new = NULL; - object_t *obj = obj_get(s, xs->objp); - script_t *local_script = script_locate_by_segment(s, xs->local_segment); + ExecStack *xs = s->execution_stack + s->execution_stack_pos; + ExecStack *xs_new = NULL; + Object *obj = obj_get(s, xs->objp); + Script *local_script = script_locate_by_segment(s, xs->local_segment); int old_execution_stack_base = s->execution_stack_base; // Used to detect the stack bottom, for "physical" returns byte *code_buf = NULL; // (Avoid spurious warning) @@ -643,7 +643,7 @@ void run_vm(EngineState *s, int restoring) { while (1) { byte opcode; int old_pc_offset; - stack_ptr_t old_sp = xs->sp; + StackPtr old_sp = xs->sp; byte opnumber; int var_type; // See description below int var_number; @@ -651,7 +651,7 @@ void run_vm(EngineState *s, int restoring) { old_pc_offset = xs->addr.pc.offset; if (s->execution_stack_pos_changed) { - script_t *scr; + Script *scr; xs = s->execution_stack + s->execution_stack_pos; s->execution_stack_pos_changed = 0; @@ -995,7 +995,7 @@ void run_vm(EngineState *s, int restoring) { case 0x20: { // call int argc = (opparams[1] >> 1) // Given as offset, but we need count + 1 + restadjust; - stack_ptr_t call_base = xs->sp - argc; + StackPtr call_base = xs->sp - argc; xs->sp[1].offset += restadjust; xs_new = add_exec_stack_entry(s, make_reg(xs->addr.pc.segment, xs->addr.pc.offset + opparams[0]), @@ -1074,9 +1074,9 @@ void run_vm(EngineState *s, int restoring) { case 0x24: // ret do { - stack_ptr_t old_sp2 = xs->sp; - stack_ptr_t old_fp = xs->fp; - exec_stack_t *old_xs = s->execution_stack + s->execution_stack_pos; + StackPtr old_sp2 = xs->sp; + StackPtr old_fp = xs->fp; + ExecStack *old_xs = s->execution_stack + s->execution_stack_pos; if (s->execution_stack_pos == s->execution_stack_base) { // Have we reached the base? s->execution_stack_base = old_execution_stack_base; // Restore stack base @@ -1476,7 +1476,7 @@ void run_vm(EngineState *s, int restoring) { } } -static inline int _obj_locate_varselector(EngineState *s, object_t *obj, selector_t slc) { +static inline int _obj_locate_varselector(EngineState *s, Object *obj, Selector slc) { // Determines if obj explicitly defines slc as a varselector // Returns -1 if not found @@ -1509,7 +1509,7 @@ static inline int _obj_locate_varselector(EngineState *s, object_t *obj, selecto } } -static inline int _class_locate_funcselector(EngineState *s, object_t *obj, selector_t slc) { +static inline int _class_locate_funcselector(EngineState *s, Object *obj, Selector slc) { // Determines if obj is a class and explicitly defines slc as a funcselector // Does NOT say anything about obj's superclasses, i.e. failure may be // returned even if one of the superclasses defines the funcselector. @@ -1523,7 +1523,7 @@ static inline int _class_locate_funcselector(EngineState *s, object_t *obj, sele return -1; // Failed } -static inline int _lookup_selector_function(EngineState *s, int seg_id, object_t *obj, selector_t selector_id, reg_t *fptr) { +static inline SelectorType _lookup_selector_function(EngineState *s, int seg_id, Object *obj, Selector selector_id, reg_t *fptr) { int index; // "recursive" lookup @@ -1539,19 +1539,19 @@ static inline int _lookup_selector_function(EngineState *s, int seg_id, object_t *fptr = make_reg(obj->pos.segment, getUInt16((byte *)(obj->base_method + index * 2 + 2))); } - return SELECTOR_METHOD; + return kSelectorMethod; } else { seg_id = obj->variables[SCRIPT_SUPERCLASS_SELECTOR].segment; obj = obj_get(s, obj->variables[SCRIPT_SUPERCLASS_SELECTOR]); } } - return SELECTOR_NONE; + return kSelectorNone; } -int lookup_selector(EngineState *s, reg_t obj_location, selector_t selector_id, reg_t **vptr, reg_t *fptr) { - object_t *obj = obj_get(s, obj_location); - object_t *species; +SelectorType lookup_selector(EngineState *s, reg_t obj_location, Selector selector_id, reg_t **vptr, reg_t *fptr) { + Object *obj = obj_get(s, obj_location); + Object *species; int index; // Early SCI versions used the LSB in the selector ID as a read/write @@ -1562,7 +1562,7 @@ int lookup_selector(EngineState *s, reg_t obj_location, selector_t selector_id, if (!obj) { CORE_ERROR("SLC-LU", "Attempt to send to non-object or invalid script"); sciprintf("Address was "PREG"\n", PRINT_REG(obj_location)); - return SELECTOR_NONE; + return kSelectorNone; } if (IS_CLASS(obj)) @@ -1575,7 +1575,7 @@ int lookup_selector(EngineState *s, reg_t obj_location, selector_t selector_id, CORE_ERROR("SLC-LU", "Error while looking up Species class"); sciprintf("Original address was "PREG"\n", PRINT_REG(obj_location)); sciprintf("Species address was "PREG"\n", PRINT_REG(obj->variables[SCRIPT_SPECIES_SELECTOR])); - return SELECTOR_NONE; + return kSelectorNone; } index = _obj_locate_varselector(s, obj, selector_id); @@ -1584,7 +1584,7 @@ int lookup_selector(EngineState *s, reg_t obj_location, selector_t selector_id, // Found it as a variable if (vptr) *vptr = obj->variables + index; - return SELECTOR_VARIABLE; + return kSelectorVariable; } return _lookup_selector_function(s, obj_location.segment, obj, selector_id, fptr); @@ -1613,8 +1613,8 @@ void script_detect_versions(EngineState *s) { } } -seg_id_t script_get_segment(EngineState *s, int script_nr, int load) { - seg_id_t segment; +SegmentId script_get_segment(EngineState *s, int script_nr, int load) { + SegmentId segment; if ((load & SCRIPT_GET_LOAD) == SCRIPT_GET_LOAD) script_instantiate(s, script_nr); @@ -1631,9 +1631,9 @@ seg_id_t script_get_segment(EngineState *s, int script_nr, int load) { } reg_t script_lookup_export(EngineState *s, int script_nr, int export_index) { - seg_id_t seg = script_get_segment(s, script_nr, SCRIPT_GET_DONT_LOAD); - mem_obj_t *memobj; - script_t *script = NULL; + SegmentId seg = script_get_segment(s, script_nr, SCRIPT_GET_DONT_LOAD); + MemObject *memobj; + Script *script = NULL; #ifndef DISABLE_VALIDATIONS if (!seg) { @@ -1674,7 +1674,7 @@ int script_instantiate_common(EngineState *s, int script_nr, resource_t **script int seg; int seg_id; int marked_for_deletion; - mem_obj_t *mem; + MemObject *mem; reg_t reg; *was_new = 1; @@ -1853,8 +1853,8 @@ int script_instantiate_sci0(EngineState *s, int script_nr) { break; case sci_obj_object: case sci_obj_class: { // object or class? - object_t *obj = s->seg_manager->scriptObjInit(s, addr); - object_t *base_obj; + Object *obj = s->seg_manager->scriptObjInit(s, addr); + Object *base_obj; // Instantiate the superclass, if neccessary obj->variables[SCRIPT_SPECIES_SELECTOR] = INST_LOOKUP_CLASS(obj->variables[SCRIPT_SPECIES_SELECTOR].offset); @@ -1929,7 +1929,7 @@ int script_instantiate(EngineState *s, int script_nr) { return script_instantiate_sci0(s, script_nr); } -void script_uninstantiate_sci0(EngineState *s, int script_nr, seg_id_t seg) { +void script_uninstantiate_sci0(EngineState *s, int script_nr, SegmentId seg) { reg_t reg = make_reg(seg, (s->version < SCI_VERSION_FTU_NEW_SCRIPT_HEADER) ? 2 : 0); int objtype, objlength; @@ -2011,7 +2011,7 @@ void script_uninstantiate(EngineState *s, int script_nr) { return; } -static void _init_stack_base_with_selector(EngineState *s, selector_t selector) { +static void _init_stack_base_with_selector(EngineState *s, Selector selector) { s->stack_base[0] = make_reg(0, (uint16)selector); s->stack_base[1] = NULL_REG; } @@ -2051,7 +2051,7 @@ static EngineState *_game_run(EngineState *s, int restoring) { if (!send_calls_allocated) { send_calls_allocated = 16; - send_calls = (calls_struct_t *)sci_calloc(sizeof(calls_struct_t), 16); + send_calls = (CallsStruct *)sci_calloc(sizeof(CallsStruct), 16); } if (script_abort_flag == SCRIPT_ABORT_WITH_REPLAY) { @@ -2124,9 +2124,9 @@ int game_restore(EngineState **_s, char *game_name) { } #endif -object_t *obj_get(EngineState *s, reg_t offset) { - mem_obj_t *memobj = GET_OBJECT_SEGMENT(*s->seg_manager, offset.segment); - object_t *obj = NULL; +Object *obj_get(EngineState *s, reg_t offset) { + MemObject *memobj = GET_OBJECT_SEGMENT(*s->seg_manager, offset.segment); + Object *obj = NULL; int idx; if (memobj != NULL) { @@ -2146,7 +2146,7 @@ object_t *obj_get(EngineState *s, reg_t offset) { } const char *obj_get_name(EngineState *s, reg_t pos) { - object_t *obj = obj_get(s, pos); + Object *obj = obj_get(s, pos); if (!obj) return ""; diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h index 608f9b7550..6c05ccb3f5 100644 --- a/engines/sci/engine/vm.h +++ b/engines/sci/engine/vm.h @@ -118,13 +118,14 @@ struct SystemStrings { #define CALL_SP_CARRY NULL /* Stack pointer value: Use predecessor's value */ +// Types of selectors as returned by lookup_selector() below +enum SelectorType { + kSelectorNone = 0, + kSelectorVariable, + kSelectorMethod +}; -#define SELECTOR_NONE 0 -#define SELECTOR_VARIABLE 1 -#define SELECTOR_METHOD 2 -/* Types of selectors as returned by grep_selector() below */ - -struct class_t { +struct Class { int script; /* number of the script the class is in, -1 for non-existing */ reg_t reg; /* offset; script-relative offset, segment: 0 if not instantiated */ }; @@ -135,19 +136,19 @@ struct class_t { #define IS_CLASS(obj) (obj->variables[SCRIPT_INFO_SELECTOR].offset & SCRIPT_INFO_CLASS) /* This struct is used to buffer the list of send calls in send_selector() */ -struct calls_struct_t { +struct CallsStruct { union { reg_t func; reg_t *var; } address; - stack_ptr_t argp; + StackPtr argp; int argc; - selector_t selector; - stack_ptr_t sp; /* Stack pointer */ - int type; /* Same as exec_stack_t.type */ + Selector selector; + StackPtr sp; /* Stack pointer */ + int type; /* Same as ExecStack.type */ }; -struct local_variables_t { +struct LocalVariables { int script_id; /* Script ID this local variable block belongs to */ reg_t *locals; int nr; @@ -155,7 +156,7 @@ struct local_variables_t { #define OBJECT_FLAG_FREED (0x1 << 0) /* Clone has been marked as 'freed' */ -struct object_t { +struct Object { int flags; reg_t pos; /* Object offset within its script; for clones, this is their base */ int variables_nr; @@ -168,7 +169,7 @@ struct object_t { reg_t *variables; }; -struct code_block_t { +struct CodeBlock { reg_t pos; int size; }; @@ -195,7 +196,7 @@ struct code_block_t { -struct script_t { +struct Script { int nr; /* Script number */ byte* buf; /* Static data buffer, or NULL if not used */ size_t buf_size; @@ -212,7 +213,7 @@ struct script_t { int synonyms_nr; /* Number of entries in the synonyms block */ int lockers; /* Number of classes and objects that require this script */ - object_t *objects; /* Table for objects, contains property variables */ + Object *objects; /* Table for objects, contains property variables */ /* Indexed by the value stored at SCRIPT_LOCALVARPTR_OFFSET, ** see VM_OBJECT_[GS]ET_INDEX() */ int objects_nr; /* Number of objects and classes */ @@ -220,9 +221,9 @@ struct script_t { int locals_offset; int locals_segment; /* The local variable segment */ - local_variables_t *locals_block; + LocalVariables *locals_block; - code_block_t *code; + CodeBlock *code; int code_blocks_nr; int code_blocks_allocated; int relocated; @@ -237,39 +238,40 @@ struct dstack_t { #define CLONE_USED -1 #define CLONE_NONE -1 -typedef object_t clone_t; +typedef Object Clone; -struct node_t { +struct Node { reg_t pred, succ; /* Predecessor, successor */ reg_t key; reg_t value; }; /* List nodes */ -struct list_t { +struct List { reg_t first; reg_t last; }; -struct hunk_t { +struct Hunk { void *mem; unsigned int size; const char *type; }; -/* clone_table_t */ -DECLARE_HEAPENTRY(clone) -/* node_table_t */ -DECLARE_HEAPENTRY(node) -/* list_table_t */ -DECLARE_HEAPENTRY(list) /* list entries */ -/* hunk_table_t */ -DECLARE_HEAPENTRY(hunk) - -struct dynmem_t { +/* CloneTable */ +DECLARE_HEAPENTRY(Clone) +/* NodeTable */ +DECLARE_HEAPENTRY(Node) +/* ListTable */ +DECLARE_HEAPENTRY(List) /* list entries */ +/* HunkTable */ +DECLARE_HEAPENTRY(Hunk) + +// Free-style memory +struct DynMem { int size; char *description; byte *buf; -}; /* Free-style memory */ +}; enum memObjType { MEM_OBJ_INVALID = 0, @@ -286,19 +288,19 @@ enum memObjType { MEM_OBJ_MAX = MEM_OBJ_RESERVED // For sanity checking }; -struct mem_obj_t { +struct MemObject { memObjType type; int segmgr_id; /* Internal value used by the seg_manager's hash map */ union { - script_t script; - clone_table_t clones; - local_variables_t locals; + Script script; + CloneTable clones; + LocalVariables locals; dstack_t stack; SystemStrings sys_strings; - list_table_t lists; - node_table_t nodes; - hunk_table_t hunks; - dynmem_t dynmem; + ListTable lists; + NodeTable nodes; + HunkTable hunks; + DynMem dynmem; char *reserved; } data; }; @@ -306,80 +308,80 @@ struct mem_obj_t { struct selector_map_t { - selector_t init; /* Init function */ - selector_t play; /* Play function (first function to be called) */ - selector_t replay; /* Replay function */ - selector_t x, y, z; /* Coordinates */ - selector_t priority; - selector_t view, loop, cel; /* Description of a specific image */ - selector_t brLeft, brRight, brTop, brBottom; /* Bounding Rectangle */ - selector_t xStep, yStep; /* BR adjustments */ - selector_t nsLeft, nsRight, nsTop, nsBottom; /* View boundaries ('now seen') */ - selector_t text, font; /* Used by controls */ - selector_t type, state; /* Used by contols as well */ - selector_t doit; /* Called (!) by the Animate() system call */ - selector_t signal; /* Used by Animate() to control a view's behaviour */ - selector_t underBits; /* Used by the graphics subroutines to store backupped BG pic data */ + Selector init; /* Init function */ + Selector play; /* Play function (first function to be called) */ + Selector replay; /* Replay function */ + Selector x, y, z; /* Coordinates */ + Selector priority; + Selector view, loop, cel; /* Description of a specific image */ + Selector brLeft, brRight, brTop, brBottom; /* Bounding Rectangle */ + Selector xStep, yStep; /* BR adjustments */ + Selector nsLeft, nsRight, nsTop, nsBottom; /* View boundaries ('now seen') */ + Selector text, font; /* Used by controls */ + Selector type, state; /* Used by contols as well */ + Selector doit; /* Called (!) by the Animate() system call */ + Selector signal; /* Used by Animate() to control a view's behaviour */ + Selector underBits; /* Used by the graphics subroutines to store backupped BG pic data */ /* The following selectors are used by the Bresenham syscalls: */ - selector_t canBeHere; /* Funcselector: Checks for movement validity */ - selector_t client; /* The object that wants to be moved */ - selector_t cycler; /* The cycler of the client */ - selector_t dx, dy; /* Deltas */ - selector_t edgeHit; - selector_t b_movCnt, b_i1, b_i2, b_di, b_xAxis, b_incr; /* Various Bresenham vars */ - selector_t completed; + Selector canBeHere; /* Funcselector: Checks for movement validity */ + Selector client; /* The object that wants to be moved */ + Selector cycler; /* The cycler of the client */ + Selector dx, dy; /* Deltas */ + Selector edgeHit; + Selector b_movCnt, b_i1, b_i2, b_di, b_xAxis, b_incr; /* Various Bresenham vars */ + Selector completed; - selector_t illegalBits; /* Used by CanBeHere */ - selector_t dispose; + Selector illegalBits; /* Used by CanBeHere */ + Selector dispose; - selector_t prevSignal; /* Used by DoSound */ + Selector prevSignal; /* Used by DoSound */ - selector_t message, modifiers; /* Used by GetEvent */ + Selector message, modifiers; /* Used by GetEvent */ - selector_t owner, handle; - selector_t cue; - selector_t number; + Selector owner, handle; + Selector cue; + Selector number; - selector_t max, cursor; /* Used by EditControl */ - selector_t mode; /* Used by text controls (-> DrawControl()) */ + Selector max, cursor; /* Used by EditControl */ + Selector mode; /* Used by text controls (-> DrawControl()) */ - selector_t wordFail, syntaxFail, semanticFail; /* Used by Parse() */ + Selector wordFail, syntaxFail, semanticFail; /* Used by Parse() */ - selector_t claimed; /* Used generally by the event mechanism */ + Selector claimed; /* Used generally by the event mechanism */ - selector_t elements; /* Used by SetSynonyms() */ + Selector elements; /* Used by SetSynonyms() */ - selector_t lsTop, lsBottom, lsRight, lsLeft; /* Used by Animate() subfunctions and scroll list controls */ + Selector lsTop, lsBottom, lsRight, lsLeft; /* Used by Animate() subfunctions and scroll list controls */ - selector_t baseSetter; /* Alternative baseSetter */ + Selector baseSetter; /* Alternative baseSetter */ - selector_t who, distance; /* Used for 'chasing' movers */ + Selector who, distance; /* Used for 'chasing' movers */ - selector_t looper, mover, isBlocked, heading; /* Used in DoAvoider */ + Selector looper, mover, isBlocked, heading; /* Used in DoAvoider */ - selector_t caller, moveDone, moveSpeed; /* Used for DoBresen */ + Selector caller, moveDone, moveSpeed; /* Used for DoBresen */ - selector_t delete_; /* Called by Animate() to dispose a view object */ + Selector delete_; /* Called by Animate() to dispose a view object */ - selector_t vol; - selector_t pri; + Selector vol; + Selector pri; - selector_t min; /* SMPTE time format */ - selector_t sec; - selector_t frame; + Selector min; /* SMPTE time format */ + Selector sec; + Selector frame; - selector_t dataInc; - selector_t size; - selector_t palette; - selector_t cantBeHere; - selector_t nodePtr; - selector_t flags; + Selector dataInc; + Selector size; + Selector palette; + Selector cantBeHere; + Selector nodePtr; + Selector flags; - selector_t points; /* Used by AvoidPath() */ + Selector points; /* Used by AvoidPath() */ }; /* Contains selector IDs for a few selected selectors */ -struct view_object_t { +struct ViewObject { reg_t obj; reg_t *signalp; /* Used only indirectly */ reg_t *underBitsp; /* The same goes for the handle storage */ @@ -402,35 +404,35 @@ struct view_object_t { #define EXEC_STACK_TYPE_KERNEL 1 #define EXEC_STACK_TYPE_VARSELECTOR 2 -struct exec_stack_t { +struct ExecStack { reg_t objp; reg_t sendp; /* Pointer to the object containing the invoked method */ union { reg_t *varp; /* Variable pointer for read/write access */ reg_t pc; /* Not accurate for the TOS element */ } addr; - stack_ptr_t fp; /* Frame pointer */ - stack_ptr_t sp; /* Stack pointer */ + StackPtr fp; /* Frame pointer */ + StackPtr sp; /* Stack pointer */ int argc; /* former variables[4]: [all other values are derived] */ - stack_ptr_t variables_argp; /* Argument pointer */ - seg_id_t local_segment; /* local variables etc. */ + StackPtr variables_argp; /* Argument pointer */ + SegmentId local_segment; /* local variables etc. */ - selector_t selector; /* The selector which was used to call or -1 if not applicable */ + Selector selector; // The selector which was used to call or -1 if not applicable int origin; /* The stack frame position the call was made from, or -1 if it ** was the initial call. */ byte type; /* EXEC_STACK_TYPE* */ }; -struct breakpoint_t { +struct Breakpoint { int type; union { uint32 address; /* Breakpoints on exports */ char *name; /* Breakpoints on selector names */ } data; - breakpoint_t *next; + Breakpoint *next; }; #define BREAK_SELECTOR 1 @@ -480,70 +482,70 @@ extern kernel_function* kfuncs[]; extern int max_instance; /*inline*/ -exec_stack_t *execute_method(EngineState *s, uint16 script, uint16 pubfunct, stack_ptr_t sp, reg_t calling_obj, - uint16 argc, stack_ptr_t argp); +ExecStack *execute_method(EngineState *s, uint16 script, uint16 pubfunct, StackPtr sp, reg_t calling_obj, + uint16 argc, StackPtr argp); /* Executes function pubfunct of the specified script. ** Parameters: (EngineState *) s: The state which is to be executed with ** (uint16) script: The script which is called ** (uint16) pubfunct: The exported script function which is to be called -** (stack_ptr_t) sp: Stack pointer position +** (StackPtr) sp: Stack pointer position ** (reg_t) calling_obj: The heap address of the object which executed the call ** (uint16) argc: Number of arguments supplied -** (stack_ptr_t) argp: Pointer to the first supplied argument -** Returns : (exec_stack_t *): A pointer to the new exec stack TOS entry +** (StackPtr) argp: Pointer to the first supplied argument +** Returns : (ExecStack *): A pointer to the new exec stack TOS entry */ -exec_stack_t *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, - stack_ptr_t sp, int framesize, stack_ptr_t argp); +ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, + StackPtr sp, int framesize, StackPtr argp); /* Executes a "send" or related operation to a selector ** Parameters: (EngineState *) s: The EngineState to operate on ** (reg_t) send_obj: Heap address of the object to send to ** (reg_t) work_obj: Heap address of the object initiating the send -** (stack_ptr_t) sp: Stack pointer position +** (StackPtr) sp: Stack pointer position ** (int) framesize: Size of the send as determined by the "send" operation -** (stack_ptr_t) argp: Pointer to the beginning of the heap block containing the +** (StackPtr) argp: Pointer to the beginning of the heap block containing the ** data to be send. This area is a succession of one or more ** sequences of [selector_number][argument_counter] and then ** "argument_counter" word entries with the parameter values. -** Returns : (exec_stack_t *): A pointer to the new execution stack TOS entry +** Returns : (ExecStack *): A pointer to the new execution stack TOS entry */ #define SCI_XS_CALLEE_LOCALS -1 -exec_stack_t *add_exec_stack_entry(EngineState *s, reg_t pc, stack_ptr_t sp, reg_t objp, int argc, - stack_ptr_t argp, selector_t selector, reg_t sendp, int origin, seg_id_t local_segment); +ExecStack *add_exec_stack_entry(EngineState *s, reg_t pc, StackPtr sp, reg_t objp, int argc, + StackPtr argp, Selector selector, reg_t sendp, int origin, SegmentId local_segment); /* Adds an entry to the top of the execution stack ** Parameters: (EngineState *) s: The state with which to execute ** (reg_t) pc: The initial program counter -** (stack_ptr_t) sp: The initial stack pointer +** (StackPtr) sp: The initial stack pointer ** (reg_t) objp: Pointer to the beginning of the current object ** (int) argc: Number of parameters to call with -** (stack_ptr_t) argp: Heap pointer to the first parameter -** (selector_t) selector: The selector by which it was called or -** NULL_SELECTOR if n.a. For debugging. +** (StackPtr) argp: Heap pointer to the first parameter +** (Selector) selector: The selector by which it was called or +** NULL_SELECTOR if n.a. For debugging. ** (reg_t) sendp: Pointer to the object which the message was sent to. ** Equal to objp for anything but super. ** (int) origin: Number of the execution stack element this entry was created by ** (usually the current TOS number, except for multiple sends). -** (seg_id_t) local_segment: The segment to use for local variables, +** (SegmentId) local_segment: The segment to use for local variables, ** or SCI_XS_CALLEE_LOCALS to use obj's segment. -** Returns : (exec_stack_t *): A pointer to the new exec stack TOS entry +** Returns : (ExecStack *): A pointer to the new exec stack TOS entry */ -exec_stack_t *add_exec_stack_varselector(EngineState *s, reg_t objp, int argc, stack_ptr_t argp, - selector_t selector, reg_t *address, int origin); +ExecStack *add_exec_stack_varselector(EngineState *s, reg_t objp, int argc, StackPtr argp, + Selector selector, reg_t *address, int origin); /* Adds one varselector access to the execution stack ** Parameters: (EngineState *) s: The EngineState to use ** (reg_t) objp: Pointer to the object owning the selector ** (int) argc: 1 for writing, 0 for reading -** (stack_ptr_t) argp: Pointer to the address of the data to write -2 +** (StackPtr) argp: Pointer to the address of the data to write -2 ** (int) selector: Selector name ** (reg_t *) address: Heap address of the selector ** (int) origin: Stack frame which the access originated from -** Returns : (exec_stack_t *): Pointer to the new exec-TOS element +** Returns : (ExecStack *): Pointer to the new exec-TOS element ** This function is called from send_selector only. */ @@ -565,17 +567,17 @@ void vm_handle_fatal_error(EngineState *s, int line, const char *file); */ -void script_debug(EngineState *s, reg_t *pc, stack_ptr_t *sp, stack_ptr_t *pp, reg_t *objp, - int *restadjust, seg_id_t *segids, reg_t **variables, reg_t **variables_base, +void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *objp, + int *restadjust, SegmentId *segids, reg_t **variables, reg_t **variables_base, int *variables_nr, int bp); /* Debugger functionality ** Parameters: (EngineState *) s: The state at which debugging should take place ** (reg_t *) pc: Pointer to the program counter -** (stack_ptr_t *) sp: Pointer to the stack pointer -** (stack_ptr_t *) pp: Pointer to the frame pointer +** (StackPtr *) sp: Pointer to the stack pointer +** (StackPtr *) pp: Pointer to the frame pointer ** (reg_t *) objp: Pointer to the object base pointer ** (int *) restadjust: Pointer to the &rest adjustment value -** (seg_id_t *) segids: four-element array containing segment IDs for locals etc. +** (SegmentId *) segids: four-element array containing segment IDs for locals etc. ** (reg_t **) variables: four-element array referencing registers for globals etc. ** (reg_t **) variables_base: four-element array referencing ** register bases for temps etc. @@ -612,14 +614,14 @@ void script_free_vm_memory(EngineState *s); */ -int lookup_selector(EngineState *s, reg_t obj, selector_t selectorid, reg_t **vptr, reg_t *fptr); +SelectorType lookup_selector(EngineState *s, reg_t obj, Selector selectorid, reg_t **vptr, reg_t *fptr); /* Looks up a selector and returns its type and value ** Parameters: (EngineState *) s: The EngineState to use ** (reg_t) obj: Address of the object to look the selector up in -** (selector_t) selectorid: The selector to look up -** Returns : (int) SELECTOR_NONE if the selector was not found in the object or its superclasses. -** SELECTOR_VARIABLE if the selector represents an object-relative variable -** SELECTOR_METHOD if the selector represents a method +** (Selector) selectorid: The selector to look up +** Returns : (SelectorType) kSelectorNone if the selector was not found in the object or its superclasses. +** kSelectorVariable if the selector represents an object-relative variable +** kSelectorMethod if the selector represents a method ** (reg_t *) *vptr: A pointer to the storage space associated with the selector, if ** it is a variable ** (reg_t) *fptr: A reference to the function described by that selector, if it is @@ -633,7 +635,7 @@ int lookup_selector(EngineState *s, reg_t obj, selector_t selectorid, reg_t **vp #define SCRIPT_GET_LOAD 1 /* Load, if neccessary */ #define SCRIPT_GET_LOCK 3 /* Load, if neccessary, and lock */ -seg_id_t script_get_segment(EngineState *s, int script_id, int load); +SegmentId script_get_segment(EngineState *s, int script_id, int load); /* Determines the segment occupied by a certain script ** Parameters: (EngineState *) s: The state to operate on ** (int) script_id: The script in question @@ -807,11 +809,11 @@ const char *obj_get_name(EngineState *s, reg_t pos); ** may it be modified). */ -object_t *obj_get(EngineState *s, reg_t offset); +Object *obj_get(EngineState *s, reg_t offset); /* Retreives an object from the specified location ** Parameters: (EngineState *) s: Pointer to the EngineState to operate on ** (reg_t) offset: The object's offset -** Returns : (object_t *) The object in question, or NULL if there is none +** Returns : (Object *) The object in question, or NULL if there is none */ } // End of namespace Sci diff --git a/engines/sci/engine/vm_types.h b/engines/sci/engine/vm_types.h index 016ab7504a..d2ddf839bc 100644 --- a/engines/sci/engine/vm_types.h +++ b/engines/sci/engine/vm_types.h @@ -30,7 +30,8 @@ namespace Sci { -typedef int seg_id_t; /* Segment ID type */ +// Segment ID type +typedef int SegmentId; struct reg_t { uint16 segment; @@ -40,8 +41,10 @@ struct reg_t { #define PREG "%04x:%04x" #define PRINT_REG(r) (0xffff) & (unsigned) (r).segment, (unsigned) (r).offset -typedef reg_t *stack_ptr_t; /* Stack pointer type */ -typedef int selector_t; /* Selector ID */ +// Stack pointer type +typedef reg_t *StackPtr; +// Selector ID +typedef int Selector; #define NULL_SELECTOR -1 #define PSTK "ST:%04x" -- cgit v1.2.3