Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1#include "common.h"
2#include "nu/nusys.h"
3#include "dx/profiling.h"
4
5// TODO move these somewhere else...
6u8 nuYieldBuf[NU_GFX_YIELD_BUF_SIZE];
8u8 nuBootStack[0x2000] ALIGNED(8);
9
10// used in effects/gfx/flame.c
11unsigned char D_800B32E0[0x800] ALIGNED(16);
12unsigned char D_800B3AE0[0x800] ALIGNED(16);
13
14s16 D_80074010 = 8; // might be an array, could be size 1-8
15
16void gfxRetrace_Callback(s32);
17void gfxPreNMI_Callback(void);
19
20void gfx_draw_frame(void);
21void gfx_init_state(void);
22
23void create_audio_system(void);
24void load_engine_data(void);
25
26enum {
30};
31
32// TODO try uniting these two split files
33extern s32 ResetGameState;
34extern u16* ResetSavedFrameImg;
35extern s16 D_80073E08;
36extern s16 D_80073E0A;
37extern IMG_BIN ResetTilesImg[];
39
40#if defined(SHIFT) || VERSION_IQUE
41#define shim_create_audio_system_obfuscated create_audio_system
42#define shim_load_engine_data_obfuscated load_engine_data
43#endif
44
47
51
52void boot_main(void* data) {
53#if VERSION_JP
54 if (osTvType == OS_TV_NTSC) {
55 nuGfxDisplayOff();
56 osViSetMode(&osViModeNtscLan1);
57 osViSetSpecialFeatures(OS_VI_GAMMA_OFF | OS_VI_GAMMA_DITHER_OFF | OS_VI_DIVOT_ON | OS_VI_DITHER_FILTER_ON);
58 nuGfxDisplayOff();
59 } else {
60 PANIC();
61 }
62#else // not VERSION_JP
63 if (osTvType == OS_TV_NTSC) {
64 osViSetMode(&osViModeNtscLan1);
65 osViSetSpecialFeatures(OS_VI_GAMMA_OFF | OS_VI_GAMMA_DITHER_OFF | OS_VI_DIVOT_ON | OS_VI_DITHER_FILTER_ON);
66 } else if (osTvType == OS_TV_MPAL) {
67 osViSetMode(&osViModeMpalLan1);
68 osViSetSpecialFeatures(OS_VI_GAMMA_OFF | OS_VI_GAMMA_DITHER_OFF | OS_VI_DIVOT_ON | OS_VI_DITHER_FILTER_ON);
69 } else {
70 PANIC();
71 }
72
73 nuGfxDisplayOff();
75#endif
76
77#if !VERSION_IQUE
79#endif
80 nuGfxInit();
81 gGameStatusPtr->contBitPattern = nuContInit();
82
83#if !VERSION_IQUE
85#endif
88
89 nuGfxFuncSet((NUGfxFunc) gfxRetrace_Callback);
90 nuGfxPreNMIFuncSet(gfxPreNMI_Callback);
91 nuGfxTaskEndFunc = gfx_task_end_callback;
92 gRandSeed += osGetCount();
93 nuGfxDisplayOn();
94
95 while (TRUE) {}
96}
97
98void gfxRetrace_Callback(s32 gfxTaskNum) {
102 nuGfxTaskAllEndWait();
103 if (gfxTaskNum == 0) {
104 u16* fb = (u16*) osViGetCurrentFramebuffer();
105 u16** bufferSet = &ResetFrameBufferArray;
106
107 bufferSet[2] = fb;
108 bufferSet[1] = fb;
109 bufferSet[0] = fb;
111 nuGfxSetCfb(&ResetFrameBufferArray, 3);
112 osViSwapBuffer(ResetFrameBufferArray);
114 }
115 }
118 }
119 } else {
120 D_80073E0A ^= 1;
121 if (D_80073E0A == 0) {
123 D_80073E08 = 1;
124
125 if (gfxTaskNum < 3) {
126 D_80073E08 = 0;
129 }
130 }
131 }
132}
133
134// on reset, draw a series of animated triangular black tiles emanating from the center of the screen
136 s16 t;
137 s16 i;
138 s16 j;
139 u16* frozenFrame;
140
141 gMatrixListPos = 0;
144 frozenFrame = ResetSavedFrameImg;
146
147 gDPSetDepthImage(gMainGfxPos++, OS_K0_TO_PHYSICAL(nuGfxZBuffer));
148 gDPSetColorImage(gMainGfxPos++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, osVirtualToPhysical(frozenFrame));
149 gDPSetScissor(gMainGfxPos++, G_SC_NON_INTERLACE, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
150 gSPTexture(gMainGfxPos++, -1, -1, 0, G_TX_RENDERTILE, G_ON);
151 gDPSetCycleType(gMainGfxPos++, G_CYC_1CYCLE);
152 gDPSetTexturePersp(gMainGfxPos++, G_TP_NONE);
153 gDPSetTextureLUT(gMainGfxPos++, G_TT_NONE);
154 gDPSetRenderMode(gMainGfxPos++, G_RM_OPA_SURF, G_RM_OPA_SURF2);
155 gDPSetTextureFilter(gMainGfxPos++, G_TF_POINT);
156 gDPSetCombineMode(gMainGfxPos++, PM_CC_RESET_TILES, PM_CC_RESET_TILES);
157 gDPSetAlphaCompare(gMainGfxPos++, G_AC_THRESHOLD);
158 gDPSetBlendColor(gMainGfxPos++, 0, 0, 0, 127);
159 gDPLoadTextureTile_4b(gMainGfxPos++, ResetTilesImg, G_IM_FMT_I, 128, 8, 0, 0, 127, 7, 0, G_TX_NOMIRROR | G_TX_WRAP,
160 G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
161
162 for (i = 0; i < 20; i++) {
163 for (j = 0; j < 15; j++) {
164 s32 s4 = i + 14;
165 t = (33 - (s4 - j)) / 2 + 15 - D_80074010;
166 if (t >= 16) {
167 continue;
168 }
169 if (t < 0) {
170 continue;
171 }
172 gSPTextureRectangle(gMainGfxPos++, ((i * 8) + 160) * 4,
173 ((j * 8)) * 4,
174 ((i * 8) + 168) * 4,
175 ((j * 8) + 8) * 4,
176 G_TX_RENDERTILE,
177 (t * 8) * 32, 0, 0x0400, 0x0400);
178 gSPTextureRectangle(gMainGfxPos++, ((i * 8) + 160) * 4,
179 (232 - (j * 8)) * 4,
180 ((i * 8) + 168) * 4,
181 (240 - (j * 8)) * 4,
182 G_TX_RENDERTILE,
183 (t * 8) * 32, 7 * 32, 0x0400, -0x0400);
184 gSPTextureRectangle(gMainGfxPos++, (152 - (i * 8)) * 4,
185 ((j * 8)) * 4,
186 (160 - (i * 8)) * 4,
187 ((j * 8) + 8) * 4,
188 G_TX_RENDERTILE,
189 (t * 8 + 7) * 32, 0, -0x0400, 0x0400);
190 gSPTextureRectangle(gMainGfxPos++, (152 - (i * 8)) * 4,
191 (232 - (j * 8)) * 4,
192 (160 - (i * 8)) * 4,
193 (240 - (j * 8)) * 4,
194 G_TX_RENDERTILE,
195 (t * 8 + 7) * 32, 7 * 32, -0x0400, -0x0400);
196 }
197 }
198
199 D_80074010++;
200 gDPFullSync(gMainGfxPos++);
201 gSPEndDisplayList(gMainGfxPos++);
202 nuGfxTaskStart(gDisplayContext->mainGfx, (u32)(gMainGfxPos - gDisplayContext->mainGfx) * 8, NU_GFX_UCODE_F3DEX, NU_SC_TASK_LODABLE);
204}
205
208 nuContRmbForceStop();
209}
#define IMG_BIN
Gfx mainGfx[0x2080]
void is_debug_init(void)
Definition is_debug.c:19
void gfx_task_background(void)
Definition main_loop.c:169
void step_game_loop(void)
Definition main_loop.c:54
void load_obfuscation_shims(void)
void shim_create_audio_system_obfuscated(void)
void shim_load_engine_data_obfuscated(void)
void crash_screen_init(void)
unsigned char D_800B3AE0[]
unsigned char D_800B32E0[]
void boot_main(void *data)
Definition main.c:52
@ RESET_STATE_FADE
Definition main.c:29
@ RESET_STATE_NONE
Definition main.c:27
@ RESET_STATE_INIT
Definition main.c:28
s16 D_80073E0A
Definition main_pre.c:7
OSThread __osThreadSave
Definition main.c:7
DisplayContext DisplayContexts[2]
Definition main_loop.c:16
void gfxPreNMI_Callback(void)
Definition main.c:206
void gfx_init_state(void)
void load_engine_data(void)
Definition main_loop.c:285
s16 D_80073E08
Definition main_pre.c:6
void gfx_draw_frame(void)
Definition main_loop.c:187
s32 ResetGameState
Definition main_pre.c:4
u8 nuYieldBuf[NU_GFX_YIELD_BUF_SIZE]
Definition main.c:6
void appendGfx_reset_tile_pattern(void)
Definition main.c:135
u16 * nuGfxZBuffer
Definition main.c:46
s16 D_80074010
Definition main.c:14
void gfxRetrace_Callback(s32)
Definition main.c:98
void create_audio_system(void)
void gfx_task_end_callback(void *unk)
Definition main.c:48
IMG_BIN ResetTilesImg[]
u16 * ResetSavedFrameImg
Definition main_pre.c:5
u16 * ResetFrameBufferArray
Definition main.c:45
@ PROFILER_RSP_GFX
Definition profiling.h:98
#define profiler_rsp_started(which)
Definition profiling.h:160
#define profiler_rsp_completed(which)
Definition profiling.h:161
#define SCREEN_WIDTH
Definition macros.h:105
#define SCREEN_HEIGHT
Definition macros.h:106
#define PANIC()
Definition macros.h:55
#define ALIGNED(x)
Definition macros.h:10
#define PM_CC_RESET_TILES
Definition macros.h:413
GameStatus * gGameStatusPtr
Definition main_loop.c:32
Gfx * gMainGfxPos
Definition cam_main.c:15
u16 gMatrixListPos
Definition main_loop.c:45
u32 gRandSeed
Definition 43F0.c:28
s32 gCurrentDisplayContextIndex
Definition main_loop.c:47
DisplayContext * gDisplayContext
Definition cam_main.c:16