diff options
| author | MegaMech <MegaMech@users.noreply.github.com> | 2024-05-22 19:19:16 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-22 19:19:16 -0600 |
| commit | 78a7d156c9a080fab1c530d2aa8210c6d4cf5596 (patch) | |
| tree | d2ca24968a44ac59036945ae8a218e1a3b23cab2 /src | |
| parent | bd9f6b3e851c02edff594237109df01ceb336a09 (diff) | |
Changes for OTR (#15)
* Bunch of fixes
Diffstat (limited to 'src')
46 files changed, 700 insertions, 798 deletions
diff --git a/src/actors/mario_sign/render.inc.c b/src/actors/mario_sign/render.inc.c index 299470946..ec6fdb96b 100644 --- a/src/actors/mario_sign/render.inc.c +++ b/src/actors/mario_sign/render.inc.c @@ -1,6 +1,6 @@ #include <actors.h> #include <main.h> -#include "courses/mario_raceway/course_data.h" +#include <assets/mario_raceway_data.h> /** * @brief Renders the Mario sign actor. diff --git a/src/actors/piranha_plant/render.inc.c b/src/actors/piranha_plant/render.inc.c index 8be53d488..de78392df 100644 --- a/src/actors/piranha_plant/render.inc.c +++ b/src/actors/piranha_plant/render.inc.c @@ -1,8 +1,8 @@ #include <actors.h> #include <main.h> #include <libultra/gbi.h> -#include "courses/mario_raceway/course_data.h" #include "courses/royal_raceway/course_data.h" +#include <assets/mario_raceway_data.h> /** * @brief Renders the piranha plant actor. @@ -110,7 +110,7 @@ void render_actor_piranha_plant(Camera *arg0, Mat4 arg1, struct PiranhaPlant *ar if (gCurrentCourseId == COURSE_MARIO_RACEWAY) { - gSPDisplayList(gDisplayListHead++, &d_course_mario_raceway_dl_piranha_plant); + gSPDisplayList(gDisplayListHead++, d_course_mario_raceway_dl_piranha_plant); } else { gSPDisplayList(gDisplayListHead++, &d_course_royal_raceway_dl_piranha_plant); } diff --git a/src/buffers/memory_pool.c b/src/buffers/memory_pool.c index 5b401d83f..ac222a43b 100644 --- a/src/buffers/memory_pool.c +++ b/src/buffers/memory_pool.c @@ -8,4 +8,4 @@ * Memory pool variable prevents code segments flowing into the memory pool * for easier portability. */ -u8 memoryPool[MEMORY_POOL_SIZE]; +u8 gMemoryPool[MEMORY_POOL_SIZE]; diff --git a/src/code_800029B0.c b/src/code_800029B0.c index fa44153d4..ebab0302c 100644 --- a/src/code_800029B0.c +++ b/src/code_800029B0.c @@ -24,6 +24,7 @@ #include "courses/all_course_packed.h" #include "menus.h" #include <assets/other_textures.h> +#include <assets/mario_raceway_data.h> extern s32 D_802BA038; extern s16 D_802BA048; @@ -308,8 +309,9 @@ void func_80003040(void) { destroy_all_actors(); switch (gCurrentCourseId) { case COURSE_MARIO_RACEWAY: + struct ActorSpawnData *a_d_course_mario_raceway_tree_spawns = (struct ActorSpawnData *) LOAD_ASSET(d_course_mario_raceway_tree_spawns); dma_textures(gTextureTrees1, 0x35B, 0x800); - spawn_foliage(d_course_mario_raceway_tree_spawns); + spawn_foliage(a_d_course_mario_raceway_tree_spawns); break; case COURSE_BOWSER_CASTLE: // d_course_bowsers_castle_packed_dl_1350 diff --git a/src/code_80005FD0.c b/src/code_80005FD0.c index b63455fac..9210440a4 100644 --- a/src/code_80005FD0.c +++ b/src/code_80005FD0.c @@ -3,6 +3,7 @@ #include <defines.h> #include <stubs.h> #include "course_metadata.h" +#include <align_asset_macro.h> #include "code_80005FD0.h" #include "math_util.h" diff --git a/src/code_80057C60.c b/src/code_80057C60.c index e85b5dbc3..e9bddd053 100644 --- a/src/code_80057C60.c +++ b/src/code_80057C60.c @@ -7,6 +7,7 @@ #include <macros.h> #include <libultra/gbi.h> #include <mk64.h> +#include <align_asset_macro.h> #include "camera.h" #include "code_80057C60.h" @@ -35,6 +36,7 @@ #include "spawn_players.h" #include "sounds.h" #include "data/some_data.h" +#include <assets/some_data.h> //! @warning this macro is undef'd at the end of this file @@ -493,7 +495,7 @@ void func_80057FC4(u32 arg0) { if ((gHUDDisable != 0)) { return; } - gSPDisplayList(gDisplayListHead++, &D_0D0076F8); + gSPDisplayList(gDisplayListHead++, D_0D0076F8); set_matrix_hud_screen(); if ((D_801657C8 != 0)){ @@ -527,7 +529,7 @@ void render_object(u32 arg0) { return; } - gSPDisplayList(gDisplayListHead++, &D_0D0076F8); + gSPDisplayList(gDisplayListHead++, D_0D0076F8); if (D_8018D22C != 0) { return; @@ -636,7 +638,7 @@ void render_player_snow_effect(u32 arg0) { return; } - gSPDisplayList(gDisplayListHead++, &D_0D0076F8); + gSPDisplayList(gDisplayListHead++, D_0D0076F8); if (D_8018D22C != 0) { return; @@ -818,13 +820,13 @@ void render_snowing_effect(s32 arg0) { } void func_80058BF4(void) { - gSPDisplayList(gDisplayListHead++, &D_0D0076F8); + gSPDisplayList(gDisplayListHead++, D_0D0076F8); } void func_80058C20(u32 arg0) { D_8018D21C = arg0; - gSPDisplayList(gDisplayListHead++, &D_0D0076F8); + gSPDisplayList(gDisplayListHead++, D_0D0076F8); if (D_8018D22C == 0) { switch (arg0) { @@ -892,7 +894,7 @@ void func_80058C20(u32 arg0) { void render_hud(u32 arg0) { D_8018D21C = arg0; - gSPDisplayList(gDisplayListHead++, &D_0D0076F8); + gSPDisplayList(gDisplayListHead++, D_0D0076F8); if (D_8018D22C == 0) { switch (arg0) { case RENDER_SCREEN_MODE_1P_PLAYER_ONE: @@ -1040,7 +1042,7 @@ void func_800591B4(void) { if ((gHUDDisable == 0) && (D_800DC5B8 != 0)) { func_80057C60(); - gSPDisplayList(gDisplayListHead++, &D_0D0076F8); + gSPDisplayList(gDisplayListHead++, D_0D0076F8); if (gIsHUDVisible != 0) { if (D_801657D8 == 0) { @@ -5228,7 +5230,7 @@ void func_80067964(Player *player, UNUSED s8 arg1, f32 arg2, UNUSED s8 arg3, s8 func_800652D4(sp9C, sp94, player->size * arg2); gSPDisplayList(gDisplayListHead++, D_0D008C90); gSPClearGeometryMode(gDisplayListHead++, G_CULL_BOTH); - gDPLoadTLUT_pal256(gDisplayListHead++, D_800E52D0); + gDPLoadTLUT_pal256(gDisplayListHead++, gTLUTOnomatopoeia); gDPSetTextureLUT(gDisplayListHead++, G_TT_RGBA16); gDPLoadTextureBlock(gDisplayListHead++, D_8018D4AC, G_IM_FMT_CI, G_IM_SIZ_8b, 64, 32, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); gSPVertex(gDisplayListHead++, D_800E8840, 4, 0); @@ -5308,7 +5310,7 @@ void func_80068310(Player *player, UNUSED s8 arg1, UNUSED f32 arg2, s8 arg3, s8 sp94[2] = 0; func_800652D4(sp9C, sp94, player->unk_258[20 + arg4].unk_00C * player->size); gSPDisplayList(gDisplayListHead++, D_0D008C90); - gDPLoadTLUT_pal256(gDisplayListHead++, D_800E52D0); + gDPLoadTLUT_pal256(gDisplayListHead++, gTLUTOnomatopoeia); gDPSetTextureLUT(gDisplayListHead++, G_TT_RGBA16); gDPLoadTextureBlock(gDisplayListHead++, D_8018D4B4, G_IM_FMT_CI, G_IM_SIZ_8b, 64, 32, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); gSPVertex(gDisplayListHead++, D_800E8880, 4, 0); @@ -5382,7 +5384,7 @@ void func_80068DA0(Player *player, UNUSED s8 arg1, UNUSED f32 arg2, s8 arg3, s8 sp94[2] = 0; func_800652D4(sp9C, sp94, player->unk_258[20 + arg4].unk_00C * player->size); gSPDisplayList(gDisplayListHead++, D_0D008C90); - gDPLoadTLUT_pal256(gDisplayListHead++, D_800E52D0); + gDPLoadTLUT_pal256(gDisplayListHead++, gTLUTOnomatopoeia); gDPSetTextureLUT(gDisplayListHead++, G_TT_RGBA16); gDPLoadTextureBlock(gDisplayListHead++, D_8018D4A4, G_IM_FMT_CI, G_IM_SIZ_8b, 64, 32, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); gSPVertex(gDisplayListHead++, D_800E8B80, 4, 0); @@ -5788,7 +5790,7 @@ void render_battle_balloon(Player *player, s8 arg1, s16 arg2, s8 arg3) { gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(&gGfxPool->mtxEffect[gMatrixEffectCount]), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(gDisplayListHead++, D_0D008DB8); - gDPLoadTLUT_pal256(gDisplayListHead++, D_800E52D0); + gDPLoadTLUT_pal256(gDisplayListHead++, gTLUTOnomatopoeia); gDPSetTextureLUT(gDisplayListHead++, G_TT_RGBA16); func_8004B614(primRed, primGreen, primBlue, envRed, envGreen, envBlue, 0x000000D8); @@ -5902,7 +5904,7 @@ void render_balloon(Vec3f arg0, f32 arg1, s16 arg2, s16 arg3) { convert_to_fixed_point_matrix(&gGfxPool->mtxEffect[gMatrixEffectCount], sp108); gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(&gGfxPool->mtxEffect[gMatrixEffectCount]), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(gDisplayListHead++, D_0D008DB8); - gDPLoadTLUT_pal256(gDisplayListHead++, D_800E52D0); + gDPLoadTLUT_pal256(gDisplayListHead++, gTLUTOnomatopoeia); gDPSetTextureLUT(gDisplayListHead++, G_TT_RGBA16); func_8004B614(primRed, primGreen, primBlue, envRed, envGreen, envBlue, 0x000000D8); gDPSetRenderMode(gDisplayListHead++, AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_WRAP | ZMODE_XLU | CVG_X_ALPHA | FORCE_BL | GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA), AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_WRAP | ZMODE_XLU | CVG_X_ALPHA | FORCE_BL | GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA)); diff --git a/src/code_8006E9C0.c b/src/code_8006E9C0.c index 8a2adbd1c..9eb8d23a9 100644 --- a/src/code_8006E9C0.c +++ b/src/code_8006E9C0.c @@ -119,7 +119,8 @@ u8 *func_8006ED94(u8 *devAddr, u8 *baseAddress, u32 size, u32 offset) } void func_8006EE44(void) { - D_8018D1E0 = func_8006ED94((u8 *)&gTextureLogoMarioKart64, (u8 *) D_8018D9B0, 0x79E1, 0x20000); + u8 *d_gTextureLogoMarioKart64 = LOAD_ASSET(gTextureLogoMarioKart64); + D_8018D1E0 = func_8006ED94((u8 *)d_gTextureLogoMarioKart64, (u8 *) D_8018D9B0, 0x79E1, 0x20000); } // Some kind of initalization for the Item Window part of the HUD diff --git a/src/code_80091750.c b/src/code_80091750.c index 7bc74a48c..2bf44cf1c 100644 --- a/src/code_80091750.c +++ b/src/code_80091750.c @@ -1152,10 +1152,6 @@ s32 D_800E84A0[] = { 0x13, 0x13, 0x13, 0x13, }; -Vtx *D_800E84C0[] = { - &D_02007BB8[0], &D_02007BB8[18], &D_02007BB8[36], -}; - Gfx *D_800E84CC[] = { D_02007838, D_02007858, D_02007878, D_02007898, D_020078B8, D_020078D8, D_020078F8, D_02007918, @@ -1609,6 +1605,16 @@ void func_80092290(s32 arg0, s32 *arg1, s32 *arg2) { s32 a, b, c, d; Vtx *vtx; + Vtx *v1 = (Vtx *) LOAD_ASSET(D_02007BB8); + //Vtx *v2 = (Vtx *) LOAD_ASSET(D_02007CD8); + //Vtx *v3 = (Vtx *) LOAD_ASSET(D_02007DF8); + + Vtx *D_800E84C0[] = { + &v1[0], + &v1[18], + &v1[36], + }; + if ((arg0 < 4) || (arg0 >= 6)) { return; } idx = (((arg0 * 4) + ((gGlobalTimer % 2) * 2)) - 6); @@ -1620,7 +1626,14 @@ void func_80092290(s32 arg0, s32 *arg1, s32 *arg2) { } for (i = 0; i < 3; i++) { - vtx = (Vtx *) segmented_to_virtual_dupe_2(D_800E84C0[i]); + if (i == 0) { + vtx = (Vtx *) &v1[0]; + } else if (i == 1) { + vtx = (Vtx *) &v1[18]; + } else if (i == 2) { + vtx = (Vtx *) &v1[36]; + } + //vtx = (Vtx *) segmented_to_virtual_dupe_2(&v1[0]); temp_v1 = (*arg1 * 2) + 2; @@ -2391,6 +2404,7 @@ void func_800942D0(void) { s32 var_s2; s32 thing; test = &gGfxPool->mtxObject[0]; + Gfx * a_D_02007F60 = LOAD_ASSET(D_02007F60); gSPMatrix(gDisplayListHead++, &gGfxPool->mtxScreen, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION); gSPMatrix(gDisplayListHead++, &gGfxPool->mtxLookAt[0], G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); guRotate(test, D_8018EDC8, 1.0f, 0.0f, 0.0f); @@ -2401,7 +2415,7 @@ void func_800942D0(void) { gSPMatrix(gDisplayListHead++, test++, G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW); gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2); gDPSetEnvColor(gDisplayListHead++, 0x00, 0x00, 0x00, 0x00); - gSPDisplayList(gDisplayListHead++, D_02007F60); + gSPDisplayList(gDisplayListHead++, a_D_02007F60); gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW); if (D_800E8530 > 0) { var_f26 = D_800E8534; @@ -2462,14 +2476,14 @@ void func_800947B4(struct GfxPool *arg0, UNUSED s32 arg1) { void func_80094A64(struct GfxPool *pool) { gMatrixHudCount = 0; gMatrixEffectCount = 0; - gSPViewport(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(&D_802B8880)); + gSPViewport(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(D_802B8880)); gDPSetScissor(gDisplayListHead++, G_SC_NON_INTERLACE, 0, 0, 320, 240); guOrtho(&pool->mtxScreen, 0.0f, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, 0.0f, -100.0f, 100.0f, 1.0f); gSPMatrix(gDisplayListHead++, &pool->mtxScreen, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION); gSPDisplayList(gDisplayListHead++, D_02007650); func_80094C60(); func_80092290(4, D_8018E850, D_8018E858); - func_80092290(5, &D_8018E850[1], &D_8018E858[1]); + func_80092290(5, (s32 *) &D_8018E850[1], (s32 *) &D_8018E858[1]); func_80099A70(); func_8009C918(); switch (gMenuSelection) { @@ -2554,7 +2568,6 @@ void func_80094C60(void) { add_8018D9E0_entry(0x000000D9, 0, 0, 0x0A); break; case START_MENU: - // todo: figure this out. add_8018D9E0_entry(2, 0, 0, 4); add_8018D9E0_entry(1, 0, 0, 0); add_8018D9E0_entry(0x000000FB, 0, 0, 0); @@ -2758,29 +2771,22 @@ Gfx *draw_flash_select_case_fast(Gfx *displayListHead, s32 ulx, s32 uly, s32 lrx Gfx *func_800959F8(Gfx *displayListHead, Vtx *arg1) { s32 index; + Vtx *a_D_02007BB8 = (Vtx *) LOAD_ASSET(D_02007BB8); + //Vtx *a_D_02007CD8 = (Vtx *) LOAD_ASSET(D_02007CD8); + // Vtx *a_D_02007DF8 = (Vtx *) LOAD_ASSET(D_02007DF8); if ((s32) gTextColor < TEXT_BLUE_GREEN_RED_CYCLE_1) { index = gTextColor; } else { index = ((gTextColor * 2) + ((s32) gGlobalTimer % 2)) - 4; } -#ifdef AVOID_UB - if (arg1 == D_02007BB8) { + if (arg1 == &a_D_02007BB8[0]) { gSPDisplayList(displayListHead++, D_800E84CC[index]); - } else if (arg1 == &D_02007BB8[18]) { + } else if (arg1 == &a_D_02007BB8[18]) { gSPDisplayList(displayListHead++, D_800E84EC[index]); - } else if (arg1 == &D_02007BB8[36]) { + } else if (arg1 == &a_D_02007BB8[36]) { gSPDisplayList(displayListHead++, D_800E850C[index]); } -#else - if (arg1 == D_02007BB8) { - gSPDisplayList(displayListHead++, D_800E84CC[index]); - } else if (arg1 == D_02007CD8) { - gSPDisplayList(displayListHead++, D_800E84EC[index]); - } else if (arg1 == D_02007DF8) { - gSPDisplayList(displayListHead++, D_800E850C[index]); - } -#endif return displayListHead; @@ -2845,6 +2851,10 @@ Gfx *func_80095BD0(Gfx *displayListHead, u8 *arg1, f32 arg2, f32 arg3, u32 arg4, Vtx *var_a1; Mtx *sp28; + Vtx *a_D_02007BB8 = (Vtx *) LOAD_ASSET(D_02007BB8); + //Vtx *a_D_02007CD8 = (Vtx *) LOAD_ASSET(D_02007CD8); + //Vtx *a_D_02007DF8 = (Vtx *) LOAD_ASSET(D_02007DF8); + // A match is a match, but why are goto's required here? if (gMatrixEffectCount >= 0x2F7) { goto func_80095BD0_label1; @@ -2864,16 +2874,16 @@ func_80095BD0_label2: gDPLoadTextureTile_4b(displayListHead++, arg1, G_IM_FMT_I, arg4, 0, 0, 0, arg4, arg5, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); switch (arg4) { default: - var_a1 = &D_02007BB8[18]; + var_a1 = &a_D_02007BB8[18]; break; case 16: - var_a1 = &D_02007BB8[18]; + var_a1 = &a_D_02007BB8[18]; break; case 26: - var_a1 = D_02007BB8; + var_a1 = &a_D_02007BB8[0]; break; case 30: - var_a1 = &D_02007BB8[36]; + var_a1 = &a_D_02007BB8[36]; break; } @@ -3809,7 +3819,7 @@ void func_80099A94(MkTexture *arg0, s32 arg1) { // Something's up with the handling of `_textures_0aSegmentRomStart`, I don't know how to fix it void func_80099AEC(void) { s8 var_s4; - s32 var_s0; + s32 size; UNUSED s32 stackPadding0; UNUSED s32 stackPadding1; s32 huh; @@ -3820,29 +3830,29 @@ void func_80099AEC(void) { MkTexture *temp_s2; struct_8018E060_entry *var_s1; - if (gGamestate == 4) { + if (gGamestate == RACING) { sp60 = 0x00000500; } else { sp60 = 0x00001000; } var_s4 = 0; - var_s1 = D_8018E060; + var_s1 = &D_8018E060[0]; temp_s2 = var_s1->texture; if (temp_s2 == NULL) return; huh = temp_s2->size; if (huh != 0) { - var_s0 = huh; + size = huh; } else { - var_s0 = 0x1400; + size = 0x1400; } - if (var_s0 % 8) { - var_s0 = ((var_s0 / 8) * 8) + 8; + if (size % 8) { + size = ((size / 8) * 8) + 8; } - osInvalDCache(D_8018D9B4, var_s0); - //osPiStartDma(&sp68, 0, 0, (uintptr_t)&_textures_0aSegmentRomStart[SEGMENT_OFFSET(temp_s2->textureData)], D_8018D9B4, var_s0, &gDmaMesgQueue); + osInvalDCache(D_8018D9B4, size); + //osPiStartDma(&sp68, 0, 0, (uintptr_t)&_textures_0aSegmentRomStart[SEGMENT_OFFSET(temp_s2->textureData)], D_8018D9B4, size, &gDmaMesgQueue); osRecvMesg(&gDmaMesgQueue, &sp64, 1); while (1) { if ((var_s1 + 1)->texture == NULL) { @@ -3851,18 +3861,18 @@ void func_80099AEC(void) { temp_s2 = (var_s1 + 1)->texture; huh = (var_s1 + 1)->texture->size; if (huh != 0) { - var_s0 = huh; + size = huh; } else { - var_s0 = 0x1400; + size = 0x1400; } - if (var_s0 % 8) { - var_s0 = ((var_s0 / 8) * 8) + 8; + if (size % 8) { + size = ((size / 8) * 8) + 8; } - osInvalDCache(D_8018D9B4 + sp60*4, var_s0); - //osPiStartDma(&sp68, 0, 0, (uintptr_t)&_textures_0aSegmentRomStart[SEGMENT_OFFSET(temp_s2->textureData)], D_8018D9B4 + sp60*4, var_s0, &gDmaMesgQueue); + osInvalDCache(D_8018D9B4 + sp60*4, size); + //osPiStartDma(&sp68, 0, 0, (uintptr_t)&_textures_0aSegmentRomStart[SEGMENT_OFFSET(temp_s2->textureData)], D_8018D9B4 + sp60*4, size, &gDmaMesgQueue); } //mio0decode(D_8018D9B4, (u8*)&D_8018D9B0[D_8018E118[var_s1->unk_4].offset]); - memcpy(&D_8018D9B0[D_8018E118[var_s1->unk_4].offset], temp_s2->textureData, temp_s2->width * temp_s2->height * 2); + memcpy(&D_8018D9B0[D_8018E118[var_s1->unk_4].offset], var_s1->texture->textureData, var_s1->texture->width * var_s1->texture->height * 2); var_s1->texture = NULL; var_s1++; @@ -3874,18 +3884,18 @@ void func_80099AEC(void) { temp_s2 = (var_s1 + 1)->texture; huh = (var_s1 + 1)->texture->size; if (huh != 0) { - var_s0 = huh; + size = huh; } else { - var_s0 = 0x1400; + size = 0x1400; } - if (var_s0 % 8) { - var_s0 = ((var_s0 / 8) * 8) + 8; + if (size % 8) { + size = ((size / 8) * 8) + 8; } - osInvalDCache(D_8018D9B4, var_s0); - //osPiStartDma(&sp68, 0, 0, (uintptr_t)&_textures_0aSegmentRomStart[SEGMENT_OFFSET(temp_s2->textureData)], D_8018D9B4, var_s0, &gDmaMesgQueue); + osInvalDCache(D_8018D9B4, size); + //osPiStartDma(&sp68, 0, 0, (uintptr_t)&_textures_0aSegmentRomStart[SEGMENT_OFFSET(temp_s2->textureData)], D_8018D9B4, size, &gDmaMesgQueue); } //mio0decode(D_8018D9B4 + sp60*4, (u8*)&D_8018D9B0[D_8018E118[var_s1->unk_4].offset]); - memcpy(&D_8018D9B0[D_8018E118[var_s1->unk_4].offset], temp_s2->textureData, temp_s2->width * temp_s2->height * 2); + memcpy(&D_8018D9B0[D_8018E118[var_s1->unk_4].offset], var_s1->texture->textureData, var_s1->texture->width * var_s1->texture->height * 2); var_s1->texture = NULL; var_s1++; if (var_s4 != 0) break; diff --git a/src/data/data_segment2.c b/src/data/data_segment2.c deleted file mode 100644 index 602a05a86..000000000 --- a/src/data/data_segment2.c +++ /dev/null @@ -1,540 +0,0 @@ -#include <macros.h> -#include <libultra/types.h> -#include <libultra/gbi.h> -#include "data_segment2.h" -#include <assets/startup_logo.h> -#include <assets/common_data.h> - -Gfx D_02007650[] = { - gsDPPipeSync(), - gsDPSetCycleType(G_CYC_1CYCLE), - gsDPSetRenderMode(G_RM_AA_OPA_SURF, G_RM_AA_OPA_SURF2), - gsSPClearGeometryMode(G_ZBUFFER | G_SHADE | G_LIGHTING | G_SHADING_SMOOTH), - gsDPSetTexturePersp(G_TP_NONE), - gsSPTexture(0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON), - gsDPSetPrimColor(0, 0, 0xFF, 0xFF, 0xFF, 0xFF), - gsDPSetCombineMode(G_CC_DECALRGB, G_CC_DECALRGB), - gsDPSetTextureFilter(G_TF_BILERP), - gsDPSetAlphaCompare(G_AC_NONE), - gsDPSetTextureLUT(G_TT_NONE), - gsSPEndDisplayList(), -}; - -Gfx D_020076B0[] = { - gsDPPipeSync(), - gsDPSetRenderMode(G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2), - gsDPSetCombineMode(G_CC_DECALRGB, G_CC_DECALRGB), - gsDPSetTexturePersp(G_TP_PERSP), - gsSPSetGeometryMode(G_ZBUFFER), - gsSPEndDisplayList(), -}; - -Gfx D_020076E0[] = { - gsDPPipeSync(), - gsSPClearGeometryMode(G_SHADE | G_SHADING_SMOOTH), - gsDPSetRenderMode(G_RM_XLU_SURF, G_RM_XLU_SURF2), - gsDPSetCombineMode(G_CC_DECALRGBA, G_CC_DECALRGBA), - gsSPEndDisplayList(), -}; - -Gfx D_02007708[] = { - gsDPPipeSync(), - gsDPSetRenderMode(G_RM_OPA_SURF, G_RM_OPA_SURF2), - gsDPSetCombineMode(G_CC_DECALRGBA, G_CC_DECALRGBA), - gsSPEndDisplayList(), -}; - -Gfx D_02007728[] = { - gsDPPipeSync(), - gsDPSetRenderMode(G_RM_XLU_SURF, G_RM_XLU_SURF2), - gsDPSetCombineMode(G_CC_DECALRGBA, G_CC_DECALRGBA), - gsSPEndDisplayList(), -}; - -Gfx D_02007748[] = { - gsDPPipeSync(), - gsDPSetRenderMode(G_RM_XLU_SURF, G_RM_XLU_SURF2), - gsDPSetCombineMode(G_CC_MODULATEI_PRIM, G_CC_MODULATEI_PRIM), - gsSPEndDisplayList(), -}; - -Gfx D_02007768[] = { - gsDPPipeSync(), - gsDPSetRenderMode(G_RM_XLU_SURF, G_RM_XLU_SURF2), - gsDPSetCombineMode(G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM), - gsSPEndDisplayList(), -}; - -Gfx D_02007788[] = { - gsDPPipeSync(), - gsDPSetRenderMode(G_RM_XLU_SURF, G_RM_XLU_SURF2), - gsDPSetCombineLERP(TEXEL0, 0, ENVIRONMENT, 0, 0, 0, 0, TEXEL0, TEXEL0, 0, ENVIRONMENT, 0, 0, 0, 0, TEXEL0), - gsSPEndDisplayList(), -}; - -Gfx D_020077A8[] = { - gsDPPipeSync(), - gsSPTexture(0x8000, 0x8000, 0, G_TX_RENDERTILE, G_ON), - gsSPSetGeometryMode(G_SHADE | G_SHADING_SMOOTH), - gsSPClearGeometryMode(G_LIGHTING), - gsDPSetTexturePersp(G_TP_PERSP), - gsSPEndDisplayList(), -}; - -Gfx D_020077D8[] = { - gsDPPipeSync(), - gsSPTexture(0x8000, 0x8000, 0, G_TX_RENDERTILE, G_OFF), - gsDPSetTexturePersp(G_TP_NONE), - gsSPEndDisplayList(), -}; - -Gfx D_020077F8[] = { - gsDPPipeSync(), - gsDPSetRenderMode(G_RM_XLU_SURF, G_RM_XLU_SURF2), - gsDPSetCombineLERP(0, 0, 0, SHADE, TEXEL0, 0, SHADE, 0, 0, 0, 0, SHADE, TEXEL0, 0, SHADE, 0), - gsSPEndDisplayList(), -}; - -Gfx D_02007818[] = { - gsDPPipeSync(), - gsDPSetRenderMode(G_RM_XLU_SURF, G_RM_XLU_SURF2), - gsDPSetCombineLERP(0, 0, 0, SHADE, TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, SHADE, TEXEL0, 0, PRIMITIVE, 0), - gsSPEndDisplayList(), -}; - -Gfx D_02007838[] = { - gsSPVertex(D_02007BB8, 2, 0), - gsSPVertex(&D_02007BB8[2], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -Gfx D_02007858[] = { - gsSPVertex(D_02007BB8, 2, 0), - gsSPVertex(&D_02007BB8[4], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -Gfx D_02007878[] = { - gsSPVertex(D_02007BB8, 2, 0), - gsSPVertex(&D_02007BB8[6], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -Gfx D_02007898[] = { - gsSPVertex(D_02007BB8, 2, 0), - gsSPVertex(&D_02007BB8[8], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -Gfx D_020078B8[] = { - gsSPVertex(D_02007BB8, 2, 0), - gsSPVertex(&D_02007BB8[10], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -Gfx D_020078D8[] = { - gsSPVertex(D_02007BB8, 2, 0), - gsSPVertex(&D_02007BB8[12], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -Gfx D_020078F8[] = { - gsSPVertex(D_02007BB8, 2, 0), - gsSPVertex(&D_02007BB8[14], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -Gfx D_02007918[] = { - gsSPVertex(D_02007BB8, 2, 0), - gsSPVertex(&D_02007BB8[16], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -Gfx D_02007938[] = { - gsSPVertex(&D_02007BB8[18], 2, 0), - gsSPVertex(&D_02007BB8[20], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -Gfx D_02007958[] = { - gsSPVertex(&D_02007BB8[18], 2, 0), - gsSPVertex(&D_02007BB8[22], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -Gfx D_02007978[] = { - gsSPVertex(&D_02007BB8[18], 2, 0), - gsSPVertex(&D_02007BB8[24], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -Gfx D_02007998[] = { - gsSPVertex(&D_02007BB8[18], 2, 0), - gsSPVertex(&D_02007BB8[26], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -Gfx D_020079B8[] = { - gsSPVertex(&D_02007BB8[18], 2, 0), - gsSPVertex(&D_02007BB8[28], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -Gfx D_020079D8[] = { - gsSPVertex(&D_02007BB8[18], 2, 0), - gsSPVertex(&D_02007BB8[30], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -Gfx D_020079F8[] = { - gsSPVertex(&D_02007BB8[18], 2, 0), - gsSPVertex(&D_02007BB8[32], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -Gfx D_02007A18[] = { - gsSPVertex(&D_02007BB8[18], 2, 0), - gsSPVertex(&D_02007BB8[34], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -Gfx D_02007A38[] = { - gsSPVertex(&D_02007BB8[36], 2, 0), - gsSPVertex(&D_02007BB8[38], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -Gfx D_02007A58[] = { - gsSPVertex(&D_02007BB8[36], 2, 0), - gsSPVertex(&D_02007BB8[40], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -Gfx D_02007A78[] = { - gsSPVertex(&D_02007BB8[36], 2, 0), - gsSPVertex(&D_02007BB8[42], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -Gfx D_02007A98[] = { - gsSPVertex(&D_02007BB8[36], 2, 0), - gsSPVertex(&D_02007BB8[44], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -Gfx D_02007AB8[] = { - gsSPVertex(&D_02007BB8[36], 2, 0), - gsSPVertex(&D_02007BB8[46], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -Gfx D_02007AD8[] = { - gsSPVertex(&D_02007BB8[36], 2, 0), - gsSPVertex(&D_02007BB8[48], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -Gfx D_02007AF8[] = { - gsSPVertex(&D_02007BB8[36], 2, 0), - gsSPVertex(&D_02007BB8[50], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -Gfx D_02007B18[] = { - gsSPVertex(&D_02007BB8[36], 2, 0), - gsSPVertex(&D_02007BB8[52], 2, 2), - gsSPDisplayList(common_rectangle_display), - gsSPEndDisplayList(), -}; - -UNUSED Vtx D_02007B38[] = { - {{{ 0, 0, 0}, 0, { 0, 0}, {0xff, 0xff, 0xff, 0xff}}}, - {{{ 16, 0, 0}, 0, { 0, 0}, {0xff, 0xff, 0xff, 0xff}}}, - {{{ 16, 16, 0}, 0, { 0, 0}, {0xff, 0xff, 0xff, 0xff}}}, - {{{ 0, 16, 0}, 0, { 0, 0}, {0xff, 0xff, 0xff, 0xff}}}, - {{{ 0, -8, 0}, 0, { 0, 0}, {0xff, 0xff, 0xff, 0xff}}}, - {{{ 8, -8, 0}, 0, {448, 0}, {0xff, 0xff, 0xff, 0xff}}}, - {{{ 8, 0, 0}, 0, {448, 448}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 448}, {0xff, 0x00, 0x00, 0xff}}}, -}; - -#ifdef AVOID_UB -Vtx D_02007BB8[] = { - {{{ 0, 65520, 0}, 0, { 0, 0}, {0xff, 0xff, 0xff, 0xff}}}, - {{{26, 65520, 0}, 0, {1600, 0}, {0xff, 0xff, 0xff, 0xff}}}, - {{{26, 0, 0}, 0, {1600, 960}, {0x00, 0x00, 0xff, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0x00, 0x00, 0xff, 0xff}}}, - {{{26, 0, 0}, 0, {1600, 960}, {0x00, 0xff, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0x00, 0xff, 0x00, 0xff}}}, - {{{26, 0, 0}, 0, {1600, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{26, 0, 0}, 0, {1600, 960}, {0xff, 0xff, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0xff, 0x00, 0xff}}}, - {{{26, 0, 0}, 0, {1600, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{26, 0, 0}, 0, {1600, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{26, 0, 0}, 0, {1600, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{26, 0, 0}, 0, {1600, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 65520, 0}, 0, { 0, 0}, {0xff, 0xff, 0xff, 0xff}}}, - {{{16, 65520, 0}, 0, {960, 0}, {0xff, 0xff, 0xff, 0xff}}}, - {{{16, 0, 0}, 0, {960, 960}, {0x00, 0x00, 0xff, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0x00, 0x00, 0xff, 0xff}}}, - {{{16, 0, 0}, 0, {960, 960}, {0x00, 0xff, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0x00, 0xff, 0x00, 0xff}}}, - {{{16, 0, 0}, 0, {960, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{16, 0, 0}, 0, {960, 960}, {0xff, 0xff, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0xff, 0x00, 0xff}}}, - {{{16, 0, 0}, 0, {960, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{16, 0, 0}, 0, {960, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{16, 0, 0}, 0, {960, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{16, 0, 0}, 0, {960, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 65504, 0}, 0, { 0, 0}, {0xff, 0xff, 0xff, 0xff}}}, - {{{30, 65504, 0}, 0, {1856, 0}, {0xff, 0xff, 0xff, 0xff}}}, - {{{30, 0, 0}, 0, {1856, 1984}, {0x00, 0x00, 0xff, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 1984}, {0x00, 0x00, 0xff, 0xff}}}, - {{{30, 0, 0}, 0, {1856, 1984}, {0x00, 0xff, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 1984}, {0x00, 0xff, 0x00, 0xff}}}, - {{{30, 0, 0}, 0, {1856, 1984}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 1984}, {0xff, 0x00, 0x00, 0xff}}}, - {{{30, 0, 0}, 0, {1856, 1984}, {0xff, 0xff, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 1984}, {0xff, 0xff, 0x00, 0xff}}}, - {{{30, 0, 0}, 0, {1856, 1984}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 1984}, {0xff, 0x00, 0x00, 0xff}}}, - {{{30, 0, 0}, 0, {1856, 1984}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 1984}, {0xff, 0x00, 0x00, 0xff}}}, - {{{30, 0, 0}, 0, {1856, 1984}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 1984}, {0xff, 0x00, 0x00, 0xff}}}, - {{{30, 0, 0}, 0, {1856, 1984}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 1984}, {0xff, 0x00, 0x00, 0xff}}}, -}; -#else -Vtx D_02007BB8[] = { - {{{ 0, 65520, 0}, 0, { 0, 0}, {0xff, 0xff, 0xff, 0xff}}}, - {{{26, 65520, 0}, 0, {1600, 0}, {0xff, 0xff, 0xff, 0xff}}}, -}; - -Vtx D_02007BD8[] = { - {{{26, 0, 0}, 0, {1600, 960}, {0x00, 0x00, 0xff, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0x00, 0x00, 0xff, 0xff}}}, -}; - -Vtx D_02007BF8[] = { - {{{26, 0, 0}, 0, {1600, 960}, {0x00, 0xff, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0x00, 0xff, 0x00, 0xff}}}, -}; - -Vtx D_02007C18[] = { - {{{26, 0, 0}, 0, {1600, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0x00, 0x00, 0xff}}}, -}; - -Vtx D_02007C38[] = { - {{{26, 0, 0}, 0, {1600, 960}, {0xff, 0xff, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0xff, 0x00, 0xff}}}, -}; - -Vtx D_02007C58[] = { - {{{26, 0, 0}, 0, {1600, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0x00, 0x00, 0xff}}}, -}; - -Vtx D_02007C78[] = { - {{{26, 0, 0}, 0, {1600, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0x00, 0x00, 0xff}}}, -}; - -Vtx D_02007C98[] = { - {{{26, 0, 0}, 0, {1600, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0x00, 0x00, 0xff}}}, -}; - -Vtx D_02007CB8[] = { - {{{26, 0, 0}, 0, {1600, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0x00, 0x00, 0xff}}}, -}; - -Vtx D_02007CD8[] = { - {{{ 0, 65520, 0}, 0, { 0, 0}, {0xff, 0xff, 0xff, 0xff}}}, - {{{16, 65520, 0}, 0, {960, 0}, {0xff, 0xff, 0xff, 0xff}}}, -}; - -Vtx D_02007CF8[] = { - {{{16, 0, 0}, 0, {960, 960}, {0x00, 0x00, 0xff, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0x00, 0x00, 0xff, 0xff}}}, -}; - -Vtx D_02007D18[] = { - {{{16, 0, 0}, 0, {960, 960}, {0x00, 0xff, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0x00, 0xff, 0x00, 0xff}}}, -}; - -Vtx D_02007D38[] = { - {{{16, 0, 0}, 0, {960, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0x00, 0x00, 0xff}}}, -}; - -Vtx D_02007D58[] = { - {{{16, 0, 0}, 0, {960, 960}, {0xff, 0xff, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0xff, 0x00, 0xff}}}, -}; - -Vtx D_02007D78[] = { - {{{16, 0, 0}, 0, {960, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0x00, 0x00, 0xff}}}, -}; - -Vtx D_02007D98[] = { - {{{16, 0, 0}, 0, {960, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0x00, 0x00, 0xff}}}, -}; - -Vtx D_02007DB8[] = { - {{{16, 0, 0}, 0, {960, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0x00, 0x00, 0xff}}}, -}; - -Vtx D_02007DD8[] = { - {{{16, 0, 0}, 0, {960, 960}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 960}, {0xff, 0x00, 0x00, 0xff}}}, -}; - -Vtx D_02007DF8[] = { - {{{ 0, 65504, 0}, 0, { 0, 0}, {0xff, 0xff, 0xff, 0xff}}}, - {{{30, 65504, 0}, 0, {1856, 0}, {0xff, 0xff, 0xff, 0xff}}}, -}; - -Vtx D_02007E18[] = { - {{{30, 0, 0}, 0, {1856, 1984}, {0x00, 0x00, 0xff, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 1984}, {0x00, 0x00, 0xff, 0xff}}}, -}; - -Vtx D_02007E38[] = { - {{{30, 0, 0}, 0, {1856, 1984}, {0x00, 0xff, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 1984}, {0x00, 0xff, 0x00, 0xff}}}, -}; - -Vtx D_02007E58[] = { - {{{30, 0, 0}, 0, {1856, 1984}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 1984}, {0xff, 0x00, 0x00, 0xff}}}, -}; - -Vtx D_02007E78[] = { - {{{30, 0, 0}, 0, {1856, 1984}, {0xff, 0xff, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 1984}, {0xff, 0xff, 0x00, 0xff}}}, -}; - -Vtx D_02007E98[] = { - {{{30, 0, 0}, 0, {1856, 1984}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 1984}, {0xff, 0x00, 0x00, 0xff}}}, -}; - -Vtx D_02007EB8[] = { - {{{30, 0, 0}, 0, {1856, 1984}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 1984}, {0xff, 0x00, 0x00, 0xff}}}, -}; - -Vtx D_02007ED8[] = { - {{{30, 0, 0}, 0, {1856, 1984}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 1984}, {0xff, 0x00, 0x00, 0xff}}}, -}; - -Vtx D_02007EF8[] = { - {{{30, 0, 0}, 0, {1856, 1984}, {0xff, 0x00, 0x00, 0xff}}}, - {{{ 0, 0, 0}, 0, { 0, 1984}, {0xff, 0x00, 0x00, 0xff}}}, -}; -#endif - -Gfx D_02007F18[] = { - gsDPPipeSync(), - gsDPSetTexturePersp(G_TP_NONE), - gsDPSetTextureLUT(G_TT_NONE), - gsDPSetTextureFilter(G_TF_BILERP), - gsDPSetRenderMode(G_RM_OPA_SURF, G_RM_OPA_SURF2), - gsSPEndDisplayList(), -}; - -Gfx D_02007F48[] = { - gsDPPipeSync(), - gsDPSetTexturePersp(G_TP_PERSP), - gsSPEndDisplayList(), -}; - -Gfx D_02007F60[] = { - gsDPSetCycleType(G_CYC_FILL), - gsDPSetRenderMode(G_RM_OPA_SURF, G_RM_OPA_SURF2), - gsSPClearGeometryMode(G_ZBUFFER | G_CULL_BACK | G_LIGHTING), - gsDPSetFillColor(0x00010001), - gsDPFillRectangle(0, 0, 319, 239), - gsSPSetGeometryMode(G_ZBUFFER | G_CULL_BACK | G_LIGHTING), - gsDPSetRenderMode(G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2), - gsDPSetCycleType(G_CYC_1CYCLE), - gsDPSetCombineMode(G_CC_SHADE, G_CC_SHADE), - gsSPSetGeometryMode(G_SHADE | G_CULL_BACK | G_LIGHTING | G_SHADING_SMOOTH), - gsDPPipeSync(), - gsSPDisplayList(startup_texture_dl3), - gsSPEndDisplayList(), -}; - -Gfx D_02007FC8[] = { - gsDPSetTexturePersp(G_TP_PERSP), - gsDPPipeSync(), - gsSPSetGeometryMode(G_ZBUFFER | G_CULL_BACK | G_LIGHTING), - gsDPSetRenderMode(G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2), - gsDPSetCycleType(G_CYC_1CYCLE), - gsDPSetCombineMode(G_CC_SHADE, G_CC_SHADE), - gsSPSetGeometryMode(G_SHADE | G_CULL_BACK | G_LIGHTING | G_SHADING_SMOOTH), - gsSPEndDisplayList(), -}; - -Gfx D_02008008[] = { - gsDPPipeSync(), - gsDPSetCycleType(G_CYC_1CYCLE), - gsDPSetRenderMode(G_RM_XLU_SURF, G_RM_XLU_SURF2), - gsDPSetCombineMode(G_CC_PRIMITIVE, G_CC_PRIMITIVE), - gsSPEndDisplayList(), -}; - -Gfx D_02008030[] = { - gsDPPipeSync(), - gsDPSetCycleType(G_CYC_FILL), - gsDPSetRenderMode(G_RM_OPA_SURF, G_RM_OPA_SURF2), - gsDPSetCombineMode(G_CC_DECALRGBA, G_CC_DECALRGBA), - gsSPEndDisplayList(), -}; - -Gfx D_02008058[] = { - gsDPPipeSync(), - gsDPSetCycleType(G_CYC_1CYCLE), - gsSPEndDisplayList(), -}; diff --git a/src/data/path_spawn_metadata.c b/src/data/path_spawn_metadata.c index c0a4831f2..ea87e106e 100644 --- a/src/data/path_spawn_metadata.c +++ b/src/data/path_spawn_metadata.c @@ -1,6 +1,7 @@ #include "data/path_spawn_metadata.h" #include "courses/all_course_data.h" #include <assets/ceremony_data.h> +#include <assets/mario_raceway_data.h> // @warning Array contains an extra zero element at the end. KartAIBehaviour *gKartAIBehaviourLUT[] = { diff --git a/src/data/some_data.c b/src/data/some_data.c index b70068b7b..7fd4adaac 100644 --- a/src/data/some_data.c +++ b/src/data/some_data.c @@ -184,9 +184,12 @@ Vtx gBalloonVertexPlane2[] = { {{{ -9, 9, -6 }, 0, { 0, 0 }, { 0xFF, 0xFF, 0xFF, 0xFF }}}, }; -u8 D_800E52D0[] = { - #include "assets/code/some_data/gTLUTOnomatopoeia.rgba16.inc.c" -}; +// Moved to OTR asset see some_data.yml +// Symbol renamed to gTLUTOnomatopoeia +// +// u8 D_800E52D0[] = { +// #include "assets/code/some_data/gTLUTOnomatopoeia.rgba16.inc.c" +// }; u8 *gCourseOutlineTextures[] = { gTextureCourseOutlineMarioRaceway, gTextureCourseOutlineChocoMountain, gTextureCourseOutlineBowsersCastle, gTextureCourseOutlineBansheeBoardwalk, diff --git a/src/data/some_data.h b/src/data/some_data.h index 6069fb514..d22db70ef 100644 --- a/src/data/some_data.h +++ b/src/data/some_data.h @@ -1,5 +1,6 @@ -#ifndef SOME_DATA_H -#define SOME_DATA_H +#ifndef SOME_DATA_HH +#define SOME_DATA_HH +// SOME_DATA_HH named this way prevent conflict with <assets/some_data.h> #include <libultra/gbi.h> #include "spline.h" @@ -18,7 +19,6 @@ extern Vtx D_800E51D0[]; extern Vtx D_800E5210[]; extern Vtx gBalloonVertexPlane1[]; extern Vtx gBalloonVertexPlane2[]; -extern u8 D_800E52D0[]; extern u8 *gCourseOutlineTextures[]; extern s16 D_800E5520[]; extern s16 D_800E5548[]; diff --git a/src/data_segment2.h b/src/data_segment2.h deleted file mode 100644 index 1ce58e8ac..000000000 --- a/src/data_segment2.h +++ /dev/null @@ -1,83 +0,0 @@ -#ifndef DATA_SEGMENT2_H -#define DATA_SEGMENT2_H - -#include <libultra/gbi.h> - -extern Vtx D_02007B38[]; - -extern Gfx D_02007650[]; -extern Gfx D_020076B0[]; -extern Gfx D_020076E0[]; -extern Gfx D_02007708[]; -extern Gfx D_02007728[]; -extern Gfx D_02007748[]; -extern Gfx D_02007768[]; -extern Gfx D_02007788[]; -extern Gfx D_020077A8[]; -extern Gfx D_020077D8[]; -extern Gfx D_020077F8[]; -extern Gfx D_02007818[]; -extern Gfx D_02007838[]; -extern Gfx D_02007858[]; -extern Gfx D_02007878[]; -extern Gfx D_02007898[]; -extern Gfx D_020078B8[]; -extern Gfx D_020078D8[]; -extern Gfx D_020078F8[]; -extern Gfx D_02007918[]; -extern Gfx D_02007938[]; -extern Gfx D_02007958[]; -extern Gfx D_02007978[]; -extern Gfx D_02007998[]; -extern Gfx D_020079B8[]; -extern Gfx D_020079D8[]; -extern Gfx D_020079F8[]; -extern Gfx D_02007A18[]; -extern Gfx D_02007A38[]; -extern Gfx D_02007A58[]; -extern Gfx D_02007A78[]; -extern Gfx D_02007A98[]; -extern Gfx D_02007AB8[]; -extern Gfx D_02007AD8[]; -extern Gfx D_02007AF8[]; -extern Gfx D_02007B18[]; -extern Gfx D_02007F18[]; -extern Gfx D_02007F48[]; -extern Gfx D_02007F60[]; -extern Gfx D_02007FC8[]; -extern Gfx D_02008008[]; -extern Gfx D_02008030[]; -extern Gfx D_02008058[]; - -extern Vtx D_02007BB8[]; -#ifndef AVOID_UB -extern Vtx D_02007BD8[]; -extern Vtx D_02007BF8[]; -extern Vtx D_02007C18[]; -extern Vtx D_02007C38[]; -extern Vtx D_02007C58[]; -extern Vtx D_02007C78[]; -extern Vtx D_02007C98[]; -extern Vtx D_02007CB8[]; -extern Vtx D_02007CD8[]; -extern Vtx D_02007CF8[]; -extern Vtx D_02007D18[]; -extern Vtx D_02007D38[]; -extern Vtx D_02007D58[]; -extern Vtx D_02007D78[]; -extern Vtx D_02007D98[]; -extern Vtx D_02007DB8[]; -extern Vtx D_02007DD8[]; -extern Vtx D_02007DF8[]; -extern Vtx D_02007E18[]; -extern Vtx D_02007E38[]; -extern Vtx D_02007E58[]; -extern Vtx D_02007E78[]; -extern Vtx D_02007E98[]; -extern Vtx D_02007EB8[]; -extern Vtx D_02007ED8[]; -extern Vtx D_02007EF8[]; -#endif - - -#endif diff --git a/src/ending/code_80280000.c b/src/ending/code_80280000.c index e07315460..5b25c8679 100644 --- a/src/ending/code_80280000.c +++ b/src/ending/code_80280000.c @@ -53,9 +53,9 @@ void func_80280038(void) { gSPSetGeometryMode(gDisplayListHead++, G_ZBUFFER | G_SHADE | G_CULL_BACK | G_SHADING_SMOOTH); guPerspective(&gGfxPool->mtxPersp[0], &perspNorm, gCameraZoom[0], gScreenAspect, D_80150150, D_8015014C, 1.0f); gSPPerspNormalize(gDisplayListHead++, perspNorm); - gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(&gGfxPool->mtxPersp[0]), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION); + gSPMatrix(gDisplayListHead++, (&gGfxPool->mtxPersp[0]), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION); guLookAt(&gGfxPool->mtxLookAt[0], camera->pos[0], camera->pos[1], camera->pos[2], camera->lookAt[0], camera->lookAt[1], camera->lookAt[2], camera->up[0], camera->up[1], camera->up[2]); - gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(&gGfxPool->mtxLookAt[0]), G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION); + gSPMatrix(gDisplayListHead++, (&gGfxPool->mtxLookAt[0]), G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION); gCurrentCourseId = gCreditsCourseId; mtxf_identity(matrix); render_set_position(matrix, 0); diff --git a/src/ending/podium_ceremony_actors.c b/src/ending/podium_ceremony_actors.c index 4ec792ce9..046e49438 100644 --- a/src/ending/podium_ceremony_actors.c +++ b/src/ending/podium_ceremony_actors.c @@ -234,7 +234,7 @@ void func_80280A28(Vec3f arg0, Vec3s arg1, f32 arg2) { mtx[2][1] = D_80287500[1][2] * arg2; mtx[2][2] = D_80287500[2][2] * arg2; convert_to_fixed_point_matrix(&gGfxPool->mtxEffect[gMatrixEffectCount], mtx); - gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(&gGfxPool->mtxEffect[gMatrixEffectCount]), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPMatrix(gDisplayListHead++, &gGfxPool->mtxEffect[gMatrixEffectCount], G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); } void render_fireworks(Vec3f arg0, f32 arg1, s32 rgb, s16 alpha) { diff --git a/src/main.c b/src/main.c index fee93a876..711d045ad 100644 --- a/src/main.c +++ b/src/main.c @@ -508,12 +508,6 @@ void dma_copy(u8 *dest, u8 *romAddr, size_t size) { } } -static u8 memoryPool[0xAB630]; - -#define PRINT_MEMPOOL \ - printf("\nPool Start: 0x%llX, Pool End: 0x%llX, size: 0x%llX\ngNextFreeMemoryAddress: 0x%llX\n\n", memoryPool, \ - memoryPool + sizeof(memoryPool), (memoryPool + sizeof(memoryPool)) - memoryPool, gNextFreeMemoryAddress) - /** * Setup main segments and framebuffers. */ @@ -530,13 +524,10 @@ void setup_game_memory(void) { // set_segment_base_addr(0, (void *) SEG_START); // // Memory pool size of 0xAB630 - bzero(memoryPool, sizeof(memoryPool)); - initialize_memory_pool(memoryPool, memoryPool + sizeof(memoryPool)); + initialize_memory_pool(); func_80000BEC(); - PRINT_MEMPOOL; - // // Initialize trig tables segment // osInvalDCache((void *) TRIG_TABLES, TRIG_TABLES_SIZE); // osPiStartDma(&gDmaIoMesg, 0, 0, TRIG_TABLES_ROM_START, (void *) TRIG_TABLES, TRIG_TABLES_SIZE, &gDmaMesgQueue); @@ -1165,7 +1156,7 @@ void update_gamestate(void) { * @bug Reloading this segment makes random_u16() deterministic for player spawn order. * In laymens terms, random_u16() outputs the same value every time. */ - init_segment_racing(); + //init_segment_racing(); setup_race(); break; case ENDING: @@ -1175,7 +1166,7 @@ void update_gamestate(void) { break; case CREDITS_SEQUENCE: gCurrentlyLoadedCourseId = COURSE_NULL; - init_segment_racing(); + //init_segment_racing(); init_segment_ending_sequences(); load_credits(); break; @@ -1183,6 +1174,11 @@ void update_gamestate(void) { } void thread5_game_loop(void) { + + // if (GfxDebuggerIsDebugging()) { + // Graphics_PushFrame(gGfxPool->gfxPool); + // return; + // } setup_game_memory(); osCreateMesgQueue(&gGfxVblankQueue, gGfxMesgBuf, 1); osCreateMesgQueue(&gGameVblankQueue, &gGameMesgBuf, 1); diff --git a/src/menus.c b/src/menus.c index 1721ca9a1..f3df0a4e6 100644 --- a/src/menus.c +++ b/src/menus.c @@ -31,7 +31,7 @@ f32 D_8018EDD8; f32 D_8018EDDC; s32 D_8018EDE0; s8 gCharacterGridSelections[4]; // map from player id to current grid position -bool D_8018EDE8[4]; // map player id to isCharSelected on CSS +s8 D_8018EDE8[4]; // map player id to isCharSelected on CSS s8 D_8018EDEC; s8 gMainMenuSelectionDepth; s8 D_8018EDEE; // grid screen state? diff --git a/src/menus.h b/src/menus.h index 85ad94508..e789caf7b 100644 --- a/src/menus.h +++ b/src/menus.h @@ -49,7 +49,7 @@ extern f32 D_8018EDDC; extern s32 D_8018EDE0; extern s8 gCharacterGridSelections[]; -extern bool D_8018EDE8[]; +extern s8 D_8018EDE8[]; extern s8 D_8018EDEC; extern s8 gMainMenuSelectionDepth; extern s8 D_8018EDEE; diff --git a/src/port/Engine.cpp b/src/port/Engine.cpp index 09658b207..0d18255bc 100644 --- a/src/port/Engine.cpp +++ b/src/port/Engine.cpp @@ -7,6 +7,11 @@ #include "resource/importers/GenericArrayFactory.h" #include "resource/importers/Vec3fFactory.h" #include "resource/importers/Vec3sFactory.h" +#include "resource/importers/KartAIFactory.h" +#include "resource/importers/TrackSectionsFactory.h" +#include "resource/importers/TrackWaypointFactory.h" +#include "resource/importers/ActorSpawnDataFactory.h" +#include <Fast3D/Fast3dWindow.h> #include <Fast3D/gfx_pc.h> #include <Fast3D/gfx_rendering_api.h> @@ -17,6 +22,12 @@ extern "C" { float gInterpolationStep = 0.0f; #include <macros.h> +#include <DisplayListFactory.h> +#include <TextureFactory.h> +#include <MatrixFactory.h> +#include <ArrayFactory.h> +#include <BlobFactory.h> +#include <VertexFactory.h> } GameEngine* GameEngine::Instance; @@ -45,6 +56,18 @@ GameEngine::GameEngine() { loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryVec3fV0>(), RESOURCE_FORMAT_BINARY, "Vec3f", static_cast<uint32_t>(SF64::ResourceType::Vec3f), 0); loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryVec3sV0>(), RESOURCE_FORMAT_BINARY, "Vec3s", static_cast<uint32_t>(SF64::ResourceType::Vec3s), 0); loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryGenericArrayV0>(), RESOURCE_FORMAT_BINARY, "GenericArray", static_cast<uint32_t>(SF64::ResourceType::GenericArray), 0); + loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryTextureV0>(), RESOURCE_FORMAT_BINARY, "Texture", static_cast<uint32_t>(LUS::ResourceType::Texture), 0); + loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryTextureV1>(), RESOURCE_FORMAT_BINARY, "Texture", static_cast<uint32_t>(LUS::ResourceType::Texture), 1); + loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryVertexV0>(), RESOURCE_FORMAT_BINARY, "Vertex", static_cast<uint32_t>(LUS::ResourceType::Vertex), 0); + loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryDisplayListV0>(), RESOURCE_FORMAT_BINARY, "DisplayList", static_cast<uint32_t>(LUS::ResourceType::DisplayList), 0); + loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryMatrixV0>(), RESOURCE_FORMAT_BINARY, "Matrix", static_cast<uint32_t>(LUS::ResourceType::Matrix), 0); + loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryArrayV0>(), RESOURCE_FORMAT_BINARY, "Array", static_cast<uint32_t>(LUS::ResourceType::Array), 0); + loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryBlobV0>(), RESOURCE_FORMAT_BINARY, "Blob", static_cast<uint32_t>(LUS::ResourceType::Blob), 0); + loader->RegisterResourceFactory(std::make_shared<MK64::ResourceFactoryBinaryKartAIV0>(), RESOURCE_FORMAT_BINARY, "KartAI", static_cast<uint32_t>(MK64::ResourceType::KartAI), 0); + loader->RegisterResourceFactory(std::make_shared<MK64::ResourceFactoryBinaryTrackSectionsV0>(), RESOURCE_FORMAT_BINARY, "TrackSections", static_cast<uint32_t>(MK64::ResourceType::TrackSection), 0); + loader->RegisterResourceFactory(std::make_shared<MK64::ResourceFactoryBinaryTrackWaypointsV0>(), RESOURCE_FORMAT_BINARY, "Waypoints", static_cast<uint32_t>(MK64::ResourceType::Waypoints), 0); + loader->RegisterResourceFactory(std::make_shared<MK64::ResourceFactoryBinaryActorSpawnDataV0>(), RESOURCE_FORMAT_BINARY, "SpawnData", static_cast<uint32_t>(MK64::ResourceType::SpawnData), 0); + } void GameEngine::Create(){ @@ -79,9 +102,10 @@ void GameEngine::StartFrame() const{ this->context->GetWindow()->StartFrame(); } -void GameEngine::ProcessFrame(void (*run_one_game_iter)()) const { - this->context->GetWindow()->MainLoop(run_one_game_iter); -} +// void GameEngine::ProcessFrame(void (*run_one_game_iter)()) const { +// //this->context->GetWindow()->MainLoop(run_one_game_iter); +// Instance->context->GetWindow()->MainLoop(run_one_game_iter); +// } void GameEngine::RunCommands(Gfx* Commands) { gfx_run(Commands, {}); @@ -95,8 +119,11 @@ void GameEngine::RunCommands(Gfx* Commands) { void GameEngine::ProcessGfxCommands(Gfx* commands) { RunCommands(commands); - Instance->context->GetWindow()->SetTargetFps(30); - Instance->context->GetWindow()->SetMaximumFrameLatency(1); + auto wnd = std::dynamic_pointer_cast<Fast::Fast3dWindow>(Ship::Context::GetInstance()->GetWindow()); + if (wnd != nullptr) { + wnd->SetTargetFps(30); + wnd->SetMaximumFrameLatency(1); + } } extern "C" uint32_t GameEngine_GetSampleRate() { @@ -129,10 +156,8 @@ extern "C" uint32_t GameEngine_GetGameVersion() { static const char* sOtrSignature = "__OTR__"; extern "C" uint8_t GameEngine_OTRSigCheck(const char* data) { - if(data == nullptr) { - return 0; - } - return strncmp(data, sOtrSignature, strlen(sOtrSignature)) == 0; + static const char* sOtrSignaturea = "__OTR__"; + return strncmp(data, sOtrSignaturea, strlen(sOtrSignaturea)) == 0; } // struct TimedEntry { diff --git a/src/port/GBIMiddleware.cpp b/src/port/GBIMiddleware.cpp index 13bda57fd..361ca24e0 100644 --- a/src/port/GBIMiddleware.cpp +++ b/src/port/GBIMiddleware.cpp @@ -13,9 +13,9 @@ extern "C" void gSPDisplayList(Gfx* pkt, Gfx* dl) { auto resource = Ship::Context::GetInstance()->GetResourceManager()->LoadResource(imgData); auto res = std::static_pointer_cast<LUS::DisplayList>(resource); dl = &res->Instructions[0]; - // dl->words.trace.file = imgData; - // dl->words.trace.idx = 0; - // dl->words.trace.valid = true; + dl->words.trace.file = imgData; + dl->words.trace.idx = 0; + dl->words.trace.valid = true; } __gSPDisplayList(pkt, dl); diff --git a/src/port/Game.cpp b/src/port/Game.cpp index cb62afb73..b8f27818f 100644 --- a/src/port/Game.cpp +++ b/src/port/Game.cpp @@ -38,7 +38,10 @@ int main(int argc, char *argv[]) { // audio_init(); // sound_init(); thread5_game_loop(); - GameEngine::Instance->ProcessFrame(push_frame); + while (WindowIsRunning()) { + push_frame(); + } + //GameEngine::Instance->ProcessFrame(push_frame); GameEngine::Instance->Destroy(); return 0; } diff --git a/src/port/resource/importers/ActorSpawnDataFactory.cpp b/src/port/resource/importers/ActorSpawnDataFactory.cpp new file mode 100644 index 000000000..e5a2ea485 --- /dev/null +++ b/src/port/resource/importers/ActorSpawnDataFactory.cpp @@ -0,0 +1,31 @@ +#include "ActorSpawnDataFactory.h" +#include "../type/SpawnData.h" +#include "spdlog/spdlog.h" +#include "libultraship/libultra/gbi.h" +#include <common_structs.h> + +namespace MK64 { + std::shared_ptr<Ship::IResource> ResourceFactoryBinaryActorSpawnDataV0::ReadResource(std::shared_ptr<Ship::File> file) { + if (!FileHasValidFormatAndReader(file)) { + return nullptr; + } + + auto section = std::make_shared<ActorSpawn>(file->InitData); + auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader); + + uint32_t count = reader->ReadUInt32(); + section->ActorSpawnDataList.reserve(count); + + for (uint32_t i = 0; i < count; i++) { + ActorSpawnData data; + data.pos[0] = reader->ReadInt16(); + data.pos[1] = reader->ReadInt16(); + data.pos[2] = reader->ReadInt16(); + data.signedSomeId = reader->ReadUByte(); + + section->ActorSpawnDataList.push_back(data); + } + + return section; + } +}
\ No newline at end of file diff --git a/src/port/resource/importers/ActorSpawnDataFactory.h b/src/port/resource/importers/ActorSpawnDataFactory.h new file mode 100644 index 000000000..5b18717a1 --- /dev/null +++ b/src/port/resource/importers/ActorSpawnDataFactory.h @@ -0,0 +1,12 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactoryBinary.h" + +namespace MK64 { +class ResourceFactoryBinaryActorSpawnDataV0 : public Ship::ResourceFactoryBinary { + public: + std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override; +}; + +} // namespace LUS diff --git a/src/port/resource/importers/KartAIFactory.cpp b/src/port/resource/importers/KartAIFactory.cpp new file mode 100644 index 000000000..f125e154a --- /dev/null +++ b/src/port/resource/importers/KartAIFactory.cpp @@ -0,0 +1,29 @@ +#include "KartAIFactory.h" +#include "../type/KartAI.h" +#include "spdlog/spdlog.h" +#include "libultraship/libultra/gbi.h" + +namespace MK64 { + std::shared_ptr<Ship::IResource> ResourceFactoryBinaryKartAIV0::ReadResource(std::shared_ptr<Ship::File> file) { + if (!FileHasValidFormatAndReader(file)) { + return nullptr; + } + + auto ai = std::make_shared<KartAI>(file->InitData); + auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader); + + uint32_t count = reader->ReadUInt32(); + ai->KartAIList.reserve(count); + + for (uint32_t i = 0; i < count; i++) { + KartAIBehaviour data; + data.waypointStart = reader->ReadInt16(); + data.waypointEnd = reader->ReadInt16(); + data.type = reader->ReadInt32(); + + ai->KartAIList.push_back(data); + } + + return ai; + } +}
\ No newline at end of file diff --git a/src/port/resource/importers/KartAIFactory.h b/src/port/resource/importers/KartAIFactory.h new file mode 100644 index 000000000..5bf6b6ea6 --- /dev/null +++ b/src/port/resource/importers/KartAIFactory.h @@ -0,0 +1,12 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactoryBinary.h" + +namespace MK64 { +class ResourceFactoryBinaryKartAIV0 : public Ship::ResourceFactoryBinary { + public: + std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override; +}; + +} // namespace LUS diff --git a/src/port/resource/importers/TrackSectionsFactory.cpp b/src/port/resource/importers/TrackSectionsFactory.cpp new file mode 100644 index 000000000..512d2c7e3 --- /dev/null +++ b/src/port/resource/importers/TrackSectionsFactory.cpp @@ -0,0 +1,30 @@ +#include "TrackSectionsFactory.h" +#include "../type/TrackSections.h" +#include "spdlog/spdlog.h" +#include "libultraship/libultra/gbi.h" + +namespace MK64 { + std::shared_ptr<Ship::IResource> ResourceFactoryBinaryTrackSectionsV0::ReadResource(std::shared_ptr<Ship::File> file) { + if (!FileHasValidFormatAndReader(file)) { + return nullptr; + } + + auto section = std::make_shared<TrackSectionsClass>(file->InitData); + auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader); + + uint32_t count = reader->ReadUInt32(); + section->TrackSectionsList.reserve(count); + + for (uint32_t i = 0; i < count; i++) { + TrackSectionsI data; + data.addr = reader->ReadUInt32(); + data.surfaceType = reader->ReadUByte(); + data.sectionId = reader->ReadUByte(); + data.flags = reader->ReadUInt16(); + + section->TrackSectionsList.push_back(data); + } + + return section; + } +}
\ No newline at end of file diff --git a/src/port/resource/importers/TrackSectionsFactory.h b/src/port/resource/importers/TrackSectionsFactory.h new file mode 100644 index 000000000..f3cabbdb2 --- /dev/null +++ b/src/port/resource/importers/TrackSectionsFactory.h @@ -0,0 +1,12 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactoryBinary.h" + +namespace MK64 { +class ResourceFactoryBinaryTrackSectionsV0 : public Ship::ResourceFactoryBinary { + public: + std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override; +}; + +} // namespace LUS diff --git a/src/port/resource/importers/TrackWaypointFactory.cpp b/src/port/resource/importers/TrackWaypointFactory.cpp new file mode 100644 index 000000000..a24e88931 --- /dev/null +++ b/src/port/resource/importers/TrackWaypointFactory.cpp @@ -0,0 +1,30 @@ +#include "TrackWaypointFactory.h" +#include "../type/TrackWaypoint.h" +#include "spdlog/spdlog.h" +#include "libultraship/libultra/gbi.h" + +namespace MK64 { + std::shared_ptr<Ship::IResource> ResourceFactoryBinaryTrackWaypointsV0::ReadResource(std::shared_ptr<Ship::File> file) { + if (!FileHasValidFormatAndReader(file)) { + return nullptr; + } + + auto section = std::make_shared<TrackWaypoints>(file->InitData); + auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader); + + uint32_t count = reader->ReadUInt32(); + section->TrackWaypointList.reserve(count); + + for (uint32_t i = 0; i < count; i++) { + TrackWaypoint data; + data.posX = reader->ReadInt16(); + data.posY = reader->ReadInt16(); + data.posZ = reader->ReadInt16(); + data.trackSegment = reader->ReadUInt16(); + + section->TrackWaypointList.push_back(data); + } + + return section; + } +}
\ No newline at end of file diff --git a/src/port/resource/importers/TrackWaypointFactory.h b/src/port/resource/importers/TrackWaypointFactory.h new file mode 100644 index 000000000..f75f07023 --- /dev/null +++ b/src/port/resource/importers/TrackWaypointFactory.h @@ -0,0 +1,12 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactoryBinary.h" + +namespace MK64 { +class ResourceFactoryBinaryTrackWaypointsV0 : public Ship::ResourceFactoryBinary { + public: + std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override; +}; + +} // namespace LUS diff --git a/src/port/resource/type/KartAI.cpp b/src/port/resource/type/KartAI.cpp new file mode 100644 index 000000000..d99b5c091 --- /dev/null +++ b/src/port/resource/type/KartAI.cpp @@ -0,0 +1,15 @@ +#include "KartAI.h" +#include "libultraship/libultra/gbi.h" + +namespace MK64 { +KartAI::KartAI() : Resource(std::shared_ptr<Ship::ResourceInitData>()) { +} + +KartAIBehaviour* KartAI::GetPointer() { + return KartAIList.data(); +} + +size_t KartAI::GetPointerSize() { + return KartAIList.size() * sizeof(KartAIBehaviour); +} +} // namespace LUS diff --git a/src/port/resource/type/KartAI.h b/src/port/resource/type/KartAI.h new file mode 100644 index 000000000..8872b5ee9 --- /dev/null +++ b/src/port/resource/type/KartAI.h @@ -0,0 +1,24 @@ +#pragma once + +#include "resource/Resource.h" +#include <vector> + +struct KartAIBehaviour { + /* 0x0 */ int16_t waypointStart; + /* 0x2 */ int16_t waypointEnd; + /* 0x4 */ int32_t type; +}; // size = 0x8 + +namespace MK64 { +class KartAI : public Ship::Resource<KartAIBehaviour> { + public: + using Resource::Resource; + + KartAI(); + + KartAIBehaviour* GetPointer() override; + size_t GetPointerSize() override; + + std::vector<KartAIBehaviour> KartAIList; +}; +} // namespace LUS diff --git a/src/port/resource/type/ResourceType.h b/src/port/resource/type/ResourceType.h index c143457d2..e8d7d91aa 100644 --- a/src/port/resource/type/ResourceType.h +++ b/src/port/resource/type/ResourceType.h @@ -1,21 +1,32 @@ #pragma once namespace SF64 { -enum class ResourceType { + enum class ResourceType { // SF64 - AnimData = 0x414E494D, // ANIM - ColPoly = 0x43504C59, // CPLY - EnvSettings = 0x454E5653, // ENVS - Limb = 0x4C494D42, // LIMB - Message = 0x4D534720, // MSG - MessageTable = 0x4D534754, // MSGT - Skeleton = 0x534B454C, // SKEL - Script = 0x53435250, // SCRP - ScriptCmd = 0x53434D44, // SCMD - Hitbox = 0x48544258, // HTBX - ObjectInit = 0x4F42494E, // OBIN - Vec3f = 0x56433346, // VC3F - Vec3s = 0x56433353, // VC3S - GenericArray = 0x47415252, // GARR -}; + AnimData = 0x414E494D, // ANIM + ColPoly = 0x43504C59, // CPLY + EnvSettings = 0x454E5653, // ENVS + Limb = 0x4C494D42, // LIMB + Message = 0x4D534720, // MSG + MessageTable = 0x4D534754, // MSGT + Skeleton = 0x534B454C, // SKEL + Script = 0x53435250, // SCRP + ScriptCmd = 0x53434D44, // SCMD + Hitbox = 0x48544258, // HTBX + ObjectInit = 0x4F42494E, // OBIN + Vec3f = 0x56433346, // VC3F + Vec3s = 0x56433353, // VC3S + GenericArray = 0x47415252, // GARR + }; } // namespace SOH + +namespace MK64 { + enum class ResourceType { + CourseVertex = 0x43565458, // CVTX + TrackSection = 0x5343544E, // SCTN + Waypoints = 0x57505453, // WPTS + Metadata = 0x4D444154, // MDAT + SpawnData = 0x53444154, // SDAT + KartAI = 0x44424856, // DBHV + }; +}
\ No newline at end of file diff --git a/src/port/resource/type/SpawnData.cpp b/src/port/resource/type/SpawnData.cpp new file mode 100644 index 000000000..9db940b16 --- /dev/null +++ b/src/port/resource/type/SpawnData.cpp @@ -0,0 +1,15 @@ +#include "SpawnData.h" +#include "libultraship/libultra/gbi.h" + +namespace MK64 { +ActorSpawn::ActorSpawn() : Resource(std::shared_ptr<Ship::ResourceInitData>()) { +} + +ActorSpawnData* ActorSpawn::GetPointer() { + return ActorSpawnDataList.data(); +} + +size_t ActorSpawn::GetPointerSize() { + return ActorSpawnDataList.size() * sizeof(ActorSpawnData); +} +} // namespace LUS diff --git a/src/port/resource/type/SpawnData.h b/src/port/resource/type/SpawnData.h new file mode 100644 index 000000000..185050d8d --- /dev/null +++ b/src/port/resource/type/SpawnData.h @@ -0,0 +1,28 @@ +#pragma once + +#include "resource/Resource.h" +#include <vector> +#include <libultra/gbi.h> +#include <common_structs.h> + +struct ActorSpawnData { + /* 0x00 */ Vec3s pos; + union { + /* 0x06 */ u16 someId; // Usually populated, but not necessarily used by all actors types + /* 0x06 */ s16 signedSomeId; + }; +}; + +namespace MK64 { +class ActorSpawn : public Ship::Resource<ActorSpawnData> { + public: + using Resource::Resource; + + ActorSpawn(); + + ActorSpawnData* GetPointer() override; + size_t GetPointerSize() override; + + std::vector<ActorSpawnData> ActorSpawnDataList; +}; +} // namespace LUS diff --git a/src/port/resource/type/TrackSections.cpp b/src/port/resource/type/TrackSections.cpp new file mode 100644 index 000000000..c0121961b --- /dev/null +++ b/src/port/resource/type/TrackSections.cpp @@ -0,0 +1,15 @@ +#include "TrackSections.h" +#include "libultraship/libultra/gbi.h" + +namespace MK64 { +TrackSectionsClass::TrackSectionsClass() : Resource(std::shared_ptr<Ship::ResourceInitData>()) { +} + +TrackSectionsI* TrackSectionsClass::GetPointer() { + return TrackSectionsList.data(); +} + +size_t TrackSectionsClass::GetPointerSize() { + return TrackSectionsList.size() * sizeof(TrackSectionsI); +} +} // namespace LUS diff --git a/src/port/resource/type/TrackSections.h b/src/port/resource/type/TrackSections.h new file mode 100644 index 000000000..50a70c3bf --- /dev/null +++ b/src/port/resource/type/TrackSections.h @@ -0,0 +1,26 @@ +#pragma once + +#include "resource/Resource.h" +#include <vector> +#include <libultra/gbi.h> + +typedef struct { + uintptr_t addr; + uint8_t surfaceType; + uint8_t sectionId; + uint16_t flags; +} TrackSectionsI; + +namespace MK64 { +class TrackSectionsClass : public Ship::Resource<TrackSectionsI> { + public: + using Resource::Resource; + + TrackSectionsClass(); + + TrackSectionsI* GetPointer() override; + size_t GetPointerSize() override; + + std::vector<TrackSectionsI> TrackSectionsList; +}; +} // namespace LUS diff --git a/src/port/resource/type/TrackWaypoint.cpp b/src/port/resource/type/TrackWaypoint.cpp new file mode 100644 index 000000000..d8515c4a9 --- /dev/null +++ b/src/port/resource/type/TrackWaypoint.cpp @@ -0,0 +1,15 @@ +#include "TrackWaypoint.h" +#include "libultraship/libultra/gbi.h" + +namespace MK64 { +TrackWaypoints::TrackWaypoints() : Resource(std::shared_ptr<Ship::ResourceInitData>()) { +} + +TrackWaypoint* TrackWaypoints::GetPointer() { + return TrackWaypointList.data(); +} + +size_t TrackWaypoints::GetPointerSize() { + return TrackWaypointList.size() * sizeof(TrackWaypoint); +} +} // namespace LUS diff --git a/src/port/resource/type/TrackWaypoint.h b/src/port/resource/type/TrackWaypoint.h new file mode 100644 index 000000000..a1e7ce4ee --- /dev/null +++ b/src/port/resource/type/TrackWaypoint.h @@ -0,0 +1,26 @@ +#pragma once + +#include "resource/Resource.h" +#include <vector> +#include <libultra/gbi.h> + +struct TrackWaypoint { + int16_t posX; + int16_t posY; + int16_t posZ; + uint16_t trackSegment; +}; + +namespace MK64 { +class TrackWaypoints : public Ship::Resource<TrackWaypoint> { + public: + using Resource::Resource; + + TrackWaypoints(); + + TrackWaypoint* GetPointer() override; + size_t GetPointerSize() override; + + std::vector<TrackWaypoint> TrackWaypointList; +}; +} // namespace LUS diff --git a/src/racing/actors.c b/src/racing/actors.c index afcd10d44..2258a8069 100644 --- a/src/racing/actors.c +++ b/src/racing/actors.c @@ -3,6 +3,7 @@ #include <course_offsets.h> #include <macros.h> #include <mk64.h> +#include <align_asset_macro.h> #include <sounds.h> #include <common_structs.h> #include <actor_types.h> @@ -25,6 +26,7 @@ #include "courses/all_course_data.h" #include "main.h" #include <assets/other_textures.h> +#include <assets/mario_raceway_data.h> // Appears to be textures // or tluts @@ -1022,9 +1024,13 @@ void spawn_course_actors(void) { gNumPermanentActors = 0; switch (gCurrentCourseId) { case COURSE_MARIO_RACEWAY: - spawn_foliage(d_course_mario_raceway_tree_spawns); - spawn_piranha_plants(d_course_mario_raceway_piranha_plant_spawns); - spawn_all_item_boxes(d_course_mario_raceway_item_box_spawns); + struct ActorSpawnData *a_d_course_mario_raceway_tree_spawns = (struct ActorSpawnData *) LOAD_ASSET(d_course_mario_raceway_tree_spawns); + struct ActorSpawnData *a_d_course_mario_raceway_piranha_plant_spawns = (struct ActorSpawnData *) LOAD_ASSET(d_course_mario_raceway_piranha_plant_spawns); + struct ActorSpawnData *a_d_course_mario_raceway_item_box_spawns = (struct ActorSpawnData *) LOAD_ASSET(d_course_mario_raceway_item_box_spawns); + + spawn_foliage(a_d_course_mario_raceway_tree_spawns); + spawn_piranha_plants(a_d_course_mario_raceway_piranha_plant_spawns); + spawn_all_item_boxes(a_d_course_mario_raceway_item_box_spawns); vec3f_set(position, 150.0f, 40.0f, -1300.0f); position[0] *= gCourseDirection; add_actor_to_empty_slot(position, rotation, velocity, ACTOR_MARIO_SIGN); diff --git a/src/racing/collision.c b/src/racing/collision.c index 1f3b94a7a..2b0d6d0fd 100644 --- a/src/racing/collision.c +++ b/src/racing/collision.c @@ -1986,22 +1986,43 @@ void find_and_set_vertex_data(Gfx *addr, s8 surfaceType, u16 sectionId) { uintptr_t lo; uintptr_t hi; s32 i; - + //printf("Initial\n"); + //printf("ptr 0x%llX\n", &addr); + //printf("w0 0x%llX\n", addr->words.w0); + //printf("w1 0x%llX\n", addr->words.w1); + //printf("----loop----\n"); Gfx *gfx = (Gfx *) addr; D_8015F6FA = 0; D_8015F6FC = 0; + //u8 *orig = segmented_gfx_to_virtual(0x07000000); + + // printf("\n\nORIG:\n"); + // for (size_t i = 0; i < 100; i++) { + // printf(" 0x%X ", orig[i]); + // } + for (i = 0; i < 0x1FFF; i++) { lo = gfx->words.w0; hi = gfx->words.w1; opcode = GFX_GET_OPCODE(lo); + + // printf("ptr 0x%llX\n", &addr); + // printf("op 0x%llX\n", opcode); + // printf("w0 0x%X\n", lo); + // printf("w1 0x%X\n", hi); if (opcode == (G_DL << 24)) { // G_DL's hi contains an addr to another DL. - find_and_set_vertex_data((Gfx *) hi, surfaceType, sectionId); + Gfx *dl = segmented_gfx_to_virtual(hi); + // printf("DL: 0x%llX\n", &dl); + // printf(" w0 0x%X\n", dl->words.w0); + // printf(" w1 0x%X\n", dl->words.w1); + + find_and_set_vertex_data((Gfx *) (dl), surfaceType, sectionId); } else if (opcode == (G_VTX << 24)) { - set_vtx_buffer(hi, (lo >> 10) & 0x3F, ((lo >> 16) & 0xFF) >> 1); + set_vtx_buffer(segmented_gfx_to_virtual(hi), (lo >> 10) & 0x3F, ((lo >> 16) & 0xFF) >> 1); } else if (opcode == (G_TRI1 << 24)) { D_8015F58C += 1; @@ -2015,7 +2036,7 @@ void find_and_set_vertex_data(Gfx *addr, s8 surfaceType, u16 sectionId) { D_8015F58C += 2; set_vtx_from_quadrangle(hi, surfaceType, sectionId); - } else if (opcode == (G_ENDDL << 24)) { + } else if (opcode == (int32_t)(G_ENDDL << 24)) { break; } diff --git a/src/racing/math_util.c b/src/racing/math_util.c index da376866e..5a99b0ca3 100644 --- a/src/racing/math_util.c +++ b/src/racing/math_util.c @@ -52,16 +52,16 @@ s32 render_set_position(Mat4 arg0, s32 arg1) { mtxf_to_mtx(&gGfxPool->mtxObject[gMatrixObjectCount], arg0); switch (arg1) { /* irregular */ case 0: - gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(&gGfxPool->mtxObject[gMatrixObjectCount++]), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPMatrix(gDisplayListHead++, &gGfxPool->mtxObject[gMatrixObjectCount++], G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); break; case 1: - gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(&gGfxPool->mtxObject[gMatrixObjectCount++]), G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPMatrix(gDisplayListHead++, &gGfxPool->mtxObject[gMatrixObjectCount++], G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW); break; case 3: - gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(&gGfxPool->mtxObject[gMatrixObjectCount++]), G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW); + gSPMatrix(gDisplayListHead++, &gGfxPool->mtxObject[gMatrixObjectCount++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW); break; case 2: - gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(&gGfxPool->mtxObject[gMatrixObjectCount++]), G_MTX_NOPUSH | G_MTX_MUL | G_MTX_MODELVIEW); + gSPMatrix(gDisplayListHead++, &gGfxPool->mtxObject[gMatrixObjectCount++], G_MTX_NOPUSH | G_MTX_MUL | G_MTX_MODELVIEW); break; } return 1; diff --git a/src/racing/memory.c b/src/racing/memory.c index 8bf42fedb..a7ecbaa42 100644 --- a/src/racing/memory.c +++ b/src/racing/memory.c @@ -1,5 +1,6 @@ #include <libultraship.h> #include <libultra/types.h> +#include <align_asset_macro.h> #include <macros.h> #include <common_structs.h> #include <segments.h> @@ -12,10 +13,16 @@ #include "math_util.h" #include "courses/courseTable.h" #include "defines.h" +#include <assets/mario_raceway_displaylists.h> +#include <assets/mario_raceway_vertices.h> +#include <assert.h> s32 sGfxSeekPosition; s32 sPackedSeekPosition; +static u8 sMemoryPool[0xFFFFF]; // Stock memory pool size: 0xAB630 +uintptr_t sPoolEnd = sMemoryPool + sizeof(sMemoryPool); + uintptr_t sPoolFreeSpace; struct MainPoolBlock *sPoolListHeadL; struct MainPoolBlock *sPoolListHeadR; @@ -28,6 +35,11 @@ struct UnkStruct_802B8CD4 D_802B8CD4[] = { s32 D_802B8CE4 = 0; // pad s32 memoryPadding[2]; +#define PRINT_MEMPOOL \ + printf("\nPool Start: 0x%llX, Pool End: 0x%llX, size: 0x%llX\ngNextFreeMemoryAddress: 0x%llX\n\n", sMemoryPool, \ + sMemoryPool + sizeof(sMemoryPool), (sMemoryPool + sizeof(sMemoryPool)) - sMemoryPool, gNextFreeMemoryAddress) + + /** * @brief Returns the address of the next available memory location and updates the memory pointer * to reference the next location of available memory based provided size to allocate. @@ -38,6 +50,13 @@ void *get_next_available_memory_addr(uintptr_t size) { uintptr_t freeSpace = (uintptr_t) gNextFreeMemoryAddress; size = ALIGN16(size); gNextFreeMemoryAddress += size; + + if (gNextFreeMemoryAddress > sPoolEnd) { + printf("[memory.c] get_next_available_memory_addr(): Memory Pool Out of Bounds! Out of memory!\n"); + PRINT_MEMPOOL; + assert(false); + } + //printf("\nNEXT MEM ADDR 0x%llX\n\n", freeSpace[0]); return (void *) freeSpace; } @@ -73,7 +92,22 @@ void *segmented_to_virtual(const void *addr) { size_t segment = (uintptr_t) addr >> 24; size_t offset = (uintptr_t) addr & 0x00FFFFFF; - return (void *) ((gSegmentTable[segment] + offset) | 0x80000000); + return (void *) ((gSegmentTable[segment] + offset)); +} + +void *segment_offset_to_virtual(uint32_t segment, uint32_t offset) { + return (void *) (gSegmentTable[segment] + ( (offset / 8) * sizeof(Gfx) ) ); +} + +void *segmented_gfx_to_virtual(const void *addr) { + size_t segment = (uintptr_t) addr >> 24; + size_t offset = (uintptr_t) addr & 0x00FFFFFF; + + offset = (offset / 8) * sizeof(Gfx); + + printf("seg_gfx_to_virt: 0x%llX\n",addr); + + return (void *) ((gSegmentTable[segment] + offset)); } void move_segment_table_to_dmem(void) { @@ -89,15 +123,21 @@ void move_segment_table_to_dmem(void) { * * Default memory size, 701.984 Kilobytes. */ -void initialize_memory_pool(uintptr_t poolStart, uintptr_t poolEnd) { +void initialize_memory_pool() { + + uintptr_t poolStart = sMemoryPool; + //uintptr_t sPoolEnd = sMemoryPool + sizeof(sMemoryPool); + + bzero(sMemoryPool, sizeof(sMemoryPool)); poolStart = ALIGN16(poolStart); // Truncate to a 16-byte boundary. - poolEnd &= ~0xF; + sPoolEnd &= ~0xF; - gFreeMemorySize = (poolEnd - poolStart) - 0x10; + gFreeMemorySize = (sPoolEnd - poolStart) - 0x10; gNextFreeMemoryAddress = poolStart; - int bp = 0; + + PRINT_MEMPOOL; } /** @@ -108,9 +148,23 @@ void *allocate_memory(uintptr_t size) { size = ALIGN16(size); gFreeMemorySize -= size; + + if (gFreeMemorySize < 0) { + printf("[memory.c] allocate_memory(): gFreeMemorySize below zero!\n"); + printf("gFreeMemorySize: 0x%X", gFreeMemorySize); + PRINT_MEMPOOL; + assert(false); + } + freeSpace = (uintptr_t ) gNextFreeMemoryAddress; gNextFreeMemoryAddress += size; + if (gNextFreeMemoryAddress > sPoolEnd) { + printf("[memory.c] allocate_memory(): Memory Pool Out of Bounds! Out of memory!\n"); + PRINT_MEMPOOL; + assert(false); + } + return (void *) freeSpace; } @@ -415,21 +469,15 @@ uintptr_t MIO0_0F(u8 *arg0, uintptr_t arg1, uintptr_t arg2) { return oldHeapEndPtr; } -void func_802A86A8(CourseVtx *data, uintptr_t arg1) { - CourseVtx *courseVtx = data; - Vtx *vtx; +void func_802A86A8(CourseVtx *courseVtx, Vtx *vtx, size_t arg1) { s32 tmp = ALIGN16(arg1 * 0x10); -#ifdef AVOID_UB - uintptr_t i; -#else - s32 i; -#endif + size_t i; s8 temp_a0; s8 temp_a3; s8 flags; - gHeapEndPtr -= tmp; - vtx = (Vtx *) gHeapEndPtr; + //gHeapEndPtr -= tmp; + //vtx = (Vtx *) gHeapEndPtr; // s32 to uintptr_t comparison required for matching. for (i = 0; i < arg1; i++) { @@ -469,7 +517,7 @@ void decompress_vtx(CourseVtx *arg0, uintptr_t vertexCount) { gNextFreeMemoryAddress += size; mio0decode(vtxCompressed, (u8 *) freeSpace); - func_802A86A8((CourseVtx *) freeSpace, vertexCount); + //func_802A86A8((CourseVtx *) freeSpace, vertexCount); set_segment_base_addr(4, (void *) gHeapEndPtr); } @@ -961,18 +1009,19 @@ UNUSED void func_802A9AEC(void) { * This issue is prevented so long as the packed file adheres to correct opcodes and unpack code * increments the file pointer the correct number of times. */ -void displaylist_unpack(uintptr_t *data, uintptr_t finalDisplaylistOffset, uintptr_t arg2) { + +void displaylist_unpack(Gfx *gfx, u8 *data, uintptr_t arg2) { u8 *packed_dl = data; - Gfx *gfx; - uintptr_t addr; + //uintptr_t addr; u8 opcode; - finalDisplaylistOffset = ALIGN16(finalDisplaylistOffset) + 8; - gHeapEndPtr -= finalDisplaylistOffset; - addr = gHeapEndPtr; - gfx = (Gfx *) gHeapEndPtr; + // finalDisplaylistOffset = ALIGN16(finalDisplaylistOffset) + 8; + // gHeapEndPtr -= finalDisplaylistOffset; + // addr = gHeapEndPtr; + // gfx = (Gfx *) gHeapEndPtr; + sGfxSeekPosition = 0; sPackedSeekPosition = 0; @@ -1251,7 +1300,7 @@ void displaylist_unpack(uintptr_t *data, uintptr_t finalDisplaylistOffset, uintp break; } } - set_segment_base_addr(0x7, (void *) addr); + //set_segment_base_addr(0x7, (void *) addr); } struct UnkStr_802AA7C8 { @@ -1323,6 +1372,29 @@ void *decompress_segments(u8 *start, u8 *end) { * @param courseId */ void load_course(s32 courseId) { + printf("Loading Course Data\n"); + + // Extract packed DLs + u8 *packed = (u8 *) LOAD_ASSET(d_course_mario_raceway_packed_dls); + Gfx *gfx = (Gfx *) allocate_memory(sizeof(Gfx) * 3366); // Size of unpacked DLs + displaylist_unpack(gfx, packed, 0); + + gSegmentTable[7] = &gfx[0]; + + // Convert course vtx to vtx + CourseVtx *cvtx = (CourseVtx *) LOAD_ASSET(d_course_mario_raceway_vertex); + Vtx *vtx = (Vtx *) allocate_memory(sizeof(Vtx) * 5757); + func_802A86A8(cvtx, vtx, 5757); + gSegmentTable[4] = &vtx[0]; + + + + +// __gSPSegment(gDisplayListHead++, 7, &gfx); + + + //printf("Course Data Loaded!\n"); + // Future implementation for Extra mode and course stretching. // if (gIsMirrorMode) { diff --git a/src/racing/memory.h b/src/racing/memory.h index 0f7bf5ec9..ed940453b 100644 --- a/src/racing/memory.h +++ b/src/racing/memory.h @@ -45,8 +45,10 @@ void *get_next_available_memory_addr(uintptr_t); uintptr_t set_segment_base_addr(s32, void*); void *get_segment_base_addr(s32); void *segmented_to_virtual(const void *); +void *segment_offset_to_virtual(uint32_t, uint32_t); +void *segmented_gfx_to_virtual(const void *); void move_segment_table_to_dmem(void); -void initialize_memory_pool(uintptr_t, uintptr_t); +void initialize_memory_pool(void); void *decompress_segments(u8*, u8*); void *allocate_memory(uintptr_t); void *load_data(uintptr_t, uintptr_t); diff --git a/src/racing/render_courses.c b/src/racing/render_courses.c index 0ae83937e..5a625aef8 100644 --- a/src/racing/render_courses.c +++ b/src/racing/render_courses.c @@ -19,6 +19,7 @@ #include "courses/all_course_data.h" #include "courses/all_course_packed.h" #include "courses/all_course_offsets.h" +#include <assets/mario_raceway_data.h> s16 D_802B87B0 = 995; s16 D_802B87B4 = 1000; @@ -45,8 +46,19 @@ s32 func_80290C20(Camera *camera) { return 0; } -void parse_course_displaylists(uintptr_t addr) { - TrackSections *section = (TrackSections *) addr; +void parse_course_displaylists(TrackSections *addr) { + TrackSections *first = addr; + TrackSections *section = addr; + + while (addr->addr != 0) { + section->addr = segmented_gfx_to_virtual(addr->addr); + addr++; + section++; + } + section = first; + //section->surfaceType = addr->surfaceType; + //section->flags = addr->flags; + //section->sectionId = addr->sectionId; while(section->addr != 0) { if (section->flags & 0x8000) { @@ -183,14 +195,17 @@ void load_surface_map(Gfx *addr[], struct UnkStruct_800DC5EC *arg1) { } void func_80291198(void) { - gSPDisplayList(gDisplayListHead++, ((uintptr_t)d_course_mario_raceway_packed_dl_1140)); + // d_course_mario_raceway_packed_dl_1140 + gSPDisplayList(gDisplayListHead++, ((uintptr_t) segmented_gfx_to_virtual(0x07001140))); // } void func_802911C4(void) { if (gScreenModeSelection == SCREEN_MODE_1P) { - gSPDisplayList(gDisplayListHead++, ((uintptr_t)d_course_mario_raceway_packed_dl_8E8)); + // d_course_mario_raceway_packed_dl_8E8 + gSPDisplayList(gDisplayListHead++, ((uintptr_t)segmented_gfx_to_virtual(0x070008E8))); } else { - gSPDisplayList(gDisplayListHead++, ((uintptr_t)d_course_mario_raceway_packed_dl_2D68)); + // d_course_mario_raceway_packed_dl_2D68 + gSPDisplayList(gDisplayListHead++, ((uintptr_t)segmented_gfx_to_virtual(0x07002D68))); } } @@ -512,7 +527,8 @@ void render_mario_raceway(struct UnkStruct_800DC5EC *arg0) { if (func_80290C20(arg0->camera) == 1) { gDPSetCombineMode(gDisplayListHead++, G_CC_SHADE, G_CC_SHADE); gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2); - gSPDisplayList(gDisplayListHead++, ((uintptr_t) d_course_mario_raceway_packed_dl_3050)); + // d_course_mario_raceway_packed_dl_3050 + gSPDisplayList(gDisplayListHead++, ((uintptr_t) segmented_gfx_to_virtual(0x07003050))); } gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING); @@ -595,19 +611,26 @@ void render_mario_raceway(struct UnkStruct_800DC5EC *arg0) { } gDPSetCombineMode(gDisplayListHead++, G_CC_MODULATEIA, G_CC_MODULATEIA); gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2); - gSPDisplayList(gDisplayListHead++, ((uintptr_t) d_course_mario_raceway_packed_dl_3508)); - gSPDisplayList(gDisplayListHead++, ((uintptr_t) d_course_mario_raceway_packed_dl_3240)); - gSPDisplayList(gDisplayListHead++, ((uintptr_t) d_course_mario_raceway_packed_dl_14A0)); + // d_course_mario_raceway_packed_dl_3508 + gSPDisplayList(gDisplayListHead++, ((uintptr_t) segmented_gfx_to_virtual(0x07003508))); + // d_course_mario_raceway_packed_dl_3240 + gSPDisplayList(gDisplayListHead++, ((uintptr_t) segmented_gfx_to_virtual(0x07003240))); + // d_course_mario_raceway_packed_dl_14A0 + gSPDisplayList(gDisplayListHead++, ((uintptr_t) segmented_gfx_to_virtual(0x070014A0))); printf("LOADING SURFACE MAP\n"); load_surface_map(&mario_raceway_dls, arg0); gDPSetCombineMode(gDisplayListHead++, G_CC_MODULATEIDECALA, G_CC_MODULATEIDECALA); gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_TEX_EDGE, G_RM_AA_ZB_TEX_EDGE2); gSPClearGeometryMode(gDisplayListHead++, G_CULL_BACK); - gSPDisplayList(gDisplayListHead++, ((uintptr_t) d_course_mario_raceway_packed_dl_450)); - gSPDisplayList(gDisplayListHead++, ((uintptr_t) d_course_mario_raceway_packed_dl_240)); + // d_course_mario_raceway_packed_dl_450 + gSPDisplayList(gDisplayListHead++, ((uintptr_t) segmented_gfx_to_virtual(0x07000450))); + // d_course_mario_raceway_packed_dl_240 + gSPDisplayList(gDisplayListHead++, ((uintptr_t) segmented_gfx_to_virtual(0x07000240))); gSPSetGeometryMode(gDisplayListHead++, G_CULL_BACK); - gSPDisplayList(gDisplayListHead++, ((uintptr_t) d_course_mario_raceway_packed_dl_E0)); - gSPDisplayList(gDisplayListHead++, ((uintptr_t) d_course_mario_raceway_packed_dl_160)); + // d_course_mario_raceway_packed_dl_E0 + gSPDisplayList(gDisplayListHead++, ((uintptr_t) segmented_gfx_to_virtual(0x070000E0))); + // d_course_mario_raceway_packed_dl_160 + gSPDisplayList(gDisplayListHead++, ((uintptr_t) segmented_gfx_to_virtual(0x07000160))); printf("SURFACE MAP LOADED\n"); } @@ -1390,6 +1413,14 @@ void func_80295D6C(void) { D_8015F6F6 = -3000; } +typedef struct { + uint16_t segment; + uint16_t offset; + uint8_t surfaceType; + uint8_t sectionId; + uint16_t flags; +} TrackSectionsI; + void func_80295D88(void) { gNumActors = 0; @@ -1411,13 +1442,18 @@ void func_80295D88(void) { D_800DC5C8 = 0; switch (gCurrentCourseId) { case COURSE_MARIO_RACEWAY: - set_vertex_data_with_defaults((Gfx *) d_course_mario_raceway_packed_dl_1140); + // d_course_mario_raceway_packed_dl_1140 + set_vertex_data_with_defaults((Gfx *) segmented_gfx_to_virtual(0x07001140)); if (gScreenModeSelection == SCREEN_MODE_1P) { - set_vertex_data_with_defaults((Gfx *) d_course_mario_raceway_packed_dl_8E8); + // d_course_mario_raceway_packed_dl_8E8 + set_vertex_data_with_defaults((Gfx *) segmented_gfx_to_virtual(0x070008E8)); } else { - set_vertex_data_with_defaults((Gfx *) d_course_mario_raceway_packed_dl_2D68); + // d_course_mario_raceway_packed_dl_2D68 + set_vertex_data_with_defaults((Gfx *) segmented_gfx_to_virtual(0x07002D68)); } - parse_course_displaylists((uintptr_t) d_course_mario_raceway_addr); + TrackSections *section = (TrackSections *) LOAD_ASSET(d_course_mario_raceway_addr); + + parse_course_displaylists(section); func_80295C6C(); D_8015F8E4 = gCourseMinY - 10.0f; break; diff --git a/src/racing/skybox_and_splitscreen.c b/src/racing/skybox_and_splitscreen.c index 4f4dd5075..e07c7211e 100644 --- a/src/racing/skybox_and_splitscreen.c +++ b/src/racing/skybox_and_splitscreen.c @@ -248,7 +248,7 @@ UNUSED s32 set_viewport2(void) { } void set_viewport(void) { - gSPViewport(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(&D_802B8880)); + gSPViewport(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(D_802B8880)); gSPClearGeometryMode(gDisplayListHead++, G_CLEAR_ALL_MODES); gSPSetGeometryMode(gDisplayListHead++, G_SHADE | G_CULL_BACK | G_SHADING_SMOOTH); } @@ -279,7 +279,7 @@ void func_802A4300(void) { gDPSetCycleType(gDisplayListHead++, G_CYC_FILL); gDPSetColorImage(gDisplayListHead++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, VIRTUAL_TO_PHYSICAL(gPhysicalFramebuffers[sRenderingFramebuffer])); gDPSetFillColor(gDisplayListHead++, 0x00010001); - gSPViewport(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(&D_802B8880)); + gSPViewport(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(D_802B8880)); gDPSetScissor(gDisplayListHead++, G_SC_NON_INTERLACE, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); gDPPipeSync(gDisplayListHead++); diff --git a/src/render_objects.c b/src/render_objects.c index 758826b65..0d1f4eccf 100644 --- a/src/render_objects.c +++ b/src/render_objects.c @@ -36,6 +36,7 @@ #include "courses/all_course_data.h" #include <vehicles.h> #include "data/some_data.h" +#include <assets/some_data.h> void func_800431B0(Vec3f pos, Vec3su orientation, f32 scale, Vtx *vtx) { rsp_set_matrix_transformation(pos, orientation, scale); @@ -3554,7 +3555,7 @@ void func_80053E6C(s32 arg0) { s32 objectIndex; gSPDisplayList(gDisplayListHead++, D_0D007E98); - gDPLoadTLUT_pal256(gDisplayListHead++, D_800E52D0); + gDPLoadTLUT_pal256(gDisplayListHead++, gTLUTOnomatopoeia); func_8004B614(0, 0, 0, 0, 0, 0, 0); D_80183E80[0] = 0; D_80183E80[1] = 0x8000; |
