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

    Watford Electronics ROM/RAM Board

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

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


#include "emu.h"
#include "weromram.h"


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

DEFINE_DEVICE_TYPE(BBC_WEROMRAM, bbc_weromram_device, "bbc_weromram", "Watford Electronics ROM/RAM Board");


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

void bbc_weromram_device::device_add_mconfig(machine_config &config)
{
	/* 3 rom sockets, 64K dynamic ram, 16K static ram (battery backed) */
	BBC_ROMSLOT16(config, m_rom[0], bbc_rom_devices, "ram").set_fixed_ram(true);
	BBC_ROMSLOT16(config, m_rom[1], bbc_rom_devices, "ram").set_fixed_ram(true);
	BBC_ROMSLOT16(config, m_rom[2], bbc_rom_devices, "ram").set_fixed_ram(true);
	BBC_ROMSLOT16(config, m_rom[3], bbc_rom_devices, "ram").set_fixed_ram(true);
	BBC_ROMSLOT16(config, m_rom[4], bbc_rom_devices, "ram").set_fixed_ram(true);
	BBC_ROMSLOT16(config, m_rom[5], bbc_rom_devices, "ram").set_fixed_ram(true);
	BBC_ROMSLOT16(config, m_rom[6], bbc_rom_devices, "ram").set_fixed_ram(true);
	BBC_ROMSLOT16(config, m_rom[7], bbc_rom_devices, "ram").set_fixed_ram(true);
	BBC_ROMSLOT16(config, m_rom[12], bbc_rom_devices, nullptr);
	BBC_ROMSLOT16(config, m_rom[13], bbc_rom_devices, nullptr);
	BBC_ROMSLOT16(config, m_rom[14], bbc_rom_devices, "nvram").set_fixed_ram(true);
	BBC_ROMSLOT16(config, m_rom[15], bbc_rom_devices, nullptr);
}


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

//-------------------------------------------------
//  bbc_weromram_device - constructor
//-------------------------------------------------

bbc_weromram_device::bbc_weromram_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, BBC_WEROMRAM, tag, owner, clock)
	, device_bbc_internal_interface(mconfig, *this)
	, m_rom(*this, "romslot%u", 0U)
{
}


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

void bbc_weromram_device::device_start()
{
	/* move internal roms to board */
	memmove(m_region_swr->base() + 0x2c000, m_region_swr->base(), 0xc000);
	memmove(m_region_swr->base() + 0x3c000, m_region_swr->base() + 0xc000, 0x4000);
	memset(m_region_swr->base(), 0xff, 0x10000);

	/* register for save states */
	save_item(NAME(m_romsel));
	save_item(NAME(m_ramsel));
}


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

uint8_t bbc_weromram_device::paged_r(offs_t offset)
{
	uint8_t data = 0xff;

	switch (m_romsel)
	{
	case 8: case 9: case 10: case 11:
		/* motherboard rom sockets 0-3 are re-assigned to 8-11 */
		if (m_mb_rom[m_romsel & 0x03] && m_mb_rom[m_romsel & 0x03]->present())
		{
			data = m_mb_rom[m_romsel & 0x03]->read(offset);
		}
		else
		{
			data = m_region_swr->base()[offset + (m_romsel << 14) - 0x20000];
		}
		break;
	default:
		/* expansion board sockets */
		if (m_rom[m_romsel] && m_rom[m_romsel]->present())
		{
			data = m_rom[m_romsel]->read(offset);
		}
		else
		{
			data = m_region_swr->base()[offset + (m_romsel << 14)];
		}
		break;
	}

	return data;
}

void bbc_weromram_device::paged_w(offs_t offset, uint8_t data)
{
	switch (m_romsel)
	{
	case 8: case 9: case 10: case 11:
		/* motherboard rom sockets 0-3 are re-assigned to 8-11 */
		if (m_mb_rom[m_romsel & 0x03])
		{
			m_mb_rom[m_romsel & 0x03]->write(offset, data);
		}
		break;
	}

	/* expansion board sockets */
	if (m_rom[m_ramsel])
	{
		m_rom[m_ramsel]->write(offset, data);
	}
}