void psp_init(void) { SceUID thid; char buff[128], *r; /* fw 1.5 sometimes returns 8002032c, although getcwd works */ r = getcwd(buff, sizeof(buff)); if (r) sceIoChdir(buff); main_thread_id = sceKernelGetThreadId(); lprintf("running on %08x kernel\n", sceKernelDevkitVersion()), lprintf("entered psp_init, threadId %08x, priority %i\n", main_thread_id, sceKernelGetThreadCurrentPriority()); thid = sceKernelCreateThread("update_thread", callback_thread, 0x11, 0xFA0, 0, NULL); if (thid >= 0) { sceKernelStartThread(thid, 0, 0); } /* video */ sceDisplaySetMode(0, 480, 272); sceDisplaySetFrameBuf(VRAM_FB1, 512, PSP_DISPLAY_PIXEL_FORMAT_565, PSP_DISPLAY_SETBUF_NEXTFRAME); current_screen = 1; psp_screen = VRAM_FB0; /* gu */ sceGuInit(); sceGuStart(GU_DIRECT, guCmdList); sceGuDrawBuffer(GU_PSM_5650, (void *)VRAMOFFS_FB0, 512); sceGuDispBuffer(480, 272, (void *)VRAMOFFS_FB1, 512); // don't care sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT); sceGuDepthBuffer((void *)VRAMOFFS_DEPTH, 512); sceGuOffset(2048 - (480 / 2), 2048 - (272 / 2)); sceGuViewport(2048, 2048, 480, 272); sceGuDepthRange(0xc350, 0x2710); sceGuScissor(0, 0, 480, 272); sceGuEnable(GU_SCISSOR_TEST); sceGuDepthMask(0xffff); sceGuDisable(GU_DEPTH_TEST); sceGuFrontFace(GU_CW); sceGuEnable(GU_TEXTURE_2D); sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB); sceGuAmbientColor(0xffffffff); sceGuColor(0xffffffff); sceGuFinish(); sceGuSync(0, 0); sceDisplayWaitVblankStart(); sceGuDisplay(GU_TRUE); /* input */ sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); }
void MasterGuRenderer::guInit() { DEBUG_ENTER_FUNC(); sceGuInit(); sceGuStart(0, _displayList); guProgramDisplayBufferSizes(); sceGuOffset(2048 - (PSP_SCREEN_WIDTH / 2), 2048 - (PSP_SCREEN_HEIGHT / 2)); sceGuViewport(2048, 2048, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT); sceGuDepthRange(0xC350, 0x2710); sceGuDisable(GU_DEPTH_TEST); // We'll use depth buffer area sceGuDepthMask(GU_TRUE); // Prevent writes to depth buffer sceGuScissor(0, 0, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT); sceGuEnable(GU_SCISSOR_TEST); sceGuFrontFace(GU_CW); sceGuEnable(GU_TEXTURE_2D); sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT); sceGuFinish(); sceGuSync(0, 0); sceDisplayWaitVblankStart(); sceGuDisplay(1); }
void init() { sceGuInit(); sceGuStart(GU_DIRECT, list); sceGuDrawBuffer(GU_PSM_8888, fbp0, 512); sceGuDispBuffer(480, 272, fbp0, 512); sceGuDepthBuffer(dbp0, 512); sceGuOffset(2048 - (240 / 2), 2048 - (136 / 2)); sceGuViewport(2048, 2048, 240, 136); sceGuDepthRange(65535, 0); sceGuDepthMask(0); sceGuScissor(0, 0, 480, 272); sceGuEnable(GU_SCISSOR_TEST); sceGuFrontFace(GU_CW); sceGuShadeModel(GU_SMOOTH); sceGuDisable(GU_TEXTURE_2D); ScePspFMatrix4 ones = { {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}, }; sceGuSetMatrix(GU_MODEL, &ones); sceGuSetMatrix(GU_VIEW, &ones); sceGuSetMatrix(GU_PROJECTION, &ones); sceGuFinish(); sceGuSync(0, 0); sceDisplayWaitVblankStart(); sceGuDisplay(1); memset(copybuf, 0x44, sizeof(copybuf)); sceKernelDcacheWritebackInvalidateAll(); sceDmacMemcpy(sceGeEdramGetAddr(), copybuf, sizeof(copybuf)); sceKernelDcacheWritebackInvalidateAll(); displayBuffer("Initial"); }
int dxpGraphicsSetup2D(u32 color) { GUSTART; if(dxpGraphicsData.drawstate != DXP_DRAWSTATE_NONTEX2D) { GUDISABLE(GU_TEXTURE_2D); dxpGraphicsData.texture = NULL; dxpGraphicsData.drawstate = DXP_DRAWSTATE_NONTEX2D; if(dxpGraphicsData.usedepth) { GUENABLE(GU_DEPTH_TEST); sceGuDepthFunc(dxpGraphicsData.depthfunc); sceGuDepthBuffer(dxpGraphicsData.depthbuffer.texvram,512); //深度バッファを有効にするときでいい if(dxpGraphicsData.writedepth)sceGuDepthMask(0); else sceGuDepthMask(1); } else GUDISABLE(GU_DEPTH_TEST); dxpGraphicsData.forceupdate = 1; } register u32 r,g,b,a,t; r = color & 0x000000ff; t = dxpGraphicsData.color & 0x000000ff; r *= t; r /= 255; g = (color & 0x0000ff00) >> 8; t = (dxpGraphicsData.color & 0x0000ff00) >> 8; g *= t; g /= 255; b = (color & 0x00ff0000) >> 16; t = (dxpGraphicsData.color & 0x00ff0000) >> 16; b *= t; b /= 255; //a = (color & 0xff000000) >> 24; //t = (dxpGraphicsData.color & 0xff000000) >> 24; //a *= t; //a /= 255; a = (dxpGraphicsData.color & 0xff000000) >> 24; color = (a << 24) | (b << 16) | (g << 8) | r; int op; int src,dest; unsigned int srcfix; unsigned int destfix; switch(dxpGraphicsData.blendmode) { case DX_BLENDMODE_NOBLEND: GUDISABLE(GU_BLEND); sceGuColor(dxpGraphicsData.gucolor = color); dxpGraphicsData.forceupdate = 0; return 0; case DX_BLENDMODE_INVSRC: op = GU_ADD; src = GU_SRC_ALPHA; dest = GU_ONE_MINUS_SRC_ALPHA; srcfix = 0; destfix = 0; color = (color & 0xff000000) | ~(color & 0x00ffffff); break; case DX_BLENDMODE_ALPHA: op = GU_ADD; src = GU_SRC_ALPHA; dest = GU_ONE_MINUS_SRC_ALPHA; srcfix = 0; destfix = 0; break; case DX_BLENDMODE_ADD: op = GU_ADD; src = GU_SRC_ALPHA; dest = GU_FIX; srcfix = 0xffffffff; destfix = 0xffffffff; break; case DX_BLENDMODE_SUB: op = GU_REVERSE_SUBTRACT; src = GU_SRC_ALPHA; dest = GU_FIX; srcfix = 0xffffffff; destfix = 0xffffffff; break; case DX_BLENDMODE_MUL: op = GU_ADD; src = GU_DST_COLOR; dest = GU_FIX; srcfix = 0; destfix = 0; break; case DX_BLENDMODE_DESTCOLOR: op = GU_ADD; src = GU_FIX; dest = GU_FIX; srcfix = 0; destfix = 0xffffffff; break; case DX_BLENDMODE_INVDESTCOLOR: op = GU_ADD; src = GU_ONE_MINUS_DST_COLOR; dest = GU_FIX; srcfix = 0; destfix = 0; break; default: return -1; } sceGuColor(dxpGraphicsData.gucolor = color); GUENABLE(GU_BLEND); if(dxpGraphicsData.forceupdate || dxpGraphicsData.op != op || dxpGraphicsData.src != src || dxpGraphicsData.dest != dest || dxpGraphicsData.srcfix != srcfix || dxpGraphicsData.destfix != destfix ){ sceGuBlendFunc(op,src,dest,srcfix,destfix); dxpGraphicsData.op = op; dxpGraphicsData.src = src; dxpGraphicsData.dest = dest; dxpGraphicsData.srcfix = srcfix; dxpGraphicsData.destfix = destfix; } dxpGraphicsData.forceupdate = 0; return 0; }
int dxpGraphicsSetup2DTex(DXPTEXTURE3 *texptr,int flag) { if(!texptr)return -1; //設定が同じなら変更処理をしない if(dxpGraphicsData.drawstate == DXP_DRAWSTATE_TEX2D && flag == dxpGraphicsData.flag && texptr == dxpGraphicsData.texture && !texptr->reloadflag && !dxpGraphicsData.forceupdate )return 0; GUSTART; if(dxpGraphicsData.drawstate != DXP_DRAWSTATE_TEX2D) {//2Dテクスチャ用の描画設定を行う。 dxpGraphicsData.drawstate = DXP_DRAWSTATE_TEX2D; dxpGraphicsData.forceupdate = 1; GUENABLE(GU_TEXTURE_2D); if(dxpGraphicsData.bilinear_enable) sceGuTexFilter(GU_LINEAR,GU_LINEAR); else sceGuTexFilter(GU_NEAREST,GU_NEAREST); if(dxpGraphicsData.usedepth) { GUENABLE(GU_DEPTH_TEST); sceGuDepthFunc(dxpGraphicsData.depthfunc); sceGuDepthBuffer(dxpGraphicsData.depthbuffer.texvram,512); //深度バッファを有効にするときでいい if(dxpGraphicsData.writedepth)sceGuDepthMask(0); else sceGuDepthMask(1); } else GUDISABLE(GU_DEPTH_TEST); } //テクスチャの設定開始 if(texptr != dxpGraphicsData.texture || texptr->reloadflag) {//GUにテクスチャの指定をする if(texptr->ppalette && (texptr->psm == GU_PSM_T8 || texptr->psm == GU_PSM_T4)) {//パレットの設定 sceGuClutMode(GU_PSM_8888,0,0xff,0); sceGuClutLoad(texptr->psm == GU_PSM_T4 ? 2 : 32,texptr->ppalette); } sceGuTexMode(texptr->psm,0,0,texptr->swizzledflag); sceGuTexImage(0,texptr->width,texptr->height,texptr->pitch,texptr->texvram ? texptr->texvram : texptr->texdata); dxpGraphicsData.texture = texptr; if(texptr != &dxpGraphicsData.displaybuffer[0] && texptr != &dxpGraphicsData.displaybuffer[1])texptr->reloadflag = 0; } u8 colorKey = 0,alphaEnable = 0; if(flag) { if(texptr->alphabit) alphaEnable = 1; else colorKey = 1; } if(colorKey) { GUENABLE(GU_COLOR_TEST); sceGuColorFunc(GU_NOTEQUAL,texptr->colorkey,0x00fefefe); } else { GUDISABLE(GU_COLOR_TEST); } int op; int src,dest; unsigned int srcfix; unsigned int destfix; switch(dxpGraphicsData.blendmode) { case DX_BLENDMODE_NOBLEND: op = GU_ADD; src = GU_FIX; dest = GU_FIX; srcfix = 0xffffffff; destfix = 0; if(!alphaEnable)break; case DX_BLENDMODE_ALPHA: op = GU_ADD; src = GU_SRC_ALPHA; dest = GU_ONE_MINUS_SRC_ALPHA; srcfix = 0; destfix = 0; break; case DX_BLENDMODE_ADD: op = GU_ADD; src = GU_SRC_ALPHA; dest = GU_FIX; srcfix = 0xffffffff; destfix = 0xffffffff; break; case DX_BLENDMODE_SUB: op = GU_REVERSE_SUBTRACT; src = GU_SRC_ALPHA; dest = GU_FIX; srcfix = 0xffffffff; destfix = 0xffffffff; break; case DX_BLENDMODE_MUL: op = GU_ADD; src = GU_DST_COLOR; dest = GU_FIX; srcfix = 0xffffffff; destfix = 0; break; case DX_BLENDMODE_DESTCOLOR: op = GU_ADD; src = GU_FIX; dest = GU_FIX; srcfix = 0; destfix = 0xffffffff; break; case DX_BLENDMODE_INVDESTCOLOR: op = GU_ADD; src = GU_ONE_MINUS_DST_COLOR; dest = GU_FIX; srcfix = 0; destfix = 0; break; case DX_BLENDMODE_INVSRC: op = GU_ADD; src = GU_SRC_ALPHA; dest = GU_ONE_MINUS_SRC_ALPHA; srcfix = 0; destfix = 0; break; default: return -1; } if(dxpGraphicsData.blendmode == DX_BLENDMODE_NOBLEND && !alphaEnable) { GUDISABLE(GU_BLEND); } else { GUENABLE(GU_BLEND); if(dxpGraphicsData.forceupdate || dxpGraphicsData.op != op || dxpGraphicsData.src != src || dxpGraphicsData.dest != dest || dxpGraphicsData.srcfix != srcfix || dxpGraphicsData.destfix != destfix ){ sceGuBlendFunc(op,src,dest,srcfix,destfix); dxpGraphicsData.op = op; dxpGraphicsData.src = src; dxpGraphicsData.dest = dest; dxpGraphicsData.srcfix = srcfix; dxpGraphicsData.destfix = destfix; } } if(dxpGraphicsData.forceupdate || dxpGraphicsData.color != dxpGraphicsData.gucolor) {//色を設定 sceGuColor(dxpGraphicsData.color); dxpGraphicsData.gucolor = dxpGraphicsData.color; } int tfx,tcc; switch(dxpGraphicsData.blendmode) { case DX_BLENDMODE_NOBLEND: case DX_BLENDMODE_MUL: case DX_BLENDMODE_DESTCOLOR: tcc = GU_TCC_RGB; tfx = GU_TFX_MODULATE; if(!alphaEnable) { GUDISABLE(GU_ALPHA_TEST); break; } case DX_BLENDMODE_ALPHA: case DX_BLENDMODE_ADD: case DX_BLENDMODE_SUB: case DX_BLENDMODE_INVDESTCOLOR: tcc = GU_TCC_RGBA; tfx = GU_TFX_MODULATE; GUENABLE(GU_ALPHA_TEST); sceGuAlphaFunc(GU_NOTEQUAL,0x00,0xff); break; case DX_BLENDMODE_INVSRC: sceGuTexEnvColor(0x00000000); tcc = GU_TCC_RGBA; tfx = GU_TFX_BLEND; GUDISABLE(GU_ALPHA_TEST); break; default: return -1; } if(dxpGraphicsData.forceupdate || dxpGraphicsData.tfx != tfx || dxpGraphicsData.tcc != tcc) { sceGuTexFunc(tfx,tcc); dxpGraphicsData.tfx = tfx; dxpGraphicsData.tcc = tcc; } dxpGraphicsData.forceupdate = 0; dxpGraphicsData.flag = flag; return 0; }
void update_frame_ge(void) { check_gba_video_status(); // return; // printf("video mode: %u\n", gba_video_registers->lcd_control.bg_mode); int i; palette_ram_8bit[0]=palette_ram[0]&0x7FFF; for (i=1; i<256;i++) palette_ram_8bit[i]=palette_ram[i]|0x8000; palette_ram_8bit[256]=palette_ram[256]&0x7FFF; for (i=257; i<512;i++) palette_ram_8bit[i]=palette_ram[i]|0x8000; for (i=0; i<512;i++) { if (i&0xF) palette_ram_4bit[i]=palette_ram_8bit[i]|0x8000; else palette_ram_4bit[i]=palette_ram_8bit[i]&0x7FFF; } // sceKernelDcacheWritebackAll(); // sceKernelDcacheWritebackInvalidateAll(); RETRO_PERFORMANCE_INIT(gu_sync_time); RETRO_PERFORMANCE_START(gu_sync_time); sceGuSync(0,0); RETRO_PERFORMANCE_STOP(gu_sync_time); main_context_status= sceGuGetAllStatus(); sceGeSaveContext(&main_context_buffer); sceGuSetCallback(GU_CALLBACK_FINISH, list_finish_callback); sceGuStart(GU_DIRECT, d_list); init_3Dprojection(); setup_3Dprojection_16bit(); sceGuDisable(GU_DEPTH_TEST); // sceGuDepthBuffer((void*)VRAM_DEPTH,512); sceGuDepthMask(GU_TRUE); sceGuDepthRange(0,65535); sceGuDisable(GU_CULL_FACE); sceGuDisable(GU_CLIP_PLANES); // sceGuTexFilter(GU_NEAREST,GU_NEAREST); RETRO_PERFORMANCE_INIT(gba_upload_vram_proc); RETRO_PERFORMANCE_START(gba_upload_vram_proc); gba_upload_vram(); RETRO_PERFORMANCE_STOP(gba_upload_vram_proc); // sceGuDrawBufferList(GU_PSM_5551, GBA_FRAME_TEXTURE_GU, GBA_LINE_SIZE); sceGuDrawBufferList(GU_PSM_8888, GBA_FRAME_TEXTURE_GU, GBA_LINE_SIZE); sceGuDepthBuffer(GBA_DEPTH_BUFFER, GBA_LINE_SIZE); sceGuScissor(0,0,GBA_SCREEN_WIDTH,GBA_SCREEN_HEIGHT); sceGuScissor(0,0,240,160); sceGuEnable(GU_SCISSOR_TEST); // sceGuClearColor(0x000000FF); // sceGuClearColor((palette_ram[0]&0x1F<<3)|(palette_ram[0]&0x3E0<<6)|(palette_ram[0]&0x7C00<<9)|0xFF000000); sceGuClearColor(GU_COLOR(((palette_ram[0]>> 0) & 31) / 31.0f, ((palette_ram[0]>> 5) & 31) / 31.0f, ((palette_ram[0]>>10) & 31) / 31.0f, 1.0)); sceGuClear(GU_COLOR_BUFFER_BIT); // if (gba_draw_bg[gba_video_registers->lcd_control.bg_mode]) // gba_draw_bg[gba_video_registers->lcd_control.bg_mode](); RETRO_PERFORMANCE_INIT(gba_draw_bg_mode0_proc); RETRO_PERFORMANCE_START(gba_draw_bg_mode0_proc); gba_draw_bg_mode0(); RETRO_PERFORMANCE_STOP(gba_draw_bg_mode0_proc); // sceGuFinish(); sceGuFinishId(GBA_DISPLAY_LIST_ID); // RETRO_PERFORMANCE_INIT(gu_sync_time); // RETRO_PERFORMANCE_START(gu_sync_time); // sceGuSync(0,0); // RETRO_PERFORMANCE_STOP(gu_sync_time); }
static void gba_draw_bg_mode0 (void) { // goto show_tiles; RETRO_PERFORMANCE_INIT(draw_bgs_procs); RETRO_PERFORMANCE_START(draw_bgs_procs); sceGuEnable(GU_BLEND); sceGuBlendFunc(GU_ADD,GU_SRC_ALPHA,GU_ONE_MINUS_SRC_ALPHA,0xFFFFFFFF,0xFFFFFFFF); // sceGuEnable(GU_DEPTH_TEST); sceGuDepthMask(GU_FALSE); sceGuDepthFunc(GU_GEQUAL); // sceGuDisable(GU_BLEND); //BG0 if (gba_video_registers->lcd_control.screen_display_BG3) draw_bg(&gba_video_registers->BG3_control, &gba_video_registers->BG3_scroll); if (gba_video_registers->lcd_control.screen_display_BG2) draw_bg(&gba_video_registers->BG2_control, &gba_video_registers->BG2_scroll); if (gba_video_registers->lcd_control.screen_display_BG1) draw_bg(&gba_video_registers->BG1_control, &gba_video_registers->BG1_scroll); if (gba_video_registers->lcd_control.screen_display_BG0) draw_bg(&gba_video_registers->BG0_control, &gba_video_registers->BG0_scroll); RETRO_PERFORMANCE_STOP(draw_bgs_procs); RETRO_PERFORMANCE_INIT(draw_sprites_proc); RETRO_PERFORMANCE_START(draw_sprites_proc); // draw_sprites_old(); // sceGuClutMode(GU_PSM_5551,0,0xFF,32); draw_sprites(); RETRO_PERFORMANCE_STOP(draw_sprites_proc); return; show_tiles: sceGuTexMode(GU_PSM_T16, 0, 0, GU_TRUE); sceGuClutMode(GU_PSM_5551,0,0xFF,0); sceGuClutLoad(32, palette_ram); sceGuDisable(GU_BLEND); sceGuEnable(GU_TEXTURE_2D); sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGB); // sceGuClutMode(GU_PSM_4444,0,0xFF,0); // sceGuClutLoad(32, index_copy_clut); if (show_4bit_tilemap) { sceGuTexImage(0, 256, 256, 256, ((u16*)GBA_VRAMTEXTURE_4bit) + 256 * 256 * tilemap_offset); sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, NULL,(void*)frame_256_256); } else { sceGuTexImage(0, 128, 256, 128, ((u16*)GBA_VRAMTEXTURE_8bit) + 128 * 256 * tilemap_offset); sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, NULL,(void*)frame_128_256); } }