unify emufile across emulators
This commit is contained in:
parent
84e9be0e29
commit
3562dbad63
|
@ -19,7 +19,7 @@ libdesmume_a_SOURCES = \
|
|||
common.cpp common.h \
|
||||
debug.cpp debug.h \
|
||||
Disassembler.cpp Disassembler.h \
|
||||
emufat.h emufat.cpp emufat_types.h emufile.h emufile.cpp fat.h FIFO.cpp FIFO.h \
|
||||
emufat.h emufat.cpp emufat_types.h emufile.h emufile.cpp emufile_types.h fat.h FIFO.cpp FIFO.h \
|
||||
firmware.cpp firmware.h GPU.cpp GPU.h \
|
||||
GPU_osd.h \
|
||||
mem.h mc.cpp mc.h \
|
||||
|
|
|
@ -1,3 +1,25 @@
|
|||
/*
|
||||
Copyright (C) 2009-2010 DeSmuME team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "emufile.h"
|
||||
|
||||
#include <vector>
|
||||
|
@ -24,7 +46,7 @@ size_t EMUFILE_MEMORY::_fread(const void *ptr, size_t bytes){
|
|||
{
|
||||
u8* src = buf()+pos;
|
||||
u8* dst = (u8*)ptr;
|
||||
for(int i=0;i<todo;i++)
|
||||
for(size_t i=0;i<todo;i++)
|
||||
*dst++ = *src++;
|
||||
}
|
||||
else
|
||||
|
@ -64,4 +86,174 @@ EMUFILE* EMUFILE_MEMORY::memwrap()
|
|||
return this;
|
||||
}
|
||||
|
||||
|
||||
void EMUFILE::write64le(u64* val)
|
||||
{
|
||||
write64le(*val);
|
||||
}
|
||||
|
||||
void EMUFILE::write64le(u64 val)
|
||||
{
|
||||
#ifdef LOCAL_BE
|
||||
u8 s[8];
|
||||
s[0]=(u8)b;
|
||||
s[1]=(u8)(b>>8);
|
||||
s[2]=(u8)(b>>16);
|
||||
s[3]=(u8)(b>>24);
|
||||
s[4]=(u8)(b>>32);
|
||||
s[5]=(u8)(b>>40);
|
||||
s[6]=(u8)(b>>48);
|
||||
s[7]=(u8)(b>>56);
|
||||
fwrite((char*)&s,8);
|
||||
return 8;
|
||||
#else
|
||||
fwrite(&val,8);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
size_t EMUFILE::read64le(u64 *Bufo)
|
||||
{
|
||||
u64 buf;
|
||||
if(fread((char*)&buf,8) != 8)
|
||||
return 0;
|
||||
#ifndef LOCAL_BE
|
||||
*Bufo=buf;
|
||||
#else
|
||||
*Bufo = LE_TO_LOCAL_64(buf);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
u64 EMUFILE::read64le()
|
||||
{
|
||||
u64 temp;
|
||||
read64le(&temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
void EMUFILE::write32le(u32* val)
|
||||
{
|
||||
write32le(*val);
|
||||
}
|
||||
|
||||
void EMUFILE::write32le(u32 val)
|
||||
{
|
||||
#ifdef LOCAL_BE
|
||||
u8 s[4];
|
||||
s[0]=(u8)val;
|
||||
s[1]=(u8)(val>>8);
|
||||
s[2]=(u8)(val>>16);
|
||||
s[3]=(u8)(val>>24);
|
||||
fwrite(s,4);
|
||||
#else
|
||||
fwrite(&val,4);
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t EMUFILE::read32le(s32* Bufo) { return read32le((u32*)Bufo); }
|
||||
|
||||
size_t EMUFILE::read32le(u32* Bufo)
|
||||
{
|
||||
u32 buf;
|
||||
if(fread(&buf,4)<4)
|
||||
return 0;
|
||||
#ifndef LOCAL_BE
|
||||
*(u32*)Bufo=buf;
|
||||
#else
|
||||
*(u32*)Bufo=((buf&0xFF)<<24)|((buf&0xFF00)<<8)|((buf&0xFF0000)>>8)|((buf&0xFF000000)>>24);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
u32 EMUFILE::read32le()
|
||||
{
|
||||
u32 ret;
|
||||
read32le(&ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void EMUFILE::write16le(u16* val)
|
||||
{
|
||||
write16le(*val);
|
||||
}
|
||||
|
||||
void EMUFILE::write16le(u16 val)
|
||||
{
|
||||
#ifdef LOCAL_BE
|
||||
u8 s[2];
|
||||
s[0]=(u8)val;
|
||||
s[1]=(u8)(val>>8);
|
||||
fwrite(s,2);
|
||||
#else
|
||||
fwrite(&val,2);
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t EMUFILE::read16le(s16* Bufo) { return read16le((u16*)Bufo); }
|
||||
|
||||
size_t EMUFILE::read16le(u16* Bufo)
|
||||
{
|
||||
u32 buf;
|
||||
if(fread(&buf,2)<2)
|
||||
return 0;
|
||||
#ifndef LOCAL_BE
|
||||
*(u16*)Bufo=buf;
|
||||
#else
|
||||
*Bufo = LE_TO_LOCAL_16(buf);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
u16 EMUFILE::read16le()
|
||||
{
|
||||
u16 ret;
|
||||
read16le(&ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void EMUFILE::write8le(u8* val)
|
||||
{
|
||||
write8le(*val);
|
||||
}
|
||||
|
||||
|
||||
void EMUFILE::write8le(u8 val)
|
||||
{
|
||||
fwrite(&val,1);
|
||||
}
|
||||
|
||||
size_t EMUFILE::read8le(u8* val)
|
||||
{
|
||||
return fread(val,1);
|
||||
}
|
||||
|
||||
u8 EMUFILE::read8le()
|
||||
{
|
||||
u8 temp;
|
||||
fread(&temp,1);
|
||||
return temp;
|
||||
}
|
||||
|
||||
void EMUFILE::writedouble(double* val)
|
||||
{
|
||||
write64le(double_to_u64(*val));
|
||||
}
|
||||
void EMUFILE::writedouble(double val)
|
||||
{
|
||||
write64le(double_to_u64(val));
|
||||
}
|
||||
|
||||
double EMUFILE::readdouble()
|
||||
{
|
||||
double temp;
|
||||
readdouble(&temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
size_t EMUFILE::readdouble(double* val)
|
||||
{
|
||||
u64 temp;
|
||||
size_t ret = read64le(&temp);
|
||||
*val = u64_to_double(temp);
|
||||
return ret;
|
||||
}
|
|
@ -1,17 +1,23 @@
|
|||
/* Copyright (C) 2009-2010 DeSmuME team
|
||||
/*
|
||||
Copyright (C) 2009-2010 DeSmuME team
|
||||
|
||||
This file 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.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
This file 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.
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with the this software. If not, see <http://www.gnu.org/licenses/>.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
//don't use emufile for files bigger than 2GB! you have been warned! some day this will be fixed.
|
||||
|
@ -27,7 +33,7 @@
|
|||
#include <string>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "types.h"
|
||||
#include "emufile_types.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <io.h>
|
||||
|
@ -78,6 +84,31 @@ public:
|
|||
|
||||
virtual void fwrite(const void *ptr, size_t bytes) = 0;
|
||||
|
||||
void write64le(u64* val);
|
||||
void write64le(u64 val);
|
||||
size_t read64le(u64* val);
|
||||
u64 read64le();
|
||||
void write32le(u32* val);
|
||||
void write32le(s32* val) { write32le((u32*)val); }
|
||||
void write32le(u32 val);
|
||||
size_t read32le(u32* val);
|
||||
size_t read32le(s32* val);
|
||||
u32 read32le();
|
||||
void write16le(u16* val);
|
||||
void write16le(s16* val) { write16le((u16*)val); }
|
||||
void write16le(u16 val);
|
||||
size_t read16le(s16* Bufo);
|
||||
size_t read16le(u16* val);
|
||||
u16 read16le();
|
||||
void write8le(u8* val);
|
||||
void write8le(u8 val);
|
||||
size_t read8le(u8* val);
|
||||
u8 read8le();
|
||||
void writedouble(double* val);
|
||||
void writedouble(double val);
|
||||
double readdouble();
|
||||
size_t readdouble(double* val);
|
||||
|
||||
virtual int fseek(int offset, int origin) = 0;
|
||||
|
||||
virtual int ftell() = 0;
|
||||
|
@ -125,7 +156,10 @@ public:
|
|||
if(pos>length) pos=length;
|
||||
}
|
||||
|
||||
u8* buf() { return &(*vec)[0]; }
|
||||
u8* buf() {
|
||||
if(size()==0) reserve(1);
|
||||
return &(*vec)[0];
|
||||
}
|
||||
|
||||
std::vector<u8>* get_vec() { return vec; };
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef EMUFILE_TYPES_H
|
||||
#define EMUFILE_TYPES_H
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#endif //EMUFILE_TYPES_H
|
Loading…
Reference in New Issue