| ... | ... |
@@ -18,71 +18,22 @@ |
| 18 | 18 |
#include "readwrite.h" |
| 19 | 19 |
#include "types.h" |
| 20 | 20 |
|
| 21 |
-//well. just for the sake of consistency |
|
| 22 |
-/*int write8le(uint8_t b, EMUFILE*os) |
|
| 21 |
+int read8le(uint8_t *Bufo, EMUFILE *is) |
|
| 23 | 22 |
{
|
| 24 |
- os->fwrite((char*)&b,1); |
|
| 25 |
- return 1; |
|
| 26 |
-}*/ |
|
| 27 |
- |
|
| 28 |
-//well. just for the sake of consistency |
|
| 29 |
-int read8le(uint8_t *Bufo, EMUFILE*is) |
|
| 30 |
-{
|
|
| 31 |
- if(is->_fread((char*)Bufo,1) != 1) |
|
| 23 |
+ if (is->_fread(Bufo, 1) != 1) |
|
| 32 | 24 |
return 0; |
| 33 | 25 |
return 1; |
| 34 | 26 |
} |
| 35 | 27 |
|
| 36 |
-///writes a little endian 16bit value to the specified file |
|
| 37 |
-/*int write16le(uint16_t b, EMUFILE *fp) |
|
| 38 |
-{
|
|
| 39 |
- uint8_t s[2]; |
|
| 40 |
- s[0]=(uint8_t)b; |
|
| 41 |
- s[1]=(uint8_t)(b>>8); |
|
| 42 |
- fp->fwrite(s,2); |
|
| 43 |
- return 2; |
|
| 44 |
-}*/ |
|
| 45 |
- |
|
| 46 |
- |
|
| 47 |
-///writes a little endian 32bit value to the specified file |
|
| 48 |
-/*int write32le(uint32_t b, EMUFILE *fp) |
|
| 49 |
-{
|
|
| 50 |
- uint8_t s[4]; |
|
| 51 |
- s[0]=(uint8_t)b; |
|
| 52 |
- s[1]=(uint8_t)(b>>8); |
|
| 53 |
- s[2]=(uint8_t)(b>>16); |
|
| 54 |
- s[3]=(uint8_t)(b>>24); |
|
| 55 |
- fp->fwrite(s,4); |
|
| 56 |
- return 4; |
|
| 57 |
-}*/ |
|
| 58 |
- |
|
| 59 |
-//void writebool(bool b, EMUFILE* os) { write32le(b?1:0,os); }
|
|
| 60 |
- |
|
| 61 |
-/*int write64le(uint64_t b, EMUFILE* os) |
|
| 62 |
-{
|
|
| 63 |
- uint8_t s[8]; |
|
| 64 |
- s[0]=(uint8_t)b; |
|
| 65 |
- s[1]=(uint8_t)(b>>8); |
|
| 66 |
- s[2]=(uint8_t)(b>>16); |
|
| 67 |
- s[3]=(uint8_t)(b>>24); |
|
| 68 |
- s[4]=(uint8_t)(b>>32); |
|
| 69 |
- s[5]=(uint8_t)(b>>40); |
|
| 70 |
- s[6]=(uint8_t)(b>>48); |
|
| 71 |
- s[7]=(uint8_t)(b>>56); |
|
| 72 |
- os->fwrite((char*)&s,8); |
|
| 73 |
- return 8; |
|
| 74 |
-}*/ |
|
| 75 |
- |
|
| 76 |
- |
|
| 77 | 28 |
int read32le(uint32_t *Bufo, EMUFILE *fp) |
| 78 | 29 |
{
|
| 79 | 30 |
uint32_t buf; |
| 80 |
- if(fp->_fread(&buf,4)<4) |
|
| 31 |
+ if (fp->_fread(&buf, 4) < 4) |
|
| 81 | 32 |
return 0; |
| 82 | 33 |
#ifdef LOCAL_LE |
| 83 |
- *(uint32_t*)Bufo=buf; |
|
| 34 |
+ *Bufo = buf; |
|
| 84 | 35 |
#else |
| 85 |
- *(uint32_t*)Bufo=((buf&0xFF)<<24)|((buf&0xFF00)<<8)|((buf&0xFF0000)>>8)|((buf&0xFF000000)>>24); |
|
| 36 |
+ *Bufo = ((buf & 0xFF) << 24) | ((buf & 0xFF00) << 8) | ((buf & 0xFF0000) >> 8) | ((buf & 0xFF000000) >> 24); |
|
| 86 | 37 |
#endif |
| 87 | 38 |
return 1; |
| 88 | 39 |
} |
| ... | ... |
@@ -90,10 +41,10 @@ int read32le(uint32_t *Bufo, EMUFILE *fp) |
| 90 | 41 |
int read16le(uint16_t *Bufo, EMUFILE *is) |
| 91 | 42 |
{
|
| 92 | 43 |
uint16_t buf; |
| 93 |
- if(is->_fread((char*)&buf,2) != 2) |
|
| 44 |
+ if (is->_fread(&buf, 2) != 2) |
|
| 94 | 45 |
return 0; |
| 95 | 46 |
#ifdef LOCAL_LE |
| 96 |
- *Bufo=buf; |
|
| 47 |
+ *Bufo = buf; |
|
| 97 | 48 |
#else |
| 98 | 49 |
*Bufo = LE_TO_LOCAL_16(buf); |
| 99 | 50 |
#endif |
| ... | ... |
@@ -103,50 +54,31 @@ int read16le(uint16_t *Bufo, EMUFILE *is) |
| 103 | 54 |
int read64le(uint64_t *Bufo, EMUFILE *is) |
| 104 | 55 |
{
|
| 105 | 56 |
uint64_t buf; |
| 106 |
- if(is->_fread((char*)&buf,8) != 8) |
|
| 57 |
+ if (is->_fread(&buf, 8) != 8) |
|
| 107 | 58 |
return 0; |
| 108 | 59 |
#ifdef LOCAL_LE |
| 109 |
- *Bufo=buf; |
|
| 60 |
+ *Bufo = buf; |
|
| 110 | 61 |
#else |
| 111 | 62 |
*Bufo = LE_TO_LOCAL_64(buf); |
| 112 | 63 |
#endif |
| 113 | 64 |
return 1; |
| 114 | 65 |
} |
| 115 | 66 |
|
| 116 |
-/*static int read32le(uint32_t *Bufo, std::istream *is) |
|
| 117 |
-{
|
|
| 118 |
- uint32_t buf; |
|
| 119 |
- if(is->read((char*)&buf,4).gcount() != 4) |
|
| 120 |
- return 0; |
|
| 121 |
-#ifdef LOCAL_LE |
|
| 122 |
- *(uint32_t*)Bufo=buf; |
|
| 123 |
-#else |
|
| 124 |
- *(uint32_t*)Bufo=((buf&0xFF)<<24)|((buf&0xFF00)<<8)|((buf&0xFF0000)>>8)|((buf&0xFF000000)>>24); |
|
| 125 |
-#endif |
|
| 126 |
- return 1; |
|
| 127 |
-}*/ |
|
| 128 |
- |
|
| 129 |
-int readbool(bool *b, EMUFILE* is) |
|
| 67 |
+int readbool(bool *b, EMUFILE *is) |
|
| 130 | 68 |
{
|
| 131 | 69 |
uint32_t temp = 0; |
| 132 |
- int ret = read32le(&temp,is); |
|
| 133 |
- *b = temp!=0; |
|
| 70 |
+ int ret = read32le(&temp, is); |
|
| 71 |
+ *b = !!temp; |
|
| 134 | 72 |
return ret; |
| 135 | 73 |
} |
| 136 | 74 |
|
| 137 |
-int readbuffer(std::vector<uint8_t> &vec, EMUFILE* is) |
|
| 75 |
+int readbuffer(std::vector<uint8_t> &vec, EMUFILE *is) |
|
| 138 | 76 |
{
|
| 139 | 77 |
uint32_t size; |
| 140 |
- if(read32le(&size,is) != 1) return 0; |
|
| 78 |
+ if (read32le(&size, is) != 1) |
|
| 79 |
+ return 0; |
|
| 141 | 80 |
vec.resize(size); |
| 142 |
- if(size>0) is->fread((char*)&vec[0],size); |
|
| 81 |
+ if (size > 0) |
|
| 82 |
+ is->fread(&vec[0], size); |
|
| 143 | 83 |
return 1; |
| 144 | 84 |
} |
| 145 |
- |
|
| 146 |
-/*int writebuffer(std::vector<uint8_t>& vec, EMUFILE* os) |
|
| 147 |
-{
|
|
| 148 |
- uint32_t size = vec.size(); |
|
| 149 |
- write32le(size,os); |
|
| 150 |
- if(size>0) os->fwrite((char*)&vec[0],size); |
|
| 151 |
- return 1; |
|
| 152 |
-}*/ |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,152 @@ |
| 1 |
+/* |
|
| 2 |
+ Copyright (C) 2006-2009 DeSmuME team |
|
| 3 |
+ |
|
| 4 |
+ This file is free software: you can redistribute it and/or modify |
|
| 5 |
+ it under the terms of the GNU General Public License as published by |
|
| 6 |
+ the Free Software Foundation, either version 2 of the License, or |
|
| 7 |
+ (at your option) any later version. |
|
| 8 |
+ |
|
| 9 |
+ This file is distributed in the hope that it will be useful, |
|
| 10 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 12 |
+ GNU General Public License for more details. |
|
| 13 |
+ |
|
| 14 |
+ You should have received a copy of the GNU General Public License |
|
| 15 |
+ along with the this software. If not, see <http://www.gnu.org/licenses/>. |
|
| 16 |
+*/ |
|
| 17 |
+ |
|
| 18 |
+#include "readwrite.h" |
|
| 19 |
+#include "types.h" |
|
| 20 |
+ |
|
| 21 |
+//well. just for the sake of consistency |
|
| 22 |
+/*int write8le(uint8_t b, EMUFILE*os) |
|
| 23 |
+{
|
|
| 24 |
+ os->fwrite((char*)&b,1); |
|
| 25 |
+ return 1; |
|
| 26 |
+}*/ |
|
| 27 |
+ |
|
| 28 |
+//well. just for the sake of consistency |
|
| 29 |
+int read8le(uint8_t *Bufo, EMUFILE*is) |
|
| 30 |
+{
|
|
| 31 |
+ if(is->_fread((char*)Bufo,1) != 1) |
|
| 32 |
+ return 0; |
|
| 33 |
+ return 1; |
|
| 34 |
+} |
|
| 35 |
+ |
|
| 36 |
+///writes a little endian 16bit value to the specified file |
|
| 37 |
+/*int write16le(uint16_t b, EMUFILE *fp) |
|
| 38 |
+{
|
|
| 39 |
+ uint8_t s[2]; |
|
| 40 |
+ s[0]=(uint8_t)b; |
|
| 41 |
+ s[1]=(uint8_t)(b>>8); |
|
| 42 |
+ fp->fwrite(s,2); |
|
| 43 |
+ return 2; |
|
| 44 |
+}*/ |
|
| 45 |
+ |
|
| 46 |
+ |
|
| 47 |
+///writes a little endian 32bit value to the specified file |
|
| 48 |
+/*int write32le(uint32_t b, EMUFILE *fp) |
|
| 49 |
+{
|
|
| 50 |
+ uint8_t s[4]; |
|
| 51 |
+ s[0]=(uint8_t)b; |
|
| 52 |
+ s[1]=(uint8_t)(b>>8); |
|
| 53 |
+ s[2]=(uint8_t)(b>>16); |
|
| 54 |
+ s[3]=(uint8_t)(b>>24); |
|
| 55 |
+ fp->fwrite(s,4); |
|
| 56 |
+ return 4; |
|
| 57 |
+}*/ |
|
| 58 |
+ |
|
| 59 |
+//void writebool(bool b, EMUFILE* os) { write32le(b?1:0,os); }
|
|
| 60 |
+ |
|
| 61 |
+/*int write64le(uint64_t b, EMUFILE* os) |
|
| 62 |
+{
|
|
| 63 |
+ uint8_t s[8]; |
|
| 64 |
+ s[0]=(uint8_t)b; |
|
| 65 |
+ s[1]=(uint8_t)(b>>8); |
|
| 66 |
+ s[2]=(uint8_t)(b>>16); |
|
| 67 |
+ s[3]=(uint8_t)(b>>24); |
|
| 68 |
+ s[4]=(uint8_t)(b>>32); |
|
| 69 |
+ s[5]=(uint8_t)(b>>40); |
|
| 70 |
+ s[6]=(uint8_t)(b>>48); |
|
| 71 |
+ s[7]=(uint8_t)(b>>56); |
|
| 72 |
+ os->fwrite((char*)&s,8); |
|
| 73 |
+ return 8; |
|
| 74 |
+}*/ |
|
| 75 |
+ |
|
| 76 |
+ |
|
| 77 |
+int read32le(uint32_t *Bufo, EMUFILE *fp) |
|
| 78 |
+{
|
|
| 79 |
+ uint32_t buf; |
|
| 80 |
+ if(fp->_fread(&buf,4)<4) |
|
| 81 |
+ return 0; |
|
| 82 |
+#ifdef LOCAL_LE |
|
| 83 |
+ *(uint32_t*)Bufo=buf; |
|
| 84 |
+#else |
|
| 85 |
+ *(uint32_t*)Bufo=((buf&0xFF)<<24)|((buf&0xFF00)<<8)|((buf&0xFF0000)>>8)|((buf&0xFF000000)>>24); |
|
| 86 |
+#endif |
|
| 87 |
+ return 1; |
|
| 88 |
+} |
|
| 89 |
+ |
|
| 90 |
+int read16le(uint16_t *Bufo, EMUFILE *is) |
|
| 91 |
+{
|
|
| 92 |
+ uint16_t buf; |
|
| 93 |
+ if(is->_fread((char*)&buf,2) != 2) |
|
| 94 |
+ return 0; |
|
| 95 |
+#ifdef LOCAL_LE |
|
| 96 |
+ *Bufo=buf; |
|
| 97 |
+#else |
|
| 98 |
+ *Bufo = LE_TO_LOCAL_16(buf); |
|
| 99 |
+#endif |
|
| 100 |
+ return 1; |
|
| 101 |
+} |
|
| 102 |
+ |
|
| 103 |
+int read64le(uint64_t *Bufo, EMUFILE *is) |
|
| 104 |
+{
|
|
| 105 |
+ uint64_t buf; |
|
| 106 |
+ if(is->_fread((char*)&buf,8) != 8) |
|
| 107 |
+ return 0; |
|
| 108 |
+#ifdef LOCAL_LE |
|
| 109 |
+ *Bufo=buf; |
|
| 110 |
+#else |
|
| 111 |
+ *Bufo = LE_TO_LOCAL_64(buf); |
|
| 112 |
+#endif |
|
| 113 |
+ return 1; |
|
| 114 |
+} |
|
| 115 |
+ |
|
| 116 |
+/*static int read32le(uint32_t *Bufo, std::istream *is) |
|
| 117 |
+{
|
|
| 118 |
+ uint32_t buf; |
|
| 119 |
+ if(is->read((char*)&buf,4).gcount() != 4) |
|
| 120 |
+ return 0; |
|
| 121 |
+#ifdef LOCAL_LE |
|
| 122 |
+ *(uint32_t*)Bufo=buf; |
|
| 123 |
+#else |
|
| 124 |
+ *(uint32_t*)Bufo=((buf&0xFF)<<24)|((buf&0xFF00)<<8)|((buf&0xFF0000)>>8)|((buf&0xFF000000)>>24); |
|
| 125 |
+#endif |
|
| 126 |
+ return 1; |
|
| 127 |
+}*/ |
|
| 128 |
+ |
|
| 129 |
+int readbool(bool *b, EMUFILE* is) |
|
| 130 |
+{
|
|
| 131 |
+ uint32_t temp = 0; |
|
| 132 |
+ int ret = read32le(&temp,is); |
|
| 133 |
+ *b = temp!=0; |
|
| 134 |
+ return ret; |
|
| 135 |
+} |
|
| 136 |
+ |
|
| 137 |
+int readbuffer(std::vector<uint8_t> &vec, EMUFILE* is) |
|
| 138 |
+{
|
|
| 139 |
+ uint32_t size; |
|
| 140 |
+ if(read32le(&size,is) != 1) return 0; |
|
| 141 |
+ vec.resize(size); |
|
| 142 |
+ if(size>0) is->fread((char*)&vec[0],size); |
|
| 143 |
+ return 1; |
|
| 144 |
+} |
|
| 145 |
+ |
|
| 146 |
+/*int writebuffer(std::vector<uint8_t>& vec, EMUFILE* os) |
|
| 147 |
+{
|
|
| 148 |
+ uint32_t size = vec.size(); |
|
| 149 |
+ write32le(size,os); |
|
| 150 |
+ if(size>0) os->fwrite((char*)&vec[0],size); |
|
| 151 |
+ return 1; |
|
| 152 |
+}*/ |