summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/cpu/m68hc16/m68hc16z.cpp
blob: 0974727634a68ede0693d413ec29b8e532333176 (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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
// license:BSD-3-Clause
// copyright-holders:AJR
/***************************************************************************

    Motorola M68HC16Z series modular microcontrollers

    Most microcontrollers in this series include the following modules:
    • Central Processing Unit (CPU16)
    • System Integration Module (SIM)
    • Standby RAM (SRAM)
    • Analog-to-Digital Converter (ADC)
    • Queued Serial Module (QSM)
    • General-Purpose Timer (GPT)

    MC68HC11Z4/MC68CK11Z4 uses special low-power versions of the CPU and
    SIM, and replaces the QSM with a simpler SCI/SPI combination (MCCI).

    SRAM size is 1, 2 or 4 KB, depending on the model. 8 KB of mask ROM is
    also provided on MC68HC11Z2 and MC68HC11Z3.

    Package types are 132-pin PFQP and 144-pin TQFP.

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

#include "emu.h"
#include "m68hc16z.h"


// device type definition
DEFINE_DEVICE_TYPE(MC68HC16Z1, mc68hc16z1_device, "mc68hc16z1", "Motorola MC68HC16Z1")

m68hc16z_device::m68hc16z_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, const XTAL &clock, address_map_constructor map)
	: cpu16_device(mconfig, type, tag, owner, clock, map)
	, m_pitr(0)
	, m_sccr{0, 0}
	, m_spcr{0, 0, 0, 0}
	, m_tmsk1(0)
{
}

mc68hc16z1_device::mc68hc16z1_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock)
	: m68hc16z_device(mconfig, MC68HC16Z1, tag, owner, clock, address_map_constructor(FUNC(mc68hc16z1_device::internal_map), this))
{
}

void m68hc16z_device::device_start()
{
	cpu16_device::device_start();

	save_item(NAME(m_pitr));
	save_item(NAME(m_sccr));
	save_item(NAME(m_spcr));
	save_item(NAME(m_tmsk1));
}

void m68hc16z_device::device_reset()
{
	cpu16_device::device_reset();

	m_pitr = 0;
	m_sccr[0] = 0x0004;
	m_sccr[1] = 0;
	m_spcr[0] = 0x0104;
	m_spcr[1] = 0x0404;
	m_spcr[2] = 0;
	m_spcr[3] = 0;
	m_tmsk1 = 0;
}


void m68hc16z_device::sim_map(address_map &map)
{
	map(0xffa00, 0xffa01).w(FUNC(m68hc16z_device::simcr_w));
	map(0xffa04, 0xffa05).w(FUNC(m68hc16z_device::syncr_w));
	map(0xffa07, 0xffa07).r(FUNC(m68hc16z_device::rsr_r));
	map(0xffa11, 0xffa11).mirror(2).w(FUNC(m68hc16z_device::porte_w));
	map(0xffa15, 0xffa15).w(FUNC(m68hc16z_device::ddre_w));
	map(0xffa17, 0xffa17).w(FUNC(m68hc16z_device::pepar_w));
	map(0xffa19, 0xffa19).mirror(2).w(FUNC(m68hc16z_device::portf_w));
	map(0xffa1d, 0xffa1d).w(FUNC(m68hc16z_device::ddrf_w));
	map(0xffa1f, 0xffa1f).w(FUNC(m68hc16z_device::pfpar_w));
	map(0xffa21, 0xffa21).w(FUNC(m68hc16z_device::sypcr_w));
	map(0xffa22, 0xffa23).w(FUNC(m68hc16z_device::picr_w));
	map(0xffa24, 0xffa25).rw(FUNC(m68hc16z_device::pitr_r), FUNC(m68hc16z_device::pitr_w));
	map(0xffa27, 0xffa27).w(FUNC(m68hc16z_device::swsr_w));
	map(0xffa44, 0xffa47).w(FUNC(m68hc16z_device::cspar_w));
	map(0xffa48, 0xffa77).w(FUNC(m68hc16z_device::csbar_csor_w));
}

void m68hc16z_device::sram_map(address_map &map)
{
	map(0xffb00, 0xffb01).w(FUNC(m68hc16z_device::rammcr_w));
	map(0xffb04, 0xffb07).w(FUNC(m68hc16z_device::ramba_w));
}

void m68hc16z_device::adc_map(address_map &map)
{
	map(0xff700, 0xff701).w(FUNC(m68hc16z_device::adcmcr_w));
	map(0xff70b, 0xff70b).w(FUNC(m68hc16z_device::adctl0_w));
	map(0xff70d, 0xff70d).w(FUNC(m68hc16z_device::adctl1_w));
	map(0xff70e, 0xff70f).r(FUNC(m68hc16z_device::adcstat_r));
	map(0xff710, 0xff71f).r(FUNC(m68hc16z_device::rjurr_r));
	map(0xff720, 0xff72f).r(FUNC(m68hc16z_device::ljsrr_r));
	map(0xff730, 0xff73f).r(FUNC(m68hc16z_device::ljurr_r));
}

void m68hc16z_device::qsm_map(address_map &map)
{
	map(0xffc00, 0xffc01).w(FUNC(m68hc16z_device::qsmcr_w));
	map(0xffc04, 0xffc04).w(FUNC(m68hc16z_device::qsilr_w));
	map(0xffc05, 0xffc05).w(FUNC(m68hc16z_device::qsivr_w));
	map(0xffc08, 0xffc0b).rw(FUNC(m68hc16z_device::sccr_r), FUNC(m68hc16z_device::sccr_w));
	map(0xffc0c, 0xffc0d).r(FUNC(m68hc16z_device::scsr_r));
	map(0xffc0e, 0xffc0f).w(FUNC(m68hc16z_device::scdr_w));
	map(0xffc15, 0xffc15).w(FUNC(m68hc16z_device::portqs_w));
	map(0xffc16, 0xffc16).w(FUNC(m68hc16z_device::pqspar_w));
	map(0xffc17, 0xffc17).w(FUNC(m68hc16z_device::ddrqs_w));
	map(0xffc18, 0xffc1f).rw(FUNC(m68hc16z_device::spcr_r), FUNC(m68hc16z_device::spcr_w));
	map(0xffd00, 0xffd4f).ram(); // Receive RAM, Transmit RAM, Command RAM
}

void m68hc16z_device::gpt_map(address_map &map)
{
	map(0xff900, 0xff901).w(FUNC(m68hc16z_device::gptmcr_w));
	map(0xff904, 0xff905).w(FUNC(m68hc16z_device::gpticr_w));
	map(0xff906, 0xff906).w(FUNC(m68hc16z_device::ddrgp_w));
	map(0xff907, 0xff907).w(FUNC(m68hc16z_device::portgp_w));
	map(0xff908, 0xff908).w(FUNC(m68hc16z_device::oc1m_w));
	map(0xff90a, 0xff90b).r(FUNC(m68hc16z_device::tcnt_r));
	map(0xff90c, 0xff90c).w(FUNC(m68hc16z_device::pactl_w));
	map(0xff914, 0xff91d).w(FUNC(m68hc16z_device::toc_w));
	map(0xff91e, 0xff91e).w(FUNC(m68hc16z_device::tctl1_w));
	map(0xff91f, 0xff91f).w(FUNC(m68hc16z_device::tctl2_w));
	map(0xff920, 0xff920).rw(FUNC(m68hc16z_device::tmsk1_r), FUNC(m68hc16z_device::tmsk1_w));
	map(0xff921, 0xff921).w(FUNC(m68hc16z_device::tmsk2_w));
	map(0xff922, 0xff922).w(FUNC(m68hc16z_device::tflg1_w));
	map(0xff923, 0xff923).w(FUNC(m68hc16z_device::tflg2_w));
}

void mc68hc16z1_device::internal_map(address_map &map)
{
	map(0xfe000, 0xfe3ff).ram(); // FIXME: SRAM can be relocated by setting RAMBAH:RAMBAL
	sim_map(map);
	sram_map(map);
	adc_map(map);
	qsm_map(map);
	gpt_map(map);
}


void m68hc16z_device::simcr_w(offs_t offset, u16 data, u16 mem_mask)
{
	logerror("%s: SIMCR = $%04X\n", machine().describe_context(), data);
}

void m68hc16z_device::syncr_w(offs_t offset, u16 data, u16 mem_mask)
{
	logerror("%s: SYNCR = $%04X\n", machine().describe_context(), data);
}

u8 m68hc16z_device::rsr_r()
{
	if (!machine().side_effects_disabled())
		logerror("%s: Read from RSR\n", machine().describe_context());
	return 0;
}

void m68hc16z_device::porte_w(u8 data)
{
	logerror("%s: PORTE = $%02X\n", machine().describe_context(), data);
}

void m68hc16z_device::ddre_w(u8 data)
{
	logerror("%s: DDRE = $%02X\n", machine().describe_context(), data);
}

void m68hc16z_device::pepar_w(u8 data)
{
	logerror("%s: PEPAR = $%02X\n", machine().describe_context(), data);
}

void m68hc16z_device::portf_w(u8 data)
{
	logerror("%s: PORTF = $%02X\n", machine().describe_context(), data);
}

void m68hc16z_device::ddrf_w(u8 data)
{
	logerror("%s: DDRF = $%02X\n", machine().describe_context(), data);
}

void m68hc16z_device::pfpar_w(u8 data)
{
	logerror("%s: PFPAR = $%02X\n", machine().describe_context(), data);
}

void m68hc16z_device::sypcr_w(u8 data)
{
	logerror("%s: SYPCR = $%02X\n", machine().describe_context(), data);
}

void m68hc16z_device::picr_w(offs_t offset, u16 data, u16 mem_mask)
{
	logerror("%s: PICR = $%04X\n", machine().describe_context(), data);
}

u16 m68hc16z_device::pitr_r()
{
	return m_pitr;
}

void m68hc16z_device::pitr_w(offs_t offset, u16 data, u16 mem_mask)
{
	u16 old_pitr = std::exchange(m_pitr, (m_pitr & ~mem_mask) | (data & mem_mask & 0x01ff));
	if (m_pitr != old_pitr)
		logerror("%s: PITR = $%04X\n", machine().describe_context(), m_pitr);
}

void m68hc16z_device::swsr_w(u8 data)
{
	if (data != 0x55 && data != 0xaa)
		logerror("%s: SWSR = $%02X\n", machine().describe_context(), data);
}

void m68hc16z_device::cspar_w(offs_t offset, u16 data, u16 mem_mask)
{
	logerror("%s: CSPAR%d = $%04X\n", machine().describe_context(), offset, data);
}

void m68hc16z_device::csbar_csor_w(offs_t offset, u16 data, u16 mem_mask)
{
	if (offset <= 1)
		logerror("%s: CS%sRBT = $%04X\n", machine().describe_context(), BIT(offset, 0) ? "BA" : "O", data);
	else
		logerror("%s: CS%sR%d = $%04X\n", machine().describe_context(), BIT(offset, 0) ? "BA" : "O", (offset >> 1) - 1, data);
}


void m68hc16z_device::rammcr_w(offs_t offset, u16 data, u16 mem_mask)
{
	logerror("%s: RAMMCR = $%04X\n", machine().describe_context(), data);
}

void m68hc16z_device::ramba_w(offs_t offset, u16 data, u16 mem_mask)
{
	logerror("%s: RAMBA%c = $%04X\n", machine().describe_context(), offset ? 'L' : 'H', data);
}


void m68hc16z_device::adcmcr_w(offs_t offset, u16 data, u16 mem_mask)
{
	logerror("%s: ADCMCR = $%04X\n", machine().describe_context(), data);
}

void m68hc16z_device::adctl0_w(u8 data)
{
	logerror("%s: ADCTL0 = $%02X\n", machine().describe_context(), data);
}

void m68hc16z_device::adctl1_w(u8 data)
{
	logerror("%s: ADCTL1 = $%02X\n", machine().describe_context(), data);
}

u16 m68hc16z_device::adcstat_r()
{
	if (!machine().side_effects_disabled())
		logerror("%s: Read from ADCSTAT\n", machine().describe_context());
	return 0;
}

u16 m68hc16z_device::rjurr_r(offs_t offset)
{
	if (!machine().side_effects_disabled())
		logerror("%s: Read from RJURR%d\n", machine().describe_context(), offset);
	return 0;
}

u16 m68hc16z_device::ljsrr_r(offs_t offset)
{
	if (!machine().side_effects_disabled())
		logerror("%s: Read from LJSRR%d\n", machine().describe_context(), offset);
	return 0;
}

u16 m68hc16z_device::ljurr_r(offs_t offset)
{
	if (!machine().side_effects_disabled())
		logerror("%s: Read from LJURR%d\n", machine().describe_context(), offset);
	return 0;
}


void m68hc16z_device::qsmcr_w(offs_t offset, u16 data, u16 mem_mask)
{
	logerror("%s: QSMCR = $%04X\n", machine().describe_context(), data);
}

void m68hc16z_device::qsilr_w(u8 data)
{
	logerror("%s: QSILR = $%02X\n", machine().describe_context(), data);
}

void m68hc16z_device::qsivr_w(u8 data)
{
	logerror("%s: QSIVR = $%02X\n", machine().describe_context(), data);
}

u16 m68hc16z_device::sccr_r(offs_t offset)
{
	return m_sccr[offset];
}

void m68hc16z_device::sccr_w(offs_t offset, u16 data, u16 mem_mask)
{
	u16 old_sccr = std::exchange(m_sccr[offset], (m_sccr[offset] & ~mem_mask) | (data & mem_mask));
	if (m_sccr[offset] != old_sccr)
		logerror("%s: SCCR%d = $%04X\n", machine().describe_context(), offset, m_sccr[offset]);
}

u16 m68hc16z_device::scsr_r()
{
	return 0x0180;
}

void m68hc16z_device::scdr_w(u16 data)
{
	if (BIT(m_sccr[1], 9))
		logerror("%s: SCDR = $%03X\n", machine().describe_context(), data & 0x01ff);
	else
	{
		data &= 0x00ff;
		logerror("%s: SCDR = $%02X%s\n", machine().describe_context(), data & 0x00ff,
				data >= 0x20 && data < 0x7f ? util::string_format(" ('%c')", data) : std::string());
	}
}

void m68hc16z_device::portqs_w(u8 data)
{
	logerror("%s: PORTQS = $%02X\n", machine().describe_context(), data);
}

void m68hc16z_device::pqspar_w(u8 data)
{
	logerror("%s: PQSPAR = $%02X\n", machine().describe_context(), data);
}

void m68hc16z_device::ddrqs_w(u8 data)
{
	logerror("%s: DDRQS = $%02X\n", machine().describe_context(), data);
}

u16 m68hc16z_device::spcr_r(offs_t offset)
{
	return m_spcr[offset];
}

void m68hc16z_device::spcr_w(offs_t offset, u16 data, u16 mem_mask)
{
	u16 old_spcr = std::exchange(m_spcr[offset], (m_spcr[offset] & ~mem_mask) | (data & mem_mask));
	if (m_spcr[offset] != old_spcr)
		logerror("%s: SPCR%d = $%04X\n", machine().describe_context(), offset, m_spcr[offset]);

	// HACK: always reset SPE
	if (offset == 1)
		m_spcr[offset] &= 0x7fff;
}


void m68hc16z_device::gptmcr_w(offs_t offset, u16 data, u16 mem_mask)
{
	logerror("%s: GPTMCR = $%04X\n", machine().describe_context(), data);
}

void m68hc16z_device::gpticr_w(offs_t offset, u16 data, u16 mem_mask)
{
	logerror("%s: GPTICR = $%04X\n", machine().describe_context(), data);
}

void m68hc16z_device::ddrgp_w(u8 data)
{
	logerror("%s: DDRGP = $%02X\n", machine().describe_context(), data);
}

void m68hc16z_device::portgp_w(u8 data)
{
	logerror("%s: PORTGP = $%02X\n", machine().describe_context(), data);
}

void m68hc16z_device::oc1m_w(u8 data)
{
	logerror("%s: OC1M = $%02X\n", machine().describe_context(), data);
}

u16 m68hc16z_device::tcnt_r()
{
	if (!machine().side_effects_disabled())
		logerror("%s: TCNT read\n", machine().describe_context());
	return 0;
}

void m68hc16z_device::pactl_w(u8 data)
{
	logerror("%s: PACTL = $%02X\n", machine().describe_context(), data);
}

void m68hc16z_device::toc_w(offs_t offset, u16 data, u16 mem_mask)
{
	logerror("%s: TOC%d = $%04X\n", machine().describe_context(), offset + 1, data);
}

void m68hc16z_device::tctl1_w(u8 data)
{
	logerror("%s: TCTL1 = $%02X\n", machine().describe_context(), data);
}

void m68hc16z_device::tctl2_w(u8 data)
{
	logerror("%s: TCTL2 = $%02X\n", machine().describe_context(), data);
}

u8 m68hc16z_device::tmsk1_r()
{
	return m_tmsk1;
}

void m68hc16z_device::tmsk1_w(u8 data)
{
	if (m_tmsk1 != data)
	{
		m_tmsk1 = data;
		//logerror("%s: TMSK1 = $%02X\n", machine().describe_context(), data);
	}
}

void m68hc16z_device::tmsk2_w(u8 data)
{
	logerror("%s: TMSK2 = $%02X\n", machine().describe_context(), data);
}

void m68hc16z_device::tflg1_w(u8 data)
{
	logerror("%s: TFLG1 = $%02X\n", machine().describe_context(), data);
}

void m68hc16z_device::tflg2_w(u8 data)
{
	logerror("%s: TFLG2 = $%02X\n", machine().describe_context(), data);
}