Skip to content

Commit

Permalink
PSP2: first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Cpasjuste committed Sep 26, 2016
1 parent 2cb593c commit 8e79e86
Show file tree
Hide file tree
Showing 11 changed files with 529 additions and 29 deletions.
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PoP Hall of Fame file
ls d# PoP Hall of Fame file
PRINCE.HOF

# PoP saved game file
Expand Down Expand Up @@ -53,3 +53,12 @@ Makefile.win
# CLion
.idea/
src/.idea/

# PSP2
src/data.d
src/eboot.bin
src/main.d
src/param.sfo
src/psp2shell_cli
src/vpk*
src/vpop*
80 changes: 56 additions & 24 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,65 @@
# Project: SDLPoP
PHONY := all package clean

CC = gcc
RM = rm -f
DATE := $(shell date +%y-%m-%d)

HFILES = common.h config.h data.h proto.h types.h
OBJ = main.o data.o seg000.o seg001.o seg002.o seg003.o seg004.o seg005.o seg006.o seg007.o seg008.o seg009.o seqtbl.o replay.o options.o
BIN = ../prince
CC := arm-vita-eabi-gcc
CXX := arm-vita-eabi-g++
STRIP := arm-vita-eabi-strip

OS := $(shell uname)
PROJECT_TITLE := Prince Of Persia
PROJECT_TITLEID := PRINCEPER
PROJECT := vpop

ifeq ($(OS),Darwin)
LIBS := $(shell sdl2-config --libs) -lSDL2_image -lSDL2_mixer
INCS := -I/opt/local/include
CFLAGS += $(INCS) -Wall -std=gnu99 -D_GNU_SOURCE=1 -D_THREAD_SAFE -DOSX -O2
else
LIBS := $(shell pkg-config --libs sdl2 SDL2_image SDL2_mixer)
INCS := $(shell pkg-config --cflags sdl2 SDL2_image SDL2_mixer)
CFLAGS += $(INCS) -Wall -std=gnu99 -O2
endif
LIBS = -lpsp2shell -lpthread -lSDL2 -lSDL2_image -lSDL2_mixer -lvorbis -lvorbisfile -logg \
-lvita2d -lSceDisplay_stub -lSceGxm_stub \
-lSceSysmodule_stub -lSceCtrl_stub -lScePgf_stub -lSceNetCtl_stub \
-lSceNet_stub -lScePower_stub -lSceKernel_stub -lSceCommonDialog_stub \
-lSceAppUtil_stub -lSceAudio_stub -lSceAppMgr_stub -lpng -ljpeg -lz -lm -lc

all: $(BIN)

clean:
$(RM) $(OBJ) $(BIN)
CFLAGS = -Wl,-q -O3 -Wall \
-march=armv7-a -mtune=cortex-a9 -mfpu=neon -mfloat-abi=hard \
-DPSP2 -std=gnu99 -I$(VITASDK)/arm-vita-eabi/include

OBJS := main.o data.o seg000.o seg001.o seg002.o seg003.o seg004.o \
seg005.o seg006.o seg007.o seg008.o seg009.o seqtbl.o replay.o options.o \
strtoumax.o strtoimax.o

all: package

package: $(PROJECT).vpk

$(PROJECT).vpk: eboot.bin param.sfo
rm -rf vpk && mkdir -p vpk/sce_sys/livearea/contents
cp eboot.bin vpk/
cp param.sfo vpk/sce_sys/
cp ../*.DAT vpk/
cp -r ../data vpk/data
cd vpk && zip -r ../$(PROJECT)-$(DATE).vpk . && cd ..
# cp vita/icon0.png vpk/sce_sys/
# cp vita/template.xml vpk/sce_sys/livearea/contents/
# cp vita/bg.png vpk/sce_sys/livearea/contents/
# cp vita/startup.png vpk/sce_sys/livearea/contents/

eboot.bin: $(PROJECT).velf
vita-make-fself $(PROJECT).velf eboot.bin

$(BIN): $(OBJ)
$(CC) $(LDFLAGS) $(OBJ) -o $@ $(LIBS)
param.sfo:
vita-mksfoex -s TITLE_ID="$(PROJECT_TITLEID)" "$(PROJECT_TITLE)" param.sfo

%.o: %.c $(HFILES)
$(CC) $(CFLAGS) $(LDFLAGS) -c $<
$(PROJECT).velf: $(PROJECT).elf
$(STRIP) -g $<
vita-elf-create $< $@

.PHONY: all clean
$(PROJECT).elf: $(OBJS)
$(CC) -Wl,-q -o $@ $^ $(LIBS)

$(OBJ_DIRS):
mkdir -p $@

out/%.o : src/%.c | $(OBJ_DIRS)
$(CC) -c $(CFLAGS) -o $@ $<

clean:
rm -f $(PROJECT).velf $(PROJECT).elf *.vpk param.sfo eboot.bin $(OBJS)
rm -rf vpk
33 changes: 33 additions & 0 deletions src/Makefile.unix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Project: SDLPoP

CC = gcc
RM = rm -f

HFILES = common.h config.h data.h proto.h types.h
OBJ = main.o data.o seg000.o seg001.o seg002.o seg003.o seg004.o seg005.o seg006.o seg007.o seg008.o seg009.o seqtbl.o replay.o options.o
BIN = ../prince

OS := $(shell uname)

ifeq ($(OS),Darwin)
LIBS := $(shell sdl2-config --libs) -lSDL2_image -lSDL2_mixer
INCS := -I/opt/local/include
CFLAGS += $(INCS) -Wall -std=gnu99 -D_GNU_SOURCE=1 -D_THREAD_SAFE -DOSX -O2
else
LIBS := $(shell pkg-config --libs sdl2 SDL2_image SDL2_mixer)
INCS := $(shell pkg-config --cflags sdl2 SDL2_image SDL2_mixer)
CFLAGS += $(INCS) -Wall -std=gnu99 -O2
endif

all: $(BIN)

clean:
$(RM) $(OBJ) $(BIN)

$(BIN): $(OBJ)
$(CC) $(LDFLAGS) $(OBJ) -o $@ $(LIBS)

%.o: %.c $(HFILES)
$(CC) $(CFLAGS) $(LDFLAGS) -c $<

.PHONY: all clean
11 changes: 11 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ extern "C" {
#define ABS(x) ((x)<0?-(x):(x))
#endif

#ifdef PSP2
#include <psp2shell.h>
#define printf psp2shell_print
FILE *_fopen(const char *filename, const char *mode);
#undef fopen
#define fopen _fopen
int _fprintf(FILE *stream, const char *format, ...);
#undef fprintf
#define fprintf _fprintf
#endif

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ The authors of this program may be contacted at http://forum.princed.org

// Enable or disable fading.
// Fading used to be very buggy, but now it works correctly.
#ifndef PSP2
#define USE_FADE
#endif

// Enable or disable the potions level. (copy protection)
#define USE_COPYPROT
Expand Down
47 changes: 46 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,58 @@ 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
*/

#ifdef PSP2
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>

#include <psp2/io/stat.h>
#include <psp2shell.h>

int _newlib_heap_size_user = 192 * 1024 * 1024;

#define printf psp2shell_print

FILE *_fopen(const char *filename, const char *mode) {
char path[512];
memset(path, 0, 512);

if(strcmp(filename, "SDLPoP.ini") == 0) {
sprintf(path, "ux0:/data/vpop/%s", filename);
} else {
sprintf(path, "app0:/%s", filename);
}
return fopen(path, mode);
}

int _fprintf(FILE *stream, const char *format, ...) {
char *s = malloc(1024);
va_list args;
va_start(args, format);
int size = vsnprintf(s, 1024, format, args);
printf(s);
va_end(args);
free(s);
return size;
}

#endif

#include "common.h"

int main(int argc, char *argv[])
{
#ifdef PSP2
sceIoMkdir("ux0:/data/vpop", 0777);
psp2shell_init(3333);
#endif
g_argc = argc;
g_argv = argv;
pop_main();

#ifdef PSP2
psp2shell_exit();
#endif
return 0;
}

7 changes: 7 additions & 0 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ The authors of this program may be contacted at http://forum.princed.org
#include <inttypes.h>

void use_default_options() {
#ifdef PSP2
options.use_fixes_and_enhancements = 1;
options.enable_copyprot = 0;
options.enable_mixer = 1;
options.enable_fade = 0;
#else
options.use_fixes_and_enhancements = 0;
options.enable_copyprot = 0;
options.enable_mixer = 1;
options.enable_fade = 1;
#endif
options.enable_flash = 1;
options.enable_text = 1;
options.enable_quicksave = 1;
Expand Down
2 changes: 2 additions & 0 deletions src/seg001.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,9 @@ int __pascal far fade_in_1() {
#else
// stub
method_1_blit_rect(onscreen_surface_, offscreen_surface, &screen_rect, &screen_rect, 0);
#ifndef PSP2
updateScreen();
#endif
// SDL_UpdateRect(onscreen_surface_, 0, 0, 0, 0); // debug
return 0;
#endif
Expand Down
Loading

1 comment on commit 8e79e86

@usineur
Copy link

Choose a reason for hiding this comment

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

Hello Cpasjuste,

I already made a port of SDLPoP for Vita. Here you can take a look if you want: https://github.com/usineur/SDLPoP-Vita

Regards

Please sign in to comment.