summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/snes/sfx.cpp
blob: cf9942ada4d2f7181b7806fb70240b8a3f3b0a3b (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:Fabio Priuli
/***********************************************************************************************************

 SuperFX add-on chip emulation (for SNES/SFC)

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


#include "emu.h"
#include "sfx.h"

//-------------------------------------------------
//  sns_rom_superfx_device - constructor
//-------------------------------------------------

DEFINE_DEVICE_TYPE(SNS_LOROM_SUPERFX, sns_rom_superfx_device, "sns_rom_superfx", "SNES Cart (LoROM) + SuperFX")


sns_rom_superfx_device::sns_rom_superfx_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: sns_rom_device(mconfig, SNS_LOROM_SUPERFX, tag, owner, clock)
	, m_superfx(*this, "superfx")
{
}

void sns_rom_superfx_device::device_start()
{
	save_item(NAME(sfx_ram));
}

void sns_rom_superfx_device::device_reset()
{
	memset(sfx_ram, 0x00, sizeof(sfx_ram));
}

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

// LoROM + SuperFX (GSU-1,2)
// TODO: mask sfx_ram based on the actual RAM...

READ8_MEMBER( sns_rom_superfx_device::superfx_r_bank1 )
{
	return m_rom[rom_bank_map[offset / 0x10000] * 0x8000 + (offset & 0x7fff)];
}

READ8_MEMBER( sns_rom_superfx_device::superfx_r_bank2 )
{
	return m_rom[rom_bank_map[offset / 0x8000] * 0x8000 + (offset & 0x7fff)];
}

READ8_MEMBER( sns_rom_superfx_device::superfx_r_bank3 )
{
	return sfx_ram[offset & 0xfffff];
}

WRITE8_MEMBER( sns_rom_superfx_device::superfx_w_bank1 )
{
}

WRITE8_MEMBER( sns_rom_superfx_device::superfx_w_bank2 )
{
}

WRITE8_MEMBER( sns_rom_superfx_device::superfx_w_bank3 )
{
	sfx_ram[offset & 0xfffff] = data;
}

void sns_rom_superfx_device::sfx_map(address_map &map)
{
	map(0x000000, 0x3fffff).rw(FUNC(sns_rom_superfx_device::superfx_r_bank1), FUNC(sns_rom_superfx_device::superfx_w_bank1));
	map(0x400000, 0x5fffff).rw(FUNC(sns_rom_superfx_device::superfx_r_bank2), FUNC(sns_rom_superfx_device::superfx_w_bank2));
	map(0x600000, 0x7dffff).rw(FUNC(sns_rom_superfx_device::superfx_r_bank3), FUNC(sns_rom_superfx_device::superfx_w_bank3));
	map(0x800000, 0xbfffff).rw(FUNC(sns_rom_superfx_device::superfx_r_bank1), FUNC(sns_rom_superfx_device::superfx_w_bank1));
	map(0xc00000, 0xdfffff).rw(FUNC(sns_rom_superfx_device::superfx_r_bank2), FUNC(sns_rom_superfx_device::superfx_w_bank2));
	map(0xe00000, 0xffffff).rw(FUNC(sns_rom_superfx_device::superfx_r_bank3), FUNC(sns_rom_superfx_device::superfx_w_bank3));
}


WRITE_LINE_MEMBER(sns_rom_superfx_device::snes_extern_irq_w)
{
	write_irq(state);
}


void sns_rom_superfx_device::device_add_mconfig(machine_config &config)
{
	SUPERFX(config, m_superfx, DERIVED_CLOCK(1, 1));  /* 21.48MHz */
	m_superfx->set_addrmap(AS_PROGRAM, &sns_rom_superfx_device::sfx_map);
	m_superfx->irq().set(FUNC(sns_rom_superfx_device::snes_extern_irq_w));  /* IRQ line from cart */
}

READ8_MEMBER( sns_rom_superfx_device::chip_read )
{
	return m_superfx->mmio_read(offset);
}

WRITE8_MEMBER( sns_rom_superfx_device::chip_write )
{
	m_superfx->mmio_write(offset, data);
}


READ8_MEMBER( sns_rom_superfx_device::read_l )
{
	return read_h(space, offset);
}

READ8_MEMBER(sns_rom_superfx_device::read_h)
{
	if (offset < 0x400000)
		return m_rom[rom_bank_map[offset / 0x10000] * 0x8000 + (offset & 0x7fff)];
	else if (offset < 0x600000)
	{
		if (m_superfx->access_rom())
		{
			return m_rom[rom_bank_map[(offset - 0x400000) / 0x8000] * 0x8000 + (offset & 0x7fff)];
		}
		else
		{
			static const uint8_t sfx_data[16] = {
				0x00, 0x01, 0x00, 0x01, 0x04, 0x01, 0x00, 0x01,
				0x00, 0x01, 0x08, 0x01, 0x00, 0x01, 0x0c, 0x01,
			};
			return sfx_data[offset & 0x0f];
		}
	}
	return 0xff;    // this handler should never be called for [60-7f]/[e0-ff] ranges
}

READ8_MEMBER( sns_rom_superfx_device::read_ram )
{
	if (m_superfx->access_ram())
		return sfx_ram[offset & 0xfffff];
	return 0xff;    // should be open bus...
}

WRITE8_MEMBER( sns_rom_superfx_device::write_ram )
{
	if (m_superfx->access_ram())
		sfx_ram[offset & 0xfffff] = data;
}