diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt new file mode 100644 index 0000000..df54a2a --- /dev/null +++ b/app/CMakeLists.txt @@ -0,0 +1,36 @@ +cmake_minimum_required(VERSION 2.8) + +set(CMAKE_SYSTEM_NAME "Generic") +set(CMAKE_C_COMPILER "arm-vita-eabi-gcc") +set(CMAKE_CXX_COMPILER "arm-vita-eabi-g++") + +project(activate.vpk) +set(TITLE_ID "ACTIVATE0") + +set(CMAKE_C_FLAGS "-Wl,-q -O3 -std=c99") + +add_executable(${PROJECT_NAME}.elf + main.c + font.c + graphics.c +) + +target_link_libraries(${PROJECT_NAME}.elf + SceDisplay_stub + SceCtrl_stub + SceVshBridge_stub + SceAppMgr_stub + SceIofilemgr_stub + ScePower_stub + SceRegistryMgr_stub + taihen_stub + user_clockset_stub_weak +) + +add_custom_target(${PROJECT_NAME}.vpk ALL + COMMAND vita-elf-create ${PROJECT_NAME}.elf ${PROJECT_NAME}.velf + COMMAND vita-make-fself ${PROJECT_NAME}.velf eboot.bin + COMMAND vita-mksfoex -s TITLE_ID=${TITLE_ID} "${PROJECT_NAME}" param.sfo + COMMAND vita-pack-vpk -s param.sfo -b eboot.bin -a kern_clockset.skprx=kern_clockset.skprx -a user_clockset.suprx=user_clockset.suprx -a sce_sys/icon0.png=sce_sys/icon0.png -a sce_sys/livearea/contents/bg.png=sce_sys/livearea/contents/bg.png -a sce_sys/livearea/contents/startup.png=sce_sys/livearea/contents/startup.png -a sce_sys/livearea/contents/template.xml=sce_sys/livearea/contents/template.xml activate.vpk +) +add_dependencies(${PROJECT_NAME}.vpk ${PROJECT_NAME}.elf) diff --git a/app/font.c b/app/font.c new file mode 100644 index 0000000..e685de2 --- /dev/null +++ b/app/font.c @@ -0,0 +1,146 @@ +/* + * PSP Software Development Kit - http://www.pspdev.org + * ----------------------------------------------------------------------- + * Licensed under the BSD license, see LICENSE in PSPSDK root for details. + * + * font.c - Debug Font. + * + * Copyright (c) 2005 Marcus R. Brown + * Copyright (c) 2005 James Forshaw + * Copyright (c) 2005 John Kelley + * + * $Id: font.c 540 2005-07-08 19:35:10Z warren $ + */ + +unsigned char msx[]= +"\x00\x00\x00\x00\x00\x00\x00\x00\x3c\x42\xa5\x81\xa5\x99\x42\x3c" +"\x3c\x7e\xdb\xff\xff\xdb\x66\x3c\x6c\xfe\xfe\xfe\x7c\x38\x10\x00" +"\x10\x38\x7c\xfe\x7c\x38\x10\x00\x10\x38\x54\xfe\x54\x10\x38\x00" +"\x10\x38\x7c\xfe\xfe\x10\x38\x00\x00\x00\x00\x30\x30\x00\x00\x00" +"\xff\xff\xff\xe7\xe7\xff\xff\xff\x38\x44\x82\x82\x82\x44\x38\x00" +"\xc7\xbb\x7d\x7d\x7d\xbb\xc7\xff\x0f\x03\x05\x79\x88\x88\x88\x70" +"\x38\x44\x44\x44\x38\x10\x7c\x10\x30\x28\x24\x24\x28\x20\xe0\xc0" +"\x3c\x24\x3c\x24\x24\xe4\xdc\x18\x10\x54\x38\xee\x38\x54\x10\x00" +"\x10\x10\x10\x7c\x10\x10\x10\x10\x10\x10\x10\xff\x00\x00\x00\x00" +"\x00\x00\x00\xff\x10\x10\x10\x10\x10\x10\x10\xf0\x10\x10\x10\x10" +"\x10\x10\x10\x1f\x10\x10\x10\x10\x10\x10\x10\xff\x10\x10\x10\x10" +"\x10\x10\x10\x10\x10\x10\x10\x10\x00\x00\x00\xff\x00\x00\x00\x00" +"\x00\x00\x00\x1f\x10\x10\x10\x10\x00\x00\x00\xf0\x10\x10\x10\x10" +"\x10\x10\x10\x1f\x00\x00\x00\x00\x10\x10\x10\xf0\x00\x00\x00\x00" +"\x81\x42\x24\x18\x18\x24\x42\x81\x01\x02\x04\x08\x10\x20\x40\x80" +"\x80\x40\x20\x10\x08\x04\x02\x01\x00\x10\x10\xff\x10\x10\x00\x00" +"\x00\x00\x00\x00\x00\x00\x00\x00\x20\x20\x20\x20\x00\x00\x20\x00" +"\x50\x50\x50\x00\x00\x00\x00\x00\x50\x50\xf8\x50\xf8\x50\x50\x00" +"\x20\x78\xa0\x70\x28\xf0\x20\x00\xc0\xc8\x10\x20\x40\x98\x18\x00" +"\x40\xa0\x40\xa8\x90\x98\x60\x00\x10\x20\x40\x00\x00\x00\x00\x00" +"\x10\x20\x40\x40\x40\x20\x10\x00\x40\x20\x10\x10\x10\x20\x40\x00" +"\x20\xa8\x70\x20\x70\xa8\x20\x00\x00\x20\x20\xf8\x20\x20\x00\x00" +"\x00\x00\x00\x00\x00\x20\x20\x40\x00\x00\x00\x78\x00\x00\x00\x00" +"\x00\x00\x00\x00\x00\x60\x60\x00\x00\x00\x08\x10\x20\x40\x80\x00" +"\x70\x88\x98\xa8\xc8\x88\x70\x00\x20\x60\xa0\x20\x20\x20\xf8\x00" +"\x70\x88\x08\x10\x60\x80\xf8\x00\x70\x88\x08\x30\x08\x88\x70\x00" +"\x10\x30\x50\x90\xf8\x10\x10\x00\xf8\x80\xe0\x10\x08\x10\xe0\x00" +"\x30\x40\x80\xf0\x88\x88\x70\x00\xf8\x88\x10\x20\x20\x20\x20\x00" +"\x70\x88\x88\x70\x88\x88\x70\x00\x70\x88\x88\x78\x08\x10\x60\x00" +"\x00\x00\x20\x00\x00\x20\x00\x00\x00\x00\x20\x00\x00\x20\x20\x40" +"\x18\x30\x60\xc0\x60\x30\x18\x00\x00\x00\xf8\x00\xf8\x00\x00\x00" +"\xc0\x60\x30\x18\x30\x60\xc0\x00\x70\x88\x08\x10\x20\x00\x20\x00" +"\x70\x88\x08\x68\xa8\xa8\x70\x00\x20\x50\x88\x88\xf8\x88\x88\x00" +"\xf0\x48\x48\x70\x48\x48\xf0\x00\x30\x48\x80\x80\x80\x48\x30\x00" +"\xe0\x50\x48\x48\x48\x50\xe0\x00\xf8\x80\x80\xf0\x80\x80\xf8\x00" +"\xf8\x80\x80\xf0\x80\x80\x80\x00\x70\x88\x80\xb8\x88\x88\x70\x00" +"\x88\x88\x88\xf8\x88\x88\x88\x00\x70\x20\x20\x20\x20\x20\x70\x00" +"\x38\x10\x10\x10\x90\x90\x60\x00\x88\x90\xa0\xc0\xa0\x90\x88\x00" +"\x80\x80\x80\x80\x80\x80\xf8\x00\x88\xd8\xa8\xa8\x88\x88\x88\x00" +"\x88\xc8\xc8\xa8\x98\x98\x88\x00\x70\x88\x88\x88\x88\x88\x70\x00" +"\xf0\x88\x88\xf0\x80\x80\x80\x00\x70\x88\x88\x88\xa8\x90\x68\x00" +"\xf0\x88\x88\xf0\xa0\x90\x88\x00\x70\x88\x80\x70\x08\x88\x70\x00" +"\xf8\x20\x20\x20\x20\x20\x20\x00\x88\x88\x88\x88\x88\x88\x70\x00" +"\x88\x88\x88\x88\x50\x50\x20\x00\x88\x88\x88\xa8\xa8\xd8\x88\x00" +"\x88\x88\x50\x20\x50\x88\x88\x00\x88\x88\x88\x70\x20\x20\x20\x00" +"\xf8\x08\x10\x20\x40\x80\xf8\x00\x70\x40\x40\x40\x40\x40\x70\x00" +"\x00\x00\x80\x40\x20\x10\x08\x00\x70\x10\x10\x10\x10\x10\x70\x00" +"\x20\x50\x88\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf8\x00" +"\x40\x20\x10\x00\x00\x00\x00\x00\x00\x00\x70\x08\x78\x88\x78\x00" +"\x80\x80\xb0\xc8\x88\xc8\xb0\x00\x00\x00\x70\x88\x80\x88\x70\x00" +"\x08\x08\x68\x98\x88\x98\x68\x00\x00\x00\x70\x88\xf8\x80\x70\x00" +"\x10\x28\x20\xf8\x20\x20\x20\x00\x00\x00\x68\x98\x98\x68\x08\x70" +"\x80\x80\xf0\x88\x88\x88\x88\x00\x20\x00\x60\x20\x20\x20\x70\x00" +"\x10\x00\x30\x10\x10\x10\x90\x60\x40\x40\x48\x50\x60\x50\x48\x00" +"\x60\x20\x20\x20\x20\x20\x70\x00\x00\x00\xd0\xa8\xa8\xa8\xa8\x00" +"\x00\x00\xb0\xc8\x88\x88\x88\x00\x00\x00\x70\x88\x88\x88\x70\x00" +"\x00\x00\xb0\xc8\xc8\xb0\x80\x80\x00\x00\x68\x98\x98\x68\x08\x08" +"\x00\x00\xb0\xc8\x80\x80\x80\x00\x00\x00\x78\x80\xf0\x08\xf0\x00" +"\x40\x40\xf0\x40\x40\x48\x30\x00\x00\x00\x90\x90\x90\x90\x68\x00" +"\x00\x00\x88\x88\x88\x50\x20\x00\x00\x00\x88\xa8\xa8\xa8\x50\x00" +"\x00\x00\x88\x50\x20\x50\x88\x00\x00\x00\x88\x88\x98\x68\x08\x70" +"\x00\x00\xf8\x10\x20\x40\xf8\x00\x18\x20\x20\x40\x20\x20\x18\x00" +"\x20\x20\x20\x00\x20\x20\x20\x00\xc0\x20\x20\x10\x20\x20\xc0\x00" +"\x40\xa8\x10\x00\x00\x00\x00\x00\x00\x00\x20\x50\xf8\x00\x00\x00" +"\x70\x88\x80\x80\x88\x70\x20\x60\x90\x00\x00\x90\x90\x90\x68\x00" +"\x10\x20\x70\x88\xf8\x80\x70\x00\x20\x50\x70\x08\x78\x88\x78\x00" +"\x48\x00\x70\x08\x78\x88\x78\x00\x20\x10\x70\x08\x78\x88\x78\x00" +"\x20\x00\x70\x08\x78\x88\x78\x00\x00\x70\x80\x80\x80\x70\x10\x60" +"\x20\x50\x70\x88\xf8\x80\x70\x00\x50\x00\x70\x88\xf8\x80\x70\x00" +"\x20\x10\x70\x88\xf8\x80\x70\x00\x50\x00\x00\x60\x20\x20\x70\x00" +"\x20\x50\x00\x60\x20\x20\x70\x00\x40\x20\x00\x60\x20\x20\x70\x00" +"\x50\x00\x20\x50\x88\xf8\x88\x00\x20\x00\x20\x50\x88\xf8\x88\x00" +"\x10\x20\xf8\x80\xf0\x80\xf8\x00\x00\x00\x6c\x12\x7e\x90\x6e\x00" +"\x3e\x50\x90\x9c\xf0\x90\x9e\x00\x60\x90\x00\x60\x90\x90\x60\x00" +"\x90\x00\x00\x60\x90\x90\x60\x00\x40\x20\x00\x60\x90\x90\x60\x00" +"\x40\xa0\x00\xa0\xa0\xa0\x50\x00\x40\x20\x00\xa0\xa0\xa0\x50\x00" +"\x90\x00\x90\x90\xb0\x50\x10\xe0\x50\x00\x70\x88\x88\x88\x70\x00" +"\x50\x00\x88\x88\x88\x88\x70\x00\x20\x20\x78\x80\x80\x78\x20\x20" +"\x18\x24\x20\xf8\x20\xe2\x5c\x00\x88\x50\x20\xf8\x20\xf8\x20\x00" +"\xc0\xa0\xa0\xc8\x9c\x88\x88\x8c\x18\x20\x20\xf8\x20\x20\x20\x40" +"\x10\x20\x70\x08\x78\x88\x78\x00\x10\x20\x00\x60\x20\x20\x70\x00" +"\x20\x40\x00\x60\x90\x90\x60\x00\x20\x40\x00\x90\x90\x90\x68\x00" +"\x50\xa0\x00\xa0\xd0\x90\x90\x00\x28\x50\x00\xc8\xa8\x98\x88\x00" +"\x00\x70\x08\x78\x88\x78\x00\xf8\x00\x60\x90\x90\x90\x60\x00\xf0" +"\x20\x00\x20\x40\x80\x88\x70\x00\x00\x00\x00\xf8\x80\x80\x00\x00" +"\x00\x00\x00\xf8\x08\x08\x00\x00\x84\x88\x90\xa8\x54\x84\x08\x1c" +"\x84\x88\x90\xa8\x58\xa8\x3c\x08\x20\x00\x00\x20\x20\x20\x20\x00" +"\x00\x00\x24\x48\x90\x48\x24\x00\x00\x00\x90\x48\x24\x48\x90\x00" +"\x28\x50\x20\x50\x88\xf8\x88\x00\x28\x50\x70\x08\x78\x88\x78\x00" +"\x28\x50\x00\x70\x20\x20\x70\x00\x28\x50\x00\x20\x20\x20\x70\x00" +"\x28\x50\x00\x70\x88\x88\x70\x00\x50\xa0\x00\x60\x90\x90\x60\x00" +"\x28\x50\x00\x88\x88\x88\x70\x00\x50\xa0\x00\xa0\xa0\xa0\x50\x00" +"\xfc\x48\x48\x48\xe8\x08\x50\x20\x00\x50\x00\x50\x50\x50\x10\x20" +"\xc0\x44\xc8\x54\xec\x54\x9e\x04\x10\xa8\x40\x00\x00\x00\x00\x00" +"\x00\x20\x50\x88\x50\x20\x00\x00\x88\x10\x20\x40\x80\x28\x00\x00" +"\x7c\xa8\xa8\x68\x28\x28\x28\x00\x38\x40\x30\x48\x48\x30\x08\x70" +"\x00\x00\x00\x00\x00\x00\xff\xff\xf0\xf0\xf0\xf0\x0f\x0f\x0f\x0f" +"\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00" +"\x00\x00\x00\x3c\x3c\x00\x00\x00\xff\xff\xff\xff\xff\xff\x00\x00" +"\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\x0f\x0f\x0f\x0f\xf0\xf0\xf0\xf0" +"\xfc\xfc\xfc\xfc\xfc\xfc\xfc\xfc\x03\x03\x03\x03\x03\x03\x03\x03" +"\x3f\x3f\x3f\x3f\x3f\x3f\x3f\x3f\x11\x22\x44\x88\x11\x22\x44\x88" +"\x88\x44\x22\x11\x88\x44\x22\x11\xfe\x7c\x38\x10\x00\x00\x00\x00" +"\x00\x00\x00\x00\x10\x38\x7c\xfe\x80\xc0\xe0\xf0\xe0\xc0\x80\x00" +"\x01\x03\x07\x0f\x07\x03\x01\x00\xff\x7e\x3c\x18\x18\x3c\x7e\xff" +"\x81\xc3\xe7\xff\xff\xe7\xc3\x81\xf0\xf0\xf0\xf0\x00\x00\x00\x00" +"\x00\x00\x00\x00\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x00\x00\x00\x00" +"\x00\x00\x00\x00\xf0\xf0\xf0\xf0\x33\x33\xcc\xcc\x33\x33\xcc\xcc" +"\x00\x20\x20\x50\x50\x88\xf8\x00\x20\x20\x70\x20\x70\x20\x20\x00" +"\x00\x00\x00\x50\x88\xa8\x50\x00\xff\xff\xff\xff\xff\xff\xff\xff" +"\x00\x00\x00\x00\xff\xff\xff\xff\xf0\xf0\xf0\xf0\xf0\xf0\xf0\xf0" +"\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\xff\xff\xff\xff\x00\x00\x00\x00" +"\x00\x00\x68\x90\x90\x90\x68\x00\x30\x48\x48\x70\x48\x48\x70\xc0" +"\xf8\x88\x80\x80\x80\x80\x80\x00\xf8\x50\x50\x50\x50\x50\x98\x00" +"\xf8\x88\x40\x20\x40\x88\xf8\x00\x00\x00\x78\x90\x90\x90\x60\x00" +"\x00\x50\x50\x50\x50\x68\x80\x80\x00\x50\xa0\x20\x20\x20\x20\x00" +"\xf8\x20\x70\xa8\xa8\x70\x20\xf8\x20\x50\x88\xf8\x88\x50\x20\x00" +"\x70\x88\x88\x88\x50\x50\xd8\x00\x30\x40\x40\x20\x50\x50\x50\x20" +"\x00\x00\x00\x50\xa8\xa8\x50\x00\x08\x70\xa8\xa8\xa8\x70\x80\x00" +"\x38\x40\x80\xf8\x80\x40\x38\x00\x70\x88\x88\x88\x88\x88\x88\x00" +"\x00\xf8\x00\xf8\x00\xf8\x00\x00\x20\x20\xf8\x20\x20\x00\xf8\x00" +"\xc0\x30\x08\x30\xc0\x00\xf8\x00\x18\x60\x80\x60\x18\x00\xf8\x00" +"\x10\x28\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\xa0\x40" +"\x00\x20\x00\xf8\x00\x20\x00\x00\x00\x50\xa0\x00\x50\xa0\x00\x00" +"\x00\x18\x24\x24\x18\x00\x00\x00\x00\x30\x78\x78\x30\x00\x00\x00" +"\x00\x00\x00\x00\x30\x00\x00\x00\x3e\x20\x20\x20\xa0\x60\x20\x00" +"\xa0\x50\x50\x50\x00\x00\x00\x00\x40\xa0\x20\x40\xe0\x00\x00\x00" +"\x00\x38\x38\x38\x38\x38\x38\x00\x00\x00\x00\x00\x00\x00\x00"; + + + diff --git a/app/graphics.c b/app/graphics.c new file mode 100644 index 0000000..91f243d --- /dev/null +++ b/app/graphics.c @@ -0,0 +1,168 @@ +#include "graphics.h" + +#include +#include +#include + +#define SCE_DISPLAY_UPDATETIMING_NEXTVSYNC SCE_DISPLAY_SETBUF_NEXTFRAME +#include +#include +#include + +enum { + SCREEN_WIDTH = 960, + SCREEN_HEIGHT = 544, + LINE_SIZE = 960, + FRAMEBUFFER_SIZE = 2 * 1024 * 1024, + FRAMEBUFFER_ALIGNMENT = 256 * 1024 +}; + +typedef union +{ + int rgba; + struct + { + char r; + char g; + char b; + char a; + } c; +} color_t; + +extern u8 msx[]; +void* g_vram_base; +static int gX = 0; +static int gY = 0; + +static Color g_fg_color; +static Color g_bg_color; + +static Color* getVramDisplayBuffer() +{ + Color* vram = (Color*) g_vram_base; + return vram; +} + +void *psvDebugScreenGetVram() { + return g_vram_base; +} + +int psvDebugScreenGetX() { + return gX; +} + +int psvDebugScreenGetY() { + return gY; +} + + // #define LOG(args...) vita_logf (__FILE__, __LINE__, args) ///< Write a log entry + +int g_log_mutex; + +void psvDebugScreenInit() { + g_log_mutex = sceKernelCreateMutex("log_mutex", 0, 0, NULL); + + SceKernelAllocMemBlockOpt opt = { 0 }; + opt.size = sizeof(opt); + opt.attr = 0x00000004; + opt.alignment = FRAMEBUFFER_ALIGNMENT; + SceUID displayblock = sceKernelAllocMemBlock("display", SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW, FRAMEBUFFER_SIZE, &opt); + printf("displayblock: 0x%08x", displayblock); + void *base; + sceKernelGetMemBlockBase(displayblock, &base); + // LOG("base: 0x%08x", base); + + SceDisplayFrameBuf framebuf = { 0 }; + framebuf.size = sizeof(framebuf); + framebuf.base = base; + framebuf.pitch = SCREEN_WIDTH; + framebuf.pixelformat = SCE_DISPLAY_PIXELFORMAT_A8B8G8R8; + framebuf.width = SCREEN_WIDTH; + framebuf.height = SCREEN_HEIGHT; + + g_vram_base = base; + + int ret = sceDisplaySetFrameBuf(&framebuf, SCE_DISPLAY_UPDATETIMING_NEXTVSYNC); + + g_fg_color = 0xFFFFFFFF; + g_bg_color = 0x00000000; +} + +void psvDebugScreenClear(int bg_color) +{ + gX = gY = 0; + int i; + color_t *pixel = (color_t *)getVramDisplayBuffer(); + for(i = 0; i < SCREEN_WIDTH * SCREEN_HEIGHT; i++) { + pixel->rgba = bg_color; + pixel++; + } +} + +static void printTextScreen(const char * text) +{ + int c, i, j, l; + u8 *font; + Color *vram_ptr; + Color *vram; + + for (c = 0; c < strlen(text); c++) { + if (gX + 8 > SCREEN_WIDTH) { + gY += 8; + gX = 0; + } + if (gY + 8 > SCREEN_HEIGHT) { + gY = 0; + psvDebugScreenClear(g_bg_color); + } + char ch = text[c]; + if (ch == '\n') { + gX = 0; + gY += 8; + continue; + } else if (ch == '\r') { + gX = 0; + continue; + } + + vram = getVramDisplayBuffer() + gX + gY * LINE_SIZE; + + font = &msx[ (int)ch * 8]; + for (i = l = 0; i < 8; i++, l += 8, font++) { + vram_ptr = vram; + for (j = 0; j < 8; j++) { + if ((*font & (128 >> j))) *vram_ptr = g_fg_color; + else *vram_ptr = g_bg_color; + vram_ptr++; + } + vram += LINE_SIZE; + } + gX += 8; + } +} + +void psvDebugScreenPrintf(const char *format, ...) { + char buf[0x1000]; + + sceKernelLockMutex(g_log_mutex, 1, NULL); + + va_list opt; + va_start(opt, format); + vsnprintf(buf, sizeof(buf), format, opt); + printTextScreen(buf); + va_end(opt); + + sceKernelUnlockMutex(g_log_mutex, 1); +} + +Color psvDebugScreenSetFgColor(Color color) { + Color prev_color = g_fg_color; + g_fg_color = color; + return prev_color; +} + +Color psvDebugScreenSetBgColor(Color color) { + Color prev_color = g_bg_color; + g_bg_color = color; + return prev_color; +} \ No newline at end of file diff --git a/app/graphics.h b/app/graphics.h new file mode 100644 index 0000000..4685dd8 --- /dev/null +++ b/app/graphics.h @@ -0,0 +1,34 @@ +#pragma once + +typedef unsigned char u8; +typedef unsigned u32; +typedef u32 Color; + +// allocates memory for framebuffer and initializes it +void psvDebugScreenInit(); + +// clears screen with a given color +void psvDebugScreenClear(int bg_color); + +// printf to the screen +void psvDebugScreenPrintf(const char *format, ...); + +// set foreground (text) color +Color psvDebugScreenSetFgColor(Color color); + +// set background color +Color psvDebugScreenSetBgColor(Color color); + +void *psvDebugScreenGetVram(); +int psvDebugScreenGetX(); +int psvDebugScreenGetY(); + +enum { + COLOR_CYAN = 0xFFFFFF00, + COLOR_WHITE = 0xFFFFFFFF, + COLOR_BLACK = 0xFF000000, + COLOR_RED = 0xFF0000FF, + COLOR_YELLOW = 0xFF00FFFF, + COLOR_GREY = 0xFF808080, + COLOR_GREEN = 0xFF00FF00, +}; diff --git a/app/main.c b/app/main.c new file mode 100644 index 0000000..d367aca --- /dev/null +++ b/app/main.c @@ -0,0 +1,279 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "graphics.h" +#include "rtcUserBridge.h" + +#define printf psvDebugScreenPrintf + +int ret; +SceUID fd; + +int get_key(void) { + static unsigned buttons[] = { + SCE_CTRL_SELECT, + SCE_CTRL_START, + SCE_CTRL_UP, + SCE_CTRL_RIGHT, + SCE_CTRL_DOWN, + SCE_CTRL_LEFT, + SCE_CTRL_LTRIGGER, + SCE_CTRL_RTRIGGER, + SCE_CTRL_TRIANGLE, + SCE_CTRL_CIRCLE, + SCE_CTRL_CROSS, + SCE_CTRL_SQUARE, + }; + + static unsigned prev = 0; + SceCtrlData pad; + while (1) { + memset(&pad, 0, sizeof(pad)); + sceCtrlPeekBufferPositive(0, &pad, 1); + unsigned newb = prev ^ (pad.buttons & prev); + prev = pad.buttons; + for (int i = 0; i < sizeof(buttons)/sizeof(*buttons); ++i) + if (newb & buttons[i]) + return buttons[i]; + + sceKernelDelayThread(1000); // 1ms + } +} + +int WriteFile(char *file, void *buf, int size) { + SceUID fd = sceIoOpen(file, SCE_O_WRONLY | SCE_O_CREAT | SCE_O_TRUNC, 0777); + if (fd < 0) + return fd; + + int written = sceIoWrite(fd, buf, size); + + sceIoClose(fd); + return written; +} + +int ReadFile(char *file, void *buf, int size) { + SceUID fd = sceIoOpen(file,SCE_O_RDONLY, 0777); + if (fd < 0) + return fd; + + int read = sceIoRead(fd, buf, size); + + sceIoClose(fd); + return read; +} + +int getFileSize(const char *file) { + SceUID fd = sceIoOpen(file, SCE_O_RDONLY, 0); + if (fd < 0) + return fd; + int fileSize = sceIoLseek(fd, 0, SCE_SEEK_END); + sceIoClose(fd); + return fileSize; +} + + + + +void main() { + + psvDebugScreenInit(); + if(vshSblAimgrIsDEX() == 9) + { + printf("This is not a testing kit . . . \n"); + get_key(); + sceKernelExitProcess(0); + } + + char kplugin_path[0x200]; + memset(kplugin_path,0x00,0x200); + + char uplugin_path[0x200]; + memset(uplugin_path,0x00,0x200); + + char titleid[12]; + sceAppMgrUmount("app0:"); + + printf("Loading kmodule..."); + + sceAppMgrAppParamGetString(0, 12, titleid , 256); + sprintf(kplugin_path, "ux0:app/%s/kern_clockset.skprx", titleid); + int kernel_modid = 0; + kernel_modid = taiLoadStartKernelModule(kplugin_path, 0, NULL, 0); + + + if(kernel_modid <= 0 && kernel_modid != 0x8002d013 && kernel_modid != 0x8002d004) + { + printf("Error cannot load kern_clockset.skprx error 0x%x\n",kernel_modid); + get_key(); + sceKernelExitProcess(0); + } + + printf("OK\n"); + + printf("Loading umodule..."); + + sceAppMgrAppParamGetString(0, 12, titleid , 256); + sprintf(uplugin_path, "ux0:app/%s/user_clockset.suprx", titleid); + int user_modid = 0; + user_modid = sceKernelLoadStartModule(uplugin_path, 0, NULL, 0, NULL, NULL); + + + if(user_modid <= 0) + { + printf("Error cannot load user_clockset.suprx error 0x%x\n",user_modid); + get_key(); + sceKernelExitProcess(0); + } + + printf("OK\n"); + + + + + printf("Finding expiration start date..."); + + unsigned char startDate[0x4]; + fd = sceIoOpen("tm0:/activate/act.dat",SCE_O_RDONLY, 0444); + if(fd <= -1) + { + printf("\ntm0:/activate/act.dat not found, cannot proceed :'( 0x%x\n",ret); + get_key(); + sceKernelExitProcess(0); + } + + sceIoLseek(fd,0xC,SCE_SEEK_SET); + sceIoRead(fd,&startDate,0x04); + sceIoClose(fd); + + fd = sceIoOpen("tm0:/activate/actsig.dat",SCE_O_RDONLY, 0444); + if(fd <= -1) + { + printf("\ntm0:/activate/actsig.dat not found, cannot proceed :'( 0x%x\n",ret); + get_key(); + sceKernelExitProcess(0); + } + sceIoClose(fd); + + printf(" found: 0x%02X%02X%02X%02X\n",startDate[0],startDate[1],startDate[2],startDate[3]); + + + printf("Backing up activation files... "); + + uint32_t buf[3]; + buf[0] = 0x00; + buf[1] = 0x00; + buf[2] = 0x00; + + vshIoUmount(0xC00, 0, 0, 0); + vshIoUmount(0xC00, 1, 0, 0); + _vshIoMount(0xC00, 0, 2, buf); + + //backup actdat + int size = getFileSize("tm0:/activate/act.dat"); + if (size <= -1){ + printf("getFileSize Failed, ret: 0x%x\n",size); + } + else + { + char *actdat = malloc(size); + ret = ReadFile("tm0:/activate/act.dat",actdat,size); + if (ret <= -1) + { + printf("ReadFile act failed 0x%x\n",ret); + } + + ret = WriteFile("pd0:/data/act.dat",actdat,size); + if (ret <= -1){ + printf("WriteFile actsig failed 0x%x\n",ret); + } + ret = WriteFile("ux0:/data/act.dat",actdat,size); + if (ret <= -1){ + printf("WriteFile act failed 0x%x\n",ret); + } + } + + //backup actsig + size = getFileSize("tm0:/activate/actsig.dat"); + if (size <= -1){ + printf("getFileSize failed ret: 0x%x\n",size); + } + else + { + char *actsig = malloc(size); + + ret = ReadFile("tm0:/activate/actsig.dat",actsig,size); + if (ret <= -1){ + printf("ReadFile actsig failed 0x%x\n",ret); + } + + ret = WriteFile("pd0:/data/actsig.dat",actsig,size); + if (ret <= -1){ + printf("WriteFile actsig failed 0x%x\n",ret); + } + + ret = WriteFile("ux0:/data/actsig.dat",actsig,size); + if (ret <= -1){ + printf("WriteFile actsig failed 0x%x\n",ret); + } + } + + vshIoUmount(0xC00, 0, 0, 0); + vshIoUmount(0xC00, 1, 0, 0); + _vshIoMount(0xC00, 0, 1, buf); + + printf("Done, backup at pd0:/data and ux0:/data\n"); + + printf("Calculating PSTime: "); + + unsigned long long int timestamp; + memset(×tamp,0,sizeof(unsigned long long int)); + timestamp = *((unsigned int*)&startDate); + timestamp = ((timestamp * 1000) + 62135596800000) * 1000; + + + printf("%llx\n",timestamp); + + printf("Creating splits..\n"); + char hexint[15]; + memset(hexint,0,15); + + sprintf(hexint,"%llx",timestamp); + + char ts1[7] = {hexint[0],hexint[1],hexint[2],hexint[3],hexint[4],hexint[5],0x00}; + unsigned long long int split1 = (unsigned int)strtoul(ts1, NULL, 16); + printf("Split1: %llx\n",split1); + + + char ts2[10] = {hexint[6],hexint[7],hexint[8],hexint[9],hexint[10],hexint[11],hexint[12],hexint[13],hexint[14],0x00}; + unsigned long long int split2 = (unsigned int)strtoul(ts2, NULL, 16); + printf("Split2: %llx\n",split2); + + printf("Updating SecureTick.. "); + + ret = silRtcSetCurrentSecureTick(split2,split1); + sceRegMgrSetKeyInt("/CONFIG/DATE", "set_automatically", 0); + + printf("has ret 0x%x\n",ret); + + if(ret == 0) + { + printf("\n\nYour PSVITA Testing Kit has been activated!\n"); + printf("\n"); + printf("Deactivate by holding START + SELECT + PS + POWER\n\n"); + printf("Press any key to reboot console"); + get_key(); + scePowerRequestColdReset(); + } + else + { + printf("Error: 0x%x\n",ret); + } + + get_key(); + } diff --git a/app/rtcUserBridge.h b/app/rtcUserBridge.h new file mode 100644 index 0000000..b89f4ec --- /dev/null +++ b/app/rtcUserBridge.h @@ -0,0 +1,3 @@ +int silRtcSetCurrentTick(unsigned int timestamp1, unsigned int timestamp2); +int silRtcSetCurrentNetworkTick(unsigned int timestamp1, unsigned int timestamp2); +int silRtcSetCurrentSecureTick(unsigned int timestamp1, unsigned int timestamp2); \ No newline at end of file diff --git a/app/sce_sys/icon0.png b/app/sce_sys/icon0.png new file mode 100644 index 0000000..140b936 Binary files /dev/null and b/app/sce_sys/icon0.png differ diff --git a/app/sce_sys/livearea/contents/bg.png b/app/sce_sys/livearea/contents/bg.png new file mode 100644 index 0000000..778b96b Binary files /dev/null and b/app/sce_sys/livearea/contents/bg.png differ diff --git a/app/sce_sys/livearea/contents/startup.png b/app/sce_sys/livearea/contents/startup.png new file mode 100644 index 0000000..a99b04b Binary files /dev/null and b/app/sce_sys/livearea/contents/startup.png differ diff --git a/app/sce_sys/livearea/contents/template.xml b/app/sce_sys/livearea/contents/template.xml new file mode 100644 index 0000000..730c4fa --- /dev/null +++ b/app/sce_sys/livearea/contents/template.xml @@ -0,0 +1,12 @@ + + + + + bg.png + + + + startup.png + + + diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..7f42e67 --- /dev/null +++ b/build.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +mkdir built + +echo "Building kmod" +cd kern +cmake . +make install +mv ./kern_clockset.skprx ../app + +make clean +rm -rf ./CMakeFiles +rm -rf ./kern_clockset-stubs +rm -f cmake_install.cmake +rm -f CMakeCache.txt +rm -f Makefile +rm -f install_manifest.txt + +cd .. + +echo "Building umod" +cd user +cmake . +make install +mv ./user_clockset.suprx ../app + +make clean +rm -rf ./stubs +rm -rf ./CMakeFiles +rm -f CMakeCache.txt +rm -f Makefile +rm -f install_manifest.txt +rm -f cmake_install.cmake + + +cd .. + +echo "Building app" +cd app +cmake . && make +mv activate.vpk ../built +mv eboot.bin ../built + +make clean +rm -rf ./CMakeFiles +rm -f activate.vpk.velf +rm -f cmake_install.cmake +rm -f CMakeCache.txt +rm -f eboot.bin +rm -f Makefile +rm -f param.sfo +rm -f kern_clockset.skprx +rm -f user_clockset.suprx \ No newline at end of file diff --git a/kern/CMakeLists.txt b/kern/CMakeLists.txt new file mode 100644 index 0000000..696b39d --- /dev/null +++ b/kern/CMakeLists.txt @@ -0,0 +1,51 @@ +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(kern_clockset) +include("$ENV{VITASDK}/share/vita.cmake" REQUIRED) + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-q -Wall -O3 -std=gnu99") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -nostdlib") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-rtti -fno-exceptions") + +link_directories( + ${CMAKE_CURRENT_BINARY_DIR} +) + +add_executable(${PROJECT_NAME} + kern_clockset.c +) + +target_link_libraries(${PROJECT_NAME} + k + SceSysmemForDriver_stub + SceThreadmgrForDriver_stub + SceIofilemgrForDriver_stub + SceDebugForDriver_stub + SceSysmem_stub + SceRtcForDriver_stub + SceCpuForDriver_stub + taihenForKernel_stub + gcc + -nostdlib +) +vita_create_self(${PROJECT_NAME}.skprx ${PROJECT_NAME} + UNSAFE + CONFIG ${CMAKE_SOURCE_DIR}/exports.yml +) +vita_create_stubs(${PROJECT_NAME}-stubs ${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/exports.yml + KERNEL +) + +install(DIRECTORY ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-stubs/ + DESTINATION lib + FILES_MATCHING PATTERN "*.a" +) + diff --git a/kern/exports.yml b/kern/exports.yml new file mode 100644 index 0000000..9f8961b --- /dev/null +++ b/kern/exports.yml @@ -0,0 +1,15 @@ +kern_clockset: + attributes: 0 + version: + major: 1 + minor: 1 + main: + start: module_start + stop: module_stop + modules: + kern_clockset: + syscall: true + functions: + - ksilRtcSetCurrentSecureTick + - ksilRtcSetCurrentNetworkTick + - ksilRtcSetCurrentTick \ No newline at end of file diff --git a/kern/kern_clockset.c b/kern/kern_clockset.c new file mode 100644 index 0000000..28aaa9c --- /dev/null +++ b/kern/kern_clockset.c @@ -0,0 +1,60 @@ +/* +* +* SILICAANDPINA +* +* KERNEL < - > USERLAND SceRtc BRIDGE +* +*/ + + + +#include +#include +#include +#include +#include + +int ksilRtcSetCurrentTick(timestamp1,timestamp2) +{ + unsigned int timestamp[2]; + + timestamp[0] = timestamp1; + timestamp[1] = timestamp2; + + return ksceRtcSetCurrentTick(timestamp); +} + +int ksilRtcSetCurrentNetworkTick(timestamp1,timestamp2) +{ + unsigned int timestamp[2]; + + timestamp[0] = timestamp1; + timestamp[1] = timestamp2; + + return ksceRtcSetCurrentNetworkTick(timestamp); +} + +int ksilRtcSetCurrentSecureTick(timestamp1,timestamp2) +{ + unsigned int timestamp[2]; + + timestamp[0] = timestamp1; + timestamp[1] = timestamp2; + + return ksceRtcSetCurrentSecureTick(timestamp); +} + + + +void _start() __attribute__ ((weak, alias ("module_start"))); +int module_start(SceSize argc, const void *args) +{ + return SCE_KERNEL_START_SUCCESS; +} + +int module_stop(SceSize argc, const void *args) +{ + return SCE_KERNEL_STOP_SUCCESS; +} + + diff --git a/user/CMakeLists.txt b/user/CMakeLists.txt new file mode 100644 index 0000000..0fa4f4a --- /dev/null +++ b/user/CMakeLists.txt @@ -0,0 +1,52 @@ +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(user_clockset) +include("${VITASDK}/share/vita.cmake" REQUIRED) + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-q -Wall -O3 -std=gnu99") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-rtti -fno-exceptions") + +include_directories( +) + +link_directories( + ${CMAKE_CURRENT_BINARY_DIR} +) + +if (NOT ${RELEASE}) + add_definitions(-DENABLE_LOGGING) +endif() + +add_executable(user_clockset + user_clockset.c +) + +target_link_libraries(user_clockset + taihen_stub + SceLibKernel_stub + SceIofilemgr_stub + kern_clockset_stub +) + +set_target_properties(user_clockset + PROPERTIES LINK_FLAGS "-nostdlib" +) + +vita_create_self(user_clockset.suprx user_clockset + CONFIG ${CMAKE_SOURCE_DIR}/exports.yml +) + +vita_create_stubs(stubs user_clockset ${CMAKE_SOURCE_DIR}/exports.yml) + +install(DIRECTORY ${CMAKE_BINARY_DIR}/stubs/ + DESTINATION lib + FILES_MATCHING PATTERN "*.a" +) diff --git a/user/exports.yml b/user/exports.yml new file mode 100644 index 0000000..ee0598a --- /dev/null +++ b/user/exports.yml @@ -0,0 +1,15 @@ +user_clockset: + attributes: 0 + version: + major: 1 + minor: 1 + main: + start: module_start + stop: module_stop + modules: + user_clockset: + syscall: false + functions: + - silRtcSetCurrentNetworkTick + - silRtcSetCurrentTick + - silRtcSetCurrentSecureTick diff --git a/user/rtcUserBridge.h b/user/rtcUserBridge.h new file mode 100644 index 0000000..9a85632 --- /dev/null +++ b/user/rtcUserBridge.h @@ -0,0 +1,3 @@ +int ksilRtcSetCurrentTick(unsigned int timestamp1, unsigned int timestamp2); +int ksilRtcSetCurrentNetworkTick(unsigned int timestamp1, unsigned int timestamp2); +int ksilRtcSetCurrentSecureTick(unsigned int timestamp1, unsigned int timestamp2); \ No newline at end of file diff --git a/user/user_clockset.c b/user/user_clockset.c new file mode 100644 index 0000000..5232590 --- /dev/null +++ b/user/user_clockset.c @@ -0,0 +1,32 @@ +// SilicaAndPina +// userland <-> userland bridge +// WHY TF DO I HAVE TO DO THIS ? + +#include +#include +#include +#include "rtcUserBridge.h" + +int silRtcSetCurrentTick(timestamp1,timestamp2) +{ + return ksilRtcSetCurrentTick(timestamp1,timestamp2); +} + +int silRtcSetCurrentNetworkTick(timestamp1,timestamp2) +{ + return ksilRtcSetCurrentNetworkTick(timestamp1,timestamp2); +} + +int silRtcSetCurrentSecureTick(timestamp1,timestamp2) +{ + return ksilRtcSetCurrentSecureTick(timestamp1,timestamp2); +} + + +int module_start(SceSize argc, const void *args) { + return SCE_KERNEL_START_SUCCESS; +} + +int module_stop(SceSize argc, const void *args) { + return SCE_KERNEL_STOP_SUCCESS; +}