Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright (C) 2013, xerpi
- */
- #include "tinyfont.h"
- #include <pspgu.h>
- #include <psputils.h>
- #include <stdarg.h>
- #include <string.h>
- #include <stdio.h>
- extern const char vincent_font_data[];
- static Vertex3S __attribute__((aligned(16))) _tinyfont_static_vertices[8 * 8];
- static void *_tinyfont_framebuffer = NULL;
- static void _tinyfont_draw_gu_char(int x, int y, unsigned int color, char c)
- {
- if(c == ' ' || x > 480 || y > 272 || x < 0 || y < 0) return;
- int offset_pos = c * 8;
- int i, j, b, count = 0;
- for(i = 0; i < 8; i++) {
- b = vincent_font_data[offset_pos + i];
- for(j = 0; j < 8; j++) {
- if(b & (1<<j)) {
- _tinyfont_static_vertices[count] = (Vertex3S){(short)(x+(7-j)), (short)(y+i), 0};
- ++count;
- }
- }
- }
- Vertex3S *vertices = sceGuGetMemory(count * sizeof(Vertex3S));
- for(i = 0; i < count; i++) {
- vertices[i] = _tinyfont_static_vertices[i];
- }
- sceGuDrawArray(GU_POINTS, GU_VERTEX_16BIT|GU_TRANSFORM_2D, count, 0, vertices);
- }
- static void _tinyfont_draw_copy_char(int x, int y, unsigned int color, char c)
- {
- if(c == ' ' || x > 480 || y > 272 || x < 0 || y < 0) return;
- int offset_pos = c * 8;
- unsigned int __attribute__((aligned(16))) glyph[8*8];
- int l;
- for(l = 0; l < 8*8; ++l)
- glyph[l] = 0;
- 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)) {
- glyph[(7-j) + i*8] = color;
- }
- }
- }
- sceKernelDcacheWritebackRange(glyph, 8*8 * sizeof(unsigned int));
- sceGuCopyImage(GU_PSM_8888,0,0,8,8,8,glyph,x,y,512,(void*)(0x04000000+(u32)_tinyfont_framebuffer));
- }
- void tinyfont_set_framebuffer(void *framebuffer)
- {
- _tinyfont_framebuffer = framebuffer;
- }
- void tinyfont_draw_char(int x, int y, unsigned int color, char c)
- {
- //sceGuColor(color);
- //_tinyfont_draw_gu_char(x, y, color, c);
- _tinyfont_draw_texture_char(x, y, color, c);
- }
- void tinyfont_draw_string(int x, int y, unsigned int color, const char *string)
- {
- if(string == NULL) return;
- int startx = x;
- const char *s = string;
- //sceGuColor(color);
- while(*s) {
- if(*s == '\n') {
- x = startx;
- y+=8;
- } else if(*s == '\t') {
- x+=8*4;
- } else {
- tinyfont_draw_char(x, y, color, *s);
- x+=8;
- }
- ++s;
- }
- }
- void tinyfont_draw_stringf(int x, int y, unsigned int color, const char *s, ...)
- {
- char buffer[256];
- va_list args;
- va_start(args, s);
- vsnprintf(buffer, 256, s, args);
- tinyfont_draw_string(x, y, color, buffer);
- va_end(args);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement