From e115dff18a06e3b26b2c6510541c5d1ca7ca891a Mon Sep 17 00:00:00 2001 From: luigiblood Date: Sat, 2 May 2015 03:31:48 +0200 Subject: [PATCH 1/2] Added 4 controller support for N64/N64DD, as well as rough mouse support. You can select the device on each controller port. --- src/mame/machine/n64.c | 129 ++++++++++++++++++++++++++++++++--------- src/mess/drivers/n64.c | 100 ++++++++++++++++++++++++++++++-- 2 files changed, 198 insertions(+), 31 deletions(-) diff --git a/src/mame/machine/n64.c b/src/mame/machine/n64.c index b033527b0bd42..41895a655bedd 100644 --- a/src/mame/machine/n64.c +++ b/src/mame/machine/n64.c @@ -15,6 +15,8 @@ UINT32 *rsp_dmem; // device type definition const device_type N64PERIPH = &device_creator; +int mouse_dx = 0, mouse_dy = 0, mouse_x2 = 0, mouse_y2 = 0, mouse_cntx = 0, mouse_cnty = 0; + @@ -1709,18 +1711,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: { @@ -1744,9 +1756,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) { @@ -1757,22 +1771,83 @@ 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; + + if (x != mouse_x2) + { + mouse_dx = x - mouse_x2; + + if (mouse_dx > 0x40) + mouse_dx = (0x80) - mouse_dx; + else if (mouse_dx < -0x40) + mouse_dx = -(0x80) - mouse_dx; + + mouse_cntx = mouse_dx; + mouse_x2 = x; + } + + if (y != mouse_y2) + { + mouse_dy = y - mouse_y2; + + if (mouse_dy > 0x40) + mouse_dy = (0x80) - mouse_dy; + else if (mouse_dy < -0x40) + mouse_dy = -(0x80) - mouse_dy; + + mouse_cnty = mouse_dy; + mouse_y2 = y; + } + + if (mouse_cntx) + { + if(mouse_cntx < 0) + mouse_cntx++; + else + mouse_cntx--; + } + + if (mouse_cnty) + { + if(mouse_cnty < 0) + mouse_cnty++; + else + mouse_cnty--; + } + + rdata[0] = (buttons >> 8) & 0xff; + rdata[1] = (buttons >> 0) & 0xff; + rdata[2] = (UINT8)(mouse_cntx); + rdata[3] = (UINT8)(mouse_cnty); + return 0; + + } } } diff --git a/src/mess/drivers/n64.c b/src/mess/drivers/n64.c index 2c05e3766744b..1037d2dd65f05 100644 --- a/src/mess/drivers/n64.c +++ b/src/mess/drivers/n64.c @@ -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 */ @@ -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 */ @@ -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) From 7aa17da424f616047fe285f3bf398332c6699302 Mon Sep 17 00:00:00 2001 From: luigiblood Date: Sat, 2 May 2015 15:25:11 +0200 Subject: [PATCH 2/2] Mouse optimizations and moved global vars to n64_periphs. --- src/mame/includes/n64.h | 4 ++++ src/mame/machine/n64.c | 47 +++++++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/mame/includes/n64.h b/src/mame/includes/n64.h index 8fd6324bcf9c2..8f55c04823f1d 100644 --- a/src/mame/includes/n64.h +++ b/src/mame/includes/n64.h @@ -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; diff --git a/src/mame/machine/n64.c b/src/mame/machine/n64.c index 41895a655bedd..75b68b3f419b6 100644 --- a/src/mame/machine/n64.c +++ b/src/mame/machine/n64.c @@ -15,9 +15,6 @@ UINT32 *rsp_dmem; // device type definition const device_type N64PERIPH = &device_creator; -int mouse_dx = 0, mouse_dy = 0, mouse_x2 = 0, mouse_y2 = 0, mouse_cntx = 0, mouse_cnty = 0; - - @@ -273,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) @@ -1799,52 +1803,53 @@ int n64_periphs::pif_channel_handle_command(int channel, int slength, UINT8 *sda //x /= 4; //y /= 4; - if (x != mouse_x2) + int mouse_dx = 0; + int mouse_dy = 0; + + if (x != mouse_x2[channel]) { - mouse_dx = x - mouse_x2; + 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_cntx = mouse_dx; - mouse_x2 = x; + mouse_x2[channel] = x; } - if (y != mouse_y2) + if (y != mouse_y2[channel]) { - mouse_dy = y - mouse_y2; + 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_cnty = mouse_dy; - mouse_y2 = y; + mouse_y2[channel] = y; } - if (mouse_cntx) + if (mouse_dx) { - if(mouse_cntx < 0) - mouse_cntx++; + if(mouse_dx < 0) + mouse_dx++; else - mouse_cntx--; + mouse_dx--; } - if (mouse_cnty) + if (mouse_dy) { - if(mouse_cnty < 0) - mouse_cnty++; + if(mouse_dy < 0) + mouse_dy++; else - mouse_cnty--; + mouse_dy--; } rdata[0] = (buttons >> 8) & 0xff; rdata[1] = (buttons >> 0) & 0xff; - rdata[2] = (UINT8)(mouse_cntx); - rdata[3] = (UINT8)(mouse_cnty); + rdata[2] = (UINT8)(mouse_dx); + rdata[3] = (UINT8)(mouse_dy); return 0; }