fileio.cpp 1.5 KB
Newer Older
1
/* FILEIO.C
2
 * Author : Gerhard Stein (gerstrong@gmail.com)
3 4 5 6 7 8 9
 */

#include <unistd.h>
#include <sys/types.h>
#include <vector>
#include <stdio.h>

Gerhard Stein's avatar
Gerhard Stein committed
10
#include <base/video/CVideoDriver.h>
11
#include "sdl/audio/Audio.h"
12
#include "fileio.h"
13
#include <base/GsLogging.h>
14
#include <base/utils/StringUtils.h>
15 16
#include <base/utils/Debug.h>
#include <base/utils/FindFile.h>
17 18 19 20

#ifdef TARGET_WIN32
#define uint unsigned int
#define ulong unsigned long
21 22 23 24 25
#endif

#ifdef __APPLE__
#define uint unsigned int
#define ulong unsigned long
26 27 28 29 30 31 32 33 34
#endif

unsigned int fgeti(FILE *fp) {
	unsigned int lsb, msb;
	lsb = fgetc(fp);
	msb = fgetc(fp);
	return (msb<<8) | lsb;
}

35
void fputi(unsigned int word, FILE *fp)
36 37 38 39 40 41 42 43 44 45 46 47 48 49
{
	fputc(word&255, fp);
	fputc(word/256, fp);
}

unsigned long fgetl(FILE *fp) {
	unsigned int temp1, temp2, temp3, temp4;
	temp1 = fgetc(fp);
	temp2 = fgetc(fp);
	temp3 = fgetc(fp);
	temp4 = fgetc(fp);
	return (temp4<<24) | (temp3<<16) | (temp2<<8) | temp1;
}

gerstrong's avatar
gerstrong committed
50 51 52 53 54 55 56 57 58
unsigned long fgetl(std::ifstream &file) {
	int temp1, temp2, temp3, temp4;
	temp1 = file.get();
	temp2 = file.get();
	temp3 = file.get();
	temp4 = file.get();
	return (temp4<<24) | (temp3<<16) | (temp2<<8) | temp1;
}

gerstrong's avatar
gerstrong committed
59 60 61 62 63 64 65 66
word fgetw(std::ifstream &file) {
	int temp1, temp2;
	temp1 = file.get();
	temp2 = file.get();
	return (temp2<<8) | temp1;
}


67 68 69 70 71 72 73 74 75 76 77 78 79
void fputl(unsigned long word, FILE *fp)
{
	unsigned long a,b,c,d;
	a=b=c=d = word;
	a &= 0xFF000000; a >>= 24;
	b &= 0x00FF0000; b >>= 16;
	c &= 0x0000FF00; c >>= 8;
	d &= 0x000000FF;
	fputc(d, fp);
	fputc(c, fp);
	fputc(b, fp);
	fputc(a, fp);
}