summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/bbc/tube/tube_zep100.cpp
blob: 30c48564e89daa891cd53151ddb4907b7d170fbe (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
// license:BSD-3-Clause
// copyright-holders:Nigel Barnes
/**********************************************************************

    Torch Z80 Communicator (ZEP100)

    http://chrisacorns.computinghistory.org.uk/8bit_Upgrades/Torch_Z802ndproc.html

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


#include "emu.h"
#include "tube_zep100.h"
#include "softlist_dev.h"


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

DEFINE_DEVICE_TYPE(BBC_TUBE_ZEP100, bbc_tube_zep100_device, "bbc_tube_zep100", "Torch Z80 Communicator")


//-------------------------------------------------
//  ADDRESS_MAP( tube_zep100_mem )
//-------------------------------------------------

void bbc_tube_zep100_device::tube_zep100_mem(address_map &map)
{
	map(0x0000, 0xffff).rw(this, FUNC(bbc_tube_zep100_device::mem_r), FUNC(bbc_tube_zep100_device::mem_w));
}

//-------------------------------------------------
//  ADDRESS_MAP( tube_zep100_io )
//-------------------------------------------------

void bbc_tube_zep100_device::tube_zep100_io(address_map &map)
{
	map.unmap_value_high();
	map(0x00, 0x07).mirror(0xff00).rw(this, FUNC(bbc_tube_zep100_device::io_r), FUNC(bbc_tube_zep100_device::io_w));
}

//-------------------------------------------------
//  ROM( tube_zep100 )
//-------------------------------------------------

ROM_START( tube_zep100 )
	ROM_REGION(0x2000, "rom", 0)
	ROM_DEFAULT_BIOS("cccp102")
	ROM_SYSTEM_BIOS(0, "cccp102", "CCCP 1.02")
	ROMX_LOAD("CCCP102.rom", 0x0000, 0x2000, CRC(2eb40a21) SHA1(e6ee738e5f2f8556002b79d18caa8ef21f14e08d), ROM_BIOS(1))
	ROM_SYSTEM_BIOS(1, "cccp094", "CCCP 0.94")
	ROMX_LOAD("CCCP094.rom", 0x0000, 0x2000, CRC(49989bd4) SHA1(62b57c858a3baa4ff943c31f77d331c414772a61), ROM_BIOS(2))
ROM_END

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

MACHINE_CONFIG_START(bbc_tube_zep100_device::device_add_mconfig)
	MCFG_CPU_ADD("z80", Z80, XTAL(4'000'000))
	MCFG_CPU_PROGRAM_MAP(tube_zep100_mem)
	MCFG_CPU_IO_MAP(tube_zep100_io)

	MCFG_DEVICE_ADD("via", VIA6522, XTAL(4'000'000) / 2)
	MCFG_VIA6522_WRITEPB_HANDLER(WRITE8(bbc_tube_zep100_device, via_pb_w))
	MCFG_VIA6522_CB2_HANDLER(DEVWRITELINE("ppi", i8255_device, pc2_w))
	MCFG_VIA6522_CA2_HANDLER(DEVWRITELINE("ppi", i8255_device, pc6_w))
	MCFG_VIA6522_IRQ_HANDLER(DEVWRITELINE(DEVICE_SELF_OWNER, bbc_tube_slot_device, irq_w))

	MCFG_DEVICE_ADD("ppi", I8255A, 0)
	MCFG_I8255_OUT_PORTA_CB(DEVWRITE8("via", via6522_device, write_pa))
	MCFG_I8255_IN_PORTB_CB(READ8(bbc_tube_zep100_device, ppi_pb_r))
	MCFG_I8255_OUT_PORTC_CB(WRITE8(bbc_tube_zep100_device, ppi_pc_w))

	/* internal ram */
	MCFG_RAM_ADD(RAM_TAG)
	MCFG_RAM_DEFAULT_SIZE("64K")
	MCFG_RAM_DEFAULT_VALUE(0x00)

	/* software lists */
	MCFG_SOFTWARE_LIST_ADD("flop_ls_torch", "bbc_flop_torch")
MACHINE_CONFIG_END

//-------------------------------------------------
//  rom_region - device-specific ROM region
//-------------------------------------------------

const tiny_rom_entry *bbc_tube_zep100_device::device_rom_region() const
{
	return ROM_NAME( tube_zep100 );
}

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

//-------------------------------------------------
//  bbc_tube_zep100_device - constructor
//-------------------------------------------------

bbc_tube_zep100_device::bbc_tube_zep100_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, BBC_TUBE_ZEP100, tag, owner, clock),
		device_bbc_tube_interface(mconfig, *this),
		m_z80(*this, "z80"),
		m_via(*this, "via"),
		m_ppi(*this, "ppi"),
		m_ram(*this, "ram"),
		m_rom(*this, "rom"),
		m_port_b(0),
		m_rom_enabled(true)
{
}

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

void bbc_tube_zep100_device::device_start()
{
	m_slot = dynamic_cast<bbc_tube_slot_device *>(owner());
}

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

void bbc_tube_zep100_device::device_reset()
{
	m_via->reset();

	m_rom_enabled = true;
}


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

READ8_MEMBER(bbc_tube_zep100_device::host_r)
{
	return m_via->read(space, offset & 0x0f);
}

WRITE8_MEMBER(bbc_tube_zep100_device::host_w)
{
	if (offset & 0x10)
		m_z80->reset();

	m_via->write(space, offset & 0x0f, data);
}


READ8_MEMBER(bbc_tube_zep100_device::mem_r)
{
	uint8_t data;

	if (m_rom_enabled)
		data = m_rom->base()[offset];
	else
		data = m_ram->pointer()[offset];

	return data;
}

WRITE8_MEMBER(bbc_tube_zep100_device::mem_w)
{
	m_ram->pointer()[offset] = data;
}


READ8_MEMBER(bbc_tube_zep100_device::io_r)
{
	uint8_t data = 0xff;

	if (!machine().side_effects_disabled())
		m_rom_enabled = !BIT(offset, 2);

	data = m_ppi->read(space, offset & 0x03);

	return data;
}

WRITE8_MEMBER(bbc_tube_zep100_device::io_w)
{
	m_ppi->write(space, offset & 0x03, data);
}


WRITE8_MEMBER(bbc_tube_zep100_device::via_pb_w)
{
	m_port_b = data;
}

READ8_MEMBER(bbc_tube_zep100_device::ppi_pb_r)
{
	return m_port_b;
}

WRITE8_MEMBER(bbc_tube_zep100_device::ppi_pc_w)
{
	m_via->write_ca1(BIT(data, 7));
	m_via->write_cb1(BIT(data, 1));
}