Skip to content

Commit

Permalink
Only restore shadow regs on bmp->text transition, added general patch…
Browse files Browse the repository at this point in the history
… for sound mixer used in many games
  • Loading branch information
Gericom committed Jul 7, 2019
1 parent 53b7cce commit 916020e
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 75 deletions.
6 changes: 6 additions & 0 deletions arm9/source/emu/gfx.s
Expand Up @@ -72,6 +72,8 @@ write_address_dispcontrol_cont:

bicge r12, #0xB00 //clear all bg bits except bg2

ldr r10, [r9]

str r12, [r9]

//move gba vram block b to either bg or obj
Expand All @@ -89,6 +91,10 @@ write_address_dispcontrol_cont:

bge 1f

and r10, #7
cmp r10, #5
bxne lr //only if the previous mode was bitmap restore the shadow registers

//restore the bg2cnt register if not bitmap mode
ldr r13,= BG2CNT_copy
ldrh r12, [r13]
Expand Down
4 changes: 3 additions & 1 deletion arm9/source/gamePatches.h
@@ -1,3 +1,5 @@
#pragma once

void gptc_patchRom();
void gptc_patchRom();

u32* gptc_findSignature(const u8* signature);
55 changes: 27 additions & 28 deletions arm9/source/gamePatches.vram.cpp
Expand Up @@ -2,33 +2,20 @@
#include "sd_access.h"
#include "gamePatches.h"

static const u8 sSomeBuggedMixer[16] =
{0xF0, 0x1F, 0x2D, 0xE9, 0x0F, 0x00, 0xB0, 0xE8, 0x03, 0x32, 0xA0, 0xE1, 0x01, 0x20, 0x82, 0xE0};

void gptc_patchRom()
{
//fix a soundmixer that has ldm with writeback and rb in rlist
u32* buggedMixer = gptc_findSignature(sSomeBuggedMixer);
if (buggedMixer)
buggedMixer[1] = 0xE890000F;

u32 gameTitle0 = *(u32*)(MAIN_MEMORY_ADDRESS_ROM_DATA + 0xA0);
u32 gameTitle1 = *(u32*)(MAIN_MEMORY_ADDRESS_ROM_DATA + 0xA4);
u32 gameTitle2 = *(u32*)(MAIN_MEMORY_ADDRESS_ROM_DATA + 0xA8);
u32 gameCode = *(u32*)(MAIN_MEMORY_ADDRESS_ROM_DATA + 0xAC);
if (gameTitle0 == 0x49424942 && gameTitle1 == 0x414E4954 && gameTitle2 == 0x00003130 && gameCode == 0x44585542)
{
//Bibi und Tina - Ferien auf dem Martinshof (Germany)
//Sound fix, by removing writeback from ldm
if (*(u32*)(MAIN_MEMORY_ADDRESS_ROM_DATA + 0x12D9F4) == 0xE8B0000F)
*(u32*)(MAIN_MEMORY_ADDRESS_ROM_DATA + 0x12D9F4) = 0xE890000F;
}
else if (gameTitle0 == 0x53524143 && gameTitle1 == 0x4554414D && gameTitle2 == 0x54414E52 && gameCode == 0x50504342)
{
//Cars - Mater-National Championship (Europe) (En,Fr,De,Es,It,Nl)
//Sound fix, by removing writeback from ldm
if (*(u32*)(MAIN_MEMORY_ADDRESS_ROM_DATA + 0xB664) == 0xE8B0000F)
*(u32*)(MAIN_MEMORY_ADDRESS_ROM_DATA + 0xB664) = 0xE890000F;
}
else if (gameTitle0 == 0x53524143 && gameTitle1 == 0x4554414D && gameTitle2 == 0x00000052 && gameCode == 0x45504342)
{
//Cars - Mater-National Championship (USA) (En,Fr)
//Sound fix, by removing writeback from ldm
if (*(u32*)(MAIN_MEMORY_ADDRESS_ROM_DATA + 0xB664) == 0xE8B0000F)
*(u32*)(MAIN_MEMORY_ADDRESS_ROM_DATA + 0xB664) = 0xE890000F;
}
/*else if (gameTitle0 == 0x4C415256 && gameTitle1 == 0x3320594C && gameTitle2 == 0x00000000 && gameCode == 0x45525641)
{
//V-Rally 3 (USA) (En,Fr,Es)
Expand All @@ -45,13 +32,6 @@ void gptc_patchRom()
if (*(u32*)(MAIN_MEMORY_ADDRESS_ROM_DATA + 0x1FC71C) == 0xE8B2001C)
*(u32*)(MAIN_MEMORY_ADDRESS_ROM_DATA + 0x1FC71C) = 0xE892001C;
}*/
else if (gameTitle0 == 0x4159414D && gameTitle1 == 0x45485420 && gameTitle2 == 0x45454220 && gameCode == 0x50454542)
{
//Maya the Bee - Sweet Gold (Europe) (En,Fr,De,Es,It)
//remove writeback from ldm
if (*(u32*)(MAIN_MEMORY_ADDRESS_ROM_DATA + 0x1D0F4) == 0xE8B0000F)
*(u32*)(MAIN_MEMORY_ADDRESS_ROM_DATA + 0x1D0F4) = 0xE890000F;
}
/*else if(gameTitle0 == 0x4E534944 && gameTitle1 == 0x4F565945 && gameTitle2 == 0x3130304C && gameCode == 0x4543444D)
{
//Game Boy Advance Video - Disney Channel Collection - Volume 1 (USA)
Expand All @@ -61,3 +41,22 @@ void gptc_patchRom()
*(u32*)(MAIN_MEMORY_ADDRESS_ROM_DATA + 0xCF4) = 0x9D;
}*/
}

u32* gptc_findSignature(const u8* signature)
{
u32* pRom = (u32*)MAIN_MEMORY_ADDRESS_ROM_DATA;
bool found = false;
for (int i = 0; i < ROM_DATA_LENGTH; i += 4)
{
if (pRom[0] == ((u32*)signature)[0] && pRom[1] == ((u32*)signature)[1] &&
pRom[2] == ((u32*)signature)[2] && pRom[3] == ((u32*)signature)[3])
{
found = true;
break;
}
pRom++;
}
if (!found)
return NULL;
return pRom;
}
17 changes: 9 additions & 8 deletions arm9/source/save/EepromSave.vram.cpp
@@ -1,5 +1,6 @@
#include "vram.h"
#include "sd_access.h"
#include "gamePatches.h"
#include "Save.h"
#include "EepromSave.h"

Expand Down Expand Up @@ -57,12 +58,12 @@ GBA_INTERWORK_BRIDGE(programEepromDword)

bool eeprom_patchV111(const save_type_t* type)
{
u32* readFunc = save_findSignature(sReadEepromDwordV111Sig);
u32* readFunc = gptc_findSignature(sReadEepromDwordV111Sig);
if (!readFunc)
return false;
save_injectJump(readFunc, (void*)readEepromDword);

u32* progFunc = save_findSignature(sProgramEepromDwordV111Sig);
u32* progFunc = gptc_findSignature(sProgramEepromDwordV111Sig);
if (!progFunc)
return false;
save_injectJump(progFunc, (void*)programEepromDword);
Expand All @@ -71,12 +72,12 @@ bool eeprom_patchV111(const save_type_t* type)

bool eeprom_patchV120(const save_type_t* type)
{
u32* readFunc = save_findSignature(sReadEepromDwordV120Sig);
u32* readFunc = gptc_findSignature(sReadEepromDwordV120Sig);
if (!readFunc)
return false;
save_injectJump(readFunc, (void*)readEepromDword);

u32* progFunc = save_findSignature(sProgramEepromDwordV120Sig);
u32* progFunc = gptc_findSignature(sProgramEepromDwordV120Sig);
if (!progFunc)
return false;
save_injectJump(progFunc, (void*)programEepromDword);
Expand All @@ -85,12 +86,12 @@ bool eeprom_patchV120(const save_type_t* type)

bool eeprom_patchV124(const save_type_t* type)
{
u32* readFunc = save_findSignature(sReadEepromDwordV120Sig);
u32* readFunc = gptc_findSignature(sReadEepromDwordV120Sig);
if (!readFunc)
return false;
save_injectJump(readFunc, (void*)readEepromDword);

u32* progFunc = save_findSignature(sProgramEepromDwordV124Sig);
u32* progFunc = gptc_findSignature(sProgramEepromDwordV124Sig);
if (!progFunc)
return false;
save_injectJump(progFunc, (void*)programEepromDword);
Expand All @@ -99,12 +100,12 @@ bool eeprom_patchV124(const save_type_t* type)

bool eeprom_patchV126(const save_type_t* type)
{
u32* readFunc = save_findSignature(sReadEepromDwordV120Sig);
u32* readFunc = gptc_findSignature(sReadEepromDwordV120Sig);
if (!readFunc)
return false;
save_injectJump(readFunc, (void*)readEepromDword);

u32* progFunc = save_findSignature(sProgramEepromDwordV126Sig);
u32* progFunc = gptc_findSignature(sProgramEepromDwordV126Sig);
if (!progFunc)
return false;
save_injectJump(progFunc, (void*)programEepromDword);
Expand Down
25 changes: 13 additions & 12 deletions arm9/source/save/FlashSave.vram.cpp
@@ -1,5 +1,6 @@
#include "vram.h"
#include "sd_access.h"
#include "gamePatches.h"
#include "Save.h"
#include "FlashSave.h"

Expand Down Expand Up @@ -257,7 +258,7 @@ bool flash_patchV120(const save_type_t* type)
if (!loadDataV120(type))
return false;

u32* pIdentify = save_findSignature(sIdentifyFlashV120Sig);
u32* pIdentify = gptc_findSignature(sIdentifyFlashV120Sig);
if (!pIdentify)
return false;

Expand All @@ -276,7 +277,7 @@ bool flash_patchV123(const save_type_t* type)
if (!loadDataV120(type))
return false;

u32* pIdentify = save_findSignature(sIdentifyFlashV123Sig);
u32* pIdentify = gptc_findSignature(sIdentifyFlashV123Sig);
if (!pIdentify)
return false;

Expand All @@ -295,7 +296,7 @@ bool flash_patchV126(const save_type_t* type)
if (!loadDataV120(type))
return false;

u32* pIdentify = save_findSignature(sIdentifyFlashV123Sig);
u32* pIdentify = gptc_findSignature(sIdentifyFlashV123Sig);
if (!pIdentify)
return false;

Expand All @@ -307,7 +308,7 @@ bool flash_patchV126(const save_type_t* type)
save_injectJump((u32*)((*(u32*)(vram_cd->tmpSector + FLASH_V120_OFFSET_VERIFY_SECTOR) & ~1) - 0x08000000 +
MAIN_MEMORY_ADDRESS_ROM_DATA), (void*)verifyFlashSector);

u32* verify = save_findSignature(sVerifyFlashV126Sig);
u32* verify = gptc_findSignature(sVerifyFlashV126Sig);
if (!verify)
return false;
save_injectJump(verify, (void*)verifyFlash);
Expand All @@ -329,23 +330,23 @@ bool flash_patch512V130(const save_type_t* type)
sPatchInfo.flMaxTimePtr = *(u32**)(vram_cd->tmpSector + FLASH_512V130_OFFSET_FL_MAXTIME);
sPatchInfo.flashPtr = *(u32**)(vram_cd->tmpSector + FLASH_512V130_OFFSET_FLASH);

u32* pIdentify = save_findSignature(sIdentifyFlashV123Sig);
u32* pIdentify = gptc_findSignature(sIdentifyFlashV123Sig);
if (!pIdentify)
return false;

save_injectJump(pIdentify, (void*)identifyFlash512);

u32* readFunc = save_findSignature(sReadFlash512V130Sig);
u32* readFunc = gptc_findSignature(sReadFlash512V130Sig);
if (!readFunc)
return false;
save_injectJump(readFunc, (void*)readFlash);

u32* verifySector = save_findSignature(sVerifyFlashSector512V130Sig);
u32* verifySector = gptc_findSignature(sVerifyFlashSector512V130Sig);
if (!verifySector)
return false;
save_injectJump(verifySector, (void*)verifyFlashSector);

u32* verify = save_findSignature(sVerifyFlash512V130Sig);
u32* verify = gptc_findSignature(sVerifyFlash512V130Sig);
if (!verify)
return false;
save_injectJump(verify, (void*)verifyFlash);
Expand All @@ -369,23 +370,23 @@ bool flash_patch1MV102(const save_type_t* type)
sPatchInfo.flashPtr = *(u32**)(vram_cd->tmpSector + FLASH_1MV102_OFFSET_FLASH + (
type->type == SAVE_TYPE_FLASH1M_V102 ? 0 : 4));

u32* pIdentify = save_findSignature(type->type == SAVE_TYPE_FLASH1M_V102 ? sIdentifyFlashV123Sig : sIdentifyFlash1MV103Sig);
u32* pIdentify = gptc_findSignature(type->type == SAVE_TYPE_FLASH1M_V102 ? sIdentifyFlashV123Sig : sIdentifyFlash1MV103Sig);
if (!pIdentify)
return false;

save_injectJump(pIdentify, (void*)identifyFlash1M);

u32* readFunc = save_findSignature(sReadFlash512V130Sig);
u32* readFunc = gptc_findSignature(sReadFlash512V130Sig);
if (!readFunc)
return false;
save_injectJump(readFunc, (void*)readFlash);

u32* verifySector = save_findSignature(sVerifyFlashSector512V130Sig);
u32* verifySector = gptc_findSignature(sVerifyFlashSector512V130Sig);
if (!verifySector)
return false;
save_injectJump(verifySector, (void*)verifyFlashSector);

u32* verify = save_findSignature(sVerifyFlash512V130Sig);
u32* verify = gptc_findSignature(sVerifyFlash512V130Sig);
if (!verify)
return false;
save_injectJump(verify, (void*)verifyFlash);
Expand Down
1 change: 0 additions & 1 deletion arm9/source/save/Save.h
Expand Up @@ -62,5 +62,4 @@ struct save_type_t
}

const save_type_t* save_findTag();
u32* save_findSignature(const u8* signature);
void save_injectJump(u32* location, void* jumpTarget);
19 changes: 0 additions & 19 deletions arm9/source/save/Save.vram.cpp
Expand Up @@ -108,25 +108,6 @@ const save_type_t* save_findTag()
return NULL;
}

u32* save_findSignature(const u8* signature)
{
u32* pRom = (u32*)MAIN_MEMORY_ADDRESS_ROM_DATA;
bool found = false;
for (int i = 0; i < ROM_DATA_LENGTH; i += 4)
{
if (pRom[0] == ((u32*)signature)[0] && pRom[1] == ((u32*)signature)[1] &&
pRom[2] == ((u32*)signature)[2] && pRom[3] == ((u32*)signature)[3])
{
found = true;
break;
}
pRom++;
}
if (!found)
return NULL;
return pRom;
}

void save_injectJump(u32* location, void* jumpTarget)
{
if (((u32)location & 2) != 0)
Expand Down
13 changes: 7 additions & 6 deletions arm9/source/save/SramSave.vram.cpp
@@ -1,5 +1,6 @@
#include "vram.h"
#include "sd_access.h"
#include "gamePatches.h"
#include "Save.h"
#include "SramSave.h"

Expand Down Expand Up @@ -54,17 +55,17 @@ GBA_INTERWORK_BRIDGE(verifySram)

bool sram_patchV110(const save_type_t* type)
{
u32* readFunc = save_findSignature(sReadSramV110Sig);
u32* readFunc = gptc_findSignature(sReadSramV110Sig);
if (!readFunc)
return false;
save_injectJump(readFunc, (void*)readSram);

u32* writeFunc = save_findSignature(sWriteSramV110Sig);
u32* writeFunc = gptc_findSignature(sWriteSramV110Sig);
if (!writeFunc)
return false;
save_injectJump(writeFunc, (void*)writeSram);

u32* verifyFunc = save_findSignature(sVerifySramV110Sig);
u32* verifyFunc = gptc_findSignature(sVerifySramV110Sig);
if (!verifyFunc)
return false;
save_injectJump(verifyFunc, (void*)verifySram);
Expand All @@ -73,17 +74,17 @@ bool sram_patchV110(const save_type_t* type)

bool sram_patchV111(const save_type_t* type)
{
u32* readFunc = save_findSignature(sReadSramV111Sig);
u32* readFunc = gptc_findSignature(sReadSramV111Sig);
if (!readFunc)
return false;
save_injectJump(readFunc, (void*)readSram);

u32* writeFunc = save_findSignature(sWriteSramV111Sig);
u32* writeFunc = gptc_findSignature(sWriteSramV111Sig);
if (!writeFunc)
return false;
save_injectJump(writeFunc, (void*)writeSram);

u32* verifyFunc = save_findSignature(sVerifySramV111Sig);
u32* verifyFunc = gptc_findSignature(sVerifySramV111Sig);
if (!verifyFunc)
return false;
save_injectJump(verifyFunc, (void*)verifySram);
Expand Down

0 comments on commit 916020e

Please sign in to comment.