int run_emu(const char *path) { SceCtrlData pad; unsigned int joypad1, joypad2; setup_audio(); emu->set_sample_rate(44100); emu->set_equalizer(Nes_Emu::nes_eq); emu->set_palette_range(0); vita2d_texture *tex = vita2d_create_empty_texture(Nes_Emu::image_width, Nes_Emu::image_height); void *tex_data = vita2d_texture_get_datap(tex); static uint32_t video_buffer[Nes_Emu::image_width * Nes_Emu::image_height]; emu->set_pixels(video_buffer, Nes_Emu::image_width); Auto_File_Reader freader(path); emu->load_ines(freader); int scale = 2; int pos_x = SCREEN_W/2 - (Nes_Emu::image_width/2)*scale; int pos_y = SCREEN_H/2 - (Nes_Emu::image_height/2)*scale; while (1) { sceCtrlPeekBufferPositive(0, &pad, 1); if ((pad.buttons & CHANGE_GAME_MASK) == CHANGE_GAME_MASK) break; joypad1 = joypad2 = update_input(&pad); emu->emulate_frame(joypad1, joypad2); const Nes_Emu::frame_t &frame = emu->frame(); const uint8_t *in_pixels = frame.pixels; uint32_t *out_pixels = (uint32_t *)tex_data; for (unsigned h = 0; h < Nes_Emu::image_height; h++, in_pixels += frame.pitch, out_pixels += Nes_Emu::image_width) { for (unsigned w = 0; w < Nes_Emu::image_width; w++) { unsigned col = frame.palette[in_pixels[w]]; const Nes_Emu::rgb_t& rgb = emu->nes_colors[col]; unsigned r = rgb.red; unsigned g = rgb.green; unsigned b = rgb.blue; out_pixels[w] = 0xFF000000 | (r << 0) | (g << 8) | (b << 16); } } vita2d_start_drawing(); vita2d_clear_screen(); vita2d_draw_texture_scale(tex, pos_x, pos_y, scale, scale); show_fps(); vita2d_end_drawing(); vita2d_swap_buffers(); } return 0; }
void video_DrawFrame(){ uint16_t *src = (uint16_t *)GPU->GetDisplayInfo().masterNativeBuffer; vita2d_start_drawing(); vita2d_clear_screen(); memcpy(data, src, sizeof(uint16_t) * 256 * 192 * 2); switch(video_layout){ case LAYOUT_PORTRAIT: vita2d_draw_texture_scale_rotate(fb, PORTRAIT_X, PORTRAIT_Y, 2, 2, PI/2); break; case LAYOUT_SBS: vita2d_draw_texture_part_scale(fb, 0, SBS_Y, 0, 0, 256, 192, SBS_SCALE, SBS_SCALE); vita2d_draw_texture_part_scale(fb, SBS_X, SBS_Y, 0, 192, 256, 192, SBS_SCALE, SBS_SCALE); break; case LAYOUT_LANDSCAPE: default: vita2d_draw_texture_scale(fb, LANDSCAPE_X, LANDSCAPE_Y, LANDSCAPE_SCALE, LANDSCAPE_SCALE); break; } vita2d_draw_rectangle(930,514,30,30,RGBA8(30,30,30,255)); vita2d_end_drawing(); vita2d_swap_buffers(); }
void Psp2Ui::UpdateDisplay() { vita2d_start_drawing(); vita2d_clear_screen(); switch (zoom_state){ case 0: // 640x480 vita2d_draw_texture_scale(main_texture, 160, 32, 2.0, 2.0); break; case 1: // 725x544 vita2d_draw_texture_scale(main_texture, 117, 0, 2.266, 2.266); break; case 2: // 960x544 vita2d_draw_texture_scale(main_texture, 0, 0, 3, 2.266); break; } vita2d_end_drawing(); vita2d_wait_rendering_done(); vita2d_swap_buffers(); }
static int renderThread(unsigned int args, void* arg){ for (;;){ sceKernelWaitSema(GPU_Mutex, 1, NULL); memcpy(vita2d_texture_get_datap(gpu_texture), vita2d_texture_get_datap(next_texture), vita2d_texture_get_stride(gpu_texture)*240); sceKernelSignalSema(GPU_Mutex, 1); sceKernelWaitSema(GPU_Cleanup_Mutex, 1, NULL); if (main_texture == NULL) sceKernelExitDeleteThread(0); // Exit procedure vita2d_start_drawing(); if (set_shader){ Output::Post("Shader set to %s.",shader_names[in_use_shader]); set_shader = false; vita2d_texture_set_program(shaders[in_use_shader]->vertexProgram, shaders[in_use_shader]->fragmentProgram); vita2d_texture_set_wvp(shaders[in_use_shader]->wvpParam); vita2d_texture_set_vertexInput(&shaders[in_use_shader]->vertexInput); vita2d_texture_set_fragmentInput(&shaders[in_use_shader]->fragmentInput); } vita2d_clear_screen(); switch (zoom_state){ case 0: // 640x480 vita2d_draw_texture_scale(gpu_texture, 160, 32, 2.0, 2.0); break; case 1: // 725x544 vita2d_draw_texture_scale(gpu_texture, 117, 0, 2.266, 2.266); break; case 2: // 960x544 vita2d_draw_texture_scale(gpu_texture, 0, 0, 3, 2.266); break; } vita2d_end_drawing(); vita2d_wait_rendering_done(); vita2d_swap_buffers(); sceKernelSignalSema(GPU_Cleanup_Mutex, 1); } }
static void update(void) { vita2d_start_drawing(); vita2d_clear_screen(); update_input(); theGearboyCore->RunToVBlank((GB_Color *)gb_texture_pixels); if (fullscreen) { vita2d_draw_texture_scale(gb_texture, 0, 0, fullscreen_scale_x, fullscreen_scale_y); } else { vita2d_draw_texture_scale(gb_texture, gb_draw_x, gb_draw_y, scale, scale); } vita2d_end_drawing(); vita2d_swap_buffers(); }
void VID_Update (vrect_t *rects) { if (fixpalette > 0){ Cvar_SetValue ("v_gamma", fixpalette); fixpalette = 0; } vita2d_start_drawing(); vita2d_draw_texture_scale(tex_buffer, 0, 0, rend_scale, rend_scale); vita2d_end_drawing(); if (isKeyboard) vita2d_common_dialog_update(); vita2d_wait_rendering_done(); vita2d_swap_buffers(); if (vid_vsync.value) sceDisplayWaitVblankStart(); }
static bool vita2d_gfx_frame(void *data, const void *frame, unsigned width, unsigned height, uint64_t frame_count, unsigned pitch, const char *msg, video_frame_info_t *video_info) { void *tex_p; vita_video_t *vita = (vita_video_t *)data; if (frame) { if(!(vita->texture&&vita2d_texture_get_datap(vita->texture)==frame)) { unsigned i; unsigned int stride; if ((width != vita->width || height != vita->height) && vita->texture) { vita2d_free_texture(vita->texture); vita->texture = NULL; } if (!vita->texture) { RARCH_LOG("Creating texture: %ix%i\n", width, height); vita->width = width; vita->height = height; vita->texture = vita2d_create_empty_texture_format(width, height, vita->format); vita2d_texture_set_filters(vita->texture,vita->tex_filter,vita->tex_filter); } tex_p = vita2d_texture_get_datap(vita->texture); stride = vita2d_texture_get_stride(vita->texture); if (vita->format == SCE_GXM_TEXTURE_FORMAT_X8U8U8U8_1RGB) { stride /= 4; pitch /= 4; uint32_t *tex32 = tex_p; const uint32_t *frame32 = frame; for (i = 0; i < height; i++) memcpy_neon(&tex32[i*stride],&frame32[i*pitch],pitch*sizeof(uint32_t)); } else { stride /= 2; pitch /= 2; uint16_t *tex16 = tex_p; const uint16_t *frame16 = frame; for (i = 0; i < height; i++) memcpy_neon(&tex16[i*stride],&frame16[i*pitch],width*sizeof(uint16_t)); } } } if (vita->should_resize) vita2d_gfx_update_viewport(vita); vita2d_start_drawing(); vita2d_draw_rectangle(0,0,PSP_FB_WIDTH,PSP_FB_HEIGHT,vita2d_get_clear_color()); if (vita->texture) { if (vita->fullscreen) vita2d_draw_texture_scale(vita->texture, 0, 0, PSP_FB_WIDTH / (float)vita->width, PSP_FB_HEIGHT / (float)vita->height); else { const float radian = 90 * 0.0174532925f; const float rad = vita->rotation * radian; float scalex = vita->vp.width / (float)vita->width; float scaley = vita->vp.height / (float)vita->height; vita2d_draw_texture_scale_rotate(vita->texture,vita->vp.x, vita->vp.y, scalex, scaley, rad); } } #ifdef HAVE_OVERLAY if (vita->overlay_enable) vita2d_render_overlay(vita); #endif if (vita->menu.active) { #ifdef HAVE_MENU menu_driver_frame(video_info); #endif if(vita->menu.texture) { if (vita->fullscreen) vita2d_draw_texture_scale(vita->menu.texture, 0, 0, PSP_FB_WIDTH / (float)vita->menu.width, PSP_FB_HEIGHT / (float)vita->menu.height); else { if (vita->menu.width > vita->menu.height) { float scale = PSP_FB_HEIGHT / (float)vita->menu.height; float w = vita->menu.width * scale; vita2d_draw_texture_scale(vita->menu.texture, PSP_FB_WIDTH / 2.0f - w/2.0f, 0.0f, scale, scale); } else { float scale = PSP_FB_WIDTH / (float)vita->menu.width; float h = vita->menu.height * scale; vita2d_draw_texture_scale(vita->menu.texture, 0.0f, PSP_FB_HEIGHT / 2.0f - h/2.0f, scale, scale); } } } } if(!string_is_empty(msg)) font_driver_render_msg(video_info, NULL, msg, NULL); vita2d_end_drawing(); vita2d_swap_buffers(); return true; }
/*** * Callback for when a new frame is generated that we need to render. */ bool retro_video_refresh_callback(const void *data, unsigned width, unsigned height, size_t pitch) { curr_frame++; // initialize our main render texture once we get the dimensions for the first time if (!tex) { tex = vita2d_create_empty_texture_format(width, height, SCE_GXM_TEXTURE_FORMAT_R5G6B5); tex_data = vita2d_texture_get_datap(tex); // initialize PSPImage if (Screen) free(Screen); int size = width * height * 2; Screen = (PspImage*)malloc(sizeof(PspImage)); Screen->TextureFormat = SCE_GXM_TEXTURE_FORMAT_R5G6B5; Screen->PalSize = (unsigned short)0; memset(tex_data, 0, size); Screen->Width = width; Screen->Height = height; Screen->Pixels = tex_data; Screen->Texture = tex; Screen->Viewport.X = 0; Screen->Viewport.Y = 0; Screen->Viewport.Width = width; Screen->Viewport.Height = height; int i; for (i = 1; i < width; i *= 2); Screen->PowerOfTwo = (i == width); Screen->BytesPerPixel = 2; Screen->FreeBuffer = 0; Screen->Depth = 16; } // initialize our render variables if they're uninitalized, or // if they've changed due to user action if(OptionsChanged) { OptionsChanged = false; // handle changes to scale from the options switch (Options.DisplayMode) { case DISPLAY_MODE_UNSCALED: scale_x = 1.0f; scale_y = 1.0f; break; case DISPLAY_MODE_2X: scale_x = 2.0f; scale_y = 2.0f; break; case DISPLAY_MODE_FIT_HEIGHT: scale_y = (float)SCREEN_H / (float)height; scale_x = scale_y; break; case DISPLAY_MODE_FILL_SCREEN: scale_x = (float)SCREEN_W / (float)width; scale_y = (float)SCREEN_H / (float)height; break; } curr_frame = 0; curr_fps = 0.0f; pos_x = (SCREEN_W / 2) - (width / 2) * scale_x; pos_y = (SCREEN_H / 2) - (height / 2) * scale_y; // handle texture filtering options tex_filter = Options.TextureFilter ? SCE_GXM_TEXTURE_FILTER_LINEAR : SCE_GXM_TEXTURE_FILTER_POINT; sceGxmTextureSetMinFilter(&(tex->gxm_tex), tex_filter); sceGxmTextureSetMagFilter(&(tex->gxm_tex), tex_filter); } // copy the input pixels into the output buffer const uint16_t* in_pixels = (const uint16_t*)data; uint16_t *out_pixels = (uint16_t *)tex_data; for (h = 0; h < height; h++, in_pixels += pitch / 2, out_pixels += width) { memcpy(out_pixels, in_pixels, width * sizeof(uint16_t)); } // draw the screen vita2d_start_drawing(); vita2d_draw_texture_scale(tex, pos_x, pos_y, scale_x, scale_y); if(Options.ShowFps) show_fps(); vita2d_end_drawing(); vita2d_swap_buffers(); return true; }
static bool vita2d_gfx_frame(void *data, const void *frame, unsigned width, unsigned height, uint64_t frame_count, unsigned pitch, const char *msg) { int i, j; void *tex_p; unsigned int stride; vita_video_t *vita = (vita_video_t *)data; (void)frame; (void)width; (void)height; (void)pitch; (void)msg; if (frame) { if ((width != vita->width || height != vita->height) && vita->texture) { vita2d_free_texture(vita->texture); vita->texture = NULL; } if (!vita->texture) { RARCH_LOG("Creating texture: %ix%i\n", width, height); vita->width = width; vita->height = height; vita->texture = vita2d_create_empty_texture_format(width, height, vita->format); vita2d_texture_set_filters(vita->texture,vita->tex_filter,vita->tex_filter); } tex_p = vita2d_texture_get_datap(vita->texture); stride = vita2d_texture_get_stride(vita->texture); if (vita->format == SCE_GXM_TEXTURE_FORMAT_X8U8U8U8_1RGB) { stride /= 4; pitch /= 4; uint32_t *tex32 = tex_p; const uint32_t *frame32 = frame; for (i = 0; i < height; i++) for (j = 0; j < width; j++) tex32[j + i*stride] = frame32[j + i*pitch]; } else { stride /= 2; pitch /= 2; uint16_t *tex16 = tex_p; const uint16_t *frame16 = frame; for (i = 0; i < height; i++) for (j = 0; j < width; j++) tex16[j + i*stride] = frame16[j + i*pitch]; } } if (vita->should_resize) vita2d_gfx_update_viewport(vita); vita2d_start_drawing(); vita2d_clear_screen(); if (vita->texture) { if (vita->fullscreen) vita2d_draw_texture_scale(vita->texture, 0, 0, PSP_FB_WIDTH / (float)vita->width, PSP_FB_HEIGHT / (float)vita->height); else { const float radian = 90 * 0.0174532925f; const float rad = vita->rotation * radian; float scalex = vita->vp.width / (float)vita->width; float scaley = vita->vp.height / (float)vita->height; vita2d_draw_texture_scale_rotate(vita->texture, vita->vp.x, vita->vp.y, scalex, scaley, rad); } } if (vita->menu.active && vita->menu.texture) { if (vita->fullscreen) vita2d_draw_texture_scale(vita->menu.texture, 0, 0, PSP_FB_WIDTH / (float)vita->menu.width, PSP_FB_HEIGHT / (float)vita->menu.height); else { if (vita->menu.width > vita->menu.height) { float scale = PSP_FB_HEIGHT / (float)vita->menu.height; float w = vita->menu.width * scale; vita2d_draw_texture_scale(vita->menu.texture, PSP_FB_WIDTH / 2.0f - w/2.0f, 0.0f, scale, scale); } else { float scale = PSP_FB_WIDTH / (float)vita->menu.width; float h = vita->menu.height * scale; vita2d_draw_texture_scale(vita->menu.texture, 0.0f, PSP_FB_HEIGHT / 2.0f - h/2.0f, scale, scale); } } } vita2d_end_drawing(); vita2d_swap_buffers(); return true; }