Musashi context is now cleared in M68KCtx constructor. The internal Musashi context is zeroed out initially but the dynamically allocated external contexts would sometimes be filled with garbage, which would trigger interrupts at the very first instruction after reset, making the 68K go off into the weeds. This fixes a nasty randomly-occurring bug I was seeing.

This commit is contained in:
Bart Trzynadlowski 2011-08-14 23:59:01 +00:00
parent 4e7b7cc59b
commit 6c5b4293eb
5 changed files with 15 additions and 3 deletions

View file

@ -32,6 +32,7 @@
#ifndef INCLUDED_68K_H
#define INCLUDED_68K_H
#include <cstring>
#include "Types.h"
#include "Musashi/m68k.h"
#include "CPU/Bus.h"
@ -75,6 +76,7 @@ public:
Bus = NULL;
IRQAck = NULL;
musashiCtx = new unsigned char[m68k_context_size()];
memset(musashiCtx, 0, m68k_context_size()); // very important! garbage in context at reset can cause very strange bugs
}
~SM68KCtx(void)

View file

@ -26,6 +26,10 @@
*
* Permission was obtained from Karl Stenerud to apply the GPL license to this
* code.
*
* NOTE: The internal CPU context is initialized to all zeros here. If setting
* an external context for the first time, make sure it is cleared first,
* otherwise interrupts may appear pending and other nasty problems.
*/
/* ======================================================================== */

View file

@ -1,4 +1,3 @@
//TODO: DSB2 save states not working!
//TODO: amp can print error messages -- change them to Supermodel error messages
/**
** Supermodel
@ -950,6 +949,7 @@ void CDSB2::RunFrame(INT16 *audioL, INT16 *audioR)
{
#ifdef SUPERMODEL_SOUND
M68KSetContext(&M68K);
//printf("DSB2 run frame PC=%06X\n", M68KGetPC());
// While FIFO not empty...
while (fifoIdxR != fifoIdxW)
@ -995,6 +995,7 @@ void CDSB2::Reset(void)
M68KSetContext(&M68K);
M68KReset();
printf("DSB2 PC=%06X\n", M68KGetPC());
M68KGetContext(&M68K);
DebugLog("DSB2 Reset\n");

View file

@ -394,10 +394,15 @@ void CSoundBoard::Reset(void)
UpdateROMBanks();
M68KSetContext(&M68K);
M68KReset();
printf("SBrd PC=%06X\n", M68KGetPC());
M68KGetContext(&M68K);
if (NULL != DSB)
DSB->Reset();
DebugLog("Sound Board Reset\n");
printf("PC=%06X\n", M68KGetPC());
M68KSetContext(&M68K);
M68KGetContext(&M68K);
printf("PC=%06X\n", M68KGetPC());
}
void CSoundBoard::SaveState(CBlockFile *SaveState)
@ -453,7 +458,7 @@ void CSoundBoard::AttachDSB(CDSB *DSBPtr)
#define OFFSET_RAM2 (0x100000) // 1 MB SCSP2 RAM
#define OFFSET_AUDIO_LEFT (0x200000) // 1470 bytes (16 bits, 44.1 KHz, 1/60th second) left audio channel
#define OFFSET_AUDIO_RIGHT (0x2005BE) // 1470 bytes right audio channel
#define MEMORY_POOL_SIZE (0x100000 + 0x100000 + 0x5be + 0x5be)
#define MEMORY_POOL_SIZE (0x100000+0x100000+0x5be+0x5be)
BOOL CSoundBoard::Init(const UINT8 *soundROMPtr, const UINT8 *sampleROMPtr)
{