summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/cpu/m6502/m6510.cpp
blob: 0bfa5a183951f1c4ce7807029752cdcc3ec307c6 (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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
// license:BSD-3-Clause
// copyright-holders:Olivier Galibert
/***************************************************************************

    m6510.c

    6502 with 6 i/o pins, also known as 8500

    6508 is 6510 plus 256 bytes of internal RAM, mirrored across pages 0
    and 1.

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

#include "emu.h"
#include "m6510.h"
#include "m6510d.h"

DEFINE_DEVICE_TYPE(M6510, m6510_device, "m6510", "MOS Technology 6510")
DEFINE_DEVICE_TYPE(M6508, m6508_device, "m6508", "MOS Technology 6508")

m6510_device::m6510_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	m6510_device(mconfig, M6510, tag, owner, clock)
{
}

m6510_device::m6510_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) :
	m6502_device(mconfig, type, tag, owner, clock),
	read_port(*this),
	write_port(*this), dir(0), port(0), drive(0)
{
	pullup = 0x00;
	floating = 0x00;
}

void m6510_device::set_pulls(uint8_t _pullup, uint8_t _floating)
{
	pullup = _pullup;
	floating = _floating;
}

std::unique_ptr<util::disasm_interface> m6510_device::create_disassembler()
{
	return std::make_unique<m6510_disassembler>();
}

void m6510_device::init_port()
{
	read_port.resolve_safe(0);
	write_port.resolve_safe();

	save_item(NAME(pullup));
	save_item(NAME(floating));
	save_item(NAME(dir));
	save_item(NAME(port));
	save_item(NAME(drive));
}

void m6510_device::device_start()
{
	mintf = std::make_unique<mi_6510>(this);

	init();
	init_port();
}

void m6510_device::device_reset()
{
	m6502_device::device_reset();
	dir = 0x00;
	port = 0x00;
	drive = 0x00;
	update_port();
}

void m6510_device::update_port()
{
	drive = (port & dir) | (drive & ~dir);
	write_port((port & dir) | (pullup & ~dir));
}

uint8_t m6510_device::get_port()
{
	return (port & dir) | (pullup & ~dir);
}

uint8_t m6510_device::dir_r()
{
	return dir;
}

uint8_t m6510_device::port_r()
{
	return ((read_port() | (floating & drive)) & ~dir) | (port & dir);
}

void m6510_device::dir_w(uint8_t data)
{
	dir = data;
	update_port();
}

void m6510_device::port_w(uint8_t data)
{
	port = data;
	update_port();
}


m6510_device::mi_6510::mi_6510(m6510_device *_base)
{
	base = _base;
}

uint8_t m6510_device::mi_6510::read(uint16_t adr)
{
	uint8_t res = program->read_byte(adr);
	if(adr == 0x0000)
		res = base->dir_r();
	else if(adr == 0x0001)
		res = base->port_r();
	return res;
}

uint8_t m6510_device::mi_6510::read_sync(uint16_t adr)
{
	uint8_t res = scache->read_byte(adr);
	if(adr == 0x0000)
		res = base->dir_r();
	else if(adr == 0x0001)
		res = base->port_r();
	return res;
}

uint8_t m6510_device::mi_6510::read_arg(uint16_t adr)
{
	uint8_t res = cache->read_byte(adr);
	if(adr == 0x0000)
		res = base->dir_r();
	else if(adr == 0x0001)
		res = base->port_r();
	return res;
}

void m6510_device::mi_6510::write(uint16_t adr, uint8_t val)
{
	program->write_byte(adr, val);
	if(adr == 0x0000)
		base->dir_w(val);
	else if(adr == 0x0001)
		base->port_w(val);
}


m6508_device::m6508_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	m6510_device(mconfig, M6508, tag, owner, clock)
{
}

void m6508_device::device_start()
{
	mintf = std::make_unique<mi_6508>(this);

	init();
	init_port();

	ram_page = make_unique_clear<uint8_t[]>(256);
	save_pointer(NAME(ram_page), 256);
}


m6508_device::mi_6508::mi_6508(m6508_device *_base)
{
	base = _base;
}

uint8_t m6508_device::mi_6508::read(uint16_t adr)
{
	uint8_t res = program->read_byte(adr);
	if(adr == 0x0000)
		res = base->dir_r();
	else if(adr == 0x0001)
		res = base->port_r();
	else if(adr < 0x0200)
		res = base->ram_page[adr & 0x00ff];
	return res;
}

uint8_t m6508_device::mi_6508::read_sync(uint16_t adr)
{
	uint8_t res = scache->read_byte(adr);
	if(adr == 0x0000)
		res = base->dir_r();
	else if(adr == 0x0001)
		res = base->port_r();
	else if(adr < 0x0200)
		res = base->ram_page[adr & 0x00ff];
	return res;
}

uint8_t m6508_device::mi_6508::read_arg(uint16_t adr)
{
	uint8_t res = cache->read_byte(adr);
	if(adr == 0x0000)
		res = base->dir_r();
	else if(adr == 0x0001)
		res = base->port_r();
	else if(adr < 0x0200)
		res = base->ram_page[adr & 0x00ff];
	return res;
}

void m6508_device::mi_6508::write(uint16_t adr, uint8_t val)
{
	program->write_byte(adr, val);
	if(adr == 0x0000)
		base->dir_w(val);
	else if(adr == 0x0001)
		base->port_w(val);
	else if(adr < 0x0200)
		base->ram_page[adr & 0x00ff] = val;
}


#include "cpu/m6502/m6510.hxx"