-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ilya Cohen
committed
Apr 18, 2020
1 parent
8d0596a
commit 168ceba
Showing
12 changed files
with
619 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
VitaVolume | ||
CMakeCache.txt | ||
eboot.bin* | ||
cmake_install.cmake | ||
*.out | ||
*.vpk | ||
*.velf | ||
*param.sfo | ||
CMakeFiles/ | ||
CMakeFiles/* | ||
Makefile | ||
.vs-code/* | ||
.vs-code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Linux", | ||
"includePath": [ | ||
"${workspaceFolder}/**", | ||
"/usr/local/", | ||
"/usr/local/vitasdk/arm-vita-eabi/include" | ||
], | ||
"defines": [], | ||
"compilerPath": "/usr/bin/gcc", | ||
"cStandard": "c11", | ||
"cppStandard": "c++17", | ||
"intelliSenseMode": "clang-x64" | ||
} | ||
], | ||
"version": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
cmake_minimum_required(VERSION 2.8) | ||
|
||
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(VitaMGR) | ||
|
||
include("${VITASDK}/share/vita.cmake" REQUIRED) | ||
|
||
set(VITA_APP_NAME "Vita Manager") | ||
set(VITA_TITLEID "VITAVOLUM") | ||
|
||
set(VITA_VERSION "01.00") | ||
|
||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") | ||
|
||
set(VITA_MKSFOEX_FLAGS "${VITA_MKSFOEX_FLAGS} -s CATEGORY=gdb") | ||
set(VITA_MAKE_FSELF_FLAGS "${VITA_MAKE_FSELF_FLAGS}") | ||
|
||
include_directories( | ||
) | ||
|
||
link_directories( | ||
${CMAKE_CURRENT_BINARY_DIR} | ||
) | ||
|
||
add_executable(${PROJECT_NAME} | ||
src/main.c | ||
src/ctrl.c | ||
) | ||
|
||
target_link_libraries(${PROJECT_NAME} | ||
SceLibKernel_stub | ||
SceIofilemgr_stub | ||
SceAppMgr_stub | ||
SceCtrl_stub | ||
SceDisplay_stub | ||
SceVshBridge_stub | ||
ScePower_stub | ||
SceRegistryMgr_stub | ||
SceLibc_stub | ||
) | ||
|
||
vita_create_self(eboot.bin ${PROJECT_NAME} UNSAFE) | ||
|
||
vita_create_vpk(${PROJECT_NAME}.vpk ${VITA_TITLEID} eboot.bin | ||
VERSION ${VITA_VERSION} | ||
NAME ${VITA_APP_NAME} | ||
|
||
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 | ||
) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?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> | ||
</livearea> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
#include <vitasdk.h> | ||
|
||
#define printf psvDebugScreenPrintf | ||
|
||
int get_key(int type) | ||
{ | ||
|
||
SceCtrlData pad; | ||
|
||
if (type == 0) | ||
{ | ||
|
||
while (1) | ||
{ | ||
//memset(&pad, 0, sizeof(pad)); | ||
sceCtrlPeekBufferPositive(0, &pad, 1); | ||
|
||
if (pad.buttons != 0) | ||
return pad.buttons; | ||
|
||
sceKernelDelayThread(1000); // 1ms | ||
} | ||
} | ||
else | ||
{ | ||
|
||
while (1) | ||
{ | ||
|
||
//memset(&pad, 0, sizeof(pad)); | ||
sceCtrlPeekBufferPositive(0, &pad, 1); | ||
if (pad.buttons == 0) | ||
{ | ||
|
||
break; | ||
} | ||
|
||
sceKernelDelayThread(1000); // 1ms | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
void press_exit(void) | ||
{ | ||
|
||
get_key(1); | ||
|
||
printf("Press any key to exit this application.\n"); | ||
|
||
get_key(0); | ||
|
||
sceKernelExitProcess(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
int get_key(int type); | ||
void press_exit(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
#ifndef DEBUG_SCREEN_H | ||
#define DEBUG_SCREEN_H | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdarg.h> | ||
#include <inttypes.h> | ||
|
||
|
||
typedef struct PsvDebugScreenFont { | ||
unsigned char* glyphs, width, height, first, last, size_w, size_h; | ||
} PsvDebugScreenFont; | ||
|
||
#include "debugScreenFont.c" | ||
|
||
#define SCREEN_WIDTH (960) | ||
#define SCREEN_HEIGHT (544) | ||
#define SCREEN_FB_WIDTH (960) | ||
#define SCREEN_FB_SIZE (2 * 1024 * 1024) //Must be 256KB aligned | ||
#ifndef SCREEN_TAB_SIZE /* this allow easy overriding */ | ||
#define SCREEN_TAB_SIZE (8) | ||
#endif | ||
#define SCREEN_TAB_W ((F.size_w) * SCREEN_TAB_SIZE) | ||
#define F psvDebugScreenFont | ||
|
||
#define FROM_GREY(c ) ((((c)*9) <<16) | (((c)*9) <<8) | ((c)*9)) | ||
#define FROM_3BIT(c,dark) (((!!((c)&4))<<23) | ((!!((c)&2))<<15) | ((!!((c)&1))<<7) | (dark ? 0 : 0x7F7F7F)) | ||
#define FROM_6BIT(c ) ((((c)%6)*(51<<16)) | ((((c)/6)%6)*(51<<8)) | ((((c)/36)%6)*51)) | ||
#define FROM_FULL(r,g,b ) ((r<<16) | (g<<8) | (b)) | ||
#define CLEARSCRN(H,toH,W,toW) for(int h = H; h < toH; h++)for(int w = W; w < toW; w++)((uint32_t*)base)[h*SCREEN_FB_WIDTH + w] = colorBg; | ||
|
||
static int mutex, coordX, savedX, coordY, savedY; | ||
static uint32_t defaultFg = 0xFFFFFFFF, colorFg = 0xFFFFFFFF; | ||
static uint32_t defaultBg = 0xFF000000, colorBg = 0xFF000000; | ||
|
||
|
||
#ifdef __vita__ | ||
#include <psp2/display.h> | ||
#include <psp2/kernel/sysmem.h> | ||
#include <psp2/kernel/threadmgr.h> | ||
static void* base; // pointer to frame buffer | ||
#else | ||
#define sceKernelLockMutex(m,v,x) m=v | ||
#define sceKernelUnlockMutex(m,v) m=v | ||
static char base[SCREEN_FB_WIDTH * SCREEN_HEIGHT * 4]; | ||
#endif | ||
|
||
static size_t psvDebugScreenEscape(const unsigned char *str) { | ||
for(unsigned i = 0, argc = 0, arg[32] = {0}; argc < (sizeof(arg)/sizeof(*arg)) && str[i]!='\0'; i++) | ||
switch(str[i]) { | ||
case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8':case '9': | ||
arg[argc]=(arg[argc]*10) + (str[i] - '0');continue; | ||
case ';': argc++;continue; | ||
case 's': savedX = coordX; savedY = coordY; return i; | ||
case 'u': coordX = savedX; coordY = savedY; return i; | ||
case 'A': coordY -= arg[0] * (F.size_h); return i; | ||
case 'B': coordY += arg[0] * (F.size_h); return i; | ||
case 'C': coordX += arg[0] * (F.size_w); return i; | ||
case 'D': coordX -= arg[0] * (F.size_w); return i; | ||
case 'E': coordY += arg[0] * (F.size_h); coordX = 0; return i; | ||
case 'F': coordY -= arg[0] * (F.size_h); coordX = 0; return i; | ||
case 'G': coordX = (arg[0]-1) * (F.size_w); return i; | ||
case 'H': | ||
case 'f': coordY = (arg[0]-1) * (F.size_h); | ||
coordX = (arg[1]-1) * (F.size_w); return i; | ||
case 'J': //clear part of (J=screen, K=Line) so J code reuse part of K | ||
case 'K': if(arg[0]==0)CLEARSCRN(coordY, coordY + F.size_h, coordX, SCREEN_WIDTH);//from curosr to end | ||
if(arg[0]==1)CLEARSCRN(coordY, coordY + F.size_h, 0, coordX);//from begining to cursor | ||
if(arg[0]==2)CLEARSCRN(coordY, coordY + F.size_h, 0, SCREEN_WIDTH);//whole line | ||
if(str[i]=='K')return i; | ||
if(arg[0]==0)CLEARSCRN(coordY, SCREEN_HEIGHT, 0, SCREEN_WIDTH); | ||
if(arg[0]==1)CLEARSCRN(0, coordY, 0, SCREEN_WIDTH); | ||
if(arg[0]==2)CLEARSCRN(0, SCREEN_HEIGHT, 0, SCREEN_WIDTH); | ||
return i; | ||
case 'm':// Color | ||
if(!arg[0]) {arg[0] = 39;arg[1] = 49;argc = 1;}//no/0 args == reset BG + FG | ||
for(unsigned c = 0; c <= argc; c++) { | ||
uint32_t unit = arg[c] % 10, mode = arg[c] / 10, *color = mode&1 ? &colorFg : &colorBg; | ||
if (arg[c]==1)colorFg|=0x808080; | ||
if (arg[c]==2)colorFg&=0x7F7F7F; | ||
if (mode!=3 && mode!=4 && mode!=9 && mode!=10)continue;//skip unsported modes | ||
if (unit == 9){ // reset FG or BG | ||
*color = mode&1 ? defaultFg : defaultBg; | ||
} else if ((unit==8) && (arg[c+1]==5)) { // 8bit : [0-15][16-231][232-256] color map | ||
c+=2;*color = arg[c]<=15?FROM_3BIT(arg[c],mode<9):arg[c]>=232?FROM_GREY(arg[c]-232):FROM_6BIT(arg[c]-16); | ||
} else if ((unit==8) && (arg[c+1]==2)) { // 24b color space | ||
*color = FROM_FULL(arg[c+4], arg[c+3], arg[c+2]);c+=4; | ||
} else *color = FROM_3BIT(unit,mode<9); // standard 8+8 colors | ||
} | ||
return i; | ||
} | ||
return 0; | ||
} | ||
int psvDebugScreenInit() { | ||
mutex = sceKernelCreateMutex("log_mutex", 0, 0, NULL); | ||
SceUID displayblock = sceKernelAllocMemBlock("display", SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW, SCREEN_FB_SIZE, NULL); | ||
sceKernelGetMemBlockBase(displayblock, (void**)&base); | ||
SceDisplayFrameBuf frame = { sizeof(frame), base, SCREEN_FB_WIDTH, 0, SCREEN_WIDTH, SCREEN_HEIGHT}; | ||
//reset X/Y | ||
coordX = 0; | ||
coordY = 0; | ||
return sceDisplaySetFrameBuf(&frame, SCE_DISPLAY_SETBUF_NEXTFRAME); | ||
} | ||
|
||
int psvDebugScreenPuts(const char * _text) { | ||
const unsigned char*text = (const unsigned char*)_text; | ||
int bytes_per_glyph = (F.width * F.height) / 8; | ||
sceKernelLockMutex(mutex, 1, NULL); | ||
int c; | ||
for (c = 0; text[c] ; c++) { | ||
unsigned char t = text[c]; | ||
if (t == '\t') { | ||
coordX += SCREEN_TAB_W - coordX % SCREEN_TAB_W; | ||
continue; | ||
} | ||
if (coordX + F.width > SCREEN_WIDTH) { | ||
coordY += F.size_h; | ||
coordX = 0; | ||
} | ||
if (coordY + F.height > SCREEN_HEIGHT) { | ||
coordX = coordY = 0; | ||
} | ||
if (t == '\n') { | ||
coordX = 0; | ||
coordY += F.size_h; | ||
continue; | ||
} else if (t == '\r') { | ||
coordX = 0; | ||
continue; | ||
} else if ((t == '\e') && (text[c+1] == '[')) { | ||
c += psvDebugScreenEscape(text + c + 2) + 2; | ||
if(coordX < 0)coordX = 0;// CSI position are 1-based, | ||
if(coordY < 0)coordY = 0;// prevent 0-based coordiate from producing a negativ X/Y | ||
continue; | ||
}else if ((t > F.last) || (t < F.first)) | ||
continue; // skip non printable glyph | ||
uint32_t *vram = ((uint32_t*)base) + coordX + coordY * SCREEN_FB_WIDTH; | ||
uint8_t *font = &F.glyphs[ (t - F.first) * bytes_per_glyph]; | ||
for (int row = 0, mask = 1 << 7; row < F.height; row++, vram += SCREEN_FB_WIDTH) { | ||
for (uint32_t *pixel = vram, col = 0; col < F.width ; col++, mask>>=1) { | ||
if (!mask) {font++; mask = 1 << 7;}// no more mask : we exausted this byte | ||
*pixel++ = (*font&mask)?colorFg:colorBg; | ||
} | ||
for (uint32_t *pixel = vram + F.width, col = F.width; col < F.size_w ; col++) | ||
*pixel++ = colorBg;// right margin | ||
} | ||
for (int row = F.height; row < F.size_h; row++, vram += SCREEN_FB_WIDTH) | ||
for (uint32_t *pixel = vram, col = 0; col < F.size_w ; col++) | ||
*pixel++ = colorBg;// bottom margin | ||
coordX += F.size_w; | ||
} | ||
sceKernelUnlockMutex(mutex, 1); | ||
return c; | ||
} | ||
|
||
__attribute__((__format__ (__printf__, 1, 2))) | ||
int psvDebugScreenPrintf(const char *format, ...) { | ||
char buf[4096]; | ||
|
||
va_list opt; | ||
va_start(opt, format); | ||
int ret = vsnprintf(buf, sizeof(buf), format, opt); | ||
psvDebugScreenPuts(buf); | ||
va_end(opt); | ||
|
||
return ret; | ||
} | ||
|
||
void psvDebugScreenSetFgColor(uint32_t rgb){ | ||
psvDebugScreenPrintf("\e[38;2;%lu;%lu;%lum", (rgb>>16)&0xFF, (rgb>>8)&0xFF, rgb&0xFF); | ||
} | ||
void psvDebugScreenSetBgColor(uint32_t rgb){ | ||
psvDebugScreenPrintf("\e[48;2;%lu;%lu;%lum", (rgb>>16)&0xFF, (rgb>>8)&0xFF, rgb&0xFF); | ||
} | ||
void psvDebugScreenClear(){ | ||
psvDebugScreenPrintf(" "); | ||
psvDebugScreenPrintf(" "); | ||
psvDebugScreenPrintf(" "); | ||
psvDebugScreenPrintf(" "); | ||
coordX = 0; | ||
coordY = 0; | ||
} | ||
#undef F | ||
#endif |
Oops, something went wrong.