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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [tests/] [instructions/] [TestNot.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
template <typename T>
27
struct NotTest {
28
    T val;
29
    T expected;
30
};
31
 
32
using Not8Params =
33
    std::pair<const std::vector<uint8_t>, const struct NotTest<uint8_t>>;
34
using Not16Params =
35
    std::pair<const std::vector<uint8_t>, const struct NotTest<uint16_t>>;
36
 
37
static const std::vector<struct NotTest<uint8_t>> not8_tests = {
38
    {0x00, 0xff}, {0xff, 0x00}, {0xaa, 0x55},
39
};
40
 
41
static const std::vector<struct NotTest<uint16_t>> not16_tests = {
42
    {0xaa55, 0x55aa}, {0x0000, 0xffff}, {0xffff, 0x0000},
43
};
44
 
45
TEST_F(EmulateFixture, Not8Reg)
46
{
47
    // not al
48
    for (auto &t : not8_tests) {
49
        reset();
50
 
51
        SCOPED_TRACE("not " + std::to_string(static_cast<int>(t.val)));
52
        write_reg(AL, t.val);
53
        set_instruction({0xf6, 0xd0});
54
 
55
        emulate();
56
 
57
        ASSERT_EQ(read_reg(AL), t.expected);
58
    }
59
}
60
 
61
TEST_F(EmulateFixture, Not8Mem)
62
{
63
    // not byte [bx]
64
    for (auto &t : not8_tests) {
65
        reset();
66
 
67
        SCOPED_TRACE("not " + std::to_string(static_cast<int>(t.val)));
68
        write_reg(BX, 0x0100);
69
        write_mem8(0x0100, t.val);
70
        set_instruction({0xf6, 0x17});
71
 
72
        emulate();
73
 
74
        ASSERT_EQ(read_mem8(0x0100), t.expected);
75
    }
76
}
77
 
78
TEST_F(EmulateFixture, Not16Reg)
79
{
80
    // not ax
81
    for (auto &t : not16_tests) {
82
        reset();
83
 
84
        SCOPED_TRACE("not " + std::to_string(static_cast<int>(t.val)));
85
        write_reg(AX, t.val);
86
        set_instruction({0xf7, 0xd0});
87
 
88
        emulate();
89
 
90
        ASSERT_EQ(read_reg(AX), t.expected);
91
    }
92
}
93
 
94
TEST_F(EmulateFixture, Not16Mem)
95
{
96
    // not byte [bx]
97
    for (auto &t : not16_tests) {
98
        reset();
99
 
100
        SCOPED_TRACE("not " + std::to_string(static_cast<int>(t.val)));
101
        write_reg(BX, 0x0100);
102
        write_mem16(0x0100, t.val);
103
        set_instruction({0xf7, 0x17});
104
 
105
        emulate();
106
 
107
        ASSERT_EQ(read_mem16(0x0100), t.expected);
108
    }
109
}

powered by: WebSVN 2.1.0

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