More work on fixNES integration

This commit is contained in:
Jack Andersen 2018-06-18 10:12:40 -10:00
parent 56b1e562ce
commit 9f1e6736b2
5 changed files with 1442 additions and 13 deletions

View File

@ -133,6 +133,7 @@ bool emuSkipFrame = false;
extern bool fdsSwitch; extern bool fdsSwitch;
bool apuCycleURDE(); bool apuCycleURDE();
uint32_t apuGetMaxBufSize();
uint8_t* ppuGetVRAM(); uint8_t* ppuGetVRAM();
int audioUpdate() int audioUpdate()
@ -269,7 +270,7 @@ void CNESEmulator::InitializeEmulator()
double useFreq = apuGetFrequency(); double useFreq = apuGetFrequency();
m_booVoice = CAudioSys::GetVoiceEngine()->allocateNewStereoVoice(useFreq, this); m_booVoice = CAudioSys::GetVoiceEngine()->allocateNewStereoVoice(useFreq, this);
m_booVoice->start(); m_booVoice->start();
uint32_t apuBufSz = apuGetBufSize(); uint32_t apuBufSz = apuGetMaxBufSize();
m_audioBufBlock.reset(new u8[apuBufSz * NUM_AUDIO_BUFFERS]); m_audioBufBlock.reset(new u8[apuBufSz * NUM_AUDIO_BUFFERS]);
for (int i=0 ; i<NUM_AUDIO_BUFFERS ; ++i) for (int i=0 ; i<NUM_AUDIO_BUFFERS ; ++i)
m_audioBufs[i] = m_audioBufBlock.get() + apuBufSz * i; m_audioBufs[i] = m_audioBufBlock.get() + apuBufSz * i;
@ -340,7 +341,7 @@ int CNESEmulator::audioUpdate()
if(data != NULL && m_procBufs) if(data != NULL && m_procBufs)
{ {
--m_procBufs; --m_procBufs;
memmove(m_audioBufs[m_headBuf], data, apuGetBufSize()); memmove(m_audioBufs[m_headBuf], data, apuGetMaxBufSize());
//printf("PUSH\n"); //printf("PUSH\n");
++m_headBuf; ++m_headBuf;
if (m_headBuf == NUM_AUDIO_BUFFERS) if (m_headBuf == NUM_AUDIO_BUFFERS)
@ -360,7 +361,7 @@ size_t CNESEmulator::supplyAudio(boo::IAudioVoice& voice, size_t frames, int16_t
size_t remFrames = frames; size_t remFrames = frames;
while (remFrames) while (remFrames)
{ {
if (m_posInBuf == apuGetBufSize()) if (m_posInBuf == apuGetMaxBufSize())
{ {
++m_tailBuf; ++m_tailBuf;
if (m_tailBuf == NUM_AUDIO_BUFFERS) if (m_tailBuf == NUM_AUDIO_BUFFERS)
@ -377,7 +378,7 @@ size_t CNESEmulator::supplyAudio(boo::IAudioVoice& voice, size_t frames, int16_t
return frames; return frames;
} }
size_t copySz = std::min(apuGetBufSize() - m_posInBuf, remFrames * AudioFrameSz); size_t copySz = std::min(apuGetMaxBufSize() - m_posInBuf, remFrames * AudioFrameSz);
memmove(data, m_audioBufs[m_tailBuf] + m_posInBuf, copySz); memmove(data, m_audioBufs[m_tailBuf] + m_posInBuf, copySz);
data += copySz / sizeof(int16_t); data += copySz / sizeof(int16_t);
m_posInBuf += copySz; m_posInBuf += copySz;
@ -393,7 +394,7 @@ static int catchupFrames = 0;
void CNESEmulator::NesEmuMainLoop(bool forceDraw) void CNESEmulator::NesEmuMainLoop(bool forceDraw)
{ {
int start = GetTickCount(); //int start = GetTickCount();
int loopCount = 0; int loopCount = 0;
do do
{ {
@ -447,7 +448,8 @@ void CNESEmulator::NesEmuMainLoop(bool forceDraw)
emuFrameStart = end; emuFrameStart = end;
#endif #endif
//update audio before drawing //update audio before drawing
while(!apuUpdate()) {} if(!apuUpdate())
break;
//glutPostRedisplay(); //glutPostRedisplay();
#if 0 #if 0
if(ppuDebugPauseFrame) if(ppuDebugPauseFrame)
@ -462,7 +464,7 @@ void CNESEmulator::NesEmuMainLoop(bool forceDraw)
continue; continue;
} }
#if 1 #if 0
if (!forceDraw && (loopCount % 10000) == 0 && GetTickCount() - start >= 14) if (!forceDraw && (loopCount % 10000) == 0 && GetTickCount() - start >= 14)
{ {
#if CATCHUP_SKIP #if CATCHUP_SKIP

View File

@ -15,7 +15,7 @@ class IDvdRequest;
namespace MP1 namespace MP1
{ {
#define NUM_AUDIO_BUFFERS 10 #define NUM_AUDIO_BUFFERS 3
class CNESEmulator final : public boo::IAudioVoiceCallback class CNESEmulator final : public boo::IAudioVoiceCallback
{ {

View File

@ -48,7 +48,7 @@ BOO_GLSL_BINDING_HEAD
"TBINDING0 uniform sampler2D tex;\n" "TBINDING0 uniform sampler2D tex;\n"
"void main()\n" "void main()\n"
"{\n" "{\n"
" colorOut = vtf.color * vec4(texture(tex, vtf.uv).bgr, 1.0);\n" " colorOut = vtf.color * texture(tex, vtf.uv);\n"
"}\n"; "}\n";
#if _WIN32 #if _WIN32
@ -94,7 +94,7 @@ static const char* FS_HLSL =
"\n" "\n"
"float4 main(in VertToFrag vtf) : SV_Target0\n" "float4 main(in VertToFrag vtf) : SV_Target0\n"
"{\n" "{\n"
" return vtf.color * float4(tex.Sample(samp, vtf.uv).bgr, 1.0);\n" " return vtf.color * tex.Sample(samp, vtf.uv);\n"
"}\n"; "}\n";
#endif #endif
@ -145,7 +145,7 @@ static const char* FS_METAL =
" sampler clampSamp [[ sampler(4) ]],\n" " sampler clampSamp [[ sampler(4) ]],\n"
" texture2d<float> tex [[ texture(0) ]])\n" " texture2d<float> tex [[ texture(0) ]])\n"
"{\n" "{\n"
" return vtf.color * float4(tex.sample(clampSamp, vtf.uv).bgr, 1.0);\n" " return vtf.color * tex.sample(clampSamp, vtf.uv);\n"
"}\n"; "}\n";
#endif #endif

View File

@ -313,3 +313,8 @@ bool apuCycleURDE()
return true; return true;
} }
uint32_t apuGetMaxBufSize()
{
return apu.BufSizeBytes;
}

File diff suppressed because it is too large Load Diff