void UpdateEMUCore(Config *config) { int ntsccol, ntsctint, ntschue, flag, start, end; std::string cpalette; config->getOption("SDL.NTSCpalette", &ntsccol); config->getOption("SDL.Tint", &ntsctint); config->getOption("SDL.Hue", &ntschue); FCEUI_SetNTSCTH(ntsccol, ntsctint, ntschue); config->getOption("SDL.Palette", &cpalette); if(cpalette.size()) { LoadCPalette(cpalette); } config->getOption("SDL.PAL", &flag); FCEUI_SetVidSystem(flag ? 1 : 0); config->getOption("SDL.GameGenie", &flag); FCEUI_SetGameGenie(flag ? 1 : 0); config->getOption("SDL.Sound.LowPass", &flag); FCEUI_SetLowPass(flag ? 1 : 0); config->getOption("SDL.DisableSpriteLimit", &flag); FCEUI_DisableSpriteLimitation(flag ? 1 : 0); //Not used anymore. //config->getOption("SDL.SnapName", &flag); //FCEUI_SetSnapName(flag ? true : false); config->getOption("SDL.ScanLineStart", &start); config->getOption("SDL.ScanLineEnd", &end); #if DOING_SCANLINE_CHECKS for(int i = 0; i < 2; x++) { if(srendlinev[x]<0 || srendlinev[x]>239) srendlinev[x]=0; if(erendlinev[x]<srendlinev[x] || erendlinev[x]>239) erendlinev[x]=239; } #endif FCEUI_SetRenderedLines(start + 8, end - 8, start, end); }
void UpdateEMUCore(Config *config) { FCEUI_SetVidSystem(0); FCEUI_SetGameGenie(0); FCEUI_SetLowPass(0); FCEUI_DisableSpriteLimitation(0); int start = 0, end = 239; // TODO: tsone: can be removed? not sure what this is.. it's disabled due to #define #if DOING_SCANLINE_CHECKS for(int i = 0; i < 2; x++) { if(srendlinev[x]<0 || srendlinev[x]>239) srendlinev[x]=0; if(erendlinev[x]<srendlinev[x] || erendlinev[x]>239) erendlinev[x]=239; } #endif FCEUI_SetRenderedLines(start + 8, end - 8, start, end); }
void Ingame_Menu(void) { char *temp; int i,selection = 0; oldselect = -1; char stateoption[16]; strcpy(stateoption,"State number: "); int option_changed = 0; int menu_x1 = gsGlobal->Width*0.25; int menu_y1 = gsGlobal->Height*0.15; int menu_x2 = gsGlobal->Width*0.75; int menu_y2 = gsGlobal->Height*0.85+FONT_HEIGHT; int text_line = menu_y1 + 4; char options[14][23] = { { "State number: " }, { "Save State" }, { "Load State" }, { "Filtering: "}, { "LowPass: "******"Configure Input" }, { "Rapidfire Switch: "}, { "RapidFire P1: " }, { "RapidFire P2: " }, { "Reset Game" }, { "Exit Game" }, { "Exit Menu" }, { "Palette:" }, { "" } }; for(i=0;i<14;i++) { switch(i) { case 0: sprintf(options[i],"%s%d",options[i],statenum); break; case 3: if(!Settings.filter) sprintf(options[i],"%s%s",options[i],"Off"); else sprintf(options[i],"%s%s",options[i],"On"); break; case 4: if(!Settings.lowpass) sprintf(options[i],"%s%s",options[i],"Off"); else sprintf(options[i],"%s%s",options[i],"On"); break; case 6: if(!Settings.turbo) { sprintf(options[i],"%s%s",options[i],"Off"); } else { sprintf(options[i],"%s%s",options[i],"On"); } break; case 7: switch(aorborab[0]) { case 0: sprintf(options[i],"%s%s",options[i],"Off"); break; case 1: sprintf(options[i],"%s%s",options[i],"A"); break; case 2: sprintf(options[i],"%s%s",options[i],"B"); break; case 3: sprintf(options[i],"%s%s",options[i],"AB"); break; } break; case 8: switch(aorborab[1]) { case 0: sprintf(options[i],"%s%s",options[i],"Off"); break; case 1: sprintf(options[i],"%s%s",options[i],"A"); break; case 2: sprintf(options[i],"%s%s",options[i],"B"); break; case 3: sprintf(options[i],"%s%s",options[i],"AB"); break; } break; case 13: sprintf(options[i],"%s%s",options[i],palette_names[Settings.current_palette - 1].name); break; } } #ifdef SOUND_ON audsrv_stop_audio(); #endif gsKit_mode_switch(gsGlobal, GS_ONESHOT); gsGlobal->DrawOrder = GS_PER_OS; while(1) { selected = 0; //clear selected flag selection += menu_input(0,0); if(selection == 12 && oldselect == 11) { selection++; } //12 is palette if(selection == 12 && oldselect == 13) { selection--; } if(selection > 13) { selection = 0; } if(selection < 0) { selection = 13; } if(oldselect != selection || option_changed) { i = 0x10000; while(i--) asm("nop\nnop\nnop\nnop"); gsKit_queue_reset(gsGlobal->Os_Queue); option_changed = 0; menu_primitive("Options", &MENU_TEX, menu_x1, menu_y1, menu_x2, menu_y2); for(i=0;i<14;i++) { if(selection == i) { //font_print(gsGlobal, menu_x1+10.0f, text_line + i*FONT_HEIGHT, 2, DarkYellowFont, options[i]); printXY(options[i],menu_x1+10,text_line + i*FONT_HEIGHT, 4, FCEUSkin.highlight, 1, 0); } else { //font_print(gsGlobal, menu_x1+10.0f, text_line + i*FONT_HEIGHT, 2, WhiteFont, options[i]); printXY(options[i],menu_x1+10,text_line + i*FONT_HEIGHT, 4, FCEUSkin.textcolor, 1, 0); } } DrawScreen(gsGlobal); } oldselect = selection; if(selected) { if(selected == 2) { //menu combo pressed again selection = 11; } i = selection; switch(i) { case 0: //State Number statenum++; if(statenum > 9) {statenum = 0;} sprintf(options[i],"%s%d",stateoption,statenum); FCEUI_SelectState(statenum); option_changed = 1; break; case 1: FCEUI_SaveState(NULL); SetupNESGS(); return; case 2: FCEUI_LoadState(NULL); SetupNESGS(); return; case 3: Settings.filter ^= 1; if(Settings.filter) { temp = strstr(options[i],"Off"); *temp = 0; strcat(options[i],"On"); } else { temp = strstr(options[i],"On"); *temp = 0; strcat(options[i],"Off"); } option_changed = 1; break; case 4: Settings.lowpass ^= 1; if(Settings.lowpass) { FCEUI_SetLowPass(Settings.lowpass); temp = strstr(options[i],"Off"); *temp = 0; strcat(options[i],"On"); } else { FCEUI_SetLowPass(Settings.lowpass); temp = strstr(options[i],"On"); *temp = 0; strcat(options[i],"Off"); } option_changed = 1; break; case 6: Settings.turbo ^= 1; if(Settings.turbo) { temp = strstr(options[i],"Off"); *temp = 0; strcat(options[i],"On"); } else { temp = strstr(options[i],"On"); *temp = 0; strcat(options[i],"Off"); } option_changed = 1; break; case 7: aorborab[0]++; if(aorborab[0] > 3) aorborab[0] = 0; switch(aorborab[0]) { case 0: //Off rapidfire_a[0] = 0; rapidfire_b[0] = 0; temp = strstr(options[i],"AB"); *temp = 0; strcat(options[i],"Off"); break; case 1: //A rapidfire_a[0] = 1; rapidfire_b[0] = 0; temp = strstr(options[i],"Off"); *temp = 0; strcat(options[i],"A"); break; case 2: //B rapidfire_a[0] = 0; rapidfire_b[0] = 1; temp = strstr(options[i]," A"); *temp = 0; strcat(options[i]," B"); break; case 3: //AB rapidfire_a[0] = 1; rapidfire_b[0] = 1; temp = strstr(options[i]," B"); *temp = 0; strcat(options[i]," AB"); break; } option_changed = 1; break; case 8: aorborab[1]++; if(aorborab[1] > 3) aorborab[1] = 0; switch(aorborab[1]) { case 0: //Off rapidfire_a[1] = 0; rapidfire_b[1] = 0; temp = strstr(options[i],"AB"); *temp = 0; strcat(options[i],"Off"); break; case 1: //A rapidfire_a[1] = 1; rapidfire_b[1] = 0; temp = strstr(options[i],"Off"); *temp = 0; strcat(options[i],"A"); break; case 2: //B rapidfire_a[1] = 0; rapidfire_b[1] = 1; temp = strstr(options[i]," A"); *temp = 0; strcat(options[i]," B"); break; case 3: //AB rapidfire_a[1] = 1; rapidfire_b[1] = 1; temp = strstr(options[i]," B"); *temp = 0; strcat(options[i]," AB"); break; } option_changed = 1; break; case 9: FCEUI_ResetNES(); SetupNESGS(); return; case 10: fdsswap = 0; statenum = 0; exitgame = 1; selected = 0; return; case 11: SetupNESGS(); return; case 13: Settings.current_palette++; if(Settings.current_palette > MAXPAL) {Settings.current_palette = 1;} sprintf(options[i],"%s",palette_names[Settings.current_palette - 1].name); SetupNESTexture(); option_changed = 1; break; } } } }
int GCMemROM(int method, int size) { ResetGameLoaded(); /*** Allocate and clear GameInfo ***/ FCEUGameInfo = malloc(sizeof(FCEUGI)); memset(FCEUGameInfo, 0, sizeof(FCEUGI)); /*** Set some default values ***/ FCEUGameInfo->soundchan = 1; FCEUGameInfo->soundrate = SAMPLERATE; FCEUGameInfo->name=0; FCEUGameInfo->type=GIT_CART; FCEUGameInfo->vidsys=GIV_USER; FCEUGameInfo->input[0]=FCEUGameInfo->input[1]=-1; FCEUGameInfo->inputfc=-1; FCEUGameInfo->cspecial=0; /*** Set internal sound information ***/ FCEUI_Sound(SAMPLERATE); FCEUI_SetSoundVolume(100); // 0-100 FCEUI_SetSoundQuality(0); // 0 - low, 1 - high FCEUI_SetLowPass(0); InitialisePads(); MakeFCEUFile((char *)nesrom, size); nesGameType = 0; if(iNESLoad(NULL, fceufp)) nesGameType = 1; else if(UNIFLoad(NULL,fceufp)) nesGameType = 2; else if(NSFLoad(fceufp)) nesGameType = 3; else { // read FDS BIOS into FDSBIOS - should be 8192 bytes if(FDSBIOS[1] == 0) { int biosSize = 0; char * tmpbuffer = (char *)malloc(64 * 1024); char filepath[1024]; switch (method) { case METHOD_SD: case METHOD_USB: sprintf(filepath, "%s/%s/disksys.rom", ROOTFATDIR, GCSettings.LoadFolder); biosSize = LoadBufferFromFAT(tmpbuffer, filepath, NOTSILENT); break; case METHOD_SMB: sprintf(filepath, "%s/disksys.rom", GCSettings.LoadFolder); biosSize = LoadBufferFromSMB(tmpbuffer, filepath, NOTSILENT); break; } if(biosSize == 8192) { memcpy(FDSBIOS, tmpbuffer, 8192); } else { if(biosSize > 0) WaitPrompt("FDS BIOS file is invalid!"); return 0; // BIOS not loaded, do not load game } free(tmpbuffer); } // load game if(FDSLoad(NULL,fceufp)) nesGameType = 4; } if (nesGameType > 0) { FCEU_ResetVidSys(); PowerNES(); FCEU_ResetPalette(); FCEU_ResetMessages(); // Save state, status messages, etc. SetSoundVariables(); romLoaded = true; return 1; } else { WaitPrompt("Invalid game file!"); romLoaded = false; return 0; } }
/** * Initialize the audio subsystem. */ int InitSound() { int sound, soundrate, soundbufsize, soundvolume, soundtrianglevolume, soundsquare1volume, soundsquare2volume, soundnoisevolume, soundpcmvolume, soundq, lowpass, samples; FCEUI_printf("Initializing audio...\n"); g_config->getOption("SDL.Sound", &sound); if (!sound) return 0; memset(&spec, 0, sizeof(spec)); if(SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { puts(SDL_GetError()); KillSound(); return(0); } char driverName[8]; SDL_AudioDriverName(driverName, 8); fprintf(stderr, "Loading SDL sound with %s driver...\n", driverName); // load configuration variables g_config->getOption("SDL.Sound.Rate", &soundrate); g_config->getOption("SDL.Sound.BufSize", &soundbufsize); g_config->getOption("SDL.Sound.Volume", &soundvolume); g_config->getOption("SDL.Sound.Quality", &soundq); g_config->getOption("SDL.Sound.TriangleVolume", &soundtrianglevolume); g_config->getOption("SDL.Sound.Square1Volume", &soundsquare1volume); g_config->getOption("SDL.Sound.Square2Volume", &soundsquare2volume); g_config->getOption("SDL.Sound.NoiseVolume", &soundnoisevolume); g_config->getOption("SDL.Sound.PCMVolume", &soundpcmvolume); g_config->getOption("SDL.Sound.LowPass", &lowpass); spec.freq = soundrate; spec.format = AUDIO_S16; spec.channels = 2; spec.samples = 512; spec.callback = fillaudio; spec.userdata = 0; while(spec.samples < (soundrate / 60) * 1) spec.samples <<= 1; s_BufferSize = spec.samples * 4; s_Buffer = (int16 *) malloc(sizeof(int16) * s_BufferSize); if (!s_Buffer) return 0; s_BufferRead = s_BufferWrite = s_BufferIn = 0; printf("SDL Size: %d, Internal size: %d\n", spec.samples, s_BufferSize); if(SDL_OpenAudio(&spec, 0) < 0) { puts(SDL_GetError()); KillSound(); return(0); } SDL_PauseAudio(0); FCEUI_SetSoundVolume(soundvolume); FCEUI_SetSoundQuality(soundq); FCEUI_Sound(soundrate); FCEUI_SetTriangleVolume(soundtrianglevolume); FCEUI_SetSquare1Volume(soundsquare1volume); FCEUI_SetSquare2Volume(soundsquare2volume); FCEUI_SetNoiseVolume(soundnoisevolume); FCEUI_SetPCMVolume(soundpcmvolume); FCEUI_SetLowPass(lowpass); return (1); }
int main() { xenon_make_it_faster(XENON_SPEED_FULL); xenos_init(VIDEO_MODE_AUTO); console_init(); xenon_sound_init(); pAudioStart = pAudioBuffer = (uint16_t*) malloc(48000 * sizeof (uint16_t)); memset(pAudioBuffer, 0, 48000 * sizeof (uint16_t)); usb_init(); usb_do_poll(); SYSVideoInit(); // Allocates and initializes memory. Should only be called once, before // any calls to other FCEU functions. FCEUI_Initialize(); //------------------------------------------------------------------------------------- // Set some setting //------------------------------------------------------------------------------------- // Specifies the base FCE Ultra directory. This should be called // immediately after FCEUI_Initialize() and any time afterwards. std::string base = "uda:/"; //FCEUI_SetBaseDirectory(base); // doesn't work ? newlib bug ? FCEUI_SetVidSystem(0); //Apply settings FCEUI_Sound(48000); FCEUI_SetSoundVolume(50); FCEUI_SetLowPass(0); if (FCEUI_LoadGame("uda:/Super Mario Bros. (Europe) (Rev 0A).zip", 0) != NULL) { FCEUI_SetInput(0, SI_GAMEPAD, (void*) &powerpadbuf, 0); FCEUI_SetInput(1, SI_GAMEPAD, (void*) &powerpadbuf, 0); //set to ntsc extern FCEUGI * GameInfo; GameInfo->vidsys = GIV_NTSC; } int32 * snd = NULL; int32 sndsize; // Copy contents of XBuf over to video memory(or whatever needs to be // done to make the contents of XBuf visible on screen). // Each line is 256 pixels(and bytes) in width, and there can be 240 // lines. The pitch for each line is 272 bytes. // XBuf will be 0 if the symbol FRAMESKIP is defined and this frame // was skipped. uint8 * bitmap; while (1) { FCEUI_Emulate(&bitmap, &snd, &sndsize, 0); for (int i = 0; i < (256 * 240); i++) { //Make an ARGB bitmap nesBitmap[i] = ((pcpalette[bitmap[i]].r) << 16) | ((pcpalette[bitmap[i]].g) << 8) | (pcpalette[bitmap[i]].b) | (0xFF << 24); } SYSVideoUpdate(); // Add Sound update_sound(snd,sndsize); // Add Input update_input(); } return 0; }
int GCMemROM(int size) { bool biosError = false; ResetGameLoaded(); CloseGame(); GameInfo = new FCEUGI(); memset(GameInfo, 0, sizeof(FCEUGI)); GameInfo->filename = strdup(romFilename); GameInfo->archiveCount = 0; /*** Set some default values ***/ GameInfo->name=0; GameInfo->type=GIT_CART; GameInfo->vidsys=(EGIV)GCSettings.timing; GameInfo->input[0]=GameInfo->input[1]=SI_UNSET; GameInfo->inputfc=SIFC_UNSET; GameInfo->cspecial=SIS_NONE; /*** Set internal sound information ***/ SetSampleRate(); FCEUI_SetSoundVolume(100); // 0-100 FCEUI_SetLowPass(0); FCEUFILE * fceufp = new FCEUFILE(); fceufp->size = size; fceufp->filename = romFilename; fceufp->mode = FCEUFILE::READ; // read only EMUFILE_MEMFILE *fceumem = new EMUFILE_MEMFILE(nesrom, size); fceufp->stream = fceumem; romLoaded = iNESLoad(romFilename, fceufp, 1); if(!romLoaded) { romLoaded = UNIFLoad(romFilename, fceufp); } if(!romLoaded) { romLoaded = NSFLoad(romFilename, fceufp); } if(!romLoaded) { // read FDS BIOS into FDSBIOS - should be 8192 bytes if (FDSBIOS[1] == 0) { size_t biosSize = 0; char * tmpbuffer = (char *) memalign(32, 64 * 1024); char filepath[1024]; sprintf (filepath, "%s%s/disksys.rom", pathPrefix[GCSettings.LoadMethod], APPFOLDER); biosSize = LoadFile(tmpbuffer, filepath, 0, SILENT); if(biosSize == 0 && strlen(appPath) > 0) { sprintf (filepath, "%s/disksys.rom", appPath); biosSize = LoadFile(tmpbuffer, filepath, 0, SILENT); } if (biosSize == 8192) { memcpy(FDSBIOS, tmpbuffer, 8192); } else { biosError = true; if (biosSize > 0) ErrorPrompt("FDS BIOS file is invalid!"); else ErrorPrompt("FDS BIOS file not found!"); } free(tmpbuffer); } if (FDSBIOS[1] != 0) { romLoaded = FDSLoad(romFilename, fceufp); } } delete fceufp; if (romLoaded) { FCEU_ResetVidSys(); if(GameInfo->type!=GIT_NSF) if(FSettings.GameGenie) OpenGameGenie(); PowerNES(); //if(GameInfo->type!=GIT_NSF) // FCEU_LoadGamePalette(); FCEU_ResetPalette(); FCEU_ResetMessages(); // Save state, status messages, etc. SetupCheats(); ResetAudio(); return 1; } else { delete GameInfo; GameInfo = 0; if(!biosError) ErrorPrompt("Invalid game file!"); romLoaded = false; return 0; } }