mirror of
https://github.com/zeldaret/ss
synced 2026-08-01 16:19:28 -04:00
Merge branch 'main' into pr/20
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#include <rvl/GX.h>
|
||||
#include <egg/core/eggGraphicsFifo.h>
|
||||
#include <egg/core/eggHeap.h>
|
||||
|
||||
|
||||
extern "C" void *GXInit(void *buf, u32 bufSize);
|
||||
extern "C" void GXGetGPStatus(GXBool *overhi, GXBool *underlow, GXBool *readIdle, GXBool *cmdIdle, GXBool *brkpt);
|
||||
|
||||
namespace EGG {
|
||||
|
||||
|
||||
GraphicsFifo *GraphicsFifo::sGraphicsFifo;
|
||||
u8 GraphicsFifo::sGpStatus[];
|
||||
|
||||
void GraphicsFifo::create(u32 size, Heap *heap) {
|
||||
if (heap == nullptr) {
|
||||
heap = Heap::sCurrentHeap;
|
||||
}
|
||||
sGraphicsFifo = new(heap, 0x04) GraphicsFifo(size, heap);
|
||||
}
|
||||
|
||||
GraphicsFifo::~GraphicsFifo() {
|
||||
do {
|
||||
GXGetGPStatus(&sGpStatus[0], &sGpStatus[1], &sGpStatus[2], &sGpStatus[3], &sGpStatus[4]);
|
||||
} while (sGpStatus[2] == false);
|
||||
Heap::free(mBuffBase, nullptr);
|
||||
}
|
||||
|
||||
GraphicsFifo::GraphicsFifo(u32 size, Heap *heap) {
|
||||
mBufSize = ROUND_UP(size, 0x20);
|
||||
mBuffBase = Heap::alloc(mBufSize, 0x20, heap);
|
||||
mGxInitData = GXInit(mBuffBase, mBufSize);
|
||||
}
|
||||
|
||||
} // namespace EGG
|
||||
@@ -0,0 +1,108 @@
|
||||
#include <common.h>
|
||||
#include <egg/core/eggXfb.h>
|
||||
#include <egg/core/eggXfbManager.h>
|
||||
#include <nw4r/db/db_directPrint.h>
|
||||
#include <rvl/VI/vi.h>
|
||||
|
||||
namespace EGG {
|
||||
|
||||
/* 80498af0 */ bool XfbManager::isRegisterd(Xfb &xfb) const {
|
||||
Xfb *x = mNextXfb;
|
||||
Xfb *iter = x;
|
||||
|
||||
if (mNextXfb != nullptr) {
|
||||
do {
|
||||
if (iter == &xfb) {
|
||||
return true;
|
||||
}
|
||||
iter = iter->mNext;
|
||||
} while (iter != x);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* 80498b30 */ bool XfbManager::attach(Xfb *xfb) {
|
||||
int interrupts = OSDisableInterrupts();
|
||||
bool u3 = 0;
|
||||
|
||||
if (xfb != nullptr && !isRegisterd(*xfb)) {
|
||||
xfb->mState = Xfb::XFB_UNPROCESSED;
|
||||
if (mNextXfb == nullptr) {
|
||||
mNextXfb = xfb;
|
||||
mToCopyXfb = xfb;
|
||||
xfb->mNext = xfb;
|
||||
xfb->mPrev = xfb;
|
||||
} else {
|
||||
mNextXfb->mPrev->mNext = xfb;
|
||||
xfb->mPrev = mNextXfb->mPrev;
|
||||
mNextXfb->mPrev = xfb;
|
||||
xfb->mNext = mNextXfb;
|
||||
}
|
||||
u3 = 1;
|
||||
mNumXfbs += 1;
|
||||
mNumXfbs_Copy += 1;
|
||||
}
|
||||
OSRestoreInterrupts(interrupts);
|
||||
return u3;
|
||||
}
|
||||
/* 80498c10 */ void XfbManager::copyEFB(bool bUpdate) {
|
||||
if (mNumXfbs == 1 && mToCopyXfb == nullptr) {
|
||||
mToCopyXfb = mNextXfb;
|
||||
}
|
||||
|
||||
if (mToCopyXfb != nullptr) {
|
||||
if (bUpdate) {
|
||||
GXSetZMode(true, GX_ALWAYS, true);
|
||||
GXSetAlphaUpdate(true);
|
||||
GXSetColorUpdate(true);
|
||||
}
|
||||
|
||||
GXCopyDisp(mToCopyXfb->mBuffer, bUpdate);
|
||||
|
||||
GXFlush();
|
||||
GXDrawDone();
|
||||
u32 interrupts = OSDisableInterrupts();
|
||||
mToCopyXfb->mState = Xfb::XFB_COPIED;
|
||||
if (mToShowXfb == nullptr) {
|
||||
mToShowXfb = mToCopyXfb;
|
||||
}
|
||||
|
||||
Xfb *next = mToCopyXfb->mNext->mState == Xfb::XFB_UNPROCESSED ? mToCopyXfb->mNext : nullptr;
|
||||
mToCopyXfb = next;
|
||||
OSRestoreInterrupts(interrupts);
|
||||
}
|
||||
}
|
||||
|
||||
/* 80498d00 */ void XfbManager::setNextFrameBuffer() {
|
||||
if (mToShowXfb != nullptr) {
|
||||
if (mNumXfbs_Copy > 2) {
|
||||
mNumXfbs_Copy -= 1;
|
||||
} else {
|
||||
VISetNextFrameBuffer(mToShowXfb->mBuffer);
|
||||
VIFlush();
|
||||
nw4r::db::DirectPrint_ChangeXfb(mToShowXfb->mBuffer, mToShowXfb->mWidth, mToShowXfb->mHeight);
|
||||
if (mNumXfbs > 1) {
|
||||
mNextXfb->mState = Xfb::XFB_UNPROCESSED;
|
||||
if (mToCopyXfb == nullptr) {
|
||||
mToCopyXfb = mNextXfb;
|
||||
}
|
||||
mToShowXfb->mState = Xfb::XFB_SHOWN;
|
||||
mNextXfb = mToShowXfb;
|
||||
mToShowXfb = mToShowXfb->mNext->mState == Xfb::XFB_COPIED ? mToShowXfb->mNext : nullptr;
|
||||
} else {
|
||||
mToShowXfb->mState = Xfb::XFB_UNPROCESSED;
|
||||
if (mToCopyXfb == nullptr) {
|
||||
mToCopyXfb = mToShowXfb;
|
||||
}
|
||||
mToShowXfb = nullptr;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (mNumXfbs == 1 && mNextXfb != nullptr) {
|
||||
mNextXfb->mState = Xfb::XFB_UNPROCESSED;
|
||||
mToCopyXfb = mNextXfb;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace EGG
|
||||
@@ -0,0 +1,202 @@
|
||||
#include <Runtime.PPCEABI.H/__va_arg.h>
|
||||
#include <egg/core/eggSystem.h>
|
||||
#include <egg/core/eggXfbManager.h>
|
||||
#include <egg/prim/eggAssert.h>
|
||||
#include <nw4r/db/db_directPrint.h>
|
||||
#include <rvl/OS.h>
|
||||
#include <rvl/VI.h>
|
||||
#include <MSL_C/string.h>
|
||||
|
||||
|
||||
namespace nw4r {
|
||||
namespace db {
|
||||
// TODO
|
||||
extern s32 MapFile_QuerySymbol(void *arg, char *buf, u32 buf_size);
|
||||
} // namespace db
|
||||
} // namespace nw4r
|
||||
|
||||
namespace EGG {
|
||||
|
||||
namespace Assert {
|
||||
|
||||
AssertCallback sAssertCallback;
|
||||
AssertCallback sAssertCallback2;
|
||||
u32 sPtrOverride;
|
||||
bool sInstantHalt;
|
||||
bool sAssertOccurred;
|
||||
|
||||
/* 8049bf90 */ void wait(u32 time) {
|
||||
u32 tick = OSGetTick();
|
||||
u32 tick2;
|
||||
do {
|
||||
tick2 = OSGetTick();
|
||||
} while ((tick2 - tick) / (OS_BUS_CLOCK_SPEED / 4 / 1000) < time);
|
||||
}
|
||||
|
||||
// extern "C" void OSVReport(const char *str, va_list list);
|
||||
|
||||
/* 8049c010 */ void system_vreport(const char *str, va_list list) {
|
||||
OSVReport(str, list);
|
||||
}
|
||||
/* 8049c010 */ void system_report(const char *str, ...) {
|
||||
va_list l;
|
||||
va_start(l, str);
|
||||
system_vreport(str, l);
|
||||
va_end(l);
|
||||
}
|
||||
/* 8049c0a0 */ s32 getPeriodPos(const char *str) {
|
||||
char *b = strchr(str, '.');
|
||||
s32 len;
|
||||
if (b == nullptr) {
|
||||
len = strlen(str);
|
||||
} else {
|
||||
len = b - str;
|
||||
}
|
||||
|
||||
if (len > 0xff) {
|
||||
return 0xff;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
/* 80674c60 */ char buf[260];
|
||||
|
||||
/* 8049c100 */ const char *getMapSymbol(void *arg) {
|
||||
u32 success = nw4r::db::MapFile_QuerySymbol(arg, buf, sizeof(buf));
|
||||
return success ? buf : nullptr;
|
||||
}
|
||||
|
||||
/* 8049c150 */ bool isOutsideMEM1(u32 addr) {
|
||||
if (!(0x80000000 <= addr) || !(addr <= 0x83000000 - 1)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* 8049c180 */ AssertCallback setAssertCallback(AssertCallback cb) {
|
||||
AssertCallback old = sAssertCallback;
|
||||
sAssertCallback = cb;
|
||||
return old;
|
||||
}
|
||||
|
||||
/* 8049c190 */ void system_halt(const char *file, u32 line, const char *msg, va_list list) {
|
||||
if (sAssertOccurred) {
|
||||
#line 152
|
||||
OSError("Recursive assertioned");
|
||||
}
|
||||
|
||||
sAssertOccurred = true;
|
||||
if (sAssertCallback != nullptr) {
|
||||
sAssertCallback();
|
||||
}
|
||||
VISetPreRetraceCallback(nullptr);
|
||||
VISetPostRetraceCallback(nullptr);
|
||||
system_report("\n---------- HALT -------------\n");
|
||||
s32 pos = getPeriodPos(file);
|
||||
system_report("%.*s(%d):", pos, file, line);
|
||||
va_list args;
|
||||
va_copy(args, list);
|
||||
system_vreport(msg, args);
|
||||
system_report("\n");
|
||||
u32 *stackp = (u32 *)OSGetStackPointer();
|
||||
if (sPtrOverride != 0) {
|
||||
stackp = (u32*)((u32*)sPtrOverride)[1];
|
||||
}
|
||||
u32 *stack = stackp;
|
||||
|
||||
s32 num = 0;
|
||||
for (s32 num = 0; num < 0x1e; num++) {
|
||||
if (isOutsideMEM1((u32)stack)) {
|
||||
break;
|
||||
}
|
||||
const char *sym = getMapSymbol((void *)stack[1]);
|
||||
if (sym != nullptr) {
|
||||
system_report("%d: %s\n", num, sym);
|
||||
} else {
|
||||
system_report("%d: %p\n", num, stack[1]);
|
||||
}
|
||||
stack = (u32*)stack[0];
|
||||
if (isOutsideMEM1((u32)stack)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (sInstantHalt == 0) {
|
||||
VISetBlack(false);
|
||||
VIFlush();
|
||||
nw4r::db::DirectPrint_Init();
|
||||
nw4r::db::detail::DirectPrint_SetupFB(0);
|
||||
Xfb *fb = BaseSystem::mConfigData->getXfbMgr()->mToShowXfb;
|
||||
if (fb == nullptr) {
|
||||
fb = BaseSystem::mConfigData->getXfbMgr()->mNextXfb;
|
||||
}
|
||||
|
||||
if (fb == nullptr) {
|
||||
#line 239
|
||||
OSError("Program Halt");
|
||||
}
|
||||
|
||||
// Random float conversion here for no reason
|
||||
f32 wid = fb->mWidth;
|
||||
nw4r::db::DirectPrint_EraseXfb(0, 0, fb->mWidth, fb->mHeight);
|
||||
nw4r::db::DirectPrint_StoreCache();
|
||||
OSDisableInterrupts();
|
||||
OSDisableScheduler();
|
||||
OSEnableInterrupts();
|
||||
while (true) {
|
||||
nw4r::db::DirectPrint_EraseXfb(0, 0, fb->mWidth, fb->mHeight);
|
||||
nw4r::db::DirectPrint_StoreCache();
|
||||
nw4r::db::DirectPrint_Printf(2, 2, "%.*s:%d", pos, file, line);
|
||||
va_list args;
|
||||
va_copy(args, list);
|
||||
nw4r::db::DirectPrint_printfsub(2, 0xe, msg, args);
|
||||
nw4r::db::DirectPrint_StoreCache();
|
||||
|
||||
s32 line;
|
||||
u32 *stack = stackp;
|
||||
s32 counter;
|
||||
|
||||
for (counter = 0, line = 0x1a; counter < 0x10; counter++) {
|
||||
if (isOutsideMEM1((u32)stack)) {
|
||||
break;
|
||||
}
|
||||
const char *sym = getMapSymbol((void*)stack[1]);
|
||||
if (sym != nullptr) {
|
||||
nw4r::db::DirectPrint_Printf(2, line, "%d:%s\n", counter, sym);
|
||||
} else {
|
||||
nw4r::db::DirectPrint_Printf(2, line, "LR Save[%d]:%p\n", counter, (void*)stack[1]);
|
||||
}
|
||||
nw4r::db::DirectPrint_StoreCache();
|
||||
stack = (u32*)*stack;
|
||||
if (isOutsideMEM1((u32)stack)) {
|
||||
break;
|
||||
}
|
||||
line += 0xc;
|
||||
}
|
||||
nw4r::db::DirectPrint_StoreCache();
|
||||
wait(4000);
|
||||
if (sAssertCallback2 == nullptr) {
|
||||
goto end;
|
||||
}
|
||||
nw4r::db::DirectPrint_EraseXfb(0, 0, fb->mWidth, fb->mHeight);
|
||||
(sAssertCallback2)();
|
||||
nw4r::db::DirectPrint_StoreCache();
|
||||
wait(4000);
|
||||
}
|
||||
}
|
||||
end:
|
||||
#line 315
|
||||
OSError("Program Halt");
|
||||
return;
|
||||
}
|
||||
/* 8049c530 */ void assert(const char *file, u32 line, const char *msg, ...) {
|
||||
va_list l;
|
||||
va_start(l, msg);
|
||||
system_halt(file, line, msg, l);
|
||||
va_end(l);
|
||||
}
|
||||
|
||||
} // namespace Assert
|
||||
|
||||
} // namespace EGG
|
||||
@@ -0,0 +1,30 @@
|
||||
#include <m/m_angle.h>
|
||||
|
||||
/** 80575c08 */
|
||||
mAng3_c mAng3_c::Zero = mAng3_c::mAng3_c(0, 0, 0);
|
||||
|
||||
/** 802ee5f0 */
|
||||
s32 mAng::step(s16 target, s32 steps, s16 max, s16 min) {
|
||||
if (mVal != target) {
|
||||
int stepSize;
|
||||
int diff = target - mVal;
|
||||
stepSize = diff / steps;
|
||||
if (stepSize > min || stepSize < -min) {
|
||||
mVal += stepSize < -max ? -max : stepSize > max ? max : stepSize;
|
||||
} else if (diff >= 0) {
|
||||
if (mVal + min >= target) {
|
||||
mVal = target;
|
||||
} else {
|
||||
mVal += min;
|
||||
}
|
||||
} else {
|
||||
if (mVal - min <= target) {
|
||||
mVal = target;
|
||||
} else {
|
||||
mVal -= min;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return target - mVal;
|
||||
}
|
||||
Reference in New Issue
Block a user