From c53c7bfd1d244cfab8aea62815dd577f0bcaf864 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Sat, 21 Apr 2018 23:15:48 -0500 Subject: [PATCH] Add function to return true if an instruction would write to memory --- include/mos6502/mos6502.h | 1 + src/mos6502/mos6502.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/mos6502/mos6502.h b/include/mos6502/mos6502.h index ccb9930..dfb4442 100644 --- a/include/mos6502/mos6502.h +++ b/include/mos6502/mos6502.h @@ -166,6 +166,7 @@ typedef vm_8bit (*mos6502_address_resolver)(mos6502 *); typedef void (*mos6502_instruction_handler)(mos6502 *, vm_8bit); extern bool mos6502_would_jump(int); +extern bool mos6502_would_write_mem(int); extern int mos6502_cycles(mos6502 *, vm_8bit); extern int mos6502_instruction(vm_8bit); extern mos6502 *mos6502_create(vm_segment *, vm_segment *); diff --git a/src/mos6502/mos6502.c b/src/mos6502/mos6502.c index b1a5c28..644b307 100644 --- a/src/mos6502/mos6502.c +++ b/src/mos6502/mos6502.c @@ -404,6 +404,22 @@ mos6502_would_jump(int inst_code) inst_code == RTI; } +/* + * Return true if the given instruction _might_ write to memory, if used + * with an appropriate address mode (e.g. anything other than ACC). + */ +inline bool +mos6502_would_write_mem(int inst_code) +{ + return + inst_code == ASL || + inst_code == DEC || + inst_code == INC || + inst_code == LSR || + inst_code == ROL || + inst_code == ROR; +} + /* * This is a _kind_ of factory method, except we're obviously not * instantiating an object. Given an address mode, we return the