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(); }
int main() { SceCtrlData pad; vita2d_pgf *pgf; vita2d_texture *image; float rad = 0.0f; vita2d_init(); vita2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF)); pgf = vita2d_load_default_pgf(); /* * Load the statically compiled image.png file. */ image = vita2d_load_PNG_buffer(&_binary_image_png_start); memset(&pad, 0, sizeof(pad)); while (1) { sceCtrlPeekBufferPositive(0, &pad, 1); if (pad.buttons & SCE_CTRL_START) break; vita2d_start_drawing(); vita2d_clear_screen(); vita2d_draw_rectangle(20, 20, 400, 250, RGBA8(255, 0, 0, 255)); vita2d_draw_rectangle(680, 350, 100, 150, RGBA8(0, 0, 255, 255)); vita2d_draw_fill_circle(200, 420, 100, RGBA8(0, 255,0 ,255)); vita2d_draw_texture_rotate(image, 940/2, 544/2, rad); vita2d_draw_line(500, 30, 800, 300, RGBA8(255, 0, 255, 255)); vita2d_pgf_draw_text(pgf, 700, 30, RGBA8(0,255,0,255), 1.0f, "PGF Font sample!"); vita2d_end_drawing(); vita2d_swap_buffers(); rad += 0.1f; } /* * vita2d_fini() waits until the GPU has finished rendering, * then we can free the assets freely. */ vita2d_fini(); vita2d_free_texture(image); vita2d_free_pgf(pgf); sceKernelExitProcess(0); return 0; }
int main() { vita2d_init(); vita2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF)); vita2d_pgf *pgf = vita2d_load_default_pgf(); vita2d_texture *tex = vita2d_create_empty_texture(128, 128); unsigned int *tex_data = vita2d_texture_get_datap(tex); SceCtrlData pad; memset(&pad, 0, sizeof(pad)); float rad = 0.0f; while (1) { sceCtrlPeekBufferPositive(0, &pad, 1); if (pad.buttons & SCE_CTRL_START) break; vita2d_start_drawing(); vita2d_clear_screen(); vita2d_draw_rectangle(20, 20, 400, 250, RGBA8(255, 0, 0, 255)); vita2d_draw_rectangle(680, 350, 100, 150, RGBA8(0, 0, 255, 255)); vita2d_draw_fill_circle(200, 420, 100, RGBA8(0, 255,0 ,255)); /* Fill the texture with random data */ int i, j; for (i = 0; i < 128; i++) { for (j = 0; j < 128; j++) { tex_data[j + i*128] = rand(); } } vita2d_draw_texture_rotate(tex, 940/2, 544/2, rad); vita2d_draw_line(500, 30, 800, 300, RGBA8(255, 0, 255, 255)); vita2d_pgf_draw_text(pgf, 700, 30, RGBA8(0,255,0,255), 1.0f, "PGF Font sample!"); vita2d_end_drawing(); vita2d_swap_buffers(); rad += 0.1f; } vita2d_fini(); vita2d_free_texture(tex); vita2d_free_pgf(pgf); sceKernelExitProcess(0); return 0; }
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(); }
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(); }
void show_splash() { vita2d_start_drawing(); vita2d_clear_screen(); vita2d_texture *splash = vita2d_create_empty_texture(960, 544); splash = vita2d_load_PNG_buffer(revitalize); vita2d_draw_texture(splash, 0, 0); vita2d_end_drawing(); vita2d_swap_buffers(); sceKernelDelayThread(5000000); // Delay 5 seconds vita2d_free_texture(splash); }
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); } }
int main() { SceCtrlData pad; vita2d_pgf *pgf; vita2d_texture *image; float rad = 0.0f; vita2d_init(); vita2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF)); pgf = vita2d_load_default_pgf(); image = vita2d_load_PNG_buffer(&_binary_image_png_start); memset(&pad, 0, sizeof(pad)); while (1) { sceCtrlPeekBufferPositive(0, &pad, 1); if (pad.buttons & SCE_CTRL_START) break; vita2d_start_drawing(); vita2d_clear_screen(); vita2d_draw_texture_rotate(image, 940/2, 544/2, rad); vita2d_pgf_draw_text(pgf, 50, 50, RGBA8(255,255,255,255), 1.0f, "ミクのおっぱい柔かぁい。柔軟剤使ったのか?"); vita2d_end_drawing(); vita2d_swap_buffers(); rad += 0.1f; } vita2d_fini(); vita2d_free_texture(image); vita2d_free_pgf(pgf); sceKernelExitProcess(0); return 0; }
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(); }
int main() { vita2d_init(); vita2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF)); vita2d_pgf *pgf = vita2d_load_default_pgf(); SceCtrlData pad; memset(&pad, 0, sizeof(pad)); vu_rectangle *r = vu_rectangle_new(); vu_rectangle_set_color(r, (vec4){0xFF, 0x00, 0x00, 0xFF}); vu_rectangle_resize(r, (vec2){200, 200}); while (1) { sceCtrlPeekBufferPositive(0, &pad, 1); if (pad.buttons & SCE_CTRL_START) break; vita2d_start_drawing(); vita2d_clear_screen(); vu_rectangle_render(r); vita2d_pgf_draw_text(pgf, 20, 30, RGBA8(0xFF,0xFF,0xFF,0xFF), 1.0f, "PS Vita Package Manager"); vita2d_end_drawing(); vita2d_swap_buffers(); } vita2d_free_pgf(pgf); //vita2d_fini(); crashes sceKernelExitProcess(0); return 0; }
int run_emu(char *path) { SceCtrlData pad; unsigned int joypad1, joypad2; joypad1 = joypad2 = update_input(&pad); emu->emulate_frame(joypad1, joypad2); const Nes_Emu::frame_t &frame = emu->frame(); static uint32_t video_buffer[Nes_Emu::image_width * Nes_Emu::image_height]; const uint8_t *in_pixels = frame.pixels; uint32_t *out_pixels = video_buffer; 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] = (r << 16) | (g << 8) | (b << 0); } } vita2d_start_drawing(); vita2d_clear_screen(); vita2d_end_drawing(); vita2d_swap_buffers(); return 0; }
void pspVideoEnd() { /*sceGuFinish(); sceGuSync(0, 0);*/ vita2d_end_drawing(); }
int main() { char vita_ip[16]; unsigned short int vita_port = 0; vita2d_init(); vita2d_set_clear_color(RGBA8(0x00, 0x00, 0x00, 0xFF)); clr_color = 0x000000FF; vita2d_texture* texture_splash = vita2d_load_JPEG_buffer(splash, size_splash); vita2d_start_drawing(); vita2d_draw_texture(texture_splash, 0, 0); vita2d_end_drawing(); vita2d_swap_buffers(); sceKernelDelayThread(4000000); vita2d_start_drawing(); vita2d_clear_screen(); vita2d_end_drawing(); vita2d_swap_buffers(); vita2d_free_texture(texture_splash); SceCtrlData pad; SceCtrlData oldpad; while (1) { // Load main script SceUID id = sceIoDopen("cache0:/lpp"); SceIoDirent entry; memset(&entry, 0, sizeof(SceIoDirent)); while (sceIoDread(id, &entry) > 0){ script_files++; memset(&entry, 0, sizeof(SceIoDirent)); } sceIoDclose(id); if (script_files>1) errMsg = runScript((const char*)main_menu, true); else{ SceUID main_file = sceIoOpen("cache0:/lpp/index.lua", PSP2_O_RDONLY, 0777); if (main_file < 0) errMsg = "index.lua not found."; else{ SceOff size = sceIoLseek(main_file, 0, SEEK_END); if (size < 1) errMsg = "Invalid main script."; else{ sceIoLseek(main_file, 0, SEEK_SET); script = (unsigned char*)malloc(size + 1); sceIoRead(main_file, script, size); script[size] = 0; sceIoClose(main_file); errMsg = runScript((const char*)script, true); free(script); } } } if (errMsg != NULL){ if (strstr(errMsg, "lpp_shutdown")) break; else{ int restore = 0; bool s = true; while (restore == 0){ vita2d_start_drawing(); vita2d_clear_screen(); font_draw_string(10, 10, RGBA8(255, 255, 255, 255), "An error occurred:"); font_draw_string(10, 30, RGBA8(255, 255, 255, 255), errMsg); font_draw_string(10, 70, RGBA8(255, 255, 255, 255), "Press X to restart."); font_draw_string(10, 90, RGBA8(255, 255, 255, 255), "Press O to enable/disable FTP."); if (vita_port != 0){ font_draw_stringf(10, 150, RGBA8(255, 255, 255, 255), "PSVITA listening on IP %s , Port %u", vita_ip, vita_port); } vita2d_end_drawing(); vita2d_swap_buffers(); if (s){ sceKernelDelayThread(800000); s = false; } sceCtrlPeekBufferPositive(0, &pad, 1); if (pad.buttons & PSP2_CTRL_CROSS) { errMsg = NULL; restore = 1; if (vita_port != 0){ ftp_fini(); vita_port = 0; } sceKernelDelayThread(800000); }else if ((pad.buttons & PSP2_CTRL_CIRCLE) && (!(oldpad.buttons & PSP2_CTRL_CIRCLE))){ if (vita_port == 0) ftp_init(vita_ip, &vita_port); else{ ftp_fini(); vita_port = 0; } } oldpad = pad; } } } } vita2d_fini(); sceKernelExitProcess(0); return 0; }
int file_choose(const char *start_path, char *chosen_file, const char *title, const char *supported_ext[]) { SceCtrlData pad, old_pad; unsigned int keys_down; int i; int selected = 0; char cur_path[PATH_MAX]; pad.buttons = old_pad.buttons = 0; strcpy(cur_path, start_path); file_list list; file_list_entry *entry; file_list_build(cur_path, &list, supported_ext); while (1) { sceCtrlPeekBufferPositive(0, &pad, 1); if (pad.buttons & PSP2_CTRL_SELECT) break; keys_down = pad.buttons & ~old_pad.buttons; if (keys_down & PSP2_CTRL_UP) { selected--; if (selected < 0) { selected = list.length - 1; } } else if (keys_down & PSP2_CTRL_DOWN) { selected++; if (selected == list.length) { selected = 0; } } if (keys_down & (PSP2_CTRL_CROSS | PSP2_CTRL_START)) { file_list_entry *entry = file_list_get_nth_entry(&list, selected); if (entry->is_dir) { if (strcmp(entry->name, "..") == 0) { dir_up(cur_path); } else { char new_path[PATH_MAX]; sprintf(new_path, "%s/%s", cur_path, entry->name); strcpy(cur_path, new_path); } file_list_empty(&list); file_list_build(cur_path, &list, supported_ext); selected = 0; } else if (entry->supported) { sprintf(chosen_file, "%s/%s", cur_path, entry->name); file_list_empty(&list); return 1; } } else if (keys_down & PSP2_CTRL_CIRCLE) { dir_up(cur_path); file_list_empty(&list); file_list_build(cur_path, &list, supported_ext); selected = 0; } vita2d_start_drawing(); vita2d_clear_screen(); font_draw_stringf(10, 10, WHITE, title); entry = list.head; for (i = 0; i < list.length; i++) { font_draw_stringf( 10, 40 + i*20, (!entry->is_dir && entry->supported) ? GREEN : WHITE, "%s %s", (selected == i) ? ">" : "", entry->name); entry = entry->next; } old_pad = pad; vita2d_end_drawing(); vita2d_swap_buffers(); } return 0; }
void MOD_SelectModMenu(char *basedir){ SceCtrlData pad, oldpad; sceCtrlPeekBufferPositive(0, &pad, 1); // Ch0wW: Enable the mod menu once the R trigger is hold on startup. if (!(pad.buttons & SCE_CTRL_RTRIGGER)) { // Reading current used mod char cur_mod[64]; modname = malloc(64); FILE* f; if ((f = fopen( va("%s/%s", basedir, MOD_FILE), "r")) != NULL) { char tmp[256]; fseek(f, 0, SEEK_END); int len = ftell(f); fseek(f, 0, SEEK_SET); fread(tmp, 1, len, f); fclose(f); tmp[len] = 0; sprintf(modname, "%s", tmp); } else modname = NULL; return; } // Initializing empty ModList ModsList* mods = NULL; int i = 0; int max_idx = -1; // Scanning main folder in search of mods int dd = sceIoDopen(basedir); SceIoDirent entry; int res; while (sceIoDread(dd, &entry) > 0){ if (SCE_S_ISDIR(entry.d_stat.st_mode)){ if (CheckForMod( va("%s/%s", basedir, entry.d_name))){ mods = addMod(entry.d_name, mods); max_idx++; } } } sceIoDclose(dd); // Reading current used mod char cur_mod[64]; modname = malloc(64); FILE* f; if ((f = fopen(va("%s/%s", basedir, MOD_FILE), "r")) != NULL) { char tmp[256]; fseek(f, 0, SEEK_END); int len = ftell(f); fseek(f, 0, SEEK_SET); fread(tmp, 1, len, f); fclose(f); tmp[len] = 0; sprintf(modname, "%s", tmp); sprintf(cur_mod, "Current in use mod: %s - Press START to launch vitaQuake core", tmp); }else strcpy(cur_mod,"Current in use mod: id1 - Press START to launch vitaQuake core"); // Initializing graphics stuffs vita2d_set_clear_color(RGBA8(0x00, 0x00, 0x00, 0xFF)); vita2d_pgf* debug_font = vita2d_load_default_pgf(); uint32_t white = RGBA8(0xFF, 0xFF, 0xFF, 0xFF); uint32_t green = RGBA8(0x00, 0xFF, 0x00, 0xFF); uint32_t red = RGBA8(0xFF, 0x00, 0x00, 0xFF); // Main loop while (max_idx >= 0){ vita2d_start_drawing(); vita2d_clear_screen(); vita2d_pgf_draw_text(debug_font, 2, 20, red, 1.0, cur_mod); // Drawing menu int y = 40; int d = 0; ModsList* ptr = mods; while (ptr != NULL && y < 540){ uint32_t color = white; if (d++ == i) color = green; vita2d_pgf_draw_text(debug_font, 2, y, color, 1.0, ptr->name); ptr = ptr->next; y += 20; } // Controls checking sceCtrlPeekBufferPositive(0, &pad, 1); if ((pad.buttons & SCE_CTRL_CROSS) && (!(oldpad.buttons & SCE_CTRL_CROSS))){ int z = 0; ModsList* tmp = mods; while (z < i){ tmp = tmp->next; z++; } sprintf(cur_mod,"Current in use mod: %s - Press START to launch vitaQuake core", tmp->name); if (!strcmp(tmp->name, "id1")) { sceIoRemove( va("%s/%s", basedir, MOD_FILE) ); modname = NULL; } else{ f = fopen(va("%s/%s", basedir, MOD_FILE), "w"); fwrite(tmp->name,1,strlen(tmp->name),f); fclose(f); strcpy(modname, tmp->name); // Refresh the mod directory. } }else if ((pad.buttons & SCE_CTRL_UP) && (!(oldpad.buttons & SCE_CTRL_UP))){ i--; if (i < 0) i = max_idx; }else if ((pad.buttons & SCE_CTRL_DOWN) && (!(oldpad.buttons & SCE_CTRL_DOWN))){ i++; if (i > max_idx) i = 0; }else if (pad.buttons & SCE_CTRL_START) break; oldpad = pad; vita2d_end_drawing(); vita2d_wait_rendering_done(); vita2d_swap_buffers(); } // Freeing stuffs ModsList* tmp = mods; ModsList* tmp2; while (tmp != NULL){ tmp2 = tmp->next; free(tmp); tmp = tmp2; } return; }
/* Programme "Flocon de Koch" */ int main(int argc, char *argv[]) { struct parameters parameters; struct list *koch = NULL; uint32_t *picture = NULL; char *outfile = NULL; bool screenshots = false; srand(time(NULL)); #ifdef PSP2 vita2d_init(); vita2d_set_clear_color(RGBA8(0, 0, 0, 0xFF)); vita2d_texture *tex = vita2d_create_empty_texture(960, 544); uint32_t *tex_data = vita2d_texture_get_datap(tex); SceCtrlData pad, lastbuttons; memset(&pad, 0, sizeof(pad)); #endif /* Initialisations */ init_parameters(¶meters, argc, argv); show_parameters(parameters); init_koch(&koch, parameters.image_size, parameters.segment_length); outfile = malloc(3 + strlen(parameters.outfile) + 1); int32_t i = 0, step = 1; bool done = false; /* Génération de chaque flocon */ while (!done) { #ifdef PSP2 lastbuttons = pad; sceCtrlPeekBufferPositive(0, &pad, 1); if (pad.buttons & PSP2_CTRL_TRIANGLE) break; if (PRESSED(lastbuttons.buttons, pad.buttons, PSP2_CTRL_LTRIGGER)) parameters.fg_color = RGBA8(rand()%255, rand()%255, rand()%255, 255); //if (PRESSED(lastbuttons.buttons, pad.buttons, PSP2_CTRL_RTRIGGER)) // screenshots ^= 1; vita2d_start_drawing(); vita2d_clear_screen(); #endif sprintf(outfile, "%02d_%s", i, parameters.outfile); if (step > 0) generer_koch(koch, i); else { for (uint32_t j = 0; j < i; j++) generer_koch(koch, j); } //show_koch_list(koch); /* Ne générer l'image que si c'est la dernière ou qu'on les génère toutes */ if (parameters.all_images || i == parameters.nb_iterations) { init_picture(&picture, parameters.image_size, parameters.bg_color); render_image_bresenham(picture, koch, parameters.image_size, parameters.fg_color); #ifndef PSP2 const uint32_t LEN = 960 * 544; uint32_t *data = calloc(LEN, sizeof(uint32_t)); for (uint32_t i = 0; i < LEN; i++) data[i] = 0; uint32_t k = 0; for (uint32_t i = 0; i < 544; i++) for (uint32_t j = 0; j < 960; j++) { if (208 <= j && j < 752 && k < 544*544) data[i * 960 + j] = picture[k++]; else data[i * 960 + j] = 0; } create_image(data, 960, 544, outfile); //create_image(picture, parameters.image_size, parameters.image_size, outfile); #else uint32_t k = 0; for (uint32_t i = 0; i < 544; i++) for (uint32_t j = 0; j < 960; j++) { if (208 <= j && j < 752 && k < 544*544) tex_data[i * 960 + j] = picture[k++]; else tex_data[i * 960 + j] = 0; } if (screenshots) create_image(tex_data, 960, 544, outfile); #endif } #ifdef PSP2 vita2d_draw_texture(tex, 0, 0); vita2d_end_drawing(); vita2d_swap_buffers(); sceKernelDelayThread(100000); #endif i = i + step; if (i == parameters.nb_iterations) #ifdef PSP2 i--, step = -1; #else done = true; #endif else if (i == 0) { step = 1; free_koch(koch); init_koch(&koch, parameters.image_size, parameters.segment_length); } if (step < 0) { free_koch(koch); init_koch(&koch, parameters.image_size, parameters.segment_length); } if (parameters.nb_iterations == 1) done = true; }
int file_choose(const char *start_path, char *chosen_file, const char *title, const char *supported_ext[]) { SceCtrlData pad, old_pad; unsigned int keys_down; int i; int selected = 0; char cur_path[PATH_MAX]; pad.buttons = old_pad.buttons = 0; strcpy(cur_path, start_path); file_list list; file_list_entry *entry; file_list_build(cur_path, &list, supported_ext); while (1) { sceCtrlPeekBufferPositive(0, &pad, 1); if (pad.buttons & SCE_CTRL_SELECT) break; keys_down = pad.buttons & ~old_pad.buttons; if (keys_down & SCE_CTRL_UP) { selected--; if (selected < list.scroll) { list.scroll--; } if (selected < 0) { selected = list.length - 1; list.scroll = max(0, list.length - LIST_MAX_ONSCREEN); } } else if (keys_down & SCE_CTRL_DOWN) { selected++; if (selected == list.scroll + LIST_MAX_ONSCREEN) { list.scroll++; } if (selected == list.length) { selected = 0; list.scroll = 0; } } if (keys_down & (SCE_CTRL_CROSS | SCE_CTRL_START)) { file_list_entry *entry = file_list_get_nth_entry(&list, selected); if (entry->is_dir) { if (strcmp(entry->name, "..") == 0) { dir_up(cur_path); } else { char new_path[PATH_MAX]; // no valid elf with new toolchain with sprintf(new_path, "%s/%s", cur_path, entry->name); sceClibSnprintf(new_path, PATH_MAX, "%s/%s", cur_path, entry->name); strcpy(cur_path, new_path); } file_list_empty(&list); file_list_build(cur_path, &list, supported_ext); selected = 0; } else if (entry->supported) { // no valid elf with new toolchain with sprintfsprintf(chosen_file, "%s/%s", cur_path, entry->name); sceClibSnprintf(chosen_file,PATH_MAX, "%s/%s", cur_path, entry->name); file_list_empty(&list); return 1; } } else if (keys_down & SCE_CTRL_CIRCLE) { dir_up(cur_path); file_list_empty(&list); file_list_build(cur_path, &list, supported_ext); selected = 0; } vita2d_start_drawing(); vita2d_clear_screen(); font_draw_stringf(10, 10, WHITE, title); entry = file_list_get_nth_entry(&list, list.scroll); for (i = list.scroll; i < min(list.length, list.scroll + LIST_MAX_ONSCREEN); i++) { font_draw_stringf( 10, 40 + (i - list.scroll)*20, (!entry->is_dir && entry->supported) ? GREEN : WHITE, "%s %s", (selected == i) ? ">" : "", entry->name); entry = entry->next; } old_pad = pad; vita2d_end_drawing(); vita2d_swap_buffers(); } return 0; }
/*** * 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, 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; }
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; }