summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/machine/bsktball.cpp
blob: 8621570341a285656dcafba28ae8d6389105227f (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
// license:BSD-3-Clause
// copyright-holders:Mike Balfour
/***************************************************************************

    Atari Basketball hardware

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

#include "emu.h"
#include "includes/bsktball.h"

/***************************************************************************
    bsktball_nmion_w
***************************************************************************/
WRITE8_MEMBER(bsktball_state::bsktball_nmion_w)
{
	m_nmi_on = offset & 0x01;
}

/***************************************************************************
    bsktball_interrupt
***************************************************************************/
/* NMI every 32V, IRQ every VBLANK */
TIMER_DEVICE_CALLBACK_MEMBER(bsktball_state::bsktball_scanline)
{
	int scanline = param;

	if(scanline == 0) // vblank irq
		m_maincpu->set_input_line(0, HOLD_LINE);
	else if(((scanline % 28) == 0) && (m_nmi_on)) // 32v timer irq
		m_maincpu->set_input_line(INPUT_LINE_NMI, PULSE_LINE);
}


/***************************************************************************
    bsktball_ld_w
***************************************************************************/

WRITE8_MEMBER(bsktball_state::bsktball_ld1_w)
{
	m_ld1 = (offset & 0x01);
}

WRITE8_MEMBER(bsktball_state::bsktball_ld2_w)
{
	m_ld2 = (offset & 0x01);
}


/***************************************************************************
    bsktball_in0_r
***************************************************************************/

READ8_MEMBER(bsktball_state::bsktball_in0_r)
{
	int p1_horiz;
	int p1_vert;
	int p2_horiz;
	int p2_vert;
	int temp;

	p1_horiz = ioport("TRACK0_X")->read();
	p1_vert  = ioport("TRACK0_Y")->read();
	p2_horiz = ioport("TRACK1_X")->read();
	p2_vert  = ioport("TRACK1_Y")->read();

	/* Set direction bits */

	/* P1 H DIR */
	if (p1_horiz > m_last_p1_horiz)
	{
		if ((p1_horiz - m_last_p1_horiz) > 128)
			m_dir2 = 0x40;
		else
			m_dir2 = 0;
	}
	else if (p1_horiz < m_last_p1_horiz)
	{
		if ((m_last_p1_horiz - p1_horiz) > 128)
			m_dir2 = 0;
		else
			m_dir2 = 0x40;
	}

	/* P1 V DIR */
	if (p1_vert > m_last_p1_vert)
	{
		if ((p1_vert - m_last_p1_vert) > 128)
			m_dir3 = 0;
		else
			m_dir3 = 0x80;
	}
	else if (p1_vert < m_last_p1_vert)
	{
		if ((m_last_p1_vert - p1_vert) > 128)
			m_dir3 = 0x80;
		else
			m_dir3 = 0;
	}

	/* P2 H DIR */
	if (p2_horiz > m_last_p2_horiz)
	{
		if ((p2_horiz - m_last_p2_horiz) > 128)
			m_dir0 = 0x10;
		else
			m_dir0 = 0;
	}
	else if (p2_horiz < m_last_p2_horiz)
	{
		if ((m_last_p2_horiz - p2_horiz) > 128)
			m_dir0 = 0;
		else
			m_dir0 = 0x10;
	}

	/* P2 V DIR */
	if (p2_vert > m_last_p2_vert)
	{
		if ((p2_vert - m_last_p2_vert) > 128)
			m_dir1 = 0;
		else
			m_dir1 = 0x20;
	}
	else if (p2_vert < m_last_p2_vert)
	{
		if ((m_last_p2_vert - p2_vert) > 128)
			m_dir1 = 0x20;
		else
			m_dir1 = 0;
	}

	m_last_p1_horiz = p1_horiz;
	m_last_p1_vert  = p1_vert;
	m_last_p2_horiz = p2_horiz;
	m_last_p2_vert  = p2_vert;

	/* D0-D3 = Plyr 1 Horiz, D4-D7 = Plyr 1 Vert */
	if ((m_ld1) & (m_ld2))
	{
		return ((p1_horiz & 0x0f) | ((p1_vert << 4) & 0xf0));
	}
	/* D0-D3 = Plyr 2 Horiz, D4-D7 = Plyr 2 Vert */
	else if (m_ld2)
	{
		return ((p2_horiz & 0x0f) | ((p2_vert << 4) & 0xf0));
	}
	else
	{
		temp = ioport("IN0")->read() & 0x0f;

		return (temp | m_dir0 | m_dir1 | m_dir2 | m_dir3);
	}
}

/***************************************************************************
    bsktball_led_w
***************************************************************************/
WRITE8_MEMBER(bsktball_state::bsktball_led1_w)
{
	output().set_led_value(0, offset & 0x01);
}

WRITE8_MEMBER(bsktball_state::bsktball_led2_w)
{
	output().set_led_value(1, offset & 0x01);
}