mirror of https://github.com/mgba-emu/mgba.git
Core: Add romSize function
This commit is contained in:
parent
71f74d25b0
commit
57880bf674
|
@ -86,6 +86,7 @@ struct mCore {
|
||||||
bool (*loadSave)(struct mCore*, struct VFile* vf);
|
bool (*loadSave)(struct mCore*, struct VFile* vf);
|
||||||
bool (*loadTemporarySave)(struct mCore*, struct VFile* vf);
|
bool (*loadTemporarySave)(struct mCore*, struct VFile* vf);
|
||||||
void (*unloadROM)(struct mCore*);
|
void (*unloadROM)(struct mCore*);
|
||||||
|
size_t (*romSize)(const struct mCore*);
|
||||||
void (*checksum)(const struct mCore*, void* data, enum mCoreChecksumType type);
|
void (*checksum)(const struct mCore*, void* data, enum mCoreChecksumType type);
|
||||||
|
|
||||||
bool (*loadBIOS)(struct mCore*, struct VFile* vf, int biosID);
|
bool (*loadBIOS)(struct mCore*, struct VFile* vf, int biosID);
|
||||||
|
|
|
@ -424,6 +424,7 @@ mSCRIPT_DECLARE_STRUCT_CD_METHOD(mCore, S32, frameCycles, 0);
|
||||||
mSCRIPT_DECLARE_STRUCT_CD_METHOD(mCore, S32, frequency, 0);
|
mSCRIPT_DECLARE_STRUCT_CD_METHOD(mCore, S32, frequency, 0);
|
||||||
mSCRIPT_DECLARE_STRUCT_C_METHOD(mCore, WSTR, getGameTitle, _mScriptCoreGetGameTitle, 0);
|
mSCRIPT_DECLARE_STRUCT_C_METHOD(mCore, WSTR, getGameTitle, _mScriptCoreGetGameTitle, 0);
|
||||||
mSCRIPT_DECLARE_STRUCT_C_METHOD(mCore, WSTR, getGameCode, _mScriptCoreGetGameCode, 0);
|
mSCRIPT_DECLARE_STRUCT_C_METHOD(mCore, WSTR, getGameCode, _mScriptCoreGetGameCode, 0);
|
||||||
|
mSCRIPT_DECLARE_STRUCT_CD_METHOD(mCore, S64, romSize, 0);
|
||||||
mSCRIPT_DECLARE_STRUCT_C_METHOD_WITH_DEFAULTS(mCore, WSTR, checksum, _mScriptCoreChecksum, 1, S32, type);
|
mSCRIPT_DECLARE_STRUCT_C_METHOD_WITH_DEFAULTS(mCore, WSTR, checksum, _mScriptCoreChecksum, 1, S32, type);
|
||||||
|
|
||||||
// Run functions
|
// Run functions
|
||||||
|
@ -483,6 +484,8 @@ mSCRIPT_DEFINE_STRUCT(mCore)
|
||||||
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, frameCycles)
|
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, frameCycles)
|
||||||
mSCRIPT_DEFINE_DOCSTRING("Get the number of cycles per second")
|
mSCRIPT_DEFINE_DOCSTRING("Get the number of cycles per second")
|
||||||
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, frequency)
|
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, frequency)
|
||||||
|
mSCRIPT_DEFINE_DOCSTRING("Get the size of the loaded ROM")
|
||||||
|
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, romSize)
|
||||||
mSCRIPT_DEFINE_DOCSTRING("Get the checksum of the loaded ROM")
|
mSCRIPT_DEFINE_DOCSTRING("Get the checksum of the loaded ROM")
|
||||||
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, checksum)
|
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, checksum)
|
||||||
|
|
||||||
|
|
|
@ -473,8 +473,16 @@ static void _GBCoreUnloadROM(struct mCore* core) {
|
||||||
GBUnloadROM(core->board);
|
GBUnloadROM(core->board);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static size_t _GBCoreROMSize(const struct mCore* core) {
|
||||||
|
const struct GB* gb = (const struct GB*) core->board;
|
||||||
|
if (gb->romVf) {
|
||||||
|
return gb->romVf->size(gb->romVf);
|
||||||
|
}
|
||||||
|
return gb->pristineRomSize;
|
||||||
|
}
|
||||||
|
|
||||||
static void _GBCoreChecksum(const struct mCore* core, void* data, enum mCoreChecksumType type) {
|
static void _GBCoreChecksum(const struct mCore* core, void* data, enum mCoreChecksumType type) {
|
||||||
struct GB* gb = (struct GB*) core->board;
|
const struct GB* gb = (const struct GB*) core->board;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case mCHECKSUM_CRC32:
|
case mCHECKSUM_CRC32:
|
||||||
memcpy(data, &gb->romCrc32, sizeof(gb->romCrc32));
|
memcpy(data, &gb->romCrc32, sizeof(gb->romCrc32));
|
||||||
|
@ -1237,6 +1245,7 @@ struct mCore* GBCoreCreate(void) {
|
||||||
core->loadTemporarySave = _GBCoreLoadTemporarySave;
|
core->loadTemporarySave = _GBCoreLoadTemporarySave;
|
||||||
core->loadPatch = _GBCoreLoadPatch;
|
core->loadPatch = _GBCoreLoadPatch;
|
||||||
core->unloadROM = _GBCoreUnloadROM;
|
core->unloadROM = _GBCoreUnloadROM;
|
||||||
|
core->romSize = _GBCoreROMSize;
|
||||||
core->checksum = _GBCoreChecksum;
|
core->checksum = _GBCoreChecksum;
|
||||||
core->reset = _GBCoreReset;
|
core->reset = _GBCoreReset;
|
||||||
core->runFrame = _GBCoreRunFrame;
|
core->runFrame = _GBCoreRunFrame;
|
||||||
|
|
|
@ -568,8 +568,16 @@ static void _GBACoreUnloadROM(struct mCore* core) {
|
||||||
GBAUnloadROM(core->board);
|
GBAUnloadROM(core->board);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static size_t _GBACoreROMSize(const struct mCore* core) {
|
||||||
|
const struct GBA* gba = (const struct GBA*) core->board;
|
||||||
|
if (gba->romVf) {
|
||||||
|
return gba->romVf->size(gba->romVf);
|
||||||
|
}
|
||||||
|
return gba->pristineRomSize;
|
||||||
|
}
|
||||||
|
|
||||||
static void _GBACoreChecksum(const struct mCore* core, void* data, enum mCoreChecksumType type) {
|
static void _GBACoreChecksum(const struct mCore* core, void* data, enum mCoreChecksumType type) {
|
||||||
struct GBA* gba = (struct GBA*) core->board;
|
const struct GBA* gba = (const struct GBA*) core->board;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case mCHECKSUM_CRC32:
|
case mCHECKSUM_CRC32:
|
||||||
memcpy(data, &gba->romCrc32, sizeof(gba->romCrc32));
|
memcpy(data, &gba->romCrc32, sizeof(gba->romCrc32));
|
||||||
|
@ -1362,6 +1370,7 @@ struct mCore* GBACoreCreate(void) {
|
||||||
core->loadTemporarySave = _GBACoreLoadTemporarySave;
|
core->loadTemporarySave = _GBACoreLoadTemporarySave;
|
||||||
core->loadPatch = _GBACoreLoadPatch;
|
core->loadPatch = _GBACoreLoadPatch;
|
||||||
core->unloadROM = _GBACoreUnloadROM;
|
core->unloadROM = _GBACoreUnloadROM;
|
||||||
|
core->romSize = _GBACoreROMSize;
|
||||||
core->checksum = _GBACoreChecksum;
|
core->checksum = _GBACoreChecksum;
|
||||||
core->reset = _GBACoreReset;
|
core->reset = _GBACoreReset;
|
||||||
core->runFrame = _GBACoreRunFrame;
|
core->runFrame = _GBACoreRunFrame;
|
||||||
|
|
|
@ -9,12 +9,6 @@
|
||||||
#include "CoreController.h"
|
#include "CoreController.h"
|
||||||
|
|
||||||
#include <mgba/core/core.h>
|
#include <mgba/core/core.h>
|
||||||
#ifdef M_CORE_GB
|
|
||||||
#include <mgba/internal/gb/gb.h>
|
|
||||||
#endif
|
|
||||||
#ifdef M_CORE_GBA
|
|
||||||
#include <mgba/internal/gba/gba.h>
|
|
||||||
#endif
|
|
||||||
#ifdef USE_SQLITE3
|
#ifdef USE_SQLITE3
|
||||||
#include "feature/sqlite3/no-intro.h"
|
#include "feature/sqlite3/no-intro.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -46,25 +40,8 @@ ROMInfo::ROMInfo(std::shared_ptr<CoreController> controller, QWidget* parent)
|
||||||
|
|
||||||
core->checksum(core, &crc32, mCHECKSUM_CRC32);
|
core->checksum(core, &crc32, mCHECKSUM_CRC32);
|
||||||
|
|
||||||
switch (controller->thread()->core->platform(controller->thread()->core)) {
|
m_ui.size->setText(QString::number(core->romSize(core)) + tr(" bytes"));
|
||||||
#ifdef M_CORE_GBA
|
|
||||||
case mPLATFORM_GBA: {
|
|
||||||
GBA* gba = static_cast<GBA*>(core->board);
|
|
||||||
m_ui.size->setText(QString::number(gba->pristineRomSize) + tr(" bytes"));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#ifdef M_CORE_GB
|
|
||||||
case mPLATFORM_GB: {
|
|
||||||
GB* gb = static_cast<GB*>(core->board);
|
|
||||||
m_ui.size->setText(QString::number(gb->pristineRomSize) + tr(" bytes"));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
default:
|
|
||||||
m_ui.size->setText(tr("(unknown)"));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (crc32) {
|
if (crc32) {
|
||||||
m_ui.crc->setText(QString::number(crc32, 16));
|
m_ui.crc->setText(QString::number(crc32, 16));
|
||||||
#ifdef USE_SQLITE3
|
#ifdef USE_SQLITE3
|
||||||
|
|
Loading…
Reference in New Issue