2014-10-08 00:52:15 +00:00
|
|
|
#include "BinaryIO.h"
|
|
|
|
#include <iostream>
|
|
|
|
#include <cassert>
|
|
|
|
|
2014-10-12 17:12:10 +00:00
|
|
|
#include "ResType.h"
|
|
|
|
|
2014-10-08 00:52:15 +00:00
|
|
|
void byte(std::ostream& out, int byte)
|
|
|
|
{
|
2019-08-18 11:21:00 +00:00
|
|
|
out.put((unsigned char)byte);
|
2014-10-08 00:52:15 +00:00
|
|
|
}
|
|
|
|
void word(std::ostream& out, int word)
|
|
|
|
{
|
2019-08-18 11:21:00 +00:00
|
|
|
byte(out,(word >> 8) & 0xFF);
|
|
|
|
byte(out,word & 0xFF);
|
2014-10-08 00:52:15 +00:00
|
|
|
}
|
2014-10-12 17:12:10 +00:00
|
|
|
void ostype(std::ostream& out, ResType type)
|
2014-10-08 00:52:15 +00:00
|
|
|
{
|
2019-08-18 11:21:00 +00:00
|
|
|
longword(out, type);
|
2014-10-08 00:52:15 +00:00
|
|
|
}
|
|
|
|
void longword(std::ostream& out, int longword)
|
|
|
|
{
|
2019-08-18 11:21:00 +00:00
|
|
|
byte(out,(longword >> 24) & 0xFF);
|
|
|
|
byte(out,(longword >> 16) & 0xFF);
|
|
|
|
byte(out,(longword >> 8) & 0xFF);
|
|
|
|
byte(out,longword & 0xFF);
|
2014-10-08 00:52:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int byte(std::istream& in)
|
|
|
|
{
|
2019-08-18 11:21:00 +00:00
|
|
|
return in.get() & 0xFF;
|
2014-10-08 00:52:15 +00:00
|
|
|
}
|
|
|
|
int word(std::istream& in)
|
|
|
|
{
|
2019-08-18 11:21:00 +00:00
|
|
|
int a = byte(in);
|
|
|
|
int b = byte(in);
|
|
|
|
return (a << 8) | b;
|
2014-10-08 00:52:15 +00:00
|
|
|
}
|
2014-10-12 17:12:10 +00:00
|
|
|
ResType ostype(std::istream& in)
|
2014-10-08 00:52:15 +00:00
|
|
|
{
|
2019-08-18 11:21:00 +00:00
|
|
|
return longword(in);
|
2014-10-08 00:52:15 +00:00
|
|
|
}
|
|
|
|
int longword(std::istream& in)
|
|
|
|
{
|
2019-08-18 11:21:00 +00:00
|
|
|
int a = byte(in);
|
|
|
|
int b = byte(in);
|
|
|
|
int c = byte(in);
|
|
|
|
int d = byte(in);
|
|
|
|
return (a << 24) | (b << 16) | (c << 8) | d;
|
2014-10-08 00:52:15 +00:00
|
|
|
}
|
|
|
|
|