m_Do_MemCard / m_Do_MemCardRWmng (#184)

* memcard wip

* format / asm

* fix includes

Co-authored-by: TakaRikka <taka@DESKTOP-T4B7CTF.localdomain>
This commit is contained in:
TakaRikka
2022-03-22 23:42:16 -04:00
committed by GitHub
co-authored by TakaRikka
parent 1f5630246e
commit 3af0f51186
32 changed files with 682 additions and 1155 deletions
+74
View File
@@ -0,0 +1,74 @@
#ifndef CARD_H
#define CARD_H
#include "dolphin/types.h"
#define CARD_ERROR_UNLOCKED 1
#define CARD_ERROR_READY 0
#define CARD_ERROR_BUSY -1
#define CARD_ERROR_WRONGDEVICE -2
#define CARD_ERROR_NOCARD -3
#define CARD_ERROR_NOFILE -4
#define CARD_ERROR_IOERROR -5
#define CARD_ERROR_BROKEN -6
#define CARD_ERROR_EXIST -7
#define CARD_ERROR_NOENT -8
#define CARD_ERROR_INSSPACE -9
#define CARD_ERROR_NOPERM -10
#define CARD_ERROR_LIMIT -11
#define CARD_ERROR_NAMETOOLONG -12
#define CARD_ERROR_ENCODING -13
#define CARD_ERROR_CANCELED -14
#define CARD_ERROR_FATAL_ERROR -128
struct CARDFileInfo {
/* 0x00 */ s32 channel;
/* 0x04 */ s32 fileNo;
/* 0x08 */ u32 offset;
/* 0x0C */ u16 iconIndex;
/* 0x0E */ u16 commentIndex;
/* 0x10 */ u16 field_0x10;
}; // Size: 0x10
struct CARDStat {
/* 0x00 */ char filename[32];
/* 0x20 */ u32 length;
/* 0x24 */ u32 time;
/* 0x28 */ char gamecode[4];
/* 0x2C */ char company[2];
/* 0x2E */ u8 gameVersion;
/* 0x2F */ u8 bannerFormat;
/* 0x30 */ u32 iconAddress;
/* 0x34 */ u16 iconFormat;
/* 0x36 */ u16 iconSpeed;
/* 0x38 */ u32 commentAddress;
/* 0x3C */ u32 bannerOffset;
/* 0x40 */ u32 bannerPalOffset;
/* 0x44 */ u32 iconOffset[8];
/* 0x64 */ u32 iconPalOffset;
/* 0x68 */ u32 dataOffset;
}; // Size: 0x6C
typedef void (*CARDCallback)(s32 channel, s32 result);
extern "C" {
s32 CARDInit(void);
s32 CARDFreeBlocks(s32 channel, s32* free_bytes, s32* free_files);
s32 CARDCheck(s32 channel);
s32 CARDProbe(s32 channel);
s32 CARDProbeEx(s32 channel, s32* mem_size, s32* sect_size);
s32 CARDMount(s32 channel, void* buffer, CARDCallback callback);
s32 CARDUnmount(s32 channel);
s32 CARDFormat(s32 channel);
s32 CARDOpen(s32 channel, const char* filename, CARDFileInfo* file);
s32 CARDClose(CARDFileInfo* file);
s32 CARDCreate(s32 channel, const char* filename, u32 size, CARDFileInfo* file);
s32 CARDRead(CARDFileInfo* file, void* buffer, u32 size, u32 offset);
s32 CARDWrite(CARDFileInfo* file, void* buffer, u32 size, u32 offset);
s32 CARDGetStatus(s32 channel, s32 fileNo, CARDStat* stat);
s32 CARDSetStatus(s32 channel, s32 fileNo, CARDStat* stat);
s32 CARDGetSerialNo(s32 channel, u32* serial1, u32* serial2);
};
#endif /* CARD_H */
+27 -22
View File
@@ -1,38 +1,43 @@
#ifndef MTX_H
#define MTX_H
#include "dolphin/mtx/mtx44.h"
#include "dolphin/mtx/quat.h"
#include "dolphin/mtx/vec.h"
#include "dolphin/types.h"
typedef float Mtx[3][4];
typedef float Mtx33[3][3];
typedef float Mtx23[2][3];
typedef f32 Mtx[3][4];
typedef f32 Mtx33[3][3];
typedef f32 Mtx23[2][3];
typedef f32 (*MtxP)[4];
typedef const f32 (*CMtxP)[4]; // Change name later?
extern "C" {
void PSMTXIdentity(Mtx matrix);
void PSMTXIdentity(Mtx m);
void PSMTXCopy(const Mtx src, Mtx dst);
void PSMTXConcat(const Mtx src_a, const Mtx src_b, Mtx dst);
u32 PSMTXInverse(const Mtx src, Mtx dst);
void PSMTXRotRad(Mtx matrix, u8 axis, float rad);
void PSMTXRotTrig(Mtx matrix, u8 axis, float sin, float cos);
double __PSMTXRotAxisRadInternal(double param_1, double param_2, int param_3, int param_4);
void PSMTXRotAxisRad(Mtx matrix, const Vec* axis, float rad);
void PSMTXTrans(Mtx matrix, float x_trans, float y_trans, float z_trans);
void PSMTXTransApply(const Mtx src, Mtx dst, float x, float y, float z);
void PSMTXScale(Mtx matrix, float x_scale, float y_scale, float z_scale);
void PSMTXScaleApply(const Mtx src, Mtx dst, float x_scale, float y_scale, float z_scale);
void PSMTXQuat(Mtx matrix, const Quaternion* quat);
void PSMTXMultVec(const Mtx matrix, const Vec* src, Vec* dst);
void PSMTXMultVecSR(const Mtx matrix, const Vec* src, Vec* dst);
void PSMTXConcat(const Mtx a, const Mtx b, Mtx ab);
u32 PSMTXInverse(const Mtx src, Mtx inv);
void PSMTXRotRad(Mtx m, u8 axis, f32 rad);
void PSMTXRotTrig(Mtx m, u8 axis, f32 sin, f32 cos);
f64 __PSMTXRotAxisRadInternal(f64 param_1, f64 param_2, int param_3, int param_4);
void PSMTXRotAxisRad(Mtx m, const Vec* axis, f32 rad);
void PSMTXTrans(Mtx m, f32 x_trans, f32 y_trans, f32 z_trans);
void PSMTXTransApply(const Mtx src, Mtx dst, f32 x, f32 y, f32 z);
void PSMTXScale(Mtx m, f32 x_scale, f32 y_scale, f32 z_scale);
void PSMTXScaleApply(const Mtx src, Mtx dst, f32 x_scale, f32 y_scale, f32 z_scale);
void PSMTXQuat(Mtx m, const Quaternion* q);
void PSMTXMultVec(const Mtx m, const Vec* src, Vec* dst);
void PSMTXMultVecSR(const Mtx m, const Vec* src, Vec* dst);
void PSMTXMultVec(const Mtx m, const Vec* src, Vec* dst);
void PSMTXMultVecArray(const Mtx m, const Vec* srcBase, Vec* dstBase, u32 count);
void PSMTXMultVecSR(const Mtx m, const Vec* src, Vec* dst);
void PSMTXMultVecArraySR(const Mtx m, const Vec* srcBase, Vec* dstBase, u32 count);
void C_MTXLookAt(Mtx param_1, const Vec* param_2, const Vec* param_3, const Vec* param_4);
void C_MTXLightPerspective(Mtx matrix, float fov_y, float aspect, float scale_s, float scale_t,
float trans_s, float trans_t);
void C_MTXLightOrtho(Mtx matrix, float top, float bottom, float left, float right, float scale_s,
float scale_t, float trans_s, float trans_t);
void C_MTXLookAt(Mtx m, const Vec* camPos, const Vec* camUp, const Vec* target);
void C_MTXLightPerspective(Mtx m, f32 fovY, f32 aspect, f32 scale_s, f32 scale_t, f32 trans_s,
f32 trans_t);
void C_MTXLightOrtho(Mtx m, f32 top, f32 bottom, f32 left, f32 right, f32 scale_s, f32 scale_t,
f32 trans_s, f32 trans_t);
}
#endif /* MTX_H */
+2 -4
View File
@@ -6,10 +6,8 @@
typedef float Mtx44[4][4];
extern "C" {
void C_MTXPerspective(Mtx44 matrix, float fov_y, float aspect, float near, float far);
void C_MTXOrtho(Mtx44 matrix, float top, float bottom, float left, float right, float near,
float far);
void C_MTXPerspective(Mtx44 m, f32 fovy, f32 aspect, f32 near, f32 far);
void C_MTXOrtho(Mtx44 m, f32 top, f32 bottom, f32 left, f32 right, f32 near, f32 far);
}
#endif /* MTX44_H */
+3 -3
View File
@@ -5,13 +5,13 @@
#include "dolphin/types.h"
struct Quaternion {
float x, y, z, w;
f32 x, y, z, w;
};
extern "C" {
void PSQUATMultiply(const Quaternion* src_a, const Quaternion* src_b, Quaternion* dst);
void C_QUATRotAxisRad(Quaternion* quat, const Vec* axis, float rad);
void C_QUATSlerp(const Quaternion* p, const Quaternion* q, Quaternion* r, float t);
void C_QUATRotAxisRad(Quaternion* q, const Vec* axis, f32 rad);
void C_QUATSlerp(const Quaternion* p, const Quaternion* q, Quaternion* r, f32 t);
}
#endif /* QUAT_H */
+24 -19
View File
@@ -4,13 +4,13 @@
#include "dolphin/types.h"
struct Vec {
float x, y, z;
float GetX() const { return x; }
float GetY() const { return y; }
float GetZ() const { return z; }
float getXDiff(const Vec* other) const { return x - other->x; }
float getYDiff(const Vec* other) const { return y - other->y; }
float getZDiff(const Vec* other) const { return z - other->z; }
f32 x, y, z;
f32 GetX() const { return x; }
f32 GetY() const { return y; }
f32 GetZ() const { return z; }
f32 getXDiff(const Vec* other) const { return x - other->x; }
f32 getYDiff(const Vec* other) const { return y - other->y; }
f32 getZDiff(const Vec* other) const { return z - other->z; }
void set(f32 pX, f32 pY, f32 pZ) {
x = pX;
y = pY;
@@ -23,6 +23,10 @@ struct Vec {
}
};
typedef Vec* VecPtr;
typedef Vec Point3d;
typedef Vec* Point3dPtr;
struct SVec {
s16 x, y, z;
@@ -34,18 +38,19 @@ struct SVec {
};
extern "C" {
void PSVECAdd(const Vec* src_a, const Vec* src_b, Vec* dst);
void PSVECSubtract(const Vec* a, const Vec* b, Vec* dst);
void PSVECScale(const Vec* src, Vec* dst, float scale);
void PSVECNormalize(const Vec* src, Vec* dst);
float PSVECSquareMag(const Vec* vec);
float PSVECMag(const Vec* data);
float PSVECDotProduct(const Vec* a, const Vec* b);
void PSVECCrossProduct(const Vec* src_a, const Vec* src_b, Vec* dst);
void C_VECHalfAngle(const Vec* incident, const Vec* line_of_sight, Vec* out_half);
void C_VECReflect(const Vec* src, const Vec* surface_normal, Vec* dst);
float PSVECSquareDistance(const Vec* a, const Vec* b);
float PSVECDistance(const Vec* a, const Vec* b);
void PSVECAdd(const Vec* a, const Vec* b, Vec* ab);
void PSVECSubtract(const Vec* a, const Vec* b, Vec* a_b);
void PSVECScale(const Vec* src, Vec* dst, f32 scale);
void PSVECNormalize(const Vec* src, Vec* unit);
f32 PSVECSquareMag(const Vec* v);
f32 PSVECMag(const Vec* v);
f32 PSVECDotProduct(const Vec* a, const Vec* b);
void PSVECCrossProduct(const Vec* a, const Vec* b, Vec* axb);
f32 PSVECSquareDistance(const Vec* a, const Vec* b);
f32 PSVECDistance(const Vec* a, const Vec* b);
void C_VECHalfAngle(const Vec* a, const Vec* b, Vec* half);
void C_VECReflect(const Vec* src, const Vec* normal, Vec* dst);
}
#endif /* VEC_H */
+18 -16
View File
@@ -137,7 +137,7 @@ struct OSAlarmLink {
/* 0x4 */ OSAlarm* next;
};
typedef void (*OSAlarmHandler)(OSAlarm*, OSContext*);
typedef void (*OSAlarmHandler)(OSAlarm* alarm, OSContext* context);
struct OSAlarm {
/* 0x00 */ OSAlarmHandler handler;
@@ -157,13 +157,13 @@ OSThread* OSGetCurrentThread(void);
s32 OSSuspendThread(OSThread* thread);
s32 OSSetThreadPriority(OSThread* thread, u32 pri);
s32 OSGetThreadPriority(OSThread* thread);
s32 OSCreateThread(OSThread* thread, void* func, void* param, void* stack, u32 stackSize,
int param_6, int param_7);
BOOL OSCreateThread(OSThread* thread, void* func, void* param, void* stack, u32 stackSize,
int priority, int attr);
void OSCancelThread(OSThread* thread);
void OSDetachThread(OSThread* thread);
s32 OSResumeThread(OSThread* thread);
void OSExitThread(void* exit_val);
bool OSIsThreadSuspended(OSThread* thread);
BOOL OSIsThreadSuspended(OSThread* thread);
BOOL OSIsThreadTerminated(OSThread* thread);
OSSwitchThreadCallback OSSetSwitchThreadCallback(OSSwitchThreadCallback callback);
@@ -197,21 +197,19 @@ OSTick OSGetTick(void);
u32 OSGetArenaLo();
u32 OSGetArenaHi();
u32 OSInitAlloc(u32 low, u32 high, int param_3);
void OSSetArenaLo(u32 param_1);
void OSSetArenaHi(u32 param_1);
u32 OSInitAlloc(u32 low, u32 high, int maxHeaps);
void OSSetArenaLo(u32 newLo);
void OSSetArenaHi(u32 newHi);
void* OSAllocFromArenaLo(u32 size, int alignment);
// void OSCancelAlarm(OSAlarm *alarm);
void OSInitMutex(OSMutex* mutex);
void OSLockMutex(OSMutex* mutex);
void OSTryLockMutex(OSMutex* mutex);
BOOL OSTryLockMutex(OSMutex* mutex);
void OSUnlockMutex(OSMutex* mutex);
s32 OSDisableInterrupts();
s32 OSEnableInterrupts();
s32 OSRestoreInterrupts(s32 level);
BOOL OSDisableInterrupts();
BOOL OSEnableInterrupts();
BOOL OSRestoreInterrupts(s32 level);
void OSResetSystem(s32 param_1, u32 param_2, s32 param_3);
@@ -223,9 +221,13 @@ void OSReportInit__Fv(void); // needed for inline asm
u8* OSGetStackPointer(void);
void OSCreateAlarm(OSAlarm*);
void OSCancelAlarm(OSAlarm*);
void OSSetAlarm(OSAlarm*, OSTime, OSAlarmHandler);
void OSCreateAlarm(OSAlarm* alarm);
void OSCancelAlarm(OSAlarm* alarm);
void OSSetAlarm(OSAlarm* alarm, OSTime time, OSAlarmHandler handler);
void OSInitCond(OSCond* cond);
void OSWaitCond(OSCond* cond, OSMutex* mutex);
void OSSignalCond(OSCond* cond);
inline s16 __OSf32tos16(register f32 inF) {
register s16 out;