summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/snes/sfx.cpp
blob: 59908b9b06eecbad1b26b915491a4e61397d3bd5 (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...

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

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

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

void sns_rom_superfx_device::superfx_w_bank1(offs_t offset, uint8_t data)
{
}

void sns_rom_superfx_device::superfx_w_bank2(offs_t offset, uint8_t data)
{
}

void sns_rom_superfx_device::superfx_w_bank3(offs_t offset, uint8_t data)
{
	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 */
}

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

void sns_rom_superfx_device::chip_write(offs_t offset, uint8_t data)
{
	m_superfx->mmio_write(offset, data);
}


uint8_t sns_rom_superfx_device::read_l(offs_t offset)
{
	return read_h(offset);
}

uint8_t sns_rom_superfx_device::read_h(offs_t offset)
{
	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
}

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

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