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; }
vector<string> GetAllLinesFromFile(string filename) { ifstream freader(filename.c_str()); vector<string> lines; if(!freader.fail()) { while(!freader.eof()) { string new_line; getline(freader, new_line); if(new_line != "") lines.push_back(new_line); } } return lines; }
/** * Read a file to detect the type. * @param aFile - open file to be read. File pointer will be closed. * @param aFileName - file name to be read * @param aName - wxString to receive the module name iff type is LEGACY */ static IO_MGR::PCB_FILE_T detect_file_type( FILE* aFile, const wxFileName& aFileName, wxString* aName ) { FILE_LINE_READER freader( aFile, aFileName.GetFullPath() ); WHITESPACE_FILTER_READER reader( freader ); IO_MGR::PCB_FILE_T file_type; wxASSERT( aName ); reader.ReadLine(); char* line = reader.Line(); if( !strncasecmp( line, "(module", strlen( "(module" ) ) ) { file_type = IO_MGR::KICAD_SEXP; *aName = aFileName.GetName(); } else if( !strncasecmp( line, FOOTPRINT_LIBRARY_HEADER, FOOTPRINT_LIBRARY_HEADER_CNT ) ) { file_type = IO_MGR::LEGACY; while( reader.ReadLine() ) { if( !strncasecmp( line, "$MODULE", strlen( "$MODULE" ) ) ) { *aName = FROM_UTF8( StrPurge( line + strlen( "$MODULE" ) ) ); break; } } } else if( !strncasecmp( line, "Element", strlen( "Element" ) ) ) { file_type = IO_MGR::GEDA_PCB; *aName = aFileName.GetName(); } else { file_type = IO_MGR::FILE_TYPE_NONE; } return file_type; }
MODULE* FOOTPRINT_EDIT_FRAME::Import_Module() { // use the clipboard for this in the future? // Some day it might be useful save the last library type selected along with the path. static int lastFilterIndex = 0; wxString lastOpenedPathForLoading = m_mruPath; wxConfigBase* config = Kiface().KifaceSettings(); if( config ) config->Read( EXPORT_IMPORT_LASTPATH_KEY, &lastOpenedPathForLoading ); wxString wildCard; wildCard << wxGetTranslation( KiCadFootprintLibFileWildcard ) << wxChar( '|' ) << wxGetTranslation( ModLegacyExportFileWildcard ) << wxChar( '|' ) << wxGetTranslation( ModImportFileWildcard ) << wxChar( '|' ) << wxGetTranslation( GedaPcbFootprintLibFileWildcard ); wxFileDialog dlg( this, FMT_IMPORT_MODULE, lastOpenedPathForLoading, wxEmptyString, wildCard, wxFD_OPEN | wxFD_FILE_MUST_EXIST ); dlg.SetFilterIndex( lastFilterIndex ); if( dlg.ShowModal() == wxID_CANCEL ) return NULL; lastFilterIndex = dlg.GetFilterIndex(); FILE* fp = wxFopen( dlg.GetPath(), wxT( "rt" ) ); if( !fp ) { wxString msg = wxString::Format( FMT_FILE_NOT_FOUND, GetChars( dlg.GetPath() ) ); DisplayError( this, msg ); return NULL; } if( config ) // Save file path { lastOpenedPathForLoading = wxPathOnly( dlg.GetPath() ); config->Write( EXPORT_IMPORT_LASTPATH_KEY, lastOpenedPathForLoading ); } wxString moduleName; bool isGeda = false; bool isLegacy = false; { FILE_LINE_READER freader( fp, dlg.GetPath() ); // I own fp, and will close it. WHITESPACE_FILTER_READER reader( freader ); // skip blank lines reader.ReadLine(); char* line = reader.Line(); if( !strnicmp( line, "(module", 7 ) ) { // isKicad = true; } else if( !strnicmp( line, FOOTPRINT_LIBRARY_HEADER, FOOTPRINT_LIBRARY_HEADER_CNT ) ) { isLegacy = true; while( reader.ReadLine() ) { if( !strnicmp( line, "$MODULE", 7 ) ) { moduleName = FROM_UTF8( StrPurge( line + sizeof( "$MODULE" ) -1 ) ); break; } } } else if( !strnicmp( line, "Element", 7 ) ) { isGeda = true; } else { DisplayError( this, FMT_NOT_MODULE ); return NULL; } // fp is closed here by ~FILE_LINE_READER() } MODULE* module; if( isGeda ) { try { wxFileName fn = dlg.GetPath(); PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::GEDA_PCB ) ); moduleName = fn.GetName(); module = pi->FootprintLoad( fn.GetPath(), moduleName ); if( !module ) { wxString msg = wxString::Format( FMT_MOD_NOT_FOUND, GetChars( moduleName ), GetChars( fn.GetPath() ) ); DisplayError( this, msg ); return NULL; } } catch( const IO_ERROR& ioe ) { DisplayError( this, ioe.errorText ); return NULL; } } else if( isLegacy ) { try { PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) ); module = pi->FootprintLoad( dlg.GetPath(), moduleName ); if( !module ) { wxString msg = wxString::Format( FMT_MOD_NOT_FOUND, GetChars( moduleName ), GetChars( dlg.GetPath() ) ); DisplayError( this, msg ); return NULL; } } catch( const IO_ERROR& ioe ) { DisplayError( this, ioe.errorText ); return NULL; } } else // if( isKicad ) { try { // This technique was chosen to create an example of how reading // the s-expression format from clipboard could be done. wxString fcontents; PCB_IO pcb_io; wxFFile f( dlg.GetPath() ); if( !f.IsOpened() ) { wxString msg = wxString::Format( FMT_BAD_PATH, GetChars( dlg.GetPath() ) ); DisplayError( this, msg ); return NULL; } f.ReadAll( &fcontents ); module = dyn_cast<MODULE*>( pcb_io.Parse( fcontents ) ); if( !module ) { wxString msg = wxString::Format( FMT_BAD_PATH, GetChars( dlg.GetPath() ) ); DisplayError( this, msg ); return NULL; } } catch( const IO_ERROR& ioe ) { DisplayError( this, ioe.errorText ); return NULL; } } // Insert footprint in list GetBoard()->Add( module ); // Display info : SetMsgPanel( module ); PlaceModule( module, NULL ); if( IsGalCanvasActive() ) module->SetPosition( wxPoint( 0, 0 ) ); GetBoard()->m_Status_Pcb = 0; GetBoard()->BuildListOfNets(); updateView(); return module; }