Skip to content

Commit

Permalink
Minor clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
joel16 committed Apr 27, 2017
1 parent a549e2b commit cf094f3
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 67 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -27,7 +27,7 @@ endif()

add_executable(batteryPercent
batteryPercent.c
blit.c
draw.c
font.c
)

Expand Down
22 changes: 10 additions & 12 deletions batteryPercent.c
Expand Up @@ -3,7 +3,7 @@
#include <psp2/ctrl.h>
#include <psp2/power.h>
#include <taihen.h>
#include "blit.h"
#include "draw.h"

static SceUID g_hooks[5];
int showMenu = 0;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
}
}
}

Expand Down Expand Up @@ -124,7 +122,7 @@ int module_start(SceSize argc, const void *args)
TAI_ANY_LIBRARY,
0xC4226A3E, // sceCtrlReadBufferPositive2
keys_patched4);

return SCE_KERNEL_START_SUCCESS;
}

Expand All @@ -143,4 +141,4 @@ int module_stop(SceSize argc, const void *args)
taiHookRelease(g_hooks[4], ref_hook4);

return SCE_KERNEL_STOP_SUCCESS;
}
}
22 changes: 0 additions & 22 deletions blit.h

This file was deleted.

66 changes: 34 additions & 32 deletions blit.c → draw.c
@@ -1,27 +1,20 @@
/*
PSP VSH 24bpp text bliter
*/
#include <psp2/types.h>
#include <psp2/display.h>
#include <psp2/kernel/clib.h>

#include "blit.h"
#include "draw.h"

#define ALPHA_BLEND 1

extern unsigned char msx[];

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
static int pwidth, pheight, bufferwidth, pixelformat;
static unsigned int* vram32;

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;
Expand All @@ -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);
Expand All @@ -55,33 +48,34 @@ 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;

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;
Expand Down Expand Up @@ -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];
Expand All @@ -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;
Expand All @@ -176,5 +178,5 @@ int blit_set_frame_buf(const SceDisplayFrameBuf *param)
fcolor = 0x00ffffff;
bcolor = 0xff000000;

return 0;
return 0;
}
47 changes: 47 additions & 0 deletions draw.h
@@ -0,0 +1,47 @@
#ifndef __DRAW_H__
#define __DRAW_H__

#include <psp2/display.h>

#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

0 comments on commit cf094f3

Please sign in to comment.