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

« back to all changes in this revision

Viewing changes to mess/src/mame/machine/tx1.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
 
    Tatsumi TX-1/Buggy Boy machine hardware
4
 
 
5
 
***************************************************************************/
6
 
 
7
 
#include "emu.h"
8
 
#include "debugger.h"
9
 
#include "includes/tx1.h"
10
 
 
11
 
 
12
 
/*
13
 
    Helper functions
14
 
*/
15
 
#define INC_PROM_ADDR           ( math.promaddr = (math.promaddr + 1) & 0x1ff )
16
 
#define ROR16(val, shift)       ( ((UINT16)val >> shift) | ((UINT16)val << (16 - shift)) )
17
 
#define ROL16(val, shift)       ( ((UINT16)val << shift) | ((UINT16)val >> (16 - shift)) )
18
 
#define SWAP16(val)                     ( (((UINT16)val << 8) & 0xff00) | ((UINT16)val >> 8) )
19
 
 
20
 
INLINE UINT8 reverse_nibble(UINT8 nibble)
21
 
{
22
 
        return  (nibble & 1) << 3 |
23
 
                        (nibble & 2) << 1 |
24
 
                        (nibble & 4) >> 1 |
25
 
                        (nibble & 8) >> 3;
26
 
}
27
 
 
28
 
 
29
 
/*
30
 
    State transition table
31
 
 
32
 
    A little different to the real thing in that
33
 
    there are no states between final input and
34
 
    multiplication/division.
35
 
*/
36
 
static const UINT8 state_table[16][8] =
37
 
{
38
 
        {  4,  4,  4,  4,  5,  1,  1,  0 },
39
 
        {  4,  4,  4,  4,  5,  5,  3,  0 },
40
 
        { -1, -1, -1, -1, -1, -1, -1, -1 },
41
 
        {  4,  4,  4,  4,  5,  5, 11,  0 },
42
 
        {  8,  8,  8,  8,  8,  8,  8,  8 },
43
 
        { 10, 10, 10, 10, 10, 10, 10, 10 },
44
 
        { -1, -1, -1, -1, -1, -1, -1, -1 },
45
 
        { -1, -1, -1, -1, -1, -1, -1, -1 },
46
 
        {  4,  4,  4,  4,  5,  0,  1,  0 },
47
 
        { -1, -1, -1, -1, -1, -1, -1, -1 },
48
 
        {  4,  4,  4,  4,  4,  5,  1,  0 },
49
 
        {  4,  4,  4,  4,  5,  5,  1,  0 },
50
 
        { -1, -1, -1, -1, -1, -1, -1, -1 },
51
 
        { -1, -1, -1, -1, -1, -1, -1, -1 },
52
 
        { -1, -1, -1, -1, -1, -1, -1, -1 },
53
 
        { -1, -1, -1, -1, -1, -1, -1, -1 },
54
 
};
55
 
 
56
 
static void sn_multiply(running_machine &machine)
57
 
{
58
 
        tx1_state *state = machine.driver_data<tx1_state>();
59
 
        sn74s516_t &SN74S516 = state->m_sn74s516;
60
 
 
61
 
        switch (SN74S516.code)
62
 
        {
63
 
                case 0:
64
 
                {
65
 
                        SN74S516.ZW.ZW32 = SN74S516.X * SN74S516.Y;
66
 
                        break;
67
 
                }
68
 
                case 2:
69
 
                {
70
 
                        SN74S516.ZW.ZW32 += SN74S516.X * SN74S516.Y;
71
 
                        break;
72
 
                }
73
 
                case 3:
74
 
                {
75
 
                        SN74S516.ZW.ZW32 += -SN74S516.X * SN74S516.Y;
76
 
                        break;
77
 
                }
78
 
                case 0x60:
79
 
                {
80
 
                        SN74S516.ZW.ZW32 = SN74S516.X * SN74S516.Y;
81
 
                        break;
82
 
                }
83
 
                case 0x61:
84
 
                {
85
 
                        SN74S516.ZW.ZW32 = -SN74S516.X * SN74S516.Y;
86
 
                        break;
87
 
                }
88
 
                case 0x62:
89
 
                {
90
 
                        SN74S516.ZW.ZW32 += SN74S516.X * SN74S516.Y;
91
 
                        break;
92
 
                }
93
 
                case 0x63:
94
 
                {
95
 
                        SN74S516.ZW.ZW32 += -SN74S516.X * SN74S516.Y;
96
 
                        break;
97
 
                }
98
 
                case 0x660:
99
 
                {
100
 
                        SN74S516.ZW.ZW32 = (SN74S516.X * SN74S516.Y) + (SN74S516.ZW.ZW32 & 0xffff0000);
101
 
                        break;
102
 
                }
103
 
                case 0x661:
104
 
                {
105
 
                        SN74S516.ZW.ZW32 = (-SN74S516.X * SN74S516.Y) + (SN74S516.ZW.ZW32 & 0xffff0000);
106
 
                        break;
107
 
                }
108
 
                case 0x662:
109
 
                {
110
 
                        SN74S516.ZW.ZW32 = (-SN74S516.X * SN74S516.Y) + (SN74S516.ZW.ZW32 & 0xffff0000);
111
 
                        break;
112
 
                }
113
 
                case 0x6660:
114
 
                {
115
 
                        SN74S516.ZW.ZW32 += (SN74S516.X * SN74S516.Y);
116
 
                        break;
117
 
                }
118
 
                default:
119
 
                {
120
 
                        mame_printf_debug("sn74s516 ??? multiply: %x\n", SN74S516.code);
121
 
                }
122
 
        }
123
 
 
124
 
        /* Seems a good enough place to clear it. */
125
 
        SN74S516.ZWfl = 0;
126
 
}
127
 
 
128
 
static void sn_divide(running_machine &machine)
129
 
{
130
 
        tx1_state *state = machine.driver_data<tx1_state>();
131
 
        sn74s516_t &SN74S516 = state->m_sn74s516;
132
 
        INT32 Z = 0;
133
 
        INT32 W = 0;
134
 
 
135
 
        if (SN74S516.X == 0)
136
 
        {
137
 
                mame_printf_debug("%s:SN74S516 tried to divide by zero\n", machine.describe_context());
138
 
                SN74S516.ZW.Z = (INT16)0xffff;
139
 
                SN74S516.ZW.W = 0xffff;
140
 
                SN74S516.ZWfl = 0;
141
 
                return;
142
 
        }
143
 
 
144
 
        switch (SN74S516.code)
145
 
        {
146
 
                case 4:
147
 
                {
148
 
                        Z = SN74S516.ZW.ZW32 / SN74S516.X;
149
 
                        W = SN74S516.ZW.ZW32 % SN74S516.X;
150
 
                        break;
151
 
                }
152
 
                case 0x664:
153
 
                {
154
 
                        Z = SN74S516.ZW.ZW32 / SN74S516.X;
155
 
                        W = SN74S516.ZW.ZW32 % SN74S516.X;
156
 
                        break;
157
 
                }
158
 
                case 0x6664:
159
 
                {
160
 
                        Z = SN74S516.ZW.W / SN74S516.X;
161
 
                        W = SN74S516.ZW.W % SN74S516.X;
162
 
                        break;
163
 
                }
164
 
                default:
165
 
                {
166
 
                        mame_printf_debug("SN74S516 unhandled divide type: %x\n", SN74S516.code);
167
 
                }
168
 
        }
169
 
 
170
 
        /* Divide overflow Only happens during chip test anyway */
171
 
        if (Z > 0xffff)
172
 
                Z |= 0xff00;
173
 
 
174
 
        SN74S516.ZW.Z = Z;
175
 
        SN74S516.ZW.W = W;
176
 
        SN74S516.ZWfl = 0;
177
 
}
178
 
 
179
 
static void sn74s516_update(running_machine &machine, int ins)
180
 
{
181
 
        tx1_state *state = machine.driver_data<tx1_state>();
182
 
        sn74s516_t &SN74S516 = state->m_sn74s516;
183
 
        SN74S516.state = state_table[SN74S516.state][ins];
184
 
 
185
 
        if (SN74S516.state == 4)
186
 
        {
187
 
                sn_multiply(machine);
188
 
                SN74S516.state = 8;
189
 
        }
190
 
        else if (SN74S516.state == 5)
191
 
        {
192
 
                sn_divide(machine);
193
 
                SN74S516.state = 10;
194
 
        }
195
 
}
196
 
 
197
 
static void kick_sn74s516(running_machine &machine, UINT16 *data, const int ins)
198
 
{
199
 
        tx1_state *state = machine.driver_data<tx1_state>();
200
 
        sn74s516_t &SN74S516 = state->m_sn74s516;
201
 
        math_t &math = state->m_math;
202
 
 
203
 
#define LOAD_X          (SN74S516.X = *data)
204
 
#define LOAD_Y          (SN74S516.Y = *data)
205
 
#define LOAD_Z          (SN74S516.ZW.Z = *data)
206
 
#define LOAD_W          (SN74S516.ZW.W = *data)
207
 
#define READ_ZW         *data = SN74S516.ZWfl ? SN74S516.ZW.W : SN74S516.ZW.Z; \
208
 
                                        SN74S516.ZWfl ^= 1;
209
 
 
210
 
#define UPDATE_SEQUENCE (SN74S516.code = (SN74S516.code << 4) | ins)
211
 
#define CLEAR_SEQUENCE  (SN74S516.code = 0)
212
 
 
213
 
        /*
214
 
        Remember to change the Z/W flag.
215
 
    */
216
 
        switch (SN74S516.state)
217
 
        {
218
 
                case 0:
219
 
                {
220
 
                        CLEAR_SEQUENCE;
221
 
                        UPDATE_SEQUENCE;
222
 
 
223
 
                        if (ins < 4)
224
 
                        {
225
 
                                LOAD_Y;
226
 
                                sn74s516_update(machine, ins);
227
 
                        }
228
 
                        else if (ins == 4)
229
 
                        {
230
 
                                sn74s516_update(machine, ins);
231
 
                        }
232
 
                        else if (ins < 7)
233
 
                        {
234
 
                                LOAD_X;
235
 
                                sn74s516_update(machine, ins);
236
 
                        }
237
 
                        else if (ins == 7)
238
 
                        {
239
 
                                READ_ZW;
240
 
                                break;
241
 
                        }
242
 
 
243
 
                        break;
244
 
                }
245
 
                case 8:
246
 
                case 10:
247
 
                {
248
 
                        CLEAR_SEQUENCE;
249
 
                        UPDATE_SEQUENCE;
250
 
 
251
 
                        if (ins < 4)
252
 
                        {
253
 
                                LOAD_Y;
254
 
                                sn74s516_update(machine, ins);
255
 
                        }
256
 
                        else if (ins == 4)
257
 
                        {
258
 
                                sn74s516_update(machine, ins);
259
 
                        }
260
 
                        else if (ins == 5)
261
 
                        {
262
 
                                // Rounding
263
 
                                // Operation
264
 
                                sn74s516_update(machine, ins);
265
 
                        }
266
 
                        else if (ins == 6)
267
 
                        {
268
 
                                LOAD_X;
269
 
                                sn74s516_update(machine, ins);
270
 
                        }
271
 
                        else if (ins == 7)
272
 
                        {
273
 
                                READ_ZW;
274
 
                                sn74s516_update(machine, ins);
275
 
                        }
276
 
                        break;
277
 
                }
278
 
                case 1:
279
 
                {
280
 
                        // TODO: 6666 represents an incomplete state - clear it.
281
 
                        if (SN74S516.code == 0x6666)
282
 
                        {
283
 
                                CLEAR_SEQUENCE;
284
 
                                mame_printf_debug("%s:Code 6666: PROMADDR:%x\n", machine.describe_context(), math.promaddr);
285
 
                        }
286
 
 
287
 
                        UPDATE_SEQUENCE;
288
 
                        if (ins < 4)
289
 
                        {
290
 
                                LOAD_Y;
291
 
                                sn74s516_update(machine, ins);
292
 
                        }
293
 
                        else if (ins < 6)
294
 
                        {
295
 
                                sn74s516_update(machine, ins);
296
 
                        }
297
 
                        else if (ins == 6)
298
 
                        {
299
 
                                LOAD_Z;
300
 
                                sn74s516_update(machine, ins);
301
 
                        }
302
 
                        else if (ins == 7)
303
 
                        {
304
 
                                // Pointless operation.
305
 
                                sn74s516_update(machine, ins);
306
 
                        }
307
 
 
308
 
                        break;
309
 
                }
310
 
                case 3:
311
 
                {
312
 
                        UPDATE_SEQUENCE;
313
 
                        if (ins < 4)
314
 
                        {
315
 
                                LOAD_Y;
316
 
                                sn74s516_update(machine, ins);
317
 
                        }
318
 
                        else if (ins == 4)
319
 
                        {
320
 
                                LOAD_W;
321
 
                                sn74s516_update(machine, ins);
322
 
                        }
323
 
                        else if (ins == 5)
324
 
                        {
325
 
                                sn74s516_update(machine, ins);
326
 
                        }
327
 
                        else if (ins == 6)
328
 
                        {
329
 
                                LOAD_W;
330
 
                                sn74s516_update(machine, ins);
331
 
                        }
332
 
                        else if (ins == 7)
333
 
                        {
334
 
                                READ_ZW;
335
 
                                sn74s516_update(machine, ins);
336
 
                        }
337
 
                        break;
338
 
                }
339
 
                case 11:
340
 
                {
341
 
                        UPDATE_SEQUENCE;
342
 
                        if (ins < 4)
343
 
                        {
344
 
                                LOAD_Y;
345
 
                                sn74s516_update(machine, ins);
346
 
                        }
347
 
                        else if (ins < 6)
348
 
                        {
349
 
                                sn74s516_update(machine, ins);
350
 
                        }
351
 
                        else if (ins == 6)
352
 
                        {
353
 
                                // CHECK: Incomplete state
354
 
                                sn74s516_update(machine, ins);
355
 
                        }
356
 
                        else if (ins == 7)
357
 
                        {
358
 
                                /* 6667 = Load X, Load Z, Load W, Clear Z */
359
 
                                SN74S516.ZW.Z = 0;
360
 
                                sn74s516_update(machine, ins);
361
 
                        }
362
 
                        break;
363
 
                }
364
 
                default:
365
 
                {
366
 
                        mame_printf_debug("Unknown SN74S516 state. %x\n", SN74S516.code);
367
 
                }
368
 
        }
369
 
 
370
 
        math.dbgaddr = math.promaddr;
371
 
        math.dbgpc = cpu_get_previouspc(machine.device("math_cpu"));
372
 
}
373
 
 
374
 
 
375
 
/***************************************************************************
376
 
 
377
 
  TX-1
378
 
 
379
 
  Preliminary
380
 
 
381
 
***************************************************************************/
382
 
 
383
 
/* Same mapping as Buggy Boy actually */
384
 
#define TX1_INSLD               0x100
385
 
#define TX1_CNTST               0x80
386
 
#define TX1_RADCHG              0x20
387
 
#define TX1_DSEL                0x03
388
 
 
389
 
enum
390
 
{
391
 
        TX1_SEL_MULEN = 0x00,
392
 
        TX1_SEL_PPSEN,
393
 
        TX1_SEL_PSSEN,
394
 
        TX1_SEL_LMSEL,
395
 
        TX1_SEL_DSELOE,
396
 
        TX1_SEL_INSCL = 0x06,
397
 
        TX1_SEL_ILDEN
398
 
};
399
 
 
400
 
#define TX1_SET_INS0_BIT        do { if (!(ins & 0x4) && math.i0ff) ins |= math.i0ff; } while(0)
401
 
 
402
 
INLINE UINT16 get_tx1_datarom_addr(math_t &math)
403
 
{
404
 
        UINT16 addr;
405
 
 
406
 
        addr = ((math.inslatch & 0x1c00) << 1) | (math.ppshift & 0xff);
407
 
 
408
 
        if ((math.inslatch >> 8) & TX1_RADCHG)
409
 
                addr |= (math.ppshift & 0x0700);
410
 
        else
411
 
                addr |= (math.promaddr << 3) & 0x0700;
412
 
 
413
 
        return addr & 0x3fff;
414
 
}
415
 
 
416
 
static void tx1_update_state(running_machine &machine)
417
 
{
418
 
#define LHIEN(a)        !(a & 0x80)
419
 
#define LLOEN(a)        !(a & 0x40)
420
 
#define GO_EN(a)        !(a & 0x4000)
421
 
 
422
 
        tx1_state *state = machine.driver_data<tx1_state>();
423
 
        math_t &math = state->m_math;
424
 
        const UINT16 *prom = (UINT16*)machine.region("au_data")->base() + (0x8000 >> 1);
425
 
 
426
 
        for (;;)
427
 
        {
428
 
                int go = 0;
429
 
 
430
 
                if (!GO_EN(math.inslatch) && GO_EN(prom[math.promaddr]))
431
 
                        go = 1;
432
 
                /*
433
 
            Example:
434
 
            120 /GO /LHIEN
435
 
            121 /GO        /LLOEN
436
 
            Both 120 and 121 are used.
437
 
        */
438
 
                else if ((GO_EN(math.inslatch) && GO_EN(prom[math.promaddr])) && (LHIEN(math.inslatch) && LLOEN(prom[math.promaddr])))
439
 
                        go = 1;
440
 
 
441
 
                /* Now update the latch */
442
 
                math.inslatch = prom[math.promaddr] & 0x7fff;
443
 
                math.mux = (math.inslatch >> 3) & 7;
444
 
 
445
 
                if (math.mux == TX1_SEL_INSCL)
446
 
                {
447
 
                        math.i0ff = 0;
448
 
                }
449
 
                else if (math.mux == TX1_SEL_PPSEN)
450
 
                {
451
 
                        // NOTE: Doesn't do anything without SPCS.
452
 
                }
453
 
 
454
 
                /* TODO */
455
 
                if (go)
456
 
                {
457
 
                        int ins = math.inslatch & 7;
458
 
 
459
 
                        TX1_SET_INS0_BIT;
460
 
 
461
 
                        if (math.mux == TX1_SEL_DSELOE)
462
 
                        {
463
 
                                int             dsel = (math.inslatch >> 8) & TX1_DSEL;
464
 
                                int             tfad = (math.inslatch & 0x1c00) << 1;
465
 
                                int             sd   = math.ppshift;
466
 
                                int             o4;
467
 
                                UINT16  data;
468
 
 
469
 
                                o4 =
470
 
                                        (!BIT(sd, 9) && !BIT(sd,10)) ||
471
 
                                        ( BIT(sd, 7) &&  BIT(sd,10)) ||
472
 
                                        (!BIT(sd, 8) &&  BIT(sd, 9)) ||
473
 
                                        (!BIT(sd, 7) &&  BIT(sd, 8)) ||
474
 
                                        !BIT(dsel, 1) || BIT(tfad, 13) || BIT(tfad, 12) || BIT(tfad, 11);
475
 
 
476
 
                                dsel = (dsel & 2) | ((dsel & o4) ^ 1);
477
 
 
478
 
                                if (dsel == 0)
479
 
                                        data = math.muxlatch;
480
 
                                else if (dsel == 1)
481
 
                                {
482
 
                                        UINT16 *romdata = (UINT16*)machine.region("au_data")->base();
483
 
                                        UINT16 addr = get_tx1_datarom_addr(math);
484
 
                                        data = romdata[addr];
485
 
                                }
486
 
                                else if (dsel == 2)
487
 
                                        data = ROL16(math.muxlatch, 4);
488
 
                                else if (dsel == 3)
489
 
                                        data = ROL16(SWAP16(math.muxlatch), 3);
490
 
 
491
 
                                kick_sn74s516(machine, &data, ins);
492
 
                        }
493
 
                        /*
494
 
                TODO: Changed ppshift to muxlatch for TX-1
495
 
 
496
 
                /TMPLD1: /LHIEN
497
 
                /TMPLD2: /LLOEN.!O4 + (/LHIEN.O4)
498
 
                /TMPLD3: /LLOEN
499
 
                     O4: !SD9.!SD10./LMSEL + SD7.SD10./LMSEL +
500
 
                         !SD8.SD9./LMSEL + !SD7.SD8./LMSEL +
501
 
                         /LMSEL./DSEL1 + /LMSEL.TFAD13 + /LMSEL.TFAD12 + /LMSEL.TFAD11
502
 
            */
503
 
                        else if (LHIEN(math.inslatch) || LLOEN(math.inslatch))
504
 
                        {
505
 
                                UINT16 data;
506
 
 
507
 
                                kick_sn74s516(machine, &data, ins);
508
 
 
509
 
                                /* All latches enabled */
510
 
                                if (LHIEN(math.inslatch) && LLOEN(math.inslatch))
511
 
                                {
512
 
                                        math.muxlatch = data;
513
 
                                }
514
 
                                else if (math.mux == TX1_SEL_LMSEL) // O4 = 0
515
 
                                {
516
 
                                        // TMPLD2/TMPLD3 15-5
517
 
                                        if (LLOEN(math.inslatch))
518
 
                                        {
519
 
                                                math.muxlatch &= 0x001f;
520
 
                                                math.muxlatch |= data & 0xffe0;
521
 
                                        }
522
 
                                        // TMLPD1 4-0???????
523
 
                                        else if (LHIEN(math.inslatch))
524
 
                                        {
525
 
                                                math.muxlatch &= 0xffe0;
526
 
                                                math.muxlatch |= data & 0x001f;
527
 
                                        }
528
 
                                }
529
 
                                else
530
 
                                {
531
 
                                        /*
532
 
                        /TMPLD1: /LHIEN
533
 
                        /TMPLD2: /LLOEN.!O4 + /LHIEN.O4
534
 
                        /TMPLD3: /LLOEN
535
 
                         O4: !SD9.!SD10./LMSEL + SD7.SD10./LMSEL +
536
 
                             !SD8.SD9./LMSEL + !SD7.SD8./LMSEL +
537
 
                             /LMSEL./DSEL1 + /LMSEL.TFAD13 + /LMSEL.TFAD12 + /LMSEL.TFAD11
538
 
                    */
539
 
                                        int             dsel = (math.inslatch >> 8) & TX1_DSEL;
540
 
                                        int             tfad = (math.inslatch & 0x1c00) << 1;
541
 
                                        int             sd   = math.ppshift;
542
 
                                        int             o4;
543
 
 
544
 
                                        o4 =
545
 
                                                (!BIT(sd, 9) && !BIT(sd,10)) ||
546
 
                                                ( BIT(sd, 7) &&  BIT(sd,10)) ||
547
 
                                                (!BIT(sd, 8) &&  BIT(sd, 9)) ||
548
 
                                                (!BIT(sd, 7) &&  BIT(sd, 8)) ||
549
 
                                                !BIT(dsel, 1) || BIT(tfad, 13) || BIT(tfad, 12) || BIT(tfad, 11);
550
 
 
551
 
                                        if (LLOEN(math.inslatch))
552
 
                                        {
553
 
                                                math.muxlatch &= 0x0fff;
554
 
                                                math.muxlatch |= data & 0xf000;
555
 
 
556
 
                                                if (!o4)
557
 
                                                {
558
 
                                                        // TMPLD11-5
559
 
                                                        math.muxlatch &= 0xf01f;
560
 
                                                        math.muxlatch |= data & 0x0fe0;
561
 
                                                }
562
 
                                        }
563
 
                                        else if (LHIEN(math.inslatch))
564
 
                                        {
565
 
                                                math.muxlatch &= 0xffe0;
566
 
                                                math.muxlatch |= data & 0x001f;
567
 
 
568
 
                                                if (o4)
569
 
                                                {
570
 
                                                        // TMPLD11-5
571
 
                                                        math.muxlatch &= 0xf01f;
572
 
                                                        math.muxlatch |= data & 0x0fe0;
573
 
                                                }
574
 
                                        }
575
 
                                }
576
 
                        }
577
 
                        else
578
 
                        {
579
 
                                if (math.mux == TX1_SEL_PPSEN)
580
 
                                {
581
 
                                        kick_sn74s516(machine, &math.ppshift, ins);
582
 
                                }
583
 
                                else
584
 
                                {
585
 
                                        /* Bus pullups give 0xffff */
586
 
                                        UINT16 data = 0xffff;
587
 
                                        kick_sn74s516(machine, &data, ins);
588
 
                                }
589
 
                        }
590
 
                }
591
 
 
592
 
                /* Is there another instruction in the sequence? */
593
 
                if (prom[math.promaddr] & 0x8000)
594
 
                        break;
595
 
                else
596
 
                        INC_PROM_ADDR;
597
 
        }
598
 
}
599
 
 
600
 
READ16_HANDLER( tx1_math_r )
601
 
{
602
 
        tx1_state *state = space->machine().driver_data<tx1_state>();
603
 
        math_t &math = state->m_math;
604
 
        offset = offset << 1;
605
 
 
606
 
        /* /MLPCS */
607
 
        if (offset < 0x400)
608
 
        {
609
 
                int ins;
610
 
 
611
 
                if (offset & 0x200)
612
 
                {
613
 
                        ins = math.inslatch & 7;
614
 
                        TX1_SET_INS0_BIT;
615
 
                }
616
 
                else
617
 
                {
618
 
                        ins = (offset >> 1) & 7;
619
 
                }
620
 
 
621
 
                /* TODO What do we return? */
622
 
                kick_sn74s516(space->machine(), &math.retval, ins);
623
 
        }
624
 
        /* /PPSEN */
625
 
        else if (offset < 0x800)
626
 
        {
627
 
                // Unused - just pullups?
628
 
                math.retval = 0xffff;
629
 
        }
630
 
        /* /MUXCS */
631
 
        else if ((offset & 0xc00) == 0xc00)
632
 
        {
633
 
                int             dsel = (math.inslatch >> 8) & TX1_DSEL;
634
 
                int             tfad = (math.inslatch & 0x1c00) << 1;
635
 
                int             sd   = math.ppshift;
636
 
                int             o4;
637
 
 
638
 
                if (math.mux == TX1_SEL_LMSEL)
639
 
                        o4 = 0;
640
 
                else
641
 
                {
642
 
                        o4 =
643
 
                        (!BIT(sd, 9) && !BIT(sd,10)) ||
644
 
                        ( BIT(sd, 7) &&  BIT(sd,10)) ||
645
 
                        (!BIT(sd, 8) &&  BIT(sd, 9)) ||
646
 
                        (!BIT(sd, 7) &&  BIT(sd, 8)) ||
647
 
                        !BIT(dsel, 1) || BIT(tfad, 13) || BIT(tfad, 12) || BIT(tfad, 11);
648
 
                }
649
 
 
650
 
                dsel = (dsel & 2) | ((dsel & o4) ^ 1);
651
 
 
652
 
                if (dsel == 0)
653
 
                        math.retval = math.muxlatch;
654
 
                else if (dsel == 1 )
655
 
                {
656
 
                        /*
657
 
                TODO make this constant somewhere
658
 
                e.g. math.retval =  math.romptr[ get_tx1_datarom_addr() ];
659
 
            */
660
 
                        UINT16 *romdata = (UINT16*)space->machine().region("au_data")->base();
661
 
                        UINT16 addr = get_tx1_datarom_addr(math);
662
 
                        math.retval = romdata[addr];
663
 
                }
664
 
                else if (dsel == 2)
665
 
                        math.retval = ROL16(math.muxlatch, 4);
666
 
                else if (dsel == 3)
667
 
                        math.retval = ROL16(SWAP16(math.muxlatch), 3);
668
 
 
669
 
                /* TODO for TX-1: This is /SPCS region? */
670
 
                if (offset < 0xe00)
671
 
                {
672
 
                        // Load the PP with retval??????
673
 
                        if (math.mux == TX1_SEL_PPSEN)
674
 
                        {
675
 
                                math.ppshift = math.retval & 0x3fff;
676
 
                        }
677
 
                        else if (math.mux == TX1_SEL_PSSEN)
678
 
                        {
679
 
                                // WRONG!!!!
680
 
                                mame_printf_debug("Math Read with PSSEN!\n");
681
 
                                math.ppshift = math.retval;
682
 
                        }
683
 
 
684
 
                        if (math.mux != TX1_SEL_ILDEN)
685
 
                        {
686
 
                                INC_PROM_ADDR;
687
 
                                tx1_update_state(space->machine());
688
 
 
689
 
                                // MUST RETURN HERE?
690
 
                                return math.retval;
691
 
                        }
692
 
                }
693
 
        }
694
 
        else
695
 
        {
696
 
                if (math.mux == TX1_SEL_PPSEN)
697
 
                        math.retval = math.ppshift & 0x3fff;
698
 
                else
699
 
                        /* Nothing is mapped - read from pull up resistors! */
700
 
                        math.retval = 0xffff;
701
 
        }
702
 
 
703
 
        if (offset & TX1_INSLD)
704
 
        {
705
 
                math.promaddr = (offset << 2) & 0x1ff;
706
 
                tx1_update_state(space->machine());
707
 
        }
708
 
        else if (offset & TX1_CNTST)
709
 
        {
710
 
                INC_PROM_ADDR;
711
 
                tx1_update_state(space->machine());
712
 
        }
713
 
 
714
 
        return math.retval;
715
 
}
716
 
 
717
 
WRITE16_HANDLER( tx1_math_w )
718
 
{
719
 
        tx1_state *state = space->machine().driver_data<tx1_state>();
720
 
        math_t &math = state->m_math;
721
 
        math.cpulatch = data;
722
 
        offset <<= 1;
723
 
 
724
 
//  printf("W %x: %x\n", 0x3000 + offset, data);
725
 
 
726
 
        /* /MLPCS */
727
 
        if (offset < 0x400)
728
 
        {
729
 
                int ins;
730
 
 
731
 
                if (offset & 0x200)
732
 
                {
733
 
                        ins = math.inslatch & 7;
734
 
                        TX1_SET_INS0_BIT;
735
 
                }
736
 
                else
737
 
                {
738
 
                        ins = (offset >> 1) & 7;
739
 
                }
740
 
 
741
 
                kick_sn74s516(space->machine(), &math.cpulatch, ins);
742
 
        }
743
 
        /* /PPSEN */
744
 
        else if ((offset & 0xc00) == 0x400)
745
 
        {
746
 
                /* Input is 14 bits */
747
 
                math.ppshift = math.cpulatch & 0x3fff;
748
 
        }
749
 
        /* /PSSEN */
750
 
        else if ((offset & 0xc00) == 0x800)
751
 
        {
752
 
                //if (((math.inslatch >> 8) & TX1_DSEL) == 3 )
753
 
                {
754
 
                        int shift;
755
 
                        UINT16 val = math.ppshift;
756
 
 
757
 
                        if (math.cpulatch & 0x3800)
758
 
                        {
759
 
                                shift = (math.cpulatch >> 11) & 0x7;
760
 
 
761
 
                                while (shift)
762
 
                                {
763
 
                                        val >>= 1;
764
 
                                        shift >>= 1;
765
 
                                }
766
 
                        }
767
 
                        else
768
 
                        {
769
 
                                shift = (math.cpulatch >> 7) & 0xf;
770
 
                                shift = reverse_nibble(shift);
771
 
                                shift >>= 1;
772
 
 
773
 
                                while (shift)
774
 
                                {
775
 
                                        val <<= 1;
776
 
                                        shift >>= 1;
777
 
                                }
778
 
                        }
779
 
                        math.ppshift = val;
780
 
                }
781
 
        }
782
 
        /* /MUXCS */
783
 
        else if ((offset & 0xc00) == 0xc00)
784
 
        {
785
 
 
786
 
                /*
787
 
            /TMPLD1: 0
788
 
            /TMPLD2: 0
789
 
            /TMPLD3: 0
790
 
        */
791
 
                math.muxlatch = math.cpulatch;
792
 
        }
793
 
 
794
 
        if (offset & TX1_INSLD)
795
 
        {
796
 
                math.promaddr = (offset << 2) & 0x1ff;
797
 
                tx1_update_state(space->machine());
798
 
        }
799
 
        else if (offset & TX1_CNTST)
800
 
        {
801
 
                INC_PROM_ADDR;
802
 
                tx1_update_state(space->machine());
803
 
        }
804
 
}
805
 
 
806
 
READ16_HANDLER( tx1_spcs_rom_r )
807
 
{
808
 
        tx1_state *state = space->machine().driver_data<tx1_state>();
809
 
        math_t &math = state->m_math;
810
 
        math.cpulatch = *(UINT16*)((UINT8*)space->machine().region("math_cpu")->base() + 0xfc000 + 0x1000 + offset*2);
811
 
 
812
 
        if (math.mux == TX1_SEL_ILDEN)
813
 
        {
814
 
                math.i0ff = math.cpulatch & (1 << 14) ? 1 : 0;
815
 
        }
816
 
        else if (math.mux == TX1_SEL_MULEN)
817
 
        {
818
 
                int ins = math.inslatch & 7;
819
 
 
820
 
                TX1_SET_INS0_BIT;
821
 
                kick_sn74s516(space->machine(), &math.cpulatch, ins);
822
 
        }
823
 
        else if (math.mux == TX1_SEL_PPSEN)
824
 
        {
825
 
                math.ppshift = math.cpulatch;
826
 
        }
827
 
        else if (math.mux == TX1_SEL_PSSEN)
828
 
        {
829
 
                        //if ( ((math.inslatch >> 8) & TX1_DSEL) == 3 )
830
 
                {
831
 
                        int shift;
832
 
                        UINT16 val = math.ppshift;
833
 
 
834
 
                        if (math.cpulatch & 0x3800)
835
 
                        {
836
 
                                shift = (math.cpulatch >> 11) & 0x7;
837
 
 
838
 
                                while (shift)
839
 
                                {
840
 
                                        val >>= 1;
841
 
                                        shift >>= 1;
842
 
                                }
843
 
                        }
844
 
                        else
845
 
                        {
846
 
                                shift = (math.cpulatch >> 7) & 0xf;
847
 
                                shift = reverse_nibble(shift);
848
 
                                shift >>= 1;
849
 
 
850
 
                                while (shift)
851
 
                                {
852
 
                                        val <<= 1;
853
 
                                        shift >>= 1;
854
 
                                }
855
 
                        }
856
 
                        math.ppshift = val & 0x7ff;
857
 
                }
858
 
        }
859
 
 
860
 
        if (math.mux != TX1_SEL_ILDEN)
861
 
        {
862
 
                INC_PROM_ADDR;
863
 
                tx1_update_state(space->machine());
864
 
        }
865
 
 
866
 
        return math.cpulatch;
867
 
 
868
 
}
869
 
 
870
 
READ16_HANDLER( tx1_spcs_ram_r )
871
 
{
872
 
        tx1_state *state = space->machine().driver_data<tx1_state>();
873
 
        math_t &math = state->m_math;
874
 
        math.cpulatch = state->m_math_ram[offset];
875
 
 
876
 
        offset <<= 1;
877
 
 
878
 
        if (math.mux == TX1_SEL_ILDEN)
879
 
        {
880
 
                math.i0ff = math.cpulatch & (1 << 14) ? 1 : 0;
881
 
        }
882
 
        else if (math.mux == TX1_SEL_MULEN)
883
 
        {
884
 
                int ins = math.inslatch & 7;
885
 
 
886
 
                TX1_SET_INS0_BIT;
887
 
                kick_sn74s516(space->machine(), &math.cpulatch, ins);
888
 
        }
889
 
        else if (math.mux == TX1_SEL_PPSEN)
890
 
        {
891
 
//      math.ppshift = math.retval & 0x3fff;
892
 
                math.ppshift = math.cpulatch;
893
 
        }
894
 
        else if (math.mux == TX1_SEL_PSSEN)
895
 
        {
896
 
                int shift;
897
 
                UINT16 val = math.ppshift;
898
 
 
899
 
                if (math.cpulatch & 0x3800)
900
 
                {
901
 
                        shift = (math.cpulatch >> 11) & 0x7;
902
 
 
903
 
                        while (shift)
904
 
                        {
905
 
                                val >>= 1;
906
 
                                shift >>= 1;
907
 
                        }
908
 
                }
909
 
                else
910
 
                {
911
 
                        shift = (math.cpulatch >> 7) & 0xf;
912
 
                        shift = reverse_nibble(shift);
913
 
                        shift >>= 1;
914
 
 
915
 
                        while (shift)
916
 
                        {
917
 
                                val <<= 1;
918
 
                                shift >>= 1;
919
 
                        }
920
 
                }
921
 
                math.ppshift = val & 0x7ff;
922
 
        }
923
 
 
924
 
        if (math.mux != TX1_SEL_ILDEN)
925
 
        {
926
 
                INC_PROM_ADDR;
927
 
                tx1_update_state(space->machine());
928
 
        }
929
 
 
930
 
        return math.cpulatch;
931
 
}
932
 
 
933
 
/* Should never occur */
934
 
WRITE16_HANDLER( tx1_spcs_ram_w )
935
 
{
936
 
        tx1_state *state = space->machine().driver_data<tx1_state>();
937
 
        mame_printf_debug("Write to /SPCS RAM?");
938
 
        COMBINE_DATA(&state->m_math_ram[offset]);
939
 
}
940
 
 
941
 
 
942
 
/***************************************************************************
943
 
 
944
 
  Buggy Boy
945
 
 
946
 
***************************************************************************/
947
 
#define BB_INSLD                0x100
948
 
#define BB_CNTST                0x80
949
 
#define BB_RADCHG               0x20
950
 
#define BB_DSEL                 0x03
951
 
 
952
 
enum
953
 
{
954
 
        BB_MUX_MULEN = 0x00,
955
 
        BB_MUX_PPSEN,
956
 
        BB_MUX_PSSEN,
957
 
        BB_MUX_LMSEL,
958
 
        BB_MUX_DPROE,
959
 
        BB_MUX_PPOE,
960
 
        BB_MUX_INSCL,
961
 
        BB_MUX_ILDEN,
962
 
};
963
 
 
964
 
#define BB_SET_INS0_BIT do { if (!(ins & 0x4) && math.i0ff) ins |= math.i0ff;} while(0)
965
 
 
966
 
INLINE UINT16 get_bb_datarom_addr(math_t &math)
967
 
{
968
 
        UINT16 addr;
969
 
 
970
 
        addr = ((math.inslatch & 0x1c00) << 1) | (math.ppshift & 0xff);
971
 
 
972
 
        if ((math.inslatch >> 8) & BB_RADCHG)
973
 
        {
974
 
                addr |= (math.ppshift & 0x0700);
975
 
        }
976
 
        else
977
 
        {
978
 
                addr |= (math.promaddr << 3) & 0x0700;
979
 
        }
980
 
 
981
 
        return addr & 0x3fff;
982
 
}
983
 
 
984
 
static void buggyboy_update_state(running_machine &machine)
985
 
{
986
 
#define LHIEN(a)        !(a & 0x80)
987
 
#define LLOEN(a)        !(a & 0x40)
988
 
#define GO_EN(a)        !(a & 0x4000)
989
 
 
990
 
        tx1_state *state = machine.driver_data<tx1_state>();
991
 
        math_t &math = state->m_math;
992
 
        const UINT16 *prom = (UINT16*)machine.region("au_data")->base() + (0x8000 >> 1);
993
 
 
994
 
        for (;;)
995
 
        {
996
 
                int go = 0;
997
 
 
998
 
                if (!GO_EN(math.inslatch) && GO_EN(prom[math.promaddr]))
999
 
                        go = 1;
1000
 
                else if ((GO_EN(math.inslatch) && GO_EN(prom[math.promaddr])) && (LHIEN(math.inslatch) && LLOEN(prom[math.promaddr])))
1001
 
                        go = 1;
1002
 
 
1003
 
                /* Now update the latch */
1004
 
                math.inslatch = prom[math.promaddr] & 0x7fff;
1005
 
                math.mux = (math.inslatch >> 3) & 7;
1006
 
 
1007
 
                if (math.mux == BB_MUX_INSCL)
1008
 
                        math.i0ff = 0;
1009
 
                else if (math.mux == BB_MUX_PPSEN)
1010
 
                {
1011
 
                        // TODO: Needed?
1012
 
                        //mame_printf_debug("/PPSEN with INS: %x\n", math.promaddr);
1013
 
                        //math.ppshift = lastval;//math.cpulatch;
1014
 
                }
1015
 
 
1016
 
                /* TODO */
1017
 
                if (go)
1018
 
                {
1019
 
                        int ins = math.inslatch & 7;
1020
 
 
1021
 
                        BB_SET_INS0_BIT;
1022
 
 
1023
 
                        if (math.mux == BB_MUX_DPROE)
1024
 
                        {
1025
 
                                UINT16 *romdata = (UINT16*)machine.region("au_data")->base();
1026
 
                                UINT16 addr = get_bb_datarom_addr(math);
1027
 
                                kick_sn74s516(machine, &romdata[addr], ins);
1028
 
                        }
1029
 
                        else if (math.mux == BB_MUX_PPOE)
1030
 
                        {
1031
 
                                kick_sn74s516(machine, &math.ppshift, ins);
1032
 
                        }
1033
 
                        /* This is quite tricky. */
1034
 
                        /* It can either be a read operation or */
1035
 
                        /* What if /LHIEN and /LLOEN? */
1036
 
                        else if (LHIEN(math.inslatch) || LLOEN(math.inslatch))
1037
 
                        {
1038
 
                                UINT16 data;
1039
 
 
1040
 
                                kick_sn74s516(machine, &data, ins);
1041
 
 
1042
 
                                if (LHIEN(math.inslatch) && LLOEN(math.inslatch))
1043
 
                                {
1044
 
                                        math.ppshift = data;
1045
 
                                }
1046
 
                                else if (math.mux == BB_MUX_LMSEL)
1047
 
                                {
1048
 
                                        if (LLOEN(math.inslatch))
1049
 
                                        {
1050
 
                                                math.ppshift &= 0x000f;
1051
 
                                                math.ppshift |= data & 0xfff0;
1052
 
                                        }
1053
 
                                        else if (LHIEN(math.inslatch))
1054
 
                                        {
1055
 
                                                math.ppshift &= 0xfff0;
1056
 
                                                math.ppshift |= data & 0x000f;
1057
 
                                        }
1058
 
                                }
1059
 
                                else
1060
 
                                {
1061
 
                                        if (LLOEN(math.inslatch))
1062
 
                                        {
1063
 
                                                math.ppshift &= 0x0fff;
1064
 
                                                math.ppshift |= data & 0xf000;
1065
 
                                        }
1066
 
                                        else if (LHIEN(math.inslatch))
1067
 
                                        {
1068
 
                                                math.ppshift &= 0xf000;
1069
 
                                                math.ppshift |= data & 0x0fff;
1070
 
                                        }
1071
 
                                }
1072
 
                        }
1073
 
                        else
1074
 
                        {
1075
 
                                if (math.mux == BB_MUX_PPSEN)
1076
 
                                {
1077
 
                                        kick_sn74s516(machine, &math.ppshift, ins);
1078
 
                                }
1079
 
                                else
1080
 
                                {
1081
 
                                        /* Bus pullups give 0xffff */
1082
 
                                        UINT16 data = 0xffff;
1083
 
                                        kick_sn74s516(machine, &data, ins);
1084
 
                                }
1085
 
                        }
1086
 
                }
1087
 
 
1088
 
                /* Handle rotation */
1089
 
                if (((math.inslatch >> 8) & BB_DSEL) == 1)
1090
 
                {
1091
 
                        math.ppshift = ROR16(math.ppshift, 4);
1092
 
                }
1093
 
                else if (((math.inslatch >> 8) & BB_DSEL) == 2)
1094
 
                {
1095
 
                        math.ppshift = ROL16(math.ppshift, 4);
1096
 
                }
1097
 
 
1098
 
                /* Is there another instruction in the sequence? */
1099
 
                if (prom[math.promaddr] & 0x8000)
1100
 
                        break;
1101
 
                else
1102
 
                        INC_PROM_ADDR;
1103
 
        }
1104
 
}
1105
 
 
1106
 
READ16_HANDLER( buggyboy_math_r )
1107
 
{
1108
 
        tx1_state *state = space->machine().driver_data<tx1_state>();
1109
 
        math_t &math = state->m_math;
1110
 
        offset = offset << 1;
1111
 
 
1112
 
        /* /MLPCS */
1113
 
        if (offset < 0x400)
1114
 
        {
1115
 
                int ins;
1116
 
 
1117
 
                if (offset & 0x200)
1118
 
                {
1119
 
                        ins = math.inslatch & 7;
1120
 
                        BB_SET_INS0_BIT;
1121
 
                }
1122
 
                else
1123
 
                {
1124
 
                        ins = (offset >> 1) & 7;
1125
 
                }
1126
 
 
1127
 
                /* TODO What do we return? */
1128
 
                kick_sn74s516(space->machine(), &math.retval, ins);
1129
 
 
1130
 
                /* TODO */
1131
 
                //if (math.mux == BB_MUX_PPSEN)
1132
 
                //  math.ppshift = math.retval;
1133
 
        }
1134
 
        /* /PPSEN */
1135
 
        else if (offset < 0x800)
1136
 
        {
1137
 
                math.retval = math.ppshift;
1138
 
        }
1139
 
        /* /DPROE */
1140
 
        else if ((offset & 0xc00) == 0xc00)
1141
 
        {
1142
 
                UINT16 *romdata = (UINT16*)space->machine().region("au_data")->base();
1143
 
                UINT16 addr = get_bb_datarom_addr(math);
1144
 
 
1145
 
                math.retval = romdata[addr];
1146
 
 
1147
 
                /* This is necessary */
1148
 
                if (math.mux == BB_MUX_PPSEN)
1149
 
                        math.ppshift = romdata[addr];
1150
 
 
1151
 
                /* This is /SPCS region? Necessary anyway */
1152
 
                if (offset < 0xe00)
1153
 
                {
1154
 
                        if (math.mux != BB_MUX_ILDEN)
1155
 
                        {
1156
 
                                INC_PROM_ADDR;
1157
 
                                buggyboy_update_state(space->machine());
1158
 
                        }
1159
 
                }
1160
 
        }
1161
 
        else
1162
 
        {
1163
 
                if (math.mux == BB_MUX_PPSEN)
1164
 
                        math.retval = math.ppshift;
1165
 
                else
1166
 
                        /* Nothing is mapped - read from pull up resistors! */
1167
 
                        math.retval = 0xffff;
1168
 
        }
1169
 
 
1170
 
        if (offset & BB_INSLD)
1171
 
        {
1172
 
                math.promaddr = (offset << 2) & 0x1ff;
1173
 
                buggyboy_update_state(space->machine());
1174
 
        }
1175
 
        else if (offset & BB_CNTST)
1176
 
        {
1177
 
                INC_PROM_ADDR;
1178
 
                buggyboy_update_state(space->machine());
1179
 
        }
1180
 
 
1181
 
        return math.retval;
1182
 
}
1183
 
 
1184
 
WRITE16_HANDLER( buggyboy_math_w )
1185
 
{
1186
 
        tx1_state *state = space->machine().driver_data<tx1_state>();
1187
 
        math_t &math = state->m_math;
1188
 
        math.cpulatch = data;
1189
 
 
1190
 
        offset <<= 1;
1191
 
 
1192
 
        /* /MLPCS */
1193
 
        if (offset < 0x400)
1194
 
        {
1195
 
                int ins;
1196
 
 
1197
 
                if (offset & 0x200)
1198
 
                {
1199
 
                        ins = math.inslatch & 7;
1200
 
                        BB_SET_INS0_BIT;
1201
 
                }
1202
 
                else
1203
 
                {
1204
 
                        ins = (offset >> 1) & 7;
1205
 
                }
1206
 
 
1207
 
                kick_sn74s516(space->machine(), &math.cpulatch, ins);
1208
 
        }
1209
 
        /* /PPSEN */
1210
 
        else if ((offset & 0xc00) == 0x400)
1211
 
        {
1212
 
                math.ppshift = math.cpulatch;
1213
 
        }
1214
 
        /* /PSSEN */
1215
 
        else if ((offset & 0xc00) == 0x800)
1216
 
        {
1217
 
                if (((math.inslatch >> 8) & BB_DSEL) == 3)
1218
 
                {
1219
 
                        int shift;
1220
 
                        UINT16 val = math.ppshift;
1221
 
 
1222
 
                        if (math.cpulatch & 0x3800)
1223
 
                        {
1224
 
                                shift = (math.cpulatch >> 11) & 0x7;
1225
 
 
1226
 
                                while (shift)
1227
 
                                {
1228
 
                                        val = ROR16(val, 1);
1229
 
                                        shift >>= 1;
1230
 
                                }
1231
 
                        }
1232
 
                        else
1233
 
                        {
1234
 
                                shift = (math.cpulatch >> 7) & 0xf;
1235
 
                                shift = reverse_nibble(shift);
1236
 
                                shift >>= 1;
1237
 
 
1238
 
                                while (shift)
1239
 
                                {
1240
 
                                        val = ROL16(val, 1);
1241
 
                                        shift >>= 1;
1242
 
                                }
1243
 
                        }
1244
 
                        math.ppshift = val;
1245
 
                }
1246
 
                else
1247
 
                {
1248
 
                        mame_printf_debug("BB_DSEL was not 3 for P->S load!\n");
1249
 
                        debugger_break(space->machine());
1250
 
                }
1251
 
        }
1252
 
        else
1253
 
        {
1254
 
                mame_printf_debug("Buggy Boy unknown math state!\n");
1255
 
                debugger_break(space->machine());
1256
 
        }
1257
 
 
1258
 
        if (offset & BB_INSLD)
1259
 
        {
1260
 
                math.promaddr = (offset << 2) & 0x1ff;
1261
 
                buggyboy_update_state(space->machine());
1262
 
        }
1263
 
        else if (offset & BB_CNTST)
1264
 
        {
1265
 
                INC_PROM_ADDR;
1266
 
                buggyboy_update_state(space->machine());
1267
 
        }
1268
 
}
1269
 
 
1270
 
/*
1271
 
    This is for ROM range 0x5000-0x7fff
1272
 
*/
1273
 
READ16_HANDLER( buggyboy_spcs_rom_r )
1274
 
{
1275
 
        tx1_state *state = space->machine().driver_data<tx1_state>();
1276
 
        math_t &math = state->m_math;
1277
 
        math.cpulatch = *(UINT16*)((UINT8*)space->machine().region("math_cpu")->base() + 0xfc000 + 0x1000 + offset*2);
1278
 
 
1279
 
        if (math.mux == BB_MUX_ILDEN)
1280
 
        {
1281
 
                math.i0ff = math.cpulatch & (1 << 14) ? 1 : 0;
1282
 
        }
1283
 
        else if (math.mux == BB_MUX_MULEN)
1284
 
        {
1285
 
                int ins = math.inslatch & 7;
1286
 
 
1287
 
                BB_SET_INS0_BIT;
1288
 
                kick_sn74s516(space->machine(), &math.cpulatch, ins);
1289
 
        }
1290
 
        else if (math.mux == BB_MUX_PPSEN)
1291
 
        {
1292
 
                math.ppshift = math.cpulatch;
1293
 
        }
1294
 
        else if (math.mux == BB_MUX_PSSEN)
1295
 
        {
1296
 
                if (((math.inslatch >> 8) & BB_DSEL) == 3)
1297
 
                {
1298
 
                        int shift;
1299
 
                        UINT16 val = math.ppshift;
1300
 
 
1301
 
                        if (math.cpulatch & 0x3800)
1302
 
                        {
1303
 
                                shift = (math.cpulatch >> 11) & 0x7;
1304
 
 
1305
 
                                while (shift)
1306
 
                                {
1307
 
                                        val = ROR16(val, 1);
1308
 
                                        shift >>= 1;
1309
 
                                }
1310
 
                        }
1311
 
                        else
1312
 
                        {
1313
 
                                shift = (math.cpulatch >> 7) & 0xf;
1314
 
                                shift = reverse_nibble(shift);
1315
 
                                shift >>= 1;
1316
 
 
1317
 
                                while (shift)
1318
 
                                {
1319
 
                                        val = ROL16(val, 1);
1320
 
                                        shift >>= 1;
1321
 
                                }
1322
 
                        }
1323
 
                        math.ppshift = val;
1324
 
                }
1325
 
        }
1326
 
 
1327
 
        if (math.mux != BB_MUX_ILDEN)
1328
 
        {
1329
 
                INC_PROM_ADDR;
1330
 
                buggyboy_update_state(space->machine());
1331
 
        }
1332
 
 
1333
 
        return math.cpulatch;
1334
 
}
1335
 
 
1336
 
WRITE16_HANDLER( buggyboy_spcs_ram_w )
1337
 
{
1338
 
        tx1_state *state = space->machine().driver_data<tx1_state>();
1339
 
        COMBINE_DATA(&state->m_math_ram[offset]);
1340
 
}
1341
 
 
1342
 
READ16_HANDLER( buggyboy_spcs_ram_r )
1343
 
{
1344
 
        tx1_state *state = space->machine().driver_data<tx1_state>();
1345
 
        math_t &math = state->m_math;
1346
 
        math.cpulatch = state->m_math_ram[offset];
1347
 
 
1348
 
        offset <<= 1;
1349
 
 
1350
 
        if (math.mux == BB_MUX_ILDEN)
1351
 
        {
1352
 
                math.i0ff = math.cpulatch & (1 << 14) ? 1 : 0;
1353
 
        }
1354
 
        else if (math.mux == BB_MUX_MULEN)
1355
 
        {
1356
 
                int ins = math.inslatch & 7;
1357
 
 
1358
 
                BB_SET_INS0_BIT;
1359
 
                kick_sn74s516(space->machine(), &math.cpulatch, ins);
1360
 
        }
1361
 
        else if (math.mux == BB_MUX_PPSEN)
1362
 
        {
1363
 
                math.ppshift = math.cpulatch;
1364
 
        }
1365
 
        else if (math.mux == BB_MUX_PSSEN)
1366
 
        {
1367
 
                if (((math.inslatch >> 8) & BB_DSEL) == 3)
1368
 
                {
1369
 
                        int shift;
1370
 
                        UINT16 val = math.ppshift;
1371
 
 
1372
 
                        if (math.cpulatch & 0x3800)
1373
 
                        {
1374
 
                                shift = (math.cpulatch >> 11) & 0x7;
1375
 
 
1376
 
                                while (shift)
1377
 
                                {
1378
 
                                        val = ROR16(val, 1);
1379
 
                                        shift >>= 1;
1380
 
                                }
1381
 
                        }
1382
 
                        else
1383
 
                        {
1384
 
                                shift = (math.cpulatch >> 7) & 0xf;
1385
 
                                shift = reverse_nibble(shift);
1386
 
                                shift >>= 1;
1387
 
 
1388
 
                                while (shift)
1389
 
                                {
1390
 
                                        val = ROL16(val, 1);
1391
 
                                        shift >>= 1;
1392
 
                                }
1393
 
                        }
1394
 
                        math.ppshift = val;
1395
 
                }
1396
 
        }
1397
 
 
1398
 
        if (math.mux != BB_MUX_ILDEN)
1399
 
        {
1400
 
                INC_PROM_ADDR;
1401
 
                buggyboy_update_state(space->machine());
1402
 
        }
1403
 
 
1404
 
        return math.cpulatch;
1405
 
}
1406
 
 
1407
 
 
1408
 
 
1409
 
/*************************************
1410
 
 *
1411
 
 *  Machine Reset
1412
 
 *
1413
 
 *************************************/
1414
 
 
1415
 
MACHINE_RESET( buggyboy )
1416
 
{
1417
 
        tx1_state *state = machine.driver_data<tx1_state>();
1418
 
        memset(&state->m_math, 0, sizeof(state->m_math));
1419
 
}
1420
 
 
1421
 
MACHINE_RESET( tx1 )
1422
 
{
1423
 
        tx1_state *state = machine.driver_data<tx1_state>();
1424
 
        memset(&state->m_math, 0, sizeof(state->m_math));
1425
 
}