[Scummvm-cvs-logs] SF.net SVN: scummvm:[54827] scummvm/trunk/sound/softsynth/mt32
lordhoto at users.sourceforge.net
lordhoto at users.sourceforge.net
Wed Dec 8 02:35:13 CET 2010
Revision: 54827
http://scummvm.svn.sourceforge.net/scummvm/?rev=54827&view=rev
Author: lordhoto
Date: 2010-12-08 01:35:12 +0000 (Wed, 08 Dec 2010)
Log Message:
-----------
MT32: Get rid of ANSIFile.
Modified Paths:
--------------
scummvm/trunk/sound/softsynth/mt32/mt32_file.cpp
scummvm/trunk/sound/softsynth/mt32/mt32_file.h
scummvm/trunk/sound/softsynth/mt32/synth.cpp
Modified: scummvm/trunk/sound/softsynth/mt32/mt32_file.cpp
===================================================================
--- scummvm/trunk/sound/softsynth/mt32/mt32_file.cpp 2010-12-07 23:55:27 UTC (rev 54826)
+++ scummvm/trunk/sound/softsynth/mt32/mt32_file.cpp 2010-12-08 01:35:12 UTC (rev 54827)
@@ -20,95 +20,51 @@
*/
-// FIXME: Disable symbol overrides so that we can use system headers.
-// But we *really* should get rid of this usage of FILE, fopen etc.
-#define FORBIDDEN_SYMBOL_ALLOW_ALL
-
-
-#include <stdio.h>
-
#include "mt32emu.h"
namespace MT32Emu {
- bool ANSIFile::open(const char *filename, OpenMode mode) {
- const char *fmode;
- if (mode == OpenMode_read) {
- fmode = "rb";
- } else {
- fmode = "wb";
- }
- fp = fopen(filename, fmode);
- return (fp != NULL);
- }
+bool File::readBit16u(Bit16u *in) {
+ Bit8u b[2];
+ if (read(&b[0], 2) != 2)
+ return false;
+ *in = ((b[0] << 8) | b[1]);
+ return true;
+}
- void ANSIFile::close() {
- fclose((FILE *)fp);
- }
+bool File::readBit32u(Bit32u *in) {
+ Bit8u b[4];
+ if (read(&b[0], 4) != 4)
+ return false;
+ *in = ((b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]);
+ return true;
+}
- size_t ANSIFile::read(void *in, size_t size) {
- return fread(in, 1, size, (FILE *)fp);
+bool File::writeBit16u(Bit16u out) {
+ if (!writeBit8u((Bit8u)((out & 0xFF00) >> 8))) {
+ return false;
}
-
- bool ANSIFile::readBit8u(Bit8u *in) {
- int c = fgetc((FILE *)fp);
- if (c == EOF)
- return false;
- *in = (Bit8u)c;
- return true;
+ if (!writeBit8u((Bit8u)(out & 0x00FF))) {
+ return false;
}
+ return true;
+}
- bool File::readBit16u(Bit16u *in) {
- Bit8u b[2];
- if (read(&b[0], 2) != 2)
- return false;
- *in = ((b[0] << 8) | b[1]);
- return true;
+bool File::writeBit32u(Bit32u out) {
+ if (!writeBit8u((Bit8u)((out & 0xFF000000) >> 24))) {
+ return false;
}
-
- bool File::readBit32u(Bit32u *in) {
- Bit8u b[4];
- if (read(&b[0], 4) != 4)
- return false;
- *in = ((b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]);
- return true;
+ if (!writeBit8u((Bit8u)((out & 0x00FF0000) >> 16))) {
+ return false;
}
-
- size_t ANSIFile::write(const void *out, size_t size) {
- return fwrite(out, 1, size, (FILE *)fp);
+ if (!writeBit8u((Bit8u)((out & 0x0000FF00) >> 8))) {
+ return false;
}
-
- bool ANSIFile::writeBit8u(Bit8u out) {
- return fputc(out, (FILE *)fp) != EOF;
+ if (!writeBit8u((Bit8u)(out & 0x000000FF))) {
+ return false;
}
+ return true;
+}
- bool File::writeBit16u(Bit16u out) {
- if (!writeBit8u((Bit8u)((out & 0xFF00) >> 8))) {
- return false;
- }
- if (!writeBit8u((Bit8u)(out & 0x00FF))) {
- return false;
- }
- return true;
- }
+} // End of namespace MT32Emu
- bool File::writeBit32u(Bit32u out) {
- if (!writeBit8u((Bit8u)((out & 0xFF000000) >> 24))) {
- return false;
- }
- if (!writeBit8u((Bit8u)((out & 0x00FF0000) >> 16))) {
- return false;
- }
- if (!writeBit8u((Bit8u)((out & 0x0000FF00) >> 8))) {
- return false;
- }
- if (!writeBit8u((Bit8u)(out & 0x000000FF))) {
- return false;
- }
- return true;
- }
-
- bool ANSIFile::isEOF() {
- return feof((FILE *)fp) != 0;
- }
-}
Modified: scummvm/trunk/sound/softsynth/mt32/mt32_file.h
===================================================================
--- scummvm/trunk/sound/softsynth/mt32/mt32_file.h 2010-12-07 23:55:27 UTC (rev 54826)
+++ scummvm/trunk/sound/softsynth/mt32/mt32_file.h 2010-12-08 01:35:12 UTC (rev 54827)
@@ -22,7 +22,7 @@
#ifndef MT32EMU_FILE_H
#define MT32EMU_FILE_H
-#include <stdio.h>
+#include "common/scummsys.h"
namespace MT32Emu {
@@ -47,19 +47,6 @@
virtual bool isEOF() = 0;
};
-class ANSIFile: public File {
-private:
- void *fp;
-public:
- bool open(const char *filename, OpenMode mode);
- void close();
- size_t read(void *in, size_t size);
- bool readBit8u(Bit8u *in);
- size_t write(const void *out, size_t size);
- bool writeBit8u(Bit8u out);
- bool isEOF();
-};
+} // End of namespace MT32Emu
-}
-
#endif
Modified: scummvm/trunk/sound/softsynth/mt32/synth.cpp
===================================================================
--- scummvm/trunk/sound/softsynth/mt32/synth.cpp 2010-12-07 23:55:27 UTC (rev 54826)
+++ scummvm/trunk/sound/softsynth/mt32/synth.cpp 2010-12-08 01:35:12 UTC (rev 54827)
@@ -162,21 +162,11 @@
}
File *Synth::openFile(const char *filename, File::OpenMode mode) {
- if (myProp.openFile != NULL) {
- return myProp.openFile(myProp.userData, filename, mode);
- }
- char pathBuf[2048];
- if (myProp.baseDir != NULL) {
- strcpy(&pathBuf[0], myProp.baseDir);
- strcat(&pathBuf[0], filename);
- filename = pathBuf;
- }
- ANSIFile *file = new ANSIFile();
- if (!file->open(filename, mode)) {
- delete file;
- return NULL;
- }
- return file;
+ // It should never happen that openFile is NULL in our use case.
+ // Just to cover the case where something is horrible wrong we
+ // use an assert here.
+ assert(myProp.openFile != NULL);
+ return myProp.openFile(myProp.userData, filename, mode);
}
void Synth::closeFile(File *file) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list