summaryrefslogtreecommitdiff
path: root/emu/6502.c
diff options
context:
space:
mode:
Diffstat (limited to 'emu/6502.c')
-rw-r--r--emu/6502.c68
1 files changed, 67 insertions, 1 deletions
diff --git a/emu/6502.c b/emu/6502.c
index e39dc38..877f3f5 100644
--- a/emu/6502.c
+++ b/emu/6502.c
@@ -252,16 +252,41 @@ void cpu_6502_step( cpu_6502_t *cpu )
update_negative_and_sign( cpu, cpu->A );
break;
+ case STX_ZERO:
+ operand8 = cpu_6502_read_byte( cpu, cpu->PC );
+ cpu->PC++;
+ cpu_6502_write_byte( cpu, operand8, cpu->X );
+ break;
+
case STX_ABS:
operand16 = cpu_6502_read_word( cpu, cpu->PC );
cpu->PC += 2;
cpu_6502_write_byte( cpu, operand16, cpu->X );
break;
-
+
+ case DEX_IMPL:
+ cpu->X--;
+ update_negative_and_sign( cpu, cpu->X );
+ break;
+
case DEY_IMPL:
cpu->Y--;
update_negative_and_sign( cpu, cpu->Y );
break;
+
+ case INY_IMPL:
+ cpu->Y++;
+ update_negative_and_sign( cpu, cpu->Y );
+ break;
+
+ case INC_IMPL:
+ operand8 = cpu_6502_read_byte( cpu, cpu->PC );
+ cpu->PC++;
+ tmp = cpu_6502_read_byte( cpu, operand8 );
+ tmp++;
+ cpu_6502_write_byte( cpu, operand8, tmp );
+ update_negative_and_sign( cpu, tmp );
+ break;
case ROL_ACC:
tmp = ( cpu->A << 1 ) | is_carry( cpu );
@@ -274,6 +299,36 @@ void cpu_6502_step( cpu_6502_t *cpu )
update_negative_and_sign( cpu, cpu->A );
break;
+ case CPX_IMM:
+ operand8 = cpu_6502_read_byte( cpu, cpu->PC );
+ cpu->PC++;
+ tmp = ( cpu->X - operand8 ) & 0xFF;
+ if( cpu->X >= operand8 ) {
+ cpu->PS |= PS_C;
+ } else {
+ cpu->PS &= ~PS_C;
+ }
+ update_negative_and_sign( cpu, tmp );
+ break;
+
+ case SBC_IMM:
+ operand8 = cpu_6502_read_byte( cpu, cpu->PC );
+ cpu->PC++;
+ tmp = cpu->A - operand8 - ( is_carry( cpu ) ? 0 : 1 );
+ update_negative_and_sign( cpu, tmp );
+ if( tmp & 0xFF00 ) {
+ cpu->PS |= PS_C;
+ } else {
+ cpu->PS &= ~PS_C;
+ }
+ if( ( ( cpu->A ^ tmp ) & 0x80 ) && ( ( cpu->A ^ operand8 ) & 0x80 ) ) {
+ cpu->PS |= PS_V;
+ } else {
+ cpu->PS &= ~PS_V;
+ }
+ cpu->A = tmp & 0xFF;
+ break;
+
case BNE_REL:
operand8 = cpu_6502_read_byte( cpu, cpu->PC );
cpu->PC++;
@@ -289,6 +344,14 @@ void cpu_6502_step( cpu_6502_t *cpu )
cpu->PC += (int8_t)operand8;
}
break;
+
+ case BCS_REL:
+ operand8 = cpu_6502_read_byte( cpu, cpu->PC );
+ cpu->PC++;
+ if( is_carry( cpu ) ) {
+ cpu->PC += (int8_t)operand8;
+ }
+ break;
case JMP_ABS:
cpu->PC = cpu_6502_read_word( cpu, cpu->PC );
@@ -308,6 +371,9 @@ void cpu_6502_step( cpu_6502_t *cpu )
cpu->SP = cpu->X;
break;
+ case NOP_IMPL:
+ break;
+
default:
fprintf( stderr, "ERROR: Illegal opcode %02X at PC %04X\n", opcode, cpu->PC );
exit( EXIT_FAILURE );