From 9eb3ffcc30184c67bb8873ef39d9ffbfc1831dc6 Mon Sep 17 00:00:00 2001 From: Phnod Date: Fri, 1 Sep 2023 00:02:47 -0400 Subject: [PATCH 01/13] port: add a config option to disable texture filtering on fonts --- port/include/video.h | 1 + port/src/video.c | 8 ++++++++ src/game/game_1531a0.c | 7 ++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/port/include/video.h b/port/include/video.h index 81738a76e..e5c82e576 100644 --- a/port/include/video.h +++ b/port/include/video.h @@ -19,6 +19,7 @@ s32 videoGetNativeHeight(void); s32 videoGetWidth(void); s32 videoGetHeight(void); f32 videoGetAspect(void); +u32 videoGetFontTextureFilter(void); s32 videoCreateFramebuffer(u32 w, u32 h); void videoSetFramebuffer(s32 target); diff --git a/port/src/video.c b/port/src/video.c index 17674ac80..e2928f338 100644 --- a/port/src/video.c +++ b/port/src/video.c @@ -20,6 +20,7 @@ static u32 dlcount = 0; static u32 frames = 0; static u32 framesPerSec = 0; static f64 startTime, endTime, fpsTime; +static u32 fontTextureFilter = 1; s32 videoInit(void) { @@ -46,6 +47,8 @@ s32 videoInit(void) if (filter > FILTER_THREE_POINT) filter = FILTER_THREE_POINT; renderingAPI->set_texture_filter((enum FilteringMode)filter); + fontTextureFilter = configGetInt("Video.FontTextureFilter", 1); + initDone = true; return 0; } @@ -134,6 +137,11 @@ f32 videoGetAspect(void) return gfx_current_dimensions.aspect_ratio; } +u32 videoGetFontTextureFilter(void) +{ + return fontTextureFilter; +} + s32 videoCreateFramebuffer(u32 w, u32 h) { return gfx_create_framebuffer(w, h); diff --git a/src/game/game_1531a0.c b/src/game/game_1531a0.c index 24fd38485..743d46c6a 100644 --- a/src/game/game_1531a0.c +++ b/src/game/game_1531a0.c @@ -394,7 +394,12 @@ Gfx *text0f153628(Gfx *gdl) } #endif else { - gDPSetTextureFilter(gdl++, G_TF_BILERP); + if (videoGetFontTextureFilter() == 0) { + gDPSetTextureFilter(gdl++, G_TF_POINT); + } + else { + gDPSetTextureFilter(gdl++, G_TF_BILERP); + } } return gdl; From 5235581e33888ebc94ab94f858098408a80c6282 Mon Sep 17 00:00:00 2001 From: Phnod Date: Fri, 1 Sep 2023 13:49:22 -0400 Subject: [PATCH 02/13] fix: remove height trim on rotated text --- src/game/game_1531a0.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/game_1531a0.c b/src/game/game_1531a0.c index 24fd38485..d1bc4f4da 100644 --- a/src/game/game_1531a0.c +++ b/src/game/game_1531a0.c @@ -1790,7 +1790,7 @@ Gfx *text0f15568c(Gfx *gdl, s32 *x, s32 *y, struct fontchar *curchar, struct fon (*x + curchar->width) * 4 + var8007fadc, G_TX_RENDERTILE, var8007fae8 + 32, - ((curchar->height - 1) << 5) + var8007fae4 + 32, + ((curchar->height) << 5) + var8007fae4 + 32, 1024, 65536 - 1024 / var8007fad0); } else { From eff475c4980d14365f1250fbe55789a5fe62e63e Mon Sep 17 00:00:00 2001 From: Phnod Date: Fri, 1 Sep 2023 14:38:17 -0400 Subject: [PATCH 03/13] fix: nudge menu left side text a pixel to the left to counteract extra pixel column --- src/game/menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/menu.c b/src/game/menu.c index 7f11faf3d..3a13a2f0e 100644 --- a/src/game/menu.c +++ b/src/game/menu.c @@ -3011,7 +3011,7 @@ Gfx *dialogRender(Gfx *gdl, struct menudialog *dialog, struct menu *menu, bool l textMeasure(&textheight, &textwidth, title, g_CharsHandelGothicXs, g_FontHandelGothicXs, 0); - x = dialogleft - 1; + x = dialogleft - 2; y = (dialogtop + dialogbottom) / 2 - textwidth - 3; if (y < dialogtop) { From b83604a677b7fd52279ff471d4330ceac20dd09c Mon Sep 17 00:00:00 2001 From: Phnod Date: Sat, 2 Sep 2023 02:44:41 -0400 Subject: [PATCH 04/13] fix: return false in chrHasLosToPosWasteful if outside FOV check --- src/game/chraction.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/game/chraction.c b/src/game/chraction.c index 04ceeb77e..8b87163ae 100644 --- a/src/game/chraction.c +++ b/src/game/chraction.c @@ -6579,7 +6579,11 @@ bool chrHasLosToPosWasteful(struct chrdata *chr, struct coord *pos, RoomNum *roo return chrHasLosToPos(chr, pos, rooms); } +#ifdef N64_PLATFORM return chrHasLosToPos(chr, pos, rooms); +#else + return false; +#endif } bool chrHasLosToProp(struct chrdata *chr, struct prop *prop) From 721c27c3292a2cb25989d5e920303742cdfbabb8 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Sat, 2 Sep 2023 22:05:33 +0200 Subject: [PATCH 05/13] port: add exit option to 4mb menu --- src/game/fmb.c | 10 ++++++++++ src/include/game/mainmenu.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/game/fmb.c b/src/game/fmb.c index 2fe4c2c05..f6de5aadd 100644 --- a/src/game/fmb.c +++ b/src/game/fmb.c @@ -585,6 +585,16 @@ struct menuitem g_MainMenu4MbMenuItems[] = { 0, (void *)&g_ChangeAgentMenuDialog, }, +#ifndef PLATFORM_N64 + { + MENUITEMTYPE_SELECTABLE, + 0, + MENUITEMFLAG_SELECTABLE_OPENSDIALOG | MENUITEMFLAG_BIGFONT, + L_OPTIONS_110, // "Exit Game" + 0x00000007, + (void *)&g_ExitGameMenuDialog, + }, +#endif { MENUITEMTYPE_END }, }; diff --git a/src/include/game/mainmenu.h b/src/include/game/mainmenu.h index 349d7458c..c44cd7c7d 100644 --- a/src/include/game/mainmenu.h +++ b/src/include/game/mainmenu.h @@ -10,6 +10,9 @@ extern struct menudialogdef g_AcceptMissionMenuDialog; extern struct menudialogdef g_PreAndPostMissionBriefingMenuDialog; extern struct menudialogdef g_RetryMissionMenuDialog; extern struct menudialogdef g_NextMissionMenuDialog; +#ifndef PLATFORM_N64 +extern struct menudialogdef g_ExitGameMenuDialog; +#endif char *menuTextCurrentStageName(struct menuitem *item); char *soloMenuTextDifficulty(struct menuitem *item); From 0d6a62ada0358e6f525bc38b8078205f0d440b4a Mon Sep 17 00:00:00 2001 From: Catherine Reprobate Date: Sat, 2 Sep 2023 13:28:21 -0700 Subject: [PATCH 06/13] Use XBox / PC Menu A/B semantics Fixes #110 --- port/src/input.c | 2 +- src/game/menu.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/port/src/input.c b/port/src/input.c index 743042aea..021d0e61f 100644 --- a/port/src/input.c +++ b/port/src/input.c @@ -156,7 +156,7 @@ void inputSetDefaultKeyBinds(void) }; static const u32 joybinds[][2] = { - { CK_B, SDL_CONTROLLER_BUTTON_A }, + { CK_A, SDL_CONTROLLER_BUTTON_A }, { CK_X, SDL_CONTROLLER_BUTTON_X }, { CK_Y, SDL_CONTROLLER_BUTTON_Y }, { CK_DPAD_L, SDL_CONTROLLER_BUTTON_B, }, diff --git a/src/game/menu.c b/src/game/menu.c index 7f11faf3d..57e9f222b 100644 --- a/src/game/menu.c +++ b/src/game/menu.c @@ -4624,11 +4624,11 @@ void menuProcessInput(void) if (buttonsnow & BUTTON_RADIAL) { inputs.select = 1; } - // this will naturally feel nice w/ a switch layout - // with the default mapping for weapon-back + if (buttonsnow & BUTTON_WPNBACK) { - inputs.select = 1; + inputs.back = 1; } + #endif if (buttonsnow & B_BUTTON) { inputs.back = 1; From 07c3a513ef02cdbaa2ec08ae11ed1b4f07d4a860 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Sun, 3 Sep 2023 00:36:27 +0200 Subject: [PATCH 07/13] port: generalize the texture font filter a bit now called TextureFilter2D; although for now I couldn't find anything other than fonts to use it on --- port/include/video.h | 2 +- port/src/video.c | 8 ++++---- src/game/game_1531a0.c | 7 +------ src/game/tex.c | 3 +++ src/game/texreset.c | 3 +++ src/include/data.h | 10 ++++++++++ 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/port/include/video.h b/port/include/video.h index e5c82e576..c0f676ec4 100644 --- a/port/include/video.h +++ b/port/include/video.h @@ -19,7 +19,7 @@ s32 videoGetNativeHeight(void); s32 videoGetWidth(void); s32 videoGetHeight(void); f32 videoGetAspect(void); -u32 videoGetFontTextureFilter(void); +u32 videoGetTextureFilter2D(void); s32 videoCreateFramebuffer(u32 w, u32 h); void videoSetFramebuffer(s32 target); diff --git a/port/src/video.c b/port/src/video.c index e2928f338..ccac1972f 100644 --- a/port/src/video.c +++ b/port/src/video.c @@ -20,7 +20,7 @@ static u32 dlcount = 0; static u32 frames = 0; static u32 framesPerSec = 0; static f64 startTime, endTime, fpsTime; -static u32 fontTextureFilter = 1; +static u32 texFilter2D = 1; s32 videoInit(void) { @@ -47,7 +47,7 @@ s32 videoInit(void) if (filter > FILTER_THREE_POINT) filter = FILTER_THREE_POINT; renderingAPI->set_texture_filter((enum FilteringMode)filter); - fontTextureFilter = configGetInt("Video.FontTextureFilter", 1); + texFilter2D = configGetIntClamped("Video.TextureFilter2D", 1, 0, 1); initDone = true; return 0; @@ -137,9 +137,9 @@ f32 videoGetAspect(void) return gfx_current_dimensions.aspect_ratio; } -u32 videoGetFontTextureFilter(void) +u32 videoGetTextureFilter2D(void) { - return fontTextureFilter; + return texFilter2D; } s32 videoCreateFramebuffer(u32 w, u32 h) diff --git a/src/game/game_1531a0.c b/src/game/game_1531a0.c index 52434cfc3..33a443e37 100644 --- a/src/game/game_1531a0.c +++ b/src/game/game_1531a0.c @@ -394,12 +394,7 @@ Gfx *text0f153628(Gfx *gdl) } #endif else { - if (videoGetFontTextureFilter() == 0) { - gDPSetTextureFilter(gdl++, G_TF_POINT); - } - else { - gDPSetTextureFilter(gdl++, G_TF_BILERP); - } + gDPSetTextureFilter(gdl++, TEX_FILTER_2D); } return gdl; diff --git a/src/game/tex.c b/src/game/tex.c index 82f29b5ea..953b5a464 100644 --- a/src/game/tex.c +++ b/src/game/tex.c @@ -39,6 +39,9 @@ s32 g_TexLutMode; u32 var800ab5b4; struct tilestate g_TexTileStates[8]; struct tilesize g_TexTileSizes[8]; +#ifndef PLATFORM_N64 +u32 g_TexFilter2D = G_TF_BILERP; +#endif // Default u16 g_SurfaceTypeDefaultSounds[] = { SFX_HIT_STONE_8087, SFX_HIT_STONE_8088 }; diff --git a/src/game/texreset.c b/src/game/texreset.c index 30251c2ff..4bf444113 100644 --- a/src/game/texreset.c +++ b/src/game/texreset.c @@ -136,6 +136,9 @@ void texReset(void) // reset backend texture cache videoResetTextureCache(); + + // get backend texture settings + g_TexFilter2D = videoGetTextureFilter2D() ? G_TF_BILERP : G_TF_POINT; #endif g_TexWords = mempAlloc(ALIGN16(g_TexNumConfigs * 4), MEMPOOL_STAGE); diff --git a/src/include/data.h b/src/include/data.h index c70056c8c..c6c84d346 100644 --- a/src/include/data.h +++ b/src/include/data.h @@ -528,12 +528,22 @@ extern struct menudialogdef g_HtDetailsMenuDialog; extern struct menudialogdef g_HtFailedMenuDialog; extern struct menudialogdef g_HtCompletedMenuDialog; extern struct menudialogdef g_HangarListMenuDialog; + #ifndef PLATFORM_N64 + extern f32 g_PlayerCrosshairSway; extern f32 g_PlayerDefaultFovY; extern s32 g_PlayerMouseAimMode; extern f32 g_PlayerMouseAimSpeedX; extern f32 g_PlayerMouseAimSpeedY; +extern u32 g_TexFilter2D; + +#define TEX_FILTER_2D g_TexFilter2D + +#else + +#define TEX_FILTER_2D G_TF_BILERP + #endif #endif From 840a2e73a5ba8080a596c5c4faad8b35fadfe5d0 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Sun, 3 Sep 2023 19:12:29 +0200 Subject: [PATCH 08/13] port: implement screen shake --- port/include/video.h | 2 ++ port/src/main.c | 1 + port/src/pdsched.c | 1 + port/src/video.c | 6 ++++++ src/game/explosions.c | 12 +++++++++--- src/include/data.h | 1 + src/lib/vi.c | 12 ++++++++++++ 7 files changed, 32 insertions(+), 3 deletions(-) diff --git a/port/include/video.h b/port/include/video.h index c0f676ec4..09335e954 100644 --- a/port/include/video.h +++ b/port/include/video.h @@ -21,6 +21,8 @@ s32 videoGetHeight(void); f32 videoGetAspect(void); u32 videoGetTextureFilter2D(void); +void videoSetWindowOffset(s32 x, s32 y); + s32 videoCreateFramebuffer(u32 w, u32 h); void videoSetFramebuffer(s32 target); void videoResetFramebuffer(void); diff --git a/port/src/main.c b/port/src/main.c index 6e7d04dd4..589a18675 100644 --- a/port/src/main.c +++ b/port/src/main.c @@ -72,6 +72,7 @@ static void gameLoadConfig(void) g_PlayerMouseAimMode = configGetIntClamped("Game.MouseAimMode", g_PlayerMouseAimMode, 0, 1); g_PlayerMouseAimSpeedX = configGetFloatClamped("Game.MouseAimSpeedX", g_PlayerMouseAimSpeedX, 0.f, 10.f); g_PlayerMouseAimSpeedY = configGetFloatClamped("Game.MouseAimSpeedY", g_PlayerMouseAimSpeedY, 0.f, 10.f); + g_ViShakeIntensityMult = configGetFloatClamped("Game.ScreenShakeIntensity", 1.f, 0.f, 100.f); } int main(int argc, const char **argv) diff --git a/port/src/pdsched.c b/port/src/pdsched.c index ad119f8bf..5cf9ff5e1 100644 --- a/port/src/pdsched.c +++ b/port/src/pdsched.c @@ -94,6 +94,7 @@ bool g_SchedViModesPending[NUM_GFXTASKS] = {false, false}; s32 g_ViUnblackTimer = NUM_FRAMEBUFFERS + 1; s32 g_ViShakeDirection = 1; s32 g_ViShakeIntensity = 0; +f32 g_ViShakeIntensityMult = 1.f; s32 g_ViShakeTimer = 0; u32 var8005cea0 = 0; u32 var8005cea4 = 0; diff --git a/port/src/video.c b/port/src/video.c index ccac1972f..80f353ca3 100644 --- a/port/src/video.c +++ b/port/src/video.c @@ -142,6 +142,12 @@ u32 videoGetTextureFilter2D(void) return texFilter2D; } +void videoSetWindowOffset(s32 x, s32 y) +{ + gfx_current_game_window_viewport.x = x; + gfx_current_game_window_viewport.y = y; +} + s32 videoCreateFramebuffer(u32 w, u32 h) { return gfx_create_framebuffer(w, h); diff --git a/src/game/explosions.c b/src/game/explosions.c index 361dadb65..c7516f216 100644 --- a/src/game/explosions.c +++ b/src/game/explosions.c @@ -28,6 +28,12 @@ #include "data.h" #include "types.h" +#ifdef PLATFORM_N64 +#define SHAKE_TIME 6 +#else +#define SHAKE_TIME 12 +#endif + struct explosion *g_Explosions; s32 g_MaxExplosions; @@ -296,7 +302,7 @@ bool explosionCreate(struct prop *sourceprop, struct coord *exppos, RoomNum *exp struct prop *expprop = propAllocate(); if (type != EXPLOSIONTYPE_16 && type != EXPLOSIONTYPE_BULLETHOLE) { - g_ExplosionShakeTotalTimer = 6; + g_ExplosionShakeTotalTimer = SHAKE_TIME; } if (expprop) { @@ -554,8 +560,8 @@ bool explosionCreate(struct prop *sourceprop, struct coord *exppos, RoomNum *exp */ void explosionShake(void) { - g_ExplosionShakeTotalTimer = 6; - g_ExplosionShakeIntensityTimer = 6; + g_ExplosionShakeTotalTimer = SHAKE_TIME; + g_ExplosionShakeIntensityTimer = SHAKE_TIME; } void explosionsUpdateShake(struct coord *arg0, struct coord *arg1, struct coord *arg2) diff --git a/src/include/data.h b/src/include/data.h index c6c84d346..cf2554829 100644 --- a/src/include/data.h +++ b/src/include/data.h @@ -536,6 +536,7 @@ extern f32 g_PlayerDefaultFovY; extern s32 g_PlayerMouseAimMode; extern f32 g_PlayerMouseAimSpeedX; extern f32 g_PlayerMouseAimSpeedY; +extern f32 g_ViShakeIntensityMult; extern u32 g_TexFilter2D; #define TEX_FILTER_2D g_TexFilter2D diff --git a/src/lib/vi.c b/src/lib/vi.c index 77124383b..a7edc92e8 100644 --- a/src/lib/vi.c +++ b/src/lib/vi.c @@ -14,6 +14,9 @@ #include "lib/mtx.h" #include "data.h" #include "types.h" +#ifndef PLATFORM_N64 +#include "video.h" +#endif #define TO_U16_A(x) ((u16)(x)) #define TO_U16_B(x) ((x) & 0xffff) @@ -280,6 +283,10 @@ void viHandleRetrace(void) osSetIntMask(prevmask); #endif +#ifndef PLATFORM_N64 + videoSetWindowOffset(0, offset); +#endif + osViSetMode(var8008dd60[1 - var8005ce74]); osViBlack(g_ViUnblackTimer); osViSetXScale(g_ViXScalesBySlot[1 - var8005ce74]); @@ -460,8 +467,13 @@ void viShake(f32 intensity) intensity = 0; } +#ifdef PLATFORM_N64 g_ViShakeIntensity = intensity; g_ViShakeTimer = 10; +#else + g_ViShakeIntensity = intensity * g_ViShakeIntensityMult; + g_ViShakeTimer = 20; +#endif } void viSetMode(s32 mode) From 110386a3dd071518ca872fa53b174d3fbd8f70aa Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 4 Sep 2023 21:02:50 +0200 Subject: [PATCH 09/13] tools: mklang: explicitly specify utf-8 --- tools/assetmgr/mklang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/assetmgr/mklang b/tools/assetmgr/mklang index 047896d63..a4dfbc8cc 100755 --- a/tools/assetmgr/mklang +++ b/tools/assetmgr/mklang @@ -7,7 +7,7 @@ import re import sys def main(): - fd = open(sys.argv[1], 'r') + fd = open(sys.argv[1], 'r', encoding='UTF-8') data = fd.read() fd.close() From d6854c412c4a36c74d51af21cb7b1dde0f2d2b1b Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 4 Sep 2023 21:04:23 +0200 Subject: [PATCH 10/13] port: allow building with pal-final and jpn-final this will produce a separate executable that will load pd.pal-final.z64 or pd.jpn-final.z64, respectively japanese characters are broken in jpn and pal crashes when you try to select language, so no autobuilds yet --- Makefile.port | 11 ++++- port/fast3d/gfx_pc.h | 1 + port/src/romdata.c | 100 +++++++++++++++++++++++++++-------------- src/game/game_1531a0.c | 2 +- src/game/lang.c | 6 +-- src/game/langinit.c | 9 ++++ 6 files changed, 90 insertions(+), 39 deletions(-) diff --git a/Makefile.port b/Makefile.port index 0ca2bd254..34f2cb983 100644 --- a/Makefile.port +++ b/Makefile.port @@ -27,6 +27,8 @@ TARGET_PLATFORM ?= # # Supported values: # * ntsc-final +# * pal-final +# * jpn-final ROMID ?= ntsc-final @@ -99,6 +101,13 @@ TARGET_BIG_ENDIAN = 0 # TODO # The VERSION constant is used in the source to handle version-specific code. ifeq ($(ROMID),ntsc-final) VERSION = 2 + IS_PAL = 0 +else ifeq ($(ROMID),pal-final) + VERSION = 4 + IS_PAL = 1 +else ifeq ($(ROMID),jpn-final) + VERSION = 5 + IS_PAL = 0 else $(error ROM version $(VERSION) is not supported) endif @@ -113,7 +122,7 @@ DEFINES := \ VERSION_TARGET=\"$(VERSION_TARGET)\" \ VERSION_ROMID=\"$(VERSION_ROMID)\" \ MATCHING=0 \ - PAL=0 \ + PAL=$(IS_PAL) \ PIRACYCHECKS=0 \ ROM_SIZE=$(ROM_SIZE) \ _LANGUAGE_C=1 diff --git a/port/fast3d/gfx_pc.h b/port/fast3d/gfx_pc.h index 0ca55152f..363efd0cf 100644 --- a/port/fast3d/gfx_pc.h +++ b/port/fast3d/gfx_pc.h @@ -25,6 +25,7 @@ struct TextureCacheKey { const uint8_t* palette_addrs[2]; uint8_t fmt, siz; uint8_t palette_index; + uint32_t salt; bool operator==(const TextureCacheKey&) const noexcept = default; diff --git a/port/src/romdata.c b/port/src/romdata.c index 091f18726..41f9957e0 100644 --- a/port/src/romdata.c +++ b/port/src/romdata.c @@ -20,16 +20,31 @@ * at load time, which is fucking terrible */ -#define ROMDATA_ROM_NAME "pd.ntsc-final.z64" -#define ROMDATA_ROM_SIZE 33554432 -#define ROMDATA_ROM_HASH // TODO - #define ROMDATA_FILEDIR "files" #define ROMDATA_SEGDIR "segs" -// for ntsc-final +#define ROMDATA_ROM_NAME "pd." VERSION_ROMID ".z64" +#define ROMDATA_ROM_SIZE 33554432 +#define ROMDATA_ROM_HASH // TODO + +#if VERSION == VERSION_NTSC_FINAL +#define ROMDATA_ROM_TITLE "Perfect Dark" +#define ROMDATA_ROM_ID "NPDE" #define ROMDATA_FILES_OFS 0x28080 #define ROMDATA_DATA_OFS 0x39850 +#elif VERSION == VERSION_PAL_FINAL +#define ROMDATA_ROM_TITLE "Perfect Dark" +#define ROMDATA_ROM_ID "NPDP" +#define ROMDATA_FILES_OFS 0x28910 +#define ROMDATA_DATA_OFS 0x39850 +#elif VERSION == VERSION_JPN_FINAL +#define ROMDATA_ROM_TITLE "PERFECT DARK" +#define ROMDATA_ROM_ID "NPDJ" +#define ROMDATA_FILES_OFS 0x28800 +#define ROMDATA_DATA_OFS 0x39850 +#else +#error "This ROM version is unsupported." +#endif #define ROMDATA_MAX_FILES 2048 @@ -59,37 +74,40 @@ static struct romfile fileSlots[ROMDATA_MAX_FILES]; /* segment table for ntsc-final */ /* size will get calculated automatically if it is 0 */ /* if there are replacement files in the data dir, they will be loaded instead */ +/* offsets are specified for ntsc-final, pal-final and jpn-final in that order */ #define ROMSEG_LIST() \ - ROMSEG_DECL_SEG(fontjpnsingle, 0x194b20, 0x0, preprocessJpnFont ) \ - ROMSEG_DECL_SEG(fontjpnmulti, 0x19fb40, 0x0, preprocessJpnFont ) \ - ROMSEG_DECL_SEG(animations, 0x1a15c0, 0x0, preprocessAnimations ) \ - ROMSEG_DECL_SEG(mpconfigs, 0x7d0a40, 0x11E0, preprocessMpConfigs ) \ - ROMSEG_DECL_SEG(mpstringsE, 0x7d1c20, 0x3700, NULL ) \ - ROMSEG_DECL_SEG(mpstringsJ, 0x7d5320, 0x3700, NULL ) \ - ROMSEG_DECL_SEG(mpstringsP, 0x7d8a20, 0x3700, NULL ) \ - ROMSEG_DECL_SEG(mpstringsG, 0x7dc120, 0x3700, NULL ) \ - ROMSEG_DECL_SEG(mpstringsF, 0x7df820, 0x3700, NULL ) \ - ROMSEG_DECL_SEG(mpstringsS, 0x7e2f20, 0x3700, NULL ) \ - ROMSEG_DECL_SEG(mpstringsI, 0x7e6620, 0x3700, NULL ) \ - ROMSEG_DECL_SEG(firingrange, 0x7e9d20, 0x1550, NULL ) \ - ROMSEG_DECL_SEG(fonttahoma, 0x7f7860, 0x0, preprocessFont ) \ - ROMSEG_DECL_SEG(fontnumeric, 0x7f8b20, 0x0, preprocessFont ) \ - ROMSEG_DECL_SEG(fonthandelgothicsm, 0x7f9d30, 0x0, preprocessFont ) \ - ROMSEG_DECL_SEG(fonthandelgothicxs, 0x7fbfb0, 0x0, preprocessFont ) \ - ROMSEG_DECL_SEG(fonthandelgothicmd, 0x7fdd80, 0x0, preprocessFont ) \ - ROMSEG_DECL_SEG(fonthandelgothiclg, 0x8008e0, 0x0, preprocessFont ) \ - ROMSEG_DECL_SEG(sfxctl, 0x80a250, 0x2fb80, preprocessALBankFile ) \ - ROMSEG_DECL_SEG(sfxtbl, 0x839dd0, 0x4c2160, NULL ) \ - ROMSEG_DECL_SEG(seqctl, 0xcfbf30, 0xa060, preprocessALBankFile ) \ - ROMSEG_DECL_SEG(seqtbl, 0xd05f90, 0x17c070, NULL ) \ - ROMSEG_DECL_SEG(sequences, 0xe82000, 0x563a0, preprocessSequences ) \ - ROMSEG_DECL_SEG(texturesdata, 0x1d65f40, 0x291d60, NULL ) \ - ROMSEG_DECL_SEG(textureslist, 0x1ff7ca0, 0x6d80, preprocessTexturesList ) + ROMSEG_DECL_SEG(fontjpnsingle, 0x194b20, 0x180330, 0x0, 0x0, preprocessJpnFont ) \ + ROMSEG_DECL_SEG(fontjpnmulti, 0x19fb40, 0x18b340, 0x0, 0x0, preprocessJpnFont ) \ + ROMSEG_DECL_SEG(animations, 0x1a15c0, 0x18cdc0, 0x190c50, 0x0, preprocessAnimations ) \ + ROMSEG_DECL_SEG(mpconfigs, 0x7d0a40, 0x7bc240, 0x7c00d0, 0x11e0, preprocessMpConfigs ) \ + ROMSEG_DECL_SEG(mpstringsE, 0x7d1c20, 0x7bd420, 0x7c12b0, 0x3700, NULL ) \ + ROMSEG_DECL_SEG(mpstringsJ, 0x7d5320, 0x7c0b20, 0x7c49b0, 0x3700, NULL ) \ + ROMSEG_DECL_SEG(mpstringsP, 0x7d8a20, 0x7c4220, 0x7c80b0, 0x3700, NULL ) \ + ROMSEG_DECL_SEG(mpstringsG, 0x7dc120, 0x7c7920, 0x7cb7b0, 0x3700, NULL ) \ + ROMSEG_DECL_SEG(mpstringsF, 0x7df820, 0x7cb020, 0x7ceeb0, 0x3700, NULL ) \ + ROMSEG_DECL_SEG(mpstringsS, 0x7e2f20, 0x7ce720, 0x7d25b0, 0x3700, NULL ) \ + ROMSEG_DECL_SEG(mpstringsI, 0x7e6620, 0x7d1e20, 0x7d5cb0, 0x3700, NULL ) \ + ROMSEG_DECL_SEG(firingrange, 0x7e9d20, 0x7d5520, 0x7d93b0, 0x1550, NULL ) \ + ROMSEG_DECL_SEG(fonttahoma, 0x7f7860, 0x7e3060, 0x7e6ef0, 0x0, preprocessFont ) \ + ROMSEG_DECL_SEG(fontnumeric, 0x7f8b20, 0x7e4320, 0x7e81b0, 0x0, preprocessFont ) \ + ROMSEG_DECL_SEG(fonthandelgothicsm, 0x7f9d30, 0x7e5530, 0x7e93c0, 0x0, preprocessFont ) \ + ROMSEG_DECL_SEG(fonthandelgothicxs, 0x7fbfb0, 0x7e87b0, 0x7ec640, 0x0, preprocessFont ) \ + ROMSEG_DECL_SEG(fonthandelgothicmd, 0x7fdd80, 0x7eae20, 0x7eecb0, 0x0, preprocessFont ) \ + ROMSEG_DECL_SEG(fonthandelgothiclg, 0x8008e0, 0x7eee70, 0x7f2d00, 0x0, preprocessFont ) \ + ROMSEG_DECL_SEG(sfxctl, 0x80a250, 0x7f87e0, 0x7fc670, 0x2fb80, preprocessALBankFile ) \ + ROMSEG_DECL_SEG(sfxtbl, 0x839dd0, 0x828360, 0x82c1f0, 0x4c2160, NULL ) \ + ROMSEG_DECL_SEG(seqctl, 0xcfbf30, 0xcea4c0, 0xcee350, 0xa060, preprocessALBankFile ) \ + ROMSEG_DECL_SEG(seqtbl, 0xd05f90, 0xcf4520, 0xcf83b0, 0x17c070, NULL ) \ + ROMSEG_DECL_SEG(sequences, 0xe82000, 0xe70590, 0xe74420, 0x563a0, preprocessSequences ) \ + ROMSEG_DECL_SEG(texturesdata, 0x1d65f40, 0x1d5ca20, 0x1d61f90, 0x0, NULL ) \ + ROMSEG_DECL_SEG(textureslist, 0x1ff7ca0, 0x1fee780, 0x1ff68f0, 0x0, preprocessTexturesList ) \ + ROMSEG_DECL_SEG(copyright, 0x1ffea20, 0x1ff5500, 0x1ffd6b0, 0xb30, NULL ) \ + ROMSEG_DECL_SEG(fontjpn, 0x0, 0x0, 0x178c40, 0x17920, preprocessJpnFont ) // declare the vars first #undef ROMSEG_DECL_SEG -#define ROMSEG_DECL_SEG(name, ofs, size, preproc) u8 *ROMSEG_START(name), *ROMSEG_END(name); +#define ROMSEG_DECL_SEG(name, ofs_ntsc, ofs_pal, ofs_jpn, size, preproc) u8 *ROMSEG_START(name), *ROMSEG_END(name); ROMSEG_LIST() // this is part of the animations seg and as such does not follow the naming convention @@ -100,13 +118,21 @@ u8 *_animationsTableRomEnd; // then build the table #undef ROMSEG_DECL_SEG -#define ROMSEG_DECL_SEG(name, ofs, size, preproc) { &ROMSEG_START(name), &ROMSEG_END(name), #name, (u8 *)ofs, size, preproc }, + +#if VERSION == VERSION_NTSC_FINAL +#define ROMSEG_DECL_SEG(name, ofs_ntsc, ofs_pal, ofs_jpn, size, preproc) { &ROMSEG_START(name), &ROMSEG_END(name), #name, (u8 *)ofs_ntsc, size, preproc }, +#elif VERSION == VERSION_PAL_FINAL +#define ROMSEG_DECL_SEG(name, ofs_ntsc, ofs_pal, ofs_jpn, size, preproc) { &ROMSEG_START(name), &ROMSEG_END(name), #name, (u8 *)ofs_pal, size, preproc }, +#elif VERSION == VERSION_JPN_FINAL +#define ROMSEG_DECL_SEG(name, ofs_ntsc, ofs_pal, ofs_jpn, size, preproc) { &ROMSEG_START(name), &ROMSEG_END(name), #name, (u8 *)ofs_jpn, size, preproc }, +#endif + static struct romfile romSegs[] = { ROMSEG_LIST() { NULL, NULL, NULL, NULL, 0, NULL }, }; -/* the game sets g_LoadType to the type of file it expects, */ +/* the game sets g_LoadType to the type of file it expects, */ /* so we can hijack that in fileLoad and automatically byteswap the file */ static preprocessfunc filePreprocFuncs[] = { /* LOADTYPE_NONE */ NULL, @@ -133,7 +159,7 @@ static inline void romdataLoadRom(void) sysFatalError("Wrong ROM file size.\nExpected: %u\nGot: %u", ROMDATA_ROM_SIZE, g_RomFileSize); } - if (memcmp(g_RomFile + 0x3b, "NPDE", 4) || memcmp(g_RomFile + 0x20, "Perfect Dark", 12)) { + if (memcmp(g_RomFile + 0x3b, ROMDATA_ROM_ID, 4) || memcmp(g_RomFile + 0x20, ROMDATA_ROM_TITLE, sizeof(ROMDATA_ROM_TITLE) - 1)) { sysFatalError("Wrong ROM file.\nEnsure that it is the correct NTSC v1.1 ROM in z64 format."); } @@ -169,6 +195,12 @@ static inline void romdataLoadRom(void) static inline void romdataInitSegment(struct romfile *seg) { + if (!seg->data) { + // unused in this ROM, skip it + sysLogPrintf(LOG_NOTE, "skipping segment %s", seg->name); + return; + } + if (!seg->size) { // size unknown if (seg[1].name) { diff --git a/src/game/game_1531a0.c b/src/game/game_1531a0.c index 33a443e37..e4082a6e2 100644 --- a/src/game/game_1531a0.c +++ b/src/game/game_1531a0.c @@ -341,7 +341,7 @@ void textReset(void) textLoadFont(REF_SEG _fonthandelgothiclgSegmentRomStart, REF_SEG _fonthandelgothiclgSegmentRomEnd, &g_FontHandelGothicLg, &g_CharsHandelGothicLg, false); } - textLoadFont(&_fonthandelgothicxsSegmentRomStart, &_fonthandelgothicxsSegmentRomEnd, &g_FontHandelGothicXs, &g_CharsHandelGothicXs, false); + textLoadFont(REF_SEG _fonthandelgothicxsSegmentRomStart, REF_SEG _fonthandelgothicxsSegmentRomEnd, &g_FontHandelGothicXs, &g_CharsHandelGothicXs, false); #elif VERSION >= VERSION_PAL_BETA textLoadFont(REF_SEG _fontnumericSegmentRomStart, REF_SEG _fontnumericSegmentRomEnd, &g_FontNumeric, &g_CharsNumeric, false); textLoadFont(REF_SEG _fonthandelgothicxsSegmentRomStart, REF_SEG _fonthandelgothicxsSegmentRomEnd, &g_FontHandelGothicXs, &g_CharsHandelGothicXs, false); diff --git a/src/game/lang.c b/src/game/lang.c index 5c39493fd..5762cc39d 100644 --- a/src/game/lang.c +++ b/src/game/lang.c @@ -290,7 +290,7 @@ struct jpncharpixels *langGetJpnCharPixels(s32 codepoint) g_JpnCacheCacheItems[freeindexsingle].codepoint = codepoint; dmaExec((u8 *) (freeindexsingle * (TMUL * 0x0c) + (romptr_t) &g_JpnCharCachePixels[0]), - (romptr_t) &_fontjpnSegmentRomStart + ((codepoint * TMUL) * 0xc + TMUL * (24 * 0xc)), + (romptr_t) REF_SEG _fontjpnSegmentRomStart + ((codepoint * TMUL) * 0xc + TMUL * (24 * 0xc)), TMUL * 0x0c); return &g_JpnCharCachePixels[TMUL * freeindexsingle]; @@ -311,7 +311,7 @@ struct jpncharpixels *langGetJpnCharPixels(s32 codepoint) g_JpnCacheCacheItems[freeindexsingle].ttl = 2; g_JpnCacheCacheItems[freeindexsingle].codepoint = codepoint >> 1; - dmaExec(&g_JpnCharCachePixels[freeindexsingle * 8], (romptr_t) &_fontjpnsingleSegmentRomStart + (codepoint >> SHIFTAMOUNT) * 0x60, 0x60); + dmaExec(&g_JpnCharCachePixels[freeindexsingle * 8], (romptr_t) REF_SEG _fontjpnsingleSegmentRomStart + (codepoint >> SHIFTAMOUNT) * 0x60, 0x60); return &g_JpnCharCachePixels[freeindexsingle * 8]; } @@ -322,7 +322,7 @@ struct jpncharpixels *langGetJpnCharPixels(s32 codepoint) g_JpnCacheCacheItems[freeindexmulti + 0].codepoint = codepoint >> 1; g_JpnCacheCacheItems[freeindexmulti + 1].codepoint = codepoint >> 1; - dmaExec(&g_JpnCharCachePixels[freeindexmulti * 8], (romptr_t) &_fontjpnmultiSegmentRomStart + ((codepoint & 0x1fff) >> SHIFTAMOUNT) * 0x80, 0x80); + dmaExec(&g_JpnCharCachePixels[freeindexmulti * 8], (romptr_t) REF_SEG _fontjpnmultiSegmentRomStart + ((codepoint & 0x1fff) >> SHIFTAMOUNT) * 0x80, 0x80); return &g_JpnCharCachePixels[freeindexmulti * 8]; } diff --git a/src/game/langinit.c b/src/game/langinit.c index e7b48c326..0d25371b4 100644 --- a/src/game/langinit.c +++ b/src/game/langinit.c @@ -7,6 +7,15 @@ u16 *g_FrameBuffers[NUM_FRAMEBUFFERS]; +#ifndef PLATFORM_N64 +#if VERSION >= VERSION_JPN_FINAL +u32 var8009d010pf[4]; +s32 g_JpnMaxCacheItems; +#elif VERSION >= VERSION_PAL_BETA +u32 var8009d010pf[4]; +#endif +#endif + void langInit(void) { s32 i; From 491d3521f7507eb9c1d958df409e856a6e411f5b Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 4 Sep 2023 21:06:49 +0200 Subject: [PATCH 11/13] port: different names for pal and jpn EXEs --- Makefile.port | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile.port b/Makefile.port index 34f2cb983..2b123e83b 100644 --- a/Makefile.port +++ b/Makefile.port @@ -100,12 +100,15 @@ TARGET_BIG_ENDIAN = 0 # TODO # The VERSION constant is used in the source to handle version-specific code. ifeq ($(ROMID),ntsc-final) + BIN_NAME = pd.exe VERSION = 2 IS_PAL = 0 else ifeq ($(ROMID),pal-final) + BIN_NAME = pd.pal.exe VERSION = 4 IS_PAL = 1 else ifeq ($(ROMID),jpn-final) + BIN_NAME = pd.jpn.exe VERSION = 5 IS_PAL = 0 else @@ -257,7 +260,7 @@ LDFLAGS := $(TARGET_LDFLAGS) # (We use this a lot) export ROMID -BIN := $(B_DIR)/pd.exe +BIN := $(B_DIR)/$(BIN_NAME) default: $(JSON_HEADERS) $(BIN) From d7652a6db6d3cf59e6d954404d6f5a10aeddf1ab Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 4 Sep 2023 21:10:20 +0200 Subject: [PATCH 12/13] port: remove stray field in TextureCacheKey --- port/fast3d/gfx_pc.h | 1 - 1 file changed, 1 deletion(-) diff --git a/port/fast3d/gfx_pc.h b/port/fast3d/gfx_pc.h index 363efd0cf..0ca55152f 100644 --- a/port/fast3d/gfx_pc.h +++ b/port/fast3d/gfx_pc.h @@ -25,7 +25,6 @@ struct TextureCacheKey { const uint8_t* palette_addrs[2]; uint8_t fmt, siz; uint8_t palette_index; - uint32_t salt; bool operator==(const TextureCacheKey&) const noexcept = default; From dde656c4c355d8eb72722d80f5ec00da905f4630 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 4 Sep 2023 21:47:42 +0200 Subject: [PATCH 13/13] port: fix typo --- src/game/chraction.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/chraction.c b/src/game/chraction.c index 8b87163ae..5f442f965 100644 --- a/src/game/chraction.c +++ b/src/game/chraction.c @@ -6579,7 +6579,7 @@ bool chrHasLosToPosWasteful(struct chrdata *chr, struct coord *pos, RoomNum *roo return chrHasLosToPos(chr, pos, rooms); } -#ifdef N64_PLATFORM +#ifdef PLATFORM_N64 return chrHasLosToPos(chr, pos, rooms); #else return false;