Skip to content

Commit

Permalink
famiyirl: SBC absolute/imediat
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Gatto <[email protected]>
  • Loading branch information
cosmo-ray committed Apr 28, 2024
1 parent 93156e4 commit c7199d7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
29 changes: 27 additions & 2 deletions modules/famiyirl/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ static int process_inst(void)
char res = get_mem(addr);
int check_carry = cpu.a + res;

cpu.a += res;
cpu.a += res + (cpu.flag & CARY_FLAG);
SET_CARY(check_carry > 255);
SET_OVERFLOW(old_sign != (cpu.a & 0x80));
SET_NEGATIVE(!!(0x80 & cpu.a));
Expand All @@ -465,14 +465,39 @@ static int process_inst(void)

int check_carry = cpu.a + addr;

cpu.a += addr;
cpu.a += addr + (cpu.flag & CARY_FLAG);
SET_CARY(check_carry > 255);
SET_OVERFLOW(old_sign != (cpu.a & 0x80));
SET_NEGATIVE(!!(0x80 & cpu.a));
SET_ZERO(!cpu.a);
cpu.cycle_cnt += 2;
}
break;
case SBC_ab:
case SBC_im:
{
char res;
if (opcode == SBC_ab) {
int addr = get_mem(++cpu.pc);

addr |= get_mem(++cpu.pc) << 8;
res = get_mem(addr);
cpu.cycle_cnt += 2;
} else {
res = get_mem(++cpu.pc);

}
char old_sign = cpu.a & 0x80;
int check_carry = cpu.a - res - 1 + (cpu.flag & CARY_FLAG);

cpu.a -= res;
SET_CARY(check_carry >= 0);
SET_OVERFLOW(old_sign != (cpu.a & 0x80));
SET_NEGATIVE(!!(0x80 & cpu.a));
SET_ZERO(!cpu.a);
cpu.cycle_cnt += 2;
}
break;
case LDA_addx:
{
unsigned char base_addr = get_mem(++cpu.pc);
Expand Down
3 changes: 2 additions & 1 deletion modules/famiyirl/opcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
OPCODE(BNE, 0xD0) //branch on not equal (zero clear)
OPCODE(CLD, 0xD8) //clear decimal
OPCODE(CPX, 0xE0) //compare with X
OPCODE(SBC, 0xE1) //subtract with carry
OPCODE(SBC_im, 0xE9) //subtract with carry
OPCODE(SBC_ab, 0xEd) //subtract with carry
OPCODE(INX, 0xE8) //increment X
OPCODE(NOP, 0xEA) //no operation
OPCODE(CPX_var, 0xEC) //compare with X
Expand Down

0 comments on commit c7199d7

Please sign in to comment.