Commit c2113f03 authored by Libretro-Admin's avatar Libretro-Admin
Browse files

Take out Player

parent 80a4b27c
......@@ -27,9 +27,6 @@ SOURCES_CXX := \
$(MEDNAFEN_DIR)/cheat_formats/snes.cpp \
$(MEDNAFEN_DIR)/hash/sha1.cpp \
$(MEDNAFEN_DIR)/hash/sha256.cpp \
$(MEDNAFEN_DIR)/player.cpp \
$(MEDNAFEN_DIR)/SNSFLoader.cpp \
$(MEDNAFEN_DIR)/SPCReader.cpp \
$(MEDNAFEN_DIR)/MTStreamReader.cpp
ifeq ($(THREADING_TYPE),Win32)
......
/******************************************************************************/
/* Mednafen - Multi-system Emulator */
/******************************************************************************/
/* SNSFLoader.cpp:
** Copyright (C) 2012-2016 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 <mednafen/SNSFLoader.h>
namespace Mednafen
{
bool SNSFLoader::TestMagic(Stream* fp)
{
return false;
/*
return PSFLoader::TestMagic(0x23, fp);
*/
}
SNSFLoader::SNSFLoader(VirtualFS* vfs, const std::string& dir_path, Stream* fp)
{
/*
tags = Load(0x23, 8 + 1024 * 8192, vfs, dir_path, fp);
assert(ROM_Data.size() <= 8192 * 1024);
*/
}
SNSFLoader::~SNSFLoader()
{
}
/*
void SNSFLoader::HandleReserved(Stream* fp, uint32 len)
{
uint64 bound_pos = fp->tell() + len;
if(len < 9)
return;
while(fp->tell() < bound_pos)
{
uint8 raw_header[8];
uint32 header_type;
uint32 header_size;
fp->read(raw_header, sizeof(raw_header));
header_type = MDFN_de32lsb(&raw_header[0]);
header_size = MDFN_de32lsb(&raw_header[4]);
switch(header_type)
{
case 0xFFFFFFFF: // EOR
goto Breakout;
default:
throw MDFN_Error(0, _("SNSF Reserved Section Unknown/Unsupported Data Type 0x%08x"), header_type);
break;
case 0: // SRAM
{
uint8 raw_subheader[4];
uint32 srd_offset, srd_size;
fp->read(raw_subheader, sizeof(raw_subheader));
srd_offset = MDFN_de32lsb(&raw_subheader[0]);
srd_size = header_size - 4;
if(srd_size > 0x20000)
{
throw MDFN_Error(0, _("SNSF Reserved Section SRAM block size(=%u) is too large."), srd_size);
}
if(((uint64)srd_offset + srd_size) > 0x20000)
{
throw MDFN_Error(0, _("SNSF Reserved Section SRAM block combined offset+size(=%llu) is too large."), (unsigned long long)srd_offset + srd_size);
}
MDFN_printf("SNSF SRAM Data: Offset=0x%08x, Size=0x%08x\n", srd_offset, srd_size);
if((srd_offset + srd_size) > SRAM_Data.size())
{
const size_t old_size = SRAM_Data.size();
SRAM_Data.truncate(srd_offset + srd_size);
if(srd_offset > old_size)
memset(SRAM_Data.map() + old_size, 0xFF, srd_offset - old_size);
}
fp->read(&SRAM_Data.map()[srd_offset], srd_size);
}
break;
}
}
Breakout:;
if(fp->tell() != bound_pos)
throw MDFN_Error(0, _("Malformed SNSF reserved section."));
}
void SNSFLoader::HandleEXE(Stream* fp, bool ignore_pcsp)
{
uint8 raw_header[8];
fp->read(raw_header, sizeof(raw_header));
const uint32 header_size = MDFN_de32lsb(&raw_header[4]);
uint32 adj_offset;
{
const uint32 header_offset = MDFN_de32lsb(&raw_header[0]);
if(ROM_BaseOffset < 0)
{
ROM_BaseOffset = header_offset;
adj_offset = ROM_BaseOffset;
}
else
adj_offset = ROM_BaseOffset + header_offset;
MDFN_printf("SNSF ROM Data: SNSF_Offset=0x%08x(adjusted: 0x%08x) Size=0x%08x\n", header_offset, adj_offset, header_size);
}
if(adj_offset > (1024 * 8192))
{
throw MDFN_Error(0, _("SNSF Adjusted Offset(=%u) is too large."), adj_offset);
}
if(header_size > (1024 * 8192))
{
throw MDFN_Error(0, _("SNSF Header Field Size(=%u) is too large."), header_size);
}
if(((uint64)adj_offset + header_size) > (1024 * 8192))
{
throw MDFN_Error(0, _("SNSF Combined Adjusted Offset(=%u) + Size(=%u) is too large."), adj_offset, header_size);
}
if((adj_offset + header_size) > ROM_Data.size())
ROM_Data.truncate(adj_offset + header_size);
fp->read(&ROM_Data.map()[adj_offset], header_size);
}
*/
}
/******************************************************************************/
/* Mednafen - Multi-system Emulator */
/******************************************************************************/
/* SNSFLoader.h:
** Copyright (C) 2012-2016 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.
*/
#ifndef __MDFN_SNSFLOADER_H
#define __MDFN_SNSFLOADER_H
//#include <mednafen/PSFLoader.h>
#include <mednafen/MemoryStream.h>
namespace Mednafen
{
struct PSFTags
{
INLINE int64 GetTagI(const char *name) { return 0; }
INLINE std::string GetTag(const char *name) { return ""; }
INLINE bool TagExists(const char *name) { return false; }
};
class SNSFLoader //: public PSFLoader
{
public:
SNSFLoader(VirtualFS* vfs, const std::string& dir_path, Stream* fp);
virtual ~SNSFLoader();
static bool TestMagic(Stream* fp);
/*
virtual void HandleEXE(Stream* fp, bool ignore_pcsp = false) override;
virtual void HandleReserved(Stream* fp, uint32 len) override;
*/
PSFTags tags;
int64 ROM_BaseOffset = -1;
MemoryStream ROM_Data;
MemoryStream SRAM_Data;
};
}
#endif
/******************************************************************************/
/* Mednafen - Multi-system Emulator */
/******************************************************************************/
/* SPCReader.cpp:
** Copyright (C) 2015-2016 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 <mednafen/SPCReader.h>
#include <mednafen/string/string.h>
namespace Mednafen
{
bool SPCReader::TestMagic(Stream* fp)
{
#if 0
return true;
#endif
static const char* spc_magic = "SNES-SPC700 Sound File Data";
uint8 header[0x100];
uint64 rc;
if(fp->size() < 0x10200)
return false;
rc = fp->read(header, sizeof(header), false);
fp->rewind();
if(rc != sizeof(header))
return false;
if(memcmp(header, spc_magic, strlen(spc_magic)))
return false;
return true;
}
static std::string GrabString(Stream* fp, size_t len)
{
std::string ret;
size_t null_pos;
ret.resize(len);
fp->read(&ret[0], len);
null_pos = ret.find('\0'); // ANDDYYYYYYYYY
if(null_pos != std::string::npos)
ret.resize(null_pos);
MDFN_zapctrlchars(&ret);
MDFN_trim(&ret);
return ret;
}
SPCReader::SPCReader(Stream* fp)
{
#if 0
reg_pc = 0x430;
reg_a = 0;
reg_x = 0;
reg_y = 0;
reg_psw = 0;
reg_sp = 0xFF;
memset(apuram, 0x00, sizeof(apuram));
memset(dspregs, 0x00, sizeof(dspregs));
dspregs[0x6C] = 0xE0;
fp->read(&apuram[0x400], 0x1000);
return;
#endif
if(!TestMagic(fp))
throw MDFN_Error(0, _("Not a valid SPC file!"));
uint8 header[0x100];
fp->rewind();
fp->read(header, sizeof(header));
reg_pc = MDFN_de16lsb<false>(&header[0x25]);
reg_a = header[0x27];
reg_x = header[0x28];
reg_y = header[0x29];
reg_psw = header[0x2A];
reg_sp = header[0x2B];
fp->read(apuram, 65536);
fp->read(dspregs, 0x80);
fp->seek(0x101C0, SEEK_SET);
fp->read(apuram + 0xFFC0, 0x40);
if(header[0x23] == 0x1A)
{
bool binary_tags = true;
if(header[0xA0] == '/' && header[0xA3] == '/')
binary_tags = false;
if(header[0xD2] >= '0' && header[0xD2] <= '9' && header[0xD3] == 0x00)
binary_tags = false;
fp->seek(0x2E, SEEK_SET);
song_name = GrabString(fp, 32);
game_name = GrabString(fp, 32);
fp->seek(binary_tags ? 0xB0 : 0xB1, SEEK_SET);
artist_name = GrabString(fp, 32);
}
//
//
//
#if 0
fp->seek(0x10200, SEEK_SET);
uint8 xid_header[8];
if(fp->read(xid_header, sizeof(xid_header), false) == sizeof(xid_header) && !memcmp(xid_header, "xid6", 4))
{
uint8 sub_header[4];
while(fp->read(sub_header, sizeof(sub_header), false) == sizeof(sub_header))
{
const uint8 id = sub_header[0];
const uint8 type = sub_header[1];
uint16 len = MDFN_de16lsb(&sub_header[2]);
printf("ID: 0x%02x, Type: 0x%02x, Len: 0x%04x\n", id, type, len);
if(type == 1 && len > 4)
len = (len + 3) &~ 3;
switch(id)
{
default:
if(type)
fp->seek(len, SEEK_CUR);
break;
case 0x01: song_name = GrabString(fp, len); break;
case 0x02: game_name = GrabString(fp, len); break;
case 0x03: artist_name = GrabString(fp, len); break;
}
}
}
#endif
}
SPCReader::~SPCReader()
{
}
}
/******************************************************************************/
/* Mednafen - Multi-system Emulator */
/******************************************************************************/
/* SPCReader.h:
** Copyright (C) 2015-2016 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.
*/
#ifndef __MDFN_SPCREADER_H
#define __MDFN_SPCREADER_H
#include <mednafen/Stream.h>
namespace Mednafen
{
class SPCReader
{
public:
static bool TestMagic(Stream* fp) MDFN_COLD;
SPCReader(Stream* fp) MDFN_COLD;
~SPCReader() MDFN_COLD;
INLINE const uint8* APURAM(void) { return apuram; }
INLINE const uint8* DSPRegs(void) { return dspregs; }
INLINE uint16 PC(void) { return reg_pc; }
INLINE uint8 A(void) { return reg_a; }
INLINE uint8 X(void) { return reg_x; }
INLINE uint8 Y(void) { return reg_y; }
INLINE uint8 PSW(void) { return reg_psw; }
INLINE uint8 SP(void) { return reg_sp; }
INLINE std::string GameName(void) { return game_name; }
INLINE std::string ArtistName(void) { return artist_name; }
INLINE std::string SongName(void) { return song_name; }
private:
uint8 apuram[65536];
uint8 dspregs[128];
uint16 reg_pc;
uint8 reg_a, reg_x, reg_y;
uint8 reg_psw;
uint8 reg_sp;
std::string game_name;
std::string artist_name;
std::string song_name;
};
}
#endif
/* Mednafen - Multi-system Emulator
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mednafen.h"
#include "video.h"
#include "player.h"
namespace Mednafen
{
template<typename T>
static INLINE void FastDrawLine(T* buf, int32 pitch, uint32 color, uint32 bmatch, uint32 breplace, const int xs, const int ys, const int ydelta)
{
int y = ys;
int y_inc = (ydelta < 0) ? -1 : 1;
unsigned i_bound = abs(ydelta); // No +1, or we'll overflow our buffer(we compensate in our calculation of half_point).
unsigned half_point = (i_bound + 1) >> 1;
for(unsigned i = 0; i <= half_point; i++, y += y_inc)
{
if(bmatch != ~0U)
{
uint32 tmpcolor = color;
if(buf[xs + y * pitch] == bmatch)
tmpcolor = breplace;
if(buf[xs + y * pitch] != breplace)
buf[xs + y * pitch] = tmpcolor;
}
else
buf[xs + y * pitch] = color;
}
y -= y_inc;
for(unsigned i = half_point; i < i_bound; i++, y += y_inc)
{
if(bmatch != ~0U)
{
uint32 tmpcolor = color;
if(buf[xs + 1 + y * pitch] == bmatch)
tmpcolor = breplace;
if(buf[xs + 1+ y * pitch] != breplace)
buf[xs + 1 + y * pitch] = tmpcolor;
}
else
buf[xs + 1 + y * pitch] = color;
}
}
template<typename T>
static void DrawWaveformSub(T* const pixels, const int32 pitch, const uint32 lcolor, const uint32 rcolor, const uint32 ccolor, const int32 w, const int32 h, const int32 numchan, const int16* soundbuf, int32 framecount)
{
// Now we draw the waveform data. It should be centered vertically, and extend the screen horizontally from left to right.
if(framecount)
{
const int32 x_scale = (framecount << 8) / w;
const int32 y_scale = -h;
int lastX, lastY;
for(int wc = 0; wc < numchan; wc++)
{
uint32 color = wc ? rcolor : lcolor;
if(numchan == 1)
color = ccolor;
lastX = -1;
lastY = 0;
for(int x = 0; x < w; x++)
{
const int32 samp = soundbuf[wc + (x * x_scale >> 8) * numchan];
int ypos;
ypos = (h / 2) + ((samp * y_scale + 0x4000) >> 15);
//ypos = (rand() & 0xFFF) - 0x800;
if(ypos < 0)
ypos = 0;
if(ypos >= h)
ypos = h - 1;
if(lastX >= 0)
FastDrawLine(pixels, pitch, color, wc ? lcolor : ~0U, ccolor, lastX, lastY, ypos - lastY);
lastX = x;
lastY = ypos;
}
}
}
}
static INLINE void DrawWaveform(MDFN_Surface* surface, const MDFN_Rect& dr, const int32 numchan, const int16* soundbuf, const int32 framecount)
{
const uint32 left_color = surface->MakeColor(0x80, 0x80, 0xFF);
const uint32 right_color = surface->MakeColor(0x80, 0xFF, 0x80);
const uint32 center_color = surface->MakeColor(0x80, 0xCC, 0xCC);
switch(surface->format.bpp)
{
case 8:
// TODO(colors):
DrawWaveformSub(surface->pix<uint8>() + dr.x + dr.y * surface->pitchinpix, surface->pitchinpix, left_color, right_color, center_color, dr.w, dr.h, numchan, soundbuf, framecount);
break;
case 16:
DrawWaveformSub(surface->pix<uint16>() + dr.x + dr.y * surface->pitchinpix, surface->pitchinpix, left_color, right_color, center_color, dr.w, dr.h, numchan, soundbuf, framecount);
break;
case 32:
DrawWaveformSub(surface->pix<uint32>() + dr.x + dr.y * surface->pitchinpix, surface->pitchinpix, left_color, right_color, center_color, dr.w, dr.h, numchan, soundbuf, framecount);
break;
}
}
void Player_Init(int tsongs, const std::string &album, const std::string &artist, const std::string &copyright, const std::vector<std::string> &snames, bool override_gi)
{
if(override_gi)
{
MDFNGameInfo->nominal_width = 384;
MDFNGameInfo->nominal_height = 240;
MDFNGameInfo->fb_width = 384;
MDFNGameInfo->fb_height = 240;
MDFNGameInfo->lcm_width = 384;
MDFNGameInfo->lcm_height = 240;
}
}
void Player_Draw(MDFN_Surface* surface, MDFN_Rect* dr, int CurrentSong, int16* soundbuf, int32 framecount)
{
dr->x = 0;
dr->y = 0;
dr->w = surface->w;
dr->h = surface->h;
surface->Fill(0x20, 0x00, 0x08, 0);
DrawWaveform(surface, *dr, MDFNGameInfo->soundchan, soundbuf, framecount);