Skip to content

Commit b185344

Browse files
authored
Commodore: added machine configuration switch in C16, C64, C128 and C65 to swap joystick ports on the fly, avoiding the need to reset the machine when loading a game that requires joystick to be in the opposite port to the one we plugged it in (#15250)
* Update c64.cpp c64: added machine configuration switch in C64 to swap joystick ports on the fly, avoiding the need to reset the machine when loading a game that requires joystick to be in the opposite port to the one we plugged it in * plus4: added machine configuration switch to swap joystick ports on the fly, avoiding the need to reset the machine when loading a game that requires joystick to be in the opposite port to the one we plugged it in * c128.cpp: added machine configuration switch to swap joystick ports on the fly, avoiding the need to reset the machine when loading a game that requires joystick to be in the opposite port to the one we plugged it in * c65.cpp: added machine configuration switch to swap joystick ports on the fly, avoiding the need to reset the machine when loading a game that requires joystick to be in the opposite port to the one we plugged it in
1 parent 47377bf commit b185344

4 files changed

Lines changed: 104 additions & 48 deletions

File tree

src/mame/commodore/c128.cpp

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class c128_state : public driver_device
7878
m_lock(*this, "LOCK"),
7979
m_caps(*this, "CAPS"),
8080
m_40_80(*this, "40_80"),
81+
m_portswap(*this, "JOYSWAP"),
8182
m_z80en(0),
8283
m_loram(1),
8384
m_hiram(1),
@@ -122,6 +123,7 @@ class c128_state : public driver_device
122123
required_ioport m_lock;
123124
required_ioport m_caps;
124125
required_ioport m_40_80;
126+
optional_ioport m_portswap;
125127

126128
virtual void machine_start() override ATTR_COLD;
127129
virtual void machine_reset() override ATTR_COLD;
@@ -851,6 +853,11 @@ static INPUT_PORTS_START( c128 )
851853

852854
PORT_START( "40_80" )
853855
PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD ) PORT_NAME("40/80 DISPLAY") PORT_CODE(KEYCODE_F11) PORT_TOGGLE
856+
857+
PORT_START( "JOYSWAP" )
858+
PORT_CONFNAME( 0x01, 0x00, "Swap joystick ports" )
859+
PORT_CONFSETTING( 0x01, "Joystick in swapped port" )
860+
PORT_CONFSETTING( 0x00, "Joystick in assigned port" )
854861
INPUT_PORTS_END
855862

856863

@@ -1112,23 +1119,25 @@ void c128_state::vic_k_w(uint8_t data)
11121119
uint8_t c128_state::sid_potx_r()
11131120
{
11141121
uint8_t data = 0xff;
1122+
vcs_control_port_device *cur1 = m_portswap->read() ? m_joy2 : m_joy1;
1123+
vcs_control_port_device *cur2 = m_portswap->read() ? m_joy1 : m_joy2;
11151124

11161125
switch (m_cia1->pa_r() >> 6)
11171126
{
1118-
case 1: data = m_joy1->read_pot_x(); break;
1119-
case 2: data = m_joy2->read_pot_x(); break;
1127+
case 1: data = cur1->read_pot_x(); break;
1128+
case 2: data = cur2->read_pot_x(); break;
11201129
case 3:
1121-
if (m_joy1->has_pot_x() && m_joy2->has_pot_x())
1130+
if (cur1->has_pot_x() && cur2->has_pot_x())
11221131
{
1123-
data = 1 / (1 / m_joy1->read_pot_x() + 1 / m_joy2->read_pot_x());
1132+
data = 1 / (1 / cur1->read_pot_x() + 1 / cur2->read_pot_x());
11241133
}
1125-
else if (m_joy1->has_pot_x())
1134+
else if (cur1->has_pot_x())
11261135
{
1127-
data = m_joy1->read_pot_x();
1136+
data = cur1->read_pot_x();
11281137
}
1129-
else if (m_joy2->has_pot_x())
1138+
else if (cur2->has_pot_x())
11301139
{
1131-
data = m_joy2->read_pot_x();
1140+
data = cur2->read_pot_x();
11321141
}
11331142
break;
11341143
}
@@ -1139,23 +1148,25 @@ uint8_t c128_state::sid_potx_r()
11391148
uint8_t c128_state::sid_poty_r()
11401149
{
11411150
uint8_t data = 0xff;
1151+
vcs_control_port_device *cur1 = m_portswap->read() ? m_joy2 : m_joy1;
1152+
vcs_control_port_device *cur2 = m_portswap->read() ? m_joy1 : m_joy2;
11421153

11431154
switch (m_cia1->pa_r() >> 6)
11441155
{
1145-
case 1: data = m_joy1->read_pot_y(); break;
1146-
case 2: data = m_joy2->read_pot_y(); break;
1156+
case 1: data = cur1->read_pot_y(); break;
1157+
case 2: data = cur2->read_pot_y(); break;
11471158
case 3:
1148-
if (m_joy1->has_pot_y() && m_joy2->has_pot_y())
1159+
if (cur1->has_pot_y() && cur2->has_pot_y())
11491160
{
1150-
data = 1 / (1 / m_joy1->read_pot_y() + 1 / m_joy2->read_pot_y());
1161+
data = 1 / (1 / cur1->read_pot_y() + 1 / cur2->read_pot_y());
11511162
}
1152-
else if (m_joy1->has_pot_y())
1163+
else if (cur1->has_pot_y())
11531164
{
1154-
data = m_joy1->read_pot_y();
1165+
data = cur1->read_pot_y();
11551166
}
1156-
else if (m_joy2->has_pot_y())
1167+
else if (cur2->has_pot_y())
11571168
{
1158-
data = m_joy2->read_pot_y();
1169+
data = cur2->read_pot_y();
11591170
}
11601171
break;
11611172
}
@@ -1186,9 +1197,10 @@ uint8_t c128_state::cia1_pa_r()
11861197
*/
11871198

11881199
uint8_t data = 0xff;
1200+
vcs_control_port_device *cur2 = m_portswap->read() ? m_joy1 : m_joy2;
11891201

11901202
// joystick
1191-
uint8_t joy_b = m_joy2->read_joy();
1203+
uint8_t joy_b = cur2->read_joy();
11921204

11931205
data &= (0xf0 | (joy_b & 0x0f));
11941206
data &= ~(!BIT(joy_b, 5) << 4);
@@ -1233,7 +1245,8 @@ void c128_state::cia1_pa_w(uint8_t data)
12331245
12341246
*/
12351247

1236-
m_joy2->joy_w(data & 0x1f);
1248+
vcs_control_port_device *cur2 = m_portswap->read() ? m_joy1 : m_joy2;
1249+
cur2->joy_w(data & 0x1f);
12371250
}
12381251

12391252
uint8_t c128_state::cia1_pb_r()
@@ -1254,9 +1267,10 @@ uint8_t c128_state::cia1_pb_r()
12541267
*/
12551268

12561269
uint8_t data = 0xff;
1270+
vcs_control_port_device *cur1 = m_portswap->read() ? m_joy2 : m_joy1;
12571271

12581272
// joystick
1259-
uint8_t joy_a = m_joy1->read_joy();
1273+
uint8_t joy_a = cur1->read_joy();
12601274

12611275
data &= (0xf0 | (joy_a & 0x0f));
12621276
data &= ~(!BIT(joy_a, 5) << 4);
@@ -1297,7 +1311,9 @@ void c128_state::cia1_pb_w(uint8_t data)
12971311
12981312
*/
12991313

1300-
m_joy1->joy_w(data & 0x1f);
1314+
vcs_control_port_device *cur1 = m_portswap->read() ? m_joy2 : m_joy1;
1315+
1316+
cur1->joy_w(data & 0x1f);
13011317

13021318
m_vic->lp_w(BIT(data, 4));
13031319
}

src/mame/commodore/c64.cpp

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class c64_state : public driver_device
7070
m_color_ram(*this, "color_ram", 0x400, ENDIANNESS_LITTLE),
7171
m_row(*this, "ROW%u", 0),
7272
m_lock(*this, "LOCK"),
73+
m_portswap(*this, "JOYSWAP"),
7374
m_loram(1),
7475
m_hiram(1),
7576
m_charen(1),
@@ -101,6 +102,7 @@ class c64_state : public driver_device
101102
memory_share_creator<uint8_t> m_color_ram;
102103
optional_ioport_array<8> m_row;
103104
optional_ioport m_lock;
105+
optional_ioport m_portswap;
104106

105107
virtual void machine_start() override ATTR_COLD;
106108
virtual void machine_reset() override ATTR_COLD;
@@ -844,6 +846,11 @@ static INPUT_PORTS_START( c64 )
844846
PORT_START( "LOCK" )
845847
PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("SHIFT LOCK") PORT_CODE(KEYCODE_CAPSLOCK) PORT_TOGGLE PORT_CHAR(UCHAR_MAMEKEY(CAPSLOCK))
846848
PORT_BIT( 0x7f, IP_ACTIVE_LOW, IPT_UNUSED )
849+
850+
PORT_START( "JOYSWAP" )
851+
PORT_CONFNAME( 0x01, 0x00, "Swap joystick ports" )
852+
PORT_CONFSETTING( 0x01, "Joystick in swapped port" )
853+
PORT_CONFSETTING( 0x00, "Joystick in assigned port" )
847854
INPUT_PORTS_END
848855

849856

@@ -874,6 +881,11 @@ INPUT_PORTS_END
874881

875882
static INPUT_PORTS_START( c64gs )
876883
// no keyboard
884+
885+
PORT_START( "JOYSWAP" )
886+
PORT_CONFNAME( 0x01, 0x00, "Switch joystick ports" )
887+
PORT_CONFSETTING( 0x01, "Joystick in switched port" )
888+
PORT_CONFSETTING( 0x00, "Joystick in assigned port" )
877889
INPUT_PORTS_END
878890

879891

@@ -899,23 +911,25 @@ INPUT_PORTS_END
899911
uint8_t c64_state::sid_potx_r()
900912
{
901913
uint8_t data = 0xff;
914+
vcs_control_port_device *cur1 = m_portswap->read() ? m_joy2 : m_joy1;
915+
vcs_control_port_device *cur2 = m_portswap->read() ? m_joy1 : m_joy2;
902916

903917
switch (m_cia1->pa_r() >> 6)
904918
{
905-
case 1: data = m_joy1->read_pot_x(); break;
906-
case 2: data = m_joy2->read_pot_x(); break;
919+
case 1: data = cur1->read_pot_x(); break;
920+
case 2: data = cur2->read_pot_x(); break;
907921
case 3:
908-
if (m_joy1->has_pot_x() && m_joy2->has_pot_x())
922+
if (cur1->has_pot_x() && cur2->has_pot_x())
909923
{
910-
data = 1 / (1 / m_joy1->read_pot_x() + 1 / m_joy2->read_pot_x());
924+
data = 1 / (1 / cur1->read_pot_x() + 1 / cur2->read_pot_x());
911925
}
912-
else if (m_joy1->has_pot_x())
926+
else if (cur1->has_pot_x())
913927
{
914-
data = m_joy1->read_pot_x();
928+
data = cur1->read_pot_x();
915929
}
916-
else if (m_joy2->has_pot_x())
930+
else if (cur2->has_pot_x())
917931
{
918-
data = m_joy2->read_pot_x();
932+
data = cur2->read_pot_x();
919933
}
920934
break;
921935
}
@@ -926,23 +940,25 @@ uint8_t c64_state::sid_potx_r()
926940
uint8_t c64_state::sid_poty_r()
927941
{
928942
uint8_t data = 0xff;
943+
vcs_control_port_device *cur1 = m_portswap->read() ? m_joy2 : m_joy1;
944+
vcs_control_port_device *cur2 = m_portswap->read() ? m_joy1 : m_joy2;
929945

930946
switch (m_cia1->pa_r() >> 6)
931947
{
932-
case 1: data = m_joy1->read_pot_y(); break;
933-
case 2: data = m_joy2->read_pot_y(); break;
948+
case 1: data = cur1->read_pot_y(); break;
949+
case 2: data = cur2->read_pot_y(); break;
934950
case 3:
935-
if (m_joy1->has_pot_y() && m_joy2->has_pot_y())
951+
if (cur1->has_pot_y() && cur2->has_pot_y())
936952
{
937-
data = 1 / (1 / m_joy1->read_pot_y() + 1 / m_joy2->read_pot_y());
953+
data = 1 / (1 / cur1->read_pot_y() + 1 / cur2->read_pot_y());
938954
}
939-
else if (m_joy1->has_pot_y())
955+
else if (cur1->has_pot_y())
940956
{
941-
data = m_joy1->read_pot_y();
957+
data = cur1->read_pot_y();
942958
}
943-
else if (m_joy2->has_pot_y())
959+
else if (cur2->has_pot_y())
944960
{
945-
data = m_joy2->read_pot_y();
961+
data = cur2->read_pot_y();
946962
}
947963
break;
948964
}
@@ -973,9 +989,10 @@ uint8_t c64_state::cia1_pa_r()
973989
*/
974990

975991
uint8_t data = 0xff;
992+
vcs_control_port_device *cur2 = m_portswap->read() ? m_joy1 : m_joy2;
976993

977994
// joystick
978-
uint8_t joy_b = m_joy2->read_joy();
995+
uint8_t joy_b = cur2->read_joy();
979996

980997
data &= (0xf0 | (joy_b & 0x0f));
981998
data &= ~(!BIT(joy_b, 5) << 4);
@@ -1041,9 +1058,10 @@ uint8_t c64_state::cia1_pb_r()
10411058
*/
10421059

10431060
uint8_t data = 0xff;
1061+
vcs_control_port_device *cur1 = m_portswap->read() ? m_joy2 : m_joy1;
10441062

10451063
// joystick
1046-
uint8_t joy_a = m_joy1->read_joy();
1064+
uint8_t joy_a = cur1->read_joy();
10471065

10481066
data &= (0xf0 | (joy_a & 0x0f));
10491067
data &= ~(!BIT(joy_a, 5) << 4);
@@ -1079,8 +1097,9 @@ void c64_state::cia1_pb_w(uint8_t data)
10791097
PB7 ROW7
10801098
10811099
*/
1100+
vcs_control_port_device *cur1 = m_portswap->read() ? m_joy2 : m_joy1;
10821101

1083-
m_joy1->joy_w(data & 0x1f);
1102+
cur1->joy_w(data & 0x1f);
10841103

10851104
m_vic->lp_w(BIT(data, 4));
10861105
}
@@ -1103,9 +1122,10 @@ uint8_t c64gs_state::cia1_pa_r()
11031122
*/
11041123

11051124
uint8_t data = 0xff;
1125+
vcs_control_port_device *cur2 = m_portswap->read() ? m_joy1 : m_joy2;
11061126

11071127
// joystick
1108-
uint8_t joy_b = m_joy2->read_joy();
1128+
uint8_t joy_b = cur2->read_joy();
11091129

11101130
data &= (0xf0 | (joy_b & 0x0f));
11111131
data &= ~(!BIT(joy_b, 5) << 4);
@@ -1131,9 +1151,10 @@ uint8_t c64gs_state::cia1_pb_r()
11311151
*/
11321152

11331153
uint8_t data = 0xff;
1154+
vcs_control_port_device *cur1 = m_portswap->read() ? m_joy2 : m_joy1;
11341155

11351156
// joystick
1136-
uint8_t joy_a = m_joy1->read_joy();
1157+
uint8_t joy_a = cur1->read_joy();
11371158

11381159
data &= (0xf0 | (joy_a & 0x0f));
11391160
data &= ~(!BIT(joy_a, 5) << 4);

src/mame/commodore/c65.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ class c65_state : public driver_device
324324
, m_ipl_rom(*this, "ipl")
325325
, m_cart_exp(*this, "cart_exp")
326326
, m_exrom_view(*this, "exrom_view")
327+
, m_portswap(*this, "JOYSWAP")
327328
{ }
328329

329330
void init_c65();
@@ -367,6 +368,7 @@ class c65_state : public driver_device
367368
required_memory_region m_ipl_rom;
368369
required_device<generic_slot_device> m_cart_exp;
369370
memory_view m_exrom_view;
371+
optional_ioport m_portswap;
370372

371373
uint8_t m_keyb_input[10]{};
372374
uint8_t m_keyb_c0_c7 = 0U;
@@ -1097,9 +1099,10 @@ void c65_state::uart_w(offs_t offset, uint8_t data)
10971099
uint8_t c65_state::cia0_porta_r()
10981100
{
10991101
uint8_t res = 0xff;
1102+
int cur_joy = m_portswap->read() ? 0 : 1;
11001103

11011104
// joystick
1102-
uint8_t joy_b = m_joy[1]->read_joy();
1105+
uint8_t joy_b = m_joy[cur_joy]->read_joy();
11031106

11041107
res &= (0xf0 | (joy_b & 0x0f));
11051108
res &= ~(!BIT(joy_b, 5) << 4);
@@ -1112,10 +1115,11 @@ uint8_t c65_state::cia0_portb_r()
11121115
{
11131116
static const char *const c64ports[] = { "C0", "C1", "C2", "C3", "C4", "C5", "C6", "C7" };
11141117
static const char *const c65ports[] = { "C8", "C9" };
1118+
int cur_joy = m_portswap->read() ? 1 : 0;
11151119
uint8_t res;
11161120

11171121
res = 0xff;
1118-
uint8_t joy_a = m_joy[0]->read_joy();
1122+
uint8_t joy_a = m_joy[cur_joy]->read_joy();
11191123

11201124
res &= (0xf0 | (joy_a & 0x0f));
11211125
res &= ~(!BIT(joy_a, 5) << 4);
@@ -1141,15 +1145,16 @@ uint8_t c65_state::cia0_portb_r()
11411145

11421146
void c65_state::cia0_porta_w(uint8_t data)
11431147
{
1148+
int cur_joy = m_portswap->read() ? 0 : 1;
11441149
m_keyb_c0_c7 = ~data;
1145-
m_joy[1]->joy_w(data & 0x1f);
1150+
m_joy[cur_joy]->joy_w(data & 0x1f);
11461151
// logerror("%02x\n",m_keyb_c0_c7);
11471152
}
11481153

11491154
void c65_state::cia0_portb_w(uint8_t data)
11501155
{
1151-
m_joy[0]->joy_w(data & 0x1f);
1152-
1156+
int cur_joy = m_portswap->read() ? 1 : 0;
1157+
m_joy[cur_joy]->joy_w(data & 0x1f);
11531158
}
11541159

11551160
/*
@@ -1323,6 +1328,11 @@ static INPUT_PORTS_START( c65 )
13231328

13241329
PORT_START("CAPS")
13251330
PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_KEYBOARD ) PORT_NAME("CAPS LOCK") PORT_CODE(KEYCODE_F8) PORT_TOGGLE
1331+
1332+
PORT_START( "JOYSWAP" )
1333+
PORT_CONFNAME( 0x01, 0x00, "Swap joystick ports" )
1334+
PORT_CONFSETTING( 0x01, "Joystick in swapped port" )
1335+
PORT_CONFSETTING( 0x00, "Joystick in assigned port" )
13261336
INPUT_PORTS_END
13271337

13281338

0 commit comments

Comments
 (0)