aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/events/default/default-events.h3
-rw-r--r--backends/platform/ps2/Gs2dScreen.cpp15
-rw-r--r--backends/platform/ps2/Gs2dScreen.h1
-rw-r--r--backends/platform/ps2/Makefile.gdb94
-rw-r--r--backends/platform/ps2/Makefile.ps210
-rw-r--r--backends/platform/ps2/fileio.cpp126
-rw-r--r--backends/platform/ps2/fileio.h5
-rw-r--r--backends/platform/ps2/irxboot.cpp9
-rw-r--r--backends/platform/ps2/ps2input.cpp34
-rw-r--r--backends/platform/ps2/savefilemgr.cpp6
-rw-r--r--backends/platform/ps2/systemps2.cpp44
-rw-r--r--backends/platform/ps2/systemps2.h15
-rw-r--r--backends/platform/wince/wince-sdl.cpp7
-rw-r--r--backends/platform/wince/wince-sdl.h3
-rw-r--r--base/main.cpp6
-rw-r--r--common/array.h12
-rw-r--r--common/events.h4
-rw-r--r--common/util.cpp4
-rw-r--r--engines/cruise/cruise_main.cpp77
-rw-r--r--engines/kyra/script.cpp2
-rw-r--r--engines/kyra/script_tim.cpp2
-rw-r--r--engines/sci/console.cpp64
-rw-r--r--engines/sci/engine/game.cpp14
-rw-r--r--engines/sci/engine/kernel.h8
-rw-r--r--engines/sci/engine/kgraphics.cpp34
-rw-r--r--engines/sci/engine/kmisc.cpp4
-rw-r--r--engines/sci/engine/kmovement.cpp4
-rw-r--r--engines/sci/engine/kscripts.cpp6
-rw-r--r--engines/sci/engine/ksound.cpp4
-rw-r--r--engines/sci/engine/kstring.cpp7
-rw-r--r--engines/sci/engine/said.cpp2
-rw-r--r--engines/sci/engine/said.y2
-rw-r--r--engines/sci/engine/savegame.cpp14
-rw-r--r--engines/sci/engine/scriptdebug.cpp10
-rw-r--r--engines/sci/engine/seg_manager.cpp2
-rw-r--r--engines/sci/engine/state.cpp3
-rw-r--r--engines/sci/engine/state.h5
-rw-r--r--engines/sci/engine/vm.cpp34
-rw-r--r--engines/sci/engine/vm.h2
-rw-r--r--engines/sci/sci.cpp7
-rw-r--r--engines/sci/sci.h8
-rw-r--r--engines/scumm/gfx.cpp2
-rw-r--r--engines/scumm/saveload.cpp2
-rw-r--r--engines/sword1/sound.cpp99
-rw-r--r--engines/sword1/sound.h3
-rw-r--r--engines/sword1/sword1.cpp4
-rw-r--r--gui/ListWidget.cpp2
47 files changed, 597 insertions, 228 deletions
diff --git a/backends/events/default/default-events.h b/backends/events/default/default-events.h
index 5841318fd4..9d47104608 100644
--- a/backends/events/default/default-events.h
+++ b/backends/events/default/default-events.h
@@ -143,6 +143,9 @@ public:
virtual int shouldQuit() const { return _shouldQuit; }
virtual int shouldRTL() const { return _shouldRTL; }
virtual void resetRTL() { _shouldRTL = false; }
+#ifdef FORCE_RTL
+ virtual void resetQuit() { _shouldQuit = false; }
+#endif
#ifdef ENABLE_KEYMAPPER
virtual Common::Keymapper *getKeymapper() { return _keymapper; }
diff --git a/backends/platform/ps2/Gs2dScreen.cpp b/backends/platform/ps2/Gs2dScreen.cpp
index e9a846f659..a9f1d7c51d 100644
--- a/backends/platform/ps2/Gs2dScreen.cpp
+++ b/backends/platform/ps2/Gs2dScreen.cpp
@@ -337,6 +337,7 @@ void Gs2dScreen::newScreenSize(uint16 width, uint16 height) {
memset(_screenBuf, 0, _width * height);
memset(_overlayBuf, 0, _width * height * 2);
memset(_clut, 0, 256 * sizeof(uint32));
+ _clut[1] = GS_RGBA(0xC0, 0xC0, 0xC0, 0);
// clear video ram
_dmaPipe->uploadTex(_clutPtrs[MOUSE], 64, 0, 0, GS_PSMCT32, _clut, 16, 16);
@@ -345,7 +346,8 @@ void Gs2dScreen::newScreenSize(uint16 width, uint16 height) {
_dmaPipe->flush();
_dmaPipe->waitForDma();
- _clutChanged = _screenChanged = _overlayChanged = false;
+ /*_clutChanged = */ _screenChanged = _overlayChanged = false;
+ _clutChanged = true; // reload palette on scr change
_texCoords[1].u = SCALE(_width);
_texCoords[1].v = SCALE(_height);
@@ -396,6 +398,13 @@ void Gs2dScreen::clearScreen(void) {
SignalSema(g_DmacSema);
}
+void Gs2dScreen::fillScreen(uint32 col) {
+ WaitSema(g_DmacSema);
+ memset(_screenBuf, col, _width * _height);
+ _screenChanged = true;
+ SignalSema(g_DmacSema);
+}
+
Graphics::Surface *Gs2dScreen::lockScreen() {
WaitSema(g_DmacSema);
@@ -541,11 +550,11 @@ Graphics::PixelFormat Gs2dScreen::getOverlayFormat(void) {
}
int16 Gs2dScreen::getOverlayWidth(void) {
- return _videoMode.overlayWidth;
+ return _width; // _videoMode.overlayWidth;
}
int16 Gs2dScreen::getOverlayHeight(void) {
- return _videoMode.overlayHeight;
+ return _height; // _videoMode.overlayHeight;
}
void Gs2dScreen::setShakePos(int shake) {
diff --git a/backends/platform/ps2/Gs2dScreen.h b/backends/platform/ps2/Gs2dScreen.h
index 91dfc9d327..4657ab02d9 100644
--- a/backends/platform/ps2/Gs2dScreen.h
+++ b/backends/platform/ps2/Gs2dScreen.h
@@ -61,6 +61,7 @@ public:
void copyPrintfOverlay(const uint8* buf);
void clearPrintfOverlay(void);
void clearScreen(void);
+ void fillScreen(uint32 col);
Graphics::Surface *lockScreen();
void unlockScreen();
diff --git a/backends/platform/ps2/Makefile.gdb b/backends/platform/ps2/Makefile.gdb
new file mode 100644
index 0000000000..7177275830
--- /dev/null
+++ b/backends/platform/ps2/Makefile.gdb
@@ -0,0 +1,94 @@
+# $Header: Exp $
+ include $(PS2SDK)/Defs.make
+
+PS2_EXTRA = /media/disk/nw8240/extras/scummvm/ports
+PS2_EXTRA_INCS = /zlib/include /libmad/ee/include /SjPcm/ee/src /tremor
+PS2_EXTRA_LIBS = /zlib/lib /libmad/ee/lib /SjPcm/ee/lib /tremor/tremor
+
+ENABLED=STATIC_PLUGIN
+
+#control build
+DISABLE_SCALERS = true
+DISABLE_HQ_SCALERS = true
+
+ENABLE_SCUMM = $(ENABLED)
+ENABLE_SCUMM_7_8 = $(ENABLED)
+#ENABLE_HE = $(ENABLED)
+#ENABLE_AGI = $(ENABLED)
+#ENABLE_AGOS = $(ENABLED)
+#ENABLE_CINE = $(ENABLED)
+#ENABLE_CRUISE = $(ENABLED)
+#ENABLE_DRASCULA = $(ENABLED)
+#ENABLE_GOB = $(ENABLED)
+#ENABLE_IGOR = $(ENABLED)
+#ENABLE_KYRA = $(ENABLED)
+#ENABLE_LURE = $(ENABLED)
+ # ENABLE_M4 = $(ENABLED)
+#ENABLE_MADE = $(ENABLED)
+#ENABLE_PARALLACTION = $(ENABLED)
+#ENABLE_QUEEN = $(ENABLED)
+#ENABLE_SAGA = $(ENABLED)
+#ENABLE_SAGA2 = $(ENABLED)
+#ENABLE_IHNM = $(ENABLED)
+#ENABLE_SKY = $(ENABLED)
+#ENABLE_SWORD1 = $(ENABLED)
+#ENABLE_SWORD2 = $(ENABLED)
+ # ENABLE_TINSEL = $(ENABLED)
+#ENABLE_TOUCHE = $(ENABLED)
+
+HAVE_GCC3 = true
+
+CC = ee-gcc
+CXX = ee-g++
+AS = ee-gcc
+LD = ee-gcc
+AR = ee-ar cru
+RANLIB = ee-ranlib
+STRIP = ee-strip
+MKDIR = mkdir -p
+RM = rm -f
+
+srcdir = ../../..
+VPATH = $(srcdir)
+INCDIR = ../../../
+# DEPDIR = .deps
+
+DEFINES = -DUSE_VORBIS -DUSE_TREMOR -DUSE_MAD -DUSE_ZLIB -DFORCE_RTL -D_EE -D__PLAYSTATION2__ -D__PS2_DEBUG__ -g -Wall -Wno-multichar
+
+
+INCLUDES = $(addprefix -I$(PS2_EXTRA),$(PS2_EXTRA_INCS))
+INCLUDES += -I $(PS2GDB)/ee -I $(PS2SDK)/ee/include -I $(PS2SDK)/common/include -I ./common -I . -I $(srcdir) -I $(srcdir)/engines
+
+TARGET = elf/scummvm.elf
+
+OBJS := backends/platform/ps2/DmaPipe.o \
+ backends/platform/ps2/Gs2dScreen.o \
+ backends/platform/ps2/irxboot.o \
+ backends/platform/ps2/ps2input.o \
+ backends/platform/ps2/ps2pad.o \
+ backends/platform/ps2/savefilemgr.o \
+ backends/platform/ps2/fileio.o \
+ backends/platform/ps2/asyncfio.o \
+ backends/platform/ps2/icon.o \
+ backends/platform/ps2/cd.o \
+ backends/platform/ps2/eecodyvdfs.o \
+ backends/platform/ps2/rpckbd.o \
+ backends/platform/ps2/systemps2.o \
+ backends/platform/ps2/ps2mutex.o \
+ backends/platform/ps2/ps2time.o \
+ backends/platform/ps2/ps2debug.o
+
+MODULE_DIRS += .
+
+include $(srcdir)/Makefile.common
+
+LDFLAGS += -mno-crt0 $(PS2SDK)/ee/startup/crt0.o -T $(PS2SDK)/ee/startup/linkfile
+LDFLAGS += -L $(PS2GDB)/lib -L $(PS2SDK)/ee/lib -L .
+LDFLAGS += $(addprefix -L$(PS2_EXTRA),$(PS2_EXTRA_LIBS))
+LDFLAGS += -lmc -lpad -lmouse -lhdd -lpoweroff -lsjpcm -lmad -ltremor -lz -lm -lc -lfileXio -lps2gdbStub -lps2ip -ldebug -lkernel -lstdc++
+
+all: $(TARGET)
+
+$(TARGET): $(OBJS)
+ $(LD) $^ $(LDFLAGS) -o $@
+
diff --git a/backends/platform/ps2/Makefile.ps2 b/backends/platform/ps2/Makefile.ps2
index 812599d0c0..5abeae5fb5 100644
--- a/backends/platform/ps2/Makefile.ps2
+++ b/backends/platform/ps2/Makefile.ps2
@@ -1,7 +1,7 @@
# $Header: Exp $
include $(PS2SDK)/Defs.make
-PS2_EXTRA = /media/disk-1/nw8240/extras/scummvm/ports
+PS2_EXTRA = /media/disk/nw8240/extras/scummvm/ports
PS2_EXTRA_INCS = /zlib/include /libmad/ee/include /SjPcm/ee/src /tremor
PS2_EXTRA_LIBS = /zlib/lib /libmad/ee/lib /SjPcm/ee/lib /tremor/tremor
@@ -45,15 +45,15 @@ LD = ee-gcc
AR = ee-ar cru
RANLIB = ee-ranlib
STRIP = ee-strip
-MKDIR = mkdir -p
-RM = rm -f
+MKDIR = mkdir -p
+RM = rm -f
srcdir = ../../..
VPATH = $(srcdir)
INCDIR = ../../../
# DEPDIR = .deps
-DEFINES = -DUSE_VORBIS -DUSE_TREMOR -DUSE_MAD -DUSE_ZLIB -D_EE -D__PLAYSTATION2__ -O2 -Wall -Wno-multichar
+DEFINES = -DUSE_VORBIS -DUSE_TREMOR -DUSE_MAD -DUSE_ZLIB -DFORCE_RTL -D_EE -D__PLAYSTATION2__ -O2 -Wall -Wno-multichar
INCLUDES = $(addprefix -I$(PS2_EXTRA),$(PS2_EXTRA_INCS))
@@ -86,7 +86,7 @@ LDFLAGS += -mno-crt0 $(PS2SDK)/ee/startup/crt0.o -T $(PS2SDK)/ee/startup/linkfil
LDFLAGS += -L $(PS2SDK)/ee/lib -L .
LDFLAGS += $(addprefix -L$(PS2_EXTRA),$(PS2_EXTRA_LIBS))
LDFLAGS += -lmc -lpad -lmouse -lhdd -lpoweroff -lsjpcm -lmad -ltremor -lz -lm -lc -lfileXio -lkernel -lstdc++
-# LDFLAGS += -s
+LDFLAGS += -s
all: $(TARGET)
diff --git a/backends/platform/ps2/fileio.cpp b/backends/platform/ps2/fileio.cpp
index fc35306907..864f840e8a 100644
--- a/backends/platform/ps2/fileio.cpp
+++ b/backends/platform/ps2/fileio.cpp
@@ -58,10 +58,11 @@ Ps2File::Ps2File(void) {
_cacheSize = 0;
_cachePos = 0;
_eof = false;
+ _err = false;
// _cache = (uint8 *)malloc(PS2_CACHE_MAX);
- _cacheBuf = (uint8*)memalign(64, CACHE_SIZE);
+ _cacheBuf = (uint8*)memalign(64, CACHE_SIZE * 2);
_cacheOpRunning = 0;
_filePos = _physFilePos = _cachePos = 0;
@@ -80,7 +81,16 @@ Ps2File::Ps2File(void) {
}
Ps2File::~Ps2File(void) {
+ uint32 w;
if (_fd >= 0) {
+
+ if (_mode != O_RDONLY) {
+ fio.seek(_fd, 0, SEEK_SET);
+ fio.write(_fd, _cacheBuf, _filePos);
+ w = fio.sync(_fd);
+ printf("flushed wbuf: %x of %x\n", w, _filePos);
+ }
+
fio.close(_fd);
uint32 r = fio.sync(_fd);
printf("close [%d] - sync'd = %d\n", _fd, r);
@@ -95,24 +105,87 @@ Ps2File::~Ps2File(void) {
}
bool Ps2File::open(const char *name, int mode) {
- assert(_fd < 0);
-
+#if 1
_fd = fio.open(name, mode);
printf("open %s [%d]\n", name, _fd);
if (_fd >= 0) {
- _fileSize = fio.seek(_fd, 0, SEEK_END);
- if (mode == O_RDONLY)
- // if (!(mode & O_APPEND))
+ _mode = mode;
+ _filePos = 0;
+
+ if (_mode == O_RDONLY) {
+ _fileSize = fio.seek(_fd, 0, SEEK_END);
fio.seek(_fd, 0, SEEK_SET);
+ }
+ else
+ _fileSize = 0;
+ printf(" _mode = %x\n", _mode);
+ printf(" _fileSize = %d\n", _fileSize);
+ // printf(" _filePos = %d\n", _filePos);
+
+ return true;
+ }
+
+ return false;
+#else
+ uint32 r;
+
+ // hack: FIO does not reports size for RW (?)
+ _fd = fio.open(name, O_RDONLY);
+ if (_fd >= 0) {
+ _fileSize = fio.seek(_fd, 0, SEEK_END);
+ fio.seek(_fd, 0, SEEK_SET); /* rewind ! */
+
+ if (_fileSize && mode != O_RDONLY) {
+ fio.read(_fd, _cacheBuf, _fileSize);
+ r = fio.sync(_fd);
+ printf(" sz=%d, read=%d\n", _fileSize, r);
+ assert(r == _fileSize);
+ }
+
+ fio.close(_fd);
+ }
+ else
+ _fileSize = 0; /* new file */
+
+ _fd = fio.open(name, mode);
+
+ printf("open %s [%d]\n", name, _fd);
+
+ if (_fd >= 0) {
+ _mode = mode;
+ _filePos = 0;
+
+ if (_fileSize) { /* existing data */
+ if (mode == O_RDONLY) {
+ /* DANGER: for w* modes it will truncate your fine files */
+ fio.seek(_fd, 0, SEEK_SET);
+ }
+ else if (_mode & O_APPEND) {
+ fio.seek(_fd, 0, _fileSize);
+ _filePos = _fileSize;
+ }
+ #if 0 /* file already trunc'd when opened as w* -> moved up */
+ if (mode != O_RDONLY) {
+ fio.read(_fd, _cacheBuf, _fileSize);
+ r = fio.sync(_fd);
+ printf(" sz=%d, read=%d\n", _fileSize, r);
+ assert(r == _fileSize);
+ // _fileSize = fio.seek(_fd, 0, SEEK_END);
+ }
+ #endif
+ }
+
+ printf(" _mode = %x\n", _mode);
printf(" _fileSize = %d\n", _fileSize);
printf(" _filePos = %d\n", _filePos);
return true;
} else
return false;
+#endif
}
int32 Ps2File::tell(void) {
@@ -152,10 +225,11 @@ bool Ps2File::eof(void) {
}
bool Ps2File::getErr(void) {
- return _eof;
+ return _err;
}
void Ps2File::setErr(bool err) {
+ _err = err;
_eof = err;
}
@@ -189,7 +263,9 @@ int Ps2File::seek(int32 offset, int origin) {
_eof = false;
res = 0;
}
- else _eof = true;
+ else {
+ _eof = true;
+ }
// printf("seek [%d] %d %d\n", _fd, offset, origin);
// printf(" res = %d\n", res);
@@ -225,7 +301,7 @@ void Ps2File::cacheReadAhead(void) {
_cachePos = cachePosEnd = _filePos & ~READ_ALIGN_MASK;
assert(_filePos == _physFilePos);
} else {
- uint32 cacheDiff = _filePos - _cachePos;
+ uint32 cacheDiff = _filePos - _cachePos;
assert(_bytesInCache >= cacheDiff);
cacheDiff &= ~READ_ALIGN_MASK;
_bytesInCache -= cacheDiff;
@@ -278,10 +354,17 @@ uint32 Ps2File::read(void *dest, uint32 len) {
printf("read (1) : _cachePos = %d\n", _cachePos);
#endif
+ if (len == 0) {
+#ifdef __PS2_FILE_SEMA__
+ SignalSema(_sema);
+#endif
+ return 0;
+ }
+
if (_filePos >= _fileSize) {
_eof = true;
#ifdef __PS2_FILE_SEMA__
- SignalSema(_sema);
+ SignalSema(_sema);
#endif
return 0;
}
@@ -344,32 +427,18 @@ uint32 Ps2File::read(void *dest, uint32 len) {
}
uint32 Ps2File::write(const void *src, uint32 len) {
- uint32 w;
#ifdef __PS2_FILE_SEMA__
WaitSema(_sema);
#endif
- _cacheSize = 0;
- w = fio.sync(_fd);
- assert(w==0);
-
- fio.seek(_fd, _filePos, SEEK_SET);
- fio.write(_fd, src, len);
-
- w = fio.sync(_fd);
+ memcpy(&_cacheBuf[_filePos], src, len);
+ _filePos += len;
#ifdef __PS2_FILE_SEMA__
SignalSema(_sema);
#endif
- if (w) {
- _filePos += w;
- if (w < len)
- _eof = true;
- return w;
- }
-
- return 0;
+ return len;
}
FILE *ps2_fopen(const char *fname, const char *mode) {
@@ -468,8 +537,9 @@ int ps2_fflush(FILE *stream) {
int ps2_ferror(FILE *stream) {
int err = ((Ps2File*)stream)->getErr();
- if (err)
+ if (err) {
printf("ferror -> %d\n", err);
+ }
return err;
}
diff --git a/backends/platform/ps2/fileio.h b/backends/platform/ps2/fileio.h
index e793c29d4b..6838162e06 100644
--- a/backends/platform/ps2/fileio.h
+++ b/backends/platform/ps2/fileio.h
@@ -62,15 +62,16 @@ private:
void cacheReadSync(void);
int _fd;
+ uint32 _mode;
uint32 _fileSize;
uint32 _filePos;
uint32 _cacheSize;
uint32 _cachePos;
- // uint8 cache[2048];
uint8 *_cache;
- int _eof;
+ bool _eof;
+ bool _err;
int _sema;
diff --git a/backends/platform/ps2/irxboot.cpp b/backends/platform/ps2/irxboot.cpp
index daa592522a..15cb816c31 100644
--- a/backends/platform/ps2/irxboot.cpp
+++ b/backends/platform/ps2/irxboot.cpp
@@ -55,15 +55,16 @@ IrxFile irxFiles[] = {
{ "USB_MASS.IRX", USB | OPTIONAL, MASS_DRIVER, NULL, 0 },
{ "PS2MOUSE.IRX", USB | OPTIONAL, MOUSE_DRIVER, NULL, 0 },
{ "RPCKBD.IRX", USB | OPTIONAL, KBD_DRIVER, NULL, 0 },
-
+#ifndef NO_ADAPTOR
{ "POWEROFF.IRX", HDD | OPTIONAL | NOT_HOST | DEPENDANCY, HDD_DRIVER, NULL, 0 },
{ "PS2DEV9.IRX", HDD | OPTIONAL | NOT_HOST | DEPENDANCY, HDD_DRIVER, NULL, 0 },
{ "PS2ATAD.IRX", HDD | OPTIONAL | DEPENDANCY, HDD_DRIVER, NULL, 0 },
{ "PS2HDD.IRX", HDD | OPTIONAL | DEPENDANCY, HDD_DRIVER, hddArg, sizeof(hddArg) },
{ "PS2FS.IRX", HDD | OPTIONAL | DEPENDANCY, HDD_DRIVER, pfsArg, sizeof(pfsArg) },
- { "PS2IP.IRX", NET | NOT_HOST, NET_DRIVER, NULL, 0 },
- { "PS2SMAP.IRX", NET | NOT_HOST, NET_DRIVER, netArg, sizeof(netArg) },
- { "PS2HOST.IRX", NET | NOT_HOST, NET_DRIVER, NULL, 0 }
+ { "PS2IP.IRX", NET | OPTIONAL | NOT_HOST | DEPENDANCY, NET_DRIVER, NULL, 0 },
+ { "PS2SMAP.IRX", NET | OPTIONAL | NOT_HOST | DEPENDANCY, NET_DRIVER, netArg, sizeof(netArg) },
+ { "PS2HOST.IRX", NET | OPTIONAL | NOT_HOST | DEPENDANCY, NET_DRIVER, NULL, 0 }
+#endif
};
static const int numIrxFiles = sizeof(irxFiles) / sizeof(irxFiles[0]);
diff --git a/backends/platform/ps2/ps2input.cpp b/backends/platform/ps2/ps2input.cpp
index c320e79eed..964a773f7e 100644
--- a/backends/platform/ps2/ps2input.cpp
+++ b/backends/platform/ps2/ps2input.cpp
@@ -510,22 +510,22 @@ const Common::KeyCode Ps2Input::_usbToSdlk[0x100] = {
};
const Common::KeyCode Ps2Input::_padCodes[16] = {
- Common::KEYCODE_1, // Select
- Common::KEYCODE_INVALID, // L3
- Common::KEYCODE_INVALID, // R3
- Common::KEYCODE_F5, // Start
- Common::KEYCODE_INVALID, // Up
- Common::KEYCODE_INVALID, // Right
- Common::KEYCODE_INVALID, // Down
- Common::KEYCODE_INVALID, // Left
- Common::KEYCODE_KP0, // L2
- Common::KEYCODE_INVALID, // R2
- Common::KEYCODE_n, // L1
- Common::KEYCODE_y, // R1
- Common::KEYCODE_ESCAPE, // Triangle
- Common::KEYCODE_INVALID, // Circle => Right mouse button
- Common::KEYCODE_INVALID, // Cross => Left mouse button
- Common::KEYCODE_RETURN // Square
+ Common::KEYCODE_1, // Select
+ Common::KEYCODE_INVALID, // L3
+ Common::KEYCODE_INVALID, // R3
+ Common::KEYCODE_F5, // Start
+ Common::KEYCODE_INVALID, // Up
+ Common::KEYCODE_INVALID, // Right
+ Common::KEYCODE_INVALID, // Down
+ Common::KEYCODE_INVALID, // Left
+ Common::KEYCODE_KP0, // L2
+ Common::KEYCODE_PERIOD, // R2
+ Common::KEYCODE_n, // L1
+ Common::KEYCODE_y, // R1
+ Common::KEYCODE_ESCAPE, // Triangle
+ Common::KEYCODE_INVALID, // Circle => Right mouse button
+ Common::KEYCODE_INVALID, // Cross => Left mouse button
+ Common::KEYCODE_RETURN // Square
};
const Common::KeyCode Ps2Input::_padFlags[16] = {
@@ -544,7 +544,7 @@ const Common::KeyCode Ps2Input::_padFlags[16] = {
Common::KEYCODE_INVALID, // Triangle
Common::KEYCODE_INVALID, // Circle
Common::KEYCODE_INVALID, // Cross
- Common::KEYCODE_INVALID // Square
+ Common::KEYCODE_INVALID // Square
};
diff --git a/backends/platform/ps2/savefilemgr.cpp b/backends/platform/ps2/savefilemgr.cpp
index 1271a43d42..1613863530 100644
--- a/backends/platform/ps2/savefilemgr.cpp
+++ b/backends/platform/ps2/savefilemgr.cpp
@@ -239,10 +239,10 @@ Common::StringList Ps2SaveFileManager::listSavefiles(const Common::String &patte
if (!savePath.exists() || !savePath.isDirectory())
return Common::StringList();
- printf("listSavefiles = %s\n", pattern);
+ printf("listSavefiles = %s\n", pattern.c_str());
if (_mc) {
- strcpy(temp, pattern);
+ strcpy(temp, pattern.c_str());
// mcSplit(temp, game, ext);
game = strdup(strtok(temp, "."));
@@ -255,7 +255,7 @@ Common::StringList Ps2SaveFileManager::listSavefiles(const Common::String &patte
}
else {
_dir = Common::String(savePath.getPath());
- search = Common::String(pattern);
+ search = pattern;
}
Common::FSDirectory dir(_dir);
diff --git a/backends/platform/ps2/systemps2.cpp b/backends/platform/ps2/systemps2.cpp
index f29caf2279..57a03f777d 100644
--- a/backends/platform/ps2/systemps2.cpp
+++ b/backends/platform/ps2/systemps2.cpp
@@ -66,6 +66,10 @@
#include "icon.h"
#include "ps2temp.h"
+#ifdef __PS2_DEBUG__
+#include <debug.h>
+#endif
+
// asm("mfc0 %0, $9\n" : "=r"(tickStart));
extern void *_gp;
@@ -95,6 +99,11 @@ PS2Device detectBootPath(const char *elfPath, char *bootPath);
extern AsyncFio fio;
+#ifdef __PS2_DEBUG__
+extern "C" int gdb_stub_main(int argc, char *argv[]);
+extern "C" void breakpoint(void);
+#endif
+
extern "C" int scummvm_main(int argc, char *argv[]);
extern "C" int main(int argc, char *argv[]) {
@@ -117,6 +126,10 @@ extern "C" int main(int argc, char *argv[]) {
sioprintf("Result = %d\n", res);
}
+#ifdef __PS2_DEBUG__
+ gdb_stub_main(argc, argv);
+#endif
+
sioprintf("Creating system\n");
g_system = g_systemPs2 = new OSystem_PS2(argv[0]);
@@ -241,6 +254,8 @@ OSystem_PS2::OSystem_PS2(const char *elfPath) {
_printY = 0;
_msgClearTime = 0;
_systemQuit = false;
+ _modeChanged = false;
+ _screenChangeCount = 0;
_screen = new Gs2dScreen(320, 200, TV_DONT_CARE);
@@ -327,9 +342,8 @@ OSystem_PS2::OSystem_PS2(const char *elfPath) {
void OSystem_PS2::init(void) {
sioprintf("Timer...\n");
_scummTimerManager = new DefaultTimerManager();
- _scummEventManager = new DefaultEventManager();
_scummMixer = new Audio::MixerImpl(this);
- _scummMixer->setOutputRate(44100);
+ _scummMixer->setOutputRate(48000);
_scummMixer->setReady(true);
initTimer();
@@ -520,6 +534,9 @@ void OSystem_PS2::initSize(uint width, uint height) {
_oldMouseX = width / 2;
_oldMouseY = height / 2;
+
+ _modeChanged = true;
+ _screenChangeCount++;
printf("done\n");
}
@@ -574,11 +591,11 @@ void OSystem_PS2::delayMillis(uint msecs) {
Common::TimerManager *OSystem_PS2::getTimerManager() {
return _scummTimerManager;
}
-
+/*
Common::EventManager *OSystem_PS2::getEventManager() {
- return _scummEventManager;
+ return getEventManager();
}
-
+*/
Audio::Mixer *OSystem_PS2::getMixer() {
return _scummMixer;
}
@@ -661,7 +678,7 @@ int16 OSystem_PS2::getOverlayHeight(void) {
return _screen->getOverlayHeight();
}
-Graphics::Surface *OSystem_PS2::lockScreen() {
+Graphics::Surface *OSystem_PS2::lockScreen(void) {
return _screen->lockScreen();
}
@@ -669,6 +686,10 @@ void OSystem_PS2::unlockScreen(void) {
_screen->unlockScreen();
}
+void OSystem_PS2::fillScreen(uint32 col) {
+ _screen->fillScreen(col);
+}
+
const OSystem::GraphicsMode OSystem_PS2::_graphicsMode = { NULL, NULL, 0 };
const OSystem::GraphicsMode *OSystem_PS2::getSupportedGraphicsModes(void) const {
@@ -688,7 +709,16 @@ int OSystem_PS2::getDefaultGraphicsMode(void) const {
}
bool OSystem_PS2::pollEvent(Common::Event &event) {
- bool res = _input->pollEvent(&event);
+ bool res;
+
+ if (_modeChanged) {
+ _modeChanged = false;
+ event.type = Common::EVENT_SCREEN_CHANGED;
+ return true;
+ }
+
+ res = _input->pollEvent(&event);
+
if (res && (event.type == Common::EVENT_MOUSEMOVE))
_screen->setMouseXy(event.mouse.x, event.mouse.y);
return res;
diff --git a/backends/platform/ps2/systemps2.h b/backends/platform/ps2/systemps2.h
index ab27d93574..24cd94f503 100644
--- a/backends/platform/ps2/systemps2.h
+++ b/backends/platform/ps2/systemps2.h
@@ -27,9 +27,9 @@
#define SYSTEMPS2_H
#include "common/system.h"
+#include "backends/base-backend.h"
class DefaultTimerManager;
-class DefaultEventManager;
class DefaultSaveFileManager;
class Gs2dScreen;
@@ -54,7 +54,7 @@ namespace Audio {
class MixerImpl;
};
-class OSystem_PS2 : public OSystem {
+class OSystem_PS2 : public BaseBackend {
public:
OSystem_PS2(const char *elfPath);
virtual ~OSystem_PS2(void);
@@ -72,6 +72,7 @@ public:
virtual Graphics::Surface *lockScreen();
virtual void unlockScreen();
virtual void updateScreen();
+ virtual void fillScreen(uint32);
/* TODO : check */
virtual void displayMessageOnOSD(const char *msg) { printf("displayMessageOnOSD: %s\n", msg); };
/* */
@@ -92,7 +93,7 @@ public:
virtual uint32 getMillis();
virtual void delayMillis(uint msecs);
virtual Common::TimerManager *getTimerManager();
- virtual Common::EventManager *getEventManager();
+// virtual Common::EventManager *getEventManager();
virtual bool pollEvent(Common::Event &event);
virtual Audio::Mixer *getMixer();
@@ -112,14 +113,14 @@ public:
virtual int getDefaultGraphicsMode() const;
virtual bool setGraphicsMode(int mode);
virtual int getGraphicsMode() const;
+ virtual int getScreenChangeID() const { return _screenChangeCount; }
virtual void quit();
virtual Common::SeekableReadStream *createConfigReadStream();
virtual Common::WriteStream *createConfigWriteStream();
- virtual Graphics::PixelFormat getOverlayFormat() const;
-
+ virtual Graphics::PixelFormat getOverlayFormat() const;
virtual Common::SaveFileManager *getSavefileManager();
virtual FilesystemFactory *getFilesystemFactory();
@@ -149,7 +150,6 @@ private:
void readRtcTime(void);
DefaultTimerManager *_scummTimerManager;
- DefaultEventManager *_scummEventManager;
Audio::MixerImpl *_scummMixer;
bool _mouseVisible;
@@ -163,6 +163,8 @@ private:
uint16 _oldMouseX, _oldMouseY;
uint32 _msgClearTime;
uint16 _printY;
+ bool _modeChanged;
+ int _screenChangeCount;
int _mutexSema;
Ps2Mutex _mutex[MAX_MUTEXES];
@@ -179,4 +181,3 @@ private:
};
#endif // SYSTEMPS2_H
-
diff --git a/backends/platform/wince/wince-sdl.cpp b/backends/platform/wince/wince-sdl.cpp
index b8261d029e..9a4b312631 100644
--- a/backends/platform/wince/wince-sdl.cpp
+++ b/backends/platform/wince/wince-sdl.cpp
@@ -908,18 +908,13 @@ int OSystem_WINCE3::getOutputSampleRate() const {
return _sampleRate;
}
-void OSystem_WINCE3::setWindowCaption(const char *caption) {
+void OSystem_WINCE3::engineInit() {
check_mappings(); // called here to initialize virtual keys handling
//update_game_settings();
// finalize mixer init
compute_sample_rate();
setupMixer();
-
-FIXME: move check_mappings() etc. calls to engineInit() & engineDone()
-
- // handle the actual event
- OSystem_SDL::setWindowCaption(caption);
}
bool OSystem_WINCE3::openCD(int drive) {
diff --git a/backends/platform/wince/wince-sdl.h b/backends/platform/wince/wince-sdl.h
index 13f20ecccf..cc2948f93d 100644
--- a/backends/platform/wince/wince-sdl.h
+++ b/backends/platform/wince/wince-sdl.h
@@ -84,7 +84,7 @@ public:
// Overloaded from SDL backend (master volume and sample rate subtleties)
void setupMixer();
// Overloaded from OSystem
- //void engineInit();
+ void engineInit();
void getTimeAndDate(struct tm &t) const;
virtual Common::SeekableReadStream *createConfigReadStream();
virtual Common::WriteStream *createConfigWriteStream();
@@ -145,7 +145,6 @@ protected:
//int getGraphicsMode() const;
int getDefaultGraphicsMode() const;
- void setWindowCaption(const char *caption);
bool openCD(int drive);
int getOutputSampleRate() const;
diff --git a/base/main.cpp b/base/main.cpp
index a091c5885a..2d4091c0d5 100644
--- a/base/main.cpp
+++ b/base/main.cpp
@@ -382,11 +382,15 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
}
// Quit unless an error occurred, or Return to launcher was requested
+ #ifndef FORCE_RTL
if (result == 0 && !g_system->getEventManager()->shouldRTL())
break;
-
+ #endif
// Reset RTL flag in case we want to load another engine
g_system->getEventManager()->resetRTL();
+ #ifdef FORCE_RTL
+ g_system->getEventManager()->resetQuit();
+ #endif
// Discard any command line options. It's unlikely that the user
// wanted to apply them to *all* games ever launched.
diff --git a/common/array.h b/common/array.h
index 7852cabf06..ac8a4b20d7 100644
--- a/common/array.h
+++ b/common/array.h
@@ -222,7 +222,13 @@ public:
T *old_storage = _storage;
_capacity = newCapacity;
+ // PS2 gcc 3.2.2 can't do "new T[newCapacity]()" but only
+ // "new T[newCapacity]" -> quick fix until we update tools.
+ #ifndef __PLAYSTATION2__
_storage = new T[newCapacity]();
+ #else
+ _storage = new T[newCapacity];
+ #endif
assert(_storage);
if (old_storage) {
@@ -273,7 +279,13 @@ protected:
// If there is not enough space, allocate more and
// copy old elements over.
uint newCapacity = roundUpCapacity(_size + n);
+ // PS2 gcc 3.2.2 can't do "new T[newCapacity]()" but only
+ // "new T[newCapacity]" -> quick fix until we update tools.
+ #ifndef __PLAYSTATION2__
newStorage = new T[newCapacity]();
+ #else
+ newStorage = new T[newCapacity];
+ #endif
assert(newStorage);
copy(_storage, _storage + idx, newStorage);
pos = newStorage + idx;
diff --git a/common/events.h b/common/events.h
index e13d95cf47..82b85e60ea 100644
--- a/common/events.h
+++ b/common/events.h
@@ -195,7 +195,9 @@ public:
* Used when we have returned to the launcher.
*/
virtual void resetRTL() = 0;
-
+#ifdef FORCE_RTL
+ virtual void resetQuit() = 0;
+#endif
// Optional: check whether a given key is currently pressed ????
//virtual bool isKeyPressed(int keycode) = 0;
diff --git a/common/util.cpp b/common/util.cpp
index e99bbeb12d..5f5e31aa93 100644
--- a/common/util.cpp
+++ b/common/util.cpp
@@ -477,7 +477,11 @@ void NORETURN error(const char *s, ...) {
// Print the error message to stderr
+#ifndef __PLAYSTATION2__
fputs(buf_output, stderr);
+#else
+ fprintf(stderr, "%s", buf_output);
+#endif
// Unless this error -originated- within the debugger itself, we
// now invoke the debugger, if available / supported.
diff --git a/engines/cruise/cruise_main.cpp b/engines/cruise/cruise_main.cpp
index faea3e1e3a..711f7bdf94 100644
--- a/engines/cruise/cruise_main.cpp
+++ b/engines/cruise/cruise_main.cpp
@@ -35,6 +35,8 @@
namespace Cruise {
+enum RelationType {RT_REL = 30, RT_MSG = 50};
+
static int playerDontAskQuit;
unsigned int timer = 0;
@@ -1024,8 +1026,8 @@ void callSubRelation(menuElementSubStruct *pMenuElement, int nOvl, int nObj) {
}
if ((obj2Ovl == nOvl) && (pHeader->obj2Number != -1) && (pHeader->obj2Number == nObj)) {
-// int x = 60;
-// int y = 60;
+ int x = 60;
+ int y = 60;
objectParamsQuery params;
memset(&params, 0, sizeof(objectParamsQuery)); // to remove warning
@@ -1035,7 +1037,7 @@ void callSubRelation(menuElementSubStruct *pMenuElement, int nOvl, int nObj) {
}
if ((pHeader->obj2OldState == -1) || (params.state == pHeader->obj2OldState)) {
- if (pHeader->type == 30) { // REL
+ if (pHeader->type == RT_REL) { // REL
if (currentScriptPtr) {
attacheNewScriptToTail(&relHead, ovlIdx, pHeader->id, 30, currentScriptPtr->scriptNumber, currentScriptPtr->overlayNumber, scriptType_REL);
} else {
@@ -1073,8 +1075,69 @@ void callSubRelation(menuElementSubStruct *pMenuElement, int nOvl, int nObj) {
changeScriptParamInList(ovlIdx, pHeader->id, &relHead, 0, 9998);
}
}
- } else if (pHeader->type == 50) {
- ASSERT(0);
+ } else if (pHeader->type == RT_MSG) {
+
+ if (pHeader->obj2Number >= 0) {
+ if ((pHeader->trackX !=-1) && (pHeader->trackY !=-1) &&
+ (pHeader->trackX != 9999) && (pHeader->trackY != 9999)) {
+ x = pHeader->trackX - 100;
+ y = pHeader->trackY - 150;
+ } else if (params.scale >= 0) {
+ x = params.X - 100;
+ y = params.Y - 40;
+ }
+
+ if (pHeader->obj2NewState != -1) {
+ objInit(obj2Ovl, pHeader->obj2Number, pHeader->obj2NewState);
+ }
+ }
+
+ if ((pHeader->obj1Number >= 0) && (pHeader->obj1NewState != -1)) {
+ int obj1Ovl = pHeader->obj1Overlay;
+ if (!obj1Ovl) obj1Ovl = ovlIdx;
+ objInit(obj1Ovl, pHeader->obj1Number, pHeader->obj1NewState);
+ }
+
+ if (currentScriptPtr) {
+ createTextObject(&cellHead, ovlIdx, pHeader->id, x, y, 200, findHighColor(), masterScreen, currentScriptPtr->overlayNumber, currentScriptPtr->scriptNumber);
+ } else {
+ createTextObject(&cellHead, ovlIdx, pHeader->id, x, y, 200, findHighColor(), masterScreen, 0, 0);
+ }
+
+ userWait = 1;
+ autoOvl = ovlIdx;
+ autoMsg = pHeader->id;
+
+ if ((narratorOvl > 0) && (pHeader->trackX != -1) && (pHeader->trackY != -1)) {
+ actorStruct *pTrack = findActor(&actorHead, narratorOvl, narratorIdx, 0);
+
+ if (pTrack) {
+ objectParamsQuery naratorParams;
+ animationStart = false;
+
+ if (pHeader->trackDirection == 9999) {
+ getMultipleObjectParam(narratorOvl, narratorIdx, &naratorParams);
+ pTrack->x_dest = naratorParams.X;
+ pTrack->y_dest = naratorParams.Y;
+ pTrack->endDirection = direction(naratorParams.X, naratorParams.Y, pHeader->trackX,pHeader->trackY, 0, 0);
+ } else if ((pHeader->trackX == 9999) && (pHeader->trackY == 9999)) {
+ getMultipleObjectParam(narratorOvl, narratorIdx, &naratorParams);
+ pTrack->x_dest = naratorParams.X;
+ pTrack->y_dest = naratorParams.Y;
+ pTrack->endDirection = pHeader->trackDirection;
+ } else {
+ pTrack->x_dest = pHeader->trackX;
+ pTrack->y_dest = pHeader->trackY;
+ pTrack->endDirection = pHeader->trackDirection;
+ }
+
+ pTrack->flag = 1;
+ autoTrack = true;
+ userWait = 0;
+ userEnabled = 0;
+ freezeCell(&cellHead, ovlIdx, pHeader->id, 5, -1, 0, 9998);
+ }
+ }
}
}
}
@@ -1112,7 +1175,7 @@ void callRelation(menuElementSubStruct *pMenuElement, int nObj2) {
if (pHeader->obj2Number == nObj2) {
// REL
- if (pHeader->type == 30) {
+ if (pHeader->type == RT_REL) {
if (currentScriptPtr) {
attacheNewScriptToTail(&relHead, ovlIdx, pHeader->id, 30, currentScriptPtr->scriptNumber, currentScriptPtr->overlayNumber, scriptType_REL);
} else {
@@ -1150,7 +1213,7 @@ void callRelation(menuElementSubStruct *pMenuElement, int nObj2) {
changeScriptParamInList(ovlIdx, pHeader->id, &relHead, 0, 9998);
}
}
- } else if (pHeader->type == 50) { // MSG
+ } else if (pHeader->type == RT_MSG) { // MSG
int obj1Ovl = pHeader->obj1Overlay;
if (!obj1Ovl)
obj1Ovl = ovlIdx;
diff --git a/engines/kyra/script.cpp b/engines/kyra/script.cpp
index 0473f03591..726c013b5a 100644
--- a/engines/kyra/script.cpp
+++ b/engines/kyra/script.cpp
@@ -125,7 +125,7 @@ bool EMCInterpreter::load(const char *filename, EMCData *scriptData, const Commo
error("No DATA chunk found in file: '%s'", filename);
if (stream->err())
- error("Read error while parsing file '%s", filename);
+ error("Read error while parsing file '%s'", filename);
delete stream;
diff --git a/engines/kyra/script_tim.cpp b/engines/kyra/script_tim.cpp
index 424a62aaf8..bc62e5bd6a 100644
--- a/engines/kyra/script_tim.cpp
+++ b/engines/kyra/script_tim.cpp
@@ -169,7 +169,7 @@ TIM *TIMInterpreter::load(const char *filename, const Common::Array<const TIMOpc
error("No AVTL chunk found in file: '%s'", filename);
if (stream->err())
- error("Read error while parsing file '%s", filename);
+ error("Read error while parsing file '%s'", filename);
delete stream;
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp
index ebf9656739..7c1a165ec1 100644
--- a/engines/sci/console.cpp
+++ b/engines/sci/console.cpp
@@ -366,8 +366,8 @@ ResourceType parseResourceType(const char *resid) {
}
const char *selector_name(EngineState *s, int selector) {
- if (selector >= 0 && selector < (int)s->_kernel->getSelectorNamesSize())
- return s->_kernel->getSelectorName(selector).c_str();
+ if (selector >= 0 && selector < (int)((SciEngine*)g_engine)->getKernel()->getSelectorNamesSize())
+ return ((SciEngine*)g_engine)->getKernel()->getSelectorName(selector).c_str();
else
return "--INVALID--";
}
@@ -381,8 +381,8 @@ bool Console::cmdGetVersion(int argc, const char **argv) {
bool Console::cmdOpcodes(int argc, const char **argv) {
DebugPrintf("Opcode names in numeric order [index: type name]:\n");
- for (uint seeker = 0; seeker < _vm->_gamestate->_kernel->getOpcodesSize(); seeker++) {
- opcode op = _vm->_gamestate->_kernel->getOpcode(seeker);
+ for (uint seeker = 0; seeker < _vm->getKernel()->getOpcodesSize(); seeker++) {
+ opcode op = _vm->getKernel()->getOpcode(seeker);
DebugPrintf("%03x: %03x %20s | ", seeker, op.type, op.name.c_str());
if ((seeker % 3) == 2)
DebugPrintf("\n");
@@ -400,9 +400,9 @@ bool Console::cmdSelector(int argc, const char **argv) {
return true;
}
- for (uint seeker = 0; seeker < _vm->_gamestate->_kernel->getSelectorNamesSize(); seeker++) {
- if (!scumm_stricmp(_vm->_gamestate->_kernel->getSelectorName(seeker).c_str(), argv[1])) {
- DebugPrintf("Selector %s found at %03x\n", _vm->_gamestate->_kernel->getSelectorName(seeker).c_str(), seeker);
+ for (uint seeker = 0; seeker < _vm->getKernel()->getSelectorNamesSize(); seeker++) {
+ if (!scumm_stricmp(_vm->getKernel()->getSelectorName(seeker).c_str(), argv[1])) {
+ DebugPrintf("Selector %s found at %03x\n", _vm->getKernel()->getSelectorName(seeker).c_str(), seeker);
return true;
}
}
@@ -414,8 +414,8 @@ bool Console::cmdSelector(int argc, const char **argv) {
bool Console::cmdSelectors(int argc, const char **argv) {
DebugPrintf("Selector names in numeric order:\n");
- for (uint seeker = 0; seeker < _vm->_gamestate->_kernel->getSelectorNamesSize(); seeker++) {
- DebugPrintf("%03x: %20s | ", seeker, _vm->_gamestate->_kernel->getSelectorName(seeker).c_str());
+ for (uint seeker = 0; seeker < _vm->getKernel()->getSelectorNamesSize(); seeker++) {
+ DebugPrintf("%03x: %20s | ", seeker, _vm->getKernel()->getSelectorName(seeker).c_str());
if ((seeker % 3) == 2)
DebugPrintf("\n");
}
@@ -427,8 +427,8 @@ bool Console::cmdSelectors(int argc, const char **argv) {
bool Console::cmdKernelFunctions(int argc, const char **argv) {
DebugPrintf("Kernel function names in numeric order:\n");
- for (uint seeker = 0; seeker < _vm->_gamestate->_kernel->getKernelNamesSize(); seeker++) {
- DebugPrintf("%03x: %20s | ", seeker, _vm->_gamestate->_kernel->getKernelName(seeker).c_str());
+ for (uint seeker = 0; seeker < _vm->getKernel()->getKernelNamesSize(); seeker++) {
+ DebugPrintf("%03x: %20s | ", seeker, _vm->getKernel()->getKernelName(seeker).c_str());
if ((seeker % 3) == 2)
DebugPrintf("\n");
}
@@ -439,13 +439,13 @@ bool Console::cmdKernelFunctions(int argc, const char **argv) {
}
bool Console::cmdSuffixes(int argc, const char **argv) {
- _vm->_gamestate->_vocabulary->printSuffixes();
+ _vm->getVocabulary()->printSuffixes();
return true;
}
bool Console::cmdParserWords(int argc, const char **argv) {
- _vm->_gamestate->_vocabulary->printParserWords();
+ _vm->getVocabulary()->printParserWords();
return true;
}
@@ -604,7 +604,7 @@ bool Console::cmdDissectScript(int argc, const char **argv) {
return true;
}
- _vm->_gamestate->_kernel->dissectScript(atoi(argv[1]), _vm->_gamestate->_vocabulary);
+ _vm->getKernel()->dissectScript(atoi(argv[1]), _vm->getVocabulary());
return true;
}
@@ -894,10 +894,10 @@ bool Console::cmdClassTable(int argc, const char **argv) {
bool Console::cmdSentenceFragments(int argc, const char **argv) {
DebugPrintf("Sentence fragments (used to build Parse trees)\n");
- for (uint i = 0; i < _vm->_gamestate->_vocabulary->getParserBranchesSize(); i++) {
+ for (uint i = 0; i < _vm->getVocabulary()->getParserBranchesSize(); i++) {
int j = 0;
- const parse_tree_branch_t &branch = _vm->_gamestate->_vocabulary->getParseTreeBranch(i);
+ const parse_tree_branch_t &branch = _vm->getVocabulary()->getParseTreeBranch(i);
DebugPrintf("R%02d: [%x] ->", i, branch.id);
while ((j < 10) && branch.data[j]) {
int dat = branch.data[j++];
@@ -929,7 +929,7 @@ bool Console::cmdSentenceFragments(int argc, const char **argv) {
DebugPrintf("\n");
}
- DebugPrintf("%d rules.\n", _vm->_gamestate->_vocabulary->getParserBranchesSize());
+ DebugPrintf("%d rules.\n", _vm->getVocabulary()->getParserBranchesSize());
return true;
}
@@ -952,7 +952,7 @@ bool Console::cmdParse(int argc, const char **argv) {
}
DebugPrintf("Parsing '%s'\n", string);
- bool res = _vm->_gamestate->_vocabulary->tokenizeString(words, string, &error);
+ bool res = _vm->getVocabulary()->tokenizeString(words, string, &error);
if (res && !words.empty()) {
int syntax_fail = 0;
@@ -963,7 +963,7 @@ bool Console::cmdParse(int argc, const char **argv) {
for (ResultWordList::const_iterator i = words.begin(); i != words.end(); ++i)
DebugPrintf(" Type[%04x] Group[%04x]\n", i->_class, i->_group);
- if (_vm->_gamestate->_vocabulary->parseGNF(_vm->_gamestate->parser_nodes, words, true))
+ if (_vm->getVocabulary()->parseGNF(_vm->_gamestate->parser_nodes, words, true))
syntax_fail = 1; // Building a tree failed
if (syntax_fail)
@@ -1214,7 +1214,7 @@ bool Console::cmdPrintPort(int argc, const char **argv) {
bool Console::cmdParseGrammar(int argc, const char **argv) {
DebugPrintf("Parse grammar, in strict GNF:\n");
- _vm->_gamestate->_vocabulary->buildGNF(true);
+ _vm->getVocabulary()->buildGNF(true);
return true;
}
@@ -2049,12 +2049,12 @@ bool Console::cmdBacktrace(int argc, const char **argv) {
break;
case EXEC_STACK_TYPE_KERNEL: // Kernel function
- printf(" %x:[%x] k%s(", i, call.origin, _vm->_gamestate->_kernel->getKernelName(-(call.selector) - 42).c_str());
+ printf(" %x:[%x] k%s(", i, call.origin, _vm->getKernel()->getKernelName(-(call.selector) - 42).c_str());
break;
case EXEC_STACK_TYPE_VARSELECTOR:
printf(" %x:[%x] vs%s %s::%s (", i, call.origin, (call.argc) ? "write" : "read",
- objname, _vm->_gamestate->_kernel->getSelectorName(call.selector).c_str());
+ objname, _vm->getKernel()->getSelectorName(call.selector).c_str());
break;
}
@@ -2139,8 +2139,8 @@ bool Console::cmdStepCallk(int argc, const char **argv) {
callk_index = strtoul(argv[1], &endptr, 0);
if (*endptr != '\0') {
callk_index = -1;
- for (uint i = 0; i < _vm->_gamestate->_kernel->getKernelNamesSize(); i++)
- if (argv[1] == _vm->_gamestate->_kernel->getKernelName(i)) {
+ for (uint i = 0; i < _vm->getKernel()->getKernelNamesSize(); i++)
+ if (argv[1] == _vm->getKernel()->getKernelName(i)) {
callk_index = i;
break;
}
@@ -2176,7 +2176,7 @@ bool Console::cmdDissassemble(int argc, const char **argv) {
}
Object *obj = obj_get(_vm->_gamestate, objAddr);
- int selector_id = _vm->_gamestate->_kernel->findSelector(argv[2]);
+ int selector_id = _vm->getKernel()->findSelector(argv[2]);
reg_t addr;
if (!obj) {
@@ -2276,7 +2276,7 @@ bool Console::cmdSend(int argc, const char **argv) {
Object *o;
reg_t fptr;
- selector_id = _vm->_gamestate->_kernel->findSelector(selector_name);
+ selector_id = _vm->getKernel()->findSelector(selector_name);
if (selector_id < 0) {
DebugPrintf("Unknown selector: \"%s\"\n", selector_name);
@@ -3108,7 +3108,7 @@ static void viewobjinfo(EngineState *s, HeapPtr pos) {
int have_rects = 0;
Common::Rect nsrect, nsrect_clipped, brrect;
- if (lookup_selector(s, pos, s->_kernel->_selectorMap.nsBottom, NULL) == kSelectorVariable) {
+ if (lookup_selector(s, pos, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsBottom, NULL) == kSelectorVariable) {
GETRECT(nsLeft, nsRight, nsBottom, nsTop);
GETRECT(lsLeft, lsRight, lsBottom, lsTop);
GETRECT(brLeft, brRight, brBottom, brTop);
@@ -3122,7 +3122,7 @@ static void viewobjinfo(EngineState *s, HeapPtr pos) {
x = GET_SELECTOR(pos, x);
y = GET_SELECTOR(pos, y);
priority = GET_SELECTOR(pos, priority);
- if (s->_kernel->_selectorMap.z > 0) {
+ if (((SciEngine*)g_engine)->getKernel()->_selectorMap.z > 0) {
z = GET_SELECTOR(pos, z);
printf("(%d,%d,%d)\n", x, y, z);
} else
@@ -3186,10 +3186,10 @@ static int c_gfx_draw_viewobj(EngineState *s, const Common::Array<cmd_param_t> &
}
- is_view = (lookup_selector(s, pos, s->_kernel->_selectorMap.x, NULL) == kSelectorVariable) &&
- (lookup_selector(s, pos, s->_kernel->_selectorMap.brLeft, NULL) == kSelectorVariable) &&
- (lookup_selector(s, pos, s->_kernel->_selectorMap.signal, NULL) == kSelectorVariable) &&
- (lookup_selector(s, pos, s->_kernel->_selectorMap.nsTop, NULL) == kSelectorVariable);
+ is_view = (lookup_selector(s, pos, ((SciEngine*)g_engine)->getKernel()->_selectorMap.x, NULL) == kSelectorVariable) &&
+ (lookup_selector(s, pos, ((SciEngine*)g_engine)->getKernel()->_selectorMap.brLeft, NULL) == kSelectorVariable) &&
+ (lookup_selector(s, pos, ((SciEngine*)g_engine)->getKernel()->_selectorMap.signal, NULL) == kSelectorVariable) &&
+ (lookup_selector(s, pos, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsTop, NULL) == kSelectorVariable);
if (!is_view) {
printf("Not a dynamic View object.\n");
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp
index 5b4c30f6b3..0a74ac32e4 100644
--- a/engines/sci/engine/game.cpp
+++ b/engines/sci/engine/game.cpp
@@ -87,7 +87,7 @@ int _reset_graphics_input(EngineState *s) {
s->priority_first = 42; // Priority zone 0 ends here
- if (s->_kernel->usesOldGfxFunctions())
+ if (((SciEngine*)g_engine)->getKernel()->usesOldGfxFunctions())
s->priority_last = 200;
else
s->priority_last = 190;
@@ -257,7 +257,7 @@ static int create_class_table_sci0(EngineState *s) {
Resource *script = s->resmgr->findResource(ResourceId(kResourceTypeScript, scriptnr), 0);
if (script) {
- if (s->_kernel->hasOldScriptHeader())
+ if (((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader())
magic_offset = seeker = 2;
else
magic_offset = seeker = 0;
@@ -327,9 +327,6 @@ int script_init_engine(EngineState *s) {
s->kernel_opt_flags = 0;
- s->_kernel = new Kernel(s->resmgr);
- s->_vocabulary = new Vocabulary(s->resmgr);
-
if (s->_version >= SCI_VERSION_1_1)
result = create_class_table_sci11(s);
else
@@ -375,7 +372,7 @@ int script_init_engine(EngineState *s) {
s->bp_list = NULL; // No breakpoints defined
s->have_bp = 0;
- if (s->_kernel->hasLofsAbsolute())
+ if (((SciEngine*)g_engine)->getKernel()->hasLofsAbsolute())
s->seg_manager->setExportWidth(1);
else
s->seg_manager->setExportWidth(0);
@@ -412,11 +409,6 @@ void script_free_engine(EngineState *s) {
script_free_vm_memory(s);
debug(2, "Freeing state-dependant data");
-
- delete s->_vocabulary;
- s->_vocabulary = 0;
- delete s->_kernel;
- s->_kernel = 0;
}
void script_free_breakpoints(EngineState *s) {
diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h
index 17997e4a20..15f7c9fcf3 100644
--- a/engines/sci/engine/kernel.h
+++ b/engines/sci/engine/kernel.h
@@ -205,7 +205,7 @@ enum SelectorInvocation {
kContinueOnInvalidSelector = 1
};
-#define GET_SEL32(_o_, _slc_) read_selector(s, _o_, s->_kernel->_selectorMap._slc_, __FILE__, __LINE__)
+#define GET_SEL32(_o_, _slc_) read_selector(s, _o_, ((SciEngine*)g_engine)->getKernel()->_selectorMap._slc_, __FILE__, __LINE__)
#define GET_SEL32V(_o_, _slc_) (GET_SEL32(_o_, _slc_).offset)
#define GET_SEL32SV(_o_, _slc_) ((int16)(GET_SEL32(_o_, _slc_).offset))
/* Retrieves a selector from an object
@@ -216,8 +216,8 @@ enum SelectorInvocation {
** selector_map_t and mapped in script.c.
*/
-#define PUT_SEL32(_o_, _slc_, _val_) write_selector(s, _o_, s->_kernel->_selectorMap._slc_, _val_, __FILE__, __LINE__)
-#define PUT_SEL32V(_o_, _slc_, _val_) write_selector(s, _o_, s->_kernel->_selectorMap._slc_, make_reg(0, _val_), __FILE__, __LINE__)
+#define PUT_SEL32(_o_, _slc_, _val_) write_selector(s, _o_, ((SciEngine*)g_engine)->getKernel()->_selectorMap._slc_, _val_, __FILE__, __LINE__)
+#define PUT_SEL32V(_o_, _slc_, _val_) write_selector(s, _o_, ((SciEngine*)g_engine)->getKernel()->_selectorMap._slc_, make_reg(0, _val_), __FILE__, __LINE__)
/* Writes a selector value to an object
** Parameters: (reg_t) object: The address of the object which the selector should be written to
** (selector_name) selector: The selector to read
@@ -229,7 +229,7 @@ enum SelectorInvocation {
#define INV_SEL(_object_, _selector_, _noinvalid_) \
- s, _object_, s->_kernel->_selectorMap._selector_, _noinvalid_, funct_nr, argv, argc, __FILE__, __LINE__
+ s, _object_, ((SciEngine*)g_engine)->getKernel()->_selectorMap._selector_, _noinvalid_, funct_nr, argv, argc, __FILE__, __LINE__
/* Kludge for use with invoke_selector(). Used for compatibility with compilers that can't
** handle vararg macros.
*/
diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp
index d46ce3b938..c7086ddef7 100644
--- a/engines/sci/engine/kgraphics.cpp
+++ b/engines/sci/engine/kgraphics.cpp
@@ -164,7 +164,7 @@ int _find_view_priority(EngineState *s, int y) {
return j;
return 14; // Maximum
} else {
- if (!s->_kernel->usesOldGfxFunctions())
+ if (!((SciEngine*)g_engine)->getKernel()->usesOldGfxFunctions())
return SCI0_VIEW_PRIORITY_14_ZONES(y);
else
return SCI0_VIEW_PRIORITY(y) == 15 ? 14 : SCI0_VIEW_PRIORITY(y);
@@ -172,7 +172,7 @@ int _find_view_priority(EngineState *s, int y) {
}
int _find_priority_band(EngineState *s, int nr) {
- if (!s->_kernel->usesOldGfxFunctions() && (nr < 0 || nr > 14)) {
+ if (!((SciEngine*)g_engine)->getKernel()->usesOldGfxFunctions() && (nr < 0 || nr > 14)) {
if (nr == 15)
return 0xffff;
else {
@@ -181,7 +181,7 @@ int _find_priority_band(EngineState *s, int nr) {
return 0;
}
- if (s->_kernel->usesOldGfxFunctions() && (nr < 0 || nr > 15)) {
+ if (((SciEngine*)g_engine)->getKernel()->usesOldGfxFunctions() && (nr < 0 || nr > 15)) {
warning("Attempt to get priority band %d", nr);
return 0;
}
@@ -191,7 +191,7 @@ int _find_priority_band(EngineState *s, int nr) {
else {
int retval;
- if (!s->_kernel->usesOldGfxFunctions())
+ if (!((SciEngine*)g_engine)->getKernel()->usesOldGfxFunctions())
retval = SCI0_PRIORITY_BAND_FIRST_14_ZONES(nr);
else
retval = SCI0_PRIORITY_BAND_FIRST(nr);
@@ -696,7 +696,7 @@ void _k_dirloop(reg_t obj, uint16 angle, EngineState *s, int funct_nr, int argc,
angle %= 360;
- if (!s->_kernel->hasOldScriptHeader()) {
+ if (!((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) {
if (angle < 45)
loop = 3;
else if (angle < 136)
@@ -1002,7 +1002,7 @@ reg_t kDrawPic(EngineState *s, int funct_nr, int argc, reg_t *argv) {
gfx_color_t transparent = s->wm_port->_bgcolor;
int picFlags = DRAWPIC01_FLAG_FILL_NORMALLY;
- if (s->_kernel->usesOldGfxFunctions())
+ if (((SciEngine*)g_engine)->getKernel()->usesOldGfxFunctions())
add_to_pic = (argc > 2) ? argv[2].toSint16() : false;
dp.nr = argv[0].toSint16();
@@ -1056,7 +1056,7 @@ reg_t kDrawPic(EngineState *s, int funct_nr, int argc, reg_t *argv) {
s->priority_first = 42;
- if (s->_kernel->usesOldGfxFunctions())
+ if (((SciEngine*)g_engine)->getKernel()->usesOldGfxFunctions())
s->priority_last = 200;
else
s->priority_last = 190;
@@ -1079,7 +1079,7 @@ Common::Rect set_base(EngineState *s, reg_t object) {
x = GET_SEL32SV(object, x);
original_y = y = GET_SEL32SV(object, y);
- if (s->_kernel->_selectorMap.z > -1)
+ if (((SciEngine*)g_engine)->getKernel()->_selectorMap.z > -1)
z = GET_SEL32SV(object, z);
else
z = 0;
@@ -1133,7 +1133,7 @@ Common::Rect set_base(EngineState *s, reg_t object) {
void _k_base_setter(EngineState *s, reg_t object) {
Common::Rect absrect = set_base(s, object);
- if (lookup_selector(s, object, s->_kernel->_selectorMap.brLeft, NULL, NULL) != kSelectorVariable)
+ if (lookup_selector(s, object, ((SciEngine*)g_engine)->getKernel()->_selectorMap.brLeft, NULL, NULL) != kSelectorVariable)
return; // non-fatal
// Note: there was a check here for a very old version of SCI, which supposedly needed
@@ -1214,7 +1214,7 @@ Common::Rect get_nsrect(EngineState *s, reg_t object, byte clip) {
x = GET_SEL32SV(object, x);
y = GET_SEL32SV(object, y);
- if (s->_kernel->_selectorMap.z > -1)
+ if (((SciEngine*)g_engine)->getKernel()->_selectorMap.z > -1)
z = GET_SEL32SV(object, z);
else
z = 0;
@@ -1238,7 +1238,7 @@ Common::Rect get_nsrect(EngineState *s, reg_t object, byte clip) {
static void _k_set_now_seen(EngineState *s, reg_t object) {
Common::Rect absrect = get_nsrect(s, object, 0);
- if (lookup_selector(s, object, s->_kernel->_selectorMap.nsTop, NULL, NULL) != kSelectorVariable) {
+ if (lookup_selector(s, object, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsTop, NULL, NULL) != kSelectorVariable) {
return;
} // This isn't fatal
@@ -1724,7 +1724,7 @@ static void _k_view_list_do_postdraw(EngineState *s, GfxList *list) {
* if ((widget->signal & (_K_VIEW_SIG_FLAG_PRIVATE | _K_VIEW_SIG_FLAG_REMOVE | _K_VIEW_SIG_FLAG_NO_UPDATE)) == _K_VIEW_SIG_FLAG_PRIVATE) {
*/
if ((widget->signal & (_K_VIEW_SIG_FLAG_REMOVE | _K_VIEW_SIG_FLAG_NO_UPDATE)) == 0) {
- int has_nsrect = lookup_selector(s, obj, s->_kernel->_selectorMap.nsBottom, NULL, NULL) == kSelectorVariable;
+ int has_nsrect = lookup_selector(s, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsBottom, NULL, NULL) == kSelectorVariable;
if (has_nsrect) {
int temp;
@@ -1746,7 +1746,7 @@ static void _k_view_list_do_postdraw(EngineState *s, GfxList *list) {
}
#ifdef DEBUG_LSRECT
else
- fprintf(stderr, "Not lsRecting %04x:%04x because %d\n", PRINT_REG(obj), lookup_selector(s, obj, s->_kernel->_selectorMap.nsBottom, NULL, NULL));
+ fprintf(stderr, "Not lsRecting %04x:%04x because %d\n", PRINT_REG(obj), lookup_selector(s, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsBottom, NULL, NULL));
#endif
if (widget->signal & _K_VIEW_SIG_FLAG_HIDDEN)
@@ -1900,7 +1900,7 @@ static GfxDynView *_k_make_dynview_obj(EngineState *s, reg_t obj, int options, i
loop = oldloop = sign_extend_byte(GET_SEL32V(obj, loop));
cel = oldcel = sign_extend_byte(GET_SEL32V(obj, cel));
- if (s->_kernel->_selectorMap.palette)
+ if (((SciEngine*)g_engine)->getKernel()->_selectorMap.palette)
palette = GET_SEL32V(obj, palette);
else
palette = 0;
@@ -1923,7 +1923,7 @@ static GfxDynView *_k_make_dynview_obj(EngineState *s, reg_t obj, int options, i
}
ObjVarRef under_bitsp;
- if (lookup_selector(s, obj, s->_kernel->_selectorMap.underBits, &(under_bitsp), NULL) != kSelectorVariable) {
+ if (lookup_selector(s, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.underBits, &(under_bitsp), NULL) != kSelectorVariable) {
under_bitsp.obj = NULL_REG;
under_bits = NULL_REG;
debugC(2, kDebugLevelGraphics, "Object at %04x:%04x has no underBits\n", PRINT_REG(obj));
@@ -1931,7 +1931,7 @@ static GfxDynView *_k_make_dynview_obj(EngineState *s, reg_t obj, int options, i
under_bits = *under_bitsp.getPointer(s);
ObjVarRef signalp;
- if (lookup_selector(s, obj, s->_kernel->_selectorMap.signal, &(signalp), NULL) != kSelectorVariable) {
+ if (lookup_selector(s, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.signal, &(signalp), NULL) != kSelectorVariable) {
signalp.obj = NULL_REG;
signal = 0;
debugC(2, kDebugLevelGraphics, "Object at %04x:%04x has no signal selector\n", PRINT_REG(obj));
@@ -2024,7 +2024,7 @@ static void _k_prepare_view_list(EngineState *s, GfxList *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->_kernel->_selectorMap.nsBottom, NULL, NULL) == kSelectorVariable;
+ int has_nsrect = (view->_ID <= 0) ? 0 : lookup_selector(s, obj, ((SciEngine*)g_engine)->getKernel()->_selectorMap.nsBottom, NULL, NULL) == kSelectorVariable;
int oldsignal = view->signal;
_k_set_now_seen(s, obj);
diff --git a/engines/sci/engine/kmisc.cpp b/engines/sci/engine/kmisc.cpp
index 7e0aca5b7a..c693009b35 100644
--- a/engines/sci/engine/kmisc.cpp
+++ b/engines/sci/engine/kmisc.cpp
@@ -240,7 +240,7 @@ reg_t kMemory(EngineState *s, int funct_nr, int argc, reg_t *argv) {
reg_t kStub(EngineState *s, int funct_nr, int argc, reg_t *argv) {
char tmpbuf[200];
sprintf(tmpbuf, "Unimplemented syscall: %s[%x] (",
- s->_kernel->getKernelName(funct_nr).c_str(), funct_nr);
+ ((SciEngine*)g_engine)->getKernel()->getKernelName(funct_nr).c_str(), funct_nr);
for (int i = 0; i < argc; i++) {
char tmpbuf2[20];
@@ -257,7 +257,7 @@ reg_t kStub(EngineState *s, int funct_nr, int argc, reg_t *argv) {
}
reg_t kNOP(EngineState *s, int funct_nr, int argc, reg_t *argv) {
- warning("Kernel function 0x%02x (%s) invoked: unmapped", funct_nr, s->_kernel->_kernelFuncs[funct_nr].orig_name.c_str());
+ warning("Kernel function 0x%02x (%s) invoked: unmapped", funct_nr, ((SciEngine*)g_engine)->getKernel()->_kernelFuncs[funct_nr].orig_name.c_str());
return NULL_REG;
}
diff --git a/engines/sci/engine/kmovement.cpp b/engines/sci/engine/kmovement.cpp
index 90db630bfa..8774224f60 100644
--- a/engines/sci/engine/kmovement.cpp
+++ b/engines/sci/engine/kmovement.cpp
@@ -267,7 +267,7 @@ static void bresenham_autodetect(EngineState *s) {
return;
}
- if (lookup_selector(s, motion_class, s->_kernel->_selectorMap.doit, NULL, &fptr) != kSelectorMethod) {
+ if (lookup_selector(s, motion_class, ((SciEngine*)g_engine)->getKernel()->_selectorMap.doit, NULL, &fptr) != kSelectorMethod) {
warning("bresenham_autodetect failed");
handle_movecnt = INCREMENT_MOVECNT; // Most games do this, so best guess
return;
@@ -362,7 +362,7 @@ reg_t kDoBresen(EngineState *s, int funct_nr, int argc, reg_t *argv) {
debugC(2, kDebugLevelBresen, "New data: (x,y)=(%d,%d), di=%d\n", x, y, bdi);
- if (s->_kernel->_selectorMap.cantBeHere != -1)
+ if (((SciEngine*)g_engine)->getKernel()->_selectorMap.cantBeHere != -1)
invoke_selector(INV_SEL(client, cantBeHere, kStopOnInvalidSelector), 0);
else
invoke_selector(INV_SEL(client, canBeHere, kStopOnInvalidSelector), 0);
diff --git a/engines/sci/engine/kscripts.cpp b/engines/sci/engine/kscripts.cpp
index d82f8ff132..df25e11729 100644
--- a/engines/sci/engine/kscripts.cpp
+++ b/engines/sci/engine/kscripts.cpp
@@ -43,7 +43,7 @@ reg_t read_selector(EngineState *s, reg_t object, Selector selector_id, const ch
void write_selector(EngineState *s, reg_t object, Selector selector_id, reg_t value, const char *fname, int line) {
ObjVarRef address;
- if ((selector_id < 0) || (selector_id > (int)s->_kernel->getSelectorNamesSize())) {
+ if ((selector_id < 0) || (selector_id > (int)((SciEngine*)g_engine)->getKernel()->getSelectorNamesSize())) {
warning("Attempt to write to invalid selector %d of"
" object at %04x:%04x (%s L%d).", selector_id, PRINT_REG(object), fname, line);
return;
@@ -51,7 +51,7 @@ void write_selector(EngineState *s, reg_t object, Selector selector_id, reg_t va
if (lookup_selector(s, object, selector_id, &address, NULL) != kSelectorVariable)
warning("Selector '%s' of object at %04x:%04x could not be"
- " written to (%s L%d)", s->_kernel->getSelectorName(selector_id).c_str(), PRINT_REG(object), fname, line);
+ " written to (%s L%d)", ((SciEngine*)g_engine)->getKernel()->getSelectorName(selector_id).c_str(), PRINT_REG(object), fname, line);
else
*address.getPointer(s) = value;
}
@@ -72,7 +72,7 @@ int invoke_selector(EngineState *s, reg_t object, int selector_id, SelectorInvoc
if (slc_type == kSelectorNone) {
warning("Selector '%s' of object at %04x:%04x could not be invoked (%s L%d)",
- s->_kernel->getSelectorName(selector_id).c_str(), PRINT_REG(object), fname, line);
+ ((SciEngine*)g_engine)->getKernel()->getSelectorName(selector_id).c_str(), PRINT_REG(object), fname, line);
if (noinvalid == kStopOnInvalidSelector)
error("[Kernel] Not recoverable: VM was halted\n");
return 1;
diff --git a/engines/sci/engine/ksound.cpp b/engines/sci/engine/ksound.cpp
index 95c2eaab1d..8c113d35a3 100644
--- a/engines/sci/engine/ksound.cpp
+++ b/engines/sci/engine/ksound.cpp
@@ -988,9 +988,9 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) {
* Used for synthesized music playback
*/
reg_t kDoSound(EngineState *s, int funct_nr, int argc, reg_t *argv) {
- if (s->_kernel->usesSci1SoundFunctions())
+ if (((SciEngine*)g_engine)->getKernel()->usesSci1SoundFunctions())
return kDoSound_SCI1(s, funct_nr, argc, argv);
- else if (s->_kernel->usesSci01SoundFunctions())
+ else if (((SciEngine*)g_engine)->getKernel()->usesSci01SoundFunctions())
return kDoSound_SCI01(s, funct_nr, argc, argv);
else
return kDoSound_SCI0(s, funct_nr, argc, argv);
diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp
index c572906285..b6bb404d5b 100644
--- a/engines/sci/engine/kstring.cpp
+++ b/engines/sci/engine/kstring.cpp
@@ -95,7 +95,7 @@ reg_t kSaid(EngineState *s, int funct_nr, int argc, reg_t *argv) {
#ifdef DEBUG_PARSER
debugC(2, kDebugLevelParser, "Said block:", 0);
- s->_vocabulary->decipherSaidBlock(said_block);
+ ((SciEngine*)g_engine)->getVocabulary()->decipherSaidBlock(said_block);
#endif
if (s->parser_event.isNull() || (GET_SEL32V(s->parser_event, claimed))) {
@@ -190,10 +190,11 @@ reg_t kParse(EngineState *s, int funct_nr, int argc, reg_t *argv) {
char *error;
ResultWordList words;
reg_t event = argv[1];
+ Vocabulary *voc = ((SciEngine*)g_engine)->getVocabulary();
s->parser_event = event;
- bool res = s->_vocabulary->tokenizeString(words, string, &error);
+ bool res = voc->tokenizeString(words, string, &error);
s->parser_valid = 0; /* not valid */
if (res && !words.empty()) {
@@ -211,7 +212,7 @@ reg_t kParse(EngineState *s, int funct_nr, int argc, reg_t *argv) {
debugC(2, kDebugLevelParser, " Type[%04x] Group[%04x]\n", i->_class, i->_group);
#endif
- if (s->_vocabulary->parseGNF(s->parser_nodes, words))
+ if (voc->parseGNF(s->parser_nodes, words))
syntax_fail = 1; /* Building a tree failed */
if (syntax_fail) {
diff --git a/engines/sci/engine/said.cpp b/engines/sci/engine/said.cpp
index 921fa4e599..b1d174b30f 100644
--- a/engines/sci/engine/said.cpp
+++ b/engines/sci/engine/said.cpp
@@ -2449,7 +2449,7 @@ int said(EngineState *s, byte *spec, int verbose) {
if (s->parser_valid) {
if (said_parse_spec(s, spec)) {
printf("Offending spec was: ");
- s->_vocabulary->decipherSaidBlock(spec);
+ ((SciEngine*)g_engine)->getVocabulary()->decipherSaidBlock(spec);
return SAID_NO_MATCH;
}
diff --git a/engines/sci/engine/said.y b/engines/sci/engine/said.y
index c1c8424cb5..e7c225b3e6 100644
--- a/engines/sci/engine/said.y
+++ b/engines/sci/engine/said.y
@@ -805,7 +805,7 @@ int said(EngineState *s, byte *spec, int verbose) {
if (s->parser_valid) {
if (said_parse_spec(s, spec)) {
warning("Offending spec was: ");
- s->_vocabulary->decypherSaidBlock(spec);
+ ((SciEngine*)g_engine)->getVocabulary()->decypherSaidBlock(spec);
return SAID_NO_MATCH;
}
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp
index e167e7eca8..d5f094b540 100644
--- a/engines/sci/engine/savegame.cpp
+++ b/engines/sci/engine/savegame.cpp
@@ -497,7 +497,7 @@ static SegmentId find_unique_seg_by_type(SegManager *self, int type) {
}
static byte *find_unique_script_block(EngineState *s, byte *buf, int type) {
- if (s->_kernel->hasOldScriptHeader())
+ if (((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader())
buf += 2;
do {
@@ -756,13 +756,6 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
// FIXME: Do in-place loading at some point, instead of creating a new EngineState instance from scratch.
retval = new EngineState(s->resmgr, s->_version, s->_flags);
- // static VM/Kernel information:
- assert(0 == retval->_kernel);
- retval->_kernel = s->_kernel; // needs to be initialized before _reset_graphics_input is called
-// s->_kernel = 0; // FIXME: We should set s->_kernel to 0 here,
-// else it could be freed when the old EngineState is freed. Luckily, this freeing currently
-// never happens, so we don't need to.
-
// Copy some old data
retval->gfx_state = s->gfx_state;
retval->sound_mute = s->sound_mute;
@@ -821,11 +814,6 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
retval->game_start_time = g_system->getMillis() - retval->game_time * 1000;
// static parser information:
- assert(0 == retval->_vocabulary);
- retval->_vocabulary = s->_vocabulary;
-// s->_vocabulary = 0; // FIXME: We should set s->_vocabulary to 0 here,
-// else it could be freed when the old EngineState is freed. Luckily, this freeing currently
-// never happens, so we don't need to.
retval->parser_base = make_reg(s->sys_strings_segment, SYS_STRING_PARSER_BASE);
diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp
index 7f5f201079..92cfe9daf3 100644
--- a/engines/sci/engine/scriptdebug.cpp
+++ b/engines/sci/engine/scriptdebug.cpp
@@ -148,7 +148,7 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod
if (print_bw_tag)
printf("[%c] ", opsize ? 'B' : 'W');
- printf("%s", s->_kernel->getOpcode(opcode).name.c_str());
+ printf("%s", ((SciEngine*)g_engine)->getKernel()->getOpcode(opcode).name.c_str());
i = 0;
while (g_opcode_formats[opcode][i]) {
@@ -183,8 +183,8 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod
}
if (opcode == op_callk)
- printf(" %s[%x]", (param_value < s->_kernel->_kernelFuncs.size()) ?
- ((param_value < s->_kernel->getKernelNamesSize()) ? s->_kernel->getKernelName(param_value).c_str() : "[Unknown(postulated)]")
+ printf(" %s[%x]", (param_value < ((SciEngine*)g_engine)->getKernel()->_kernelFuncs.size()) ?
+ ((param_value < ((SciEngine*)g_engine)->getKernel()->getKernelNamesSize()) ? ((SciEngine*)g_engine)->getKernel()->getKernelName(param_value).c_str() : "[Unknown(postulated)]")
: "<invalid>", param_value);
else
printf(opsize ? " %02x" : " %04x", param_value);
@@ -238,7 +238,7 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod
int stackframe = (scr[pos.offset + 2] >> 1) + (scriptState.restAdjust);
int argc = ((scriptState.xs->sp)[- stackframe - 1]).offset;
- if (!s->_kernel->hasOldScriptHeader())
+ if (!((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader())
argc += (scriptState.restAdjust);
printf(" Kernel params: (");
@@ -273,7 +273,7 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod
if (!name)
name = "<invalid>";
- printf(" %s::%s[", name, (selector > s->_kernel->getSelectorNamesSize()) ? "<invalid>" : selector_name(s, selector));
+ printf(" %s::%s[", name, (selector > ((SciEngine*)g_engine)->getKernel()->getSelectorNamesSize()) ? "<invalid>" : selector_name(s, selector));
switch (lookup_selector(s, called_obj_addr, selector, 0, &fun_ref)) {
case kSelectorMethod:
diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp
index 74486ef015..6752ba3e56 100644
--- a/engines/sci/engine/seg_manager.cpp
+++ b/engines/sci/engine/seg_manager.cpp
@@ -138,7 +138,7 @@ void SegManager::setScriptSize(Script &scr, EngineState *s, int script_nr) {
if (!script || (s->_version >= SCI_VERSION_1_1 && !heap)) {
error("SegManager::setScriptSize: failed to load %s", !script ? "script" : "heap");
}
- if (s->_kernel->hasOldScriptHeader()) {
+ if (((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) {
scr.buf_size = script->size + READ_LE_UINT16(script->data) * 2;
//locals_size = READ_LE_UINT16(script->data) * 2;
} else if (s->_version < SCI_VERSION_1_1) {
diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp
index c43fe9b6de..38320c29cc 100644
--- a/engines/sci/engine/state.cpp
+++ b/engines/sci/engine/state.cpp
@@ -113,9 +113,6 @@ EngineState::EngineState(ResourceManager *res, sci_version_t version, uint32 fla
seg_manager = 0;
gc_countdown = 0;
- _vocabulary = 0;
- _kernel = 0;
-
successor = 0;
}
diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h
index 1759b26dcb..b41e9e383a 100644
--- a/engines/sci/engine/state.h
+++ b/engines/sci/engine/state.h
@@ -257,9 +257,6 @@ public:
MessageState _msgState;
- Vocabulary *_vocabulary;
- Kernel *_kernel;
-
EngineState *successor; /**< Successor of this state: Used for restoring */
private:
@@ -283,7 +280,7 @@ PaletteEntry get_pic_color(EngineState *s, int color);
// misleading. A different name (and a different place for declaring this)
// would be highly welcome.
static inline reg_t not_register(EngineState *s, reg_t r) {
- if (s->_kernel->_selectorMap.cantBeHere != -1)
+ if (((SciEngine*)g_engine)->getKernel()->_selectorMap.cantBeHere != -1)
return make_reg(0, !r.offset);
else
return r;
diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp
index d220547c92..99b5a86e53 100644
--- a/engines/sci/engine/vm.cpp
+++ b/engines/sci/engine/vm.cpp
@@ -312,7 +312,7 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt
Breakpoint *bp;
char method_name [256];
- sprintf(method_name, "%s::%s", obj_get_name(s, send_obj), s->_kernel->getSelectorName(selector).c_str());
+ sprintf(method_name, "%s::%s", obj_get_name(s, send_obj), ((SciEngine*)g_engine)->getKernel()->getSelectorName(selector).c_str());
bp = s->bp_list;
while (bp) {
@@ -952,26 +952,26 @@ void run_vm(EngineState *s, int restoring) {
gc_countdown(s);
scriptState.xs->sp -= (opparams[1] >> 1) + 1;
- if (!s->_kernel->hasOldScriptHeader()) {
+ if (!((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) {
scriptState.xs->sp -= scriptState.restAdjust;
s->restAdjust = 0; // We just used up the scriptState.restAdjust, remember?
}
- if (opparams[0] >= (int)s->_kernel->_kernelFuncs.size()) {
+ if (opparams[0] >= (int)((SciEngine*)g_engine)->getKernel()->_kernelFuncs.size()) {
error("Invalid kernel function 0x%x requested\n", opparams[0]);
} else {
int argc = ASSERT_ARITHMETIC(scriptState.xs->sp[0]);
- if (!s->_kernel->hasOldScriptHeader())
+ if (!((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader())
argc += scriptState.restAdjust;
- if (s->_kernel->_kernelFuncs[opparams[0]].signature
+ if (((SciEngine*)g_engine)->getKernel()->_kernelFuncs[opparams[0]].signature
&& !kernel_matches_signature(s,
- s->_kernel->_kernelFuncs[opparams[0]].signature, argc,
+ ((SciEngine*)g_engine)->getKernel()->_kernelFuncs[opparams[0]].signature, argc,
scriptState.xs->sp + 1)) {
error("[VM] Invalid arguments to kernel call %x\n", opparams[0]);
} else {
- s->r_acc = s->_kernel->_kernelFuncs[opparams[0]].fun(s, opparams[0],
+ s->r_acc = ((SciEngine*)g_engine)->getKernel()->_kernelFuncs[opparams[0]].fun(s, opparams[0],
argc, scriptState.xs->sp + 1);
}
// Call kernel function
@@ -982,7 +982,7 @@ void run_vm(EngineState *s, int restoring) {
xs_new = &(s->_executionStack.back());
s->_executionStackPosChanged = true;
- if (!s->_kernel->hasOldScriptHeader())
+ if (!((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader())
scriptState.restAdjust = s->restAdjust;
}
@@ -1194,7 +1194,7 @@ void run_vm(EngineState *s, int restoring) {
if (s->_version >= SCI_VERSION_1_1) {
s->r_acc.offset = opparams[0] + local_script->script_size;
} else {
- if (s->_kernel->hasLofsAbsolute())
+ if (((SciEngine*)g_engine)->getKernel()->hasLofsAbsolute())
s->r_acc.offset = opparams[0];
else
s->r_acc.offset = scriptState.xs->addr.pc.offset + opparams[0];
@@ -1214,7 +1214,7 @@ void run_vm(EngineState *s, int restoring) {
if (s->_version >= SCI_VERSION_1_1) {
r_temp.offset = opparams[0] + local_script->script_size;
} else {
- if (s->_kernel->hasLofsAbsolute())
+ if (((SciEngine*)g_engine)->getKernel()->hasLofsAbsolute())
r_temp.offset = opparams[0];
else
r_temp.offset = scriptState.xs->addr.pc.offset + opparams[0];
@@ -1500,7 +1500,7 @@ SelectorType lookup_selector(EngineState *s, reg_t obj_location, Selector select
// Early SCI versions used the LSB in the selector ID as a read/write
// toggle, meaning that we must remove it for selector lookup.
- if (s->_kernel->hasOldScriptHeader())
+ if (((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader())
selector_id &= ~1;
if (!obj) {
@@ -1659,7 +1659,7 @@ int script_instantiate_sci0(EngineState *s, int script_nr) {
Script *scr = s->seg_manager->getScript(seg_id);
- if (s->_kernel->hasOldScriptHeader()) {
+ if (((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) {
//
int locals_nr = READ_LE_UINT16(script->data);
@@ -1835,7 +1835,7 @@ int script_instantiate(EngineState *s, int script_nr) {
}
void script_uninstantiate_sci0(EngineState *s, int script_nr, SegmentId seg) {
- reg_t reg = make_reg(seg, s->_kernel->hasOldScriptHeader() ? 2 : 0);
+ reg_t reg = make_reg(seg, ((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader() ? 2 : 0);
int objtype, objlength;
Script *scr = s->seg_manager->getScript(seg);
@@ -1879,7 +1879,7 @@ void script_uninstantiate_sci0(EngineState *s, int script_nr, SegmentId seg) {
}
void script_uninstantiate(EngineState *s, int script_nr) {
- reg_t reg = make_reg(0, s->_kernel->hasOldScriptHeader() ? 2 : 0);
+ reg_t reg = make_reg(0, ((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader() ? 2 : 0);
reg.segment = s->seg_manager->segGet(script_nr);
Script *scr = script_locate_by_segment(s, reg.segment);
@@ -1938,7 +1938,7 @@ static EngineState *_game_run(EngineState *&s, int restoring) {
script_init_engine(s);
game_init(s);
sfx_reset_player();
- _init_stack_base_with_selector(s, s->_kernel->_selectorMap.play);
+ _init_stack_base_with_selector(s, ((SciEngine*)g_engine)->getKernel()->_selectorMap.play);
send_selector(s, s->game_obj, s->game_obj, s->stack_base, 2, s->stack_base);
@@ -1957,7 +1957,7 @@ static EngineState *_game_run(EngineState *&s, int restoring) {
debugC(2, kDebugLevelVM, "Restarting with replay()\n");
s->_executionStack.clear(); // Restart with replay
- _init_stack_base_with_selector(s, s->_kernel->_selectorMap.replay);
+ _init_stack_base_with_selector(s, ((SciEngine*)g_engine)->getKernel()->_selectorMap.replay);
send_selector(s, s->game_obj, s->game_obj, s->stack_base, 2, s->stack_base);
}
@@ -1976,7 +1976,7 @@ int game_run(EngineState **_s) {
EngineState *s = *_s;
debugC(2, kDebugLevelVM, "Calling %s::play()\n", s->_gameName.c_str());
- _init_stack_base_with_selector(s, s->_kernel->_selectorMap.play); // Call the play selector
+ _init_stack_base_with_selector(s, ((SciEngine*)g_engine)->getKernel()->_selectorMap.play); // Call the play selector
// Now: Register the first element on the execution stack-
if (!send_selector(s, s->game_obj, s->game_obj, s->stack_base, 2, s->stack_base)) {
diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h
index 1472fae97c..f711570d11 100644
--- a/engines/sci/engine/vm.h
+++ b/engines/sci/engine/vm.h
@@ -419,7 +419,7 @@ void script_debug(EngineState *s, bool bp);
* @return 0 on success, 1 if vocab.996 (the class table) is missing
* or corrupted
*/
-int script_init_engine(EngineState *s);
+int script_init_engine(EngineState *);
/**
* Sets the gamestate's save_dir to the parameter path
diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp
index cf08c69738..af8aac3147 100644
--- a/engines/sci/sci.cpp
+++ b/engines/sci/sci.cpp
@@ -100,7 +100,10 @@ SciEngine::~SciEngine() {
// Remove all of our debug levels here
Common::clearAllDebugChannels();
+ delete _kernel;
+ delete _vocabulary;
delete _console;
+ delete _resmgr;
}
Common::Error SciEngine::run() {
@@ -143,6 +146,8 @@ Common::Error SciEngine::run() {
return Common::kNoGameDataFoundError;
}
+ _kernel = new Kernel(_resmgr);
+ _vocabulary = new Vocabulary(_resmgr);
script_adjust_opcode_formats(_resmgr->_sciVersion);
#if 0
@@ -235,8 +240,6 @@ Common::Error SciEngine::run() {
delete _gamestate;
- delete _resmgr;
-
gfxop_exit(&gfx_state);
return Common::kNoError;
diff --git a/engines/sci/sci.h b/engines/sci/sci.h
index a2de5c3136..886a579799 100644
--- a/engines/sci/sci.h
+++ b/engines/sci/sci.h
@@ -35,6 +35,8 @@ namespace Sci {
class Console;
struct EngineState;
+class Kernel;
+class Vocabulary;
// our engine debug levels
enum kDebugLevels {
@@ -107,7 +109,9 @@ public:
Common::Language getLanguage() const;
Common::Platform getPlatform() const;
uint32 getFlags() const;
- ResourceManager *getResMgr() { return _resmgr; }
+ ResourceManager *getResMgr() const { return _resmgr; }
+ Kernel *getKernel() const { return _kernel; }
+ Vocabulary *getVocabulary() const { return _vocabulary; }
Common::String getSavegameName(int nr) const;
Common::String getSavegamePattern() const;
@@ -122,6 +126,8 @@ private:
const SciGameDescription *_gameDescription;
ResourceManager *_resmgr;
EngineState *_gamestate;
+ Kernel *_kernel;
+ Vocabulary *_vocabulary;
Console *_console;
};
diff --git a/engines/scumm/gfx.cpp b/engines/scumm/gfx.cpp
index 4574ece6d0..a54199272f 100644
--- a/engines/scumm/gfx.cpp
+++ b/engines/scumm/gfx.cpp
@@ -36,7 +36,7 @@
#include "scumm/util.h"
#ifdef USE_ARM_GFX_ASM
-extern "C" void asmDrawStripToScreen(int height, int width, byte const* text, byte const* src, byte* dst,
+extern "C" void asmDrawStripToScreen(int height, int width, void const* text, void const* src, byte* dst,
int vsPitch, int vmScreenWidth, int textSurfacePitch);
extern "C" void asmCopy8Col(byte* dst, int dstPitch, const byte* src, int height);
#endif /* USE_ARM_GFX_ASM */
diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp
index 051873e147..144de2f5f1 100644
--- a/engines/scumm/saveload.cpp
+++ b/engines/scumm/saveload.cpp
@@ -137,7 +137,7 @@ bool ScummEngine::saveState(Common::OutSaveFile *out, bool writeHeader) {
memcpy(hdr.name, _saveLoadName, sizeof(hdr.name));
saveSaveGameHeader(out, hdr);
}
-#if !defined(__DS__)
+#if !defined(__DS__) /* && !defined(__PLAYSTATION2__) */
Graphics::saveThumbnail(*out);
#endif
saveInfos(out);
diff --git a/engines/sword1/sound.cpp b/engines/sword1/sound.cpp
index 5577c66fc6..3e920c5018 100644
--- a/engines/sword1/sound.cpp
+++ b/engines/sword1/sound.cpp
@@ -51,6 +51,7 @@ Sound::Sound(const char *searchPath, Audio::Mixer *mixer, ResMan *pResMan) {
strcpy(_filePath, searchPath);
_mixer = mixer;
_resMan = pResMan;
+ _bigEndianSpeech = false;
_cowHeader = NULL;
_endOfQueue = 0;
_currentCowFile = 0;
@@ -67,6 +68,83 @@ Sound::~Sound(void) {
closeCowSystem();
}
+void Sound::checkSpeechFileEndianness() {
+ // Some mac versions (not all of them) use big endian wav, although
+ // the wav header doesn't indicate it.
+ // Use heuristic to determine endianness of speech.
+ // The heuristic consist in computing the sum of the absolute difference for
+ // every two consecutive samples. This is done both with a big endian and a
+ // little endian assumption. The one with the smallest sum should be the
+ // correct one (the sound wave is supposed to be relatively smooth).
+ // It needs at least 1000 samples to get stable result (the code below is
+ // using the first 2000 samples of the wav sound.
+
+ // Init speach file if not already done.
+ if (!_currentCowFile) {
+ // Open one of the speech file. It uses SwordEngine::_systemVars.currentCD
+ // to decide which file to open, therefore if it is currently set to zero
+ // we have to set it to either 1 or 2 (I decided to set it to 1 as this is
+ // more likely to be the first file that will be needed).
+ bool no_current_cd = false;
+ if (SwordEngine::_systemVars.currentCD == 0) {
+ SwordEngine::_systemVars.currentCD = 1;
+ no_current_cd = true;
+ }
+ initCowSystem();
+ if (no_current_cd) {
+ // In case it fails with CD1 retyr with CD2
+ if (!_currentCowFile) {
+ SwordEngine::_systemVars.currentCD = 2;
+ initCowSystem();
+ }
+ // Reset curentCD flag
+ SwordEngine::_systemVars.currentCD = 0;
+ }
+ }
+
+ // Testing for endianness makes sense only if using the nom compressed files.
+ if (_cowHeader == NULL || (_cowMode != CowWave && _cowMode != CowDemo))
+ return;
+
+ // I picked the sample to use randomly (I just made sure it is long enough so that there is
+ // a fair change of the heuristic to have a stable result and work for every languages).
+ int roomNo = _currentCowFile == 1 ? 1 : 129;
+ int localNo = _currentCowFile == 1 ? 2 : 933;
+ // Get the speech data and apply the heuristic
+ uint32 locIndex = _cowHeader[roomNo] >> 2;
+ uint32 sampleSize = _cowHeader[locIndex + (localNo * 2)];
+ uint32 index = _cowHeader[locIndex + (localNo * 2) - 1];
+ if (sampleSize) {
+ uint32 size;
+ double be_diff_sum = 0., le_diff_sum = 0.;
+ _bigEndianSpeech = false;
+ int16 *data = uncompressSpeech(index + _cowHeaderSize, sampleSize, &size);
+ // Compute average of differecen between two consecutive samples for both BE and LE
+ if (data) {
+ if (size > 4000)
+ size = 2000;
+ else
+ size /= 2;
+ int16 prev_be_value = (int16)SWAP_BYTES_16(*((uint16*)(data)));
+ for (uint32 i = 1 ; i < size ; ++i) {
+ le_diff_sum += fabs(data[i] - data[i-1]);
+ int16 be_value = (int16)SWAP_BYTES_16(*((uint16*)(data + i)));
+ be_diff_sum += fabs(be_value - prev_be_value);
+ prev_be_value = be_value;
+ }
+ delete [] data;
+ }
+ // Set the big endian flag
+ _bigEndianSpeech = (be_diff_sum < le_diff_sum);
+ if (_bigEndianSpeech)
+ debug(6, "Mac version: using big endian speech file");
+ else
+ debug(6, "Mac version: using little endian speech file");
+ debug(8, "Speech endianness heuristic: average = %f for BE and %f for LE, computed on %d samples)", be_diff_sum / (size - 1), le_diff_sum / (size - 1), size);
+ }
+}
+
+
int Sound::addToQueue(int32 fxNo) {
bool alreadyInQueue = false;
for (uint8 cnt = 0; (cnt < _endOfQueue) && (!alreadyInQueue); cnt++)
@@ -386,21 +464,32 @@ int16 *Sound::uncompressSpeech(uint32 index, uint32 cSize, uint32 *size) {
int16 *dstData = (int16*)malloc(resSize * 2);
int32 samplesLeft = resSize;
while (srcPos < cSize && samplesLeft > 0) {
- length = (int16)READ_LE_UINT16(srcData + srcPos);
+ length = (int16)(_bigEndianSpeech ? READ_BE_UINT16(srcData + srcPos) : READ_LE_UINT16(srcData + srcPos));
srcPos++;
if (length < 0) {
length = -length;
if (length > samplesLeft)
length = samplesLeft;
+ int16 value;
+ if (_bigEndianSpeech) {
+ value = (int16)SWAP_BYTES_16(*((uint16*)(srcData + srcPos)));
+ } else {
+ value = srcData[srcPos];
+ }
for (uint16 cnt = 0; cnt < (uint16)length; cnt++)
- dstData[dstPos++] = srcData[srcPos];
+ dstData[dstPos++] = value;
srcPos++;
} else {
if (length > samplesLeft)
length = samplesLeft;
- memcpy(dstData + dstPos, srcData + srcPos, length * 2);
- dstPos += length;
- srcPos += length;
+ if (_bigEndianSpeech) {
+ for (uint16 cnt = 0; cnt < (uint16)length; cnt++)
+ dstData[dstPos++] = (int16)SWAP_BYTES_16(*((uint16*)(srcData + (srcPos++))));
+ } else {
+ memcpy(dstData + dstPos, srcData + srcPos, length * 2);
+ dstPos += length;
+ srcPos += length;
+ }
}
samplesLeft -= length;
}
diff --git a/engines/sword1/sound.h b/engines/sword1/sound.h
index cdbdcdf6bb..c105d06b50 100644
--- a/engines/sword1/sound.h
+++ b/engines/sword1/sound.h
@@ -95,6 +95,8 @@ public:
void engine(void);
+ void checkSpeechFileEndianness();
+
private:
uint8 _sfxVolL, _sfxVolR, _speechVolL, _speechVolR;
void playSample(QueueElement *elem);
@@ -116,6 +118,7 @@ private:
uint8 _endOfQueue;
Audio::Mixer *_mixer;
ResMan *_resMan;
+ bool _bigEndianSpeech;
char _filePath[100];
static const char _musicList[270];
static const uint16 _roomsFixedFx[TOTAL_ROOMS][TOTAL_FX_PER_ROOM];
diff --git a/engines/sword1/sword1.cpp b/engines/sword1/sword1.cpp
index 3796ceefd6..61ab835da6 100644
--- a/engines/sword1/sword1.cpp
+++ b/engines/sword1/sword1.cpp
@@ -145,6 +145,10 @@ Common::Error SwordEngine::init() {
_systemVars.playSpeech = 1;
_mouseState = 0;
+
+ // Some Mac versions use big endian for the speech files but not all of them.
+ if (_systemVars.platform == Common::kPlatformMacintosh)
+ _sound->checkSpeechFileEndianness();
_logic->initialize();
_objectMan->initialize();
diff --git a/gui/ListWidget.cpp b/gui/ListWidget.cpp
index 07d22973ac..8661444cf3 100644
--- a/gui/ListWidget.cpp
+++ b/gui/ListWidget.cpp
@@ -564,7 +564,7 @@ void ListWidget::setFilter(const String &filter, bool redraw) {
// Restrict the list to everything which contains all words in _filter
// as substrings, ignoring case.
- Common::StringTokenizer tok(filter);
+ Common::StringTokenizer tok(_filter);
String tmp;
int n = 0;