summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/machine/k007452.cpp
blob: 3f6a3202d610370388e0e029822e65f0be674206 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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;
}