void CRam::Reset(void) { MDFNMP_AddRAM(65536, 0x0000, mRamData); for(int loop=0;loop<RAM_SIZE;loop++) mRamData[loop]=DEFAULT_RAM_CONTENTS; // Open up the file if(mFileSize) { HOME_HEADER header; uint8 tmp; // Zero the RAM for(int loop=0;loop<RAM_SIZE;loop++) mRamData[loop]=0x00; // Reverse the bytes in the header words memcpy(&header,mFileData,sizeof(HOME_HEADER)); tmp=(header.load_address&0xff00)>>8; header.load_address=(header.load_address<<8)+tmp; tmp=(header.size&0xff00)>>8; header.size=(header.size<<8)+tmp; // Now we can safely read/manipulate the data header.load_address-=10; memcpy(mRamData+header.load_address,mFileData,header.size); gCPUBootAddress=header.load_address; } }
static void SetRAM8K(uint8 bank) { if(gbRamSize) { gbMemoryMap[0x0a] = &gbRam[((bank << 13) + 0x0000) & gbRamSizeMask]; gbMemoryMap[0x0b] = &gbRam[((bank << 13) + 0x1000) & gbRamSizeMask]; MDFNMP_AddRAM((gbRamSize > 8192) ? 8192 : gbRamSize, 0xA000, &gbRam[(bank << 13) & gbRamSizeMask]); } }
static void LoadCommon(MDFNFILE *fp) { try { /* Assign default settings (US NTSC machine) */ sms.display = DISPLAY_NTSC; sms.territory = MDFN_GetSettingI("sms.territory"); sms.use_fm = FALSE; Cart_Init(fp); Cart_LoadNV(); if(IS_SMS && sms.territory == TERRITORY_DOMESTIC) sms.use_fm = MDFN_GetSettingB("sms.fm"); MDFNMP_Init(1024, 65536 / 1024); system_assign_device(PORT_A, DEVICE_PAD2B); system_assign_device(PORT_B, DEVICE_PAD2B); MDFNMP_AddRAM(8192, 0xC000, sms.wram); sms_init(); pio_init(); vdp_init(IS_SMS && sms.territory == TERRITORY_DOMESTIC); render_init(); MDFNGameInfo->GameSetMD5Valid = FALSE; uint32 sndclk; if(sms.display == DISPLAY_PAL) { sndclk = 3546893; MDFNGameInfo->fps = (uint32)((uint64)65536 * 256 * sndclk / 313 / 228); //6144000 * 65536 * 256 / 515 / 198); // 3072000 * 2 * 10000 / 515 / 198 } else { sndclk = 3579545; MDFNGameInfo->fps = (uint32)((uint64)65536 * 256 * sndclk / 262 / 228); //6144000 * 65536 * 256 / 515 / 198); // 3072000 * 2 * 10000 / 515 / 198 } MDFNGameInfo->MasterClock = MDFN_MASTERCLOCK_FIXED(sndclk); SMS_SoundInit(sndclk, sms.use_fm); sms.save = 0; system_reset(); } catch(...) { Cleanup(); throw; } }
static void Load(MDFNFILE *fp) { try { const uint64 fp_size = fp->size(); if(fp_size > 1024 * 1024 * 8) // 4MiB maximum ROM size, 2* to be a little tolerant of garbage. throw MDFN_Error(0, _("NGP/NGPC ROM image is too large.")); ngpc_rom.length = fp_size; ngpc_rom.data = new uint8[ngpc_rom.length]; fp->read(ngpc_rom.data, ngpc_rom.length); md5_context md5; md5.starts(); md5.update(ngpc_rom.data, ngpc_rom.length); md5.finish(MDFNGameInfo->MD5); rom_loaded(); MDFN_printf(_("ROM: %uKiB\n"), (ngpc_rom.length + 1023) / 1024); MDFN_printf(_("ROM MD5: 0x%s\n"), md5_context::asciistr(MDFNGameInfo->MD5, 0).c_str()); FLASH_LoadNV(); MDFNMP_Init(1024, 1024 * 1024 * 16 / 1024); NGPGfx = new NGPGFX_CLASS(); MDFNGameInfo->fps = (uint32)((uint64)6144000 * 65536 * 256 / 515 / 198); // 3072000 * 2 * 10000 / 515 / 198 MDFNGameInfo->GameSetMD5Valid = FALSE; MDFNNGPCSOUND_Init(); MDFNMP_AddRAM(16384, 0x4000, CPUExRAM); SetFRM(); // Set up fast read memory mapping bios_install(); //main_timeaccum = 0; z80_runtime = 0; reset(); } catch(...) { Cleanup(); throw; } }
void PowerNES(void) { MDFNMOV_AddCommand(MDFN_MSC_POWER); if(!MDFNGameInfo) return; if(!Genie_BIOSInstalled()) MDFNMP_RemoveReadPatches(); MDFNMP_AddRAM(0x0800, 0x0000, RAM); // Genie_Power() will remove any cheat read patches, and then install the BIOS(and its read hooks) Genie_Power(); // http://wiki.nesdev.com/w/index.php/CPU_power_up_state memset(RAM, 0xFF, 0x800); RAM[0x008] = 0xF7; RAM[0x009] = 0xEF; RAM[0x00A] = 0xDF; RAM[0x00F] = 0xBF; NESINPUT_Power(); MDFNSND_Power(); MDFNPPU_Power(); /* Have the external game hardware "powered" after the internal NES stuff. Needed for the NSF code and VS System code. */ if(GameInterface->Power) GameInterface->Power(); if(NESIsVSUni) MDFN_VSUniPower(); timestampbase = 0; X6502_Power(); if(!Genie_BIOSInstalled()) MDFNMP_InstallReadPatches(); }
static int Load(const char *name, MDFNFILE *fp) { if(!(ngpc_rom.data = (uint8 *)MDFN_malloc(GET_FSIZE_PTR(fp), _("Cart ROM")))) return(0); ngpc_rom.length = GET_FSIZE_PTR(fp); memcpy(ngpc_rom.data, GET_FDATA_PTR(fp), GET_FSIZE_PTR(fp)); md5_context md5; md5.starts(); md5.update(ngpc_rom.data, ngpc_rom.length); md5.finish(MDFNGameInfo->MD5); rom_loaded(); MDFN_printf(_("ROM: %dKiB\n"), (ngpc_rom.length + 1023) / 1024); MDFN_printf(_("ROM MD5: 0x%s\n"), md5_context::asciistr(MDFNGameInfo->MD5, 0).c_str()); MDFNMP_Init(1024, 1024 * 1024 * 16 / 1024); NGPGfx = new NGPGFX_CLASS(); MDFNGameInfo->fps = (uint32)((uint64)6144000 * 65536 * 256 / 515 / 198); // 3072000 * 2 * 10000 / 515 / 198 MDFNGameInfo->GameSetMD5Valid = FALSE; MDFNNGPCSOUND_Init(); MDFNMP_AddRAM(16384, 0x4000, CPUExRAM); SetFRM(); // Set up fast read memory mapping bios_install(); //main_timeaccum = 0; z80_runtime = 0; reset(); return(1); }
void HuC_Load(const uint8 *data, uint32 len, uint32 crc32) { try { uint32 sf2_threshold = 2048 * 1024; uint32 sf2_required_size = 2048 * 1024 + 512 * 1024; uint32 m_len = (len + 8191)&~8191; bool sf2_mapper = FALSE; if(m_len >= sf2_threshold) { sf2_mapper = TRUE; if(m_len != sf2_required_size) m_len = sf2_required_size; } IsPopulous = 0; PCE_IsCD = 0; md5_context md5; md5.starts(); md5.update(data, len); md5.finish(MDFNGameInfo->MD5); MDFN_printf(_("ROM: %dKiB\n"), (len + 1023) / 1024); MDFN_printf(_("ROM CRC32: 0x%04x\n"), crc32); MDFN_printf(_("ROM MD5: 0x%s\n"), md5_context::asciistr(MDFNGameInfo->MD5, 0).c_str()); HuCROM = (uint8 *)MDFN_malloc(m_len, _("HuCard ROM")); memset(HuCROM, 0xFF, m_len); memcpy(HuCROM, data, (m_len < len) ? m_len : len); memset(ROMSpace, 0xFF, 0x88 * 8192 + 8192); if(m_len == 0x60000) { memcpy(ROMSpace + 0x00 * 8192, HuCROM, 0x20 * 8192); memcpy(ROMSpace + 0x20 * 8192, HuCROM, 0x20 * 8192); memcpy(ROMSpace + 0x40 * 8192, HuCROM + 0x20 * 8192, 0x10 * 8192); memcpy(ROMSpace + 0x50 * 8192, HuCROM + 0x20 * 8192, 0x10 * 8192); memcpy(ROMSpace + 0x60 * 8192, HuCROM + 0x20 * 8192, 0x10 * 8192); memcpy(ROMSpace + 0x70 * 8192, HuCROM + 0x20 * 8192, 0x10 * 8192); } else if(m_len == 0x80000) { memcpy(ROMSpace + 0x00 * 8192, HuCROM, 0x40 * 8192); memcpy(ROMSpace + 0x40 * 8192, HuCROM + 0x20 * 8192, 0x20 * 8192); memcpy(ROMSpace + 0x60 * 8192, HuCROM + 0x20 * 8192, 0x20 * 8192); } else { memcpy(ROMSpace + 0x00 * 8192, HuCROM, (m_len < 1024 * 1024) ? m_len : 1024 * 1024); } for(int x = 0x00; x < 0x80; x++) { HuCPUFastMap[x] = ROMSpace; PCERead[x] = HuCRead; } if(!memcmp(HuCROM + 0x1F26, "POPULOUS", strlen("POPULOUS"))) { uint8 *PopRAM = ROMSpace + 0x40 * 8192; gzFile fp; memset(PopRAM, 0xFF, 32768); if((fp = gzopen(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav").c_str(), "rb"))) { gzread(fp, PopRAM, 32768); gzclose(fp); } IsPopulous = 1; MDFN_printf("Populous\n"); for(int x = 0x40; x < 0x44; x++) { HuCPUFastMap[x] = &PopRAM[(x & 3) * 8192] - x * 8192; PCERead[x] = HuCRead; PCEWrite[x] = HuCRAMWrite; } MDFNMP_AddRAM(32768, 0x40 * 8192, PopRAM); } else { gzFile fp; memset(SaveRAM, 0x00, 2048); memcpy(SaveRAM, BRAM_Init_String, 8); // So users don't have to manually intialize the file cabinet // in the CD BIOS screen. if((fp = gzopen(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav").c_str(), "rb"))) { gzread(fp, SaveRAM, 2048); gzclose(fp); } PCEWrite[0xF7] = SaveRAMWrite; PCERead[0xF7] = SaveRAMRead; MDFNMP_AddRAM(2048, 0xF7 * 8192, SaveRAM); } // 0x1A558 //if(len >= 0x20000 && !memcmp(HuCROM + 0x1A558, "STREET FIGHTER#", strlen("STREET FIGHTER#"))) if(sf2_mapper) { for(int x = 0x40; x < 0x80; x++) { // FIXME: PCE_FAST HuCPUFastMap[x] = NULL; // Make sure our reads go through our read function, and not a table lookup PCERead[x] = HuCSF2Read; } PCEWrite[0] = HuCSF2Write; MDFN_printf("Street Fighter 2 Mapper\n"); HuCSF2Latch = 0; } } catch(...) { Cleanup(); throw; } }
void HuC_LoadCD(const char *bios_path) { static const FileExtensionSpecStruct KnownBIOSExtensions[] = { { ".pce", gettext_noop("PC Engine ROM Image") }, { ".bin", gettext_noop("PC Engine ROM Image") }, { ".bios", gettext_noop("BIOS Image") }, { NULL, NULL } }; try { MDFNFILE fp(bios_path, KnownBIOSExtensions, _("CD BIOS")); memset(ROMSpace, 0xFF, 262144); memcpy(ROMSpace, fp.Data() + (fp.Size() & 512), ((fp.Size() & ~512) > 262144) ? 262144 : (fp.Size() &~ 512) ); fp.Close(); PCE_IsCD = 1; PCE_InitCD(); md5_context md5; md5.starts(); // md5_update(&md5, HuCROM, 262144); #if 0 int32 track = CDIF_GetFirstTrack(); int32 last_track = CDIF_GetLastTrack(); bool DTFound = 0; for(; track <= last_track; track++) { CDIF_Track_Format format; if(CDIF_GetTrackFormat(track, format) && format == CDIF_FORMAT_MODE1) { DTFound = 1; break; } } if(DTFound) // Only add the MD5 hash if we were able to find a data track. { uint32 start_sector = CDIF_GetTrackStartPositionLBA(track); uint8 sector_buffer[2048]; for(int x = 0; x < 128; x++) { memset(sector_buffer, 0, 2048); CDIF_ReadSector(sector_buffer, NULL, start_sector + x, 1); md5.update(sector_buffer, 2048); } } md5.finish(MDFNGameInfo->MD5); MDFN_printf(_("CD MD5(first 256KiB): 0x%s\n"), md5_context::asciistr(MDFNGameInfo->MD5, 0).c_str()); #endif MDFN_printf(_("Arcade Card Emulation: %s\n"), PCE_ACEnabled ? _("Enabled") : _("Disabled")); for(int x = 0; x < 0x40; x++) { HuCPUFastMap[x] = ROMSpace; PCERead[x] = HuCRead; } for(int x = 0x68; x < 0x88; x++) { HuCPUFastMap[x] = ROMSpace; PCERead[x] = HuCRead; PCEWrite[x] = HuCRAMWrite; } PCEWrite[0x80] = HuCRAMWriteCDSpecial; // Hyper Dyne Special hack MDFNMP_AddRAM(262144, 0x68 * 8192, ROMSpace + 0x68 * 8192); if(PCE_ACEnabled) { arcade_card = new ArcadeCard(); for(int x = 0x40; x < 0x44; x++) { HuCPUFastMap[x] = NULL; PCERead[x] = ACPhysRead; PCEWrite[x] = ACPhysWrite; } } gzFile srp; memset(SaveRAM, 0x00, 2048); memcpy(SaveRAM, BRAM_Init_String, 8); // So users don't have to manually intialize the file cabinet // in the CD BIOS screen. if((srp = gzopen(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav").c_str(), "rb"))) { gzread(srp, SaveRAM, 2048); gzclose(srp); } PCEWrite[0xF7] = SaveRAMWrite; PCERead[0xF7] = SaveRAMRead; MDFNMP_AddRAM(2048, 0xF7 * 8192, SaveRAM); } catch(...) { Cleanup(); throw; } }
void HuC_Load(const uint8 *data, uint32 len, uint32 crc32, bool DisableBRAM, SysCardType syscard) { const uint32 sf2_threshold = 2048 * 1024; uint32 m_len = (len + 8191) &~ 8191; bool sf2_mapper = FALSE; bool mcg_mapper = FALSE; bool UseBRAM = FALSE; // // Obvious, but anyway: catch exceptions and free any allocated memory here, otherwise when code higher up calls HuC_Close(), it might wipe out save game files. // try { if(len >= 8192 && !memcmp(data + 0x1FD0, "MCGENJIN", 8)) mcg_mapper = TRUE; if(!syscard && m_len >= sf2_threshold && !mcg_mapper) { sf2_mapper = TRUE; // Only used the "extended" SF2 mapper if it's considerably larger than the normal SF2 mapper size. if(m_len < (512 * 1024 * 6)) m_len = 512 * 1024 * 5; else m_len = round_up_pow2(m_len - 512 * 1024) + 512 * 1024; if(m_len > 8912896) throw MDFN_Error(0, _("ROM image is too large for extended SF2 mapper!")); HuCSF2BankMask = ((m_len - 512 * 1024) / (512 * 1024)) - 1; //printf("%d %d, %02x\n", len, m_len, HuCSF2BankMask); } IsPopulous = 0; PCE_IsCD = 0; if(syscard == SYSCARD_NONE) { md5_context md5; md5.starts(); md5.update(data, len); md5.finish(MDFNGameInfo->MD5); MDFN_printf(_("ROM: %dKiB\n"), (len + 1023) / 1024); MDFN_printf(_("ROM CRC32: 0x%08x\n"), crc32); MDFN_printf(_("ROM MD5: 0x%s\n"), md5_context::asciistr(MDFNGameInfo->MD5, 0).c_str()); } if(syscard != SYSCARD_NONE) { CDRAM = (uint8 *)MDFN_calloc_T(1, 8 * 8192, _("CD RAM")); for(int x = 0x80; x < 0x88; x++) { ROMMap[x] = &CDRAM[(x - 0x80) * 8192] - x * 8192; HuCPU->SetFastRead(x, ROMMap[x] + x * 8192); HuCPU->SetReadHandler(x, CDRAMRead); HuCPU->SetWriteHandler(x, CDRAMWrite); } MDFNMP_AddRAM(8 * 8192, 0x80 * 8192, CDRAM); UseBRAM = TRUE; } if(mcg_mapper) { mcg = new MCGenjin(data, len); for(unsigned i = 0; i < 128; i++) { HuCPU->SetFastRead(i, NULL); HuCPU->SetReadHandler(i, MCG_ReadHandler); HuCPU->SetWriteHandler(i, MCG_WriteHandler); } goto BRAM_Init; // SO EVIL YES EVVIIIIIL(FIXME) } HuCROM = (uint8 *)MDFN_malloc_T(m_len, _("HuCard ROM")); memset(HuCROM, 0xFF, m_len); memcpy(HuCROM, data, (m_len < len) ? m_len : len); if(m_len == 0x60000) { for(int x = 0; x < 128; x++) { ROMMap[x] = &HuCROM[(x & 0x1F) * 8192] - x * 8192; HuCPU->SetFastRead(x, ROMMap[x] + x * 8192); HuCPU->SetReadHandler(x, HuCRead); } for(int x = 64; x < 128; x++) { ROMMap[x] = &HuCROM[((x & 0xF) + 32) * 8192] - x * 8192; HuCPU->SetFastRead(x, ROMMap[x] + x * 8192); HuCPU->SetReadHandler(x, HuCRead); } } else if(m_len == 0x80000) { for(int x = 0; x < 64; x++) { ROMMap[x] = &HuCROM[(x & 0x3F) * 8192] - x * 8192; HuCPU->SetFastRead(x, ROMMap[x] + x * 8192); HuCPU->SetReadHandler(x, HuCRead); } for(int x = 64; x < 128; x++) { ROMMap[x] = &HuCROM[((x & 0x1F) + 32) * 8192] - x * 8192; HuCPU->SetFastRead(x, ROMMap[x] + x * 8192); HuCPU->SetReadHandler(x, HuCRead); } } else { for(int x = 0; x < 128; x++) { uint8 bank = x % (m_len / 8192); ROMMap[x] = &HuCROM[bank * 8192] - x * 8192; HuCPU->SetFastRead(x, ROMMap[x] + x * 8192); HuCPU->SetReadHandler(x, HuCRead); } } if(syscard) { if(syscard == SYSCARD_3 || syscard == SYSCARD_ARCADE) { SysCardRAM = (uint8 *)MDFN_calloc_T(1, 24 * 8192, _("System Card RAM")); for(int x = 0x68; x < 0x80; x++) { ROMMap[x] = &SysCardRAM[(x - 0x68) * 8192] - x * 8192; HuCPU->SetFastRead(x, ROMMap[x] + x * 8192); HuCPU->SetReadHandler(x, SysCardRAMRead); HuCPU->SetWriteHandler(x, SysCardRAMWrite); } MDFNMP_AddRAM(24 * 8192, 0x68 * 8192, SysCardRAM); } if(syscard == SYSCARD_ARCADE) { arcade_card = new ArcadeCard(); for(int x = 0x40; x < 0x44; x++) { ROMMap[x] = NULL; HuCPU->SetFastRead(x, NULL); HuCPU->SetReadHandler(x, AC_PhysRead); HuCPU->SetWriteHandler(x, AC_PhysWrite); } } } else { if(!memcmp(HuCROM + 0x1F26, "POPULOUS", strlen("POPULOUS"))) { gzFile fp; PopRAM = (uint8 *)MDFN_malloc_T(32768, _("Populous RAM")); memset(PopRAM, 0xFF, 32768); if((fp = gzopen(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav").c_str(), "rb"))) { gzread(fp, PopRAM, 32768); gzclose(fp); } IsPopulous = 1; MDFN_printf("Populous\n"); for(int x = 0x40; x < 0x44; x++) { ROMMap[x] = &PopRAM[(x & 3) * 8192] - x * 8192; HuCPU->SetFastRead(x, ROMMap[x] + x * 8192); HuCPU->SetReadHandler(x, HuCRead); HuCPU->SetWriteHandler(x, HuCRAMWrite); } MDFNMP_AddRAM(32768, 0x40 * 8192, PopRAM); } else if(crc32 == 0x34dc65c4) // Tsushin Booster { gzFile fp; TsushinRAM = (uint8*)MDFN_malloc_T(0x8000, _("Tsushin Booster RAM")); memset(TsushinRAM, 0xFF, 0x8000); if((fp = gzopen(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav").c_str(), "rb"))) { gzread(fp, TsushinRAM, 32768); gzclose(fp); } IsTsushin = 1; MDFN_printf("Tsushin Booster\n"); for(int x = 0x88; x < 0x8C; x++) { ROMMap[x] = &TsushinRAM[(x & 3) * 8192] - x * 8192; HuCPU->SetFastRead(x, ROMMap[x] + x * 8192); HuCPU->SetReadHandler(x, HuCRead); HuCPU->SetWriteHandler(x, HuCRAMWrite); } MDFNMP_AddRAM(32768, 0x88 * 8192, TsushinRAM); } else UseBRAM = TRUE; // 0x1A558 if(sf2_mapper) { for(int x = 0x20; x < 0x40; x++) HuCPU->SetReadHandler(x, HuCSF2ReadLow); for(int x = 0x40; x < 0x80; x++) { HuCPU->SetFastRead(x, NULL); // Make sure our reads go through our read function, and not a table lookup HuCPU->SetReadHandler(x, HuCSF2Read); } HuCPU->SetWriteHandler(0, HuCSF2Write); MDFN_printf("Street Fighter 2 Mapper\n"); HuCSF2Latch = 0; } } // end else to if(syscard) BRAM_Init: BRAM_Disabled = DisableBRAM; if(BRAM_Disabled) UseBRAM = false; if(UseBRAM) { gzFile fp; memset(SaveRAM, 0x00, 2048); memcpy(SaveRAM, BRAM_Init_String, 8); // So users don't have to manually intialize the file cabinet // in the CD BIOS screen. if((fp = gzopen(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav").c_str(), "rb"))) { gzread(fp, SaveRAM, 2048); gzclose(fp); } HuCPU->SetWriteHandler(0xF7, SaveRAMWrite); HuCPU->SetReadHandler(0xF7, SaveRAMRead); MDFNMP_AddRAM(2048, 0xF7 * 8192, SaveRAM); } } catch(...) { Cleanup(); throw; } }
static void LoadCommon(void) { IsSGX |= MDFN_GetSettingB("pce_fast.forcesgx") ? 1 : 0; if(IsHES) IsSGX = 1; // Don't modify IsSGX past this point. VDC_Init(IsSGX); VDC_SetSettings(MDFN_GetSettingB("pce_fast.nospritelimit"), MDFN_GetSettingB("pce_fast.correct_aspect")); if(IsSGX) { MDFN_printf("SuperGrafx Emulation Enabled.\n"); HuCPU.PCERead[0xF8] = HuCPU.PCERead[0xF9] = HuCPU.PCERead[0xFA] = HuCPU.PCERead[0xFB] = BaseRAMReadSGX; HuCPU.PCEWrite[0xF8] = HuCPU.PCEWrite[0xF9] = HuCPU.PCEWrite[0xFA] = HuCPU.PCEWrite[0xFB] = BaseRAMWriteSGX; for(int x = 0xf8; x < 0xfb; x++) HuCPU.FastMap[x] = &BaseRAM[(x & 0x3) * 8192]; HuCPU.PCERead[0xFF] = IOReadSGX; } else { HuCPU.PCERead[0xF8] = BaseRAMRead; HuCPU.PCERead[0xF9] = HuCPU.PCERead[0xFA] = HuCPU.PCERead[0xFB] = BaseRAMRead_Mirrored; HuCPU.PCEWrite[0xF8] = BaseRAMWrite; HuCPU.PCEWrite[0xF9] = HuCPU.PCEWrite[0xFA] = HuCPU.PCEWrite[0xFB] = BaseRAMWrite_Mirrored; for(int x = 0xf8; x < 0xfb; x++) HuCPU.FastMap[x] = &BaseRAM[0]; HuCPU.PCERead[0xFF] = IORead; } MDFNMP_AddRAM(IsSGX ? 32768 : 8192, 0xf8 * 8192, BaseRAM); HuCPU.PCEWrite[0xFF] = IOWrite; psg = new PCEFast_PSG(sbuf); psg->SetVolume(1.0); if(PCE_IsCD) { unsigned int cdpsgvolume = MDFN_GetSettingUI("pce_fast.cdpsgvolume"); if(cdpsgvolume != 100) { MDFN_printf(_("CD PSG Volume: %d%%\n"), cdpsgvolume); } psg->SetVolume(0.678 * cdpsgvolume / 100); } PCEINPUT_Init(); PCE_Power(); MDFNGameInfo->LayerNames = IsSGX ? "BG0\0SPR0\0BG1\0SPR1\0" : "Background\0Sprites\0"; MDFNGameInfo->fps = (uint32)((double)7159090.90909090 / 455 / 263 * 65536 * 256); if(!IsHES) { // Clean this up: if(!MDFN_GetSettingB("pce_fast.correct_aspect")) MDFNGameInfo->fb_width = 682; MDFNGameInfo->nominal_width = MDFN_GetSettingB("pce_fast.correct_aspect") ? 288 : 341; MDFNGameInfo->nominal_height = MDFN_GetSettingUI("pce_fast.slend") - MDFN_GetSettingUI("pce_fast.slstart") + 1; MDFNGameInfo->lcm_width = MDFN_GetSettingB("pce_fast.correct_aspect") ? 1024 : 341; MDFNGameInfo->lcm_height = MDFNGameInfo->nominal_height; } }
void HuC_LoadCD(const std::string& bios_path) { static const FileExtensionSpecStruct KnownBIOSExtensions[] = { { ".pce", gettext_noop("PC Engine ROM Image") }, { ".bin", gettext_noop("PC Engine ROM Image") }, { ".bios", gettext_noop("BIOS Image") }, { NULL, NULL } }; try { MDFNFILE fp(bios_path.c_str(), KnownBIOSExtensions, _("CD BIOS")); memset(ROMSpace, 0xFF, 262144); if(fp.size() & 512) fp.seek(512, SEEK_SET); fp.read(ROMSpace, 262144); fp.Close(); PCE_IsCD = 1; PCE_InitCD(); MDFN_printf(_("Arcade Card Emulation: %s\n"), PCE_ACEnabled ? _("Enabled") : _("Disabled")); for(int x = 0; x < 0x40; x++) { HuCPUFastMap[x] = ROMSpace; PCERead[x] = HuCRead; } for(int x = 0x68; x < 0x88; x++) { HuCPUFastMap[x] = ROMSpace; PCERead[x] = HuCRead; PCEWrite[x] = HuCRAMWrite; } PCEWrite[0x80] = HuCRAMWriteCDSpecial; // Hyper Dyne Special hack MDFNMP_AddRAM(262144, 0x68 * 8192, ROMSpace + 0x68 * 8192); if(PCE_ACEnabled) { arcade_card = new ArcadeCard(); for(int x = 0x40; x < 0x44; x++) { HuCPUFastMap[x] = NULL; PCERead[x] = ACPhysRead; PCEWrite[x] = ACPhysWrite; } } memset(SaveRAM, 0x00, 2048); memcpy(SaveRAM, BRAM_Init_String, 8); // So users don't have to manually intialize the file cabinet // in the CD BIOS screen. LoadSaveMemory(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav"), SaveRAM, 2048); PCEWrite[0xF7] = SaveRAMWrite; PCERead[0xF7] = SaveRAMRead; MDFNMP_AddRAM(2048, 0xF7 * 8192, SaveRAM); } catch(...) { Cleanup(); throw; } }
static int GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int battery) { is155=0; info->StateAction = StateAction; info->Close=GenMMC1Close; MMC1PRGHook16=MMC1CHRHook4=0; mmc1opts=0; PRGmask16[0]&=(prg>>14)-1; CHRmask4[0]&=(chr>>12)-1; CHRmask8[0]&=(chr>>13)-1; WRAM_Size = wram * 1024; if(wram) { if(!(WRAM=(uint8*)malloc(WRAM_Size))) { GenMMC1Close(); return(0); } memset(WRAM, 0, WRAM_Size); mmc1opts|=1; if(wram>8) mmc1opts|=4; SetupCartPRGMapping(0x10,WRAM,WRAM_Size,1); if(battery) { mmc1opts|=2; info->SaveGame[0]=WRAM+((mmc1opts&4)?8192:0); info->SaveGameLen[0]=8192; } } if(!chr) { if(!(CHRRAM=(uint8*)malloc(8192))) { GenMMC1Close(); return(0); } SetupCartCHRMapping(0, CHRRAM, 8192, 1); } info->Power=GenMMC1Power; #ifdef WANT_DEBUGGER MDFNDBG_AddRegGroup(&DBGMMC1RegsGroup); #endif SetWriteHandler(0x8000,0xFFFF,MMC1_write); SetReadHandler(0x8000,0xFFFF,CartBR); if(mmc1opts&1) { MDFNMP_AddRAM(WRAM_Size, 0x6000, WRAM); SetReadHandler(0x6000,0x7FFF,MAWRAM); SetWriteHandler(0x6000,0x7FFF,MBWRAM); } return(1); }
static int LoadCommon(MDFNFILE *fp) { int32 size = fp->size; const uint8 *data_ptr = fp->data; if(size & 512) { size -= 512; data_ptr += 512; } /* Assign default settings (US NTSC machine) */ sms.display = DISPLAY_NTSC; sms.territory = MDFN_GetSettingI("sms.territory"); sms.use_fm = FALSE; if(!SMS_CartInit(data_ptr, size)) return(0); if(IS_SMS && sms.territory == TERRITORY_DOMESTIC) sms.use_fm = MDFN_GetSettingB("sms.fm"); MDFNMP_Init(1024, 65536 / 1024); system_assign_device(PORT_A, DEVICE_PAD2B); system_assign_device(PORT_B, DEVICE_PAD2B); MDFNMP_AddRAM(8192, 0xC000, sms.wram); sms_init(); pio_init(); vdp_init(IS_SMS && sms.territory == TERRITORY_DOMESTIC); render_init(); MDFNGameInfo->GameSetMD5Valid = FALSE; uint32 sndclk; if(sms.display == DISPLAY_PAL) { sndclk = 3546893; MDFNGameInfo->fps = (uint32)((uint64)65536 * 256 * sndclk / 313 / 228); //6144000 * 65536 * 256 / 515 / 198); // 3072000 * 2 * 10000 / 515 / 198 } else { sndclk = 3579545; MDFNGameInfo->fps = (uint32)((uint64)65536 * 256 * sndclk / 262 / 228); //6144000 * 65536 * 256 / 515 / 198); // 3072000 * 2 * 10000 / 515 / 198 } MDFNGameInfo->MasterClock = MDFN_MASTERCLOCK_FIXED(sndclk); SMS_SoundInit(sndclk, sms.use_fm); sms.save = 0; system_reset(); return(1); }
uint32 HuC_Load(MDFNFILE* fp) { uint32 crc = 0; try { uint32 sf2_threshold = 2048 * 1024; uint32 sf2_required_size = 2048 * 1024 + 512 * 1024; uint64 len = fp->size(); if(len & 512) // Skip copier header. { len &= ~512; fp->seek(512, SEEK_SET); } uint64 m_len = (len + 8191)&~8191; bool sf2_mapper = FALSE; if(m_len >= sf2_threshold) { sf2_mapper = TRUE; if(m_len != sf2_required_size) m_len = sf2_required_size; } IsPopulous = 0; PCE_IsCD = 0; HuCROM = new uint8[m_len]; memset(HuCROM, 0xFF, m_len); fp->read(HuCROM, std::min<uint64>(m_len, len)); md5_context md5; md5.starts(); md5.update(HuCROM, std::min<uint64>(m_len, len)); md5.finish(MDFNGameInfo->MD5); crc = crc32(0, HuCROM, std::min<uint64>(m_len, len)); MDFN_printf(_("ROM: %lluKiB\n"), (unsigned long long)(std::min<uint64>(m_len, len) / 1024)); MDFN_printf(_("ROM CRC32: 0x%04x\n"), crc); MDFN_printf(_("ROM MD5: 0x%s\n"), md5_context::asciistr(MDFNGameInfo->MD5, 0).c_str()); memset(ROMSpace, 0xFF, 0x88 * 8192 + 8192); if(m_len == 0x60000) { memcpy(ROMSpace + 0x00 * 8192, HuCROM, 0x20 * 8192); memcpy(ROMSpace + 0x20 * 8192, HuCROM, 0x20 * 8192); memcpy(ROMSpace + 0x40 * 8192, HuCROM + 0x20 * 8192, 0x10 * 8192); memcpy(ROMSpace + 0x50 * 8192, HuCROM + 0x20 * 8192, 0x10 * 8192); memcpy(ROMSpace + 0x60 * 8192, HuCROM + 0x20 * 8192, 0x10 * 8192); memcpy(ROMSpace + 0x70 * 8192, HuCROM + 0x20 * 8192, 0x10 * 8192); } else if(m_len == 0x80000) { memcpy(ROMSpace + 0x00 * 8192, HuCROM, 0x40 * 8192); memcpy(ROMSpace + 0x40 * 8192, HuCROM + 0x20 * 8192, 0x20 * 8192); memcpy(ROMSpace + 0x60 * 8192, HuCROM + 0x20 * 8192, 0x20 * 8192); } else { memcpy(ROMSpace + 0x00 * 8192, HuCROM, (m_len < 1024 * 1024) ? m_len : 1024 * 1024); } for(int x = 0x00; x < 0x80; x++) { HuCPU.FastMap[x] = &ROMSpace[x * 8192]; HuCPU.PCERead[x] = HuCRead; } if(!memcmp(HuCROM + 0x1F26, "POPULOUS", strlen("POPULOUS"))) { uint8 *PopRAM = ROMSpace + 0x40 * 8192; memset(PopRAM, 0xFF, 32768); LoadSaveMemory(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav"), PopRAM, 32768); IsPopulous = 1; MDFN_printf("Populous\n"); for(int x = 0x40; x < 0x44; x++) { HuCPU.FastMap[x] = &PopRAM[(x & 3) * 8192]; HuCPU.PCERead[x] = HuCRead; HuCPU.PCEWrite[x] = HuCRAMWrite; } MDFNMP_AddRAM(32768, 0x40 * 8192, PopRAM); } else { memset(SaveRAM, 0x00, 2048); memcpy(SaveRAM, BRAM_Init_String, 8); // So users don't have to manually intialize the file cabinet // in the CD BIOS screen. LoadSaveMemory(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav"), SaveRAM, 2048); HuCPU.PCEWrite[0xF7] = SaveRAMWrite; HuCPU.PCERead[0xF7] = SaveRAMRead; MDFNMP_AddRAM(2048, 0xF7 * 8192, SaveRAM); } // 0x1A558 //if(len >= 0x20000 && !memcmp(HuCROM + 0x1A558, "STREET FIGHTER#", strlen("STREET FIGHTER#"))) if(sf2_mapper) { for(int x = 0x40; x < 0x80; x++) { HuCPU.PCERead[x] = HuCSF2Read; } HuCPU.PCEWrite[0] = HuCSF2Write; MDFN_printf("Street Fighter 2 Mapper\n"); HuCSF2Latch = 0; } } catch(...) { Cleanup(); throw; } return crc; }
static void LoadCommonPost(const md_game_info &ginfo) { MDFN_printf(_("ROM: %dKiB\n"), (ginfo.rom_size + 1023) / 1024); MDFN_printf(_("ROM CRC32: 0x%08x\n"), ginfo.crc32); MDFN_printf(_("ROM MD5: 0x%s\n"), md5_context::asciistr(ginfo.md5, 0).c_str()); MDFN_printf(_("Header MD5: 0x%s\n"), md5_context::asciistr(ginfo.info_header_md5, 0).c_str()); MDFN_printf(_("Product Code: %s\n"), ginfo.product_code); MDFN_printf(_("Domestic name: %s\n"), ginfo.domestic_name); // TODO: Character set conversion(shift_jis -> utf-8) MDFN_printf(_("Overseas name: %s\n"), ginfo.overseas_name); MDFN_printf(_("Copyright: %s\n"), ginfo.copyright); if(ginfo.checksum == ginfo.checksum_real) MDFN_printf(_("Checksum: 0x%04x\n"), ginfo.checksum); else MDFN_printf(_("Checksum: 0x%04x\n Warning: calculated checksum(0x%04x) does not match\n"), ginfo.checksum, ginfo.checksum_real); MDFN_printf(_("Supported I/O devices:\n")); MDFN_indent(1); for(unsigned int iot = 0; iot < sizeof(IO_types) / sizeof(IO_type_t); iot++) { if(ginfo.io_support & (1 << IO_types[iot].id)) MDFN_printf(_("%s\n"), _(IO_types[iot].name)); } MDFN_indent(-1); MDFNMP_Init(8192, (1 << 24) / 8192); MDFNMP_AddRAM(65536, 0x7 << 21, work_ram); MDFNGameInfo->GameSetMD5Valid = FALSE; MDSound_Init(); MDFN_printf(_("Supported regions:\n")); MDFN_indent(1); if(ginfo.region_support & REGIONMASK_JAPAN_NTSC) MDFN_printf(_("Japan/Domestic NTSC\n")); if(ginfo.region_support & REGIONMASK_JAPAN_PAL) MDFN_printf(_("Japan/Domestic PAL\n")); if(ginfo.region_support & REGIONMASK_OVERSEAS_NTSC) MDFN_printf(_("Overseas NTSC\n")); if(ginfo.region_support & REGIONMASK_OVERSEAS_PAL) MDFN_printf(_("Overseas PAL\n")); MDFN_indent(-1); { const int region_setting = MDFN_GetSettingI("md.region"); const int reported_region_setting = MDFN_GetSettingI("md.reported_region"); // Default, in case the game doesn't support any regions! bool game_overseas = TRUE; bool game_pal = FALSE; bool overseas; bool pal; bool overseas_reported; bool pal_reported; // Preference order, TODO: Make it configurable if(ginfo.region_support & REGIONMASK_OVERSEAS_NTSC) { game_overseas = TRUE; game_pal = FALSE; } else if(ginfo.region_support & REGIONMASK_JAPAN_NTSC) { game_overseas = FALSE; game_pal = FALSE; } else if(ginfo.region_support & REGIONMASK_OVERSEAS_PAL) { game_overseas = TRUE; game_pal = TRUE; } else if(ginfo.region_support & REGIONMASK_JAPAN_PAL) // WTF? { game_overseas = FALSE; game_pal = TRUE; } if(region_setting == REGION_GAME) { overseas = game_overseas; pal = game_pal; } else { decode_region_setting(region_setting, overseas, pal); } if(reported_region_setting == REGION_GAME) { overseas_reported = game_overseas; pal_reported = game_pal; } else if(reported_region_setting == REGION_SAME) { overseas_reported = overseas; pal_reported = pal; } else { decode_region_setting(reported_region_setting, overseas_reported, pal_reported); } MDFN_printf("\n"); MDFN_printf(_("Active Region: %s %s\n"), overseas ? _("Overseas") : _("Domestic"), pal ? _("PAL") : _("NTSC")); MDFN_printf(_("Active Region Reported: %s %s\n"), overseas_reported ? _("Overseas") : _("Domestic"), pal_reported ? _("PAL") : _("NTSC")); system_init(overseas, pal, overseas_reported, pal_reported); if(pal) MDFNGameInfo->nominal_height = 240; else MDFNGameInfo->nominal_height = 224; MDFNGameInfo->MasterClock = MDFN_MASTERCLOCK_FIXED(pal ? CLOCK_PAL : CLOCK_NTSC); if(pal) MDFNGameInfo->fps = (int64)CLOCK_PAL * 65536 * 256 / (313 * 3420); else MDFNGameInfo->fps = (int64)CLOCK_NTSC * 65536 * 256 / (262 * 3420); //printf("%f\n", (double)MDFNGameInfo->fps / 65536 / 256); } if(MDFN_GetSettingB("md.correct_aspect")) { MDFNGameInfo->nominal_width = 292; MDFNGameInfo->lcm_width = 1280; } else { MDFNGameInfo->nominal_width = 320; MDFNGameInfo->lcm_width = 320; } MDFNGameInfo->lcm_height = MDFNGameInfo->nominal_height * 2; MDFNGameInfo->LayerNames = "BG0\0BG1\0OBJ\0"; // // { unsigned mtt = MDFN_GetSettingUI("md.input.multitap"); if(MDFN_GetSettingB("md.input.auto")) { for(auto const& e : InputDB) { if(e.crc32 == ginfo.crc32 && (!e.prod_code || !strcmp(e.prod_code, ginfo.product_code))) { MDFNGameInfo->DesiredInput.resize(8); for(unsigned n = e.max_players; n < 8; n++) // Particularly for Gauntlet 4. MDFNGameInfo->DesiredInput[n] = "none"; mtt = e.tap; break; } } } for(const auto* mte = MultiTap_List; mte->string; mte++) { if((unsigned)mte->number == mtt) { MDFN_printf(_("Active Multitap(s): %s\n"), mte->description); break; } } MDINPUT_SetMultitap(mtt); } // // system_reset(true); }
uint32 HuC_Load(MDFNFILE* fp, bool DisableBRAM, SysCardType syscard) { uint32 crc = 0; const uint32 sf2_threshold = 2048 * 1024; bool sf2_mapper = FALSE; bool mcg_mapper = FALSE; bool UseBRAM = FALSE; try { uint64 len, m_len; len = fp->size(); if(len & 512) // Skip copier header. { len &= ~512; fp->seek(512, SEEK_SET); } m_len = (len + 8191) &~ 8191; if(len >= 8192) { uint8 buf[8192]; fp->read(buf, 8192); if(!memcmp(buf + 0x1FD0, "MCGENJIN", 8)) mcg_mapper = TRUE; fp->seek(-8192, SEEK_CUR); // Seek backwards so we don't undo skip copier header. } if(!syscard && m_len >= sf2_threshold && !mcg_mapper) { sf2_mapper = TRUE; // Only used the "extended" SF2 mapper if it's considerably larger than the normal SF2 mapper size. if(m_len < (512 * 1024 * 6)) m_len = 512 * 1024 * 5; else m_len = round_up_pow2(m_len - 512 * 1024) + 512 * 1024; if(m_len > 8912896) throw MDFN_Error(0, _("ROM image is too large for extended SF2 mapper!")); HuCSF2BankMask = ((m_len - 512 * 1024) / (512 * 1024)) - 1; //printf("%d %d, %02x\n", len, m_len, HuCSF2BankMask); } IsPopulous = 0; PCE_IsCD = 0; if(syscard != SYSCARD_NONE) { CDRAM = new uint8[8 * 8192]; for(int x = 0x80; x < 0x88; x++) { ROMMap[x] = &CDRAM[(x - 0x80) * 8192] - x * 8192; HuCPU.SetFastRead(x, ROMMap[x] + x * 8192); HuCPU.SetReadHandler(x, CDRAMRead); HuCPU.SetWriteHandler(x, CDRAMWrite); } MDFNMP_AddRAM(8 * 8192, 0x80 * 8192, CDRAM); UseBRAM = TRUE; } if(mcg_mapper) { mcg = new MCGenjin(fp); for(unsigned i = 0; i < 128; i++) { HuCPU.SetFastRead(i, NULL); HuCPU.SetReadHandler(i, MCG_ReadHandler); HuCPU.SetWriteHandler(i, MCG_WriteHandler); } for(unsigned i = 0; i < mcg->GetNVPDC(); i++) { uint32 nvs = mcg->GetNVSize(i); if(nvs) { char buf[32]; std::vector<uint8> tmp_buf; tmp_buf.resize(nvs); trio_snprintf(buf, sizeof(buf), "mg%d", i); LoadSaveMemory(MDFN_MakeFName(MDFNMKF_SAV, 0, buf), &tmp_buf[0], tmp_buf.size(), false); mcg->WriteNV(i, &tmp_buf[0], 0, tmp_buf.size()); } } goto BRAM_Init; // SO EVIL YES EVVIIIIIL(FIXME) } HuCROM = new uint8[m_len]; memset(HuCROM, 0xFF, m_len); fp->read(HuCROM, std::min<uint64>(m_len, len)); crc = crc32(0, HuCROM, std::min<uint64>(m_len, len)); if(syscard == SYSCARD_NONE) { md5_context md5; md5.starts(); md5.update(HuCROM, std::min<uint64>(m_len, len)); md5.finish(MDFNGameInfo->MD5); MDFN_printf(_("ROM: %lluKiB\n"), (unsigned long long)(std::min<uint64>(m_len, len) / 1024)); MDFN_printf(_("ROM CRC32: 0x%08x\n"), crc); MDFN_printf(_("ROM MD5: 0x%s\n"), md5_context::asciistr(MDFNGameInfo->MD5, 0).c_str()); } if(m_len == 0x60000) { for(int x = 0; x < 128; x++) { ROMMap[x] = &HuCROM[(x & 0x1F) * 8192] - x * 8192; HuCPU.SetFastRead(x, ROMMap[x] + x * 8192); HuCPU.SetReadHandler(x, HuCRead); } for(int x = 64; x < 128; x++) { ROMMap[x] = &HuCROM[((x & 0xF) + 32) * 8192] - x * 8192; HuCPU.SetFastRead(x, ROMMap[x] + x * 8192); HuCPU.SetReadHandler(x, HuCRead); } } else if(m_len == 0x80000) { for(int x = 0; x < 64; x++) { ROMMap[x] = &HuCROM[(x & 0x3F) * 8192] - x * 8192; HuCPU.SetFastRead(x, ROMMap[x] + x * 8192); HuCPU.SetReadHandler(x, HuCRead); } for(int x = 64; x < 128; x++) { ROMMap[x] = &HuCROM[((x & 0x1F) + 32) * 8192] - x * 8192; HuCPU.SetFastRead(x, ROMMap[x] + x * 8192); HuCPU.SetReadHandler(x, HuCRead); } } else { for(int x = 0; x < 128; x++) { uint8 bank = x % (m_len / 8192); ROMMap[x] = &HuCROM[bank * 8192] - x * 8192; HuCPU.SetFastRead(x, ROMMap[x] + x * 8192); HuCPU.SetReadHandler(x, HuCRead); } } if(syscard) { if(syscard == SYSCARD_3 || syscard == SYSCARD_ARCADE) { SysCardRAM = new uint8[24 * 8192]; for(int x = 0x68; x < 0x80; x++) { ROMMap[x] = &SysCardRAM[(x - 0x68) * 8192] - x * 8192; HuCPU.SetFastRead(x, ROMMap[x] + x * 8192); HuCPU.SetReadHandler(x, SysCardRAMRead); HuCPU.SetWriteHandler(x, SysCardRAMWrite); } MDFNMP_AddRAM(24 * 8192, 0x68 * 8192, SysCardRAM); } if(syscard == SYSCARD_ARCADE) { arcade_card = new ArcadeCard(); for(int x = 0x40; x < 0x44; x++) { ROMMap[x] = NULL; HuCPU.SetFastRead(x, NULL); HuCPU.SetReadHandler(x, AC_PhysRead); HuCPU.SetWriteHandler(x, AC_PhysWrite); } } } else { if(!memcmp(HuCROM + 0x1F26, "POPULOUS", strlen("POPULOUS"))) { PopRAM = new uint8[32768]; memset(PopRAM, 0xFF, 32768); LoadSaveMemory(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav"), PopRAM, 32768); IsPopulous = 1; MDFN_printf("Populous\n"); for(int x = 0x40; x < 0x44; x++) { ROMMap[x] = &PopRAM[(x & 3) * 8192] - x * 8192; HuCPU.SetFastRead(x, ROMMap[x] + x * 8192); HuCPU.SetReadHandler(x, HuCRead); HuCPU.SetWriteHandler(x, HuCRAMWrite); } MDFNMP_AddRAM(32768, 0x40 * 8192, PopRAM); } else if(crc == 0x34dc65c4) // Tsushin Booster { TsushinRAM = new uint8[0x8000]; memset(TsushinRAM, 0xFF, 0x8000); LoadSaveMemory(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav"), TsushinRAM, 32768); IsTsushin = 1; MDFN_printf("Tsushin Booster\n"); for(int x = 0x88; x < 0x8C; x++) { ROMMap[x] = &TsushinRAM[(x & 3) * 8192] - x * 8192; HuCPU.SetFastRead(x, ROMMap[x] + x * 8192); HuCPU.SetReadHandler(x, HuCRead); HuCPU.SetWriteHandler(x, HuCRAMWrite); } MDFNMP_AddRAM(32768, 0x88 * 8192, TsushinRAM); } else UseBRAM = TRUE; // 0x1A558 if(sf2_mapper) { for(int x = 0x20; x < 0x40; x++) HuCPU.SetReadHandler(x, HuCSF2ReadLow); for(int x = 0x40; x < 0x80; x++) { HuCPU.SetFastRead(x, NULL); // Make sure our reads go through our read function, and not a table lookup HuCPU.SetReadHandler(x, HuCSF2Read); } HuCPU.SetWriteHandler(0, HuCSF2Write); MDFN_printf("Street Fighter 2 Mapper\n"); HuCSF2Latch = 0; } } // end else to if(syscard) BRAM_Init: BRAM_Disabled = DisableBRAM; if(BRAM_Disabled) UseBRAM = false; if(UseBRAM) { // Initialize BRAM here so users don't have to manually intialize the file cabinet // in the CD BIOS screen. memset(SaveRAM, 0x00, 2048); memcpy(SaveRAM, BRAM_Init_String, 8); LoadSaveMemory(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav"), SaveRAM, 2048); HuCPU.SetWriteHandler(0xF7, SaveRAMWrite); HuCPU.SetReadHandler(0xF7, SaveRAMRead); MDFNMP_AddRAM(2048, 0xF7 * 8192, SaveRAM); } } catch(...) { Cleanup(); throw; } return crc; }
static int LoadCommon(void) { IsSGX |= MDFN_GetSettingB("pce_fast.forcesgx") ? 1 : 0; if(IsHES) IsSGX = 1; // Don't modify IsSGX past this point. VDC_Init(IsSGX); if(IsSGX) { MDFN_printf("SuperGrafx Emulation Enabled.\n"); PCERead[0xF8] = PCERead[0xF9] = PCERead[0xFA] = PCERead[0xFB] = BaseRAMReadSGX; PCEWrite[0xF8] = PCEWrite[0xF9] = PCEWrite[0xFA] = PCEWrite[0xFB] = BaseRAMWriteSGX; for(int x = 0xf8; x < 0xfb; x++) HuCPUFastMap[x] = BaseRAM - 0xf8 * 8192; PCERead[0xFF] = IOReadSGX; } else { PCERead[0xF8] = BaseRAMRead; PCERead[0xF9] = PCERead[0xFA] = PCERead[0xFB] = BaseRAMRead_Mirrored; PCEWrite[0xF8] = BaseRAMWrite; PCEWrite[0xF9] = PCEWrite[0xFA] = PCEWrite[0xFB] = BaseRAMWrite_Mirrored; for(int x = 0xf8; x < 0xfb; x++) HuCPUFastMap[x] = BaseRAM - x * 8192; PCERead[0xFF] = IORead; } MDFNMP_AddRAM(IsSGX ? 32768 : 8192, 0xf8 * 8192, BaseRAM); PCEWrite[0xFF] = IOWrite; HuC6280_Init(); psg = new PCE_PSG(&sbuf[0], &sbuf[1], PCE_PSG::REVISION_ENHANCED); //HUC6280A); //psg->init(&sbuf[0], &sbuf[1], PCE_PSG::REVISION_ENHANCED); psg->SetVolume(1.0); if(PCE_IsCD) { unsigned int cdpsgvolume = MDFN_GetSettingUI("pce_fast.cdpsgvolume"); if(cdpsgvolume != 100) { MDFN_printf(_("CD PSG Volume: %d%%\n"), cdpsgvolume); } psg->SetVolume(0.678 * cdpsgvolume / 100); } PCEINPUT_Init(); PCE_Power(); MDFNGameInfo->LayerNames = IsSGX ? "BG0\0SPR0\0BG1\0SPR1\0" : "Background\0Sprites\0"; MDFNGameInfo->fps = (uint32)((double)7159090.90909090 / 455 / 263 * 65536 * 256); // Clean this up: if(!MDFN_GetSettingB("pce_fast.correct_aspect")) MDFNGameInfo->fb_width = 682; if(!IsHES) { MDFNGameInfo->nominal_width = MDFN_GetSettingB("pce_fast.correct_aspect") ? 320 : 341; MDFNGameInfo->nominal_height = MDFN_GetSettingUI("pce_fast.slend") - MDFN_GetSettingUI("pce_fast.slstart") + 1; MDFNGameInfo->lcm_width = MDFN_GetSettingB("pce_fast.correct_aspect") ? 1024 : 341; MDFNGameInfo->lcm_height = MDFNGameInfo->nominal_height; } return(1); }
static int ModuleLoad () { //Load the BIOS MDFNFILE biosFile; if(biosFile.Open(MDFN_MakeFName(MDFNMKF_FIRMWARE, 0, MDFN_GetSettingS("pcsxr.bios").c_str()).c_str(), 0)) { if(biosFile.size == 512 * 1024) { memcpy(BiosBuffer, biosFile.data, 512 * 1024); } else { MDFN_printf("pcsxr: BIOS file size incorrect\n"); } } else { MDFN_printf("pcsxr: Failed to load bios\n"); return 0; } //Setup the config structure memset(&Config, 0, sizeof(Config)); Config.PsxAuto = 1; Config.Cpu = MDFN_GetSettingB("pcsxr.recompiler") ? CPU_DYNAREC : CPU_INTERPRETER; Config.SlowBoot = MDFN_GetSettingB("pcsxr.slowboot"); strcpy(Config.PluginsDir, "builtin"); strcpy(Config.Gpu, "builtin"); strcpy(Config.Spu, "builtin"); strcpy(Config.Pad1, "builtin"); strcpy(Config.Pad2, "builtin"); strcpy(Config.Cdr, "builtin"); strcpy(Config.Net, "Disabled"); strncpy(Config.Mcd1, MDFN_MakeFName(MDFNMKF_SAV, 0, "sav").c_str(), MAXPATHLEN); strncpy(Config.Mcd2, MDFN_MakeFName(MDFNMKF_SAV, 0, "sav2").c_str(), MAXPATHLEN); //Init psx cpu emulator and memory mapping EmuInit(); //Open and initialize all of the plugins OpenPlugins(); //Load memory cards LoadMcds(Config.Mcd1, Config.Mcd2); //Get cdrom ID and init PPF support... CheckCdrom(); //Reset the emulated CPU and Memory EmuReset(); //Prepares the game to run, either runs the CPU thru the bios or finds and loads the game EXE if using the emulated bios LoadCdrom(); //TODO: Set the clock if the machine is PAL //Just say two 1M pages, for fun not profit MDFNMP_Init(1024 * 1024, 2); MDFNMP_AddRAM(1024 * 1024 * 2, 0, (uint8_t*)psxM); return 1; }
int HuCLoadCD(const char *bios_path) { static const FileExtensionSpecStruct KnownBIOSExtensions[] = { { ".pce", gettext_noop("PC Engine ROM Image") }, { ".bin", gettext_noop("PC Engine ROM Image") }, { ".bios", gettext_noop("BIOS Image") }, { NULL, NULL } }; MDFNFILE fp; if(!fp.Open(bios_path, KnownBIOSExtensions, "CD BIOS")) return(0); memset(ROMSpace, 0xFF, 262144); memcpy(ROMSpace, fp.f_data + (fp.f_size & 512), ((fp.f_size & ~512) > 262144) ? 262144 : (fp.f_size &~ 512) ); fp.Close(); PCE_IsCD = 1; PCE_InitCD(); md5_context md5; md5.starts(); MDFN_printf(_("Arcade Card Emulation: %s\n"), PCE_ACEnabled ? _("Enabled") : _("Disabled")); for(int x = 0; x < 0x40; x++) { HuCPUFastMap[x] = ROMSpace; PCERead[x] = HuCRead; } for(int x = 0x68; x < 0x88; x++) { HuCPUFastMap[x] = ROMSpace; PCERead[x] = HuCRead; PCEWrite[x] = HuCRAMWrite; } PCEWrite[0x80] = HuCRAMWriteCDSpecial; // Hyper Dyne Special hack MDFNMP_AddRAM(262144, 0x68 * 8192, ROMSpace + 0x68 * 8192); if(PCE_ACEnabled) { try { arcade_card = new ArcadeCard(); } catch(std::exception &e) { MDFN_PrintError(_("Error creating %s object: %s"), "ArcadeCard", e.what()); return(0); } for(int x = 0x40; x < 0x44; x++) { HuCPUFastMap[x] = NULL; PCERead[x] = ACPhysRead; PCEWrite[x] = ACPhysWrite; } } FILE *srp; memset(SaveRAM, 0x00, 2048); memcpy(SaveRAM, BRAM_Init_String, 8); // So users don't have to manually intialize the file cabinet // in the CD BIOS screen. if((srp = fopen(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav").c_str(), "rb"))) { fread(SaveRAM, 2048, 1, srp); fclose(srp); } PCEWrite[0xF7] = SaveRAMWrite; PCERead[0xF7] = SaveRAMRead; MDFNMP_AddRAM(2048, 0xF7 * 8192, SaveRAM); return(1); }