2009-02-17 15:02:16 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-21 15:40:14 +00:00
|
|
|
#include "common/system.h"
|
2009-02-22 19:45:53 +00:00
|
|
|
#include "common/file.h"
|
2009-02-21 15:40:14 +00:00
|
|
|
|
2009-05-13 16:52:41 +00:00
|
|
|
#include "sci/sci.h"
|
2009-05-15 14:07:45 +00:00
|
|
|
#include "sci/resource.h"
|
2009-02-27 02:23:40 +00:00
|
|
|
#include "sci/engine/state.h"
|
2009-02-24 05:51:55 +00:00
|
|
|
#include "sci/engine/kernel.h"
|
2009-02-15 08:34:13 +00:00
|
|
|
#include "sci/engine/kernel_types.h"
|
2009-02-21 22:50:35 +00:00
|
|
|
#include "sci/gfx/gfx_widgets.h"
|
2009-04-24 10:46:20 +00:00
|
|
|
#include "sci/gfx/gfx_state_internal.h" // required for GfxPort, GfxVisual
|
2009-02-21 22:50:35 +00:00
|
|
|
#include "sci/gfx/menubar.h"
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-21 10:23:36 +00:00
|
|
|
namespace Sci {
|
|
|
|
|
2009-02-21 10:47:56 +00:00
|
|
|
int _reset_graphics_input(EngineState *s) {
|
2009-02-28 21:59:49 +00:00
|
|
|
Resource *resource;
|
2009-02-15 06:10:59 +00:00
|
|
|
int font_nr;
|
2009-03-08 20:17:01 +00:00
|
|
|
gfx_color_t transparent = { PaletteEntry(), 0, -1, -1, 0 };
|
2009-05-26 14:44:14 +00:00
|
|
|
debug(2, "Initializing graphics");
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-08-25 08:38:14 +00:00
|
|
|
if (s->resourceManager->getViewType() == kViewEga) {
|
2009-07-07 07:44:25 +00:00
|
|
|
for (int i = 0; i < 16; i++) {
|
2009-08-31 14:24:35 +00:00
|
|
|
gfxop_set_color(s->gfx_state, &(s->ega_colors[i]), gfx_sci0_image_colors[sci0_palette][i].r,
|
|
|
|
gfx_sci0_image_colors[sci0_palette][i].g, gfx_sci0_image_colors[sci0_palette][i].b, 0, -1, -1);
|
2009-03-08 20:17:01 +00:00
|
|
|
gfxop_set_system_color(s->gfx_state, i, &(s->ega_colors[i]));
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
2009-02-15 22:28:12 +00:00
|
|
|
} else {
|
2009-05-10 10:27:45 +00:00
|
|
|
// Allocate SCI1 system colors
|
2009-05-10 11:08:50 +00:00
|
|
|
gfx_color_t black = { PaletteEntry(0, 0, 0), 0, 0, 0, GFX_MASK_VISUAL };
|
2009-05-10 10:27:45 +00:00
|
|
|
gfxop_set_system_color(s->gfx_state, 0, &black);
|
2009-03-29 21:46:49 +00:00
|
|
|
|
2009-02-18 22:41:57 +00:00
|
|
|
// Check for Amiga palette file.
|
2009-02-22 19:45:53 +00:00
|
|
|
Common::File file;
|
|
|
|
if (file.open("spal")) {
|
2009-03-22 23:11:43 +00:00
|
|
|
s->gfx_state->gfxResMan->setStaticPalette(gfxr_read_pal1_amiga(file));
|
2009-02-22 19:45:53 +00:00
|
|
|
file.close();
|
2009-02-15 06:10:59 +00:00
|
|
|
} else {
|
2009-08-25 08:38:14 +00:00
|
|
|
resource = s->resourceManager->findResource(ResourceId(kResourceTypePalette, 999), 1);
|
2009-02-15 06:10:59 +00:00
|
|
|
if (resource) {
|
2009-08-25 08:38:14 +00:00
|
|
|
if (s->resourceManager->sciVersion() < SCI_VERSION_1_1)
|
2009-03-22 23:11:43 +00:00
|
|
|
s->gfx_state->gfxResMan->setStaticPalette(gfxr_read_pal1(999, resource->data, resource->size));
|
2009-02-15 22:28:12 +00:00
|
|
|
else
|
2009-03-22 23:11:43 +00:00
|
|
|
s->gfx_state->gfxResMan->setStaticPalette(gfxr_read_pal11(999, resource->data, resource->size));
|
2009-08-25 08:38:14 +00:00
|
|
|
s->resourceManager->unlockResource(resource);
|
2009-02-18 22:41:57 +00:00
|
|
|
} else {
|
2009-05-26 14:44:14 +00:00
|
|
|
debug(2, "Couldn't find the default palette!");
|
2009-02-18 22:41:57 +00:00
|
|
|
}
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-18 22:41:57 +00:00
|
|
|
gfxop_fill_box(s->gfx_state, gfx_rect(0, 0, 320, 200), s->ega_colors[0]); // Fill screen black
|
2009-02-15 06:10:59 +00:00
|
|
|
gfxop_update(s->gfx_state);
|
|
|
|
|
2009-02-17 19:15:37 +00:00
|
|
|
gfxop_set_pointer_position(s->gfx_state, Common::Point(160, 150));
|
2009-02-15 06:10:59 +00:00
|
|
|
|
|
|
|
s->pic_is_new = 0;
|
2009-02-18 22:41:57 +00:00
|
|
|
s->pic_visible_map = GFX_MASK_NONE; // Other values only make sense for debugging
|
|
|
|
s->dyn_views = NULL; // no DynViews
|
|
|
|
s->drop_views = NULL; // And, consequently, no list for dropped views
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-18 22:41:57 +00:00
|
|
|
s->priority_first = 42; // Priority zone 0 ends here
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-07-11 23:45:54 +00:00
|
|
|
if (((SciEngine*)g_engine)->getKernel()->usesOldGfxFunctions())
|
2009-02-15 22:28:12 +00:00
|
|
|
s->priority_last = 200;
|
|
|
|
else
|
2009-02-15 06:10:59 +00:00
|
|
|
s->priority_last = 190;
|
|
|
|
|
|
|
|
font_nr = -1;
|
|
|
|
do {
|
2009-08-25 08:38:14 +00:00
|
|
|
resource = s->resourceManager->testResource(ResourceId(kResourceTypeFont, ++font_nr));
|
2009-07-07 13:39:24 +00:00
|
|
|
} while ((!resource) && (font_nr < 65536));
|
2009-02-15 06:10:59 +00:00
|
|
|
|
|
|
|
if (!resource) {
|
2009-05-26 14:44:14 +00:00
|
|
|
debug(2, "No text font was found.");
|
2009-02-15 06:10:59 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-06-02 14:16:59 +00:00
|
|
|
s->visual = new GfxVisual(s->gfx_state, font_nr);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-06-02 14:16:59 +00:00
|
|
|
s->wm_port = new GfxPort(s->visual, s->gfx_state->pic_port_bounds, s->ega_colors[0], transparent);
|
2009-04-21 19:57:11 +00:00
|
|
|
|
2009-06-02 14:16:59 +00:00
|
|
|
s->iconbar_port = new GfxPort(s->visual, gfx_rect(0, 0, 320, 200), s->ega_colors[0], transparent);
|
2009-04-24 10:45:09 +00:00
|
|
|
s->iconbar_port->_flags |= GFXW_FLAG_NO_IMPLICIT_SWITCH;
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-08-25 08:38:14 +00:00
|
|
|
if (s->resourceManager->isVGA()) {
|
2009-02-15 15:15:26 +00:00
|
|
|
// This bit sets the foreground and background colors in VGA SCI games
|
2009-02-15 06:10:59 +00:00
|
|
|
gfx_color_t fgcolor;
|
|
|
|
gfx_color_t bgcolor;
|
2009-02-16 07:17:36 +00:00
|
|
|
memset(&fgcolor, 0, sizeof(gfx_color_t));
|
|
|
|
memset(&bgcolor, 0, sizeof(gfx_color_t));
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-16 07:02:11 +00:00
|
|
|
#if 0
|
2009-02-15 06:10:59 +00:00
|
|
|
fgcolor.visual = s->gfx_state->resstate->static_palette[0];
|
|
|
|
fgcolor.mask = GFX_MASK_VISUAL;
|
|
|
|
bgcolor.visual = s->gfx_state->resstate->static_palette[255];
|
|
|
|
bgcolor.mask = GFX_MASK_VISUAL;
|
2009-02-16 07:02:11 +00:00
|
|
|
#endif
|
2009-06-02 14:16:59 +00:00
|
|
|
s->titlebar_port = new GfxPort(s->visual, gfx_rect(0, 0, 320, 10), fgcolor, bgcolor);
|
2009-02-18 22:41:57 +00:00
|
|
|
} else {
|
2009-06-02 14:16:59 +00:00
|
|
|
s->titlebar_port = new GfxPort(s->visual, gfx_rect(0, 0, 320, 10), s->ega_colors[0], s->ega_colors[15]);
|
2009-02-18 22:41:57 +00:00
|
|
|
}
|
2009-04-24 10:45:09 +00:00
|
|
|
s->titlebar_port->_color.mask |= GFX_MASK_PRIORITY;
|
|
|
|
s->titlebar_port->_color.priority = 11;
|
|
|
|
s->titlebar_port->_bgcolor.mask |= GFX_MASK_PRIORITY;
|
|
|
|
s->titlebar_port->_bgcolor.priority = 11;
|
|
|
|
s->titlebar_port->_flags |= GFXW_FLAG_NO_IMPLICIT_SWITCH;
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-18 22:41:57 +00:00
|
|
|
// but this is correct
|
2009-06-02 14:16:59 +00:00
|
|
|
s->picture_port = new GfxPort(s->visual, s->gfx_state->pic_port_bounds, s->ega_colors[0], transparent);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-05-10 20:13:43 +00:00
|
|
|
s->_pics.clear();
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-05-30 14:30:39 +00:00
|
|
|
s->visual->add((GfxContainer *)s->visual, s->wm_port);
|
|
|
|
s->visual->add((GfxContainer *)s->visual, s->titlebar_port);
|
|
|
|
s->visual->add((GfxContainer *)s->visual, s->picture_port);
|
|
|
|
s->visual->add((GfxContainer *)s->visual, s->iconbar_port);
|
2009-02-18 22:41:57 +00:00
|
|
|
// Add ports to visual
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-18 22:41:57 +00:00
|
|
|
s->port = s->picture_port; // Currently using the picture port
|
2009-02-15 06:10:59 +00:00
|
|
|
|
|
|
|
#if 0
|
2009-04-24 10:45:09 +00:00
|
|
|
s->titlebar_port->_bgcolor.mask |= GFX_MASK_PRIORITY;
|
|
|
|
s->titlebar_port->_bgcolor.priority = 11; // Standard priority for the titlebar port
|
2009-02-15 06:10:59 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-21 10:47:56 +00:00
|
|
|
int game_init_graphics(EngineState *s) {
|
2009-04-01 20:32:45 +00:00
|
|
|
#ifdef CUSTOM_GRAPHICS_OPTIONS
|
2009-02-15 06:10:59 +00:00
|
|
|
#ifndef WITH_PIC_SCALING
|
|
|
|
if (s->gfx_state->options->pic0_unscaled == 0)
|
2009-04-03 08:10:58 +00:00
|
|
|
warning("Pic scaling was disabled; your version of ScummVM has no support for scaled pic drawing built in.");
|
2009-02-15 06:10:59 +00:00
|
|
|
|
|
|
|
s->gfx_state->options->pic0_unscaled = 1;
|
2009-04-01 20:32:45 +00:00
|
|
|
#endif
|
2009-02-15 06:10:59 +00:00
|
|
|
#endif
|
|
|
|
return _reset_graphics_input(s);
|
|
|
|
}
|
|
|
|
|
2009-02-21 10:47:56 +00:00
|
|
|
static void _free_graphics_input(EngineState *s) {
|
2009-05-26 14:44:14 +00:00
|
|
|
debug(2, "Freeing graphics");
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-04-24 10:48:25 +00:00
|
|
|
delete s->visual;
|
2009-02-15 06:10:59 +00:00
|
|
|
|
|
|
|
s->wm_port = s->titlebar_port = s->picture_port = NULL;
|
|
|
|
s->visual = NULL;
|
|
|
|
s->dyn_views = NULL;
|
|
|
|
s->port = NULL;
|
|
|
|
|
2009-05-10 20:13:43 +00:00
|
|
|
s->_pics.clear();
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
2009-02-21 10:47:56 +00:00
|
|
|
int game_init_sound(EngineState *s, int sound_flags) {
|
2009-08-25 08:38:14 +00:00
|
|
|
if (s->resourceManager->sciVersion() > SCI_VERSION_0_LATE)
|
2009-02-15 06:10:59 +00:00
|
|
|
sound_flags |= SFX_STATE_FLAG_MULTIPLAY;
|
|
|
|
|
|
|
|
s->sfx_init_flags = sound_flags;
|
2009-08-25 08:38:14 +00:00
|
|
|
s->_sound.sfx_init(s->resourceManager, sound_flags);
|
2009-02-18 22:41:57 +00:00
|
|
|
|
2009-02-15 06:10:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-18 22:41:57 +00:00
|
|
|
// Architectural stuff: Init/Unintialize engine
|
2009-06-04 21:44:39 +00:00
|
|
|
int script_init_engine(EngineState *s) {
|
2009-02-15 06:10:59 +00:00
|
|
|
s->kernel_opt_flags = 0;
|
2009-08-25 08:38:14 +00:00
|
|
|
s->segmentManager = new SegManager(s->resourceManager);
|
2009-05-26 14:44:14 +00:00
|
|
|
s->gc_countdown = GC_INTERVAL - 1;
|
|
|
|
|
2009-08-25 08:38:14 +00:00
|
|
|
SegmentId script_000_segment = s->segmentManager->getSegment(0, SCRIPT_GET_LOCK);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-05-18 15:07:04 +00:00
|
|
|
if (script_000_segment <= 0) {
|
2009-05-26 14:44:14 +00:00
|
|
|
debug(2, "Failed to instantiate script.000");
|
2009-02-15 06:10:59 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-08-25 08:38:14 +00:00
|
|
|
s->script_000 = s->segmentManager->getScript(script_000_segment);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-08-25 08:38:14 +00:00
|
|
|
s->sys_strings = s->segmentManager->allocateSysStrings(&s->sys_strings_segment);
|
|
|
|
s->string_frag_segment = s->segmentManager->allocateStringFrags();
|
2009-03-10 14:52:02 +00:00
|
|
|
|
2009-02-18 22:41:57 +00:00
|
|
|
// Allocate static buffer for savegame and CWD directories
|
2009-02-26 23:03:35 +00:00
|
|
|
SystemString *str = &s->sys_strings->strings[SYS_STRING_SAVEDIR];
|
|
|
|
str->name = strdup("savedir");
|
|
|
|
str->max_size = MAX_SAVE_DIR_SIZE;
|
2009-05-05 12:23:05 +00:00
|
|
|
str->value = (reg_t *)calloc(MAX_SAVE_DIR_SIZE, sizeof(reg_t)); // FIXME -- sizeof(char) or sizeof(reg_t) ??
|
|
|
|
str->value[0].segment = s->string_frag_segment; // Set to empty string
|
2009-05-20 17:53:31 +00:00
|
|
|
str->value[0].offset = 0;
|
2009-03-10 14:52:02 +00:00
|
|
|
|
2009-02-15 06:10:59 +00:00
|
|
|
|
|
|
|
s->r_acc = s->r_prev = NULL_REG;
|
2009-07-08 10:25:37 +00:00
|
|
|
s->restAdjust = 0;
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-04-28 15:58:19 +00:00
|
|
|
s->_executionStack.clear(); // Start without any execution stack
|
2009-02-18 22:41:57 +00:00
|
|
|
s->execution_stack_base = -1; // No vm is running yet
|
2009-02-15 06:10:59 +00:00
|
|
|
|
|
|
|
s->restarting_flags = SCI_GAME_IS_NOT_RESTARTING;
|
|
|
|
|
2009-02-18 22:41:57 +00:00
|
|
|
s->bp_list = NULL; // No breakpoints defined
|
2009-02-15 06:10:59 +00:00
|
|
|
s->have_bp = 0;
|
|
|
|
|
2009-08-30 14:53:58 +00:00
|
|
|
if (s->detectLofsType() == SCI_VERSION_1_MIDDLE)
|
2009-08-25 08:38:14 +00:00
|
|
|
s->segmentManager->setExportWidth(1);
|
2009-02-15 06:10:59 +00:00
|
|
|
else
|
2009-08-25 08:38:14 +00:00
|
|
|
s->segmentManager->setExportWidth(0);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-05-26 14:44:14 +00:00
|
|
|
debug(2, "Engine initialized");
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-03-23 14:24:10 +00:00
|
|
|
s->pic_priority_table = NULL;
|
2009-05-10 20:13:43 +00:00
|
|
|
s->_pics.clear();
|
2009-02-15 06:10:59 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-21 10:47:56 +00:00
|
|
|
void script_set_gamestate_save_dir(EngineState *s, const char *path) {
|
2009-02-26 23:03:35 +00:00
|
|
|
SystemString *str = &s->sys_strings->strings[SYS_STRING_SAVEDIR];
|
2009-05-20 17:53:31 +00:00
|
|
|
|
2009-05-05 12:23:05 +00:00
|
|
|
strncpy((char *)str->value, path, str->max_size); // FIXME -- strncpy or internal_stringfrag_strncpy ?
|
2009-03-11 22:50:06 +00:00
|
|
|
str->value[str->max_size - 1].segment = s->string_frag_segment; // Make sure to terminate
|
|
|
|
str->value[str->max_size - 1].offset &= 0xff00; // Make sure to terminate
|
2009-03-10 14:52:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void internal_stringfrag_strncpy(EngineState *s, reg_t *dest, reg_t *src, int len);
|
|
|
|
|
2009-02-21 10:47:56 +00:00
|
|
|
void script_free_vm_memory(EngineState *s) {
|
2009-05-26 14:44:14 +00:00
|
|
|
debug(2, "Freeing VM memory");
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-08-25 08:38:14 +00:00
|
|
|
if (s->segmentManager)
|
|
|
|
s->segmentManager->_classtable.clear();
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-18 22:41:57 +00:00
|
|
|
// Close all opened file handles
|
2009-02-22 21:38:46 +00:00
|
|
|
s->_fileHandles.clear();
|
2009-02-27 01:17:24 +00:00
|
|
|
s->_fileHandles.resize(5);
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
2009-02-21 10:47:56 +00:00
|
|
|
void script_free_engine(EngineState *s) {
|
2009-02-15 06:10:59 +00:00
|
|
|
script_free_vm_memory(s);
|
|
|
|
|
2009-05-26 14:44:14 +00:00
|
|
|
debug(2, "Freeing state-dependant data");
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
2009-02-21 10:47:56 +00:00
|
|
|
void script_free_breakpoints(EngineState *s) {
|
2009-02-28 11:12:59 +00:00
|
|
|
Breakpoint *bp, *bp_next;
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-18 22:41:57 +00:00
|
|
|
// Free breakpoint list
|
2009-02-15 06:10:59 +00:00
|
|
|
bp = s->bp_list;
|
|
|
|
while (bp) {
|
|
|
|
bp_next = bp->next;
|
2009-02-18 22:41:57 +00:00
|
|
|
if (bp->type == BREAK_SELECTOR)
|
|
|
|
free(bp->data.name);
|
2009-02-15 22:28:12 +00:00
|
|
|
free(bp);
|
2009-02-15 06:10:59 +00:00
|
|
|
bp = bp_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
s->bp_list = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************/
|
|
|
|
/* Game instance stuff: Init/Unitialize state-dependant data */
|
|
|
|
/*************************************************************/
|
|
|
|
|
2009-02-21 10:47:56 +00:00
|
|
|
int game_init(EngineState *s) {
|
2009-02-24 22:40:54 +00:00
|
|
|
// FIXME Use new VM instantiation code all over the place"
|
2009-05-08 09:53:31 +00:00
|
|
|
DataStack *stack;
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-08-25 08:38:14 +00:00
|
|
|
stack = s->segmentManager->allocateStack(VM_STACK_SIZE, &s->stack_segment);
|
2009-02-15 06:10:59 +00:00
|
|
|
s->stack_base = stack->entries;
|
|
|
|
s->stack_top = s->stack_base + VM_STACK_SIZE;
|
|
|
|
|
2009-08-25 08:38:14 +00:00
|
|
|
if (!script_instantiate(s->resourceManager, s->segmentManager, 0)) {
|
2009-05-26 14:44:14 +00:00
|
|
|
warning("game_init(): Could not instantiate script 0");
|
2009-02-15 06:10:59 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-02-18 22:41:57 +00:00
|
|
|
s->parser_valid = 0; // Invalidate parser
|
|
|
|
s->parser_event = NULL_REG; // Invalidate parser event
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-03-24 17:41:26 +00:00
|
|
|
s->_synonyms.clear(); // No synonyms
|
2009-02-15 06:10:59 +00:00
|
|
|
|
|
|
|
if (s->gfx_state && _reset_graphics_input(s))
|
|
|
|
return 1;
|
|
|
|
|
2009-02-18 22:41:57 +00:00
|
|
|
s->successor = NULL; // No successor
|
2009-03-24 12:46:48 +00:00
|
|
|
s->_statusBarText.clear(); // Status bar is blank
|
2009-02-15 06:10:59 +00:00
|
|
|
s->status_bar_foreground = 0;
|
2009-08-25 08:38:14 +00:00
|
|
|
s->status_bar_background = !s->resourceManager->isVGA() ? 15 : 255;
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-26 23:03:35 +00:00
|
|
|
SystemString *str = &s->sys_strings->strings[SYS_STRING_PARSER_BASE];
|
|
|
|
str->name = strdup("parser-base");
|
|
|
|
str->max_size = MAX_PARSER_BASE;
|
2009-05-05 12:23:05 +00:00
|
|
|
str->value = (reg_t *)calloc(MAX_PARSER_BASE + 1, sizeof(char)); // FIXME -- sizeof(char) or sizeof(reg_t) ??
|
2009-03-10 14:52:02 +00:00
|
|
|
str->value[0].segment = s->string_frag_segment; // Set to empty string
|
|
|
|
str->value[0].offset = 0; // Set to empty string
|
2009-02-26 23:03:35 +00:00
|
|
|
|
2009-02-15 06:10:59 +00:00
|
|
|
s->parser_base = make_reg(s->sys_strings_segment, SYS_STRING_PARSER_BASE);
|
|
|
|
|
2009-02-25 21:43:57 +00:00
|
|
|
s->game_start_time = g_system->getMillis();
|
|
|
|
s->last_wait_time = s->game_start_time;
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-21 18:39:53 +00:00
|
|
|
srand(g_system->getMillis()); // Initialize random number generator
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-23 03:04:52 +00:00
|
|
|
// script_dissect(0, s->_selectorNames);
|
2009-02-18 22:41:57 +00:00
|
|
|
// The first entry in the export table of script 0 points to the game object
|
2009-08-25 08:38:14 +00:00
|
|
|
s->game_obj = script_lookup_export(s->segmentManager, 0, 0);
|
|
|
|
s->_gameName = obj_get_name(s->segmentManager, s->game_obj);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-08-17 05:55:21 +00:00
|
|
|
debug(2, " \"%s\" at %04x:%04x", s->_gameName.c_str(), PRINT_REG(s->game_obj));
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-18 22:41:57 +00:00
|
|
|
// Mark parse tree as unused
|
2009-06-06 16:43:13 +00:00
|
|
|
s->parser_nodes[0].type = kParseTreeLeafNode;
|
2009-02-15 06:10:59 +00:00
|
|
|
s->parser_nodes[0].content.value = 0;
|
|
|
|
|
2009-03-24 11:31:16 +00:00
|
|
|
s->_menubar = new Menubar(); // Create menu bar
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-26 19:28:21 +00:00
|
|
|
if (s->sfx_init_flags & SFX_STATE_FLAG_NOSOUND)
|
|
|
|
game_init_sound(s, 0);
|
|
|
|
|
2009-08-10 18:37:47 +00:00
|
|
|
// Load game language into printLang property of game object
|
|
|
|
s->getLanguage();
|
|
|
|
|
2009-02-15 06:10:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-21 10:47:56 +00:00
|
|
|
int game_exit(EngineState *s) {
|
2009-04-28 15:58:19 +00:00
|
|
|
s->_executionStack.clear();
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-26 19:28:21 +00:00
|
|
|
if (!s->successor) {
|
2009-05-28 22:48:15 +00:00
|
|
|
s->_sound.sfx_exit();
|
2009-02-26 19:28:21 +00:00
|
|
|
// Reinit because some other code depends on having a valid state
|
|
|
|
game_init_sound(s, SFX_STATE_FLAG_NOSOUND);
|
|
|
|
}
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-08-25 08:38:14 +00:00
|
|
|
s->segmentManager->_classtable.clear();
|
|
|
|
delete s->segmentManager;
|
|
|
|
s->segmentManager = 0;
|
2009-02-15 22:28:12 +00:00
|
|
|
|
2009-03-24 17:41:26 +00:00
|
|
|
s->_synonyms.clear();
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-05-26 14:44:14 +00:00
|
|
|
debug(2, "Freeing miscellaneous data...");
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-24 22:40:54 +00:00
|
|
|
// TODO Free parser segment here
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-24 22:40:54 +00:00
|
|
|
// TODO Free scripts here
|
|
|
|
|
2009-03-24 11:31:16 +00:00
|
|
|
delete s->_menubar;
|
2009-02-15 06:10:59 +00:00
|
|
|
|
|
|
|
_free_graphics_input(s);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-21 10:23:36 +00:00
|
|
|
} // End of namespace Sci
|