int main(int argc, char *argv[]) { wchar_t **argv1 = CommandLineArgs(argc,argv); CParameter parameter; if (! parameter.CommandLine (argc, argv1)) { return 4; } if (parameter.Sis().empty()) { cleanup(argc,argv1); return 0; } ERR_load_crypto_strings (); OpenSSL_add_all_algorithms (); OpenSSL_add_all_ciphers (); OpenSSL_add_all_digests (); int retValue = 0; try { bool isSisFile = CSISContents::IsSisFile(parameter.Sis ()); if(isSisFile) { CSISContents content; content.Load (parameter.Sis ()); CSignSis signsis(parameter.Sis ()); if (parameter.Sign ()) { if (parameter.Verbose ()) { std::cout << "Signing" << std::endl; } signsis.SignSis(parameter.Output (), parameter.Certificate(), parameter.Key(), parameter.PassPhrase(), parameter.Algorithm()); } if (parameter.Unsign ()) { if (parameter.Verbose ()) { std::cout << "Removing signature" << std::endl; } signsis.RemoveSignature (parameter.Output ()); } if (parameter.Report() || parameter.ExtractCert()) { ReportSignatures(content.Controller(), parameter.ExtractCert()); } if (parameter.Dump ()) { content.Dump (std::cout, 0); } } else { if (parameter.Report ()||parameter.ExtractCert()) { std::cout<<"Reporting Stub Sis Controller"<<std::endl; CSISController ctrl; ctrl.Load (parameter.Sis ()); ReportSignatures(ctrl, parameter.ExtractCert()); } } } catch(const CSISException& oops) { std::wcout << oops.widewhat () << std::endl; retValue = 1; } catch (...) { std::wcout << L"Unexpected error." << std::endl; retValue = 1; } EVP_cleanup (); ERR_free_strings (); // cleanup the memory cleanup(argc,argv1); return retValue; }
// Main function int main(int argc, char **argv) { SDL_Joystick *joy; SDL_Event event; // Process arguments printf("%s\n\n", AppName); PokeMini_InitDirs(argv[0], NULL); CommandLineInit(); CommandLineConfFile("pokemini.cfg", NULL, NULL); if (!CommandLineArgs(argc, argv, NULL)) { PrintHelpUsage(stdout); return 1; } JoystickSetup("WIZ", 0, 0, WIZ_KeysNames, 16, WIZ_KeysMapping); // Initialize SDL if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0) { fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); exit(1); } joy = SDL_JoystickOpen(0); atexit(SDL_Quit); // Clean up on exit // Set video spec and check if is supported if (!PokeMini_SetVideo((TPokeMini_VideoSpec *)&PokeMini_Video3x3, 16, CommandLine.lcdfilter, CommandLine.lcdmode)) { fprintf(stderr, "Couldn't set video spec\n"); exit(1); } UIMenu_SetDisplay(288, 192, PokeMini_BGR16, (uint8_t *)PokeMini_BG3, (uint16_t *)PokeMini_BG3_PalBGR16, (uint32_t *)PokeMini_BG3_PalBGR32); // Initialize the display screen = SDL_SetVideoMode(320, 240, 16, SDL_SWSURFACE); // SDL_HWSURFACE | SDL_DOUBLEBUF if (screen == NULL) { fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError()); exit(1); } PixPitch = screen->pitch / 2; ScOffP = (24 * PixPitch) + 16; // Initialize the sound SDL_AudioSpec audfmt; audfmt.freq = 44100; audfmt.format = AUDIO_U8; audfmt.channels = 1; audfmt.samples = SOUNDBUFFER; audfmt.callback = emulatorsound; audfmt.userdata = NULL; // Open the audio device if (SDL_OpenAudio(&audfmt, NULL) < 0) { fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError()); fprintf(stderr, "Audio will be disabled\n"); AudioEnabled = 0; } else { AudioEnabled = 1; } // Disable key repeat and hide cursor SDL_EnableKeyRepeat(0, 0); SDL_ShowCursor(SDL_DISABLE); // Initialize the emulator printf("Starting emulator...\n"); if (!PokeMini_Create(0, PMSOUNDBUFF)) { fprintf(stderr, "Error while initializing emulator.\n"); } // Setup palette and LCD mode PokeMini_VideoPalette_Init(PokeMini_BGR16, 1); PokeMini_VideoPalette_Index(CommandLine.palette, CommandLine.custompal, CommandLine.lcdcontrast, CommandLine.lcdbright); PokeMini_ApplyChanges(); // Load stuff PokeMini_UseDefaultCallbacks(); if (!PokeMini_LoadFromCommandLines("Using FreeBIOS", "EEPROM data will be discarded!")) { UI_Status = UI_STATUS_MENU; } // Enable sound & init UI printf("Starting emulator...\n"); UIMenu_Init(); enablesound(CommandLine.sound); // Emulator's loop unsigned long time, NewTickSync = 0; while (emurunning) { // Emulate and syncronize if (RequireSoundSync) { PokeMini_EmulateFrame(); // Sleep a little in the hope to free a few samples while (MinxAudio_SyncWithAudio()) SDL_Delay(1); } else { time = SDL_GetTicks(); PokeMini_EmulateFrame(); do { SDL_Delay(1); // This lower CPU usage time = SDL_GetTicks(); } while (time < NewTickSync); NewTickSync = time + 13; // Aprox 72 times per sec } // Screen rendering SDL_FillRect(screen, NULL, 0); if (SDL_LockSurface(screen) == 0) { // Render the menu or the game screen if (PokeMini_Rumbling) { PokeMini_VideoBlit((uint16_t *)screen->pixels + ScOffP + PokeMini_GenRumbleOffset(PixPitch), PixPitch); } else { PokeMini_VideoBlit((uint16_t *)screen->pixels + ScOffP, PixPitch); } LCDDirty = 0; // Unlock surface SDL_UnlockSurface(screen); SDL_Flip(screen); } // Handle events while (SDL_PollEvent(&event)) handleevents(&event); // Menu if (UI_Status == UI_STATUS_MENU) menuloop(); } // Disable sound & free UI enablesound(0); UIMenu_Destroy(); // Save Stuff PokeMini_SaveFromCommandLines(1); // Close joystick if (joy) SDL_JoystickClose(joy); // Terminate... printf("Shutdown emulator...\n"); PokeMini_VideoPalette_Free(); PokeMini_Destroy(); return 0; }