summaryrefslogtreecommitdiff
path: root/tools/endian.c
diff options
context:
space:
mode:
authorXavi Del Campo <xavi.dcr@tutanota.com>2020-01-31 10:32:23 +0100
committerXavi Del Campo <xavi.dcr@tutanota.com>2020-01-31 10:32:23 +0100
commit7c24e9a9b02b04dcaf9507acb94091ea70a2c02d (patch)
treec28d0748652ad4b4222309e46e6cfc82c0906220 /tools/endian.c
parenta2b7b6bb1cc2f4a3258b7b2dbc92399d151f864d (diff)
downloadpsxsdk-7c24e9a9b02b04dcaf9507acb94091ea70a2c02d.tar.gz
Imported pristine psxsdk-20190410 from official repo
Diffstat (limited to 'tools/endian.c')
-rw-r--r--tools/endian.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/tools/endian.c b/tools/endian.c
new file mode 100644
index 0000000..333390f
--- /dev/null
+++ b/tools/endian.c
@@ -0,0 +1,52 @@
+unsigned short read_le_word(FILE *f)
+{
+ unsigned char c;
+ unsigned short i;
+
+ fread(&c, sizeof(char), 1, f);
+ i = c;
+ fread(&c, sizeof(char), 1, f);
+ i|=(c<<8);
+
+ return i;
+}
+
+unsigned int read_le_dword(FILE *f)
+{
+ unsigned char c;
+ unsigned int i;
+
+ fread(&c, sizeof(char), 1, f);
+ i = c;
+ fread(&c, sizeof(char), 1, f);
+ i|=(c<<8);
+ fread(&c, sizeof(char), 1, f);
+ i|=(c<<16);
+ fread(&c, sizeof(char), 1, f);
+ i|=(c<<24);
+
+ return i;
+}
+
+
+void write_le_word(FILE *f, unsigned short leword)
+{
+ unsigned char c;
+
+ c = leword & 0xff;
+ fwrite(&c, sizeof(char), 1, f);
+ c = leword >> 8;
+ fwrite(&c, sizeof(char), 1, f);
+}
+
+void write_le_dword(FILE *f, unsigned int ledword)
+{
+ unsigned char c;
+ int x;
+
+ for(x = 0; x < 4; x++)
+ {
+ c = (ledword >> (x<<3)) & 0xff;
+ fwrite(&c, sizeof(char), 1, f);
+ }
+}