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

« back to all changes in this revision

Viewing changes to src/mame/machine/mcr68.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:
5
5
***************************************************************************/
6
6
 
7
7
#include "emu.h"
8
 
#include "audio/mcr.h"
 
8
#include "audio/midway.h"
 
9
#include "includes/mcr.h"
9
10
#include "includes/mcr68.h"
10
11
 
11
12
#define VERBOSE 0
40
41
 
41
42
static READ8_DEVICE_HANDLER( zwackery_port_1_r )
42
43
{
43
 
        UINT8 ret = input_port_read(device->machine(), "IN1");
 
44
        UINT8 ret = device->machine().root_device().ioport("IN1")->read();
44
45
 
45
46
        downcast<pia6821_device *>(device)->set_port_a_z_mask(ret);
46
47
 
50
51
 
51
52
static READ8_DEVICE_HANDLER( zwackery_port_3_r )
52
53
{
53
 
        UINT8 ret = input_port_read(device->machine(), "IN3");
 
54
        UINT8 ret = device->machine().root_device().ioport("IN3")->read();
54
55
 
55
56
        downcast<pia6821_device *>(device)->set_port_a_z_mask(ret);
56
57
 
170
171
 
171
172
        /* initialize the clock */
172
173
        state->m_m6840_internal_counter_period = attotime::from_hz(machine.device("maincpu")->unscaled_clock() / 10);
173
 
 
174
 
        /* initialize the sound */
175
 
        mcr_sound_reset(machine);
176
174
}
177
175
 
178
176
 
276
274
WRITE8_DEVICE_HANDLER( zwackery_pia0_w )
277
275
{
278
276
        /* bit 7 is the watchdog */
279
 
        if (!(data & 0x80)) watchdog_reset(device->machine());
 
277
        if (!(data & 0x80)) device->machine().watchdog_reset();
280
278
 
281
279
        /* bits 5 and 6 control hflip/vflip */
282
280
        /* bits 3 and 4 control coin counters? */
295
293
{
296
294
        mcr68_state *drvstate = device->machine().driver_data<mcr68_state>();
297
295
        address_space *space = device->machine().device("maincpu")->memory().space(AS_PROGRAM);
298
 
        csdeluxe_data_w(space, 0, (state << 4) | drvstate->m_zwackery_sound_data);
 
296
        drvstate->m_chip_squeak_deluxe->write(*space, 0, (state << 4) | drvstate->m_zwackery_sound_data);
299
297
}
300
298
 
301
299
 
423
421
}
424
422
 
425
423
 
426
 
static void reload_count(mcr68_state *state, int counter)
 
424
void mcr68_state::reload_count(int counter)
427
425
{
428
 
        struct counter_state *m6840 = &state->m_m6840_state[counter];
 
426
        struct counter_state *m6840 = &m_m6840_state[counter];
429
427
        attotime period;
430
428
        attotime total_period;
431
429
        int count;
443
441
 
444
442
        /* determine the clock period for this timer */
445
443
        if (m6840->control & 0x02)
446
 
                period = state->m_m6840_internal_counter_period;
 
444
                period = m_m6840_internal_counter_period;
447
445
        else
448
 
                period = state->m_m6840_counter_periods[counter];
 
446
                period = m_m6840_counter_periods[counter];
449
447
 
450
448
        /* determine the number of clock periods before we expire */
451
449
        count = m6840->count;
462
460
}
463
461
 
464
462
 
465
 
static UINT16 compute_counter(mcr68_state *state, int counter)
 
463
UINT16 mcr68_state::compute_counter(int counter)
466
464
{
467
 
        struct counter_state *m6840 = &state->m_m6840_state[counter];
 
465
        struct counter_state *m6840 = &m_m6840_state[counter];
468
466
        attotime period;
469
467
        int remaining;
470
468
 
474
472
 
475
473
        /* determine the clock period for this timer */
476
474
        if (m6840->control & 0x02)
477
 
                period = state->m_m6840_internal_counter_period;
 
475
                period = m_m6840_internal_counter_period;
478
476
        else
479
 
                period = state->m_m6840_counter_periods[counter];
 
477
                period = m_m6840_counter_periods[counter];
480
478
        /* see how many are left */
481
479
        remaining = m6840->timer->remaining().as_attoseconds() / period.as_attoseconds();
482
480
 
500
498
 *
501
499
 *************************************/
502
500
 
503
 
static WRITE8_HANDLER( mcr68_6840_w_common )
 
501
WRITE8_MEMBER(mcr68_state::mcr68_6840_w_common)
504
502
{
505
 
        mcr68_state *state = space->machine().driver_data<mcr68_state>();
506
503
        int i;
507
504
 
508
505
        /* offsets 0 and 1 are control registers */
509
506
        if (offset < 2)
510
507
        {
511
 
                int counter = (offset == 1) ? 1 : (state->m_m6840_state[1].control & 0x01) ? 0 : 2;
512
 
                struct counter_state *m6840 = &state->m_m6840_state[counter];
 
508
                int counter = (offset == 1) ? 1 : (m_m6840_state[1].control & 0x01) ? 0 : 2;
 
509
                struct counter_state *m6840 = &m_m6840_state[counter];
513
510
                UINT8 diffs = data ^ m6840->control;
514
511
 
515
512
                m6840->control = data;
522
519
                        {
523
520
                                for (i = 0; i < 3; i++)
524
521
                                {
525
 
                                        state->m_m6840_state[i].timer->adjust(attotime::never);
526
 
                                        state->m_m6840_state[i].timer_active = 0;
 
522
                                        m_m6840_state[i].timer->adjust(attotime::never);
 
523
                                        m_m6840_state[i].timer_active = 0;
527
524
                                }
528
525
                        }
529
526
 
531
528
                        else
532
529
                        {
533
530
                                for (i = 0; i < 3; i++)
534
 
                                        reload_count(state, i);
 
531
                                        reload_count(i);
535
532
                        }
536
533
 
537
 
                        state->m_m6840_status = 0;
538
 
                        update_interrupts(space->machine());
 
534
                        m_m6840_status = 0;
 
535
                        update_interrupts(machine());
539
536
                }
540
537
 
541
538
                /* changing the clock source? (needed for Zwackery) */
542
539
                if (diffs & 0x02)
543
 
                        reload_count(state, counter);
 
540
                        reload_count(counter);
544
541
 
545
 
                LOG(("%06X:Counter %d control = %02X\n", cpu_get_previouspc(&space->device()), counter, data));
 
542
                LOG(("%06X:Counter %d control = %02X\n", cpu_get_previouspc(&space.device()), counter, data));
546
543
        }
547
544
 
548
545
        /* offsets 2, 4, and 6 are MSB buffer registers */
549
546
        else if ((offset & 1) == 0)
550
547
        {
551
 
                LOG(("%06X:MSB = %02X\n", cpu_get_previouspc(&space->device()), data));
552
 
                state->m_m6840_msb_buffer = data;
 
548
                LOG(("%06X:MSB = %02X\n", cpu_get_previouspc(&space.device()), data));
 
549
                m_m6840_msb_buffer = data;
553
550
        }
554
551
 
555
552
        /* offsets 3, 5, and 7 are Write Timer Latch commands */
556
553
        else
557
554
        {
558
555
                int counter = (offset - 2) / 2;
559
 
                struct counter_state *m6840 = &state->m_m6840_state[counter];
560
 
                m6840->latch = (state->m_m6840_msb_buffer << 8) | (data & 0xff);
 
556
                struct counter_state *m6840 = &m_m6840_state[counter];
 
557
                m6840->latch = (m_m6840_msb_buffer << 8) | (data & 0xff);
561
558
 
562
559
                /* clear the interrupt */
563
 
                state->m_m6840_status &= ~(1 << counter);
564
 
                update_interrupts(space->machine());
 
560
                m_m6840_status &= ~(1 << counter);
 
561
                update_interrupts(machine());
565
562
 
566
563
                /* reload the count if in an appropriate mode */
567
564
                if (!(m6840->control & 0x10))
568
 
                        reload_count(state, counter);
 
565
                        reload_count(counter);
569
566
 
570
 
                LOG(("%06X:Counter %d latch = %04X\n", cpu_get_previouspc(&space->device()), counter, m6840->latch));
 
567
                LOG(("%06X:Counter %d latch = %04X\n", cpu_get_previouspc(&space.device()), counter, m6840->latch));
571
568
        }
572
569
}
573
570
 
574
571
 
575
 
static READ16_HANDLER( mcr68_6840_r_common )
 
572
READ16_MEMBER(mcr68_state::mcr68_6840_r_common)
576
573
{
577
 
        mcr68_state *state = space->machine().driver_data<mcr68_state>();
578
574
        /* offset 0 is a no-op */
579
575
        if (offset == 0)
580
576
                return 0;
582
578
        /* offset 1 is the status register */
583
579
        else if (offset == 1)
584
580
        {
585
 
                LOG(("%06X:Status read = %04X\n", cpu_get_previouspc(&space->device()), state->m_m6840_status));
586
 
                state->m_m6840_status_read_since_int |= state->m_m6840_status & 0x07;
587
 
                return state->m_m6840_status;
 
581
                LOG(("%06X:Status read = %04X\n", cpu_get_previouspc(&space.device()), m_m6840_status));
 
582
                m_m6840_status_read_since_int |= m_m6840_status & 0x07;
 
583
                return m_m6840_status;
588
584
        }
589
585
 
590
586
        /* offsets 2, 4, and 6 are Read Timer Counter commands */
591
587
        else if ((offset & 1) == 0)
592
588
        {
593
589
                int counter = (offset - 2) / 2;
594
 
                int result = compute_counter(state, counter);
 
590
                int result = compute_counter(counter);
595
591
 
596
592
                /* clear the interrupt if the status has been read */
597
 
                if (state->m_m6840_status_read_since_int & (1 << counter))
598
 
                        state->m_m6840_status &= ~(1 << counter);
599
 
                update_interrupts(space->machine());
600
 
 
601
 
                state->m_m6840_lsb_buffer = result & 0xff;
602
 
 
603
 
                LOG(("%06X:Counter %d read = %04X\n", cpu_get_previouspc(&space->device()), counter, result));
 
593
                if (m_m6840_status_read_since_int & (1 << counter))
 
594
                        m_m6840_status &= ~(1 << counter);
 
595
                update_interrupts(machine());
 
596
 
 
597
                m_m6840_lsb_buffer = result & 0xff;
 
598
 
 
599
                LOG(("%06X:Counter %d read = %04X\n", cpu_get_previouspc(&space.device()), counter, result));
604
600
                return result >> 8;
605
601
        }
606
602
 
607
603
        /* offsets 3, 5, and 7 are LSB buffer registers */
608
604
        else
609
 
                return state->m_m6840_lsb_buffer;
 
605
                return m_m6840_lsb_buffer;
610
606
}
611
607
 
612
608
 
613
 
WRITE16_HANDLER( mcr68_6840_upper_w )
 
609
WRITE16_MEMBER(mcr68_state::mcr68_6840_upper_w)
614
610
{
615
611
        if (ACCESSING_BITS_8_15)
616
612
                mcr68_6840_w_common(space, offset, (data >> 8) & 0xff);
617
613
}
618
614
 
619
615
 
620
 
WRITE16_HANDLER( mcr68_6840_lower_w )
 
616
WRITE16_MEMBER(mcr68_state::mcr68_6840_lower_w)
621
617
{
622
618
        if (ACCESSING_BITS_0_7)
623
619
                mcr68_6840_w_common(space, offset, data & 0xff);
624
620
}
625
621
 
626
622
 
627
 
READ16_HANDLER( mcr68_6840_upper_r )
 
623
READ16_MEMBER(mcr68_state::mcr68_6840_upper_r)
628
624
{
629
625
        return (mcr68_6840_r_common(space,offset,0) << 8) | 0x00ff;
630
626
}
631
627
 
632
628
 
633
 
READ16_HANDLER( mcr68_6840_lower_r )
 
629
READ16_MEMBER(mcr68_state::mcr68_6840_lower_r)
634
630
{
635
631
        return mcr68_6840_r_common(space,offset,0) | 0xff00;
636
632
}