diff options
author | zeromus <zeromus@users.sf.net> | 2010-05-18 01:02:38 +0400 |
---|---|---|
committer | zeromus <zeromus@users.sf.net> | 2010-05-18 01:02:38 +0400 |
commit | 4e66aaef9c4e252e9a9ad57ed10df8b673a55a74 (patch) | |
tree | 8ca0a9f1e42662189f2135eacdef7214e4ccce95 /src/emufile.h | |
parent | fb1240c262c6efafadac4349f5676c65fc88e16e (diff) |
replace most of the crappy iostream stuff with EMUFILE
Diffstat (limited to 'src/emufile.h')
-rw-r--r-- | src/emufile.h | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/src/emufile.h b/src/emufile.h index c059d0b8..41a55294 100644 --- a/src/emufile.h +++ b/src/emufile.h @@ -23,12 +23,21 @@ #include <assert.h>
#include <stdio.h>
#include <string.h>
-#include "types-des.h"
#include <vector>
#include <algorithm>
#include <string>
#include <stdarg.h>
+//should be changed to #ifdef FCEUX but too much work
+#ifndef DESMUME
+typedef unsigned char u8;
+typedef unsigned short u16;
+typedef unsigned int u32;
+typedef char s8;
+typedef short s16;
+typedef int s32;
+#endif
+
#ifdef _XBOX
#undef min;
#undef max;
@@ -97,6 +106,11 @@ public: EMUFILE_MEMORY(std::vector<u8> *underlying) : vec(underlying), ownvec(false), pos(0), len(underlying->size()) { }
EMUFILE_MEMORY(u32 preallocate) : vec(new std::vector<u8>()), ownvec(true), pos(0), len(0) { vec->reserve(preallocate); }
EMUFILE_MEMORY() : vec(new std::vector<u8>()), ownvec(true), pos(0), len(0) { vec->reserve(1024); }
+ EMUFILE_MEMORY(void* buf, s32 size) : vec(new std::vector<u8>()), ownvec(true), pos(0), len(size) {
+ vec->reserve(size);
+ if(size != 0)
+ memcpy(&vec[0],buf,size);
+ }
~EMUFILE_MEMORY() {
if(ownvec) delete vec;
@@ -180,6 +194,11 @@ public: return pos;
}
+ void trim()
+ {
+ vec->resize(len);
+ }
+
virtual int size() { return (int)len; }
};
@@ -187,14 +206,18 @@ class EMUFILE_FILE : public EMUFILE { protected:
FILE* fp;
-public:
-
- EMUFILE_FILE(const char* fname, const char* mode)
+private:
+ void open(const char* fname, const char* mode)
{
fp = fopen(fname,mode);
if(!fp)
failbit = true;
- };
+ }
+
+public:
+
+ EMUFILE_FILE(const std::string& fname, const char* mode) { open(fname.c_str(),mode); }
+ EMUFILE_FILE(const char* fname, const char* mode) { open(fname,mode); }
virtual ~EMUFILE_FILE() {
if(NULL != fp)
@@ -205,6 +228,8 @@ public: return fp;
}
+ bool is_open() { return fp != NULL; }
+
virtual int fprintf(const char *format, ...) {
va_list argptr;
va_start(argptr, format);
|