summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/audio/cchasm.cpp
blob: 6ca1bbf12401f401699597db537ed65efaad29c5 (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
// license:BSD-3-Clause
// copyright-holders:Mathis Rosenhauer
/***************************************************************************

    Cinematronics Cosmic Chasm hardware

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

#include "emu.h"
#include "cpu/z80/z80.h"
#include "machine/z80ctc.h"
#include "includes/cchasm.h"
#include "sound/ay8910.h"


WRITE8_MEMBER(cchasm_state::reset_coin_flag_w)
{
	if (m_coin_flag)
	{
		m_coin_flag = 0;
		m_ctc->trg0(m_coin_flag);
	}
}

INPUT_CHANGED_MEMBER(cchasm_state::set_coin_flag )
{
	if (!newval && !m_coin_flag)
	{
		m_coin_flag = 1;
		m_ctc->trg0(m_coin_flag);
	}
}

READ8_MEMBER(cchasm_state::coin_sound_r)
{
	uint8_t coin = (ioport("IN3")->read() >> 4) & 0x7;
	return m_sound_flags | (m_coin_flag << 3) | coin;
}

READ8_MEMBER(cchasm_state::soundlatch2_r)
{
	m_sound_flags &= ~0x80;
	m_ctc->trg2(0);
	return m_soundlatch2->read();
}

WRITE8_MEMBER(cchasm_state::soundlatch4_w)
{
	m_sound_flags |= 0x40;
	m_soundlatch4->write(data);
	m_maincpu->set_input_line(1, HOLD_LINE);
}

WRITE16_MEMBER(cchasm_state::io_w)
{
	//static int led;

	if (ACCESSING_BITS_8_15)
	{
		data >>= 8;
		switch (offset & 0xf)
		{
		case 0:
			m_soundlatch->write(data);
			break;
		case 1:
			m_sound_flags |= 0x80;
			m_soundlatch2->write(data);
			m_ctc->trg2(1);
			m_audiocpu->pulse_input_line(INPUT_LINE_NMI, attotime::zero);
			break;
		case 2:
			//led = data;
			break;
		}
	}
}

READ16_MEMBER(cchasm_state::io_r)
{
	switch (offset & 0xf)
	{
	case 0x0:
		return m_soundlatch3->read() << 8;
	case 0x1:
		m_sound_flags &= ~0x40;
		return m_soundlatch4->read() << 8;
	case 0x2:
		return (m_sound_flags| (ioport("IN3")->read() & 0x07) | 0x08) << 8;
	case 0x5:
		return ioport("IN2")->read() << 8;
	case 0x8:
		return ioport("IN1")->read() << 8;
	default:
		return 0xff << 8;
	}
}


WRITE_LINE_MEMBER(cchasm_state::ctc_timer_1_w)
{
	if (state) /* rising edge */
	{
		m_output[0] = !m_output[0];
		m_dac1->write(m_output[0]);
	}
}

WRITE_LINE_MEMBER(cchasm_state::ctc_timer_2_w)
{
	if (state) /* rising edge */
	{
		m_output[1] = !m_output[1];
		m_dac2->write(m_output[1]);
	}
}

void cchasm_state::sound_start()
{
	m_coin_flag = 0;
	m_sound_flags = 0;
	m_output[0] = 0;
	m_output[1] = 0;

	save_item(NAME(m_sound_flags));
	save_item(NAME(m_coin_flag));
	save_item(NAME(m_output));
}