From 71f8ce0894117a9b5431c7066ad1352203d89c4a Mon Sep 17 00:00:00 2001 From: Kamil Zbróg Date: Sun, 13 Oct 2013 22:34:26 +0100 Subject: PRINCE: script added --- engines/prince/module.mk | 1 + engines/prince/script.cpp | 58 +++++++++++++++++++++++++++++++++++++ engines/prince/script.h | 73 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 engines/prince/script.cpp create mode 100644 engines/prince/script.h diff --git a/engines/prince/module.mk b/engines/prince/module.mk index 8997ee1daa..853592b503 100644 --- a/engines/prince/module.mk +++ b/engines/prince/module.mk @@ -1,6 +1,7 @@ MODULE := engines/prince MODULE_OBJS = \ + script.o \ graphics.o \ mhwanh.o \ detection.o \ diff --git a/engines/prince/script.cpp b/engines/prince/script.cpp new file mode 100644 index 0000000000..da1dd4cf28 --- /dev/null +++ b/engines/prince/script.cpp @@ -0,0 +1,58 @@ +#include "prince/script.h" + +#include "common/debug-channels.h" +#include "common/stream.h" + +namespace Prince { + +Script::Script(PrinceEngine *vm) : + _code(NULL), _stacktop(0), _vm(vm), _random("GroovieScripts") { +} + +Script::~Script() { +} + +bool Script::loadFromStream(Common::SeekableReadStream &stream) { + _codeSize = stream.size(); + _code = new byte[_codeSize]; + + if (!_code) + return false; + + stream.read(_code, _codeSize); + // Initialize the script + _currentInstruction = 0; + + return true; +} + +void Script::step() { +} + +uint8 Script::getCodeByte(uint16 address) { + if (address >= _codeSize) + error("Trying to read a script byte at address 0x%04X, while the " + "script is just 0x%04X bytes long", address, _codeSize); + return _code[address]; +} + +uint8 Script::readScript8bits() { + uint8 data = getCodeByte(_currentInstruction); + _currentInstruction++; + return data; +} + +uint16 Script::readScript16bits() { + uint8 lower = readScript8bits(); + uint8 upper = readScript8bits(); + return lower | (upper << 8); +} + +uint32 Script::readScript32bits() { + uint16 lower = readScript16bits(); + uint16 upper = readScript16bits(); + return lower | (upper << 16); +} + +} + diff --git a/engines/prince/script.h b/engines/prince/script.h new file mode 100644 index 0000000000..1365fb7ec5 --- /dev/null +++ b/engines/prince/script.h @@ -0,0 +1,73 @@ +/* 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. + * + */ + +#ifndef PRINCE_SCRIPT_H +#define PRINCE_SCRIPT_H + +#include "common/random.h" + +namespace Common { + class SeekableReadStream; +} + +namespace Prince { + +class PrinceEngine; + +class Script +{ +public: + Script(PrinceEngine *vm); + virtual ~Script(); + + bool loadFromStream(Common::SeekableReadStream &stream); + + void step(); + +private: + PrinceEngine *_vm; + + Common::RandomSource _random; + + byte *_code; + uint16 _codeSize; + uint16 _currentInstruction; + + // Stack + uint16 _stack[0x20]; + uint8 _stacktop; + uint8 _savedStacktop; + + // Helper functions + uint8 getCodeByte(uint16 address); + uint8 readScript8bits(); + uint16 readScript16bits(); + uint32 readScript32bits(); + uint16 readScript8or16bits(); + + typedef void (Script::*OpcodeFunc)(); + static OpcodeFunc _opcodes[]; +}; + +} + +#endif -- cgit v1.2.3