Skip to content

Commit

Permalink
Merge pull request #155 from dshadoff/PCE_fix_HuCard_BRAM_protection
Browse files Browse the repository at this point in the history
Default behaviour for BRAM should be 'locked' at startup; this is currently correct for CDROM games, but not for HuCard games.

This means that memory at physical address $1EE000 should be all $FF values (as seen by the Physical Memory debug screen), but the BRAM memory editor screen should show the BRAM properly.
  • Loading branch information
pceDev16 authored Apr 13, 2024
2 parents 7edc9b2 + 4edf275 commit 3a78525
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions mednafen/src/pce/huc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static DECLFR(SaveRAMRead)
if(BRAM_Disabled)
return(0xFF);

if((!PCE_IsCD || PCECD_IsBRAMEnabled()) && (A & 8191) < 2048)
if((PCE_IsBRAMEnabled()) && (A & 8191) < 2048)
return(SaveRAM[A & 2047]);
else
return(0xFF);
Expand All @@ -145,7 +145,7 @@ static DECLFW(SaveRAMWrite)
if(BRAM_Disabled)
return;

if((!PCE_IsCD || PCECD_IsBRAMEnabled()) && (A & 8191) < 2048)
if((PCE_IsBRAMEnabled()) && (A & 8191) < 2048)
SaveRAM[A & 2047] = V;
}

Expand Down
15 changes: 15 additions & 0 deletions mednafen/src/pce/pce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ static bool SetSoundRate(double rate);
static void Cleanup(void);

bool PCE_ACEnabled;
bool bBRAMEnabled;
uint32 PCE_InDebug = 0;
uint64 PCE_TimestampBase; // Only used with the debugger for the time being.

Expand Down Expand Up @@ -174,6 +175,9 @@ static DECLFR(IORead)
case 0x1800: if(IsTsushin)
return(PCE_TsushinRead(A));

if (((A & 0x1fff) == 0x1803) && (!PCE_InDebug))
bBRAMEnabled = false;

if(!PCE_IsCD)
break;
if((A & 0x1E00) == 0x1A00)
Expand Down Expand Up @@ -240,6 +244,9 @@ static DECLFW(IOWrite)
case 0x1800: if(IsTsushin)
PCE_TsushinWrite(A & 0x1FFF, V);

if ((A & 0x1fff) == 0x1807) // $1807: D7=1 enables backup ram
bBRAMEnabled = (V & 0x80) ? true : false;

if(!PCE_IsCD)
{
if(!PCE_InDebug)
Expand Down Expand Up @@ -1004,6 +1011,7 @@ static void StateAction(StateMem *sm, const unsigned load, const bool data_only)
{
SFPTR8(BaseRAM, IsSGX? 32768 : 8192),
SFVAR(PCE_TimestampBase),
SFVAR(bBRAMEnabled),

SFEND
};
Expand Down Expand Up @@ -1048,6 +1056,8 @@ void PCE_Power(void)

PCEINPUT_Power(timestamp);

bBRAMEnabled = false;

if(PCE_IsCD)
{
vce->SetCDEvent(PCECD_Power(timestamp));
Expand All @@ -1071,6 +1081,11 @@ static void SetMedia(uint32 drive_idx, uint32 state_idx, uint32 media_idx, uint3
}
}

bool PCE_IsBRAMEnabled()
{
return bBRAMEnabled;
}

static void DoSimpleCommand(int cmd)
{
switch(cmd)
Expand Down
2 changes: 2 additions & 0 deletions mednafen/src/pce/pce.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ MDFN_HIDE extern uint32 PCE_InDebug;
MDFN_HIDE extern bool PCE_ACEnabled; // Arcade Card emulation enabled?
void PCE_Power(void);

bool PCE_IsBRAMEnabled(void);

uint8 PCE_PeekMainRAM(uint32 A);
void PCE_PokeMainRAM(uint32 A, uint8 V);

Expand Down
16 changes: 2 additions & 14 deletions mednafen/src/pce/pcecd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ static bool ADPCMExtraPrecision;
//static bool ADPCMFancyLP; // Commented out, not really a worthwhile feature IMO(sound effects don't sound right without the extra spectrum duplicates).


static bool bBRAMEnabled;
static uint8 _Port[15];
static uint8 ACKStatus;

Expand Down Expand Up @@ -490,7 +489,6 @@ int32 PCECD_Power(uint32 timestamp)
SCSICD_Power(timestamp);
scsicd_ne = 0x7fffffff;

bBRAMEnabled = false;
memset(_Port, 0, sizeof(_Port));
ACKStatus = 0;
ClearACKDelay = 0;
Expand Down Expand Up @@ -530,11 +528,6 @@ int32 PCECD_Power(uint32 timestamp)
return(CalcNextEvent(0x7FFFFFFF));
}

bool PCECD_IsBRAMEnabled()
{
return bBRAMEnabled;
}

MDFN_FASTCALL uint8 PCECD_Read(uint32 timestamp, uint32 A, int32 &next_event, const bool PeekMode)
{
uint8 ret = 0;
Expand Down Expand Up @@ -573,9 +566,7 @@ MDFN_FASTCALL uint8 PCECD_Read(uint32 timestamp, uint32 A, int32 &next_event, co
case 0x2: ret = _Port[2];
break;

case 0x3: if(!PeekMode)
bBRAMEnabled = false;

case 0x3:
/* switch left/right of digitized cd playback */
ret = _Port[0x3];
if(!PeekMode)
Expand Down Expand Up @@ -760,9 +751,7 @@ MDFN_FASTCALL int32 PCECD_Write(uint32 timestamp, uint32 physAddr, uint8 data)
}
break;

case 0x7: // $1807: D7=1 enables backup ram

bBRAMEnabled = (data & 0x80) ? true : false;
case 0x7:
break;

case 0x8: // Set ADPCM address low
Expand Down Expand Up @@ -1374,7 +1363,6 @@ void PCECD_StateAction(StateMem *sm, const unsigned load, const bool data_only)
{
SFORMAT StateRegs[] =
{
SFVAR(bBRAMEnabled),
SFVAR(ACKStatus),
SFVAR(ClearACKDelay),
SFVAR(RawPCMVolumeCache),
Expand Down
2 changes: 0 additions & 2 deletions mednafen/src/pce/pcecd.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ int32 PCECD_Power(uint32 timestamp);
MDFN_FASTCALL uint8 PCECD_Read(uint32 timestamp, uint32, int32 &next_event, const bool PeekMode = false);
MDFN_FASTCALL int32 PCECD_Write(uint32 timestamp, uint32, uint8 data) MDFN_WARN_UNUSED_RESULT;

bool PCECD_IsBRAMEnabled();

void PCECD_StateAction(StateMem *sm, const unsigned load, const bool data_only);

void ADPCM_PeekRAM(uint32 Address, uint32 Length, uint8 *Buffer);
Expand Down

0 comments on commit 3a78525

Please sign in to comment.