summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/cpu/m6502/r65c19.cpp
blob: 9cda9d33a0e0d92146734e79abc522d52691bc65 (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
102
103
104
105
106
// license:BSD-3-Clause
// copyright-holders:AJR
/**********************************************************************

    Rockwell R65C19 Microcomputer (MCU)

    TODO: fully describe this MCU and its successors (C29, C39) and
    emulate their internal peripherals (only core emulation now)

**********************************************************************/

#include "emu.h"
#include "r65c19.h"
#include "r65c19d.h"

DEFINE_DEVICE_TYPE(R65C19, r65c19_device, "r65c19", "Rockwell R65C19 MCU")

r65c19_device::r65c19_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock, address_map_constructor internal_map)
	: r65c02_device(mconfig, type, tag, owner, clock)
	, m_w(0)
	, m_i(0)
{
	program_config.m_internal_map = std::move(internal_map);
}

r65c19_device::r65c19_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
	: r65c19_device(mconfig, R65C19, tag, owner, clock, address_map_constructor())
{
}

std::unique_ptr<util::disasm_interface> r65c19_device::create_disassembler()
{
	return std::make_unique<r65c19_disassembler>();
}

void r65c19_device::do_add(u8 v)
{
	P &= ~F_C;
	do_adc(v);
}

u16 r65c19_device::do_accumulate(u16 v, u16 w)
{
	// Compute the sum
	s32 result = s16(v) + s16(w);

	// Determine flags and saturate result upon overflow
	P &= ~(F_N | F_V);
	if (result > 32767)
	{
		P |= F_V;
		result = 32767;
	}
	else if (result < 0)
	{
		P |= F_N;
		if (result < -32768)
		{
			P |= F_V;
			result = -32768;
		}
	}

	// MPA and MPY always destroy the old value of Y, as does RND when it overflows
	Y = result & 0xff;

	// 16-bit result to W, or high byte to A
	return result & 0xffff;
}

u16 r65c19_device::get_irq_vector()
{
	// TODO: this is a stub
	return 0xfffc;
}

void r65c19_device::device_start()
{
	mintf = std::make_unique<mi_default>();

	c19_init();
}

void r65c19_device::c19_init()
{
	init();

	state_add(R65C19_W, "W", m_w);
	state_add<u8>(R65C19_WL, "WL",
		[this]() { return m_w & 0xff; },
		[this](u8 data) { m_w = set_l(m_w, data); }).noshow();
	state_add<u8>(R65C19_WH, "WH",
		[this]() { return m_w >> 8; },
		[this](u8 data) { m_w = set_h(m_w, data); }).noshow();
	state_add(R65C19_I, "I", m_i);

	save_item(NAME(m_w));
	save_item(NAME(m_i));
}

void r65c19_device::device_reset()
{
	r65c02_device::device_reset();
}

#include "cpu/m6502/r65c19.hxx"