Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit 7c8a54a

Browse files
committed
VS System: Fixed/improved button remapping
1 parent 36b88ac commit 7c8a54a

32 files changed

+331
-145
lines changed

Core/BaseControlDevice.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@ class BaseControlDevice : public Snapshotable
7474
void SetRawState(ControlDeviceState state);
7575
ControlDeviceState GetRawState();
7676

77-
template<typename T>
78-
shared_ptr<T> GetState()
79-
{
80-
return std::dynamic_pointer_cast<T>(_state);
81-
}
82-
8377
virtual uint8_t ReadRAM(uint16_t addr) = 0;
8478
virtual void WriteRAM(uint16_t addr, uint8_t value) = 0;
8579

Core/ControlManager.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ uint8_t ControlManager::GetOpenBusMask(uint8_t port)
244244
}
245245
}
246246

247+
void ControlManager::RemapControllerButtons()
248+
{
249+
//Used by VS System games
250+
}
251+
247252
void ControlManager::UpdateInputState()
248253
{
249254
if(_isLagging) {
@@ -277,6 +282,9 @@ void ControlManager::UpdateInputState()
277282
//log += "|" + device->GetTextState();
278283
}
279284

285+
//Used by VS System games
286+
RemapControllerButtons();
287+
280288
shared_ptr<Debugger> debugger = _console->GetDebugger(false);
281289
if(debugger) {
282290
debugger->ProcessEvent(EventType::InputPolled);

Core/ControlManager.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,13 @@ class ControlManager : public Snapshotable, public IMemoryHandler
2222
vector<IInputProvider*> _inputProviders;
2323

2424
//Static so that power cycle does not reset its value
25-
//TODOCONSOLE : PollCounter needs to be kept through power cycle
2625
uint32_t _pollCounter;
2726

2827
shared_ptr<BaseControlDevice> _mapperControlDevice;
2928

3029
uint32_t _lagCounter = 0;
3130
bool _isLagging = false;
3231

33-
uint8_t GetOpenBusMask(uint8_t port);
34-
3532
protected:
3633
shared_ptr<Console> _console;
3734
SimpleLock _deviceLock;
@@ -42,6 +39,8 @@ class ControlManager : public Snapshotable, public IMemoryHandler
4239

4340
virtual void StreamState(bool saving) override;
4441
virtual ControllerType GetControllerType(uint8_t port);
42+
virtual void RemapControllerButtons();
43+
virtual uint8_t GetOpenBusMask(uint8_t port);
4544

4645
public:
4746
ControlManager(shared_ptr<Console> console, shared_ptr<BaseControlDevice> systemActionManager, shared_ptr<BaseControlDevice> mapperControlDevice);

Core/EmulationSettings.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,8 @@ enum class PpuModel
307307
enum class VsInputType
308308
{
309309
Default = 0,
310-
TypeA = 1,
311-
TypeB = 2,
312-
TypeC = 3,
313-
TypeD = 4,
314-
TypeE = 5
310+
SwapControllers = 1,
311+
SwapAB = 2
315312
};
316313

317314
struct KeyMapping

Core/GameDatabase.cpp

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -528,13 +528,12 @@ void GameDatabase::SetVsSystemDefaults(uint32_t prgCrc32)
528528
switch(prgCrc32) {
529529
case 0xEB2DBA63: case 0x98CFE016:
530530
//TKOBoxing
531-
inputType = VsInputType::TypeA;
532531
model = PpuModel::Ppu2C04C;
533532
break;
534533

535534
case 0x135ADF7C:
536535
//RBIBaseball
537-
inputType = VsInputType::TypeB;
536+
inputType = VsInputType::SwapControllers;
538537
model = PpuModel::Ppu2C04A;
539538
break;
540539

@@ -545,105 +544,96 @@ void GameDatabase::SetVsSystemDefaults(uint32_t prgCrc32)
545544

546545
case 0x16D3F469:
547546
//NinjaJajamaruKun
548-
inputType = VsInputType::TypeC;
547+
inputType = VsInputType::SwapControllers;
549548
model = PpuModel::Ppu2C05A;
550549
break;
551550

552551
case 0x8850924B:
553552
//Tetris
554553
model = PpuModel::Ppu2C03;
555-
inputType = VsInputType::TypeB;
554+
inputType = VsInputType::SwapControllers;
556555
defaultDip = 32;
557556
break;
558557

559558
case 0x8C0C2DF5:
560559
//TopGun
561-
inputType = VsInputType::TypeA;
562560
model = PpuModel::Ppu2C05D;
563561
break;
564562

565563
case 0x70901B25:
566564
//Slalom
567-
inputType = VsInputType::TypeA;
568565
model = PpuModel::Ppu2C04B;
569566
break;
570567

571568
case 0xCF36261E:
572569
//SuperSkyKid
573-
inputType = VsInputType::TypeC;
570+
inputType = VsInputType::SwapControllers;
574571
model = PpuModel::Ppu2C04A;
575572
break;
576573

577574
case 0xE1AA8214:
578575
//StarLuster
579-
inputType = VsInputType::TypeA;
580576
model = PpuModel::Ppu2C04A;
581577
defaultDip = 32;
582578
break;
583579

584580
case 0xD5D7EAC4:
585581
//DrMario
586-
inputType = VsInputType::TypeB;
582+
inputType = VsInputType::SwapControllers;
587583
model = PpuModel::Ppu2C04C;
588584
break;
589585

590586
case 0xFFBEF374:
591587
//Castlevania
592-
inputType = VsInputType::TypeA;
593588
model = PpuModel::Ppu2C04B;
594589
break;
595590

596591
case 0xE2C0A2BE:
597592
//Platoon
598-
inputType = VsInputType::TypeA;
599593
model = PpuModel::Ppu2C04A;
600594
break;
601595

602596
case 0x29155E0C:
603597
//ExciteBike
604-
inputType = VsInputType::TypeA;
605598
model = PpuModel::Ppu2C04D;
606599
break;
607600

608601
case 0xCBE85490:
609602
//ExciteBikeB
610-
inputType = VsInputType::TypeA;
611603
model = PpuModel::Ppu2C04C;
612604
break;
613605

614606
case 0x07138C06:
615607
//Clu Clu Land
616-
inputType = VsInputType::TypeB;
608+
inputType = VsInputType::SwapControllers;
617609
model = PpuModel::Ppu2C04D;
618610
break;
619611

620612
case 0x43A357EF:
621613
//IceClimber
622-
inputType = VsInputType::TypeB;
614+
inputType = VsInputType::SwapControllers;
623615
model = PpuModel::Ppu2C04D;
624616
break;
625617

626618
case 0xD4EB5923:
627619
//IceClimberB
628-
inputType = VsInputType::TypeD;
620+
inputType = VsInputType::SwapControllers;
629621
model = PpuModel::Ppu2C04D;
630622
break;
631623

632624
case 0x737DD1BF: case 0x4BF3972D: case 0x8B60CC58: case 0x8192C804:
633625
//SuperMarioBros
634-
inputType = VsInputType::TypeA;
635626
model = PpuModel::Ppu2C04D;
636627
break;
637628

638629
case 0xE528F651:
639630
//Pinball
640-
inputType = VsInputType::TypeE;
631+
inputType = VsInputType::SwapAB;
641632
model = PpuModel::Ppu2C03;
642633
break;
643634

644635
case 0xEC461DB9:
645636
//PinballB
646-
inputType = VsInputType::TypeA;
647637
model = PpuModel::Ppu2C04A;
648638
break;
649639

@@ -654,31 +644,29 @@ void GameDatabase::SetVsSystemDefaults(uint32_t prgCrc32)
654644

655645
case 0x0B65A917: case 0x8A6A9848:
656646
//MachRider
657-
inputType = VsInputType::TypeA;
658647
model = PpuModel::Ppu2C04B;
659648
break;
660649

661650
case 0x46914E3E:
662651
//Soccer
663-
inputType = VsInputType::TypeB;
652+
inputType = VsInputType::SwapControllers;
664653
model = PpuModel::Ppu2C04C;
665654
break;
666655

667656
case 0x70433F2C:
668657
//Battle City
669-
inputType = VsInputType::TypeB;
658+
inputType = VsInputType::SwapControllers;
670659
model = PpuModel::Ppu2C04A;
671660
break;
672661

673662
case 0xD99A2087:
674663
//Gradius
675-
inputType = VsInputType::TypeB;
664+
inputType = VsInputType::SwapControllers;
676665
model = PpuModel::Ppu2C04A;
677666
break;
678667

679668
case 0x1E438D52:
680669
//Goonies
681-
inputType = VsInputType::TypeA;
682670
model = PpuModel::Ppu2C04C;
683671
break;
684672

@@ -694,31 +682,29 @@ void GameDatabase::SetVsSystemDefaults(uint32_t prgCrc32)
694682

695683
case 0xC99EC059:
696684
//RaidBungelingBay
697-
inputType = VsInputType::TypeD;
685+
inputType = VsInputType::SwapControllers;
698686
model = PpuModel::Ppu2C04B;
699687
break;
700688

701689
case 0xF9D3B0A3: case 0x66BB838F: case 0x9924980A:
702690
//SuperXevious
703-
inputType = VsInputType::TypeA;
704691
model = PpuModel::Ppu2C04A;
705692
break;
706693

707694
case 0xA93A5AEE:
708695
//Golf
709-
inputType = VsInputType::TypeB;
696+
inputType = VsInputType::SwapControllers;
710697
model = PpuModel::Ppu2C03;
711698
break;
712699

713700
case 0xCC2C4B5D: case 0x86167220:
714701
//GolfB
715-
inputType = VsInputType::TypeB;
702+
inputType = VsInputType::SwapControllers;
716703
model = PpuModel::Ppu2C04B;
717704
break;
718705

719706
case 0xCA85E56D:
720707
//MightyBombJack
721-
inputType = VsInputType::TypeA;
722708
model = PpuModel::Ppu2C05B;
723709
break;
724710

Core/VsControlManager.cpp

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -53,35 +53,36 @@ void VsControlManager::RemapControllerButtons()
5353
}
5454

5555
VsInputType inputType = EmulationSettings::GetVsInputType();
56-
if(inputType == VsInputType::TypeA) {
57-
BaseControlDevice::SwapButtons(controllers[0], StandardController::Buttons::Select, controllers[0], StandardController::Buttons::Start);
58-
BaseControlDevice::SwapButtons(controllers[1], StandardController::Buttons::Select, controllers[1], StandardController::Buttons::Start);
59-
} else if(inputType == VsInputType::TypeB) {
60-
std::swap(controllers[0], controllers[1]);
61-
BaseControlDevice::SwapButtons(controllers[1], StandardController::Buttons::Select, controllers[0], StandardController::Buttons::Start);
62-
BaseControlDevice::SwapButtons(controllers[0], StandardController::Buttons::Select, controllers[1], StandardController::Buttons::Start);
63-
} else if(inputType == VsInputType::TypeC) {
64-
std::swap(controllers[0], controllers[1]);
65-
66-
if(controllers[0]->IsPressed(StandardController::Buttons::Start)) {
67-
controllers[1]->SetBit(StandardController::Buttons::Select);
68-
} else {
69-
controllers[1]->ClearBit(StandardController::Buttons::Select);
70-
}
71-
72-
controllers[0]->ClearBit(StandardController::Buttons::Start);
73-
controllers[0]->ClearBit(StandardController::Buttons::Select);
74-
} else if(inputType == VsInputType::TypeD) {
75-
std::swap(controllers[0], controllers[1]);
76-
BaseControlDevice::SwapButtons(controllers[1], StandardController::Buttons::Select, controllers[0], StandardController::Buttons::Start);
77-
BaseControlDevice::SwapButtons(controllers[0], StandardController::Buttons::Select, controllers[1], StandardController::Buttons::Start);
78-
controllers[0]->InvertBit(StandardController::Buttons::Select);
79-
controllers[1]->InvertBit(StandardController::Buttons::Select);
80-
} else if(inputType == VsInputType::TypeE) {
56+
if(inputType == VsInputType::SwapControllers) {
57+
//Swap controllers 1 & 2
58+
ControlDeviceState port1State = controllers[0]->GetRawState();
59+
ControlDeviceState port2State = controllers[1]->GetRawState();
60+
controllers[0]->SetRawState(port2State);
61+
controllers[1]->SetRawState(port1State);
62+
63+
//But don't swap the start/select buttons
64+
BaseControlDevice::SwapButtons(controllers[0], StandardController::Buttons::Start, controllers[1], StandardController::Buttons::Start);
65+
BaseControlDevice::SwapButtons(controllers[0], StandardController::Buttons::Select, controllers[1], StandardController::Buttons::Select);
66+
} else if(inputType == VsInputType::SwapAB) {
67+
//Swap buttons P1 A & P2 B (Pinball (Japan))
8168
BaseControlDevice::SwapButtons(controllers[0], StandardController::Buttons::B, controllers[1], StandardController::Buttons::A);
82-
BaseControlDevice::SwapButtons(controllers[0], StandardController::Buttons::Select, controllers[0], StandardController::Buttons::Start);
83-
BaseControlDevice::SwapButtons(controllers[1], StandardController::Buttons::Select, controllers[1], StandardController::Buttons::Start);
8469
}
70+
71+
//Swap Start/Select for all configurations (makes it more intuitive)
72+
BaseControlDevice::SwapButtons(controllers[0], StandardController::Buttons::Start, controllers[0], StandardController::Buttons::Select);
73+
BaseControlDevice::SwapButtons(controllers[1], StandardController::Buttons::Start, controllers[1], StandardController::Buttons::Select);
74+
75+
uint32_t crc = _console->GetMapperInfo().Hash.PrgCrc32Hash;
76+
if(crc == 0x99FB3B3B) {
77+
//Bit 3 of the input status must always be on (Raid on Bungeling Bay protection)
78+
controllers[0]->InvertBit(StandardController::Buttons::Start);
79+
controllers[1]->InvertBit(StandardController::Buttons::Start);
80+
}
81+
}
82+
83+
uint8_t VsControlManager::GetOpenBusMask(uint8_t port)
84+
{
85+
return 0x00;
8586
}
8687

8788
uint8_t VsControlManager::ReadRAM(uint16_t addr)
@@ -93,7 +94,7 @@ uint8_t VsControlManager::ReadRAM(uint16_t addr)
9394
switch(addr) {
9495
case 0x4016: {
9596
uint32_t dipSwitches = EmulationSettings::GetDipSwitches();
96-
value = ControlManager::ReadRAM(addr);
97+
value = ControlManager::ReadRAM(addr) & 0x65;
9798
value |= ((dipSwitches & 0x01) ? 0x08 : 0x00);
9899
value |= ((dipSwitches & 0x02) ? 0x10 : 0x00);
99100
value |= (_console->IsMaster() ? 0x00 : 0x80);
@@ -145,10 +146,6 @@ void VsControlManager::WriteRAM(uint16_t addr, uint8_t value)
145146
bool previousState = _refreshState;
146147
_refreshState = (value & 0x01) == 0x01;
147148

148-
if(previousState && !_refreshState) {
149-
RemapControllerButtons();
150-
}
151-
152149
if(addr == 0x4016) {
153150
_prgChrSelectBit = (value >> 2) & 0x01;
154151

Core/VsControlManager.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ class VsControlManager : public ControlManager, public IInputProvider
4141
}
4242
};
4343

44+
protected:
4445
ControllerType GetControllerType(uint8_t port) override;
46+
void RemapControllerButtons() override;
47+
uint8_t GetOpenBusMask(uint8_t port) override;
48+
4549
void UpdateSlaveMasterBit(uint8_t slaveMasterBit);
4650

4751
public:
@@ -56,8 +60,6 @@ class VsControlManager : public ControlManager, public IInputProvider
5660

5761
void UpdateControlDevices() override;
5862

59-
void RemapControllerButtons();
60-
6163
uint8_t ReadRAM(uint16_t addr) override;
6264
void WriteRAM(uint16_t addr, uint8_t value) override;
6365

Core/iNesLoader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ RomData iNesLoader::LoadRom(vector<uint8_t>& romFile, NESHeader *preloadedHeader
7777

7878
romData.PrgCrc32 = CRC32::GetCRC(romData.PrgRom.data(), romData.PrgRom.size());
7979

80+
Log("PRG CRC32: 0x" + HexUtilities::ToHex(romData.PrgCrc32, true));
8081
Log("PRG+CHR CRC32: 0x" + HexUtilities::ToHex(romData.PrgChrCrc32, true));
8182

8283
if(romData.IsNes20Header) {

0 commit comments

Comments
 (0)