1 #ifndef JBUS_ENDPOINT_HPP 2 #define JBUS_ENDPOINT_HPP 6 #include "optional.hpp" 23 class KawasedoChallenge
47 void ProcessGBACrypto()
50 x20_publicKey = x0_gbaChallenge ^ 0x6f646573;
53 u16 paletteSpeedCoded;
54 s16 logoSpeed =
static_cast<s8>(x8_logoSpeed);
56 paletteSpeedCoded = ((-logoSpeed + 2) * 2) | (x4_logoPalette << 4);
57 else if (logoSpeed == 0)
58 paletteSpeedCoded = (x4_logoPalette * 2) | 0x70;
60 paletteSpeedCoded = ((logoSpeed - 1) * 2) | (x4_logoPalette << 4);
63 s32 lengthNoHeader = ROUND_UP_8(xc_progLength) - 0x200;
67 u16 packetPairCount = (lengthNoHeader < 0) ? 0 : lengthNoHeader / 8;
68 paletteSpeedCoded |= (packetPairCount & 0x4000) >> 14;
71 u32 t1 = (((packetPairCount << 16) | 0x3f80) & 0x3f80ffff) * 2;
72 t1 += (
static_cast<s16>(
static_cast<s8>(t1 >> 8)) & packetPairCount) << 16;
73 u32 t2 = ((paletteSpeedCoded & 0xff) << 16) + (t1 & 0xff0000) + ((t1 >> 8) & 0xffff00);
74 u32 t3 = paletteSpeedCoded << 16 | ((t2 << 8) & 0xff000000) | (t1 >> 16) | 0x80808080;
77 x24_authInitCode = t3 ^ ((t3 & 0x200) != 0 ? 0x6f646573 : 0x6177614b);
94 u32 x3c_checkStore[7];
99 bool m_started =
true;
105 void _DSPCryptoInit();
115 return std::bind(ptmf,
this, std::placeholders::_1, std::placeholders::_2);
119 KawasedoChallenge(
Endpoint& endpoint,
s32 paletteColor,
s32 paletteSpeed,
121 bool started()
const {
return m_started; }
122 u8 percentComplete()
const 126 return x34_bytesSent * 100 / x64_totalBytes;
128 bool isDone()
const {
return !x14_callback; }
141 static const u64 BITS_PER_SECOND = 115200;
142 static const u64 BYTES_PER_SECOND = BITS_PER_SECOND / 8;
146 std::thread m_transferThread;
147 std::mutex m_syncLock;
148 std::condition_variable m_syncCv;
149 std::condition_variable m_issueCv;
150 std::experimental::optional<KawasedoChallenge> m_joyBoot;
153 u8* m_readDstPtr =
nullptr;
154 u8* m_statusPtr =
nullptr;
155 u64 m_lastGCTick = 0;
158 bool m_booted =
false;
159 bool m_cmdIssued =
false;
160 bool m_running =
true;
163 void send(
const u8* buffer);
164 size_t receive(
u8* buffer);
165 size_t runBuffer(
u8* buffer, std::unique_lock<std::mutex>& lk);
166 bool idleGetStatus(std::unique_lock<std::mutex>& lk);
172 return std::bind(&Endpoint::transferWakeup,
this,
173 std::placeholders::_1, std::placeholders::_2);
244 const u8* programp,
s32 length,
u8* status,
298 #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.
int GetChan() const
Get virtual SI channel assigned to this endpoint.
Definition: Endpoint.hpp:293
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:131
Definition: Socket.hpp:103
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
Definition: Endpoint.hpp:15
uint32_t u32
Definition: Common.hpp:16
void stop()
Request stop of I/O thread and block until joined. Further use of this Endpoint is undefined behavior...
EJoyReturn GBAReset(u8 *status)
Send RESET command to GBA synchronously.
int GetChan() const
Get virtual SI channel assigned to this endpoint.
Definition: Endpoint.hpp:249
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:258