mirror of
https://github.com/isledecomp/isle-portable.git
synced 2025-09-27 06:32:06 -04:00
Mostly match MxDSBuffer::AllocateBuffer
This commit is contained in:
parent
afd24fbe18
commit
f3c1fc75e2
@ -45,68 +45,65 @@ MxDSBuffer::~MxDSBuffer()
|
|||||||
MxResult MxDSBuffer::AllocateBuffer(MxU32 p_bufferSize, MxDSBufferType p_mode)
|
MxResult MxDSBuffer::AllocateBuffer(MxU32 p_bufferSize, MxDSBufferType p_mode)
|
||||||
{
|
{
|
||||||
MxResult result = FAILURE;
|
MxResult result = FAILURE;
|
||||||
MxU32 i = 0;
|
|
||||||
if (p_mode == MxDSBufferType_Allocate) {
|
|
||||||
m_pBuffer = new MxU8[p_bufferSize];
|
|
||||||
}
|
|
||||||
else if (p_mode == MxDSBufferType_Chunk) {
|
|
||||||
MxStreamer* streamer = Streamer();
|
|
||||||
// I have no clue as to what this does, or even if its correct. Maybe it's related to storing chunks in
|
|
||||||
// MxDiskStreamController?
|
|
||||||
if (p_bufferSize >> 10 == 0x40) {
|
|
||||||
i = 0;
|
|
||||||
while (i < 22) {
|
|
||||||
if ((*(MxU32*) ((streamer->GetSubclass1().GetUnk08() + ((i & 0xffffffe7) >> 3)) & 1 << ((MxU8) i & 0x1f)
|
|
||||||
)) == 0) {
|
|
||||||
MxU32* ptr = (MxU32*) ((streamer->GetSubclass1().GetUnk08() + ((i & 0xffffffe7) >> 3)) &
|
|
||||||
1 << ((MxU8) i & 0x1f));
|
|
||||||
|
|
||||||
// mark it as used?
|
switch (p_mode) {
|
||||||
|
case MxDSBufferType_Allocate:
|
||||||
|
m_pBuffer = new MxU8[p_bufferSize];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MxDSBufferType_Chunk: {
|
||||||
|
MxStreamer* streamer = Streamer();
|
||||||
|
|
||||||
|
switch (p_bufferSize / 1024) {
|
||||||
|
case 0x40: {
|
||||||
|
for (MxU32 i = 0; i < 22; i++) {
|
||||||
|
if (((1 << (i & 0x1f)) & (*(MxU32*) &streamer->GetSubclass1().GetUnk08Ref()[(i & ~0x18u) >> 3])) == 0) {
|
||||||
|
MxU32* ptr = (MxU32*) &streamer->GetSubclass1().GetUnk08Ref()[(i & 0xffffffe7) >> 3];
|
||||||
|
|
||||||
*ptr = *ptr ^ 1 << (i & 0x1f);
|
*ptr = *ptr ^ 1 << (i & 0x1f);
|
||||||
|
|
||||||
m_pBuffer =
|
m_pBuffer =
|
||||||
(MxU8*) (streamer->GetSubclass1().GetSize() * i * 0x400 + streamer->GetSubclass1().GetBuffer());
|
(MxU8*) (streamer->GetSubclass1().GetSize() * i * 0x400 + streamer->GetSubclass1().GetBuffer());
|
||||||
break;
|
goto done;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pBuffer = NULL;
|
m_pBuffer = NULL;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if (p_bufferSize >> 10 == 0x80) {
|
case 0x80: {
|
||||||
i = 0;
|
for (MxU32 i = 0; i < 2; i++) {
|
||||||
// Same thing as above but it uses subclass2
|
if (((1 << (i & 0x1f)) & (*(MxU32*) &streamer->GetSubclass2().GetUnk08Ref()[(i & ~0x18u) >> 3])) == 0) {
|
||||||
while (i < 22) {
|
MxU32* ptr = (MxU32*) &streamer->GetSubclass2().GetUnk08Ref()[(i & 0xffffffe7) >> 3];
|
||||||
if ((*(MxU32*) ((streamer->GetSubclass2().GetUnk08() + ((i & 0xffffffe7) >> 3)) & 1 << ((MxU8) i & 0x1f)
|
|
||||||
)) == 0) {
|
|
||||||
MxU32* ptr = (MxU32*) ((streamer->GetSubclass2().GetUnk08() + ((i & 0xffffffe7) >> 3)) &
|
|
||||||
1 << ((MxU8) i & 0x1f));
|
|
||||||
|
|
||||||
// mark it as used?
|
|
||||||
*ptr = *ptr ^ 1 << (i & 0x1f);
|
*ptr = *ptr ^ 1 << (i & 0x1f);
|
||||||
|
|
||||||
m_pBuffer =
|
m_pBuffer =
|
||||||
(MxU8*) (streamer->GetSubclass2().GetSize() * i * 0x400 + streamer->GetSubclass2().GetBuffer());
|
(MxU8*) (streamer->GetSubclass2().GetSize() * i * 0x400 + streamer->GetSubclass2().GetBuffer());
|
||||||
break;
|
goto done;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pBuffer = NULL;
|
m_pBuffer = NULL;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else {
|
default:
|
||||||
m_pIntoBuffer = NULL;
|
m_pBuffer = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
m_pIntoBuffer = m_pBuffer;
|
m_pIntoBuffer = m_pBuffer;
|
||||||
m_pIntoBuffer2 = m_pBuffer;
|
m_pIntoBuffer2 = m_pBuffer;
|
||||||
|
|
||||||
if (m_pBuffer != NULL) {
|
if (m_pBuffer != NULL) {
|
||||||
m_mode = p_mode;
|
m_mode = p_mode;
|
||||||
m_bytesRemaining = p_bufferSize;
|
m_bytesRemaining = p_bufferSize;
|
||||||
m_writeOffset = p_bufferSize;
|
m_writeOffset = p_bufferSize;
|
||||||
result = SUCCESS;
|
result = SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,8 +218,8 @@ MxResult MxDSBuffer::ParseChunk(
|
|||||||
// FUNCTION: LEGO1 0x100c6d00
|
// FUNCTION: LEGO1 0x100c6d00
|
||||||
MxCore* MxDSBuffer::ReadChunk(MxDSBuffer* p_buffer, MxU32* p_chunkData, MxU16 p_flags)
|
MxCore* MxDSBuffer::ReadChunk(MxDSBuffer* p_buffer, MxU32* p_chunkData, MxU16 p_flags)
|
||||||
{
|
{
|
||||||
// This function reads a chunk. If it is an object, this function returns an MxDSObject. If it is a chunk, returns a
|
// This function reads a chunk. If it is an object, this function returns an MxDSObject. If it is a chunk,
|
||||||
// MxDSChunk.
|
// returns a MxDSChunk.
|
||||||
MxCore* result = NULL;
|
MxCore* result = NULL;
|
||||||
MxU8* dataStart = (MxU8*) p_chunkData + 8;
|
MxU8* dataStart = (MxU8*) p_chunkData + 8;
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ public:
|
|||||||
|
|
||||||
void SetBuffer(undefined* p_buf) { m_buffer = p_buf; }
|
void SetBuffer(undefined* p_buf) { m_buffer = p_buf; }
|
||||||
inline undefined* GetBuffer() const { return m_buffer; }
|
inline undefined* GetBuffer() const { return m_buffer; }
|
||||||
inline undefined4 GetUnk08() const { return m_unk0x08; }
|
inline undefined* GetUnk08Ref() const { return (undefined*) &m_unk0x08; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
undefined* m_buffer;
|
undefined* m_buffer;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user