aboutsummaryrefslogtreecommitdiff
path: root/engines/tony/mpal
diff options
context:
space:
mode:
authorPaul Gilbert2012-04-29 23:19:30 +1000
committerPaul Gilbert2012-04-29 23:22:24 +1000
commit118f5ca0102144b5c282f012def6c96c69052bc1 (patch)
tree388ae8a2c5096e44e139e0b88c793c569a1a8a15 /engines/tony/mpal
parent4784367debbaeae656f3bdec5a146b821150a2d0 (diff)
downloadscummvm-rg350-118f5ca0102144b5c282f012def6c96c69052bc1.tar.gz
scummvm-rg350-118f5ca0102144b5c282f012def6c96c69052bc1.tar.bz2
scummvm-rg350-118f5ca0102144b5c282f012def6c96c69052bc1.zip
TONY: Implemented RMGameBoxes class and all dependent classes
Diffstat (limited to 'engines/tony/mpal')
-rw-r--r--engines/tony/mpal/expr.cpp4
-rw-r--r--engines/tony/mpal/loadmpc.cpp2
-rw-r--r--engines/tony/mpal/memory.cpp145
-rw-r--r--engines/tony/mpal/memory.h82
-rw-r--r--engines/tony/mpal/mpal.cpp12
-rw-r--r--engines/tony/mpal/mpaldll.h1
-rw-r--r--engines/tony/mpal/mpalutils.cpp106
-rw-r--r--engines/tony/mpal/mpalutils.h69
-rw-r--r--engines/tony/mpal/stubs.cpp39
-rw-r--r--engines/tony/mpal/stubs.h12
10 files changed, 416 insertions, 56 deletions
diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp
index 0faf91744c..2f0e890af9 100644
--- a/engines/tony/mpal/expr.cpp
+++ b/engines/tony/mpal/expr.cpp
@@ -48,8 +48,10 @@
**************************************************************************/
#include "mpal.h"
+#include "memory.h"
#include "mpaldll.h"
#include "stubs.h"
+#include "tony/tony.h"
/*
#include "lzo1x.h"
@@ -149,7 +151,7 @@ static byte *DuplicateExpression(HGLOBAL h) {
num=*(byte *)orig;
one=(LPEXPRESSION)(orig+1);
- clone=GlobalAlloc(GMEM_FIXED,sizeof(EXPRESSION)*num+1);
+ clone = (byte *)GlobalAlloc(GMEM_FIXED, sizeof(EXPRESSION)*num+1);
two=(LPEXPRESSION)(clone+1);
CopyMemory(clone,orig,sizeof(EXPRESSION)*num+1);
diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp
index f9426c8d58..ff94dbae8d 100644
--- a/engines/tony/mpal/loadmpc.cpp
+++ b/engines/tony/mpal/loadmpc.cpp
@@ -52,6 +52,8 @@
*/
#include "mpal.h"
#include "mpaldll.h"
+#include "memory.h"
+#include "tony/tony.h"
namespace Tony {
diff --git a/engines/tony/mpal/memory.cpp b/engines/tony/mpal/memory.cpp
new file mode 100644
index 0000000000..604e61ed24
--- /dev/null
+++ b/engines/tony/mpal/memory.cpp
@@ -0,0 +1,145 @@
+/* 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.
+ *
+ *
+ */
+
+#include "common/textconsole.h"
+#include "tony/mpal/memory.h"
+
+namespace Tony {
+
+namespace MPAL {
+
+/****************************************************************************\
+* MemoryItem methods
+\****************************************************************************/
+
+/**
+ * Constructor
+ * @param Data sizee
+ */
+MemoryItem::MemoryItem(uint32 size) {
+ _size = size;
+ _buffer = (size == 0) ? NULL : new byte[size];
+}
+
+/**
+ * Destructor
+ */
+MemoryItem::~MemoryItem() {
+ delete[] _buffer;
+}
+
+/**
+ * Returns a pointer to the resource
+ */
+MemoryItem::operator void *() {
+ return DataPointer();
+}
+
+/****************************************************************************\
+* MemoryManager methods
+\****************************************************************************/
+
+MemoryManager::MemoryManager() {
+}
+
+/**
+ * Destructor
+ */
+MemoryManager::~MemoryManager() {
+ Common::List<MemoryItem *>::iterator i;
+ for (i = _memoryBlocks.begin(); i != _memoryBlocks.end(); ++i) {
+ MemoryItem *item = *i;
+ delete item;
+ }
+}
+
+/**
+ * Allocates a new memory block
+ * @returns Returns a MemoryItem instance for the new block
+ */
+MemoryItem &MemoryManager::allocate(uint32 size) {
+ MemoryItem *newItem = new MemoryItem(size);
+ _memoryBlocks.push_back(newItem);
+
+ return *newItem;
+}
+
+/**
+ * Allocates a new memory block and returns it's data pointer
+ * @returns Data pointer to allocated block
+ */
+HGLOBAL MemoryManager::alloc(uint32 size) {
+ MemoryItem &newItem = allocate(size);
+ return (HGLOBAL)newItem.DataPointer();
+}
+
+/**
+ * Returns a reference to the MemoryItem for a gien byte pointer
+ * @param block Byte pointer
+ */
+MemoryItem &MemoryManager::getItem(HGLOBAL handle) {
+ Common::List<MemoryItem *>::iterator i;
+ for (i = _memoryBlocks.begin(); i != _memoryBlocks.end(); ++i) {
+ MemoryItem *item = *i;
+ if (item->DataPointer() == handle)
+ return *item;
+ }
+
+ error("Could not locate a memory block");
+}
+
+/**
+ * Square bracketes operator
+ * @param block Byte pointer
+ */
+MemoryItem &MemoryManager::operator[](HGLOBAL handle) {
+ return getItem(handle);
+}
+
+/**
+ * Returns a size of a memory block given it's pointer
+ */
+uint32 MemoryManager::getSize(HGLOBAL handle) {
+ MemoryItem &item = getItem(handle);
+ return item.Size();
+}
+
+/**
+ * Erases a given item
+ */
+void MemoryManager::erase(MemoryItem &item) {
+ delete item;
+ _memoryBlocks.remove(&item);
+}
+
+/**
+ * Erases a given item
+ */
+void MemoryManager::erase(HGLOBAL handle) {
+ MemoryItem &item = getItem(handle);
+ erase(item);
+}
+
+} // end of namespace MPAL
+
+} // end of namespace Tony
diff --git a/engines/tony/mpal/memory.h b/engines/tony/mpal/memory.h
new file mode 100644
index 0000000000..dde2e8908c
--- /dev/null
+++ b/engines/tony/mpal/memory.h
@@ -0,0 +1,82 @@
+/* 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 TONY_MPAL_MEMORY
+#define TONY_MPAL_MEMORY
+
+#include "common/scummsys.h"
+#include "common/list.h"
+
+namespace Tony {
+
+namespace MPAL {
+
+typedef void *HANDLE;
+typedef HANDLE HGLOBAL;
+
+class MemoryItem {
+protected:
+ void *_buffer;
+ uint32 _size;
+public:
+ MemoryItem(uint32 size);
+ virtual ~MemoryItem();
+
+ uint32 Size() { return _size; }
+ void *DataPointer() { return _buffer; }
+ bool IsValid() { return _buffer != NULL; }
+
+ // Casting for access to data
+ operator void *();
+};
+
+class MemoryManager {
+private:
+ Common::List<MemoryItem *> _memoryBlocks;
+public:
+ MemoryManager();
+ virtual ~MemoryManager();
+
+ MemoryItem &allocate(uint32 size);
+ HGLOBAL alloc(uint32 size);
+ MemoryItem &getItem(HGLOBAL handle);
+ MemoryItem &operator[](HGLOBAL handle);
+ void erase(MemoryItem &item);
+ void erase(HGLOBAL handle);
+
+ uint32 getSize(HANDLE handle);
+};
+
+// defines
+#define GlobalAlloc(flags, size) _vm->_memoryManager.alloc(size)
+#define GlobalAllocate(size) _vm->_memoryManager.allocate(size)
+#define GlobalFree(handle) _vm->_memoryManager.erase(handle)
+#define GlobalLock(handle) (_vm->_memoryManager.getItem(handle).DataPointer())
+#define GlobalUnlock(handle) {}
+#define GlobalSize(handle) (_vm->_memoryManager.getItem(handle).Size())
+
+} // end of namespace MPAL
+
+} // end of namespace Tony
+
+#endif
diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp
index e07669849e..b4b37e7723 100644
--- a/engines/tony/mpal/mpal.cpp
+++ b/engines/tony/mpal/mpal.cpp
@@ -860,7 +860,7 @@ void PASCAL ScriptThread(LPMPALSCRIPT s) {
uint32 dwCurTime;
uint32 dwId;
static HANDLE cfHandles[MAX_COMMANDS_PER_MOMENT];
- int numHandles;
+ int numHandles = 0;
LPCFCALL p;
// warning("PlayScript(): Moments: %u\n",s->nMoments);
@@ -1785,7 +1785,7 @@ bool mpalInit(char * lpszMpcFileName, char * lpszMprFileName, LPLPCUSTOMFUNCTION
if (lpResources==NULL)
return false;
- cmpbuf = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, dwSizeComp);
+ cmpbuf = (byte *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, dwSizeComp);
if (cmpbuf==NULL)
return false;
@@ -1840,12 +1840,14 @@ bool mpalInit(char * lpszMpcFileName, char * lpszMprFileName, LPLPCUSTOMFUNCTION
#define GETARG(type) va_arg(v,type)
uint32 mpalQuery(uint16 wQueryType, ...) {
- uint32 dwRet; int x,y,z; char * n;
+ uint32 dwRet = 0;
+ int x,y,z;
+ char *n;
va_list v;
Common::String buf;
- mpalError=OK;
- va_start(v,wQueryType);
+ mpalError = OK;
+ va_start(v, wQueryType);
switch (wQueryType) {
/*
diff --git a/engines/tony/mpal/mpaldll.h b/engines/tony/mpal/mpaldll.h
index 8a52f1ed90..ee3820531a 100644
--- a/engines/tony/mpal/mpaldll.h
+++ b/engines/tony/mpal/mpaldll.h
@@ -51,6 +51,7 @@
#define __MPALDLL_H
#include "common/file.h"
+#include "memory.h"
#include "stubs.h"
namespace Tony {
diff --git a/engines/tony/mpal/mpalutils.cpp b/engines/tony/mpal/mpalutils.cpp
new file mode 100644
index 0000000000..2e3bd07383
--- /dev/null
+++ b/engines/tony/mpal/mpalutils.cpp
@@ -0,0 +1,106 @@
+/* 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.
+ *
+ *
+ */
+
+#include "tony/mpal/mpalutils.h"
+#include "tony/tony.h"
+
+namespace Tony {
+
+namespace MPAL {
+
+/****************************************************************************\
+* RMRes methods
+\****************************************************************************/
+
+/**
+ * Constructor
+ * @param resId MPAL resource to open
+ */
+RMRes::RMRes(uint32 resID) {
+ m_h = _vm->_resUpdate.QueryResource(resID);
+ if (m_h == NULL)
+ m_h = mpalQueryResource(resID);
+ if (m_h != NULL)
+ m_buf = (byte *)GlobalLock(m_h);
+}
+
+/**
+ * Destructor
+ */
+RMRes::~RMRes() {
+ if (m_h != NULL) {
+ GlobalUnlock(m_h);
+ GlobalFree(m_h);
+ }
+}
+
+/**
+ * Returns a pointer to the resource
+ */
+const byte *RMRes::DataPointer() {
+ return m_buf;
+}
+
+/**
+ * Returns a pointer to the resource
+ */
+RMRes::operator const byte *() {
+ return DataPointer();
+}
+
+/**
+ * Returns the size of the resource
+ */
+unsigned int RMRes::Size() {
+ return GlobalSize(m_h);
+}
+
+/****************************************************************************\
+* RMResRaw methods
+\****************************************************************************/
+
+RMResRaw::RMResRaw(uint32 resID) : RMRes(resID) {
+}
+
+RMResRaw::~RMResRaw() {
+}
+
+const byte *RMResRaw::DataPointer() {
+ return m_buf + 8;
+}
+
+RMResRaw::operator const byte *() {
+ return DataPointer();
+}
+
+int RMResRaw::Width() {
+ return READ_LE_UINT16(m_buf + 4);
+}
+
+int RMResRaw::Height() {
+ return READ_LE_UINT16(m_buf + 6);
+}
+
+} // end of namespace MPAL
+
+} // end of namespace Tony
diff --git a/engines/tony/mpal/mpalutils.h b/engines/tony/mpal/mpalutils.h
new file mode 100644
index 0000000000..cb8d4ec97d
--- /dev/null
+++ b/engines/tony/mpal/mpalutils.h
@@ -0,0 +1,69 @@
+/* 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 TONY_MPAL_MPALUTILS
+#define TONY_MPAL_MPALUTILS
+
+#include "common/scummsys.h"
+#include "memory.h"
+#include "stubs.h"
+
+namespace Tony {
+
+namespace MPAL {
+
+class RMRes {
+protected:
+ HGLOBAL m_h;
+ byte *m_buf;
+
+public:
+ RMRes(uint32 resID);
+ virtual ~RMRes();
+
+ // Attributes
+ unsigned int Size();
+ const byte *DataPointer();
+ bool IsValid() { return m_h != NULL; }
+
+ // Casting for access to data
+ operator const byte*();
+};
+
+class RMResRaw : public RMRes {
+public:
+ RMResRaw(uint32 resID);
+ virtual ~RMResRaw();
+
+ const byte *DataPointer();
+ operator const byte*();
+
+ int Width();
+ int Height();
+};
+
+} // end of namespace MPAL
+
+} // end of namespace Tony
+
+#endif
diff --git a/engines/tony/mpal/stubs.cpp b/engines/tony/mpal/stubs.cpp
index c25dd2ab43..054ed55c68 100644
--- a/engines/tony/mpal/stubs.cpp
+++ b/engines/tony/mpal/stubs.cpp
@@ -37,45 +37,6 @@ namespace Tony {
namespace MPAL {
/**
- * Allocates a memory block
- */
-byte *GlobalAlloc(uint16 flags, int size) {
- byte *result = (byte *)malloc(size);
-
- if (flags & GMEM_ZEROINIT)
- Common::fill(result, result + size, 0);
-
- return result;
-}
-
-/**
- * Lock a global handle
- * @param h Global handle
- * @remarks Since HGLOBALs are directly representing the pointers anyway,
- * simply return it
- */
-void *GlobalLock(HGLOBAL h) {
- return h;
-}
-
-/**
- * Unlock a global handle
- * @param h Global handle
- * @remarks Since HGLOBALs are directly representing the pointers anyway,
- * the unlock method doesn't need to do anything
- */
-void GlobalUnlock(HGLOBAL h) {
-}
-
-/**
- * Free a globally allocated memory block
- * @param h Global handle
- */
-void GlobalFree(HGLOBAL h) {
- free(h);
-}
-
-/**
* Display a message
* @param msg Message to display
*/
diff --git a/engines/tony/mpal/stubs.h b/engines/tony/mpal/stubs.h
index f41d222b8a..be856790bc 100644
--- a/engines/tony/mpal/stubs.h
+++ b/engines/tony/mpal/stubs.h
@@ -31,6 +31,7 @@
#include "common/scummsys.h"
#include "common/algorithm.h"
+#include "tony/mpal/memory.h"
namespace Tony {
@@ -40,9 +41,6 @@ namespace MPAL {
* Types
\****************************************************************************/
-typedef void *HGLOBAL;
-typedef void *HANDLE;
-
typedef uint32 (*LPTHREAD_START_ROUTINE)(void *lpThreadParameter);
/****************************************************************************\
@@ -75,14 +73,6 @@ Out CopyMemory(Out dst, In first, int size) {
* Methods
\****************************************************************************/
-extern byte *GlobalAlloc(uint16 flags, int size);
-
-extern void *GlobalLock(HGLOBAL h);
-
-extern void GlobalUnlock(HGLOBAL h);
-
-extern void GlobalFree(HGLOBAL h);
-
extern void MessageBox(const Common::String &msg);
extern uint32 timeGetTime();