summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/kc/rom.cpp
blob: eca6d6a1907e8fb141f0f040d61ed5604aafcfa0 (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:Sandro Ronco
/***************************************************************************

    rom.c

    KC 85 ROM modules emulation

    Supported modules:
    - Generic 8KB ROM module
    - M006 BASIC
    - M033 TypeStar

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

#include "emu.h"
#include "rom.h"

#define REGION_TAG          "rom"

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

ROM_START( kc_rom )
	ROM_REGION(0x4000, REGION_TAG, ROMREGION_ERASEFF)
ROM_END

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

DEFINE_DEVICE_TYPE(KC_STANDARD, kc_8k_device,   "kc_8k",   "Standard 8K ROM module")
DEFINE_DEVICE_TYPE(KC_M006,     kc_m006_device, "kc_m006", "M006 BASIC")
DEFINE_DEVICE_TYPE(KC_M033,     kc_m033_device, "kc_m033", "M033 TypeStar")

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

//-------------------------------------------------
//  kc_8k_device - constructor
//-------------------------------------------------

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

kc_8k_device::kc_8k_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, type, tag, owner, clock)
	, device_kcexp_interface(mconfig, *this)
	, m_slot(nullptr), m_mei(0), m_rom(nullptr), m_enabled(0), m_base(0)
{
}


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

void kc_8k_device::device_start()
{
	m_slot = dynamic_cast<kcexp_slot_device *>(owner());
	m_rom = memregion(REGION_TAG)->base();
}

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

void kc_8k_device::device_reset()
{
	m_enabled = 0;
	m_base = 0;
	m_mei = 0;
}

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

const tiny_rom_entry *kc_8k_device::device_rom_region() const
{
	return ROM_NAME( kc_rom );
}

/*-------------------------------------------------
    get_cart_base
-------------------------------------------------*/

uint8_t* kc_8k_device::get_cart_base()
{
	return m_rom;
}

/*-------------------------------------------------
    module control write
-------------------------------------------------*/

void kc_8k_device::control_w(uint8_t data)
{
	if (m_mei)
	{
		m_enabled = BIT(data, 0);
		m_base = (data & 0xe0) << 8;
	}
}

/*-------------------------------------------------
    read
-------------------------------------------------*/

void kc_8k_device::read(offs_t offset, uint8_t &data)
{
	if (offset >= m_base && offset < (m_base + 0x2000) && m_enabled && m_mei)
	{
		data = m_rom[offset - m_base];

		// clear the MEO line for disable other modules with less priority
		m_slot->meo_w(CLEAR_LINE);
	}
}

/*-------------------------------------------------
   MEI line write
-------------------------------------------------*/

WRITE_LINE_MEMBER( kc_8k_device::mei_w )
{
	m_mei = state;

	// update MEO line
	m_slot->meo_w(state);
}

//**************************************************************************
//  M006 BASIC
//**************************************************************************

//-------------------------------------------------
//  kc_m006_device - constructor
//-------------------------------------------------

kc_m006_device::kc_m006_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: kc_8k_device(mconfig, KC_M006, tag, owner, clock)
{
}

/*-------------------------------------------------
    module control write
-------------------------------------------------*/

void kc_m006_device::control_w(uint8_t data)
{
	if (m_mei)
	{
		m_enabled = BIT(data, 0);
		m_base = (data & 0xc0) << 8;
	}
}

/*-------------------------------------------------
    read
-------------------------------------------------*/

void kc_m006_device::read(offs_t offset, uint8_t &data)
{
	if (offset >= m_base && offset < (m_base + 0x4000) && m_enabled)
	{
		data = m_rom[offset - m_base];

		// clear the MEO line for disable other modules with less priority
		m_slot->meo_w(CLEAR_LINE);
	}
}


//**************************************************************************
//  M033 TypeStar module
//**************************************************************************

//-------------------------------------------------
//  kc_m033_device - constructor
//-------------------------------------------------

kc_m033_device::kc_m033_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: kc_8k_device(mconfig, KC_M033, tag, owner, clock)
	, m_bank(0)
{
}

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

void kc_m033_device::device_reset()
{
	kc_8k_device::device_reset();

	m_bank = 0;
}

/*-------------------------------------------------
    module control write
-------------------------------------------------*/

void kc_m033_device::control_w(uint8_t data)
{
	if (m_mei)
	{
		m_enabled = BIT(data, 0);
		m_base = (data & 0xc0) << 8;
		m_bank = BIT(data, 4);
	}
}

/*-------------------------------------------------
    read
-------------------------------------------------*/

void kc_m033_device::read(offs_t offset, uint8_t &data)
{
	if (offset >= m_base && offset < (m_base + 0x2000) && m_enabled && m_mei)
	{
		data = m_rom[(offset - m_base) | (m_bank<<13)];

		// clear the MEO line for disable other modules with less priority
		m_slot->meo_w(CLEAR_LINE);
	}
}