Skip to content

Commit

Permalink
Update Mednafen to 1.24.0
Browse files Browse the repository at this point in the history
  • Loading branch information
clobber committed Apr 19, 2020
1 parent 026cf39 commit 1a9f9fd
Show file tree
Hide file tree
Showing 215 changed files with 11,794 additions and 5,219 deletions.
2 changes: 1 addition & 1 deletion Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.23.0</string>
<string>1.24.0</string>
<key>NSPrincipalClass</key>
<string>OEGameCoreController</string>
<key>OEGameCoreClass</key>
Expand Down
16 changes: 11 additions & 5 deletions Mednafen.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
8715A97C1D6E54E3003ADE26 /* 3dpad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8715A9381D6E5273003ADE26 /* 3dpad.cpp */; };
8715A97D1D6E54E3003ADE26 /* gamepad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8715A93B1D6E5273003ADE26 /* gamepad.cpp */; };
8715A97E1D6E54E3003ADE26 /* mouse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8715A93D1D6E5273003ADE26 /* mouse.cpp */; };
87179166244CBA8900DA5B87 /* MTStreamReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 87179165244CBA8900DA5B87 /* MTStreamReader.cpp */; };
872FC2B422A96F6800AF67DE /* ExtMemStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 872FC2B222A96F6700AF67DE /* ExtMemStream.cpp */; };
872FC2B822A96FF300AF67DE /* NativeVFS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 872FC2B622A96FF300AF67DE /* NativeVFS.cpp */; };
872FC2BC22A9713200AF67DE /* VirtualFS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 872FC2BB22A9713200AF67DE /* VirtualFS.cpp */; };
Expand Down Expand Up @@ -421,6 +422,8 @@
8715A96A1D6E534F003ADE26 /* vdp2.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = vdp2.cpp; path = ss/vdp2.cpp; sourceTree = "<group>"; };
8715A96B1D6E534F003ADE26 /* vdp2.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = vdp2.h; path = ss/vdp2.h; sourceTree = "<group>"; };
8715A97F1D6E557F003ADE26 /* OESaturnSystemResponderClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = OESaturnSystemResponderClient.h; path = ../OpenEmu/Saturn/OESaturnSystemResponderClient.h; sourceTree = "<group>"; };
87179164244CBA8800DA5B87 /* MTStreamReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTStreamReader.h; sourceTree = "<group>"; };
87179165244CBA8900DA5B87 /* MTStreamReader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MTStreamReader.cpp; sourceTree = "<group>"; };
872FC2B222A96F6700AF67DE /* ExtMemStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExtMemStream.cpp; sourceTree = "<group>"; };
872FC2B322A96F6800AF67DE /* ExtMemStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExtMemStream.h; sourceTree = "<group>"; };
872FC2B522A96FF200AF67DE /* MThreading.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MThreading.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2162,6 +2165,8 @@
8CB3D6ED17F1DE5B0090372A /* mpcdec */,
872FC2C922A9761800AF67DE /* mthreading */,
872FC2B522A96FF200AF67DE /* MThreading.h */,
87179165244CBA8900DA5B87 /* MTStreamReader.cpp */,
87179164244CBA8800DA5B87 /* MTStreamReader.h */,
872FC2B622A96FF300AF67DE /* NativeVFS.cpp */,
872FC2B722A96FF300AF67DE /* NativeVFS.h */,
8CB3D70F17F1DE5B0090372A /* nes */,
Expand Down Expand Up @@ -4555,6 +4560,7 @@
8CB3E10417F216630090372A /* Deinterlacer.cpp in Sources */,
8CB3E07B17F1DE5E0090372A /* gfx.cpp in Sources */,
8CB3DE7317F1DE5E0090372A /* fxscsi.cpp in Sources */,
87179166244CBA8900DA5B87 /* MTStreamReader.cpp in Sources */,
94CFB6471A75DB60001F174F /* gpu_sprite.cpp in Sources */,
8CB3DE7817F1DE5E0090372A /* input.cpp in Sources */,
8CB3DE9D17F1DE5E0090372A /* multitap.cpp in Sources */,
Expand Down Expand Up @@ -4746,9 +4752,9 @@
OTHER_CFLAGS = (
"-fwrapv",
"-DHAVE_MKDIR",
"-DMEDNAFEN_VERSION=\\\"1.23.0-UNSTABLE\\\"",
"-DMEDNAFEN_VERSION=\\\"1.24.0-UNSTABLE\\\"",
"-DPACKAGE=\\\"mednafen\\\"",
"-DMEDNAFEN_VERSION_NUMERIC=0x00102300",
"-DMEDNAFEN_VERSION_NUMERIC=0x00102400",
"-DPSS_STYLE=1",
"-DMPC_FIXED_POINT",
"-DARCH_X86",
Expand Down Expand Up @@ -4812,9 +4818,9 @@
OTHER_CFLAGS = (
"-fwrapv",
"-DHAVE_MKDIR",
"-DMEDNAFEN_VERSION=\\\"1.23.0-UNSTABLE\\\"",
"-DMEDNAFEN_VERSION=\\\"1.24.0-UNSTABLE\\\"",
"-DPACKAGE=\\\"mednafen\\\"",
"-DMEDNAFEN_VERSION_NUMERIC=0x00102300",
"-DMEDNAFEN_VERSION_NUMERIC=0x00102400",
"-DPSS_STYLE=1",
"-DMPC_FIXED_POINT",
"-DARCH_X86",
Expand Down Expand Up @@ -4885,7 +4891,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
LLVM_LTO = NO;
LLVM_LTO = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
OTHER_LDFLAGS = (
"-fwrapv",
Expand Down
2 changes: 2 additions & 0 deletions MednafenGameCore.mm
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
#define Label(_NAME_) @{ OEGameCoreDisplayModeLabelKey : _NAME_, }
#define SeparatorItem() @{ OEGameCoreDisplayModeSeparatorItemKey : @"",}

using namespace Mednafen;

static MDFNGI *game;
static MDFN_Surface *surf;

Expand Down
235 changes: 235 additions & 0 deletions mednafen/MTStreamReader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
/******************************************************************************/
/* Mednafen - Multi-system Emulator */
/******************************************************************************/
/* MTStreamReader.cpp:
** Copyright (C) 2019 Mednafen Team
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software Foundation, Inc.,
** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#include <mednafen/mednafen.h>
#include "MTStreamReader.h"

#undef NDEBUG
#include <assert.h>

namespace Mednafen
{

void MTStreamReader::cleanup(void)
{
if(thread)
{
MThreading::Sem_Wait(ack_sem);
pending_command = Command_Exit;
MThreading::Sem_Post(command_sem);
//
MThreading::Thread_Wait(thread, nullptr);
thread = nullptr;
}

if(command_sem)
{
MThreading::Sem_Destroy(command_sem);
command_sem = nullptr;
}

if(ack_sem)
{
MThreading::Sem_Destroy(ack_sem);
ack_sem = nullptr;
}
}

int MTStreamReader::read_thread_entry_(void* data)
{
return ((MTStreamReader*)data)->read_thread_entry();
}

MTStreamReader::MTStreamReader(const uint64 affinity)
{
try
{
command_sem = MThreading::Sem_Create();
ack_sem = MThreading::Sem_Create();
thread = MThreading::Thread_Create(read_thread_entry_, this);
if(affinity)
MThreading::Thread_SetAffinity(thread, affinity);

pending_command = Command_NOP;
MThreading::Sem_Post(command_sem);
}
catch(...)
{
cleanup();
throw;
}
}

MTStreamReader::~MTStreamReader()
{
cleanup();
}

void MTStreamReader::zero_into_buffer(uint32 count)
{
while(count)
{
size_t sub_count = std::min<uint64>(Buffer_Size - (write_pos & Buffer_Size_Mask), count);

memset(&buffer[write_pos & Buffer_Size_Mask], 0, sub_count);
//printf("Zero: %04zx %zu\n", write_pos & Buffer_Size_Mask, sub_count);
write_pos += sub_count;
count -= sub_count;
}
//
memcpy(&buffer[Buffer_Size], &buffer[0], Overbuffer_Count);
}

void MTStreamReader::read_into_buffer(uint32 count)
{
assert(count <= Buffer_Size);
//
uint8* basep = nullptr;

//printf("ruh read_into_buffer %u\n", count);

while(count)
{
if(active->pos == active->size)
{
//printf("Ruh roh: %u\n", count);
//puts("Ruh roh");
zero_into_buffer(count);
count = 0;
break;
}
//
//const size_t prev_pos = active->pos;
//const size_t prev_write_pos = write_pos;
size_t sub_count = std::min<uint64>(Buffer_Size - (write_pos & Buffer_Size_Mask), std::min<uint64>(count, active->size - active->pos));
uint8* const dp = &buffer[write_pos & Buffer_Size_Mask];
if(basep)
{
//assert(active->pos == active->loop_pos);
memmove(dp, basep + (active->pos - active->loop_pos), sub_count);
}
else
active->stream->read(dp, sub_count);
//printf("Read: %04zx %zu %08x\n", write_pos & Buffer_Size_Mask, sub_count, (uint32)active->pos);
write_pos += sub_count;
active->pos += sub_count;
count -= sub_count;

if(active->pos == active->size)
{
//printf("ruh %llu %llu %llu %u\n", (unsigned long long)active->pos, (unsigned long long)active->size, (unsigned long long)active->loop_pos, count);
//
active->pos = active->loop_pos;

if(!basep)
{
if(active->loop_pos < active->size && (active->size - active->loop_pos) == sub_count)
basep = &buffer[(write_pos - sub_count) & Buffer_Size_Mask];
else
active->stream->seek(active->pos);
}
}
}

if(basep)
active->stream->seek(active->pos);
//
memcpy(&buffer[Buffer_Size], &buffer[0], Overbuffer_Count);
}

int MTStreamReader::read_thread_entry(void)
{
bool running = true;

try
{
while(running)
{
MThreading::Sem_Wait(command_sem);
//
const uint32 command = pending_command;

if(command == Command_Exit)
{
running = false;
}
else if(command == Command_NOP)
{

}
else if(command == Command_SetActive)
{
const uint32 w = pending_which;
const uint64 skip = pending_skip;
const uint32 pzb = pending_pzb;
uint64 pos;

active = &streams[w];

if(skip >= active->size)
{
if(active->loop_pos == active->size)
pos = active->size;
else
pos = active->loop_pos + ((skip - active->loop_pos) % (active->size - active->loop_pos));
}
else
pos = skip;

active->pos = pos;
active->stream->seek(pos);
//
zero_into_buffer(pzb);
read_into_buffer(Buffer_Size - pzb);
}
else if(command == Command_BufferNext)
{
read_into_buffer(Chunk_Size);
}
//
MThreading::Sem_Post(ack_sem);
}
}
catch(std::exception& e)
{
MDFN_Notify(MDFN_NOTICE_ERROR, _("MTStreamReader() error: %s"), e.what());

while(running)
{
MThreading::Sem_Wait(command_sem);
//
if(pending_command == Command_Exit)
running = false;
//
MThreading::Sem_Post(ack_sem);
}
}

return 0;
}

void MTStreamReader::add_stream(StreamInfo si)
{
assert(si.loop_pos <= si.size);
streams.push_back(std::move(si));
}

}
Loading

0 comments on commit 1a9f9fd

Please sign in to comment.