From 8ec22586fb44b13a0f52f083d9b50f3a38fe769f Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 19 Aug 2023 09:55:27 +1000 Subject: [PATCH] Vita: Launcher at least renders now --- src/Makefile_vita | 11 +++----- src/Window_PSVita.c | 63 +++++++++++++++++++++------------------------ 2 files changed, 32 insertions(+), 42 deletions(-) diff --git a/src/Makefile_vita b/src/Makefile_vita index 50ff22fd1..107795119 100644 --- a/src/Makefile_vita +++ b/src/Makefile_vita @@ -1,5 +1,5 @@ PROJECT_TITLE := ClassiCube -PROJECT_TITLEID := VSDK00007 +PROJECT_TITLEID := CUBE00200 TARGET := ClassiCube-vita BUILD_DIR := build @@ -21,12 +21,7 @@ $(BUILD_DIR): mkdir -p $(BUILD_DIR) $(TARGET).vpk: eboot.bin param.sfo - vita-pack-vpk -s param.sfo -b eboot.bin \ - --add sce_sys/icon0.png=sce_sys/icon0.png \ - --add sce_sys/livearea/contents/bg.png=sce_sys/livearea/contents/bg.png \ - --add sce_sys/livearea/contents/startup.png=sce_sys/livearea/contents/startup.png \ - --add sce_sys/livearea/contents/template.xml=sce_sys/livearea/contents/template.xml \ - $(TARGET).vpk + vita-pack-vpk -s param.sfo -b eboot.bin $(TARGET).vpk eboot.bin: $(TARGET).velf vita-make-fself $(TARGET).velf eboot.bin @@ -45,4 +40,4 @@ $(BUILD_DIR)/%.o : src/%.c arm-vita-eabi-gcc -c $(CFLAGS) -o $@ $< clean: - rm $(PROJECT).velf $(PROJECT).elf $(PROJECT).vpk param.sfo eboot.bin $(OBJS) + rm $(TARGET).velf $(TARGET).elf $(TARGET).vpk param.sfo eboot.bin $(OBJS) diff --git a/src/Window_PSVita.c b/src/Window_PSVita.c index 9b137b93e..d37773721 100644 --- a/src/Window_PSVita.c +++ b/src/Window_PSVita.c @@ -117,34 +117,46 @@ void Window_AllocFramebuffer(struct Bitmap* bmp) { } #define ALIGNUP(size, a) (((size) + ((a) - 1)) & ~((a) - 1)) + +static void AllocGPUMemory(int size, SceUID* ret_uid, void** ret_mem) { + SceUID uid; + void* mem; + size = ALIGNUP(size, 256 * 1024); + + // https://wiki.henkaku.xyz/vita/SceSysmem + uid = sceKernelAllocMemBlock("CC Framebuffer", SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW, size, NULL); + if (uid < 0) Logger_Abort2(uid, "Failed to allocate 2D framebuffer"); + + int res1 = sceKernelGetMemBlockBase(uid, &mem); + if (res1 < 0) Logger_Abort2(res1, "Failed to get base of 2D framebuffer"); + + int res2 = sceGxmMapMemory(mem, size, SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE); + if (res1 < 0) Logger_Abort2(res2, "Failed to map framebuffer for GPU usage"); + // https://wiki.henkaku.xyz/vita/GPU + + *ret_uid = uid; + *ret_mem = mem; +} + void Window_DrawFramebuffer(Rect2D r) { static SceUID fb_uid; static void* fb; - // TODO: Purge when closing the 2D window, so more memory for 3D ClassiCube - if (!fb) { - int size = ALIGNUP(4 * BUFFER_WIDTH * SCREEN_HEIGHT, 256 * 1024); - // https://wiki.henkaku.xyz/vita/SceSysmem - fb_uid = sceKernelAllocMemBlock("CC Framebuffer", SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW, size, NULL); - if (fb_uid < 0) Logger_Abort2(fb_uid, "Failed to allocate 2D framebuffer"); - - int res1 = sceKernelGetMemBlockBase(fb_uid, &fb); - if (res1 < 0) Logger_Abort2(res1, "Failed to get base of 2D framebuffer"); - - int res2 = sceGxmMapMemory(fb, size, SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE); - if (res1 < 0) Logger_Abort2(res2, "Failed to map framebuffer for GPU usage"); - // https://wiki.henkaku.xyz/vita/GPU - } + // TODO: Purge when closing the 2D window, so more memory for 3D ClassiCube + // TODO: Use framebuffers directly instead of our own internal framebuffer too.. + if (!fb) + AllocGPUMemory(4 * SCREEN_WIDTH * SCREEN_HEIGHT, &fb_uid, &fb); + sceDisplayWaitVblankStart(); SceDisplayFrameBuf framebuf = { 0 }; framebuf.size = sizeof(SceDisplayFrameBuf); framebuf.base = fb; - framebuf.pitch = BUFFER_WIDTH * 4; + framebuf.pitch = SCREEN_WIDTH; framebuf.pixelformat = SCE_DISPLAY_PIXELFORMAT_A8B8G8R8; framebuf.width = SCREEN_WIDTH; framebuf.height = SCREEN_HEIGHT; - + sceDisplaySetFrameBuf(&framebuf, SCE_DISPLAY_SETBUF_NEXTFRAME); cc_uint32* src = (cc_uint32*)fb_bmp.scan0 + r.X; @@ -152,7 +164,7 @@ void Window_DrawFramebuffer(Rect2D r) { for (int y = r.Y; y < r.Y + r.Height; y++) { - Mem_Copy(dst + y * BUFFER_WIDTH, src + y * fb_bmp.width, r.Width * 4); + Mem_Copy(dst + y * SCREEN_WIDTH, src + y * fb_bmp.width, r.Width * 4); } } @@ -160,23 +172,6 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) { 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) { - -}*/ - /*########################################################################################################################* *------------------------------------------------------Soft keyboard------------------------------------------------------*