TextureTable::TextureTable(int texture_x, int texture_y) : texture_x(texture_x), texture_y(texture_y), nb_character_per_line(TEXTURE_WIDTH_MAX/FONT_WIDTH-1) { // -1 : avoid sony last column bug ! int nb_character = FONT_END - FONT_BEGIN + 1; const int texture_width = nb_character_per_line * FONT_WIDTH; int nb_lines = ((nb_character-1) / nb_character_per_line+1); const int texture_height = nb_lines * FONT_HEIGHT; int sz = texture_width * texture_height / 2; unsigned char* texture = (unsigned char*)MemoryManager::malloc(sz); memset(texture, 0, sz); for (int i = 0; i < nb_character; i++ ) { int line_i = i / nb_character_per_line; unsigned char* pattern = &font_ascii[i][0]; for ( int y = 0; y < FONT_HEIGHT; y++ ) { for (int x = 0; x < FONT_WIDTH; x++ ) { unsigned char b = ((pattern[y] >> x) & 1); unsigned char v = b << (4 * (x&1)); texture[line_i * texture_width * (FONT_HEIGHT-1) / 2 + y * texture_width/2 + i*FONT_WIDTH/2 + x/2] |= v; } } } RECT r; setRECT(&r, texture_x, texture_y, texture_width/4, texture_height); LoadImage(&r, (u_long*)texture); DrawSync(0); MemoryManager::free(texture); }
bool GPUCommon::BusyDrawing() { u32 state = DrawSync(1); if (state == PSP_GE_LIST_DRAWING || state == PSP_GE_LIST_STALLING) { lock_guard guard(listLock); if (currentList && currentList->state != PSP_GE_DL_STATE_PAUSED) { return true; } } return false; }
/****************************************************************************** Function: void setup_text_fonts(void) By: David Schwartz Date: Jan 1995 Parameters: None Returns: None Description: load in text fonts, setup to use printfs, etc ******************************************************************************/ void setup_text_fonts(void) { RECT frame; /* load fonts into VRAM */ frame.w=128; frame.h=60; frame.x=FONT_15_BASE_X; frame.y=FONT_15_BASE_Y; texture_level_load(LVL_FONTS,SYNC_LOAD); LOADIMAGE(&frame,(ADDRESS *)p2_heap); font_lists[0].f_tpage=font_lists[1].f_tpage=font_lists[2].f_tpage=GetTPage(TEXTURE_MODE,TRANS_RATE,FONT_15_BASE_X,FONT_15_BASE_Y); DrawSync(0); return; }
/************* MAIN START ******************************************/ main() { int i; GsDOBJ2 *op; int outbuf_idx; MATRIX tmpls, tmplw; u_long vcount; u_long *p; long psize, tsize, amount, reduct; long sxy0,sxy1,sxy2,sxy3; POLY_FT4 *pft; ResetCallback(); init_all(); while (1) { if (obj_interactive() == 0) return 0; GsSetRefView2(&view); outbuf_idx = GsGetActiveBuff(); GsSetWorkBase((PACKET *) out_packet[outbuf_idx]); GsClearOt(0, 0, &Wot[outbuf_idx]); for (i = 0, op = object; i < Objnum; i++) { GsGetLws(op->coord2, &tmplw, &tmpls); GsSetLightMatrix(&tmplw); GsSetLsMatrix(&tmpls); SortTMDobject(op, &Wot[outbuf_idx], 14 - OT_LENGTH); op++; } VSync(0); padd = PadRead(1); GsSwapDispBuff(); GsSortClear(0x0, 0x0, 0x0, &Wot[outbuf_idx]); amount = 0; reduct = 0; for(p = (u_long *)Wot[outbuf_idx].tag; !isendprim(p); p = nextPrim(p)){ if((getlen(p) != 0) && (getcode(p) == 0x2c)){ amount++; psize = abs(NormalClip( *(u_long *)&(((POLY_FT4 *)p)->x0), *(u_long *)&(((POLY_FT4 *)p)->x1), *(u_long *)&(((POLY_FT4 *)p)->x2)))/2; psize += abs(NormalClip( *(u_long *)&(((POLY_FT4 *)p)->x1), *(u_long *)&(((POLY_FT4 *)p)->x2), *(u_long *)&(((POLY_FT4 *)p)->x3)))/2; pft = (POLY_FT4 *)p; sxy0 = (pft->v0)<<16 | pft->u0; sxy1 = (pft->v1)<<16 | pft->u1; sxy2 = (pft->v2)<<16 | pft->u2; sxy3 = (pft->v3)<<16 | pft->u3; tsize = abs(NormalClip(sxy0,sxy1,sxy2))/2; tsize += abs(NormalClip(sxy1,sxy2,sxy3))/2; if(psize < tsize) reduct++; } } GsClearVcount(); GsDrawOt(&Wot[outbuf_idx]); DrawSync(0); vcount = GsGetVcount(); if(ismip) KanjiFntPrint("(mip-map) %d\n(%d/%d)", vcount, reduct, amount); else KanjiFntPrint("(original) %d\n(%d/%d)", vcount, reduct, amount); KanjiFntFlush(-1); } }
main() { DB db[2]; /* packet double buffer */ DB *cdb; /* current db */ MATRIX rottrans; /* rot-trans matrix */ int i; /* work */ int dmy, flg; /* dummy */ CVECTOR col[12]; /* cube color */ u_long cnt; etc.near_clip=500; etc.far_clip=5000; etc.clip_off=0; PadInit(0); /* initialize PAD */ ResetGraph(0); /* reset graphic subsystem (0:cold,1:warm) */ SetGraphDebug(0); /* set debug mode (0:off, 1:monitor, 2:dump) */ InitGeom(); /* initialize geometry subsystem */ SetGeomOffset(320, 240); /* set geometry origin as (160, 120) */ SetGeomScreen(SCR_Z); /* distance to viewing-screen */ SetLightMatrix(&LLM); SetColorMatrix(&LCM); SetBackColor(BK.vx,BK.vy,BK.vz); SetFarColor(FC.vx,FC.vy,FC.vz); SetFogNear(1*SCR_Z,SCR_Z); /* initialize environment for double buffer (interlace) * buffer ID VRAM address *------------------------------------------------------- * buffer #0 (0, 0)-(640,480) * buffer #1 (0, 0)-(640,480) */ SetDefDrawEnv(&db[0].draw, 0, 0, 640, 480); SetDefDrawEnv(&db[1].draw, 0, 0, 640, 480); SetDefDispEnv(&db[0].disp, 0, 0, 640, 480); SetDefDispEnv(&db[1].disp, 0, 0, 640, 480); FntLoad(960,256); SetDumpFnt(FntOpen(64,64,256,200,0,512)); SetRCnt(RCntCNT2,0xffff,RCntMdNOINTR|RCntMdFR); StartRCnt(RCntCNT2); /* set surface colors */ for (i = 0; i < 12; i+=2) { col[i].r = col[i+1].r = 0xff/*rand()*/; /* R */ col[i].g = col[i+1].g = 0xff/*rand()*/; /* G */ col[i].b = col[i+1].b = 0xff/*rand()*/; /* B */ col[i].cd = col[i+1].cd = CODE_G3; /* cd */ } init_prim(&db[0]); /* set primitive parameters on buffer #0 */ init_prim(&db[1]); /* set primitive parameters on buffer #1 */ SetDispMask(1); /* enable to display (0:inhibit, 1:enable) */ while (pad_read(&rottrans) == 0) { cdb = (cdb==db)? db+1: db; /* swap double buffer ID */ ClearOTagR(cdb->ot, OTSIZE); /* clear ordering table */ /* add cube */ ResetRCnt(RCntCNT2); add_cube(cdb->ot, cdb->s, v, n, col); cnt= GetRCnt(RCntCNT2); FntPrint("cnt=%d\n",cnt); /* swap buffer */ DrawSync(0); /* wait for end of drawing */ VSync(0); /* wait for the next V-BLNK */ PutDrawEnv(&cdb->draw); /* update drawing environment */ PutDispEnv(&cdb->disp); /* update display environment */ DrawOTag(cdb->ot+OTSIZE-1); /* draw */ FntFlush(-1); } PadStop(); exit(); }
/****************************************************************************** Function: void stringer(void) By: David Schwartz Date: Jan 1995 Parameters: fnt_state - init state information fnt_buffer - set to text to print current_proc->pa8 - ptr to fnt_buffer str_flags - insert:justify bit 17 = set the "no_scroll" bit in oflags2 bit 16 = 1 insert on obj list bit 15 = 1 shadow the characters that get kicked out justify = 0 left justify 1 center justify 2 right justify Returns: None Description: read fnt_buffer and create an object lists of text to display ******************************************************************************/ void stringer(void) { LONG str_flags; short b2; // emul b2 register XYTYPE initpos; // a3 char cur_char; FNTTPAGE *fptr; OBJECT *obj,*tobj; // current object /* setup correct flag state */ switch (fnt_state.fnt_routine) { case STRCNRMOS: str_flags=0x18001; break; case STRCNRMOS_SCR: str_flags=0x18001|STR_SCROLL; break; case STRLNRMOS_SCR: str_flags=0x18000|STR_SCROLL; break; case STRRNRMOS_SCR: str_flags=0x18002|STR_SCROLL; break; case STRCNRMO_SCR: str_flags=0x10001|STR_SCROLL; break; case STRLNRMO_SCR: str_flags=0x10002|STR_SCROLL; break; case STRRNRMO_SCR: str_flags=0x10000|STR_SCROLL; break; } string_underline=0; // clear shadowing and underling flag (char *)current_proc->pa8=fnt_buffer; // set to start of string to display string_shadow=(str_flags & STR_SHADOW) ? 1:0; /* stringer_noshad */ spacing(); initpos.u.xpos=fnt_state.fnt_posx; initpos.u.ypos=fnt_state.fnt_posy; justify(str_flags & STR_JUSTIFY); /* stringr2 */ while (((short)*((char *)current_proc->pa8))!=0) { cur_char=*((char *)current_proc->pa8); ((char *)(current_proc->pa8))++; // next char b0=0; // not a space, yet if (cur_char<' ') { /* control character */ switch ((short)cur_char) { case NEW_XY: fnt_state.fnt_posx=(short)(*((char *)(current_proc->pa8))); ((char *)(current_proc->pa8))++; // next char fnt_state.fnt_posy=(short)(*((char *)(current_proc->pa8))); ((char *)(current_proc->pa8))++; // next char break; case NEW_SPACING: fnt_state.fnt_spacing=(WORD)(*((char *)(current_proc->pa8))); ((char *)(current_proc->pa8))++; // next char break; case ASCII_CR: fnt_state.fnt_posx=initpos.u.xpos; // get back to where we started fnt_state.fnt_posy=initpos.u.ypos+fnt_spacing.u.ypos; // move down 1 line initpos.u.xpos=fnt_state.fnt_posx; // store position initpos.u.ypos=fnt_state.fnt_posy; justify(str_flags & STR_JUSTIFY); break; case ADD_DYDX: fnt_state.fnt_posx+=((short)(*((char *)(current_proc->pa8)))); // add delta x ((char *)(current_proc->pa8))++; // next char fnt_state.fnt_posy+=((short)(*((char *)(current_proc->pa8)))); // add delta y ((char *)(current_proc->pa8))++; // next char break; } } else { if (cur_char==' ') { /* spacing info setup */ b2=fnt_state.fnt_posx; fnt_state.fnt_posx+=(fnt_spacing.u.xpos+fnt_state.fnt_spacing); if (string_underline==0) goto SKIP_DRAW; b0=b2; b2=fnt_state.fnt_posx; // swap locations fnt_state.fnt_posx=b0; b0=1; cur_char='a'; goto SKIP_DRAW; } /* strnchar, legal character draw time */ fptr=(font_lists[fnt_state.fnt_num].f_ptr)+((WORD)cur_char-0x21); // get ptr to correct character if (text_draw==1) { setXY4(cdb->curr_prim, \ fnt_state.fnt_posx,fnt_state.fnt_posy, \ fnt_state.fnt_posx+fptr->w,fnt_state.fnt_posy, \ fnt_state.fnt_posx,fnt_state.fnt_posy+fptr->h, \ fnt_state.fnt_posx+fptr->w,fnt_state.fnt_posy+fptr->h); SetUVWH(cdb->curr_prim,fptr->u0, \ fptr->v0, \ fptr->w, \ fptr->h); cdb->curr_prim->tpage=font_lists[fnt_state.fnt_num].f_tpage; cdb->curr_prim->clut=get_fore_pal(fnt_state.fnt_pal); DrawPrim(cdb->curr_prim); DrawSync(0); } else { if ((obj=get_object())!=NULL) { obj->oflags2=0; if (str_flags & STR_SCROLL) obj->oflags2|=M_NOSCROLL; // set no scroll bit obj->osag=fptr; obj->oxvel.pos=0; // clear out position & vel info obj->oyvel.pos=0; obj->oxpos.pos=0; obj->oypos.pos=0; #if CD_DEBUG if ( f_cdbug==1 ) { obj->oid=OID_CD; // stuff findable ID obj->opal=get_fore_pal(YELLOW_p); obj->ozval=1000; } else { obj->oid=OID_TEXT; // stuff findable ID obj->opal=get_fore_pal(fnt_state.fnt_pal); obj->ozval=1; } #else obj->oid=OID_TEXT; // stuff findable ID obj->opal=get_fore_pal(fnt_state.fnt_pal); obj->ozval=1; #endif obj->oxpos.u.intpos=fnt_state.fnt_posx; // eliminated anim point stuff obj->oypos.u.intpos=fnt_state.fnt_posy; /* setup header stuff */ obj->header.tpage=font_lists[fnt_state.fnt_num].f_tpage; obj->header.t_xoffset=(fptr->u0); obj->header.t_yoffset=fptr->v0; obj->header.t_width=fptr->w; obj->header.t_height=fptr->h; if (b0==0) insert_object(obj,&objlst2); /* check for underlining */ /* check for shadowing */ if (string_shadow!=0) { tobj=obj; if ((obj=get_object())!=NULL) { copy_obj(tobj,obj); if (fnt_state.fnt_num==FONT_15) { obj->oxpos.u.intpos+=1; obj->oypos.u.intpos+=1; } else { obj->oxpos.u.intpos+=1; obj->oypos.u.intpos+=1; } obj->ozval=0; // normal letters in front of shadows obj->opal=get_fore_pal(bpal_black_P); // shadow is done in black insert_object(obj,&objlst2); } } } } /* strngdun */ if (b0==0) { /* if characters is one need special spacing routine */ if (cur_char=='1') fptr++; fnt_state.fnt_posx+=(fnt_state.fnt_spacing+fptr->w); // pass character size and font spacing } else { fnt_state.fnt_posx=b2; } /* strng_bypass_1 */ if (fnt_state.fnt_sleep!=0) process_sleep(fnt_state.fnt_sleep); } SKIP_DRAW: } /* stringrx */ return; } /****************************************************************************** Function: void spacing(void) By: David Schwartz Date: Jan 1995 Parameters: None Returns: fnt_spacing - sets variables with correct spacing Description: set the spacing for the current font ******************************************************************************/ void spacing(void) { FNTTPAGE *fptr; if (fnt_state.fnt_num==FONT_15) { fnt_spacing.u.xpos=SCX(0x0a); fnt_spacing.u.ypos=SCY(0x13); } else { fptr=font_lists[fnt_state.fnt_num].f_ptr; // get pointer to font info fptr+='H'-0x21; // USE 'H' for space and newline stuff /* x sizing = (x size of 'H')/2 */ fnt_spacing.u.xpos=(fptr->w)>>1; /* x sizing = 3*(y size of 'H')/2 */ fnt_spacing.u.ypos=(fptr->h)+((fptr->h)>>1); } return; }