rendered paste body#include <pspkernel.h>#include <pspdisplay.h>#include <math.h>#include <string.h>#include <pspgu.h>#include <pspgum.h>#include "font.c"#define BUF_WIDTH (512)#define SCR_WIDTH (480)#define SCR_HEIGHT (272)PSP_MODULE_INFO("Text Sample", 0, 1, 1);PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);static unsigned int __attribute__((aligned(16))) list[262144];static int fontwidthtab[94] = { 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, // a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, // q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, // G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, // W, X, Y, Z, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, -, =, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, // `, !, @, #, $, %, ^, &, *, (, ), _, +, ~, [, ], 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, // \, {, }, |, ;, ', :, ", ,, ., /, <, >, ?,};int done = 0;// --------------------------------------------------------------------------int ExitCallback(int arg1, int arg2, void *common) { done = 1; sceKernelExitGame(); return 0;}// --------------------------------------------------------------------------int CallbackThread(SceSize args, void *argp) { int cbid; cbid = sceKernelCreateCallback("Exit Callback", ExitCallback, NULL); sceKernelRegisterExitCallback(cbid); sceKernelSleepThreadCB(); return 0;}// --------------------------------------------------------------------------int SetupCallbacks(void) { int thid = 0; thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, PSP_THREAD_ATTR_USER, 0); if (thid >= 0) { sceKernelStartThread(thid, 0, 0); } return thid;}// --------------------------------------------------------------------------void DrawString(const char* text, int x, int y, unsigned int color, int fw) { int len = (int)strlen(text); if(!len) return; typedef struct { float s, t; unsigned int c; float x, y, z; } VERT; VERT* v = sceGuGetMemory(sizeof(VERT) * 2 * len); int i; for (i = 0; i < len; i++) { unsigned char c = (unsigned char)text[i]; if (c < 32) { c = 0; } else if(c >= 128) { c = 0; } int tx = (c & 0x0F) << 4; int ty = (c & 0xF0); VERT* v0 = &v[i * 2 + 0]; VERT* v1 = &v[i * 2 + 1]; v0->s = (float)(tx + (fw ? ((16 - fw) >> 1) : ((16 - fontwidthtab[c]) >> 1))); v0->t = (float)(ty); v0->c = color; v0->x = (float)(x); v0->y = (float)(y); v0->z = 0.0f; v1->s = (float)(tx + 16 - (fw ? ((16 - fw) >> 1) : ((16 - fontwidthtab[c]) >> 1))); v1->t = (float)(ty + 16); v1->c = color; v1->x = (float)(x + (fw ? fw : fontwidthtab[c])); v1->y = (float)(y + 16); v1->z = 0.0f; x += (fw ? fw : fontwidthtab[c]); } sceGumDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_2D, len * 2, 0, v);}// --------------------------------------------------------------------------int main (int argc, char** argv) { SetupCallbacks(); sceGuInit(); sceGuStart(GU_DIRECT, list); sceGuDrawBuffer(GU_PSM_8888, (void*)0, BUF_WIDTH); sceGuDispBuffer(SCR_WIDTH, SCR_HEIGHT, (void*)0x88000, BUF_WIDTH); sceGuDepthBuffer((void*)0x110000, BUF_WIDTH); sceGuOffset(2048 - (SCR_WIDTH / 2), 2048 - (SCR_HEIGHT / 2)); sceGuViewport(2048, 2048, SCR_WIDTH, SCR_HEIGHT); sceGuDepthRange(0xc350, 0x2710); sceGuScissor(0, 0, SCR_WIDTH, SCR_HEIGHT); sceGuEnable(GU_SCISSOR_TEST); sceGuDisable(GU_DEPTH_TEST); sceGuShadeModel(GU_SMOOTH); sceGuEnable(GU_BLEND); sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); sceGuEnable(GU_TEXTURE_2D); sceGuTexMode(GU_PSM_8888, 0, 0, 0); sceGuTexImage(0, 256, 128, 256, font); sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA); sceGuTexEnvColor(0xFFFFFFFF); sceGuTexOffset(0.0f, 0.0f); sceGuTexScale(1.0f / 256.0f, 1.0f / 128.0f); sceGuTexWrap(GU_REPEAT, GU_REPEAT); sceGuTexFilter(GU_NEAREST, GU_NEAREST); sceGuFinish(); sceGuSync(0, 0); sceGuDisplay(GU_TRUE); sceGuClearColor(0xaa6633); while (!done) { sceGuStart(GU_DIRECT, list); sceGuClear(GU_COLOR_BUFFER_BIT); DrawString("ThIs Is My 1sT tEsT!", 0, 0, 0xFFFFFFFF, 0); DrawString("abcdefgABCDEFG", 0, 16, 0xFFFFFFFF, 0); sceGuFinish(); sceGuSync(0, 0); sceDisplayWaitVblankStart(); sceGuSwapBuffers(); } sceGuDisplay(GU_FALSE); sceGuTerm(); sceKernelExitGame(); return 0;}