From c10050a14c5b60362abcd0ba0f31f38627dbf9e6 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 11 Sep 2023 18:32:09 +0200 Subject: [PATCH] port: jpn-final: possibly fix japanese characters --- port/fast3d/gfx_api.h | 1 + port/fast3d/gfx_pc.cpp | 11 +++++++++-- port/include/video.h | 1 + port/src/video.c | 5 +++++ src/game/lang.c | 18 ++++++++++++++++++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/port/fast3d/gfx_api.h b/port/fast3d/gfx_api.h index 27109a5fc..6b9fd7acf 100644 --- a/port/fast3d/gfx_api.h +++ b/port/fast3d/gfx_api.h @@ -39,6 +39,7 @@ void gfx_end_frame(void); void gfx_set_target_fps(int); void gfx_set_maximum_frame_latency(int latency); void gfx_texture_cache_clear(void); +void gfx_texture_cache_delete(const uint8_t *orig_addr); int gfx_create_framebuffer(uint32_t width, uint32_t height); void gfx_set_framebuffer(int fb, float noise_scale) ; void gfx_reset_framebuffer(void); diff --git a/port/fast3d/gfx_pc.cpp b/port/fast3d/gfx_pc.cpp index a1ebe4ec1..9193c2d47 100644 --- a/port/fast3d/gfx_pc.cpp +++ b/port/fast3d/gfx_pc.cpp @@ -558,9 +558,16 @@ static bool gfx_texture_cache_lookup(int i, const TextureCacheKey& key) { return false; } -static void gfx_texture_cache_delete(const uint8_t* orig_addr) { +void gfx_texture_cache_delete(const uint8_t* orig_addr) { gfx_flush(); - rdp.textures_changed[0] = rdp.textures_changed[1] = true; + + for (int i = 0; i < 2; ++i) { + if (rendering_state.textures[i] && rendering_state.textures[i]->first.texture_addr == orig_addr) { + rdp.textures_changed[i] = true; + rendering_state.textures[i] = nullptr; + } + } + while (gfx_texture_cache.map.bucket_count() > 0) { TextureCacheKey key = { orig_addr, { 0 }, 0, 0 }; // bucket index only depends on the address size_t bucket = gfx_texture_cache.map.bucket(key); diff --git a/port/include/video.h b/port/include/video.h index 09335e954..4f6f814c0 100644 --- a/port/include/video.h +++ b/port/include/video.h @@ -29,5 +29,6 @@ void videoResetFramebuffer(void); void videoCopyFramebuffer(s32 dst, s32 src, s32 left, s32 top); void videoResetTextureCache(void); +void videoFreeCachedTexture(const void *texptr); #endif diff --git a/port/src/video.c b/port/src/video.c index 80f353ca3..ae1612f58 100644 --- a/port/src/video.c +++ b/port/src/video.c @@ -172,3 +172,8 @@ void videoResetTextureCache(void) { gfx_texture_cache_clear(); } + +void videoFreeCachedTexture(const void *texptr) +{ + gfx_texture_cache_delete(texptr); +} diff --git a/src/game/lang.c b/src/game/lang.c index 5762cc39d..b2e595371 100644 --- a/src/game/lang.c +++ b/src/game/lang.c @@ -10,6 +10,9 @@ #include "data.h" #include "types.h" #include "platform.h" +#ifndef PLATFORM_N64 +#include "video.h" +#endif /** * Officially, the NTSC versions are American English only, while the PAL @@ -293,6 +296,11 @@ struct jpncharpixels *langGetJpnCharPixels(s32 codepoint) (romptr_t) REF_SEG _fontjpnSegmentRomStart + ((codepoint * TMUL) * 0xc + TMUL * (24 * 0xc)), TMUL * 0x0c); +#ifndef PLATFORM_N64 + // indicate that this is a new texture + videoFreeCachedTexture(&g_JpnCharCachePixels[TMUL * freeindexsingle]); +#endif + return &g_JpnCharCachePixels[TMUL * freeindexsingle]; } @@ -313,6 +321,11 @@ struct jpncharpixels *langGetJpnCharPixels(s32 codepoint) dmaExec(&g_JpnCharCachePixels[freeindexsingle * 8], (romptr_t) REF_SEG _fontjpnsingleSegmentRomStart + (codepoint >> SHIFTAMOUNT) * 0x60, 0x60); +#ifndef PLATFORM_N64 + // indicate that this is a new texture + videoFreeCachedTexture(&g_JpnCharCachePixels[freeindexsingle * 8]); +#endif + return &g_JpnCharCachePixels[freeindexsingle * 8]; } @@ -324,6 +337,11 @@ struct jpncharpixels *langGetJpnCharPixels(s32 codepoint) dmaExec(&g_JpnCharCachePixels[freeindexmulti * 8], (romptr_t) REF_SEG _fontjpnmultiSegmentRomStart + ((codepoint & 0x1fff) >> SHIFTAMOUNT) * 0x80, 0x80); +#ifndef PLATFORM_N64 + // indicate that this is a new texture + videoFreeCachedTexture(&g_JpnCharCachePixels[freeindexmulti * 8]); +#endif + return &g_JpnCharCachePixels[freeindexmulti * 8]; }