Almost matched CInputStream

Former-commit-id: 18079ecfee
This commit is contained in:
2022-07-14 20:48:18 -04:00
parent ffd6ba5818
commit 3f96fa4865
9 changed files with 213 additions and 19 deletions

View File

@@ -5,11 +5,11 @@
bool CStopwatch::CSWData::Initialize() {
x0_timerFreq = OS_TIMER_CLOCK;
x8_timerFreqO1M = x0_timerFreq / 1000000ull;
x10_timerPeriod = 1.f / static_cast<float>(x0_timerFreq);
x10_timerPeriod = 1.f / static_cast<f32>(x0_timerFreq);
return true;
}
void CStopwatch::CSWData::Wait(float v) const {
void CStopwatch::CSWData::Wait(f32 v) const {
OSTime duration = OSSecondsToTicks(v);
OSTime end = OSGetTime() + duration;
volatile OSTime current;

View File

@@ -0,0 +1,158 @@
#include "Kyoto_CWD/CInputStream.hpp"
#include "string.h"
#include "Kyoto_CWD/CMemory.hpp"
// TODO move into functions
static u8 lbl_805A94F0;
static s16 lbl_805A94F2;
static s32 lbl_805A94F4;
static s64 lbl_805A94F8;
static f32 lbl_805A9500;
f32 CInputStream::ReadFloat() {
Get(&lbl_805A9500, sizeof(f32));
return lbl_805A9500;
}
s64 CInputStream::ReadLongLong() {
Get(&lbl_805A94F8, sizeof(s64));
return lbl_805A94F8;
}
s32 CInputStream::ReadLong() {
Get(&lbl_805A94F4, sizeof(s32));
return lbl_805A94F4;
}
s16 CInputStream::ReadShort() {
Get(&lbl_805A94F2, sizeof(s16));
return lbl_805A94F2;
}
bool CInputStream::ReadBool() { return static_cast< bool >(ReadChar()); }
u8 CInputStream::ReadChar() {
Get(&lbl_805A94F0, sizeof(u8));
return lbl_805A94F0;
}
// TODO https://decomp.me/scratch/nzMPg
u32 CInputStream::ReadBits(s32 bitCount) {
u32 ret = 0;
u32 bitOffset = x20_bitOffset;
if (bitOffset < bitCount) {
u32 shiftAmt = bitCount - bitOffset;
const u32 mask = bitOffset == 32 ? 0xffffffff : (1 << bitOffset) - 1;
const u32 bitWord = x1c_bitWord;
x20_bitOffset = 0;
const u32 len = (shiftAmt / 8) + static_cast< unsigned int >((shiftAmt % 8) != 0);
Get(&x1c_bitWord, len);
const u32 mask2 = shiftAmt == 32 ? 0xffffffff : (1 << shiftAmt) - 1;
u32 tmp = x20_bitOffset;
x20_bitOffset = len * 8;
ret = ((mask & (bitWord >> (32 - bitOffset))) << shiftAmt) | ((mask2 & (x1c_bitWord >> (32 - shiftAmt))) << tmp);
x20_bitOffset -= shiftAmt;
x1c_bitWord <<= u64(shiftAmt);
} else {
u32 baseVal2 = (bitCount == 0x20 ? 0xffffffff : (1 << bitCount) - 1);
x20_bitOffset -= bitCount;
ret = baseVal2 & (x1c_bitWord >> (32 - bitCount));
x1c_bitWord <<= u64(bitCount);
}
return ret;
}
u32 CInputStream::ReadBytes(void* dest, unsigned long len) {
if (len == 0) {
return 0;
}
if (x4_blockOffset == x8_blockLen) {
GrabAnotherBlock();
}
u32 curLen = len;
u32 curReadLen = 0;
while (curReadLen < len) {
u32 remain = x8_blockLen - x4_blockOffset;
if (remain == 0) {
if (InternalReadNext()) {
continue;
} else {
return curReadLen;
}
}
u32 sz = curLen < remain ? curLen : remain;
memcpy(reinterpret_cast< u8* >(dest) + curReadLen, x10_ptr + x4_blockOffset, sz);
curReadLen += sz;
curLen -= sz;
x4_blockOffset += sz;
}
x18_readPosition += curReadLen;
return curReadLen;
}
void CInputStream::Get(void* dest, unsigned long len) {
u32 remain = len;
u32 readCount = 0;
x20_bitOffset = 0;
while (remain != 0) {
u32 blockLen = x8_blockLen - x4_blockOffset;
blockLen = remain < blockLen ? remain : blockLen;
if (blockLen != 0) {
memcpy(reinterpret_cast< u8* >(dest) + readCount, x10_ptr + x4_blockOffset, blockLen);
remain -= blockLen;
readCount += blockLen;
x4_blockOffset += blockLen;
} else if (remain > 256) {
u32 readLen = Read(reinterpret_cast< u8* >(dest) + readCount, remain);
remain -= readLen;
readCount += readLen;
} else {
GrabAnotherBlock();
}
}
x18_readPosition += readCount;
}
bool CInputStream::GrabAnotherBlock() { return InternalReadNext(); }
bool CInputStream::InternalReadNext() {
x8_blockLen = Read(x10_ptr, xc_len);
x4_blockOffset = 0;
return x8_blockLen != 0;
}
CInputStream::~CInputStream() {
if (x14_owned) {
delete x10_ptr;
}
}
CInputStream::CInputStream(const void* ptr, size_t len, bool owned)
: x4_blockOffset(0)
, x8_blockLen(len)
, xc_len(len)
, x10_ptr(const_cast< u8* >(reinterpret_cast< const u8* >(ptr)))
, x14_owned(owned)
, x18_readPosition(0)
, x1c_bitWord(0)
, x20_bitOffset(0) {}
CInputStream::CInputStream(size_t len)
: x4_blockOffset(0)
, x8_blockLen(0)
, xc_len(len)
, x10_ptr(new u8[len])
, x14_owned(true)
, x18_readPosition(0)
, x1c_bitWord(0)
, x20_bitOffset(0) {}

View File

@@ -3,7 +3,7 @@
#include "Kyoto_CWD/CGraphics.hpp"
// FIXME non-matching https://decomp.me/scratch/8N81d
void CCameraFilterPass::DrawWideScreen(const CColor& color, const CTexture* tex, float lod) {
void CCameraFilterPass::DrawWideScreen(const CColor& color, const CTexture* tex, f32 lod) {
const rstl::pair< CVector2f, CVector2f > vp = gpRender->SetViewportOrtho(true, -4096.f, 4096.f);
f32 left = vp.first.mX;
f32 dVar5 = -((vp.second.mX - vp.first.mX) * 0.0625f * 9.f - (vp.second.mY - vp.first.mY)) * 0.5f;
@@ -20,7 +20,7 @@ void CCameraFilterPass::DrawWideScreen(const CColor& color, const CTexture* tex,
{
CGraphics::StreamBegin(kP_TriangleStrip);
float v = (float)(rand() % 4000) / 16384.f;
f32 v = (f32)(rand() % 4000) / 16384.f;
CGraphics::StreamColor(color);
CGraphics::StreamTexcoord(v, 1.f);
CGraphics::StreamVertex(CVector3f(left - 10.f, 0.f, bottom + (dVar5 * lod)));
@@ -34,7 +34,7 @@ void CCameraFilterPass::DrawWideScreen(const CColor& color, const CTexture* tex,
}
{
CGraphics::StreamBegin(kP_TriangleStrip);
float v = (float)(rand() % 4000) / 16384.f;
f32 v = (f32)(rand() % 4000) / 16384.f;
CGraphics::StreamColor(color);
CGraphics::StreamTexcoord(v, 0.f);
CGraphics::StreamVertex(CVector3f(left - 10.f, 0.f, top));