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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [sim/] [cppmodel/] [instructions/] [ror.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
template <typename T>
19
std::pair<uint16_t, T> do_ror(T v, int count)
20
{
21
    uint16_t flags = 0;
22
 
23
    for (int i = 0; i < count; ++i) {
24
        flags &= ~CF;
25
        if (v & 0x1)
26
            flags |= CF;
27
        T lsb = v & 1;
28
        v >>= 1;
29
        v += (lsb << ((sizeof(T) * 8) - 1));
30
    }
31
 
32
    // 2 MSB's XOR'd == OF
33
    T msbs = (v >> ((sizeof(T) * 8) - 2)) & 0x3;
34
    if (msbs == 2 || msbs == 1)
35
        flags |= OF;
36
 
37
    return std::make_pair(flags, v);
38
}
39
 
40
// ror r/m, N
41
void EmulatorPimpl::rorc0()
42
{
43
    auto v = read_data<uint8_t>();
44
    auto count = fetch_byte();
45
    uint16_t flags;
46
 
47
    if (!(count & 0x1f))
48
        return;
49
 
50
    std::tie(flags, v) = do_ror(v, count & 0x1f);
51
 
52
    write_data<uint8_t>(v);
53
    registers->set_flags(flags, CF);
54
}
55
 
56
// ror r/m, 1
57
void EmulatorPimpl::rorc1()
58
{
59
    auto v = read_data<uint16_t>();
60
    auto count = fetch_byte();
61
    uint16_t flags;
62
 
63
    if (!(count & 0x1f))
64
        return;
65
 
66
    std::tie(flags, v) = do_ror(v, count & 0x1f);
67
 
68
    write_data<uint16_t>(v);
69
    registers->set_flags(flags, CF);
70
}
71
 
72
// ror r/m, 1
73
void EmulatorPimpl::rord0()
74
{
75
    auto v = read_data<uint8_t>();
76
    uint16_t flags;
77
 
78
    std::tie(flags, v) = do_ror(v, 1);
79
 
80
    write_data<uint8_t>(v);
81
    registers->set_flags(flags, CF | OF);
82
}
83
 
84
// ror r/m, 1
85
void EmulatorPimpl::rord1()
86
{
87
    auto v = read_data<uint16_t>();
88
    uint16_t flags;
89
 
90
    std::tie(flags, v) = do_ror(v, 1);
91
 
92
    write_data<uint16_t>(v);
93
    registers->set_flags(flags, CF | OF);
94
}
95
 
96
// ror r/m, N
97
void EmulatorPimpl::rord2()
98
{
99
    auto v = read_data<uint8_t>();
100
    uint16_t flags;
101
 
102
    if (!registers->get(CL))
103
        return;
104
 
105
    std::tie(flags, v) = do_ror(v, registers->get(CL));
106
 
107
    write_data<uint8_t>(v);
108
    registers->set_flags(flags, CF);
109
}
110
 
111
// ror r/m, N
112
void EmulatorPimpl::rord3()
113
{
114
    auto v = read_data<uint16_t>();
115
    uint16_t flags;
116
 
117
    if (!registers->get(CL))
118
        return;
119
 
120
    std::tie(flags, v) = do_ror(v, registers->get(CL));
121
 
122
    write_data<uint16_t>(v);
123
    registers->set_flags(flags, CF);
124
}

powered by: WebSVN 2.1.0

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