diff --git a/CMakeLists.txt b/CMakeLists.txt index bca457f..167f59b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ endif() add_executable(batteryPercent batteryPercent.c - blit.c + draw.c font.c ) diff --git a/batteryPercent.c b/batteryPercent.c index 4e7ec37..69cf653 100644 --- a/batteryPercent.c +++ b/batteryPercent.c @@ -3,7 +3,7 @@ #include #include #include -#include "blit.h" +#include "draw.h" static SceUID g_hooks[5]; int showMenu = 0; @@ -18,18 +18,19 @@ static tai_hook_ref_t ref_hook4; int sceDisplaySetFrameBuf_patched(const SceDisplayFrameBuf *pParam, int sync) { - blit_set_frame_buf(pParam); + drawSetFrameBuf(pParam); if(showMenu == 1) { - blit_set_color(0x00FFFFFF, 0x00000000); - blit_stringf(896, 0, "%d %%", scePowerGetBatteryLifePercent()); + drawSetColour(WHITE, BLACK); + drawStringf(896, 0, "%d %%", scePowerGetBatteryLifePercent()); } else if(showMenu == 2) { int batteryLifeTime = scePowerGetBatteryLifeTime(); - blit_set_color(0x00FFFFFF, 0x00000000); - blit_stringf(848, 0, "%02ih %02im", batteryLifeTime / 60, batteryLifeTime - (batteryLifeTime / 60 * 60)); + drawSetColour(WHITE, BLACK); + if (batteryLifeTime >= 0) + drawStringf(848, 0, "%02ih %02im", batteryLifeTime / 60, batteryLifeTime - (batteryLifeTime / 60 * 60)); } return TAI_CONTINUE(int, ref_hook0, pParam, sync); @@ -41,6 +42,7 @@ int checkButtons(int port, tai_hook_ref_t ref_hook, SceCtrlData *ctrl, int count if (ref_hook == 0) ret = 1; + else { ret = TAI_CONTINUE(int, ref_hook, port, ctrl, count); @@ -58,13 +60,9 @@ int checkButtons(int port, tai_hook_ref_t ref_hook, SceCtrlData *ctrl, int count else { if ((ctrl->buttons & SCE_CTRL_SELECT) && (ctrl->buttons & SCE_CTRL_UP)) - { showMenu = 1; - } else if ((ctrl->buttons & SCE_CTRL_SELECT) && (ctrl->buttons & SCE_CTRL_RIGHT)) - { showMenu = 2; - } } } @@ -124,7 +122,7 @@ int module_start(SceSize argc, const void *args) TAI_ANY_LIBRARY, 0xC4226A3E, // sceCtrlReadBufferPositive2 keys_patched4); - + return SCE_KERNEL_START_SUCCESS; } @@ -143,4 +141,4 @@ int module_stop(SceSize argc, const void *args) taiHookRelease(g_hooks[4], ref_hook4); return SCE_KERNEL_STOP_SUCCESS; -} +} \ No newline at end of file diff --git a/blit.h b/blit.h deleted file mode 100644 index 4a71bc2..0000000 --- a/blit.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __BLIT_H__ -#define __BLIT_H__ - -#include - -#define COLOR_CYAN 0x00ffff00 -#define COLOR_MAGENDA 0x00ff00ff -#define COLOR_YELLOW 0x0000ffff - -#define RGB(R,G,B) (((B)<<16)|((G)<<8)|(R)) -#define RGBT(R,G,B,T) (((T)<<24)|((B)<<16)|((G)<<8)|(R)) - -#define CENTER(num) ((960/2)-(num*(16/2))) - -int blit_setup(void); -void blit_set_color(int fg_col,int bg_col); -int blit_string(int sx,int sy,const char *msg); -int blit_string_ctr(int sy,const char *msg); -int blit_stringf(int sx, int sy, const char *msg, ...); -int blit_set_frame_buf(const SceDisplayFrameBuf *param); - -#endif diff --git a/blit.c b/draw.c similarity index 66% rename from blit.c rename to draw.c index b4bd31c..f99b2ae 100644 --- a/blit.c +++ b/draw.c @@ -1,18 +1,13 @@ -/* - PSP VSH 24bpp text bliter -*/ #include #include #include -#include "blit.h" +#include "draw.h" #define ALPHA_BLEND 1 extern unsigned char msx[]; -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// static int pwidth, pheight, bufferwidth, pixelformat; static unsigned int* vram32; @@ -20,8 +15,6 @@ static uint32_t fcolor = 0x00ffffff; static uint32_t bcolor = 0xff000000; #if ALPHA_BLEND -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// static uint32_t adjust_alpha(uint32_t col) { uint32_t alpha = col>>24; @@ -40,10 +33,10 @@ static uint32_t adjust_alpha(uint32_t col) } #endif -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// -//int blit_setup(int sx,int sy,const char *msg,int fg_col,int bg_col) -int blit_setup(void) +/* +* Sets up draw functions. +*/ +int drawInit(void) { SceDisplayFrameBuf param; param.size = sizeof(SceDisplayFrameBuf); @@ -55,7 +48,8 @@ int blit_setup(void) bufferwidth = param.pitch; pixelformat = param.pixelformat; - if( (bufferwidth==0) || (pixelformat!=0)) return -1; + if((bufferwidth==0) || (pixelformat!=0)) + return -1; fcolor = 0x00ffffff; bcolor = 0xff000000; @@ -63,25 +57,25 @@ int blit_setup(void) return 0; } -///////////////////////////////////////////////////////////////////////////// -// blit text -///////////////////////////////////////////////////////////////////////////// -void blit_set_color(int fg_col,int bg_col) +/* +* This function sets the string colour, as well as the background colour. +*/ +void drawSetColour(int fg_col, int bg_col) { fcolor = fg_col; bcolor = bg_col; } -///////////////////////////////////////////////////////////////////////////// -// blit text -///////////////////////////////////////////////////////////////////////////// -int blit_string(int sx,int sy,const char *msg) +/* +* This function draws a string onto the screen. +*/ +int drawString(int sx, int sy, const char *msg) { - int x,y,p; + int x, y, p; int offset; char code; unsigned char font; - uint32_t fg_col,bg_col; + uint32_t fg_col, bg_col; #if ALPHA_BLEND uint32_t col,c1,c2; @@ -144,13 +138,19 @@ int blit_string(int sx,int sy,const char *msg) return x; } -int blit_string_ctr(int sy,const char *msg) +/* +* This function draws a string onto the center of the screen. +*/ +int drawStringCenter(int sy, const char *msg) { - int sx = 960/2-sceClibStrnlen(msg, 512)*(16/2); - return blit_string(sx,sy,msg); + int sx = (960 / 2) - (sceClibStrnlen(msg, 512) * (16 / 2)); + return drawString(sx, sy, msg); } -int blit_stringf(int sx, int sy, const char *msg, ...) +/* +* This function draws a string onto the screen with string specifier formats. +*/ +int drawStringf(int sx, int sy, const char *msg, ...) { va_list list; char string[512]; @@ -159,12 +159,14 @@ int blit_stringf(int sx, int sy, const char *msg, ...) sceClibVsnprintf(string, 512, msg, list); va_end(list); - return blit_string(sx, sy, string); + return drawString(sx, sy, string); } -int blit_set_frame_buf(const SceDisplayFrameBuf *param) -{ - +/* +* This function sets the frame buffer. +*/ +int drawSetFrameBuf(const SceDisplayFrameBuf *param) +{ pwidth = param->width; pheight = param->height; vram32 = param->base; @@ -176,5 +178,5 @@ int blit_set_frame_buf(const SceDisplayFrameBuf *param) fcolor = 0x00ffffff; bcolor = 0xff000000; - return 0; + return 0; } diff --git a/draw.h b/draw.h new file mode 100644 index 0000000..cb8385f --- /dev/null +++ b/draw.h @@ -0,0 +1,47 @@ +#ifndef __DRAW_H__ +#define __DRAW_H__ + +#include + +#define CYAN 0x00FFFF00 +#define MAGENTA 0x00FF00FF +#define YELLOW 0x0000FFFF +#define WHITE 0x00FFFFFF +#define BLACK 0x00000000 + +#define RGB(R, G, B) (((B) << 16) | ((G) << 8) | (R)) +#define RGBT(R, G, B, T) (((T) << 24) | ((B) << 16) | ((G) << 8) | (R)) + +#define CENTER(num) ((960 / 2)-(num*(16/2))) + +/* +* Sets up draw functions. +*/ +int drawInit(void); + +/* +* This function sets the string colour, as well as the background colour. +*/ +void drawSetColour(int fg_col, int bg_col); + +/* +* This function draws a string onto the screen. +*/ +int drawString(int sx, int sy, const char *msg); + +/* +* This function draws a string onto the center of the screen. +*/ +int drawStringCenter(int sy, const char *msg); + +/* +* This function draws a string onto the screen with string specifier formats. +*/ +int drawStringf(int sx, int sy, const char *msg, ...); + +/* +* This function sets the frame buffer. +*/ +int drawSetFrameBuf(const SceDisplayFrameBuf *param); + +#endif