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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [tests/] [instructions/] [TestAscii.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 <gtest/gtest.h>
19
 
20
#include "EmulateFixture.h"
21
#include "Flags.h"
22
 
23
struct AsciiTest {
24
    uint16_t ax;
25
    uint16_t ax_expected;
26
    uint16_t flags;
27
    uint16_t flags_expected;
28
};
29
 
30
static const std::vector<AsciiTest> aaa_tests{
31
    AsciiTest{0, 0, 0, 0},
32
    AsciiTest{0, 0, CF, 0},
33
    AsciiTest{0, 0x0106, AF, AF | CF},
34
    AsciiTest{0x9, 0x9, 0, 0},
35
    AsciiTest{0xa, 0x0100, 0, AF | CF},
36
};
37
 
38
TEST_F(EmulateFixture, Aaa)
39
{
40
    // aaa
41
    for (auto &t : aaa_tests) {
42
        reset();
43
 
44
        write_flags(t.flags);
45
        write_reg(AX, t.ax);
46
        set_instruction({0x37});
47
 
48
        emulate();
49
 
50
        EXPECT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
51
                            FLAGS_STUCK_BITS | t.flags_expected);
52
        EXPECT_EQ(read_reg(AX), t.ax_expected);
53
    }
54
}
55
 
56
static const std::vector<AsciiTest> daa_tests{
57
    AsciiTest{0x00, 0x00, 0, 0},       AsciiTest{0x00, 0x06, AF, AF},
58
    AsciiTest{0x0a, 0x10, AF, AF},     AsciiTest{0x00, 0x60, CF, CF},
59
    AsciiTest{0x9a, 0x00, 0, CF | AF},
60
};
61
 
62
TEST_F(EmulateFixture, Daa)
63
{
64
    // daa
65
    for (auto &t : daa_tests) {
66
        reset();
67
 
68
        write_flags(t.flags);
69
        write_reg(AX, t.ax);
70
        set_instruction({0x27});
71
 
72
        emulate();
73
 
74
        EXPECT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
75
                            FLAGS_STUCK_BITS | t.flags_expected);
76
        EXPECT_EQ(read_reg(AX), t.ax_expected);
77
    }
78
}
79
 
80
static const std::vector<AsciiTest> aas_tests{
81
    AsciiTest{0x00, 0x00, 0, 0}, AsciiTest{0x0a, 0xff04, 0, AF | CF},
82
    AsciiTest{0x00, 0xff0a, AF, AF | CF},
83
};
84
 
85
TEST_F(EmulateFixture, Aas)
86
{
87
    // aas
88
    for (auto &t : aas_tests) {
89
        reset();
90
 
91
        write_flags(t.flags);
92
        write_reg(AX, t.ax);
93
        set_instruction({0x3f});
94
 
95
        emulate();
96
 
97
        EXPECT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
98
                            FLAGS_STUCK_BITS | t.flags_expected);
99
        EXPECT_EQ(read_reg(AX), t.ax_expected);
100
    }
101
}
102
 
103
static const std::vector<AsciiTest> das_tests{
104
    AsciiTest{0x00, 0x00, 0, ZF | PF}, AsciiTest{0x0a, 0x04, 0, AF},
105
    AsciiTest{0x00, 0x9a, AF, AF | PF | SF | CF},
106
    AsciiTest{0x00, 0xa0, CF, CF | PF | SF},
107
    AsciiTest{0xff, 0x99, 0, AF | CF | PF | SF}};
108
 
109
TEST_F(EmulateFixture, Das)
110
{
111
    // das
112
    for (auto &t : das_tests) {
113
        reset();
114
 
115
        write_flags(t.flags);
116
        write_reg(AX, t.ax);
117
        set_instruction({0x2f});
118
 
119
        emulate();
120
 
121
        EXPECT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
122
                            FLAGS_STUCK_BITS | t.flags_expected);
123
        EXPECT_EQ(read_reg(AX), t.ax_expected);
124
    }
125
}
126
 
127
static const std::vector<AsciiTest> aam_tests{
128
    AsciiTest{0x00, 0x00, 0, ZF | PF}, AsciiTest{0x0a, 0x0100, 0, PF},
129
    AsciiTest{0x50, 0x0800, 0, PF},
130
};
131
 
132
TEST_F(EmulateFixture, Aam)
133
{
134
    // aam
135
    for (auto &t : aam_tests) {
136
        reset();
137
 
138
        write_flags(t.flags);
139
        write_reg(AX, t.ax);
140
        set_instruction({0xd4, 0x0a});
141
 
142
        emulate();
143
 
144
        EXPECT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
145
                            FLAGS_STUCK_BITS | t.flags_expected);
146
        EXPECT_EQ(read_reg(AX), t.ax_expected);
147
    }
148
}
149
 
150
static const std::vector<AsciiTest> aam_129_tests{
151
    AsciiTest{0x80, 0x0080, 0, 0},
152
};
153
TEST_F(EmulateFixture, Aam129)
154
{
155
    // aam 129
156
    for (auto &t : aam_129_tests) {
157
        reset();
158
 
159
        write_flags(t.flags);
160
        write_reg(AX, t.ax);
161
        set_instruction({0xd4, 129});
162
 
163
        emulate();
164
 
165
        EXPECT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
166
                            FLAGS_STUCK_BITS | t.flags_expected);
167
        EXPECT_EQ(read_reg(AX), t.ax_expected);
168
    }
169
}
170
 
171
TEST_F(EmulateFixture, AamSigned)
172
{
173
    // aam 1
174
    write_flags(0);
175
    write_reg(AX, 0xffff);
176
    set_instruction({0xd4, 0x10});
177
 
178
    emulate();
179
 
180
    EXPECT_PRED_FORMAT2(AssertFlagsEqual, read_flags(), FLAGS_STUCK_BITS | PF);
181
    EXPECT_EQ(read_reg(AX), 0x0f0f);
182
}
183
 
184
TEST_F(EmulateFixture, AamDivByZero)
185
{
186
    // aam 0
187
    write_flags(0);
188
    write_reg(AX, 1);
189
    set_instruction({0xd4, 0});
190
    write_mem16(VEC_DIVIDE_ERROR + 0, 0x8000, CS);
191
    write_mem16(VEC_DIVIDE_ERROR + 2, 0xc000, CS);
192
 
193
    emulate();
194
 
195
    EXPECT_PRED_FORMAT2(AssertFlagsEqual, read_flags(), FLAGS_STUCK_BITS | 0);
196
    EXPECT_EQ(read_reg(CS), 0xc000);
197
    EXPECT_EQ(read_reg(IP), 0x8000);
198
}
199
 
200
static const std::vector<AsciiTest> aad_tests{
201
    AsciiTest{0x0000, 0x00, 0, ZF | PF}, AsciiTest{0x0105, 0x0f, 0, PF},
202
    AsciiTest{0x0909, 0x63, 0, PF},
203
};
204
 
205
TEST_F(EmulateFixture, Aad)
206
{
207
    // aad
208
    for (auto &t : aad_tests) {
209
        reset();
210
 
211
        write_flags(t.flags);
212
        write_reg(AX, t.ax);
213
        set_instruction({0xd5, 0x0a});
214
 
215
        emulate();
216
 
217
        EXPECT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
218
                            FLAGS_STUCK_BITS | t.flags_expected);
219
        EXPECT_EQ(read_reg(AX), t.ax_expected);
220
    }
221
}
222
 
223
TEST_F(EmulateFixture, AadSigned)
224
{
225
    // aad 0xff
226
    write_flags(0);
227
    write_reg(AX, 0xff00);
228
    set_instruction({0xd5, 0xff});
229
 
230
    emulate();
231
 
232
    EXPECT_PRED_FORMAT2(AssertFlagsEqual, read_flags(), FLAGS_STUCK_BITS | SF);
233
    EXPECT_EQ(read_reg(AX), 1);
234
}

powered by: WebSVN 2.1.0

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