From c07d34a5fccdad55c9abc249786247cc3650f893 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 6 Apr 2023 21:08:56 +1000 Subject: [PATCH] PSP: Launcher now doesn't immediately crash --- src/Core.h | 1 + src/Platform_PSP.c | 5 +++-- src/Window_PSP.c | 49 ++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/src/Core.h b/src/Core.h index 5964b4d04..4da14cbb4 100644 --- a/src/Core.h +++ b/src/Core.h @@ -244,6 +244,7 @@ typedef cc_uint8 cc_bool; #define CC_BUILD_CURL #define CC_BUILD_OPENAL #define CC_BUILD_PSP +#undef CC_BUILD_FREETYPE #undef EXTENDED_BLOCKS #endif #endif diff --git a/src/Platform_PSP.c b/src/Platform_PSP.c index 630cd6386..610937708 100644 --- a/src/Platform_PSP.c +++ b/src/Platform_PSP.c @@ -228,7 +228,8 @@ void Thread_Sleep(cc_uint32 milliseconds) { } static int ExecThread(unsigned int argc, void *argv) { - ((Thread_StartFunc)argv)(); + Thread_StartFunc* func = (Thread_StartFunc*)argv; + (*func)(); return 0; } @@ -247,7 +248,7 @@ void Thread_Start2(void* handle, Thread_StartFunc func) { } void Thread_Detach(void* handle) { - sceKernelDeleteThread((int)handle); + sceKernelDeleteThread((int)handle); // TODO don't call this?? } void Thread_Join(void* handle) { diff --git a/src/Window_PSP.c b/src/Window_PSP.c index 933108621..82c6699e3 100644 --- a/src/Window_PSP.c +++ b/src/Window_PSP.c @@ -6,6 +6,8 @@ #include "Funcs.h" #include "Bitmap.h" #include "Errors.h" +#include +#include #define BUFFER_WIDTH 512 #define SCREEN_WIDTH 480 @@ -18,8 +20,9 @@ void Window_Init(void) { DisplayInfo.ScaleX = 1; DisplayInfo.ScaleY = 1; - WindowInfo.Width = SCREEN_WIDTH; - WindowInfo.Height = SCREEN_HEIGHT; + WindowInfo.Width = SCREEN_WIDTH; + WindowInfo.Height = SCREEN_HEIGHT; + //WindowInfo.Focused = true; } static void DoCreateWindow(int _3d) { @@ -72,18 +75,52 @@ cc_result Window_SaveFileDialog(const struct SaveFileDialogArgs* args) { return ERR_NOT_SUPPORTED; } +static struct Bitmap fb_bmp; void Window_AllocFramebuffer(struct Bitmap* bmp) { - /* TODO implement */ + bmp->scan0 = (BitmapCol*)Mem_Alloc(bmp->width * bmp->height, 4, "window pixels"); + fb_bmp = *bmp; } void Window_DrawFramebuffer(Rect2D r) { - /* TODO implement */ + void* fb = sceGeEdramGetAddr(); + cc_uint32* src; + cc_uint32* dst; + int y; + + /* TODO: This probably isn't great and tears, and stuff like that.. */ + sceDisplayWaitVblankStart(); + sceDisplaySetMode(0, SCREEN_WIDTH, SCREEN_HEIGHT); + sceDisplaySetFrameBuf(fb, BUFFER_WIDTH, PSP_DISPLAY_PIXEL_FORMAT_8888, PSP_DISPLAY_SETBUF_IMMEDIATE); + + src = (cc_uint32*)fb_bmp.scan0 + r.X; + dst = (cc_uint32*)fb + r.X; + + for (y = r.Y; y < r.Y + r.Height; y++) { + Mem_Copy(dst + y * BUFFER_WIDTH, src + y * fb_bmp.width, r.Width * 4); + } } void Window_FreeFramebuffer(struct Bitmap* bmp) { - /* TODO implement */ + Mem_Free(bmp->scan0); } +/*void Window_AllocFramebuffer(struct Bitmap* bmp) { + void* fb = sceGeEdramGetAddr(); + bmp->scan0 = fb; + bmp->width = BUFFER_WIDTH; + bmp->height = SCREEN_HEIGHT; +} + +void Window_DrawFramebuffer(Rect2D r) { + //sceDisplayWaitVblankStart(); + //sceDisplaySetMode(0, SCREEN_WIDTH, SCREEN_HEIGHT); + //sceDisplaySetFrameBuf(sceGeEdramGetAddr(), BUFFER_WIDTH, PSP_DISPLAY_PIXEL_FORMAT_8888, PSP_DISPLAY_SETBUF_IMMEDIATE); +} + +void Window_FreeFramebuffer(struct Bitmap* bmp) { + +}*/ + void Window_OpenKeyboard(struct OpenKeyboardArgs* args) { /* TODO implement */ } void Window_SetKeyboardText(const cc_string* text) { } void Window_CloseKeyboard(void) { /* TODO implement */ } @@ -98,4 +135,4 @@ void Window_DisableRawMouse(void) { RegrabMouse(); Input_RawMode = false; } -#endif +#endif \ No newline at end of file