summaryrefslogtreecommitdiff
path: root/include/JSystem/JKernel/JKRDecomp.h
blob: c3972185919b31c511178487b9505203e6cb32eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef JKRDECOMP_H
#define JKRDECOMP_H

#include "JSystem/JKernel/JKRCompression.h"
#include "JSystem/JKernel/JKRThread.h"

class JKRAMCommand;

/**
 * @ingroup jsystem-jkernel
 * 
 */
class JKRDecompCommand {
public:
    typedef void (*AsyncCallback)(u32);

    JKRDecompCommand();
    ~JKRDecompCommand();

public:
    /* 0x00 */ u32 field_0x0;
    /* 0x04 */ u8* mSrcBuffer;
    /* 0x08 */ u8* mDstBuffer;
    /* 0x0C */ u32 mSrcLength;
    /* 0x10 */ u32 mDstLength;
    /* 0x14 */ AsyncCallback mCallback;
    /* 0x18 */ JKRDecompCommand* mThis;
    /* 0x1C */ OSMessageQueue* field_0x1c;
    /* 0x20 */ s32 field_0x20;
    /* 0x24 */ JKRAMCommand* mAMCommand;
    /* 0x28 */ OSMessageQueue mMessageQueue;
    /* 0x48 */ OSMessage mMessage;
};

#define JKRDECOMP_SYNC_BLOCKING 0
#define JKRDECOMP_SYNC_NON_BLOCKING 1

/**
 * @ingroup jsystem-jkernel
 * 
 */
class JKRDecomp : public JKRThread {
private:
    JKRDecomp(s32);
    virtual ~JKRDecomp();

    /* vt[03] */ virtual void* run(); /* override */

public:
    static JKRDecomp* create(s32);
    static JKRDecompCommand* prepareCommand(u8*, u8*, u32, u32, JKRDecompCommand::AsyncCallback);
    static void sendCommand(JKRDecompCommand*);
    static bool sync(JKRDecompCommand*, int);
    static JKRDecompCommand* orderAsync(u8*, u8*, u32, u32, JKRDecompCommand::AsyncCallback);
    static bool orderSync(u8*, u8*, u32, u32);
    static void decode(u8*, u8*, u32, u32);
    static void decodeSZP(u8*, u8*, u32, u32);
    static void decodeSZS(u8*, u8*, u32, u32);
    static JKRCompression checkCompressed(u8*);

    static JKRDecomp* sDecompObject;
    static OSMessage sMessageBuffer[8];
    static OSMessageQueue sMessageQueue;
};

inline void JKRDecompress(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 dstLength) {
    JKRDecomp::orderSync(srcBuffer, dstBuffer, srcLength, dstLength);
}

inline JKRDecomp* JKRCreateDecompManager(s32 priority) {
    return JKRDecomp::create(priority);
}

inline JKRCompression JKRCheckCompressed_noASR(u8 *pBuf) {
    JKRCompression compression = JKRDecomp::checkCompressed(pBuf);
    if (compression == COMPRESSION_ASR) // ternary i had before was either incorrect, or was not a ternary at all
        compression = COMPRESSION_NONE;
    return compression;
}

inline u32 JKRDecompExpandSize(u8* pBuf) {
    return (pBuf[4] << 0x18) | (pBuf[5] << 0x10) | (pBuf[6] << 8) | pBuf[7];
}

#endif /* JKRDECOMP_H */