summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/cpu/dsp16/dsp16.c
blob: 411496ec88b8a0db4477a21202a035fc1acc7e6e (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
451
/***************************************************************************

    dsp16.h

    WE|AT&T DSP16 series emulator.

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

#include "emu.h"
#include "debugger.h"
#include "dsp16.h"

//
// TODO:
//  * Store the cache in 15 unique memory locations as it is on-chip.
//  * Modify cycle counts when running from within the cache
//  * A write to PI resets the pseudoramdom sequence generator)  (page 2-4)
//  * Handle virtual shift addressing using RB & RE (when RE is enabled)  (page 2-6)
//  * The ALU sign-extends 32-bit operands from y or p to 36 bits and produces a 36-bit output
//  * Interrupt lines  (page 2-15)
// 

//**************************************************************************
//  DEVICE INTERFACE
//**************************************************************************

// device type definition
const device_type DSP16 = &device_creator<dsp16_device>;


//-------------------------------------------------
//  dsp16_device - constructor
//-------------------------------------------------

dsp16_device::dsp16_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
	: cpu_device(mconfig, DSP16, "DSP16", tag, owner, clock, "dsp16", __FILE__),
		m_program_config("program", ENDIANNESS_LITTLE, 16, 16, -1),
		m_data_config("data", ENDIANNESS_LITTLE, 16, 16, -1),
		m_i(0),
		m_pc(0),
		m_pt(0),
		m_pr(0),
		m_pi(0),
		m_j(0),
		m_k(0),
		m_rb(0),
		m_re(0),
		m_r0(0),
		m_r1(0),
		m_r2(0),
		m_r3(0),
		m_x(0),
		m_y(0),
		m_p(0),
		m_a0(0),
		m_a1(0),
		m_auc(0),
		m_psw(0),
		m_c0(0),
		m_c1(0),
		m_c2(0),
		m_sioc(0),
		m_srta(0),
		m_sdx(0),
		m_pioc(0),
		m_pdx0(0),
		m_pdx1(0),
		m_ppc(0),
		m_cacheStart(CACHE_INVALID),
		m_cacheEnd(CACHE_INVALID),
		m_cacheRedoNextPC(CACHE_INVALID),
		m_cacheIterations(0),
		m_program(NULL),
		m_data(NULL),
		m_direct(NULL),
		m_icount(0)
{
	// Allocate & setup
}



//-------------------------------------------------
//  device_start - start up the device
//-------------------------------------------------

void dsp16_device::device_start()
{
	// register state with the debugger
	state_add(STATE_GENPC,    "GENPC",     m_pc).noshow();
	//state_add(STATE_GENPCBASE, "GENPCBASE", m_ppc).noshow();
	state_add(STATE_GENFLAGS, "GENFLAGS",  m_psw).callimport().callexport().formatstr("%10s").noshow();
	state_add(DSP16_PC,       "PC",        m_pc);
	state_add(DSP16_I,        "I",         m_i);
	state_add(DSP16_PT,       "PT",        m_pt);
	state_add(DSP16_PR,       "PR",        m_pr);
	state_add(DSP16_PI,       "PI",        m_pi);
	state_add(DSP16_J,        "J",         m_j);
	state_add(DSP16_K,        "K",         m_k);
	state_add(DSP16_RB,       "RB",        m_rb);
	state_add(DSP16_RE,       "RE",        m_re);
	state_add(DSP16_R0,       "R0",        m_r0);
	state_add(DSP16_R1,       "R1",        m_r1);
	state_add(DSP16_R2,       "R2",        m_r2);
	state_add(DSP16_R3,       "R3",        m_r3);
	state_add(DSP16_X,        "X",         m_x);
	state_add(DSP16_Y,        "Y",         m_y);
	state_add(DSP16_P,        "P",         m_p);
	state_add(DSP16_A0,       "A0",        m_a0).mask(U64(0xfffffffff));
	state_add(DSP16_A1,       "A1",        m_a1).mask(U64(0xfffffffff));
	state_add(DSP16_AUC,      "AUC",       m_auc).formatstr("%8s");
	state_add(DSP16_PSW,      "PSW",       m_psw).formatstr("%16s");
	state_add(DSP16_C0,       "C0",        m_c0);
	state_add(DSP16_C1,       "C1",        m_c1);
	state_add(DSP16_C2,       "C2",        m_c2);
	state_add(DSP16_SIOC,     "SIOC",      m_sioc).formatstr("%10s");
	state_add(DSP16_SRTA,     "SRTA",      m_srta);
	state_add(DSP16_SDX,      "SDX",       m_sdx);
	state_add(DSP16_PIOC,     "PIOC",      m_pioc).formatstr("%16s");
	state_add(DSP16_PDX0,     "PDX0",      m_pdx0);
	state_add(DSP16_PDX1,     "PDX1",      m_pdx1);

	// register our state for saving
	save_item(NAME(m_i));
	save_item(NAME(m_pc));
	save_item(NAME(m_pt));
	save_item(NAME(m_pr));
	save_item(NAME(m_pi));
	save_item(NAME(m_j));
	save_item(NAME(m_k));
	save_item(NAME(m_rb));
	save_item(NAME(m_re));
	save_item(NAME(m_r0));
	save_item(NAME(m_r1));
	save_item(NAME(m_r2));
	save_item(NAME(m_r3));
	save_item(NAME(m_x));
	save_item(NAME(m_y));
	save_item(NAME(m_p));
	save_item(NAME(m_a0));
	save_item(NAME(m_a1));
	save_item(NAME(m_auc));
	save_item(NAME(m_psw));
	save_item(NAME(m_c0));
	save_item(NAME(m_c1));
	save_item(NAME(m_c2));
	save_item(NAME(m_sioc));
	save_item(NAME(m_srta));
	save_item(NAME(m_sdx));
	save_item(NAME(m_pioc));
	save_item(NAME(m_pdx0));
	save_item(NAME(m_pdx1));
	save_item(NAME(m_ppc));
	save_item(NAME(m_cacheStart));
	save_item(NAME(m_cacheEnd));
	save_item(NAME(m_cacheRedoNextPC));
	save_item(NAME(m_cacheIterations));

	// get our address spaces
	m_program = &space(AS_PROGRAM);
	m_data = &space(AS_DATA);
	m_direct = &m_program->direct();

	// set our instruction counter
	m_icountptr = &m_icount;
}


//-------------------------------------------------
//  device_reset - reset the device
//-------------------------------------------------

void dsp16_device::device_reset()
{
	// Page 7-5
	m_pc = 0x0000;
	m_pi = 0x0000;
	m_sioc = 0x0000;    // (page 5-4)
    
	// SRTA is unaltered by reset
	m_pioc = 0x0008;
	m_rb = 0x0000;
	m_re = 0x0000;
	
    // AUC is not affected by reset
	m_ppc = m_pc;

	// Hacky cache emulation.
	m_cacheStart = CACHE_INVALID;
	m_cacheEnd = CACHE_INVALID;
	m_cacheRedoNextPC = CACHE_INVALID;
	m_cacheIterations = 0;
}


//-------------------------------------------------
//  memory_space_config - return the configuration
//  of the specified address space, or NULL if
//  the space doesn't exist
//-------------------------------------------------

const address_space_config *dsp16_device::memory_space_config(address_spacenum spacenum) const
{
	return (spacenum == AS_PROGRAM) ? &m_program_config :
		   (spacenum == AS_DATA) ? &m_data_config :
		   NULL;
}


//-------------------------------------------------
//  state_string_export - export state as a string
//  for the debugger
//-------------------------------------------------

void dsp16_device::state_string_export(const device_state_entry &entry, astring &string)
{
	switch (entry.index())
	{
		case STATE_GENFLAGS:
		string.printf("(below)");
			break;

        case DSP16_AUC:
        {
            astring alignString;
            const UINT8 align = m_auc & 0x03;
            switch (align)
            {
                case 0x00: alignString.printf("xy"); break;
                case 0x01: alignString.printf("/4"); break;
                case 0x02: alignString.printf("x4"); break;
                case 0x03: alignString.printf(",,"); break;
            }
            string.printf("%c%c%c%c%c%s",
                          m_auc & 0x40 ? 'Y':'.',
                          m_auc & 0x20 ? '1':'.',
                          m_auc & 0x10 ? '0':'.',
                          m_auc & 0x08 ? '1':'.',
                          m_auc & 0x04 ? '0':'.',
                          alignString.cstr());
            break;
        }

        case DSP16_PSW:
            string.printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
                          m_psw & 0x8000 ? 'M':'.',
                          m_psw & 0x4000 ? 'E':'.',
                          m_psw & 0x2000 ? 'L':'.',
                          m_psw & 0x1000 ? 'V':'.',
                          m_psw & 0x0800 ? ',':',',
                          m_psw & 0x0400 ? ',':',',
                          m_psw & 0x0200 ? 'O':'.',
                          m_psw & 0x0100 ? '1':'.',
                          m_psw & 0x0080 ? '1':'.',
                          m_psw & 0x0040 ? '1':'.',
                          m_psw & 0x0020 ? '1':'.',
                          m_psw & 0x0010 ? 'O':'.',
                          m_psw & 0x0008 ? '1':'.',
                          m_psw & 0x0004 ? '1':'.',
                          m_psw & 0x0002 ? '1':'.',
                          m_psw & 0x0001 ? '1':'.');
            break;

        case DSP16_PIOC:
        {
            astring strobeString;
            const UINT8 strobe = (m_pioc & 0x6000) >> 13;
            switch (strobe)
            {
                case 0x00: strobeString.printf("1T"); break;
                case 0x01: strobeString.printf("2T"); break;
                case 0x02: strobeString.printf("3T"); break;
                case 0x03: strobeString.printf("4T"); break;
            }
            string.printf("%c%s%c%c%c%c%c%c%c%c%c%c%c%c%c",
                          m_pioc & 0x8000 ? 'I':'.',
                          strobeString.cstr(),
                          m_pioc & 0x1000 ? 'O':'I',
                          m_pioc & 0x0800 ? 'O':'I',
                          m_pioc & 0x0400 ? 'S':'.',
                          m_pioc & 0x0200 ? 'I':'.',
                          m_pioc & 0x0100 ? 'O':'.',
                          m_pioc & 0x0080 ? 'P':'.',
                          m_pioc & 0x0040 ? 'P':'.',
                          m_pioc & 0x0020 ? 'I':'.',
                          m_pioc & 0x0010 ? 'I':'.',
                          m_pioc & 0x0008 ? 'O':'.',
                          m_pioc & 0x0004 ? 'P':'.',
                          m_pioc & 0x0002 ? 'P':'.',
                          m_pioc & 0x0001 ? 'I':'.');
            break;
        }
            
		// Placeholder for a better view later (TODO)
		case DSP16_SIOC:
        {
            astring clkString;
            const UINT8 clk = (m_sioc & 0x0180) >> 7;
            switch (clk)
            {
                case 0x00: clkString.printf("/4"); break;
                case 0x01: clkString.printf("12"); break;
                case 0x02: clkString.printf("16"); break;
                case 0x03: clkString.printf("20"); break;
            }
            string.printf("%c%s%c%c%c%c%c%c%c",
                          m_sioc & 0x0200 ? 'I':'O',
                          clkString.cstr(),
                          m_sioc & 0x0040 ? 'L':'M',
                          m_sioc & 0x0020 ? 'I':'O',
                          m_sioc & 0x0010 ? 'I':'O',
                          m_sioc & 0x0008 ? 'I':'O',
                          m_sioc & 0x0004 ? 'I':'O',
                          m_sioc & 0x0002 ? '2':'1',
                          m_sioc & 0x0001 ? '2':'1');
            break;
        }
	}
}


//-------------------------------------------------
//  disasm_min_opcode_bytes - return the length
//  of the shortest instruction, in bytes
//-------------------------------------------------

UINT32 dsp16_device::disasm_min_opcode_bytes() const
{
	return 2;
}


//-------------------------------------------------
//  disasm_max_opcode_bytes - return the length
//  of the longest instruction, in bytes
//-------------------------------------------------

UINT32 dsp16_device::disasm_max_opcode_bytes() const
{
	return 4;
}


//-------------------------------------------------
//  disasm_disassemble - call the disassembly
//  helper function
//-------------------------------------------------

offs_t dsp16_device::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options)
{
	extern CPU_DISASSEMBLE( dsp16a );
	return CPU_DISASSEMBLE_NAME(dsp16a)(this, buffer, pc, oprom, opram, options);
}



/***************************************************************************
    MEMORY ACCESSORS
***************************************************************************/

inline UINT32 dsp16_device::data_read(const UINT16& addr)
{
	return m_data->read_word(addr << 1);
}

inline void dsp16_device::data_write(const UINT16& addr, const UINT16& data)
{
	m_data->write_word(addr << 1, data & 0xffff);
}

inline UINT32 dsp16_device::opcode_read(const UINT8 pcOffset)
{
	const UINT16 readPC = m_pc + pcOffset;
	return m_direct->read_decrypted_dword(readPC << 1);
}


/***************************************************************************
    CORE EXECUTION LOOP
***************************************************************************/

//-------------------------------------------------
//  execute_min_cycles - return minimum number of
//  cycles it takes for one instruction to execute
//-------------------------------------------------

UINT32 dsp16_device::execute_min_cycles() const
{
	return 1;
}


//-------------------------------------------------
//  execute_max_cycles - return maximum number of
//  cycles it takes for one instruction to execute
//-------------------------------------------------

UINT32 dsp16_device::execute_max_cycles() const
{
	return 1;
}


//-------------------------------------------------
//  execute_input_lines - return the number of
//  input/interrupt lines
//-------------------------------------------------

UINT32 dsp16_device::execute_input_lines() const
{
	return 1;
}


void dsp16_device::execute_set_input(int inputnum, int state)
{
	// Only has one external IRQ line
}


void dsp16_device::execute_run()
{
	// HACK TO MAKE CPU DO NOTHING.
	// REMOVE IF DEVELOPING CPU CORE.
	m_icount = 0;
	return;

	do
	{
		// debugging
		m_ppc = m_pc;   // copy PC to previous PC
		debugger_instruction_hook(this, m_pc);

		// instruction fetch & execute
		UINT8 cycles;
		UINT8 pcAdvance;
		const UINT16 op = opcode_read();
		execute_one(op, cycles, pcAdvance);

		// step
		m_pc += pcAdvance;
		m_icount -= cycles;

        // The 16 bit PI "shadow" register gets set to PC on each instruction except
        // when an interrupt service routine is active (TODO: Interrupt check)  (page 2-4)
        m_pi = m_pc;

	} while (m_icount > 0);
}

#include "dsp16ops.c"