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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [sim/] [cppmodel/] [instructions/] [mov.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
// mov m/r, r (8-bit)
19
void EmulatorPimpl::mov88()
20
{
21
    modrm_decoder->set_width(OP_WIDTH_8);
22
    modrm_decoder->decode();
23
 
24
    auto source = modrm_decoder->reg();
25
    auto val = registers->get(source);
26
 
27
    write_data<uint8_t>(val);
28
}
29
 
30
// mov m/r, r (16-bit)
31
void EmulatorPimpl::mov89()
32
{
33
    modrm_decoder->set_width(OP_WIDTH_16);
34
    modrm_decoder->decode();
35
 
36
    auto source = modrm_decoder->reg();
37
    auto val = registers->get(source);
38
 
39
    write_data<uint16_t>(val);
40
}
41
 
42
// mov r, m/r (8-bit)
43
void EmulatorPimpl::mov8a()
44
{
45
    modrm_decoder->set_width(OP_WIDTH_8);
46
    modrm_decoder->decode();
47
 
48
    uint8_t val = read_data<uint8_t>();
49
 
50
    auto dest = modrm_decoder->reg();
51
    registers->set(dest, val);
52
}
53
 
54
// mov r, m/r (16-bit)
55
void EmulatorPimpl::mov8b()
56
{
57
    modrm_decoder->set_width(OP_WIDTH_16);
58
    modrm_decoder->decode();
59
 
60
    uint16_t val = read_data<uint16_t>();
61
 
62
    auto dest = modrm_decoder->reg();
63
    registers->set(dest, val);
64
}
65
 
66
// mov r/m, immediate (reg == 0), 8-bit
67
void EmulatorPimpl::movc6()
68
{
69
    modrm_decoder->set_width(OP_WIDTH_8);
70
    modrm_decoder->decode();
71
 
72
    if (modrm_decoder->raw_reg() == 0) {
73
        uint8_t immed = fetch_byte();
74
        write_data<uint8_t>(immed);
75
    }
76
}
77
 
78
// mov r/m, immediate (reg == 0), 16-bit
79
void EmulatorPimpl::movc7()
80
{
81
    modrm_decoder->set_width(OP_WIDTH_16);
82
    modrm_decoder->decode();
83
 
84
    if (modrm_decoder->raw_reg() == 0)
85
        write_data<uint16_t>(fetch_16bit());
86
}
87
 
88
// mov r, immediate, 8-bit
89
void EmulatorPimpl::movb0_b7()
90
{
91
    uint8_t immed = fetch_byte();
92
    auto reg = static_cast<GPR>(static_cast<int>(AL) + (opcode & 0x7));
93
    registers->set(reg, immed);
94
}
95
 
96
// mov r, immediate, 16-bit
97
void EmulatorPimpl::movb8_bf()
98
{
99
    uint16_t immed = fetch_16bit();
100
    auto reg = static_cast<GPR>(static_cast<int>(AX) + (opcode & 0x7));
101
    registers->set(reg, immed);
102
}
103
 
104
// mov al, m, 8-bit
105
void EmulatorPimpl::mova0()
106
{
107
    auto displacement = fetch_16bit();
108
    auto addr = get_phys_addr(registers->get(get_segment(false)), displacement);
109
    auto val = mem->read<uint8_t>(addr);
110
    registers->set(AL, val);
111
}
112
 
113
// mov ax, m, 16-bit
114
void EmulatorPimpl::mova1()
115
{
116
    auto displacement = fetch_16bit();
117
    auto addr = get_phys_addr(registers->get(get_segment(false)), displacement);
118
    auto val = mem->read<uint16_t>(addr);
119
    registers->set(AX, val);
120
}
121
 
122
// mov m, al 8-bit
123
void EmulatorPimpl::mova2()
124
{
125
    auto displacement = fetch_16bit();
126
    auto val = registers->get(AL);
127
    auto addr = get_phys_addr(registers->get(get_segment(false)), displacement);
128
    mem->write<uint8_t>(addr, val);
129
}
130
 
131
// mov m, al 16-bit
132
void EmulatorPimpl::mova3()
133
{
134
    auto displacement = fetch_16bit();
135
    auto val = registers->get(AX);
136
    auto addr = get_phys_addr(registers->get(get_segment(false)), displacement);
137
    mem->write<uint16_t>(addr, val);
138
}
139
 
140
// mov sr, r/m
141
void EmulatorPimpl::mov8e()
142
{
143
    modrm_decoder->set_width(OP_WIDTH_16);
144
    modrm_decoder->decode();
145
 
146
    uint16_t val = read_data<uint16_t>();
147
    auto segnum = modrm_decoder->raw_reg() & 0x3;
148
    auto reg = static_cast<GPR>(static_cast<int>(ES) + segnum);
149
 
150
    registers->set(reg, val);
151
    ext_int_inhibit = true;
152
}
153
 
154
// mov r/m, sr
155
void EmulatorPimpl::mov8c()
156
{
157
    modrm_decoder->set_width(OP_WIDTH_16);
158
    modrm_decoder->decode();
159
 
160
    auto segnum = modrm_decoder->raw_reg() & 0x3;
161
    auto reg = static_cast<GPR>(static_cast<int>(ES) + segnum);
162
    uint16_t val = registers->get(reg);
163
 
164
    write_data<uint16_t>(val);
165
}

powered by: WebSVN 2.1.0

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