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

Add Nintendo Switch support #2

Merged
merged 2 commits into from
Dec 29, 2020
Merged
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 .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
rvm.xcodeproj/project.xcworkspace/xcuserdata
.vs
.vscode
Rvm_Win64/x64
/x64*
*.o
Expand Down
49 changes: 49 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
project(soniccd)

cmake_minimum_required(VERSION 3.0)

include(FindPkgConfig)

set(CMAKE_C_FLAGS "-g -DLINUX -DSDL_DISABLE_IMMINTRIN_H -DSDL_DISABLE_MMINTRIN_H -std=c99 ${CMAKE_C_FLAGS}")

pkg_check_modules(SDL2 sdl2 REQUIRED)
if(NSWITCH)
set(CMAKE_C_FLAGS "-DGLEW_NO_GLU ${CMAKE_C_FLAGS}")
find_package(GLEW REQUIRED)
find_library(GLEW_LIBRARY NAMES GLEW)
set(EXTRA_LIBS mpg123 modplug mikmod vorbisfile vorbis ogg FLAC fluidsynth opusfile opus ${GLEW_LIBRARY} stdc++)
else()
set(OpenGL_GL_PREFERENCE LEGACY)
find_package(OpenGL REQUIRED)
set(EXTRA_LIBS ${OPENGL_gl_LIBRARY})
endif(NSWITCH)

include_directories(
${SDL2_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/rvm/Core
)

file(GLOB SRC rvm/*.c rvm/Core/*.c)
add_executable(${CMAKE_PROJECT_NAME}
${SRC}
)

target_link_libraries(${CMAKE_PROJECT_NAME}
SDL2_mixer
${SDL2_LIBRARIES}
${EXTRA_LIBS}
m
)

if(NSWITCH)
add_definitions(-D__SWITCH__)
add_custom_target(${CMAKE_PROJECT_NAME}.nro
DEPENDS ${CMAKE_PROJECT_NAME}
COMMAND nacptool --create "Sonic CD" "Sappharad, usineur" "0.7.5" ${CMAKE_PROJECT_NAME}.nacp
COMMAND elf2nro ${CMAKE_PROJECT_NAME} ${CMAKE_PROJECT_NAME}.nro --icon=${CMAKE_SOURCE_DIR}/icon.jpg --nacp=${CMAKE_PROJECT_NAME}.nacp
)
add_custom_target(nxlink
COMMAND nxlink -a $(SWITCHIP) ${CMAKE_PROJECT_NAME}.nro -s -p ${CMAKE_PROJECT_NAME}/${CMAKE_PROJECT_NAME}.nro
DEPENDS ${CMAKE_PROJECT_NAME}.nro
)
endif(NSWITCH)
Binary file added icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion rvm/Core/AnimationSystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void AnimationSystem_LoadAnimationFile(char* filePath)
animationFrames[animationFramesNo].xSize = (int)b2;
b2 = FileIO_ReadByte();
animationFrames[animationFramesNo].ySize = (int)b2;
char b3 = (char)FileIO_ReadByte();
signed char b3 = (signed char)FileIO_ReadByte();
animationFrames[animationFramesNo].xPivot = (int)b3;
b3 = (char)FileIO_ReadByte();
animationFrames[animationFramesNo].yPivot = (int)b3;
Expand Down
1 change: 1 addition & 0 deletions rvm/Core/FileIO.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ bool FileIO_CheckRSDKFile()
useRSDKFile = true;
useByteCode = false;
fclose(fileReader);
fileReader = NULL;

if (FileIO_LoadFile("Data/Scripts/ByteCode/GlobalCode.bin", &fData))
{
Expand Down
8 changes: 8 additions & 0 deletions rvm/Core/InputSystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,19 @@ void InputSystem_CheckGamepadInput(){
{
touchData.right = 1;
}
#ifdef __SWITCH__
if(SDL_GameControllerGetButton(sdlController, SDL_CONTROLLER_BUTTON_B))
#else
if(SDL_GameControllerGetButton(sdlController, SDL_CONTROLLER_BUTTON_A))
#endif
{
touchData.buttonA = 1;
}
#ifdef __SWITCH__
if(SDL_GameControllerGetButton(sdlController, SDL_CONTROLLER_BUTTON_A))
#else
if(SDL_GameControllerGetButton(sdlController, SDL_CONTROLLER_BUTTON_B))
#endif
{
touchData.buttonB = 1;
}
Expand Down
6 changes: 4 additions & 2 deletions rvm/Core/RenderDevice.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
#include <Windows.h>
#include <GL/glew.h>
#pragma comment(lib, "glew32s.lib")
#elif __SWITCH__
#include <GL/glew.h>
#elif LINUX
#include <gl/GL.h>
#include <gl/glext.h>
#include <GL/gl.h>
#include <GL/glext.h>
#else
#include <OpenGL/gl.h>
#endif
Expand Down
30 changes: 27 additions & 3 deletions rvm/main_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
#include <string.h>
#include <math.h>
#include <SDL2/SDL.h>
#ifdef __SWITCH__
#include <GL/glew.h>
#include <switch.h>
#else
#include <SDL2/SDL_opengl.h>
#include <GL/gl.h>
#endif
#include "GlobalAppDefinitions.h"
#include "GraphicsSystem.h"
#ifdef __EMSCRIPTEN__
Expand Down Expand Up @@ -34,6 +38,10 @@ static void initAttributes()
// on OpenGL double buffering.
value = 1;
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, value);

#ifdef __SWITCH__
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
#endif
}

static void printAttributes()
Expand Down Expand Up @@ -77,6 +85,14 @@ static void createSurface(int fullscreen)
exit(2);
}
SDL_GL_CreateContext(gWindow);
#ifdef __SWITCH__
GLenum err = glewInit();
if (err != GLEW_OK) {
fprintf(stderr, "glewInit() failed: %s\n", glewGetErrorString(err));
SDL_Quit();
return;
}
#endif

glViewport(0, 0, 800, 480);
//glViewport(0, 0, 864, 480);
Expand All @@ -98,6 +114,7 @@ static void createSurface(int fullscreen)

void UpdateIO() {
InputSystem_CheckKeyboardInput();
InputSystem_CheckGamepadInput();
InputSystem_ClearTouchData();

if (stageMode != 2)
Expand Down Expand Up @@ -216,8 +233,12 @@ void loop_func(void *arg) {

int main (int argc, char **argv)
{
#ifdef __SWITCH__
socketInitializeDefault();
nxlinkStdio();
#endif
// Init SDL video subsystem
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {

fprintf(stderr, "Couldn't initialize SDL: %s\n",
SDL_GetError());
Expand Down Expand Up @@ -248,6 +269,9 @@ int main (int argc, char **argv)
// Cleanup
SDL_Quit();

#ifdef __SWITCH__
socketExit();
#endif

return 0;
}