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

    Atari Basketball hardware

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

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

/***************************************************************************
    bsktball_nmion_w
***************************************************************************/

WRITE_LINE_MEMBER(bsktball_state::nmion_w)
{
	m_nmi_on = state;
}

/***************************************************************************
    bsktball_interrupt
***************************************************************************/

TIMER_DEVICE_CALLBACK_MEMBER(bsktball_state::bsktball_scanline)
{
	// NMI every 32V
	if (m_nmi_on)
		m_maincpu->pulse_input_line(INPUT_LINE_NMI, attotime::zero);
}


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

WRITE_LINE_MEMBER(bsktball_state::ld1_w)
{
	m_ld1 = state;
}

WRITE_LINE_MEMBER(bsktball_state::ld2_w)
{
	m_ld2 = state;
}


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

uint8_t 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);
	}
}