/** * setCountry(): Set the current country code. * @param newCountry New country code. */ void Options::setCountry(const int newCountry) { unsigned char Reg_1[0x200]; Flag_Clr_Scr = 1; Country = newCountry; switch (Country) { default: case -1: // Auto-detect. if (Genesis_Started || _32X_Started) Detect_Country_Genesis(); else if (SegaCD_Started) Detect_Country_SegaCD(); break; case 0: // Japan (NTSC) Game_Mode = 0; CPU_Mode = 0; break; case 1: // USA (NTSC) Game_Mode = 1; CPU_Mode = 0; break; case 2: // Europe (PAL) Game_Mode = 1; CPU_Mode = 1; break; case 3: // Japan (PAL) Game_Mode = 0; CPU_Mode = 1; break; } // TODO: Combine this with gens.cpp:Set_Clock_Freq(). if (CPU_Mode) { CPL_Z80 = roundDouble((((double)CLOCK_PAL / 15.0) / 50.0) / 312.0); CPL_M68K = roundDouble((((double)CLOCK_PAL / 7.0) / 50.0) / 312.0); CPL_MSH2 = roundDouble(((((((double)CLOCK_PAL / 7.0) * 3.0) / 50.0) / 312.0) * (double)MSH2_Speed) / 100.0); CPL_SSH2 = roundDouble(((((((double)CLOCK_PAL / 7.0) * 3.0) / 50.0) / 312.0) * (double)SSH2_Speed) / 100.0); VDP_Num_Lines = 312; VDP_Status |= 0x0001; _32X_VDP.Mode &= ~0x8000; CD_Access_Timer = 2080; Timer_Step = 136752; } else { CPL_Z80 = roundDouble((((double)CLOCK_NTSC / 15.0) / 60.0) / 262.0); CPL_M68K = roundDouble((((double)CLOCK_NTSC / 7.0) / 60.0) / 262.0); CPL_MSH2 = roundDouble(((((((double)CLOCK_NTSC / 7.0) * 3.0) / 60.0) / 262.0) * (double)MSH2_Speed) / 100.0); CPL_SSH2 = roundDouble(((((((double) CLOCK_NTSC / 7.0) * 3.0) / 60.0) / 262.0) * (double)SSH2_Speed) / 100.0); VDP_Num_Lines = 262; VDP_Status &= 0xFFFE; _32X_VDP.Mode |= 0x8000; CD_Access_Timer = 2096; Timer_Step = 135708; } if (audio->enabled()) { PSG_Save_State(); YM2612_Save(Reg_1); audio->endSound(); audio->setEnabled(false); if (CPU_Mode) { YM2612_Init(CLOCK_PAL / 7, audio->soundRate(), YM2612_Improv); PSG_Init(CLOCK_PAL / 15, audio->soundRate()); } else { YM2612_Init(CLOCK_NTSC / 7, audio->soundRate(), YM2612_Improv); PSG_Init(CLOCK_NTSC / 15, audio->soundRate()); } if (SegaCD_Started) Set_Rate_PCM(audio->soundRate()); YM2612_Restore (Reg_1); PSG_Restore_State(); if (!audio->initSound()) return; audio->setEnabled(true); audio->playSound(); } if (Game_Mode) { if (CPU_Mode) MESSAGE_L("Europe system (50 FPS)", "Europe system (50 FPS)", 1500); else MESSAGE_L("USA system (60 FPS)", "USA system (60 FPS)", 1500); } else { if (CPU_Mode) MESSAGE_L("Japan system (50 FPS)", "Japan system (50 FPS)", 1500); else MESSAGE_L("Japan system (60 FPS)", "Japan system (60 FPS)", 1500); } setGameName(); return; }
/** * Init_Genesis(): Initialize the Genesis with the specified ROM image. * @param MD_ROM ROM image struct. * @return 1 if successful. */ int Init_Genesis(ROM_t* MD_ROM) { // Clear the sound buffer. audio_clear_sound_buffer(); Flag_Clr_Scr = 1; Settings.Paused = Frame_Number = 0; SRAM_Start = SRAM_End = SRAM_ON = SRAM_Write = 0; Controller_1_COM = Controller_2_COM = 0; #ifdef GENS_DEBUGGER STOP_DEBUGGING(); #endif #if 0 // TODO: Replace with MDP "exclusive mode" later. if (!Kaillera_Client_Running) #endif Init_Genesis_SRAM(MD_ROM); // Check what country code should be used. // TODO: Get rid of magic numbers. switch (Country) { default: case -1: // Autodetection. Detect_Country_Genesis(MD_ROM); break; case 0: // Japan (NTSC) Game_Mode = 0; CPU_Mode = 0; break; case 1: // US (NTSC) Game_Mode = 1; CPU_Mode = 0; break; case 2: // Europe (PAL) Game_Mode = 1; CPU_Mode = 1; break; case 3: // Japan (PAL) Game_Mode = 0; CPU_Mode = 1; break; } VDP_Num_Vis_Lines = 224; Gen_Version = 0x20 + 0x0; // Version de la megadrive (0x0 - 0xF) // Byteswap the ROM data. be16_to_cpu_array(Rom_Data, Rom_Size); ROM_ByteSwap_State |= ROM_BYTESWAPPED_MD_ROM; // Reset all CPUs and other components. M68K_Reset(0); Z80_Reset(); VDP_Reset(); // Initialize the controller state. Init_Controllers(); // Set clock rates depending on the CPU mode (NTSC / PAL). Set_Clock_Freq(0); // If auto-fix checksum is enabled, fix the ROM checksum. if (Auto_Fix_CS) ROM::fixChecksum(); // Initialize sound. if (audio_get_enabled()) { audio_end(); if (audio_init(AUDIO_BACKEND_DEFAULT)) audio_set_enabled(false); else { if (audio_play_sound) audio_play_sound(); } } Reset_Update_Timers(); // Set the appropriate frame update function pointers. Update_Frame = Do_Genesis_Frame; Update_Frame_Fast = Do_Genesis_Frame_No_VDP; return 1; }