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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [tests/] [instructions/] [Arithmetic.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 "Arithmetic.h"
19
#include "Flags.h"
20
 
21
TEST_P(ArithmeticRegReg8Test, ResultAndFlags)
22
{
23
    auto params = GetParam();
24
    for (auto &t : params.second) {
25
        reset();
26
        SCOPED_TRACE(std::to_string(static_cast<int>(t.v1)) + " + " +
27
                     std::to_string(static_cast<int>(t.v2)) + " + " +
28
                     std::to_string(static_cast<int>(t.carry_set)));
29
        write_flags(0);
30
        if (t.carry_set)
31
            write_flags(CF);
32
        write_reg(AL, t.v1);
33
        write_reg(BL, t.v2);
34
        // ARITH al, bl
35
        set_instruction(params.first);
36
 
37
        emulate();
38
 
39
        ASSERT_EQ(read_reg(AL), t.expected);
40
        ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
41
                            FLAGS_STUCK_BITS | t.expected_flags);
42
    }
43
}
44
 
45
TEST_P(ArithmeticMemReg8Test, ResultAndFlags)
46
{
47
    auto params = GetParam();
48
    for (auto &t : params.second) {
49
        reset();
50
        SCOPED_TRACE(std::to_string(static_cast<int>(t.v1)) + " + " +
51
                     std::to_string(static_cast<int>(t.v2)) + " + " +
52
                     std::to_string(static_cast<int>(t.carry_set)));
53
        write_flags(0);
54
        if (t.carry_set)
55
            write_flags(CF);
56
        write_reg(AL, t.v2);
57
        write_reg(BX, 0x100);
58
        write_mem8(0x100, t.v1);
59
 
60
        // ARITH [bx], al
61
        set_instruction(params.first);
62
 
63
        emulate();
64
 
65
        ASSERT_EQ(read_mem8(0x100), t.expected);
66
        ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
67
                            FLAGS_STUCK_BITS | t.expected_flags);
68
    }
69
}
70
 
71
TEST_P(ArithmeticRegReg8TestReversed, ResultAndFlags)
72
{
73
    auto params = GetParam();
74
    for (auto &t : params.second) {
75
        reset();
76
        SCOPED_TRACE(std::to_string(static_cast<int>(t.v1)) + " + " +
77
                     std::to_string(static_cast<int>(t.v2)) + " + " +
78
                     std::to_string(static_cast<int>(t.carry_set)));
79
        write_flags(0);
80
        if (t.carry_set)
81
            write_flags(CF);
82
        write_reg(AL, t.v2);
83
        write_reg(BL, t.v1);
84
        // ARITH bl, al
85
        set_instruction(params.first);
86
 
87
        emulate();
88
 
89
        ASSERT_EQ(read_reg(BL), t.expected);
90
        ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
91
                            FLAGS_STUCK_BITS | t.expected_flags);
92
    }
93
}
94
 
95
TEST_P(ArithmeticMemReg8TestReversed, ResultAndFlags)
96
{
97
    auto params = GetParam();
98
    for (auto &t : params.second) {
99
        reset();
100
        SCOPED_TRACE(std::to_string(static_cast<int>(t.v1)) + " + " +
101
                     std::to_string(static_cast<int>(t.v2)) + " + " +
102
                     std::to_string(static_cast<int>(t.carry_set)));
103
        write_flags(0);
104
        if (t.carry_set)
105
            write_flags(CF);
106
        write_reg(AL, t.v1);
107
        write_reg(BX, 0x100);
108
        write_mem8(0x100, t.v2);
109
 
110
        // ARITH al, [bx]
111
        set_instruction(params.first);
112
 
113
        emulate();
114
 
115
        ASSERT_EQ(read_reg(AL), t.expected);
116
        ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
117
                            FLAGS_STUCK_BITS | t.expected_flags);
118
    }
119
}
120
 
121
TEST_P(ArithmeticRegReg8TestReversedNoResult, ResultAndFlags)
122
{
123
    auto params = GetParam();
124
    for (auto &t : params.second) {
125
        reset();
126
        SCOPED_TRACE(std::to_string(static_cast<int>(t.v1)) + " + " +
127
                     std::to_string(static_cast<int>(t.v2)) + " + " +
128
                     std::to_string(static_cast<int>(t.carry_set)));
129
        write_flags(0);
130
        if (t.carry_set)
131
            write_flags(CF);
132
        write_reg(AL, t.v2);
133
        write_reg(BL, t.v1);
134
        // ARITH bl, al
135
        set_instruction(params.first);
136
 
137
        emulate();
138
 
139
        ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
140
                            FLAGS_STUCK_BITS | t.expected_flags);
141
    }
142
}
143
 
144
TEST_P(ArithmeticMemReg8TestReversedNoResult, ResultAndFlags)
145
{
146
    auto params = GetParam();
147
    for (auto &t : params.second) {
148
        reset();
149
        SCOPED_TRACE(std::to_string(static_cast<int>(t.v1)) + " + " +
150
                     std::to_string(static_cast<int>(t.v2)) + " + " +
151
                     std::to_string(static_cast<int>(t.carry_set)));
152
        write_flags(0);
153
        if (t.carry_set)
154
            write_flags(CF);
155
        write_reg(AL, t.v1);
156
        write_reg(BX, 0x100);
157
        write_mem8(0x100, t.v2);
158
 
159
        // ARITH al, [bx]
160
        set_instruction(params.first);
161
 
162
        emulate();
163
 
164
        ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
165
                            FLAGS_STUCK_BITS | t.expected_flags);
166
    }
167
}
168
 
169
TEST_P(ArithmeticRegReg16Test, ResultAndFlags)
170
{
171
    auto params = GetParam();
172
    for (auto &t : params.second) {
173
        reset();
174
        SCOPED_TRACE(std::to_string(static_cast<int>(t.v1)) + " + " +
175
                     std::to_string(static_cast<int>(t.v2)) + " + " +
176
                     std::to_string(static_cast<int>(t.carry_set)));
177
        write_flags(0);
178
        if (t.carry_set)
179
            write_flags(CF);
180
        write_reg(AX, t.v1);
181
        write_reg(BX, t.v2);
182
        // ARITH ax, bx
183
        set_instruction(params.first);
184
 
185
        emulate();
186
 
187
        ASSERT_EQ(read_reg(AX), t.expected);
188
        ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
189
                            FLAGS_STUCK_BITS | t.expected_flags);
190
    }
191
}
192
 
193
TEST_P(ArithmeticRegMem16Test, ResultAndFlags)
194
{
195
    auto params = GetParam();
196
    for (auto &t : params.second) {
197
        reset();
198
        SCOPED_TRACE(std::to_string(static_cast<int>(t.v1)) + " + " +
199
                     std::to_string(static_cast<int>(t.v2)) + " + " +
200
                     std::to_string(static_cast<int>(t.carry_set)));
201
        write_flags(0);
202
        if (t.carry_set)
203
            write_flags(CF);
204
        write_reg(AX, t.v2);
205
        write_reg(BX, 0x100);
206
        write_mem16(0x100, t.v1);
207
 
208
        // ARITH [bx], ax
209
        set_instruction(params.first);
210
 
211
        emulate();
212
 
213
        ASSERT_EQ(read_mem16(0x100), t.expected);
214
        ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
215
                            FLAGS_STUCK_BITS | t.expected_flags);
216
    }
217
}
218
 
219
TEST_P(ArithmeticRegReg16TestReversed, ResultAndFlags)
220
{
221
    auto params = GetParam();
222
    for (auto &t : params.second) {
223
        reset();
224
        SCOPED_TRACE(std::to_string(static_cast<int>(t.v1)) + " + " +
225
                     std::to_string(static_cast<int>(t.v2)) + " + " +
226
                     std::to_string(static_cast<int>(t.carry_set)));
227
        write_flags(0);
228
        if (t.carry_set)
229
            write_flags(CF);
230
        write_reg(AX, t.v2);
231
        write_reg(BX, t.v1);
232
        // ARITH bx, ax
233
        set_instruction(params.first);
234
 
235
        emulate();
236
 
237
        ASSERT_EQ(read_reg(BX), t.expected);
238
        ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
239
                            FLAGS_STUCK_BITS | t.expected_flags);
240
    }
241
}
242
 
243
TEST_P(ArithmeticMemReg16TestReversed, ResultAndFlags)
244
{
245
    auto params = GetParam();
246
    for (auto &t : params.second) {
247
        reset();
248
        SCOPED_TRACE(std::to_string(static_cast<int>(t.v1)) + " + " +
249
                     std::to_string(static_cast<int>(t.v2)) + " + " +
250
                     std::to_string(static_cast<int>(t.carry_set)));
251
        write_flags(0);
252
        if (t.carry_set)
253
            write_flags(CF);
254
        write_reg(AX, t.v1);
255
        write_reg(BX, 0x100);
256
        write_mem16(0x100, t.v2);
257
 
258
        // ARITH ax, [bx]
259
        set_instruction(params.first);
260
 
261
        emulate();
262
 
263
        ASSERT_EQ(read_reg(AX), t.expected);
264
        ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
265
                            FLAGS_STUCK_BITS | t.expected_flags);
266
    }
267
}
268
 
269
TEST_P(ArithmeticRegReg16TestReversedNoResult, ResultAndFlags)
270
{
271
    auto params = GetParam();
272
    for (auto &t : params.second) {
273
        reset();
274
        SCOPED_TRACE(std::to_string(static_cast<int>(t.v1)) + " + " +
275
                     std::to_string(static_cast<int>(t.v2)) + " + " +
276
                     std::to_string(static_cast<int>(t.carry_set)));
277
        write_flags(0);
278
        if (t.carry_set)
279
            write_flags(CF);
280
        write_reg(AX, t.v2);
281
        write_reg(BX, t.v1);
282
        // ARITH bx, ax
283
        set_instruction(params.first);
284
 
285
        emulate();
286
 
287
        ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
288
                            FLAGS_STUCK_BITS | t.expected_flags);
289
    }
290
}
291
 
292
TEST_P(ArithmeticMemReg16TestReversedNoResult, ResultAndFlags)
293
{
294
    auto params = GetParam();
295
    for (auto &t : params.second) {
296
        reset();
297
        SCOPED_TRACE(std::to_string(static_cast<int>(t.v1)) + " + " +
298
                     std::to_string(static_cast<int>(t.v2)) + " + " +
299
                     std::to_string(static_cast<int>(t.carry_set)));
300
        write_flags(0);
301
        if (t.carry_set)
302
            write_flags(CF);
303
        write_reg(AX, t.v1);
304
        write_reg(BX, 0x100);
305
        write_mem16(0x100, t.v2);
306
 
307
        // ARITH ax, [bx]
308
        set_instruction(params.first);
309
 
310
        emulate();
311
 
312
        ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
313
                            FLAGS_STUCK_BITS | t.expected_flags);
314
    }
315
}
316
 
317
TEST_P(ArithmeticRegImmed8Test, ResultAndFlags)
318
{
319
    auto params = GetParam();
320
    if (params.second.carry_set)
321
        write_flags(CF);
322
    set_instruction(params.first);
323
    write_reg(BL, params.second.v1);
324
 
325
    emulate();
326
 
327
    ASSERT_EQ(read_reg(BL), params.second.expected);
328
    ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
329
                        FLAGS_STUCK_BITS | params.second.expected_flags);
330
}
331
 
332
TEST_P(ArithmeticMemImmed8Test, ResultAndFlags)
333
{
334
    auto params = GetParam();
335
    if (params.second.carry_set)
336
        write_flags(CF);
337
    set_instruction(params.first);
338
    write_mem8(0x0100, params.second.v1);
339
    write_reg(BX, 0x0100);
340
 
341
    emulate();
342
 
343
    ASSERT_EQ(read_mem8(0x0100), params.second.expected);
344
    ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
345
                        FLAGS_STUCK_BITS | params.second.expected_flags);
346
}
347
 
348
TEST_P(ArithmeticRegImmed16Test, ResultAndFlags)
349
{
350
    auto params = GetParam();
351
    if (params.second.carry_set)
352
        write_flags(CF);
353
    // ARITH bx, 1
354
    set_instruction(params.first);
355
    write_reg(BX, params.second.v1);
356
 
357
    emulate();
358
 
359
    ASSERT_EQ(read_reg(BX), params.second.expected);
360
    ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
361
                        FLAGS_STUCK_BITS | params.second.expected_flags);
362
}
363
 
364
TEST_P(ArithmeticMemImmed16Test, ResultAndFlags)
365
{
366
    auto params = GetParam();
367
    if (params.second.carry_set)
368
        write_flags(CF);
369
    // ARITH word [bx], 1
370
    set_instruction(params.first);
371
    write_mem16(0x0100, params.second.v1);
372
    write_reg(BX, 0x0100);
373
 
374
    emulate();
375
 
376
    ASSERT_EQ(read_mem16(0x0100), params.second.expected);
377
    ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
378
                        FLAGS_STUCK_BITS | params.second.expected_flags);
379
}
380
 
381
TEST_P(ArithmeticRegImmed16TestExtend, ResultAndFlags)
382
{
383
    auto params = GetParam();
384
    if (params.second.carry_set)
385
        write_flags(CF);
386
    // ARITH bx, -1
387
    set_instruction(params.first);
388
    write_reg(BX, params.second.v1);
389
 
390
    emulate();
391
 
392
    ASSERT_EQ(read_reg(BX), params.second.expected);
393
    ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
394
                        FLAGS_STUCK_BITS | params.second.expected_flags);
395
}
396
 
397
TEST_P(ArithmeticMemImmed16TestExtend, ResultAndFlags)
398
{
399
    auto params = GetParam();
400
    if (params.second.carry_set)
401
        write_flags(CF);
402
    // ARITH word [bx], 1
403
    set_instruction(params.first);
404
    write_mem16(0x0100, params.second.v1);
405
    write_reg(BX, 0x0100);
406
 
407
    emulate();
408
 
409
    ASSERT_EQ(read_mem16(0x0100), params.second.expected);
410
    ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
411
                        FLAGS_STUCK_BITS | params.second.expected_flags);
412
}
413
 
414
TEST_P(ArithmeticAlImmedTest, ResultAndFlags)
415
{
416
    auto params = GetParam();
417
    if (params.second.carry_set)
418
        write_flags(CF);
419
    // ARITH al, 1
420
    set_instruction(params.first);
421
    write_reg(AL, params.second.v1);
422
 
423
    emulate();
424
 
425
    ASSERT_EQ(read_reg(AL), params.second.expected);
426
    ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
427
                        FLAGS_STUCK_BITS | params.second.expected_flags);
428
}
429
 
430
TEST_P(ArithmeticAxImmedTest, ResultAndFlags)
431
{
432
    auto params = GetParam();
433
    if (params.second.carry_set)
434
        write_flags(CF);
435
    // ARITH ax, 1
436
    set_instruction(params.first);
437
    write_reg(AX, params.second.v1);
438
 
439
    emulate();
440
 
441
    ASSERT_EQ(read_reg(AX), params.second.expected);
442
    ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
443
                        FLAGS_STUCK_BITS | params.second.expected_flags);
444
}

powered by: WebSVN 2.1.0

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