fix issue 122 using MrWint42's patch. thanks! gambatte RTC for movies should work now.

This commit is contained in:
goyuken 2013-11-24 17:32:46 +00:00
parent 544f4855fa
commit fc110cbeae
16 changed files with 42 additions and 39 deletions

View File

@ -30,13 +30,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
/// <summary>
/// RTC time when emulation begins.
/// </summary>
long zerotime = 0;
uint zerotime = 0;
LibGambatte.RTCCallback TimeCallback;
long GetCurrentTime()
uint GetCurrentTime()
{
long fn = Frame;
uint fn = (uint)Frame;
fn /= 60; // exactly 60 fps. in case you feel bad about it, remember that we're not exactly tracking cpu cycles either.
fn += zerotime;
return fn;

View File

@ -206,7 +206,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
/// </summary>
/// <returns>what time is it, unixy</returns>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate long RTCCallback();
public delegate uint RTCCallback();
/// <summary>
/// sets RTC callback. probably mandatory.

View File

@ -23,7 +23,7 @@
#include "gbint.h"
#include <string>
#include <sstream>
#include <ctime>
#include <cstdint>
namespace gambatte {
enum { BG_PALETTE = 0, SP1_PALETTE = 1, SP2_PALETTE = 2 };
@ -45,7 +45,7 @@ public:
* @param flags ORed combination of LoadFlags.
* @return 0 on success, negative value on failure.
*/
int load(const char *romfiledata, unsigned romfilelength, std::time_t now, unsigned flags = 0);
int load(const char *romfiledata, unsigned romfilelength, std::uint32_t now, unsigned flags = 0);
/** Emulates until at least 'samples' stereo sound samples are produced in the supplied buffer,
* or until a video frame has been drawn.
@ -74,7 +74,7 @@ public:
/** Reset to initial state.
* Equivalent to reloading a ROM image, or turning a Game Boy Color off and on again.
*/
void reset(std::time_t now);
void reset(std::uint32_t now);
/** @param palNum 0 <= palNum < 3. One of BG_PALETTE, SP1_PALETTE and SP2_PALETTE.
* @param colorNum 0 <= colorNum < 4
@ -91,7 +91,7 @@ public:
void setExecCallback(void (*callback)(unsigned));
void setTraceCallback(void (*callback)(void *));
void setScanlineCallback(void (*callback)(), int sl);
void setRTCCallback(std::time_t (*callback)());
void setRTCCallback(std::uint32_t (*callback)());
/** Sets the directory used for storing save data. The default is the same directory as the ROM Image file. */
void setSaveDir(const std::string &sdir);

View File

@ -19,6 +19,9 @@
#ifndef GAMBATTE_INT_H
#define GAMBATTE_INT_H
// note that this is a hack to overcome the fact that libgambatte's original defines are not propagated.
#define HAVE_CSTDINT
#ifdef HAVE_CSTDINT
#include <cstdint>

View File

@ -28,7 +28,7 @@ __declspec(dllexport) long gambatte_runfor(void *core, unsigned long *videobuf,
{
GB *g = (GB *) core;
unsigned sampv = *samples;
long ret = g->runFor(videobuf, pitch, (unsigned long *) soundbuf, sampv);
long ret = g->runFor((unsigned int*)videobuf, pitch, (unsigned int *) soundbuf, sampv);
*samples = sampv;
return ret;
}
@ -101,7 +101,7 @@ __declspec(dllexport) void gambatte_setscanlinecallback(void *core, void (*callb
g->setScanlineCallback(callback, sl);
}
__declspec(dllexport) void gambatte_setrtccallback(void *core, long long (*callback)())
__declspec(dllexport) void gambatte_setrtccallback(void *core, unsigned int (*callback)())
{
GB *g = (GB *) core;
g->setRTCCallback(callback);
@ -170,7 +170,7 @@ __declspec(dllexport) int gambatte_savestate(void *core, const unsigned long *vi
GB *g = (GB *) core;
std::ostringstream os = std::ostringstream(std::ios_base::binary | std::ios_base::out);
if (!g->saveState(videobuf, pitch, os))
if (!g->saveState((const unsigned int*)videobuf, pitch, os))
return 0;
os.flush();

View File

@ -30,7 +30,7 @@ extern "C"
__declspec(dllexport) void gambatte_setscanlinecallback(void *core, void (*callback)(), int sl);
__declspec(dllexport) void gambatte_setrtccallback(void *core, long long (*callback)());
__declspec(dllexport) void gambatte_setrtccallback(void *core, unsigned int (*callback)());
__declspec(dllexport) void gambatte_setsavedir(void *core, const char *sdir);

View File

@ -87,7 +87,7 @@ public:
memory.setScanlineCallback(callback, sl);
}
void setRTCCallback(std::time_t (*callback)()) {
void setRTCCallback(std::uint32_t (*callback)()) {
memory.setRTCCallback(callback);
}

View File

@ -68,7 +68,7 @@ long GB::runFor(gambatte::uint_least32_t *const videoBuf, const int pitch,
return cyclesSinceBlit < 0 ? cyclesSinceBlit : static_cast<long>(samples) - (cyclesSinceBlit >> 1);
}
void GB::reset(const std::time_t now) {
void GB::reset(const std::uint32_t now) {
if (p_->cpu.loaded()) {
int length = p_->cpu.saveSavedataLength();
@ -115,7 +115,7 @@ void GB::setScanlineCallback(void (*callback)(), int sl) {
p_->cpu.setScanlineCallback(callback, sl);
}
void GB::setRTCCallback(long long (*callback)()) {
void GB::setRTCCallback(std::uint32_t (*callback)()) {
p_->cpu.setRTCCallback(callback);
}
@ -123,7 +123,7 @@ void GB::setSaveDir(const std::string &sdir) {
p_->cpu.setSaveDir(sdir);
}
int GB::load(const char *romfiledata, unsigned romfilelength, const std::time_t now, const unsigned flags) {
int GB::load(const char *romfiledata, unsigned romfilelength, const std::uint32_t now, const unsigned flags) {
//if (p_->cpu.loaded())
// p_->cpu.saveSavedata();

View File

@ -22,7 +22,6 @@
#include "sound/sound_unit.h"
#include <algorithm>
#include <cstring>
#include <ctime>
namespace {
@ -1147,7 +1146,7 @@ static void setInitialDmgIoamhram(unsigned char *const ioamhram) {
} // anon namespace
void gambatte::setInitState(SaveState &state, const bool cgb, const bool gbaCgbMode, const std::time_t now) {
void gambatte::setInitState(SaveState &state, const bool cgb, const bool gbaCgbMode, const std::uint32_t now) {
static const unsigned char cgbObjpDump[0x40] = {
0x00, 0x00, 0xF2, 0xAB,
0x61, 0xC2, 0xD9, 0xBA,

Binary file not shown.

View File

@ -94,7 +94,7 @@ public:
const char * romTitle() const { return reinterpret_cast<const char *>(memptrs.romdata() + 0x134); }
void setGameGenie(const std::string &codes);
void setRTCCallback(std::time_t (*callback)()) {
void setRTCCallback(std::uint32_t (*callback)()) {
rtc.setRTCCallback(callback);
}
};

View File

@ -18,6 +18,7 @@
***************************************************************************/
#include "rtc.h"
#include "../savestate.h"
#include <cstdlib>
namespace gambatte {
@ -39,7 +40,7 @@ Rtc::Rtc()
}
void Rtc::doLatch() {
std::time_t tmp = ((dataDh & 0x40) ? haltTime : timeCB()) - baseTime;
std::uint32_t tmp = ((dataDh & 0x40) ? haltTime : timeCB()) - baseTime;
while (tmp > 0x1FF * 86400) {
baseTime += 0x1FF * 86400;
@ -114,8 +115,8 @@ void Rtc::loadState(const SaveState &state) {
}
void Rtc::setDh(const unsigned new_dh) {
const std::time_t unixtime = (dataDh & 0x40) ? haltTime : timeCB();
const std::time_t old_highdays = ((unixtime - baseTime) / 86400) & 0x100;
const std::uint32_t unixtime = (dataDh & 0x40) ? haltTime : timeCB();
const std::uint32_t old_highdays = ((unixtime - baseTime) / 86400) & 0x100;
baseTime += old_highdays * 86400;
baseTime -= ((new_dh & 0x1) << 8) * 86400;
@ -128,28 +129,28 @@ void Rtc::setDh(const unsigned new_dh) {
}
void Rtc::setDl(const unsigned new_lowdays) {
const std::time_t unixtime = (dataDh & 0x40) ? haltTime : timeCB();
const std::time_t old_lowdays = ((unixtime - baseTime) / 86400) & 0xFF;
const std::uint32_t unixtime = (dataDh & 0x40) ? haltTime : timeCB();
const std::uint32_t old_lowdays = ((unixtime - baseTime) / 86400) & 0xFF;
baseTime += old_lowdays * 86400;
baseTime -= new_lowdays * 86400;
}
void Rtc::setH(const unsigned new_hours) {
const std::time_t unixtime = (dataDh & 0x40) ? haltTime : timeCB();
const std::time_t old_hours = ((unixtime - baseTime) / 3600) % 24;
const std::uint32_t unixtime = (dataDh & 0x40) ? haltTime : timeCB();
const std::uint32_t old_hours = ((unixtime - baseTime) / 3600) % 24;
baseTime += old_hours * 3600;
baseTime -= new_hours * 3600;
}
void Rtc::setM(const unsigned new_minutes) {
const std::time_t unixtime = (dataDh & 0x40) ? haltTime : timeCB();
const std::time_t old_minutes = ((unixtime - baseTime) / 60) % 60;
const std::uint32_t unixtime = (dataDh & 0x40) ? haltTime : timeCB();
const std::uint32_t old_minutes = ((unixtime - baseTime) / 60) % 60;
baseTime += old_minutes * 60;
baseTime -= new_minutes * 60;
}
void Rtc::setS(const unsigned new_seconds) {
const std::time_t unixtime = (dataDh & 0x40) ? haltTime : timeCB();
const std::uint32_t unixtime = (dataDh & 0x40) ? haltTime : timeCB();
baseTime += (unixtime - baseTime) % 60;
baseTime -= new_seconds;
}

View File

@ -19,7 +19,7 @@
#ifndef RTC_H
#define RTC_H
#include <ctime>
#include <cstdint>
namespace gambatte {
@ -29,8 +29,8 @@ class Rtc {
private:
unsigned char *activeData;
void (Rtc::*activeSet)(unsigned);
std::time_t baseTime;
std::time_t haltTime;
std::uint32_t baseTime;
std::uint32_t haltTime;
unsigned char index;
unsigned char dataDh;
unsigned char dataDl;
@ -39,7 +39,7 @@ private:
unsigned char dataS;
bool enabled;
bool lastLatchData;
std::time_t (*timeCB)();
std::uint32_t (*timeCB)();
void doLatch();
void doSwapActive();
@ -53,9 +53,9 @@ public:
Rtc();
const unsigned char* getActive() const { return activeData; }
std::time_t getBaseTime() const { return baseTime; }
std::uint32_t getBaseTime() const { return baseTime; }
void setBaseTime(const std::time_t baseTime) {
void setBaseTime(const std::uint32_t baseTime) {
this->baseTime = baseTime;
// doLatch();
}
@ -86,7 +86,7 @@ public:
*activeData = data;
}
void setRTCCallback(std::time_t (*callback)()) {
void setRTCCallback(std::uint32_t (*callback)()) {
timeCB = callback;
}
};

View File

@ -183,7 +183,7 @@ public:
display.setScanlineCallback(callback, sl);
}
void setRTCCallback(std::time_t (*callback)()) {
void setRTCCallback(std::uint32_t (*callback)()) {
cart.setRTCCallback(callback);
}

View File

@ -19,7 +19,7 @@
#ifndef SAVESTATE_H
#define SAVESTATE_H
#include <ctime>
#include <cstdint>
namespace gambatte {
@ -38,7 +38,7 @@ struct SaveState {
void set(T *ptr, const unsigned long sz) { this->ptr = ptr; this->sz = sz; }
friend class SaverList;
friend void setInitState(SaveState &, bool, bool, std::time_t);
friend void setInitState(SaveState &, bool, bool, std::uint32_t);
};
struct CPU {

Binary file not shown.