From 847868c099dfb0db8e7f00b750155facd40fcd0e Mon Sep 17 00:00:00 2001 From: Seeky Date: Tue, 22 Dec 2020 14:15:39 +0000 Subject: [PATCH] Decompiled all known swdrv functions --- include/evtmgr_cmd.h | 4 ++++ include/spmario.h | 8 +++---- include/swdrv.h | 57 +++++++++++++++++++++++++++++++++++++------- src/swdrv.c | 28 +++++++++++++++++++++- 4 files changed, 83 insertions(+), 14 deletions(-) diff --git a/include/evtmgr_cmd.h b/include/evtmgr_cmd.h index 136999d..8610a67 100644 --- a/include/evtmgr_cmd.h +++ b/include/evtmgr_cmd.h @@ -1,3 +1,7 @@ +/* + Functions to execute interpreted evt script code and handle evt variables +*/ + #ifndef EVTMGR_CMD_H #define EVTMGR_CMD_H diff --git a/include/spmario.h b/include/spmario.h index 3c81b7f..dd35baf 100644 --- a/include/spmario.h +++ b/include/spmario.h @@ -8,10 +8,10 @@ typedef struct { s64 time; u8 unknown_0x100[0x140 - 0x100]; s32 gsw0; - u32 gswf[256]; - u8 gsw[2048]; - s32 lswf[16]; - u8 lsw[1024]; + u32 gswf[256]; // 8192 flags + s8 gsw[2048]; + u32 lswf[16]; // 512 flags + s8 lsw[1024]; u8 unknown_0x1184[0x900]; // coin related? u8 unknown_0x1a84[0x1ab0 - 0x1a84]; } SpmarioGlobals; diff --git a/include/swdrv.h b/include/swdrv.h index c1cd0bf..9bdd982 100644 --- a/include/swdrv.h +++ b/include/swdrv.h @@ -1,3 +1,11 @@ +/* + Functions handling "Saved Work", which are variables used in evt + scripts that are saved when closing the game + Set, Get & Clear functions handle bools + ByteGet and ByteSet functions handle s8 (or s32 for gsw0) + LSW(F) functions are prefixed by an underscore, the rest are GSW(F) +*/ + #ifndef SWDRV_H #define SWDRV_H @@ -33,22 +41,53 @@ void swClear(s32 num); // 80038034 /* Sets a global saved work value - Value cast to s8 unless setting GSW 0 + Value cast to u8 unless setting GSW 0 */ -void swByteSet(s32 num, s32 value); +void swByteSet(s32 num, s32 value); // 80038074 /* Gets a global saved work value - Return is s8 unless getting GSW 0 + Return is u8 unless getting GSW 0 */ -s32 swByteGet(s32 num); +s32 swByteGet(s32 num); // 800380f8 + +/* + Turns on a local saved work flag +*/ +void _swSet(s32 num); // 8003811c + +/* + Returns the value of a local saved work flag +*/ +bool _swGet(s32 num); // 8003815c + +/* + Turns off a local saved work flag +*/ +void _swClear(s32 num); // 800381a4 -// _swSet -s32 _swGet(s32 num); -// _swClear // TTYD symbol map shows there's an _swToggle but it went unused in both games -// _swToggle -// _swByteSet + +/* + Sets a local saved work value +*/ +void _swByteSet(s32 num, s8 value); + +/* + Returns a local saved work value + Note: return is technically just s8 but calls used wrong casts when it was set to that +*/ s32 _swByteGet(s32 num); +// New to SPM so no symbols: +// 80038204 +// 800383a0 +// 80038478 +// 80038550 +// 8003863c +// 8003864c +// 8003865c +// 8003875c +// 800387d8 + #endif \ No newline at end of file diff --git a/src/swdrv.c b/src/swdrv.c index 7a7cd92..9ffcdb0 100644 --- a/src/swdrv.c +++ b/src/swdrv.c @@ -1,3 +1,7 @@ +/* + 80037eac-800388b3 +*/ + #include #include #include @@ -45,7 +49,7 @@ void swByteSet(s32 num, s32 value) { else { // "The value is strange" assertf(num < 256, "値がおかしい sw_byte[%d] = %d", num + EVTDAT_LSW_BASE, value); - gp->gsw[num] = (u8) value; + gp->gsw[num] = (s8) value; } } @@ -54,5 +58,27 @@ s32 swByteGet(s32 num) { else return gp->gsw[num]; } +void _swSet(s32 num) { + gp->lswf[num / 32] |= 1U << (num % 32); +} + +bool _swGet(s32 num) { + u32 mask = 1U << (num % 32); + u32 dat = gp->lswf[num / 32]; + return (bool) (mask & dat); +} + +void _swClear(s32 num) { + gp->lswf[num / 32] &= ~(1U << (num % 32)); +} + +void _swByteSet(s32 num, s8 value) { + gp->lsw[num] = (s8) value; +} + +s32 _swByteGet(s32 num) { + return gp->gsw[num]; +} + // a lot