Skip to content

Commit

Permalink
Switch: first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
usineur committed May 13, 2018
1 parent bc4a78e commit d35dbcc
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 2 deletions.
46 changes: 46 additions & 0 deletions CMakeLists.txt
@@ -0,0 +1,46 @@
cmake_minimum_required(VERSION 3.0)

set(CMAKE_SYSTEM_NAME "Generic")
set(DEVKITPRO $ENV{DEVKITPRO})
set(CMAKE_SYSTEM_PROCESSOR "armv8-a")
set(CMAKE_C_COMPILER "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-gcc")
set(CMAKE_CXX_COMPILER "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-g++")
set(CMAKE_ASM_COMPILER "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-as")
set(CMAKE_AR "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-gcc-ar" CACHE STRING "")
set(CMAKE_RANLIB "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-gcc-ranlib" CACHE STRING "")
set(CMAKE_C_FLAGS "-march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE -ffast-math -ffunction-sections -fdata-sections -I${DEVKITPRO}/libnx/include -I${DEVKITPRO}/portlibs/switch/include" CACHE STRING "C flags")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -fpermissive -fno-rtti -fno-exceptions -std=gnu++11" CACHE STRING "C++ flags")
set(CMAKE_FIND_ROOT_PATH ${DEVKITPRO} ${DEVKITPRO}/devkitA64 ${DEVKITPRO}/libnx ${DEVKITPRO}/portlibs/switch)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "Shared libs not available")
link_directories(${DEVKITPRO}/libnx/lib ${DEVKITPRO}/portlibs/switch/lib)

project(SDLPoP)

file(GLOB SRCS src/*.c)

set(POP_INC src)
set(POP_CFLAGS -fno-exceptions -O2)
set(POP_LDFLAGS SDL2_image SDL2 jpeg png z)

#list(REMOVE_ITEM SRCS ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)
#list(REMOVE_ITEM SRCS ${CMAKE_CURRENT_SOURCE_DIR}/dynlib.cpp)
#list(APPEND SRCS switch/main_switch.cpp switch/switch.c)
list(APPEND POP_CFLAGS -D__SWITCH__ -I${DEVKITPRO}/portlibs/switch/include/SDL2)
list(APPEND POP_LDFLAGS nx m -specs=${DEVKITPRO}/libnx/switch.specs)

add_executable(${CMAKE_PROJECT_NAME}.elf
${SRCS}
)
target_include_directories(${CMAKE_PROJECT_NAME}.elf PRIVATE ${POP_INC})
target_compile_options(${CMAKE_PROJECT_NAME}.elf PRIVATE ${POP_CFLAGS})
target_link_libraries(${CMAKE_PROJECT_NAME}.elf ${POP_LDFLAGS})

add_custom_target(${CMAKE_PROJECT_NAME}.nro
DEPENDS ${CMAKE_PROJECT_NAME}.elf
COMMAND nacptool --create "${CMAKE_PROJECT_NAME}" "usineur" "1.0" ${CMAKE_PROJECT_NAME}.nacp
COMMAND elf2nro ${CMAKE_PROJECT_NAME}.elf ${CMAKE_PROJECT_NAME}.nro --icon=${CMAKE_SOURCE_DIR}/res/icon.jpg --nacp=${CMAKE_PROJECT_NAME}.nacp
)
Binary file added res/icon.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/lighting.c
Expand Up @@ -19,20 +19,20 @@ The authors of this program may be contacted at http://forum.princed.org
*/

#include "common.h"
#include "lighting.h"

#ifdef USE_LIGHTING

image_type* screen_overlay = NULL;
Uint32 bgcolor;

const char mask_filename[] = "data/light.png";
const Uint8 ambient_level = 128;

// Called once at startup.
void init_lighting() {
if (!enable_lighting) return;

lighting_mask = IMG_Load(locate_file(mask_filename));
lighting_mask = IMG_Load_RW(SDL_RWFromConstMem(mask_img, mask_img_length), mask_img_length);
if (lighting_mask == NULL) {
sdlperror("IMG_Load (lighting_mask)");
enable_lighting = 0;
Expand Down
85 changes: 85 additions & 0 deletions src/lighting.h
@@ -0,0 +1,85 @@
/*
SDLPoP, a port/conversion of the DOS game Prince of Persia.
Copyright (C) 2013-2018 Dávid Nagy
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
The authors of this program may be contacted at http://forum.princed.org
*/

const char mask_img[664] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00,
0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00,
0x00, 0x64, 0x08, 0x02, 0x00, 0x00, 0x00, 0xff, 0x80, 0x02, 0x03,
0x00, 0x00, 0x00, 0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xae, 0xce,
0x1c, 0xe9, 0x00, 0x00, 0x00, 0x04, 0x67, 0x41, 0x4d, 0x41, 0x00,
0x00, 0xb1, 0x8f, 0x0b, 0xfc, 0x61, 0x05, 0x00, 0x00, 0x00, 0x20,
0x63, 0x48, 0x52, 0x4d, 0x00, 0x00, 0x7a, 0x26, 0x00, 0x00, 0x80,
0x84, 0x00, 0x00, 0xfa, 0x00, 0x00, 0x00, 0x80, 0xe8, 0x00, 0x00,
0x75, 0x30, 0x00, 0x00, 0xea, 0x60, 0x00, 0x00, 0x3a, 0x98, 0x00,
0x00, 0x17, 0x70, 0x9c, 0xba, 0x51, 0x3c, 0x00, 0x00, 0x02, 0x16,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0xf2, 0xba, 0xf4,
0xd2, 0xdb, 0xca, 0x7d, 0xf7, 0xe0, 0xe9, 0x07, 0x94, 0x49, 0x10,
0xd5, 0x3f, 0x2c, 0x80, 0x8b, 0xac, 0xbf, 0xef, 0xd4, 0x62, 0xdd,
0x4b, 0x69, 0x9b, 0x3f, 0x2d, 0xab, 0xb0, 0xe4, 0x75, 0x78, 0xd5,
0x4a, 0x09, 0x0b, 0xc3, 0x4a, 0xee, 0x05, 0x8c, 0xd5, 0x23, 0x5a,
0xbb, 0x0d, 0x32, 0xe6, 0x60, 0xac, 0xb4, 0x5e, 0x2d, 0x52, 0x39,
0xe7, 0xab, 0x5d, 0x2a, 0x9b, 0x57, 0xaf, 0x54, 0x1e, 0xaf, 0x31,
0x52, 0x49, 0x36, 0xaf, 0x61, 0x58, 0xf4, 0x5e, 0x23, 0xa5, 0xb8,
0x6f, 0xc6, 0xf1, 0x52, 0xac, 0x5e, 0x56, 0x52, 0x7c, 0x5e, 0xb6,
0x52, 0x4c, 0x5e, 0x33, 0xa4, 0xce, 0x73, 0xc4, 0x7d, 0xce, 0x99,
0xca, 0x14, 0xda, 0x6b, 0x8d, 0x54, 0xc4, 0x5b, 0x72, 0xa5, 0x54,
0x2c, 0xaf, 0xf5, 0x52, 0x21, 0x6e, 0x49, 0x47, 0x4c, 0xcf, 0x4b,
0xf1, 0xb6, 0xeb, 0x3b, 0x65, 0xf2, 0x46, 0x16, 0x80, 0xc9, 0x03,
0x59, 0x30, 0xa6, 0x55, 0x64, 0x81, 0x99, 0x5e, 0x96, 0x6e, 0xb7,
0x9d, 0xf1, 0x18, 0xbd, 0x77, 0x32, 0x4a, 0x8d, 0xd9, 0xa8, 0xdc,
0x5b, 0x59, 0xd0, 0x89, 0xcb, 0x37, 0x89, 0x47, 0xeb, 0x0a, 0x65,
0x68, 0xb9, 0xa7, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44,
0xae, 0x42, 0x60, 0x82
};

const int mask_img_length = 664;
2 changes: 2 additions & 0 deletions src/seg000.c
Expand Up @@ -163,7 +163,9 @@ void __pascal far init_game_main() {
load_all_sounds();

hof_read();
#ifndef __SWITCH__
show_splash(); // added
#endif
start_game();
}

Expand Down
69 changes: 69 additions & 0 deletions src/seg009.c
Expand Up @@ -29,6 +29,29 @@ The authors of this program may be contacted at http://forum.princed.org
#include "dirent.h"
#endif

#ifdef __SWITCH__
#define BTN_A 0
#define BTN_B 1
#define BTN_X 2
#define BTN_Y 3
#define BTN_PLUS 10
#define BTN_MINUS 11
#define BTN_UP 13
#define BTN_DOWN 15
#define BTN_LEFT 12
#define BTN_RIGHT 14

int access(const char *pathname, int mode)
{
struct stat st;

if (stat(pathname, &st) < 0)
return -1;

return 0;
}
#endif

// Most functions in this file are different from those in the original game.

void sdlperror(const char* header) {
Expand Down Expand Up @@ -796,6 +819,7 @@ int __pascal far set_joy_mode() {
if (SDL_NumJoysticks() < 1) {
is_joyst_mode = 0;
} else {
#ifndef __SWITCH__
if (SDL_IsGameController(0)) {
sdl_controller_ = SDL_GameControllerOpen(0);
if (sdl_controller_ == NULL) {
Expand All @@ -807,10 +831,13 @@ int __pascal far set_joy_mode() {
// We have a joystick connected, but it's NOT compatible with the SDL_GameController
// interface, so we resort to the classic SDL_Joystick interface instead
else {
#endif
sdl_joystick_ = SDL_JoystickOpen(0);
is_joyst_mode = 1;
using_sdl_joystick_interface = 1;
#ifndef __SWITCH__
}
#endif
}
if (enable_controller_rumble && is_joyst_mode) {
sdl_haptic = SDL_HapticOpen(0);
Expand Down Expand Up @@ -1689,7 +1716,11 @@ size_t digi_remaining_length = 0;
// The properties of the audio device.
SDL_AudioSpec* digi_audiospec = NULL;
// The desired samplerate. Everything will be resampled to this.
#ifdef __SWITCH__
const int digi_samplerate = 48000;
#else
const int digi_samplerate = 44100;
#endif

void stop_digi() {
// SDL_PauseAudio(1);
Expand Down Expand Up @@ -2247,8 +2278,12 @@ void __pascal far set_gr_mode(byte grmode) {
#ifdef SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING
SDL_SetHint(SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING, "1");
#endif
#ifdef __SWITCH__
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK) != 0) {
#else
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE |
SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC ) != 0) {
#endif
sdlperror("SDL_Init");
quit(1);
}
Expand All @@ -2273,7 +2308,11 @@ void __pascal far set_gr_mode(byte grmode) {
pop_window_width, pop_window_height, flags);
// Make absolutely sure that VSync will be off, to prevent timer issues.
SDL_SetHint(SDL_HINT_RENDER_VSYNC, "0");
#ifdef __SWITCH__
renderer_ = SDL_CreateRenderer(window_, -1 , SDL_RENDERER_SOFTWARE);
#else
renderer_ = SDL_CreateRenderer(window_, -1 , SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
#endif
SDL_RendererInfo renderer_info;
if (SDL_GetRendererInfo(renderer_, &renderer_info) == 0) {
if (renderer_info.flags & SDL_RENDERER_TARGETTEXTURE) {
Expand Down Expand Up @@ -3114,8 +3153,37 @@ void process_events() {
}
break;
case SDL_JOYBUTTONDOWN:
#ifdef __SWITCH__
switch (event.jbutton.button)
{
case BTN_LEFT: joy_hat_states[0] = -1; break;
case BTN_RIGHT: joy_hat_states[0] = 1; break;
case BTN_UP: joy_hat_states[1] = -1; break;
case BTN_DOWN: joy_hat_states[1] = 1; break;
case BTN_A: if (!is_menu_shown) { joy_X_button_state = 1; last_key_scancode = 1; } else { last_key_scancode = SDL_SCANCODE_RETURN; } break;
case BTN_B: if (!is_menu_shown) { joy_hat_states[1] = -1; } else { last_key_scancode = SDL_SCANCODE_BACKSPACE; } break;
case BTN_X: is_show_time = 1; break;
case BTN_MINUS: last_key_scancode = SDL_SCANCODE_F9; break;
case BTN_PLUS: last_key_scancode = SDL_SCANCODE_F6; break;
case BTN_Y: last_key_scancode = SDL_SCANCODE_ESCAPE; break;
}
break;
#endif
case SDL_JOYBUTTONUP:
#ifdef __SWITCH__
switch (event.jbutton.button)
{
case BTN_LEFT: joy_hat_states[0] = 0; break;
case BTN_RIGHT: joy_hat_states[0] = 0; break;
case BTN_UP: joy_hat_states[1] = 0; break;
case BTN_DOWN: joy_hat_states[1] = 0; break;
case BTN_A: if (!is_menu_shown) { joy_X_button_state = 0; } break;
case BTN_B: if (!is_menu_shown) { joy_hat_states[1] = 0; } break;
}
break;
#endif
case SDL_JOYAXISMOTION:
#ifndef __SWITCH__
// Only handle the event if the joystick is incompatible with the SDL_GameController interface.
// (Otherwise it will interfere with the normal action of the SDL_GameController API.)
if (!using_sdl_joystick_interface) {
Expand Down Expand Up @@ -3149,6 +3217,7 @@ void process_events() {
if (event.jbutton.button == SDL_JOYSTICK_BUTTON_Y) joy_AY_buttons_state = 0; // Y (up)
else if (event.jbutton.button == SDL_JOYSTICK_BUTTON_X) joy_X_button_state = 0; // X (shift)
}
#endif
break;

case SDL_TEXTINPUT:
Expand Down

0 comments on commit d35dbcc

Please sign in to comment.