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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [tests/] [instructions/] [TestPush.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
 
22
TEST_F(EmulateFixture, PushRegFF)
23
{
24
    // push ax
25
    set_instruction({0xff, 0xf0});
26
 
27
    write_reg(AX, 0xaa55);
28
    write_reg(SP, 0x100);
29
 
30
    emulate();
31
 
32
    ASSERT_EQ(0x0fe, read_reg(SP));
33
    ASSERT_EQ(0xaa55, read_mem16(0x0fe, SS));
34
}
35
 
36
TEST_F(EmulateFixture, PushRegFFSP)
37
{
38
    // push sp
39
    set_instruction({0xff, 0xf4});
40
 
41
    write_reg(SP, 0x100);
42
 
43
    emulate();
44
 
45
    ASSERT_EQ(0x0fe, read_reg(SP));
46
    ASSERT_EQ(0x0fe, read_mem16(0x0fe, SS));
47
}
48
 
49
TEST_F(EmulateFixture, PushImm16)
50
{
51
    // push $0xaa55
52
    set_instruction({0x68, 0x55, 0xaa});
53
 
54
    write_reg(SP, 0x100);
55
 
56
    emulate();
57
 
58
    ASSERT_EQ(0x0fe, read_reg(SP));
59
    ASSERT_EQ(0xaa55, read_mem16(0x0fe, SS));
60
}
61
 
62
TEST_F(EmulateFixture, PushImm8)
63
{
64
    // push $0x80
65
    set_instruction({0x6a, 0x80});
66
 
67
    write_reg(SP, 0x100);
68
 
69
    emulate();
70
 
71
    ASSERT_EQ(0x0fe, read_reg(SP));
72
    ASSERT_EQ(0xff80, read_mem16(0x0fe, SS));
73
}
74
 
75
TEST_F(EmulateFixture, PushMemFF)
76
{
77
    // push [1234]
78
    set_instruction({0xff, 0x36, 0x34, 0x12});
79
 
80
    write_mem16(0x1234, 0xaa55);
81
    write_reg(SP, 0x100);
82
 
83
    emulate();
84
 
85
    ASSERT_EQ(0x0fe, read_reg(SP));
86
    ASSERT_EQ(0xaa55, read_mem16(0x0fe, SS));
87
}
88
 
89
TEST_F(EmulateFixture, PushReg5X)
90
{
91
    // push r
92
    for (uint8_t i = 0; i < 8; ++i) {
93
        reset();
94
 
95
        auto reg = static_cast<GPR>(static_cast<int>(AX) + i);
96
        write_reg(reg, 0x0100 + i);
97
        write_reg(SP, 0x0100);
98
 
99
        set_instruction({static_cast<uint8_t>(0x50 + i)});
100
        emulate();
101
 
102
        ASSERT_EQ(0x0fe, read_reg(SP));
103
        if (reg != SP)
104
            ASSERT_EQ(0x0100 + i, read_mem16(0x0fe, SS));
105
        else
106
            ASSERT_EQ(0x00fe, read_mem16(0x0fe, SS));
107
    }
108
}
109
 
110
TEST_F(EmulateFixture, PushSR)
111
{
112
    // push sr
113
    for (uint8_t i = 0; i < 4; ++i) {
114
        reset();
115
 
116
        auto reg = static_cast<GPR>(static_cast<int>(ES) + i);
117
        write_reg(reg, 0x0100 + i);
118
        write_reg(SP, 0x0100);
119
 
120
        set_instruction({static_cast<uint8_t>((i << 3) | 0x6)});
121
        emulate();
122
 
123
        ASSERT_EQ(0x0fe, read_reg(SP));
124
        ASSERT_EQ(0x0100 + i, read_mem16(0x0fe, SS));
125
    }
126
}
127
 
128
TEST_F(EmulateFixture, Pusha)
129
{
130
    write_reg(AX, 1);
131
    write_reg(CX, 2);
132
    write_reg(DX, 3);
133
    write_reg(BX, 4);
134
    write_reg(SP, 0x0100);
135
    write_reg(BP, 5);
136
    write_reg(SI, 6);
137
    write_reg(DI, 7);
138
 
139
    set_instruction({0x60});
140
    emulate();
141
 
142
    EXPECT_EQ(0x0f0, read_reg(SP));
143
    EXPECT_EQ(1, read_mem16(0xfe, SS));
144
    EXPECT_EQ(2, read_mem16(0xfc, SS));
145
    EXPECT_EQ(3, read_mem16(0xfa, SS));
146
    EXPECT_EQ(4, read_mem16(0xf8, SS));
147
    EXPECT_EQ(0x100, read_mem16(0xf6, SS));
148
    EXPECT_EQ(5, read_mem16(0xf4, SS));
149
    EXPECT_EQ(6, read_mem16(0xf2, SS));
150
    EXPECT_EQ(7, read_mem16(0xf0, SS));
151
}
152
 
153
TEST_F(EmulateFixture, Popa)
154
{
155
    write_reg(SP, 0xf0);
156
 
157
    write_mem16(0xfe, 1, SS);
158
    write_mem16(0xfc, 2, SS);
159
    write_mem16(0xfa, 3, SS);
160
    write_mem16(0xf8, 4, SS);
161
    write_mem16(0xf6, 0x800, SS); // Ignored
162
    write_mem16(0xf4, 5, SS);
163
    write_mem16(0xf2, 6, SS);
164
    write_mem16(0xf0, 7, SS);
165
 
166
    set_instruction({0x61});
167
    emulate();
168
 
169
    EXPECT_EQ(read_reg(AX), 1);
170
    EXPECT_EQ(read_reg(CX), 2);
171
    EXPECT_EQ(read_reg(DX), 3);
172
    EXPECT_EQ(read_reg(BX), 4);
173
    EXPECT_EQ(read_reg(BP), 5);
174
    EXPECT_EQ(read_reg(SI), 6);
175
    EXPECT_EQ(read_reg(DI), 7);
176
    EXPECT_EQ(read_reg(SP), 0x100);
177
}
178
 
179
TEST_F(EmulateFixture, PopReg8F)
180
{
181
    // pop ax
182
    set_instruction({0x8f, 0xc0});
183
 
184
    write_mem16(0x0fe, 0xaa55, SS);
185
    write_reg(SP, 0x0fe);
186
 
187
    emulate();
188
 
189
    ASSERT_EQ(0x100, read_reg(SP));
190
    ASSERT_EQ(0xaa55, read_reg(AX));
191
}
192
 
193
TEST_F(EmulateFixture, PopMem8F)
194
{
195
    // pop [1234]
196
    set_instruction({0x8f, 0x06, 0x34, 0x12});
197
 
198
    write_mem16(0x0fe, 0xaa55, SS);
199
    write_reg(SP, 0x0fe);
200
 
201
    emulate();
202
 
203
    ASSERT_EQ(0x100, read_reg(SP));
204
    ASSERT_EQ(0xaa55, read_mem16(0x1234, DS));
205
}
206
 
207
TEST_F(EmulateFixture, PopReg8FInvalidReg)
208
{
209
    // pop ax
210
    set_instruction({0x8f, 0xc8});
211
 
212
    write_mem16(0x0fe, 0xaa55, SS);
213
    write_reg(SP, 0x0fe);
214
 
215
    emulate();
216
 
217
    ASSERT_EQ(0x0fe, read_reg(SP));
218
    ASSERT_EQ(0x0, read_reg(AX));
219
 
220
    ASSERT_FALSE(instruction_had_side_effects());
221
}
222
 
223
TEST_F(EmulateFixture, PopReg5X)
224
{
225
    // pop r
226
    for (uint8_t i = 0; i < 8; ++i) {
227
        reset();
228
 
229
        auto reg = static_cast<GPR>(static_cast<int>(AX) + i);
230
        write_mem16(0x0fe, 0x0100 + i, SS);
231
        write_reg(SP, 0x0fe);
232
 
233
        set_instruction({static_cast<uint8_t>(0x58 + i)});
234
        emulate();
235
 
236
        if (reg != SP)
237
            EXPECT_EQ(0x100, read_reg(SP));
238
        EXPECT_EQ(0x0100 + i, read_reg(reg));
239
    }
240
}
241
 
242
TEST_F(EmulateFixture, PopSR)
243
{
244
    // pop sr
245
    for (uint8_t i = 0; i < 4; ++i) {
246
        auto reg = static_cast<GPR>(static_cast<int>(ES) + i);
247
        if (reg == CS)
248
            continue;
249
 
250
        reset();
251
 
252
        write_reg(SS, 0);
253
 
254
        write_mem16(0x0fe, 0x0100 + i, SS);
255
        write_reg(SP, 0x0fe);
256
 
257
        set_instruction({static_cast<uint8_t>((i << 3) | 0x7)});
258
        emulate();
259
 
260
        ASSERT_EQ(0x100, read_reg(SP));
261
        ASSERT_EQ(0x0100 + i, read_reg(reg));
262
    }
263
}

powered by: WebSVN 2.1.0

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