~ubuntu-branches/ubuntu/raring/mame/raring-proposed

« back to all changes in this revision

Viewing changes to mess/src/emu/cpu/dsp32/dsp32.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach, Jordi Mallach, Emmanuel Kasper
  • Date: 2011-12-19 22:56:27 UTC
  • mfrom: (0.1.2)
  • Revision ID: package-import@ubuntu.com-20111219225627-ub5oga1oys4ogqzm
Tags: 0.144-1
[ Jordi Mallach ]
* Fix syntax errors in DEP5 copyright file (lintian).
* Use a versioned copyright Format specification field.
* Update Vcs-* URLs.
* Move transitional packages to the new metapackages section, and make
  them priority extra.
* Remove references to GNU/Linux and MESS sources from copyright.
* Add build variables for s390x.
* Use .xz tarballs as it cuts 4MB for the upstream sources.
* Add nplayers.ini as a patch. Update copyright file to add CC-BY-SA-3.0.

[ Emmanuel Kasper ]
* New upstream release. Closes: #651538.
* Add Free Desktop compliant png icons of various sizes taken from
  the hydroxygen iconset
* Mess is now built from a new source package, to avoid possible source
  incompatibilities between mame and the mess overlay.
* Mame-tools are not built from the mame source package anymore, but
  from the mess source package

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 
3
 
    dsp32.c
4
 
    Core implementation for the portable DSP32 emulator.
5
 
 
6
 
****************************************************************************
7
 
 
8
 
    Copyright Aaron Giles
9
 
    All rights reserved.
10
 
 
11
 
    Redistribution and use in source and binary forms, with or without
12
 
    modification, are permitted provided that the following conditions are
13
 
    met:
14
 
 
15
 
        * Redistributions of source code must retain the above copyright
16
 
          notice, this list of conditions and the following disclaimer.
17
 
        * Redistributions in binary form must reproduce the above copyright
18
 
          notice, this list of conditions and the following disclaimer in
19
 
          the documentation and/or other materials provided with the
20
 
          distribution.
21
 
        * Neither the name 'MAME' nor the names of its contributors may be
22
 
          used to endorse or promote products derived from this software
23
 
          without specific prior written permission.
24
 
 
25
 
    THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
26
 
    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27
 
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28
 
    DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
29
 
    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30
 
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31
 
    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32
 
    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33
 
    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
34
 
    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35
 
    POSSIBILITY OF SUCH DAMAGE.
36
 
 
37
 
****************************************************************************
38
 
 
39
 
    Important note:
40
 
 
41
 
    At this time, the emulator is rather incomplete. However, it is
42
 
    sufficiently complete to run both Race Drivin' and Hard Drivin's
43
 
    Airborne, which is all I was after.
44
 
 
45
 
    Things that still need to be implemented:
46
 
 
47
 
        * interrupts
48
 
        * carry-reverse add operations
49
 
        * do loops
50
 
        * ieee/dsp conversions
51
 
        * input/output conversion
52
 
        * serial I/O
53
 
 
54
 
    In addition, there are several optimizations enabled which make
55
 
    assumptions about the code which may not be valid for other
56
 
    applications. Check dsp32ops.c for details.
57
 
 
58
 
***************************************************************************/
59
 
 
60
 
#include "emu.h"
61
 
#include "debugger.h"
62
 
#include "dsp32.h"
63
 
 
64
 
 
65
 
//**************************************************************************
66
 
//  DEBUGGING
67
 
//**************************************************************************
68
 
 
69
 
#define DETECT_MISALIGNED_MEMORY        0
70
 
 
71
 
 
72
 
 
73
 
//**************************************************************************
74
 
//  CONSTANTS
75
 
//**************************************************************************
76
 
 
77
 
// internal register numbering for PIO registers
78
 
#define PIO_PAR                 0
79
 
#define PIO_PDR                 1
80
 
#define PIO_EMR                 2
81
 
#define PIO_ESR                 3
82
 
#define PIO_PCR                 4
83
 
#define PIO_PIR                 5
84
 
#define PIO_PARE                6
85
 
#define PIO_PDR2                7
86
 
#define PIO_RESERVED    8
87
 
 
88
 
#define UPPER                   (0x00ff << 8)
89
 
#define LOWER                   (0xff00 << 8)
90
 
 
91
 
// bits in the PCR register
92
 
#define PCR_RESET               0x001
93
 
#define PCR_REGMAP              0x002
94
 
#define PCR_ENI                 0x004
95
 
#define PCR_DMA                 0x008
96
 
#define PCR_AUTO                0x010
97
 
#define PCR_PDFs                0x020
98
 
#define PCR_PIFs                0x040
99
 
#define PCR_RES                 0x080
100
 
#define PCR_DMA32               0x100
101
 
#define PCR_PIO16               0x200
102
 
#define PCR_FLG                 0x400
103
 
 
104
 
// internal flag bits
105
 
#define UFLAGBIT                1
106
 
#define VFLAGBIT                2
107
 
 
108
 
 
109
 
 
110
 
//**************************************************************************
111
 
//  MACROS
112
 
//**************************************************************************
113
 
 
114
 
// register mapping
115
 
#define R0                              m_r[0]
116
 
#define R1                              m_r[1]
117
 
#define R2                              m_r[2]
118
 
#define R3                              m_r[3]
119
 
#define R4                              m_r[4]
120
 
#define R5                              m_r[5]
121
 
#define R6                              m_r[6]
122
 
#define R7                              m_r[7]
123
 
#define R8                              m_r[8]
124
 
#define R9                              m_r[9]
125
 
#define R10                             m_r[10]
126
 
#define R11                             m_r[11]
127
 
#define R12                             m_r[12]
128
 
#define R13                             m_r[13]
129
 
#define R14                             m_r[14]
130
 
#define PC                              m_r[15]
131
 
#define R0_ALT                  m_r[16]
132
 
#define R15                             m_r[17]
133
 
#define R16                             m_r[18]
134
 
#define R17                             m_r[19]
135
 
#define R18                             m_r[20]
136
 
#define R19                             m_r[21]
137
 
#define RMM                             m_r[22]
138
 
#define RPP                             m_r[23]
139
 
#define R20                             m_r[24]
140
 
#define R21                             m_r[25]
141
 
#define DAUC                    m_r[26]
142
 
#define IOC                             m_r[27]
143
 
#define R22                             m_r[29]
144
 
#define PCSH                    m_r[30]
145
 
 
146
 
#define A0                              m_a[0]
147
 
#define A1                              m_a[1]
148
 
#define A2                              m_a[2]
149
 
#define A3                              m_a[3]
150
 
#define A_0                             m_a[4]
151
 
#define A_1                             m_a[5]
152
 
 
153
 
#define zFLAG                   ((m_nzcflags & 0xffffff) == 0)
154
 
#define nFLAG                   ((m_nzcflags & 0x800000) != 0)
155
 
#define cFLAG                   ((m_nzcflags & 0x1000000) != 0)
156
 
#define vFLAG                   ((m_vflags & 0x800000) != 0)
157
 
#define ZFLAG                   (m_NZflags == 0)
158
 
#define NFLAG                   (m_NZflags < 0)
159
 
#define UFLAG                   (m_VUflags & UFLAGBIT)
160
 
#define VFLAG                   (m_VUflags & VFLAGBIT)
161
 
 
162
 
 
163
 
 
164
 
//**************************************************************************
165
 
//  DEVICE INTERFACE
166
 
//**************************************************************************
167
 
 
168
 
const device_type DSP32C = &device_creator<dsp32c_device>;
169
 
 
170
 
//-------------------------------------------------
171
 
//  dsp32c_device - constructor
172
 
//-------------------------------------------------
173
 
 
174
 
dsp32c_device::dsp32c_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
175
 
        : cpu_device(mconfig, DSP32C, "DSP32C", tag, owner, clock),
176
 
          m_program_config("program", ENDIANNESS_LITTLE, 32, 24),
177
 
          m_pin(0),
178
 
          m_pout(0),
179
 
          m_ivtp(0),
180
 
          m_nzcflags(0),
181
 
          m_vflags(0),
182
 
          m_NZflags(0),
183
 
          m_VUflags(0),
184
 
          m_abuf_index(0),
185
 
          m_mbuf_index(0),
186
 
          m_par(0),
187
 
          m_pare(0),
188
 
          m_pdr(0),
189
 
          m_pdr2(0),
190
 
          m_pir(0),
191
 
          m_pcr(0),
192
 
          m_emr(0),
193
 
          m_esr(0),
194
 
          m_pcw(0),
195
 
          m_piop(0),
196
 
          m_ibuf(0),
197
 
          m_isr(0),
198
 
          m_obuf(0),
199
 
          m_osr(0),
200
 
          m_iotemp(0),
201
 
          m_lastp(0),
202
 
          m_icount(0),
203
 
          m_lastpins(0),
204
 
          m_ppc(0),
205
 
          m_program(NULL),
206
 
          m_direct(NULL)
207
 
{
208
 
        m_output_pins_changed = NULL;
209
 
 
210
 
        // set our instruction counter
211
 
        m_icountptr = &m_icount;
212
 
}
213
 
 
214
 
 
215
 
//-------------------------------------------------
216
 
//  static_set_config - set the configuration
217
 
//  structure
218
 
//-------------------------------------------------
219
 
 
220
 
void dsp32c_device::static_set_config(device_t &device, const dsp32_config &config)
221
 
{
222
 
        dsp32c_device &dsp = downcast<dsp32c_device &>(device);
223
 
        static_cast<dsp32_config &>(dsp) = config;
224
 
}
225
 
 
226
 
 
227
 
//-------------------------------------------------
228
 
//  device_start - start up the device
229
 
//-------------------------------------------------
230
 
 
231
 
void dsp32c_device::device_start()
232
 
{
233
 
        // get our address spaces
234
 
        m_program = space(AS_PROGRAM);
235
 
        m_direct = &m_program->direct();
236
 
 
237
 
        // register our state for the debugger
238
 
        astring tempstr;
239
 
        state_add(STATE_GENPC,     "GENPC",     m_r[15]).noshow();
240
 
        state_add(STATE_GENPCBASE, "GENPCBASE", m_ppc).noshow();
241
 
        state_add(STATE_GENSP,     "GENSP",     m_r[21]).noshow();
242
 
        state_add(STATE_GENFLAGS,  "GENFLAGS",  m_iotemp).callimport().callexport().formatstr("%6s").noshow();
243
 
        state_add(DSP32_PC,        "PC",        m_r[15]).mask(0xffffff);
244
 
        for (int regnum = 0; regnum <= 14; regnum++)
245
 
                state_add(DSP32_R0 + regnum, tempstr.format("R%d", regnum), m_r[regnum]).mask(0xffffff);
246
 
        state_add(DSP32_R15,       "R15",       m_r[17]).mask(0xffffff);
247
 
        state_add(DSP32_R16,       "R16",       m_r[18]).mask(0xffffff);
248
 
        state_add(DSP32_R17,       "R17",       m_r[19]).mask(0xffffff);
249
 
        state_add(DSP32_R18,       "R18",       m_r[20]).mask(0xffffff);
250
 
        state_add(DSP32_R19,       "R19",       m_r[21]).mask(0xffffff);
251
 
        state_add(DSP32_R20,       "R20",       m_r[24]).mask(0xffffff);
252
 
        state_add(DSP32_R21,       "R21",       m_r[25]).mask(0xffffff);
253
 
        state_add(DSP32_R22,       "R22",       m_r[29]).mask(0xffffff);
254
 
        state_add(DSP32_PIN,       "PIN",       m_pin).mask(0xffffff);
255
 
        state_add(DSP32_POUT,      "POUT",      m_pout).mask(0xffffff);
256
 
        state_add(DSP32_IVTP,      "IVTP",      m_ivtp).mask(0xffffff);
257
 
        state_add(DSP32_A0,        "A0",        m_a[0]).formatstr("%8s");
258
 
        state_add(DSP32_A1,        "A1",        m_a[1]).formatstr("%8s");
259
 
        state_add(DSP32_A2,        "A2",        m_a[2]).formatstr("%8s");
260
 
        state_add(DSP32_A3,        "A3",        m_a[3]).formatstr("%8s");
261
 
        state_add(DSP32_DAUC,      "DAUC",      m_r[26]).mask(0xff);
262
 
        state_add(DSP32_PAR,       "PAR",       m_par);
263
 
        state_add(DSP32_PDR,       "PDR",       m_pdr);
264
 
        state_add(DSP32_PIR,       "PIR",       m_pir);
265
 
        state_add(DSP32_PCR,       "PCR",       m_iotemp).mask(0x3ff).callimport();
266
 
        state_add(DSP32_EMR,       "EMR",       m_emr);
267
 
        state_add(DSP32_ESR,       "ESR",       m_esr);
268
 
        state_add(DSP32_PCW,       "PCW",       m_pcw);
269
 
        state_add(DSP32_PIOP,      "PIOP",      m_piop);
270
 
        state_add(DSP32_IBUF,      "IBUF",      m_ibuf);
271
 
        state_add(DSP32_ISR,       "ISR",       m_isr);
272
 
        state_add(DSP32_OBUF,      "OBUF",      m_obuf);
273
 
        state_add(DSP32_OSR,       "OSR" ,      m_osr);
274
 
        state_add(DSP32_IOC,       "IOC",       m_r[27]).mask(0xfffff);
275
 
 
276
 
        // register our state for saving
277
 
        save_item(NAME(m_r));
278
 
        save_item(NAME(m_pin));
279
 
        save_item(NAME(m_pout));
280
 
        save_item(NAME(m_ivtp));
281
 
        save_item(NAME(m_nzcflags));
282
 
        save_item(NAME(m_vflags));
283
 
        save_item(NAME(m_a));
284
 
        save_item(NAME(m_NZflags));
285
 
        save_item(NAME(m_VUflags));
286
 
        save_item(NAME(m_abuf));
287
 
        save_item(NAME(m_abufreg));
288
 
        save_item(NAME(m_abufVUflags));
289
 
        save_item(NAME(m_abufNZflags));
290
 
        save_item(NAME(m_abufcycle));
291
 
        save_item(NAME(m_abuf_index));
292
 
        save_item(NAME(m_mbufaddr));
293
 
        save_item(NAME(m_mbufdata));
294
 
        save_item(NAME(m_par));
295
 
        save_item(NAME(m_pare));
296
 
        save_item(NAME(m_pdr));
297
 
        save_item(NAME(m_pdr2));
298
 
        save_item(NAME(m_pir));
299
 
        save_item(NAME(m_pcr));
300
 
        save_item(NAME(m_emr));
301
 
        save_item(NAME(m_esr));
302
 
        save_item(NAME(m_pcw));
303
 
        save_item(NAME(m_piop));
304
 
        save_item(NAME(m_ibuf));
305
 
        save_item(NAME(m_isr));
306
 
        save_item(NAME(m_obuf));
307
 
        save_item(NAME(m_osr));
308
 
        save_item(NAME(m_lastpins));
309
 
        save_item(NAME(m_ppc));
310
 
}
311
 
 
312
 
 
313
 
//-------------------------------------------------
314
 
//  device_reset - reset the device
315
 
//-------------------------------------------------
316
 
 
317
 
void dsp32c_device::device_reset()
318
 
{
319
 
        // reset goes to 0
320
 
        PC = 0;
321
 
 
322
 
        // clear some registers
323
 
        m_pcw &= 0x03ff;
324
 
        update_pcr(m_pcr & PCR_RESET);
325
 
        m_esr = 0;
326
 
        m_emr = 0xffff;
327
 
 
328
 
        // initialize fixed registers
329
 
        R0 = R0_ALT = 0;
330
 
        RMM = -1;
331
 
        RPP = 1;
332
 
        A_0 = 0.0;
333
 
        A_1 = 1.0;
334
 
 
335
 
        // init internal stuff
336
 
        m_abufcycle[0] = m_abufcycle[1] = m_abufcycle[2] = m_abufcycle[3] = 12345678;
337
 
        m_mbufaddr[0] = m_mbufaddr[1] = m_mbufaddr[2] = m_mbufaddr[3] = 1;
338
 
}
339
 
 
340
 
 
341
 
//-------------------------------------------------
342
 
//  memory_space_config - return the configuration
343
 
//  of the specified address space, or NULL if
344
 
//  the space doesn't exist
345
 
//-------------------------------------------------
346
 
 
347
 
const address_space_config *dsp32c_device::memory_space_config(address_spacenum spacenum) const
348
 
{
349
 
        return (spacenum == AS_PROGRAM) ? &m_program_config : NULL;
350
 
}
351
 
 
352
 
 
353
 
//-------------------------------------------------
354
 
//  state_import - import state into the device,
355
 
//  after it has been set
356
 
//-------------------------------------------------
357
 
 
358
 
void dsp32c_device::state_import(const device_state_entry &entry)
359
 
{
360
 
        switch (entry.index())
361
 
        {
362
 
                case STATE_GENFLAGS:
363
 
                        break;
364
 
 
365
 
                case DSP32_PCR:
366
 
                        update_pcr(m_iotemp);
367
 
                        break;
368
 
 
369
 
                default:
370
 
                        fatalerror("dsp32c_device::state_import called for unexpected value\n");
371
 
                        break;
372
 
        }
373
 
}
374
 
 
375
 
 
376
 
//-------------------------------------------------
377
 
//  state_export - export state out of the device
378
 
//-------------------------------------------------
379
 
 
380
 
void dsp32c_device::state_export(const device_state_entry &entry)
381
 
{
382
 
        switch (entry.index())
383
 
        {
384
 
                case STATE_GENFLAGS:
385
 
                        // no actual flags register, so just make something up
386
 
                        m_iotemp =      ((zFLAG != 0) << 0) |
387
 
                                                ((nFLAG != 0) << 1) |
388
 
                                                ((cFLAG != 0) << 2) |
389
 
                                                ((vFLAG != 0) << 3) |
390
 
                                                ((ZFLAG != 0) << 4) |
391
 
                                                ((NFLAG != 0) << 5) |
392
 
                                                ((UFLAG != 0) << 6) |
393
 
                                                ((VFLAG != 0) << 7);
394
 
                        break;
395
 
 
396
 
                case DSP32_PCR:
397
 
                        m_iotemp = m_pcr;
398
 
                        break;
399
 
 
400
 
                default:
401
 
                        fatalerror("dsp32c_device::state_export called for unexpected value\n");
402
 
                        break;
403
 
        }
404
 
}
405
 
 
406
 
 
407
 
//-------------------------------------------------
408
 
//  state_string_export - export state as a string
409
 
//  for the debugger
410
 
//-------------------------------------------------
411
 
 
412
 
void dsp32c_device::state_string_export(const device_state_entry &entry, astring &string)
413
 
{
414
 
        switch (entry.index())
415
 
        {
416
 
                case STATE_GENFLAGS:
417
 
                        string.printf("%c%c%c%c%c%c%c%c",
418
 
                                NFLAG ? 'N':'.',
419
 
                                ZFLAG ? 'Z':'.',
420
 
                UFLAG ? 'U':'.',
421
 
                VFLAG ? 'V':'.',
422
 
                nFLAG ? 'n':'.',
423
 
                zFLAG ? 'z':'.',
424
 
                cFLAG ? 'c':'.',
425
 
                vFLAG ? 'v':'.');
426
 
                        break;
427
 
 
428
 
                case DSP32_A0:
429
 
                case DSP32_A1:
430
 
                case DSP32_A2:
431
 
                case DSP32_A3:
432
 
                        string.printf("%8g", *(double *)entry.dataptr());
433
 
                        break;
434
 
        }
435
 
}
436
 
 
437
 
 
438
 
//-------------------------------------------------
439
 
//  disasm_min_opcode_bytes - return the length
440
 
//  of the shortest instruction, in bytes
441
 
//-------------------------------------------------
442
 
 
443
 
UINT32 dsp32c_device::disasm_min_opcode_bytes() const
444
 
{
445
 
        return 4;
446
 
}
447
 
 
448
 
 
449
 
//-------------------------------------------------
450
 
//  disasm_max_opcode_bytes - return the length
451
 
//  of the longest instruction, in bytes
452
 
//-------------------------------------------------
453
 
 
454
 
UINT32 dsp32c_device::disasm_max_opcode_bytes() const
455
 
{
456
 
        return 4;
457
 
}
458
 
 
459
 
 
460
 
//-------------------------------------------------
461
 
//  disasm_disassemble - call the disassembly
462
 
//  helper function
463
 
//-------------------------------------------------
464
 
 
465
 
offs_t dsp32c_device::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options)
466
 
{
467
 
        extern CPU_DISASSEMBLE( dsp32c );
468
 
        return CPU_DISASSEMBLE_NAME(dsp32c)(NULL, buffer, pc, oprom, opram, 0);
469
 
}
470
 
 
471
 
 
472
 
 
473
 
 
474
 
//**************************************************************************
475
 
//  MEMORY ACCESSORS
476
 
//**************************************************************************
477
 
 
478
 
inline UINT32 dsp32c_device::ROPCODE(offs_t pc)
479
 
{
480
 
        return m_direct->read_decrypted_dword(pc);
481
 
}
482
 
 
483
 
inline UINT8 dsp32c_device::RBYTE(offs_t addr)
484
 
{
485
 
        return m_program->read_byte(addr);
486
 
}
487
 
 
488
 
inline void dsp32c_device::WBYTE(offs_t addr, UINT8 data)
489
 
{
490
 
        m_program->write_byte(addr, data);
491
 
}
492
 
 
493
 
inline UINT16 dsp32c_device::RWORD(offs_t addr)
494
 
{
495
 
#if DETECT_MISALIGNED_MEMORY
496
 
        if (addr & 1) fprintf(stderr, "Unaligned word read @ %06X, PC=%06X\n", addr, PC);
497
 
#endif
498
 
        return m_program->read_word(addr);
499
 
}
500
 
 
501
 
inline UINT32 dsp32c_device::RLONG(offs_t addr)
502
 
{
503
 
#if DETECT_MISALIGNED_MEMORY
504
 
        if (addr & 3) fprintf(stderr, "Unaligned long read @ %06X, PC=%06X\n", addr, PC);
505
 
#endif
506
 
        return m_program->read_dword(addr);
507
 
}
508
 
 
509
 
inline void dsp32c_device::WWORD(offs_t addr, UINT16 data)
510
 
{
511
 
#if DETECT_MISALIGNED_MEMORY
512
 
        if (addr & 1) fprintf(stderr, "Unaligned word write @ %06X, PC=%06X\n", addr, PC);
513
 
#endif
514
 
        m_program->write_word(addr, data);
515
 
}
516
 
 
517
 
inline void dsp32c_device::WLONG(offs_t addr, UINT32 data)
518
 
{
519
 
#if DETECT_MISALIGNED_MEMORY
520
 
        if (addr & 3) fprintf(stderr, "Unaligned long write @ %06X, PC=%06X\n", addr, PC);
521
 
#endif
522
 
        m_program->write_dword(addr, data);
523
 
}
524
 
 
525
 
 
526
 
 
527
 
//**************************************************************************
528
 
//  IRQ HANDLING
529
 
//**************************************************************************
530
 
 
531
 
void dsp32c_device::check_irqs()
532
 
{
533
 
        // finish me!
534
 
}
535
 
 
536
 
 
537
 
void dsp32c_device::set_irq_line(int irqline, int state)
538
 
{
539
 
        // finish me!
540
 
}
541
 
 
542
 
 
543
 
 
544
 
//**************************************************************************
545
 
//  REGISTER HANDLING
546
 
//**************************************************************************
547
 
 
548
 
void dsp32c_device::update_pcr(UINT16 newval)
549
 
{
550
 
        UINT16 oldval = m_pcr;
551
 
        m_pcr = newval;
552
 
 
553
 
        // reset the chip if we get a reset
554
 
        if ((oldval & PCR_RESET) == 0 && (newval & PCR_RESET) != 0)
555
 
                reset();
556
 
 
557
 
        // track the state of the output pins
558
 
        if (m_output_pins_changed != NULL)
559
 
        {
560
 
                UINT16 newoutput = ((newval & (PCR_PIFs | PCR_ENI)) == (PCR_PIFs | PCR_ENI)) ? DSP32_OUTPUT_PIF : 0;
561
 
                if (newoutput != m_lastpins)
562
 
                {
563
 
                        m_lastpins = newoutput;
564
 
                        (*m_output_pins_changed)(*this, newoutput);
565
 
                }
566
 
        }
567
 
}
568
 
 
569
 
 
570
 
 
571
 
//**************************************************************************
572
 
//  CORE INCLUDE
573
 
//**************************************************************************
574
 
 
575
 
#include "dsp32ops.c"
576
 
 
577
 
 
578
 
 
579
 
//**************************************************************************
580
 
//  CORE EXECUTION LOOP
581
 
//**************************************************************************
582
 
 
583
 
//-------------------------------------------------
584
 
//  execute_min_cycles - return minimum number of
585
 
//  cycles it takes for one instruction to execute
586
 
//-------------------------------------------------
587
 
 
588
 
UINT32 dsp32c_device::execute_min_cycles() const
589
 
{
590
 
        return 4;
591
 
}
592
 
 
593
 
 
594
 
//-------------------------------------------------
595
 
//  execute_max_cycles - return maximum number of
596
 
//  cycles it takes for one instruction to execute
597
 
//-------------------------------------------------
598
 
 
599
 
UINT32 dsp32c_device::execute_max_cycles() const
600
 
{
601
 
        return 4;
602
 
}
603
 
 
604
 
 
605
 
//-------------------------------------------------
606
 
//  execute_input_lines - return the number of
607
 
//  input/interrupt lines
608
 
//-------------------------------------------------
609
 
 
610
 
UINT32 dsp32c_device::execute_input_lines() const
611
 
{
612
 
        return 2;
613
 
}
614
 
 
615
 
 
616
 
void dsp32c_device::execute_set_input(int inputnum, int state)
617
 
{
618
 
}
619
 
 
620
 
 
621
 
void dsp32c_device::execute_run()
622
 
{
623
 
        // skip if halted
624
 
        if ((m_pcr & PCR_RESET) == 0)
625
 
        {
626
 
                m_icount = 0;
627
 
                return;
628
 
        }
629
 
 
630
 
        // update buffered accumulator values
631
 
        m_abufcycle[0] += m_icount;
632
 
        m_abufcycle[1] += m_icount;
633
 
        m_abufcycle[2] += m_icount;
634
 
        m_abufcycle[3] += m_icount;
635
 
 
636
 
        // handle interrupts
637
 
        check_irqs();
638
 
 
639
 
        while (m_icount > 0)
640
 
                execute_one();
641
 
 
642
 
        // normalize buffered accumulator values
643
 
        m_abufcycle[0] -= m_icount;
644
 
        m_abufcycle[1] -= m_icount;
645
 
        m_abufcycle[2] -= m_icount;
646
 
        m_abufcycle[3] -= m_icount;
647
 
}
648
 
 
649
 
 
650
 
 
651
 
//**************************************************************************
652
 
//  PARALLEL INTERFACE WRITES
653
 
//**************************************************************************
654
 
 
655
 
const UINT32 dsp32c_device::s_regmap[4][16] =
656
 
{
657
 
        {       // DSP32 compatible mode
658
 
                PIO_PAR|LOWER, PIO_PAR|UPPER, PIO_PDR|LOWER, PIO_PDR|UPPER,
659
 
                PIO_EMR|LOWER, PIO_EMR|UPPER, PIO_ESR|LOWER, PIO_PCR|LOWER,
660
 
                PIO_PIR|UPPER, PIO_PIR|UPPER, PIO_PIR|UPPER, PIO_PIR|UPPER,
661
 
                PIO_PIR|UPPER, PIO_PIR|UPPER, PIO_PIR|UPPER, PIO_PIR|UPPER
662
 
        },
663
 
        {       // DSP32C 8-bit mode
664
 
                PIO_PAR|LOWER, PIO_PAR|UPPER, PIO_PDR|LOWER, PIO_PDR|UPPER,
665
 
                PIO_EMR|LOWER, PIO_EMR|UPPER, PIO_ESR|LOWER, PIO_PCR|LOWER,
666
 
                PIO_PIR|LOWER, PIO_PIR|UPPER, PIO_PCR|UPPER, PIO_PARE|LOWER,
667
 
                PIO_PDR2|LOWER,PIO_PDR2|UPPER,PIO_RESERVED,  PIO_RESERVED
668
 
        },
669
 
        {       // DSP32C illegal mode
670
 
                PIO_RESERVED,  PIO_RESERVED,  PIO_RESERVED,  PIO_RESERVED,
671
 
                PIO_RESERVED,  PIO_RESERVED,  PIO_RESERVED,  PIO_RESERVED,
672
 
                PIO_RESERVED,  PIO_RESERVED,  PIO_RESERVED,  PIO_RESERVED,
673
 
                PIO_RESERVED,  PIO_RESERVED,  PIO_RESERVED,  PIO_RESERVED
674
 
        },
675
 
        {       // DSP32C 16-bit mode
676
 
                PIO_PAR,       PIO_RESERVED,  PIO_PDR,       PIO_RESERVED,
677
 
                PIO_EMR,       PIO_RESERVED,  PIO_ESR|LOWER, PIO_PCR,
678
 
                PIO_PIR,       PIO_RESERVED,  PIO_RESERVED,  PIO_PARE|LOWER,
679
 
                PIO_PDR2,      PIO_RESERVED,  PIO_RESERVED,  PIO_RESERVED
680
 
        }
681
 
};
682
 
 
683
 
 
684
 
 
685
 
//**************************************************************************
686
 
//  PARALLEL INTERFACE WRITES
687
 
//**************************************************************************
688
 
 
689
 
void dsp32c_device::dma_increment()
690
 
{
691
 
        if (m_pcr & PCR_AUTO)
692
 
        {
693
 
                int amount = (m_pcr & PCR_DMA32) ? 4 : 2;
694
 
                m_par += amount;
695
 
                if (m_par < amount)
696
 
                        m_pare++;
697
 
        }
698
 
}
699
 
 
700
 
 
701
 
void dsp32c_device::dma_load()
702
 
{
703
 
        // only process if DMA is enabled
704
 
        if (m_pcr & PCR_DMA)
705
 
        {
706
 
                UINT32 addr = m_par | (m_pare << 16);
707
 
 
708
 
                // 16-bit case
709
 
                if (!(m_pcr & PCR_DMA32))
710
 
                        m_pdr = RWORD(addr & 0xfffffe);
711
 
 
712
 
                // 32-bit case
713
 
                else
714
 
                {
715
 
                        UINT32 temp = RLONG(addr & 0xfffffc);
716
 
                        m_pdr = temp >> 16;
717
 
                        m_pdr2 = temp & 0xffff;
718
 
                }
719
 
 
720
 
                // set the PDF flag to indicate we have data ready
721
 
                update_pcr(m_pcr | PCR_PDFs);
722
 
        }
723
 
}
724
 
 
725
 
 
726
 
void dsp32c_device::dma_store()
727
 
{
728
 
        // only process if DMA is enabled
729
 
        if (m_pcr & PCR_DMA)
730
 
        {
731
 
                UINT32 addr = m_par | (m_pare << 16);
732
 
 
733
 
                // 16-bit case
734
 
                if (!(m_pcr & PCR_DMA32))
735
 
                        WWORD(addr & 0xfffffe, m_pdr);
736
 
 
737
 
                // 32-bit case
738
 
                else
739
 
                        WLONG(addr & 0xfffffc, (m_pdr << 16) | m_pdr2);
740
 
 
741
 
                // clear the PDF flag to indicate we have taken the data
742
 
                update_pcr(m_pcr & ~PCR_PDFs);
743
 
        }
744
 
}
745
 
 
746
 
 
747
 
void dsp32c_device::pio_w(int reg, int data)
748
 
{
749
 
        UINT16 mask;
750
 
        UINT8 mode;
751
 
 
752
 
        // look up register and mask
753
 
        mode = ((m_pcr >> 8) & 2) | ((m_pcr >> 1) & 1);
754
 
        reg = s_regmap[mode][reg];
755
 
        mask = reg >> 8;
756
 
        if (mask == 0x00ff) data <<= 8;
757
 
        data &= ~mask;
758
 
        reg &= 0xff;
759
 
 
760
 
        // switch off the register
761
 
        switch (reg)
762
 
        {
763
 
                case PIO_PAR:
764
 
                        m_par = (m_par & mask) | data;
765
 
 
766
 
                        // trigger a load on the upper half
767
 
                        if (!(mask & 0xff00))
768
 
                                dma_load();
769
 
                        break;
770
 
 
771
 
                case PIO_PARE:
772
 
                        m_pare = (m_pare & mask) | data;
773
 
                        break;
774
 
 
775
 
                case PIO_PDR:
776
 
                        m_pdr = (m_pdr & mask) | data;
777
 
 
778
 
                        // trigger a write and PDF setting on the upper half
779
 
                        if (!(mask & 0xff00))
780
 
                        {
781
 
                                dma_store();
782
 
                                dma_increment();
783
 
                        }
784
 
                        break;
785
 
 
786
 
                case PIO_PDR2:
787
 
                        m_pdr2 = (m_pdr2 & mask) | data;
788
 
                        break;
789
 
 
790
 
                case PIO_EMR:
791
 
                        m_emr = (m_emr & mask) | data;
792
 
                        break;
793
 
 
794
 
                case PIO_ESR:
795
 
                        m_esr = (m_esr & mask) | data;
796
 
                        break;
797
 
 
798
 
                case PIO_PCR:
799
 
                        mask |= 0x0060;
800
 
                        data &= ~mask;
801
 
                        update_pcr((m_pcr & mask) | data);
802
 
                        break;
803
 
 
804
 
                case PIO_PIR:
805
 
                        m_pir = (m_pir & mask) | data;
806
 
 
807
 
                        // set PIF on upper half
808
 
                        if (!(mask & 0xff00))
809
 
                                update_pcr(m_pcr | PCR_PIFs);
810
 
                        break;
811
 
 
812
 
                // error case
813
 
                default:
814
 
                        logerror("dsp32_pio_w called on invalid register %d\n", reg);
815
 
                        break;
816
 
        }
817
 
}
818
 
 
819
 
 
820
 
 
821
 
//**************************************************************************
822
 
//  PARALLEL INTERFACE READS
823
 
//**************************************************************************
824
 
 
825
 
int dsp32c_device::pio_r(int reg)
826
 
{
827
 
        UINT16 mask, result = 0xffff;
828
 
        UINT8 mode, shift = 0;
829
 
 
830
 
        // look up register and mask
831
 
        mode = ((m_pcr >> 8) & 2) | ((m_pcr >> 1) & 1);
832
 
        reg = s_regmap[mode][reg];
833
 
        mask = reg >> 8;
834
 
        if (mask == 0x00ff) mask = 0xff00, shift = 8;
835
 
        reg &= 0xff;
836
 
 
837
 
        // switch off the register
838
 
        switch (reg)
839
 
        {
840
 
                case PIO_PAR:
841
 
                        result = m_par | 1;
842
 
                        break;
843
 
 
844
 
                case PIO_PARE:
845
 
                        result = m_pare;
846
 
                        break;
847
 
 
848
 
                case PIO_PDR:
849
 
                        result = m_pdr;
850
 
 
851
 
                        // trigger an increment on the lower half
852
 
                        if (shift != 8)
853
 
                                dma_increment();
854
 
 
855
 
                        // trigger a fetch on the upper half
856
 
                        if (!(mask & 0xff00))
857
 
                                dma_load();
858
 
                        break;
859
 
 
860
 
                case PIO_PDR2:
861
 
                        result = m_pdr2;
862
 
                        break;
863
 
 
864
 
                case PIO_EMR:
865
 
                        result = m_emr;
866
 
                        break;
867
 
 
868
 
                case PIO_ESR:
869
 
                        result = m_esr;
870
 
                        break;
871
 
 
872
 
                case PIO_PCR:
873
 
                        result = m_pcr;
874
 
                        break;
875
 
 
876
 
                case PIO_PIR:
877
 
                        if (!(mask & 0xff00))
878
 
                                update_pcr(m_pcr & ~PCR_PIFs);  // clear PIFs
879
 
                        result = m_pir;
880
 
                        break;
881
 
 
882
 
                // error case
883
 
                default:
884
 
                        logerror("dsp32_pio_w called on invalid register %d\n", reg);
885
 
                        break;
886
 
        }
887
 
 
888
 
        return (result >> shift) & ~mask;
889
 
}