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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [sim/] [cppmodel/] [instructions/] [inc_dec.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
// inc r/m, 8-bit
19
void EmulatorPimpl::inc_dec_fe()
20
{
21
    modrm_decoder->set_width(OP_WIDTH_8);
22
    modrm_decoder->decode();
23
 
24
    if (modrm_decoder->raw_reg() == 7) {
25
        invalid_opcode();
26
        return;
27
    }
28
 
29
    if (modrm_decoder->raw_reg() != 0 && modrm_decoder->raw_reg() != 1) {
30
        std::cerr << "warning: invalid reg " << std::hex
31
                  << (unsigned)modrm_decoder->raw_reg() << " for opcode 0x"
32
                  << opcode << std::endl;
33
        return;
34
    }
35
 
36
    uint8_t v = read_data<uint8_t>();
37
    uint8_t result;
38
    uint16_t flags;
39
 
40
    if (modrm_decoder->raw_reg() == 0)
41
        std::tie(flags, result) = do_add<uint8_t>(v, 1);
42
    else
43
        std::tie(flags, result) = do_sub<uint8_t>(v, 1);
44
 
45
    registers->set_flags(flags, OF | SF | ZF | AF | PF);
46
    write_data<uint8_t>(result);
47
}
48
 
49
// inc r/m, 16-bit
50
void EmulatorPimpl::incff()
51
{
52
    assert(modrm_decoder->raw_reg() == 0);
53
 
54
    uint16_t v = read_data<uint16_t>();
55
    uint16_t result;
56
    uint16_t flags;
57
 
58
    std::tie(flags, result) = do_add<uint16_t>(v, 1);
59
 
60
    registers->set_flags(flags, OF | SF | ZF | AF | PF);
61
    write_data<uint16_t>(result);
62
}
63
 
64
// inc r, 16-bit
65
void EmulatorPimpl::inc40_47()
66
{
67
    auto reg = static_cast<GPR>(static_cast<int>(AX) + (opcode & 0x7));
68
    auto v = registers->get(reg);
69
    uint16_t result;
70
    uint16_t flags;
71
 
72
    std::tie(flags, result) = do_add<uint16_t>(v, 1);
73
 
74
    registers->set_flags(flags, OF | SF | ZF | AF | PF);
75
    registers->set(reg, result);
76
}
77
 
78
// dec r/m, 16-bit
79
void EmulatorPimpl::decff()
80
{
81
    assert(modrm_decoder->raw_reg() == 1);
82
 
83
    uint16_t v = read_data<uint16_t>();
84
    uint16_t result;
85
    uint16_t flags;
86
 
87
    std::tie(flags, result) = do_sub<uint16_t>(v, 1);
88
 
89
    registers->set_flags(flags, OF | SF | ZF | AF | PF);
90
    write_data<uint16_t>(result);
91
}
92
 
93
// dec r, 16-bit
94
void EmulatorPimpl::dec48_4f()
95
{
96
    auto reg = static_cast<GPR>(static_cast<int>(AX) + (opcode & 0x7));
97
    auto v = registers->get(reg);
98
    uint16_t result;
99
    uint16_t flags;
100
 
101
    std::tie(flags, result) = do_sub<uint16_t>(v, 1);
102
 
103
    registers->set_flags(flags, OF | SF | ZF | AF | PF);
104
    registers->set(reg, result);
105
}

powered by: WebSVN 2.1.0

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