summaryrefslogtreecommitdiff
path: root/emu
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2020-12-21 20:36:10 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2020-12-21 20:36:10 +0100
commitcc9c81e4fef6938ec0b8a29c040b174b6c29daa8 (patch)
tree10c99eb1dee7e4e6504cc149e37fff268794b291 /emu
parent27ccbbb488ce6873a72e64b097f88066123efe9c (diff)
download6502-cc9c81e4fef6938ec0b8a29c040b174b6c29daa8.tar.gz
6502-cc9c81e4fef6938ec0b8a29c040b174b6c29daa8.tar.bz2
more tests
Diffstat (limited to 'emu')
-rw-r--r--emu/emul.c2
-rw-r--r--emu/tests/test_cpu_6502.c92
2 files changed, 94 insertions, 0 deletions
diff --git a/emu/emul.c b/emu/emul.c
index ff3ac38..53d5ed2 100644
--- a/emu/emul.c
+++ b/emu/emul.c
@@ -120,6 +120,8 @@ void emul_run( emul_t *emul, int nof_steps )
case SDLK_s:
cpu_6502_run( emul->cpu, 1 );
break;
+ case SDLK_EQUALS:
+ case SDLK_KP_EQUALS:
case SDLK_PLUS:
case SDLK_KP_PLUS:
emul->speed *= 10;
diff --git a/emu/tests/test_cpu_6502.c b/emu/tests/test_cpu_6502.c
index 86fcc60..b926c1a 100644
--- a/emu/tests/test_cpu_6502.c
+++ b/emu/tests/test_cpu_6502.c
@@ -562,6 +562,95 @@ START_TEST( test_cpu_6502_inc_flags_zero )
}
END_TEST
+// ROL
+
+START_TEST( test_cpu_6502_rol_flags_accumulator_carry )
+{
+ INIT_CPU_TEST
+
+ CODE_SET1( 0x2a ); // ROL
+
+ cpu.PS |= PS_C;
+ cpu.A = 0xf0;
+
+ COPY_CPU_TEST
+
+ cpu_6502_run( &cpu, 1 );
+
+ PRINT_CPU_TEST
+
+ ck_assert_int_eq( cpu.error_state, ERROR_STATE_OK );
+ ck_assert_int_eq( cpu.PC, before_cpu.PC+1 );
+ ck_assert_int_eq( cpu.SP, before_cpu.SP );
+ ck_assert_int_eq( cpu.PS & ~( PS_C | PS_N | PS_Z ), before_cpu.PS & ~( PS_C | PS_N | PS_Z ) );
+ ck_assert( cpu_6502_is_carry( &cpu ) );
+ ck_assert( !cpu_6502_is_zero( &cpu ) );
+ ck_assert( cpu_6502_is_negative( &cpu ) );
+ ck_assert_int_eq( cpu.A, 0xe1 );
+ ck_assert_int_eq( cpu.X, before_cpu.X );
+ ck_assert_int_eq( cpu.Y, before_cpu.Y );
+ ck_assert_mem_eq( ram.cell, before_ram.cell, ram.size );
+
+ DEINIT_CPU_TEST
+}
+END_TEST
+
+// BCC
+
+START_TEST( test_cpu_6502_bcc_carry_clear )
+{
+ INIT_CPU_TEST
+
+ CODE_SET2( 0x90, 0x12 ); // BCC $12
+
+ cpu.PS &= ~PS_C;
+
+ COPY_CPU_TEST
+
+ cpu_6502_run( &cpu, 1 );
+
+ PRINT_CPU_TEST
+
+ ck_assert_int_eq( cpu.error_state, ERROR_STATE_OK );
+ ck_assert_int_eq( cpu.PC, before_cpu.PC + 2 + 0x12 ); // carry is clear, jump taken
+ ck_assert_int_eq( cpu.SP, before_cpu.SP );
+ ck_assert_int_eq( cpu.PS, before_cpu.PS );
+ ck_assert_int_eq( cpu.A, before_cpu.A );
+ ck_assert_int_eq( cpu.X, before_cpu.X );
+ ck_assert_int_eq( cpu.Y, before_cpu.Y );
+ ck_assert_mem_eq( ram.cell, before_ram.cell, ram.size );
+
+ DEINIT_CPU_TEST
+}
+END_TEST
+
+START_TEST( test_cpu_6502_bcc_carry_set )
+{
+ INIT_CPU_TEST
+
+ CODE_SET2( 0x90, 0x12 ); // BCC $12
+
+ cpu.PS |= PS_C;
+
+ COPY_CPU_TEST
+
+ cpu_6502_run( &cpu, 1 );
+
+ PRINT_CPU_TEST
+
+ ck_assert_int_eq( cpu.error_state, ERROR_STATE_OK );
+ ck_assert_int_eq( cpu.PC, before_cpu.PC+2 ); // carry is set, execute next opcode, don't jump
+ ck_assert_int_eq( cpu.SP, before_cpu.SP );
+ ck_assert_int_eq( cpu.PS, before_cpu.PS );
+ ck_assert_int_eq( cpu.A, before_cpu.A );
+ ck_assert_int_eq( cpu.X, before_cpu.X );
+ ck_assert_int_eq( cpu.Y, before_cpu.Y );
+ ck_assert_mem_eq( ram.cell, before_ram.cell, ram.size );
+
+ DEINIT_CPU_TEST
+}
+END_TEST
+
// JMP
START_TEST( test_cpu_6502_jmp_abs )
@@ -652,6 +741,9 @@ static Suite *make_cpu_6502_testsuite( void )
create_cpu_6502_testcase( suite, "INC (flags, positive)", test_cpu_6502_inc_flags_positive );
create_cpu_6502_testcase( suite, "INC (flags, negative)", test_cpu_6502_inc_flags_negative );
create_cpu_6502_testcase( suite, "INC (flags, zero)", test_cpu_6502_inc_flags_zero );
+ create_cpu_6502_testcase( suite, "ROL (flags, carry)", test_cpu_6502_rol_flags_accumulator_carry );
+ create_cpu_6502_testcase( suite, "BCC (branch taken, carry clear)", test_cpu_6502_bcc_carry_clear );
+ create_cpu_6502_testcase( suite, "BCC (branch not taken, carry set)", test_cpu_6502_bcc_carry_set );
create_cpu_6502_testcase( suite, "JMP (absolute)", test_cpu_6502_jmp_abs );
create_cpu_6502_testcase( suite, "JSR (absolute)", test_cpu_6502_jsr_abs );