Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ColecoVision - Added "Super Action Controller" support #1338

Closed
Closed
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 ares/cv/controller/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ namespace ares::ColecoVision {

#include "port.cpp"
#include "gamepad/gamepad.cpp"
#include "super_action/super_action.cpp"

}
1 change: 1 addition & 0 deletions ares/cv/controller/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ struct Controller : Thread {

#include "port.hpp"
#include "gamepad/gamepad.hpp"
#include "super_action/super_action.hpp"
3 changes: 2 additions & 1 deletion ares/cv/controller/port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ auto ControllerPort::load(Node::Object parent) -> void {
port->setHotSwappable(true);
port->setAllocate([&](auto name) { return allocate(name); });
port->setDisconnect([&] { device.reset(); });
port->setSupported({"Gamepad"});
port->setSupported({"Gamepad","SuperActionController"});
}

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 == "SuperActionController") device = new SuperActionController(port);
if(device) return device->node;
return {};
}
Expand Down
92 changes: 92 additions & 0 deletions ares/cv/controller/super_action/super_action.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
SuperActionController::SuperActionController(Node::Port parent) {
node = parent->append<Node::Peripheral>("SuperActionController");

up = node->append<Node::Input::Button>("Up");
down = node->append<Node::Input::Button>("Down");
left = node->append<Node::Input::Button>("Left");
right = node->append<Node::Input::Button>("Right");
l = node->append<Node::Input::Button>("L");
r = node->append<Node::Input::Button>("R");
one = node->append<Node::Input::Button>("1");
two = node->append<Node::Input::Button>("2");
three = node->append<Node::Input::Button>("3");
four = node->append<Node::Input::Button>("4");
five = node->append<Node::Input::Button>("5");
six = node->append<Node::Input::Button>("6");
seven = node->append<Node::Input::Button>("7");
eight = node->append<Node::Input::Button>("8");
nine = node->append<Node::Input::Button>("9");
star = node->append<Node::Input::Button>("*");
zero = node->append<Node::Input::Button>("0");
pound = node->append<Node::Input::Button>("#");

y = node->append<Node::Input::Button>("Y");
x = node->append<Node::Input::Button>("X");
}

auto SuperActionController::read() -> n8 {
platform->input(up);
platform->input(down);
platform->input(left);
platform->input(right);
platform->input(l);
platform->input(r);
platform->input(one);
platform->input(two);
platform->input(three);
platform->input(four);
platform->input(five);
platform->input(six);
platform->input(seven);
platform->input(eight);
platform->input(nine);
platform->input(star);
platform->input(zero);
platform->input(pound);

platform->input(x);
platform->input(y);

if(!(up->value() & down->value())) {
yHold = 0, upLatch = up->value(), downLatch = down->value();
} else if(!yHold) {
yHold = 1, swap(upLatch, downLatch);
}

if(!(left->value() & right->value())) {
xHold = 0, leftLatch = left->value(), rightLatch = right->value();
} else if(!xHold) {
xHold = 1, swap(leftLatch, rightLatch);
}

n8 data = 0x7f;
if(select == 0) {
if(one->value ()) data.bit(0,3) = 0b1101;
else if(two->value ()) data.bit(0,3) = 0b0111;
else if(three->value()) data.bit(0,3) = 0b1100;
else if(four->value ()) data.bit(0,3) = 0b0010;
else if(five->value ()) data.bit(0,3) = 0b0011;
else if(six->value ()) data.bit(0,3) = 0b1110;
else if(seven->value()) data.bit(0,3) = 0b0101;
else if(eight->value()) data.bit(0,3) = 0b0001;
else if(nine->value ()) data.bit(0,3) = 0b1011;
else if(star->value ()) data.bit(0,3) = 0b1001;
else if(zero->value ()) data.bit(0,3) = 0b1010;
else if(pound->value()) data.bit(0,3) = 0b0110;

else if(x->value ()) data.bit(0,3) = 0x04;
else if(y->value()) data.bit(0,3) = 0x08;
data.bit(6) = !r->value();
} else {
data.bit(0) = !upLatch;
data.bit(1) = !rightLatch;
data.bit(2) = !downLatch;
data.bit(3) = !leftLatch;
data.bit(6) = !l->value();
}
return data;
}

auto SuperActionController::write(n8 data) -> void {
select = data.bit(0);
}
38 changes: 38 additions & 0 deletions ares/cv/controller/super_action/super_action.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
struct SuperActionController : Controller {
Node::Input::Button up;
Node::Input::Button down;
Node::Input::Button left;
Node::Input::Button right;
Node::Input::Button l;
Node::Input::Button r;
Node::Input::Button one;
Node::Input::Button two;
Node::Input::Button three;
Node::Input::Button four;
Node::Input::Button five;
Node::Input::Button six;
Node::Input::Button seven;
Node::Input::Button eight;
Node::Input::Button nine;
Node::Input::Button star;
Node::Input::Button zero;
Node::Input::Button pound;

Node::Input::Button x;
Node::Input::Button y;

SuperActionController(Node::Port);

auto read() -> n8 override;
auto write(n8 data) -> void override;

n1 select;

private:
b1 yHold;
b1 upLatch;
b1 downLatch;
b1 xHold;
b1 leftLatch;
b1 rightLatch;
};
26 changes: 24 additions & 2 deletions desktop-ui/emulator/colecovision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ ColecoVision::ColecoVision() {
device.digital("Down", virtualPorts[id].pad.down);
device.digital("Left", virtualPorts[id].pad.left);
device.digital("Right", virtualPorts[id].pad.right);
device.digital("L", virtualPorts[id].pad.south);
device.digital("R", virtualPorts[id].pad.east);
device.digital("L", virtualPorts[id].pad.south); // F1
device.digital("R", virtualPorts[id].pad.east); // F2
device.digital("1", virtualPorts[id].pad.west);
device.digital("2", virtualPorts[id].pad.north);
device.digital("3", virtualPorts[id].pad.l_bumper);
Expand All @@ -34,6 +34,28 @@ ColecoVision::ColecoVision() {
device.digital("*", virtualPorts[id].pad.select);
device.digital("#", virtualPorts[id].pad.start);
port.append(device); }

{ InputDevice device{"SuperActionController"};
device.digital("Up", virtualPorts[id].pad.up);
device.digital("Down", virtualPorts[id].pad.down);
device.digital("Left", virtualPorts[id].pad.left);
device.digital("Right", virtualPorts[id].pad.right);
device.digital("L", virtualPorts[id].pad.south); // F1
device.digital("R", virtualPorts[id].pad.east); // F2
device.digital("Y", virtualPorts[id].pad.lstick_down); // F3
device.digital("X", virtualPorts[id].pad.lstick_up); // F4
device.digital("2", virtualPorts[id].pad.north);
device.digital("3", virtualPorts[id].pad.l_bumper);
device.digital("4", virtualPorts[id].pad.l_trigger);
device.digital("5", virtualPorts[id].pad.r_bumper);
device.digital("6", virtualPorts[id].pad.r_trigger);
device.digital("7", virtualPorts[id].pad.lstick_click);
device.digital("8", virtualPorts[id].pad.rstick_click);
device.digital("9", virtualPorts[id].pad.rstick_down);
device.digital("0", virtualPorts[id].pad.rstick_right);
device.digital("*", virtualPorts[id].pad.select);
device.digital("#", virtualPorts[id].pad.start);
port.append(device); }

ports.append(port);
}
Expand Down
Loading