From c7aa9e9fc354c2f1a501845ff3b3447b9fa0ffba Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Fri, 5 Jan 2018 14:57:38 -0600 Subject: [PATCH] Resolver may be NULL; don't call if so This change also registers a default value for operand (0). --- src/mos6502.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/mos6502.c b/src/mos6502.c index 1d7deb9..8abc3ee 100644 --- a/src/mos6502.c +++ b/src/mos6502.c @@ -352,7 +352,7 @@ mos6502_get_instruction_handler(vm_8bit opcode) void mos6502_execute(mos6502 *cpu, vm_8bit opcode) { - vm_8bit operand; + vm_8bit operand = 0; int cycles; mos6502_address_resolver resolver; mos6502_instruction_handler handler; @@ -369,7 +369,13 @@ mos6502_execute(mos6502 *cpu, vm_8bit opcode) // side-effect, resolver will set the last_addr field in cpu to the // effective address where the operand can be found in memory, or // zero if that does not apply (such as in immediate mode). - operand = resolver(cpu); + // + // Note also that resolver may be NULL, as there may not be any + // operand for this instruction! If so, we let the default for + // operand stand, which is zero. + if (resolver) { + operand = resolver(cpu); + } // Here's where the magic happens. Whatever the instruction does, it // happens in the handler function.