Skip to content

Commit

Permalink
Add support for the Japanese HPD-200 Paddle
Browse files Browse the repository at this point in the history
This makes games requiring a Paddle, such as Megumi Rescue,
playable with an analog stick, or using adapters USB adapters
supporting the HPD-200 Paddle.

"Prefer Japan" should be selected in tools->Boot Options before load
otherwise the game will expect the "Export Paddle" which is not
compatible.
  • Loading branch information
raphnet authored and LukeUsher committed Aug 16, 2022
1 parent 2ade0e3 commit 23416ea
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions ares/ms/controller/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ namespace ares::MasterSystem {
#include "port.cpp"
#include "gamepad/gamepad.cpp"
#include "light-phaser/light-phaser.cpp"
#include "paddle/paddle.cpp"

}
1 change: 1 addition & 0 deletions ares/ms/controller/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ struct Controller {
#include "port.hpp"
#include "gamepad/gamepad.hpp"
#include "light-phaser/light-phaser.hpp"
#include "paddle/paddle.hpp"
40 changes: 40 additions & 0 deletions ares/ms/controller/paddle/paddle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Paddle::Paddle(Node::Port parent) {
node = parent->append<Node::Peripheral>("Paddle");

button = node->append<Node::Input::Button>("Button");
axis = node->append<Node::Input::Axis> ("X-Axis");

// 18kHz - As measured on real hardware
Thread::create(18000, {&Paddle::main, this});
}

Paddle::~Paddle() {
Thread::destroy();
}

auto Paddle::main() -> void {
secondNibble = !secondNibble;

Thread::step(1);
Thread::synchronize(cpu);
}

auto Paddle::read() -> n7 {
platform->input(button);
platform->input(axis);

n7 data;
if (secondNibble) {
data.bit(0,3) = value.bit(4,7);
} else {
// scale {-32768 ... +32767} to {0 ... 255 }
value = (axis->value() + 32768.0) * 255.0 / 65535.0;
data.bit(0,3) = value.bit(0,3);
}

data.bit(4) = !button->value();
data.bit(5) = secondNibble;
data.bit(6) = 1;

return data;
}
14 changes: 14 additions & 0 deletions ares/ms/controller/paddle/paddle.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
struct Paddle : Controller, Thread {
Node::Input::Axis axis;
Node::Input::Button button;

Paddle(Node::Port);
~Paddle();

auto main() -> void;
auto read() -> n7 override;

private:
n8 value;
b1 secondNibble;
};
3 changes: 2 additions & 1 deletion ares/ms/controller/port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ auto ControllerPort::load(Node::Object parent) -> void {
port->setType("Controller");
port->setHotSwappable(true);
port->setAllocate([&](auto name) { return allocate(name); });
port->setSupported({"Gamepad", "Light Phaser"});
port->setSupported({"Gamepad", "Light Phaser", "Paddle"});
}

auto ControllerPort::unload() -> void {
Expand All @@ -21,6 +21,7 @@ auto ControllerPort::unload() -> void {
auto ControllerPort::allocate(string name) -> Node::Peripheral {
if(name == "Gamepad") device = new Gamepad(port);
if(name == "Light Phaser") device = new LightPhaser(port);
if(name == "Paddle") device = new Paddle(port);
if(device) return device->node;
return {};
}
Expand Down
7 changes: 7 additions & 0 deletions desktop-ui/emulator/master-system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ MasterSystem::MasterSystem() {
device.digital("2", virtualPorts[id].pad.east);
port.append(device); }

{ InputDevice device{"Paddle"};
device.analog ("L-Left", virtualPorts[id].pad.lstick_left);
device.analog ("L-Right", virtualPorts[id].pad.lstick_right);
device.analog ("X-Axis", virtualPorts[id].pad.lstick_left, virtualPorts[id].pad.lstick_right);
device.digital("Button", virtualPorts[id].pad.south);
port.append(device); }

ports.append(port);
}
}
Expand Down

0 comments on commit 23416ea

Please sign in to comment.