-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
One of the funcs has a regswap >:(
- Loading branch information
Showing
7 changed files
with
321 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,124 @@ | ||
#ifndef JSUINPUTSTREAM_HPP | ||
#define JSUINPUTSTREAM_HPP | ||
#ifndef JSUINPUTSTREAM_H | ||
#define JSUINPUTSTREAM_H | ||
|
||
#include <types.h> | ||
#include <JSystem/JSupport/JSUIosBase.h> | ||
|
||
class JSUInputStream { | ||
class JSUInputStream : public JSUIosBase { | ||
public: | ||
virtual ~JSUInputStream(); | ||
virtual void getAvailable() = 0; | ||
void read(void*, s32); | ||
virtual void skip(u16); | ||
u32 _000; | ||
u32 _004; | ||
}; | ||
virtual int getAvailable() const = 0; | ||
virtual int skip(s32 amount); | ||
virtual int readData(void* buf, s32 size) = 0; | ||
|
||
int read(void* buf, s32 size); | ||
char* read(char* buf); | ||
char* readString(); | ||
char* readString(char* buf, u16 len); | ||
|
||
int read(s8& p) { return this->read(&p, sizeof(s8)); } /* @fabricated */ | ||
int read(u8& p) { return this->read(&p, sizeof(u8)); } | ||
int read(bool& p) { return this->read(&p, sizeof(bool)); } | ||
int read(s16& p) { return this->read(&p, sizeof(s16)); } /* @fabricated */ | ||
int read(u16& p) { return this->read(&p, sizeof(u16)); } /* @fabricated */ | ||
int read(s32& p) { return this->read(&p, sizeof(s32)); } /* @fabricated */ | ||
int read(u32& p) { return this->read(&p, sizeof(u32)); } | ||
int read(s64& p) { return this->read(&p, sizeof(s64)); } /* @fabricated */ | ||
int read(u64& p) { return this->read(&p, sizeof(u64)); } /* @fabricated */ | ||
|
||
u8 read8b() | ||
{ | ||
u8 b; | ||
this->read(&b, sizeof(u8)); | ||
return b; | ||
} | ||
|
||
u16 read16b() | ||
{ | ||
u16 s; | ||
this->read(&s, sizeof(u16)); | ||
return s; | ||
} | ||
|
||
u32 read32b() | ||
{ | ||
u32 i; | ||
this->read(&i, sizeof(u32)); | ||
return i; | ||
} | ||
|
||
/* @fabricated */ | ||
s8 readS8() | ||
{ | ||
s8 b; | ||
this->read(&b, sizeof(s8)); | ||
return b; | ||
} | ||
|
||
u8 readU8() | ||
{ | ||
u8 b; | ||
this->read(&b, sizeof(u8)); | ||
return b; | ||
} | ||
|
||
s16 readS16() | ||
{ | ||
s16 s; | ||
this->read(&s, sizeof(s16)); | ||
return s; | ||
} | ||
|
||
class JSURandomInputStream : public JSUInputStream { }; | ||
u16 readU16() | ||
{ | ||
u16 s; | ||
this->read(&s, sizeof(u16)); | ||
return s; | ||
} | ||
|
||
s32 readS32() | ||
{ | ||
s32 i; | ||
this->read(&i, sizeof(s32)); | ||
return i; | ||
} | ||
|
||
u32 readU32() | ||
{ | ||
u32 i; | ||
this->read(&i, sizeof(u32)); | ||
return i; | ||
} | ||
|
||
JSUInputStream& operator>>(s8& p) | ||
{ | ||
this->read(&p, sizeof(s8)); | ||
return *this; | ||
} | ||
|
||
JSUInputStream& operator>>(u8& p) | ||
{ | ||
this->read(&p, sizeof(u8)); | ||
return *this; | ||
} | ||
|
||
JSUInputStream& operator>>(s16& p) | ||
{ | ||
this->read(&p, sizeof(s16)); | ||
return *this; | ||
} | ||
|
||
JSUInputStream& operator>>(u16& p) | ||
{ | ||
this->read(&p, sizeof(u16)); | ||
return *this; | ||
} | ||
|
||
JSUInputStream& operator>>(u32& p) | ||
{ | ||
this->read(&p, sizeof(u32)); | ||
return *this; | ||
} | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef JSUIOSBASE_H | ||
#define JSUIOSBASE_H | ||
|
||
#include <types.h> | ||
#include <JSystem/JSupport/JSUStreamEnum.hpp> | ||
|
||
class JSUIosBase { | ||
public: | ||
inline JSUIosBase() | ||
: mState(GOOD) | ||
{ | ||
} | ||
|
||
virtual ~JSUIosBase() { } | ||
|
||
bool isGood() { return !this->mState; } | ||
void clrState(EIoState ioState) { this->mState &= ~ioState; } | ||
void setState(EIoState ioState) { this->mState |= ioState; } | ||
|
||
u8 mState; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef JSU_RANDOM_INPUT_STREAM_H | ||
#define JSU_RANDOM_INPUT_STREAM_H | ||
|
||
#include <types.h> | ||
#include <JSystem/JSupport/JSUInputStream.hpp> | ||
|
||
#ifdef __cplusplus | ||
class JSURandomInputStream : public JSUInputStream { | ||
public: | ||
virtual ~JSURandomInputStream() { } | ||
|
||
virtual int getAvailable() const | ||
{ | ||
return this->getLength() - this->getPosition(); | ||
} | ||
virtual int skip(s32 amount); | ||
virtual int readData(void* buf, s32 count) = 0; | ||
virtual int getLength() const = 0; | ||
virtual int getPosition() const = 0; | ||
virtual int seekPos(s32 offset, JSUStreamSeekFrom from) = 0; | ||
|
||
int align(s32 alignment); | ||
int peek(void* buf, s32 len); | ||
int seek(s32 offset, JSUStreamSeekFrom from); | ||
}; | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef JSU_STREAM_ENUM_H | ||
#define JSU_STREAM_ENUM_H | ||
|
||
enum JSUStreamSeekFrom { SEEK_SET = 0, SEEK_CUR = 1, SEEK_END = 2 }; | ||
|
||
enum EIoState { GOOD = 0, EOF = 1 }; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
#include <JSystem/JSupport/JSUInputStream.hpp> | ||
#include <JSystem/JSupport/JSURandomInputStream.hpp> | ||
#include <macros.h> | ||
|
||
JSUInputStream::~JSUInputStream() { } | ||
|
||
int JSUInputStream::read(void* buf, s32 size) | ||
{ | ||
int len = readData(buf, size); | ||
if (len != size) { | ||
setState(EOF); | ||
} | ||
return len; | ||
} | ||
|
||
char* JSUInputStream::readString() | ||
{ | ||
u16 strLen; | ||
if (readData(&strLen, sizeof(strLen)) != sizeof(strLen)) { | ||
setState(EOF); | ||
return nullptr; | ||
} | ||
|
||
char* buf = new char[strLen + 1]; | ||
|
||
int r; | ||
if (buf == nullptr) { | ||
r = skip(strLen); | ||
} else { | ||
r = readData(buf, strLen); | ||
buf[r] = '\0'; | ||
} | ||
|
||
if (r != strLen) { | ||
setState(EOF); | ||
} | ||
return buf; | ||
} | ||
|
||
char* JSUInputStream::readString(char* buf, u16 len) | ||
{ | ||
u16 strLen; | ||
if (readData(&strLen, sizeof(strLen)) != sizeof(strLen)) { | ||
buf[0] = '\0'; | ||
setState(EOF); | ||
return nullptr; | ||
} | ||
|
||
s32 r = 0; | ||
if (strLen < len) { | ||
r = readData(buf, strLen); | ||
buf[r] = '\0'; | ||
} else { | ||
r = readData(buf, len - 1); | ||
buf[r] = '\0'; | ||
r += skip(strLen - (len - 1)); | ||
} | ||
|
||
if (r != strLen) { | ||
setState(EOF); | ||
} | ||
|
||
return buf; | ||
} | ||
|
||
int JSUInputStream::skip(s32 amount) | ||
{ | ||
u8 _p; | ||
int i; | ||
|
||
for (i = 0; i < amount; i++) { | ||
if (readData(&_p, sizeof(_p)) != sizeof(_p)) { | ||
setState(EOF); | ||
break; | ||
} | ||
} | ||
|
||
return i; | ||
} | ||
|
||
/* JSURandomInputStream */ | ||
|
||
int JSURandomInputStream::skip(s32 amount) | ||
{ | ||
int s = seekPos(amount, SEEK_CUR); | ||
if (s != amount) { | ||
setState(EOF); | ||
} | ||
return s; | ||
} | ||
|
||
int JSURandomInputStream::align(s32 alignment) | ||
{ | ||
int pos = getPosition(); | ||
int aligned = ALIGN_NEXT(pos, alignment); | ||
int change; | ||
// NOTE: this is insane but it matches | ||
if ((change = aligned - pos) != 0) { | ||
int s = seekPos(aligned, SEEK_SET); | ||
if (s != change) { | ||
setState(EOF); | ||
} | ||
} | ||
|
||
return change; | ||
} | ||
|
||
int JSURandomInputStream::peek(void* buf, s32 len) | ||
{ | ||
int r = 0; // NOTE: does not match unless we declare this first | ||
int pos = getPosition(); | ||
// NOTE: this is read, but there's no inlining padding here so the code was | ||
// actually copy-pasted in the original? | ||
r = readData(buf, len); | ||
if (r != len) { | ||
setState(EOF); | ||
} | ||
if (r != 0) { | ||
seekPos(pos, SEEK_SET); | ||
} | ||
|
||
return r; | ||
} | ||
|
||
int JSURandomInputStream::seek(s32 offset, JSUStreamSeekFrom from) | ||
{ | ||
int s = seekPos(offset, from); | ||
clrState(EOF); | ||
return s; | ||
} |