00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef BVIRTUALFILE_H
00013 #define BVIRTUALFILE_H
00014
00015
00016 #include <gba_nds_fat/gba_nds_fat.h>
00017
00018
00019
00020
00021 class BVirtualFile {
00022 public:
00023 typedef enum {
00024 WHENCE_START,
00025 WHENCE_CURRENT,
00026 WHENCE_END
00027 } Whence;
00028
00029 virtual ~BVirtualFile() {}
00030
00031 virtual int read(void* buf, unsigned int nbytes) = 0;
00032 virtual int write(void* buf, unsigned int nbytes) = 0;
00033 virtual long tell() = 0;
00034 virtual int seek(long offset, Whence whence) = 0;
00035 virtual int eof() = 0;
00036
00037 int getc();
00038
00039 void rewind() { seek(0, WHENCE_START); }
00040 };
00041
00042 class BFATFile: public BVirtualFile {
00043 public:
00044 BFATFile(char* filename, char* mode="r");
00045 BFATFile(FAT_FILE* file, bool closeWhenDone);
00046 ~BFATFile();
00047
00048 virtual int read(void* buf, unsigned int nbytes);
00049 virtual int write(void* buf, unsigned int nbytes);
00050 virtual long tell();
00051 virtual int seek(long offset, Whence whence);
00052 virtual int eof();
00053
00054 private:
00055 FAT_FILE* _file;
00056 bool _close;
00057 };
00058
00059 class BMemFile: public BVirtualFile {
00060 public:
00061 BMemFile(u32 address, u32 len);
00062
00063 virtual int read(void* buf, unsigned int nbytes);
00064 virtual int write(void* buf, unsigned int nbytes);
00065 virtual long tell();
00066 virtual int seek(long offset, Whence whence);
00067 virtual int eof();
00068
00069 private:
00070 u32 _adr; u32 _len; u32 _cur;
00071 };
00072
00073 #endif