| 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 |
|
|
// imul r/m, 8-bit
|
| 19 |
|
|
void EmulatorPimpl::imulf6()
|
| 20 |
|
|
{
|
| 21 |
|
|
auto old_flags = registers->get_flags();
|
| 22 |
|
|
int16_t v1 = sign_extend<int16_t, uint8_t>(read_data<uint8_t>());
|
| 23 |
|
|
int16_t v2 = sign_extend<int16_t, uint8_t>(registers->get(AL));
|
| 24 |
|
|
|
| 25 |
|
|
uint16_t result, flags;
|
| 26 |
|
|
std::tie(flags, result) = do_mul<int16_t>(v1, v2);
|
| 27 |
|
|
flags = old_flags & ~(CF | OF | ZF);
|
| 28 |
|
|
if (result & 0xff00)
|
| 29 |
|
|
flags |= CF | OF;
|
| 30 |
|
|
|
| 31 |
|
|
registers->set(AX, result);
|
| 32 |
|
|
registers->set_flags(flags, OF | CF | ZF);
|
| 33 |
|
|
}
|
| 34 |
|
|
|
| 35 |
|
|
// imul r/m, 16-bit
|
| 36 |
|
|
void EmulatorPimpl::imulf7()
|
| 37 |
|
|
{
|
| 38 |
|
|
auto old_flags = registers->get_flags();
|
| 39 |
|
|
int32_t v1 = sign_extend<int32_t, uint16_t>(read_data<uint16_t>());
|
| 40 |
|
|
int32_t v2 = sign_extend<int32_t, uint16_t>(registers->get(AX));
|
| 41 |
|
|
|
| 42 |
|
|
uint32_t result;
|
| 43 |
|
|
uint16_t flags;
|
| 44 |
|
|
std::tie(flags, result) = do_mul<int32_t>(v1, v2);
|
| 45 |
|
|
flags = old_flags & ~(CF | OF | ZF);
|
| 46 |
|
|
if (result & 0xffff0000)
|
| 47 |
|
|
flags |= CF | OF;
|
| 48 |
|
|
|
| 49 |
|
|
registers->set(AX, result & 0xffff);
|
| 50 |
|
|
registers->set(DX, (result >> 16) & 0xffff);
|
| 51 |
|
|
registers->set_flags(flags, OF | CF | ZF);
|
| 52 |
|
|
}
|
| 53 |
|
|
|
| 54 |
|
|
// imul r/m, 16-bit immediate
|
| 55 |
|
|
void EmulatorPimpl::imul69()
|
| 56 |
|
|
{
|
| 57 |
|
|
modrm_decoder->set_width(OP_WIDTH_16);
|
| 58 |
|
|
modrm_decoder->decode();
|
| 59 |
|
|
|
| 60 |
|
|
auto old_flags = registers->get_flags();
|
| 61 |
|
|
int32_t v1 = sign_extend<int32_t, int16_t>(read_data<uint16_t>());
|
| 62 |
|
|
int32_t v2 = sign_extend<int32_t, int16_t>(fetch_16bit());
|
| 63 |
|
|
|
| 64 |
|
|
uint32_t result;
|
| 65 |
|
|
uint16_t flags;
|
| 66 |
|
|
std::tie(flags, result) = do_mul<int32_t>(v1, v2);
|
| 67 |
|
|
flags = old_flags & ~(CF | OF | ZF);
|
| 68 |
|
|
if (result & 0xffff0000)
|
| 69 |
|
|
flags |= CF | OF;
|
| 70 |
|
|
|
| 71 |
|
|
registers->set(modrm_decoder->reg(), result & 0xffff);
|
| 72 |
|
|
registers->set_flags(flags, OF | CF | ZF);
|
| 73 |
|
|
}
|
| 74 |
|
|
|
| 75 |
|
|
// imul r/m, 8-bit immediate
|
| 76 |
|
|
void EmulatorPimpl::imul6b()
|
| 77 |
|
|
{
|
| 78 |
|
|
modrm_decoder->set_width(OP_WIDTH_16);
|
| 79 |
|
|
modrm_decoder->decode();
|
| 80 |
|
|
|
| 81 |
|
|
auto old_flags = registers->get_flags();
|
| 82 |
|
|
int32_t v1 = sign_extend<int32_t, int16_t>(read_data<uint16_t>());
|
| 83 |
|
|
int32_t v2 = sign_extend<int32_t, int8_t>(fetch_byte());
|
| 84 |
|
|
|
| 85 |
|
|
uint32_t result;
|
| 86 |
|
|
uint16_t flags;
|
| 87 |
|
|
std::tie(flags, result) = do_mul<int32_t>(v1, v2);
|
| 88 |
|
|
flags = old_flags & ~(CF | OF | ZF);
|
| 89 |
|
|
if (result & 0xffff0000)
|
| 90 |
|
|
flags |= CF | OF;
|
| 91 |
|
|
|
| 92 |
|
|
registers->set(modrm_decoder->reg(), result & 0xffff);
|
| 93 |
|
|
registers->set_flags(flags, OF | CF | ZF);
|
| 94 |
|
|
}
|