summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/cpu/dsp32/dsp32.h
blob: 67dca61d3d146d2fdaf9d873a11486ab0fd42439 (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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
/***************************************************************************

    dsp32.h
    Interface file for the portable DSP32 emulator.

****************************************************************************

    Copyright Aaron Giles
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are
    met:

        * Redistributions of source code must retain the above copyright
          notice, this list of conditions and the following disclaimer.
        * Redistributions in binary form must reproduce the above copyright
          notice, this list of conditions and the following disclaimer in
          the documentation and/or other materials provided with the
          distribution.
        * Neither the name 'MAME' nor the names of its contributors may be
          used to endorse or promote products derived from this software
          without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    POSSIBILITY OF SUCH DAMAGE.

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

#pragma once

#ifndef __DSP32_H__
#define __DSP32_H__


//**************************************************************************
//  INTERFACE CONFIGURATION MACROS
//**************************************************************************

#define MCFG_DSP32C_CONFIG(_config) \
	dsp32c_device_config::static_set_config(device, _config); \



//**************************************************************************
//  CONSTANTS
//**************************************************************************

// IRQ sources
const int DSP32_IRQ0		= 0;		// IRQ0
const int DSP32_IRQ1		= 1;		// IRQ1

// pin signal bits
const int DSP32_OUTPUT_PIF = 0x01;

// register enumeration
enum
{
	// CAU
	DSP32_PC=1,
	DSP32_R0,
	DSP32_R1,
	DSP32_R2,
	DSP32_R3,
	DSP32_R4,
	DSP32_R5,
	DSP32_R6,
	DSP32_R7,
	DSP32_R8,
	DSP32_R9,
	DSP32_R10,
	DSP32_R11,
	DSP32_R12,
	DSP32_R13,
	DSP32_R14,
	DSP32_R15,
	DSP32_R16,
	DSP32_R17,
	DSP32_R18,
	DSP32_R19,
	DSP32_R20,
	DSP32_R21,
	DSP32_R22,
	DSP32_PIN,
	DSP32_POUT,
	DSP32_IVTP,

	// DAU
	DSP32_A0,
	DSP32_A1,
	DSP32_A2,
	DSP32_A3,
	DSP32_DAUC,

	// PIO
	DSP32_PAR,
	DSP32_PDR,
	DSP32_PIR,
	DSP32_PCR,
	DSP32_EMR,
	DSP32_ESR,
	DSP32_PCW,
	DSP32_PIOP,

	// SIO
	DSP32_IBUF,
	DSP32_ISR,
	DSP32_OBUF,
	DSP32_OSR,
	DSP32_IOC
};


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

extern const device_type DSP32C;



//**************************************************************************
//  TYPE DEFINITIONS
//**************************************************************************

class dsp32c_device;


// ======================> dsp32_config

struct dsp32_config
{
	void (*m_output_pins_changed)(dsp32c_device &device, UINT32 pins);	// a change has occurred on an output pin
};



// ======================> dsp32c_device_config

class dsp32c_device_config : 	public cpu_device_config,
								public dsp32_config
{
	friend class dsp32c_device;

	// construction/destruction
	dsp32c_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);

public:
	// allocators
	static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
	virtual device_t *alloc_device(running_machine &machine) const;

	// inline configuration helpers
	static void static_set_config(device_config *device, const dsp32_config &config);

protected:
	// device_config_execute_interface overrides
	virtual UINT32 execute_min_cycles() const;
	virtual UINT32 execute_max_cycles() const;
	virtual UINT32 execute_input_lines() const;

	// device_config_memory_interface overrides
	virtual const address_space_config *memory_space_config(int spacenum = 0) const;

	// device_config_disasm_interface overrides
	virtual UINT32 disasm_min_opcode_bytes() const;
	virtual UINT32 disasm_max_opcode_bytes() const;

	// inline data
	const address_space_config		m_program_config;
};



// ======================> dsp32c_device

class dsp32c_device : public cpu_device
{
	friend class dsp32c_device_config;

	// construction/destruction
	dsp32c_device(running_machine &_machine, const dsp32c_device_config &config);

public:
	// public interfaces
	void pio_w(int reg, int data);
	int pio_r(int reg);

protected:
	// device-level overrides
	virtual void device_start();
	virtual void device_reset();

	// device_execute_interface overrides
	virtual void execute_run();
	virtual void execute_set_input(int inputnum, int state);

	// device_state_interface overrides
	virtual void state_import(const device_state_entry &entry);
	virtual void state_export(const device_state_entry &entry);
	virtual void state_string_export(const device_state_entry &entry, astring &string);

	// device_disasm_interface overrides
	virtual offs_t disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options);

	// memory accessors
	UINT32 ROPCODE(offs_t pc);
	UINT8 RBYTE(offs_t addr);
	void WBYTE(offs_t addr, UINT8 data);
	UINT16 RWORD(offs_t addr);
	UINT32 RLONG(offs_t addr);
	void WWORD(offs_t addr, UINT16 data);
	void WLONG(offs_t addr, UINT32 data);

	// interrupts
	void check_irqs();
	void set_irq_line(int irqline, int state);

	void update_pcr(UINT16 newval);
	void illegal(UINT32 op);
	void unimplemented(UINT32 op);
	void execute_one();

	// CAU helpers
	UINT32 cau_read_pi_special(UINT8 i);
	void cau_write_pi_special(UINT8 i, UINT32 val);
	UINT8 cau_read_pi_1byte(int pi);
	UINT16 cau_read_pi_2byte(int pi);
	UINT32 cau_read_pi_4byte(int pi);
	void cau_write_pi_1byte(int pi, UINT8 val);
	void cau_write_pi_2byte(int pi, UINT16 val);
	void cau_write_pi_4byte(int pi, UINT32 val);

	// DAU helpers
	double dau_get_amult(int aidx);
	double dau_get_anzflags();
	UINT8 dau_get_avuflags();
	void remember_last_dau(int aidx);
	void dau_set_val_noflags(int aidx, double res);
	void dau_set_val_flags(int aidx, double res);
	double dsp_to_double(UINT32 val);
	UINT32 double_to_dsp(double val);
	double dau_read_pi_special(int i);
	void dau_write_pi_special(int i, double val);
	double dau_read_pi_double_1st(int pi, int multiplier);
	double dau_read_pi_double_2nd(int pi, int multiplier, double xval);
	UINT32 dau_read_pi_4bytes(int pi);
	UINT16 dau_read_pi_2bytes(int pi);
	void dau_write_pi_double(int pi, double val);
	void dau_write_pi_4bytes(int pi, UINT32 val);
	void dau_write_pi_2bytes(int pi, UINT16 val);

	// common condition routine
	int condition(int cond);

	// CAU branch instruction implementation
	void nop(UINT32 op);
	void goto_t(UINT32 op);
	void goto_pl(UINT32 op);
	void goto_mi(UINT32 op);
	void goto_ne(UINT32 op);
	void goto_eq(UINT32 op);
	void goto_vc(UINT32 op);
	void goto_vs(UINT32 op);
	void goto_cc(UINT32 op);
	void goto_cs(UINT32 op);
	void goto_ge(UINT32 op);
	void goto_lt(UINT32 op);
	void goto_gt(UINT32 op);
	void goto_le(UINT32 op);
	void goto_hi(UINT32 op);
	void goto_ls(UINT32 op);
	void goto_auc(UINT32 op);
	void goto_aus(UINT32 op);
	void goto_age(UINT32 op);
	void goto_alt(UINT32 op);
	void goto_ane(UINT32 op);
	void goto_aeq(UINT32 op);
	void goto_avc(UINT32 op);
	void goto_avs(UINT32 op);
	void goto_agt(UINT32 op);
	void goto_ale(UINT32 op);
	void goto_ibe(UINT32 op);
	void goto_ibf(UINT32 op);
	void goto_obf(UINT32 op);
	void goto_obe(UINT32 op);
	void goto_pde(UINT32 op);
	void goto_pdf(UINT32 op);
	void goto_pie(UINT32 op);
	void goto_pif(UINT32 op);
	void goto_syc(UINT32 op);
	void goto_sys(UINT32 op);
	void goto_fbc(UINT32 op);
	void goto_fbs(UINT32 op);
	void goto_irq1lo(UINT32 op);
	void goto_irq1hi(UINT32 op);
	void goto_irq2lo(UINT32 op);
	void goto_irq2hi(UINT32 op);
	void dec_goto(UINT32 op);
	void call(UINT32 op);
	void goto24(UINT32 op);
	void call24(UINT32 op);
	void do_i(UINT32 op);
	void do_r(UINT32 op);

	// CAU 16-bit arithmetic implementation
	void add_si(UINT32 op);
	void add_ss(UINT32 op);
	void mul2_s(UINT32 op);
	void subr_ss(UINT32 op);
	void addr_ss(UINT32 op);
	void sub_ss(UINT32 op);
	void neg_s(UINT32 op);
	void andc_ss(UINT32 op);
	void cmp_ss(UINT32 op);
	void xor_ss(UINT32 op);
	void rcr_s(UINT32 op);
	void or_ss(UINT32 op);
	void rcl_s(UINT32 op);
	void shr_s(UINT32 op);
	void div2_s(UINT32 op);
	void and_ss(UINT32 op);
	void test_ss(UINT32 op);
	void add_di(UINT32 op);
	void subr_di(UINT32 op);
	void addr_di(UINT32 op);
	void sub_di(UINT32 op);
	void andc_di(UINT32 op);
	void cmp_di(UINT32 op);
	void xor_di(UINT32 op);
	void or_di(UINT32 op);
	void and_di(UINT32 op);
	void test_di(UINT32 op);

	// CAU 24-bit arithmetic implementation
	void adde_si(UINT32 op);
	void adde_ss(UINT32 op);
	void mul2e_s(UINT32 op);
	void subre_ss(UINT32 op);
	void addre_ss(UINT32 op);
	void sube_ss(UINT32 op);
	void nege_s(UINT32 op);
	void andce_ss(UINT32 op);
	void cmpe_ss(UINT32 op);
	void xore_ss(UINT32 op);
	void rcre_s(UINT32 op);
	void ore_ss(UINT32 op);
	void rcle_s(UINT32 op);
	void shre_s(UINT32 op);
	void div2e_s(UINT32 op);
	void ande_ss(UINT32 op);
	void teste_ss(UINT32 op);
	void adde_di(UINT32 op);
	void subre_di(UINT32 op);
	void addre_di(UINT32 op);
	void sube_di(UINT32 op);
	void andce_di(UINT32 op);
	void cmpe_di(UINT32 op);
	void xore_di(UINT32 op);
	void ore_di(UINT32 op);
	void ande_di(UINT32 op);
	void teste_di(UINT32 op);

	// CAU load/store implementation
	void load_hi(UINT32 op);
	void load_li(UINT32 op);
	void load_i(UINT32 op);
	void load_ei(UINT32 op);
	void store_hi(UINT32 op);
	void store_li(UINT32 op);
	void store_i(UINT32 op);
	void store_ei(UINT32 op);
	void load_hr(UINT32 op);
	void load_lr(UINT32 op);
	void load_r(UINT32 op);
	void load_er(UINT32 op);
	void store_hr(UINT32 op);
	void store_lr(UINT32 op);
	void store_r(UINT32 op);
	void store_er(UINT32 op);
	void load24(UINT32 op);

	// DAU form 1 implementation
	void d1_aMpp(UINT32 op);
	void d1_aMpm(UINT32 op);
	void d1_aMmp(UINT32 op);
	void d1_aMmm(UINT32 op);
	void d1_0px(UINT32 op);
	void d1_0mx(UINT32 op);
	void d1_1pp(UINT32 op);
	void d1_1pm(UINT32 op);
	void d1_1mp(UINT32 op);
	void d1_1mm(UINT32 op);
	void d1_aMppr(UINT32 op);
	void d1_aMpmr(UINT32 op);
	void d1_aMmpr(UINT32 op);
	void d1_aMmmr(UINT32 op);

	// DAU form 2 implementation
	void d2_aMpp(UINT32 op);
	void d2_aMpm(UINT32 op);
	void d2_aMmp(UINT32 op);
	void d2_aMmm(UINT32 op);
	void d2_aMppr(UINT32 op);
	void d2_aMpmr(UINT32 op);
	void d2_aMmpr(UINT32 op);
	void d2_aMmmr(UINT32 op);

	// DAU form 3 implementation
	void d3_aMpp(UINT32 op);
	void d3_aMpm(UINT32 op);
	void d3_aMmp(UINT32 op);
	void d3_aMmm(UINT32 op);
	void d3_aMppr(UINT32 op);
	void d3_aMpmr(UINT32 op);
	void d3_aMmpr(UINT32 op);
	void d3_aMmmr(UINT32 op);

	// DAU form 4 implementation
	void d4_pp(UINT32 op);
	void d4_pm(UINT32 op);
	void d4_mp(UINT32 op);
	void d4_mm(UINT32 op);
	void d4_ppr(UINT32 op);
	void d4_pmr(UINT32 op);
	void d4_mpr(UINT32 op);
	void d4_mmr(UINT32 op);

	// DAU form 5 implementation
	void d5_ic(UINT32 op);
	void d5_oc(UINT32 op);
	void d5_float(UINT32 op);
	void d5_int(UINT32 op);
	void d5_round(UINT32 op);
	void d5_ifalt(UINT32 op);
	void d5_ifaeq(UINT32 op);
	void d5_ifagt(UINT32 op);
	void d5_float24(UINT32 op);
	void d5_int24(UINT32 op);
	void d5_ieee(UINT32 op);
	void d5_dsp(UINT32 op);
	void d5_seed(UINT32 op);
	
	// dma helpers
	void dma_increment();
	void dma_load();
	void dma_store();

	// configuration
	const dsp32c_device_config &m_config;

	// internal state
	UINT32			m_r[32];
	UINT32			m_pin, m_pout;
	UINT32			m_ivtp;
	UINT32			m_nzcflags;
	UINT32			m_vflags;

	double			m_a[6];
	double			m_NZflags;
	UINT8			m_VUflags;

	double			m_abuf[4];
	UINT8			m_abufreg[4];
	UINT8			m_abufVUflags[4];
	UINT8			m_abufNZflags[4];
	int				m_abufcycle[4];
	int				m_abuf_index;

	INT32			m_mbufaddr[4];
	UINT32			m_mbufdata[4];
	int				m_mbuf_index;

	UINT16			m_par;
	UINT8			m_pare;
	UINT16			m_pdr;
	UINT16			m_pdr2;
	UINT16			m_pir;
	UINT16			m_pcr;
	UINT16			m_emr;
	UINT8			m_esr;
	UINT16			m_pcw;
	UINT8			m_piop;

	UINT32			m_ibuf;
	UINT32			m_isr;
	UINT32			m_obuf;
	UINT32			m_osr;
	
	UINT32			m_iotemp;

	// internal stuff
	int 			m_lastp;
	int				m_icount;
	UINT8			m_lastpins;
	UINT32			m_ppc;
	address_space *	m_program;
	direct_read_data *m_direct;

	// tables
	static void (dsp32c_device::*const s_dsp32ops[])(UINT32 op);
	static const UINT32 s_regmap[4][16];
};


#endif /* __DSP32_H__ */