OpenCores
URL https://opencores.org/ocsvn/s80186/s80186/trunk

Subversion Repositories s80186

[/] [s80186/] [trunk/] [tests/] [instructions/] [TestAdd.cpp] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
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 "EmulateFixture.h"
23
#include "Flags.h"
24
#include "Arithmetic.h"
25
 
26
static const std::vector<struct ArithmeticTest<uint8_t>> add8_tests = {
27
    {0, 0, 0, PF | ZF, false}, {0xf, 1, 0x10, AF, false},
28
        {255, 1, 0, ZF | CF | PF | AF, false}, {0xff, 0, 0xff, PF | SF, false},
29
        {127, 1, 128, OF | SF | AF, false},
30
};
31
 
32
static const std::vector<struct ArithmeticTest<uint16_t>> add16_tests = {
33
    {0, 0, 0, PF | ZF, false}, {0xf, 1, 0x10, AF, false},
34
        {0xffff, 1, 0, ZF | CF | PF | AF, false},
35
        {0xffff, 0, 0xffff, PF | SF, false},
36
        {32767, 1, 32768, OF | SF | AF | PF, false},
37
};
38
 
39
INSTANTIATE_TEST_CASE_P(Add,
40
                        ArithmeticRegReg8Test,
41
                        ::testing::Values(
42
                            // add al, bl
43
                            Arith8Params({0x00, 0xd8}, add8_tests)));
44
 
45
INSTANTIATE_TEST_CASE_P(Add,
46
                        ArithmeticMemReg8Test,
47
                        ::testing::Values(
48
                            // add [bx], al
49
                            Arith8Params({0x00, 0x07}, add8_tests)));
50
 
51
INSTANTIATE_TEST_CASE_P(Add,
52
                        ArithmeticRegReg8TestReversed,
53
                        ::testing::Values(
54
                            // add bl, al
55
                            Arith8Params({0x02, 0xd8}, add8_tests)));
56
 
57
INSTANTIATE_TEST_CASE_P(Add,
58
                        ArithmeticMemReg8TestReversed,
59
                        ::testing::Values(
60
                            // add al, [bx]
61
                            Arith8Params({0x02, 0x07}, add8_tests)));
62
 
63
INSTANTIATE_TEST_CASE_P(Add,
64
                        ArithmeticRegReg16Test,
65
                        ::testing::Values(
66
                            // add ax, bx
67
                            Arith16Params({0x01, 0xd8}, add16_tests)));
68
 
69
INSTANTIATE_TEST_CASE_P(Add,
70
                        ArithmeticRegMem16Test,
71
                        ::testing::Values(
72
                            // adc [bx], ax
73
                            Arith16Params({0x01, 0x07}, add16_tests)));
74
 
75
INSTANTIATE_TEST_CASE_P(Add,
76
                        ArithmeticRegReg16TestReversed,
77
                        ::testing::Values(
78
                            // add bx, ax
79
                            Arith16Params({0x03, 0xd8}, add16_tests)));
80
 
81
INSTANTIATE_TEST_CASE_P(Add,
82
                        ArithmeticMemReg16TestReversed,
83
                        ::testing::Values(
84
                            // add ax, bx
85
                            Arith16Params({0x03, 0x07}, add16_tests)));
86
 
87
INSTANTIATE_TEST_CASE_P(
88
    Add,
89
    ArithmeticRegImmed8Test,
90
    ::testing::Values(
91
        // add bl, 1
92
        ArithImmed8Params(std::vector<uint8_t>{0x80, 0xc3, 0x01},
93
                          {1, 2, 0, false}),
94
        ArithImmed8Params(std::vector<uint8_t>{0x82, 0xc3, 0x01},
95
                          {1, 2, 0, false})));
96
 
97
INSTANTIATE_TEST_CASE_P(
98
    Add,
99
    ArithmeticMemImmed8Test,
100
    ::testing::Values(
101
        // add byte [bx], 1
102
        ArithImmed8Params(std::vector<uint8_t>{0x80, 0x07, 0x01},
103
                          {1, 2, 0, false}),
104
        ArithImmed8Params(std::vector<uint8_t>{0x82, 0x07, 0x01},
105
                          {1, 2, 0, false})));
106
 
107
INSTANTIATE_TEST_CASE_P(Add,
108
                        ArithmeticRegImmed16Test,
109
                        ::testing::Values(
110
                            // add bx, 1
111
                            ArithImmed16Params(std::vector<uint8_t>{0x81, 0xc3,
112
                                                                    0x01, 0x0},
113
                                               {1, 2, 0, false})));
114
 
115
INSTANTIATE_TEST_CASE_P(Add,
116
                        ArithmeticMemImmed16Test,
117
                        ::testing::Values(
118
                            // add word [bx], 1
119
                            ArithImmed16Params(std::vector<uint8_t>{0x81, 0x07,
120
                                                                    0x01, 0x00},
121
                                               {1, 2, 0, false})));
122
 
123
INSTANTIATE_TEST_CASE_P(
124
    Add,
125
    ArithmeticRegImmed16TestExtend,
126
    ::testing::Values(
127
        // add bx, -1
128
        ArithImmed16Params(std::vector<uint8_t>{0x83, 0xc3, 0xff},
129
                           {2, 1, CF | AF, false}),
130
        // add bx, 1
131
        ArithImmed16Params(std::vector<uint8_t>{0x83, 0xc3, 0x01},
132
                           {2, 3, PF, false})));
133
 
134
INSTANTIATE_TEST_CASE_P(
135
    Add,
136
    ArithmeticMemImmed16TestExtend,
137
    ::testing::Values(
138
        // add word [bx], -1
139
        ArithImmed16Params(std::vector<uint8_t>{0x83, 0x07, 0xff},
140
                           {2, 1, CF | AF, false}),
141
        // add word [bx], 1
142
        ArithImmed16Params(std::vector<uint8_t>{0x83, 0x07, 0x01},
143
                           {2, 3, PF, false})));
144
 
145
INSTANTIATE_TEST_CASE_P(Add,
146
                        ArithmeticAlImmedTest,
147
                        ::testing::Values(
148
                            // add al, 1
149
                            ArithImmed8Params(std::vector<uint8_t>{0x04, 0x01},
150
                                              {1, 2, 0, false})));
151
 
152
INSTANTIATE_TEST_CASE_P(Add,
153
                        ArithmeticAxImmedTest,
154
                        ::testing::Values(
155
                            // add ax, 1
156
                            ArithImmed16Params(std::vector<uint8_t>{0x05, 0x01,
157
                                                                    0x0},
158
                                               {1, 2, 0, false})));
159
 
160
TEST_F(EmulateFixture, MultipleAdd)
161
{
162
    // add al, 1; add al, 1
163
    set_instruction({0x04, 0x01, 0x04, 0x01});
164
 
165
    emulate(2);
166
 
167
    ASSERT_EQ(0x2, read_reg(AL));
168
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.