diff --git a/Makefile b/Makefile index d6606c87..8f43ab3d 100755 --- a/Makefile +++ b/Makefile @@ -214,6 +214,10 @@ ifeq ($(shell getconf LONG_BIT), 64) endif CC_CHECK_CFLAGS := -fsyntax-only -funsigned-char $(INCLUDE_CFLAGS) $(DEF_INC_CFLAGS) -std=gnu90 -Wall -Wextra -Wno-format-security -Wno-main -DNON_MATCHING -DAVOID_UB -D_LANGUAGE_C -DNDEBUG -Werror-implicit-function-declaration +# Disable GCC complaining about fakematches necessary to match if building a matching ROM. Example: "var2 = (0, var1)" +ifeq ($(NON_MATCHING),0) + CC_CHECK_CFLAGS += -Wno-unused-value +endif #Warnings to ignore CC_CHECK_CFLAGS += -Wno-builtin-declaration-mismatch -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -Wno-switch diff --git a/asm/non_matchings/menu/func_80087F14.s b/asm/non_matchings/menu/func_80087F14.s index 12ef6ae2..6371b317 100644 --- a/asm/non_matchings/menu/func_80087F14.s +++ b/asm/non_matchings/menu/func_80087F14.s @@ -261,7 +261,7 @@ glabel func_80087F14 /* 088EB8 800882B8 25080004 */ addiu $t0, $t0, 4 /* 088EBC 800882BC 14BFFFBE */ bne $a1, $ra, .L800881B8 /* 088EC0 800882C0 A3200000 */ sb $zero, ($t9) -/* 088EC4 800882C4 0C01D859 */ jal packDirectoryFree +/* 088EC4 800882C4 0C01D859 */ jal cpak_free_files /* 088EC8 800882C8 AFAA0078 */ sw $t2, 0x78($sp) /* 088ECC 800882CC 8FAE0090 */ lw $t6, 0x90($sp) /* 088ED0 800882D0 3C108012 */ lui $s0, %hi(sCurrentControllerPakFreeSpace) # $s0, 0x8012 diff --git a/src/audio_spatial.c b/src/audio_spatial.c index c3e65cc7..a31d1795 100644 --- a/src/audio_spatial.c +++ b/src/audio_spatial.c @@ -544,9 +544,9 @@ void debug_render_line(Gfx **dlist, Vertex **verts, Triangle **tris, floatXYZVal temp_tris[0].vi0 = 2; temp_tris[0].vi1 = 1; temp_tris[0].vi2 = 0; - temp_tris[0].uv0.u = 0x3E0; - temp_tris[0].uv0.v = 0x3E0; - temp_tris[0].uv1.u = 0x3E0; + temp_tris[0].uv0.u = 1024 - 32; + temp_tris[0].uv0.v = 1024 - 32; + temp_tris[0].uv1.u = 1024 - 32; temp_tris[0].uv1.v = 0; temp_tris[0].uv2.u = 1; temp_tris[0].uv2.v = 0; @@ -555,9 +555,9 @@ void debug_render_line(Gfx **dlist, Vertex **verts, Triangle **tris, floatXYZVal temp_tris[1].vi1 = 2; temp_tris[1].vi2 = 1; temp_tris[1].uv0.u = 1; - temp_tris[1].uv0.v = 0x3E0; - temp_tris[1].uv1.u = 0x3E0; - temp_tris[1].uv1.v = 0x3E0; + temp_tris[1].uv0.v = 1024 - 32; + temp_tris[1].uv1.u = 1024 - 32; + temp_tris[1].uv1.v = 1024 - 32; temp_tris[1].uv2.u = 1; temp_tris[1].uv2.v = 0; temp_tris += 2; diff --git a/src/game_ui.c b/src/game_ui.c index e04256da..9c8a9625 100644 --- a/src/game_ui.c +++ b/src/game_ui.c @@ -381,7 +381,7 @@ void render_hud(Gfx **dList, MatrixS **mtx, Vertex **vertexList, Object *obj, s3 gMinimapOpacity = 0; } } - if (gShowHUD == 0) { + if (gShowHUD == FALSE) { racer = (Object_Racer *) obj->unk64; if (D_8012718A) { D_80126D10 = 1 - racer->playerIndex; @@ -959,7 +959,8 @@ void render_hud_battle(s32 countdown, Object *obj, s32 updateRate) { } } -#ifdef NON_EQUIVALENT +#ifdef NON_MATCHING +// hud_render_lives void func_800A1E48(Object *racerObj, s32 updateRate) { f32 temp; s32 i; @@ -2188,10 +2189,11 @@ void hud_draw_finish_misc(Object_Racer *racer) { } } -#ifdef NON_EQUIVALENT +#ifdef NON_MATCHING +// hud_render_finish void func_800A6254(Object_Racer *racer, s32 updateRate) { - s32 *var_a0; - s32 var_t0; + UNUSED s32 *var_a0; + UNUSED s32 var_t0; s32 var_a2; s32 var_v1; s32 raceType; diff --git a/src/gzip.c b/src/gzip.c index eb559946..b8287c26 100644 --- a/src/gzip.c +++ b/src/gzip.c @@ -8,7 +8,7 @@ /************ .data ************/ huft *gHuftTable = NULL; // gzip_huft_alloc -s32 *gAssetAddress = NULL; +s32 *gPackedHeader = NULL; u8 *gzip_inflate_input = NULL; u8 *gzip_inflate_output = NULL; @@ -22,9 +22,12 @@ s32 gHuftTablePos; // gzip_hufts /******************************/ -void init_rzip(void) { +/** + * Allocate space for the decompression heap and file header. + */ +void gzip_init(void) { gHuftTable = (huft *) allocate_from_main_pool_safe(0x2800, COLOUR_TAG_BLACK); - gAssetAddress = (s32 *) allocate_from_main_pool_safe(0x10, COLOUR_TAG_BLACK); + gPackedHeader = (s32 *) allocate_from_main_pool_safe(0x10, COLOUR_TAG_BLACK); } /** @@ -46,8 +49,8 @@ s32 byteswap32(u8 *arg0) { * Official name: rzipUncompressSizeROM */ s32 get_asset_uncompressed_size(s32 assetIndex, s32 assetOffset) { - load_asset_to_address(assetIndex, (u32) gAssetAddress, assetOffset, 8); - return byteswap32((u8 *) gAssetAddress); + load_asset_to_address(assetIndex, (u32) gPackedHeader, assetOffset, 8); + return byteswap32((u8 *) gPackedHeader); } /** diff --git a/src/gzip.h b/src/gzip.h index 2509cf0c..f6c8ccee 100644 --- a/src/gzip.h +++ b/src/gzip.h @@ -18,7 +18,7 @@ typedef struct huft { #define BMAX 16 /* maximum bit length of any code (16 for explode) */ #define N_MAX 288 /* maximum number of codes in any set */ -void init_rzip(void); +void gzip_init(void); s32 byteswap32(u8 *arg0); s32 get_asset_uncompressed_size(s32 assetIndex, s32 assetOffset); u8 *gzip_inflate(u8 *compressedInput, u8 *decompressedOutput); diff --git a/src/math_util.c b/src/math_util.c index ed3441e0..c0eca87a 100644 --- a/src/math_util.c +++ b/src/math_util.c @@ -761,7 +761,8 @@ GLOBAL_ASM("asm/math_util/area_triangle_2d.s") GLOBAL_ASM("asm/math_util/set_breakpoint.s") #ifdef NON_MATCHING -void dmacopy_doubleword(void *src, void *dst, s32 size) { +void dmacopy_doubleword(void *src, void *dst, s32 end) { + s32 size = end - (u32) dst; memcpy(dst, src, size); } #else diff --git a/src/math_util.h b/src/math_util.h index d16b5e96..e415aa2e 100644 --- a/src/math_util.h +++ b/src/math_util.h @@ -58,7 +58,7 @@ void f32_matrix_from_position(Matrix *mtx, f32 x, f32 y, f32 z); void f32_matrix_from_scale(Matrix, f32, f32, f32); s32 atan2s(s32 xDelta, s32 zDelta); f32 area_triangle_2d(f32 x0, f32 z0, f32 x1, f32 z1, f32 x2, f32 z2); -void dmacopy_doubleword(void *src, void *dst, s32 size); +void dmacopy_doubleword(void *src, void *dst, s32 end); unk800B7D10 *get_stack_pointer(void); u32 disable_interrupts(void); void enable_interrupts(u32 flags); diff --git a/src/memory.c b/src/memory.c index 75684dd3..eb58f0fd 100644 --- a/src/memory.c +++ b/src/memory.c @@ -107,7 +107,7 @@ void *allocate_from_main_pool_safe(s32 size, u32 colourTag) { dump_memory_to_cpak(get_stack_pointer()->unk14, size, colourTag); } temp_v0 = allocate_from_memory_pool(0, size, colourTag); - if (temp_v0 == (void *) NULL) { + if (temp_v0 == NULL) { dump_memory_to_cpak(get_stack_pointer()->unk14, size, colourTag); } return temp_v0; @@ -673,23 +673,6 @@ UNUSED void render_memory_colour_tags(void) { render_printf("ORANGE %d\n\n", get_memory_colour_tag_count(COLOUR_TAG_ORANGE)); } -/************ .rodata ************/ - -UNUSED const char D_800E7590[] = "Region = %d loc = %x size = %x\t"; -UNUSED const char D_800E75B4[] = "FREE"; -UNUSED const char D_800E75BC[] = "ALLOCATED"; -UNUSED const char D_800E75C8[] = "ALLOCATED,FIXED"; -UNUSED const char D_800E75D8[] = "\n"; -UNUSED const char D_800E75DC[] = "\n"; -UNUSED const char D_800E75E0[] = "Region number = %d\t"; -UNUSED const char D_800E75F4[] = "maxSlots = %d\t"; -UNUSED const char D_800E7604[] = "slotsUsed = %d\t"; -UNUSED const char D_800E7614[] = "loc = %x\t"; -UNUSED const char D_800E7620[] = "size = %x\n"; -UNUSED const char D_800E762C[] = "\n"; - -/*********************************/ - UNUSED void mmSlotPrint(void) { s32 i; s32 skip; @@ -698,7 +681,8 @@ UNUSED void mmSlotPrint(void) { s32 nextIndex; MemoryPoolSlot *slot; - for (i = 0; (gNumberOfMemoryPools ^ 0) >= i; i++) { + for (i = 0; gNumberOfMemoryPools >= i; i++) { + stubbed_printf("Region = %d loc = %x size = %x\t", i, gMemoryPools[i].slots, gMemoryPools[i].size); if (i && i) {} // Fakematch slot = &gMemoryPools[i].slots[0]; index = 1; @@ -720,10 +704,23 @@ UNUSED void mmSlotPrint(void) { } } -// Unused. Does nothing? -UNUSED void func_80071CE8(void) { +UNUSED const char D_800E75B4[] = "FREE"; +UNUSED const char D_800E75BC[] = "ALLOCATED"; +UNUSED const char D_800E75C8[] = "ALLOCATED,FIXED"; +UNUSED const char D_800E75D8[] = "\n"; +UNUSED const char D_800E75DC[] = "\n"; + +/** + * Print out the current status of each existing memory pool. + */ +UNUSED void mempool_print_data(void) { s32 i; for (i = gNumberOfMemoryPools; i != -1; i--) { - // Nothing here. There might've been a printf or something similar. + stubbed_printf("Region number = %d\t", i); + stubbed_printf("maxSlots = %d\t", gMemoryPools[i].maxNumSlots); + stubbed_printf("slotsUsed = %d\t", gMemoryPools[i].curNumSlots); + stubbed_printf("loc = %x\t", gMemoryPools[i].slots); + stubbed_printf("size = %x\n", gMemoryPools[i].size); + stubbed_printf("\n"); } } diff --git a/src/memory.h b/src/memory.h index 5d73f13c..0a20d2d6 100644 --- a/src/memory.h +++ b/src/memory.h @@ -87,7 +87,6 @@ u8 *align8(u8 *address); u8 *align4(u8 *address); void print_memory_colour_tags(void); void render_memory_colour_tags(void); -void func_80071CE8(void); MemoryPoolSlot *new_memory_pool(MemoryPoolSlot *slots, s32 poolSize, s32 numSlots); void free_memory_pool_slot(s32 poolIndex, s32 slotIndex); s32 allocate_memory_pool_slot(s32 poolIndex, s32 slotIndex, s32 size, s32 slotIsTaken, s32 newSlotIsTaken, diff --git a/src/menu.c b/src/menu.c index 9d2d712a..d8d7eaef 100644 --- a/src/menu.c +++ b/src/menu.c @@ -3830,7 +3830,7 @@ SIDeviceStatus savemenu_load_sources(void) { gSaveMenuOptionCountUpper++; } } - packDirectoryFree(); + cpak_free_files(); } else if (temp == CONTROLLER_PAK_RUMBLE_PAK_FOUND) { gSaveMenuRumbleConnected = TRUE; if (gSaveMenuSourceState < 0) { @@ -4573,7 +4573,7 @@ SIDeviceStatus func_80087F14(s32 *controllerIndex, s32 arg1) { gBootPakData[i - 1][j] = 0; } while (&gBootPakData != &sCurrentControllerPakAllFileNames); - packDirectoryFree(); // Free D_800DE440 from memory + cpak_free_files(); // Free gPakFileList from memory get_free_space(*controllerIndex, &sCurrentControllerPakFreeSpace, NULL); // Get Available Space in Controller // Pak sCurrentControllerPakFreeSpace = sCurrentControllerPakFreeSpace / 256; // Bytes @@ -10115,7 +10115,7 @@ s32 menu_results_loop(s32 updateRate) { dialogue_close(7); dialogue_clear(7); if (gResultOptionText[gMenuOption] == gMenuText[ASSET_MENU_TEXT_TRYAGAIN]) { - return (MENU_RESULT_FLAGS_100 | MENU_RESULT_FLAGS_2); // This gets parsed in menu_logic_loop as a flag + return (MENU_RESULT_FLAGS_100 | MENU_RESULT_FLAGS_2); // This gets parsed in mode_menu as a flag // and an ID from the bottom 7 bits. } if (gResultOptionText[gMenuOption] == gMenuText[ASSET_MENU_TEXT_SELECTTRACK]) { diff --git a/src/object_models.c b/src/object_models.c index 35c93243..1563afb0 100644 --- a/src/object_models.c +++ b/src/object_models.c @@ -73,7 +73,7 @@ void allocate_object_model_pools(void) { checksum += *(u8 *) (((s32) &render_scene) + i); } if (checksum != gTractionTableChecksum) { - antipiracy_modify_surface_traction_table(); + drm_vehicle_traction(); } #endif } diff --git a/src/objects.c b/src/objects.c index 0fd4ab07..74845d08 100644 --- a/src/objects.c +++ b/src/objects.c @@ -5761,7 +5761,7 @@ void func_8001E6EC(s8 arg0) { void func_8001E89C(void) { s32 i; Object *obj; - Object_8001E89C_64 *obj64; + Object_8001E89C_64 *obj64; // some flag, flips to 1 when loading a new zone if (D_8011AE01 != 0) { @@ -6459,7 +6459,7 @@ s32 get_object_property_size(Object *obj, Object_64 *obj64) { ret = sizeof(Object_AudioLine); break; case BHV_AINODE: - ret = 0x1C; + ret = sizeof(Object_AiNode); break; case BHV_MODECHANGE: case BHV_BONUS: @@ -6500,7 +6500,7 @@ s32 get_object_property_size(Object *obj, Object_64 *obj64) { ret = sizeof(Object_LaserGun); break; case BHV_OVERRIDE_POS: - ret = 0x10; + ret = sizeof(Object_OverridePos); break; case BHV_DINO_WHALE: case BHV_ANIMATED_OBJECT: diff --git a/src/racer.c b/src/racer.c index fd0f9724..8f321a7a 100644 --- a/src/racer.c +++ b/src/racer.c @@ -143,7 +143,6 @@ s32 gCurrentCarSteerVel; s32 D_8011D558; s32 gCurrentPlayerIndex; s16 D_8011D560; // Set, but never read. -UNUSED s16 D_8011D562; f32 *gCurrentRacerMiscAssetPtr; f32 *D_8011D568; f32 gCurrentRacerWeightStat; @@ -5699,7 +5698,7 @@ s32 timetrial_load_player_ghost(s32 controllerID, s32 mapId, s16 arg2, s16 *char nodeID = (gCurrentGhostIndex + 1) & 1; cpakStatus = func_80074B34(controllerID, mapId, arg2, (u16 *) characterID, time, &nodeCount, - (GhostHeader *) gGhostData[nodeID]); + (unk80075000 *) gGhostData[nodeID]); if (characterID) { if (cpakStatus == CONTROLLER_PAK_GOOD) { gGhostNodeCount[nodeID] = nodeCount; @@ -5752,7 +5751,7 @@ void timetrial_free_staff_ghost(void) { */ SIDeviceStatus timetrial_write_player_ghost(s32 controllerIndex, s32 mapId, s16 arg2, s16 arg3, s16 arg4) { return func_80075000(controllerIndex, (s16) mapId, arg2, arg3, arg4, gGhostNodeCount[gCurrentGhostIndex], - (GhostHeader *) gGhostData[gCurrentGhostIndex]); + (unk80075000_body *) gGhostData[gCurrentGhostIndex]); } /** @@ -5942,7 +5941,7 @@ void racer_set_dialogue_camera(void) { * Antipiracy function that loops over an address of a function a number of times. * It compares the number it gets to a generated checksum to determine if the game has been tampered with at all. */ -void compare_balloon_checksums(void) { +void drm_checksum_balloon(void) { s32 i; s32 count = 0; u8 *temp = (u8 *) &obj_loop_goldenballoon; @@ -6580,7 +6579,7 @@ GLOBAL_ASM("asm/non_matchings/racer/func_8005B818.s") * Triggered upon failure of an anti-tamper test. Sets the first index of the surface speed * table to an unreasonable value, wrecking drivability while on it. */ -void antipiracy_modify_surface_traction_table(void) { +void drm_vehicle_traction(void) { gSurfaceTractionTable[SURFACE_DEFAULT] = 0.05f; } #endif diff --git a/src/racer.h b/src/racer.h index 4dcbbfee..9b6e52d4 100644 --- a/src/racer.h +++ b/src/racer.h @@ -193,8 +193,8 @@ SIDeviceStatus timetrial_write_player_ghost(s32 controllerIndex, s32 mapId, s16 s16 timetrial_ghost_full(void); void disable_racer_input(void); void racer_set_dialogue_camera(void); -void compare_balloon_checksums(void); -void antipiracy_modify_surface_traction_table(void); +void drm_checksum_balloon(void); +void drm_vehicle_traction(void); s32 turn_head_towards_object(Object *obj, Object_Racer *racer, Object *targetObj, f32 distance); void onscreen_ai_racer_physics(Object *obj, Object_Racer *racer, s32 arg2); void func_8005C270(Object_Racer *racer); diff --git a/src/rcp.c b/src/rcp.c index 132de5ed..faf37a99 100644 --- a/src/rcp.c +++ b/src/rcp.c @@ -7,6 +7,7 @@ #include "macros.h" #include "video.h" #include "camera.h" +#include "set_rsp_segment.h" // #include "lib/src/unknown_0D24D0.h" /************ .data ************/ @@ -136,11 +137,11 @@ Gfx dTextureRectangleScaledXlu[][2] = { u8 gDramStack[SP_DRAM_STACK_SIZE8]; u8 gGfxSPTaskYieldBuffer[YIELD_BUFFER_SIZE]; -OSMesgQueue D_80125EA0; -OSMesg D_80125EB8; -OSMesgQueue D_80125EC0; +OSMesgQueue gRCPMesgQueue; +OSMesg gRCPMesgBuf; +UNUSED OSMesgQueue gUnusedMesgQueue; OSMesgQueue gGfxTaskMesgQueue; -OSMesg D_80125EF0[8]; +UNUSED OSMesg gUnusedMesgBuf[8]; OSMesg gGfxTaskMesgBuf[8]; u8 gChequerBGColourR1; u8 gChequerBGColourG1; @@ -190,7 +191,7 @@ s32 setup_ostask_xbus(Gfx *dlBegin, Gfx *dlEnd, UNUSED s32 recvMesg) { dkrtask->task.dram_stack = (u64 *) gDramStack; dkrtask->task.dram_stack_size = SP_DRAM_STACK_SIZE8; dkrtask->task.output_buff = (u64 *) gGfxSPTaskYieldBuffer; - dkrtask->task.output_buff_size = (u64 *) &D_80125EA0; + dkrtask->task.output_buff_size = (u64 *) &gRCPMesgQueue; dkrtask->task.yield_data_ptr = (u64 *) gGfxTaskYieldData; dkrtask->task.yield_data_size = sizeof(gGfxTaskYieldData); dkrtask->task.output_buff = NULL; @@ -245,12 +246,12 @@ UNUSED void setup_ostask_xbus_2(Gfx *dlBegin, Gfx *dlEnd, s32 recvMesg) { dkrtask->unk68 = 0; if (recvMesg) { - dkrtask->mesgQueue = &D_80125EA0; + dkrtask->mesgQueue = &gRCPMesgQueue; } osWritebackDCacheAll(); osSendMesg(osScInterruptQ, dkrtask, 1); if (recvMesg) { - osRecvMesg(&D_80125EA0, &mesgBuf, OS_MESG_BLOCK); + osRecvMesg(&gRCPMesgQueue, &mesgBuf, OS_MESG_BLOCK); } } @@ -298,13 +299,13 @@ UNUSED void setup_ostask_fifo(Gfx *dlBegin, Gfx *dlEnd, s32 recvMesg) { dkrtask->unk68 = 0; if (recvMesg) { - dkrtask->mesgQueue = &D_80125EA0; + dkrtask->mesgQueue = &gRCPMesgQueue; } osWritebackDCacheAll(); osSendMesg(osScInterruptQ, dkrtask, 1); if (recvMesg) { - osRecvMesg(&D_80125EA0, &mesgBuf, OS_MESG_BLOCK); + osRecvMesg(&gRCPMesgQueue, &mesgBuf, OS_MESG_BLOCK); } } @@ -336,7 +337,7 @@ UNUSED void setup_ostask_fifo_2(Gfx *dlBegin, Gfx *dlEnd, s32 recvMesg) { dkrtask->task.dram_stack = (u64 *) gDramStack; dkrtask->task.dram_stack_size = SP_DRAM_STACK_SIZE8; dkrtask->task.output_buff = (u64 *) gGfxSPTaskYieldBuffer; - dkrtask->task.output_buff_size = (u64 *) &D_80125EA0; + dkrtask->task.output_buff_size = (u64 *) &gRCPMesgQueue; dkrtask->task.yield_data_ptr = (u64 *) gGfxTaskYieldData; dkrtask->task.yield_data_size = sizeof(gGfxTaskYieldData); dkrtask->next = NULL; @@ -374,7 +375,7 @@ s32 wait_for_gfx_task(void) { return (s32) mesg[1]; } -UNUSED void func_80077AAC(void *bufPtr, s32 bufSize, UNUSED s32 unused) { +UNUSED void gfxtask_run_rdp(void *bufPtr, s32 bufSize, UNUSED s32 unused) { osWritebackDCacheAll(); while (osDpGetStatus() & DPC_CLR_CMD_CTR) {} osDpSetNextBuffer(bufPtr, bufSize); @@ -424,11 +425,11 @@ void render_background(Gfx **dList, Matrix *mtx, s32 drawBG) { //!@bug: the scissor does not need the off by one here, despite being intended for fill mode. gDPSetScissor((*dList)++, 0, 0, 0, w - 1, h - 1); gDPSetCycleType((*dList)++, G_CYC_FILL); - gDPSetColorImage((*dList)++, G_IM_FMT_RGBA, G_IM_SIZ_16b, w, SEGMENT_DEPTH_BUFFER); + gDPSetColorImage((*dList)++, G_IM_FMT_RGBA, G_IM_SIZ_16b, w, SEGMENT_ZBUFFER << 24); gDPSetFillColor((*dList)++, GPACK_RGBA5551(255, 255, 240, 0) << 16 | GPACK_RGBA5551(255, 255, 240, 0)); gDPFillRectangle((*dList)++, 0, 0, w - 1, h - 1); gDPPipeSync((*dList)++); - gDPSetColorImage((*dList)++, G_IM_FMT_RGBA, G_IM_SIZ_16b, w, SEGMENT_COLOUR_BUFFER); + gDPSetColorImage((*dList)++, G_IM_FMT_RGBA, G_IM_SIZ_16b, w, SEGMENT_FRAMEBUFFER << 24); if (drawBG) { if (check_viewport_background_flag(0)) { if (gChequerBGEnabled) { @@ -477,8 +478,8 @@ void render_background(Gfx **dList, Matrix *mtx, s32 drawBG) { */ void init_rdp_and_framebuffer(Gfx **dList) { s32 width = GET_VIDEO_WIDTH(get_video_width_and_height_as_s32()); - gDPSetColorImage((*dList)++, G_IM_FMT_RGBA, G_IM_SIZ_16b, width, SEGMENT_COLOUR_BUFFER); - gDPSetDepthImage((*dList)++, SEGMENT_DEPTH_BUFFER); + gDPSetColorImage((*dList)++, G_IM_FMT_RGBA, G_IM_SIZ_16b, width, SEGMENT_FRAMEBUFFER << 24); + gDPSetDepthImage((*dList)++, SEGMENT_ZBUFFER << 24); gSPDisplayList((*dList)++, dRdpInit); } @@ -495,8 +496,8 @@ void init_rsp(Gfx **dList) { */ void setup_gfx_mesg_queues(OSSched *sc) { osScInterruptQ = osScGetInterruptQ(sc); - osCreateMesgQueue(&D_80125EA0, &D_80125EB8, 1); - osCreateMesgQueue(&D_80125EC0, D_80125EF0, ARRAY_COUNT(D_80125EF0)); + osCreateMesgQueue(&gRCPMesgQueue, &gRCPMesgBuf, 1); + osCreateMesgQueue(&gUnusedMesgQueue, gUnusedMesgBuf, ARRAY_COUNT(gUnusedMesgBuf)); osCreateMesgQueue(&gGfxTaskMesgQueue, gGfxTaskMesgBuf, ARRAY_COUNT(gGfxTaskMesgBuf)); } diff --git a/src/rcp.h b/src/rcp.h index f22fb14f..d2852529 100644 --- a/src/rcp.h +++ b/src/rcp.h @@ -10,9 +10,6 @@ #include "game_ui.h" #include "video.h" -#define SEGMENT_DEPTH_BUFFER 0x02000000 -#define SEGMENT_COLOUR_BUFFER 0x01000000 - enum TextureRectangleFlags { TEXRECT_BILERP, TEXRECT_POINT = (1 << 0), @@ -65,7 +62,6 @@ extern s8 rspF3DDKRFifoStart[]; extern s8 rspF3DDKRDataFifoStart[]; s32 wait_for_gfx_task(void); -void func_80077AAC(void *bufPtr, s32 bufSize, UNUSED s32 arg2); void set_background_prim_colour(u8 red, u8 green, u8 blue); void set_background_fill_colour(s32 red, s32 green, s32 blue); void init_rdp_and_framebuffer(Gfx **dList); diff --git a/src/save_data.c b/src/save_data.c index 6b8affa5..0e7ab997 100644 --- a/src/save_data.c +++ b/src/save_data.c @@ -15,7 +15,7 @@ /************ .data ************/ -s8 *D_800DE440 = 0; +s8 *gPakFileList = 0; u8 gN64FontCodes[] = "\0 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#'*+,-./:=?@"; @@ -1263,7 +1263,7 @@ SIDeviceStatus func_80074EB8(s32 controllerIndex, s16 levelId, s16 vehicleId, s1 if (1) {} // fake ghost = allocate_from_main_pool_safe(sp24 + (GHSS_SIZE * 2), COLOUR_TAG_BLACK); ghost->signature = GHSS; - ghostBody = &ghost->data; + ghostBody = &ghost->data[0]; ghostBody[0].unk0 = levelId; ghostBody[0].unk1 = vehicleId; ghostBody[0].unk2 = GHSS_SIZE; @@ -1273,8 +1273,9 @@ SIDeviceStatus func_80074EB8(s32 controllerIndex, s16 levelId, s16 vehicleId, s1 ghostBody[i].unk2 = ghostBody[1].unk2; } - func_80074AA8(AS_BYTES(ghost) + ghostBody[0].unk2, ghostCharacterId, ghostTime, ghostNodeCount, dest); - pakStatus = write_controller_pak_file(controllerIndex, -1, "DKRACING-GHOSTS", "", ghost, sp24 + GHSS_SIZE); + func_80074AA8((GhostHeader *) (AS_BYTES(ghost) + ghostBody[0].unk2), ghostCharacterId, ghostTime, ghostNodeCount, + dest); + pakStatus = write_controller_pak_file(controllerIndex, -1, "DKRACING-GHOSTS", "", (u8 *) ghost, sp24 + GHSS_SIZE); free_from_memory_pool(ghost); return pakStatus; } @@ -1634,7 +1635,7 @@ SIDeviceStatus repair_controller_pak(s32 controllerIndex) { s32 status = get_si_device_status(controllerIndex); if (status == CONTROLLER_PAK_GOOD || status == CONTROLLER_PAK_INCONSISTENT) { status = osPfsChecker(&pfs[controllerIndex]); - if (status == 0) { + if (status == CONTROLLER_PAK_GOOD) { ret = CONTROLLER_PAK_GOOD; } else if (status == PFS_ERR_NEW_PACK) { ret = CONTROLLER_PAK_CHANGED; @@ -1677,7 +1678,7 @@ s32 get_controller_pak_file_list(s32 controllerIndex, s32 maxNumOfFilesToGet, ch s32 ret; s32 maxNumOfFilesOnCpak; s32 files_used; - s8 *temp_D_800DE440; + s8 *list; s32 i; u32 gameCode; @@ -1704,23 +1705,23 @@ s32 get_controller_pak_file_list(s32 controllerIndex, s32 maxNumOfFilesToGet, ch maxNumOfFilesOnCpak = maxNumOfFilesToGet; } - if (D_800DE440 != NULL) { - free_from_memory_pool(D_800DE440); + if (gPakFileList != NULL) { + free_from_memory_pool(gPakFileList); } files_used = maxNumOfFilesOnCpak * 24; - D_800DE440 = allocate_from_main_pool_safe(files_used, COLOUR_TAG_BLACK); - bzero(D_800DE440, files_used); - temp_D_800DE440 = D_800DE440; + gPakFileList = allocate_from_main_pool_safe(files_used, COLOUR_TAG_BLACK); + bzero(gPakFileList, files_used); + list = gPakFileList; // TODO: There's probably an unidentified struct here for (i = 0; i < maxNumOfFilesOnCpak; i++) { - fileNames[i] = (char *) temp_D_800DE440; - temp_D_800DE440 += 0x12; - fileExtensions[i] = (char *) temp_D_800DE440; + fileNames[i] = (char *) list; + list += 0x12; + fileExtensions[i] = (char *) list; fileSizes[i] = 0; fileTypes[i] = SAVE_FILE_TYPE_UNSET; - temp_D_800DE440 += 6; + list += 6; } while (i < maxNumOfFilesToGet) { @@ -1757,12 +1758,15 @@ s32 get_controller_pak_file_list(s32 controllerIndex, s32 maxNumOfFilesToGet, ch return CONTROLLER_PAK_GOOD; } -// Free D_800DE440 -void packDirectoryFree(void) { - if (D_800DE440 != 0) { - free_from_memory_pool(D_800DE440); +/** + * Free the controller pak file list from memory. + * Official Name: pakDirectoryFree + */ +void cpak_free_files(void) { + if (gPakFileList) { + free_from_memory_pool(gPakFileList); } - D_800DE440 = 0; + gPakFileList = NULL; } // Get Available Space in Controller Pak diff --git a/src/save_data.h b/src/save_data.h index eefe2266..19d7d726 100644 --- a/src/save_data.h +++ b/src/save_data.h @@ -114,7 +114,7 @@ typedef struct unk80075000 { unk80075000_body data[1]; } unk80075000; -extern s8 *D_800DE440; +extern s8 *gPakFileList; extern u8 gN64FontCodes[68]; extern s32 gRumbleKillTimer; extern OSPfs pfs[MAXCONTROLLERS]; @@ -146,7 +146,7 @@ SIDeviceStatus check_for_rumble_pak(s32 controllerIndex); SIDeviceStatus repair_controller_pak(s32 controllerIndex); SIDeviceStatus reformat_controller_pak(s32 controllerIndex); s32 get_controller_pak_file_list(s32 controllerIndex, s32 maxNumOfFilesToGet, char **fileNames, char **fileExtensions, u32 *fileSizes, u8 *fileTypes); -void packDirectoryFree(void); +void cpak_free_files(void); s32 get_free_space(s32 controllerIndex, u32 *bytesFree, s32 *notesFree); s32 delete_file(s32 controllerIndex, s32 fileNum); s32 copy_controller_pak_data(s32 controllerIndex, s32 fileNumber, s32 secondControllerIndex); diff --git a/src/set_rsp_segment.c b/src/set_rsp_segment.c index 2977b74e..ecaf5d60 100644 --- a/src/set_rsp_segment.c +++ b/src/set_rsp_segment.c @@ -11,6 +11,6 @@ * This is used for the colour and depth buffers. * Official name: segSetBase */ -void set_rsp_segment(Gfx **dlist, s32 segment, s32 base) { +void rsp_segment(Gfx **dlist, s32 segment, s32 base) { gSPSegment((*dlist)++, segment, base + K0BASE) } diff --git a/src/set_rsp_segment.h b/src/set_rsp_segment.h index e0145fe4..8523d4a6 100644 --- a/src/set_rsp_segment.h +++ b/src/set_rsp_segment.h @@ -3,6 +3,21 @@ #include "PR/gbi.h" -void set_rsp_segment(Gfx **dlist, s32 segment, s32 base); +/** + * Normally, in F3D, RSP segments go up to 16. + * DKR's custom microcode is an exception, capping at 8. + * A DMEM saving measure, since they don't use segments for assets. +*/ +enum RSPSegments { + SEGMENT_MAIN, + SEGMENT_FRAMEBUFFER, + SEGMENT_ZBUFFER, + SEGMENT_UNUSED_3, + SEGMENT_FRAMEBUFFER_OFFSET, // Also unused + + SEGMENT_COUNT, +}; + +void rsp_segment(Gfx **dlist, s32 segment, s32 base); #endif diff --git a/src/thread0_epc.c b/src/thread0_epc.c index f4c03390..5cd7914e 100644 --- a/src/thread0_epc.c +++ b/src/thread0_epc.c @@ -243,7 +243,7 @@ s32 get_lockup_status(void) { * Counts up. Automatically switches page every second. * Official name: diCpuTraceTick */ -void lockup_screen_loop(s32 updateRate) { +void mode_lockup(s32 updateRate) { sLockupDelay += updateRate; if (sLockupDelay > 60) { sLockupDelay = 0; diff --git a/src/thread0_epc.h b/src/thread0_epc.h index 6a2ccccb..f2d1b58c 100644 --- a/src/thread0_epc.h +++ b/src/thread0_epc.h @@ -88,7 +88,7 @@ void enable_interupts_on_main(void); void stop_all_threads_except_main(void); void update_object_stack_trace(s32 index, s32 value); s32 get_lockup_status(void); -void lockup_screen_loop(s32 updateRate); +void mode_lockup(s32 updateRate); void thread0_create(void); void write_epc_data_to_cpak(void); void dump_memory_to_cpak(s32 epc, s32 size, u32 colourTag); diff --git a/src/thread3_main.c b/src/thread3_main.c index 1dc89c0c..598d1110 100644 --- a/src/thread3_main.c +++ b/src/thread3_main.c @@ -172,10 +172,10 @@ void init_game(void) { stubbed_printf(sDebugRomBuildInfo); init_main_memory_pool(); - init_rzip(); // Initialise gzip decompression related things + gzip_init(); #ifdef ANTI_TAMPER sAntiPiracyTriggered = TRUE; - if (check_imem_validity()) { + if (drm_validate_imem()) { sAntiPiracyTriggered = FALSE; } #endif @@ -194,7 +194,7 @@ void init_game(void) { #ifdef ANTI_TAMPER // Antipiracy measure. gDmemInvalid = FALSE; - if (check_dmem_validity() == FALSE) { + if (drm_validate_dmem() == FALSE) { gDmemInvalid = TRUE; } #endif @@ -244,10 +244,10 @@ void main_game_loop(void) { if (gScreenStatus == MESG_SKIP_BUFFER_SWAP) { gCurrDisplayList = gDisplayLists[gSPTaskNum]; - set_rsp_segment(&gCurrDisplayList, 0, 0); - set_rsp_segment(&gCurrDisplayList, 1, (s32) gVideoCurrFramebuffer); - set_rsp_segment(&gCurrDisplayList, 2, (s32) gVideoLastDepthBuffer); - set_rsp_segment(&gCurrDisplayList, 4, (s32) gVideoCurrFramebuffer - 0x500); + rsp_segment(&gCurrDisplayList, SEGMENT_MAIN, 0x00000000); + rsp_segment(&gCurrDisplayList, SEGMENT_FRAMEBUFFER, (s32) gVideoCurrFramebuffer); + rsp_segment(&gCurrDisplayList, SEGMENT_ZBUFFER, (s32) gVideoLastDepthBuffer); + rsp_segment(&gCurrDisplayList, SEGMENT_FRAMEBUFFER_OFFSET, (s32) gVideoCurrFramebuffer - VI_OFFSET); // Unused } if (gDrawFrameTimer == 0) { setup_ostask_xbus(gDisplayLists[gSPTaskNum], gCurrDisplayList, 0); @@ -263,10 +263,10 @@ void main_game_loop(void) { gGameCurrVertexList = gVertexHeap[gSPTaskNum]; gGameCurrTriList = gTriangleHeap[gSPTaskNum]; - set_rsp_segment(&gCurrDisplayList, 0, 0); - set_rsp_segment(&gCurrDisplayList, 1, (s32) gVideoLastFramebuffer); - set_rsp_segment(&gCurrDisplayList, 2, (s32) gVideoLastDepthBuffer); - set_rsp_segment(&gCurrDisplayList, 4, (s32) gVideoLastFramebuffer - 0x500); + rsp_segment(&gCurrDisplayList, SEGMENT_MAIN, 0x00000000); + rsp_segment(&gCurrDisplayList, SEGMENT_FRAMEBUFFER, (s32) gVideoLastFramebuffer); + rsp_segment(&gCurrDisplayList, SEGMENT_ZBUFFER, (s32) gVideoLastDepthBuffer); + rsp_segment(&gCurrDisplayList, SEGMENT_FRAMEBUFFER_OFFSET, (s32) gVideoLastFramebuffer - VI_OFFSET); // Unused init_rsp(&gCurrDisplayList); init_rdp_and_framebuffer(&gCurrDisplayList); render_background(&gCurrDisplayList, (Matrix *) &gGameCurrMatrix, TRUE); @@ -287,16 +287,16 @@ void main_game_loop(void) { switch (gGameMode) { case GAMEMODE_INTRO: // Pre-boot screen - pre_intro_loop(); + mode_intro(); break; case GAMEMODE_MENU: // In a menu - menu_logic_loop(sLogicUpdateRate); + mode_menu(sLogicUpdateRate); break; case GAMEMODE_INGAME: // In game (Controlling a character) - ingame_logic_loop(sLogicUpdateRate); + mode_game(sLogicUpdateRate); break; case GAMEMODE_LOCKUP: // EPC (lockup display) - lockup_screen_loop(sLogicUpdateRate); + mode_lockup(sLogicUpdateRate); break; } @@ -411,7 +411,7 @@ void unload_level_game(void) { * The main behaviour function involving all of the ingame stuff. * Involves the updating of all objects and setting up the render scene. */ -void ingame_logic_loop(s32 updateRate) { +void mode_game(s32 updateRate) { s32 buttonPressedInputs, buttonHeldInputs, i, loadContext, sp3C; loadContext = LEVEL_CONTEXT_NONE; @@ -912,7 +912,7 @@ void update_menu_scene(s32 updateRate) { * Main function for handling behaviour in menus. * Runs the menu code, with a simplified object update and scene rendering system. */ -void menu_logic_loop(s32 updateRate) { +void mode_menu(s32 updateRate) { s32 menuLoopResult; s32 temp; s32 playerVehicle; @@ -1398,15 +1398,17 @@ void alloc_displaylist_heap(s32 numberOfPlayers) { gSPEndDisplayList(gCurrDisplayList++); } +#ifdef ANTI_TAMPER /** * Returns FALSE if dmem doesn't begin with a -1. This is checked on every main game loop iteration. */ -s32 check_dmem_validity(void) { +s32 drm_validate_dmem(void) { if (IO_READ(SP_DMEM_START) != -1U) { return FALSE; } return TRUE; } +#endif /** * Defaults allocations for 4 players @@ -1555,7 +1557,7 @@ void set_frame_blackout_timer(void) { /** * Give the player 8 frames to enter the CPak menu with start, then load the intro sequence. */ -void pre_intro_loop(void) { +void mode_intro(void) { s32 i; s32 buttonInputs = 0; @@ -1590,7 +1592,7 @@ s32 is_controller_missing(void) { * false read, meaning you're caught running an illegitimate copy, will force the game to pause when you enter the * world. */ -s32 check_imem_validity(void) { +s32 drm_validate_imem(void) { if (IO_READ(SP_IMEM_START) != CIC_ID) { return FALSE; } diff --git a/src/thread3_main.h b/src/thread3_main.h index 6133c740..c23ea82d 100644 --- a/src/thread3_main.h +++ b/src/thread3_main.h @@ -156,7 +156,7 @@ void safe_mark_write_save_file(s32 saveFileIndex); void mark_save_file_to_erase(s32 saveFileIndex); void mark_read_eeprom_settings(void); void mark_write_eeprom_settings(void); -s32 check_dmem_validity(void); +s32 drm_validate_dmem(void); void level_transition_begin(s32 type); void func_8006F20C(void); void begin_trophy_race_teleport(void); @@ -165,14 +165,14 @@ void begin_level_teleport(s32 levelID); void set_pause_lockout_timer(u8 time); void swap_lead_player(void); void set_frame_blackout_timer(void); -void pre_intro_loop(void); +void mode_intro(void); s32 is_controller_missing(void); -s32 check_imem_validity(void); -void ingame_logic_loop(s32 updateRate); +s32 drm_validate_imem(void); +void mode_game(s32 updateRate); void load_level(s32 levelId, s32 numberOfPlayers, s32 entranceId, Vehicle vehicleId, s32 cutsceneId); void init_level_globals(void); void alloc_displaylist_heap(s32 numberOfPlayers); void default_alloc_displaylist_heap(void); -void menu_logic_loop(s32 updateRate); +void mode_menu(s32 updateRate); #endif diff --git a/src/tracks.c b/src/tracks.c index bff86224..ea176490 100644 --- a/src/tracks.c +++ b/src/tracks.c @@ -249,7 +249,7 @@ void init_track(u32 geometry, u32 skybox, s32 numberOfPlayers, Vehicle vehicle, set_active_viewports_and_max(gScenePlayerViewports); numberOfPlayers = gScenePlayerViewports; - gAntiAliasing = 0; + gAntiAliasing = FALSE; for (i = 0; i < ARRAY_COUNT(gShadowHeapTextures); i++) { gShadowHeapTextures[i] = (DrawTexture *) allocate_from_main_pool_safe(sizeof(DrawTexture) * 400, COLOUR_TAG_YELLOW); @@ -709,7 +709,7 @@ void spawn_skydome(s32 objectID) { #ifdef ANTI_TAMPER // Antipiracy measure - compare_balloon_checksums(); + drm_checksum_balloon(); #endif if (objectID == -1) { gSkydomeSegment = NULL; diff --git a/src/video.h b/src/video.h index 95a6151d..b0b86568 100644 --- a/src/video.h +++ b/src/video.h @@ -32,6 +32,17 @@ #define HEIGHT_RATIO_NTSC (LOW_RES_NTSC_HEIGHT / LOW_RES_NTSC_HEIGHT) #define HEIGHT_RATIO_MPAL (LOW_RES_MPAL_HEIGHT / LOW_RES_NTSC_HEIGHT) +/** + * This is an offset with a size of two rows of the framebuffer. + * It's likely they were trying to offset the framebuffer in order to + * undo what Libultra does, where in order to sample pixels from the top and + * bottom of the screen for anti aliasing and dedithering, they shift the framebuffer + * to hide some visible rows. + * A small mistake is present though, where they offset by two rows instead of one. + * This will cause there to be visible noise on the bottom row. +*/ +#define VI_OFFSET (SCREEN_WIDTH * sizeof(u16) * 2) + /** * The video width is the lower 16 bits of the returned 32 bit value */ diff --git a/src/waves.c b/src/waves.c index dda714cf..1090a6e4 100644 --- a/src/waves.c +++ b/src/waves.c @@ -162,7 +162,7 @@ void wave_init(void) { free_waves(); D_800E3040 = (f32 *) allocate_from_main_pool_safe(D_80129FC8.unk20 << 2, COLOUR_TAG_CYAN); - D_800E3044 = (s32 *) allocate_from_main_pool_safe((D_80129FC8.unk4 << 2) * D_80129FC8.unk4, COLOUR_TAG_CYAN); + D_800E3044 = (s16 *) allocate_from_main_pool_safe((D_80129FC8.unk4 << 2) * D_80129FC8.unk4, COLOUR_TAG_CYAN); D_800E3048 = (s32 *) allocate_from_main_pool_safe(((D_80129FC8.unk0 + 1) << 2) * (D_80129FC8.unk0 + 1), COLOUR_TAG_CYAN); allocSize = ((D_80129FC8.unk0 + 1) << 2) * (D_80129FC8.unk0 + 1); @@ -184,12 +184,12 @@ void wave_init(void) { allocSize = (D_80129FC8.unk0 * 32) * D_80129FC8.unk0; if (D_8012A078 != 2) { D_800E3080[0] = allocate_from_main_pool_safe(allocSize << 1, COLOUR_TAG_CYAN); - D_800E3080[1] = (s32 *) (((u32) D_800E3080[0]) + allocSize); + D_800E3080[1] = (u8 *) (((u32) D_800E3080[0]) + allocSize); } else { - D_800E3080[0] = (s32 *) allocate_from_main_pool_safe(allocSize << 2, COLOUR_TAG_CYAN); - D_800E3080[1] = (s32 *) (((u32) D_800E3080[0]) + allocSize); - D_800E3080[2] = (s32 *) (((u32) D_800E3080[1]) + allocSize); - D_800E3080[3] = (s32 *) (((u32) D_800E3080[2]) + allocSize); + D_800E3080[0] = (u8 *) allocate_from_main_pool_safe(allocSize << 2, COLOUR_TAG_CYAN); + D_800E3080[1] = (u8 *) (((u32) D_800E3080[0]) + allocSize); + D_800E3080[2] = (u8 *) (((u32) D_800E3080[1]) + allocSize); + D_800E3080[3] = (u8 *) (((u32) D_800E3080[2]) + allocSize); } D_800E30D0 = load_texture(D_80129FC8.unk2C); }