Skip to content

Commit

Permalink
Vita: regroup all required changes in one commit
Browse files Browse the repository at this point in the history
  • Loading branch information
usineur committed Mar 31, 2019
1 parent 17b104d commit 9c9ba22
Show file tree
Hide file tree
Showing 17 changed files with 478 additions and 4 deletions.
84 changes: 84 additions & 0 deletions CMakeLists.txt
@@ -0,0 +1,84 @@
cmake_minimum_required(VERSION 2.8)

# VitaSDK defines
if( NOT DEFINED CMAKE_TOOLCHAIN_FILE )
if( DEFINED ENV{VITASDK} )
set(CMAKE_TOOLCHAIN_FILE "$ENV{VITASDK}/share/vita.toolchain.cmake" CACHE PATH "toolchain file")
else()
message(FATAL_ERROR "Please define VITASDK to point to your SDK path!")
endif()
endif()

# Project start
set(VITA_APPNAME SDLPoP-Vita)
set(VITA_TITLEID "SPOP00001")

project(${VITA_APPNAME})
include("${VITASDK}/share/vita.cmake" REQUIRED)

# Flags and includes
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-exceptions -O3")

include_directories(
${VITASDK}/arm-vita-eabi/include/vitashaders
)

link_directories(
${CMAKE_CURRENT_BINARY_DIR}
)

# Builds
add_executable(${VITA_APPNAME}
src/data.c
src/lighting.c
src/main.c
src/menu.c
src/midi.c
src/opl3.c
src/options.c
src/replay.c
src/seg000.c
src/seg001.c
src/seg002.c
src/seg003.c
src/seg004.c
src/seg005.c
src/seg006.c
src/seg007.c
src/seg008.c
src/seg009.c
src/seqtbl.c
src/stb_vorbis.c
src/psp2_shader.c
)

target_link_libraries(${VITA_APPNAME}
SDL2_image
SDL2
jpeg
png
kbdvita
vita2d_fbo
vitashaders
z
m
SceAppUtil_stub
SceAudio_stub
SceCommonDialog_stub
SceCtrl_stub
SceDisplay_stub
SceGxm_stub
SceHid_stub
SceSysmodule_stub
SceTouch_stub
)

# Create Vita artifacts
vita_create_self(eboot.bin ${VITA_APPNAME} UNSAFE)
vita_create_vpk(${VITA_APPNAME}.vpk ${VITA_TITLEID} eboot.bin
NAME ${VITA_APPNAME}
FILE res/icon0.png sce_sys/icon0.png
FILE res/bg.png sce_sys/livearea/contents/bg.png
FILE res/startup.png sce_sys/livearea/contents/startup.png
FILE res/template.xml sce_sys/livearea/contents/template.xml
)
Binary file added res/bg.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/icon0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/startup.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions res/template.xml
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>

<livearea style="a1" format-ver="01.00" content-rev="1">
<livearea-background>
<image>bg.png</image>
</livearea-background>
<gate>
<startup-image>startup.png</startup-image>
</gate>
</livearea>
5 changes: 5 additions & 0 deletions src/common.h
Expand Up @@ -67,6 +67,11 @@ extern "C" {
#define ABS(x) ((x)<0?-(x):(x))
#endif

#ifdef __vita__
#include <psp2/kernel/clib.h>
#define printf sceClibPrintf
#endif

#ifdef __cplusplus
}
#endif
Expand Down
17 changes: 17 additions & 0 deletions src/config.h
Expand Up @@ -214,7 +214,9 @@ The authors of this program may be contacted at http://forum.princed.org
#define USE_LIGHTING

// Enable screenshot features.
#ifndef __vita__
#define USE_SCREENSHOT
#endif

// Automatically switch to keyboard or joystick/gamepad mode if there is input from that device.
// Useful if SDL detected a gamepad but there is none.
Expand All @@ -226,9 +228,24 @@ The authors of this program may be contacted at http://forum.princed.org
#define USE_COLORED_TORCHES

// Default SDL_Joystick button values
#ifdef __vita__
#define BTN_TRIANGLE 0
#define BTN_CIRCLE 1
#define BTN_CROSS 2
#define BTN_SQUARE 3
#define BTN_LTRIGGER 4
#define BTN_RTRIGGER 5
#define BTN_DOWN 6
#define BTN_LEFT 7
#define BTN_UP 8
#define BTN_RIGHT 9
#define BTN_SELECT 10
#define BTN_START 11
#else
#define SDL_JOYSTICK_BUTTON_Y 2
#define SDL_JOYSTICK_BUTTON_X 3
#define SDL_JOYSTICK_X_AXIS 0
#define SDL_JOYSTICK_Y_AXIS 1
#endif

#endif
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,
0x49, 0x44, 0x41, 0x54, 0x78, 0x5e, 0xed, 0xdb, 0x51, 0x72, 0x83,
0x30, 0x0c, 0x04, 0xd0, 0x72, 0xff, 0x43, 0x53, 0x3a, 0xe9, 0xd0,
0x34, 0x21, 0xc6, 0x6b, 0x5b, 0xb6, 0xb4, 0xda, 0x7c, 0x2f, 0xc2,
0x7a, 0x08, 0x4f, 0x98, 0x90, 0xed, 0xcb, 0xc7, 0x67, 0xdf, 0xf7,
0xc2, 0x42, 0xb6, 0x6d, 0xf3, 0xb1, 0xcc, 0xe9, 0xab, 0x38, 0x5c,
0x86, 0x7c, 0xa6, 0x2f, 0x7c, 0xe2, 0x09, 0x87, 0x00, 0x5d, 0x16,
0x99, 0xd8, 0x84, 0xf1, 0xa9, 0xec, 0x8c, 0xde, 0x2b, 0x1b, 0xb7,
0x62, 0x59, 0x7e, 0x26, 0xd3, 0xf3, 0xb9, 0x2c, 0x7b, 0x32, 0xa8,
0xbd, 0x8a, 0x29, 0x18, 0x99, 0x07, 0xa6, 0x00, 0x64, 0xde, 0x98,
0x9c, 0x92, 0x79, 0x66, 0xf2, 0x45, 0x16, 0x45, 0xea, 0xb1, 0x4e,
0x83, 0xfd, 0xb9, 0xba, 0x64, 0x2c, 0xa9, 0x95, 0x5e, 0x11, 0xa5,
0x16, 0x78, 0xc5, 0x65, 0x9a, 0xbd, 0x85, 0x71, 0x48, 0xcd, 0x18,
0x31, 0x26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 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;
16 changes: 16 additions & 0 deletions src/menu.c
Expand Up @@ -2035,7 +2035,11 @@ dword exe_crc = 0;
void calculate_exe_crc() {
if (exe_crc == 0) {
// Get the CRC32 fingerprint of the executable.
#ifdef __vita__
FILE* exe_file = fopen("app0:eboot.bin", "rb");
#else
FILE* exe_file = fopen(g_argv[0], "rb");
#endif
if (exe_file != NULL) {
fseek(exe_file, 0, SEEK_END);
int size = ftell(exe_file);
Expand All @@ -2052,7 +2056,14 @@ void calculate_exe_crc() {
}

void save_ingame_settings() {
#ifdef __vita__
const char* cfg_filename = "ux0:data/prince/SDLPoP.cfg";
FILE *fp = fopen(cfg_filename, "ab+");
fclose(fp);
SDL_RWops* rw = SDL_RWFromFile(locate_file(cfg_filename), "wb");
#else
SDL_RWops* rw = SDL_RWFromFile(locate_file("SDLPoP.cfg"), "wb");
#endif
if (rw != NULL) {
calculate_exe_crc();
SDL_RWwrite(rw, &exe_crc, sizeof(exe_crc), 1);
Expand All @@ -2069,8 +2080,13 @@ void load_ingame_settings() {
// We want the SDLPoP.cfg file (in-game menu settings) to override the SDLPoP.ini file,
// but ONLY if the .ini file wasn't modified since the last time the .cfg file was saved!
struct stat st_ini, st_cfg;
#ifdef __vita__
const char* cfg_filename = locate_file("ux0:data/prince/SDLPoP.cfg");
const char* ini_filename = locate_file("ux0:data/prince/SDLPoP.ini");
#else
const char* cfg_filename = locate_file("SDLPoP.cfg");
const char* ini_filename = locate_file("SDLPoP.ini");
#endif
if (stat( cfg_filename, &st_cfg ) == 0 && stat( ini_filename, &st_ini ) == 0) {
if (st_ini.st_mtime > st_cfg.st_mtime ) {
// SDLPoP.ini is newer than SDLPoP.cfg, so just go with the .ini configuration
Expand Down
15 changes: 14 additions & 1 deletion src/options.c
Expand Up @@ -126,7 +126,7 @@ static int ini_process_##data_type(const char* curr_name, const char* value, con
if(strcasecmp(curr_name, option_name) == 0) { \
if (strcasecmp(value, "default") != 0) { \
int named_value = ini_get_named_value(value, value_names); \
*target = (named_value == INI_NO_VALID_NAME) ? ((data_type) strtoimax(value, NULL, 0)) : ((data_type) named_value); \
*target = (named_value == INI_NO_VALID_NAME) ? ((data_type) strtol(value, NULL, 0)) : ((data_type) named_value); \
} \
return 1; /* finished; don't look for more possible options that curr_name can be */ \
} \
Expand Down Expand Up @@ -439,8 +439,13 @@ void load_dos_exe_modifications(const char* folder_name);

void load_global_options() {
set_options_to_default();
#ifdef __vita__
ini_load(locate_file("ux0:data/prince/SDLPoP.ini"), global_ini_callback); // global configuration
load_dos_exe_modifications("ux0:data/prince/"); // read PRINCE.EXE
#else
ini_load(locate_file("SDLPoP.ini"), global_ini_callback); // global configuration
load_dos_exe_modifications("."); // read PRINCE.EXE in the current working directory
#endif
}

void check_mod_param() {
Expand Down Expand Up @@ -665,7 +670,11 @@ void load_mod_options() {
if (use_custom_levelset) {
// find the folder containing the mod's files
char folder_name[POP_MAX_PATH];
#ifdef __vita__
snprintf(folder_name, sizeof(folder_name), "ux0:data/prince/%s/%s", mods_folder, levelset_name);
#else
snprintf(folder_name, sizeof(folder_name), "%s/%s", mods_folder, levelset_name);
#endif
const char* located_folder_name = locate_file(folder_name);
bool ok = false;
struct stat info;
Expand All @@ -678,7 +687,11 @@ void load_mod_options() {
load_dos_exe_modifications(located_folder_name);
// Try to load mod.ini
char mod_ini_filename[POP_MAX_PATH];
#ifdef __vita__
snprintf(mod_ini_filename, sizeof(mod_ini_filename), "ux0:data/prince/%s/%s", located_folder_name, "mod.ini");
#else
snprintf(mod_ini_filename, sizeof(mod_ini_filename), "%s/%s", located_folder_name, "mod.ini");
#endif
if (file_exists(mod_ini_filename)) {
// Nearly all mods would want to use custom options, so always allow them.
use_custom_options = 1;
Expand Down

0 comments on commit 9c9ba22

Please sign in to comment.