Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/mame/includes/n64.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ class n64_periphs : public device_t,
bool disk_present;
bool cart_present;

// Mouse X2/Y2 for delta position
int mouse_x2[4];
int mouse_y2[4];

void poll_reset_button(bool button);

UINT32 dp_clock;
Expand Down
136 changes: 108 additions & 28 deletions src/mame/machine/n64.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const device_type N64PERIPH = &device_creator<n64_periphs>;




n64_periphs::n64_periphs(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, N64PERIPH, "N64 Periphal Chips", tag, owner, clock, "n64_periphs", __FILE__)
, device_video_interface(mconfig, *this)
Expand Down Expand Up @@ -271,6 +270,13 @@ void n64_periphs::device_reset()
pif_ram[0x27] = 0x3f;
cic_type=6;
}

// Mouse X2/Y2 for delta
for (int i = 0; i < 4; i++)
{
mouse_x2[i] = 0;
mouse_y2[i] = 0;
}
}

// Memory Interface (MI)
Expand Down Expand Up @@ -1709,18 +1715,28 @@ int n64_periphs::pif_channel_handle_command(int channel, int slength, UINT8 *sda
{
case 0:
case 1:
{
// Read status
rdata[0] = 0x05;
rdata[1] = 0x00;
rdata[2] = 0x01;
return 0;
}
case 2:
case 3:
{
// Read status (unconnected)
return 1;
// Read status
switch ((machine().root_device().ioport("input")->read() >> (2 * channel)) & 3)
{
case 0: //NONE (unconnected)
case 3: //Invalid
return 1;

case 1: //JOYPAD
rdata[0] = 0x05;
rdata[1] = 0x00;
rdata[2] = 0x01;
return 0;

case 2: //MOUSE
rdata[0] = 0x02;
rdata[1] = 0x00;
rdata[2] = 0x01;
return 0;
}
}
case 4:
{
Expand All @@ -1744,9 +1760,11 @@ int n64_periphs::pif_channel_handle_command(int channel, int slength, UINT8 *sda
case 0x01: // Read button values
{
UINT16 buttons = 0;
INT8 x = 0, y = 0;
/* add here tags for P3 and P4 when implemented */
static const char *const portnames[] = { "P1", "P1_ANALOG_X", "P1_ANALOG_Y", "P2", "P2_ANALOG_X", "P2_ANALOG_Y" };
int x = 0, y = 0;
static const char *const portnames[] = { "P1", "P1_ANALOG_X", "P1_ANALOG_Y", "P1_MOUSE_X", "P1_MOUSE_Y",
"P2", "P2_ANALOG_X", "P2_ANALOG_Y", "P2_MOUSE_X", "P2_MOUSE_Y",
"P3", "P3_ANALOG_X", "P3_ANALOG_Y", "P3_MOUSE_X", "P3_MOUSE_Y",
"P4", "P4_ANALOG_X", "P4_ANALOG_Y", "P4_MOUSE_X", "P4_MOUSE_Y" };

if (slength != 1 || rlength != 4)
{
Expand All @@ -1757,22 +1775,84 @@ int n64_periphs::pif_channel_handle_command(int channel, int slength, UINT8 *sda
{
case 0: // P1 Inputs
case 1: // P2 Inputs
case 2: // P3 Inputs
case 3: // P4 Inputs
{
buttons = machine().root_device().ioport(portnames[(channel*3) + 0])->read();
x = machine().root_device().ioport(portnames[(channel*3) + 1])->read() - 128;
y = machine().root_device().ioport(portnames[(channel*3) + 2])->read() - 128;

rdata[0] = (buttons >> 8) & 0xff;
rdata[1] = (buttons >> 0) & 0xff;
rdata[2] = (UINT8)(x);
rdata[3] = (UINT8)(y);
return 0;
}
case 2:
case 3:
{
// P3/P4 Inputs (not connected)
return 1;
switch ((machine().root_device().ioport("input")->read() >> (2 * channel)) & 3)
{
case 0: //NONE
case 3: //Invalid
return 1;

case 1: //JOYPAD
buttons = machine().root_device().ioport(portnames[(channel*5) + 0])->read();
x = machine().root_device().ioport(portnames[(channel*5) + 1])->read() - 128;
y = machine().root_device().ioport(portnames[(channel*5) + 2])->read() - 128;

rdata[0] = (buttons >> 8) & 0xff;
rdata[1] = (buttons >> 0) & 0xff;
rdata[2] = (UINT8)(x);
rdata[3] = (UINT8)(y);
return 0;

case 2: //MOUSE
buttons = machine().root_device().ioport(portnames[(channel*5) + 0])->read();
x = machine().root_device().ioport(portnames[(channel*5) + 1 + 2])->read() - 128;
y = machine().root_device().ioport(portnames[(channel*5) + 2 + 2])->read() - 128;

//x /= 4;
//y /= 4;

int mouse_dx = 0;
int mouse_dy = 0;

if (x != mouse_x2[channel])
{
mouse_dx = x - mouse_x2[channel];

if (mouse_dx > 0x40)
mouse_dx = (0x80) - mouse_dx;
else if (mouse_dx < -0x40)
mouse_dx = -(0x80) - mouse_dx;

mouse_x2[channel] = x;
}

if (y != mouse_y2[channel])
{
mouse_dy = y - mouse_y2[channel];

if (mouse_dy > 0x40)
mouse_dy = (0x80) - mouse_dy;
else if (mouse_dy < -0x40)
mouse_dy = -(0x80) - mouse_dy;

mouse_y2[channel] = y;
}

if (mouse_dx)
{
if(mouse_dx < 0)
mouse_dx++;
else
mouse_dx--;
}

if (mouse_dy)
{
if(mouse_dy < 0)
mouse_dy++;
else
mouse_dy--;
}

rdata[0] = (buttons >> 8) & 0xff;
rdata[1] = (buttons >> 0) & 0xff;
rdata[2] = (UINT8)(mouse_dx);
rdata[3] = (UINT8)(mouse_dy);
return 0;

}
}
}

Expand Down
100 changes: 96 additions & 4 deletions src/mess/drivers/n64.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,28 @@ static ADDRESS_MAP_START( rsp_map, AS_PROGRAM, 32, n64_mess_state )
ADDRESS_MAP_END

static INPUT_PORTS_START( n64 )
PORT_START("input")
PORT_CONFNAME(0x03, 0x01, "Controller Port 0 Device")
PORT_CONFSETTING(0x00, "None")
PORT_CONFSETTING(0x01, "Joypad")
PORT_CONFSETTING(0x02, "Mouse")
PORT_CONFNAME(0x0C, 0x00, "Controller Port 1 Device")
PORT_CONFSETTING(0x00, "None")
PORT_CONFSETTING(0x04, "Joypad")
PORT_CONFSETTING(0x08, "Mouse")
PORT_CONFNAME(0x30, 0x00, "Controller Port 2 Device")
PORT_CONFSETTING(0x00, "None")
PORT_CONFSETTING(0x10, "Joypad")
PORT_CONFSETTING(0x20, "Mouse")
PORT_CONFNAME(0xC0, 0x00, "Controller Port 3 Device")
PORT_CONFSETTING(0x00, "None")
PORT_CONFSETTING(0x40, "Joypad")
PORT_CONFSETTING(0x80, "Mouse")

//Player 1
PORT_START("P1")
PORT_BIT( 0x8000, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_NAME("P1 Button A")
PORT_BIT( 0x4000, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_NAME("P1 Button B")
PORT_BIT( 0x8000, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_NAME("P1 Button A / Left Click")
PORT_BIT( 0x4000, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_NAME("P1 Button B / Right Click")
PORT_BIT( 0x2000, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_PLAYER(1) PORT_NAME("P1 Button Z")
PORT_BIT( 0x1000, IP_ACTIVE_HIGH, IPT_START ) PORT_PLAYER(1) PORT_NAME("P1 Start")
PORT_BIT( 0x0800, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(1) PORT_NAME("P1 Joypad \xE2\x86\x91") /* Up */
Expand All @@ -111,9 +130,16 @@ static INPUT_PORTS_START( n64 )
PORT_START("P1_ANALOG_Y")
PORT_BIT( 0xff, 0x80, IPT_AD_STICK_Y ) PORT_MINMAX(0x00,0xff) PORT_SENSITIVITY(30) PORT_KEYDELTA(30) PORT_PLAYER(1) PORT_REVERSE

PORT_START("P1_MOUSE_X")
PORT_BIT( 0xffff, 0x0000, IPT_MOUSE_X ) PORT_MINMAX(0x0000,0xffff) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(1)

PORT_START("P1_MOUSE_Y")
PORT_BIT( 0xffff, 0x0000, IPT_MOUSE_Y ) PORT_MINMAX(0x0000,0xffff) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(1) PORT_REVERSE

//Player 2
PORT_START("P2")
PORT_BIT( 0x8000, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_NAME("P2 Button A")
PORT_BIT( 0x4000, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_NAME("P2 Button B")
PORT_BIT( 0x8000, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_NAME("P2 Button A / Left Click")
PORT_BIT( 0x4000, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_NAME("P2 Button B / Right Click")
PORT_BIT( 0x2000, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_PLAYER(2) PORT_NAME("P2 Button Z")
PORT_BIT( 0x1000, IP_ACTIVE_HIGH, IPT_START ) PORT_PLAYER(2) PORT_NAME("P2 Start")
PORT_BIT( 0x0800, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(2) PORT_NAME("P2 Joypad \xE2\x86\x91") /* Up */
Expand All @@ -134,6 +160,72 @@ static INPUT_PORTS_START( n64 )
PORT_START("P2_ANALOG_Y")
PORT_BIT( 0xff, 0x80, IPT_AD_STICK_Y ) PORT_MINMAX(0x00,0xff) PORT_SENSITIVITY(30) PORT_KEYDELTA(30) PORT_PLAYER(2) PORT_REVERSE

PORT_START("P2_MOUSE_X")
PORT_BIT( 0xffff, 0x0000, IPT_MOUSE_X ) PORT_MINMAX(0x0000,0xffff) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(2)

PORT_START("P2_MOUSE_Y")
PORT_BIT( 0xffff, 0x0000, IPT_MOUSE_Y ) PORT_MINMAX(0x0000,0xffff) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(2) PORT_REVERSE

//Player 3
PORT_START("P3")
PORT_BIT( 0x8000, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_PLAYER(3) PORT_NAME("P3 Button A / Left Click")
PORT_BIT( 0x4000, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_PLAYER(3) PORT_NAME("P3 Button B / Right Click")
PORT_BIT( 0x2000, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_PLAYER(3) PORT_NAME("P3 Button Z")
PORT_BIT( 0x1000, IP_ACTIVE_HIGH, IPT_START ) PORT_PLAYER(3) PORT_NAME("P3 Start")
PORT_BIT( 0x0800, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(3) PORT_NAME("P3 Joypad \xE2\x86\x91") /* Up */
PORT_BIT( 0x0400, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(3) PORT_NAME("P3 Joypad \xE2\x86\x93") /* Down */
PORT_BIT( 0x0200, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(3) PORT_NAME("P3 Joypad \xE2\x86\x90") /* Left */
PORT_BIT( 0x0100, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(3) PORT_NAME("P3 Joypad \xE2\x86\x92") /* Right */
PORT_BIT( 0x00c0, IP_ACTIVE_HIGH, IPT_UNUSED )
PORT_BIT( 0x0020, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_PLAYER(3) PORT_NAME("P3 Button L")
PORT_BIT( 0x0010, IP_ACTIVE_HIGH, IPT_BUTTON5 ) PORT_PLAYER(3) PORT_NAME("P3 Button R")
PORT_BIT( 0x0008, IP_ACTIVE_HIGH, IPT_BUTTON6 ) PORT_PLAYER(3) PORT_NAME("P3 Button C \xE2\x86\x91") /* Up */
PORT_BIT( 0x0004, IP_ACTIVE_HIGH, IPT_BUTTON7 ) PORT_PLAYER(3) PORT_NAME("P3 Button C \xE2\x86\x93") /* Down */
PORT_BIT( 0x0002, IP_ACTIVE_HIGH, IPT_BUTTON8 ) PORT_PLAYER(3) PORT_NAME("P3 Button C \xE2\x86\x90") /* Left */
PORT_BIT( 0x0001, IP_ACTIVE_HIGH, IPT_BUTTON9 ) PORT_PLAYER(3) PORT_NAME("P3 Button C \xE2\x86\x92") /* Right */

PORT_START("P3_ANALOG_X")
PORT_BIT( 0xff, 0x80, IPT_AD_STICK_X ) PORT_MINMAX(0x00,0xff) PORT_SENSITIVITY(30) PORT_KEYDELTA(30) PORT_PLAYER(3)

PORT_START("P3_ANALOG_Y")
PORT_BIT( 0xff, 0x80, IPT_AD_STICK_Y ) PORT_MINMAX(0x00,0xff) PORT_SENSITIVITY(30) PORT_KEYDELTA(30) PORT_PLAYER(3) PORT_REVERSE

PORT_START("P3_MOUSE_X")
PORT_BIT( 0xffff, 0x0000, IPT_MOUSE_X ) PORT_MINMAX(0x0000,0xffff) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(3)

PORT_START("P3_MOUSE_Y")
PORT_BIT( 0xffff, 0x0000, IPT_MOUSE_Y ) PORT_MINMAX(0x0000,0xffff) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(3) PORT_REVERSE

//Player 4
PORT_START("P4")
PORT_BIT( 0x8000, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_PLAYER(4) PORT_NAME("P4 Button A / Left Click")
PORT_BIT( 0x4000, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_PLAYER(4) PORT_NAME("P4 Button B / Right Click")
PORT_BIT( 0x2000, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_PLAYER(4) PORT_NAME("P4 Button Z")
PORT_BIT( 0x1000, IP_ACTIVE_HIGH, IPT_START ) PORT_PLAYER(4) PORT_NAME("P4 Start")
PORT_BIT( 0x0800, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(4) PORT_NAME("P4 Joypad \xE2\x86\x91") /* Up */
PORT_BIT( 0x0400, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(4) PORT_NAME("P4 Joypad \xE2\x86\x93") /* Down */
PORT_BIT( 0x0200, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(4) PORT_NAME("P4 Joypad \xE2\x86\x90") /* Left */
PORT_BIT( 0x0100, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(4) PORT_NAME("P4 Joypad \xE2\x86\x92") /* Right */
PORT_BIT( 0x00c0, IP_ACTIVE_HIGH, IPT_UNUSED )
PORT_BIT( 0x0020, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_PLAYER(4) PORT_NAME("P4 Button L")
PORT_BIT( 0x0010, IP_ACTIVE_HIGH, IPT_BUTTON5 ) PORT_PLAYER(4) PORT_NAME("P4 Button R")
PORT_BIT( 0x0008, IP_ACTIVE_HIGH, IPT_BUTTON6 ) PORT_PLAYER(4) PORT_NAME("P4 Button C \xE2\x86\x91") /* Up */
PORT_BIT( 0x0004, IP_ACTIVE_HIGH, IPT_BUTTON7 ) PORT_PLAYER(4) PORT_NAME("P4 Button C \xE2\x86\x93") /* Down */
PORT_BIT( 0x0002, IP_ACTIVE_HIGH, IPT_BUTTON8 ) PORT_PLAYER(4) PORT_NAME("P4 Button C \xE2\x86\x90") /* Left */
PORT_BIT( 0x0001, IP_ACTIVE_HIGH, IPT_BUTTON9 ) PORT_PLAYER(4) PORT_NAME("P4 Button C \xE2\x86\x92") /* Right */

PORT_START("P4_ANALOG_X")
PORT_BIT( 0xff, 0x80, IPT_AD_STICK_X ) PORT_MINMAX(0x00,0xff) PORT_SENSITIVITY(30) PORT_KEYDELTA(30) PORT_PLAYER(4)

PORT_START("P4_ANALOG_Y")
PORT_BIT( 0xff, 0x80, IPT_AD_STICK_Y ) PORT_MINMAX(0x00,0xff) PORT_SENSITIVITY(30) PORT_KEYDELTA(30) PORT_PLAYER(4) PORT_REVERSE

PORT_START("P4_MOUSE_X")
PORT_BIT( 0xffff, 0x0000, IPT_MOUSE_X ) PORT_MINMAX(0x0000,0xffff) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(4)

PORT_START("P4_MOUSE_Y")
PORT_BIT( 0xffff, 0x0000, IPT_MOUSE_Y ) PORT_MINMAX(0x0000,0xffff) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(4) PORT_REVERSE

PORT_START("RESET")
PORT_BIT( 0xfffe, IP_ACTIVE_HIGH, IPT_UNUSED )
PORT_BIT( 0x0001, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Warm Reset") PORT_CODE(KEYCODE_3)
Expand Down