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

Subversion Repositories s80186

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

powered by: WebSVN 2.1.0

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