From bd970ee132d084ebc060a8f3382597ee93c35eaf Mon Sep 17 00:00:00 2001 From: Javier Alvarez Date: Sat, 11 May 2024 12:59:53 +0200 Subject: [PATCH] Add sm83 tests 0x30 to 0x3f --- sm83/tests/data/add_hl_sp.toml | 66 ++++++++++++++++++++++++++++ sm83/tests/data/ccf.toml | 44 +++++++++++++++++++ sm83/tests/data/dec_a.toml | 64 +++++++++++++++++++++++++++ sm83/tests/data/dec_ind_hl.toml | 39 +++++++++++++++++ sm83/tests/data/dec_sp.toml | 29 +++++++++++++ sm83/tests/data/inc_a.toml | 66 ++++++++++++++++++++++++++++ sm83/tests/data/inc_ind_hl.toml | 39 +++++++++++++++++ sm83/tests/data/inc_sp.toml | 29 +++++++++++++ sm83/tests/data/jr_c_n8.toml | 67 +++++++++++++++++++++++++++++ sm83/tests/data/jr_nc_e8.toml | 67 +++++++++++++++++++++++++++++ sm83/tests/data/ld_a_ind_hldec.toml | 45 +++++++++++++++++++ sm83/tests/data/ld_a_n8.toml | 15 +++++++ sm83/tests/data/ld_ind_hl_n8.toml | 39 +++++++++++++++++ sm83/tests/data/ld_ind_hldec_a.toml | 23 ++++++++++ sm83/tests/data/ld_ind_hlinc_a.toml | 2 +- sm83/tests/data/ld_sp_n16.toml | 16 +++++++ sm83/tests/data/scf.toml | 14 ++++++ 17 files changed, 663 insertions(+), 1 deletion(-) create mode 100644 sm83/tests/data/add_hl_sp.toml create mode 100644 sm83/tests/data/ccf.toml create mode 100644 sm83/tests/data/dec_a.toml create mode 100644 sm83/tests/data/dec_ind_hl.toml create mode 100644 sm83/tests/data/dec_sp.toml create mode 100644 sm83/tests/data/inc_a.toml create mode 100644 sm83/tests/data/inc_ind_hl.toml create mode 100644 sm83/tests/data/inc_sp.toml create mode 100644 sm83/tests/data/jr_c_n8.toml create mode 100644 sm83/tests/data/jr_nc_e8.toml create mode 100644 sm83/tests/data/ld_a_ind_hldec.toml create mode 100644 sm83/tests/data/ld_a_n8.toml create mode 100644 sm83/tests/data/ld_ind_hl_n8.toml create mode 100644 sm83/tests/data/ld_ind_hldec_a.toml create mode 100644 sm83/tests/data/ld_sp_n16.toml create mode 100644 sm83/tests/data/scf.toml diff --git a/sm83/tests/data/add_hl_sp.toml b/sm83/tests/data/add_hl_sp.toml new file mode 100644 index 0000000..2fc009e --- /dev/null +++ b/sm83/tests/data/add_hl_sp.toml @@ -0,0 +1,66 @@ +## ADD HL, SP +## 1 8 +## - 0 H C + +[nominal] +cycles = 8 + +[nominal.entry_state] +h = 0x05 +l = 0xFF +sp = 0xAABB +flags = ['Z', 'N'] + +[nominal.exit_state] +h = 0xB0 +l = 0xBA +sp = 0xAABB +pc = 0x1 +flags = ['Z', 'H'] + +[nominal.program] +instructions = [ + 0x39, # add HL, SP +] + +[flags] +cycles = 8 + +[flags.entry_state] +h = 0x55 +l = 0xFF +sp = 0xAABB +flags = ['N'] + +[flags.exit_state] +h = 0x00 +l = 0xBA +sp = 0xAABB +pc = 0x1 +flags = ['C', 'H'] + +[flags.program] +instructions = [ + 0x39, # add HL, SP +] + +[no_carry] +cycles = 8 + +[no_carry.entry_state] +h = 0x11 +l = 0x22 +sp = 0xAABB +flags = ['N'] + +[no_carry.exit_state] +h = 0xBB +l = 0xDD +sp = 0xAABB +pc = 0x1 +flags = [] + +[no_carry.program] +instructions = [ + 0x39, # add HL, SP +] diff --git a/sm83/tests/data/ccf.toml b/sm83/tests/data/ccf.toml new file mode 100644 index 0000000..da399d1 --- /dev/null +++ b/sm83/tests/data/ccf.toml @@ -0,0 +1,44 @@ +[clear_carry] +cycles = 4 + +[clear_carry.entry_state] +flags = ['C', 'N', 'H', 'Z'] + +[clear_carry.exit_state] +flags = ['Z'] +pc = 0x01 + +[clear_carry.program] +instructions = [ + 0x3F, # ccf +] + +[set_carry] +cycles = 4 + +[set_carry.entry_state] +flags = ['N', 'H', 'Z'] + +[set_carry.exit_state] +flags = ['C', 'Z'] +pc = 0x01 + +[set_carry.program] +instructions = [ + 0x3F, # ccf +] + +[test_z_flag] +cycles = 4 + +[test_z_flag.entry_state] +flags = ['N', 'H'] + +[test_z_flag.exit_state] +flags = ['C'] +pc = 0x01 + +[test_z_flag.program] +instructions = [ + 0x3F, # ccf +] diff --git a/sm83/tests/data/dec_a.toml b/sm83/tests/data/dec_a.toml new file mode 100644 index 0000000..869a699 --- /dev/null +++ b/sm83/tests/data/dec_a.toml @@ -0,0 +1,64 @@ +[no_overflow] +cycles = 4 + +[no_overflow.entry_state] +a = 0xFF + +[no_overflow.exit_state] +a = 0xFE +pc = 0x01 +flags = ['N'] + +[no_overflow.program] +instructions = [ + 0x3D, # dec A +] + +[underflow] +cycles = 4 + +[underflow.entry_state] +a = 0x00 + +[underflow.exit_state] +a = 0xFF +pc = 0x01 +flags = ['N', 'H'] + +[underflow.program] +instructions = [ + 0x3D, # dec A +] + +[zflag] +cycles = 4 + +[zflag.entry_state] +a = 0x1 + +[zflag.exit_state] +a = 0x0 +pc = 0x01 +flags = ['N', 'Z'] + +[zflag.program] +instructions = [ + 0x3D, # dec A +] + +[cflag] +cycles = 4 + +[cflag.entry_state] +a = 0x1 +flags = ['C'] + +[cflag.exit_state] +a = 0x0 +pc = 0x01 +flags = ['N', 'Z', 'C'] + +[cflag.program] +instructions = [ + 0x3D, # dec A +] diff --git a/sm83/tests/data/dec_ind_hl.toml b/sm83/tests/data/dec_ind_hl.toml new file mode 100644 index 0000000..9f0dd00 --- /dev/null +++ b/sm83/tests/data/dec_ind_hl.toml @@ -0,0 +1,39 @@ +[nominal] +cycles = 12 + +[nominal.entry_state] +h = 0x12 +l = 0xFE +flags = ['C'] + +[nominal.exit_state] +h = 0x12 +l = 0xFE +pc = 0x01 +memory = { 0x12FE = [0xFF] } +flags = ['C', 'N', 'H'] + +[nominal.program] +instructions = [ + 0x35, # dec [HL] +] + +[zero] +cycles = 12 + +[zero.entry_state] +h = 0x12 +l = 0xFE +memory = { 0x12FE = [0x01] } + +[zero.exit_state] +h = 0x12 +l = 0xFE +pc = 0x01 +memory = { 0x12FE = [0x00] } +flags = ['Z', 'N'] + +[zero.program] +instructions = [ + 0x35, # dec [HL] +] diff --git a/sm83/tests/data/dec_sp.toml b/sm83/tests/data/dec_sp.toml new file mode 100644 index 0000000..777c549 --- /dev/null +++ b/sm83/tests/data/dec_sp.toml @@ -0,0 +1,29 @@ +[no_underflow] +cycles = 8 + +[no_underflow.entry_state] +sp = 0x12FF + +[no_underflow.exit_state] +sp = 0x12FE +pc = 0x1 + +[no_underflow.program] +instructions = [ + 0x3B, # dec SP +] + +[underflow] +cycles = 8 + +[underflow.entry_state] +sp = 0x1300 + +[underflow.exit_state] +sp = 0x12FF +pc = 0x1 + +[underflow.program] +instructions = [ + 0x3B, # dec SP +] diff --git a/sm83/tests/data/inc_a.toml b/sm83/tests/data/inc_a.toml new file mode 100644 index 0000000..a2a398e --- /dev/null +++ b/sm83/tests/data/inc_a.toml @@ -0,0 +1,66 @@ +[no_overflow] +cycles = 4 + +[no_overflow.entry_state] +a = 0xFE +flags = ['N'] + +[no_overflow.exit_state] +a = 0xFF +pc = 0x01 + +[no_overflow.program] +instructions = [ + 0x3C, # inc a +] + +[overflow] +cycles = 4 + +[overflow.entry_state] +a = 0xFF +flags = ['N'] + +[overflow.exit_state] +a = 0x00 +pc = 0x01 +flags = ['Z', 'H'] + +[overflow.program] +instructions = [ + 0x3C, # inc a +] + +[half_carry] +cycles = 4 + +[half_carry.entry_state] +a = 0x2F +flags = ['N'] + +[half_carry.exit_state] +a = 0x30 +pc = 0x01 +flags = ['H'] + +[half_carry.program] +instructions = [ + 0x3C, # inc a +] + +[carry] +cycles = 4 + +[carry.entry_state] +a = 0x2F +flags = ['N', 'C'] + +[carry.exit_state] +a = 0x30 +pc = 0x01 +flags = ['H', 'C'] + +[carry.program] +instructions = [ + 0x3C, # inc a +] diff --git a/sm83/tests/data/inc_ind_hl.toml b/sm83/tests/data/inc_ind_hl.toml new file mode 100644 index 0000000..c476211 --- /dev/null +++ b/sm83/tests/data/inc_ind_hl.toml @@ -0,0 +1,39 @@ +[nominal] +cycles = 12 + +[nominal.entry_state] +h = 0x12 +l = 0xFE +flags = ['C', 'N'] + +[nominal.exit_state] +h = 0x12 +l = 0xFE +pc = 0x01 +memory = { 0x12FE = [0x01] } +flags = ['C'] + +[nominal.program] +instructions = [ + 0x34, # inc [HL] +] + +[zero] +cycles = 12 + +[zero.entry_state] +h = 0x12 +l = 0xFE +memory = { 0x12FE = [0xFF] } + +[zero.exit_state] +h = 0x12 +l = 0xFE +pc = 0x01 +memory = { 0x12FE = [0x00] } +flags = ['Z', 'H'] + +[zero.program] +instructions = [ + 0x34, # inc [HL] +] diff --git a/sm83/tests/data/inc_sp.toml b/sm83/tests/data/inc_sp.toml new file mode 100644 index 0000000..36d0df6 --- /dev/null +++ b/sm83/tests/data/inc_sp.toml @@ -0,0 +1,29 @@ +[no_overflow] +cycles = 8 + +[no_overflow.entry_state] +sp = 0x12FE + +[no_overflow.exit_state] +sp = 0x12FF +pc = 0x01 + +[no_overflow.program] +instructions = [ + 0x33, # inc SP +] + +[overflow] +cycles = 8 + +[overflow.entry_state] +sp = 0x12FF + +[overflow.exit_state] +sp = 0x1300 +pc = 0x01 + +[overflow.program] +instructions = [ + 0x33, # inc SP +] diff --git a/sm83/tests/data/jr_c_n8.toml b/sm83/tests/data/jr_c_n8.toml new file mode 100644 index 0000000..1b5c4f1 --- /dev/null +++ b/sm83/tests/data/jr_c_n8.toml @@ -0,0 +1,67 @@ +[forward_jump_taken] +cycles = 12 + +[forward_jump_taken.entry_state] +pc = 0x1234 +flags = ['C'] + +[forward_jump_taken.exit_state] +pc = 0x1256 +flags = ['C'] + +[forward_jump_taken.program] +base = 0x1234 +instructions = [ + 0x38, # jr C, +32 + 0x20, +] + +[backward_jump_taken] +cycles = 12 + +[backward_jump_taken.entry_state] +pc = 0x1234 +flags = ['C'] + +[backward_jump_taken.exit_state] +pc = 0x11B6 +flags = ['C'] + +[backward_jump_taken.program] +base = 0x1234 +instructions = [ + 0x38, # jr C, -128 + 0x80, +] + +[forward_jump_not_taken] +cycles = 8 + +[forward_jump_not_taken.entry_state] +pc = 0x1234 + +[forward_jump_not_taken.exit_state] +pc = 0x1236 + +[forward_jump_not_taken.program] +base = 0x1234 +instructions = [ + 0x38, # jr C, +32 + 0x20, +] + +[backward_jump_not_taken] +cycles = 8 + +[backward_jump_not_taken.entry_state] +pc = 0x1234 + +[backward_jump_not_taken.exit_state] +pc = 0x1236 + +[backward_jump_not_taken.program] +base = 0x1234 +instructions = [ + 0x38, # jr C, -128 + 0x80, +] diff --git a/sm83/tests/data/jr_nc_e8.toml b/sm83/tests/data/jr_nc_e8.toml new file mode 100644 index 0000000..4827341 --- /dev/null +++ b/sm83/tests/data/jr_nc_e8.toml @@ -0,0 +1,67 @@ +[forward_jump_taken] +cycles = 12 + +[forward_jump_taken.entry_state] +pc = 0x1234 + +[forward_jump_taken.exit_state] +pc = 0x1256 + +[forward_jump_taken.program] +base = 0x1234 +instructions = [ + 0x30, # jr NC, +32 + 0x20, +] + +[backward_jump_taken] +cycles = 12 + +[backward_jump_taken.entry_state] +pc = 0x1234 + +[backward_jump_taken.exit_state] +pc = 0x11B6 + +[backward_jump_taken.program] +base = 0x1234 +instructions = [ + 0x30, # jr NC, +32 + 0x80, +] + +[forward_jump_not_taken] +cycles = 8 + +[forward_jump_not_taken.entry_state] +pc = 0x1234 +flags = ['C'] + +[forward_jump_not_taken.exit_state] +pc = 0x1236 +flags = ['C'] + +[forward_jump_not_taken.program] +base = 0x1234 +instructions = [ + 0x30, # jr NC, +32 + 0x20, +] + +[backward_jump_not_taken] +cycles = 8 + +[backward_jump_not_taken.entry_state] +pc = 0x1234 +flags = ['C'] + +[backward_jump_not_taken.exit_state] +pc = 0x1236 +flags = ['C'] + +[backward_jump_not_taken.program] +base = 0x1234 +instructions = [ + 0x30, # jr NC, +32 + 0x80, +] diff --git a/sm83/tests/data/ld_a_ind_hldec.toml b/sm83/tests/data/ld_a_ind_hldec.toml new file mode 100644 index 0000000..e5888fb --- /dev/null +++ b/sm83/tests/data/ld_a_ind_hldec.toml @@ -0,0 +1,45 @@ +# Executes an ld A, [HL-] instruction +[test] +cycles = 8 + +[test.entry_state] +h = 0xAA +l = 0xBB +flags = ['Z', 'C', 'H', 'N'] +memory = { 0xAABB = [0xF3] } + +[test.exit_state] +a = 0xF3 +h = 0xAA +l = 0xBA +pc = 0x1 +flags = ['Z', 'C', 'H', 'N'] +memory = { 0xAABB = [0xF3] } + +[test.program] +instructions = [ + 0x3a, # ld A, [HL-] +] + +# Check with opposite flag values. Check that they are not modified +[test2] +cycles = 8 + +[test2.entry_state] +h = 0xBB +l = 0xAA +flags = [] +memory = { 0xBBAA = [0x12] } + +[test2.exit_state] +a = 0x12 +h = 0xBB +l = 0xA9 +pc = 0x1 +flags = [] +memory = { 0xBBAA = [0x12] } + +[test2.program] +instructions = [ + 0x3a, # ld A, [HL-] +] diff --git a/sm83/tests/data/ld_a_n8.toml b/sm83/tests/data/ld_a_n8.toml new file mode 100644 index 0000000..7597cf1 --- /dev/null +++ b/sm83/tests/data/ld_a_n8.toml @@ -0,0 +1,15 @@ +[test] +cycles = 8 + +[test.entry_state] +a = 0xA5 + +[test.exit_state] +a = 0xC3 +pc = 0x02 + +[test.program] +instructions = [ + 0x3E, # ld a, 0xC3 + 0xc3, +] diff --git a/sm83/tests/data/ld_ind_hl_n8.toml b/sm83/tests/data/ld_ind_hl_n8.toml new file mode 100644 index 0000000..8df14b5 --- /dev/null +++ b/sm83/tests/data/ld_ind_hl_n8.toml @@ -0,0 +1,39 @@ +[nominal] +cycles = 12 + +[nominal.entry_state] +h = 0xA5 +l = 0xB0 + +[nominal.exit_state] +h = 0xA5 +l = 0xB0 +pc = 0x02 +memory = { 0xA5B0 = [0xC3] } + +[nominal.program] +instructions = [ + 0x36, # ld [HL], 0xC3 + 0xc3, +] + +[flags] +cycles = 12 + +[flags.entry_state] +h = 0xA5 +l = 0xB0 +flags = ['Z', 'C', 'N', 'H'] + +[flags.exit_state] +h = 0xA5 +l = 0xB0 +pc = 0x02 +memory = { 0xA5B0 = [0xC3] } +flags = ['Z', 'C', 'N', 'H'] + +[flags.program] +instructions = [ + 0x36, # ld [HL], 0xC3 + 0xc3, +] diff --git a/sm83/tests/data/ld_ind_hldec_a.toml b/sm83/tests/data/ld_ind_hldec_a.toml new file mode 100644 index 0000000..e08ae00 --- /dev/null +++ b/sm83/tests/data/ld_ind_hldec_a.toml @@ -0,0 +1,23 @@ +# Executes a ld [HL-], a instruction +[test] +cycles = 8 + +[test.entry_state] +a = 0xa5 +h = 0x12 +l = 0x34 +pc = 0x800 +memory = { 0x1234 = [0] } + +[test.exit_state] +a = 0xa5 +h = 0x12 +l = 0x33 +pc = 0x801 +memory = { 0x1234 = [0xA5] } + +[test.program] +base = 0x800 +instructions = [ + 0x32, # ld [HL-], a +] diff --git a/sm83/tests/data/ld_ind_hlinc_a.toml b/sm83/tests/data/ld_ind_hlinc_a.toml index 4233368..f421706 100644 --- a/sm83/tests/data/ld_ind_hlinc_a.toml +++ b/sm83/tests/data/ld_ind_hlinc_a.toml @@ -19,5 +19,5 @@ memory = { 0x1234 = [0xA5] } [test.program] base = 0x800 instructions = [ - 0x22, # ld [de], a + 0x22, # ld [HL], a ] diff --git a/sm83/tests/data/ld_sp_n16.toml b/sm83/tests/data/ld_sp_n16.toml new file mode 100644 index 0000000..fa3e00b --- /dev/null +++ b/sm83/tests/data/ld_sp_n16.toml @@ -0,0 +1,16 @@ +[test] +cycles = 12 + +[test.entry_state] +sp = 0x8224 + +[test.exit_state] +sp = 0x125A +pc = 0x03 + +[test.program] +instructions = [ + 0x31, # ld SP, 0x125A + 0x5A, + 0x12, +] diff --git a/sm83/tests/data/scf.toml b/sm83/tests/data/scf.toml new file mode 100644 index 0000000..68bd09f --- /dev/null +++ b/sm83/tests/data/scf.toml @@ -0,0 +1,14 @@ +[nominal] +cycles = 4 + +[nominal.entry_state] +flags = ['Z', 'N', 'H'] + +[nominal.exit_state] +pc = 0x01 +flags = ['Z', 'C'] + +[nominal.program] +instructions = [ + 0x37, # scf +]