diff --git a/.vscode/settings.json b/.vscode/settings.json index 82c6ad90..97ba01ec 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,12 +10,6 @@ "editor.tabSize": 2, "files.associations": { "source_location": "cpp", - "console_io.h": "c", - "file_struc.h": "c", - "osreset.h": "c", - "vi.h": "c", - "gxstruct.h": "c", - "vifuncs.h": "c" }, "files.autoSave": "onFocusChange", "files.insertFinalNewline": true, diff --git a/asm/Kyoto/Streams/CMemoryStreamOut.s b/asm/Kyoto/Streams/CMemoryStreamOut.s index 97db2d09..eb453da2 100644 --- a/asm/Kyoto/Streams/CMemoryStreamOut.s +++ b/asm/Kyoto/Streams/CMemoryStreamOut.s @@ -3,8 +3,8 @@ .section .data .balign 8 -.global lbl_803EE3A8 -lbl_803EE3A8: +.global __vt__16CMemoryStreamOut +__vt__16CMemoryStreamOut: # ROM: 0x3EB3A8 .4byte 0 .4byte 0 @@ -56,8 +56,8 @@ __dt__16CMemoryStreamOutFv: /* 8033F2D4 0033C234 93 C1 00 08 */ stw r30, 8(r1) /* 8033F2D8 0033C238 7C 7E 1B 79 */ or. r30, r3, r3 /* 8033F2DC 0033C23C 41 82 00 44 */ beq lbl_8033F320 -/* 8033F2E0 0033C240 3C 80 80 3F */ lis r4, lbl_803EE3A8@ha -/* 8033F2E4 0033C244 38 04 E3 A8 */ addi r0, r4, lbl_803EE3A8@l +/* 8033F2E0 0033C240 3C 80 80 3F */ lis r4, __vt__16CMemoryStreamOut@ha +/* 8033F2E4 0033C244 38 04 E3 A8 */ addi r0, r4, __vt__16CMemoryStreamOut@l /* 8033F2E8 0033C248 90 1E 00 00 */ stw r0, 0(r30) /* 8033F2EC 0033C24C 48 00 02 89 */ bl Flush__13COutputStreamFv /* 8033F2F0 0033C250 88 1E 00 88 */ lbz r0, 0x88(r30) @@ -97,9 +97,9 @@ __ct__16CMemoryStreamOutFPvUlQ216CMemoryStreamOut10EOwnerShipi: /* 8033F364 0033C2C4 93 81 00 10 */ stw r28, 0x10(r1) /* 8033F368 0033C2C8 7C 7C 1B 78 */ mr r28, r3 /* 8033F36C 0033C2CC 48 00 03 91 */ bl __ct__13COutputStreamFi -/* 8033F370 0033C2D0 3C 60 80 3F */ lis r3, lbl_803EE3A8@ha +/* 8033F370 0033C2D0 3C 60 80 3F */ lis r3, __vt__16CMemoryStreamOut@ha /* 8033F374 0033C2D4 7F E0 00 34 */ cntlzw r0, r31 -/* 8033F378 0033C2D8 38 63 E3 A8 */ addi r3, r3, lbl_803EE3A8@l +/* 8033F378 0033C2D8 38 63 E3 A8 */ addi r3, r3, __vt__16CMemoryStreamOut@l /* 8033F37C 0033C2DC 38 80 00 00 */ li r4, 0 /* 8033F380 0033C2E0 90 7C 00 00 */ stw r3, 0(r28) /* 8033F384 0033C2E4 54 00 D9 7E */ srwi r0, r0, 5 diff --git a/asm/Kyoto/Streams/CZipSupport.s b/asm/Kyoto/Streams/CZipSupport.s index 2d3fe529..c7b59530 100644 --- a/asm/Kyoto/Streams/CZipSupport.s +++ b/asm/Kyoto/Streams/CZipSupport.s @@ -38,7 +38,5 @@ Alloc__11CZipSupportFPvUiUi: lbl_803D7A88: # ROM: 0x3D4A88 .asciz "??(??)" - .byte 0x31 - .asciz ".1.3" + .asciz "1.1.3" .balign 4 - diff --git a/configure.py b/configure.py index e8b11465..fcef2f0e 100755 --- a/configure.py +++ b/configure.py @@ -619,10 +619,10 @@ LIBS = [ "Kyoto/rstl/RstlExtras", ["Kyoto/Streams/CInputStream", True], ["Kyoto/Streams/CMemoryInStream", True], - "Kyoto/Streams/CMemoryStreamOut", - "Kyoto/Streams/COutputStream", - "Kyoto/Streams/CZipInputStream", - "Kyoto/Streams/CZipSupport", + ["Kyoto/Streams/CMemoryStreamOut", True], + ["Kyoto/Streams/COutputStream", True], + ["Kyoto/Streams/CZipInputStream", True], + ["Kyoto/Streams/CZipSupport", True], "Kyoto/CSimplePool", "Kyoto/CToken", ["Kyoto/IObj", True], diff --git a/include/Kyoto/Streams/CInputStream.hpp b/include/Kyoto/Streams/CInputStream.hpp index 1cdc31d6..59f6cf50 100644 --- a/include/Kyoto/Streams/CInputStream.hpp +++ b/include/Kyoto/Streams/CInputStream.hpp @@ -14,7 +14,7 @@ public: CInputStream(int len); CInputStream(const void* ptr, int len, bool owned); virtual ~CInputStream(); - virtual uint Read(void* dest, uint len) = 0; + virtual size_t Read(void* dest, size_t len) = 0; float ReadFloat(); u64 ReadLongLong(); @@ -23,7 +23,7 @@ public: bool ReadBool(); uchar ReadChar(); uint ReadBits(uint len); - uint ReadBytes(void* dest, unsigned long len); + size_t ReadBytes(void* dest, size_t len); void Get(void* dest, unsigned long len); template < typename T > diff --git a/include/Kyoto/Streams/CMemoryInStream.hpp b/include/Kyoto/Streams/CMemoryInStream.hpp index 7b42f1c5..aabdcafb 100644 --- a/include/Kyoto/Streams/CMemoryInStream.hpp +++ b/include/Kyoto/Streams/CMemoryInStream.hpp @@ -13,7 +13,7 @@ public: CMemoryInStream(const void* ptr, unsigned long len); CMemoryInStream(const void* ptr, unsigned long len, EOwnerShip ownership); virtual ~CMemoryInStream() override {} - virtual uint Read(void* dest, uint len) override; + virtual size_t Read(void* dest, size_t len) override; }; #endif // _CMEMORYINSTREAM diff --git a/include/Kyoto/Streams/CMemoryStreamOut.hpp b/include/Kyoto/Streams/CMemoryStreamOut.hpp index 0919ce03..0224870f 100644 --- a/include/Kyoto/Streams/CMemoryStreamOut.hpp +++ b/include/Kyoto/Streams/CMemoryStreamOut.hpp @@ -10,14 +10,17 @@ public: kOS_NotOwned, }; - CMemoryStreamOut(void* buffer, size_t len, EOwnerShip ownerShip = kOS_NotOwned, int blockLen = 4096); + CMemoryStreamOut(void* buffer, size_t len, EOwnerShip ownerShip = kOS_NotOwned, + int blockLen = 4096); virtual ~CMemoryStreamOut(); + void Write(const void* ptr, size_t len); + private: - u8* x7c_ptr; - u32 x80_len; - u32 x84_position; - bool x88_owned; + void* mOutPtr; + size_t mOutLength; + size_t mCurrentPosition; + bool mBufferOwned; }; #endif // _CMEMORYSTREAMOUT diff --git a/include/Kyoto/Streams/COutputStream.hpp b/include/Kyoto/Streams/COutputStream.hpp index 6d907015..2b516be9 100644 --- a/include/Kyoto/Streams/COutputStream.hpp +++ b/include/Kyoto/Streams/COutputStream.hpp @@ -11,15 +11,15 @@ void coutput_stream_helper(const T& t, COutputStream& out); class COutputStream { void DoPut(const void* ptr, size_t len); - void Flush(); void DoFlush(); public: COutputStream(int len); virtual ~COutputStream(); - virtual void Write(const void* ptr, u32 len); + virtual void Write(const void* ptr, size_t len) = 0; void WriteBits(uint val, uint bitCount); + void Flush(); void FlushShiftRegister(); void Put(const void* ptr, size_t len) { FlushShiftRegister(); diff --git a/include/Kyoto/Streams/CZipInputStream.hpp b/include/Kyoto/Streams/CZipInputStream.hpp index 1e3b03bf..416abfdb 100644 --- a/include/Kyoto/Streams/CZipInputStream.hpp +++ b/include/Kyoto/Streams/CZipInputStream.hpp @@ -6,17 +6,20 @@ #include "Kyoto/Streams/CInputStream.hpp" #include "rstl/auto_ptr.hpp" +#include "rstl/single_ptr.hpp" + +#include "zlib/zlib.h" class CZipInputStream : public CInputStream { public: CZipInputStream(rstl::auto_ptr< CInputStream > in); ~CZipInputStream() override; - uint Read(void* dest, uint len) override; + size_t Read(void* dest, size_t len) override; private: - uchar* x24_compBuf; - rstl::auto_ptr< CInputStream > x28_stream; - unkptr x30_zstream; + rstl::single_ptr mCompBuf; + rstl::auto_ptr< CInputStream > mStream; + rstl::single_ptr mZStream; }; #endif // _CZIPINPUTSTREAM diff --git a/src/Kyoto/zlib/deflate.h b/include/zlib/deflate.h similarity index 100% rename from src/Kyoto/zlib/deflate.h rename to include/zlib/deflate.h diff --git a/src/Kyoto/zlib/infblock.h b/include/zlib/infblock.h similarity index 100% rename from src/Kyoto/zlib/infblock.h rename to include/zlib/infblock.h diff --git a/src/Kyoto/zlib/infcodes.h b/include/zlib/infcodes.h similarity index 100% rename from src/Kyoto/zlib/infcodes.h rename to include/zlib/infcodes.h diff --git a/src/Kyoto/zlib/inffast.h b/include/zlib/inffast.h similarity index 100% rename from src/Kyoto/zlib/inffast.h rename to include/zlib/inffast.h diff --git a/src/Kyoto/zlib/inffixed.h b/include/zlib/inffixed.h similarity index 100% rename from src/Kyoto/zlib/inffixed.h rename to include/zlib/inffixed.h diff --git a/src/Kyoto/zlib/inftrees.h b/include/zlib/inftrees.h similarity index 100% rename from src/Kyoto/zlib/inftrees.h rename to include/zlib/inftrees.h diff --git a/src/Kyoto/zlib/infutil.h b/include/zlib/infutil.h similarity index 100% rename from src/Kyoto/zlib/infutil.h rename to include/zlib/infutil.h diff --git a/src/Kyoto/zlib/trees.h b/include/zlib/trees.h similarity index 100% rename from src/Kyoto/zlib/trees.h rename to include/zlib/trees.h diff --git a/src/Kyoto/zlib/zconf.h b/include/zlib/zconf.h similarity index 100% rename from src/Kyoto/zlib/zconf.h rename to include/zlib/zconf.h diff --git a/src/Kyoto/zlib/zlib.h b/include/zlib/zlib.h similarity index 99% rename from src/Kyoto/zlib/zlib.h rename to include/zlib/zlib.h index d945d77b..86d8e5cb 100644 --- a/src/Kyoto/zlib/zlib.h +++ b/include/zlib/zlib.h @@ -28,8 +28,8 @@ (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). */ -#ifndef _ZLIB_H -#define _ZLIB_H +#ifndef _ZLIB +#define _ZLIB #include "zconf.h" @@ -890,4 +890,4 @@ ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); } #endif -#endif /* _ZLIB_H */ +#endif // _ZLIB diff --git a/src/Kyoto/zlib/zutil.h b/include/zlib/zutil.h similarity index 100% rename from src/Kyoto/zlib/zutil.h rename to include/zlib/zutil.h diff --git a/obj_files.mk b/obj_files.mk index eaaa1f98..a90f07e8 100644 --- a/obj_files.mk +++ b/obj_files.mk @@ -558,10 +558,10 @@ KYOTO_1 :=\ $(BUILD_DIR)/asm/Kyoto/rstl/RstlExtras.o\ $(BUILD_DIR)/src/Kyoto/Streams/CInputStream.o\ $(BUILD_DIR)/src/Kyoto/Streams/CMemoryInStream.o\ - $(BUILD_DIR)/asm/Kyoto/Streams/CMemoryStreamOut.o\ - $(BUILD_DIR)/asm/Kyoto/Streams/COutputStream.o\ - $(BUILD_DIR)/asm/Kyoto/Streams/CZipInputStream.o\ - $(BUILD_DIR)/asm/Kyoto/Streams/CZipSupport.o\ + $(BUILD_DIR)/src/Kyoto/Streams/CMemoryStreamOut.o\ + $(BUILD_DIR)/src/Kyoto/Streams/COutputStream.o\ + $(BUILD_DIR)/src/Kyoto/Streams/CZipInputStream.o\ + $(BUILD_DIR)/src/Kyoto/Streams/CZipSupport.o\ $(BUILD_DIR)/asm/Kyoto/CSimplePool.o\ $(BUILD_DIR)/asm/Kyoto/CToken.o\ $(BUILD_DIR)/src/Kyoto/IObj.o\ diff --git a/src/Kyoto/Streams/CInputStream.cpp b/src/Kyoto/Streams/CInputStream.cpp index 42aeddeb..969619d7 100644 --- a/src/Kyoto/Streams/CInputStream.cpp +++ b/src/Kyoto/Streams/CInputStream.cpp @@ -65,7 +65,7 @@ void CInputStream::Get(void* dest, unsigned long len) { x18_readPosition += readCount; } -uint CInputStream::ReadBytes(void* dest, unsigned long len) { +size_t CInputStream::ReadBytes(void* dest, size_t len) { if (len == 0) { return 0; } diff --git a/src/Kyoto/Streams/CMemoryInStream.cpp b/src/Kyoto/Streams/CMemoryInStream.cpp index 023a961f..6416c29b 100644 --- a/src/Kyoto/Streams/CMemoryInStream.cpp +++ b/src/Kyoto/Streams/CMemoryInStream.cpp @@ -6,4 +6,4 @@ CMemoryInStream::CMemoryInStream(const void* ptr, unsigned long len, EOwnerShip CMemoryInStream::CMemoryInStream(const void* ptr, unsigned long len) : CInputStream(ptr, len, false) {} -uint CMemoryInStream::Read(void* dest, uint len) { return 0; } +size_t CMemoryInStream::Read(void* dest, size_t len) { return 0; } diff --git a/src/Kyoto/Streams/COutputStream.cpp b/src/Kyoto/Streams/COutputStream.cpp index c3fd330b..9a77887d 100644 --- a/src/Kyoto/Streams/COutputStream.cpp +++ b/src/Kyoto/Streams/COutputStream.cpp @@ -75,32 +75,18 @@ void COutputStream::WriteBits(uint value, uint bitCount) { uint registerOffset = mShiftRegisterOffset; if (registerOffset >= bitCount) { - registerOffset -= bitCount; - uint mask = 0xffffffff; - uint shiftRegister = mShiftRegister; - if (bitCount != 32) { - mask = (1 << bitCount) - 1; - } - mShiftRegister = shiftRegister | ((value & mask) << registerOffset); + int off = registerOffset - bitCount; + mShiftRegister |= ((value & (bitCount != 32 ? (1 << bitCount) - 1 : 0xffffffff)) << off); mShiftRegisterOffset -= bitCount; } else { uint shiftAmt = bitCount - registerOffset; - uint shiftRegister = mShiftRegister; - uint mask = 0xffffffff; - if (registerOffset != 0x20) { - mask = (1 << registerOffset) - 1; - } + uint shiftA = value >> shiftAmt; - shiftRegister |= (value >> shiftAmt); - shiftRegister &= mask; - mShiftRegister = shiftRegister; + mShiftRegister |= (shiftA & (registerOffset != 0x20 ? (1 << registerOffset) - 1 : 0xffffffff)); mShiftRegisterOffset = 0; FlushShiftRegister(); - uint mask2 = 0xffffffff; - if (shiftAmt != 32) { - mask2 = (1 << shiftAmt) - 1; - } - mShiftRegister = (value & mask2) << (32 - shiftAmt); + int shift = (32 - shiftAmt); + mShiftRegister = (value & (shiftAmt != 32 ? (1 << shiftAmt) - 1 : 0xffffffff)) << shift; mShiftRegisterOffset -= shiftAmt; } } diff --git a/src/Kyoto/zlib/adler32.c b/src/Kyoto/zlib/adler32.c index 16cf9a70..55fbcf96 100644 --- a/src/Kyoto/zlib/adler32.c +++ b/src/Kyoto/zlib/adler32.c @@ -5,7 +5,7 @@ /* @(#) $Id$ */ -#include "zlib.h" +#include "zlib/zlib.h" #define BASE 65521L /* largest prime smaller than 65536 */ #define NMAX 5552 diff --git a/src/Kyoto/zlib/infblock.c b/src/Kyoto/zlib/infblock.c index f4920faa..f3bde821 100644 --- a/src/Kyoto/zlib/infblock.c +++ b/src/Kyoto/zlib/infblock.c @@ -3,11 +3,11 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -#include "zutil.h" -#include "infblock.h" -#include "inftrees.h" -#include "infcodes.h" -#include "infutil.h" +#include "zlib/zutil.h" +#include "zlib/infblock.h" +#include "zlib/inftrees.h" +#include "zlib/infcodes.h" +#include "zlib/infutil.h" struct inflate_codes_state {int dummy;}; /* for buggy compilers */ diff --git a/src/Kyoto/zlib/infcodes.c b/src/Kyoto/zlib/infcodes.c index d4e5ee9a..cdca92e8 100644 --- a/src/Kyoto/zlib/infcodes.c +++ b/src/Kyoto/zlib/infcodes.c @@ -3,12 +3,12 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -#include "zutil.h" -#include "inftrees.h" -#include "infblock.h" -#include "infcodes.h" -#include "infutil.h" -#include "inffast.h" +#include "zlib/zutil.h" +#include "zlib/inftrees.h" +#include "zlib/infblock.h" +#include "zlib/infcodes.h" +#include "zlib/infutil.h" +#include "zlib/inffast.h" /* simplify the use of the inflate_huft type with some defines */ #define exop word.what.Exop diff --git a/src/Kyoto/zlib/inffast.c b/src/Kyoto/zlib/inffast.c index 61a78ee9..638875a1 100644 --- a/src/Kyoto/zlib/inffast.c +++ b/src/Kyoto/zlib/inffast.c @@ -3,12 +3,12 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -#include "zutil.h" -#include "inftrees.h" -#include "infblock.h" -#include "infcodes.h" -#include "infutil.h" -#include "inffast.h" +#include "zlib/zutil.h" +#include "zlib/inftrees.h" +#include "zlib/infblock.h" +#include "zlib/infcodes.h" +#include "zlib/infutil.h" +#include "zlib/inffast.h" struct inflate_codes_state {int dummy;}; /* for buggy compilers */ diff --git a/src/Kyoto/zlib/inflate.c b/src/Kyoto/zlib/inflate.c index 015aeb36..3caf8e78 100644 --- a/src/Kyoto/zlib/inflate.c +++ b/src/Kyoto/zlib/inflate.c @@ -3,8 +3,8 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -#include "zutil.h" -#include "infblock.h" +#include "zlib/zutil.h" +#include "zlib/infblock.h" struct inflate_blocks_state {int dummy;}; /* for buggy compilers */ diff --git a/src/Kyoto/zlib/inftrees.c b/src/Kyoto/zlib/inftrees.c index ef1e0b6b..d197d7fa 100644 --- a/src/Kyoto/zlib/inftrees.c +++ b/src/Kyoto/zlib/inftrees.c @@ -3,8 +3,8 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -#include "zutil.h" -#include "inftrees.h" +#include "zlib/zutil.h" +#include "zlib/inftrees.h" #if !defined(BUILDFIXED) && !defined(STDC) # define BUILDFIXED /* non ANSI compilers may not accept inffixed.h */ @@ -392,7 +392,7 @@ local uInt fixed_bd; local inflate_huft *fixed_tl; local inflate_huft *fixed_td; #else -#include "inffixed.h" +#include "zlib/inffixed.h" #endif diff --git a/src/Kyoto/zlib/infutil.c b/src/Kyoto/zlib/infutil.c index 824dab57..ea632bf6 100644 --- a/src/Kyoto/zlib/infutil.c +++ b/src/Kyoto/zlib/infutil.c @@ -3,11 +3,11 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -#include "zutil.h" -#include "infblock.h" -#include "inftrees.h" -#include "infcodes.h" -#include "infutil.h" +#include "zlib/zutil.h" +#include "zlib/infblock.h" +#include "zlib/inftrees.h" +#include "zlib/infcodes.h" +#include "zlib/infutil.h" struct inflate_codes_state {int dummy;}; /* for buggy compilers */ diff --git a/src/Kyoto/zlib/zutil.c b/src/Kyoto/zlib/zutil.c index b3de4e88..0c544e1f 100644 --- a/src/Kyoto/zlib/zutil.c +++ b/src/Kyoto/zlib/zutil.c @@ -5,7 +5,7 @@ /* @(#) $Id$ */ -#include "zutil.h" +#include "zlib/zutil.h" struct internal_state {int dummy;}; /* for buggy compilers */