Compare commits

..

1 Commits

Author SHA1 Message Date
Felix Jones 37d10385a3
Merge 536c34c9ad into 4007e19736 2024-12-29 21:12:56 -08:00
5 changed files with 29 additions and 188 deletions

View File

@ -19,7 +19,7 @@ Other fixes:
- Core: Fix inconsistencies with setting game-specific overrides (fixes mgba.io/i/2963)
- Debugger: Fix writing to specific segment in command-line debugger
- FFmpeg: Fix failing to record videos with CRF video (fixes mgba.io/i/3368)
- GB Core: Fix cloning savedata when backing file is outdated (fixes mgba.io/i/3388)
- GB Serialize: Prevent loading invalid states where LY >= 144 in modes other than 1
- GBA: Fix getting game info for multiboot ROMs
- GBA Core: Fix booting into BIOS when skip BIOS is enabled
- GBA Hardware: Fix loading states unconditionally overwriting GPIO memory

View File

@ -769,7 +769,7 @@ static int64_t _addCallbackToBreakpoint(struct mScriptDebugger* debugger, struct
return cbid;
}
static void _runCallbacks(struct mScriptDebugger* debugger, struct mScriptBreakpoint* point, struct mScriptValue* info) {
static void _runCallbacks(struct mScriptDebugger* debugger, struct mScriptBreakpoint* point) {
struct TableIterator iter;
if (!HashTableIteratorStart(&point->callbacks, &iter)) {
return;
@ -778,7 +778,6 @@ static void _runCallbacks(struct mScriptDebugger* debugger, struct mScriptBreakp
struct mScriptValue* fn = HashTableIteratorGetValue(&point->callbacks, &iter);
struct mScriptFrame frame;
mScriptFrameInit(&frame);
mSCRIPT_PUSH(&frame.stack, WTABLE, info);
mScriptContextInvoke(debugger->p->context, fn, &frame);
mScriptFrameDeinit(&frame);
} while (HashTableIteratorNext(&point->callbacks, &iter));
@ -827,50 +826,7 @@ static void _scriptDebuggerEntered(struct mDebuggerModule* debugger, enum mDebug
return;
}
struct mScriptValue cbInfo = {
.refs = mSCRIPT_VALUE_UNREF,
.flags = 0,
.type = mSCRIPT_TYPE_MS_TABLE,
};
cbInfo.type->alloc(&cbInfo);
static struct mScriptValue keyAddress = mSCRIPT_MAKE_CHARP("address");
static struct mScriptValue keyWidth = mSCRIPT_MAKE_CHARP("width");
static struct mScriptValue keySegment = mSCRIPT_MAKE_CHARP("segment");
static struct mScriptValue keyOldValue = mSCRIPT_MAKE_CHARP("oldValue");
static struct mScriptValue keyNewValue = mSCRIPT_MAKE_CHARP("newValue");
static struct mScriptValue keyAccessType = mSCRIPT_MAKE_CHARP("accessType");
struct mScriptValue valAddress = mSCRIPT_MAKE_U32(info->address);
struct mScriptValue valWidth = mSCRIPT_MAKE_S32(info->width);
struct mScriptValue valSegment = mSCRIPT_MAKE_S32(info->segment);
struct mScriptValue valOldValue;
struct mScriptValue valNewValue;
struct mScriptValue valAccessType;
mScriptTableInsert(&cbInfo, &keyAddress, &valAddress);
if (info->width > 0) {
mScriptTableInsert(&cbInfo, &keyWidth, &valWidth);
}
if (info->segment >= 0) {
mScriptTableInsert(&cbInfo, &keySegment, &valSegment);
}
if (reason == DEBUGGER_ENTER_WATCHPOINT) {
valOldValue = mSCRIPT_MAKE_S32(info->type.wp.oldValue);
valNewValue = mSCRIPT_MAKE_S32(info->type.wp.newValue);
valAccessType = mSCRIPT_MAKE_S32(info->type.wp.accessType);
mScriptTableInsert(&cbInfo, &keyOldValue, &valOldValue);
if (info->type.wp.accessType != WATCHPOINT_READ) {
mScriptTableInsert(&cbInfo, &keyNewValue, &valNewValue);
}
mScriptTableInsert(&cbInfo, &keyAccessType, &valAccessType);
}
_runCallbacks(scriptDebugger, point, &cbInfo);
cbInfo.type->free(&cbInfo);
_runCallbacks(scriptDebugger, point);
debugger->isPaused = false;
}

View File

@ -249,16 +249,9 @@ static int _loadPNGChunkHandler(png_structp png, png_unknown_chunkp chunk) {
}
const uint8_t* data = chunk->data;
data += sizeof(uint32_t) * 2;
if (uncompress((Bytef*) item.data, &len, data, chunk->size) == Z_OK) {
if (item.size != len) {
mLOG(SAVESTATE, WARN, "Mismatched decompressed extdata %i size (%"PRIz"u vs %"PRIz"u)", tag, item.size, (size_t) len);
item.size = len;
}
mStateExtdataPut(extdata, tag, &item);
} else {
mLOG(SAVESTATE, WARN, "Failed to decompress extdata chunk");
free(item.data);
}
uncompress((Bytef*) item.data, &len, data, chunk->size);
item.size = len;
mStateExtdataPut(extdata, tag, &item);
return 1;
}
return 0;
@ -327,7 +320,7 @@ static void* _loadPNGState(struct mCore* core, struct VFile* vf, struct mStateEx
return state;
}
static bool _loadPNGExtdata(struct VFile* vf, struct mStateExtdata* extdata) {
static bool _loadPNGExtadata(struct VFile* vf, struct mStateExtdata* extdata) {
png_structp png = PNGReadOpen(vf, PNG_HEADER_BYTES);
png_infop info = png_create_info_struct(png);
png_infop end = png_create_info_struct(png);
@ -518,7 +511,7 @@ void* mCoreExtractState(struct mCore* core, struct VFile* vf, struct mStateExtda
bool mCoreExtractExtdata(struct mCore* core, struct VFile* vf, struct mStateExtdata* extdata) {
#ifdef USE_PNG
if (isPNG(vf)) {
return _loadPNGExtdata(vf, extdata);
return _loadPNGExtadata(vf, extdata);
}
#endif
if (!core) {

View File

@ -365,10 +365,8 @@ M_TEST_DEFINE(basicBreakpointGBA) {
TEST_PROGRAM(
"hit = 0\n"
"address = nil\n"
"function bkpt(info)\n"
"function bkpt()\n"
" hit = hit + 1\n"
" address = info.address\n"
"end"
);
TEST_PROGRAM("cbid = emu:setBreakpoint(bkpt, 0x020000C4)");
@ -381,7 +379,6 @@ M_TEST_DEFINE(basicBreakpointGBA) {
assert_int_equal(debugger.state, DEBUGGER_RUNNING);
TEST_PROGRAM("assert(hit >= 1)");
TEST_PROGRAM("assert(address == 0x020000C4)");
mScriptContextDeinit(&context);
TEARDOWN_CORE;
@ -407,10 +404,8 @@ M_TEST_DEFINE(basicBreakpointGB) {
TEST_PROGRAM(
"hit = 0\n"
"address = nil\n"
"function bkpt(info)\n"
"function bkpt()\n"
" hit = hit + 1\n"
" address = info.address\n"
"end"
);
TEST_PROGRAM("cbid = emu:setBreakpoint(bkpt, 0xF0)");
@ -423,7 +418,6 @@ M_TEST_DEFINE(basicBreakpointGB) {
assert_int_equal(debugger.state, DEBUGGER_RUNNING);
TEST_PROGRAM("assert(hit >= 1)");
TEST_PROGRAM("assert(address == 0xF0)");
mScriptContextDeinit(&context);
TEARDOWN_CORE;
@ -447,22 +441,11 @@ M_TEST_DEFINE(multipleBreakpoint) {
TEST_PROGRAM(
"hit = 0\n"
"address = nil\n"
"function bkpt1(info)\n"
"function bkpt1()\n"
" hit = hit + 1\n"
" if address then\n"
" address = (address + info.address) / 2\n"
" else\n"
" address = info.address\n"
" end\n"
"end\n"
"function bkpt2(info)\n"
"function bkpt2()\n"
" hit = hit + 100\n"
" if address then\n"
" address = (address + info.address) / 2\n"
" else\n"
" address = info.address\n"
" end\n"
"end"
);
#ifdef M_CORE_GBA
@ -482,13 +465,6 @@ M_TEST_DEFINE(multipleBreakpoint) {
assert_int_equal(debugger.state, DEBUGGER_RUNNING);
TEST_PROGRAM("assert(hit >= 101)");
#ifdef M_CORE_GBA
TEST_PROGRAM("assert(address >= 0x020000C4)");
TEST_PROGRAM("assert(address <= 0x020000C8)");
#else
TEST_PROGRAM("assert(address >= 0xF0)");
TEST_PROGRAM("assert(address <= 0xF1)");
#endif
mScriptContextDeinit(&context);
TEARDOWN_CORE;
@ -503,28 +479,13 @@ M_TEST_DEFINE(basicWatchpoint) {
core->reset(core);
mScriptContextAttachCore(&context, core);
int i;
for (i = 0; i < 4; ++i) {
core->busWrite8(core, RAM_BASE + i, i + 1);
}
mDebuggerInit(&debugger);
mDebuggerAttach(&debugger, core);
TEST_PROGRAM(
"hit = 0\n"
"address = nil\n"
"width = nil\n"
"oldValue = nil\n"
"newValue = nil\n"
"accessType = nil\n"
"function bkpt(info)\n"
"function bkpt()\n"
" hit = hit + 1\n"
" address = info.address\n"
" width = info.width\n"
" oldValue = info.oldValue\n"
" newValue = info.newValue\n"
" accessType = info.accessType\n"
"end"
);
struct mScriptValue base = mSCRIPT_MAKE_S32(RAM_BASE);
@ -538,13 +499,7 @@ M_TEST_DEFINE(basicWatchpoint) {
uint8_t value;
// Read
TEST_PROGRAM(
"hit = 0\n"
"address = nil\n"
"width = nil\n"
"oldValue = nil\n"
"newValue = nil\n"
"accessType = nil\n");
TEST_PROGRAM("hit = 0");
value = core->rawRead8(core, RAM_BASE, -1);
TEST_PROGRAM("assert(hit == 0)");
core->busRead8(core, RAM_BASE);
@ -553,71 +508,31 @@ M_TEST_DEFINE(basicWatchpoint) {
TEST_PROGRAM("assert(hit == 1)");
core->busWrite8(core, RAM_BASE, ~value);
TEST_PROGRAM("assert(hit == 1)");
TEST_PROGRAM("assert(address == base)");
TEST_PROGRAM("assert(width == 1)");
TEST_PROGRAM("assert(oldValue == 1)");
TEST_PROGRAM("assert(newValue == nil)");
TEST_PROGRAM("assert(accessType == C.WATCHPOINT_TYPE.READ)");
// Write
TEST_PROGRAM(
"hit = 0\n"
"address = nil\n"
"width = nil\n"
"oldValue = nil\n"
"newValue = nil\n"
"accessType = nil\n");
TEST_PROGRAM("hit = 0");
value = core->rawRead8(core, RAM_BASE + 1, -1);
TEST_PROGRAM("assert(hit == 0)");
core->busRead8(core, RAM_BASE + 1);
TEST_PROGRAM("assert(hit == 0)");
core->busWrite8(core, RAM_BASE + 1, value);
TEST_PROGRAM("assert(hit == 1)");
TEST_PROGRAM("assert(oldValue == 2)");
TEST_PROGRAM("assert(newValue == 2)");
core->busWrite8(core, RAM_BASE + 1, ~value);
TEST_PROGRAM("assert(hit == 2)");
TEST_PROGRAM("assert(address == base + 1)");
TEST_PROGRAM("assert(width == 1)");
TEST_PROGRAM("assert(oldValue == 2)");
TEST_PROGRAM("assert(newValue == -3)");
TEST_PROGRAM("assert(accessType == C.WATCHPOINT_TYPE.WRITE)");
// RW
TEST_PROGRAM(
"hit = 0\n"
"address = nil\n"
"width = nil\n"
"oldValue = nil\n"
"newValue = nil\n"
"accessType = nil\n");
TEST_PROGRAM("hit = 0");
value = core->rawRead8(core, RAM_BASE + 2, -1);
TEST_PROGRAM("assert(hit == 0)");
core->busRead8(core, RAM_BASE + 2);
TEST_PROGRAM("assert(accessType == C.WATCHPOINT_TYPE.READ)");
TEST_PROGRAM("assert(hit == 1)");
TEST_PROGRAM("assert(oldValue == 3)");
TEST_PROGRAM("assert(newValue == nil)");
core->busWrite8(core, RAM_BASE + 2, value);
TEST_PROGRAM("assert(hit == 2)");
TEST_PROGRAM("assert(oldValue == 3)");
TEST_PROGRAM("assert(newValue == 3)");
core->busWrite8(core, RAM_BASE + 2, ~value);
TEST_PROGRAM("assert(hit == 3)");
TEST_PROGRAM("assert(address == base + 2)");
TEST_PROGRAM("assert(width == 1)");
TEST_PROGRAM("assert(oldValue == 3)");
TEST_PROGRAM("assert(newValue == -4)");
TEST_PROGRAM("assert(accessType == C.WATCHPOINT_TYPE.WRITE)");
// Change
TEST_PROGRAM(
"hit = 0\n"
"address = nil\n"
"width = nil\n"
"oldValue = nil\n"
"newValue = nil\n"
"accessType = nil\n");
TEST_PROGRAM("hit = 0");
value = core->rawRead8(core, RAM_BASE + 3, -1);
TEST_PROGRAM("assert(hit == 0)");
core->busRead8(core, RAM_BASE + 3);
@ -626,11 +541,6 @@ M_TEST_DEFINE(basicWatchpoint) {
TEST_PROGRAM("assert(hit == 0)");
core->busWrite8(core, RAM_BASE + 3, ~value);
TEST_PROGRAM("assert(hit == 1)");
TEST_PROGRAM("assert(address == base + 3)");
TEST_PROGRAM("assert(width == 1)");
TEST_PROGRAM("assert(oldValue == 4)");
TEST_PROGRAM("assert(newValue == -5)");
TEST_PROGRAM("assert(accessType == C.WATCHPOINT_TYPE.WRITE)");
mScriptContextDeinit(&context);
TEARDOWN_CORE;
@ -818,10 +728,8 @@ M_TEST_DEFINE(rangeWatchpoint) {
TEST_PROGRAM(
"hit = 0\n"
"address = nil\n"
"function bkpt(info)\n"
"function bkpt()\n"
" hit = hit + 1\n"
" address = info.address\n"
"end"
);
struct mScriptValue base = mSCRIPT_MAKE_S32(RAM_BASE);
@ -833,13 +741,10 @@ M_TEST_DEFINE(rangeWatchpoint) {
TEST_PROGRAM("assert(hit == 0)");
core->busRead8(core, RAM_BASE);
TEST_PROGRAM("assert(hit == 1)");
TEST_PROGRAM("assert(address == base)");
core->busRead8(core, RAM_BASE + 1);
TEST_PROGRAM("assert(hit == 3)");
TEST_PROGRAM("assert(address == base + 1)");
core->busRead8(core, RAM_BASE + 2);
TEST_PROGRAM("assert(hit == 4)");
TEST_PROGRAM("assert(address == base + 2)");
mScriptContextDeinit(&context);
TEARDOWN_CORE;

View File

@ -1167,32 +1167,19 @@ static struct mCheatDevice* _GBCoreCheatDevice(struct mCore* core) {
static size_t _GBCoreSavedataClone(struct mCore* core, void** sram) {
struct GB* gb = core->board;
size_t sramSize = gb->sramSize;
size_t vfSize = 0;
size_t size = sramSize;
uint8_t* view = NULL;
if (gb->sramVf) {
vfSize = gb->sramVf->size(gb->sramVf);
if (vfSize > size) {
size = vfSize;
}
struct VFile* vf = gb->sramVf;
if (vf) {
*sram = malloc(vf->size(vf));
vf->seek(vf, 0, SEEK_SET);
return vf->read(vf, *sram, vf->size(vf));
}
if (!size) {
*sram = NULL;
return 0;
if (gb->sramSize) {
*sram = malloc(gb->sramSize);
memcpy(*sram, gb->memory.sram, gb->sramSize);
return gb->sramSize;
}
view = malloc(size);
if (sramSize) {
memcpy(view, gb->memory.sram, gb->sramSize);
}
if (vfSize > sramSize) {
gb->sramVf->seek(gb->sramVf, sramSize, SEEK_SET);
gb->sramVf->read(gb->sramVf, &view[sramSize], vfSize - sramSize);
}
*sram = view;
return size;
*sram = NULL;
return 0;
}
static bool _GBCoreSavedataRestore(struct mCore* core, const void* sram, size_t size, bool writeback) {