Skip to content

Commit

Permalink
Merge pull request #515 from Jcw87/JUTGba
Browse files Browse the repository at this point in the history
JUTGba
  • Loading branch information
magcius authored Oct 11, 2023
2 parents ee802bb + 735e4c1 commit 282de23
Show file tree
Hide file tree
Showing 4 changed files with 484 additions and 73 deletions.
4 changes: 4 additions & 0 deletions include/JSystem/JKernel/JKRHeap.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ inline JKRHeap* JKRGetCurrentHeap() {
return JKRHeap::getCurrentHeap();
}

inline JKRHeap* JKRSetCurrentHeap(JKRHeap* heap) {
return heap->becomeCurrentHeap();
}

inline u32 JKRGetMemBlockSize(JKRHeap* heap, void* block) {
return JKRHeap::getSize(block, heap);
}
Expand Down
60 changes: 46 additions & 14 deletions include/JSystem/JUtility/JUTGba.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,47 @@
#ifndef JUTGBA_H
#define JUTGBA_H

#include "dolphin/types.h"
#include "dolphin/os/OSMessage.h"
#include "dolphin/os/OSTime.h"

struct JUTGbaParam;
struct JUTGbaThreadVar;

typedef void (*JUTGba_Func)(JUTGbaParam*, void*);

struct JUTGbaParam {
/* 0x00 */ OSMessageQueue field_0x0;
/* 0x20 */ OSMessage field_0x20;
/* 0x24 */ u32 field_0x24;
/* 0x28 */ s32 channel;
/* 0x2C */ u8* program;
/* 0x30 */ int length;
/* 0x34 */ int palette_color;
/* 0x38 */ int palette_speed;
/* 0x3C */ u8 field_0x3c;
/* 0x40 */ int field_0x40;
/* 0x44 */ u8 status;
/* 0x48 */ u8* field_0x48;
/* 0x4C */ JUTGba_Func field_0x4c;
/* 0x50 */ void* field_0x50;
/* 0x54 */ u8 field_0x54;
/* 0x58 */ int field_0x58;
};

struct JUTGbaThreadVar {
/* 0x00 */ JUTGbaParam* field_0x0;
/* 0x08 */ OSTime field_0x8;
/* 0x10 */ u32 field_0x10;
/* 0x14 */ u32 field_0x14;
/* 0x18 */ u32 field_0x18;
};

class JUTGba {
public:
JUTGba();

static void create();
void result_common(int, u32, u32*);
void resultStatus_common(int, u32, u8*);
static JUTGba* create();
int result_common(int, u32, u32*);
int resultStatus_common(int, u32, u8*);
void doJoyBoot(int, s32, s32, u8*, u32, JUTGba_Func, void*);
int resultJoyBoot(int, u8*);
void doInitProbe(int, JUTGba_Func, void*);
Expand All @@ -29,20 +56,25 @@ class JUTGba {
BOOL resultWrite(int, u8*);
void doGetStatus(int, JUTGba_Func, void*);
BOOL resultGetStatus(int, u8*);
void gbaThreadMain(void*);
void gbaThread_sleep(s64);
static void* gbaThreadMain(void*);
void gbaThread_sleep(OSTime);
void gbaThread_Destroy(JUTGbaThreadVar*);
void gbaThread_JoyBoot(JUTGbaThreadVar*);
void gbaThread_InitProbe(JUTGbaThreadVar*);
void gbaThread_Probe(JUTGbaThreadVar*);
void gbaThread_Reset(JUTGbaThreadVar*);
void gbaThread_Read(JUTGbaThreadVar*);
void gbaThread_Write(JUTGbaThreadVar*);
void gbaThread_GetStatus(JUTGbaThreadVar*);
int gbaThread_JoyBoot(JUTGbaThreadVar*);
int gbaThread_InitProbe(JUTGbaThreadVar*);
int gbaThread_Probe(JUTGbaThreadVar*);
int gbaThread_Reset(JUTGbaThreadVar*);
int gbaThread_Read(JUTGbaThreadVar*);
int gbaThread_Write(JUTGbaThreadVar*);
int gbaThread_GetStatus(JUTGbaThreadVar*);

static JUTGba* getManager() { return sManager; }

static JUTGba* sManager;

/* 0x0000 */ OSThread mThreads[4];
/* 0x0C60 */ u8 mStacks[4][4096];
/* 0x4C60 */ JUTGbaParam mParams[4];
/* 0x4DD0 */ u8 field0x4dd0[16];
};

#endif /* JUTGBA_H */
130 changes: 130 additions & 0 deletions include/dolphin/si/SIBios.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#ifndef SIBIOS_H
#define SIBIOS_H

#include "dolphin/os/OSInterrupt.h"
#include "dolphin/os/OSTime.h"

#ifdef __cplusplus
extern "C" {
#endif

#define SI_MAX_CHAN 4
#define SI_MAX_COMCSR_INLNGTH 128
#define SI_MAX_COMCSR_OUTLNGTH 128
#define SI_ERROR_UNDER_RUN 0x0001
#define SI_ERROR_OVER_RUN 0x0002
#define SI_ERROR_COLLISION 0x0004
#define SI_ERROR_NO_RESPONSE 0x0008
#define SI_ERROR_WRST 0x0010
#define SI_ERROR_RDST 0x0020
#define SI_ERROR_UNKNOWN 0x0040
#define SI_ERROR_BUSY 0x0080
#define SI_CHAN0 0
#define SI_CHAN1 1
#define SI_CHAN2 2
#define SI_CHAN3 3
#define SI_CHAN0_BIT 0x80000000
#define SI_CHAN1_BIT 0x40000000
#define SI_CHAN2_BIT 0x20000000
#define SI_CHAN3_BIT 0x10000000
#define SI_CHAN_BIT(chan) (SI_CHAN0_BIT >> (chan))
#define SI_TYPE_MASK 0x18000000u
#define SI_TYPE_N64 0x00000000u
#define SI_TYPE_DOLPHIN 0x08000000u
#define SI_TYPE_GC SI_TYPE_DOLPHIN
#define SI_GC_WIRELESS 0x80000000
#define SI_GC_NOMOTOR 0x20000000
#define SI_GC_STANDARD 0x01000000
#define SI_WIRELESS_RECEIVED 0x40000000
#define SI_WIRELESS_IR 0x04000000
#define SI_WIRELESS_STATE 0x02000000
#define SI_WIRELESS_ORIGIN 0x00200000
#define SI_WIRELESS_FIX_ID 0x00100000
#define SI_WIRELESS_TYPE 0x000f0000
#define SI_WIRELESS_LITE_MASK 0x000c0000
#define SI_WIRELESS_LITE 0x00040000
#define SI_WIRELESS_CONT_MASK 0x00080000
#define SI_WIRELESS_CONT 0x00000000
#define SI_WIRELESS_ID 0x00c0ff00
#define SI_WIRELESS_TYPE_ID (SI_WIRELESS_TYPE | SI_WIRELESS_ID)
#define SI_N64_CONTROLLER (SI_TYPE_N64 | 0x05000000)
#define SI_N64_MIC (SI_TYPE_N64 | 0x00010000)
#define SI_N64_KEYBOARD (SI_TYPE_N64 | 0x00020000)
#define SI_N64_MOUSE (SI_TYPE_N64 | 0x02000000)
#define SI_GBA (SI_TYPE_N64 | 0x00040000)
#define SI_GC_CONTROLLER (SI_TYPE_GC | SI_GC_STANDARD)
#define SI_GC_RECEIVER (SI_TYPE_GC | SI_GC_WIRELESS)
#define SI_GC_WAVEBIRD \
(SI_TYPE_GC | SI_GC_WIRELESS | SI_GC_STANDARD | SI_WIRELESS_STATE | SI_WIRELESS_FIX_ID)
#define SI_GC_KEYBOARD (SI_TYPE_GC | 0x00200000)
#define SI_GC_STEERING (SI_TYPE_GC | 0x00000000)

typedef void (*SICallback)(s32 chan, u32 sr, OSContext* context);
typedef void (*SITypeAndStatusCallback)(s32 chan, u32 type);

typedef struct SIPacket {
s32 chan;
void* output;
u32 outputBytes;
void* input;
u32 inputBytes;
SICallback callback;
OSTime fire;
} SIPacket;

typedef struct SIControl {
s32 chan;
u32 poll;
u32 inputBytes;
void* input;
SICallback callback;
} SIControl;

typedef struct SIComm_s {
u32 tcint : 1;
u32 tcintmsk : 1;
u32 comerr : 1;
u32 rdstint : 1;
u32 rdstintmsk : 1;
u32 pad0 : 4;
u32 outlngth : 7;
u32 pad1 : 1;
u32 inlngth : 7;
u32 pad2 : 5;
u32 channel : 2;
u32 tstart : 1;
} SIComm_s;

typedef union SIComm_u {
u32 val;
SIComm_s f;
} SIComm_u;

BOOL SIBusy(void);
BOOL SIIsChanBusy(s32 chan);
static void SIInterruptHandler(OSInterrupt interrupt, OSContext* context);
static BOOL SIEnablePollingInterrupt(BOOL enable);
BOOL SIRegisterPollingHandler(OSInterruptHandler handler);
BOOL SIUnregisterPollingHandler(OSInterruptHandler handler);
void SIInit(void);
u32 SIGetStatus(s32 chan);
void SISetCommand(s32 chan, u32 command);
void SITransferCommands(void);
u32 SISetXY(u32 x, u32 y);
u32 SIEnablePolling(u32 poll);
u32 SIDisablePolling(u32 poll);
static BOOL SIGetResponseRaw(s32 chan);
BOOL SIGetResponse(s32 chan, void* data);
BOOL SITransfer(s32 chan, void* output, u32 outputBytes, void* input, u32 inputBytes,
SICallback callback, OSTime delay);
u32 SIGetType(s32 chan);
u32 SIGetTypeAsync(s32 chan, SITypeAndStatusCallback callback);
u32 SIProbe(s32 chan);

vu32 __SIRegs[64] : 0xCC006400;

#ifdef __cplusplus
}
#endif

#endif /* SIBIOS_H */
Loading

0 comments on commit 282de23

Please sign in to comment.