Skip to content

Commit

Permalink
Update to latest SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
xerpi committed Jul 28, 2016
1 parent 5259ac1 commit 3dd31c6
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 71 deletions.
43 changes: 24 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#
# Copyright (c) 2015 Sergi Granell (xerpi)
# based on Cirne's vita-toolchain test Makefile
#
TITLE_ID = XERP00004
TARGET = VITA-8
SOURCES = source
INCLUDES = include

TARGET := VITA-8
SOURCES := source
INCLUDES := include

LIBS = -lvita2d -lSceKernel_stub -lSceDisplay_stub -lSceGxm_stub \
-lSceCtrl_stub -lSceTouch_stub -lm
LIBS = -lvita2d -lSceKernel_stub -lSceDisplay_stub -lSceGxm_stub \
-lSceSysmodule_stub -lSceCtrl_stub -lScePgf_stub \
-lSceCommonDialog_stub -lm -lc

CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))
BINFILES := $(foreach dir,$(DATA), $(wildcard $(dir)/*.bin))
Expand All @@ -19,22 +16,30 @@ CC = $(PREFIX)-gcc
CFLAGS = -Wl,-q -Wall -O3 -I$(INCLUDES)
ASFLAGS = $(CFLAGS)

all: $(TARGET).velf
all: $(TARGET).vpk

%.vpk: eboot.bin
vita-mksfoex -s TITLE_ID=$(TITLE_ID) "$(TARGET)" param.sfo
vita-pack-vpk -s param.sfo -b eboot.bin $@

eboot.bin: $(TARGET).velf
vita-make-fself $< $@

%.velf: %.elf
$(PREFIX)-strip -g $<
vita-elf-create $< $@ $(VITASDK)/bin/db.json
vita-elf-create $< $@

$(TARGET).elf: $(OBJS)
$(CC) $(CFLAGS) $^ $(LIBS) -o $@

clean:
@rm -rf $(TARGET).velf $(TARGET).elf $(OBJS)
@rm -rf $(TARGET).vpk $(TARGET).velf $(TARGET).elf $(OBJS) \
eboot.bin param.sfo

copy: $(TARGET).velf
@cp $(TARGET).velf ~/shared/vitasample.elf
@echo "Copied!"
vpksend: $(TARGET).vpk
curl -T $(TARGET).vpk ftp://$(PSVITAIP):1337/ux0:/
@echo "Sent."

run: $(TARGET).velf
@sh run_homebrew_unity.sh $(TARGET).velf
send: eboot.bin
curl -T eboot.bin ftp://$(PSVITAIP):1337/ux0:/app/$(TITLE_ID)/
@echo "Sent."

2 changes: 1 addition & 1 deletion include/file_chooser.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef FILE_CHOOSER_H
#define FILE_CHOOSER_H

int file_choose(const char *start_path, char *chosen_file);
int file_choose(const char *start_path, char *chosen_file, const char *title, const char *supported_ext[]);

#endif
93 changes: 72 additions & 21 deletions source/file_chooser.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,31 @@
#include <psp2/kernel/processmgr.h>
#include <vita2d.h>
#include "font.h"
#include "utils.h"
#include "file_chooser.h"

#define GAME_EXIT_COMBO (SCE_CTRL_SELECT)

#define SCREEN_W 960
#define SCREEN_H 544
#define LIST_MAX_ONSCREEN ((SCREEN_H-40)/20)

#define min(a,b) ((a) < (b) ? (a) : (b))
#define max(a,b) ((a) > (b) ? (a) : (b))

#define WHITE RGBA8(255, 255, 255, 255)
#define GREEN RGBA8(0, 255, 0 , 255)

typedef struct file_list_entry {
char name[PATH_MAX];
int is_dir;
int supported;
struct file_list_entry *next;
} file_list_entry;

typedef struct file_list {
file_list_entry *head;
unsigned int length;
int length;
int scroll;
} file_list;


Expand Down Expand Up @@ -49,7 +62,23 @@ static void file_list_empty(file_list *list)
memset(list, 0, sizeof(*list));
}

static int file_list_build(const char *path, file_list *list)
static int file_supported(const char *filename, const char *supported_ext[])
{
int i;
const char *ext = strrchr(filename, '.');
if (ext) {
i = 0;
while (supported_ext[i]) {
if (strcmp(ext + 1, supported_ext[i]) == 0) {
return 1;
}
i++;
}
}
return 0;
}

static int file_list_build(const char *path, file_list *list, const char *supported_ext[])
{
SceUID dir;
SceIoDirent dirent;
Expand All @@ -67,7 +96,10 @@ static int file_list_build(const char *path, file_list *list)
file_list_entry *entry = malloc(sizeof(*entry));

strcpy(entry->name, dirent.d_name);
entry->is_dir = PSP2_S_ISDIR(dirent.d_stat.st_mode);
entry->is_dir = SCE_S_ISDIR(dirent.d_stat.st_mode);
if (!entry->is_dir) {
entry->supported = file_supported(entry->name, supported_ext);
}

file_list_add_entry(list, entry);

Expand Down Expand Up @@ -102,75 +134,94 @@ static void dir_up(char *path)
size_t s = len_in - (pch - path);
memset(pch, '\0', s);
}
if (strcmp(path, "cache0:/") < 0) {
strcpy(path, "cache0:/");
if (strcmp(path, "ux0:") < 0) {
strcpy(path, "ux0:");
}
}

int file_choose(const char *start_path, char *chosen_file)
int file_choose(const char *start_path, char *chosen_file, const char *title, const char *supported_ext[])
{
SceCtrlData pad, old_pad;
unsigned int keys_down;
int i;
int selected = 0;
char cur_path[PATH_MAX];

pad.buttons = old_pad.buttons = 0;

strcpy(cur_path, start_path);

file_list list;
file_list_entry *entry;

file_list_build(cur_path, &list);
file_list_build(cur_path, &list, supported_ext);

while (1) {
sceCtrlPeekBufferPositive(0, &pad, 1);
if (pad.buttons & PSP2_CTRL_SELECT) break;
keys_down = pad.buttons & ~old_pad.buttons;

if (keys_down & PSP2_CTRL_UP) {
if (pad.buttons & GAME_EXIT_COMBO)
return -1;

if (keys_down & SCE_CTRL_UP) {
selected--;
if (selected < list.scroll) {
list.scroll--;
}
if (selected < 0) {
selected = list.length - 1;
list.scroll = max(0, list.length - LIST_MAX_ONSCREEN);
}
} else if (keys_down & PSP2_CTRL_DOWN) {
} else if (keys_down & SCE_CTRL_DOWN) {
selected++;
if (selected == list.scroll + LIST_MAX_ONSCREEN) {
list.scroll++;
}
if (selected == list.length) {
selected = 0;
list.scroll = 0;
}
}

if (keys_down & (PSP2_CTRL_CROSS | PSP2_CTRL_START)) {
if (keys_down & (SCE_CTRL_CROSS | SCE_CTRL_START)) {
file_list_entry *entry = file_list_get_nth_entry(&list, selected);

if (entry->is_dir) {
if (strcmp(entry->name, "..") == 0) {
dir_up(cur_path);
} else {
char new_path[PATH_MAX];
sprintf(new_path, "%s%s/", cur_path, entry->name);
sprintf(new_path, "%s/%s", cur_path, entry->name);
strcpy(cur_path, new_path);
}
file_list_empty(&list);
file_list_build(cur_path, &list);
file_list_build(cur_path, &list, supported_ext);
selected = 0;
} else {
sprintf(chosen_file, "%s%s", cur_path, entry->name);
} else if (entry->supported) {
sprintf(chosen_file, "%s/%s", cur_path, entry->name);
file_list_empty(&list);
return 1;
}
} else if (keys_down & SCE_CTRL_CIRCLE) {
dir_up(cur_path);
file_list_empty(&list);
file_list_build(cur_path, &list, supported_ext);
selected = 0;
}


vita2d_start_drawing();
vita2d_clear_screen();

font_draw_stringf(10, 10, WHITE, "Choose a file:");
font_draw_stringf(10, 10, WHITE, title);

entry = list.head;
for (i = 0; i < list.length; i++) {
entry = file_list_get_nth_entry(&list, list.scroll);
for (i = list.scroll; i < min(list.length, list.scroll + LIST_MAX_ONSCREEN); i++) {

font_draw_stringf(
10,
40 + i*20,
WHITE,
40 + (i - list.scroll)*20,
(!entry->is_dir && entry->supported) ? GREEN : WHITE,
"%s %s",
(selected == i) ? ">" : "",
entry->name);
Expand Down
69 changes: 40 additions & 29 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,81 +20,91 @@
#include "font.h"
#include "file_chooser.h"

PSP2_MODULE_INFO(0, 0, "VITA-8");

int main()
{
int i;
char rom_file[PATH_MAX];
SceCtrlData pad, old_pad;
unsigned int keys_down;
unsigned int keys_up;
struct chip8_context chip8;
int i, pause = 0;
vita2d_texture *display_tex;
unsigned int *display_data;
int scale;
int pos_x;
int pos_y;
int pause = 0;

vita2d_init();

file_choose("cache0:/", rom_file);
file_choose("ux0:/cache", rom_file,
"Choose a CHIP-8 ROM:", NULL);

chip8_init(&chip8, 64, 32);
chip8_loadrom_file(&chip8, rom_file);

vita2d_texture *display_tex = vita2d_create_empty_texture(64, 32);
unsigned int *display_data = vita2d_texture_get_datap(display_tex);
display_tex = vita2d_create_empty_texture(64, 32);
display_data = vita2d_texture_get_datap(display_tex);

int scale = 12;
int pos_x = SCREEN_W/2 - (chip8.disp_w/2)*scale;
int pos_y = SCREEN_H/2 - (chip8.disp_h/2)*scale;
scale = 12;
pos_x = SCREEN_W/2 - (chip8.disp_w/2)*scale;
pos_y = SCREEN_H/2 - (chip8.disp_h/2)*scale;
old_pad.buttons = 0;

while (1) {
sceCtrlPeekBufferPositive(0, &pad, 1);
if (pad.buttons & PSP2_CTRL_SELECT) break;
if (pad.buttons & SCE_CTRL_SELECT)
break;

vita2d_start_drawing();
vita2d_clear_screen();

font_draw_stringf(10, 10, WHITE, "VITA-8 emulator by xerpi");

unsigned int keys_down = pad.buttons & ~old_pad.buttons;
unsigned int keys_up = ~pad.buttons & old_pad.buttons;
keys_down = pad.buttons & ~old_pad.buttons;
keys_up = ~pad.buttons & old_pad.buttons;

if (keys_down & PSP2_CTRL_UP) {
if (keys_down & SCE_CTRL_UP) {
chip8_key_press(&chip8, 1);
} else if (keys_up & PSP2_CTRL_UP) {
} else if (keys_up & SCE_CTRL_UP) {
chip8_key_release(&chip8, 1);
}
if (keys_down & PSP2_CTRL_DOWN) {
if (keys_down & SCE_CTRL_DOWN) {
chip8_key_press(&chip8, 4);
} else if (keys_up & PSP2_CTRL_DOWN) {
} else if (keys_up & SCE_CTRL_DOWN) {
chip8_key_release(&chip8, 4);
}

if (keys_down & PSP2_CTRL_TRIANGLE) {
if (keys_down & SCE_CTRL_TRIANGLE) {
chip8_key_press(&chip8, 0xC);
} else if (keys_up & PSP2_CTRL_TRIANGLE) {
} else if (keys_up & SCE_CTRL_TRIANGLE) {
chip8_key_release(&chip8, 0xC);
}
if (keys_down & PSP2_CTRL_CROSS) {
if (keys_down & SCE_CTRL_CROSS) {
chip8_key_press(&chip8, 0xD);
} else if (keys_up & PSP2_CTRL_CROSS) {
} else if (keys_up & SCE_CTRL_CROSS) {
chip8_key_release(&chip8, 0xD);
}

if (pad.buttons & PSP2_CTRL_LTRIGGER) {
if (pad.buttons & SCE_CTRL_LTRIGGER) {
scale--;
if (scale < 1) scale = 1;
if (scale < 1)
scale = 1;
/* Re-center the image */
pos_x = SCREEN_W/2 - (chip8.disp_w/2)*scale;
pos_y = SCREEN_H/2 - (chip8.disp_h/2)*scale;
} else if (pad.buttons & PSP2_CTRL_RTRIGGER) {
} else if (pad.buttons & SCE_CTRL_RTRIGGER) {
scale++;
/* Don't go outside of the screen! */
if ((chip8.disp_w*scale) > SCREEN_W) scale--;
if ((chip8.disp_w*scale) > SCREEN_W)
scale--;
/* Re-center the image */
pos_x = SCREEN_W/2 - (chip8.disp_w/2)*scale;
pos_y = SCREEN_H/2 - (chip8.disp_h/2)*scale;
}

if (keys_down & PSP2_CTRL_START) {
if (keys_down & SCE_CTRL_START)
pause = !pause;
}

if (!pause) {
// 512Hz/60 = 8.53333
Expand All @@ -109,9 +119,10 @@ int main()

if (pause) {
font_draw_stringf(SCREEN_W/2 - 40, SCREEN_H - 50, WHITE, "PAUSE");
if (keys_down & PSP2_CTRL_SQUARE) {
if (keys_down & SCE_CTRL_SQUARE) {
chip8_reset(&chip8);
file_choose("cache0:/", rom_file);
file_choose("ux0:/cache", rom_file,
"Choose a CHIP-8 ROM:", NULL);
chip8_loadrom_file(&chip8, rom_file);
pause = 0;
}
Expand All @@ -123,8 +134,8 @@ int main()
}

chip8_fini(&chip8);
vita2d_fini();
vita2d_free_texture(display_tex);
vita2d_fini();
sceKernelExitProcess(0);
return 0;
}
Loading

0 comments on commit 3dd31c6

Please sign in to comment.