1 |
2 |
jamieiles |
// Copyright Jamie Iles, 2017
|
2 |
|
|
//
|
3 |
|
|
// This file is part of s80x86.
|
4 |
|
|
//
|
5 |
|
|
// s80x86 is free software: you can redistribute it and/or modify
|
6 |
|
|
// it under the terms of the GNU General Public License as published by
|
7 |
|
|
// the Free Software Foundation, either version 3 of the License, or
|
8 |
|
|
// (at your option) any later version.
|
9 |
|
|
//
|
10 |
|
|
// s80x86 is distributed in the hope that it will be useful,
|
11 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
|
|
// GNU General Public License for more details.
|
14 |
|
|
//
|
15 |
|
|
// You should have received a copy of the GNU General Public License
|
16 |
|
|
// along with s80x86. If not, see <http://www.gnu.org/licenses/>.
|
17 |
|
|
|
18 |
|
|
#include <sstream>
|
19 |
|
|
#include <vector>
|
20 |
|
|
#include <gtest/gtest.h>
|
21 |
|
|
|
22 |
|
|
#include "Arithmetic.h"
|
23 |
|
|
#include "Flags.h"
|
24 |
|
|
|
25 |
|
|
static const std::vector<struct ArithmeticTest<uint8_t>> adc8_tests = {
|
26 |
|
|
{0, 0, 0, PF | ZF, false}, {0, 0, 1, 0, true}, {0xf, 1, 0x10, AF, false},
|
27 |
|
|
{255, 0, 0, ZF | AF | CF | PF, true}, {0xff, 0, 0xff, PF | SF, false},
|
28 |
|
|
{127, 0, 128, OF | SF | AF, true}, {255, 1, 1, CF | AF, true},
|
29 |
|
|
};
|
30 |
|
|
|
31 |
|
|
static const std::vector<struct ArithmeticTest<uint16_t>> adc16_tests = {
|
32 |
|
|
{0, 0, 0, PF | ZF, false}, {0, 1, 2, 0, true}, {0xf, 1, 0x10, AF, false},
|
33 |
|
|
{0xffff, 0, 0, ZF | AF | CF | PF, true},
|
34 |
|
|
{0xffff, 0, 0xffff, PF | SF, false},
|
35 |
|
|
{32767, 0, 32768, OF | SF | AF | PF, true},
|
36 |
|
|
{0xffff, 1, 1, CF | AF, true},
|
37 |
|
|
{0x7fff, 1, 0x8000, SF | PF | AF | OF, false},
|
38 |
|
|
};
|
39 |
|
|
|
40 |
|
|
INSTANTIATE_TEST_CASE_P(Adc,
|
41 |
|
|
ArithmeticRegReg8Test,
|
42 |
|
|
::testing::Values(
|
43 |
|
|
// adc al, bl
|
44 |
|
|
Arith8Params({0x10, 0xd8}, adc8_tests)));
|
45 |
|
|
|
46 |
|
|
INSTANTIATE_TEST_CASE_P(Adc,
|
47 |
|
|
ArithmeticMemReg8Test,
|
48 |
|
|
::testing::Values(
|
49 |
|
|
// adc [bx], al
|
50 |
|
|
Arith8Params({0x10, 0x07}, adc8_tests)));
|
51 |
|
|
|
52 |
|
|
INSTANTIATE_TEST_CASE_P(Adc,
|
53 |
|
|
ArithmeticRegReg8TestReversed,
|
54 |
|
|
::testing::Values(
|
55 |
|
|
// adc bl, al
|
56 |
|
|
Arith8Params({0x12, 0xd8}, adc8_tests)));
|
57 |
|
|
|
58 |
|
|
INSTANTIATE_TEST_CASE_P(Adc,
|
59 |
|
|
ArithmeticMemReg8TestReversed,
|
60 |
|
|
::testing::Values(
|
61 |
|
|
// adc al, [bx]
|
62 |
|
|
Arith8Params({0x12, 0x07}, adc8_tests)));
|
63 |
|
|
|
64 |
|
|
INSTANTIATE_TEST_CASE_P(Adc,
|
65 |
|
|
ArithmeticRegReg16Test,
|
66 |
|
|
::testing::Values(
|
67 |
|
|
// adc ax, bx
|
68 |
|
|
Arith16Params({0x11, 0xd8}, adc16_tests)));
|
69 |
|
|
|
70 |
|
|
INSTANTIATE_TEST_CASE_P(Adc,
|
71 |
|
|
ArithmeticRegMem16Test,
|
72 |
|
|
::testing::Values(
|
73 |
|
|
// adc [bx], ax
|
74 |
|
|
Arith16Params({0x11, 0x07}, adc16_tests)));
|
75 |
|
|
|
76 |
|
|
INSTANTIATE_TEST_CASE_P(Adc,
|
77 |
|
|
ArithmeticRegReg16TestReversed,
|
78 |
|
|
::testing::Values(
|
79 |
|
|
// adc bx, ax
|
80 |
|
|
Arith16Params({0x13, 0xd8}, adc16_tests)));
|
81 |
|
|
|
82 |
|
|
INSTANTIATE_TEST_CASE_P(Adc,
|
83 |
|
|
ArithmeticMemReg16TestReversed,
|
84 |
|
|
::testing::Values(
|
85 |
|
|
// adc ax, bx
|
86 |
|
|
Arith16Params({0x13, 0x07}, adc16_tests)));
|
87 |
|
|
|
88 |
|
|
INSTANTIATE_TEST_CASE_P(
|
89 |
|
|
Adc,
|
90 |
|
|
ArithmeticRegImmed8Test,
|
91 |
|
|
::testing::Values(
|
92 |
|
|
// adc bl, 1
|
93 |
|
|
ArithImmed8Params(std::vector<uint8_t>{0x80, 0xd3, 0x01},
|
94 |
|
|
{1, 2, 0, false}),
|
95 |
|
|
ArithImmed8Params(std::vector<uint8_t>{0x82, 0xd3, 0x01},
|
96 |
|
|
{1, 2, 0, false}),
|
97 |
|
|
ArithImmed8Params(std::vector<uint8_t>{0x80, 0xd3, 0x01},
|
98 |
|
|
{1, 3, PF, true}),
|
99 |
|
|
ArithImmed8Params(std::vector<uint8_t>{0x82, 0xd3, 0x01},
|
100 |
|
|
{1, 3, PF, true})));
|
101 |
|
|
|
102 |
|
|
INSTANTIATE_TEST_CASE_P(
|
103 |
|
|
Adc,
|
104 |
|
|
ArithmeticMemImmed8Test,
|
105 |
|
|
::testing::Values(
|
106 |
|
|
// adc byte [bx], 1
|
107 |
|
|
ArithImmed8Params(std::vector<uint8_t>{0x80, 0x17, 0x01},
|
108 |
|
|
{1, 2, 0, false}),
|
109 |
|
|
ArithImmed8Params(std::vector<uint8_t>{0x82, 0x17, 0x01},
|
110 |
|
|
{1, 2, 0, false}),
|
111 |
|
|
ArithImmed8Params(std::vector<uint8_t>{0x80, 0x17, 0x01},
|
112 |
|
|
{1, 3, PF, true}),
|
113 |
|
|
ArithImmed8Params(std::vector<uint8_t>{0x82, 0x17, 0x01},
|
114 |
|
|
{1, 3, PF, true})));
|
115 |
|
|
|
116 |
|
|
INSTANTIATE_TEST_CASE_P(
|
117 |
|
|
Adc,
|
118 |
|
|
ArithmeticRegImmed16Test,
|
119 |
|
|
::testing::Values(
|
120 |
|
|
// adc bx, 1
|
121 |
|
|
ArithImmed16Params(std::vector<uint8_t>{0x81, 0xd3, 0x01, 0x0},
|
122 |
|
|
{1, 2, 0, false}),
|
123 |
|
|
ArithImmed16Params(std::vector<uint8_t>{0x81, 0xd3, 0x01, 0x0},
|
124 |
|
|
{1, 3, PF, true})));
|
125 |
|
|
|
126 |
|
|
INSTANTIATE_TEST_CASE_P(
|
127 |
|
|
Adc,
|
128 |
|
|
ArithmeticMemImmed16Test,
|
129 |
|
|
::testing::Values(
|
130 |
|
|
// adc word [bx], 1
|
131 |
|
|
ArithImmed16Params(std::vector<uint8_t>{0x81, 0x17, 0x01, 0x00},
|
132 |
|
|
{1, 2, 0, false}),
|
133 |
|
|
ArithImmed16Params(std::vector<uint8_t>{0x81, 0x17, 0x01, 0x00},
|
134 |
|
|
{1, 3, PF, true})));
|
135 |
|
|
|
136 |
|
|
INSTANTIATE_TEST_CASE_P(
|
137 |
|
|
Adc,
|
138 |
|
|
ArithmeticRegImmed16TestExtend,
|
139 |
|
|
::testing::Values(
|
140 |
|
|
// adc bx, -1
|
141 |
|
|
ArithImmed16Params(std::vector<uint8_t>{0x83, 0xd3, 0xff},
|
142 |
|
|
{2, 1, CF | AF, false}),
|
143 |
|
|
// adc bx, 1
|
144 |
|
|
ArithImmed16Params(std::vector<uint8_t>{0x83, 0xd3, 0x01},
|
145 |
|
|
{2, 3, PF, false})));
|
146 |
|
|
|
147 |
|
|
INSTANTIATE_TEST_CASE_P(
|
148 |
|
|
Adc,
|
149 |
|
|
ArithmeticMemImmed16TestExtend,
|
150 |
|
|
::testing::Values(
|
151 |
|
|
// adc word [bx], -1
|
152 |
|
|
ArithImmed16Params(std::vector<uint8_t>{0x83, 0x17, 0xff},
|
153 |
|
|
{2, 1, CF | AF, false}),
|
154 |
|
|
// adc word [bx], 1
|
155 |
|
|
ArithImmed16Params(std::vector<uint8_t>{0x83, 0x17, 0x01},
|
156 |
|
|
{2, 3, PF, false})));
|
157 |
|
|
|
158 |
|
|
INSTANTIATE_TEST_CASE_P(Adc,
|
159 |
|
|
ArithmeticAlImmedTest,
|
160 |
|
|
::testing::Values(
|
161 |
|
|
// adc al, 1
|
162 |
|
|
ArithImmed8Params(std::vector<uint8_t>{0x14, 0x01},
|
163 |
|
|
{1, 2, 0, false})));
|
164 |
|
|
|
165 |
|
|
INSTANTIATE_TEST_CASE_P(Adc,
|
166 |
|
|
ArithmeticAxImmedTest,
|
167 |
|
|
::testing::Values(
|
168 |
|
|
// adc ax, 1
|
169 |
|
|
ArithImmed16Params(std::vector<uint8_t>{0x15, 0x01,
|
170 |
|
|
0x0},
|
171 |
|
|
{1, 2, 0, false})));
|