Core: Add romSize function

This commit is contained in:
Vicki Pfau 2022-07-02 20:41:12 -07:00
parent 71f74d25b0
commit 57880bf674
5 changed files with 26 additions and 27 deletions

View File

@ -86,6 +86,7 @@ struct mCore {
bool (*loadSave)(struct mCore*, struct VFile* vf);
bool (*loadTemporarySave)(struct mCore*, struct VFile* vf);
void (*unloadROM)(struct mCore*);
size_t (*romSize)(const struct mCore*);
void (*checksum)(const struct mCore*, void* data, enum mCoreChecksumType type);
bool (*loadBIOS)(struct mCore*, struct VFile* vf, int biosID);

View File

@ -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_C_METHOD(mCore, WSTR, getGameTitle, _mScriptCoreGetGameTitle, 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);
// Run functions
@ -483,6 +484,8 @@ mSCRIPT_DEFINE_STRUCT(mCore)
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, frameCycles)
mSCRIPT_DEFINE_DOCSTRING("Get the number of cycles per second")
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_STRUCT_METHOD(mCore, checksum)

View File

@ -473,8 +473,16 @@ static void _GBCoreUnloadROM(struct mCore* core) {
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) {
struct GB* gb = (struct GB*) core->board;
const struct GB* gb = (const struct GB*) core->board;
switch (type) {
case mCHECKSUM_CRC32:
memcpy(data, &gb->romCrc32, sizeof(gb->romCrc32));
@ -1237,6 +1245,7 @@ struct mCore* GBCoreCreate(void) {
core->loadTemporarySave = _GBCoreLoadTemporarySave;
core->loadPatch = _GBCoreLoadPatch;
core->unloadROM = _GBCoreUnloadROM;
core->romSize = _GBCoreROMSize;
core->checksum = _GBCoreChecksum;
core->reset = _GBCoreReset;
core->runFrame = _GBCoreRunFrame;

View File

@ -568,8 +568,16 @@ static void _GBACoreUnloadROM(struct mCore* core) {
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) {
struct GBA* gba = (struct GBA*) core->board;
const struct GBA* gba = (const struct GBA*) core->board;
switch (type) {
case mCHECKSUM_CRC32:
memcpy(data, &gba->romCrc32, sizeof(gba->romCrc32));
@ -1362,6 +1370,7 @@ struct mCore* GBACoreCreate(void) {
core->loadTemporarySave = _GBACoreLoadTemporarySave;
core->loadPatch = _GBACoreLoadPatch;
core->unloadROM = _GBACoreUnloadROM;
core->romSize = _GBACoreROMSize;
core->checksum = _GBACoreChecksum;
core->reset = _GBACoreReset;
core->runFrame = _GBACoreRunFrame;

View File

@ -9,12 +9,6 @@
#include "CoreController.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
#include "feature/sqlite3/no-intro.h"
#endif
@ -46,25 +40,8 @@ ROMInfo::ROMInfo(std::shared_ptr<CoreController> controller, QWidget* parent)
core->checksum(core, &crc32, mCHECKSUM_CRC32);
switch (controller->thread()->core->platform(controller->thread()->core)) {
#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;
}
m_ui.size->setText(QString::number(core->romSize(core)) + tr(" bytes"));
if (crc32) {
m_ui.crc->setText(QString::number(crc32, 16));
#ifdef USE_SQLITE3