1
/***************************************************************************
3
Tatsumi TX-1/Buggy Boy machine hardware
5
***************************************************************************/
9
#include "includes/tx1.h"
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) )
20
INLINE UINT8 reverse_nibble(UINT8 nibble)
22
return (nibble & 1) << 3 |
30
State transition table
32
A little different to the real thing in that
33
there are no states between final input and
34
multiplication/division.
36
static const UINT8 state_table[16][8] =
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 },
56
static void sn_multiply(running_machine &machine)
58
tx1_state *state = machine.driver_data<tx1_state>();
59
sn74s516_t &SN74S516 = state->m_sn74s516;
61
switch (SN74S516.code)
65
SN74S516.ZW.ZW32 = SN74S516.X * SN74S516.Y;
70
SN74S516.ZW.ZW32 += SN74S516.X * SN74S516.Y;
75
SN74S516.ZW.ZW32 += -SN74S516.X * SN74S516.Y;
80
SN74S516.ZW.ZW32 = SN74S516.X * SN74S516.Y;
85
SN74S516.ZW.ZW32 = -SN74S516.X * SN74S516.Y;
90
SN74S516.ZW.ZW32 += SN74S516.X * SN74S516.Y;
95
SN74S516.ZW.ZW32 += -SN74S516.X * SN74S516.Y;
100
SN74S516.ZW.ZW32 = (SN74S516.X * SN74S516.Y) + (SN74S516.ZW.ZW32 & 0xffff0000);
105
SN74S516.ZW.ZW32 = (-SN74S516.X * SN74S516.Y) + (SN74S516.ZW.ZW32 & 0xffff0000);
110
SN74S516.ZW.ZW32 = (-SN74S516.X * SN74S516.Y) + (SN74S516.ZW.ZW32 & 0xffff0000);
115
SN74S516.ZW.ZW32 += (SN74S516.X * SN74S516.Y);
120
mame_printf_debug("sn74s516 ??? multiply: %x\n", SN74S516.code);
124
/* Seems a good enough place to clear it. */
128
static void sn_divide(running_machine &machine)
130
tx1_state *state = machine.driver_data<tx1_state>();
131
sn74s516_t &SN74S516 = state->m_sn74s516;
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;
144
switch (SN74S516.code)
148
Z = SN74S516.ZW.ZW32 / SN74S516.X;
149
W = SN74S516.ZW.ZW32 % SN74S516.X;
154
Z = SN74S516.ZW.ZW32 / SN74S516.X;
155
W = SN74S516.ZW.ZW32 % SN74S516.X;
160
Z = SN74S516.ZW.W / SN74S516.X;
161
W = SN74S516.ZW.W % SN74S516.X;
166
mame_printf_debug("SN74S516 unhandled divide type: %x\n", SN74S516.code);
170
/* Divide overflow Only happens during chip test anyway */
179
static void sn74s516_update(running_machine &machine, int ins)
181
tx1_state *state = machine.driver_data<tx1_state>();
182
sn74s516_t &SN74S516 = state->m_sn74s516;
183
SN74S516.state = state_table[SN74S516.state][ins];
185
if (SN74S516.state == 4)
187
sn_multiply(machine);
190
else if (SN74S516.state == 5)
197
static void kick_sn74s516(running_machine &machine, UINT16 *data, const int ins)
199
tx1_state *state = machine.driver_data<tx1_state>();
200
sn74s516_t &SN74S516 = state->m_sn74s516;
201
math_t &math = state->m_math;
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; \
210
#define UPDATE_SEQUENCE (SN74S516.code = (SN74S516.code << 4) | ins)
211
#define CLEAR_SEQUENCE (SN74S516.code = 0)
214
Remember to change the Z/W flag.
216
switch (SN74S516.state)
226
sn74s516_update(machine, ins);
230
sn74s516_update(machine, ins);
235
sn74s516_update(machine, ins);
254
sn74s516_update(machine, ins);
258
sn74s516_update(machine, ins);
264
sn74s516_update(machine, ins);
269
sn74s516_update(machine, ins);
274
sn74s516_update(machine, ins);
280
// TODO: 6666 represents an incomplete state - clear it.
281
if (SN74S516.code == 0x6666)
284
mame_printf_debug("%s:Code 6666: PROMADDR:%x\n", machine.describe_context(), math.promaddr);
291
sn74s516_update(machine, ins);
295
sn74s516_update(machine, ins);
300
sn74s516_update(machine, ins);
304
// Pointless operation.
305
sn74s516_update(machine, ins);
316
sn74s516_update(machine, ins);
321
sn74s516_update(machine, ins);
325
sn74s516_update(machine, ins);
330
sn74s516_update(machine, ins);
335
sn74s516_update(machine, ins);
345
sn74s516_update(machine, ins);
349
sn74s516_update(machine, ins);
353
// CHECK: Incomplete state
354
sn74s516_update(machine, ins);
358
/* 6667 = Load X, Load Z, Load W, Clear Z */
360
sn74s516_update(machine, ins);
366
mame_printf_debug("Unknown SN74S516 state. %x\n", SN74S516.code);
370
math.dbgaddr = math.promaddr;
371
math.dbgpc = cpu_get_previouspc(machine.device("math_cpu"));
375
/***************************************************************************
381
***************************************************************************/
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
391
TX1_SEL_MULEN = 0x00,
396
TX1_SEL_INSCL = 0x06,
400
#define TX1_SET_INS0_BIT do { if (!(ins & 0x4) && math.i0ff) ins |= math.i0ff; } while(0)
402
INLINE UINT16 get_tx1_datarom_addr(math_t &math)
406
addr = ((math.inslatch & 0x1c00) << 1) | (math.ppshift & 0xff);
408
if ((math.inslatch >> 8) & TX1_RADCHG)
409
addr |= (math.ppshift & 0x0700);
411
addr |= (math.promaddr << 3) & 0x0700;
413
return addr & 0x3fff;
416
static void tx1_update_state(running_machine &machine)
418
#define LHIEN(a) !(a & 0x80)
419
#define LLOEN(a) !(a & 0x40)
420
#define GO_EN(a) !(a & 0x4000)
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);
430
if (!GO_EN(math.inslatch) && GO_EN(prom[math.promaddr]))
436
Both 120 and 121 are used.
438
else if ((GO_EN(math.inslatch) && GO_EN(prom[math.promaddr])) && (LHIEN(math.inslatch) && LLOEN(prom[math.promaddr])))
441
/* Now update the latch */
442
math.inslatch = prom[math.promaddr] & 0x7fff;
443
math.mux = (math.inslatch >> 3) & 7;
445
if (math.mux == TX1_SEL_INSCL)
449
else if (math.mux == TX1_SEL_PPSEN)
451
// NOTE: Doesn't do anything without SPCS.
457
int ins = math.inslatch & 7;
461
if (math.mux == TX1_SEL_DSELOE)
463
int dsel = (math.inslatch >> 8) & TX1_DSEL;
464
int tfad = (math.inslatch & 0x1c00) << 1;
465
int sd = math.ppshift;
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);
476
dsel = (dsel & 2) | ((dsel & o4) ^ 1);
479
data = math.muxlatch;
482
UINT16 *romdata = (UINT16*)machine.region("au_data")->base();
483
UINT16 addr = get_tx1_datarom_addr(math);
484
data = romdata[addr];
487
data = ROL16(math.muxlatch, 4);
489
data = ROL16(SWAP16(math.muxlatch), 3);
491
kick_sn74s516(machine, &data, ins);
494
TODO: Changed ppshift to muxlatch for TX-1
497
/TMPLD2: /LLOEN.!O4 + (/LHIEN.O4)
499
O4: !SD9.!SD10./LMSEL + SD7.SD10./LMSEL +
500
!SD8.SD9./LMSEL + !SD7.SD8./LMSEL +
501
/LMSEL./DSEL1 + /LMSEL.TFAD13 + /LMSEL.TFAD12 + /LMSEL.TFAD11
503
else if (LHIEN(math.inslatch) || LLOEN(math.inslatch))
507
kick_sn74s516(machine, &data, ins);
509
/* All latches enabled */
510
if (LHIEN(math.inslatch) && LLOEN(math.inslatch))
512
math.muxlatch = data;
514
else if (math.mux == TX1_SEL_LMSEL) // O4 = 0
516
// TMPLD2/TMPLD3 15-5
517
if (LLOEN(math.inslatch))
519
math.muxlatch &= 0x001f;
520
math.muxlatch |= data & 0xffe0;
523
else if (LHIEN(math.inslatch))
525
math.muxlatch &= 0xffe0;
526
math.muxlatch |= data & 0x001f;
533
/TMPLD2: /LLOEN.!O4 + /LHIEN.O4
535
O4: !SD9.!SD10./LMSEL + SD7.SD10./LMSEL +
536
!SD8.SD9./LMSEL + !SD7.SD8./LMSEL +
537
/LMSEL./DSEL1 + /LMSEL.TFAD13 + /LMSEL.TFAD12 + /LMSEL.TFAD11
539
int dsel = (math.inslatch >> 8) & TX1_DSEL;
540
int tfad = (math.inslatch & 0x1c00) << 1;
541
int sd = math.ppshift;
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);
551
if (LLOEN(math.inslatch))
553
math.muxlatch &= 0x0fff;
554
math.muxlatch |= data & 0xf000;
559
math.muxlatch &= 0xf01f;
560
math.muxlatch |= data & 0x0fe0;
563
else if (LHIEN(math.inslatch))
565
math.muxlatch &= 0xffe0;
566
math.muxlatch |= data & 0x001f;
571
math.muxlatch &= 0xf01f;
572
math.muxlatch |= data & 0x0fe0;
579
if (math.mux == TX1_SEL_PPSEN)
581
kick_sn74s516(machine, &math.ppshift, ins);
585
/* Bus pullups give 0xffff */
586
UINT16 data = 0xffff;
587
kick_sn74s516(machine, &data, ins);
592
/* Is there another instruction in the sequence? */
593
if (prom[math.promaddr] & 0x8000)
600
READ16_HANDLER( tx1_math_r )
602
tx1_state *state = space->machine().driver_data<tx1_state>();
603
math_t &math = state->m_math;
604
offset = offset << 1;
613
ins = math.inslatch & 7;
618
ins = (offset >> 1) & 7;
621
/* TODO What do we return? */
622
kick_sn74s516(space->machine(), &math.retval, ins);
625
else if (offset < 0x800)
627
// Unused - just pullups?
628
math.retval = 0xffff;
631
else if ((offset & 0xc00) == 0xc00)
633
int dsel = (math.inslatch >> 8) & TX1_DSEL;
634
int tfad = (math.inslatch & 0x1c00) << 1;
635
int sd = math.ppshift;
638
if (math.mux == TX1_SEL_LMSEL)
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);
650
dsel = (dsel & 2) | ((dsel & o4) ^ 1);
653
math.retval = math.muxlatch;
657
TODO make this constant somewhere
658
e.g. math.retval = math.romptr[ get_tx1_datarom_addr() ];
660
UINT16 *romdata = (UINT16*)space->machine().region("au_data")->base();
661
UINT16 addr = get_tx1_datarom_addr(math);
662
math.retval = romdata[addr];
665
math.retval = ROL16(math.muxlatch, 4);
667
math.retval = ROL16(SWAP16(math.muxlatch), 3);
669
/* TODO for TX-1: This is /SPCS region? */
672
// Load the PP with retval??????
673
if (math.mux == TX1_SEL_PPSEN)
675
math.ppshift = math.retval & 0x3fff;
677
else if (math.mux == TX1_SEL_PSSEN)
680
mame_printf_debug("Math Read with PSSEN!\n");
681
math.ppshift = math.retval;
684
if (math.mux != TX1_SEL_ILDEN)
687
tx1_update_state(space->machine());
696
if (math.mux == TX1_SEL_PPSEN)
697
math.retval = math.ppshift & 0x3fff;
699
/* Nothing is mapped - read from pull up resistors! */
700
math.retval = 0xffff;
703
if (offset & TX1_INSLD)
705
math.promaddr = (offset << 2) & 0x1ff;
706
tx1_update_state(space->machine());
708
else if (offset & TX1_CNTST)
711
tx1_update_state(space->machine());
717
WRITE16_HANDLER( tx1_math_w )
719
tx1_state *state = space->machine().driver_data<tx1_state>();
720
math_t &math = state->m_math;
721
math.cpulatch = data;
724
// printf("W %x: %x\n", 0x3000 + offset, data);
733
ins = math.inslatch & 7;
738
ins = (offset >> 1) & 7;
741
kick_sn74s516(space->machine(), &math.cpulatch, ins);
744
else if ((offset & 0xc00) == 0x400)
746
/* Input is 14 bits */
747
math.ppshift = math.cpulatch & 0x3fff;
750
else if ((offset & 0xc00) == 0x800)
752
//if (((math.inslatch >> 8) & TX1_DSEL) == 3 )
755
UINT16 val = math.ppshift;
757
if (math.cpulatch & 0x3800)
759
shift = (math.cpulatch >> 11) & 0x7;
769
shift = (math.cpulatch >> 7) & 0xf;
770
shift = reverse_nibble(shift);
783
else if ((offset & 0xc00) == 0xc00)
791
math.muxlatch = math.cpulatch;
794
if (offset & TX1_INSLD)
796
math.promaddr = (offset << 2) & 0x1ff;
797
tx1_update_state(space->machine());
799
else if (offset & TX1_CNTST)
802
tx1_update_state(space->machine());
806
READ16_HANDLER( tx1_spcs_rom_r )
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);
812
if (math.mux == TX1_SEL_ILDEN)
814
math.i0ff = math.cpulatch & (1 << 14) ? 1 : 0;
816
else if (math.mux == TX1_SEL_MULEN)
818
int ins = math.inslatch & 7;
821
kick_sn74s516(space->machine(), &math.cpulatch, ins);
823
else if (math.mux == TX1_SEL_PPSEN)
825
math.ppshift = math.cpulatch;
827
else if (math.mux == TX1_SEL_PSSEN)
829
//if ( ((math.inslatch >> 8) & TX1_DSEL) == 3 )
832
UINT16 val = math.ppshift;
834
if (math.cpulatch & 0x3800)
836
shift = (math.cpulatch >> 11) & 0x7;
846
shift = (math.cpulatch >> 7) & 0xf;
847
shift = reverse_nibble(shift);
856
math.ppshift = val & 0x7ff;
860
if (math.mux != TX1_SEL_ILDEN)
863
tx1_update_state(space->machine());
866
return math.cpulatch;
870
READ16_HANDLER( tx1_spcs_ram_r )
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];
878
if (math.mux == TX1_SEL_ILDEN)
880
math.i0ff = math.cpulatch & (1 << 14) ? 1 : 0;
882
else if (math.mux == TX1_SEL_MULEN)
884
int ins = math.inslatch & 7;
887
kick_sn74s516(space->machine(), &math.cpulatch, ins);
889
else if (math.mux == TX1_SEL_PPSEN)
891
// math.ppshift = math.retval & 0x3fff;
892
math.ppshift = math.cpulatch;
894
else if (math.mux == TX1_SEL_PSSEN)
897
UINT16 val = math.ppshift;
899
if (math.cpulatch & 0x3800)
901
shift = (math.cpulatch >> 11) & 0x7;
911
shift = (math.cpulatch >> 7) & 0xf;
912
shift = reverse_nibble(shift);
921
math.ppshift = val & 0x7ff;
924
if (math.mux != TX1_SEL_ILDEN)
927
tx1_update_state(space->machine());
930
return math.cpulatch;
933
/* Should never occur */
934
WRITE16_HANDLER( tx1_spcs_ram_w )
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]);
942
/***************************************************************************
946
***************************************************************************/
947
#define BB_INSLD 0x100
948
#define BB_CNTST 0x80
949
#define BB_RADCHG 0x20
964
#define BB_SET_INS0_BIT do { if (!(ins & 0x4) && math.i0ff) ins |= math.i0ff;} while(0)
966
INLINE UINT16 get_bb_datarom_addr(math_t &math)
970
addr = ((math.inslatch & 0x1c00) << 1) | (math.ppshift & 0xff);
972
if ((math.inslatch >> 8) & BB_RADCHG)
974
addr |= (math.ppshift & 0x0700);
978
addr |= (math.promaddr << 3) & 0x0700;
981
return addr & 0x3fff;
984
static void buggyboy_update_state(running_machine &machine)
986
#define LHIEN(a) !(a & 0x80)
987
#define LLOEN(a) !(a & 0x40)
988
#define GO_EN(a) !(a & 0x4000)
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);
998
if (!GO_EN(math.inslatch) && GO_EN(prom[math.promaddr]))
1000
else if ((GO_EN(math.inslatch) && GO_EN(prom[math.promaddr])) && (LHIEN(math.inslatch) && LLOEN(prom[math.promaddr])))
1003
/* Now update the latch */
1004
math.inslatch = prom[math.promaddr] & 0x7fff;
1005
math.mux = (math.inslatch >> 3) & 7;
1007
if (math.mux == BB_MUX_INSCL)
1009
else if (math.mux == BB_MUX_PPSEN)
1012
//mame_printf_debug("/PPSEN with INS: %x\n", math.promaddr);
1013
//math.ppshift = lastval;//math.cpulatch;
1019
int ins = math.inslatch & 7;
1023
if (math.mux == BB_MUX_DPROE)
1025
UINT16 *romdata = (UINT16*)machine.region("au_data")->base();
1026
UINT16 addr = get_bb_datarom_addr(math);
1027
kick_sn74s516(machine, &romdata[addr], ins);
1029
else if (math.mux == BB_MUX_PPOE)
1031
kick_sn74s516(machine, &math.ppshift, ins);
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))
1040
kick_sn74s516(machine, &data, ins);
1042
if (LHIEN(math.inslatch) && LLOEN(math.inslatch))
1044
math.ppshift = data;
1046
else if (math.mux == BB_MUX_LMSEL)
1048
if (LLOEN(math.inslatch))
1050
math.ppshift &= 0x000f;
1051
math.ppshift |= data & 0xfff0;
1053
else if (LHIEN(math.inslatch))
1055
math.ppshift &= 0xfff0;
1056
math.ppshift |= data & 0x000f;
1061
if (LLOEN(math.inslatch))
1063
math.ppshift &= 0x0fff;
1064
math.ppshift |= data & 0xf000;
1066
else if (LHIEN(math.inslatch))
1068
math.ppshift &= 0xf000;
1069
math.ppshift |= data & 0x0fff;
1075
if (math.mux == BB_MUX_PPSEN)
1077
kick_sn74s516(machine, &math.ppshift, ins);
1081
/* Bus pullups give 0xffff */
1082
UINT16 data = 0xffff;
1083
kick_sn74s516(machine, &data, ins);
1088
/* Handle rotation */
1089
if (((math.inslatch >> 8) & BB_DSEL) == 1)
1091
math.ppshift = ROR16(math.ppshift, 4);
1093
else if (((math.inslatch >> 8) & BB_DSEL) == 2)
1095
math.ppshift = ROL16(math.ppshift, 4);
1098
/* Is there another instruction in the sequence? */
1099
if (prom[math.promaddr] & 0x8000)
1106
READ16_HANDLER( buggyboy_math_r )
1108
tx1_state *state = space->machine().driver_data<tx1_state>();
1109
math_t &math = state->m_math;
1110
offset = offset << 1;
1119
ins = math.inslatch & 7;
1124
ins = (offset >> 1) & 7;
1127
/* TODO What do we return? */
1128
kick_sn74s516(space->machine(), &math.retval, ins);
1131
//if (math.mux == BB_MUX_PPSEN)
1132
// math.ppshift = math.retval;
1135
else if (offset < 0x800)
1137
math.retval = math.ppshift;
1140
else if ((offset & 0xc00) == 0xc00)
1142
UINT16 *romdata = (UINT16*)space->machine().region("au_data")->base();
1143
UINT16 addr = get_bb_datarom_addr(math);
1145
math.retval = romdata[addr];
1147
/* This is necessary */
1148
if (math.mux == BB_MUX_PPSEN)
1149
math.ppshift = romdata[addr];
1151
/* This is /SPCS region? Necessary anyway */
1154
if (math.mux != BB_MUX_ILDEN)
1157
buggyboy_update_state(space->machine());
1163
if (math.mux == BB_MUX_PPSEN)
1164
math.retval = math.ppshift;
1166
/* Nothing is mapped - read from pull up resistors! */
1167
math.retval = 0xffff;
1170
if (offset & BB_INSLD)
1172
math.promaddr = (offset << 2) & 0x1ff;
1173
buggyboy_update_state(space->machine());
1175
else if (offset & BB_CNTST)
1178
buggyboy_update_state(space->machine());
1184
WRITE16_HANDLER( buggyboy_math_w )
1186
tx1_state *state = space->machine().driver_data<tx1_state>();
1187
math_t &math = state->m_math;
1188
math.cpulatch = data;
1199
ins = math.inslatch & 7;
1204
ins = (offset >> 1) & 7;
1207
kick_sn74s516(space->machine(), &math.cpulatch, ins);
1210
else if ((offset & 0xc00) == 0x400)
1212
math.ppshift = math.cpulatch;
1215
else if ((offset & 0xc00) == 0x800)
1217
if (((math.inslatch >> 8) & BB_DSEL) == 3)
1220
UINT16 val = math.ppshift;
1222
if (math.cpulatch & 0x3800)
1224
shift = (math.cpulatch >> 11) & 0x7;
1228
val = ROR16(val, 1);
1234
shift = (math.cpulatch >> 7) & 0xf;
1235
shift = reverse_nibble(shift);
1240
val = ROL16(val, 1);
1248
mame_printf_debug("BB_DSEL was not 3 for P->S load!\n");
1249
debugger_break(space->machine());
1254
mame_printf_debug("Buggy Boy unknown math state!\n");
1255
debugger_break(space->machine());
1258
if (offset & BB_INSLD)
1260
math.promaddr = (offset << 2) & 0x1ff;
1261
buggyboy_update_state(space->machine());
1263
else if (offset & BB_CNTST)
1266
buggyboy_update_state(space->machine());
1271
This is for ROM range 0x5000-0x7fff
1273
READ16_HANDLER( buggyboy_spcs_rom_r )
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);
1279
if (math.mux == BB_MUX_ILDEN)
1281
math.i0ff = math.cpulatch & (1 << 14) ? 1 : 0;
1283
else if (math.mux == BB_MUX_MULEN)
1285
int ins = math.inslatch & 7;
1288
kick_sn74s516(space->machine(), &math.cpulatch, ins);
1290
else if (math.mux == BB_MUX_PPSEN)
1292
math.ppshift = math.cpulatch;
1294
else if (math.mux == BB_MUX_PSSEN)
1296
if (((math.inslatch >> 8) & BB_DSEL) == 3)
1299
UINT16 val = math.ppshift;
1301
if (math.cpulatch & 0x3800)
1303
shift = (math.cpulatch >> 11) & 0x7;
1307
val = ROR16(val, 1);
1313
shift = (math.cpulatch >> 7) & 0xf;
1314
shift = reverse_nibble(shift);
1319
val = ROL16(val, 1);
1327
if (math.mux != BB_MUX_ILDEN)
1330
buggyboy_update_state(space->machine());
1333
return math.cpulatch;
1336
WRITE16_HANDLER( buggyboy_spcs_ram_w )
1338
tx1_state *state = space->machine().driver_data<tx1_state>();
1339
COMBINE_DATA(&state->m_math_ram[offset]);
1342
READ16_HANDLER( buggyboy_spcs_ram_r )
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];
1350
if (math.mux == BB_MUX_ILDEN)
1352
math.i0ff = math.cpulatch & (1 << 14) ? 1 : 0;
1354
else if (math.mux == BB_MUX_MULEN)
1356
int ins = math.inslatch & 7;
1359
kick_sn74s516(space->machine(), &math.cpulatch, ins);
1361
else if (math.mux == BB_MUX_PPSEN)
1363
math.ppshift = math.cpulatch;
1365
else if (math.mux == BB_MUX_PSSEN)
1367
if (((math.inslatch >> 8) & BB_DSEL) == 3)
1370
UINT16 val = math.ppshift;
1372
if (math.cpulatch & 0x3800)
1374
shift = (math.cpulatch >> 11) & 0x7;
1378
val = ROR16(val, 1);
1384
shift = (math.cpulatch >> 7) & 0xf;
1385
shift = reverse_nibble(shift);
1390
val = ROL16(val, 1);
1398
if (math.mux != BB_MUX_ILDEN)
1401
buggyboy_update_state(space->machine());
1404
return math.cpulatch;
1409
/*************************************
1413
*************************************/
1415
MACHINE_RESET( buggyboy )
1417
tx1_state *state = machine.driver_data<tx1_state>();
1418
memset(&state->m_math, 0, sizeof(state->m_math));
1421
MACHINE_RESET( tx1 )
1423
tx1_state *state = machine.driver_data<tx1_state>();
1424
memset(&state->m_math, 0, sizeof(state->m_math));