aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/cge2/cge2.cpp11
-rw-r--r--engines/cge2/cge2.h8
-rw-r--r--engines/cge2/cge2_main.cpp70
-rw-r--r--engines/cge2/cge2_main.h38
-rw-r--r--engines/cge2/module.mk4
-rw-r--r--engines/cge2/text.cpp152
-rw-r--r--engines/cge2/text.h67
7 files changed, 344 insertions, 6 deletions
diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp
index 370846faf7..bc2ce5615d 100644
--- a/engines/cge2/cge2.cpp
+++ b/engines/cge2/cge2.cpp
@@ -31,6 +31,7 @@
#include "cge2/bitmap.h"
#include "cge2/vga13h.h"
#include "cge2/sound.h"
+#include "cge2/text.h"
namespace CGE2 {
@@ -42,11 +43,13 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription)
_midiPlayer = nullptr;
_fx = nullptr;
_sound = nullptr;
+ _text = nullptr;
_quitFlag = false;
_bitmapPalette = nullptr;
_mode = 0;
_music = true;
+ _startupMode = 1;
}
void CGE2Engine::init() {
@@ -55,6 +58,7 @@ void CGE2Engine::init() {
_fx = new Fx(this, 16);
_sound = new Sound(this);
_midiPlayer = new MusicPlayer(this);
+ _text = new Text(this, "CGE");
}
void CGE2Engine::deinit() {
@@ -64,6 +68,7 @@ void CGE2Engine::deinit() {
delete _fx;
delete _sound;
delete _midiPlayer;
+ delete _text;
}
bool CGE2Engine::hasFeature(EngineFeature f) const {
@@ -93,12 +98,8 @@ Common::Error CGE2Engine::run() {
initGraphics(kScrWidth, kScrHeight, false);
init();
-
- showTitle("WELCOME");
- // Temporary code to test the midi player.
- _midiPlayer->loadMidi(1);
- g_system->delayMillis(100000);
+ cge2_main();
deinit();
return Common::kNoError;
diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h
index 9f7fcf6244..2c06832edd 100644
--- a/engines/cge2/cge2.h
+++ b/engines/cge2/cge2.h
@@ -41,6 +41,7 @@ class Sprite;
class MusicPlayer;
class Fx;
class Sound;
+class Text;
#define kScrWidth 320
#define kScrHeight 240
@@ -58,6 +59,11 @@ public:
virtual Common::Error run();
bool showTitle(const char *name);
+ void cge2_main();
+ char *mergeExt(char *buf, const char *name, const char *ext);
+ void inf(const char *text, bool wideSpace = false);
+ void movie(const char *ext);
+ void runGame();
const ADGameDescription *_gameDescription;
@@ -65,6 +71,7 @@ public:
Dac *_bitmapPalette;
int _mode;
bool _music;
+ int _startupMode;
ResourceManager *_resman;
Vga *_vga;
@@ -72,6 +79,7 @@ public:
MusicPlayer *_midiPlayer;
Fx *_fx;
Sound *_sound;
+ Text *_text;
private:
void init();
void deinit();
diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp
new file mode 100644
index 0000000000..d3feb0a49f
--- /dev/null
+++ b/engines/cge2/cge2_main.cpp
@@ -0,0 +1,70 @@
+/* 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.
+ *
+ */
+
+/*
+ * This code is based on original Sfinx source code
+ * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon
+ */
+
+#include "sound.h"
+#include "cge2/cge2_main.h"
+#include "cge2/cge2.h"
+#include "cge2/vga13h.h"
+#include "cge2/text.h"
+
+namespace CGE2 {
+
+void CGE2Engine::movie(const char *ext) {
+ warning("STUB: CGE2Engine::movie()");
+}
+
+void CGE2Engine::runGame() {
+ warning("STUB: CGE2Engine::runGame()");
+}
+
+void CGE2Engine::cge2_main() {
+ warning("STUB: CGE2Engine::cge2_main()");
+
+ _mode++;
+
+ if (showTitle("WELCOME")) {
+ if (_mode == 1)
+ movie(kIntroExt);
+ if (_text->getText(255) != NULL) {
+ runGame();
+ _startupMode = 2;
+ } else
+ _vga->sunset();
+ } else
+ _vga->sunset();
+}
+
+char *CGE2Engine::mergeExt(char *buf, const char *name, const char *ext) {
+ strcpy(buf, name);
+ char *dot = strrchr(buf, '.');
+ if (!dot)
+ strcat(buf, ext);
+
+ return buf;
+}
+
+} // End of namespace CGE2
diff --git a/engines/cge2/cge2_main.h b/engines/cge2/cge2_main.h
new file mode 100644
index 0000000000..a1fb071b69
--- /dev/null
+++ b/engines/cge2/cge2_main.h
@@ -0,0 +1,38 @@
+/* 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.
+ *
+ */
+
+/*
+ * This code is based on original Sfinx source code
+ * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon
+ */
+
+#ifndef CGE2_MAIN_H
+#define CGE2_MAIN_H
+
+namespace CGE2 {
+
+#define kLineMax 512
+#define kIntroExt ".I80"
+
+} // End of namespace CGE2
+
+#endif // CGE2_MAIN_H
diff --git a/engines/cge2/module.mk b/engines/cge2/module.mk
index f885933e9d..4fb9156fce 100644
--- a/engines/cge2/module.mk
+++ b/engines/cge2/module.mk
@@ -6,7 +6,9 @@ MODULE_OBJS = \
fileio.o \
vga13h.o \
bitmap.o \
- sound.o
+ sound.o \
+ cge2_main.o \
+ text.o
# This module can be built as a plugin
ifeq ($(ENABLE_CGE2), DYNAMIC_PLUGIN)
diff --git a/engines/cge2/text.cpp b/engines/cge2/text.cpp
new file mode 100644
index 0000000000..e65c19f202
--- /dev/null
+++ b/engines/cge2/text.cpp
@@ -0,0 +1,152 @@
+/* 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.
+ *
+ */
+
+/*
+ * This code is based on original Sfinx source code
+ * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon
+ */
+
+//#include "cge/general.h"
+#include "cge2/text.h"
+//#include "cge/talk.h"
+//#include "cge/game.h"
+//#include "cge/snail.h"
+#include "cge2/cge2_main.h"
+#include "common/str.h"
+
+namespace CGE2 {
+
+Text::Text(CGE2Engine *vm, const char *fname) : _vm(vm) {
+ _vm->mergeExt(_fileName, fname, kSayExt);
+ if (!_vm->_resman->exist(_fileName))
+ error("No talk (%s)", _fileName);
+ int16 txtCount = count() + 1;
+ if (!txtCount)
+ error("Unable to read dialog file %s", _fileName);
+
+ _cache = new Handler[txtCount];
+ for (_size = 0; _size < txtCount; _size++) {
+ _cache[_size]._ref = 0;
+ _cache[_size]._text = NULL;
+ }
+ load();
+}
+
+Text::~Text() {
+ clear();
+ delete[] _cache;
+}
+
+int16 Text::count() {
+ EncryptedStream tf(_vm, _fileName);
+ if (tf.err())
+ return -1;
+
+ Common::String line;
+ char tmpStr[kLineMax + 1];
+
+ int counter = 0;
+
+ for (line = tf.readLine(); !tf.eos(); line = tf.readLine()) {
+ char *s;
+ assert(line.size() <= 513);
+ Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr));
+ if ((s = strtok(tmpStr, " =,;/\t\n")) == NULL)
+ continue;
+ if (!Common::isDigit(*s))
+ continue;
+
+ counter++;
+ }
+ return counter;
+}
+
+void Text::clear() {
+ for (Handler *p = _cache, *q = p + _size; p < q; p++) {
+ if (p->_ref) {
+ p->_ref = 0;
+ delete[] p->_text;
+ p->_text = NULL;
+ }
+ }
+}
+
+void Text::load() {
+ EncryptedStream tf(_vm, _fileName);
+ assert(!tf.err());
+
+ Common::String line;
+ char tmpStr[kLineMax + 1];
+ int idx;
+
+ for (idx = 0, line = tf.readLine(); !tf.eos(); line = tf.readLine()) {
+ int n = line.size();
+ char *s;
+ Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr));
+ if ((s = strtok(tmpStr, " =,;/\t\n")) == NULL)
+ continue;
+ if (!Common::isDigit(*s))
+ continue;
+
+ int r = atoi(s);
+
+ s += strlen(s);
+ if (s < tmpStr + n)
+ ++s;
+
+ _cache[idx]._ref = r;
+ _cache[idx]._text = new char[strlen(s) + 1];
+ strcpy(_cache[idx]._text, s);
+ idx++;
+ }
+}
+
+char *Text::getText(int ref) {
+ int i;
+ for (i = 0; (i < _size) && (_cache[i]._ref != ref); i++)
+ ;
+
+ if (i < _size)
+ return _cache[i]._text;
+
+ warning("getText: Unable to find ref %d", ref);
+ return NULL;
+}
+
+void Text::say(const char *text, Sprite *spr) {
+ warning("STUB: Text::say()");
+}
+
+void CGE2Engine::inf(const char *text, bool wideSpace) {
+ warning("STUB: CGE2Engine::inf()");
+}
+
+void Text::sayTime(Sprite *spr) {
+ TimeDate curTime;
+ _vm->_system->getTimeAndDate(curTime);
+
+ char t[6];
+ sprintf(t, "%d:%02d", curTime.tm_hour, curTime.tm_min);
+ say(t, spr);
+}
+
+} // End of namespace CGE2
diff --git a/engines/cge2/text.h b/engines/cge2/text.h
new file mode 100644
index 0000000000..634a3c8766
--- /dev/null
+++ b/engines/cge2/text.h
@@ -0,0 +1,67 @@
+/* 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.
+ *
+ */
+
+/*
+ * This code is based on original Sfinx source code
+ * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon
+ */
+
+#ifndef CGE2_TEXT_H
+#define CGE2_TEXT_H
+
+//#include "cge/talk.h"
+#include "cge2/cge2.h"
+
+namespace CGE2 {
+
+#define kSayExt ".SAY"
+#define kSysTextMax 1000
+#define kTextNoMouse 95
+#define kInfName 101
+#define kSayName 102
+#define kInfRef 301
+#define kSayRef 302
+
+
+class Text {
+ struct Handler {
+ int _ref;
+ char *_text;
+ } *_cache;
+ int _size;
+ char _fileName[kPathMax];
+ void load();
+ int16 count();
+public:
+ Text(CGE2Engine *vm, const char *fname);
+ ~Text();
+ void clear();
+ char *getText(int ref);
+ void say(const char *text, Sprite *spr);
+ void sayTime(Sprite *spr);
+private:
+ CGE2Engine *_vm;
+};
+
+} // End of namespace CGE2
+
+#endif // CGE2_TEXT_H