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
3 changes: 2 additions & 1 deletion Core/Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,9 @@
<ClInclude Include="WS\Debugger\WsPpuTools.h" />
<ClInclude Include="WS\Debugger\WsTraceLogger.h" />
<ClInclude Include="WS\APU\WsApu.h" />
<ClInclude Include="WS\Input\Pcv2Controller.h" />
<ClInclude Include="WS\WsConsole.h" />
<ClInclude Include="WS\WsController.h" />
<ClInclude Include="WS\Input\WsController.h" />
<ClInclude Include="WS\WsControlManager.h" />
<ClInclude Include="WS\WsCpu.h" />
<ClInclude Include="WS\WsCpuPrefetch.h" />
Expand Down
12 changes: 9 additions & 3 deletions Core/Core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -2880,9 +2880,6 @@
<ClInclude Include="WS\WsPpu.h">
<Filter>WS</Filter>
</ClInclude>
<ClInclude Include="WS\WsController.h">
<Filter>WS</Filter>
</ClInclude>
<ClInclude Include="WS\Carts\WsCart.h">
<Filter>WS\Carts</Filter>
</ClInclude>
Expand Down Expand Up @@ -2997,6 +2994,12 @@
<ClInclude Include="SNES\Input\AsciiTurboFileTwinTf2.h">
<Filter>SNES\Input</Filter>
</ClInclude>
<ClInclude Include="WS\Input\WsController.h">
<Filter>WS\Input</Filter>
</ClInclude>
<ClInclude Include="WS\Input\Pcv2Controller.h">
<Filter>WS\Input</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Shared\Video\RotateFilter.cpp">
Expand Down Expand Up @@ -3493,5 +3496,8 @@
<Filter Include="SNES\Coprocessors\SufamiTurbo">
<UniqueIdentifier>{bfdd4bb9-41c2-4255-a8c3-0176c990cbf3}</UniqueIdentifier>
</Filter>
<Filter Include="WS\Input">
<UniqueIdentifier>{5077d508-bbdf-4bab-9d03-9b3d2b05edfb}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>
3 changes: 2 additions & 1 deletion Core/Shared/FirmwareHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ class FirmwareHelper
FirmwareType firmwareType;
switch(model) {
default:
case WsModel::PocketChallenge:
case WsModel::Monochrome:
filename = "bootrom.ws";
firmwareType = FirmwareType::WonderSwan;
Expand All @@ -418,7 +419,7 @@ class FirmwareHelper
firmwareType = FirmwareType::SwanCrystal;
break;
}
uint32_t size = model == WsModel::Monochrome ? 0x1000 : 0x2000;
uint32_t size = firmwareType == FirmwareType::WonderSwan ? 0x1000 : 0x2000;
string path = FolderUtilities::CombinePath(FolderUtilities::GetFirmwareFolder(), filename);
if(AttemptLoadFirmware(bootRom, filename, size)) {
return true;
Expand Down
7 changes: 5 additions & 2 deletions Core/Shared/SettingTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ enum class ControllerType

//WS
WsController,
WsControllerVertical
WsControllerVertical,
Pcv2Controller
};

struct KeyMapping
Expand Down Expand Up @@ -762,7 +763,8 @@ enum class WsModel : uint8_t
Auto,
Monochrome,
Color,
SwanCrystal
SwanCrystal,
PocketChallenge
};

enum class WsAudioMode : uint8_t
Expand All @@ -775,6 +777,7 @@ struct WsConfig
{
ControllerConfig ControllerHorizontal;
ControllerConfig ControllerVertical;
ControllerConfig ControllerPcv2;

WsModel Model = WsModel::Auto;
bool UseBootRom = false;
Expand Down
16 changes: 8 additions & 8 deletions Core/WS/APU/WsApu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ WsApu::WsApu(Emulator* emu, WsConsole* console, WsMemoryManager* memoryManager,
_dmaController = dmaController;
_soundMixer = emu->GetSoundMixer();

_state.MasterVolume = _console->GetModel() == WsModel::Monochrome ? 2 : 3;
_state.MasterVolume = _console->IsColorModel() ? 3 : 2;
_state.InternalMasterVolume = _state.MasterVolume;

_ch1.reset(new WsApuCh1(this, _state.Ch1));
Expand All @@ -46,9 +46,9 @@ WsApu::~WsApu()

void WsApu::ChangeMasterVolume()
{
if(_emu->GetSettings()->GetWsConfig().AudioMode == WsAudioMode::Speakers) {
if(_console->GetAudioMode() == WsAudioMode::Speakers) {
if(_state.InternalMasterVolume == 0) {
_state.InternalMasterVolume = _console->GetModel() == WsModel::Monochrome ? 2 : 3;
_state.InternalMasterVolume = _console->IsColorModel() ? 3 : 2;
} else {
_state.InternalMasterVolume--;
}
Expand Down Expand Up @@ -113,7 +113,7 @@ void WsApu::UpdateOutput()
rightOutput = leftOutput;
}

if(cfg.AudioMode == WsAudioMode::Headphones) {
if(_console->GetAudioMode() == WsAudioMode::Headphones) {
if(_state.HeadphoneEnabled) {
leftOutput <<= 5;
rightOutput <<= 5;
Expand All @@ -132,7 +132,7 @@ void WsApu::UpdateOutput()
leftOutput = out;
rightOutput = out;

if(_console->GetModel() == WsModel::Monochrome) {
if(!_console->IsColorModel()) {
switch(_state.InternalMasterVolume) {
case 0:
leftOutput = 0;
Expand Down Expand Up @@ -253,7 +253,7 @@ uint8_t WsApu::Read(uint16_t port)
(uint8_t)_state.SpeakerEnabled |
(_state.SpeakerVolume << 1) |
((uint8_t)_state.HeadphoneEnabled << 3) |
(_emu->GetSettings()->GetWsConfig().AudioMode == WsAudioMode::Headphones ? 0x80 : 0));
(_console->GetAudioMode() == WsAudioMode::Headphones ? 0x80 : 0));

case 0x92: return BitUtilities::GetBits<0>(_state.Ch4.Lfsr);
case 0x93: return BitUtilities::GetBits<8>(_state.Ch4.Lfsr);
Expand All @@ -275,7 +275,7 @@ uint8_t WsApu::Read(uint16_t port)
case 0x9B: return (GetApuOutput(false) + GetApuOutput(true)) >> 8;

case 0x9E:
if(_console->GetModel() != WsModel::Monochrome) {
if(_console->IsColorModel()) {
return _state.MasterVolume;
}
break;
Expand Down Expand Up @@ -366,7 +366,7 @@ void WsApu::Write(uint16_t port, uint8_t value)
break;

case 0x9E:
if(_console->GetModel() != WsModel::Monochrome) {
if(_console->IsColorModel()) {
_state.InternalMasterVolume = value & 0x03;
_state.MasterVolume = value & 0x03;
}
Expand Down
45 changes: 29 additions & 16 deletions Core/WS/Debugger/WsDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#include "WS/Debugger/WsEventManager.h"
#include "WS/Debugger/WsTraceLogger.h"
#include "WS/Debugger/WsPpuTools.h"
#include "WS/WsController.h"
#include "WS/Input/WsController.h"
#include "WS/Input/Pcv2Controller.h"
#include "WS/WsCpu.h"
#include "WS/WsPpu.h"
#include "WS/WsConsole.h"
Expand All @@ -18,7 +19,6 @@
#include "Debugger/BreakpointManager.h"
#include "Debugger/Debugger.h"
#include "Debugger/MemoryAccessCounter.h"
#include "Debugger/ExpressionEvaluator.h"
#include "Debugger/CodeDataLogger.h"
#include "Debugger/BaseEventManager.h"
#include "Debugger/StepBackManager.h"
Expand Down Expand Up @@ -497,20 +497,33 @@ void WsDebugger::ProcessInputOverrides(DebugControllerState inputOverrides[8])
{
BaseControlManager* controlManager = _console->GetControlManager();
for(int i = 0; i < 8; i++) {
shared_ptr<WsController> controller = std::dynamic_pointer_cast<WsController>(controlManager->GetControlDeviceByIndex(i));
if(controller && inputOverrides[i].HasPressedButton()) {
controller->SetBitValue(WsController::Buttons::A, inputOverrides[i].A);
controller->SetBitValue(WsController::Buttons::B, inputOverrides[i].B);
controller->SetBitValue(WsController::Buttons::Start, inputOverrides[i].Start);
controller->SetBitValue(WsController::Buttons::Sound, inputOverrides[i].Select);
controller->SetBitValue(WsController::Buttons::Up, inputOverrides[i].Up);
controller->SetBitValue(WsController::Buttons::Down, inputOverrides[i].Down);
controller->SetBitValue(WsController::Buttons::Left, inputOverrides[i].Left);
controller->SetBitValue(WsController::Buttons::Right, inputOverrides[i].Right);
controller->SetBitValue(WsController::Buttons::Up2, inputOverrides[i].U);
controller->SetBitValue(WsController::Buttons::Down2, inputOverrides[i].D);
controller->SetBitValue(WsController::Buttons::Left2, inputOverrides[i].L);
controller->SetBitValue(WsController::Buttons::Right2, inputOverrides[i].R);
shared_ptr<WsController> wsController = std::dynamic_pointer_cast<WsController>(controlManager->GetControlDeviceByIndex(i));
if(wsController && inputOverrides[i].HasPressedButton()) {
wsController->SetBitValue(WsController::Buttons::A, inputOverrides[i].A);
wsController->SetBitValue(WsController::Buttons::B, inputOverrides[i].B);
wsController->SetBitValue(WsController::Buttons::Start, inputOverrides[i].Start);
wsController->SetBitValue(WsController::Buttons::Sound, inputOverrides[i].Select);
wsController->SetBitValue(WsController::Buttons::Up, inputOverrides[i].Up);
wsController->SetBitValue(WsController::Buttons::Down, inputOverrides[i].Down);
wsController->SetBitValue(WsController::Buttons::Left, inputOverrides[i].Left);
wsController->SetBitValue(WsController::Buttons::Right, inputOverrides[i].Right);
wsController->SetBitValue(WsController::Buttons::Up2, inputOverrides[i].U);
wsController->SetBitValue(WsController::Buttons::Down2, inputOverrides[i].D);
wsController->SetBitValue(WsController::Buttons::Left2, inputOverrides[i].L);
wsController->SetBitValue(WsController::Buttons::Right2, inputOverrides[i].R);
}

shared_ptr<Pcv2Controller> pcv2Controller = std::dynamic_pointer_cast<Pcv2Controller>(controlManager->GetControlDeviceByIndex(i));
if(pcv2Controller && inputOverrides[i].HasPressedButton()) {
pcv2Controller->SetBitValue(Pcv2Controller::Buttons::Up, inputOverrides[i].Up);
pcv2Controller->SetBitValue(Pcv2Controller::Buttons::Down, inputOverrides[i].Down);
pcv2Controller->SetBitValue(Pcv2Controller::Buttons::Left, inputOverrides[i].Left);
pcv2Controller->SetBitValue(Pcv2Controller::Buttons::Right, inputOverrides[i].Right);
pcv2Controller->SetBitValue(Pcv2Controller::Buttons::Clear, inputOverrides[i].A);
pcv2Controller->SetBitValue(Pcv2Controller::Buttons::Circle, inputOverrides[i].B);
pcv2Controller->SetBitValue(Pcv2Controller::Buttons::Pass, inputOverrides[i].D);
pcv2Controller->SetBitValue(Pcv2Controller::Buttons::Esc, inputOverrides[i].Select);
pcv2Controller->SetBitValue(Pcv2Controller::Buttons::View, inputOverrides[i].Start);
}
}
controlManager->RefreshHubState();
Expand Down
103 changes: 103 additions & 0 deletions Core/WS/Input/Pcv2Controller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#pragma once
#include "pch.h"
#include "Shared/BaseControlDevice.h"
#include "Shared/Emulator.h"
#include "Shared/InputHud.h"

class Pcv2Controller : public BaseControlDevice
{
private:
uint32_t _turboSpeed = 0;

protected:
string GetKeyNames() override
{
return "udlrepcCv";
}

void InternalSetStateFromInput() override
{
for(KeyMapping& keyMapping : _keyMappings) {
for(int i = Buttons::Up; i <= Buttons::View; i++) {
SetPressedState(Buttons::Clear, keyMapping.A);
SetPressedState(Buttons::Circle, keyMapping.B);
SetPressedState(Buttons::Pass, keyMapping.X);
SetPressedState(Buttons::Esc, keyMapping.Select);
SetPressedState(Buttons::View, keyMapping.Start);
SetPressedState(Buttons::Up, keyMapping.Up);
SetPressedState(Buttons::Down, keyMapping.Down);
SetPressedState(Buttons::Left, keyMapping.Left);
SetPressedState(Buttons::Right, keyMapping.Right);
}

uint8_t turboFreq = 1 << (4 - _turboSpeed);
bool turboOn = (uint8_t)(_emu->GetFrameCount() % turboFreq) < turboFreq / 2;
if(turboOn) {
SetPressedState(Buttons::Clear, keyMapping.TurboA);
SetPressedState(Buttons::Circle, keyMapping.TurboB);
SetPressedState(Buttons::Pass, keyMapping.TurboX);
}
}
}

public:
enum Buttons
{
Up = 0,
Down,
Left,
Right,
Esc,
Pass,
Circle,
Clear,
View
};

Pcv2Controller(Emulator* emu, uint8_t port, KeyMappingSet keyMappings) : BaseControlDevice(emu, ControllerType::Pcv2Controller, port, keyMappings)
{
_turboSpeed = keyMappings.TurboSpeed;
}

uint8_t ReadRam(uint16_t addr) override
{
return 0;
}

void WriteRam(uint16_t addr, uint8_t value) override
{
}

void InternalDrawController(InputHud& hud) override
{
hud.DrawOutline(35, 16);

hud.DrawButton(5, 5, 3, 3, IsPressed(Buttons::Up));
hud.DrawButton(5, 11, 3, 3, IsPressed(Buttons::Down));
hud.DrawButton(2, 8, 3, 3, IsPressed(Buttons::Left));
hud.DrawButton(8, 8, 3, 3, IsPressed(Buttons::Right));
hud.DrawButton(9, 2, 2, 2, IsPressed(Buttons::Esc));

hud.DrawButton(30, 5, 3, 3, IsPressed(Buttons::Clear));
hud.DrawButton(27, 8, 3, 3, IsPressed(Buttons::Circle));
hud.DrawButton(24, 11, 3, 3, IsPressed(Buttons::Pass));
hud.DrawButton(24, 2, 2, 2, IsPressed(Buttons::View));

hud.DrawNumber(_port + 1, 16, 2);
}

vector<DeviceButtonName> GetKeyNameAssociations() override
{
return {
{ "up", Buttons::Up },
{ "down", Buttons::Down },
{ "left", Buttons::Left },
{ "right", Buttons::Right },
{ "esc", Buttons::Esc },
{ "pass", Buttons::Pass },
{ "circle", Buttons::Circle },
{ "clear", Buttons::Clear },
{ "view", Buttons::View },
};
}
};
2 changes: 0 additions & 2 deletions Core/WS/WsController.h → Core/WS/Input/WsController.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
#include "WS/WsConsole.h"
#include "Shared/BaseControlDevice.h"
#include "Shared/Emulator.h"
#include "Shared/EmuSettings.h"
#include "Shared/InputHud.h"
#include "Utilities/Serializer.h"

class WsController : public BaseControlDevice
{
Expand Down
Loading
Loading