summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/c64/c128_partner.cpp
blob: 18fce1fbbaa8187f47ebe5ae133621e14fdf2f86 (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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
// license:BSD-3-Clause
// copyright-holders:Curt Coder
/**********************************************************************

    Timeworks PARTNER 128 cartridge emulation

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

/*

    PCB Layout
    ----------

    |---------------|
    |LS74  SW     * |
    |LS09      LS273|
    |LS139   RAM    |
    |LS133          |
    |     LS240     |
    |LS33    ROM    |
    |LS09           |
     |||||||||||||||

    ROM     - Toshiba TMM24128AP 16Kx8 EPROM (blank label)
    RAM     - Sony CXK5864PN-15L 8Kx8 SRAM
    SW      - push button switch
    *       - solder point for joystick port dongle

*/

#include "emu.h"
#include "c128_partner.h"



//**************************************************************************
//  DEVICE DEFINITIONS
//**************************************************************************

const device_type C128_PARTNER = &device_creator<partner128_t>;


//-------------------------------------------------
//  INPUT_PORTS( c128_partner )
//-------------------------------------------------

WRITE_LINE_MEMBER( partner128_t::nmi_w )
{
	if (state)
	{
		m_ls74_q1 = 1;
	}
}

static INPUT_PORTS_START( c128_partner )
	PORT_START("NMI")
	PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Menu") PORT_CODE(KEYCODE_END) PORT_WRITE_LINE_DEVICE_MEMBER(DEVICE_SELF, partner128_t, nmi_w)
INPUT_PORTS_END


//-------------------------------------------------
//  input_ports - device-specific input ports
//-------------------------------------------------

ioport_constructor partner128_t::device_input_ports() const
{
	return INPUT_PORTS_NAME( c128_partner );
}



//**************************************************************************
//  LIVE DEVICE
//**************************************************************************

//-------------------------------------------------
//  partner128_t - constructor
//-------------------------------------------------

partner128_t::partner128_t(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, C128_PARTNER, "PARTNER 128", tag, owner, clock, "c128_partner", __FILE__),
	device_c64_expansion_card_interface(mconfig, *this),
	//device_vcs_control_port_interface(mconfig, *this),
	m_ram(*this, "ram"), t_joyb2(nullptr),
	m_ram_a12_a7(0),
	m_ls74_cd(0),
	m_ls74_q1(0),
	m_ls74_q2(0),
	m_joyb2(0)
{
}


//-------------------------------------------------
//  device_start - device-specific startup
//-------------------------------------------------

void partner128_t::device_start()
{
	// allocate memory
	m_ram.allocate(0x2000);

	// simulate the 16.7ms pulse from CIA1 PB2 that would arrive thru the joystick port dongle
	t_joyb2 = timer_alloc();
	t_joyb2->adjust(attotime::from_msec(16), 0, attotime::from_msec(16));

	// state saving
	save_item(NAME(m_ram_a12_a7));
	save_item(NAME(m_ls74_cd));
	save_item(NAME(m_ls74_q1));
	save_item(NAME(m_ls74_q2));
	save_item(NAME(m_joyb2));
}


//-------------------------------------------------
//  device_reset - device-specific reset
//-------------------------------------------------

void partner128_t::device_reset()
{
	m_ram_a12_a7 = 0;

	m_ls74_cd = 0;
	m_ls74_q1 = 0;
	m_ls74_q2 = 0;

	nmi_w(CLEAR_LINE);
}


//-------------------------------------------------
//  device_timer -
//-------------------------------------------------

void partner128_t::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
	if (m_ls74_cd)
	{
		m_ls74_q2 = m_ls74_q1;

		nmi_w(m_ls74_q2 ? ASSERT_LINE : CLEAR_LINE);
	}
}


//-------------------------------------------------
//  c64_cd_r - cartridge data read
//-------------------------------------------------

uint8_t partner128_t::c64_cd_r(address_space &space, offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
{
	if (!roml)
	{
		data = m_roml[offset & 0x3fff];
	}

	if (!io1)
	{
		if (BIT(offset, 7))
		{
			data = m_roml[offset & 0x3fff];

			if (m_ls74_cd)
			{
				m_ls74_q1 = 0;
			}
		}
		else
		{
			data = m_ram[(m_ram_a12_a7 << 7) | (offset & 0x7f)];
		}
	}

	if (m_ls74_q2 && ((offset & 0xfffa) == 0xfffa))
	{
		// override the 8502 NMI/IRQ vectors with 0xdede
		data = 0xde;
	}

	return data;
}


//-------------------------------------------------
//  c64_cd_w - cartridge data write
//-------------------------------------------------

void partner128_t::c64_cd_w(address_space &space, offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
{
	if (!io1)
	{
		if (BIT(offset, 7))
		{
			/*

			    bit     description

			    0       RAM A7
			    1       RAM A8
			    2       RAM A9
			    3       RAM A10
			    4       RAM A11
			    5       RAM A12
			    6       LS74 1Cd,2Cd
			    7       N/C

			*/

			m_ram_a12_a7 = data & 0x3f;

			m_ls74_cd = BIT(data, 6);

			if (!m_ls74_cd)
			{
				m_ls74_q1 = 0;
				m_ls74_q2 = 0;

				nmi_w(CLEAR_LINE);
			}
		}
		else
		{
			m_ram[(m_ram_a12_a7 << 7) | (offset & 0x7f)] = data;
		}
	}

	if (sphi2 && ((offset & 0xfff0) == 0xd600))
	{
		m_ram[(m_ram_a12_a7 << 7) | (offset & 0x7f)] = data;
	}
}


//-------------------------------------------------
//  vcs_joy_w - joystick write
//-------------------------------------------------

void partner128_t::vcs_joy_w(uint8_t data)
{
	int joyb2 = BIT(data, 2);

	if (!m_joyb2 && joyb2 && m_ls74_cd)
	{
		m_ls74_q2 = m_ls74_q1;

		nmi_w(m_ls74_q2 ? ASSERT_LINE : CLEAR_LINE);
	}

	m_joyb2 = joyb2;
}