Added check if twl wram is unlocked

This commit is contained in:
Gericom 2022-10-01 11:57:51 +02:00
parent d0ea2b603e
commit 15d28caed1
7 changed files with 53 additions and 9 deletions

View File

@ -5,6 +5,7 @@
#include "fat.h"
#include "adpcm.h"
#include "irqWait.h"
#include "../../common/twlwram.h"
#include "fvPlayer7.h"
#define FV_AUDIO_START_OFFSET 12
@ -324,8 +325,13 @@ static void handleFifo(u32 value)
}
case IPC_CMD_HANDSHAKE:
fifoSendValue32(FIFO_USER_01, IPC_CMD_PACK(IPC_CMD_HANDSHAKE, 0));
{
bool canUseWram = false;
if (isDSiMode())
canUseWram = twr_isUnlocked();
fifoSendValue32(FIFO_USER_01, IPC_CMD_PACK(IPC_CMD_HANDSHAKE, canUseWram ? 1 : 0));
break;
}
}
}

View File

@ -114,8 +114,14 @@ int main(void)
if (isDSiMode())
{
twr_setBlockMapping(TWR_WRAM_BLOCK_B, 0x03100000, 0x40000, TWR_WRAM_BLOCK_IMAGE_SIZE_256K);
twr_setBlockMapping(TWR_WRAM_BLOCK_C, 0x03140000, 0x40000, TWR_WRAM_BLOCK_IMAGE_SIZE_256K);
if (twr_isUnlockable())
twr_unlockAll();
if (twr_isUnlocked())
{
twr_setBlockMapping(TWR_WRAM_BLOCK_B, 0x03100000, 0x40000, TWR_WRAM_BLOCK_IMAGE_SIZE_256K);
twr_setBlockMapping(TWR_WRAM_BLOCK_C, 0x03140000, 0x40000, TWR_WRAM_BLOCK_IMAGE_SIZE_256K);
}
// switch to 47kHz output
REG_SNDEXTCNT = 0;

View File

@ -199,10 +199,10 @@ static u32* makeMbRenderDl(u32* displayList, int height, u32 texParam)
return displayList;
}
bool fv_initPlayer(fv_player_t* player, const char* filePath)
bool fv_initPlayer(fv_player_t* player, const char* filePath, bool useWram)
{
memset(player, 0, sizeof(fv_player_t));
if (isDSiMode())
if (isDSiMode() && twr_isUnlocked() && useWram)
player->dataBuffer = (u8*)twr_getBlockAddress(TWR_WRAM_BLOCK_B);
else
player->dataBuffer = memalign(32, FV_PLAYER_DATA_BUFFER_SIZE * FV_PLAYER_DATA_BUFFER_COUNT);

View File

@ -46,7 +46,7 @@ typedef struct
extern "C" {
#endif
bool fv_initPlayer(fv_player_t* player, const char* filePath);
bool fv_initPlayer(fv_player_t* player, const char* filePath, bool useWram);
void fv_destroyPlayer(fv_player_t* player);
void fv_startPlayer(fv_player_t* player);
void fv_updatePlayer(fv_player_t* player);

View File

@ -20,12 +20,14 @@ int main(int argc, char** argv)
mpu_enableVramCache();
if (isDSiMode())
bool canUseWram = false;
if (isDSiMode() && twr_isUnlocked())
{
twr_setBlockMapping(TWR_WRAM_BLOCK_A, 0x03000000, 0x40000, TWR_WRAM_BLOCK_IMAGE_SIZE_256K);
twr_setBlockMapping(TWR_WRAM_BLOCK_B, 0x03100000, 0x40000, TWR_WRAM_BLOCK_IMAGE_SIZE_256K);
twr_setBlockMapping(TWR_WRAM_BLOCK_C, 0x03140000, 0x40000, TWR_WRAM_BLOCK_IMAGE_SIZE_256K);
mpu_enableTwlWramCache();
canUseWram = true;
}
fifoSetValue32Handler(FIFO_USER_01, NULL, NULL);
@ -33,7 +35,10 @@ int main(int argc, char** argv)
// handshake
fifoSendValue32(FIFO_USER_01, IPC_CMD_PACK(IPC_CMD_HANDSHAKE, 0));
fifoWaitValue32(FIFO_USER_01);
fifoGetValue32(FIFO_USER_01);
u32 handShake = fifoGetValue32(FIFO_USER_01);
if (canUseWram && (handShake & IPC_CMD_ARG_MASK) == 0)
canUseWram = false;
if (!isDSiMode())
{
@ -72,7 +77,7 @@ int main(int argc, char** argv)
filePath = argv[1];
// iprintf("Playing %s\n", filePath);
if (fv_initPlayer(&sPlayer, filePath))
if (fv_initPlayer(&sPlayer, filePath, canUseWram))
{
sPlayerController = new PlayerController(&sPlayer);
sPlayerController->Initialize();

View File

@ -93,6 +93,22 @@ void twr_mapWramCSlot(int slot, TWRWramCSlotMaster master, int offset, bool enab
#endif
bool twr_isUnlocked(void);
#ifdef ARM7
static inline bool twr_isUnlockable(void)
{
return (REG_SCFG_EXT & 0x80000000) != 0;
}
static inline void twr_unlockAll(void)
{
REG_MBK9 = 0;
}
#endif
#ifdef __cplusplus
}
#endif

View File

@ -66,3 +66,14 @@ void twr_mapWramCSlot(int slot, TWRWramCSlotMaster master, int offset, bool enab
}
#endif
bool twr_isUnlocked(void)
{
if ((REG_SCFG_EXT & 0x80000000) == 0)
return false; // SCFG and MBK registers are permanently locked
if ((REG_MBK9 & 0xFFFF0F) != 0)
return false; // One or more MBK registers are locked
return true;
}