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

Adding input callback for quickernes #4200

Open
wants to merge 3 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/libquicknes.dll
Binary file not shown.
Binary file modified Assets/dll/libquicknes.so
Binary file not shown.
5 changes: 5 additions & 0 deletions quicknes/bizinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ QN_EXPORT const char *qn_set_sample_rate(quickerNES::Emu *e, int rate)
return ret;
}

void (*input_callback_cb)(void) = nullptr;
QN_EXPORT void qn_set_input_callback(void (*fecb)(void))
{
input_callback_cb = fecb;
}

QN_EXPORT const char *qn_emulate_frame(quickerNES::Emu *e, uint32_t pad1, uint32_t pad2, uint8_t arkanoidPosition, uint8_t arkanoidFire, int controllerType)
{
Expand Down
2 changes: 1 addition & 1 deletion quicknes/core
2 changes: 1 addition & 1 deletion quicknes/make/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CP = cp

CXXFLAGS = -I../core/source/quickerNES/core/ -I../core/extern/jaffarCommon/include -Wall -Wfatal-errors -Werror \
-std=c++20 -O3 -fomit-frame-pointer -flto -fvisibility=internal -fvisibility-inlines-hidden \
-D_GNU_SOURCE -D__INLINE__=inline -D_QUICKERNES_DETECT_JOYPAD_READS -D_QUICKERNES_ENABLE_TRACEBACK_SUPPORT -D_QUICKERNES_SUPPORT_ARKANOID_INPUTS
-D_GNU_SOURCE -D__INLINE__=inline -D_QUICKERNES_DETECT_JOYPAD_READS -D_QUICKERNES_ENABLE_TRACEBACK_SUPPORT -D_QUICKERNES_SUPPORT_ARKANOID_INPUTS -D_QUICKERNES_ENABLE_INPUT_CALLBACK

# TODO: include these as options in the Makefile
# -fprofile-generate
Expand Down
2 changes: 1 addition & 1 deletion quicknes/msvc/libquicknes.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
<Optimization>Disabled</Optimization>
<DisableSpecificWarnings>4244;4800;4804;4996</DisableSpecificWarnings>
<AdditionalIncludeDirectories>$(ProjectDir)\..</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_WINDLL;%(PreprocessorDefinitions);_QUICKERNES_DETECT_JOYPAD_READS;_QUICKERNES_ENABLE_TRACEBACK_SUPPORT;_QUICKERNES_SUPPORT_ARKANOID_INPUTS;__INLINE__=inline</PreprocessorDefinitions>
<PreprocessorDefinitions>_WINDLL;%(PreprocessorDefinitions);_QUICKERNES_DETECT_JOYPAD_READS;_QUICKERNES_ENABLE_TRACEBACK_SUPPORT;_QUICKERNES_SUPPORT_ARKANOID_INPUTS;__INLINE__=inline;_QUICKERNES_ENABLE_INPUT_CALLBACK</PreprocessorDefinitions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ public abstract class LibQuickNES
[BizImport(CallingConvention.Cdecl)]
public abstract void qn_set_tracecb(IntPtr e, TraceCallback cb);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void input_cb();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this include the index? See #3233.


[BizImport(CallingConvention.Cdecl)]
public abstract void qn_set_input_callback(input_cb cb);

[BizImport(CallingConvention.Cdecl)]
public abstract byte qn_get_reg2000(IntPtr e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
public partial class QuickNES : IInputPollable
{
public int LagCount { get; set; }

public bool IsLagFrame { get; set; }

public IInputCallbackSystem InputCallbacks
public IInputCallbackSystem InputCallbacks => _inputCallbacks;

private readonly LibQuickNES.input_cb _inputCallback;

private readonly InputCallbackSystem _inputCallbacks = [ ];

private void InputCallback()
{
[FeatureNotImplemented]
get => throw new NotImplementedException();
InputCallbacks.Call();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public QuickNES(byte[] file, QuickNESSettings settings, QuickNESSyncSettings syn
{
ServiceProvider = new BasicServiceProvider(this);
Context = QN.qn_new();

if (Context == IntPtr.Zero)
{
throw new InvalidOperationException($"{nameof(QN.qn_new)}() returned NULL");
Expand All @@ -47,6 +48,10 @@ public QuickNES(byte[] file, QuickNESSettings settings, QuickNESSyncSettings syn
InitAudio();
InitMemoryDomains();

// Setting input callback
_inputCallback = InputCallback;
QN.qn_set_input_callback(_inputCallback);

int mapper = 0;
string mappername = Marshal.PtrToStringAnsi(QN.qn_get_mapper(Context, ref mapper));
Console.WriteLine($"{CoreNames.QuickNes}: Booted with Mapper #{mapper} \"{mappername}\"");
Expand Down