From 92a5fa8606ee0b3e61313dacb4b1afe228ff114f Mon Sep 17 00:00:00 2001 From: David Benepe Date: Thu, 1 Jul 2021 13:14:58 -0500 Subject: [PATCH] Documented unknown_080420 as screen_asset --- asm/assets/assets.s | 2 - extract-ver/us_1.0.config.json | 7 ++- include/PR/gbi.h | 2 + include/asset_sections.h | 4 +- include/f3ddkr.h | 24 ++++++- src/menu.c | 64 ++++++++++--------- src/menu.h | 6 +- src/screen_asset.c | 83 ++++++++++++++++++++++++ src/screen_asset.h | 14 +++++ src/unknown_078050.h | 26 -------- src/unknown_07B870.h | 44 ------------- src/unknown_080240.c | 87 -------------------------- src/unknown_080240.h | 9 --- tools/dkr_extractor_classes/config.cpp | 12 ++-- 14 files changed, 173 insertions(+), 211 deletions(-) create mode 100644 src/screen_asset.c create mode 100644 src/screen_asset.h delete mode 100644 src/unknown_080240.c delete mode 100644 src/unknown_080240.h diff --git a/asm/assets/assets.s b/asm/assets/assets.s index 8a166819..35d8412d 100755 --- a/asm/assets/assets.s +++ b/asm/assets/assets.s @@ -7838,12 +7838,10 @@ glabel ASSET_SECTION_9_END .balign 16 glabel ASSET_SECTION_10 -# Empty glabel ASSET_SECTION_10_END .balign 16 glabel ASSET_SECTION_11 -# Empty table .word ASSET_SECTION_10_END - ASSET_SECTION_10 .word 0xFFFFFFFF glabel ASSET_SECTION_11_END diff --git a/extract-ver/us_1.0.config.json b/extract-ver/us_1.0.config.json index 46bcf24e..dd81a802 100644 --- a/extract-ver/us_1.0.config.json +++ b/extract-ver/us_1.0.config.json @@ -118,12 +118,13 @@ "type": "Table" }, { - "name": "EMPTY_10", - "type": "Empty", + "name": "SCREENS", + "type": "Binary", + "folder": "screens", "table": 11 }, { - "name": "EMPTY_10_TABLE", + "name": "SCREENS_TABLE", "type": "Table" }, { diff --git a/include/PR/gbi.h b/include/PR/gbi.h index e459bd3e..bca5c548 100644 --- a/include/PR/gbi.h +++ b/include/PR/gbi.h @@ -20,6 +20,8 @@ #ifndef _GBI_H_ #define _GBI_H_ +#define F3D_OLD + #include /* diff --git a/include/asset_sections.h b/include/asset_sections.h index 3dbea764..ba6105b3 100644 --- a/include/asset_sections.h +++ b/include/asset_sections.h @@ -13,8 +13,8 @@ #define ASSET_GAME_TEXT_TABLE 7 #define ASSET_MENU_TEXT 8 #define ASSET_MENU_TEXT_TABLE 9 -#define ASSET_EMPTY_10 10 -#define ASSET_EMPTY_10_TABLE 11 +#define ASSET_SCREENS 10 +#define ASSET_SCREENS_TABLE 11 #define ASSET_SPRITES 12 #define ASSET_SPRITES_TABLE 13 #define ASSET_EMPTY_14 14 diff --git a/include/f3ddkr.h b/include/f3ddkr.h index 681079ca..f30247b6 100644 --- a/include/f3ddkr.h +++ b/include/f3ddkr.h @@ -17,6 +17,7 @@ #define DKR_CC_UNK7 TEXEL1, TEXEL0, PRIMITIVE, TEXEL0, TEXEL1, TEXEL0, PRIMITIVE, TEXEL0 #define DKR_CC_UNK8 COMBINED, 0, SHADE, 0, 0, 0, 0, COMBINED #define DKR_CC_UNK9 PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0 +#define DKR_CC_UNK10 TEXEL0, 0, SCALE, 0, 0, 0, 0, TEXEL0 #define DKR_CC_DECALFADEPRIM 0, 0, 0, TEXEL0, TEXEL0, 0, PRIMITIVE, 0 // For some reason DKR has a value for G_MDSFT_BLENDMASK, despite the fact that it is unsupported. @@ -34,6 +35,10 @@ #define DKR_OMH_2CYC_BILERP DKR_OMH_COMMON | G_CYC_2CYCLE | G_TT_NONE | G_TF_BILERP | G_TP_PERSP #define DKR_OMH_2CYC_POINT DKR_OMH_COMMON | G_CYC_2CYCLE | G_TT_NONE | G_TF_POINT | G_TP_PERSP #define DKR_OMH_2CYC_CI_BILERP DKR_OMH_COMMON | G_CYC_2CYCLE | G_TT_RGBA16 | G_TF_BILERP | G_TP_PERSP + +#define DKR_OMH_COPY_POINT_NOPERSP G_DKR_BLENDMASK | G_PM_NPRIMITIVE | G_TD_CLAMP | G_TL_TILE | G_TC_FILT \ + | G_CK_NONE | G_CD_DISABLE | G_AD_PATTERN | G_CYC_COPY | G_TT_NONE \ + | G_TF_POINT | G_TP_NONE // OtherMode_L values. #define DKR_OML_COMMON G_AC_NONE | G_ZS_PIXEL @@ -55,8 +60,23 @@ #define fast3d_cmd(pkt, word0, word1) \ { \ Gfx *_g = (Gfx*)(pkt); \ - _g->w0 = word0; \ - _g->w1 = word1; \ + _g->words.w0 = word0; \ + _g->words.w1 = word1; \ +} + +/****** F3DDKR display list commands ******/ + +#define G_DMADL 7 + +#define numberOfGfxCommands(gfxCmds) (sizeof(gfxCmds) / sizeof(Gwords)) + +#define gDkrDmaDisplayList(pkt, address, numberOfCommands) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_DMADL, 24, 8) | _SHIFTL((numberOfCommands), 16, 8) | \ + _SHIFTL((numberOfCommands*8), 0, 16)); \ + _g->words.w1 = (unsigned int)(address); \ } #endif diff --git a/src/menu.c b/src/menu.c index 306b9201..46fb12ee 100644 --- a/src/menu.c +++ b/src/menu.c @@ -7,7 +7,7 @@ #include "types.h" #include "macros.h" #include "structs.h" -#include "fast3d.h" +#include "f3ddkr.h" /** * @file Contains all the code used for every menu in the game. @@ -1248,19 +1248,18 @@ s16 D_800E1768[12] = { 0x3A, 0x3B, -1, 0 }; -// Fast3D (F3DDKR) display list -u32 D_800E1780[22] = { - 0xE7000000, 0x00000000, - 0xBA001402, 0x00000000, - 0xBA001001, 0x00000000, - 0xBA000E02, 0x00000000, - 0xBA001102, 0x00000000, - 0xBA001301, 0x00000000, - 0xBA000C02, 0x00002000, - 0xBA000903, 0x00000C00, - 0xB9000002, 0x00000000, - 0xB900031D, 0x00504340, - 0xB8000000, 0x00000000 +Gfx D_800E1780[11] = { + gsDPPipeSync(), + gsDPSetCycleType(G_CYC_1CYCLE), + gsDPSetTextureLOD(G_TL_TILE), + gsDPSetTextureLUT(G_TT_NONE), + gsDPSetTextureDetail(G_TD_CLAMP), + gsDPSetTexturePersp(G_TP_NONE), + gsDPSetTextureFilter(G_TF_BILERP), + gsDPSetTextureConvert(G_TC_FILT), + gsDPSetAlphaCompare(G_AC_NONE), + gsDPSetRenderMode(G_RM_CLD_SURF, G_RM_CLD_SURF2), + gsSPEndDisplayList(), }; s16 D_800E17D8[12] = { @@ -1390,20 +1389,29 @@ MenuElement D_800E1B50[9] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, 0, 0, 0, 0 } }; -// Fast3D (F3DDKR) display list -u32 D_800E1C70[24] = { - 0xE7000000, 0x00000000, - 0xBA001001, 0x00000000, - 0xBA000E02, 0x00000000, - 0xB9000002, 0x00000000, - 0xB6000000, 0x00010001, - 0xB8000000, 0x00000000, - 0xFCFFFFFF, 0xFFFE793C, - 0xEF000C0F, 0x00504240, - 0xFC121824, 0xFF33FFFF, - 0xEF082C0F, 0x00504240, - 0xFCFFFFFF, 0xFFFDF6FB, - 0xEF000C0F, 0x00504240 +Gfx D_800E1C70[] = { + gsDPPipeSync(), + gsDPSetTextureLOD(G_TL_TILE), + gsDPSetTextureLUT(G_TT_NONE), + gsDPSetAlphaCompare(G_AC_NONE), + gsSPClearGeometryMode(G_ZBUFFER | G_FOG), + gsSPEndDisplayList(), +}; + +// Unused? +Gfx D_800E1CA0[][2] = { + { + gsDPSetCombineMode(G_CC_SHADE, G_CC_SHADE), + gsDPSetOtherMode(DKR_OMH_1CYC_POINT_NOPERSP, DKR_OML_COMMON | G_RM_XLU_SURF | G_RM_XLU_SURF2), + }, + { + gsDPSetCombineMode(G_CC_MODULATEIA, G_CC_MODULATEIA), + gsDPSetOtherMode(DKR_OMH_1CYC_BILERP, DKR_OML_COMMON | G_RM_XLU_SURF | G_RM_XLU_SURF2), + }, + { + gsDPSetCombineMode(G_CC_PRIMITIVE, G_CC_PRIMITIVE), + gsDPSetOtherMode(DKR_OMH_1CYC_POINT_NOPERSP, DKR_OML_COMMON | G_RM_XLU_SURF | G_RM_XLU_SURF2), + } }; s8 D_800E1CD0[32] = { diff --git a/src/menu.h b/src/menu.h index 71ba48d1..4cb3e748 100644 --- a/src/menu.h +++ b/src/menu.h @@ -541,8 +541,7 @@ extern s16 D_800E1754[10]; extern s16 D_800E1768[12]; -// Fast3D (F3DDKR) display list -extern u32 D_800E1780[22]; +//extern u32 D_800E1780[22]; extern s16 D_800E17D8[12]; @@ -570,8 +569,7 @@ extern s32 gViewingCreditsFromCheat; extern MenuElement D_800E1B50[9]; -// Fast3D (F3DDKR) display list -extern u32 D_800E1C70[24]; +//extern u32 D_800E1C70[24]; extern s8 D_800E1CD0[32]; diff --git a/src/screen_asset.c b/src/screen_asset.c new file mode 100644 index 00000000..ac9d849e --- /dev/null +++ b/src/screen_asset.c @@ -0,0 +1,83 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x8007F640 */ + +#include "screen_asset.h" + +// Render settings for the screens +Gfx gRdpSetModeScreenAsset[] = { + gsDPSetCombineMode(DKR_CC_UNK10, DKR_CC_UNK10), + gsDPSetOtherMode(DKR_OMH_COPY_POINT_NOPERSP, DKR_OML_COMMON | G_RM_NOOP | G_RM_NOOP2), +}; + +/** + * Loads a 320x240 RGBA16 image to be displayed on the screen. + * Returns the address of the screen asset, or 0x80100000 if no screen assets were found. + * Unused. + */ +u8 *load_screen(s32 screenIndex) { + u8 *someAddr; + s32 screenTableCount, start, size; + s32 *screenTable; + + + screenTable = (u8 *)load_asset_section_from_rom(ASSET_SCREENS_TABLE); + screenTableCount = 0; + + while(screenTable[screenTableCount] != -1) { + screenTableCount++; + } + + screenTableCount--; + + // screenTableCount will always be 0 in vanilla DKR, + // since there are no screen assets in the ROM. + if (screenTableCount == 0) { + free_from_memory_pool(screenTable); + return 0x80100000; + } else { + if (screenIndex < 0 || screenIndex >= screenTableCount) { + func_800C9D54("SCREEN: No out of range!!\n"); + screenIndex = 0; + } + + start = screenTable[screenIndex]; + size = screenTable[screenIndex + 1] - start; + someAddr = allocate_from_main_pool_safe(size, COLOR_TAG_BLUE); + + load_asset_to_address(ASSET_SCREENS, someAddr, start, size); + free_from_memory_pool(screenTable); + + return someAddr; + } +} + +/** + * Renders a 320x240 RGBA16 screen asset. + * Unused. + */ +void render_screen(Gfx **dlist, u8 *screenAddress) { + s32 y_pos; + + gDkrDmaDisplayList((*dlist)++, (u32)&gRdpSetModeScreenAsset + 0x80000000, + numberOfGfxCommands(gRdpSetModeScreenAsset)) + + // Screen header is 16 bytes. + screenAddress += 16; + + // Draw each 320x6 RGBA16 slice until the screen image is fully drawn. + y_pos = 0; + while(y_pos != SCREEN_HEIGHT) { + // Load the texture. + gDPLoadTextureBlockS((*dlist)++, screenAddress + 0x80000000, G_IM_FMT_RGBA, G_IM_SIZ_16b, + SCREEN_WIDTH, SCREEN_HEIGHT_PART, 0, G_TX_CLAMP, G_TX_CLAMP, 0, 0, 0, 0) + + // Draw the texture. + gSPTextureRectangle((*dlist)++, 0, ((y_pos) << 2), SCREEN_WIDTH << 2, + ((y_pos + SCREEN_HEIGHT_PART) << 2), 0, 0, 0, 1 << 12, 1 << 10) + + // Advance to the next slice. + screenAddress += SCREEN_WIDTH * SCREEN_HEIGHT_PART * 2; + y_pos += SCREEN_HEIGHT_PART; + } +} + diff --git a/src/screen_asset.h b/src/screen_asset.h new file mode 100644 index 00000000..d11fceb4 --- /dev/null +++ b/src/screen_asset.h @@ -0,0 +1,14 @@ +#ifndef _SCREEN_ASSET_H_ +#define _SCREEN_ASSET_H_ + +#include "memory.h" +#include "types.h" +#include "macros.h" +#include "f3ddkr.h" +#include "asset_sections.h" + +#define SCREEN_WIDTH 320 +#define SCREEN_HEIGHT 240 +#define SCREEN_HEIGHT_PART 6 + +#endif diff --git a/src/unknown_078050.h b/src/unknown_078050.h index 614e2aed..6c4561bf 100644 --- a/src/unknown_078050.h +++ b/src/unknown_078050.h @@ -21,30 +21,4 @@ extern s32 D_800DE4D4; extern s32 D_800DE4D8; extern s32 D_800DE4DC; -/* -// Fast3D (F3DDKR) display list -extern u32 D_800DE4E0[]; - -// Fast3D (F3DDKR) display list -extern u32 D_800DE520[]; - -// Fast3D (F3DDKR) display list -extern u32 D_800DE598[]; - -// Fast3D (F3DDKR) display list -extern u32 D_800DE5E0[]; - -// Fast3D (F3DDKR) display list -extern u32 D_800DE628[]; - -// Fast3D (F3DDKR) display list -extern u32 D_800DE670[]; - -// Fast3D (F3DDKR) display list -extern u32 D_800DE6A8[]; - -// Fast3D (F3DDKR) display list -extern u32 D_800DE6E8[]; -*/ - #endif diff --git a/src/unknown_07B870.h b/src/unknown_07B870.h index 501b281b..de95182e 100644 --- a/src/unknown_07B870.h +++ b/src/unknown_07B870.h @@ -7,48 +7,4 @@ extern u32 D_800DE7C0; extern s32 D_800DE7C4; -/* -// Fast3D (F3DDKR) display list -extern Gfx D_800DE7C8[][2]; - -// Fast3D (F3DDKR) display list -extern u32 D_800DE848[]; - -// Fast3D (F3DDKR) display list -extern u32 D_800DE868[]; - -// Fast3D (F3DDKR) display list -extern u32 D_800DE8E8[]; - -// Fast3D (F3DDKR) display list -extern u32 D_800DECE8[]; - -// Fast3D (F3DDKR) display list -extern u32 D_800DEDE8[]; - -// Fast3D (F3DDKR) display list -extern u32 D_800DEEE8[]; - -// Fast3D (F3DDKR) display list -extern u32 D_800DEF28[]; - -// Fast3D (F3DDKR) display list -extern u32 D_800DF028[]; - -// Fast3D (F3DDKR) display list -extern u32 D_800DF0A8[]; - -// Fast3D (F3DDKR) display list -extern u32 D_800DF1A8[]; - -// Fast3D (F3DDKR) display list -extern u32 D_800DF3A8[]; - -// Fast3D (F3DDKR) display list -extern u32 D_800DF3D8[]; - -// Fast3D (F3DDKR) display list -extern u32 D_800DF410[]; -*/ - #endif diff --git a/src/unknown_080240.c b/src/unknown_080240.c deleted file mode 100644 index 5b7c94bc..00000000 --- a/src/unknown_080240.c +++ /dev/null @@ -1,87 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x8007F640 */ - -#include "unknown_080240.h" -#include "memory.h" - -#include "types.h" -#include "macros.h" -#include "fast3d.h" -#include "asset_sections.h" - -/************ .data ************/ - -// Fast3D (F3DDKR) display list -Gfx D_800DF440[] = { - 0xFC137E26, 0xFFFFF3F9, - 0xEF200CCF, 0x00000000 -}; - -/*******************************/ - -// Unused? -u32 func_8007F640(s32 arg0) { - u32 someAddr; - s32 count, start, size; - s32 *lut; - - lut = (s32 *)load_asset_section_from_rom(ASSET_EMPTY_10_TABLE); - - count = 0; - - while(lut[count] != -1) { - count++; - } - - count--; - - if (count == 0) { - free_from_memory_pool(lut); - return 0x80100000; - } else { - if (arg0 < 0 || arg0 >= count) { - func_800C9D54("SCREEN: No out of range!!\n"); - arg0 = 0; - } - - start = lut[arg0]; - size = lut[arg0 + 1] - start; - someAddr = allocate_from_main_pool_safe(size, COLOR_TAG_BLUE); - - load_asset_to_address(ASSET_EMPTY_10, someAddr, start, size); - free_from_memory_pool(lut); - - return someAddr; - } -} - -void func_8007F714(Gfx **dlist, s32 arg1) { - s32 y_pos; - - // In F3DDKR, command 0x07 is the display list call. - fast3d_cmd((*dlist)++, 0x07020010, (u32)&D_800DF440 + 0x80000000) - - arg1 += 0x10; - y_pos = 0; - - while(y_pos != 240) { - - // These 7 commands are a gDPLoadTextureBlock() - fast3d_cmd((*dlist)++, 0xFD100000, arg1 + 0x80000000) - fast3d_cmd((*dlist)++, 0xF5100000, 0x07080200) - fast3d_cmd((*dlist)++, 0xE6000000, 0x00000000) - fast3d_cmd((*dlist)++, 0xF3000000, 0x0777F000) - fast3d_cmd((*dlist)++, 0xE7000000, 0x00000000) - fast3d_cmd((*dlist)++, 0xF510A000, 0x00080200) - fast3d_cmd((*dlist)++, 0xF2000000, 0x004FC014) - - // These 3 are a gSPTextureRectangle() - fast3d_cmd((*dlist)++, 0xE4500000 | (((y_pos + 6) << 2) & 0xFFF), (y_pos << 2) & 0xFFF) - fast3d_cmd((*dlist)++, 0xB3000000, 0x00000000) - fast3d_cmd((*dlist)++, 0xB2000000, 0x10000400) - - arg1 += 0xF00; - y_pos += 6; - } -} - diff --git a/src/unknown_080240.h b/src/unknown_080240.h deleted file mode 100644 index a3e0cfe4..00000000 --- a/src/unknown_080240.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _UNKNOWN_080240_H_ -#define _UNKNOWN_080240_H_ - -#include "fast3d.h" - -// Fast3D (F3DDKR) display list -Gfx D_800DF440[]; - -#endif diff --git a/tools/dkr_extractor_classes/config.cpp b/tools/dkr_extractor_classes/config.cpp index fb7900bc..c2211bd7 100644 --- a/tools/dkr_extractor_classes/config.cpp +++ b/tools/dkr_extractor_classes/config.cpp @@ -118,6 +118,10 @@ void ExtractConfig::extract(ROM& rom, json::JSON& assetsJson) { json::JSON section = codeSections[i]; json::JSON files = section["files"]; std::string folder = this->outDirectory + "/" + section["folder"].ToString(); + if(!fs::is_directory(folder)) { + fs::create_directories(folder); + } + std::string type = section["type"].ToString(); int numFiles = files.length(); @@ -166,6 +170,10 @@ void ExtractConfig::extract(ROM& rom, json::JSON& assetsJson) { std::string folder = this->outDirectory + "/" + section["folder"].ToString(); std::string type = section["type"].ToString(); + if(!fs::is_directory(folder)) { + fs::create_directories(folder); + } + json::JSON outputAsset = json::Object(); outputAsset["type"] = type; @@ -230,10 +238,6 @@ void ExtractConfig::extract(ROM& rom, json::JSON& assetsJson) { std::string filename = extractions[i].filename; std::vector data = extractions[i].data; pool.enqueue([&rom, type, folder, filename, data] { - if(!fs::is_directory(folder)) { - fs::create_directories(folder); - } - std::string outFilepath = folder + "/" + filename; if(is_binary_type(type)) {