1 #ifndef JBUS_ENDPOINT_HPP 2 #define JBUS_ENDPOINT_HPP 6 #include "optional.hpp" 9 #include <condition_variable> 24 class KawasedoChallenge
48 void ProcessGBACrypto()
51 x20_publicKey = x0_gbaChallenge ^ 0x6f646573;
54 u16 paletteSpeedCoded;
55 s16 logoSpeed =
static_cast<s8>(x8_logoSpeed);
57 paletteSpeedCoded = ((-logoSpeed + 2) * 2) | (x4_logoPalette << 4);
58 else if (logoSpeed == 0)
59 paletteSpeedCoded = (x4_logoPalette * 2) | 0x70;
61 paletteSpeedCoded = ((logoSpeed - 1) * 2) | (x4_logoPalette << 4);
64 s32 lengthNoHeader = ROUND_UP_8(xc_progLength) - 0x200;
68 u16 packetPairCount = (lengthNoHeader < 0) ? 0 : lengthNoHeader / 8;
69 paletteSpeedCoded |= (packetPairCount & 0x4000) >> 14;
72 u32 t1 = (((packetPairCount << 16) | 0x3f80) & 0x3f80ffff) * 2;
73 t1 += (
static_cast<s16>(
static_cast<s8>(t1 >> 8)) & packetPairCount) << 16;
74 u32 t2 = ((paletteSpeedCoded & 0xff) << 16) + (t1 & 0xff0000) + ((t1 >> 8) & 0xffff00);
75 u32 t3 = paletteSpeedCoded << 16 | ((t2 << 8) & 0xff000000) | (t1 >> 16) | 0x80808080;
78 x24_authInitCode = t3 ^ ((t3 & 0x200) != 0 ? 0x6f646573 : 0x6177614b);
95 u32 x3c_checkStore[7];
100 bool m_started =
true;
106 void _DSPCryptoInit();
116 return std::bind(ptmf,
this, std::placeholders::_1, std::placeholders::_2);
120 KawasedoChallenge(
Endpoint& endpoint,
s32 paletteColor,
s32 paletteSpeed,
122 bool started()
const {
return m_started; }
123 u8 percentComplete()
const 127 return x34_bytesSent * 100 / x64_totalBytes;
129 bool isDone()
const {
return !x14_callback; }
142 static const u64 BITS_PER_SECOND = 115200;
143 static const u64 BYTES_PER_SECOND = BITS_PER_SECOND / 8;
147 std::thread m_transferThread;
148 std::mutex m_syncLock;
149 std::condition_variable m_syncCv;
150 std::condition_variable m_issueCv;
151 std::experimental::optional<KawasedoChallenge> m_joyBoot;
154 u8* m_readDstPtr =
nullptr;
155 u8* m_statusPtr =
nullptr;
156 u64 m_lastGCTick = 0;
159 bool m_booted =
false;
160 bool m_cmdIssued =
false;
161 bool m_running =
true;
164 void send(
const u8* buffer);
165 size_t receive(
u8* buffer);
166 size_t runBuffer(
u8* buffer, std::unique_lock<std::mutex>& lk);
167 bool idleGetStatus(std::unique_lock<std::mutex>& lk);
173 return std::bind(&Endpoint::transferWakeup,
this,
174 std::placeholders::_1, std::placeholders::_2);
245 const u8* programp,
s32 length,
u8* status,
312 #endif // JBUS_ENDPOINT_HPP EJoyReturn GBARead(u8 *dst, u8 *status)
Send READ command to GBA synchronously.
uint16_t u16
Definition: Common.hpp:14
EJoyReturn GBAGetStatus(u8 *status)
Get JOYSTAT register from GBA synchronously.
int8_t s8
Definition: Common.hpp:11
std::function< void(ThreadLocalEndpoint &endpoint, EJoyReturn status)> FGBACallback
Standard callback for asynchronous jbus::Endpoint APIs.
Definition: Common.hpp:169
uint8_t u8
Definition: Common.hpp:12
friend class ThreadLocalEndpoint
Definition: Endpoint.hpp:132
Definition: Socket.hpp:104
EJoyReturn GBAWriteAsync(const u8 *src, u8 *status, FGBACallback &&callback)
Send WRITE command to GBA asynchronously.
uint64_t u64
Definition: Common.hpp:18
Endpoint(u8 chan, net::Socket &&data, net::Socket &&clock)
int16_t s16
Definition: Common.hpp:13
int32_t s32
Definition: Common.hpp:15
EJoyReturn GBAGetStatusAsync(u8 *status, FGBACallback &&callback)
Get JOYSTAT register from GBA asynchronously.
EJoyReturn GBAReadAsync(u8 *dst, u8 *status, FGBACallback &&callback)
Send READ command to GBA asynchronously.
EJoyReturn GBAJoyBootAsync(s32 paletteColor, s32 paletteSpeed, const u8 *programp, s32 length, u8 *status, FGBACallback &&callback)
Initiate JoyBoot sequence on this endpoint.
EJoyReturn GBAWrite(const u8 *src, u8 *status)
Send WRITE command to GBA synchronously.
EJoyReturn
Definition: Common.hpp:157
int getChan() const
Get virtual SI channel assigned to this endpoint.
Definition: Endpoint.hpp:307
Definition: Endpoint.hpp:16
uint32_t u32
Definition: Common.hpp:16
bool connected() const
Get connection status of this endpoint.
Definition: Endpoint.hpp:263
unsigned getChan() const
Get virtual SI channel assigned to this endpoint.
Definition: Endpoint.hpp:250
void stop()
Request stop of I/O thread and block until joined. Further use of this Endpoint will return GBA_NOT_R...
EJoyReturn GBAReset(u8 *status)
Send RESET command to GBA synchronously.
void setChan(unsigned chan)
Set virtual SI channel assigned to this endpoint.
Definition: Endpoint.hpp:254
EJoyReturn GBAResetAsync(u8 *status, FGBACallback &&callback)
Send RESET command to GBA asynchronously.
EJoyReturn GBAGetProcessStatus(u8 &percentOut)
Get status of last asynchronous operation.
Definition: Endpoint.hpp:272