| 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>> sbb8_tests = {
|
| 27 |
|
|
{0, 0, 0, PF | ZF, false}, {0, 0, 0xff, PF | AF | SF | CF, true},
|
| 28 |
|
|
{0, 1, 0xff, PF | SF | CF | AF, false}, {3, 2, 1, 0, false},
|
| 29 |
|
|
{3, 2, 0, PF | ZF, true}, {0xff, 0xff, 0, PF | ZF, false},
|
| 30 |
|
|
{0xff, 0xff, 0xff, PF | AF | SF | CF, true},
|
| 31 |
|
|
{0, 0xff, 1, CF | AF, false},
|
| 32 |
|
|
};
|
| 33 |
|
|
|
| 34 |
|
|
static const std::vector<struct ArithmeticTest<uint16_t>> sbb16_tests = {
|
| 35 |
|
|
{0, 0, 0, PF | ZF, false}, {0, 0, 0xffff, PF | AF | SF | CF, true},
|
| 36 |
|
|
{0, 1, 0xffff, PF | SF | CF | AF, false}, {3, 2, 1, 0, false},
|
| 37 |
|
|
{3, 2, 0, PF | ZF, true}, {0xffff, 0xffff, 0, PF | ZF, false},
|
| 38 |
|
|
{0xffff, 0xffff, 0xffff, PF | AF | SF | CF, true},
|
| 39 |
|
|
{0, 0xffff, 1, CF | AF, false},
|
| 40 |
|
|
};
|
| 41 |
|
|
|
| 42 |
|
|
INSTANTIATE_TEST_CASE_P(Sbb,
|
| 43 |
|
|
ArithmeticRegReg8Test,
|
| 44 |
|
|
::testing::Values(
|
| 45 |
|
|
// sbb al, bl
|
| 46 |
|
|
Arith8Params({0x18, 0xd8}, sbb8_tests)));
|
| 47 |
|
|
|
| 48 |
|
|
INSTANTIATE_TEST_CASE_P(Sbb,
|
| 49 |
|
|
ArithmeticMemReg8Test,
|
| 50 |
|
|
::testing::Values(
|
| 51 |
|
|
// sbb [bx], al
|
| 52 |
|
|
Arith8Params({0x18, 0x07}, sbb8_tests)));
|
| 53 |
|
|
|
| 54 |
|
|
INSTANTIATE_TEST_CASE_P(Sbb,
|
| 55 |
|
|
ArithmeticRegReg8TestReversed,
|
| 56 |
|
|
::testing::Values(
|
| 57 |
|
|
// sbb bl, al
|
| 58 |
|
|
Arith8Params({0x1a, 0xd8}, sbb8_tests)));
|
| 59 |
|
|
|
| 60 |
|
|
INSTANTIATE_TEST_CASE_P(Sbb,
|
| 61 |
|
|
ArithmeticMemReg8TestReversed,
|
| 62 |
|
|
::testing::Values(
|
| 63 |
|
|
// sbb al, [bx]
|
| 64 |
|
|
Arith8Params({0x1a, 0x07}, sbb8_tests)));
|
| 65 |
|
|
|
| 66 |
|
|
INSTANTIATE_TEST_CASE_P(Sbb,
|
| 67 |
|
|
ArithmeticRegReg16Test,
|
| 68 |
|
|
::testing::Values(
|
| 69 |
|
|
// sbb ax, bx
|
| 70 |
|
|
Arith16Params({0x19, 0xd8}, sbb16_tests)));
|
| 71 |
|
|
|
| 72 |
|
|
INSTANTIATE_TEST_CASE_P(Sbb,
|
| 73 |
|
|
ArithmeticRegMem16Test,
|
| 74 |
|
|
::testing::Values(
|
| 75 |
|
|
// adc [bx], ax
|
| 76 |
|
|
Arith16Params({0x19, 0x07}, sbb16_tests)));
|
| 77 |
|
|
|
| 78 |
|
|
INSTANTIATE_TEST_CASE_P(Sbb,
|
| 79 |
|
|
ArithmeticRegReg16TestReversed,
|
| 80 |
|
|
::testing::Values(
|
| 81 |
|
|
// sbb bx, ax
|
| 82 |
|
|
Arith16Params({0x1b, 0xd8}, sbb16_tests)));
|
| 83 |
|
|
|
| 84 |
|
|
INSTANTIATE_TEST_CASE_P(Sbb,
|
| 85 |
|
|
ArithmeticMemReg16TestReversed,
|
| 86 |
|
|
::testing::Values(
|
| 87 |
|
|
// sbb ax, bx
|
| 88 |
|
|
Arith16Params({0x1b, 0x07}, sbb16_tests)));
|
| 89 |
|
|
|
| 90 |
|
|
// Immediates
|
| 91 |
|
|
|
| 92 |
|
|
INSTANTIATE_TEST_CASE_P(
|
| 93 |
|
|
Sbb,
|
| 94 |
|
|
ArithmeticRegImmed8Test,
|
| 95 |
|
|
::testing::Values(
|
| 96 |
|
|
// sbb bl, 1
|
| 97 |
|
|
ArithImmed8Params(std::vector<uint8_t>{0x80, 0xdb, 0x01},
|
| 98 |
|
|
{2, 1, 0, false}),
|
| 99 |
|
|
ArithImmed8Params(std::vector<uint8_t>{0x82, 0xdb, 0x01},
|
| 100 |
|
|
{2, 1, 0, false})));
|
| 101 |
|
|
|
| 102 |
|
|
INSTANTIATE_TEST_CASE_P(
|
| 103 |
|
|
Sbb,
|
| 104 |
|
|
ArithmeticMemImmed8Test,
|
| 105 |
|
|
::testing::Values(
|
| 106 |
|
|
// sbb byte [bx], 1
|
| 107 |
|
|
ArithImmed8Params(std::vector<uint8_t>{0x80, 0x1f, 0x01},
|
| 108 |
|
|
{2, 1, 0, false}),
|
| 109 |
|
|
ArithImmed8Params(std::vector<uint8_t>{0x82, 0x1f, 0x01},
|
| 110 |
|
|
{2, 1, 0, false})));
|
| 111 |
|
|
|
| 112 |
|
|
INSTANTIATE_TEST_CASE_P(Sbb,
|
| 113 |
|
|
ArithmeticRegImmed16Test,
|
| 114 |
|
|
::testing::Values(
|
| 115 |
|
|
// sbb bx, 1
|
| 116 |
|
|
ArithImmed16Params(std::vector<uint8_t>{0x81, 0xdb,
|
| 117 |
|
|
0x01, 0x0},
|
| 118 |
|
|
{2, 1, 0, false})));
|
| 119 |
|
|
|
| 120 |
|
|
INSTANTIATE_TEST_CASE_P(Sbb,
|
| 121 |
|
|
ArithmeticMemImmed16Test,
|
| 122 |
|
|
::testing::Values(
|
| 123 |
|
|
// sbb word [bx], 1
|
| 124 |
|
|
ArithImmed16Params(std::vector<uint8_t>{0x81, 0x1f,
|
| 125 |
|
|
0x01, 0x00},
|
| 126 |
|
|
{2, 1, 0, false})));
|
| 127 |
|
|
|
| 128 |
|
|
INSTANTIATE_TEST_CASE_P(
|
| 129 |
|
|
Sbb,
|
| 130 |
|
|
ArithmeticRegImmed16TestExtend,
|
| 131 |
|
|
::testing::Values(
|
| 132 |
|
|
// sbb bx, -1
|
| 133 |
|
|
ArithImmed16Params(std::vector<uint8_t>{0x83, 0xdb, 0xff},
|
| 134 |
|
|
{1, 2, CF | AF, false}),
|
| 135 |
|
|
// sbb bx, 1
|
| 136 |
|
|
ArithImmed16Params(std::vector<uint8_t>{0x83, 0xdb, 0x01},
|
| 137 |
|
|
{2, 1, 0, false})));
|
| 138 |
|
|
|
| 139 |
|
|
INSTANTIATE_TEST_CASE_P(
|
| 140 |
|
|
Sbb,
|
| 141 |
|
|
ArithmeticMemImmed16TestExtend,
|
| 142 |
|
|
::testing::Values(
|
| 143 |
|
|
// sbb word [bx], -1
|
| 144 |
|
|
ArithImmed16Params(std::vector<uint8_t>{0x83, 0x1f, 0xff},
|
| 145 |
|
|
{1, 2, CF | AF, false}),
|
| 146 |
|
|
// sbb word [bx], 1
|
| 147 |
|
|
ArithImmed16Params(std::vector<uint8_t>{0x83, 0x1f, 0x01},
|
| 148 |
|
|
{2, 1, 0, false})));
|
| 149 |
|
|
|
| 150 |
|
|
INSTANTIATE_TEST_CASE_P(
|
| 151 |
|
|
Sbb,
|
| 152 |
|
|
ArithmeticAlImmedTest,
|
| 153 |
|
|
::testing::Values(
|
| 154 |
|
|
// sbb al, 1
|
| 155 |
|
|
ArithImmed8Params(std::vector<uint8_t>{0x1c, 0x01}, {2, 1, 0, false}),
|
| 156 |
|
|
ArithImmed8Params(std::vector<uint8_t>{0x1c, 0x01}, {3, 1, 0, true})));
|
| 157 |
|
|
|
| 158 |
|
|
INSTANTIATE_TEST_CASE_P(
|
| 159 |
|
|
Sbb,
|
| 160 |
|
|
ArithmeticAxImmedTest,
|
| 161 |
|
|
::testing::Values(
|
| 162 |
|
|
// sbb ax, 1
|
| 163 |
|
|
ArithImmed16Params(std::vector<uint8_t>{0x1d, 0x01, 0x0},
|
| 164 |
|
|
{2, 1, 0, false}),
|
| 165 |
|
|
ArithImmed16Params(std::vector<uint8_t>{0x1d, 0x01, 0x0},
|
| 166 |
|
|
{3, 1, 0, true})));
|