diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/BPMemLoader.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/BPMemLoader.cpp index 95ec555181..3db8c5d493 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/BPMemLoader.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/BPMemLoader.cpp @@ -111,7 +111,25 @@ void SWBPWritten(int address, int newvalue) PanicAlert("Invalid palette pointer %08x %08x %08x", bpmem.tmem_config.tlut_src, bpmem.tmem_config.tlut_src << 5, (bpmem.tmem_config.tlut_src & 0xFFFFF)<< 5); break; } - + + case BPMEM_PRELOAD_MODE: + if (newvalue != 0) + { + // NOTE(neobrain): Apparently tmemodd doesn't affect hardware behavior at all (libogc uses it just as a buffe$ + BPS_TmemConfig& tmem_cfg = bpmem.tmem_config; + u8* ram_ptr = Memory::GetPointer(tmem_cfg.preload_addr << 5); + u32 tmem_addr = tmem_cfg.preload_tmem_even * TMEM_LINE_SIZE; + u32 size = tmem_cfg.preload_tile_info.count * 32; + + // Check if the game has overflowed TMEM, and copy up to the limit. + // Paper Mario does this when entering the Great Boogly Tree (Chap 2) + if ((tmem_addr + size) > TMEM_SIZE) + size = TMEM_SIZE - tmem_addr; + + memcpy(texMem + tmem_addr, ram_ptr, size); + } + break; + case BPMEM_TEV_REGISTER_L: // Reg 1 case BPMEM_TEV_REGISTER_L+2: // Reg 2 case BPMEM_TEV_REGISTER_L+4: // Reg 3 diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/TextureSampler.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/TextureSampler.cpp index cd984b987b..66b6b68e22 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/TextureSampler.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/TextureSampler.cpp @@ -120,8 +120,16 @@ void SampleMip(s32 s, s32 t, s32 mip, bool linear, u8 texmap, u8 *sample) TexImage0& ti0 = texUnit.texImage0[subTexmap]; TexTLUT& texTlut = texUnit.texTlut[subTexmap]; - u32 imageBase = texUnit.texImage3[subTexmap].image_base << 5; - u8 *imageSrc = Memory::GetPointer(imageBase); + u8 *imageSrc; + if (texUnit.texImage1[subTexmap].image_type) + { + imageSrc = &texMem[texUnit.texImage1[subTexmap].tmem_even * TMEM_LINE_SIZE]; + } + else + { + u32 imageBase = texUnit.texImage3[subTexmap].image_base << 5; + imageSrc = Memory::GetPointer(imageBase); + } int imageWidth = ti0.width; int imageHeight = ti0.height;