summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/spectrum/intf2.cpp
blob: ab9caf68f8ca887ca69f88f3eec64489841204af (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
// license:BSD-3-Clause
// copyright-holders:Nigel Barnes
/**********************************************************************

    ZX Interface 2

    The Sinclair ZX Interface 2 allows you to connect two joysticks
    and a ROM software cartridge to your ZX Spectrum.

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


#include "emu.h"
#include "intf2.h"


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

DEFINE_DEVICE_TYPE(SPECTRUM_INTF2, spectrum_intf2_device, "spectrum_intf2", "ZX Interface 2")


//-------------------------------------------------
//  INPUT_PORTS( intf2 )
//-------------------------------------------------

static INPUT_PORTS_START( intf2 )
	PORT_START("LINE3") /* 0xF7FE */
	PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT)  PORT_8WAY PORT_PLAYER(2) PORT_CODE(JOYCODE_X_LEFT_SWITCH)
	PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT) PORT_8WAY PORT_PLAYER(2) PORT_CODE(JOYCODE_X_RIGHT_SWITCH)
	PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN)  PORT_8WAY PORT_PLAYER(2) PORT_CODE(JOYCODE_Y_DOWN_SWITCH)
	PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP)    PORT_8WAY PORT_PLAYER(2) PORT_CODE(JOYCODE_Y_UP_SWITCH)
	PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_BUTTON1)        PORT_PLAYER(2) PORT_CODE(JOYCODE_BUTTON1)

	PORT_START("LINE4") /* 0xEFFE */
	PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_BUTTON1)        PORT_PLAYER(1)
	PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_UP)    PORT_8WAY PORT_PLAYER(1)
	PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN)  PORT_8WAY PORT_PLAYER(1)
	PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT) PORT_8WAY PORT_PLAYER(1)
	PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT)  PORT_8WAY PORT_PLAYER(1)
INPUT_PORTS_END

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

ioport_constructor spectrum_intf2_device::device_input_ports() const
{
	return INPUT_PORTS_NAME( intf2 );
}

//-------------------------------------------------
//  device_add_mconfig - add device configuration
//-------------------------------------------------

void spectrum_intf2_device::device_add_mconfig(machine_config &config)
{
	/* cartridge */
	GENERIC_CARTSLOT(config, m_cart, generic_plain_slot, "spectrum_cart", "bin,rom");
	m_cart->set_device_load(FUNC(spectrum_intf2_device::cart_load), this);

	SOFTWARE_LIST(config, "cart_list").set_original("spectrum_cart");
}

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

//-------------------------------------------------
//  spectrum_intf2_device - constructor
//-------------------------------------------------

spectrum_intf2_device::spectrum_intf2_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, SPECTRUM_INTF2, tag, owner, clock)
	, device_spectrum_expansion_interface(mconfig, *this)
	, m_cart(*this, "cartslot")
	, m_exp_line3(*this, "LINE3")
	, m_exp_line4(*this, "LINE4")
{
}

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

void spectrum_intf2_device::device_start()
{
}


//**************************************************************************
//  IMPLEMENTATION
//**************************************************************************

DEVICE_IMAGE_LOAD_MEMBER(spectrum_intf2_device::cart_load)
{
	uint32_t size = m_cart->common_get_size("rom");

	if (size != 0x4000)
	{
		image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size");
		return image_init_result::FAIL;
	}

	m_cart->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
	m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");

	return image_init_result::PASS;
}

READ_LINE_MEMBER(spectrum_intf2_device::romcs)
{
	if (m_cart && m_cart->exists())
		return 1;
	else
		return 0;
}

uint8_t spectrum_intf2_device::mreq_r(offs_t offset)
{
	if (m_cart && m_cart->exists())
		return m_cart->get_rom_base()[offset & 0x3fff];
	else
		return 0xff;
}

uint8_t spectrum_intf2_device::iorq_r(offs_t offset)
{
	uint8_t data = 0xff;

	switch (offset & 0xff)
	{
	case 0xfe:
		if (((offset >> 8) & 8) == 0)
			data = m_exp_line3->read() | (0xff ^ 0x1f);

		if (((offset >> 8) & 16) == 0)
			data = m_exp_line4->read() | (0xff ^ 0x1f);
		break;
	}

	return data;
}