34 gsFontM = calloc(1,
sizeof(GSFONTM));
35 for (pgindx=0; pgindx<GS_FONTM_PAGE_COUNT; pgindx++)
45 for (pgindx=0; pgindx<GS_FONTM_PAGE_COUNT; pgindx++) {
69static u32 gsKit_fontm_clut[16]
__attribute__((aligned(128))) = {
95 for (pgindx=0; pgindx<GS_FONTM_PAGE_COUNT; pgindx++) {
124 u8 numlines, lineno, mask;
135 typedef struct line PADLINE;
149 FontMFile = open(
"rom0:FONTM", O_RDONLY);
152 printf(
"Failed to open FONTM from ROM0\n");
156 PackedSize = lseek(FontMFile, 0, SEEK_END);
158 lseek(FontMFile, 0, SEEK_SET);
160 packed = malloc(PackedSize);
162 if(read(FontMFile, packed, PackedSize) != PackedSize)
164 printf(
"Error Reading Packed FONTM Data\n");
171 updata.size = *(u32 *)packed;
172 updata.ptr = (
void *)((u8 *)packed + 4);
174 unpacked = malloc(updata.size);
176 gsKit_fontm_unpack_raw(unpacked, &updata);
198 temp = (u8 *)((u32)unpacked +
gsFontM->
Header.baseoffset + 17680);
204 temp2 = malloc(TexSize);
206 olddata = (PADLINE *)temp;
207 newdata = (PADLINE *)temp2;
212 for(offset = 0; offset < linemax; offset += 52)
215 for(numlines = 0; numlines < 52; numlines++)
217 mask = (numlines << 7);
220 newdata[numlines + offset] = olddata[offset + lineno + 26];
225 newdata[numlines + offset] = olddata[offset + lineno];
232 for(offset = 0; offset <
gsFontM->
Header.num_entries; offset++)
234 mask32 = (offset << 31);
243 tmpsrc = (u8 *)temp2;
245 for(
byte = 0;
byte < TexSize;
byte++)
247 tmpdst[byte] = (tmpsrc[byte] << 4) | (tmpsrc[
byte] >> 4);
255 printf(
"FONTM Header:\n");
259 printf(
"\tBaseOffset: 0x%08X\n",
gsFontM->
Header.baseoffset);
260 printf(
"\tNum Entries: 0x%08X\n",
gsFontM->
Header.num_entries);
272 for (i=0, p=base; p < base+oke->size; i--, oke->data <<= 1)
277 gsKit_fontm_unpack_raw_1(oke);
280 if (oke->data & 0x80000000)
282 val = *oke->ptr++ << 8;
284 src = p - (val & oke->shft) - 1;
285 count = (val >> oke->dif) + 2;
300 oke->data = *oke->ptr++ << 8;
301 oke->data = (oke->data | *oke->ptr++) << 8;
302 oke->data = (oke->data | *oke->ptr++) << 8;
303 oke->data = oke->data | *oke->ptr++;
304 oke->shft=0x3FFF >> (oke->data & 3);
305 oke->dif=14 - (oke->data & 3);
306 oke->ande=oke->data & 3;
312static u32 gsKit_fontm_ascii[128] = { 0, 0, 0, 0, 0, 0, 0, 0,
313 0, 0, 0, 0, 0, 0, 0, 0,
314 0, 0, 0, 0, 0, 0, 0, 0,
315 0, 0, 0, 0, 0, 0, 0, 0,
316 0, 9, 40, 83, 79, 82, 84, 38,
317 41, 42, 85, 59, 3, 60, 4, 30,
318 203, 204, 205, 206, 207, 208, 209, 210,
319 211, 212, 6, 7, 66, 64, 67, 8,
320 86, 220, 221, 222, 223, 224, 225, 226,
321 227, 228, 229, 230, 231, 232, 233, 234,
322 235, 236, 237, 238, 239, 240, 241, 242,
323 243, 244, 245, 45, 31, 46, 15, 17,
324 13, 252, 253, 254, 255, 256, 257, 258,
325 259, 260, 261, 262, 263, 264, 265, 266,
326 267, 268, 269, 270, 271, 272, 273, 274,
327 275, 276, 277, 47, 34, 48, 32, 0 };
329void gsKit_fontm_print_scaled(GSGLOBAL *
gsGlobal, GSFONTM *
gsFontM,
float X,
float Y,
int Z,
330 float scale,
unsigned long color,
const char *String)
339 u32 linechars[GSKIT_FONTM_MAXLINES];
341 float posx[GSKIT_FONTM_MAXLINES];
346 u32 aligned, idxoffset, idxremain;
363 length = strlen(String);
369 tabscale = (104.0f * scale);
371 for(pos = 0; pos < length; pos++)
374 if(cur !=
'\n' && cur !=
'\t')
376 linechars[numlines]++;
381 linechars[numlines] = 0;
383 else if(cur ==
'\t' &&
gsFontM->
Align != GSKIT_FALIGN_LEFT)
385 printf(
"WARNING: Tabs not supported in GSKIT_FALIGN_CENTER/RIGHT\n");
391 for(curline = 0; curline < numlines; curline++)
396 posx[curline] = X - (((26.0f * linechars[curline]) *
gsFontM->
Spacing * scale) / 2.0f);
398 posx[curline] = X - ((26.0f * linechars[curline]) *
gsFontM->
Spacing * scale);
403 for(pos = 0; pos < length; pos++)
410 posy += (26.0f * scale);
415 u8 tab = (posx[curline] / tabscale);
416 if((
int)posx % tabscale)
418 posx[curline] = (tab * tabscale);
437 memcpy(
code, &String[pos+1], 4);
445 for(slen = 0; ((pos + slen) < length) &&
446 String[pos + slen] >=
'a' &&
447 String[pos + slen] <=
'z'; slen++);
449 if((pos+slen) <= length)
451 char extstr[slen + 1];
452 memcpy(extstr, &String[pos], slen);
457 if(!strcmp(extstr,
"le"))
459 else if(!strcmp(extstr,
"ge"))
461 else if(!strcmp(extstr,
"inf"))
463 else if(!strcmp(extstr,
"male"))
465 else if(!strcmp(extstr,
"female"))
467 else if(!strcmp(extstr,
"degc"))
469 else if(!strcmp(extstr,
"yen"))
471 else if(!strcmp(extstr,
"cent"))
473 else if(!strcmp(extstr,
"pound"))
475 else if(!strcmp(extstr,
"left"))
477 else if(!strcmp(extstr,
"right"))
479 else if(!strcmp(extstr,
"fup"))
481 else if(!strcmp(extstr,
"fdown"))
483 else if(!strcmp(extstr,
"fleft"))
485 else if(!strcmp(extstr,
"fright"))
487 else if(!strcmp(extstr,
"hup"))
489 else if(!strcmp(extstr,
"hdown"))
491 else if(!strcmp(extstr,
"hleft"))
493 else if(!strcmp(extstr,
"hright"))
495 else if(!strcmp(extstr,
"ms"))
497 else if(!strcmp(extstr,
"us"))
499 else if(!strcmp(extstr,
"ns"))
501 else if(!strcmp(extstr,
"degf"))
503 else if(!strcmp(extstr,
"mbit"))
505 else if(!strcmp(extstr,
"hz"))
507 else if(!strcmp(extstr,
"kb"))
509 else if(!strcmp(extstr,
"mb"))
511 else if(!strcmp(extstr,
"gb"))
513 else if(!strcmp(extstr,
"tb"))
524 idx = gsKit_fontm_ascii[(int)cur];
526 idxoffset = idx / 64;
527 idxremain = idx % 64;
536 voffset = (idxremain * 26);
544 uoffset, uoffset + 25,
545 voffset, voffset + 25);
549 for (pgindx=0; pgindx<GS_FONTM_PAGE_COUNT; pgindx++) {
555 if (pgindx >= GS_FONTM_PAGE_COUNT) {
558 for (pgindx=0; pgindx<GS_FONTM_PAGE_COUNT; pgindx++) {
565 if (pgindx >= GS_FONTM_PAGE_COUNT) {
577 (
float)posx[curline] + (26.0f * scale), (
float)posy + (26.0f * scale), uoffset + 26, voffset + 27, Z, color);
#define GS_ATEST_OFF
Turns off Alpha Testing (Source).
#define GS_ATEST_ON
Turns on Alpha Testing (Source).
void gsKit_set_clamp(GSGLOBAL *gsGlobal, u8 Preset)
#define GS_CMODE_RESET
Resets CLAMP vales to whatever is in gsGlobal->Clamp.
#define GS_FILTER_LINEAR
Use bilinear filter on texture.
#define GS_CMODE_REGION_CLAMP
Stretches Texture Across the Region Defined by MINU, MAXU, MINV, and MAXV.
void gsKit_set_primalpha(GSGLOBAL *gsGlobal, u64 AlphaMode, u8 PerPixel)
Sets the Alpha Blending Parameters.
void gsKit_set_test(GSGLOBAL *gsGlobal, u8 Preset)
void gsKit_free_fontm(GSGLOBAL *gsGlobal, GSFONTM *gsFontM)
Free Font Object.
GSFONTM * gsKit_init_fontm()
Create Font Object.
#define GIF_TAG_AD(NLOOP)
A+D GIFTAG.
#define GS_PSM_CT32
R8 G8 B8 A8 (RGBA32) Texture.
#define GS_CLAMP_1
GS Texture Wrap Mode (Context 1).
#define GS_PSM_T4
4 Bit Texture with CLUT
#define GS_SETREG_ALPHA(A, B, C, D, FIX)
GS ALPHA Packing Macro.
#define GIF_AD
GIF_TAG Address+Data Setting. (Used after GIF_TAG).
#define GS_SETREG_CLAMP(wms, wmt, minu, maxu, minv, maxv)
GS CLAMP Packing Macro.
unsigned int gsKit_TexManager_bind(GSGLOBAL *gsGlobal, GSTEXTURE *tex)
Bind a texture to VRAM, will automatically transfer the texture.
void gsKit_TexManager_invalidate(GSGLOBAL *gsGlobal, GSTEXTURE *tex)
Invalidate a texture, will automatically transfer the texture on next bind call.
void gsKit_TexManager_free(GSGLOBAL *gsGlobal, GSTEXTURE *tex)
GSFONTMHDR Header
FONTM Header.
GSTEXTURE * Texture[GS_FONTM_PAGE_COUNT]
Font Texture Objects.
u32 VramIdx
FONTM Current Double Buffer Index.
float Spacing
FONTM Glyph Spacing.
u8 Align
FONTM Line Alignment.
void * TexBase
Glyphs Texture Base.
GSTEST * Test
TEST Register Value Structure Pointer.
int PrimContext
Primitive Context.
u64 PrimAlpha
Primitive Alpha Value.
u8 PABE
Choose if to do Alpha Blend on a Per-Pixel Basis.
u32 * Clut
EE CLUT Memory Pointer.
u32 * Mem
EE Memory Pointer.
u8 ClutPSM
CLUT Pixel Storage Method (Color Format).
u8 PSM
Pixel Storage Method (Color Format).
u32 Height
Height of the Texture.
u32 Width
Width of the Texture.
u32 Filter
NEAREST or LINEAR.