summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/cpu/m6502/m5074x.h
blob: 10f0aa06df5111448fbeaddaccc84c2ece520378 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// license:BSD-3-Clause
// copyright-holders:Olivier Galibert
#pragma once

#ifndef __M5074X_H__
#define __M5074X_H__

#include "m740.h"

//**************************************************************************
//  CONSTANTS
//**************************************************************************

// internal ROM region
#define M5074X_INTERNAL_ROM_REGION "internal"
#define M5074X_INTERNAL_ROM(_tag) (_tag ":" M5074X_INTERNAL_ROM_REGION)

//**************************************************************************
//  INTERFACE CONFIGURATION MACROS
//**************************************************************************

#define MCFG_M5074X_PORT0_READ_CALLBACK(_read) \
	devcb = &m5074x_device::set_p0_rd_callback(*device, DEVCB_##_read);

#define MCFG_M5074X_PORT1_READ_CALLBACK(_read) \
	devcb = &m5074x_device::set_p1_rd_callback(*device, DEVCB_##_read);

#define MCFG_M5074X_PORT2_READ_CALLBACK(_read) \
	devcb = &m5074x_device::set_p2_rd_callback(*device, DEVCB_##_read);

#define MCFG_M5074X_PORT3_READ_CALLBACK(_read) \
	devcb = &m5074x_device::set_p3_rd_callback(*device, DEVCB_##_read);

#define MCFG_M5074X_PORT0_WRITE_CALLBACK(_write) \
	devcb = &m5074x_device::set_p0_wr_callback(*device, DEVCB_##_write);

#define MCFG_M5074X_PORT1_WRITE_CALLBACK(_write) \
	devcb = &m5074x_device::set_p1_wr_callback(*device, DEVCB_##_write);

#define MCFG_M5074X_PORT2_WRITE_CALLBACK(_write) \
	devcb = &m5074x_device::set_p2_wr_callback(*device, DEVCB_##_write);

#define MCFG_M5074X_PORT3_WRITE_CALLBACK(_write) \
	devcb = &m5074x_device::set_p3_wr_callback(*device, DEVCB_##_write);

//**************************************************************************
//  TYPE DEFINITIONS
//**************************************************************************

// ======================> m5074x_device

class m5074x_device :  public m740_device
{
	friend class m50740_device;
	friend class m50741_device;

	enum
	{
		M5074X_INT1_LINE = INPUT_LINE_IRQ0,

		M5074X_SET_OVERFLOW = M740_SET_OVERFLOW
	};

	enum
	{
		TIMER_1 = 0,
		TIMER_2,
		TIMER_X,

		NUM_TIMERS
	};

public:
	// construction/destruction
	m5074x_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, address_map_constructor internal_map, const char *shortname, const char *source);

	const address_space_config m_program_config;

	template<class _Object> static devcb_base &set_p0_rd_callback(device_t &device, _Object object) { return downcast<m5074x_device &>(device).read_p0.set_callback(object); }
	template<class _Object> static devcb_base &set_p1_rd_callback(device_t &device, _Object object) { return downcast<m5074x_device &>(device).read_p1.set_callback(object); }
	template<class _Object> static devcb_base &set_p2_rd_callback(device_t &device, _Object object) { return downcast<m5074x_device &>(device).read_p2.set_callback(object); }
	template<class _Object> static devcb_base &set_p3_rd_callback(device_t &device, _Object object) { return downcast<m5074x_device &>(device).read_p3.set_callback(object); }
	template<class _Object> static devcb_base &set_p0_wr_callback(device_t &device, _Object object) { return downcast<m5074x_device &>(device).write_p0.set_callback(object); }
	template<class _Object> static devcb_base &set_p1_wr_callback(device_t &device, _Object object) { return downcast<m5074x_device &>(device).write_p1.set_callback(object); }
	template<class _Object> static devcb_base &set_p2_wr_callback(device_t &device, _Object object) { return downcast<m5074x_device &>(device).write_p2.set_callback(object); }
	template<class _Object> static devcb_base &set_p3_wr_callback(device_t &device, _Object object) { return downcast<m5074x_device &>(device).write_p3.set_callback(object); }

	devcb_read8  read_p0, read_p1, read_p2, read_p3;
	devcb_write8 write_p0, write_p1, write_p2, write_p3;

	DECLARE_READ8_MEMBER(ports_r);
	DECLARE_WRITE8_MEMBER(ports_w);
	DECLARE_READ8_MEMBER(tmrirq_r);
	DECLARE_WRITE8_MEMBER(tmrirq_w);

	bool are_port_bits_output(UINT8 port, UINT8 mask) { return ((m_ddrs[port] & mask) == mask) ? true : false; }

protected:
	// device-level overrides
	virtual void device_start();
	virtual void device_reset();
	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
	virtual void execute_set_input(int inputnum, int state);
	virtual const address_space_config *memory_space_config(address_spacenum spacenum) const { return (spacenum == AS_PROGRAM) ? &m_program_config : NULL; }

	void send_port(address_space &space, UINT8 offset, UINT8 data);
	UINT8 read_port(UINT8 offset);

	void recalc_irqs();
	void recalc_timer(int timer);

	UINT8 m_ports[6], m_ddrs[6];
	UINT8 m_intctrl, m_tmrctrl;
	UINT8 m_tmr12pre, m_tmr1, m_tmr2, m_tmrxpre, m_tmrx;
	UINT8 m_tmr1latch, m_tmr2latch, m_tmrxlatch;
	UINT8 m_last_all_ints;

private:
	emu_timer *m_timers[NUM_TIMERS];
};

class m50740_device : public m5074x_device
{
public:
	m50740_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
	m50740_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source);

protected:

private:
};

class m50741_device : public m5074x_device
{
public:
	m50741_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
	m50741_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source);

protected:

private:
};

extern const device_type M50740;
extern const device_type M50741;

#endif