Skip to content

Commit

Permalink
SM83: Add tests for 16 bit arithmetical instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
msinger committed Feb 21, 2021
1 parent 6812dd3 commit d6279fb
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 4 deletions.
3 changes: 2 additions & 1 deletion sim/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ cpu/sm83_int.sv
TESTS = \
test/sm83/ld8.sh \
test/sm83/ld16.sh \
test/sm83/add8.sh
test/sm83/add8.sh \
test/sm83/add16.sh

TEST_EXTENSIONS = .sh
SH_LOG_COMPILER = $(SH)
Expand Down
68 changes: 68 additions & 0 deletions sim/test/sm83/add16.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/sh

# Tests for 16 bit arithmetical instructions on simulated SM83 CPU:
# ADD HL, ss
# ADD SP, e
# INC ss
# DEC ss

. test/sm83/functions

set -e

TEST=sm83_sim_add16

simulate 208 <<"EOF"
# @tick #0
# Preset registers with values
# LD HL, $8000; LD SP, HL; LD HL, $0080; LD BC, $0181; LD DE, $0282
21 00 80 f9 21 80 00 01 81 01 11 82 02
# 56 ticks
# @tick #56
# ADD HL, HL; ADD HL, BC; ADD HL, DE; ADD HL, SP; ADD HL, HL; ADD HL, HL; LD HL, $0000; ADD HL, HL
29 09 19 39 29 29 21 00 00 29
# 68 ticks
# @tick #124
# INC HL; DEC HL; DEC HL; INC BC; DEC DE; DEC SP
23 2b 2b 03 1b 3b
# 48 ticks
# @tick #172
# ADD SP, 5; ADD SP, -100
e8 05 e8 9c
# 32 ticks
EOF

compare_mem <<"EOF"
0000000 0021 f980 8021 0100 0181 8211 2902 1909
0000010 2939 2129 0000 2329 2b2b 1b03 e83b e805
0000020 009c 0000 0000 0000 0000 0000 0000 0000
0000030 0000 0000 0000 0000 0000 0000 0000 0000
*
0010000
EOF

grep_output <<"EOF"
# Check ADD HL, dd
67@posedge M=1 T=4 .* SP=0x8000 BC=0x0181 DE=0x0282 HL=0x0100 AF=0x0000
75@posedge M=1 T=4 .* SP=0x8000 BC=0x0181 DE=0x0282 HL=0x0281 AF=0x0000
83@posedge M=1 T=4 .* SP=0x8000 BC=0x0181 DE=0x0282 HL=0x0503 AF=0x0000
91@posedge M=1 T=4 .* SP=0x8000 BC=0x0181 DE=0x0282 HL=0x8503 AF=0x0000
99@posedge M=1 T=4 .* SP=0x8000 BC=0x0181 DE=0x0282 HL=0x0a06 AF=0x0010
107@posedge M=1 T=4 .* SP=0x8000 BC=0x0181 DE=0x0282 HL=0x140c AF=0x0020
127@posedge M=1 T=4 .* SP=0x8000 BC=0x0181 DE=0x0282 HL=0x0000 AF=0x0000
# Check INC/DEC dd
135@posedge M=1 T=4 .* SP=0x8000 BC=0x0181 DE=0x0282 HL=0x0001 AF=0x0000
143@posedge M=1 T=4 .* SP=0x8000 BC=0x0181 DE=0x0282 HL=0x0000 AF=0x0000
151@posedge M=1 T=4 .* SP=0x8000 BC=0x0181 DE=0x0282 HL=0xffff AF=0x0000
159@posedge M=1 T=4 .* SP=0x8000 BC=0x0182 DE=0x0282 HL=0xffff AF=0x0000
167@posedge M=1 T=4 .* SP=0x8000 BC=0x0182 DE=0x0281 HL=0xffff AF=0x0000
175@posedge M=1 T=4 .* SP=0x7fff BC=0x0182 DE=0x0281 HL=0xffff AF=0x0000
# Check ADD SP, e
191@posedge M=1 T=4 .* SP=0x8004 BC=0x0182 DE=0x0281 HL=0xffff AF=0x0020
207@posedge M=1 T=4 .* SP=0x7fa0 BC=0x0182 DE=0x0281 HL=0xffff AF=0x0010
EOF
22 changes: 19 additions & 3 deletions sim/test/sm83/add8.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
# INC/DEC (HL)
# CPL
# DAA
# SCF
# CCF

. test/sm83/functions

set -e

TEST=sm83_sim_add8

simulate 292 <<"EOF"
simulate 320 <<"EOF"
# @tick #0
# Preset registers with values
# LD BC, $ff05; LD DE, $0f50; LD HL, $8000; LD A, $80; LD (HL), $55; LD ($8001), A
Expand Down Expand Up @@ -49,14 +51,20 @@ a1 b3 aa e6 a5 b6 ee cc af
# CPL; ADD A, $0e; DAA; CPL; SUB A, H; ADD A, C; DAA; ADD A, $30; DAA; CPL; CPL; SUB A, L; DAA
2f c6 0e 27 2f 94 81 27 c6 30 27 2f 2f 95 27
# 60 ticks
# @tick #288
# SCF; SCF; CCF; CCF; XOR A; SCF; CCF
37 37 3f 3f af 37 3f
# 28 ticks
EOF

compare_mem <<"EOF"
0000000 0501 11ff 0f50 0021 3e80 3680 ea55 8001
0000010 8f84 8788 ce86 a10a aab3 a5e6 eeb6 afcc
0000020 2c34 3c35 1d04 3d14 fe96 bc81 d69d 9981
0000030 c62f 270e 942f 2781 30c6 2f27 952f 0027
0000040 0000 0000 0000 0000 0000 0000 0000 0000
0000030 c62f 270e 942f 2781 30c6 2f27 952f 3727
0000040 3f37 af3f 3f37 0000 0000 0000 0000 0000
0000050 0000 0000 0000 0000 0000 0000 0000 0000
*
0008000 7f56 0000 0000 0000 0000 0000 0000 0000
0008010 0000 0000 0000 0000 0000 0000 0000 0000
Expand Down Expand Up @@ -109,4 +117,12 @@ grep_output <<"EOF"
279@posedge M=1 T=4 .* BC=0x0005 DE=0x104f HL=0x8001 AF=0xfff0
283@posedge M=1 T=4 .* BC=0x0005 DE=0x104f HL=0x8001 AF=0x00f0
291@posedge M=1 T=4 .* BC=0x0005 DE=0x104f HL=0x8001 AF=0x9950
# Check SCF and CCF
295@posedge M=1 T=4 .* BC=0x0005 DE=0x104f HL=0x8001 AF=0x9910
299@posedge M=1 T=4 .* BC=0x0005 DE=0x104f HL=0x8001 AF=0x9910
303@posedge M=1 T=4 .* BC=0x0005 DE=0x104f HL=0x8001 AF=0x9900
307@posedge M=1 T=4 .* BC=0x0005 DE=0x104f HL=0x8001 AF=0x9910
315@posedge M=1 T=4 .* BC=0x0005 DE=0x104f HL=0x8001 AF=0x0090
319@posedge M=1 T=4 .* BC=0x0005 DE=0x104f HL=0x8001 AF=0x0080
EOF

0 comments on commit d6279fb

Please sign in to comment.