summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/einstein/pipe/silicon_disc.cpp
blob: c0a29f304bd7c1fc922c1a17fcc1ea22c67f29b1 (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
// license: GPL-2.0+
// copyright-holders: Dirk Best
/***************************************************************************

    Silicon Disc

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

#include "emu.h"
#include "silicon_disc.h"


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

DEFINE_DEVICE_TYPE(EINSTEIN_SILICON_DISC, einstein_silicon_disc_device, "einstein_sd", "Einstein Silicon Disc")

//-------------------------------------------------
//  device_address_map
//-------------------------------------------------

void einstein_silicon_disc_device::map(address_map &map)
{
	map(0x08, 0x08).mirror(0xff00).w(FUNC(einstein_silicon_disc_device::sector_low_w));
	map(0x09, 0x09).mirror(0xff00).w(FUNC(einstein_silicon_disc_device::sector_high_w));
}

//-------------------------------------------------
//  rom_region - device-specific ROM region
//-------------------------------------------------

ROM_START( silicon_disc )
	ROM_REGION(0x2000, "rom", 0)
	ROM_LOAD("sd11.bin", 0x0000, 0x2000, CRC(0e4f5e6d) SHA1(d0bc01e533d8963c596154435c5b2d156a96d470))
ROM_END

const tiny_rom_entry *einstein_silicon_disc_device::device_rom_region() const
{
	return ROM_NAME( silicon_disc );
}


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

//-------------------------------------------------
//  einstein_silicon_disc_device - constructor
//-------------------------------------------------

einstein_silicon_disc_device::einstein_silicon_disc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, EINSTEIN_SILICON_DISC, tag, owner, clock),
	device_tatung_pipe_interface(mconfig, *this),
	m_rom(*this, "rom"),
	m_bios(*this, ":bios"),
	m_sector(0)
{
}

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

void einstein_silicon_disc_device::device_start()
{
	// setup ram
	m_ram = std::make_unique<uint8_t[]>(0x40000);
	memset(m_ram.get(), 0xff, 0x40000);

	// register for save states
	save_pointer(NAME(m_ram), 0x40000);
	save_item(NAME(m_sector));
}

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

void einstein_silicon_disc_device::device_reset()
{
	// copy our rom into the main bios region so it will get picked up by the bank switching
	// not really part of the pipe interface cartridge but here for convenience, in reality
	// the rom gets put directly onto the main motherboard into the second empty socket
	memcpy(m_bios->base() + 0x4000, m_rom->base(), 0x2000);

	// install i/o ports
	io_space().install_device(0xf0, 0xff, *this, &einstein_silicon_disc_device::map);
	io_space().install_readwrite_handler(0xfa, 0xfa, 0, 0, 0xff00,
			read8sm_delegate(*this, FUNC(einstein_silicon_disc_device::ram_r)),
			write8sm_delegate(*this, FUNC(einstein_silicon_disc_device::ram_w)));
}


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

void einstein_silicon_disc_device::sector_low_w(uint8_t data)
{
	m_sector &= 0xff00;
	m_sector |= data;
}

void einstein_silicon_disc_device::sector_high_w(uint8_t data)
{
	m_sector &= 0x00ff;
	m_sector |= ((data & 0x07) << 8);
}

// a8 to a14 are used to specify the byte in a 128-byte sector
uint8_t einstein_silicon_disc_device::ram_r(offs_t offset)
{
	return m_ram[(m_sector * 0x80) | ((offset >> 8) & 0x7f)];
}

void einstein_silicon_disc_device::ram_w(offs_t offset, uint8_t data)
{
	m_ram[(m_sector * 0x80) | ((offset >> 8) & 0x7f)] = data;
}