Compare commits

...

4 Commits

Author SHA1 Message Date
CasualPokePlayer
e30e68e6cf
Merge 47b4df3d63 into 7c1d2a64f4 2024-11-13 07:50:01 -07:00
Nadia Holmquist Pedersen
7c1d2a64f4 Set WIN32_LEAN_AND_MEAN, gets rid of the winsock2 warnings and probably
Some checks failed
macOS / ${{ matrix.arch }} (arm64) (push) Has been cancelled
macOS / ${{ matrix.arch }} (x86_64) (push) Has been cancelled
Ubuntu / x86_64 (push) Has been cancelled
Ubuntu / aarch64 (push) Has been cancelled
Windows / build (push) Has been cancelled
macOS / Universal binary (push) Has been cancelled
speeds up compilation a tiny bit

oh and NOMINMAX too for good measure while we're at it
2024-11-11 14:18:05 +01:00
Nadia Holmquist Pedersen
b2f6fab6f4 cmake: use interface include directories properly
and fix an indent I guess
2024-11-11 12:06:12 +01:00
CasualPokePlayer
47b4df3d63 Implement BizHawk's touch input interpolation changes in the core
"Touch input interpolation" here is rather simple: it does a simple linear interpolation against the touch values between the last frame's touch position and the current frame's touch position, using the current frame cycle count. In case the last frame wasn't touching anything, it just touches immediately.

The API presented here was originally intended as a way to try to avoid merge conflicts. It is intended that before RunFrame(), the user would call MoveTouch(), then call TouchScreen() once RunFrame() returns.

Alternatively, TouchScreen() could be solely called before RunFrame() (this would probably be what the libretro port does, maybe some other ports). This however will run into issues for some games which do not like immediate changes to touch input every frame, rather needing touch input to go slowly across the frame, as touch input gets polled multiple times in a frame (see https://github.com/TASEmulators/BizHawk/issues/3397).

melonDS Qt doesn't do this however, instead just calling TouchScreen() within mouse event handlers, i.e. within the UI thread, not the emulator thread. This does end up making it (at least seemingly) avoid issues with games not liking exactly per frame touch changes, but it is just a giant race condition and probably should be changed.
2024-10-23 16:11:52 -07:00
9 changed files with 68 additions and 16 deletions

View File

@ -127,6 +127,8 @@ if (ENABLE_JIT)
endif()
endif()
target_include_directories(core INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")
set(MELONDS_VERSION_SUFFIX "$ENV{MELONDS_VERSION_SUFFIX}" CACHE STRING "Suffix to add to displayed melonDS version")
option(MELONDS_EMBED_BUILD_INFO "Embed detailed build info into the binary" OFF)
set(MELONDS_GIT_BRANCH "$ENV{MELONDS_GIT_BRANCH}" CACHE STRING "The Git branch used for this build")
@ -178,13 +180,14 @@ endif()
if (WIN32)
target_link_libraries(core PRIVATE ole32 comctl32 wsock32 ws2_32)
target_compile_definitions(core PUBLIC WIN32_LEAN_AND_MEAN NOMINMAX)
elseif(NOT APPLE AND NOT HAIKU)
check_library_exists(rt shm_open "" NEED_LIBRT)
if (NEED_LIBRT)
target_link_libraries(core PRIVATE rt)
endif()
elseif(HAIKU)
target_link_libraries(core PRIVATE network)
target_link_libraries(core PRIVATE network)
endif()
if (ENABLE_JIT_PROFILING)

View File

@ -88,6 +88,8 @@ void DSi_TSC::SetTouchCoords(u16 x, u16 y)
TouchX = x;
TouchY = y;
DeltaX = DeltaY = 0;
u8 oldpress = Bank3Regs[0x0E] & 0x01;
if (y == 0xFFF)
@ -121,6 +123,22 @@ void DSi_TSC::SetTouchCoords(u16 x, u16 y)
}
}
void DSi_TSC::MoveTouchCoords(u16 x, u16 y)
{
if (TSCMode == 0x00) return TSC::MoveTouchCoords(x, y);
if (Bank3Regs[0x0E] & 0x01)
{
return SetTouchCoords(x, y);
}
DeltaX = (x << 4) - (TouchX & ~0x8000);
DeltaY = (y << 4) - (TouchY & ~0x8000);
Bank3Regs[0x09] = 0x80;
Bank3Regs[0x0E] &= ~0x01;
}
void DSi_TSC::MicInputFrame(const s16* data, int samples)
{
if (TSCMode == 0x00) return TSC::MicInputFrame(data, samples);
@ -162,8 +180,9 @@ void DSi_TSC::Write(u8 val)
{
// X coordinates
if (id & 0x01) Data = TouchX >> 8;
else Data = TouchX & 0xFF;
u16 touchX = TouchX + CreateTouchOffset(DeltaX);
if (id & 0x01) Data = touchX >> 8;
else Data = touchX & 0xFF;
TouchX &= 0x7FFF;
}
@ -171,8 +190,9 @@ void DSi_TSC::Write(u8 val)
{
// Y coordinates
if (id & 0x01) Data = TouchY >> 8;
else Data = TouchY & 0xFF;
u16 touchY = TouchY + CreateTouchOffset(DeltaY);
if (id & 0x01) Data = touchY >> 8;
else Data = touchY & 0xFF;
TouchY &= 0x7FFF; // checkme
}

View File

@ -40,6 +40,7 @@ public:
void SetMode(u8 mode);
void SetTouchCoords(u16 x, u16 y) override;
void MoveTouchCoords(u16 x, u16 y) override;
void MicInputFrame(const s16* data, int samples) override;
void Write(u8 val) override;

View File

@ -1122,6 +1122,11 @@ void NDS::TouchScreen(u16 x, u16 y)
SPI.GetTSC()->SetTouchCoords(x, y);
}
void NDS::MoveTouch(u16 x, u16 y)
{
SPI.GetTSC()->MoveTouchCoords(x, y);
}
void NDS::ReleaseScreen()
{
SPI.GetTSC()->SetTouchCoords(0x000, 0xFFF);

View File

@ -392,6 +392,7 @@ public: // TODO: Encapsulate the rest of these members
bool IsRunning() const noexcept { return Running; }
void TouchScreen(u16 x, u16 y);
void MoveTouch(u16 x, u16 y);
void ReleaseScreen();
void SetKeyMask(u32 mask);

View File

@ -352,6 +352,12 @@ void PowerMan::Write(u8 val)
}
s16 TSC::CreateTouchOffset(s16 delta) const
{
// 560190 cycles per frame
s64 cyclepos = (s64)NDS.GetSysClockCycles(2);
return (cyclepos * delta) / 560190;
}
TSC::TSC(melonDS::NDS& nds) : SPIDevice(nds)
{
@ -392,6 +398,8 @@ void TSC::SetTouchCoords(u16 x, u16 y)
TouchX = x;
TouchY = y;
DeltaX = DeltaY = 0;
if (y == 0xFFF)
{
// released
@ -404,6 +412,17 @@ void TSC::SetTouchCoords(u16 x, u16 y)
NDS.KeyInput &= ~(1 << (16+6));
}
void TSC::MoveTouchCoords(u16 x, u16 y)
{
if (NDS.KeyInput & (1 << (16+6)))
{
return SetTouchCoords(x, y);
}
DeltaX = (x << 4) - TouchX;
DeltaY = (y << 4) - TouchY;
}
void TSC::MicInputFrame(const s16* data, int samples)
{
if (!data)
@ -433,8 +452,8 @@ void TSC::Write(u8 val)
switch (ControlByte & 0x70)
{
case 0x10: ConvResult = TouchY; break;
case 0x50: ConvResult = TouchX; break;
case 0x10: ConvResult = TouchY + CreateTouchOffset(DeltaY); break;
case 0x50: ConvResult = TouchX + CreateTouchOffset(DeltaX); break;
case 0x60:
{

View File

@ -121,6 +121,7 @@ public:
virtual void DoSavestate(Savestate* file) override;
virtual void SetTouchCoords(u16 x, u16 y);
virtual void MoveTouchCoords(u16 x, u16 y);
virtual void MicInputFrame(const s16* data, int samples);
virtual void Write(u8 val) override;
@ -131,9 +132,12 @@ protected:
u16 ConvResult;
u16 TouchX, TouchY;
s16 DeltaX, DeltaY;
s16 MicBuffer[1024];
int MicBufferLen;
s16 CreateTouchOffset(s16 delta) const;
};

View File

@ -91,8 +91,7 @@ add_compile_definitions(ARCHIVE_SUPPORT_ENABLED)
add_executable(melonDS ${SOURCES_QT_SDL})
add_subdirectory("../../net"
"${CMAKE_BINARY_DIR}/net"
)
${CMAKE_BINARY_DIR}/net)
target_link_libraries(melonDS PRIVATE net-utils)
@ -171,10 +170,10 @@ if (BUILD_STATIC)
endif()
endif()
target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..")
target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../..")
target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../../net")
target_include_directories(melonDS PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/..")
if (USE_QT6)
target_include_directories(melonDS PUBLIC ${Qt6Gui_PRIVATE_INCLUDE_DIRS})
else()

View File

@ -11,9 +11,9 @@ add_library(net-utils STATIC
MPInterface.cpp
)
target_include_directories(net-utils PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
target_include_directories(net-utils PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..")
target_include_directories(net-utils PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/..")
option(USE_SYSTEM_LIBSLIRP "Use system libslirp instead of the bundled version" OFF)
if (USE_SYSTEM_LIBSLIRP)