int done = FALSE;
int ret;
unsigned char data;
+ unsigned char old_carry;
ret = load_addr_mode(&done);
if (!ret)
return TRUE;
data = get_cpu_data_buf();
+ old_carry = cpu_reg.status.carry;
//signed, unsigned overflow check.
set_ADD_carry(cpu_reg.acc, cpu_reg.status.carry, data);
set_ADD_overflow(cpu_reg.acc, cpu_reg.status.carry, data);
//add data with carry to accumurator.
- cpu_reg.acc += data + cpu_reg.status.carry;
+ cpu_reg.acc += data + old_carry;
// N/Z flags set.
set_negative(cpu_reg.acc);
if (current_inst->addr_mode == ADDR_MODE_ACC) {
unsigned char op_data = cpu_reg.acc;
//set carry flag from the pre-opration value.
- cpu_reg.status.carry = ((op_data & 0x80) > 0);
+ cpu_reg.status.carry = ((op_data & 0x80) != 0);
cpu_reg.acc = (op_data << 1);
set_negative(cpu_reg.acc);
set_zero(cpu_reg.acc);
if (operation) {
unsigned char op_data = get_cpu_data_buf();
//set carry flag from the pre-opration value.
- cpu_reg.status.carry = ((op_data & 0x80) > 0);
+ cpu_reg.status.carry = ((op_data & 0x80) != 0);
op_data = (op_data << 1);
set_cpu_data_buf(op_data);
return TRUE;
if (current_inst->addr_mode == ADDR_MODE_ACC) {
unsigned char op_data = cpu_reg.acc;
+ unsigned char old_carry = cpu_reg.status.carry;
+
//set carry flag from the pre-opration value.
- cpu_reg.status.carry = ((op_data & 0x80) > 0);
+ cpu_reg.status.carry = ((op_data & 0x80) != 0);
cpu_reg.acc = (op_data << 1);
- if (cpu_reg.status.carry)
+ if (old_carry)
cpu_reg.acc |= 0x01;
set_negative(cpu_reg.acc);
set_zero(cpu_reg.acc);
if (operation) {
unsigned char op_data = get_cpu_data_buf();
+ unsigned char old_carry = cpu_reg.status.carry;
+
//set carry flag from the pre-opration value.
- cpu_reg.status.carry = ((op_data & 0x80) > 0);
+ cpu_reg.status.carry = ((op_data & 0x80) != 0);
op_data = (op_data << 1);
- if (cpu_reg.status.carry)
+ if (old_carry)
op_data |= 0x01;
set_cpu_data_buf(op_data);
return TRUE;
if (current_inst->addr_mode == ADDR_MODE_ACC) {
unsigned char op_data = cpu_reg.acc;
+ unsigned char old_carry = cpu_reg.status.carry;
+
//set carry flag from the pre-opration value.
cpu_reg.status.carry = (op_data & 0x01);
cpu_reg.acc = (op_data >> 1);
- if (cpu_reg.status.carry)
+ if (old_carry)
cpu_reg.acc |= 0x80;
set_negative(cpu_reg.acc);
set_zero(cpu_reg.acc);
if (operation) {
unsigned char op_data = get_cpu_data_buf();
+ unsigned char old_carry = cpu_reg.status.carry;
+
//set carry flag from the pre-opration value.
cpu_reg.status.carry = (op_data & 0x01);
op_data = (op_data >> 1);
- if (cpu_reg.status.carry)
+ if (old_carry)
op_data |= 0x80;
set_cpu_data_buf(op_data);
return TRUE;
{
//step 3, push status_reg
unsigned char stat;
- memcpy(&stat, &cpu_reg, sizeof(stat));
+ memcpy(&stat, &cpu_reg.status, sizeof(stat));
push(stat);
return TRUE;
}