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

[A26][Stella] Adds support for the console Select switch #4178

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
Binary file modified Assets/dll/stella.wbx.zst
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public abstract bool stella_init(
[In] InitSettings settings);

[BizImport(CallingConvention.Cdecl)]
public abstract void stella_frame_advance(int port1, int port2, bool reset, bool power, bool leftDiffToggled, bool rightDiffToggled);
public abstract void stella_frame_advance(int port1, int port2, int switchPort, bool power);

[BizImport(CallingConvention.Cdecl)]
public abstract void stella_get_video(out int w, out int h, out int pitch, ref IntPtr buffer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,24 @@ public bool FrameAdvance(IController controller, bool render, bool renderSound)
int port1 = _controllerDeck.ReadPort1(controller);
int port2 = _controllerDeck.ReadPort2(controller);

// Handle all the console controls here
// Handle all the console switches here
if (controller.IsPressed("Toggle Right Difficulty")) _rightDifficultyToggled = !_rightDifficultyToggled;
if (controller.IsPressed("Toggle Left Difficulty")) _leftDifficultyToggled = !_leftDifficultyToggled;

// select and reset switches default to an unpressed state
// unknown whether TV color switch matters for TASing, so default to Color for now
int switchPort = 0b00001011;
if (_rightDifficultyToggled) switchPort |= 0b10000000;
if (_leftDifficultyToggled) switchPort |= 0b01000000;
if (controller.IsPressed("Select")) switchPort &= 0b11111101; // 0 = Pressed
if (controller.IsPressed("Reset")) switchPort &= 0b11111110; // 0 = Pressed

bool powerPressed = false;
bool resetPressed = false;
if (controller.IsPressed("Power")) powerPressed = true;
if (controller.IsPressed("Reset")) resetPressed = true;
if (controller.IsPressed("Toggle Left Difficulty")) _leftDifficultyToggled = !_leftDifficultyToggled;
if (controller.IsPressed("Toggle Right Difficulty")) _rightDifficultyToggled = !_rightDifficultyToggled;

IsLagFrame = true;

Core.stella_frame_advance(port1, port2, resetPressed, powerPressed, _leftDifficultyToggled, _rightDifficultyToggled);
Core.stella_frame_advance(port1, port2, switchPort, powerPressed);

if (IsLagFrame)
LagCount++;
Expand Down
69 changes: 39 additions & 30 deletions waterbox/stella/BizhawkInterface.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -150,36 +150,45 @@ ECL_EXPORT void stella_get_audio(int *n, void **buffer)

ECL_EXPORT void stella_get_video(int& w, int& h, int& pitch, uint8_t*& buffer)
{
w = _a2600->console().tia().width();
h = _a2600->console().tia().height();
buffer = _a2600->console().tia().frameBuffer();
pitch = _a2600->console().tia().width();
}


ECL_EXPORT void stella_frame_advance(uint8_t port1, uint8_t port2, bool reset, bool power, bool leftDiffToggled, bool rightDiffToggled)
{
_a2600->console().switches().setLeftDifficultyA(leftDiffToggled);
_a2600->console().switches().setRightDifficultyA(rightDiffToggled);
_a2600->console().switches().setReset(!reset);
if (power) _a2600->console().system().reset(true);

_a2600->console().leftController().write(::Controller::DigitalPin::One, port1 & 0b00010000); // Up
_a2600->console().leftController().write(::Controller::DigitalPin::Two, port1 & 0b00100000); // Down
_a2600->console().leftController().write(::Controller::DigitalPin::Three, port1 & 0b01000000); // Left
_a2600->console().leftController().write(::Controller::DigitalPin::Four, port1 & 0b10000000); // Right
_a2600->console().leftController().write(::Controller::DigitalPin::Six, port1 & 0b00001000); // Button

_a2600->console().rightController().write(::Controller::DigitalPin::One, port2 & 0b00010000); // Up
_a2600->console().rightController().write(::Controller::DigitalPin::Two, port2 & 0b00100000); // Down
_a2600->console().rightController().write(::Controller::DigitalPin::Three, port2 & 0b01000000); // Left
_a2600->console().rightController().write(::Controller::DigitalPin::Four, port2 & 0b10000000); // Right
_a2600->console().rightController().write(::Controller::DigitalPin::Six, port2 & 0b00001000); // Button

nsamples = 0;
_a2600->dispatchEmulation();
// printRAM();
// printFrameBuffer();
w = _a2600->console().tia().width();
h = _a2600->console().tia().height();
buffer = _a2600->console().tia().frameBuffer();
pitch = _a2600->console().tia().width();
}

// Console Switches (switchPort)
// SWCHB.7 P1 Difficulty Switch (0=Beginner (B), 1=Advanced (A))
// SWCHB.6 P0 Difficulty Switch (0=Beginner (B), 1=Advanced (A))
// SWCHB.4-5 Not used
// SWCHB.3 Color Switch (0=B/W, 1=Color) (Always 0 for SECAM)
// SWCHB.2 Not used
// SWCHB.1 Select Switch (0=Pressed)
// SWCHB.0 Reset Switch (0=Pressed)
ECL_EXPORT void stella_frame_advance(uint8_t port1, uint8_t port2, uint8_t switchPort, bool power)
{
_a2600->console().switches().setRightDifficultyA(switchPort & 0b10000000);
_a2600->console().switches().setLeftDifficultyA( switchPort & 0b01000000);
_a2600->console().switches().setTvColor( switchPort & 0b00001000);
_a2600->console().switches().setSelect( switchPort & 0b00000010);
_a2600->console().switches().setReset( switchPort & 0b00000001);
if (power) _a2600->console().system().reset(true);

_a2600->console().leftController().write(::Controller::DigitalPin::One, port1 & 0b00010000); // Up
_a2600->console().leftController().write(::Controller::DigitalPin::Two, port1 & 0b00100000); // Down
_a2600->console().leftController().write(::Controller::DigitalPin::Three, port1 & 0b01000000); // Left
_a2600->console().leftController().write(::Controller::DigitalPin::Four, port1 & 0b10000000); // Right
_a2600->console().leftController().write(::Controller::DigitalPin::Six, port1 & 0b00001000); // Button

_a2600->console().rightController().write(::Controller::DigitalPin::One, port2 & 0b00010000); // Up
_a2600->console().rightController().write(::Controller::DigitalPin::Two, port2 & 0b00100000); // Down
_a2600->console().rightController().write(::Controller::DigitalPin::Three, port2 & 0b01000000); // Left
_a2600->console().rightController().write(::Controller::DigitalPin::Four, port2 & 0b10000000); // Right
_a2600->console().rightController().write(::Controller::DigitalPin::Six, port2 & 0b00001000); // Button

nsamples = 0;
_a2600->dispatchEmulation();
// printRAM();
// printFrameBuffer();
}

ECL_ENTRY void (*input_callback_cb)(void);
Expand Down
2 changes: 1 addition & 1 deletion waterbox/stella/core