Add files via upload
This commit is contained in:
parent
502fae8a5c
commit
6e0144bc57
146
src/font.c
Normal file
146
src/font.c
Normal file
|
@ -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 <mrbrown@ocgnet.org>
|
||||
* Copyright (c) 2005 James Forshaw <tyranid@gmail.com>
|
||||
* Copyright (c) 2005 John Kelley <ps2dev@kelley.ca>
|
||||
*
|
||||
* $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";
|
||||
|
||||
|
||||
|
168
src/graphics.c
Normal file
168
src/graphics.c
Normal file
|
@ -0,0 +1,168 @@
|
|||
#include "graphics.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define SCE_DISPLAY_UPDATETIMING_NEXTVSYNC SCE_DISPLAY_SETBUF_NEXTFRAME
|
||||
#include <psp2/display.h>
|
||||
#include <psp2/kernel/sysmem.h>
|
||||
#include <psp2/kernel/threadmgr.h>
|
||||
|
||||
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;
|
||||
}
|
34
src/graphics.h
Normal file
34
src/graphics.h
Normal file
|
@ -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,
|
||||
};
|
106
src/main.c
Normal file
106
src/main.c
Normal file
|
@ -0,0 +1,106 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <psp2/ctrl.h>
|
||||
#include <psp2/io/fcntl.h>
|
||||
#include <psp2/kernel/threadmgr.h>
|
||||
#include <psp2/io/stat.h>
|
||||
#include <psp2/sysmodule.h>
|
||||
#include "sqlite3.h"
|
||||
#include "graphics.h"
|
||||
|
||||
#define printf psvDebugScreenPrintf
|
||||
|
||||
#define DEBUG 0
|
||||
|
||||
#if DEBUG
|
||||
#define LOG psvDebugScreenPrintf
|
||||
#else
|
||||
#define LOG(...)
|
||||
#endif
|
||||
|
||||
#define APP_DB "ur0:shell/db/app.db"
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
int get_key(void) {
|
||||
static unsigned prev = 0;
|
||||
SceCtrlData pad;
|
||||
while (1) {
|
||||
memset(&pad, 0, sizeof(pad));
|
||||
sceCtrlPeekBufferPositive(0, &pad, 1);
|
||||
unsigned new = prev ^ (pad.buttons & prev);
|
||||
prev = pad.buttons;
|
||||
for (int i = 0; i < sizeof(buttons)/sizeof(*buttons); ++i)
|
||||
if (new & buttons[i])
|
||||
return buttons[i];
|
||||
|
||||
sceKernelDelayThread(1000); // 1ms
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void sql_simple_exec(sqlite3 *db, const char *sql) {
|
||||
char *error = NULL;
|
||||
int ret = 0;
|
||||
ret = sqlite3_exec(db, sql, NULL, NULL, &error);
|
||||
if (error) {
|
||||
printf("Failed to execute %s: %s\n", sql, error);
|
||||
sqlite3_free(error);
|
||||
goto fail;
|
||||
}
|
||||
return;
|
||||
fail:
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
||||
void patch() {
|
||||
int ret;
|
||||
char sql[0x1000];
|
||||
char *error = NULL;
|
||||
|
||||
sqlite3 *db;
|
||||
ret = sqlite3_open(APP_DB, &db);
|
||||
if (ret) {
|
||||
printf("Failed to open the database: %s\n", sqlite3_errmsg(db));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
sql_simple_exec(db, "BEGIN TRANSACTION;");
|
||||
sql_simple_exec(db, "UPDATE tbl_appinfo_icon SET titleid=REPLACE(titleid,'PSTO00001','NPXS10002');");
|
||||
sql_simple_exec(db, "COMMIT TRANSACTION;");
|
||||
sql_simple_exec(db, "BEGIN TRANSACTION;");
|
||||
sql_simple_exec(db, "UPDATE tbl_appinfo_icon SET title=REPLACE(title,'Enable PS Store','PS Store');");
|
||||
sql_simple_exec(db, "COMMIT TRANSACTION;");
|
||||
sqlite3_close(db);
|
||||
db = NULL;
|
||||
|
||||
return;
|
||||
|
||||
fail:
|
||||
if (db)
|
||||
sqlite3_close(db);
|
||||
psvDebugScreenSetFgColor(COLOR_RED);
|
||||
printf("FAILURE! Reboot your PSTV/PSV into recovery mode and select 'rebuild database'\n");
|
||||
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int key = 0;
|
||||
patch();
|
||||
scePowerRequestColdReset();
|
||||
}
|
234
src/vita_sqlite.c
Normal file
234
src/vita_sqlite.c
Normal file
|
@ -0,0 +1,234 @@
|
|||
// This was only tested with sqlite 3.6.23.1
|
||||
// Please note that this .c file does not implement thread safety for sqlite, and as such requires it to be built with -DSQLITE_THREADSAFE=0 as well
|
||||
// Build flags for sqlite: -DSQLITE_OS_OTHER=1 -DSQLITE_TEMP_STORE=3 -DSQLITE_THREADSAFE=0
|
||||
|
||||
// It's also hacky -- no sync support, no tempdir support, access returning bs, etc... don't use in production!
|
||||
|
||||
// based on test_demovfs.c
|
||||
|
||||
#include "sqlite3.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <psp2/io/fcntl.h>
|
||||
#include <psp2/io/stat.h>
|
||||
#include <psp2/kernel/threadmgr.h>
|
||||
#include <psp2/rtc.h>
|
||||
|
||||
#define VERBOSE 0
|
||||
#if VERBOSE
|
||||
#define LOG psvDebugScreenPrintf
|
||||
#else
|
||||
#define LOG(...)
|
||||
#endif
|
||||
|
||||
typedef struct VitaFile {
|
||||
sqlite3_file base;
|
||||
unsigned fd;
|
||||
} VitaFile;
|
||||
|
||||
// File ops
|
||||
static int vita_xClose(sqlite3_file *pFile) {
|
||||
VitaFile *p = (VitaFile*)pFile;
|
||||
sceIoClose(p->fd);
|
||||
LOG("close %x\n", p->fd);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int vita_xRead(sqlite3_file *pFile, void *zBuf, int iAmt, sqlite_int64 iOfst) {
|
||||
VitaFile *p = (VitaFile*)pFile;
|
||||
memset(zBuf, 0, iAmt);
|
||||
sceIoLseek(p->fd, iOfst, SCE_SEEK_SET);
|
||||
int read = sceIoRead(p->fd, zBuf, iAmt);
|
||||
LOG("read %x %x %x => %x\n", p->fd, zBuf, iAmt, read);
|
||||
if (read == iAmt)
|
||||
return SQLITE_OK;
|
||||
else if (read >= 0)
|
||||
return SQLITE_IOERR_SHORT_READ;
|
||||
return SQLITE_IOERR_READ;
|
||||
}
|
||||
|
||||
static int vita_xWrite(sqlite3_file *pFile, const void *zBuf, int iAmt, sqlite_int64 iOfst) {
|
||||
VitaFile *p = (VitaFile*)pFile;
|
||||
int ofst = sceIoLseek(p->fd, iOfst, SCE_SEEK_SET);
|
||||
LOG("seek %x %x => %x\n", p->fd, iOfst, ofst);
|
||||
if (ofst != iOfst)
|
||||
return SQLITE_IOERR_WRITE;
|
||||
int write = sceIoWrite(p->fd, zBuf, iAmt);
|
||||
LOG("write %x %x %x => %x\n", p->fd, zBuf, iAmt);
|
||||
if (write != iAmt)
|
||||
return SQLITE_IOERR_WRITE;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int vita_xTruncate(sqlite3_file *pFile, sqlite_int64 size) {
|
||||
LOG("truncate\n");
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int vita_xSync(sqlite3_file *pFile, int flags) {
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int vita_xFileSize(sqlite3_file *pFile, sqlite_int64 *pSize) {
|
||||
VitaFile *p = (VitaFile*)pFile;
|
||||
SceIoStat stat = {0};
|
||||
sceIoGetstatByFd(p->fd, &stat);
|
||||
LOG("filesize %x => %x\n", p->fd, stat.st_size);
|
||||
*pSize = stat.st_size;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int vita_xLock(sqlite3_file *pFile, int eLock) {
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int vita_xUnlock(sqlite3_file *pFile, int eLock) {
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int vita_xCheckReservedLock(sqlite3_file *pFile, int *pResOut) {
|
||||
*pResOut = 0;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int vita_xFileControl(sqlite3_file *pFile, int op, void *pArg) {
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int vita_xSectorSize(sqlite3_file *pFile) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vita_xDeviceCharacteristics(sqlite3_file *pFile) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// VFS ops
|
||||
static int vita_xOpen(sqlite3_vfs *vfs, const char *name, sqlite3_file *file, int flags, int *outFlags) {
|
||||
static const sqlite3_io_methods vitaio = {
|
||||
1,
|
||||
vita_xClose,
|
||||
vita_xRead,
|
||||
vita_xWrite,
|
||||
vita_xTruncate,
|
||||
vita_xSync,
|
||||
vita_xFileSize,
|
||||
vita_xLock,
|
||||
vita_xUnlock,
|
||||
vita_xCheckReservedLock,
|
||||
vita_xFileControl,
|
||||
vita_xSectorSize,
|
||||
vita_xDeviceCharacteristics,
|
||||
};
|
||||
|
||||
VitaFile *p = (VitaFile*)file;
|
||||
unsigned oflags = 0;
|
||||
if (flags & SQLITE_OPEN_EXCLUSIVE)
|
||||
oflags |= SCE_O_EXCL;
|
||||
if (flags & SQLITE_OPEN_CREATE)
|
||||
oflags |= SCE_O_CREAT;
|
||||
if (flags & SQLITE_OPEN_READONLY)
|
||||
oflags |= SCE_O_RDONLY;
|
||||
if (flags & SQLITE_OPEN_READWRITE)
|
||||
oflags |= SCE_O_RDWR;
|
||||
// TODO(xyz): sqlite tries to open inexistant journal and then tries to read from it, wtf?
|
||||
// so force O_CREAT here
|
||||
if (flags & SQLITE_OPEN_MAIN_JOURNAL && !(flags & SQLITE_OPEN_EXCLUSIVE))
|
||||
oflags |= SCE_O_CREAT;
|
||||
memset(p, 0, sizeof(*p));
|
||||
p->fd = sceIoOpen(name, oflags, 7);
|
||||
LOG("open %s %x orig flags %x => %x\n", name, oflags, flags, p->fd);
|
||||
if (p->fd < 0) {
|
||||
return SQLITE_CANTOPEN;
|
||||
}
|
||||
if (outFlags)
|
||||
*outFlags = flags;
|
||||
|
||||
p->base.pMethods = &vitaio;
|
||||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
int vita_xDelete(sqlite3_vfs *vfs, const char *name, int syncDir) {
|
||||
int ret = sceIoRemove(name);
|
||||
if (ret < 0)
|
||||
return SQLITE_IOERR_DELETE;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
int vita_xAccess(sqlite3_vfs *vfs, const char *name, int flags, int *pResOut) {
|
||||
*pResOut = 1;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
int vita_xFullPathname(sqlite3_vfs *vfs, const char *zName, int nOut, char *zOut) {
|
||||
snprintf(zOut, nOut, "%s", zName);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* vita_xDlOpen(sqlite3_vfs *vfs, const char *zFilename) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void vita_xDlError(sqlite3_vfs *vfs, int nByte, char *zErrMsg) {
|
||||
}
|
||||
|
||||
void (*vita_xDlSym(sqlite3_vfs *vfs,void*p, const char *zSymbol))(void) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void vita_xDlClose(sqlite3_vfs *vfs, void*p) {
|
||||
}
|
||||
|
||||
int vita_xRandomness(sqlite3_vfs *vfs, int nByte, char *zOut) {
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
int vita_xSleep(sqlite3_vfs *vfs, int microseconds) {
|
||||
sceKernelDelayThread(microseconds);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
int vita_xCurrentTime(sqlite3_vfs *vfs, double *pTime) {
|
||||
time_t t = 0;
|
||||
SceDateTime time = {0};
|
||||
sceRtcGetCurrentClock(&time, 0);
|
||||
sceRtcGetTime_t(&time, &t);
|
||||
*pTime = t/86400.0 + 2440587.5;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
int vita_xGetLastError(sqlite3_vfs *vfs, int e, char *err) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
sqlite3_vfs vita_vfs = {
|
||||
.iVersion = 1,
|
||||
.szOsFile = sizeof(VitaFile),
|
||||
.mxPathname = 0x100,
|
||||
.pNext = NULL,
|
||||
.zName = "psp2",
|
||||
.pAppData = NULL,
|
||||
.xOpen = vita_xOpen,
|
||||
.xDelete = vita_xDelete,
|
||||
.xAccess = vita_xAccess,
|
||||
.xFullPathname = vita_xFullPathname,
|
||||
.xDlOpen = vita_xDlOpen,
|
||||
.xDlError = vita_xDlError,
|
||||
.xDlSym = vita_xDlSym,
|
||||
.xDlClose = vita_xDlClose,
|
||||
.xRandomness = vita_xRandomness,
|
||||
.xSleep = vita_xSleep,
|
||||
.xCurrentTime = vita_xCurrentTime,
|
||||
.xGetLastError = vita_xGetLastError,
|
||||
};
|
||||
|
||||
int sqlite3_os_init(void) {
|
||||
sqlite3_vfs_register(&vita_vfs, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sqlite3_os_end(void) {
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user