diff --git a/cpu.c b/cpu.c index 31ca8e6..31ef3f6 100644 --- a/cpu.c +++ b/cpu.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - #include +#include #include "cpu.h" #include "hw.h" #include "hal.h" @@ -835,7 +835,7 @@ static void op_retd_cb(u8_t arg0, u8_t arg1) sp = (sp + 3) & 0xFF; SET_M(x, arg0 & 0xF); SET_M(x + 1, (arg0 >> 4) & 0xF); - x = (x + 2) & 0xFFF; + x = ((x + 2) & 0xFF) | (XP << 8); call_depth--; } @@ -854,12 +854,12 @@ static void op_halt_cb(u8_t arg0, u8_t arg1) static void op_inc_x_cb(u8_t arg0, u8_t arg1) { - x = (x + 1) & 0xFFF; + x = ((x + 1) & 0xFF) | (XP << 8); } static void op_inc_y_cb(u8_t arg0, u8_t arg1) { - y = (y + 1) & 0xFFF; + y = ((y + 1) & 0xFF) | (YP << 8); } static void op_ld_x_cb(u8_t arg0, u8_t arg1) @@ -1029,32 +1029,32 @@ static void op_ld_mn_b_cb(u8_t arg0, u8_t arg1) static void op_ldpx_mx_cb(u8_t arg0, u8_t arg1) { SET_M(x, arg0); - x = (x + 1) & 0xFFF; + x = ((x + 1) & 0xFF) | (XP << 8); } static void op_ldpx_r_cb(u8_t arg0, u8_t arg1) { SET_RQ(arg0, RQ(arg1)); - x = (x + 1) & 0xFFF; + x = ((x + 1) & 0xFF) | (XP << 8); } static void op_ldpy_my_cb(u8_t arg0, u8_t arg1) { SET_M(y, arg0); - y = (y + 1) & 0xFFF; + y = ((y + 1) & 0xFF) | (YP << 8); } static void op_ldpy_r_cb(u8_t arg0, u8_t arg1) { SET_RQ(arg0, RQ(arg1)); - y = (y + 1) & 0xFFF; + y = ((y + 1) & 0xFF) | (YP << 8); } static void op_lbpx_cb(u8_t arg0, u8_t arg1) { SET_M(x, arg0 & 0xF); SET_M(x + 1, (arg0 >> 4) & 0xF); - x = (x + 2) & 0xFFF; + x = ((x + 2) & 0xFF) | (XP << 8); } static void op_set_cb(u8_t arg0, u8_t arg1) @@ -1483,7 +1483,7 @@ static void op_acpx_cb(u8_t arg0, u8_t arg1) if (tmp >> 4) { SET_C(); } else { CLEAR_C(); } } if (!M(x)) { SET_Z(); } else { CLEAR_Z(); } - x = (x + 1) & 0xFFF; + x = ((x + 1) & 0xFF) | (XP << 8); } static void op_acpy_cb(u8_t arg0, u8_t arg1) @@ -1504,7 +1504,7 @@ static void op_acpy_cb(u8_t arg0, u8_t arg1) if (tmp >> 4) { SET_C(); } else { CLEAR_C(); } } if (!M(y)) { SET_Z(); } else { CLEAR_Z(); } - y = (y + 1) & 0xFFF; + y = ((y + 1) & 0xFF) | (YP << 8); } static void op_scpx_cb(u8_t arg0, u8_t arg1) @@ -1523,7 +1523,7 @@ static void op_scpx_cb(u8_t arg0, u8_t arg1) } if (tmp >> 4) { SET_C(); } else { CLEAR_C(); } if (!M(x)) { SET_Z(); } else { CLEAR_Z(); } - x = (x + 1) & 0xFFF; + x = ((x + 1) & 0xFF) | (XP << 8); } static void op_scpy_cb(u8_t arg0, u8_t arg1) @@ -1542,7 +1542,7 @@ static void op_scpy_cb(u8_t arg0, u8_t arg1) } if (tmp >> 4) { SET_C(); } else { CLEAR_C(); } if (!M(y)) { SET_Z(); } else { CLEAR_Z(); } - y = (y + 1) & 0xFFF; + y = ((y + 1) & 0xFF) | (YP << 8); } static void op_not_cb(u8_t arg0, u8_t arg1)