2020-10-22 12:19:57 -04:00
|
|
|
#include "iSystem.h"
|
|
|
|
|
|
|
|
|
|
#include <types.h>
|
|
|
|
|
|
2020-10-23 16:07:59 -04:00
|
|
|
#include <rwcore.h>
|
|
|
|
|
|
|
|
|
|
#include "../x/xDebug.h"
|
|
|
|
|
#include "../x/xMath.h"
|
|
|
|
|
#include "../x/xSnd.h"
|
|
|
|
|
#include "../x/xPad.h"
|
|
|
|
|
#include "../x/xMemMgr.h"
|
|
|
|
|
|
|
|
|
|
#include "iSystem.h"
|
|
|
|
|
#include "iFile.h"
|
|
|
|
|
#include "iTime.h"
|
2021-02-14 21:12:26 -05:00
|
|
|
#include "iTRC.h"
|
2020-10-23 16:07:59 -04:00
|
|
|
|
|
|
|
|
extern uint32 mem_base_alloc;
|
|
|
|
|
extern uint32 add;
|
|
|
|
|
extern uint32 size;
|
|
|
|
|
extern int32 gEmergencyMemLevel;
|
2021-01-10 17:43:04 -06:00
|
|
|
extern OSHeapHandle the_heap;
|
2020-10-23 16:07:59 -04:00
|
|
|
extern void* bad_val;
|
2021-02-14 21:12:26 -05:00
|
|
|
extern void* MemoryFunctions[4];
|
|
|
|
|
extern uint16 last_error;
|
|
|
|
|
extern OSContext* last_context;
|
2020-10-23 16:07:59 -04:00
|
|
|
|
2021-02-14 21:12:26 -05:00
|
|
|
void** psGetMemoryFunctions()
|
|
|
|
|
{
|
|
|
|
|
return MemoryFunctions;
|
|
|
|
|
}
|
2020-10-22 12:19:57 -04:00
|
|
|
|
2021-02-14 21:12:26 -05:00
|
|
|
void iVSync()
|
|
|
|
|
{
|
|
|
|
|
VIWaitForRetrace();
|
|
|
|
|
}
|
2020-10-22 12:19:57 -04:00
|
|
|
|
2021-02-14 21:12:26 -05:00
|
|
|
uint16 my_dsc(uint16 dsc)
|
|
|
|
|
{
|
|
|
|
|
return dsc;
|
|
|
|
|
}
|
2020-10-23 15:29:37 -04:00
|
|
|
|
|
|
|
|
// func_800D30E4
|
|
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "FloatingPointErrorHandler__FUsP9OSContextUlUl")
|
|
|
|
|
|
|
|
|
|
// func_800D32BC
|
2021-02-14 21:12:26 -05:00
|
|
|
//#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "MemoryProtectionErrorHandler__FUsP9OSContextUlUl")
|
|
|
|
|
|
|
|
|
|
void MemoryProtectionErrorHandler(uint16 last, OSContext* ctx, uint64 unk1, uint64 unk2)
|
|
|
|
|
{
|
|
|
|
|
last_error = last;
|
|
|
|
|
last_context = ctx;
|
|
|
|
|
if (ctx->fpscr)
|
|
|
|
|
{
|
|
|
|
|
null_func();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if 1
|
2020-10-23 15:29:37 -04:00
|
|
|
|
|
|
|
|
// func_800D32F0
|
2020-10-22 12:19:57 -04:00
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "TRCInit__Fv")
|
|
|
|
|
|
2021-02-14 21:12:26 -05:00
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
// WIP.
|
|
|
|
|
void TRCInit()
|
|
|
|
|
{
|
|
|
|
|
iTRCDisk::Init();
|
|
|
|
|
iTRCDisk::SetPadStopRumblingFunction(iPadStopRumble);
|
|
|
|
|
iTRCDisk::SetSndSuspendFunction(iSndSuspend);
|
|
|
|
|
iTRCDisk::SetSndResumeFunction(iSndResume);
|
|
|
|
|
iTRCDisk::SetSndKillFunction(iSndDIEDIEDIE);
|
|
|
|
|
iTRCDisk::SetMovieSuspendFunction(iFMV::Suspend);
|
|
|
|
|
iTRCDisk::SetMovieResumeFunction(iFMV::Resume);
|
|
|
|
|
ResetButton::SetSndKillFunction(iSndDIEDIEDIE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-10-23 15:29:37 -04:00
|
|
|
// func_800D3364
|
2020-10-22 12:19:57 -04:00
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "iSystemInit__FUi")
|
|
|
|
|
|
2020-10-23 16:07:59 -04:00
|
|
|
/*
|
|
|
|
|
void iSystemExit()
|
|
|
|
|
{
|
|
|
|
|
xDebugExit();
|
|
|
|
|
xMathExit();
|
|
|
|
|
RenderWareExit();
|
|
|
|
|
xSndExit();
|
|
|
|
|
xPadKill();
|
|
|
|
|
iFileExit();
|
|
|
|
|
iTimeExit();
|
|
|
|
|
xMemExit();
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
2020-10-23 15:29:37 -04:00
|
|
|
// func_800D344C
|
2020-10-22 12:19:57 -04:00
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "iSystemExit__Fv")
|
|
|
|
|
|
2020-10-23 15:29:37 -04:00
|
|
|
// func_800D34A4
|
2020-10-22 12:19:57 -04:00
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "RWAttachPlugins__Fv")
|
|
|
|
|
|
2020-10-23 15:29:37 -04:00
|
|
|
// func_800D3544
|
2020-10-22 12:19:57 -04:00
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "RenderWareInit__Fv")
|
|
|
|
|
|
2020-10-23 16:07:59 -04:00
|
|
|
int32 RenderWareExit()
|
|
|
|
|
{
|
|
|
|
|
RwEngineStop();
|
|
|
|
|
RwEngineClose();
|
2021-01-03 17:42:27 -06:00
|
|
|
return RwEngineTerm();
|
2020-10-23 16:07:59 -04:00
|
|
|
}
|
2020-10-22 12:19:57 -04:00
|
|
|
|
2020-10-23 15:29:37 -04:00
|
|
|
// func_800D3664
|
|
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "TextureRead__FPCcPCc")
|
|
|
|
|
|
2020-10-23 16:07:59 -04:00
|
|
|
void null_func()
|
|
|
|
|
{
|
|
|
|
|
mem_base_alloc += 4;
|
|
|
|
|
}
|
2020-10-22 12:19:57 -04:00
|
|
|
|
2020-10-23 16:07:59 -04:00
|
|
|
extern "C" {
|
|
|
|
|
void mem_null(uint32 param_1, uint32 param_2)
|
|
|
|
|
{
|
|
|
|
|
add = param_1;
|
|
|
|
|
size = param_2;
|
|
|
|
|
}
|
2020-10-22 12:19:57 -04:00
|
|
|
|
2020-10-23 16:07:59 -04:00
|
|
|
void* malloc(uint32 __size)
|
|
|
|
|
{
|
|
|
|
|
if ((int32)__size <= 0)
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2020-10-22 12:19:57 -04:00
|
|
|
|
2020-10-23 16:07:59 -04:00
|
|
|
void* result = OSAllocFromHeap(the_heap, __size);
|
2020-10-22 12:19:57 -04:00
|
|
|
|
2020-10-23 16:07:59 -04:00
|
|
|
if (result == NULL)
|
|
|
|
|
{
|
|
|
|
|
null_func();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void free(void* __ptr)
|
|
|
|
|
{
|
|
|
|
|
if (__ptr != NULL)
|
|
|
|
|
{
|
|
|
|
|
OSFreeToHeap(the_heap, __ptr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _rwDolphinHeapFree(void* __ptr)
|
|
|
|
|
{
|
|
|
|
|
if (__ptr == bad_val)
|
|
|
|
|
{
|
|
|
|
|
mem_null(0, 0);
|
|
|
|
|
}
|
|
|
|
|
if (__ptr != NULL)
|
|
|
|
|
{
|
|
|
|
|
// TODO: clear this up
|
|
|
|
|
// some number is compared against 0xbeef in the assembly.
|
|
|
|
|
// 0xbeef was probably a hardcoded constant Heavy iron used.
|
|
|
|
|
// if (*(uint32*)((int32)__ptr + -4) + 0x2153 == 0xbeef)
|
|
|
|
|
if (*(int32*)((int32)__ptr + -4) == -0x21524111)
|
|
|
|
|
{
|
|
|
|
|
free((void*)((int32)__ptr - 32));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
null_func();
|
|
|
|
|
if (gEmergencyMemLevel != 0)
|
|
|
|
|
{
|
|
|
|
|
xMemPopBase(gEmergencyMemLevel);
|
|
|
|
|
gEmergencyMemLevel = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-22 12:19:57 -04:00
|
|
|
|
2020-10-23 15:29:37 -04:00
|
|
|
// func_800D3840
|
2020-10-22 12:19:57 -04:00
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "_rwDolphinHeapAlloc__FUl")
|
|
|
|
|
|
2020-10-23 15:29:37 -04:00
|
|
|
// func_800D3910
|
|
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "_rwDolphinHeapCalloc__FUlUl")
|
|
|
|
|
|
|
|
|
|
// func_800D3960
|
|
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "_rwDolphinHeapRealloc__FPvUl")
|
|
|
|
|
|
|
|
|
|
// func_800D3A04
|
2020-10-22 12:19:57 -04:00
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "DolphinInitMemorySystem__FP17RwMemoryFunctions")
|
|
|
|
|
|
2020-10-23 15:29:37 -04:00
|
|
|
// func_800D3A3C
|
2020-10-22 12:19:57 -04:00
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "dlAccessToMode__FPCc")
|
|
|
|
|
|
2020-10-23 15:29:37 -04:00
|
|
|
// func_800D3B9C
|
|
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "dlFopen__FPCcPCc")
|
|
|
|
|
|
|
|
|
|
// func_800D3CC8
|
|
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "dlFclose__FPv")
|
|
|
|
|
|
|
|
|
|
// func_800D3D48
|
|
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "dlFexist__FPCc")
|
|
|
|
|
|
|
|
|
|
// func_800D3DB8
|
2020-10-22 12:19:57 -04:00
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "dlFread__FPvUlUlPv")
|
|
|
|
|
|
2020-10-23 15:29:37 -04:00
|
|
|
// func_800D3FDC
|
|
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "dlFwrite__FPCvUlUlPv")
|
|
|
|
|
|
|
|
|
|
// func_800D3FE4
|
2020-10-22 12:19:57 -04:00
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "dlFseek__FPvli")
|
|
|
|
|
|
2020-10-23 15:29:37 -04:00
|
|
|
// func_800D4188
|
|
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "dlFgets__FPciPv")
|
|
|
|
|
|
|
|
|
|
// func_800D428C
|
|
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "dlFputs__FPCcPv")
|
|
|
|
|
|
|
|
|
|
// func_800D4294
|
|
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "dlFeof__FPv")
|
|
|
|
|
|
|
|
|
|
// func_800D42B4
|
|
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "dlFflush__FPv")
|
|
|
|
|
|
|
|
|
|
// func_800D42BC
|
|
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "dlFtell__FPv")
|
|
|
|
|
|
|
|
|
|
// func_800D42C4
|
|
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "_rwDolphinFSOpen__FPvii")
|
|
|
|
|
|
|
|
|
|
// func_800D43EC
|
2020-10-22 12:19:57 -04:00
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "__as__15RwFileFunctionsFRC15RwFileFunctions")
|
|
|
|
|
|
2020-10-23 15:29:37 -04:00
|
|
|
// func_800D4448
|
|
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "_rwDolphinFSClose__FPvii")
|
|
|
|
|
|
|
|
|
|
// func_800D44AC
|
2020-10-22 12:19:57 -04:00
|
|
|
#pragma GLOBAL_ASM("asm/Core/p2/iSystem.s", "DolphinInstallFileSystem__Fv")
|