summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/coco/coco_ram.cpp
blob: c4dfe3500d91e6899d926f56a0cc7eda672236ac (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
// license:BSD-3-Clause
// copyright-holders:tim lindner
/***************************************************************************

    coco_ram.cpp

    Code for emulating the Disto RAM cartridge

    This cartridge came in several forms: 256K, 512K, 768K, and 1024K.
    It also includes a mini expansion bus.

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

#include "emu.h"
#include "coco_ram.h"
#include "meb_intrf.h"

//#define VERBOSE (LOG_GENERAL)
#include "logmacro.h"

#define RAM_SIZE 1024 * 1024
#define MEB_TAG "meb"


//**************************************************************************
//  TYPE DECLARATIONS
//**************************************************************************

namespace
{
	// ======================> coco_pak_ram_device

	class coco_pak_ram_device
		: public device_t
		, public device_cococart_interface
	{
		public:
			// construction/destruction
			coco_pak_ram_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock);
			virtual void device_add_mconfig(machine_config &config) override ATTR_COLD;

		protected:
			// device-level overrides
			virtual void device_start() override ATTR_COLD;
			virtual void device_reset() override ATTR_COLD;
			virtual void scs_write(offs_t offset, u8 data) override;
			virtual u8 scs_read(offs_t offset) override;
			required_device<distomeb_slot_device> m_slot;

		private:
			std::unique_ptr<uint8_t[]> m_staticram;
			u32 m_offset;
	};
};



//**************************************************************************
//  GLOBAL VARIABLES
//**************************************************************************

DEFINE_DEVICE_TYPE_PRIVATE(COCO_PAK_RAM, device_cococart_interface, coco_pak_ram_device, "cocopakram", "Disto RAM Cartridge")



//-------------------------------------------------
//  coco_pak_ram_device - constructor
//-------------------------------------------------

coco_pak_ram_device::coco_pak_ram_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
	: device_t(mconfig, COCO_PAK_RAM, tag, owner, clock)
	, device_cococart_interface(mconfig, *this)
	, m_slot(*this, MEB_TAG)
{
}



//**************************************************************************
//  MACHINE FRAGMENTS AND ADDRESS MAPS
//**************************************************************************

static void disto_meb_slot(device_slot_interface &device)
{
	disto_meb_add_basic_devices(device);
}

void coco_pak_ram_device::device_add_mconfig(machine_config &config)
{
	DISTOMEB_SLOT(config, m_slot, DERIVED_CLOCK(1, 1), disto_meb_slot, "rtime");
	m_slot->cart_callback().set([this](int state) { set_line_value(line::CART, state); });
}



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

void coco_pak_ram_device::device_start()
{
	// initial state
	m_offset = 0;
	m_staticram = std::make_unique<uint8_t[]>(RAM_SIZE);

	// save state
	save_item(NAME(m_offset));
	save_pointer(NAME(m_staticram), RAM_SIZE);
}



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

void coco_pak_ram_device::device_reset()
{
	m_offset = 0;
}



//-------------------------------------------------
//    scs_write
//-------------------------------------------------

void coco_pak_ram_device::scs_write(offs_t offset, u8 data)
{
	if (offset > 0x0f && offset < 0x18)
		m_slot->meb_write(offset - 0x10, data);
	else
	{
		switch (offset)
		{
			case 0:
				m_offset = (m_offset & 0xffff00) | u32(data);
				break;
			case 1:
				m_offset = (m_offset & 0xff00ff) | (u32(data) << 8);
				break;
			case 2:
				m_offset = (m_offset & 0x00ffff) | (u32(data) << 16);
				break;
			case 3:
				if (m_offset < RAM_SIZE)
				{
					m_staticram[m_offset] = data;
				}
				break;
		}

		LOG("scs_write: %s: %06x, %02x, %02x\n", machine().describe_context(), m_offset, offset, data);
	}
}



//-------------------------------------------------
//  scs_read
//-------------------------------------------------

u8 coco_pak_ram_device::scs_read(offs_t offset)
{
	u8 data = 0x00;

	if (offset > 0x0f && offset < 0x18)
	{
		data =  m_slot->meb_read(offset - 0x10);
	}
	else
	{
		switch (offset)
		{
			case 0:
				data = u8(m_offset & 0x00ff);
				break;
			case 1:
				data = u8((m_offset >> 8) & 0x00ff);
				break;
			case 2:
				data = u8((m_offset >> 16) & 0x00ff);
				break;
			case 3:
				if (m_offset < RAM_SIZE)
				{
					data = m_staticram[m_offset];
				}
				break;
		}

		LOG("scs_read:\t%s: %06x, %02x, %02x\n", machine().describe_context(), m_offset, offset, data);
	}

	return data;
}