Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdarg.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <pspsdk.h>
- #include <pspkernel.h>
- #include <pspdebug.h>
- #include <pspthreadman.h>
- #include <pspdisplay.h>
- PSP_MODULE_INFO("psp8x8font", PSP_MODULE_USER, 1, 1);
- PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);
- const char vincent_font_data[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x3E, 0x41, 0x55, 0x41, 0x55, 0x49, 0x3E,
- 0x00, 0x3E, 0x7F, 0x6B, 0x7F, 0x6B, 0x77, 0x3E,
- 0x00, 0x22, 0x77, 0x7F, 0x7F, 0x3E, 0x1C, 0x08,
- 0x00, 0x08, 0x1C, 0x3E, 0x7F, 0x3E, 0x1C, 0x08,
- 0x00, 0x08, 0x1C, 0x2A, 0x7F, 0x2A, 0x08, 0x1C,
- 0x00, 0x08, 0x1C, 0x3E, 0x7F, 0x3E, 0x08, 0x1C,
- 0x00, 0x00, 0x1C, 0x3E, 0x3E, 0x3E, 0x1C, 0x00,
- 0xFF, 0xFF, 0xE3, 0xC1, 0xC1, 0xC1, 0xE3, 0xFF,
- 0x00, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00,
- 0xFF, 0xFF, 0xE3, 0xDD, 0xDD, 0xDD, 0xE3, 0xFF,
- 0x00, 0x0F, 0x03, 0x05, 0x39, 0x48, 0x48, 0x30,
- 0x00, 0x08, 0x3E, 0x08, 0x1C, 0x22, 0x22, 0x1C,
- 0x00, 0x18, 0x14, 0x10, 0x10, 0x30, 0x70, 0x60,
- 0x00, 0x0F, 0x19, 0x11, 0x13, 0x37, 0x76, 0x60,
- 0x00, 0x08, 0x2A, 0x1C, 0x77, 0x1C, 0x2A, 0x08,
- 0x00, 0x60, 0x78, 0x7E, 0x7F, 0x7E, 0x78, 0x60,
- 0x00, 0x03, 0x0F, 0x3F, 0x7F, 0x3F, 0x0F, 0x03,
- 0x00, 0x08, 0x1C, 0x2A, 0x08, 0x2A, 0x1C, 0x08,
- 0x00, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x66,
- 0x00, 0x3F, 0x65, 0x65, 0x3D, 0x05, 0x05, 0x05,
- 0x00, 0x0C, 0x32, 0x48, 0x24, 0x12, 0x4C, 0x30,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x7F, 0x7F,
- 0x00, 0x08, 0x1C, 0x2A, 0x08, 0x2A, 0x1C, 0x3E,
- 0x00, 0x08, 0x1C, 0x3E, 0x7F, 0x1C, 0x1C, 0x1C,
- 0x00, 0x1C, 0x1C, 0x1C, 0x7F, 0x3E, 0x1C, 0x08,
- 0x00, 0x08, 0x0C, 0x7E, 0x7F, 0x7E, 0x0C, 0x08,
- 0x00, 0x08, 0x18, 0x3F, 0x7F, 0x3F, 0x18, 0x08,
- 0x00, 0x00, 0x00, 0x70, 0x70, 0x70, 0x7F, 0x7F,
- 0x00, 0x00, 0x14, 0x22, 0x7F, 0x22, 0x14, 0x00,
- 0x00, 0x08, 0x1C, 0x1C, 0x3E, 0x3E, 0x7F, 0x7F,
- 0x00, 0x7F, 0x7F, 0x3E, 0x3E, 0x1C, 0x1C, 0x08,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18,
- 0x00, 0x36, 0x36, 0x14, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36,
- 0x00, 0x08, 0x1E, 0x20, 0x1C, 0x02, 0x3C, 0x08,
- 0x00, 0x60, 0x66, 0x0C, 0x18, 0x30, 0x66, 0x06,
- 0x00, 0x3C, 0x66, 0x3C, 0x28, 0x65, 0x66, 0x3F,
- 0x00, 0x18, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00,
- 0x00, 0x60, 0x30, 0x18, 0x18, 0x18, 0x30, 0x60,
- 0x00, 0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06,
- 0x00, 0x00, 0x36, 0x1C, 0x7F, 0x1C, 0x36, 0x00,
- 0x00, 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x60,
- 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60,
- 0x00, 0x00, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x00,
- 0x00, 0x3C, 0x66, 0x6E, 0x76, 0x66, 0x66, 0x3C,
- 0x00, 0x18, 0x18, 0x38, 0x18, 0x18, 0x18, 0x7E,
- 0x00, 0x3C, 0x66, 0x06, 0x0C, 0x30, 0x60, 0x7E,
- 0x00, 0x3C, 0x66, 0x06, 0x1C, 0x06, 0x66, 0x3C,
- 0x00, 0x0C, 0x1C, 0x2C, 0x4C, 0x7E, 0x0C, 0x0C,
- 0x00, 0x7E, 0x60, 0x7C, 0x06, 0x06, 0x66, 0x3C,
- 0x00, 0x3C, 0x66, 0x60, 0x7C, 0x66, 0x66, 0x3C,
- 0x00, 0x7E, 0x66, 0x0C, 0x0C, 0x18, 0x18, 0x18,
- 0x00, 0x3C, 0x66, 0x66, 0x3C, 0x66, 0x66, 0x3C,
- 0x00, 0x3C, 0x66, 0x66, 0x3E, 0x06, 0x66, 0x3C,
- 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00,
- 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x30,
- 0x00, 0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06,
- 0x00, 0x00, 0x00, 0x3C, 0x00, 0x3C, 0x00, 0x00,
- 0x00, 0x60, 0x30, 0x18, 0x0C, 0x18, 0x30, 0x60,
- 0x00, 0x3C, 0x66, 0x06, 0x1C, 0x18, 0x00, 0x18,
- 0x00, 0x38, 0x44, 0x5C, 0x58, 0x42, 0x3C, 0x00,
- 0x00, 0x3C, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66,
- 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x66, 0x66, 0x7C,
- 0x00, 0x3C, 0x66, 0x60, 0x60, 0x60, 0x66, 0x3C,
- 0x00, 0x7C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7C,
- 0x00, 0x7E, 0x60, 0x60, 0x7C, 0x60, 0x60, 0x7E,
- 0x00, 0x7E, 0x60, 0x60, 0x7C, 0x60, 0x60, 0x60,
- 0x00, 0x3C, 0x66, 0x60, 0x60, 0x6E, 0x66, 0x3C,
- 0x00, 0x66, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66,
- 0x00, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C,
- 0x00, 0x1E, 0x0C, 0x0C, 0x0C, 0x6C, 0x6C, 0x38,
- 0x00, 0x66, 0x6C, 0x78, 0x70, 0x78, 0x6C, 0x66,
- 0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x7E,
- 0x00, 0x63, 0x77, 0x7F, 0x6B, 0x63, 0x63, 0x63,
- 0x00, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x63, 0x63,
- 0x00, 0x3C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C,
- 0x00, 0x7C, 0x66, 0x66, 0x66, 0x7C, 0x60, 0x60,
- 0x00, 0x3C, 0x66, 0x66, 0x66, 0x6E, 0x3C, 0x06,
- 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x78, 0x6C, 0x66,
- 0x00, 0x3C, 0x66, 0x60, 0x3C, 0x06, 0x66, 0x3C,
- 0x00, 0x7E, 0x5A, 0x18, 0x18, 0x18, 0x18, 0x18,
- 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3E,
- 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x18,
- 0x00, 0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63,
- 0x00, 0x63, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x63,
- 0x00, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x18, 0x18,
- 0x00, 0x7E, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x7E,
- 0x00, 0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E,
- 0x00, 0x00, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x00,
- 0x00, 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78,
- 0x00, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F,
- 0x00, 0x0C, 0x0C, 0x06, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x3C, 0x06, 0x3E, 0x66, 0x3E,
- 0x00, 0x60, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x7C,
- 0x00, 0x00, 0x00, 0x3C, 0x66, 0x60, 0x66, 0x3C,
- 0x00, 0x06, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3E,
- 0x00, 0x00, 0x00, 0x3C, 0x66, 0x7E, 0x60, 0x3C,
- 0x00, 0x1C, 0x36, 0x30, 0x30, 0x7C, 0x30, 0x30,
- 0x00, 0x00, 0x3E, 0x66, 0x66, 0x3E, 0x06, 0x3C,
- 0x00, 0x60, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x66,
- 0x00, 0x00, 0x18, 0x00, 0x18, 0x18, 0x18, 0x3C,
- 0x00, 0x0C, 0x00, 0x0C, 0x0C, 0x6C, 0x6C, 0x38,
- 0x00, 0x60, 0x60, 0x66, 0x6C, 0x78, 0x6C, 0x66,
- 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
- 0x00, 0x00, 0x00, 0x63, 0x77, 0x7F, 0x6B, 0x6B,
- 0x00, 0x00, 0x00, 0x7C, 0x7E, 0x66, 0x66, 0x66,
- 0x00, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x3C,
- 0x00, 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x60, 0x60,
- 0x00, 0x00, 0x3C, 0x6C, 0x6C, 0x3C, 0x0D, 0x0F,
- 0x00, 0x00, 0x00, 0x7C, 0x66, 0x66, 0x60, 0x60,
- 0x00, 0x00, 0x00, 0x3E, 0x40, 0x3C, 0x02, 0x7C,
- 0x00, 0x00, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x18,
- 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x3E,
- 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x3C, 0x18,
- 0x00, 0x00, 0x00, 0x63, 0x6B, 0x6B, 0x6B, 0x3E,
- 0x00, 0x00, 0x00, 0x66, 0x3C, 0x18, 0x3C, 0x66,
- 0x00, 0x00, 0x00, 0x66, 0x66, 0x3E, 0x06, 0x3C,
- 0x00, 0x00, 0x00, 0x3C, 0x0C, 0x18, 0x30, 0x3C,
- 0x00, 0x0E, 0x18, 0x18, 0x30, 0x18, 0x18, 0x0E,
- 0x00, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18,
- 0x00, 0x70, 0x18, 0x18, 0x0C, 0x18, 0x18, 0x70,
- 0x00, 0x00, 0x00, 0x3A, 0x6C, 0x00, 0x00, 0x00,
- 0x00, 0x08, 0x1C, 0x36, 0x63, 0x41, 0x41, 0x7F
- };
- #define SCREEN_HEIGHT 272
- #define SCREEN_WIDTH 512
- #define LINESIZE 512 //in long
- #define FRAMESIZE 0xAA000 //in byte
- unsigned long drawframe;
- unsigned char *vramtop=(unsigned char *)0x04000000;
- int run = 1;
- int exit_callback(int arg1, int arg2, void *common);
- int CallbackThread(SceSize args, void *argp);
- int SetupCallbacks(void);
- void draw_plot(int x, int y, u32 color);
- void font_draw_char(int x, int y, char c, u32 color);
- void font_draw_string(int x, int y, char *string, u32 color);
- void font_draw_stringf(int x, int y, u32 color, char *s, ...);
- unsigned char *GetVramAddr(unsigned long x,unsigned long y);
- void Fillvram(unsigned long color);
- void changeBuffer();
- void initScreen();
- int main(int argc, char* argv[]) {
- SetupCallbacks();
- initScreen();
- while(run) {
- Fillvram(0);
- font_draw_string(20, 20, "ola k aseeeeeee!!\naki salto de linea\taqui tabulador", 0xFF0000FF);
- changeBuffer();
- }
- return 0;
- }
- void draw_plot(int x, int y, u32 color)
- {
- *((u32*)GetVramAddr(x, y)) = color;
- }
- void font_draw_char(int x, int y, char c, u32 color)
- {
- if(c == ' ') return;
- int offset_pos = c * 8;
- int i, j, b;
- for(i = 0; i < 8; i++) {
- b = vincent_font_data[offset_pos + i];
- for(j = 0; j < 8; j++) {
- if(b & (1<<j)) {
- draw_plot(x+(7-j), y+i, color);
- }
- }
- }
- }
- void font_draw_string(int x, int y, char *string, u32 color)
- {
- if(!string) return;
- int startx = x;
- const char *s = string;
- while(*s) {
- if(*s == '\n') {
- x = startx;
- y+=8;
- } else if(*s == '\t') {
- x+=8*4;
- } else {
- font_draw_char(x, y, *s, color);
- x+=8;
- }
- s++;
- }
- }
- void font_draw_stringf(int x, int y, u32 color, char *s, ...)
- {
- char buffer[256];
- va_list args;
- va_start(args, s);
- vsnprintf(buffer, 256, s, args);
- font_draw_string(x, y, buffer, color);
- va_end(args);
- }
- // get vram address for character position
- unsigned char *GetVramAddr(unsigned long x,unsigned long y)
- {
- return vramtop+(drawframe?FRAMESIZE:0)+x*4+y*LINESIZE*4+0x40000000;
- }
- // clear video ram
- void Fillvram(unsigned long color)
- {
- unsigned char *vptr0; //pointer to vram
- unsigned long i;
- vptr0=GetVramAddr(0,0);
- for (i=0; i<(FRAMESIZE/4); i++)
- {
- *(unsigned long *)vptr0=color;
- vptr0+=4;
- }
- }
- void changeBuffer()
- {
- sceDisplayWaitVblankStart();
- sceDisplaySetFrameBuf( (void*)GetVramAddr(0,0), 512,
- PSP_DISPLAY_PIXEL_FORMAT_8888, 0);
- drawframe = (drawframe?0:1);
- }
- void initScreen()
- {
- drawframe = 0;
- sceDisplaySetMode(0,SCREEN_WIDTH,SCREEN_HEIGHT);
- sceDisplaySetFrameBuf((void*)vramtop, 512,
- PSP_DISPLAY_PIXEL_FORMAT_8888, 1);
- }
- /* Exit callback */
- int exit_callback(int arg1, int arg2, void *common)
- {
- run = 0;
- sceKernelExitGame();
- return 0;
- }
- /* Callback thread */
- int CallbackThread(SceSize args, void *argp)
- {
- int cbid;
- cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
- sceKernelRegisterExitCallback(cbid);
- sceKernelSleepThreadCB();
- return 0;
- }
- /* Sets up the callback thread and returns its thread id */
- int SetupCallbacks(void)
- {
- int thid = 0;
- thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
- if(thid >= 0) {
- sceKernelStartThread(thid, 0, 0);
- }
- return thid;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement