diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 1fa19e65..fe5bc675 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -208,6 +208,11 @@ f/f_manager.cpp: .sbss start:0x80575BB8 end:0x80575BC0 .bss start:0x805B84D8 end:0x805B8588 +m/m_angle.cpp: + .text start:0x802EE5F0 end:0x802EE6B8 + .ctors start:0x804DB8CC end:0x804DB8D0 + .sbss start:0x80575C08 end:0x80575C10 + m/m_heap.cpp: .text start:0x802F0F00 end:0x802F1660 .rodata start:0x804F0570 end:0x804F0580 @@ -385,7 +390,8 @@ egg/core/eggXfbManager.cpp: egg/core/eggGraphicsFifo.cpp: .text start:0x80498E20 end:0x80498F90 - .sbss start:0x80576798 end:0x805767A8 + .data start:0x8056EB80 end:0x8056EB90 + .sbss start:0x80576798 end:0x805767A4 egg/core/eggController.cpp: .text start:0x80498F90 end:0x8049AB58 @@ -420,7 +426,9 @@ egg/math/eggVector.cpp: egg/prim/eggAssert.cpp: .text start:0x8049BF90 end:0x8049C5BC .data start:0x8056EC88 end:0x8056ED00 + .sdata start:0x80574EF0 end:0x80574F18 .sbss start:0x805767F8 end:0x80576808 + .bss start:0x80674C60 end:0x80674D68 egg/gfx/eggCamera.cpp: .text start:0x8049C5C0 end:0x8049CAC8 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index a89eb182..bc2934cf 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -17227,7 +17227,7 @@ fn_802DEF80 = .text:0x802DEF80; // type:function size:0x8 fn_802DEF90 = .text:0x802DEF90; // type:function size:0x4C fn_802DEFE0 = .text:0x802DEFE0; // type:function size:0x80 OSReport = .text:0x802DF060; // type:function size:0x80 scope:weak -vprintf = .text:0x802DF0E0; // type:function size:0x4 scope:global +OSVReport = .text:0x802DF0E0; // type:function size:0x4 scope:global fn_802DF0F0 = .text:0x802DF0F0; // type:function size:0x10 fn_802DF100 = .text:0x802DF100; // type:function size:0xA0 fn_802DF1A0 = .text:0x802DF1A0; // type:function size:0x48 @@ -17710,8 +17710,8 @@ fn_802EE4A0 = .text:0x802EE4A0; // type:function size:0x70 fn_802EE510 = .text:0x802EE510; // type:function size:0x4C adjustFrmHeapRestoreCurrent__16mHeapAllocator_cFv = .text:0x802EE560; // type:function size:0x64 fn_802EE5D0 = .text:0x802EE5D0; // type:function size:0x1C -fn_802EE5F0 = .text:0x802EE5F0; // type:function size:0xA4 -fn_802EE6A0 = .text:0x802EE6A0; // type:function size:0x18 +step__4mAngFsiss = .text:0x802EE5F0; // type:function size:0xA4 +__sinit_\m_angle_cpp = .text:0x802EE6A0; // type:function size:0x18 scope:local fn_802EE6C0 = .text:0x802EE6C0; // type:function size:0x114 fn_802EE7E0 = .text:0x802EE7E0; // type:function size:0x44 fn_802EE830 = .text:0x802EE830; // type:function size:0x58 @@ -22143,7 +22143,7 @@ fn_803B3490 = .text:0x803B3490; // type:function size:0x8 fn_803B34A0 = .text:0x803B34A0; // type:function size:0x198 fn_803B3640 = .text:0x803B3640; // type:function size:0x80C VISetPreRetraceCallback = .text:0x803B3E50; // type:function size:0x44 -fn_803B3EA0 = .text:0x803B3EA0; // type:function size:0x44 +VISetPostRetraceCallback = .text:0x803B3EA0; // type:function size:0x44 fn_803B3EF0 = .text:0x803B3EF0; // type:function size:0x118 fn_803B4010 = .text:0x803B4010; // type:function size:0x200 VIInit = .text:0x803B4210; // type:function size:0x548 @@ -24182,7 +24182,7 @@ XStrToU32___Q24nw4r2dbFPCUc = .text:0x80436D20; // type:function size:0xCC CopySymbol___Q24nw4r2dbFPCUcPUcUlUc = .text:0x80436DF0; // type:function size:0x2DC QuerySymbolToMapFile___Q24nw4r2dbFPUcPC12OSModuleInfoUlPUcUl = .text:0x804370D0; // type:function size:0xD8 QuerySymbolToSingleMapFile___Q24nw4r2dbFPQ34nw4r2db7MapFileUlPUcUl = .text:0x804371B0; // type:function size:0xF8 -MapFile_QuerySymbol__Q24nw4r2dbFUlPUcUl = .text:0x804372B0; // type:function size:0x104 +MapFile_QuerySymbol__Q24nw4r2dbFPvPcUi = .text:0x804372B0; // type:function size:0x104 Assertion_SetConsole__Q24nw4r2dbFPQ44nw4r2db6detail11ConsoleHead = .text:0x804373C0; // type:function size:0x10 FExp__Q34nw4r4math6detailFf = .text:0x804373D0; // type:function size:0xAC FLog__Q34nw4r4math6detailFf = .text:0x80437480; // type:function size:0xA4 @@ -26309,9 +26309,9 @@ isRegisterd__Q23EGG10XfbManagerCFRQ23EGG3Xfb = .text:0x80498AF0; // type:functio attach__Q23EGG10XfbManagerFPQ23EGG3Xfb = .text:0x80498B30; // type:function size:0xE0 copyEFB__Q23EGG10XfbManagerFb = .text:0x80498C10; // type:function size:0xE8 setNextFrameBuffer__Q23EGG10XfbManagerFv = .text:0x80498D00; // type:function size:0x120 -create__Q23EGG12GraphicsFifoFUlPQ23EGG4Heap = .text:0x80498E20; // type:function size:0x68 +create__Q23EGG12GraphicsFifoFUiPQ23EGG4Heap = .text:0x80498E20; // type:function size:0x68 __dt__Q23EGG12GraphicsFifoFv = .text:0x80498E90; // type:function size:0x98 -__ct__Q23EGG12GraphicsFifoFUlPQ23EGG4Heap = .text:0x80498F30; // type:function size:0x60 +__ct__Q23EGG12GraphicsFifoFUiPQ23EGG4Heap = .text:0x80498F30; // type:function size:0x60 init__Q23EGG10CoreStatusFv = .text:0x80498F90; // type:function size:0xC getFSStickButton__Q23EGG10CoreStatusCFv = .text:0x80498FA0; // type:function size:0xAC __ct__Q23EGG14CoreControllerFv = .text:0x80499050; // type:function size:0x60 @@ -26394,15 +26394,15 @@ normalise__Q23EGG8Vector3fFv = .text:0x8049BCC0; // type:function size:0x84 setLength__Q23EGG8Vector3fFRCQ23EGG8Vector3ff = .text:0x8049BD50; // type:function size:0xB8 setLength__Q23EGG8Vector3fFf = .text:0x8049BE10; // type:function size:0xA0 __sinit_\eggVector_cpp = .text:0x8049BEB0; // type:function size:0xE0 scope:local -egg_assert_waittime = .text:0x8049BF90; // type:function size:0x78 -egg_assert_vreport = .text:0x8049C010; // type:function size:0x4 -egg_assert_report = .text:0x8049C020; // type:function size:0x80 -egg_assert_get_file_name = .text:0x8049C0A0; // type:function size:0x54 -egg_assert_querySymbol = .text:0x8049C100; // type:function size:0x44 -egg_assert_isOutsideMEM1 = .text:0x8049C150; // type:function size:0x2C -egg_assert_set_callback = .text:0x8049C180; // type:function size:0x10 -egg_assert_halt = .text:0x8049C190; // type:function size:0x398 -egg_assert_assert = .text:0x8049C530; // type:function size:0x8C +wait__Q23EGG6AssertFUi = .text:0x8049BF90; // type:function size:0x78 +system_vreport__Q23EGG6AssertFPCcP16__va_list_struct = .text:0x8049C010; // type:function size:0x4 +system_report__Q23EGG6AssertFPCce = .text:0x8049C020; // type:function size:0x80 +getPeriodPos__Q23EGG6AssertFPCc = .text:0x8049C0A0; // type:function size:0x54 +getMapSymbol__Q23EGG6AssertFPv = .text:0x8049C100; // type:function size:0x44 +isOutsideMEM1__Q23EGG6AssertFUi = .text:0x8049C150; // type:function size:0x2C +setAssertCallback__Q23EGG6AssertFPFv_v = .text:0x8049C180; // type:function size:0x10 +system_halt__Q23EGG6AssertFPCcUiPCcP16__va_list_struct = .text:0x8049C190; // type:function size:0x398 +assert__Q23EGG6AssertFPCcUiPCce = .text:0x8049C530; // type:function size:0x8C FUN_8049c5c0 = .text:0x8049C5C0; // type:function size:0x10 FUN_8049c5d0 = .text:0x8049C5D0; // type:function size:0x50 FUN_8049c620 = .text:0x8049C620; // type:function size:0x44 @@ -37109,7 +37109,7 @@ __vt__Q23EGG7Display = .data:0x8056EAC8; // type:object size:0x20 __vt__Q23EGG10ColorFader = .data:0x8056EAE8; // type:object size:0x24 clear_z_TX__29@unnamed@eggAsyncDisplay_cpp@ = .data:0x8056EB20; // type:object size:0x40 scope:local __vt__Q23EGG12AsyncDisplay = .data:0x8056EB60; // type:object size:0x20 -lbl_8056EB80 = .data:0x8056EB80; // type:object size:0x10 +__vt__Q23EGG12GraphicsFifo = .data:0x8056EB80; // type:object size:0xC lbl_8056EB90 = .data:0x8056EB90; // type:object size:0x18 __vt__Q23EGG19ControllerRumbleMgr = .data:0x8056EBA8; // type:object size:0xC __vt__Q23EGG20ControllerRumbleUnit = .data:0x8056EBB4; // type:object size:0xC @@ -37119,7 +37119,12 @@ __vt__Q23EGG29TBuffer = .data:0x8056EC08; // type:object s __vt__Q23EGG32TBuffer = .data:0x8056EC24; // type:object size:0x1C __vt__Q33EGG17CoreControllerMgr11T__Disposer = .data:0x8056EC40; // type:object size:0x10 __vt__Q23EGG14CoreController = .data:0x8056EC50; // type:object size:0x38 -lbl_8056EC88 = .data:0x8056EC88; // type:object size:0x78 +lbl_8056EC88 = .data:0x8056EC88; // type:object size:0xE data:string +lbl_8056EC98 = .data:0x8056EC98; // type:object size:0x16 data:string +lbl_8056ECB0 = .data:0x8056ECB0; // type:object size:0x20 data:string +lbl_8056ECD0 = .data:0x8056ECD0; // type:object size:0xA data:string +lbl_8056ECDC = .data:0x8056ECDC; // type:object size:0xD data:string +lbl_8056ECF0 = .data:0x8056ECF0; // type:object size:0x10 data:string lbl_8056ED00 = .data:0x8056ED00; // type:object size:0x30 lbl_8056ED30 = .data:0x8056ED30; // type:object size:0x30 lbl_8056ED60 = .data:0x8056ED60; // type:object size:0x10 @@ -39587,11 +39592,11 @@ lbl_80574ED0 = .sdata:0x80574ED0; // type:object size:0x8 data:byte lbl_80574ED8 = .sdata:0x80574ED8; // type:object size:0x8 lbl_80574EE0 = .sdata:0x80574EE0; // type:object size:0x8 lbl_80574EE8 = .sdata:0x80574EE8; // type:object size:0x8 data:4byte -lbl_80574EF0 = .sdata:0x80574EF0; // type:object size:0x8 +lbl_80574EF0 = .sdata:0x80574EF0; // type:object size:0x2 data:string lbl_80574EF8 = .sdata:0x80574EF8; // type:object size:0x8 data:string lbl_80574F00 = .sdata:0x80574F00; // type:object size:0x8 data:string lbl_80574F08 = .sdata:0x80574F08; // type:object size:0x8 data:string -lbl_80574F10 = .sdata:0x80574F10; // type:object size:0x8 +lbl_80574F10 = .sdata:0x80574F10; // type:object size:0x7 data:string lbl_80574F18 = .sdata:0x80574F18; // type:object size:0x8 data:4byte lbl_80574F20 = .sdata:0x80574F20; // type:object size:0x8 lbl_80574F28 = .sdata:0x80574F28; // type:object size:0x4 @@ -40251,7 +40256,7 @@ lbl_80575BF4 = .sbss:0x80575BF4; // type:object size:0x4 data:4byte lbl_80575BF8 = .sbss:0x80575BF8; // type:object size:0x4 data:4byte lbl_80575BFC = .sbss:0x80575BFC; // type:object size:0x1 data:byte lbl_80575C00 = .sbss:0x80575C00; // type:object size:0x8 data:4byte -lbl_80575C08 = .sbss:0x80575C08; // type:object size:0x8 data:2byte +Zero__7mAng3_c = .sbss:0x80575C08; // type:object size:0x6 data:2byte lbl_80575C10 = .sbss:0x80575C10; // type:object size:0x4 data:4byte lbl_80575C14 = .sbss:0x80575C14; // type:object size:0x4 data:4byte lbl_80575C18 = .sbss:0x80575C18; // type:object size:0x4 data:4byte @@ -40895,8 +40900,8 @@ lbl_80576778 = .sbss:0x80576778; // type:object size:0x8 data:4byte mConfigData__Q23EGG10BaseSystem = .sbss:0x80576780; // type:object size:0x4 data:4byte sTickPeriod__Q23EGG7Display = .sbss:0x80576788; // type:object size:0x4 data:4byte spSelector = .sbss:0x80576790; // type:object size:0x4 data:4byte -lbl_80576798 = .sbss:0x80576798; // type:object size:0x4 data:4byte -lbl_8057679C = .sbss:0x8057679C; // type:object size:0xC +sGraphicsFifo__Q23EGG12GraphicsFifo = .sbss:0x80576798; // type:object size:0x4 data:4byte +sGpStatus__Q23EGG12GraphicsFifo = .sbss:0x8057679C; // type:object size:0x5 data:byte sInstance__Q23EGG17CoreControllerMgr = .sbss:0x805767A8; // type:object size:0x4 data:4byte sStaticDisposer__Q33EGG17CoreControllerMgr11T__Disposer = .sbss:0x805767AC; // type:object size:0x4 data:4byte sCoreControllerFactory__Q23EGG17CoreControllerMgr = .sbss:0x805767B0; // type:object size:0x4 data:4byte @@ -40910,7 +40915,7 @@ zero__Q23EGG8Vector3s = .sbss:0x805767D8; // type:object size:0x6 data:2byte ex__Q23EGG8Vector3s = .sbss:0x805767E0; // type:object size:0x6 data:2byte ey__Q23EGG8Vector3s = .sbss:0x805767E8; // type:object size:0x6 data:2byte ez__Q23EGG8Vector3s = .sbss:0x805767F0; // type:object size:0x6 data:2byte -lbl_805767F8 = .sbss:0x805767F8; // type:object size:0x4 data:4byte +sAssertCallback__Q23EGG6Assert = .sbss:0x805767F8; // type:object size:0x4 data:4byte lbl_805767FC = .sbss:0x805767FC; // type:object size:0x4 data:4byte lbl_80576800 = .sbss:0x80576800; // type:object size:0x4 data:4byte lbl_80576804 = .sbss:0x80576804; // type:object size:0x1 data:byte @@ -49355,7 +49360,7 @@ zero__Q23EGG8Vector3f = .bss:0x80674C30; // type:object size:0xC data:float ex__Q23EGG8Vector3f = .bss:0x80674C3C; // type:object size:0xC data:float ey__Q23EGG8Vector3f = .bss:0x80674C48; // type:object size:0xC data:float ez__Q23EGG8Vector3f = .bss:0x80674C54; // type:object size:0xC data:float -lbl_80674C60 = .bss:0x80674C60; // type:object size:0x108 +buf__Q23EGG6Assert = .bss:0x80674C60; // type:object size:0x108 lbl_80674D68 = .bss:0x80674D68; // type:object size:0x90 lbl_80674DF8 = .bss:0x80674DF8; // type:object size:0x30 data:float lbl_80674E28 = .bss:0x80674E28; // type:object size:0x20 diff --git a/configure.py b/configure.py index d563bc4f..a09d4edc 100644 --- a/configure.py +++ b/configure.py @@ -300,6 +300,7 @@ config.libs = [ Object(NonMatching, "f/f_base.cpp"), Object(Matching, "f/f_list.cpp"), Object(Matching, "f/f_manager.cpp"), + Object(Matching, "m/m_angle.cpp"), Object(Matching, "m/m_heap.cpp"), Object(NonMatching, "m/m_mtx.cpp"), # framework (f_name) @@ -368,8 +369,8 @@ config.libs = [ Object(Matching, "egg/core/eggXfb.cpp"), Object(Matching, "egg/core/eggVideo.cpp"), Object(Matching, "egg/core/eggXfb.cpp"), - Object(NonMatching, "egg/core/eggXfbManager.cpp"), - Object(NonMatching, "egg/core/eggGraphicsFifo.cpp"), + Object(Matching, "egg/core/eggXfbManager.cpp"), + Object(Matching, "egg/core/eggGraphicsFifo.cpp"), Object(NonMatching, "egg/core/eggController.cpp"), ], ), @@ -385,7 +386,7 @@ config.libs = [ EGGLib( "prim", [ - Object(NonMatching, "egg/prim/eggAssert.cpp"), + Object(Matching, "egg/prim/eggAssert.cpp"), ], ), # { diff --git a/include/Runtime.PPCEABI.H/__va_arg.h b/include/Runtime.PPCEABI.H/__va_arg.h index d3600d51..445bb985 100644 --- a/include/Runtime.PPCEABI.H/__va_arg.h +++ b/include/Runtime.PPCEABI.H/__va_arg.h @@ -36,5 +36,6 @@ void *__va_arg(_va_list_struct *, int); #define __va_end(list) ((void)0) #define __va_copy(a, b) (*(a) = *(b)) +#define va_copy __va_copy #endif /* __VA_ARG_H */ diff --git a/include/egg/core/eggGraphicsFifo.h b/include/egg/core/eggGraphicsFifo.h index 0e060401..8226aa90 100644 --- a/include/egg/core/eggGraphicsFifo.h +++ b/include/egg/core/eggGraphicsFifo.h @@ -22,7 +22,7 @@ public: public: /* 80576798 */ static GraphicsFifo *sGraphicsFifo; - /* 8057679c */ static bool sGpStatus[4]; + /* 8057679c */ static u8 sGpStatus[5]; }; } // namespace EGG diff --git a/include/egg/core/eggXfbManager.h b/include/egg/core/eggXfbManager.h index a0895d85..948b0349 100644 --- a/include/egg/core/eggXfbManager.h +++ b/include/egg/core/eggXfbManager.h @@ -14,7 +14,7 @@ public: /* 0xC */ u8 mNumXfbs; // Total number of Xfbs ever attached /* 0xD */ u8 mNumXfbs_Copy; // Unsure of purpose yet, but showing wont proceed until its under 3 public: - /* 80498af0 */ bool isRegisterd(Xfb *xfb) const; // yes. this is correct spelling + /* 80498af0 */ bool isRegisterd(Xfb &xfb) const; // yes. this is correct spelling /* 80498b30 */ bool attach(Xfb *xfb); /* 80498c10 */ void copyEFB(bool); /* 80498d00 */ void setNextFrameBuffer(); diff --git a/include/egg/prim/eggAssert.h b/include/egg/prim/eggAssert.h index 0910f203..147847b9 100644 --- a/include/egg/prim/eggAssert.h +++ b/include/egg/prim/eggAssert.h @@ -8,14 +8,17 @@ namespace EGG { // TODO: Fixup funtions namespace Assert { +typedef void (*AssertCallback)(); + /* 8049bf90 */ void wait(u32 time); -/* 8049c010 */ void system_print(); -/* 8049c010 */ void system_report(); -/* 8049c0a0 */ s32 getPeriodPos(char *); +/* 8049c010 */ void system_vreport(const char *str, va_list list); +/* 8049c010 */ void system_report(const char *str, ...); +/* 8049c0a0 */ s32 getPeriodPos(const char *); /* 8049c100 */ char *getMapSymbol(); /* 8049c150 */ bool isOutsideMEM1(u32 addr); -/* 8049c190 */ void system_halt(); -/* 8049c530 */ void assert(); +/* 8049c180 */ AssertCallback setAssertCallback(AssertCallback cb); +/* 8049c190 */ void system_halt(const char *file, u32 line, const char *msg, va_list list); +/* 8049c530 */ void assert(const char *file, u32 line, const char *msg, ...); } // namespace Assert diff --git a/include/m/m_angle.h b/include/m/m_angle.h index 29a20d18..37fca394 100644 --- a/include/m/m_angle.h +++ b/include/m/m_angle.h @@ -5,18 +5,25 @@ struct mAng { mAng() {} - mAng(s16 s) : val(s) {} - s16 val; + mAng(s16 s) : mVal(s) {} + + s32 step(s16 target, s32 steps, s16 max, s16 min); + + s16 mVal; }; class mAng3_c { public: s16 x, y, z; + mAng3_c(s16 fx, s16 fy, s16 fz) : x(fx), y(fy), z(fz) {} + void set(s16 fx, s16 fy, s16 fz) { x = fx; y = fy; z = fz; } + + static mAng3_c Zero; }; #endif diff --git a/include/rvl/GX/GXFrameBuf.h b/include/rvl/GX/GXFrameBuf.h index f21de91f..7e8592b5 100644 --- a/include/rvl/GX/GXFrameBuf.h +++ b/include/rvl/GX/GXFrameBuf.h @@ -28,6 +28,7 @@ f32 GXGetYScaleFactor(u16 height, u16 width); u16 GXGetNumXfbLines(u16 height, f32 scale); void GXSetDispCopyDst(u16 width, u16 height); u32 GXSetDispCopyYScale(f32 scale); +void GXCopyDisp(void *data, GXBool bUpdate); extern GXRenderModeObj GXNtsc480IntDf; extern GXRenderModeObj GXMpal480IntDf; diff --git a/include/rvl/OS/OSError.h b/include/rvl/OS/OSError.h index 64ce47e1..ac9ece4b 100644 --- a/include/rvl/OS/OSError.h +++ b/include/rvl/OS/OSError.h @@ -1,6 +1,7 @@ #ifndef RVL_SDK_OS_ERROR_H #define RVL_SDK_OS_ERROR_H #include +#include #ifdef __cplusplus extern "C" { #endif @@ -41,6 +42,7 @@ extern OSErrorHandler __OSErrorTable[OS_ERR_MAX]; extern u32 __OSFpscrEnableBits; DECL_WEAK void OSReport(const char *msg, ...); +DECL_WEAK void OSVReport(const char *msg, va_list args); DECL_WEAK void OSPanic(const char *file, int line, const char *msg, ...); OSErrorHandler OSSetErrorHandler(u16 error, OSErrorHandler handler); diff --git a/src/egg/core/eggGraphicsFifo.cpp b/src/egg/core/eggGraphicsFifo.cpp new file mode 100644 index 00000000..bb937d13 --- /dev/null +++ b/src/egg/core/eggGraphicsFifo.cpp @@ -0,0 +1,35 @@ +#include +#include +#include + + +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 diff --git a/src/egg/core/eggXfbManager.cpp b/src/egg/core/eggXfbManager.cpp new file mode 100644 index 00000000..46ab8d2a --- /dev/null +++ b/src/egg/core/eggXfbManager.cpp @@ -0,0 +1,108 @@ +#include +#include +#include +#include +#include + +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 diff --git a/src/egg/prim/eggAssert.cpp b/src/egg/prim/eggAssert.cpp new file mode 100644 index 00000000..dc9e44a3 --- /dev/null +++ b/src/egg/prim/eggAssert.cpp @@ -0,0 +1,202 @@ +#include +#include +#include +#include +#include +#include +#include +#include + + +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 diff --git a/src/m/m_angle.cpp b/src/m/m_angle.cpp new file mode 100644 index 00000000..a9e9474f --- /dev/null +++ b/src/m/m_angle.cpp @@ -0,0 +1,30 @@ +#include + +/** 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; +}