summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/a7800/xboard.cpp
blob: 0005e595a88f24d8a794f7791ade3cef768b4a5c (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
// license:BSD-3-Clause
// copyright-holders:Fabio Priuli
/***********************************************************************************************************

 A7800 XBoarD & XM expansions emulation

 The XBoarD should be socketed in the A7800 pcb in place of the Maria chip.
 It adds to the system additional 128K of RAM and an onboard pokey.
 The XM seems to work the same as XBoarD, but it also features HighScore savings
 (using the same ROM as Atari HighScore cart)


 Currently, we emulate both of these as a passthru cart, even if not 100% accurate for the XBoarD


 Memory map:

 POKEY1            $0450    $045F     16 bytes
 POKEY2*           $0460    $046F     16 bytes
 XCTRL             $0470    $047F     1 byte
 RAM               $4000    $7FFF     16384 bytes

 XCTRL Bit Description

 +-------------------------------+
 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
 +-------------------------------+
   |   |   |   |   |   |   |   |
   |   |   |   |   |   |   |   +-- Bank select bit 0 \
   |   |   |   |   |   |   +------ Bank select bit 1  | Totally 128 KByte in 16 KByte banks
   |   |   |   |   |   +---------- Bank select bit 2 /
   |   |   |   |   +-------------- Enable memory bit (1 = Memory enabled, 0 after power on)
   |   |   |   +------------------ Enable POKEY bit** (1 = POKEY enabled, 0 after power on)
   |   |   |
   NA  NA  NA = Not Available or Not Used

 * = Can be mounted piggy back on the first POKEY. Description how to do this will come when i have tried it out.
 ** This bit controls both POKEY chip select signals.

 TODO:
  - verify what happens when 2 POKEYs are present

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


#include "emu.h"
#include "xboard.h"
#include "a78_carts.h"
#include "speaker.h"


//-------------------------------------------------
//  constructor
//-------------------------------------------------

DEFINE_DEVICE_TYPE(A78_XBOARD, a78_xboard_device, "a78_xboard", "Atari 7800 XBoarD expansion")
DEFINE_DEVICE_TYPE(A78_XM,     a78_xm_device,     "a78_xm",     "Atari 7800 XM expansion module")


a78_xboard_device::a78_xboard_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
	: a78_rom_device(mconfig, type, tag, owner, clock)
	, m_xbslot(*this, "xb_slot")
	, m_pokey(*this, "xb_pokey")
	, m_reg(0), m_ram_bank(0)
{
}


a78_xboard_device::a78_xboard_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: a78_xboard_device(mconfig, A78_XBOARD, tag, owner, clock)
{
}


a78_xm_device::a78_xm_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: a78_xboard_device(mconfig, A78_XM, tag, owner, clock)
	, m_ym(*this, "xm_ym2151"), m_ym_enabled(0)
{
}


void a78_xboard_device::device_start()
{
	save_item(NAME(m_reg));
	save_item(NAME(m_ram_bank));
}

void a78_xboard_device::device_reset()
{
	m_reg = 0;
	m_ram_bank = 0;
}

void a78_xm_device::device_start()
{
	save_item(NAME(m_reg));
	save_item(NAME(m_ram_bank));
	save_item(NAME(m_ym_enabled));
}

void a78_xm_device::device_reset()
{
	m_reg = 0;
	m_ram_bank = 0;
	m_ym_enabled = 0;
}


void a78_xboard_device::device_add_mconfig(machine_config &config)
{
	A78_CART_SLOT(config, m_xbslot, a7800_cart, nullptr);

	SPEAKER(config, "xb_speaker").front_center();

	POKEY(config, m_pokey, XTAL(14'318'181)/8);
	m_pokey->add_route(ALL_OUTPUTS, "xb_speaker", 1.00);
}

void a78_xm_device::device_add_mconfig(machine_config &config)
{
	A78_CART_SLOT(config, m_xbslot, a7800_cart, nullptr);

	SPEAKER(config, "xb_speaker").front_center();

	POKEY(config, m_pokey, XTAL(14'318'181)/8);
	m_pokey->add_route(ALL_OUTPUTS, "xb_speaker", 1.00);

	YM2151(config, m_ym, XTAL(14'318'181)/4).add_route(ALL_OUTPUTS, "xb_speaker", 1.00);
}


/*-------------------------------------------------
 mapper specific handlers
 -------------------------------------------------*/

/*-------------------------------------------------

 XBoarD: passthru + 128K RAM + POKEY

 -------------------------------------------------*/

READ8_MEMBER(a78_xboard_device::read_40xx)
{
	if (BIT(m_reg, 3) && offset < 0x4000)
		return m_ram[offset + (m_ram_bank * 0x4000)];
	else
		return m_xbslot->read_40xx(space, offset);
}

WRITE8_MEMBER(a78_xboard_device::write_40xx)
{
	if (BIT(m_reg, 3) && offset < 0x4000)
		m_ram[offset + (m_ram_bank * 0x4000)] = data;
	else
		m_xbslot->write_40xx(space, offset, data);
}

READ8_MEMBER(a78_xboard_device::read_04xx)
{
	if (BIT(m_reg, 4) && offset >= 0x50 && offset < 0x60)
		return m_pokey->read(offset & 0x0f);
	else if (BIT(m_reg, 4) && offset >= 0x60 && offset < 0x70)
		return m_xbslot->read_04xx(space, offset - 0x10);   // access second POKEY
	else
		return 0xff;
}

WRITE8_MEMBER(a78_xboard_device::write_04xx)
{
	if (BIT(m_reg, 4) && offset >= 0x50 && offset < 0x60)
		m_pokey->write(offset & 0x0f, data);
	else if (BIT(m_reg, 4) && offset >= 0x60 && offset < 0x70)
		m_xbslot->write_04xx(space, offset - 0x10, data);   // access second POKEY
	else if (offset >= 0x70 && offset < 0x80)
	{
		m_reg = data;
		m_ram_bank = m_reg & 7;
	}
}


/*-------------------------------------------------

 XM: Same as above but also featuring High Score savings

 -------------------------------------------------*/

READ8_MEMBER(a78_xm_device::read_10xx)
{
	return m_nvram[offset];
}

WRITE8_MEMBER(a78_xm_device::write_10xx)
{
	m_nvram[offset] = data;
}

READ8_MEMBER(a78_xm_device::read_30xx)
{
	return m_rom[offset];
}

READ8_MEMBER(a78_xm_device::read_04xx)
{
	if (BIT(m_reg, 4) && offset >= 0x50 && offset < 0x60)
		return m_pokey->read(offset & 0x0f);
	else if (m_ym_enabled && offset >= 0x60 && offset <= 0x61)
		return m_ym->read(offset & 1);
	else if (BIT(m_reg, 4) && offset >= 0x60 && offset < 0x70)
		return m_xbslot->read_04xx(space, offset - 0x10);   // access second POKEY
	else
		return 0xff;
}

WRITE8_MEMBER(a78_xm_device::write_04xx)
{
	if (BIT(m_reg, 4) && offset >= 0x50 && offset < 0x60)
		m_pokey->write(offset & 0x0f, data);
	else if (m_ym_enabled && offset >= 0x60 && offset <= 0x61)
		m_ym->write(offset & 1, data);
	else if (BIT(m_reg, 4) && offset >= 0x60 && offset < 0x70)
		m_xbslot->write_04xx(space, offset - 0x10, data);   // access second POKEY
	else if (offset >= 0x70 && offset < 0x80)
	{
		//printf("regs 0x%X\n", data);
		if (data == 0x84)
			m_ym_enabled = 1;
		m_reg = data;
		m_ram_bank = m_reg & 7;
	}
}