summaryrefslogtreecommitdiffstats
path: root/src/mame/drivers/allied.cpp
blob: e5b18995a246526ecb9b8e0ae7a391aa5f92fc5b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
// license:BSD-3-Clause
// copyright-holders:Robbbert
/**************************************************************************

  PINBALL
  Allied Leisure Cocktail Pinball
  All tables use the same base roms and some playfields even interchange
  between games.

  6504 CPU, 3x R6530 RRIOT, 5x R6520 PIA
  It is assumed that the R6530 is the same as MOS6530, and the R6520 is
  the same as MC6821.

  The schematic is too blurry to make out much detail, so used PinMAME
  for the PIA connections.

  The display units use 74164 serial units, with clock and data lines
  sufficient for all the digits of one player. Data = IC2,PB7, while
  Clock is IC2,CB2. To prevent display garbage, the new data is stored
  while IC4PBx is high, then displayed when the line goes low. IC7portB
  selects which player's display to update.

  There are no dipswitches; instead there are a number of jumper wires
  which can be pushed onto one of up to ten connector pins each. There
  are 15 10-pin connectors, a 5-pin connector and 2 2-pin connectors.

  For some reason the 'rol $46' instruction outputs the original data
  followed by the new result, so I've had to employ a horrible hack.

  Hold down X while inserting a coin.
  At the start of each ball, the display will be flashing. You need to
  hit Z, and then you can get a score. When the ball indicator goes out,
  your game is over.

  Game doesn't have any backup battery, so all info is lost at poweroff.
  If required, a fake nvram could be used at 00-3F (like PinMAME does).
  Mechanical meters are used to store accounting information.


ToDo:
- Coin slot 3 not working. Pressing it a lot kills all the coin slots.


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

#include "emu.h"
#include "machine/genpin.h"
#include "cpu/m6502/m6504.h"
#include "machine/mos6530.h"
#include "machine/6821pia.h"
#include "machine/timer.h"
#include "allied.lh"

class allied_state : public genpin_class
{
public:
	allied_state(const machine_config &mconfig, device_type type, const char *tag)
		: genpin_class(mconfig, type, tag)
		, m_maincpu(*this, "maincpu")
		, m_ic1(*this, "ic1")
		, m_ic2(*this, "ic2")
		, m_ic4(*this, "ic4")
		, m_ic5(*this, "ic5")
		, m_ic6(*this, "ic6")
		, m_ic7(*this, "ic7")
		, m_ic8(*this, "ic8")
		, m_digits(*this, "digit%u", 0U)
		, m_leds(*this, "led%u", 0U)
	{ }

	void allied(machine_config &config);

private:
	DECLARE_WRITE8_MEMBER(ic1_b_w);
	DECLARE_WRITE8_MEMBER(ic2_b_w);
	DECLARE_WRITE_LINE_MEMBER(ic2_cb2_w);
	DECLARE_WRITE8_MEMBER(ic3_b_w);
	DECLARE_WRITE8_MEMBER(ic4_b_w);
	DECLARE_WRITE_LINE_MEMBER(ic4_cb2_w);
	DECLARE_WRITE8_MEMBER(ic5_b_w);
	DECLARE_WRITE8_MEMBER(ic6_b_w);
	DECLARE_WRITE8_MEMBER(ic7_b_w);
	DECLARE_WRITE8_MEMBER(ic8_a_w);
	DECLARE_WRITE8_MEMBER(ic8_b_w);
	DECLARE_READ8_MEMBER(ic1_a_r);
	DECLARE_READ8_MEMBER(ic2_a_r);
	DECLARE_READ8_MEMBER(ic4_a_r);
	DECLARE_READ8_MEMBER(ic5_a_r);
	DECLARE_READ8_MEMBER(ic6_a_r);
	DECLARE_READ8_MEMBER(ic6_b_r);
	DECLARE_READ8_MEMBER(ic7_a_r);
	DECLARE_WRITE_LINE_MEMBER(ic8_cb2_w);
	TIMER_DEVICE_CALLBACK_MEMBER(timer_a);
	void allied_map(address_map &map);

	uint32_t m_player_score[6];
	uint8_t m_display;
	uint8_t m_bit_counter;
	bool m_disp_data;
	uint8_t m_ic5a;
	uint8_t m_ic6a0;
	uint8_t m_ic6a1;
	uint8_t m_ic6a2;
	uint8_t m_ic6b4;
	uint8_t m_ic6b7;
	virtual void machine_reset() override;
	virtual void machine_start() override;
	required_device<m6504_device> m_maincpu;
	required_device<pia6821_device> m_ic1;
	required_device<pia6821_device> m_ic2;
	required_device<pia6821_device> m_ic4;
	required_device<mos6530_device> m_ic5;
	required_device<mos6530_device> m_ic6;
	required_device<pia6821_device> m_ic7;
	required_device<pia6821_device> m_ic8;
	output_finder<42> m_digits;
	output_finder<7> m_leds;
};


void allied_state::allied_map(address_map &map)
{
	map(0x0000, 0x003f).ram(); // ic6
	map(0x0044, 0x0047).rw(m_ic2, FUNC(pia6821_device::read), FUNC(pia6821_device::write));
	map(0x0048, 0x004b).rw(m_ic1, FUNC(pia6821_device::read), FUNC(pia6821_device::write));
	map(0x0050, 0x0053).rw(m_ic7, FUNC(pia6821_device::read), FUNC(pia6821_device::write));
	map(0x0060, 0x0063).rw(m_ic4, FUNC(pia6821_device::read), FUNC(pia6821_device::write));
	map(0x0080, 0x008f).rw(m_ic5, FUNC(mos6530_device::read), FUNC(mos6530_device::write));
	map(0x0840, 0x084f).rw(m_ic6, FUNC(mos6530_device::read), FUNC(mos6530_device::write));
	map(0x00c0, 0x00c3).rw(m_ic8, FUNC(pia6821_device::read), FUNC(pia6821_device::write));
	map(0x0100, 0x013f).ram(); // ic5
	map(0x1400, 0x1fff).rom();
}

static INPUT_PORTS_START( allied )
	PORT_START("TEST")
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_SERVICE1 ) PORT_NAME("Self Test")
	PORT_START("R11")
	PORT_CONFNAME( 0x0f, 0x00, "1st Replay 1000")
	PORT_CONFSETTING(    0x00, "0")
	PORT_CONFSETTING(    0x01, "1")
	PORT_CONFSETTING(    0x02, "2")
	PORT_CONFSETTING(    0x03, "3")
	PORT_CONFSETTING(    0x04, "4")
	PORT_CONFSETTING(    0x05, "5")
	PORT_CONFSETTING(    0x06, "6")
	PORT_CONFSETTING(    0x07, "7")
	PORT_CONFSETTING(    0x08, "8")
	PORT_CONFSETTING(    0x09, "9")
	PORT_START("R12")
	PORT_CONFNAME( 0x0f, 0x05, "1st Replay 10000")
	PORT_CONFSETTING(    0x00, "0")
	PORT_CONFSETTING(    0x01, "1")
	PORT_CONFSETTING(    0x02, "2")
	PORT_CONFSETTING(    0x03, "3")
	PORT_CONFSETTING(    0x04, "4")
	PORT_CONFSETTING(    0x05, "5")
	PORT_CONFSETTING(    0x06, "6")
	PORT_CONFSETTING(    0x07, "7")
	PORT_CONFSETTING(    0x08, "8")
	PORT_CONFSETTING(    0x09, "9")
	PORT_START("R13")
	PORT_CONFNAME( 0x0f, 0x00, "1st Replay 100000")
	PORT_CONFSETTING(    0x00, "0")
	PORT_CONFSETTING(    0x01, "1")
	PORT_CONFSETTING(    0x02, "2")
	PORT_CONFSETTING(    0x03, "3")
	PORT_CONFSETTING(    0x04, "4")
	PORT_CONFSETTING(    0x05, "5")
	PORT_CONFSETTING(    0x06, "6")
	PORT_CONFSETTING(    0x07, "7")
	PORT_CONFSETTING(    0x08, "8")
	PORT_CONFSETTING(    0x09, "9")
	PORT_START("R21")
	PORT_CONFNAME( 0x0f, 0x00, "2nd Replay 1000")
	PORT_CONFSETTING(    0x00, "0")
	PORT_CONFSETTING(    0x01, "1")
	PORT_CONFSETTING(    0x02, "2")
	PORT_CONFSETTING(    0x03, "3")
	PORT_CONFSETTING(    0x04, "4")
	PORT_CONFSETTING(    0x05, "5")
	PORT_CONFSETTING(    0x06, "6")
	PORT_CONFSETTING(    0x07, "7")
	PORT_CONFSETTING(    0x08, "8")
	PORT_CONFSETTING(    0x09, "9")
	PORT_START("R22")
	PORT_CONFNAME( 0x0f, 0x00, "2nd Replay 10000")
	PORT_CONFSETTING(    0x00, "0")
	PORT_CONFSETTING(    0x01, "1")
	PORT_CONFSETTING(    0x02, "2")
	PORT_CONFSETTING(    0x03, "3")
	PORT_CONFSETTING(    0x04, "4")
	PORT_CONFSETTING(    0x05, "5")
	PORT_CONFSETTING(    0x06, "6")
	PORT_CONFSETTING(    0x07, "7")
	PORT_CONFSETTING(    0x08, "8")
	PORT_CONFSETTING(    0x09, "9")
	PORT_START("R23")
	PORT_CONFNAME( 0x0f, 0x01, "2nd Replay 100000")
	PORT_CONFSETTING(    0x00, "0")
	PORT_CONFSETTING(    0x01, "1")
	PORT_CONFSETTING(    0x02, "2")
	PORT_CONFSETTING(    0x03, "3")
	PORT_CONFSETTING(    0x04, "4")
	PORT_CONFSETTING(    0x05, "5")
	PORT_CONFSETTING(    0x06, "6")
	PORT_CONFSETTING(    0x07, "7")
	PORT_CONFSETTING(    0x08, "8")
	PORT_CONFSETTING(    0x09, "9")
	PORT_START("R31")
	PORT_CONFNAME( 0x0f, 0x00, "3rd Replay 1000")
	PORT_CONFSETTING(    0x00, "0")
	PORT_CONFSETTING(    0x01, "1")
	PORT_CONFSETTING(    0x02, "2")
	PORT_CONFSETTING(    0x03, "3")
	PORT_CONFSETTING(    0x04, "4")
	PORT_CONFSETTING(    0x05, "5")
	PORT_CONFSETTING(    0x06, "6")
	PORT_CONFSETTING(    0x07, "7")
	PORT_CONFSETTING(    0x08, "8")
	PORT_CONFSETTING(    0x09, "9")
	PORT_START("R32")
	PORT_CONFNAME( 0x0f, 0x06, "3rd Replay 10000")
	PORT_CONFSETTING(    0x00, "0")
	PORT_CONFSETTING(    0x01, "1")
	PORT_CONFSETTING(    0x02, "2")
	PORT_CONFSETTING(    0x03, "3")
	PORT_CONFSETTING(    0x04, "4")
	PORT_CONFSETTING(    0x05, "5")
	PORT_CONFSETTING(    0x06, "6")
	PORT_CONFSETTING(    0x07, "7")
	PORT_CONFSETTING(    0x08, "8")
	PORT_CONFSETTING(    0x09, "9")
	PORT_START("R33")
	PORT_CONFNAME( 0x0f, 0x01, "3rd Replay 100000")
	PORT_CONFSETTING(    0x00, "0")
	PORT_CONFSETTING(    0x01, "1")
	PORT_CONFSETTING(    0x02, "2")
	PORT_CONFSETTING(    0x03, "3")
	PORT_CONFSETTING(    0x04, "4")
	PORT_CONFSETTING(    0x05, "5")
	PORT_CONFSETTING(    0x06, "6")
	PORT_CONFSETTING(    0x07, "7")
	PORT_CONFSETTING(    0x08, "8")
	PORT_CONFSETTING(    0x09, "9")
	PORT_START("CM1")
	PORT_CONFNAME( 0x0f, 0x05, "Credits Max 1")
	PORT_CONFSETTING(    0x00, "0")
	PORT_CONFSETTING(    0x01, "1")
	PORT_CONFSETTING(    0x02, "2")
	PORT_CONFSETTING(    0x03, "3")
	PORT_CONFSETTING(    0x04, "4")
	PORT_CONFSETTING(    0x05, "5")
	PORT_CONFSETTING(    0x06, "6")
	PORT_CONFSETTING(    0x07, "7")
	PORT_CONFSETTING(    0x08, "8")
	PORT_CONFSETTING(    0x09, "9")
	PORT_START("CM2")
	PORT_CONFNAME( 0x0f, 0x01, "Credits Max 10")
	PORT_CONFSETTING(    0x00, "0")
	PORT_CONFSETTING(    0x01, "1")
	PORT_CONFSETTING(    0x02, "2")
	PORT_CONFSETTING(    0x03, "3")
	PORT_CONFSETTING(    0x04, "4")
	PORT_CONFSETTING(    0x05, "5")
	PORT_CONFSETTING(    0x06, "6")
	PORT_CONFSETTING(    0x07, "7")
	PORT_CONFSETTING(    0x08, "8")
	PORT_CONFSETTING(    0x09, "9")
	PORT_START("CS1")
	PORT_CONFNAME( 0x0f, 0x01, "Coin Slot 1")
	PORT_CONFSETTING(    0x00, "0")
	PORT_CONFSETTING(    0x01, "1")
	PORT_CONFSETTING(    0x02, "2")
	PORT_CONFSETTING(    0x03, "3")
	PORT_CONFSETTING(    0x04, "4")
	PORT_CONFSETTING(    0x05, "5")
	PORT_CONFSETTING(    0x06, "6")
	PORT_CONFSETTING(    0x07, "7")
	PORT_CONFSETTING(    0x08, "8")
	PORT_CONFSETTING(    0x09, "9")
	PORT_START("CS2")
	PORT_CONFNAME( 0x0f, 0x01, "Coin Slot 2")
	PORT_CONFSETTING(    0x00, "0")
	PORT_CONFSETTING(    0x01, "1")
	PORT_CONFSETTING(    0x02, "2")
	PORT_CONFSETTING(    0x03, "3")
	PORT_CONFSETTING(    0x04, "4")
	PORT_CONFSETTING(    0x05, "5")
	PORT_CONFSETTING(    0x06, "6")
	PORT_CONFSETTING(    0x07, "7")
	PORT_CONFSETTING(    0x08, "8")
	PORT_CONFSETTING(    0x09, "9")
	PORT_START("CS3")
	PORT_CONFNAME( 0x0f, 0x01, "Coin Slot 3")
	PORT_CONFSETTING(    0x00, "0")
	PORT_CONFSETTING(    0x01, "1")
	PORT_CONFSETTING(    0x02, "2")
	PORT_CONFSETTING(    0x03, "3")
	PORT_CONFSETTING(    0x04, "4")
	PORT_CONFSETTING(    0x05, "5")
	PORT_CONFSETTING(    0x06, "6")
	PORT_CONFSETTING(    0x07, "7")
	PORT_CONFSETTING(    0x08, "8")
	PORT_CONFSETTING(    0x09, "9")
	PORT_START("CR")
	PORT_CONFNAME( 0x0f, 0x01, "Credits Option")
	PORT_CONFSETTING(    0x01, "1")
	PORT_CONFSETTING(    0x02, "2")
	PORT_START("B")
	PORT_CONFNAME( 0x07, 0x03, "Balls")
	PORT_CONFSETTING(    0x01, "1")
	PORT_CONFSETTING(    0x02, "2")
	PORT_CONFSETTING(    0x03, "3")
	PORT_CONFSETTING(    0x04, "4")
	PORT_CONFSETTING(    0x05, "5")
	PORT_START("A")
	PORT_CONFNAME( 0x04, 0x04, "Award")
	PORT_CONFSETTING(    0x04, "Replay")
	PORT_CONFSETTING(    0x00, "Extra Ball")
	PORT_CONFNAME( 0x08, 0x08, "Line Up Inhibit")
	PORT_CONFSETTING(    0x08, DEF_STR(No))
	PORT_CONFSETTING(    0x00, DEF_STR(Yes))
	PORT_START("N")
	PORT_CONFNAME( 0x01, 0x01, "Number of Players")
	PORT_CONFSETTING(    0x00, "2")
	PORT_CONFSETTING(    0x01, "4")

	PORT_START("X1A") // ic1_a
	PORT_BIT( 0x5f, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_K) PORT_NAME("Bullseye target")
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_Z) PORT_NAME("Ball in play")

	PORT_START("X2A") // ic2_a
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_A) PORT_NAME("L Bumper")
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_S) PORT_NAME("C Bumper")
	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_D) PORT_NAME("R Bumper")
	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_F) PORT_NAME("L Bullseye")
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_G) PORT_NAME("R Bullseye")
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_H) PORT_NAME("L Sling")
	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_J) PORT_NAME("R Sling")
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_X) PORT_NAME("Outhole")

	PORT_START("X4A") // ic4_a
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_Q) PORT_NAME("Target A")
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_W) PORT_NAME("Target B")
	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_E) PORT_NAME("Target C")
	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_R) PORT_NAME("Target D")
	PORT_BIT( 0x30, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_TILT )
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START )

	PORT_START("X6A") // ic6_a
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_COIN3 )
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_COIN2 )
	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_COIN1 )
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_TILT1 ) PORT_NAME("Slam Tilt")

	PORT_START("X7A") // ic7_a
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_V) PORT_NAME("Raise Target A")
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_M) PORT_NAME("Raise Target D")
	PORT_BIT( 0x0c, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_C) PORT_NAME("500 point rollover")
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_B) PORT_NAME("Raise Target B")
	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_N) PORT_NAME("Raise Target C")
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_L) PORT_NAME("Extra Ball when Lit")
INPUT_PORTS_END

// 1 target, 1 rollover
READ8_MEMBER( allied_state::ic1_a_r )
{
	return ioport("X1A")->read();
}

// 6 lamps
WRITE8_MEMBER( allied_state::ic1_b_w )
{
}

// 8 switches
READ8_MEMBER( allied_state::ic2_a_r )
{
	return ioport("X2A")->read();
}

WRITE8_MEMBER( allied_state::ic2_b_w )
{
// PB0-4,6 - lamps

	m_disp_data = !BIT(data, 7);
}

WRITE_LINE_MEMBER( allied_state::ic2_cb2_w )
{
	if ((m_display) && (!state))
	{
		m_bit_counter++;
		if (BIT(m_bit_counter, 0))
			m_player_score[m_display-1] = (m_player_score[m_display-1] << 1) | m_disp_data;
		if (m_bit_counter == 15)
			m_bit_counter = 0;
	}
}

WRITE8_MEMBER( allied_state::ic3_b_w )
{
	m_maincpu->set_input_line(M6504_IRQ_LINE, BIT(data, 7) ? CLEAR_LINE : ASSERT_LINE );
}

// 6 switches
READ8_MEMBER( allied_state::ic4_a_r )
{
	return ioport("X4A")->read();
}

WRITE8_MEMBER( allied_state::ic4_b_w )
{
	static const uint8_t patterns[16] = { 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7c, 0x07, 0x7f, 0x67, 0x58, 0x4c, 0x62, 0x69, 0x78, 0 }; // 7446A
	uint8_t segment, i;
	for (i = 0; i < 4; i++)
	{
		if (!BIT(data, i+4))
		{
			m_digits[i*10] = patterns[0];
			segment = (m_player_score[i] >> 0) & 15;
			m_digits[i*10+1] = patterns[segment];
			segment = (m_player_score[i] >> 4) & 15;
			m_digits[i*10+2] =  patterns[segment];
			segment = (m_player_score[i] >> 8) & 15;
			m_digits[i*10+3] = patterns[segment];
			segment = (m_player_score[i] >> 12) & 15;
			m_digits[i*10+4] = patterns[segment];
			segment = (m_player_score[i] >> 16) & 15;
			m_digits[i*10+5] = patterns[segment];
		}
		else
		{
			m_digits[i*10] = 0;
			m_digits[i*10+1] = 0;
			m_digits[i*10+2] = 0;
			m_digits[i*10+3] = 0;
			m_digits[i*10+4] = 0;
			m_digits[i*10+5] = 0;
		}
	}

	// doesn't seem to be a strobe for the credits display
	segment = (m_player_score[4] >> 0) & 15;
	m_digits[40] = patterns[segment];
	segment = (m_player_score[4] >> 4) & 15;
	m_digits[41] = patterns[segment];

// PB0-3 - player 1-4 LED - to do
}

WRITE_LINE_MEMBER( allied_state::ic4_cb2_w )
{
}

// 8 of the adjustment connectors
READ8_MEMBER( allied_state::ic5_a_r )
{
	return m_ic5a;
}

// cabinet solenoids
WRITE8_MEMBER( allied_state::ic5_b_w )
{
// PB0 - play meter
// PB1 - replay meter

	if (!BIT(data, 2)) // chime C
		m_samples->start(1, 1);

	if (!BIT(data, 3)) // chime B
		m_samples->start(2, 2);

	if (!BIT(data, 4)) // chime A
		m_samples->start(3, 3); // tens have highest tone

	if (!BIT(data, 5)) // knocker
		m_samples->start(0, 6);

	m_maincpu->set_input_line(M6504_IRQ_LINE, BIT(data, 7) ? CLEAR_LINE : ASSERT_LINE );
}

// 4 adjustments, 3 coin slots, slam tilt
READ8_MEMBER( allied_state::ic6_a_r )
{
	return m_ic6a0 | m_ic6a1 | m_ic6a2 | ioport("X6A")->read();
}

// 1 adjustment, test switch
READ8_MEMBER( allied_state::ic6_b_r )
{
	return m_ic6b4 | ioport("TEST")->read() | m_ic6b7 | 0x4f;
}

WRITE8_MEMBER( allied_state::ic6_b_w )
{
// PB0-3 to drop targets

	m_maincpu->set_input_line(M6504_IRQ_LINE, BIT(data, 7) ? CLEAR_LINE : ASSERT_LINE );
}

// 6 inputs
READ8_MEMBER( allied_state::ic7_a_r )
{
	return ioport("X7A")->read();
}

WRITE8_MEMBER( allied_state::ic7_b_w )
{
// PB7 - tilt lamp

	// PB4-6 display select
	m_display = data >> 4;
	if (m_display > 5)
		m_display = 0;
	m_bit_counter = 0;

	// PB0-3 switch matrix
	data &= 15;
	bool res;
	// IC1CA1 = 3rd 100,000 replay
	res = (ioport("R33")->read() == data);
	m_ic1->ca1_w(!res);
	// IC1CB1 = Number of balls
	res = (ioport("B")->read() == data);
	m_ic1->cb1_w(!res);
	// IC2CA1 = Max. credit tens
	res = (ioport("CM2")->read() == data);
	m_ic2->ca1_w(!res);
	// IC2CB1 = Max. credit units
	res = (ioport("CM1")->read() == data);
	m_ic2->cb1_w(!res);
	// IC4CA1 = Credit 1 prog.
	res = (ioport("CS1")->read() == data);
	m_ic4->ca1_w(!res);
	// IC5PA0 = 1st 1,000 replay
	m_ic5a = (ioport("R11")->read() == data) ? 0 : 1;
	// IC5PA1 = 1st 10,000 replay
	m_ic5a |= (ioport("R12")->read() == data) ? 0 : 2;
	// IC5PA2 = 1st 100,000 replay
	m_ic5a |= (ioport("R13")->read() == data) ? 0 : 4;
	// IC5PA3 = 2nd 1,000 replay
	m_ic5a |= (ioport("R21")->read() == data) ? 0 : 8;
	// IC5PA4 = 2nd 10,000 replay
	m_ic5a |= (ioport("R22")->read() == data) ? 0 : 16;
	// IC5PA5 = 2nd 100,000 replay
	m_ic5a |= (ioport("R23")->read() == data) ? 0 : 32;
	// IC5PA6 = 3rd 1,000 replay
	m_ic5a |= (ioport("R31")->read() == data) ? 0 : 64;
	// IC5PA7 = 3rd 10,000 replay
	m_ic5a |= (ioport("R32")->read() == data) ? 0 : 128;
	// IC6PA0 = Credit options
	m_ic6a0 = (ioport("CR")->read() == data) ? 0 : 1;
	// IC6PA1 = Credit 2 prog.
	m_ic6a1 = (ioport("CS2")->read() == data) ? 0 : 2;
	// IC6PA2 = Replay / Add-a-ball / Match inhibit
	m_ic6a2 = ioport("A")->read();
	// IC6PB4 = Credit 3 prog.
	m_ic6b4 = (ioport("CS3")->read() == data) ? 0 : 16;
	// IC7CA1 = 2/4 Players
	res = ((ioport("N")->read() ? 4 : 2) == data);
	m_ic7->ca1_w(!res);
}

// playfield solenoids
WRITE8_MEMBER( allied_state::ic8_a_w )
{
	if ((data & 0x07) < 0x07) // 3 bumpers
		m_samples->start(0, 0);

	if ((data & 0x60) < 0x60) // slings
		m_samples->start(0, 7);

	if (!BIT(data, 7)) // outhole
		m_samples->start(0, 5);
}

// PB0-4 = ball 1-5 LED; PB5 = shoot again lamp
WRITE8_MEMBER( allied_state::ic8_b_w )
{
	for (int i = 0; i < 6; i++)
		m_leds[i+1] = !BIT(data, i);
}

// this line not emulated in PinMAME, maybe it isn't needed
WRITE_LINE_MEMBER( allied_state::ic8_cb2_w )
{
	m_ic6b7 = state ? 128 : 0; // i think it's pb7, hard to tell
	m_ic7->cb1_w(state);
}

TIMER_DEVICE_CALLBACK_MEMBER( allied_state::timer_a )
{
	uint8_t data = ioport("X6A")->read();

	m_ic8->ca1_w(BIT(data, 4));
	m_ic8->cb1_w(BIT(data, 5));
	m_ic8->ca2_w(BIT(data, 6));
}

void allied_state::machine_start()
{
	m_digits.resolve();
	m_leds.resolve();
}

void allied_state::machine_reset()
{
	m_display = 0;
	m_bit_counter = 0;
	m_disp_data = 0;
	m_ic5a = 0;
	m_ic6a0 = 0;
	m_ic6a1 = 0;
	m_ic6a2 = 0;
	m_ic6b4 = 0;
	m_ic6b7 = 0;
	m_leds[0] = 1;
}

void allied_state::allied(machine_config &config)
{
	/* basic machine hardware */
	M6504(config, m_maincpu, 3572549/4);
	m_maincpu->set_addrmap(AS_PROGRAM, &allied_state::allied_map);

	/* Video */
	config.set_default_layout(layout_allied);

	/* Sound */
	genpin_audio(config);

	/* Devices */
	PIA6821(config, m_ic1, 0);
	m_ic1->readpa_handler().set(FUNC(allied_state::ic1_a_r));
	//m_ic1->writepa_handler().set(FUNC(allied_state::ic1_a_w));
	//m_ic1->readpb_handler().set(FUNC(allied_state::ic1_b_r));
	m_ic1->writepb_handler().set(FUNC(allied_state::ic1_b_w));
	//m_ic1->ca2_handler().set(FUNC(allied_state::ic1_ca2_w));
	//m_ic1->cb2_handler().set(FUNC(allied_state::ic1_cb2_w));
	m_ic1->irqa_handler().set_inputline("maincpu", M6504_IRQ_LINE);
	m_ic1->irqb_handler().set_inputline("maincpu", M6504_IRQ_LINE);

	PIA6821(config, m_ic2, 0);
	m_ic2->readpa_handler().set(FUNC(allied_state::ic2_a_r));
	//m_ic2->writepa_handler().set(FUNC(allied_state::ic2_a_w));
	//m_ic2->readpb_handler().set(FUNC(allied_state::ic2_b_r));
	m_ic2->writepb_handler().set(FUNC(allied_state::ic2_b_w));
	//m_ic2->ca2_handler().set(FUNC(allied_state::ic2_ca2_w));
	m_ic2->cb2_handler().set(FUNC(allied_state::ic2_cb2_w));
	m_ic2->irqa_handler().set_inputline("maincpu", M6504_IRQ_LINE);
	m_ic2->irqb_handler().set_inputline("maincpu", M6504_IRQ_LINE);

	PIA6821(config, m_ic4, 0);
	m_ic4->readpa_handler().set(FUNC(allied_state::ic4_a_r));
	//m_ic4->writepa_handler().set(FUNC(allied_state::ic4_a_w));
	//m_ic4->readpb_handler().set(FUNC(allied_state::ic4_b_r));
	m_ic4->writepb_handler().set(FUNC(allied_state::ic4_b_w));
	//m_ic4->ca2_handler().set(FUNC(allied_state::ic4_ca2_w));
	m_ic4->cb2_handler().set(FUNC(allied_state::ic4_cb2_w));
	m_ic4->irqa_handler().set_inputline("maincpu", M6504_IRQ_LINE);
	m_ic4->irqb_handler().set_inputline("maincpu", M6504_IRQ_LINE);

	PIA6821(config, m_ic7, 0);
	m_ic7->readpa_handler().set(FUNC(allied_state::ic7_a_r));
	//m_ic7->writepa_handler().set(FUNC(allied_state::ic7_a_w));
	//m_ic7->readpb_handler().set(FUNC(allied_state::ic7_b_r));
	m_ic7->writepb_handler().set(FUNC(allied_state::ic7_b_w));
	//m_ic7->ca2_handler().set(FUNC(allied_state::ic7_ca2_w));
	//m_ic7->cb2_handler().set(FUNC(allied_state::ic7_cb2_w));
	m_ic7->irqa_handler().set_inputline("maincpu", M6504_IRQ_LINE);
	m_ic7->irqb_handler().set_inputline("maincpu", M6504_IRQ_LINE);

	PIA6821(config, m_ic8, 0);
	//m_ic8->readpa_handler().set(FUNC(allied_state::ic8_a_r));
	m_ic8->writepa_handler().set(FUNC(allied_state::ic8_a_w));
	//m_ic8->readpb_handler().set(FUNC(allied_state::ic8_b_r));
	m_ic8->writepb_handler().set(FUNC(allied_state::ic8_b_w));
	//m_ic8->ca2_handler().set(FUNC(allied_state::ic8_ca2_w));
	m_ic8->cb2_handler().set(FUNC(allied_state::ic8_cb2_w));
	m_ic8->irqa_handler().set_inputline("maincpu", M6504_IRQ_LINE);
	m_ic8->irqb_handler().set_inputline("maincpu", M6504_IRQ_LINE);

	mos6530_device &ic3(MOS6530(config, "ic3", 3572549/4)); // unknown where the ram and i/o is located
	ic3.out_pb_callback().set(FUNC(allied_state::ic3_b_w));

	MOS6530(config, m_ic5, 3572549/4);
	m_ic5->in_pa_callback().set(FUNC(allied_state::ic5_a_r));
	//m_ic5->out_pa_callback().set(FUNC(allied_state::ic5_a_w));
	//m_ic5->in_pb_callback().set(FUNC(allied_state::ic5_b_r));
	m_ic5->out_pb_callback().set(FUNC(allied_state::ic5_b_w));

	MOS6530(config, m_ic6, 3572549/4);
	m_ic6->in_pa_callback().set(FUNC(allied_state::ic6_a_r));
	//m_ic6->out_pa_callback().set(FUNC(allied_state::ic6_a_w));
	m_ic6->in_pb_callback().set(FUNC(allied_state::ic6_b_r));
	m_ic6->out_pb_callback().set(FUNC(allied_state::ic6_b_w));

	TIMER(config, "timer_a").configure_periodic(FUNC(allied_state::timer_a), attotime::from_hz(50));
}


ROM_START( allied )
	ROM_REGION( 0x2000, "maincpu", 0 )
	ROM_LOAD( "6530-009.u5", 0x1400, 0x0400, CRC(e4fb64fb) SHA1(a3d9de7cbfb42180a860e0bbbeaeba96d8bd1e20))
	ROM_LOAD( "6530-010.u6", 0x1800, 0x0400, CRC(dca980dd) SHA1(3817d75413854d889fc1ce4fd6a51d820d1e0534))
	ROM_LOAD( "6530-011.u3", 0x1c00, 0x0400, CRC(13f42789) SHA1(baa0f73fda08a3c5d6f1423fb329e4febb07ef97))
ROM_END

#define rom_suprpick    rom_allied
#define rom_royclark    rom_allied
#define rom_thndbolt    rom_allied
#define rom_hoedown     rom_allied
#define rom_takefive    rom_allied
#define rom_heartspd    rom_allied
#define rom_foathens    rom_allied
#define rom_disco79     rom_allied
#define rom_erosone     rom_allied
#define rom_circa33     rom_allied
#define rom_starshot    rom_allied


GAME(1977,  allied,   0,      allied, allied, allied_state, empty_init, ROT0, "Allied Leisure",   "Allied System",               MACHINE_IS_BIOS_ROOT | MACHINE_NOT_WORKING )
GAME(1977,  suprpick, allied, allied, allied, allied_state, empty_init, ROT0, "Allied Leisure",   "Super Picker",                MACHINE_MECHANICAL | MACHINE_NOT_WORKING )
GAME(1977,  royclark, allied, allied, allied, allied_state, empty_init, ROT0, "Fascination Int.", "Roy Clark - The Entertainer", MACHINE_MECHANICAL | MACHINE_NOT_WORKING )
GAME(1977,  thndbolt, allied, allied, allied, allied_state, empty_init, ROT0, "Allied Leisure",   "Thunderbolt",                 MACHINE_MECHANICAL | MACHINE_NOT_WORKING )
GAME(1978,  hoedown,  allied, allied, allied, allied_state, empty_init, ROT0, "Allied Leisure",   "Hoe Down",                    MACHINE_MECHANICAL | MACHINE_NOT_WORKING )
GAME(1978,  takefive, allied, allied, allied, allied_state, empty_init, ROT0, "Allied Leisure",   "Take Five",                   MACHINE_MECHANICAL | MACHINE_NOT_WORKING )
GAME(1978,  heartspd, allied, allied, allied, allied_state, empty_init, ROT0, "Allied Leisure",   "Hearts & Spades",             MACHINE_MECHANICAL | MACHINE_NOT_WORKING )
GAME(1978,  foathens, allied, allied, allied, allied_state, empty_init, ROT0, "Allied Leisure",   "Flame of Athens",             MACHINE_MECHANICAL | MACHINE_NOT_WORKING )
GAME(1979,  disco79,  allied, allied, allied, allied_state, empty_init, ROT0, "Allied Leisure",   "Disco '79",                   MACHINE_MECHANICAL | MACHINE_NOT_WORKING )
GAME(1979,  erosone,  allied, allied, allied, allied_state, empty_init, ROT0, "Fascination Int.", "Eros One",                    MACHINE_MECHANICAL | MACHINE_NOT_WORKING )
GAME(1979,  circa33,  allied, allied, allied, allied_state, empty_init, ROT0, "Fascination Int.", "Circa 1933",                  MACHINE_MECHANICAL | MACHINE_NOT_WORKING )
GAME(1979,  starshot, allied, allied, allied, allied_state, empty_init, ROT0, "Allied Leisure",   "Star Shooter",                MACHINE_MECHANICAL | MACHINE_NOT_WORKING )