Skip to content
Open
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
1 change: 1 addition & 0 deletions Core/Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@
<ClInclude Include="WS\Debugger\WsPpuTools.h" />
<ClInclude Include="WS\Debugger\WsTraceLogger.h" />
<ClInclude Include="WS\APU\WsApu.h" />
<ClInclude Include="WS\Pcv2Controller.h" />
<ClInclude Include="WS\WsConsole.h" />
<ClInclude Include="WS\WsController.h" />
<ClInclude Include="WS\WsControlManager.h" />
Expand Down
3 changes: 3 additions & 0 deletions Core/Core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -2880,6 +2880,9 @@
<ClInclude Include="WS\WsPpu.h">
<Filter>WS</Filter>
</ClInclude>
<ClInclude Include="WS\Pcv2Controller.h">
<Filter>WS</Filter>
</ClInclude>
<ClInclude Include="WS\WsController.h">
<Filter>WS</Filter>
</ClInclude>
Expand Down
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 @@ -239,7 +239,8 @@ enum class ControllerType

//WS
WsController,
WsControllerVertical
WsControllerVertical,
Pcv2Controller
};

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

enum class WsAudioMode : uint8_t
Expand All @@ -760,6 +762,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
38 changes: 24 additions & 14 deletions Core/WS/Debugger/WsDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "WS/Debugger/WsTraceLogger.h"
#include "WS/Debugger/WsPpuTools.h"
#include "WS/WsController.h"
#include "WS/Pcv2Controller.h"
#include "WS/WsCpu.h"
#include "WS/WsPpu.h"
#include "WS/WsConsole.h"
Expand Down Expand Up @@ -497,20 +498,29 @@ 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);
//TODOWS other buttons
}
}
controlManager->RefreshHubState();
Expand Down
94 changes: 94 additions & 0 deletions Core/WS/Pcv2Controller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#pragma once
#include "pch.h"
#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 Pcv2Controller : public BaseControlDevice
{
private:
WsConsole* _console = nullptr;

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

void InternalSetStateFromInput() override
{
for(KeyMapping& keyMapping : _keyMappings) {
for(int i = Buttons::Up; i <= Buttons::View; i++) {
SetPressedState(i, keyMapping.CustomKeys[i]);
}
}
}

void RefreshStateBuffer() override
{
}

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

Pcv2Controller(Emulator* emu, WsConsole* console, uint8_t port, KeyMappingSet mappings) : BaseControlDevice(emu, ControllerType::Pcv2Controller, port, mappings)
{
_console = console;
}

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 },
};
}
};
Loading