All pastes #143819 Raw Edit

Mine

public c v1 · immutable
#143819 ·published 2006-08-22 05:42 UTC
rendered paste body
#include <pspkernel.h>#include <pspdisplay.h>#include <math.h>#include <string.h>#include <pspgu.h>#include <pspgum.h>#include <stdio.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];char fontchrs[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=`!@#$%^&*()_+~[]\\{}|;':\",./<>? \0";static int fontwidthtab[95] = {  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, 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;}int FindChar (int c) {  int i;  for (i = 0; i < 95; i++) {    if (fontchrs[i] == c) break;  }  return i;}// --------------------------------------------------------------------------void DrawString(char *text, int x, int y, unsigned int color, int scale) {  int len = (int)strlen(text);  if(!len) return;  int chpos, tx, u, v;  char *t = text;  typedef struct {    float u, v;    unsigned int c;    float x, y, z;  } Vertex;  tx = x;  Vertex *sverts = sceGuGetMemory(sizeof(Vertex) * 2 * len);  Vertex *sv = sverts;  while (*t) {    chpos = FindChar(*t);    u = (chpos % 16) * 16;    v = (chpos / 6) * 16;    sv[0].x = tx;    sv[0].y = y;    sv[0].z = 0;    sv[0].c = color;    sv[0].u = u;    sv[0].v = v;    sv[1].x = tx + scale;    sv[1].y = y + scale;    sv[1].z = 0;    sv[1].c = color;    sv[1].u = u + 16;    sv[1].v = v - 16;    sv += 2;    tx += (int)(fontwidthtab[chpos] * (scale / 16.0));    t++;  }  sceGumDrawArray(GU_SPRITES, GU_VERTEX_16BIT | GU_TEXTURE_16BIT | GU_TRANSFORM_2D, len * 2, 0, sverts);}// --------------------------------------------------------------------------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, 16);    DrawString("abcdefgABCDEFG", 0, 16, 0xFF0000FF, 16);    sceGuFinish();    sceGuSync(0, 0);    sceDisplayWaitVblankStart();    sceGuSwapBuffers();  }  sceGuDisplay(GU_FALSE);  sceGuTerm();  sceKernelExitGame();  return 0;}