summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/machine/pet_64k.c
blob: 1b9b1c4f9fa9404425def372a63bc91c01a3424d (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
/**********************************************************************

    Commodore PET 64KB RAM Expansion emulation

    Copyright MESS Team.
    Visit http://mamedev.org for licensing and usage restrictions.

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

#include "pet_64k.h"



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

const device_type PET_64K = &device_creator<pet_64k_expansion_device>;



//**************************************************************************
//  INLINE HELPERS
//**************************************************************************

//-------------------------------------------------
//  read_ram -
//-------------------------------------------------

inline UINT8 pet_64k_expansion_device::read_ram(offs_t offset)
{
	UINT8 data = 0;

	if (offset < 0xc000)
	{
		data = m_ram[(BIT(m_ctrl, 2) << 14) | (offset & 0x3fff)];
	}
	else
	{
		data = m_ram[0x8000 | (BIT(m_ctrl, 3) << 14) | (offset & 0x3fff)];
	}

	return data;
}


//-------------------------------------------------
//  write_ram -
//-------------------------------------------------

inline void pet_64k_expansion_device::write_ram(offs_t offset, UINT8 data)
{
	if (offset < 0xc000)
	{
		if (!BIT(m_ctrl, 0))
		{
			m_ram[(BIT(m_ctrl, 2) << 14) | (offset & 0x3fff)] = data;
		}
	}
	else
	{
		if (!BIT(m_ctrl, 1))
		{
			m_ram[0x8000 | (BIT(m_ctrl, 3) << 14) | (offset & 0x3fff)] = data;
		}
	}
}



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

//-------------------------------------------------
//  pet_64k_expansion_device - constructor
//-------------------------------------------------

pet_64k_expansion_device::pet_64k_expansion_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
	device_t(mconfig, PET_64K, "PET 64KB RAM", tag, owner, clock),
	device_pet_expansion_card_interface(mconfig, *this),
	m_ram(*this, "ram"),
	m_ctrl(0)
{
}


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

void pet_64k_expansion_device::device_start()
{
	// allocate memory
	m_ram.allocate(0x10000);

	// state saving
	save_item(NAME(m_ctrl));
}


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

void pet_64k_expansion_device::device_reset()
{
	m_ctrl = 0;
}


//-------------------------------------------------
//  pet_norom_r - NO ROM read
//-------------------------------------------------

int pet_64k_expansion_device::pet_norom_r(address_space &space, offs_t offset, int sel)
{
	return !BIT(m_ctrl, 7);
}


//-------------------------------------------------
//  pet_bd_r - buffered data read
//-------------------------------------------------

UINT8 pet_64k_expansion_device::pet_bd_r(address_space &space, offs_t offset, UINT8 data, int &sel)
{
	if (BIT(m_ctrl, 7))
	{
		switch (sel)
		{
		case pet_expansion_slot_device::SEL8:
			if (!BIT(m_ctrl, 5))
			{
				data = read_ram(offset);
				sel = pet_expansion_slot_device::SEL_NONE;
			}
			break;

		case pet_expansion_slot_device::SELE:
			if (!BIT(m_ctrl, 6) || !BIT(offset, 11))
			{
				data = read_ram(offset);
				sel = pet_expansion_slot_device::SEL_NONE;
			}
			break;

		case pet_expansion_slot_device::SEL9:
		case pet_expansion_slot_device::SELA:
		case pet_expansion_slot_device::SELB:
		case pet_expansion_slot_device::SELC:
		case pet_expansion_slot_device::SELD:
		case pet_expansion_slot_device::SELF:
			data = read_ram(offset);
			break;
		}
	}

	return data;
}


//-------------------------------------------------
//  pet_bd_w - buffered data write
//-------------------------------------------------

void pet_64k_expansion_device::pet_bd_w(address_space &space, offs_t offset, UINT8 data, int &sel)
{
	if (BIT(m_ctrl, 7))
	{
		switch (sel)
		{
		case pet_expansion_slot_device::SEL8:
			if (!BIT(m_ctrl, 5))
			{
				write_ram(offset, data);
				sel = pet_expansion_slot_device::SEL_NONE;
			}
			break;

		case pet_expansion_slot_device::SELE:
			if (!BIT(m_ctrl, 6) || !BIT(offset, 11))
			{
				write_ram(offset, data);	
				sel = pet_expansion_slot_device::SEL_NONE;
			}
			break;

		case pet_expansion_slot_device::SEL9:
		case pet_expansion_slot_device::SELA:
		case pet_expansion_slot_device::SELB:
		case pet_expansion_slot_device::SELC:
		case pet_expansion_slot_device::SELD:
		case pet_expansion_slot_device::SELF:
			write_ram(offset, data);
			break;
		}
	}

	if (offset == 0xfff0)
	{
		m_ctrl = data;
	}
}