From e0824a15908f4e6ad70d3d0f2364efe043a98c0f Mon Sep 17 00:00:00 2001 From: TakaRikka <38417346+TakaRikka@users.noreply.github.com> Date: Sun, 19 Jan 2025 21:05:53 -0800 Subject: most of JHostIO / m_Do_hostIO done (#2288) --- include/JSystem/JGadget/linklist.h | 28 +-- include/JSystem/JHostIO/JHIComm.h | 100 +++++++++++ include/JSystem/JHostIO/JHICommonMem.h | 77 +++++++++ include/JSystem/JHostIO/JHIMccBuf.h | 77 +++++++++ include/JSystem/JHostIO/JHIRMcc.h | 15 ++ include/JSystem/JHostIO/JHIhioASync.h | 13 ++ include/JSystem/JHostIO/JOREntry.h | 62 +++++++ include/JSystem/JHostIO/JORFile.h | 94 ++++++++++ include/JSystem/JHostIO/JORHostInfo.h | 52 ++++++ include/JSystem/JHostIO/JORMContext.h | 210 +++++++++++++++++++++++ include/JSystem/JHostIO/JORReflexible.h | 53 ++++++ include/JSystem/JHostIO/JORServer.h | 111 ++++++++++++ include/JSystem/JSupport/JSUInputStream.h | 34 ++-- include/JSystem/JSupport/JSUIosBase.h | 13 +- include/JSystem/JSupport/JSUMemoryStream.h | 28 ++- include/JSystem/JSupport/JSUOutputStream.h | 52 ++++++ include/JSystem/JSupport/JSURandomOutputStream.h | 24 +++ include/JSystem/JUtility/JUTAssert.h | 2 +- 18 files changed, 1017 insertions(+), 28 deletions(-) create mode 100644 include/JSystem/JHostIO/JHIComm.h create mode 100644 include/JSystem/JHostIO/JHICommonMem.h create mode 100644 include/JSystem/JHostIO/JHIMccBuf.h create mode 100644 include/JSystem/JHostIO/JHIRMcc.h create mode 100644 include/JSystem/JHostIO/JHIhioASync.h create mode 100644 include/JSystem/JHostIO/JOREntry.h create mode 100644 include/JSystem/JHostIO/JORFile.h create mode 100644 include/JSystem/JHostIO/JORHostInfo.h create mode 100644 include/JSystem/JHostIO/JORMContext.h create mode 100644 include/JSystem/JHostIO/JORReflexible.h create mode 100644 include/JSystem/JHostIO/JORServer.h create mode 100644 include/JSystem/JSupport/JSUOutputStream.h create mode 100644 include/JSystem/JSupport/JSURandomOutputStream.h (limited to 'include/JSystem') diff --git a/include/JSystem/JGadget/linklist.h b/include/JSystem/JGadget/linklist.h index 4fb6a627df..5d0575f0db 100644 --- a/include/JSystem/JGadget/linklist.h +++ b/include/JSystem/JGadget/linklist.h @@ -1,7 +1,7 @@ #ifndef LINKLIST_H #define LINKLIST_H -#include "dolphin/types.h" +#include "JSystem/JUtility/JUTAssert.h" namespace JGadget { struct TLinkListNode { @@ -10,6 +10,8 @@ struct TLinkListNode { mPrev = NULL; } + ~TLinkListNode() {} + TLinkListNode* getNext() const { return mNext; } TLinkListNode* getPrev() const { return mPrev; } @@ -177,21 +179,21 @@ struct TLinkList : public TNodeLinkList { /* 0x00 */ TNodeLinkList::const_iterator base; }; - static const TLinkListNode* Element_toNode(const T* element) { - (void)element; // Debug-only assert - return reinterpret_cast(reinterpret_cast(element) - I); + static TLinkListNode* Element_toNode(T* p) { + JUT_ASSERT(0x2F1, p!=0); + return reinterpret_cast(reinterpret_cast(p) - I); } - static TLinkListNode* Element_toNode(T* element) { - (void)element; // Debug-only assert - return reinterpret_cast(reinterpret_cast(element) - I); + static const TLinkListNode* Element_toNode(const T* p) { + JUT_ASSERT(0x2F6, p!=0); + return reinterpret_cast(reinterpret_cast(p) - I); } - static const T* Element_toValue(const TLinkListNode* node) { - (void)node; // Debug-only assert - return reinterpret_cast(reinterpret_cast(node) + I); + static T* Element_toValue(TLinkListNode* p) { + JUT_ASSERT(0x2FB, p!=0); + return reinterpret_cast(reinterpret_cast(p) + I); } - static T* Element_toValue(TLinkListNode* node) { - (void)node; // Debug-only assert - return reinterpret_cast(reinterpret_cast(node) + I); + static const T* Element_toValue(const TLinkListNode* p) { + JUT_ASSERT(0x300, p!=0); + return reinterpret_cast(reinterpret_cast(p) + I); } iterator Insert(iterator iter, T* element) { diff --git a/include/JSystem/JHostIO/JHIComm.h b/include/JSystem/JHostIO/JHIComm.h new file mode 100644 index 0000000000..30f57ff2de --- /dev/null +++ b/include/JSystem/JHostIO/JHIComm.h @@ -0,0 +1,100 @@ +#ifndef JHICOMM_H +#define JHICOMM_H + +#include "JSystem/JHostIO/JHICommonMem.h" + +class JHICommBufHeader { +public: + void init(); + void init(JHICommonMem*, u32, u32, u32); + int load(); + + u32 getMsgBufSize(); + + /* 0x00 */ JHICommonMem* mp_memBuffer; + /* 0x04 */ u32 field_0x4; + /* 0x08 */ u32 m_msgBufSize; + /* 0x0C */ u32 field_0xc; + /* 0x10 */ u32 field_0x10; + /* 0x14 */ u32 field_0x14; + /* 0x18 */ u32 field_0x18; + /* 0x1C */ u32 field_0x1c; + /* 0x20 */ u32 field_0x20; + /* 0x24 */ u32 field_0x24; + /* 0x28 */ u32 m_alignment; + /* 0x2C */ u32 field_0x2c; +}; + +class JHICommBufWriter { +public: + struct Header : public JHICommBufHeader { + int load(); + int getRemSize(); + void updatePutAdrs(); + u32 getWritebleSize() const; + void alignPutAdrs(); + void addPutAdrs(int); + u32 getPutAdrs() const; + + /* 0x30 */ u8 field_0x30; + /* 0x31 */ u8 field_0x31; + /* 0x32 */ u8 field_0x32; + /* 0x33 */ u8 field_0x33; + /* 0x34 */ u32 field_0x34; + }; + + JHICommBufWriter(u32, u32, u32 alignment); + int writeBegin(); + void writeEnd(); + int write(void*, int); + + /* 0x00 */ Header m_header; + /* 0x38 */ JHIMemBuf* mp_memBuffer; +}; + +class JHICommBufReader { +public: + struct Header : public JHICommBufHeader { + int load(); + void updateGetAdrs(); + u32 getReadableSize() const; + void addGetAdrs(int); + u32 getGetAdrs() const; + void alignGetAdrs(); + int getContSize(); + + /* 0x30 */ u32 field_0x30; + }; + + JHICommBufReader(u32, u32, u32 alignment); + int readBegin(); + void readEnd(); + int read(void*, int); + + u32 available() { return m_header.load() ? 0xFFFFFFFF : m_header.getReadableSize(); } + + /* 0x00 */ Header m_header; + /* 0x34 */ JHIMemBuf* mp_memBuffer; +}; + +struct JHICmnMem { + u32 sendBegin() { return mp_writeBuf->writeBegin(); } + int sendCont(const void* param_0, int param_1) { return mp_writeBuf->write((void*)param_0, param_1); } + void sendEnd() { mp_writeBuf->writeEnd(); } + + void setBuf(JHICommBufReader* pReader, JHICommBufWriter* pWriter) { + mp_readBuf = pReader; + mp_writeBuf = pWriter; + } + + /* 0x0 */ JHICommBufReader* mp_readBuf; + /* 0x4 */ JHICommBufWriter* mp_writeBuf; + /* 0x8 */ u8 field_0x8; +}; + +struct JHIContext { + JHICommBufReader* mp_reader; + JHICommBufWriter* mp_writer; +}; + +#endif /* JHICOMM_H */ diff --git a/include/JSystem/JHostIO/JHICommonMem.h b/include/JSystem/JHostIO/JHICommonMem.h new file mode 100644 index 0000000000..017e8d2669 --- /dev/null +++ b/include/JSystem/JHostIO/JHICommonMem.h @@ -0,0 +1,77 @@ +#ifndef JHICOMMONMEM_H +#define JHICOMMONMEM_H + +#include + +inline u32 JHIhtonl(u32 v) { +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + return v; +#else + // todo +#endif +} + +template +struct JHITag { + JHITag(u32 tag) { + m_tag = tag; + mp_data = NULL; + } + + // NONMATCHING - stack stuff + const void* send(const void* param_0, s32 param_1) { + u32 sp10 = JHIhtonl(m_tag); + u32 sp14 = JHIhtonl(param_1); + + if (mp_data->sendBegin() >= param_1 + 8) { + mp_data->sendCont(&sp10, 8); + mp_data->sendCont(param_0, param_1); + mp_data->sendEnd(); + } + + return param_0; + } + + virtual ~JHITag() {} + virtual void receive(const char*, s32); + + /* 0x4 */ u32 m_tag; + /* 0x8 */ T* mp_data; +}; + +class JHIMemBuf; + +class JHICommonMem { +public: + virtual ~JHICommonMem() {} + virtual int create() = 0; + virtual int open() = 0; + virtual void close() = 0; + virtual u8* getPointer() const = 0; + virtual void readIO(u32 position, u32* out_data) const = 0; + virtual u32 readIO(u32 position) const = 0; + virtual void writeIO(u32 position, u32 data) const = 0; + virtual void writeIO(u32 position, u8* src_data, u32 length) const = 0; + + static JHIMemBuf* Instance(); + static JHIMemBuf* instance; +}; + +class JHIMemBuf : public JHICommonMem { +public: + JHIMemBuf(); + + virtual ~JHIMemBuf(); + virtual int create(); + virtual int open(); + virtual void close(); + virtual u8* getPointer() const; + virtual void readIO(u32 position, u32* out_data) const; + virtual u32 readIO(u32 position) const; + virtual void writeIO(u32 position, u32 data) const; + virtual void writeIO(u32 position, u8* src_data, u32 length) const; + + /* 0x4 */ u8* mp_buffer; +}; + +#endif /* JHICOMMONMEM_H */ diff --git a/include/JSystem/JHostIO/JHIMccBuf.h b/include/JSystem/JHostIO/JHIMccBuf.h new file mode 100644 index 0000000000..7343b88376 --- /dev/null +++ b/include/JSystem/JHostIO/JHIMccBuf.h @@ -0,0 +1,77 @@ +#ifndef JORMCCBUF_H_H +#define JORMCCBUF_H_H + +#include "JSystem/JHostIO/JHIComm.h" +#include "JSystem/JKernel/JKRHeap.h" + +class JHIMccBuf { +public: + JHIMccBuf(u16 channel, u16, u32); + + void setHeaderToBuf(u32 data, u32 position, u16 size); + u32 setDataToBuf(void* pData, u16 size); + int readData(u32 position, u32* pOutData); + int readDataFromBuf(void* pBuf, u32 size); + + int JHIRead(u32 channel, u32 offset, void* buffer, u32 size); + int JHIWrite(u32 channel, u32 offset, void* buffer, u32 size); + + int JHIMCCWrite(u32 channel, u32 offset, void* buffer, u32 size); + int JHIMCCRead(u32 channel, u32 offset, void* buffer, u32 size); + + virtual ~JHIMccBuf(); + virtual void initInstance(u16 channel, u16, u32); + virtual void init(); + virtual void initBuf(); + virtual void enablePort() { mPortEnabled = true; } + virtual void disablePort() { mPortEnabled = false; } + virtual bool isPort() { return mPortEnabled; } + + static u8* mTempBuf; + static u16 mRefCount; + + /* 0x04 */ u32 mTag; + /* 0x08 */ u16 field_0x8; + /* 0x0A */ u16 field_0xa; + /* 0x0C */ u16 field_0xc; + /* 0x0E */ u16 mChannel; + /* 0x10 */ u16 field_0x10; + /* 0x14 */ int mReadOffset; + /* 0x18 */ int mWriteOffset; + /* 0x1C */ int field_0x1c; + /* 0x20 */ u32 field_0x20; + /* 0x24 */ u32 mBeginPos; + /* 0x28 */ u32 mEndPos; + /* 0x2C */ bool mPortEnabled; +}; + +class JHIMccBufReader : public JHIMccBuf { +public: + JHIMccBufReader(u16 channel, u16, u32); + virtual ~JHIMccBufReader(); + + u32 available(); + int readBegin(); + int read(void* pBuf); + void readEnd(); +}; + +class JHIMccBufWriter : public JHIMccBuf { +public: + JHIMccBufWriter(u16 channel, u16, u32); + virtual ~JHIMccBufWriter(); + + int writeBegin(); + int write(void* pBuf, u32 size); + void writeEnd(); +}; + +struct JHIMccContext { + JHIMccBufReader* mp_reader; + JHIMccBufWriter* mp_writer; +}; + +void JHIReport(const char* fmt, ...); +void JHIHalt(const char* fmt, ...); + +#endif /* JORMCCBUF_H_H */ diff --git a/include/JSystem/JHostIO/JHIRMcc.h b/include/JSystem/JHostIO/JHIRMcc.h new file mode 100644 index 0000000000..6b79187c56 --- /dev/null +++ b/include/JSystem/JHostIO/JHIRMcc.h @@ -0,0 +1,15 @@ +#ifndef JHIRMCC_H +#define JHIRMCC_H + +#include + +struct JHIMccContext; + +u32 JHIInitInterface(); +bool JHINegotiateInterface(u32); +JHIMccContext JHIGetHiSpeedContext(); +JHIMccContext JHIGetLowSpeedContext(); +BOOL JHIInitMCC(JHIMccContext* pCtx, bool* param_1); +s32 JHIGetHIO2Handle(); + +#endif /* JHIRMCC_H */ diff --git a/include/JSystem/JHostIO/JHIhioASync.h b/include/JSystem/JHostIO/JHIhioASync.h new file mode 100644 index 0000000000..fa9d90ef71 --- /dev/null +++ b/include/JSystem/JHostIO/JHIhioASync.h @@ -0,0 +1,13 @@ +#ifndef JHIHIOASYNC_H +#define JHIHIOASYNC_H + +#include + +struct JHIContext; + +BOOL JHIInit(u32 enabled); +u32 JHIEventLoop(); +BOOL JOR_CHECKINTERFACE(); +void JHISetBuffer(JHIContext* pCtx); + +#endif /* JHIHIOASYNC_H */ diff --git a/include/JSystem/JHostIO/JOREntry.h b/include/JSystem/JHostIO/JOREntry.h new file mode 100644 index 0000000000..dcd6390012 --- /dev/null +++ b/include/JSystem/JHostIO/JOREntry.h @@ -0,0 +1,62 @@ +#ifndef JORENTRY_H +#define JORENTRY_H + +#include "JSystem/JHostIO/JHIComm.h" + +template +class JHIpvector { +public: + JHIpvector() { m_size = 0; } + + s32 size() const { return m_size; } + T& get(u32 i) const { return m_vector[i]; } + + s32 push_back(T p) { + if (m_size >= I) { + return 0; + } + + m_vector[m_size++] = p; + return 1; + } + + /* 0x00 */ T m_vector[I]; + /* 0x28 */ s32 m_size; +}; + +template +class JHIComPortManager { +public: + JHIComPortManager() { + field_0x10040 = 0; + field_0x10041 = 0; + } + + T& getRefPort() { return port; } + + void addTag(JHITag* pTag) { + field_0x8 = this; + field_0xc.push_back(pTag); + } + + static JHIComPortManager* create() { + if (instance == NULL) { + instance = new JHIComPortManager(); + } + + return instance; + } + + static JHIComPortManager* instance; + + /* 0x00000 */ T port; + /* 0x00008 */ JHIComPortManager* field_0x8; + /* 0x0000C */ JHIpvector*, 10> field_0xc; + /* 0x00038 */ u8 field_0x38[0x10000]; + /* 0x10038 */ u32 field_0x10038; + /* 0x1003C */ u32 field_0x1003c; + /* 0x10040 */ u8 field_0x10040; + /* 0x10041 */ u8 field_0x10041; +}; + +#endif /* JORENTRY_H */ diff --git a/include/JSystem/JHostIO/JORFile.h b/include/JSystem/JHostIO/JORFile.h new file mode 100644 index 0000000000..5d06259a48 --- /dev/null +++ b/include/JSystem/JHostIO/JORFile.h @@ -0,0 +1,94 @@ +#ifndef JORFILE_H +#define JORFILE_H + +#include "JSystem/JSupport/JSUMemoryStream.h" + +class JORDir { +public: + void setStatus(u32 status) { m_status = status; } + void setFindHandle(u32 handle) { m_findHandle = handle; } + void setFileAttribute(u32 attribute) { m_fileAttribute = attribute; } + void setLowDateTime(u32 time) { m_lowDateTime = time; } + void setHighDateTime(u32 time) { m_highDateTime = time; } + + char* getFilename() { return m_filename; } + + /* 0x00 */ u32 m_status; + /* 0x04 */ u32 m_findHandle; + /* 0x08 */ u32 m_fileAttribute; + /* 0x0C */ u32 m_lowDateTime; + /* 0x10 */ u32 m_highDateTime; + /* 0x14 */ char* m_filename; +}; + +class JORFile { +public: + enum ECommand { + ECommand_OPEN, + ECommand_CLOSE, + ECommand_READ, + ECommand_WRITE, + }; + + enum EStatus { + EStatus_WAIT, + EStatus_READ_BEGIN, + EStatus_READ_DATA, + EStatus_READ_END, + EStatus_WRITE_BEGIN, + EStatus_WRITE_DATA, + EStatus_WRITE_END, + }; + + enum EFlags { + EFlags_READ = (1 << 0), + EFlags_WRITE = (1 << 1), + EFlags_DEFAULT_EXT = (1 << 4), + EFlags_UNK_0x20 = (1 << 5), + EFlags_HAS_SUFFIX = (1 << 6), + }; + + JORFile(); + + int countMaskSize(const char* mask); + void setBuffer(void* buffer, s32 length); + + char* getFilename() { return mFilename; } + u32 getHandle() const { return mHandle; } + + JSUMemoryOutputStream& getDataStream() { return mDataStream; } + + void setHandle(u32 handle) { mHandle = handle; } + void setFileLength(s32 length) { mFileLength = length; } + void setNFileName(u16 length) { mNFileName = length; } + void setNBaseName(u16 length) { mNBaseName = length; } + void setNExtensionName(u16 length) { mNExtensionName = length; } + void setStatus(s32 status) { mStatus = status; } + + virtual ~JORFile() {} + virtual int open(const char* path, u32 flags, const char* extMask, const char* defaultExt, const char*, const char* fileSuffix); + virtual int open(u32 flags, const char* extMask, const char* defaultExt, const char*, const char* fileSuffix); + virtual void close(); + virtual s32 readData(void* buffer, s32 length); + virtual s32 writeData(const void* buffer, s32 length); + virtual void readBegin_(s32 len); + virtual void readLoop_(); + virtual void writeBegin_(s32 len); + virtual void writeLoop_(const void* pBuffer, s32 size, u32 pos); + virtual void writeDone_(s32 len); + virtual void waitMessage_(); + virtual s32 getFileSize() const; + + /* 0x04 */ u32 mHandle; + /* 0x08 */ s32 mFileLength; + /* 0x0C */ s32 mStatus; + /* 0x10 */ u16 mNFileName; + /* 0x12 */ u16 mNBaseName; + /* 0x14 */ u16 mNExtensionName; + /* 0x16 */ u16 mFlags; + /* 0x18 */ int field_0x18; + /* 0x1C */ JSUMemoryOutputStream mDataStream; + /* 0x30 */ char mFilename[8]; +}; + +#endif /* JORFILE_H */ diff --git a/include/JSystem/JHostIO/JORHostInfo.h b/include/JSystem/JHostIO/JORHostInfo.h new file mode 100644 index 0000000000..2eb43c5184 --- /dev/null +++ b/include/JSystem/JHostIO/JORHostInfo.h @@ -0,0 +1,52 @@ +#ifndef JORHOSTINFO_H +#define JORHOSTINFO_H + +#include + +#define HOSTINFO_REQ_COMPUTER_NAME 0 +#define HOSTINFO_REQ_USERNAME 1 +#define HOSTINFO_REQ_LOCAL_TIME 2 + +class JORHostInfo { +public: + /* 0x0 */ s32 m_result; + + void setResult(s32 result) { m_result = result; } + s32 getResult() { return m_result; } + + JORHostInfo() { m_result = 0; } + virtual ~JORHostInfo() {} +}; + +class JORHostInfo_String : public JORHostInfo { +public: + virtual ~JORHostInfo_String() {} + + JORHostInfo_String() { + m_stringBuffer = NULL; + m_bufferSize = 0; + } + + void setStringBuffer(char* buffer) { m_stringBuffer = buffer; } + void setBufferSize(u32 size) { m_bufferSize = size; } + char* getString() { return m_stringBuffer; } + u32 getBufferSize() { return m_bufferSize; } + + /* 0x8 */ char* m_stringBuffer; + /* 0xC */ u32 m_bufferSize; +}; + +class JORHostInfo_CalendarTime : public JORHostInfo { +public: + JORHostInfo_CalendarTime() { m_calendarTimeBuffer = NULL; } + virtual ~JORHostInfo_CalendarTime() {} + + void setCalendarTimeBuffer(OSCalendarTime* pCalendarTime) { m_calendarTimeBuffer = pCalendarTime; } + OSCalendarTime* getCalendarTime() { return m_calendarTimeBuffer; } + + /* 0x8 */ OSCalendarTime* m_calendarTimeBuffer; +}; + +BOOL JORGetYearDays(int year, int mon); + +#endif /* JORHOSTINFO_H */ diff --git a/include/JSystem/JHostIO/JORMContext.h b/include/JSystem/JHostIO/JORMContext.h new file mode 100644 index 0000000000..68f4135c59 --- /dev/null +++ b/include/JSystem/JHostIO/JORMContext.h @@ -0,0 +1,210 @@ +#ifndef JORMCONTEXT_H +#define JORMCONTEXT_H + +#include +#include "JSystem/JSupport/JSUMemoryStream.h" +#include "JSystem/JHostIO/JORReflexible.h" + +#define MCTX_MSG_RESET 0 +#define MCTX_MSG_GET_ROOT_OBJ 2 +#define MCTX_MSG_GEN_OBJ_INFO 4 +#define MCTX_MSG_INVALID_NODE 5 +#define MCTX_MSG_UPDATE_NODE 8 +#define MCTX_MSG_FIO 9 +#define MCTX_MSG_OPEN_MESSAGE_BOX 10 +#define MCTX_MSG_START_NODE 12 +#define MCTX_MSG_GET_HOST_INFO 14 +#define MCTX_MSG_SHELL_EXEC 15 + +#define MCTX_COMMAND_START_NODE (u32)0 +#define MCTX_COMMAND_END_NODE (u32)1 +#define MCTX_COMMAND_GEN_CONTROL (u32)2 +#define MCTX_COMMAND_GEN_NODE (u32)3 +#define MCTX_COMMAND_START_SELECTOR (u32)4 +#define MCTX_COMMAND_END_SELECTOR (u32)5 +#define MCTX_COMMAND_SELECTOR_ITEM (u32)6 +#define MCTX_COMMAND_INVALID_NODE (u32)7 +#define MCTX_COMMAND_UPDATE_CONTROL (u32)8 + +#define DEFINE_GEN_CHECKBOX(T, kind) \ + void genCheckBox(const char* label, T* pSrc, T mask, u32 style, JOREventListener* pListener, \ + u16 posX, u16 posY, u16 width, u16 height) { \ + genCheckBoxSub(kind, label, (u32)pSrc, style, *pSrc, mask, pListener, posX, posY, width, \ + height); \ + } + +#define DEFINE_GEN_CHECKBOX_ID(T, kind) \ + void genCheckBoxID(const char* label, u32 id, T mask, T initValue, u32 style, \ + JOREventListener* pListener, u16 posX, u16 posY, u16 width, u16 height) { \ + genCheckBoxSub(kind, label, id, style, initValue, mask, pListener, posX, posY, width, \ + height); \ + } + +#define DEFINE_GEN_SLIDER(T, kind) \ + void genSlider(const char* label, T* pSrc, T rangeMin, T rangeMax, u32 style, \ + JOREventListener* pListener, u16 posX, u16 posY, u16 width, u16 height) { \ + genSliderSub(kind, label, (u32)pSrc, style, *pSrc, rangeMin, rangeMax, pListener, posX, \ + posY, width, height); \ + } + +#define DEFINE_GEN_SLIDER_ID(T, kind) \ + void genSliderID(const char* label, u32 id, T data, T rangeMin, T rangeMax, u32 style, \ + JOREventListener* pListener, u16 posX, u16 posY, u16 width, u16 height) { \ + genSliderSub(kind, label, id, style, data, rangeMin, rangeMax, pListener, posX, posY, \ + width, height); \ + } + +namespace jhostio { + enum EKind { + EKind_8B = 0x08, + EKind_16B = 0x10, + EKind_32B = 0x20, + }; + + inline u32 GetEKindSize(u32 param_0) { return param_0 & 0xFF; } +} + +class JORReflexible; +class JORFile; +class JOREventListener; +class JORHostInfo; + +class JORMContext { +public: + JORMContext() : mOutputStream(this, 0x10000) {} + + void bufInit() { mOutputStream.seek(0, JSUStreamSeekFrom_SET); } + void putMsgID(u32 msgID) { mOutputStream << msgID; } + s32 msgSize() { return mOutputStream.getPosition(); } + u8* msgPtr() { return mBuffer; } + + void openFile(JORFile* pFile, u32 flags, const char* path, const char* extMask, u32 maskSize, + const char* defaultExt, const char* param_6, const char* fileSuffix); + void closeFile(JORFile* pFile); + void readBegin(JORFile* pFile, s32 size); + void readData(JORFile* pFile); + void writeBegin(JORFile* pFile, u16 flags, u32 size); + void writeData(JORFile* pFile, const void* pBuffer, s32 size, u32 position); + void writeDone(JORFile* pFile, u32 size); + void sendShellExecuteRequest(void*, const char*, const char*, const char*, const char*, int); + void sendHostInfoRequest(u32 requestType, JORHostInfo* pHostInfo); + void endNode(); + + void genRootNode(const char* label, JORReflexible* obj, u32 param_2, u32 param_3) { + genNodeSub(label, obj, param_2, param_3); + } + + void genNode(const char* label, JORReflexible* obj, u32 param_2, u32 param_3) { + mOutputStream << MCTX_COMMAND_GEN_NODE; + genNodeSub(label, obj, param_2, param_3); + } + + void genNode(JORReflexible* parentObj, u32 param_1, const char* label, JORReflexible* obj, + u32 param_4, u32 param_5) { + ASSERTMSGLINE(97, parentObj != NULL, + "JORMContext: genNode must specify strict( not null node ) parent object\n"); + + mOutputStream << MCTX_COMMAND_GEN_NODE; + mOutputStream << param_1; + putNode(parentObj); + genNodeSub(label, obj, param_4, param_5); + } + + void startNode(JORReflexible* parentObj, u32 param_1, const char* label, JORReflexible* obj, + u32 param_4, u32 param_5) { + ASSERTMSGLINE( + 113, parentObj != NULL, + "JORMContext: startNode must specify strict( not null node ) parent object\n"); + + mOutputStream << MCTX_COMMAND_START_NODE; + mOutputStream << param_1; + putNode(parentObj); + genNodeSub(label, obj, param_4, param_5); + } + + void startNode(const char* label, JORReflexible* obj, u32 param_2, u32 param_3) { + mOutputStream << MCTX_COMMAND_START_NODE; + genNodeSub(label, obj, param_2, param_3); + } + + void genNodeSub(const char* label, JORReflexible* i_node, u32, u32); + void putNode(JORReflexible* obj); + void invalidNode(JORReflexible* i_node, u32); + + void genControl(u32 type, u32 kind, const char* label, u32 style, u32 id, + JOREventListener* pListener, u32 initValue); + + void genSliderSub(u32 kind, const char* label, u32 id, u32 style, s32 initValue, s32 rangeMin, + s32 rangeMax, JOREventListener* pListener, u16 posX, u16 posY, u16 width, + u16 height); + + void genCheckBoxSub(u32 kind, const char* label, u32 id, u32 style, u16 initValue, u16 mask, + JOREventListener* pListener, u16 posX, u16 posY, u16 width, u16 height); + + void startSelectorSub(u32 type, u32 kind, const char* label, u32 id, u32 style, s32 initValue, + JOREventListener* pListener, u16 posX, u16 posY, u16 width, u16 height); + + void endSelectorSub(); + + void genSelectorItemSub(const char* label, s32 itemNo, u32 param_2, u16 posX, u16 posY, + u16 width, u16 height); + + void genButton(const char* label, u32 id, u32 style, JOREventListener* pListener, u16 posX, + u16 posY, u16 width, u16 height); + + void genLabel(const char* label, u32 id, u32 style, JOREventListener* pListener, u16 posX, + u16 posY, u16 width, u16 height); + + void genGroupBox(const char* label, u32 id, u32 style, JOREventListener* pListener, u16 posX, + u16 posY, u16 width, u16 height); + + void genEditBoxID(const char* label, u32 id, const char* string, u16 length, u32 style, + JOREventListener* pListener, u16 posX, u16 posY, u16 width, u16 height); + + /** + * === CHECKBOX === + */ + DEFINE_GEN_CHECKBOX(u8, 0x100 | jhostio::EKind_8B) + DEFINE_GEN_CHECKBOX(u16, 0x100 | jhostio::EKind_16B) + + DEFINE_GEN_CHECKBOX_ID(u16, JORPropertyEvent::EKind_ValueID | 0x100) + + /** + * === SLIDER === + */ + DEFINE_GEN_SLIDER(u8, 0x100 | jhostio::EKind_8B) + DEFINE_GEN_SLIDER(s16, jhostio::EKind_16B) + DEFINE_GEN_SLIDER(f32, JORPropertyEvent::EKind_FloatValue | jhostio::EKind_32B) + DEFINE_GEN_SLIDER(s32, jhostio::EKind_32B) + + DEFINE_GEN_SLIDER_ID(f64, JORPropertyEvent::EKind_ValueID | JORPropertyEvent::EKind_FloatValue) + DEFINE_GEN_SLIDER_ID(int, JORPropertyEvent::EKind_ValueID) + + void genComboBoxItem(const char* label, s32 itemNo) { + genSelectorItemSub(label, itemNo, 0, 0, 0, 0, 0); + } + + void genRadioButtonItem(const char* label, s32 itemNo, u32 param_2, u16 posX, u16 posY, + u16 width, u16 height) { + genSelectorItemSub(label, itemNo, param_2, posX, posY, width, height); + } + + void updateControl(u32 mode, u32 id, u32 param_2); + void updateControl(u32 mode, u32 id, const char* param_2); + void updateSliderSub(u32 mode, u32 id, s32 value, s32 rangeMin, s32 rangeMax, + u32 param_5); + void updateCheckBoxSub(u32 mode, u32 id, u16 value, u16 mask, u32 param_4); + void updateSelectorSub(u32 mode, u32 id, s32 value, u32 param_3); + void updateEditBoxID(u32 mode, u32 id, const char* string, u32 param_3, u16 length); + void editComboBoxItem(u32 param_0, u32 param_1, const char* param_2, s32 param_3, u32 param_4); + + void openMessageBox(void* param_0, u32 style, const char* message, const char* title); + + /* 0x00000 */ u8 mBuffer[0x10000]; + /* 0x10000 */ JSUMemoryOutputStream mOutputStream; +}; + +JORMContext* attachJORMContext(u32); +void releaseJORMContext(JORMContext*); + +#endif /* JORMCONTEXT_H */ diff --git a/include/JSystem/JHostIO/JORReflexible.h b/include/JSystem/JHostIO/JORReflexible.h new file mode 100644 index 0000000000..3a066f70ad --- /dev/null +++ b/include/JSystem/JHostIO/JORReflexible.h @@ -0,0 +1,53 @@ +#ifndef JORREFLEXIBLE_H +#define JORREFLEXIBLE_H + +#include + +class JORReflexible; + +struct JOREvent {}; + +struct JORPropertyEvent : JOREvent { + enum EKind { + EKind_HasListener = (1 << 30), + EKind_ValueID = (1 << 29), + EKind_FloatValue = (1 << 9), + }; + + /* 0x00 */ u8 field_0x0[0x4 - 0x0]; + /* 0x04 */ u32 type; + /* 0x08 */ u32 kind; + /* 0x0C */ char* field_0xc; + /* 0x10 */ JORReflexible* field_0x10; // ? + /* 0x14 */ u32 field_0x14; + union { + u32 U32; + u16 U16[2]; + } + /* 0x18 */ field_0x18; +}; + +struct JORGenEvent : JOREvent {}; +struct JORNodeEvent : JOREvent {}; + +struct JORMContext; +struct JORServer; + +class JOREventListener { +public: + virtual void listenPropertyEvent(const JORPropertyEvent*) = 0; +}; + +class JORReflexible : public JOREventListener { +public: + JORReflexible(); + static JORServer* getJORServer(); + + virtual void listenPropertyEvent(const JORPropertyEvent*); + virtual void listen(u32, const JOREvent*); + virtual void genObjectInfo(const JORGenEvent*); + virtual void genMessage(JORMContext*) = 0; + virtual void listenNodeEvent(const JORNodeEvent*); +}; + +#endif /* JORREFLEXIBLE_H */ diff --git a/include/JSystem/JHostIO/JORServer.h b/include/JSystem/JHostIO/JORServer.h new file mode 100644 index 0000000000..3f28539e45 --- /dev/null +++ b/include/JSystem/JHostIO/JORServer.h @@ -0,0 +1,111 @@ +#ifndef JORSERVER_H +#define JORSERVER_H + +#include "JSystem/JHostIO/JORMContext.h" +#include "JSystem/JHostIO/JHIComm.h" +#include "JSystem/JGadget/linklist.h" +#include "JSystem/JUtility/JUTAssert.h" + +void JOR_MESSAGELOOP(); +u32 JORMessageBox(const char* message, const char* title, u32 style); + +struct JOREventCallbackListNode { + JOREventCallbackListNode(u32, u32, bool); + void JORAppend(); + void JORRemove(); + + virtual int JORAct(u32, const char*); + virtual ~JOREventCallbackListNode(); + + /* 0x04 */ JGadget::TLinkListNode m_node; + /* 0x0C */ u32 field_0xc; + /* 0x10 */ u32 field_0x10; +}; + +class JORFile; +class JORDir; +class JORHostInfo_String; +class JORHostInfo_CalendarTime; + +class JORServer : public JHITag { +public: + enum ECommand { + ECommand_GetRootObj = 1, + ECommand_GenObjInfo = 3, + ECommand_NodeEvent = 6, + ECommand_PropertyEvent = 7, + ECommand_FIO = 9, + ECommand_ReadResultS32 = 10, + ECommand_ReadOrEvent = 11, + ECommand_DIR = 13, + ECommand_HostInfo = 14, + ECommand_ReadResultU32 = 15, + }; + + JORServer() : JHITag('ORef'), + m_event(false), + m_eventDone(true), + m_eventFunc(NULL), + m_isEventCallbackListEnabled(false) + {} + + static JORServer* create(); + void receive(const char*, s32); + + JORMContext* attachMCTX(u32); + void releaseMCTX(JORMContext*); + + void appendEventCallbackListNode(JOREventCallbackListNode* p) { + JUT_ASSERT(256, p!=0); + m_eventCallbackList.Push_front(p); + } + + void removeEventCallbackListNode(JOREventCallbackListNode* p) { + JUT_ASSERT(257, p!=0); + m_eventCallbackList.Remove(p); + } + + static void defSetVal(void*, u32, s32); + static void defSetBitVal(void*, u32, u16, u16); + + void fio_openFile_(JSUMemoryInputStream&); + void fio_closeFile_(JSUMemoryInputStream&); + void fio_readData_(JSUMemoryInputStream&); + void fio_writeData_(JSUMemoryInputStream&); + void fio_dispatchMessage_(JSUMemoryInputStream&); + + void dir_findFirstFile_(JSUMemoryInputStream&, JORDir*); + void dir_findNextFile_(JSUMemoryInputStream&, JORDir*); + void dir_browseForFolder_(JSUMemoryInputStream&, JORDir*); + + void readResultS32_(JSUMemoryInputStream&); + void readOrEvent_(JSUMemoryInputStream&); + void dir_dispatchMessage_(JSUMemoryInputStream&); + void hostinfo_dispatchMessage_(JSUMemoryInputStream&); + void hostinfo_recvString_(JSUMemoryInputStream&, JORHostInfo_String*); + void hostinfo_localTime_(JSUMemoryInputStream&, JORHostInfo_CalendarTime*); + void readResultU32_(JSUMemoryInputStream&); + + void sendReset(); + + void setRootNode(const char*, JORReflexible*, u32, u32); + void doneEvent(); + + static JORServer* getInstance() { return instance; } + static JORServer* instance; + + /* 0x0000C */ JORMContext m_context; + /* 0x10020 */ JORReflexible* mp_rootObj; + /* 0x10024 */ char m_rootName[64]; + /* 0x10064 */ u32 field_0x10064; + /* 0x10068 */ u32 field_0x10068; + /* 0x1006C */ bool m_event; + /* 0x1006D */ bool m_eventDone; + /* 0x10070 */ u32 m_eventNum; + /* 0x10074 */ char m_eventName[0x1000]; + /* 0x11074 */ void* m_eventFunc; + /* 0x11078 */ bool m_isEventCallbackListEnabled; + /* 0x1107C */ JGadget::TLinkList m_eventCallbackList; +}; + +#endif /* JORSERVER_H */ diff --git a/include/JSystem/JSupport/JSUInputStream.h b/include/JSystem/JSupport/JSUInputStream.h index 411f8c02ad..dc35d5ab91 100644 --- a/include/JSystem/JSupport/JSUInputStream.h +++ b/include/JSystem/JSupport/JSUInputStream.h @@ -3,12 +3,6 @@ #include "JSystem/JSupport/JSUIosBase.h" -enum JSUStreamSeekFrom { - JSUStreamSeekFrom_SET = 0, // absolute - JSUStreamSeekFrom_CUR = 1, // relative - JSUStreamSeekFrom_END = 2, // relative to end -}; - /** * @ingroup jsystem-jsupport * @@ -70,18 +64,38 @@ public: return val; } - JSUInputStream* operator>>(u8& dest) { + JSUInputStream& operator>>(u32& dest) { + read(&dest, 4); + return *this; + } + + JSUInputStream& operator>>(u16& dest) { + read(&dest, 2); + return *this; + } + + JSUInputStream& operator>>(u8& dest) { read(&dest, 1); - return this; + return *this; } - JSUInputStream* operator>>(s16& dest) { + JSUInputStream& operator>>(s16& dest) { read(&dest, 2); - return this; + return *this; + } + + JSUInputStream& operator>>(char* dest) { + read(dest); + return *this; + } + + s32 read(u32& param_0) { + return read(¶m_0, 4); } // TODO: return value probably wrong /* 802DC298 */ s32 read(void*, s32); + char* read(char*); }; // Size = 0x8 // move? diff --git a/include/JSystem/JSupport/JSUIosBase.h b/include/JSystem/JSupport/JSUIosBase.h index 761c1d61df..5164cc5a2a 100644 --- a/include/JSystem/JSupport/JSUIosBase.h +++ b/include/JSystem/JSupport/JSUIosBase.h @@ -3,8 +3,10 @@ #include "dolphin/types.h" -enum EIoState { - IOS_STATE_1 = 1, +enum JSUStreamSeekFrom { + JSUStreamSeekFrom_SET = 0, // absolute + JSUStreamSeekFrom_CUR = 1, // relative + JSUStreamSeekFrom_END = 2, // relative to end }; /** @@ -13,6 +15,11 @@ enum EIoState { */ class JSUIosBase { public: + enum EIoState { + IOS_STATE_1 = 1, + IOS_STATE_2 = 2, + }; + JSUIosBase() { mState = false; } virtual ~JSUIosBase() {} @@ -22,7 +29,7 @@ public: void setState(EIoState state) { mState |= state; } private: - u8 mState; + bool mState; }; // Size = 0x8 #endif diff --git a/include/JSystem/JSupport/JSUMemoryStream.h b/include/JSystem/JSupport/JSUMemoryStream.h index 0ef4703555..51b6fb601a 100644 --- a/include/JSystem/JSupport/JSUMemoryStream.h +++ b/include/JSystem/JSupport/JSUMemoryStream.h @@ -2,6 +2,7 @@ #define JSUMEMORYSTREAM_H #include "JSystem/JSupport/JSURandomInputStream.h" +#include "JSystem/JSupport/JSURandomOutputStream.h" /** * @ingroup jsystem-jsupport @@ -9,7 +10,7 @@ */ class JSUMemoryInputStream : public JSURandomInputStream { public: - JSUMemoryInputStream(const void* res, u32 size) { setBuffer(res, size); } + JSUMemoryInputStream(const void* res, s32 size) { setBuffer(res, size); } /* 802552B8 */ virtual ~JSUMemoryInputStream() {} /* 802DC520 */ void setBuffer(void const*, s32); @@ -18,10 +19,35 @@ public: /* 802DC628 */ s32 getLength() const; /* 802DC630 */ s32 getPosition() const; + void* getPointer() const { + return (u8*)mBuffer + mPosition; + } + private: /* 0x08 */ const void* mBuffer; /* 0x0C */ s32 mLength; /* 0x10 */ s32 mPosition; }; // Size = 0x14 +class JSUMemoryOutputStream : public JSURandomOutputStream { +public: + JSUMemoryOutputStream() { setBuffer(NULL, 0); } + JSUMemoryOutputStream(void* buffer, s32 len) { setBuffer(buffer, len); } + + void setBuffer(void* buffer, s32 len); + + virtual ~JSUMemoryOutputStream() {} + virtual s32 writeData(const void*, s32); + virtual s32 getLength() const; + virtual s32 getPosition() const; + virtual s32 seek(s32, JSUStreamSeekFrom); + virtual s32 getAvailable() const; + virtual s32 seekPos(s32, JSUStreamSeekFrom); + +private: + /* 0x08 */ void* mBuffer; + /* 0x0C */ s32 mLength; + /* 0x10 */ s32 mPosition; +}; // Size = 0x14 + #endif /* JSUMEMORYSTREAM_H */ diff --git a/include/JSystem/JSupport/JSUOutputStream.h b/include/JSystem/JSupport/JSUOutputStream.h new file mode 100644 index 0000000000..43d9d37ef0 --- /dev/null +++ b/include/JSystem/JSupport/JSUOutputStream.h @@ -0,0 +1,52 @@ +#ifndef JSUOUTPUTSTREAM_H +#define JSUOUTPUTSTREAM_H + +#include "JSystem/JSupport/JSUIosBase.h" + +/** +* @ingroup jsystem-jsupport +* +*/ +class JSUOutputStream : public JSUIosBase { +public: + JSUOutputStream() {} + virtual ~JSUOutputStream(); + + virtual s32 skip(s32, s8) = 0; + virtual s32 writeData(const void*, s32) = 0; + + s32 write(const void*, s32); + void write(const char*); + + JSUOutputStream& operator<<(u32 param_0) { + write(¶m_0, sizeof(u32)); + return *this; + } + + JSUOutputStream& operator<<(s32 param_0) { + write(¶m_0, sizeof(s32)); + return *this; + } + + JSUOutputStream& operator<<(s16 param_0) { + write(¶m_0, sizeof(s16)); + return *this; + } + + JSUOutputStream& operator<<(u16 param_0) { + write(¶m_0, sizeof(u16)); + return *this; + } + + JSUOutputStream& operator<<(u8 param_0) { + write(¶m_0, sizeof(u8)); + return *this; + } + + JSUOutputStream& operator<<(const char* param_0) { + write(param_0); + return *this; + } +}; // Size = 0x8 + +#endif /* JSUOUTPUTSTREAM_H */ diff --git a/include/JSystem/JSupport/JSURandomOutputStream.h b/include/JSystem/JSupport/JSURandomOutputStream.h new file mode 100644 index 0000000000..1b2648fabb --- /dev/null +++ b/include/JSystem/JSupport/JSURandomOutputStream.h @@ -0,0 +1,24 @@ +#ifndef JSURANDOMOUTPUTSTREAM_H_ +#define JSURANDOMOUTPUTSTREAM_H_ + +#include "JSystem/JSupport/JSUOutputStream.h" + +/** +* @ingroup jsystem-jsupport +* +*/ +class JSURandomOutputStream : public JSUOutputStream { +public: + JSURandomOutputStream() {} + virtual ~JSURandomOutputStream() {} + + /* vt[3] */ virtual s32 skip(s32, s8); + /* vt[4] */ virtual s32 writeData(const void*, s32) = 0; + /* vt[5] */ virtual s32 getLength() const = 0; + /* vt[6] */ virtual s32 getPosition() const = 0; + /* vt[7] */ virtual s32 seek(s32, JSUStreamSeekFrom); + /* vt[8] */ virtual s32 getAvailable() const; + /* vt[9] */ virtual s32 seekPos(s32, JSUStreamSeekFrom) = 0; +}; // Size = 0x8 + +#endif diff --git a/include/JSystem/JUtility/JUTAssert.h b/include/JSystem/JUtility/JUTAssert.h index 213f5df274..66256e08b7 100644 --- a/include/JSystem/JUtility/JUTAssert.h +++ b/include/JSystem/JUtility/JUTAssert.h @@ -21,7 +21,7 @@ JUTAssertion::setConfirmMessage(JUTAssertion::getSDevice(), __FILE__, LINE, COND, #COND) #else -#define JUT_ASSERT(...) +#define JUT_ASSERT(...) (void)0; #define JUT_PANIC(...) #define JUT_WARN(...) #define JUT_LOG(...) -- cgit v1.2.3