diff options
Diffstat (limited to 'src/mame/machine/k007452.cpp')
-rw-r--r-- | src/mame/machine/k007452.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/src/mame/machine/k007452.cpp b/src/mame/machine/k007452.cpp new file mode 100644 index 00000000000..3f6a3202d61 --- /dev/null +++ b/src/mame/machine/k007452.cpp @@ -0,0 +1,101 @@ +// license:BSD-3-Clause +// copyright-holders:Sean Gonsalves +/*************************************************************************** + + Konami 007452 multiplier/divider + +***************************************************************************/ + +#include "emu.h" +#include "k007452.h" + +//************************************************************************** +// CONSTANTS +//************************************************************************** + +// device type definition +DEFINE_DEVICE_TYPE(KONAMI_007452_MATH, k007452_device, "konami_007452", "Konami 007452 math chip") + +//------------------------------------------------- +// k007452_device - constructor +//------------------------------------------------- + +k007452_device::k007452_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) + : device_t(mconfig, KONAMI_007452_MATH, tag, owner, clock) +{ +} + + +//------------------------------------------------- +// read - read the registers +//------------------------------------------------- + +uint8_t k007452_device::read(offs_t offset) +{ + switch (offset & 7) + { + case 0: return m_multiply_result & 0xff; + case 1: return (m_multiply_result >> 8) & 0xff; + case 2: return m_divide_remainder & 0xff; + case 3: return (m_divide_remainder >> 8) & 0xff; + case 4: return m_divide_quotient & 0xff; + case 5: return (m_divide_quotient >> 8) & 0xff; + default: return 0; + } +} + + +//------------------------------------------------- +// write - write to the registers +//------------------------------------------------- + +void k007452_device::write(offs_t offset, u8 data) +{ + if (offset < 6) m_math_regs[offset] = data; + + if (offset == 1) + { + // Starts multiplication process + m_multiply_result = m_math_regs[0] * m_math_regs[1]; + } + else if (offset == 5) + { + // Starts division process + u16 dividend = (m_math_regs[4]<<8) + m_math_regs[5]; + u16 divisor = (m_math_regs[2]<<8) + m_math_regs[3]; + if (!divisor) { + m_divide_quotient = 0xffff; + m_divide_remainder = 0x0000; + } else { + m_divide_quotient = dividend / divisor; + m_divide_remainder = dividend % divisor; + } + } +} + + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void k007452_device::device_start() +{ + save_item(NAME(m_math_regs)); + save_item(NAME(m_multiply_result)); + save_item(NAME(m_divide_quotient)); + save_item(NAME(m_divide_remainder)); +} + + +//------------------------------------------------- +// device_reset - device-specific reset +//------------------------------------------------- + +void k007452_device::device_reset() +{ + std::fill(std::begin(m_math_regs), std::end(m_math_regs), 0); + m_multiply_result = 0; + m_divide_quotient = 0; + m_divide_remainder = 0; +} + |