Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Michal Chvila <miso.chvila@gmail.com>
- Loading branch information
0 parents
commit ffd7bdc
Showing
12 changed files
with
7,277 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,2 @@ | ||
build/ | ||
VGi.project |
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,45 @@ | ||
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(VGi) | ||
include("$ENV{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") | ||
|
||
add_executable(${PROJECT_NAME} | ||
main.c | ||
display.c | ||
appinfo.c | ||
graphics.c | ||
memory.c | ||
misc.c | ||
) | ||
|
||
target_link_libraries(${PROJECT_NAME} | ||
k | ||
gcc | ||
taihen_stub | ||
taihenModuleUtils_stub | ||
SceAppMgr_stub | ||
SceDisplay_stub | ||
SceCtrl_stub | ||
SceKernelModulemgr_stub | ||
SceSysmem_stub | ||
SceLibc_stub | ||
) | ||
|
||
set_target_properties(${PROJECT_NAME} | ||
PROPERTIES LINK_FLAGS "-nostdlib" | ||
) | ||
|
||
vita_create_self(${PROJECT_NAME}.suprx ${PROJECT_NAME} | ||
CONFIG ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.yml | ||
) |
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,8 @@ | ||
VGi: | ||
attributes: 0 | ||
version: | ||
major: 0 | ||
minor: 1 | ||
main: | ||
start: module_start | ||
stop: module_stop |
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,62 @@ | ||
#include <libk/stdio.h> | ||
#include <vitasdk.h> | ||
#include <taihen.h> | ||
|
||
#include "display.h" | ||
#include "main.h" | ||
|
||
// app info | ||
static tai_module_info_t g_appModuleInfo = {0}; | ||
static SceKernelModuleInfo g_appSceModuleInfo = {0}; | ||
static char g_appContent[256] = {0}; | ||
static char g_appTitle[256] = {0}; | ||
static char g_appSTitle[64] = {0}; | ||
static char g_appTitleID[12] = {0}; | ||
static char g_appRegion[10] = {0}; | ||
|
||
void drawAppInfoMenu(const SceDisplayFrameBuf *pParam) { | ||
setTextScale(2); | ||
drawStringF((pParam->width / 2) - getTextWidth(MENU_TITLE_APP_INFO) / 2, 5, MENU_TITLE_APP_INFO); | ||
|
||
setTextScale(1); | ||
drawStringF(0, 60, "Title: %s", g_appTitle); | ||
drawStringF(0, 82, "STitle: %s", g_appSTitle); | ||
drawStringF(0, 104, "ContentID: %s", g_appContent); | ||
drawStringF(0, 126, "TitleID: %s [ %s ]", g_appTitleID, g_appRegion); | ||
drawStringF(0, 148, "Module: %s", g_appModuleInfo.name); | ||
drawStringF(0, 170, "Module path: %s", g_appSceModuleInfo.path); | ||
drawStringF(0, 192, "Module NID: 0x%08X", g_appModuleInfo.module_nid); | ||
} | ||
|
||
void setupAppInfoMenu() { | ||
g_appModuleInfo.size = sizeof(tai_module_info_t); | ||
taiGetModuleInfo(TAI_MAIN_MODULE, &g_appModuleInfo); | ||
|
||
g_appSceModuleInfo.size = sizeof(SceKernelModuleInfo); | ||
sceKernelGetModuleInfo(g_appModuleInfo.modid, &g_appSceModuleInfo); | ||
|
||
sceAppMgrAppParamGetString(0, 6, g_appContent, 256); | ||
sceAppMgrAppParamGetString(0, 9, g_appTitle, 256); | ||
sceAppMgrAppParamGetString(0, 10, g_appSTitle, 64); | ||
sceAppMgrAppParamGetString(0, 12, g_appTitleID, 12); | ||
|
||
if (!strncmp(g_appTitleID, "PCSA", 4)) { | ||
snprintf(g_appRegion, 10, "US 1st"); | ||
} else if (!strncmp(g_appTitleID, "PCSE", 4)) { | ||
snprintf(g_appRegion, 10, "US 3rd"); | ||
} else if (!strncmp(g_appTitleID, "PCSB", 4)) { | ||
snprintf(g_appRegion, 10, "EU 1st"); | ||
} else if (!strncmp(g_appTitleID, "PCSF", 4)) { | ||
snprintf(g_appRegion, 10, "EU 3rd"); | ||
} else if (!strncmp(g_appTitleID, "PCSC", 4)) { | ||
snprintf(g_appRegion, 10, "JP 1st"); | ||
} else if (!strncmp(g_appTitleID, "PCSG", 4)) { | ||
snprintf(g_appRegion, 10, "JP 3rd"); | ||
} else if (!strncmp(g_appTitleID, "PCSD", 4)) { | ||
snprintf(g_appRegion, 10, "ASIA 1st"); | ||
} else if (!strncmp(g_appTitleID, "PCSH", 4)) { | ||
snprintf(g_appRegion, 10, "ASIA 3rd"); | ||
} else { | ||
snprintf(g_appRegion, 10, "?"); | ||
} | ||
} |
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,106 @@ | ||
#include <psp2/types.h> | ||
#include <psp2/display.h> | ||
#include <libk/stdio.h> | ||
#include <libk/stdarg.h> | ||
#include <libk/string.h> | ||
#include "font_sun12x22.h" | ||
|
||
#define MAX_STRING_LENGTH 512 | ||
|
||
static SceDisplayFrameBuf frameBuf; | ||
static uint8_t fontScale = 1; | ||
static uint32_t colorFg = 0xFFFFFFFF; | ||
static uint32_t colorBg = 0xFF000000; | ||
|
||
uint32_t blendColor(uint32_t fg, uint32_t bg) { | ||
unsigned int alpha = ((fg >> 24) & 0xFF) + 1; | ||
unsigned int inv_alpha = 256 - ((fg >> 24) & 0xFF); | ||
uint32_t result = 0; | ||
result |= ((alpha * (fg & 0xFF) + inv_alpha * (bg & 0xFF)) >> 8) & 0xFF; | ||
result |= (((alpha * ((fg >> 8) & 0xFF) + inv_alpha * ((bg >> 8) & 0xFF)) >> 8) & 0xFF) << 8; | ||
result |= (((alpha * ((fg >> 16) & 0xFF) + inv_alpha * ((bg >> 16) & 0xFF)) >> 8) & 0xFF) << 16; | ||
result |= 0xFF << 24; | ||
return result; | ||
} | ||
|
||
void updateFrameBuf(const SceDisplayFrameBuf *pParam) { | ||
memcpy(&frameBuf, pParam, sizeof(SceDisplayFrameBuf)); | ||
} | ||
|
||
void setTextColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a) { | ||
colorFg = (a << 24) + (b << 16) + (g << 8) + r; | ||
} | ||
void setBgColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a) { | ||
colorBg = (a << 24) + (b << 16) + (g << 8) + r; | ||
} | ||
|
||
void setTextScale(uint8_t scale) { | ||
fontScale = scale; | ||
} | ||
|
||
uint32_t getTextWidth(const char *str) { | ||
return strlen(str) * FONT_WIDTH * fontScale; | ||
} | ||
|
||
void clearScreen() { | ||
if (!((colorBg >> 24) & 0xFF)) // alpha == 0 | ||
return; | ||
|
||
if (((colorBg >> 24) & 0xFF) == 0xFF) { // alpha == 255 | ||
memset(frameBuf.base, colorBg, sizeof(uint32_t) * (frameBuf.pitch * frameBuf.height)); | ||
} else { | ||
for (int y = 0; y < frameBuf.height; y++) { | ||
for (int x = 0; x < frameBuf.width; x++) { | ||
uint32_t *frameBufPtr = (uint32_t *)frameBuf.base + y * frameBuf.pitch + x; | ||
*frameBufPtr = blendColor(colorBg, *frameBufPtr); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void drawCharacter(int character, int x, int y) { | ||
for (int yy = 0; yy < FONT_HEIGHT * fontScale; yy++) { | ||
int yy_font = yy / fontScale; | ||
uint32_t displacement = x + (y + yy) * frameBuf.pitch; | ||
uint32_t *screenPos = (uint32_t *)frameBuf.base + displacement; | ||
|
||
if (displacement >= frameBuf.pitch * frameBuf.height) | ||
return; // out of bounds | ||
|
||
for (int xx = 0; xx < FONT_WIDTH * fontScale; xx++) { | ||
if (x + xx >= frameBuf.width) | ||
return; // oob | ||
|
||
// Get px 0/1 from font.h | ||
int xx_font = xx / fontScale; | ||
uint32_t charPos = character * (FONT_HEIGHT * ((FONT_WIDTH / 8) + 1)); | ||
uint32_t charPosH = charPos + (yy_font * ((FONT_WIDTH / 8) + 1)); | ||
uint8_t charByte = font[charPosH + (xx_font / 8)]; | ||
uint32_t clr = ((charByte >> (7 - (xx_font % 8))) & 1) ? colorFg : colorBg; | ||
|
||
if ((clr >> 24) & 0xFF) { // alpha != 0 | ||
if (((clr >> 24) & 0xFF) != 0xFF) { // alpha < 0xFF | ||
*(screenPos + xx) = blendColor(clr, *(screenPos + xx)); // blend FG/BG color | ||
} else { | ||
*(screenPos + xx) = clr; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
void drawString(int x, int y, const char *str) { | ||
for (size_t i = 0; i < strlen(str); i++) | ||
drawCharacter(str[i], x + i * FONT_WIDTH * fontScale, y); | ||
} | ||
|
||
void drawStringF(int x, int y, const char *format, ...) { | ||
char buffer[MAX_STRING_LENGTH] = { 0 }; | ||
va_list va; | ||
|
||
va_start(va, format); | ||
vsnprintf(buffer, MAX_STRING_LENGTH, format, va); | ||
va_end(va); | ||
|
||
drawString(x, y, buffer); | ||
} |
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,17 @@ | ||
#ifndef _DISPLAY_H_ | ||
#define _DISPLAY_H_ | ||
|
||
void updateFrameBuf(const SceDisplayFrameBuf *param); | ||
void setBgColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a); | ||
void setTextColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a); | ||
void setTextScale(uint8_t scale); | ||
|
||
uint32_t getTextWidth(const char *str); | ||
|
||
void clearScreen(); | ||
|
||
void drawCharacter(int character, int x, int y); | ||
void drawString(int x, int y, const char *str); | ||
void drawStringF(int x, int y, const char *format, ...); | ||
|
||
#endif |
Oops, something went wrong.