GB: cleanup and stuff
This commit is contained in:
parent
6953f3d6be
commit
9a6decef06
|
@ -148,6 +148,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
|
|||
Util.Hash_SHA1(romdata), Util.Hash_MD5(romdata)
|
||||
);
|
||||
|
||||
{
|
||||
byte[] buff = new byte[32];
|
||||
LibGambatte.gambatte_romtitle(GambatteState, buff);
|
||||
string romname = System.Text.Encoding.ASCII.GetString(buff);
|
||||
Console.WriteLine("Core reported rom name: {0}", romname);
|
||||
}
|
||||
|
||||
TimeCallback = new LibGambatte.RTCCallback(GetCurrentTime);
|
||||
LibGambatte.gambatte_setrtccallback(GambatteState, TimeCallback);
|
||||
|
||||
|
|
|
@ -316,9 +316,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
|
|||
/// ROM header title of currently loaded ROM image.
|
||||
/// </summary>
|
||||
/// <param name="core">opaque state pointer</param>
|
||||
/// <param name="data">enough room for 16 ascii chars plus terminator</param>
|
||||
/// <returns></returns>
|
||||
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern string gambatte_romtitle(IntPtr core);
|
||||
public static extern string gambatte_romtitle(IntPtr core, byte[] data);
|
||||
|
||||
/// <summary>
|
||||
/// memory areas that gambatte_getmemoryarea() can return
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#ifndef GAMBATTE_H
|
||||
#define GAMBATTE_H
|
||||
|
||||
#include "inputgetter.h"
|
||||
#include "gbint.h"
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
@ -84,7 +83,7 @@ public:
|
|||
void setCgbPalette(unsigned *lut);
|
||||
|
||||
/** Sets the callback used for getting input state. */
|
||||
void setInputGetter(InputGetter *getInput);
|
||||
void setInputGetter(unsigned (*getInput)());
|
||||
|
||||
void setReadCallback(void (*callback)(unsigned));
|
||||
void setWriteCallback(void (*callback)(unsigned));
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* 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 version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef GAMBATTE_INPUTGETTER_H
|
||||
#define GAMBATTE_INPUTGETTER_H
|
||||
|
||||
namespace gambatte {
|
||||
class InputGetter {
|
||||
public:
|
||||
enum { A = 0x01, B = 0x02, SELECT = 0x04, START = 0x08, RIGHT = 0x10, LEFT = 0x20, UP = 0x40, DOWN = 0x80 };
|
||||
virtual ~InputGetter() {};
|
||||
|
||||
/** @return A|B|SELECT|START|RIGHT|LEFT|UP|DOWN if those buttons are pressed. */
|
||||
virtual unsigned operator()() = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -86,7 +86,6 @@
|
|||
<ItemGroup>
|
||||
<ClInclude Include="include\gambatte.h" />
|
||||
<ClInclude Include="include\gbint.h" />
|
||||
<ClInclude Include="include\inputgetter.h" />
|
||||
<ClInclude Include="src\cinterface.h" />
|
||||
<ClInclude Include="src\common\array.h" />
|
||||
<ClInclude Include="src\common\uncopyable.h" />
|
||||
|
|
|
@ -99,9 +99,6 @@
|
|||
<ClInclude Include="src\sound\envelope_unit.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\inputgetter.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\interruptrequester.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
|
|
@ -1,223 +1,175 @@
|
|||
#include "cinterface.h"
|
||||
#include "gambatte.h"
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include "newstate.h"
|
||||
|
||||
using namespace gambatte;
|
||||
|
||||
|
||||
GBEXPORT void *gambatte_create()
|
||||
GBEXPORT GB *gambatte_create()
|
||||
{
|
||||
GB *g = new GB();
|
||||
return (void *) g;
|
||||
return new (std::calloc(1, sizeof (GB))) GB();
|
||||
}
|
||||
|
||||
GBEXPORT void gambatte_destroy(void *core)
|
||||
GBEXPORT void gambatte_destroy(GB *g)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
delete g;
|
||||
g->~GB();
|
||||
std::free(g);
|
||||
}
|
||||
|
||||
GBEXPORT int gambatte_load(void *core, const char *romfiledata, unsigned romfilelength, long long now, unsigned flags)
|
||||
GBEXPORT int gambatte_load(GB *g, const char *romfiledata, unsigned romfilelength, long long now, unsigned flags)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
int ret = g->load(romfiledata, romfilelength, now, flags);
|
||||
return ret;
|
||||
}
|
||||
|
||||
GBEXPORT long gambatte_runfor(void *core, short *soundbuf, unsigned *samples)
|
||||
GBEXPORT long gambatte_runfor(GB *g, short *soundbuf, unsigned *samples)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
unsigned sampv = *samples;
|
||||
long ret = g->runFor((unsigned int *) soundbuf, sampv);
|
||||
*samples = sampv;
|
||||
return ret;
|
||||
}
|
||||
|
||||
GBEXPORT void gambatte_blitto(void *core, unsigned long *videobuf, int pitch)
|
||||
GBEXPORT void gambatte_blitto(GB *g, unsigned long *videobuf, int pitch)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
g->blitTo((unsigned int *)videobuf, pitch);
|
||||
}
|
||||
|
||||
GBEXPORT void gambatte_reset(void *core, long long now)
|
||||
GBEXPORT void gambatte_reset(GB *g, long long now)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
g->reset(now);
|
||||
}
|
||||
|
||||
GBEXPORT void gambatte_setdmgpalettecolor(void *core, unsigned palnum, unsigned colornum, unsigned rgb32)
|
||||
GBEXPORT void gambatte_setdmgpalettecolor(GB *g, unsigned palnum, unsigned colornum, unsigned rgb32)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
g->setDmgPaletteColor(palnum, colornum, rgb32);
|
||||
}
|
||||
|
||||
GBEXPORT void gambatte_setcgbpalette(void *core, unsigned *lut)
|
||||
GBEXPORT void gambatte_setcgbpalette(GB *g, unsigned *lut)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
g->setCgbPalette(lut);
|
||||
}
|
||||
|
||||
class CInputGetter: public InputGetter
|
||||
GBEXPORT void gambatte_setinputgetter(GB *g, unsigned (*getinput)(void))
|
||||
{
|
||||
public:
|
||||
|
||||
unsigned (*inputfunc)(void);
|
||||
unsigned operator()()
|
||||
{
|
||||
return inputfunc ();
|
||||
}
|
||||
};
|
||||
|
||||
GBEXPORT void gambatte_setinputgetter(void *core, unsigned (*getinput)(void))
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
CInputGetter *cig = new CInputGetter();
|
||||
cig->inputfunc = getinput;
|
||||
// how do i manage the lifetime of cig?
|
||||
g->setInputGetter(cig);
|
||||
g->setInputGetter(getinput);
|
||||
}
|
||||
|
||||
GBEXPORT void gambatte_setreadcallback(void *core, void (*callback)(unsigned))
|
||||
GBEXPORT void gambatte_setreadcallback(GB *g, void (*callback)(unsigned))
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
g->setReadCallback(callback);
|
||||
}
|
||||
|
||||
GBEXPORT void gambatte_setwritecallback(void *core, void (*callback)(unsigned))
|
||||
GBEXPORT void gambatte_setwritecallback(GB *g, void (*callback)(unsigned))
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
g->setWriteCallback(callback);
|
||||
}
|
||||
|
||||
GBEXPORT void gambatte_setexeccallback(void *core, void (*callback)(unsigned))
|
||||
GBEXPORT void gambatte_setexeccallback(GB *g, void (*callback)(unsigned))
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
g->setExecCallback(callback);
|
||||
}
|
||||
|
||||
GBEXPORT void gambatte_settracecallback(void *core, void (*callback)(void *))
|
||||
GBEXPORT void gambatte_settracecallback(GB *g, void (*callback)(void *))
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
g->setTraceCallback(callback);
|
||||
}
|
||||
|
||||
GBEXPORT void gambatte_setscanlinecallback(void *core, void (*callback)(), int sl)
|
||||
GBEXPORT void gambatte_setscanlinecallback(GB *g, void (*callback)(), int sl)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
g->setScanlineCallback(callback, sl);
|
||||
}
|
||||
|
||||
GBEXPORT void gambatte_setrtccallback(void *core, unsigned int (*callback)())
|
||||
GBEXPORT void gambatte_setrtccallback(GB *g, unsigned int (*callback)())
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
g->setRTCCallback(callback);
|
||||
}
|
||||
|
||||
GBEXPORT int gambatte_iscgb(void *core)
|
||||
GBEXPORT int gambatte_iscgb(GB *g)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
return g->isCgb();
|
||||
}
|
||||
|
||||
GBEXPORT int gambatte_isloaded(void *core)
|
||||
GBEXPORT int gambatte_isloaded(GB *g)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
return g->isLoaded();
|
||||
}
|
||||
|
||||
GBEXPORT void gambatte_savesavedata(void *core, char *dest)
|
||||
GBEXPORT void gambatte_savesavedata(GB *g, char *dest)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
g->saveSavedata(dest);
|
||||
}
|
||||
|
||||
GBEXPORT void gambatte_loadsavedata(void *core, const char *data)
|
||||
GBEXPORT void gambatte_loadsavedata(GB *g, const char *data)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
g->loadSavedata(data);
|
||||
}
|
||||
|
||||
GBEXPORT int gambatte_savesavedatalength(void *core)
|
||||
GBEXPORT int gambatte_savesavedatalength(GB *g)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
return g->saveSavedataLength();
|
||||
}
|
||||
|
||||
GBEXPORT long gambatte_newstatelen(void *core)
|
||||
GBEXPORT long gambatte_newstatelen(GB *g)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
NewStateDummy dummy;
|
||||
g->SyncState<false>(&dummy);
|
||||
return dummy.GetLength();
|
||||
}
|
||||
|
||||
GBEXPORT int gambatte_newstatesave(void *core, char *data, long len)
|
||||
GBEXPORT int gambatte_newstatesave(GB *g, char *data, long len)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
NewStateExternalBuffer saver(data, len);
|
||||
g->SyncState<false>(&saver);
|
||||
return !saver.Overflow() && saver.GetLength() == len;
|
||||
}
|
||||
|
||||
GBEXPORT int gambatte_newstateload(void *core, const char *data, long len)
|
||||
GBEXPORT int gambatte_newstateload(GB *g, const char *data, long len)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
NewStateExternalBuffer loader((char *)data, len);
|
||||
g->SyncState<true>(&loader);
|
||||
return !loader.Overflow() && loader.GetLength() == len;
|
||||
}
|
||||
|
||||
GBEXPORT void gambatte_newstatesave_ex(void *core, FPtrs *ff)
|
||||
GBEXPORT void gambatte_newstatesave_ex(GB *g, FPtrs *ff)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
NewStateExternalFunctions saver(ff);
|
||||
g->SyncState<false>(&saver);
|
||||
}
|
||||
|
||||
GBEXPORT void gambatte_newstateload_ex(void *core, FPtrs *ff)
|
||||
GBEXPORT void gambatte_newstateload_ex(GB *g, FPtrs *ff)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
NewStateExternalFunctions loader(ff);
|
||||
g->SyncState<true>(&loader);
|
||||
}
|
||||
|
||||
static char horriblebuff[64];
|
||||
GBEXPORT const char *gambatte_romtitle(void *core)
|
||||
GBEXPORT void gambatte_romtitle(GB *g, char *dest)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
const char *s = g->romTitle().c_str();
|
||||
std::strncpy(horriblebuff, s, 63);
|
||||
horriblebuff[63] = 0;
|
||||
return horriblebuff;
|
||||
std::strcpy(dest, g->romTitle().c_str());
|
||||
}
|
||||
|
||||
GBEXPORT int gambatte_getmemoryarea(void *core, int which, unsigned char **data, int *length)
|
||||
GBEXPORT int gambatte_getmemoryarea(GB *g, int which, unsigned char **data, int *length)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
return g->getMemoryArea(which, data, length);
|
||||
}
|
||||
|
||||
GBEXPORT unsigned char gambatte_cpuread(void *core, unsigned short addr)
|
||||
GBEXPORT unsigned char gambatte_cpuread(GB *g, unsigned short addr)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
return g->ExternalRead(addr);
|
||||
}
|
||||
|
||||
GBEXPORT void gambatte_cpuwrite(void *core, unsigned short addr, unsigned char val)
|
||||
GBEXPORT void gambatte_cpuwrite(GB *g, unsigned short addr, unsigned char val)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
g->ExternalWrite(addr, val);
|
||||
}
|
||||
|
||||
GBEXPORT int gambatte_linkstatus(void *core, int which)
|
||||
GBEXPORT int gambatte_linkstatus(GB *g, int which)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
return g->LinkStatus(which);
|
||||
}
|
||||
|
||||
GBEXPORT void gambatte_getregs(void *core, int *dest)
|
||||
GBEXPORT void gambatte_getregs(GB *g, int *dest)
|
||||
{
|
||||
GB *g = (GB *) core;
|
||||
g->GetRegs(dest);
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ public:
|
|||
memory.setVideoBuffer(videoBuf, pitch);
|
||||
}
|
||||
|
||||
void setInputGetter(InputGetter *getInput) {
|
||||
void setInputGetter(unsigned (*getInput)()) {
|
||||
memory.setInputGetter(getInput);
|
||||
}
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ void GB::reset(const std::uint32_t now) {
|
|||
}
|
||||
}
|
||||
|
||||
void GB::setInputGetter(InputGetter *getInput) {
|
||||
void GB::setInputGetter(unsigned (*getInput)()) {
|
||||
p_->cpu.setInputGetter(getInput);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "memory.h"
|
||||
#include "video.h"
|
||||
#include "sound.h"
|
||||
#include "inputgetter.h"
|
||||
#include "savestate.h"
|
||||
#include <cstring>
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ class Memory {
|
|||
void (*writeCallback)(unsigned);
|
||||
void (*execCallback)(unsigned);
|
||||
|
||||
InputGetter *getInput;
|
||||
unsigned (*getInput)();
|
||||
unsigned long divLastUpdate;
|
||||
unsigned long lastOamDmaUpdate;
|
||||
|
||||
|
@ -159,7 +159,7 @@ public:
|
|||
|
||||
int loadROM(const char *romfiledata, unsigned romfilelength, bool forceDmg, bool multicartCompat);
|
||||
|
||||
void setInputGetter(InputGetter *getInput) {
|
||||
void setInputGetter(unsigned (*getInput)()) {
|
||||
this->getInput = getInput;
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue