2#include <game/bases/d_system.hpp>
3#include <game/bases/d_2d.hpp>
5#include <game/bases/d_dvd.hpp>
6#include <game/bases/d_dvd_err.hpp>
7#include <game/bases/d_dylink.hpp>
8#include <game/bases/d_effectmanager.hpp>
9#include <game/bases/d_fader.hpp>
10#include <game/bases/d_font_manager.hpp>
11#include <game/bases/d_game_key.hpp>
12#include <game/bases/d_graph.hpp>
13#include <game/bases/d_hbm.hpp>
14#include <game/bases/d_nand_thread.hpp>
15#include <game/bases/d_message.hpp>
16#include <game/bases/d_pad.hpp>
17#include <game/bases/d_remocon_manager.hpp>
18#include <game/bases/d_reset.hpp>
19#include <game/bases/d_rom_font_manager.hpp>
20#include <game/bases/d_s_stage.hpp>
21#include <game/bases/d_save_mng.hpp>
22#include <game/cLib/c_counter.hpp>
23#include <game/mLib/m_3d.hpp>
24#include <game/mLib/m_allocator.hpp>
25#include <game/mLib/m_heap.hpp>
26#include <game/mLib/m_pad.hpp>
27#include <game/mLib/m_video.hpp>
28#include <game/sLib/s_Phase.hpp>
29#include <lib/egg/core/eggSystem.h>
30#include <lib/egg/core/eggTextureBuffer.h>
31#include <lib/revolution/KPAD.h>
32#include <lib/revolution/VI.h>
33#include <constants/sjis_constants.h>
35const char dSystem::sc_EffectManagerHeap1Name[] = EFFECT_HEAP_1_NAME;
36const char dSystem::sc_EffectManagerHeap2Name[] = EFFECT_HEAP_2_NAME;
38EGG::Heap *dSystem::s_EffectManagerHeap1;
39EGG::Heap *dSystem::s_EffectManagerHeap2;
41OSThread *s_MainThread;
43template<> EGG::TSystem<>::Configuration *EGG::TSystem<>::sConfiguration =
nullptr;
45static EGG::TSystem<>::Configuration s_configuration;
47EGG::Heap *dSys_c::ms_RootHeapMem1;
48EGG::Heap *dSys_c::ms_RootHeapMem2;
50const char dSystem::sc_FontManagerHeapName[] = FONT_MANAGER_HEAP_NAME;
51EGG::Heap *dSystem::s_FontManagerHeap;
53void dSystem::createEffectManagerHeap(EGG::Heap *heap1, EGG::Heap *heap2) {
58void dSys_c::beginRender() {
59 EGG::TSystem<>::sConfiguration->mpDisplay->beginRender();
62class dummy_unused_static_local {
64 dummy_unused_static_local() {}
69void dSys_c::endRender() {
74 EGG::TSystem<>::sConfiguration->mpDisplay->endRender();
78 EGG::TSystem<>::sConfiguration->mpDisplay->beginFrame();
79 EGG::TSystem<>::sConfiguration->onBeginFrame();
83 EGG::TSystem<>::sConfiguration->mpDisplay->endFrame();
84 EGG::TSystem<>::sConfiguration->onEndFrame();
87bool dSys_c::setBlack(
bool makeBlack) {
88 EGG::Display *display = EGG::TSystem<>::sConfiguration->mpDisplay;
89 EGG::Video *video = EGG::BaseSystem::mConfigData->getVideo();
90 if (makeBlack != video->isBlack() && (display->mScreenStateFlag & 1) == 0) {
91 display->mScreenStateFlag |= 1;
97void dSys_c::calcAudio() {
101void dSys_c::setFrameRate(u8 rate) {
102 if (EGG::TSystem<>::sConfiguration->mpDisplay !=
nullptr) {
103 EGG::TSystem<>::sConfiguration->mpDisplay->mFrameRate = rate;
108 if (EGG::TSystem<>::sConfiguration->mpDisplay !=
nullptr) {
109 EGG::TSystem<>::sConfiguration->mpDisplay->setClearColor(color);
114 if (EGG::TSystem<>::sConfiguration->mpDisplay !=
nullptr) {
115 return EGG::TSystem<>::sConfiguration->mpDisplay->getClearColor();
117 return nw4r::ut::Color::BLACK;
121 s_MainThread = OSGetCurrentThread();
123 EGG::TSystem<>::Configuration *config = &s_configuration;
124 EGG::TSystem<>::sConfiguration = config;
125 EGG::BaseSystem::mConfigData = config;
126 config->initialize();
130 EGG::Heap *rootHeap1 = ms_RootHeapMem1;
131 EGG::Heap *rootHeap2 = ms_RootHeapMem2;
150 for (
int i = 0; i < 4; i++) {
154 mPad::g_currentCore->setPosParam(0.1f, 1.0f);
160 dFader_c::setFader(dFader_c::FADE);
162 if (dSystem::s_FontManagerHeap ==
nullptr) {
166 dRomFontMgr_c::createInstance(dSystem::s_FontManagerHeap);
172 OSGetCurrentThread();
179 dAudio::init(ms_RootHeapMem2);
180 dSystem::createEffectManagerHeap(ms_RootHeapMem1, ms_RootHeapMem2);
183 rootHeap1->disableAllocation();
184 rootHeap2->disableAllocation();
201 if (dDyl::InitAsyncIsDone()) {
212sPhase_c::phaseMethod myDylinkInitPhaseMethod[] = {
218sPhase_c myDylinkInitPhase(myDylinkInitPhaseMethod, ARRAY_SIZE(myDylinkInitPhaseMethod));
223 bool dvdErr = dDvdErr_c::m_pInstance->isErrorOccured();
231 if (!inHbm && !dvdErr) {
232 dGraph_c::ms_Instance->painter();
238 dDvdErr_c::m_pInstance->draw();
247 dDvdErr_c::m_pInstance->execute();
248 bool dvdErrNew = dDvdErr_c::m_pInstance->isErrorOccured();
249 if (dvdErrNew && !dvdErr) {
257 dRemoconMng_c::execute();
259 dGameKey_c::m_instance->read();
260 dAudio::updateBgmInfo();
262 if (!inHbm && !dvdErrNew) {
266 cCounter_c::m_exeFrame++;
274 cCounter_c::m_gameFrame++;
281 if (l_breffCommand ==
nullptr) {
282 l_breffCommand = mDvd_toMainRam_c::create(
"/Effect/effect_wnmario.breff", 0, s_EffectManagerHeap2);
283 if (l_breffCommand ==
nullptr) {
287 if (l_breftCommand ==
nullptr) {
288 l_breftCommand = mDvd_toMainRam_c::create(
"/Effect/effect_wnmario.breft", 0, s_EffectManagerHeap2);
289 if (l_breftCommand ==
nullptr) {
293 if (!l_breffCommand->isDone() || !l_breftCommand->isDone()) {
300 EffectManager_c::create(s_EffectManagerHeap1, s_EffectManagerHeap2);
301 s_EffectManagerHeap2->dump();
302 EffectManager_c::setResource(l_breffCommand->mpData, l_breftCommand->mpData);
304 l_breffCommand->destroy();
305 l_breftCommand->destroy();
307 l_breffCommand =
nullptr;
308 l_breftCommand =
nullptr;
314 if (!dFontMng_c::create(s_FontManagerHeap)) {
318 s_FontManagerHeap->dump();
322const char dSystem::sc_MessageManagerHeapName[] = MESSAGE_MANAGER_HEAP_NAME;
323EGG::Heap *dSystem::s_MessageManagerHeap;
326 if (s_MessageManagerHeap ==
nullptr) {
330 if (!dMessage_c::create(s_MessageManagerHeap)) {
334 s_MessageManagerHeap->dump();
335 s_MessageManagerHeap->adjust();
339void *dSystem::s_OrgMEM1ArenaLo;
340void *dSystem::s_NewMEM1ArenaLo;
341void *dSystem::s_OrgMEM1ArenaHi;
342void *dSystem::s_NewMEM1ArenaHi;
344void dSystem::fixArena() {
345 s_OrgMEM1ArenaLo = OSGetMEM1ArenaLo();
346 s_NewMEM1ArenaLo = (
void *)
ARENA_LO;
347 if (s_OrgMEM1ArenaLo < s_NewMEM1ArenaLo) {
348 OSSetMEM1ArenaLo(s_NewMEM1ArenaLo);
351 s_OrgMEM1ArenaHi = OSGetMEM1ArenaHi();
352 s_NewMEM1ArenaHi = (
void *)
ARENA_HI;
353 if (s_OrgMEM1ArenaHi > s_NewMEM1ArenaHi) {
354 OSSetMEM1ArenaHi(s_NewMEM1ArenaHi);
358void dSystem::fixHeapsSub(EGG::ExpHeap *heap,
int size) {
359 heap->setGroupID(255);
361 void *block = heap->alloc(size, -0x20);
362 if (block ==
nullptr) {
367 size_t allocatableSize = heap->getAllocatableSize(4);
368 if (allocatableSize == 0) {
371 heap->alloc(allocatableSize, 4);
378void dSystem::fixHeaps() {
static void initLoader()
Sets the callbacks for the scrapped relocatable profile system.
static dHbm::Manage_c * GetInstance()
Gets a pointer to the instance of this class.
static dReset::Manage_c * GetInstance()
Gets a pointer to the instance of this class.
static void setStartScene()
Sets up the scene to be shown when the game boots up.
static dScene_c * createNextScene()
Creates and returns a root base for the next scene.
static void beginFrame()
Marks the beginning of a frame.
static void create()
Initializes the game.
static void endFrame()
Marks the end of a frame.
static void execute()
Executes one frame of the game loop.
static void mainLoop()
Executes the currently enabled operations on all the bases in the respective lists.
static void draw()
Draws the current fader.
A phase is a list of methods to be called in order.
METHOD_RESULT_e
Return value of a phase method and callMethod().
@ OK
Proceed to the next method in the phase.
@ WAIT
Do not proceed to the next method in the phase.
#define HEAP_SIZE_TEXTURE_BUFFER
The size of the heap used for texture buffers.
#define HEAP_SIZE_ARCHIVE
The size of the heap used for loading archives.
#define HEAP_SIZE_GAME1
The size of the first game heap.
#define ARENA_LO
The start of the arena.
#define ARENA_HI
The end of the arena.
#define HEAP_SIZE_EFFECT_MANAGER2
The size of the second heap used for the effect manager.
#define HEAP_SIZE_GAME2
The size of the second game heap.
#define HEAP_SIZE_REPLAY_DATA
The size of the heap used for replay data.
#define HEAP_SIZE_COMMAND
The size of the heap used for commands.
#define HEAP_SIZE_DYLINK
The size of the heap used for dynamic libraries.
#define HEAP_SIZE_MESSAGE_MANAGER
The size of the heap used for the message manager.
#define HEAP_SIZE_EFFECT_MANAGER1
The size of the first heap used for the effect manager.
#define HEAP_SIZE_FONT_MANAGER
The size of the heap used for the font manager.
void init()
Initializes the 2D engine.
EGG::FrmHeap * createFrmHeap(size_t size, EGG::Heap *parent, const char *name, ulong align, AllocOptBit_t opt)
Creates a frame heap.
@ GAME_HEAP_DEFAULT
The default game heap (alias of MEM1 or MEM2).
@ GAME_HEAP_MEM1
The game heap allocated in MEM1.
@ GAME_HEAP_MEM2
The game heap allocated in MEM2.
EGG::Heap * createGameHeap2(size_t size, EGG::Heap *parent)
Creates the MEM2 game heap. See createGameHeap().
EGG::ExpHeap * createExpHeap(size_t size, EGG::Heap *parent, const char *name, ulong align, AllocOptBit_t opt)
Creates an expandable heap.
EGG::Heap * createGameHeap1(size_t size, EGG::Heap *parent)
Creates the MEM1 game heap. See createGameHeap().
EGG::Heap * createArchiveHeap(size_t size, EGG::Heap *parent)
Creates the archive heap. See createHeap().
EGG::Heap * createCommandHeap(size_t size, EGG::Heap *parent)
Creates the DVD command heap. See createHeap().
EGG::ExpHeap * g_commandHeap
The DVD command heap.
EGG::ExpHeap * g_archiveHeap
The archive resource heap.
@ OPT_THREAD_SAFE
Enables thread-safe memory block de/allocation.
@ OPT_NONE
No special allocation options.
EGG::Heap * createDylinkHeap(size_t size, EGG::Heap *parent)
Creates the REL linking heap. See createHeap().
EGG::ExpHeap * g_gameHeaps[GAME_HEAP_COUNT]
The game heaps.
EGG::Heap * setCurrentHeap(EGG::Heap *heap)
Sets the specified heap as the current heap.