Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Electric1447 committed Mar 29, 2020
0 parents commit f517b09
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.vpk
88 changes: 88 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
## This file is a quick tutorial on writing CMakeLists for targeting the Vita
cmake_minimum_required(VERSION 2.8)

## This includes the Vita toolchain, must go before project definition
# It is a convenience so you do not have to type
# -DCMAKE_TOOLCHAIN_FILE=$VITASDK/share/vita.toolchain.cmake for cmake. It is
# highly recommended that you include this block for all projects.
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()

## Define project parameters here
# Name of the project
project(dvd_screensaver)
# This line adds Vita helper macros, must go after project definition in order
# to build Vita specific artifacts (self/vpk).
include("${VITASDK}/share/vita.cmake" REQUIRED)

## Configuration options for this app
# Display name (under bubble in LiveArea)
set(VITA_APP_NAME "DVD Screensaver")
# Unique ID must be exactly 9 characters. Recommended: XXXXYYYYY where X =
# unique string of developer and Y = a unique number for this app
set(VITA_TITLEID "DVDS42069")
# Optional version string to show in LiveArea's more info screen
set(VITA_VERSION "01.00")

## Flags and includes for building
# Note that we make sure not to overwrite previous flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# Optional. You can specify more param.sfo flags this way.
set(VITA_MKSFOEX_FLAGS "${VITA_MKSFOEX_FLAGS} -d PARENTAL_LEVEL=1")

# Add any additional include paths here
include_directories(
../common # This is for debugScreenPrintf(), you shouldn't need it in your projects
)

# Add any additional library paths here
# ${CMAKE_CURRENT_BINARY_DIR} lets you use any library currently being built
link_directories(
${CMAKE_CURRENT_BINARY_DIR}
)

## Build and link
# Add all the files needed to compile here
add_executable(${PROJECT_NAME}
main.c
)

# Library to link to (drop the -l prefix). This will mostly be stubs.
target_link_libraries(${PROJECT_NAME}
SceLibKernel_stub # this line is only for demonstration. It's not needed as
# the most common stubs are automatically included.
# This used by debugScreenPrintf()
vita2d
SceDisplay_stub
SceGxm_stub
SceSysmodule_stub
SceCtrl_stub
ScePgf_stub
SceCommonDialog_stub
freetype
png
jpeg
z
m
c
)

## Create Vita files
vita_create_self(${PROJECT_NAME}.self ${PROJECT_NAME})
# The FILE directive lets you add additional files to the VPK, the syntax is
# FILE src_path dst_path_in_vpk. In this case, we add the LiveArea paths.
vita_create_vpk(${PROJECT_NAME}.vpk ${VITA_TITLEID} ${PROJECT_NAME}.self
VERSION ${VITA_VERSION}
NAME ${VITA_APP_NAME}
FILE sce_assests/dvd.png icons/dvd.png
FILE sce_sys/icon0.png sce_sys/icon0.png
FILE sce_sys/livearea/contents/bg.png sce_sys/livearea/contents/bg.png
FILE sce_sys/livearea/contents/startup.png sce_sys/livearea/contents/startup.png
FILE sce_sys/livearea/contents/template.xml sce_sys/livearea/contents/template.xml
)
108 changes: 108 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#include <psp2/display.h>
#include <psp2/kernel/threadmgr.h>
#include <psp2/kernel/processmgr.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <vita2d.h>

#define SCREEN_W 960
#define SCREEN_H 544

#define BLACK RGBA8( 0, 0, 0, 255)
#define WHITE RGBA8(255, 255, 255, 255)
#define RED RGBA8(255, 0, 0, 255)
#define ORANGE RGBA8(255, 165, 0, 255)
#define YELLOW RGBA8(255, 255, 0, 255)
#define GREEN RGBA8( 0, 255, 0, 255)
#define CYAN RGBA8( 0, 255, 255, 255)
#define BLUE RGBA8( 0, 0, 255, 255)
#define PURPLE RGBA8(128, 0, 128, 255)

char* concat(const char *s1, const char *s2)
{
char *result = malloc(strlen(s1) + strlen(s2) + 1); // +1 for the null-terminator
// in real code you would check for errors in malloc here
strcpy(result, s1);
strcat(result, s2);
return result;
}

int randomInRange (int lower, int upper) {
return (rand() % (upper - lower + 1)) + lower;
}

int main() {

vita2d_init();

vita2d_texture *logo = vita2d_load_PNG_file("app0:/icons/dvd.png");

vita2d_pgf *pgf;

vita2d_set_clear_color(BLACK);

pgf = vita2d_load_default_pgf();

int index = 0;

int colors[] = {RGBA8(255, 64, 0, 255), RGBA8(255, 128, 0, 255), RGBA8(255, 191, 0, 255), RGBA8(255, 255, 0, 255), RGBA8(191, 255, 0, 255), RGBA8(128, 255, 0, 255),
RGBA8(64, 255, 0, 255), RGBA8(0, 255, 0, 255), RGBA8(0, 255, 64, 255), RGBA8(0, 255, 128, 255), RGBA8(0, 255, 191, 255), RGBA8(0, 255, 255, 255),
RGBA8(0, 191, 255, 255), RGBA8(0, 128, 255, 255), RGBA8(0, 64, 255, 255), RGBA8(0, 0, 255, 255), RGBA8(64, 0, 255, 255), RGBA8(128, 0, 255, 255),
RGBA8(191, 0, 255, 255), RGBA8(255, 0, 255, 255), RGBA8(255, 0, 191, 255), RGBA8(255, 0, 128, 255), RGBA8(255, 0, 64, 255), RGBA8(255, 0, 0, 255)};

srand(time(NULL));

int posX = randomInRange(1, 960 - 128);
int posY = randomInRange(1, 544 - 96);

float velocityX = 1.0f;
float velocityY = 1.0f;

int boings = 0;
char boingsc[2];

while(1){

vita2d_start_drawing();
vita2d_clear_screen();

sprintf(boingsc, "%i", boings);

vita2d_draw_texture_tint(logo, posX, posY, colors[boings % 23]);
vita2d_pgf_draw_text(pgf, 30, 30, WHITE, 1.0f, concat("DVD boings: ", boingsc));

vita2d_end_drawing();
vita2d_swap_buffers();
index++;

if (posX >= SCREEN_W - 128) {
velocityX = -velocityX;
posX = SCREEN_W - 128;
} else if (posX <= 0) {
velocityX = -velocityX;
posX = 0;
}

if (posY >= SCREEN_H - 96) {
velocityY = -velocityY;
posY = SCREEN_H - 96;
} else if (posY <= 0) {
velocityY = -velocityY;
posY = 0;
}

posX += velocityX;
posY += velocityY;

if (posX == 0 || posX == SCREEN_W - 128 || posY == 0 || posY == SCREEN_H - 96)
boings++;
}

vita2d_free_texture(logo);
vita2d_fini();
vita2d_free_pgf(pgf);
sceKernelExitProcess(0);
return 0;
}
Binary file added sce_assests/dvd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sce_sys/icon0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sce_sys/livearea/contents/bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sce_sys/livearea/contents/startup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions sce_sys/livearea/contents/template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?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>

0 comments on commit f517b09

Please sign in to comment.