[Scummvm-cvs-logs] CVS: scummvm/scumm util.cpp,NONE,1.1.2.1 util.h,NONE,1.1.2.1 module.mk,1.44,1.44.2.1 resource.cpp,1.286,1.286.2.1 scumm.cpp,1.283,1.283.2.1 scumm.h,1.521,1.521.2.1 sound.cpp,1.405,1.405.2.1
Max Horn
fingolfin at users.sourceforge.net
Fri Dec 17 10:03:04 CET 2004
Update of /cvsroot/scummvm/scummvm/scumm
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1455
Modified Files:
Tag: release-0-7-0
module.mk resource.cpp scumm.cpp scumm.h sound.cpp
Added Files:
Tag: release-0-7-0
util.cpp util.h
Log Message:
Reduce code size of resource.cpp to help PalmOS port, by moving util code to a new file util.cpp and sound resource code to sound.cpp
--- NEW FILE: util.cpp ---
/* ScummVM - Scumm Interpreter
* Copyright (C) 2002-2004 The ScummVM project
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header: /cvsroot/scummvm/scummvm/scumm/Attic/util.cpp,v 1.1.2.1 2004/12/17 18:01:43 fingolfin Exp $
*
*/
#include "scumm/util.h"
namespace Scumm {
#pragma mark -
#pragma mark --- ScummFile ---
#pragma mark -
ScummFile::ScummFile() : _encbyte(0), _subFileStart(0), _subFileLen(0) {
}
void ScummFile::setEnc(byte value) {
_encbyte = value;
}
void ScummFile::setSubfileRange(uint32 start, uint32 len) {
// TODO: Add sanity checks
const uint32 fileSize = File::size();
assert(start <= fileSize);
assert(start + len <= fileSize);
_subFileStart = start;
_subFileLen = len;
seek(0, SEEK_SET);
}
void ScummFile::resetSubfile() {
_subFileStart = 0;
_subFileLen = 0;
seek(0, SEEK_SET);
}
bool ScummFile::open(const char *filename, AccessMode mode) {
if (File::open(filename, mode)) {
resetSubfile();
return true;
} else {
return false;
}
}
bool ScummFile::openSubFile(const char *filename) {
assert(isOpen());
// Disable the XOR encryption and reset any current subfile range
setEnc(0);
resetSubfile();
// Read in the filename table and look for the specified file
unsigned long file_off, file_len;
char file_name[0x20+1];
unsigned long i;
// Get the length of the data file to use for consistency checks
const uint32 data_file_len = size();
// Read offset and length to the file records */
const uint32 file_record_off = readUint32BE();
const uint32 file_record_len = readUint32BE();
// Do a quick check to make sure the offset and length are good
if (file_record_off + file_record_len > data_file_len) {
return false;
}
// Do a little consistancy check on file_record_length
if (file_record_len % 0x28) {
return false;
}
// Scan through the files
for (i = 0; i < file_record_len; i += 0x28) {
// read a file record
seek(file_record_off + i, SEEK_SET);
file_off = readUint32BE();
file_len = readUint32BE();
read(file_name, 0x20);
file_name[0x20] = 0;
assert(file_name[0]);
//debug(7, " extracting \'%s\'", file_name);
// Consistency check. make sure the file data is in the file
if (file_off + file_len > data_file_len) {
return false;
}
if (scumm_stricmp(file_name, filename) == 0) {
// We got a match!
setSubfileRange(file_off, file_len);
return true;
}
}
return false;
}
bool ScummFile::eof() {
return _subFileLen ? (pos() >= _subFileLen) : File::eof();
}
uint32 ScummFile::pos() {
return File::pos() - _subFileStart;
}
uint32 ScummFile::size() {
return _subFileLen ? _subFileLen : File::size();
}
void ScummFile::seek(int32 offs, int whence) {
if (_subFileLen) {
// Constrain the seek to the subfile
switch (whence) {
case SEEK_END:
offs = _subFileStart + _subFileLen - offs;
break;
case SEEK_SET:
offs += _subFileStart;
break;
case SEEK_CUR:
offs += File::pos();
break;
}
assert((int32)_subFileStart <= offs && offs <= (int32)(_subFileStart + _subFileLen));
whence = SEEK_SET;
}
File::seek(offs, whence);
}
uint32 ScummFile::read(void *ptr, uint32 len) {
uint32 realLen;
if (_subFileLen) {
// Limit the amount we read by the subfile boundaries.
const uint32 curPos = pos();
assert(_subFileLen >= curPos);
uint32 newPos = curPos + len;
if (newPos > _subFileLen) {
len = _subFileLen - curPos;
_ioFailed = true;
}
}
realLen = File::read(ptr, len);
// If an encryption byte was specified, XOR the data we just read by it.
// This simple kind of "encryption" was used by some of the older SCUMM
// games.
if (_encbyte) {
byte *p = (byte *)ptr;
byte *end = p + realLen;
while (p < end)
*p++ ^= _encbyte;
}
return realLen;
}
uint32 ScummFile::write(const void *, uint32) {
error("ScummFile does not support writing!");
}
#pragma mark -
#pragma mark --- Utilities ---
#pragma mark -
void checkRange(int max, int min, int no, const char *str) {
if (no < min || no > max) {
char buf[256];
snprintf(buf, sizeof(buf), str, no);
error("Value %d is out of bounds (%d,%d) (%s)", no, min, max, buf);
}
}
/**
* Convert an old style direction to a new style one (angle),
*/
int newDirToOldDir(int dir) {
if (dir >= 71 && dir <= 109)
return 1;
if (dir >= 109 && dir <= 251)
return 2;
if (dir >= 251 && dir <= 289)
return 0;
return 3;
}
/**
* Convert an new style (angle) direction to an old style one.
*/
int oldDirToNewDir(int dir) {
assert(0 <= dir && dir <= 3);
const int new_dir_table[4] = { 270, 90, 180, 0 };
return new_dir_table[dir];
}
/**
* Convert an angle to a simple direction.
*/
int toSimpleDir(int dirType, int dir) {
if (dirType) {
const int16 directions[] = { 22, 72, 107, 157, 202, 252, 287, 337 };
for (int i = 0; i < 7; i++)
if (dir >= directions[i] && dir <= directions[i+1])
return i+1;
} else {
const int16 directions[] = { 71, 109, 251, 289 };
for (int i = 0; i < 3; i++)
if (dir >= directions[i] && dir <= directions[i+1])
return i+1;
}
return 0;
}
/**
* Convert a simple direction to an angle.
*/
int fromSimpleDir(int dirType, int dir) {
if (dirType)
return dir * 45;
else
return dir * 90;
}
/**
* Normalize the given angle - that means, ensure it is positive, and
* change it to the closest multiple of 45 degree by abusing toSimpleDir.
*/
int normalizeAngle(int angle) {
int temp;
temp = (angle + 360) % 360;
return toSimpleDir(1, temp) * 45;
}
const char *tag2str(uint32 tag) {
static char str[5];
str[0] = (char)(tag >> 24);
str[1] = (char)(tag >> 16);
str[2] = (char)(tag >> 8);
str[3] = (char)tag;
str[4] = '\0';
return str;
}
} // End of namespace Scumm
--- NEW FILE: util.h ---
/* ScummVM - Scumm Interpreter
* Copyright (C) 2002-2004 The ScummVM project
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header: /cvsroot/scummvm/scummvm/scumm/Attic/util.h,v 1.1.2.1 2004/12/17 18:01:43 fingolfin Exp $
*
*/
#ifndef SCUMM_UTIL_H
#define SCUMM_UTIL_H
#include "common/file.h"
#include "common/util.h"
namespace Scumm {
class ScummFile : public File {
private:
byte _encbyte;
uint32 _subFileStart;
uint32 _subFileLen;
public:
ScummFile();
void setEnc(byte value);
void setSubfileRange(uint32 start, uint32 len);
void resetSubfile();
bool open(const char *filename, AccessMode mode = kFileReadMode);
bool openSubFile(const char *filename);
bool eof();
uint32 pos();
uint32 size();
void seek(int32 offs, int whence = SEEK_SET);
uint32 read(void *ptr, uint32 size);
uint32 write(const void *ptr, uint32 size);
};
// This is a constant lookup table of reverse bit masks
extern const byte revBitMask[8];
/* Direction conversion functions (between old dir and new dir format) */
int newDirToOldDir(int dir);
int oldDirToNewDir(int dir);
int normalizeAngle(int angle);
int fromSimpleDir(int dirtype, int dir);
int toSimpleDir(int dirtype, int dir);
void checkRange(int max, int min, int no, const char *str);
const char *tag2str(uint32 tag);
} // End of namespace Scumm
#endif
Index: module.mk
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/module.mk,v
retrieving revision 1.44
retrieving revision 1.44.2.1
diff -u -d -r1.44 -r1.44.2.1
--- module.mk 27 Nov 2004 17:50:22 -0000 1.44
+++ module.mk 17 Dec 2004 18:01:17 -0000 1.44.2.1
@@ -49,6 +49,7 @@
scumm/sound.o \
scumm/string.o \
scumm/usage_bits.o \
+ scumm/util.o \
scumm/vars.o \
scumm/verbs.o \
scumm/wiz_he.o \
Index: resource.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/resource.cpp,v
retrieving revision 1.286
retrieving revision 1.286.2.1
diff -u -d -r1.286 -r1.286.2.1
--- resource.cpp 27 Nov 2004 13:10:41 -0000 1.286
+++ resource.cpp 17 Dec 2004 18:01:19 -0000 1.286.2.1
@@ -38,165 +38,6 @@
static const char *resTypeFromId(int id);
-
-ScummFile::ScummFile() : _encbyte(0), _subFileStart(0), _subFileLen(0) {
-}
-
-void ScummFile::setEnc(byte value) {
- _encbyte = value;
-}
-
[...1173 lines suppressed...]
- if (_features & GF_OLD_BUNDLE) {
- _fileHandle.seek(wa_offs, SEEK_SET);
- _fileHandle.read(createResource(type, idx, wa_size), wa_size);
- } else {
- _fileHandle.seek(wa_offs - 6, SEEK_SET);
- _fileHandle.read(createResource(type, idx, wa_size + 6), wa_size + 6);
- }
- return 1;
- } else if (ro_offs != 0) {
- _fileHandle.seek(ro_offs - 2, SEEK_SET);
- _fileHandle.read(createResource(type, idx, ro_size - 4), ro_size - 4);
- return 1;
- }
- res.roomoffs[type][idx] = 0xFFFFFFFF;
- return 0;
-}
-
int ScummEngine::getResourceRoomNr(int type, int idx) {
if (type == rtRoom && _heversion < 70)
return idx;
Index: scumm.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/scumm.cpp,v
retrieving revision 1.283
retrieving revision 1.283.2.1
diff -u -d -r1.283 -r1.283.2.1
--- scumm.cpp 9 Dec 2004 15:06:44 -0000 1.283
+++ scumm.cpp 17 Dec 2004 18:01:23 -0000 1.283.2.1
@@ -2545,91 +2545,6 @@
}
}
-#pragma mark -
-#pragma mark --- Utilities ---
-#pragma mark -
-
-void checkRange(int max, int min, int no, const char *str) {
- if (no < min || no > max) {
- char buf[256];
- snprintf(buf, sizeof(buf), str, no);
- error("Value %d is out of bounds (%d,%d) (%s)", no, min, max, buf);
- }
-}
-
-/**
- * Convert an old style direction to a new style one (angle),
- */
-int newDirToOldDir(int dir) {
- if (dir >= 71 && dir <= 109)
- return 1;
- if (dir >= 109 && dir <= 251)
- return 2;
- if (dir >= 251 && dir <= 289)
- return 0;
- return 3;
-}
-
-/**
- * Convert an new style (angle) direction to an old style one.
- */
-int oldDirToNewDir(int dir) {
- assert(0 <= dir && dir <= 3);
- const int new_dir_table[4] = { 270, 90, 180, 0 };
- return new_dir_table[dir];
-}
-
-/**
- * Convert an angle to a simple direction.
- */
-int toSimpleDir(int dirType, int dir) {
- if (dirType) {
- const int16 directions[] = { 22, 72, 107, 157, 202, 252, 287, 337 };
- for (int i = 0; i < 7; i++)
- if (dir >= directions[i] && dir <= directions[i+1])
- return i+1;
- } else {
- const int16 directions[] = { 71, 109, 251, 289 };
- for (int i = 0; i < 3; i++)
- if (dir >= directions[i] && dir <= directions[i+1])
- return i+1;
- }
-
- return 0;
-}
-
-/**
- * Convert a simple direction to an angle.
- */
-int fromSimpleDir(int dirType, int dir) {
- if (dirType)
- return dir * 45;
- else
- return dir * 90;
-}
-
-/**
- * Normalize the given angle - that means, ensure it is positive, and
- * change it to the closest multiple of 45 degree by abusing toSimpleDir.
- */
-int normalizeAngle(int angle) {
- int temp;
-
- temp = (angle + 360) % 360;
-
- return toSimpleDir(1, temp) * 45;
-}
-
-const char *tag2str(uint32 tag) {
- static char str[5];
- str[0] = (char)(tag >> 24);
- str[1] = (char)(tag >> 16);
- str[2] = (char)(tag >> 8);
- str[3] = (char)tag;
- str[4] = '\0';
- return str;
-}
-
} // End of namespace Scumm
using namespace Scumm;
Index: scumm.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/scumm.h,v
retrieving revision 1.521
retrieving revision 1.521.2.1
diff -u -d -r1.521 -r1.521.2.1
--- scumm.h 28 Nov 2004 21:24:01 -0000 1.521
+++ scumm.h 17 Dec 2004 18:01:25 -0000 1.521.2.1
@@ -31,6 +31,7 @@
#include "scumm/gfx.h"
#include "scumm/script.h"
+#include "scumm/util.h"
#include "scumm/wiz_he.h"
namespace GUI {
@@ -61,29 +62,6 @@
typedef Common::Map<Common::String, int> ObjectIDMap;
-class ScummFile : public File {
-private:
- byte _encbyte;
- uint32 _subFileStart;
- uint32 _subFileLen;
-public:
- ScummFile();
- void setEnc(byte value);
-
- void setSubfileRange(uint32 start, uint32 len);
- void resetSubfile();
-
- bool open(const char *filename, AccessMode mode = kFileReadMode);
- bool openSubFile(const char *filename);
-
- bool eof();
- uint32 pos();
- uint32 size();
- void seek(int32 offs, int whence = SEEK_SET);
- uint32 read(void *ptr, uint32 size);
- uint32 write(const void *ptr, uint32 size);
-};
-
// Use g_scumm from error() ONLY
extern ScummEngine *g_scumm;
@@ -1333,21 +1311,6 @@
byte VAR_WIZ_TCOLOR;
};
-// This is a constant lookup table of reverse bit masks
-extern const byte revBitMask[8];
-
-/* Direction conversion functions (between old dir and new dir format) */
-int newDirToOldDir(int dir);
-int oldDirToNewDir(int dir);
-
-int normalizeAngle(int angle);
-int fromSimpleDir(int dirtype, int dir);
-int toSimpleDir(int dirtype, int dir);
-
-void checkRange(int max, int min, int no, const char *str);
-
-const char *tag2str(uint32 tag);
-
} // End of namespace Scumm
#endif
Index: sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/sound.cpp,v
retrieving revision 1.405
retrieving revision 1.405.2.1
diff -u -d -r1.405 -r1.405.2.1
--- sound.cpp 11 Dec 2004 23:34:34 -0000 1.405
+++ sound.cpp 17 Dec 2004 18:01:29 -0000 1.405.2.1
@@ -1195,4 +1195,1050 @@
return soundEntries;
}
+
+#pragma mark -
+#pragma mark --- Sound resource handling ---
+#pragma mark -
+
+/*
+ * TODO: The way we handle sound/music resources really is one huge hack.
+ * We probably should reconsider how we do this, and maybe come up with a
[...1019 lines suppressed...]
+ } else if (((_midiDriver == MD_PCJR) || (_midiDriver == MD_PCSPK)) && wa_offs != 0) {
+ if (_features & GF_OLD_BUNDLE) {
+ _fileHandle.seek(wa_offs, SEEK_SET);
+ _fileHandle.read(createResource(type, idx, wa_size), wa_size);
+ } else {
+ _fileHandle.seek(wa_offs - 6, SEEK_SET);
+ _fileHandle.read(createResource(type, idx, wa_size + 6), wa_size + 6);
+ }
+ return 1;
+ } else if (ro_offs != 0) {
+ _fileHandle.seek(ro_offs - 2, SEEK_SET);
+ _fileHandle.read(createResource(type, idx, ro_size - 4), ro_size - 4);
+ return 1;
+ }
+ res.roomoffs[type][idx] = 0xFFFFFFFF;
+ return 0;
+}
+
+
} // End of namespace Scumm
More information about the Scummvm-git-logs
mailing list