aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2011-06-26 17:53:55 +1000
committerPaul Gilbert2011-06-26 17:53:55 +1000
commitfe9dc10964ab4dc4528cc473ef841709732fceff (patch)
tree9e4af910f13a2537a19e3237e8399365cb70c223
parenta307d405b6ddf4cb94d57e8365327667a6291bac (diff)
downloadscummvm-rg350-fe9dc10964ab4dc4528cc473ef841709732fceff.tar.gz
scummvm-rg350-fe9dc10964ab4dc4528cc473ef841709732fceff.tar.bz2
scummvm-rg350-fe9dc10964ab4dc4528cc473ef841709732fceff.zip
CGE: Implemented basic file access functionality
-rw-r--r--engines/cge/cge.cpp22
-rw-r--r--engines/cge/cge.h2
-rw-r--r--engines/cge/general.cpp82
-rw-r--r--engines/cge/general.h3
-rw-r--r--engines/cge/vol.cpp54
-rw-r--r--engines/cge/vol.h23
6 files changed, 100 insertions, 86 deletions
diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp
index ef00d0e517..d056a6737d 100644
--- a/engines/cge/cge.cpp
+++ b/engines/cge/cge.cpp
@@ -34,6 +34,7 @@
#include "cge/cge_main.h"
#include "cge/text.h"
#include "cge/bitmaps.h"
+#include "cge/vol.h"
namespace CGE {
@@ -41,9 +42,20 @@ namespace CGE {
CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription)
: Engine(syst), _gameDescription(gameDescription) {
+ // Debug/console setup
DebugMan.addDebugChannel(kCGEDebug, "general", "CGE general debug channel");
+ debug("CGEEngine::CGEEngine");
+}
+
+void CGEEngine::setup() {
+ // Create debugger console
_console = new CGEConsole(this);
+
+ // Initialise classes that have static members
+ VFILE::init();
+
+ // Initialise engine objects
Text = new TEXT(ProgName(), 128);
Vga = new VGA(M13H);
Heart = new HEART;
@@ -81,18 +93,20 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription)
Snail_ = new SNAIL(true);
OffUseCount = atoi(Text->getText(OFF_USE_COUNT));
-
- debug("CGEEngine::CGEEngine");
}
CGEEngine::~CGEEngine() {
debug("CGEEngine::~CGEEngine");
+ // Call classes with static members to clear them up
+ VFILE::deinit();
+
// Remove all of our debug levels here
DebugMan.clearAllDebugChannels();
_console = new CGEConsole(this);
+ // Delete engine objects
delete Text;
delete Vga;
delete Heart;
@@ -128,8 +142,8 @@ Common::Error CGEEngine::run() {
// Initialize graphics using following:
initGraphics(320, 200, false);
- // Create debugger console. It requires GFX to be initialized
- _console = new CGEConsole(this);
+ // Setup necessary game objects
+ setup();
// Additional setup.
debug("CGEEngine::init");
diff --git a/engines/cge/cge.h b/engines/cge/cge.h
index c6d9a099bf..f8857f045f 100644
--- a/engines/cge/cge.h
+++ b/engines/cge/cge.h
@@ -55,6 +55,8 @@ public:
private:
CGEConsole *_console;
+
+ void setup();
};
// Example console class
diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp
index efca664b71..9caa864227 100644
--- a/engines/cge/general.cpp
+++ b/engines/cge/general.cpp
@@ -158,9 +158,11 @@ uint16 RCrypt(void *buf, uint16 siz, uint16 seed) {
}
uint16 XCrypt(void *buf, uint16 siz, uint16 seed) {
-// for (uint16 i = 0; i < siz; i ++)
-// *(BUF ++) ^= seed;
- warning("STUB: XCrypt");
+ byte *b = static_cast<byte *>(buf);
+
+ for (uint16 i = 0; i < siz; i ++)
+ *b++ ^= seed;
+
return seed;
}
@@ -208,45 +210,32 @@ char *dwtom(uint32 val, char *str, int radix, int len) {
}
IOHAND::IOHAND(IOMODE mode, CRYPT *crpt)
- : XFILE(mode), Handle(-1), Crypt(crpt), Seed(SEED) {
+ : XFILE(mode), Crypt(crpt), Seed(SEED) {
}
IOHAND::IOHAND(const char *name, IOMODE mode, CRYPT *crpt)
- : XFILE(mode), Crypt(crpt), Seed(SEED) {
- /* switch (mode)
- {
- case REA : Error = _dos_open(name, O_RDONLY | O_DENYNONE, &Handle); break;
- case WRI : Error = _dos_creat(name, FA_ARCH, &Handle); break;
- case UPD : Error = _dos_open(name, O_RDWR | O_DENYALL, &Handle); break;
- }
- if (Error) Handle = -1;
- */
- warning("STUB: IOHAND::IOHAND");
+ : XFILE(mode), Crypt(crpt), Seed(SEED) {
+ // TODO: Check if WRI and/or UPD modes are needed, and map to a save file
+ assert(mode == REA);
+
+ _file.open(name);
}
IOHAND::~IOHAND(void) {
- /*
- if (Handle != -1)
- {
- Error = _dos_close(Handle);
- Handle = -1;
- }
- */
- warning("STUB: IOHAND::~IOHAND");
+ _file.close();
}
uint16 IOHAND::Read(void *buf, uint16 len) {
- /*
- if (Mode == WRI || Handle < 0) return 0;
- if (len) Error = _dos_read(Handle, buf, len, &len);
- if (Crypt) Seed = Crypt(buf, len, Seed);
- return len;
- */
- warning("STUB: IOHAND::Read");
- return 0;
+ if (Mode == WRI || !_file.isOpen())
+ return 0;
+
+ uint16 bytesRead = _file.read(buf, len);
+ if (Crypt) Seed = Crypt(buf, len, Seed);
+ return bytesRead;
}
uint16 IOHAND::Write(void *buf, uint16 len) {
+ error("IOHAND::Write not supported");
/*
if (len) {
if (Mode == REA || Handle < 0)
@@ -259,45 +248,24 @@ uint16 IOHAND::Write(void *buf, uint16 len) {
}
return len;
*/
- warning("STUB: IOHAND::Write");
- return 0;
}
long IOHAND::Mark(void) {
-/*
- return (Handle < 0) ? 0 : tell(Handle);
-*/
- warning("STUB: IOHAND::Mark");
- return 0;
+ return _file.pos();
}
long IOHAND::Seek(long pos) {
-/*
- if (Handle < 0)
- return 0;
- lseek(Handle, pos, SEEK_SET);
- return tell(Handle);
-*/
- warning("STUB: IOHAND::Seek");
- return 0;
+ _file.seek(pos, SEEK_SET);
+ return _file.pos();
}
long IOHAND::Size(void) {
-/*
- if (Handle < 0)
- return 0;
- return filelength(Handle);
-*/
- warning("STUB: IOHAND::Size");
- return 0;
+ return _file.size();
}
bool IOHAND::Exist(const char *name) {
-/*
- return access(name, 0) == 0;
-*/
- warning("STUB: IOHAND::Exist");
- return 0;
+ Common::File f;
+ return f.exists(name);
}
//#define EMS_ADR(a) (FP_SEG(a) > 0xA000)
diff --git a/engines/cge/general.h b/engines/cge/general.h
index 16b0c1e2bf..6fb8e24f9c 100644
--- a/engines/cge/general.h
+++ b/engines/cge/general.h
@@ -29,6 +29,7 @@
#define __GENERAL__
#include "common/system.h"
+#include "common/file.h"
#include "common/random.h"
#include "common/textconsole.h"
#include "common/str.h"
@@ -183,7 +184,7 @@ inline uint16 XRead(XFILE *xf, T *t) {
class IOHAND : public XFILE {
protected:
- int Handle;
+ Common::File _file;
uint16 Seed;
CRYPT *Crypt;
public:
diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp
index 9b6489afab..c76914c003 100644
--- a/engines/cge/vol.cpp
+++ b/engines/cge/vol.cpp
@@ -34,23 +34,45 @@
namespace CGE {
+DAT *VFILE::_Dat = NULL;
+BTFILE *VFILE::_Cat = NULL;
+VFILE *VFILE::_Recent = NULL;
+
+/*-----------------------------------------------------------------------*/
+
+DAT::DAT():
#ifdef VOL_UPD
-BTFILE VFILE::Cat(CAT_NAME, UPD, CRP);
-VOLBASE DAT::File(DAT_NAME, UPD, CRP);
+ _File(DAT_NAME, UPD, CRP)
#else
-BTFILE VFILE::Cat(CAT_NAME, REA, CRP);
-VOLBASE DAT::File(DAT_NAME, REA, CRP);
+ _File(DAT_NAME, REA, CRP)
#endif
-DAT VFILE::Dat;
-VFILE *VFILE::Recent = NULL;
+{
+}
+/*-----------------------------------------------------------------------*/
+
+void VFILE::init() {
+ _Dat = new DAT();
+#ifdef VOL_UPD
+ _Cat = new BTFILE(CAT_NAME, UPD, CRP);
+#else
+ _Cat = new BTFILE(CAT_NAME, REA, CRP);
+#endif
+
+ _Recent = NULL;
+}
+
+void VFILE::deinit() {
+ delete _Dat;
+ delete _Cat;
+}
VFILE::VFILE(const char *name, IOMODE mode)
: IOBUF(mode) {
if (mode == REA) {
- if (Dat.File.Error || Cat.Error)
+ if (_Dat->_File.Error || _Cat->Error)
error("Bad volume data");
- BT_KEYPACK *kp = Cat.Find(name);
+ BT_KEYPACK *kp = _Cat->Find(name);
if (scumm_stricmp(kp->Key, name) != 0)
Error = 1;
EndMark = (BufMark = BegMark = kp->Mark) + kp->Size;
@@ -63,26 +85,26 @@ VFILE::VFILE(const char *name, IOMODE mode)
VFILE::~VFILE(void) {
- if (Recent == this)
- Recent = NULL;
+ if (_Recent == this)
+ _Recent = NULL;
}
bool VFILE::Exist(const char *name) {
- return scumm_stricmp(Cat.Find(name)->Key, name) == 0;
+ return scumm_stricmp(_Cat->Find(name)->Key, name) == 0;
}
void VFILE::ReadBuff(void) {
- if (Recent != this) {
- Dat.File.Seek(BufMark + Lim);
- Recent = this;
+ if (_Recent != this) {
+ _Dat->_File.Seek(BufMark + Lim);
+ _Recent = this;
}
- BufMark = Dat.File.Mark();
+ BufMark = _Dat->_File.Mark();
long n = EndMark - BufMark;
if (n > IOBUF_SIZE)
n = IOBUF_SIZE;
- Lim = Dat.File.Read(Buff, (uint16) n);
+ Lim = _Dat->_File.Read(Buff, (uint16) n);
Ptr = 0;
}
diff --git a/engines/cge/vol.h b/engines/cge/vol.h
index ea82e8bf6a..a910aa7209 100644
--- a/engines/cge/vol.h
+++ b/engines/cge/vol.h
@@ -51,18 +51,22 @@ namespace CGE {
class DAT {
friend class VFILE;
- static VOLBASE File;
+ VOLBASE _File;
public:
- static bool Append(uint8 *buf, uint16 len);
- static bool Write(CFILE &f);
- static bool Read(long org, uint16 len, uint8 *buf);
+ DAT();
+
+ bool Append(uint8 *buf, uint16 len);
+ bool Write(CFILE &f);
+ bool Read(long org, uint16 len, uint8 *buf);
};
class VFILE : public IOBUF {
- static DAT Dat;
- static BTFILE Cat;
- static VFILE *Recent;
+private:
+ static DAT *_Dat;
+ static BTFILE *_Cat;
+ static VFILE *_Recent;
+
long BegMark, EndMark;
void ReadBuff(void);
void WriteBuff(void) { }
@@ -70,6 +74,9 @@ class VFILE : public IOBUF {
public:
VFILE(const char *name, IOMODE mode = REA);
~VFILE(void);
+ static void init();
+ static void deinit();
+
static bool Exist(const char *name);
static const char *Next(void);
long Mark(void) {
@@ -79,7 +86,7 @@ public:
return EndMark - BegMark;
}
long Seek(long pos) {
- Recent = NULL;
+ _Recent = NULL;
Lim = 0;
return (BufMark = BegMark + pos);
}