all repos — mgba @ 5031ef7c39843dea17fc2df03f3d7e704c5261ff

mGBA Game Boy Advance Emulator

LR35902: Fix decoding LD r, $imm and 0-valued immediates (fixes #735)
Vicki Pfau vi@endrift.com
Wed, 17 May 2017 13:47:43 -0700
commit

5031ef7c39843dea17fc2df03f3d7e704c5261ff

parent

96ac3752767923535052840ec978bbd3d873236c

2 files changed, 11 insertions(+), 10 deletions(-)

jump to
M CHANGESCHANGES

@@ -56,6 +56,7 @@ - Test: Fix crash when loading invalid file

- GBA Hardware: Fix crash if a savestate lies about game hardware - Test: Fix crash when fuzzing fails to load a file - Qt: Disable "New multiplayer window" when MAX_GBAS is reached (fixes mgba.io/i/107) + - LR35902: Fix decoding LD r, $imm and 0-valued immediates (fixes mgba.io/i/735) Misc: - SDL: Remove scancode key input - GBA Video: Clean up unused timers
M src/lr35902/decoder.csrc/lr35902/decoder.c

@@ -66,8 +66,7 @@ #define DEFINE_LD_DECODER_LR35902(NAME) \

DEFINE_LD_DECODER_LR35902_MEM(NAME, HL) \ DEFINE_LD_DECODER_LR35902_MEM_2(NAME, HL) \ DEFINE_DECODER_LR35902(LD ## NAME ## _, info->mnemonic = LR35902_MN_LD; \ - info->op1.reg = LR35902_REG_A; \ - info->op1.flags = LR35902_OP_FLAG_IMPLICIT; \ + info->op1.reg = LR35902_REG_ ## NAME; \ return 1;) \ DEFINE_LD_DECODER_LR35902_NOHL(NAME)

@@ -500,17 +499,16 @@ if (op.flags & LR35902_OP_FLAG_MEMORY) {

strncpy(buffer, "(", blen - 1); ADVANCE(1); } - if (op.immediate) { + if (op.reg) { + int written = snprintf(buffer, blen - 1, "%s", _lr35902Registers[op.reg]); + ADVANCE(written); + } else { int written = snprintf(buffer, blen - 1, "$%02X", op.immediate); ADVANCE(written); if (op.reg) { strncpy(buffer, "+", blen - 1); ADVANCE(1); } - } - if (op.reg) { - int written = snprintf(buffer, blen - 1, "%s", _lr35902Registers[op.reg]); - ADVANCE(written); } if (op.flags & LR35902_OP_FLAG_INCREMENT) { strncpy(buffer, "+", blen - 1);

@@ -546,10 +544,12 @@ ADVANCE(2);

} } - written = _decodeOperand(info->op1, buffer, blen); - ADVANCE(written); + if (info->op1.reg || info->op1.immediate) { + written = _decodeOperand(info->op1, buffer, blen); + ADVANCE(written); + } - if (info->op2.reg || info->op2.immediate) { + if (info->op2.reg || (!info->op1.immediate && info->opcodeSize > 1 && info->opcode[0] != 0xCB)) { if (written) { strncpy(buffer, ", ", blen - 1); ADVANCE(2);