/
berzerk.cpp
1458 lines (1176 loc) · 51.1 KB
/
berzerk.cpp
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
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// license:BSD-3-Clause
// copyright-holders:Zsolt Vasvari, Aaron Giles, R. Belmont, Jonathan Gevaryahu
/***************************************************************************
Berzerk hardware
Driver by Zsolt Vasvari
Original sound driver by Alex Judd
New sound driver by Aaron Giles, R. Belmont and Lord Nightmare
Some known differences between Berzerk RC28 and RC31 sets:
RC28 uses only 3 different colors for robots based on player score:
Score Robot Color Lasers
0 Gold 0
300 Red 1
1500+ Dark Blue 2
Evil Otto shows up based on a formula of 5(-1 for each new room) plus
the number of spawned robots times 40 frames
RC31 is a rebalanced game with numerous changes:
Score Robot Color Lasers Delay
0 Gold 0 80 frames
300 Red 1 80 frames
1500 Dark Blue 2 20 frames
3000 Green 3 10 frames
4500 Purple 4 10 frames
6000 Yellow 5 15 frames
7500 White 1* 60 frames
9000 White 1* 50 frames
10000 Dark Blue 2* 35 frames
11000 Pink 3* 25 frames
13000 Grey 4* 20 frames
15000 Gold 5* 15 frames
17000 Red 5* 10 frames
19000+ Light Blue 5* 5 frames
* Indicates a faster speed laser
- Score values are when the player advances to the next "level" or Robot
color.
- Lasers are the maximum robot lasers on the screen at one time.
- Delay is the number of frames between initial robot firing when you
enter a room as well as "reload" time.
In RC31, Evil Otto's formula is modified by adding in the number of lasers
before multiplying by 40 frames
Game difference analysis by The Cutting Room Floor (tcrf.net)
***************************************************************************/
#include "emu.h"
#include "exidysound.h"
#include "cpu/z80/z80.h"
#include "machine/74181.h"
#include "machine/nvram.h"
#include "sound/flt_vol.h"
#include "sound/s14001a.h"
#include "screen.h"
#include "speaker.h"
#include "video/resnet.h"
namespace {
class berzerk_state : public driver_device
{
public:
berzerk_state(const machine_config &mconfig, device_type type, const char *tag) :
driver_device(mconfig, type, tag),
m_maincpu(*this, "maincpu"),
m_s14001a(*this, "speech"),
m_s14001a_volume(*this, "s14001a_volume"),
m_ls181_10c(*this, "ls181_10c"),
m_ls181_12c(*this, "ls181_12c"),
m_custom(*this, "exidy"),
m_screen(*this, "screen"),
m_videoram(*this, "videoram"),
m_colorram(*this, "colorram"),
m_led(*this, "led0")
{ }
void berzerk(machine_config &config);
void frenzy(machine_config &config);
void init_moonwarp();
protected:
virtual void machine_start() override;
virtual void machine_reset() override;
virtual void sound_reset() override;
virtual void video_start() override;
private:
required_device<cpu_device> m_maincpu;
required_device<s14001a_device> m_s14001a;
required_device<filter_volume_device> m_s14001a_volume;
required_device<ttl74181_device> m_ls181_10c;
required_device<ttl74181_device> m_ls181_12c;
required_device<exidy_sound_device> m_custom;
required_device<screen_device> m_screen;
required_shared_ptr<uint8_t> m_videoram;
required_shared_ptr<uint8_t> m_colorram;
output_finder<> m_led;
uint8_t m_magicram_control = 0;
uint8_t m_last_shift_data = 0;
uint8_t m_intercept = 0;
emu_timer *m_irq_timer = nullptr;
emu_timer *m_nmi_timer = nullptr;
uint8_t m_irq_enabled = 0;
uint8_t m_nmi_enabled = 0;
int m_p1_counter_74ls161 = 0;
int m_p1_direction = 0;
int m_p2_counter_74ls161 = 0;
int m_p2_direction = 0;
uint8_t led_on_r();
void led_on_w(uint8_t data);
uint8_t led_off_r();
void led_off_w(uint8_t data);
void irq_enable_w(uint8_t data);
void nmi_enable_w(uint8_t data);
void nmi_disable_w(uint8_t data);
uint8_t nmi_enable_r();
uint8_t nmi_disable_r();
void magicram_w(offs_t offset, uint8_t data);
void magicram_control_w(uint8_t data);
uint8_t intercept_v256_r();
void audio_w(offs_t offset, uint8_t data);
uint8_t audio_r(offs_t offset);
uint8_t moonwarp_p1_r();
uint8_t moonwarp_p2_r();
uint32_t screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
TIMER_CALLBACK_MEMBER(irq_callback);
TIMER_CALLBACK_MEMBER(nmi_callback);
void vpos_to_vsync_chain_counter(int vpos, uint8_t *counter, uint8_t *v256);
int vsync_chain_counter_to_vpos(uint8_t counter, uint8_t v256);
void create_irq_timer();
void start_irq_timer();
void create_nmi_timer();
void start_nmi_timer();
void get_pens(rgb_t *pens);
void berzerk_io_map(address_map &map);
void berzerk_map(address_map &map);
void frenzy_map(address_map &map);
};
#define MASTER_CLOCK (XTAL(10'000'000))
#define MAIN_CPU_CLOCK (MASTER_CLOCK / 4)
#define PIXEL_CLOCK (MASTER_CLOCK / 2)
#define S14001_CLOCK (MASTER_CLOCK / 4)
#define HTOTAL (0x140)
#define HBEND (0x000)
#define HBSTART (0x100)
#define VTOTAL (0x106)
#define VBEND (0x020)
#define VBSTART (0x100)
#define VCOUNTER_START_NO_VBLANK (0x020)
#define VCOUNTER_START_VBLANK (0x0da)
#define IRQS_PER_FRAME (2)
#define NMIS_PER_FRAME (8)
static const uint8_t irq_trigger_counts[IRQS_PER_FRAME] = { 0x80, 0xda };
static const uint8_t irq_trigger_v256s [IRQS_PER_FRAME] = { 0x00, 0x01 };
static const uint8_t nmi_trigger_counts[NMIS_PER_FRAME] = { 0x30, 0x50, 0x70, 0x90, 0xb0, 0xd0, 0xf0, 0xf0 };
static const uint8_t nmi_trigger_v256s [NMIS_PER_FRAME] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
/*************************************
*
* LED handling
*
*************************************/
uint8_t berzerk_state::led_on_r()
{
m_led = 1;
return 0;
}
void berzerk_state::led_on_w(uint8_t data)
{
m_led = 1;
}
uint8_t berzerk_state::led_off_r()
{
m_led = 0;
return 0;
}
void berzerk_state::led_off_w(uint8_t data)
{
m_led = 0;
}
/*************************************
*
* Convert to/from our line counting
* to the hardware's vsync chain
*
*************************************/
void berzerk_state::vpos_to_vsync_chain_counter(int vpos, uint8_t *counter, uint8_t *v256)
{
/* convert from a vertical position to the actual values on the vertical sync counters */
*v256 = ((vpos < VBEND) || (vpos >= VBSTART));
if (*v256)
{
int temp = vpos - VBSTART + VCOUNTER_START_VBLANK;
if (temp < 0)
*counter = temp + VTOTAL;
else
*counter = temp;
}
else
*counter = vpos;
}
int berzerk_state::vsync_chain_counter_to_vpos(uint8_t counter, uint8_t v256)
{
/* convert from the vertical sync counters to an actual vertical position */
int vpos;
if (v256)
{
vpos = counter - VCOUNTER_START_VBLANK + VBSTART;
if (vpos >= VTOTAL)
vpos = vpos - VTOTAL;
}
else
vpos = counter;
return vpos;
}
/*************************************
*
* IRQ generation
*
* There are two IRQ's per frame
*
*************************************/
void berzerk_state::irq_enable_w(uint8_t data)
{
m_irq_enabled = data & 0x01;
}
TIMER_CALLBACK_MEMBER(berzerk_state::irq_callback)
{
int irq_number = param;
uint8_t next_counter;
uint8_t next_v256;
int next_vpos;
int next_irq_number;
/* set the IRQ line if enabled */
if (m_irq_enabled)
m_maincpu->set_input_line_and_vector(0, HOLD_LINE, 0xfc); // Z80
/* set up for next interrupt */
next_irq_number = (irq_number + 1) % IRQS_PER_FRAME;
next_counter = irq_trigger_counts[next_irq_number];
next_v256 = irq_trigger_v256s[next_irq_number];
next_vpos = vsync_chain_counter_to_vpos(next_counter, next_v256);
m_irq_timer->adjust(m_screen->time_until_pos(next_vpos), next_irq_number);
}
void berzerk_state::create_irq_timer()
{
m_irq_timer = timer_alloc(FUNC(berzerk_state::irq_callback), this);
}
void berzerk_state::start_irq_timer()
{
int vpos = vsync_chain_counter_to_vpos(irq_trigger_counts[0], irq_trigger_v256s[0]);
m_irq_timer->adjust(m_screen->time_until_pos(vpos));
}
/*************************************
*
* NMI generation
*
* An NMI is asserted roughly every
* 32 scanlines when V16 clocks HI.
* The NMI is cleared 2 pixels later.
* Since this happens so quickly, I am
* not emulating it, just pulse
* the line instead.
*
*************************************/
void berzerk_state::nmi_enable_w(uint8_t data)
{
m_nmi_enabled = 1;
}
void berzerk_state::nmi_disable_w(uint8_t data)
{
m_nmi_enabled = 0;
}
uint8_t berzerk_state::nmi_enable_r()
{
m_nmi_enabled = 1;
return 0;
}
uint8_t berzerk_state::nmi_disable_r()
{
m_nmi_enabled = 0;
return 0;
}
TIMER_CALLBACK_MEMBER(berzerk_state::nmi_callback)
{
int nmi_number = param;
uint8_t next_counter;
uint8_t next_v256;
int next_vpos;
int next_nmi_number;
/* pulse the NMI line if enabled */
if (m_nmi_enabled)
m_maincpu->pulse_input_line(INPUT_LINE_NMI, attotime::zero);
/* set up for next interrupt */
next_nmi_number = (nmi_number + 1) % NMIS_PER_FRAME;
next_counter = nmi_trigger_counts[next_nmi_number];
next_v256 = nmi_trigger_v256s[next_nmi_number];
next_vpos = vsync_chain_counter_to_vpos(next_counter, next_v256);
m_nmi_timer->adjust(m_screen->time_until_pos(next_vpos), next_nmi_number);
}
void berzerk_state::create_nmi_timer()
{
m_nmi_timer = timer_alloc(FUNC(berzerk_state::nmi_callback), this);
}
void berzerk_state::start_nmi_timer()
{
int vpos = vsync_chain_counter_to_vpos(nmi_trigger_counts[0], nmi_trigger_v256s[0]);
m_nmi_timer->adjust(m_screen->time_until_pos(vpos));
}
/*************************************
*
* Machine setup
*
*************************************/
void berzerk_state::machine_start()
{
create_irq_timer();
create_nmi_timer();
m_led.resolve();
/* register for state saving */
save_item(NAME(m_magicram_control));
save_item(NAME(m_last_shift_data));
save_item(NAME(m_intercept));
save_item(NAME(m_irq_enabled));
save_item(NAME(m_nmi_enabled));
}
/*************************************
*
* Machine reset
*
*************************************/
void berzerk_state::machine_reset()
{
m_irq_enabled = 0;
m_nmi_enabled = 0;
m_led = 0;
m_magicram_control = 0;
start_irq_timer();
start_nmi_timer();
}
/*************************************
*
* Video system
*
*************************************/
void berzerk_state::video_start()
{
m_ls181_10c->mode_w(1);
m_ls181_12c->mode_w(1);
}
void berzerk_state::magicram_w(offs_t offset, uint8_t data)
{
uint8_t alu_output;
uint8_t current_video_data = m_videoram[offset];
/* shift data towards LSB. MSB bits are filled by data from last_shift_data.
The shifter consists of 5 74153 devices @ 7A, 8A, 9A, 10A and 11A,
followed by 4 more 153's at 11B, 10B, 9B and 8B, which optionally
reverse the order of the resulting bits */
uint8_t shift_flop_output = (((uint16_t)m_last_shift_data << 8) | data) >> (m_magicram_control & 0x07);
if (m_magicram_control & 0x08)
shift_flop_output = bitswap<8>(shift_flop_output, 0, 1, 2, 3, 4, 5, 6, 7);
/* collision detection - AND gate output goes to the K pin of the flip-flop,
while J is LO, therefore, it only resets, never sets */
if (shift_flop_output & current_video_data)
m_intercept = 0;
/* perform ALU step */
m_ls181_12c->input_a_w(shift_flop_output >> 0);
m_ls181_10c->input_a_w(shift_flop_output >> 4);
m_ls181_12c->input_b_w(current_video_data >> 0);
m_ls181_10c->input_b_w(current_video_data >> 4);
m_ls181_12c->select_w(m_magicram_control >> 4);
m_ls181_10c->select_w(m_magicram_control >> 4);
alu_output = m_ls181_10c->function_r() << 4 | m_ls181_12c->function_r();
m_videoram[offset] = alu_output ^ 0xff;
/* save data for next time */
m_last_shift_data = data & 0x7f;
}
void berzerk_state::magicram_control_w(uint8_t data)
{
/* save the control byte, clear the shift data latch,
and set the intercept flip-flop */
m_magicram_control = data;
m_last_shift_data = 0;
m_intercept = 1;
}
uint8_t berzerk_state::intercept_v256_r()
{
uint8_t counter;
uint8_t v256;
vpos_to_vsync_chain_counter(m_screen->vpos(), &counter, &v256);
return (m_intercept^1) << 7 | v256;
}
void berzerk_state::get_pens(rgb_t *pens)
{
static const int resistances_wg[] = { 750, 0 };
static const int resistances_el[] = { static_cast<int>(1.0 / ((1.0 / 750.0) + (1.0 / 360.0))), 0 };
double color_weights[2];
if (ioport("MONITOR_TYPE")->read() == 0)
compute_resistor_weights(0, 0xff, -1.0,
2, resistances_wg, color_weights, 0, 270,
2, resistances_wg, color_weights, 0, 270,
2, resistances_wg, color_weights, 0, 270);
else
compute_resistor_weights(0, 0xff, -1.0,
2, resistances_el, color_weights, 0, 270,
2, resistances_el, color_weights, 0, 270,
2, resistances_el, color_weights, 0, 270);
for (int color = 0; color < 0x10; color++)
{
uint8_t r_bit = (color >> 0) & 0x01;
uint8_t g_bit = (color >> 1) & 0x01;
uint8_t b_bit = (color >> 2) & 0x01;
uint8_t i_bit = (color >> 3) & 0x01;
uint8_t r = combine_weights(color_weights, r_bit & i_bit, r_bit);
uint8_t g = combine_weights(color_weights, g_bit & i_bit, g_bit);
uint8_t b = combine_weights(color_weights, b_bit & i_bit, b_bit);
pens[color] = rgb_t(r, g, b);
}
}
uint32_t berzerk_state::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
{
rgb_t pens[0x10];
get_pens(pens);
for (int offs = 0; offs < m_videoram.bytes(); offs++)
{
uint8_t data = m_videoram[offs];
uint8_t color = m_colorram[((offs >> 2) & 0x07e0) | (offs & 0x001f)];
uint8_t y = offs >> 5;
uint8_t x = offs << 3;
int i;
for (i = 0; i < 4; i++)
{
rgb_t pen = (data & 0x80) ? pens[color >> 4] : rgb_t::black();
bitmap.pix(y, x) = pen;
x++;
data <<= 1;
}
for (; i < 8; i++)
{
rgb_t pen = (data & 0x80) ? pens[color & 0x0f] : rgb_t::black();
bitmap.pix(y, x) = pen;
x++;
data <<= 1;
}
}
return 0;
}
/*************************************
*
* Audio system
*
*************************************/
void berzerk_state::audio_w(offs_t offset, uint8_t data)
{
switch (offset)
{
/* offset 4 writes to the S14001A */
case 4:
switch (data >> 6)
{
/* write data to the S14001 */
case 0:
m_s14001a->data_w(data & 0x3f);
/* clock the chip via a 555 timer */
m_s14001a->start_w(1);
m_s14001a->start_w(0);
break;
case 1:
{
/* volume - 0 appears to be inaudible */
m_s14001a_volume->set_gain((data >> 3 & 7) / 7.0);
/* clock control - the first LS161 divides the clock by 9 to 16, the 2nd by 8,
giving a final clock from 19.5kHz to 34.7kHz */
int clock_divisor = 16 - (data & 0x07);
m_s14001a->set_clock(S14001_CLOCK / clock_divisor / 8);
break;
}
default: break; /* 2 and 3 are not connected */
}
break;
/* offset 6 writes to the sfxcontrol latch */
case 6:
m_custom->sfxctrl_w(data >> 6, data);
break;
/* everything else writes to the 6840 */
default:
m_custom->sh6840_w(offset, data);
break;
}
}
uint8_t berzerk_state::audio_r(offs_t offset)
{
switch (offset)
{
/* offset 4 reads from the S14001A */
case 4:
return (m_s14001a->busy_r()) ? 0x00 : 0x40;
/* offset 6 is open bus */
case 6:
logerror("attempted read from berzerk audio reg 6 (sfxctrl)!\n");
return 0;
/* everything else reads from the 6840 */
default:
return m_custom->sh6840_r(offset);
}
}
void berzerk_state::sound_reset()
{
/* clears the flip-flop controlling the volume and freq on the speech chip */
audio_w(4, 0x40);
}
/*************************************
*
* Memory handlers
*
*************************************/
void berzerk_state::berzerk_map(address_map &map)
{
map(0x0000, 0x07ff).rom();
map(0x0800, 0x0bff).mirror(0x0400).ram().share("nvram");
map(0x1000, 0x3fff).rom();
map(0x4000, 0x5fff).ram().share("videoram");
map(0x6000, 0x7fff).ram().w(FUNC(berzerk_state::magicram_w)).share("videoram");
map(0x8000, 0x87ff).mirror(0x3800).ram().share("colorram");
map(0xc000, 0xffff).noprw();
}
void berzerk_state::frenzy_map(address_map &map)
{
map(0x0000, 0x3fff).rom();
map(0x4000, 0x5fff).ram().share("videoram");
map(0x6000, 0x7fff).ram().w(FUNC(berzerk_state::magicram_w)).share("videoram");
map(0x8000, 0x87ff).mirror(0x3800).ram().share("colorram");
map(0xc000, 0xcfff).rom();
map(0xf800, 0xfbff).mirror(0x0400).ram().share("nvram");
}
/*************************************
*
* Port handlers
*
*************************************/
void berzerk_state::berzerk_io_map(address_map &map)
{
map.global_mask(0xff);
map(0x00, 0x3f).noprw();
map(0x40, 0x47).rw(FUNC(berzerk_state::audio_r), FUNC(berzerk_state::audio_w));
map(0x48, 0x48).portr("P1").nopw();
map(0x49, 0x49).portr("SYSTEM").nopw();
map(0x4a, 0x4a).portr("P2").nopw();
map(0x4b, 0x4b).nopr().w(FUNC(berzerk_state::magicram_control_w));
map(0x4c, 0x4c).rw(FUNC(berzerk_state::nmi_enable_r), FUNC(berzerk_state::nmi_enable_w));
map(0x4d, 0x4d).rw(FUNC(berzerk_state::nmi_disable_r), FUNC(berzerk_state::nmi_disable_w));
map(0x4e, 0x4e).r(FUNC(berzerk_state::intercept_v256_r)).nopw(); // note reading from here should clear pending frame interrupts, see zfb-1.tiff 74ls74 at 3D pin 13 /CLR
map(0x4f, 0x4f).nopr().w(FUNC(berzerk_state::irq_enable_w));
map(0x50, 0x57).noprw(); /* second sound board, initialized but not used */
map(0x58, 0x5f).noprw();
map(0x60, 0x60).mirror(0x18).portr("F3").nopw();
map(0x61, 0x61).mirror(0x18).portr("F2").nopw();
map(0x62, 0x62).mirror(0x18).portr("F6").nopw();
map(0x63, 0x63).mirror(0x18).portr("F5").nopw();
map(0x64, 0x64).mirror(0x18).portr("F4").nopw();
map(0x65, 0x65).mirror(0x18).portr("SW2").nopw();
map(0x66, 0x66).mirror(0x18).rw(FUNC(berzerk_state::led_off_r), FUNC(berzerk_state::led_off_w));
map(0x67, 0x67).mirror(0x18).rw(FUNC(berzerk_state::led_on_r), FUNC(berzerk_state::led_on_w));
map(0x80, 0xff).noprw();
}
/*************************************
*
* Port definitions
*
*************************************/
#define BERZERK_COINAGE(CHUTE, DIPBANK) \
PORT_DIPNAME( 0x0f, 0x00, "Coin "#CHUTE ) PORT_DIPLOCATION(#DIPBANK":1,2,3,4") \
PORT_DIPSETTING( 0x09, DEF_STR( 2C_1C ) ) \
PORT_DIPSETTING( 0x0d, DEF_STR( 4C_3C ) ) \
PORT_DIPSETTING( 0x00, DEF_STR( 1C_1C ) ) \
PORT_DIPSETTING( 0x0e, DEF_STR( 4C_5C ) ) \
PORT_DIPSETTING( 0x0a, DEF_STR( 2C_3C ) ) \
PORT_DIPSETTING( 0x0f, DEF_STR( 4C_7C ) ) \
PORT_DIPSETTING( 0x01, DEF_STR( 1C_2C ) ) \
PORT_DIPSETTING( 0x0b, DEF_STR( 2C_5C ) ) \
PORT_DIPSETTING( 0x02, DEF_STR( 1C_3C ) ) \
PORT_DIPSETTING( 0x0c, DEF_STR( 2C_7C ) ) \
PORT_DIPSETTING( 0x03, DEF_STR( 1C_4C ) ) \
PORT_DIPSETTING( 0x04, DEF_STR( 1C_5C ) ) \
PORT_DIPSETTING( 0x05, DEF_STR( 1C_6C ) ) \
PORT_DIPSETTING( 0x06, DEF_STR( 1C_7C ) ) \
PORT_DIPSETTING( 0x07, "1 Coin/10 Credits" ) \
PORT_DIPSETTING( 0x08, "1 Coin/14 Credits" )
static INPUT_PORTS_START( joystick ) // used on all games except moonwarp
PORT_START("P1")
PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY
PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY
PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY
PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY
PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 )
PORT_BIT( 0xe0, IP_ACTIVE_LOW, IPT_UNUSED )
PORT_START("P2")
PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_COCKTAIL
PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_COCKTAIL
PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_COCKTAIL
PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_COCKTAIL
PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
PORT_BIT( 0x60, IP_ACTIVE_LOW, IPT_UNUSED )
PORT_DIPNAME( 0x80, 0x80, DEF_STR( Cabinet ) )
PORT_DIPSETTING( 0x80, DEF_STR( Upright ) )
PORT_DIPSETTING( 0x00, DEF_STR( Cocktail ) )
INPUT_PORTS_END
static INPUT_PORTS_START( common ) // used on all games
PORT_START("SYSTEM")
PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_START1 )
PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_START2 )
PORT_BIT( 0x1c, IP_ACTIVE_LOW, IPT_UNUSED )
PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_COIN3 )
PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_COIN2 )
PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_COIN1 )
/* fake port for monitor type */
PORT_START("MONITOR_TYPE")
PORT_CONFNAME( 0x01, 0x00, "Monitor Type" )
PORT_CONFSETTING( 0x00, "Wells-Gardner" )
PORT_CONFSETTING( 0x01, "Electrohome" )
PORT_BIT( 0xfe, IP_ACTIVE_HIGH, IPT_UNUSED )
PORT_START("SW2")
/* port for the 'bookkeeping reset' and 'bookkeeping' buttons;
* The 'bookkeeping reset' button is an actual button on the zpu-1000 and
* zpu-1001 pcbs, labeled 'S2' or 'SW2'. It is wired to bit 0.
* * pressing it while high scores are displayed will give a free game
* without adding any coin info to the bookkeeping info in nvram.
* The 'bookkeeping' button is wired to the control panel, usually hidden
* underneath or only accessible through the coin door. Wired to bit 7.
* * It displays various bookkeeping statistics when pressed sequentially.
* Pressing P1 fire (according to the manual) when stats are displayed
* will clear the stat shown on screen.
*/
PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_SERVICE1 ) PORT_NAME("Free Game (not logged in bookkeeping)")
PORT_BIT( 0x7e, IP_ACTIVE_LOW, IPT_UNUSED )
PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_SERVICE2 ) PORT_NAME("Bookkeeping") PORT_CODE(KEYCODE_F1)
INPUT_PORTS_END
static INPUT_PORTS_START( berzerk )
PORT_INCLUDE( joystick )
PORT_INCLUDE( common )
PORT_START("F2")
PORT_DIPNAME( 0x03, 0x00, "Color Test" ) PORT_CODE(KEYCODE_F5) PORT_TOGGLE PORT_DIPLOCATION("F2:1,2")
PORT_DIPSETTING( 0x00, DEF_STR( Off ) )
PORT_DIPSETTING( 0x03, DEF_STR( On ) )
PORT_BIT( 0x3c, IP_ACTIVE_LOW, IPT_UNUSED )
PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("F2:7,8")
PORT_DIPSETTING( 0xc0, "5000 and 10000" )
PORT_DIPSETTING( 0x40, "5000" )
PORT_DIPSETTING( 0x80, "10000" )
PORT_DIPSETTING( 0x00, DEF_STR( None ) )
PORT_START("F3")
PORT_DIPNAME( 0x01, 0x00, "Input Test Mode" ) PORT_CODE(KEYCODE_F2) PORT_TOGGLE PORT_DIPLOCATION("F3:1")
PORT_DIPSETTING( 0x00, DEF_STR( Off ) )
PORT_DIPSETTING( 0x01, DEF_STR( On ) )
PORT_DIPNAME( 0x02, 0x00, "Crosshair Pattern" ) PORT_CODE(KEYCODE_F4) PORT_TOGGLE PORT_DIPLOCATION("F3:2")
PORT_DIPSETTING( 0x00, DEF_STR( Off ) )
PORT_DIPSETTING( 0x02, DEF_STR( On ) )
PORT_BIT( 0x3c, IP_ACTIVE_LOW, IPT_UNUSED )
PORT_DIPNAME( 0xc0, 0x00, DEF_STR( Language ) ) PORT_DIPLOCATION("F3:7,8")
PORT_DIPSETTING( 0x00, DEF_STR( English ) )
PORT_DIPSETTING( 0x40, DEF_STR( German ) )
PORT_DIPSETTING( 0x80, DEF_STR( French ) )
PORT_DIPSETTING( 0xc0, DEF_STR( Spanish ) )
PORT_START("F4")
BERZERK_COINAGE(1, F4)
PORT_BIT( 0xf0, IP_ACTIVE_LOW, IPT_UNUSED )
PORT_START("F5")
BERZERK_COINAGE(2, F5)
PORT_BIT( 0xf0, IP_ACTIVE_LOW, IPT_UNUSED )
PORT_START("F6")
BERZERK_COINAGE(3, F6)
PORT_BIT( 0xf0, IP_ACTIVE_LOW, IPT_UNUSED )
INPUT_PORTS_END
// this set has French speech ROMs, so default the language to French
static INPUT_PORTS_START( berzerkf )
PORT_INCLUDE( berzerk )
PORT_MODIFY("F3")
PORT_DIPNAME( 0xc0, 0x80, DEF_STR( Language ) ) PORT_DIPLOCATION("F3:7,8")
PORT_DIPSETTING( 0x00, DEF_STR( English ) )
PORT_DIPSETTING( 0x40, DEF_STR( German ) )
PORT_DIPSETTING( 0x80, DEF_STR( French ) )
PORT_DIPSETTING( 0xc0, DEF_STR( Spanish ) )
INPUT_PORTS_END
// this set has German speech ROMs, so default the language to German
static INPUT_PORTS_START( berzerkg )
PORT_INCLUDE( berzerk )
PORT_MODIFY("F3")
PORT_DIPNAME( 0xc0, 0x40, DEF_STR( Language ) ) PORT_DIPLOCATION("F3:7,8")
PORT_DIPSETTING( 0x00, DEF_STR( English ) )
PORT_DIPSETTING( 0x40, DEF_STR( German ) )
PORT_DIPSETTING( 0x80, DEF_STR( French ) )
PORT_DIPSETTING( 0xc0, DEF_STR( Spanish ) )
INPUT_PORTS_END
// this set has a Spanish speech ROM, so default the language to Spanish
static INPUT_PORTS_START( berzerks )
PORT_INCLUDE( berzerk )
PORT_MODIFY("F3")
PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Language ) ) PORT_DIPLOCATION("F3:7,8")
PORT_DIPSETTING( 0x00, DEF_STR( English ) )
PORT_DIPSETTING( 0x40, DEF_STR( German ) )
PORT_DIPSETTING( 0x80, DEF_STR( French ) )
PORT_DIPSETTING( 0xc0, DEF_STR( Spanish ) )
INPUT_PORTS_END
static INPUT_PORTS_START( frenzy )
PORT_INCLUDE( joystick )
PORT_INCLUDE( common )
PORT_MODIFY("SYSTEM")
PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED ) // frenzy lacks coin 3
PORT_START("F2")
/* Bit 0 does some more hardware tests. According to the manual, both bit 0 & 1 must be:
- ON for Signature Analysis (S.A.)
- OFF for game operation */
PORT_DIPNAME( 0x03, 0x00, "Hardware Tests" ) PORT_DIPLOCATION("F2:1,2")
PORT_DIPSETTING( 0x00, DEF_STR( Off ) )
PORT_DIPSETTING( 0x01, "Color test" )
PORT_DIPSETTING( 0x02, DEF_STR( Unknown ) )
PORT_DIPSETTING( 0x03, "Signature Analysis" )
PORT_DIPNAME( 0x04, 0x00, "Input Test Mode" ) PORT_CODE(KEYCODE_F2) PORT_TOGGLE PORT_DIPLOCATION("F2:3")
PORT_DIPSETTING( 0x00, DEF_STR( Off ) )
PORT_DIPSETTING( 0x04, DEF_STR( On ) )
PORT_DIPNAME( 0x08, 0x00, "Crosshair Pattern" ) PORT_CODE(KEYCODE_F4) PORT_TOGGLE PORT_DIPLOCATION("F2:4")
PORT_DIPSETTING( 0x00, DEF_STR( Off ) )
PORT_DIPSETTING( 0x08, DEF_STR( On ) )
PORT_BIT( 0xf0, IP_ACTIVE_HIGH, IPT_UNUSED ) PORT_DIPLOCATION("F2:5,6,7,8")
PORT_START("F3")
PORT_DIPNAME( 0x0f, 0x03, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("F3:1,2,3,4")
PORT_DIPSETTING( 0x01, "1000" )
PORT_DIPSETTING( 0x02, "2000" )
PORT_DIPSETTING( 0x03, "3000" )
PORT_DIPSETTING( 0x04, "4000" )
PORT_DIPSETTING( 0x05, "5000" )
PORT_DIPSETTING( 0x06, "6000" )
PORT_DIPSETTING( 0x07, "7000" )
PORT_DIPSETTING( 0x08, "8000" )
PORT_DIPSETTING( 0x09, "9000" )
PORT_DIPSETTING( 0x0a, "10000" )
PORT_DIPSETTING( 0x0b, "11000" )
PORT_DIPSETTING( 0x0c, "12000" )
PORT_DIPSETTING( 0x0d, "13000" )
PORT_DIPSETTING( 0x0e, "14000" )
PORT_DIPSETTING( 0x0f, "15000" )
PORT_DIPSETTING( 0x00, DEF_STR( None ) )
PORT_BIT( 0x30, IP_ACTIVE_HIGH, IPT_UNUSED ) PORT_DIPLOCATION("F3:5,6")
PORT_DIPNAME( 0xc0, 0x00, DEF_STR( Language ) ) PORT_DIPLOCATION("F3:7,8")
PORT_DIPSETTING( 0x00, DEF_STR( English ) )
PORT_DIPSETTING( 0x40, DEF_STR( German ) )
PORT_DIPSETTING( 0x80, DEF_STR( French ) )
PORT_DIPSETTING( 0xc0, DEF_STR( Spanish ) )
/* The following 3 ports use all 8 bits, but I didn't feel like adding all 256 values :-) */
PORT_START("F4")
PORT_DIPNAME( 0xff, 0x01, "Coin Multiplier" ) PORT_DIPLOCATION("F4:1,2,3,4,5,6,7,8")
PORT_DIPSETTING( 0x00, DEF_STR( Free_Play ) )
PORT_DIPSETTING( 0x01, "1" )
PORT_DIPSETTING( 0x02, "2" )
PORT_DIPSETTING( 0x03, "3" )
PORT_DIPSETTING( 0x04, "4" )
PORT_DIPSETTING( 0x05, "5" )
PORT_DIPSETTING( 0x06, "6" )
PORT_DIPSETTING( 0x07, "7" )
PORT_DIPSETTING( 0x08, "8" )
PORT_DIPSETTING( 0x09, "9" )
PORT_DIPSETTING( 0x0a, "10" )
PORT_DIPSETTING( 0x0b, "11" )
PORT_DIPSETTING( 0x0c, "12" )
PORT_DIPSETTING( 0x0d, "13" )
PORT_DIPSETTING( 0x0e, "14" )
PORT_DIPSETTING( 0x0f, "15" )
PORT_DIPSETTING( 0xff, "255" )
PORT_START("F5")
PORT_DIPNAME( 0xff, 0x01, "Coins/Credit A" ) PORT_DIPLOCATION("F5:1,2,3,4,5,6,7,8")
PORT_DIPSETTING( 0x00, "0 (invalid)" ) // Can't insert coins
PORT_DIPSETTING( 0x01, "1" )
PORT_DIPSETTING( 0x02, "2" )
PORT_DIPSETTING( 0x03, "3" )
PORT_DIPSETTING( 0x04, "4" )
PORT_DIPSETTING( 0x05, "5" )
PORT_DIPSETTING( 0x06, "6" )
PORT_DIPSETTING( 0x07, "7" )
PORT_DIPSETTING( 0x08, "8" )
PORT_DIPSETTING( 0x09, "9" )
PORT_DIPSETTING( 0x0a, "10" )
PORT_DIPSETTING( 0x0b, "11" )
PORT_DIPSETTING( 0x0c, "12" )
PORT_DIPSETTING( 0x0d, "13" )
PORT_DIPSETTING( 0x0e, "14" )
PORT_DIPSETTING( 0x0f, "15" )
PORT_DIPSETTING( 0xff, "255" )
PORT_START("F6")
PORT_DIPNAME( 0xff, 0x01, "Coins/Credit B" ) PORT_DIPLOCATION("F6:1,2,3,4,5,6,7,8")
PORT_DIPSETTING( 0x00, "0 (invalid)" ) // Can't insert coins
PORT_DIPSETTING( 0x01, "1" )
PORT_DIPSETTING( 0x02, "2" )
PORT_DIPSETTING( 0x03, "3" )
PORT_DIPSETTING( 0x04, "4" )
PORT_DIPSETTING( 0x05, "5" )
PORT_DIPSETTING( 0x06, "6" )
PORT_DIPSETTING( 0x07, "7" )
PORT_DIPSETTING( 0x08, "8" )
PORT_DIPSETTING( 0x09, "9" )
PORT_DIPSETTING( 0x0a, "10" )
PORT_DIPSETTING( 0x0b, "11" )
PORT_DIPSETTING( 0x0c, "12" )
PORT_DIPSETTING( 0x0d, "13" )
PORT_DIPSETTING( 0x0e, "14" )
PORT_DIPSETTING( 0x0f, "15" )
PORT_DIPSETTING( 0xff, "255" )
INPUT_PORTS_END
uint8_t berzerk_state::moonwarp_p1_r()
{
// This seems to be the same type of dial as the later 'moon war 2' set uses
// see http://www.cityofberwyn.com/schematics/stern/MoonWar_opto.tiff for schematic
// I.e. a 74ls161 counts from 0 to 15 which is the absolute number of bars passed on the quadrature
// one difference is it lacks the strobe input (does it?), which if not active causes
// the dial input to go open bus. This is used in moon war 2 to switch between player 1
// and player 2 dials, which share a single port. moonwarp uses separate ports for the dials.
int8_t dialread = ioport("P1_DIAL")->read();
uint8_t ret;