~ubuntu-branches/debian/sid/mame/sid

« back to all changes in this revision

Viewing changes to src/mame/drivers/berzerk.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach, Emmanuel Kasper, Jordi Mallach
  • Date: 2012-06-05 20:02:23 UTC
  • mfrom: (0.3.1) (0.1.4)
  • Revision ID: package-import@ubuntu.com-20120605200223-gnlpogjrg6oqe9md
Tags: 0.146-1
[ Emmanuel Kasper ]
* New upstream release
* Drop patch to fix man pages section and patches to link with flac 
  and jpeg system lib: all this has been pushed upstream by Cesare Falco
* Add DM-Upload-Allowed: yes field.

[ Jordi Mallach ]
* Create a "gnu" TARGETOS stanza that defines NO_AFFINITY_NP.
* Stop setting TARGETOS to "unix" in d/rules. It should be autodetected,
  and set to the appropriate value.
* mame_manpage_section.patch: Change mame's manpage section to 6 (games),
  in the TH declaration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
{
22
22
public:
23
23
        berzerk_state(const machine_config &mconfig, device_type type, const char *tag)
24
 
                : driver_device(mconfig, type, tag) { }
 
24
                : driver_device(mconfig, type, tag) ,
 
25
                m_videoram(*this, "videoram"),
 
26
                m_colorram(*this, "colorram"){ }
25
27
 
26
 
        UINT8 *m_videoram;
27
 
        size_t m_videoram_size;
28
 
        UINT8 *m_colorram;
 
28
        required_shared_ptr<UINT8> m_videoram;
 
29
        required_shared_ptr<UINT8> m_colorram;
29
30
        UINT8 m_magicram_control;
30
31
        UINT8 m_last_shift_data;
31
32
        UINT8 m_intercept;
37
38
        int m_p1_direction;
38
39
        int m_p2_counter_74ls161;
39
40
        int m_p2_direction;
 
41
        DECLARE_READ8_MEMBER(led_on_r);
 
42
        DECLARE_WRITE8_MEMBER(led_on_w);
 
43
        DECLARE_READ8_MEMBER(led_off_r);
 
44
        DECLARE_WRITE8_MEMBER(led_off_w);
 
45
        DECLARE_WRITE8_MEMBER(irq_enable_w);
 
46
        DECLARE_WRITE8_MEMBER(nmi_enable_w);
 
47
        DECLARE_WRITE8_MEMBER(nmi_disable_w);
 
48
        DECLARE_READ8_MEMBER(nmi_enable_r);
 
49
        DECLARE_READ8_MEMBER(nmi_disable_r);
 
50
        DECLARE_WRITE8_MEMBER(magicram_w);
 
51
        DECLARE_WRITE8_MEMBER(magicram_control_w);
 
52
        DECLARE_READ8_MEMBER(intercept_v256_r);
 
53
        DECLARE_WRITE8_MEMBER(berzerk_audio_w);
 
54
        DECLARE_READ8_MEMBER(berzerk_audio_r);
 
55
        DECLARE_READ8_MEMBER(moonwarp_p1_r);
 
56
        DECLARE_READ8_MEMBER(moonwarp_p2_r);
40
57
};
41
58
 
42
59
 
70
87
 *
71
88
 *************************************/
72
89
 
73
 
static READ8_HANDLER( led_on_r )
74
 
{
75
 
        set_led_status(space->machine(), 0, 1);
76
 
 
77
 
        return 0;
78
 
}
79
 
 
80
 
 
81
 
static WRITE8_HANDLER( led_on_w )
82
 
{
83
 
        set_led_status(space->machine(), 0, 1);
84
 
}
85
 
 
86
 
 
87
 
static READ8_HANDLER( led_off_r )
88
 
{
89
 
        set_led_status(space->machine(), 0, 0);
90
 
 
91
 
        return 0;
92
 
}
93
 
 
94
 
 
95
 
static WRITE8_HANDLER( led_off_w )
96
 
{
97
 
        set_led_status(space->machine(), 0, 0);
 
90
READ8_MEMBER(berzerk_state::led_on_r)
 
91
{
 
92
        set_led_status(machine(), 0, 1);
 
93
 
 
94
        return 0;
 
95
}
 
96
 
 
97
 
 
98
WRITE8_MEMBER(berzerk_state::led_on_w)
 
99
{
 
100
        set_led_status(machine(), 0, 1);
 
101
}
 
102
 
 
103
 
 
104
READ8_MEMBER(berzerk_state::led_off_r)
 
105
{
 
106
        set_led_status(machine(), 0, 0);
 
107
 
 
108
        return 0;
 
109
}
 
110
 
 
111
 
 
112
WRITE8_MEMBER(berzerk_state::led_off_w)
 
113
{
 
114
        set_led_status(machine(), 0, 0);
98
115
}
99
116
 
100
117
 
153
170
 *
154
171
 *************************************/
155
172
 
156
 
static WRITE8_HANDLER( irq_enable_w )
 
173
WRITE8_MEMBER(berzerk_state::irq_enable_w)
157
174
{
158
 
        berzerk_state *state = space->machine().driver_data<berzerk_state>();
159
 
        state->m_irq_enabled = data & 0x01;
 
175
        m_irq_enabled = data & 0x01;
160
176
}
161
177
 
162
178
 
212
228
 *
213
229
 *************************************/
214
230
 
215
 
static WRITE8_HANDLER( nmi_enable_w )
216
 
{
217
 
        berzerk_state *state = space->machine().driver_data<berzerk_state>();
218
 
        state->m_nmi_enabled = 1;
219
 
}
220
 
 
221
 
 
222
 
static WRITE8_HANDLER( nmi_disable_w )
223
 
{
224
 
        berzerk_state *state = space->machine().driver_data<berzerk_state>();
225
 
        state->m_nmi_enabled = 0;
226
 
}
227
 
 
228
 
 
229
 
static READ8_HANDLER( nmi_enable_r )
230
 
{
231
 
        berzerk_state *state = space->machine().driver_data<berzerk_state>();
232
 
        state->m_nmi_enabled = 1;
 
231
WRITE8_MEMBER(berzerk_state::nmi_enable_w)
 
232
{
 
233
        m_nmi_enabled = 1;
 
234
}
 
235
 
 
236
 
 
237
WRITE8_MEMBER(berzerk_state::nmi_disable_w)
 
238
{
 
239
        m_nmi_enabled = 0;
 
240
}
 
241
 
 
242
 
 
243
READ8_MEMBER(berzerk_state::nmi_enable_r)
 
244
{
 
245
        m_nmi_enabled = 1;
233
246
 
234
247
        return 0;
235
248
}
236
249
 
237
250
 
238
 
static READ8_HANDLER( nmi_disable_r )
 
251
READ8_MEMBER(berzerk_state::nmi_disable_r)
239
252
{
240
 
        berzerk_state *state = space->machine().driver_data<berzerk_state>();
241
 
        state->m_nmi_enabled = 0;
 
253
        m_nmi_enabled = 0;
242
254
 
243
255
        return 0;
244
256
}
347
359
}
348
360
 
349
361
 
350
 
static WRITE8_HANDLER( magicram_w )
 
362
WRITE8_MEMBER(berzerk_state::magicram_w)
351
363
{
352
 
        berzerk_state *state = space->machine().driver_data<berzerk_state>();
353
364
        UINT8 alu_output;
354
365
 
355
 
        UINT8 current_video_data = state->m_videoram[offset];
 
366
        UINT8 current_video_data = m_videoram[offset];
356
367
 
357
368
        /* shift data towards LSB.  MSB bits are filled by data from last_shift_data.
358
369
       The shifter consists of 5 74153 devices @ 7A, 8A, 9A, 10A and 11A,
359
370
       followed by 4 more 153's at 11B, 10B, 9B and 8B, which optionally
360
371
       reverse the order of the resulting bits */
361
 
        UINT8 shift_flop_output = (((UINT16)state->m_last_shift_data << 8) | data) >> (state->m_magicram_control & 0x07);
 
372
        UINT8 shift_flop_output = (((UINT16)m_last_shift_data << 8) | data) >> (m_magicram_control & 0x07);
362
373
 
363
 
        if (state->m_magicram_control & 0x08)
 
374
        if (m_magicram_control & 0x08)
364
375
                shift_flop_output = BITSWAP8(shift_flop_output, 0, 1, 2, 3, 4, 5, 6, 7);
365
376
 
366
377
        /* collision detection - AND gate output goes to the K pin of the flip-flop,
367
378
       while J is LO, therefore, it only resets, never sets */
368
379
        if (shift_flop_output & current_video_data)
369
 
                state->m_intercept = 0;
 
380
                m_intercept = 0;
370
381
 
371
382
        /* perform ALU step */
372
383
        TTL74181_write(LS181_12C, TTL74181_INPUT_A0, 4, shift_flop_output & 0x0f);
373
384
        TTL74181_write(LS181_10C, TTL74181_INPUT_A0, 4, shift_flop_output >> 4);
374
385
        TTL74181_write(LS181_12C, TTL74181_INPUT_B0, 4, current_video_data & 0x0f);
375
386
        TTL74181_write(LS181_10C, TTL74181_INPUT_B0, 4, current_video_data >> 4);
376
 
        TTL74181_write(LS181_12C, TTL74181_INPUT_S0, 4, state->m_magicram_control >> 4);
377
 
        TTL74181_write(LS181_10C, TTL74181_INPUT_S0, 4, state->m_magicram_control >> 4);
 
387
        TTL74181_write(LS181_12C, TTL74181_INPUT_S0, 4, m_magicram_control >> 4);
 
388
        TTL74181_write(LS181_10C, TTL74181_INPUT_S0, 4, m_magicram_control >> 4);
378
389
 
379
390
        alu_output = (TTL74181_read(LS181_10C, TTL74181_OUTPUT_F0, 4) << 4) |
380
391
                                 (TTL74181_read(LS181_12C, TTL74181_OUTPUT_F0, 4) << 0);
381
392
 
382
 
        state->m_videoram[offset] = alu_output ^ 0xff;
 
393
        m_videoram[offset] = alu_output ^ 0xff;
383
394
 
384
395
        /* save data for next time */
385
 
        state->m_last_shift_data = data & 0x7f;
 
396
        m_last_shift_data = data & 0x7f;
386
397
}
387
398
 
388
399
 
389
 
static WRITE8_HANDLER( magicram_control_w )
 
400
WRITE8_MEMBER(berzerk_state::magicram_control_w)
390
401
{
391
 
        berzerk_state *state = space->machine().driver_data<berzerk_state>();
392
402
        /* save the control byte, clear the shift data latch,
393
403
       and set the intercept flip-flop */
394
 
        state->m_magicram_control = data;
395
 
        state->m_last_shift_data = 0;
396
 
        state->m_intercept = 1;
 
404
        m_magicram_control = data;
 
405
        m_last_shift_data = 0;
 
406
        m_intercept = 1;
397
407
}
398
408
 
399
409
 
400
 
static READ8_HANDLER( intercept_v256_r )
 
410
READ8_MEMBER(berzerk_state::intercept_v256_r)
401
411
{
402
 
        berzerk_state *state = space->machine().driver_data<berzerk_state>();
403
412
        UINT8 counter;
404
413
        UINT8 v256;
405
414
 
406
 
        vpos_to_vsync_chain_counter(space->machine().primary_screen->vpos(), &counter, &v256);
 
415
        vpos_to_vsync_chain_counter(machine().primary_screen->vpos(), &counter, &v256);
407
416
 
408
 
        return (!state->m_intercept << 7) | v256;
 
417
        return (!m_intercept << 7) | v256;
409
418
}
410
419
 
411
420
 
417
426
        int color;
418
427
        double color_weights[2];
419
428
 
420
 
        if (input_port_read(machine, MONITOR_TYPE_PORT_TAG) == 0)
 
429
        if (machine.root_device().ioport(MONITOR_TYPE_PORT_TAG)->read() == 0)
421
430
                compute_resistor_weights(0, 0xff, -1.0,
422
431
                                                                 2, resistances_wg, color_weights, 0, 270,
423
432
                                                                 2, resistances_wg, color_weights, 0, 270,
452
461
 
453
462
        get_pens(screen.machine(), pens);
454
463
 
455
 
        for (offs = 0; offs < state->m_videoram_size; offs++)
 
464
        for (offs = 0; offs < state->m_videoram.bytes(); offs++)
456
465
        {
457
466
                int i;
458
467
 
492
501
 *
493
502
 *************************************/
494
503
 
495
 
static WRITE8_HANDLER( berzerk_audio_w )
 
504
WRITE8_MEMBER(berzerk_state::berzerk_audio_w)
496
505
{
497
506
        device_t *device;
498
507
        int clock_divisor;
501
510
        {
502
511
        /* offset 4 writes to the S14001A */
503
512
        case 4:
504
 
                device = space->machine().device("speech");
 
513
                device = machine().device("speech");
505
514
                switch (data >> 6)
506
515
                {
507
516
                /* write data to the S14001 */
519
528
                        break;
520
529
 
521
530
                case 1:
522
 
                        device = space->machine().device("speech");
 
531
                        device = machine().device("speech");
523
532
                        /* volume */
524
533
                        s14001a_set_volume(device, ((data & 0x38) >> 3) + 1);
525
534
 
537
546
 
538
547
        /* offset 6 writes to the sfxcontrol latch */
539
548
        case 6:
540
 
                exidy_sfxctrl_w(space->machine().device("exidy"), data >> 6, data);
 
549
                exidy_sfxctrl_w(machine().device("exidy"), data >> 6, data);
541
550
                break;
542
551
 
543
552
        /* everything else writes to the 6840 */
544
553
        default:
545
 
                exidy_sh6840_w(space->machine().device("exidy"), offset, data);
 
554
                exidy_sh6840_w(machine().device("exidy"), offset, data);
546
555
                break;
547
556
 
548
557
        }
549
558
}
550
559
 
551
560
 
552
 
static READ8_HANDLER( berzerk_audio_r )
 
561
READ8_MEMBER(berzerk_state::berzerk_audio_r)
553
562
{
554
 
        device_t *device = space->machine().device("speech");
 
563
        device_t *device = machine().device("speech");
555
564
        switch (offset)
556
565
        {
557
566
        /* offset 4 reads from the S14001A */
563
572
                return 0;
564
573
        /* everything else reads from the 6840 */
565
574
        default:
566
 
                return exidy_sh6840_r(space->machine().device("exidy"), offset);
 
575
                return exidy_sh6840_r(machine().device("exidy"), offset);
567
576
        }
568
577
}
569
578
 
572
581
static SOUND_RESET(berzerk)
573
582
{
574
583
        address_space *space = machine.device("maincpu")->memory().space(AS_IO);
 
584
        berzerk_state *state = machine.driver_data<berzerk_state>();
575
585
        /* clears the flip-flop controlling the volume and freq on the speech chip */
576
 
        berzerk_audio_w(space, 4, 0x40);
 
586
        state->berzerk_audio_w(*space, 4, 0x40);
577
587
}
578
588
 
579
589
 
584
594
 *
585
595
 *************************************/
586
596
 
587
 
static ADDRESS_MAP_START( berzerk_map, AS_PROGRAM, 8 )
 
597
static ADDRESS_MAP_START( berzerk_map, AS_PROGRAM, 8, berzerk_state )
588
598
        AM_RANGE(0x0000, 0x07ff) AM_ROM
589
599
        AM_RANGE(0x0800, 0x0bff) AM_MIRROR(0x0400) AM_RAM AM_SHARE("nvram")
590
600
        AM_RANGE(0x1000, 0x3fff) AM_ROM
591
 
        AM_RANGE(0x4000, 0x5fff) AM_RAM AM_BASE_MEMBER(berzerk_state, m_videoram) AM_SIZE_MEMBER(berzerk_state, m_videoram_size) AM_SHARE("share1")
592
 
        AM_RANGE(0x6000, 0x7fff) AM_RAM_WRITE(magicram_w) AM_SHARE("share1")
593
 
        AM_RANGE(0x8000, 0x87ff) AM_MIRROR(0x3800) AM_RAM AM_BASE_MEMBER(berzerk_state, m_colorram)
 
601
        AM_RANGE(0x4000, 0x5fff) AM_RAM AM_SHARE("videoram")
 
602
        AM_RANGE(0x6000, 0x7fff) AM_RAM_WRITE(magicram_w) AM_SHARE("videoram")
 
603
        AM_RANGE(0x8000, 0x87ff) AM_MIRROR(0x3800) AM_RAM AM_SHARE("colorram")
594
604
        AM_RANGE(0xc000, 0xffff) AM_NOP
595
605
ADDRESS_MAP_END
596
606
 
597
607
 
598
 
static ADDRESS_MAP_START( frenzy_map, AS_PROGRAM, 8 )
 
608
static ADDRESS_MAP_START( frenzy_map, AS_PROGRAM, 8, berzerk_state )
599
609
        AM_RANGE(0x0000, 0x3fff) AM_ROM
600
 
        AM_RANGE(0x4000, 0x5fff) AM_RAM AM_BASE_MEMBER(berzerk_state, m_videoram) AM_SIZE_MEMBER(berzerk_state, m_videoram_size) AM_SHARE("share1")
601
 
        AM_RANGE(0x6000, 0x7fff) AM_RAM_WRITE(magicram_w) AM_SHARE("share1")
602
 
        AM_RANGE(0x8000, 0x87ff) AM_MIRROR(0x3800) AM_RAM AM_BASE_MEMBER(berzerk_state, m_colorram)
 
610
        AM_RANGE(0x4000, 0x5fff) AM_RAM AM_SHARE("videoram")
 
611
        AM_RANGE(0x6000, 0x7fff) AM_RAM_WRITE(magicram_w) AM_SHARE("videoram")
 
612
        AM_RANGE(0x8000, 0x87ff) AM_MIRROR(0x3800) AM_RAM AM_SHARE("colorram")
603
613
        AM_RANGE(0xc000, 0xcfff) AM_ROM
604
614
        AM_RANGE(0xf800, 0xfbff) AM_MIRROR(0x0400) AM_RAM AM_SHARE("nvram")
605
615
ADDRESS_MAP_END
612
622
 *
613
623
 *************************************/
614
624
 
615
 
static ADDRESS_MAP_START( berzerk_io_map, AS_IO, 8 )
 
625
static ADDRESS_MAP_START( berzerk_io_map, AS_IO, 8, berzerk_state )
616
626
        ADDRESS_MAP_GLOBAL_MASK(0xff)
617
627
        AM_RANGE(0x00, 0x3f) AM_NOP
618
628
        AM_RANGE(0x40, 0x47) AM_READWRITE(berzerk_audio_r, berzerk_audio_w)
885
895
        PORT_DIPSETTING(    0xff, "255" )
886
896
INPUT_PORTS_END
887
897
 
888
 
static READ8_HANDLER( moonwarp_p1_r )
 
898
READ8_MEMBER(berzerk_state::moonwarp_p1_r)
889
899
{
890
 
        berzerk_state *state = space->machine().driver_data<berzerk_state>();
891
900
        // This seems to be the same type of dial as the later 'moon war 2' set uses
892
901
        // see http://www.cityofberwyn.com/schematics/stern/MoonWar_opto.tiff for schematic
893
902
        // I.e. a 74ls161 counts from 0 to 15 which is the absolute number of bars passed on the quadrature
894
903
        // one difference is it lacks the strobe input (does it?), which if not active causes
895
904
        // the dial input to go open bus. This is used in moon war 2 to switch between player 1
896
905
        // and player 2 dials, which share a single port. moonwarp uses separate ports for the dials.
897
 
        signed char dialread = input_port_read(space->machine(),"P1_DIAL");
 
906
        signed char dialread = ioport("P1_DIAL")->read();
898
907
        UINT8 ret;
899
 
        UINT8 buttons = (input_port_read(space->machine(),"P1")&0xe0);
900
 
        if (dialread < 0) state->m_p1_direction = 0;
901
 
        else if (dialread > 0) state->m_p1_direction = 0x10;
902
 
        state->m_p1_counter_74ls161 += abs(dialread);
903
 
        state->m_p1_counter_74ls161 &= 0xf;
904
 
        ret = state->m_p1_counter_74ls161 | state->m_p1_direction | buttons;
905
 
        //fprintf(stderr, "dialread1: %02x, p1_counter_74ls161: %02x, spinner ret is %02x\n", dialread, state->m_p1_counter_74ls161, ret);
 
908
        UINT8 buttons = (ioport("P1")->read()&0xe0);
 
909
        if (dialread < 0) m_p1_direction = 0;
 
910
        else if (dialread > 0) m_p1_direction = 0x10;
 
911
        m_p1_counter_74ls161 += abs(dialread);
 
912
        m_p1_counter_74ls161 &= 0xf;
 
913
        ret = m_p1_counter_74ls161 | m_p1_direction | buttons;
 
914
        //fprintf(stderr, "dialread1: %02x, p1_counter_74ls161: %02x, spinner ret is %02x\n", dialread, m_p1_counter_74ls161, ret);
906
915
        return ret;
907
916
}
908
917
 
909
 
static READ8_HANDLER( moonwarp_p2_r )
 
918
READ8_MEMBER(berzerk_state::moonwarp_p2_r)
910
919
{
911
 
        berzerk_state *state = space->machine().driver_data<berzerk_state>();
912
920
        // same as above, but for player 2 in cocktail mode
913
 
        signed char dialread = input_port_read(space->machine(),"P2_DIAL");
 
921
        signed char dialread = ioport("P2_DIAL")->read();
914
922
        UINT8 ret;
915
 
        UINT8 buttons = (input_port_read(space->machine(),"P2")&0xe0);
916
 
        if (dialread < 0) state->m_p2_direction = 0;
917
 
        else if (dialread > 0) state->m_p2_direction = 0x10;
918
 
        state->m_p2_counter_74ls161 += abs(dialread);
919
 
        state->m_p2_counter_74ls161 &= 0xf;
920
 
        ret = state->m_p2_counter_74ls161 | state->m_p2_direction | buttons;
921
 
        //fprintf(stderr, "dialread2: %02x, p2_counter_74ls161: %02x, spinner ret is %02x\n", dialread, state->m_p2_counter_74ls161, ret);
 
923
        UINT8 buttons = (ioport("P2")->read()&0xe0);
 
924
        if (dialread < 0) m_p2_direction = 0;
 
925
        else if (dialread > 0) m_p2_direction = 0x10;
 
926
        m_p2_counter_74ls161 += abs(dialread);
 
927
        m_p2_counter_74ls161 &= 0xf;
 
928
        ret = m_p2_counter_74ls161 | m_p2_direction | buttons;
 
929
        //fprintf(stderr, "dialread2: %02x, p2_counter_74ls161: %02x, spinner ret is %02x\n", dialread, m_p2_counter_74ls161, ret);
922
930
        return ret;
923
931
}
924
932
 
1228
1236
static DRIVER_INIT( moonwarp )
1229
1237
{
1230
1238
        address_space *io = machine.device("maincpu")->memory().space(AS_IO);
1231
 
        io->install_legacy_read_handler (0x48, 0x48, FUNC(moonwarp_p1_r));
1232
 
        io->install_legacy_read_handler (0x4a, 0x4a, FUNC(moonwarp_p2_r));
 
1239
        berzerk_state *state = machine.driver_data<berzerk_state>();
 
1240
        io->install_read_handler (0x48, 0x48, read8_delegate(FUNC(berzerk_state::moonwarp_p1_r), state));
 
1241
        io->install_read_handler (0x4a, 0x4a, read8_delegate(FUNC(berzerk_state::moonwarp_p2_r), state));
1233
1242
}
1234
1243
 
1235
1244
/*************************************