| 1 | #include <stdarg.h> |
| 2 | #include "mednafen/mednafen.h" |
| 3 | #include "mednafen/git.h" |
| 4 | #include "mednafen/general.h" |
| 5 | #include "libretro.h" |
| 6 | |
| 7 | #include <rthreads/rthreads.h> |
| 8 | #include <string/stdstring.h> |
| 9 | |
| 10 | #include "mednafen/pce_fast/pce.h" |
| 11 | #include "mednafen/pce_fast/vdc.h" |
| 12 | #include "mednafen/pce_fast/psg.h" |
| 13 | #include "mednafen/pce_fast/input.h" |
| 14 | #include "mednafen/pce_fast/huc.h" |
| 15 | #include "mednafen/pce_fast/pcecd.h" |
| 16 | #include "mednafen/pce_fast/pcecd_drive.h" |
| 17 | #include "mednafen/hw_misc/arcade_card/arcade_card.h" |
| 18 | #include "mednafen/mempatcher.h" |
| 19 | #include "mednafen/cdrom/cdromif.h" |
| 20 | #include "mednafen/cdrom/CDUtility.h" |
| 21 | |
| 22 | #ifdef _MSC_VER |
| 23 | #include "mednafen/msvc_compat.h" |
| 24 | #endif |
| 25 | |
| 26 | static bool old_cdimagecache = false; |
| 27 | |
| 28 | extern MDFNGI EmulatedPCE_Fast; |
| 29 | MDFNGI *MDFNGameInfo = &EmulatedPCE_Fast; |
| 30 | |
| 31 | /* Mednafen - Multi-system Emulator |
| 32 | * |
| 33 | * This program is free software; you can redistribute it and/or modify |
| 34 | * it under the terms of the GNU General Public License as published by |
| 35 | * the Free Software Foundation; either version 2 of the License, or |
| 36 | * (at your option) any later version. |
| 37 | * |
| 38 | * This program is distributed in the hope that it will be useful, |
| 39 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 40 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 41 | * GNU General Public License for more details. |
| 42 | * |
| 43 | * You should have received a copy of the GNU General Public License |
| 44 | * along with this program; if not, write to the Free Software |
| 45 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 46 | */ |
| 47 | |
| 48 | extern "C" unsigned long crc32(unsigned long crc, const unsigned char *buf, unsigned int len); |
| 49 | |
| 50 | static PCEFast_PSG *psg = NULL; |
| 51 | extern ArcadeCard *arcade_card; // Bah, lousy globals. |
| 52 | |
| 53 | static Blip_Buffer sbuf[2]; |
| 54 | |
| 55 | bool PCE_ACEnabled; |
| 56 | |
| 57 | int pce_overclocked; |
| 58 | |
| 59 | // Statically allocated for speed...or something. |
| 60 | uint8 ROMSpace[0x88 * 8192 + 8192]; // + 8192 for PC-as-pointer safety padding |
| 61 | |
| 62 | uint8 BaseRAM[32768 + 8192]; // 8KB for PCE, 32KB for Super Grafx // + 8192 for PC-as-pointer safety padding |
| 63 | |
| 64 | uint8 PCEIODataBuffer; |
| 65 | readfunc PCERead[0x100]; |
| 66 | writefunc PCEWrite[0x100]; |
| 67 | |
| 68 | static DECLFR(PCEBusRead) |
| 69 | { |
| 70 | //printf("BUS Read: %02x %04x\n", A >> 13, A); |
| 71 | return(0xFF); |
| 72 | } |
| 73 | |
| 74 | static DECLFW(PCENullWrite) |
| 75 | { |
| 76 | //printf("Null Write: %02x, %08x %02x\n", A >> 13, A, V); |
| 77 | } |
| 78 | |
| 79 | static DECLFR(BaseRAMRead) |
| 80 | { |
| 81 | return((BaseRAM - (0xF8 * 8192))[A]); |
| 82 | } |
| 83 | |
| 84 | static DECLFR(BaseRAMRead_Mirrored) |
| 85 | { |
| 86 | return(BaseRAM[A & 0x1FFF]); |
| 87 | } |
| 88 | |
| 89 | static DECLFW(BaseRAMWrite) |
| 90 | { |
| 91 | (BaseRAM - (0xF8 * 8192))[A] = V; |
| 92 | } |
| 93 | |
| 94 | static DECLFW(BaseRAMWrite_Mirrored) |
| 95 | { |
| 96 | BaseRAM[A & 0x1FFF] = V; |
| 97 | } |
| 98 | |
| 99 | static DECLFR(IORead) |
| 100 | { |
| 101 | #include "mednafen/pce_fast/ioread.inc" |
| 102 | } |
| 103 | |
| 104 | static DECLFW(IOWrite) |
| 105 | { |
| 106 | A &= 0x1FFF; |
| 107 | |
| 108 | switch(A >> 10) |
| 109 | { |
| 110 | case 0: HuC6280_StealCycle(); |
| 111 | VDC_Write(A, V); |
| 112 | break; |
| 113 | |
| 114 | case 1: HuC6280_StealCycle(); |
| 115 | VCE_Write(A, V); |
| 116 | break; |
| 117 | |
| 118 | case 2: PCEIODataBuffer = V; |
| 119 | psg->Write(HuCPU.timestamp / pce_overclocked, A, V); |
| 120 | break; |
| 121 | |
| 122 | case 3: PCEIODataBuffer = V; |
| 123 | HuC6280_TimerWrite(A, V); |
| 124 | break; |
| 125 | |
| 126 | case 4: PCEIODataBuffer = V; INPUT_Write(A, V); break; |
| 127 | case 5: PCEIODataBuffer = V; HuC6280_IRQStatusWrite(A, V); break; |
| 128 | case 6: |
| 129 | if(!PCE_IsCD) |
| 130 | break; |
| 131 | |
| 132 | if((A & 0x1E00) == 0x1A00) |
| 133 | { |
| 134 | if(arcade_card) |
| 135 | arcade_card->Write(A & 0x1FFF, V); |
| 136 | } |
| 137 | else |
| 138 | { |
| 139 | PCECD_Write(HuCPU.timestamp * 3, A, V); |
| 140 | } |
| 141 | break; |
| 142 | |
| 143 | case 7: break; // Expansion. |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | static void PCECDIRQCB(bool asserted) |
| 148 | { |
| 149 | if(asserted) |
| 150 | HuC6280_IRQBegin(MDFN_IQIRQ2); |
| 151 | else |
| 152 | HuC6280_IRQEnd(MDFN_IQIRQ2); |
| 153 | } |
| 154 | |
| 155 | bool PCE_InitCD(void) |
| 156 | { |
| 157 | PCECD_Settings cd_settings; |
| 158 | memset(&cd_settings, 0, sizeof(PCECD_Settings)); |
| 159 | |
| 160 | cd_settings.CDDA_Volume = (double)MDFN_GetSettingUI("pce_fast.cddavolume") / 100; |
| 161 | cd_settings.CD_Speed = MDFN_GetSettingUI("pce_fast.cdspeed"); |
| 162 | |
| 163 | cd_settings.ADPCM_Volume = (double)MDFN_GetSettingUI("pce_fast.adpcmvolume") / 100; |
| 164 | cd_settings.ADPCM_LPF = MDFN_GetSettingB("pce_fast.adpcmlp"); |
| 165 | |
| 166 | if(cd_settings.CDDA_Volume != 1.0) |
| 167 | MDFN_printf(_("CD-DA Volume: %d%%\n"), (int)(100 * cd_settings.CDDA_Volume)); |
| 168 | |
| 169 | if(cd_settings.ADPCM_Volume != 1.0) |
| 170 | MDFN_printf(_("ADPCM Volume: %d%%\n"), (int)(100 * cd_settings.ADPCM_Volume)); |
| 171 | |
| 172 | return(PCECD_Init(&cd_settings, PCECDIRQCB, PCE_MASTER_CLOCK, pce_overclocked, &sbuf[0], &sbuf[1])); |
| 173 | } |
| 174 | |
| 175 | |
| 176 | static int LoadCommon(void); |
| 177 | static void LoadCommonPre(void); |
| 178 | |
| 179 | static bool TestMagic(const char *name, MDFNFILE *fp) |
| 180 | { |
| 181 | return(TRUE); |
| 182 | } |
| 183 | |
| 184 | static int Load(const char *name, MDFNFILE *fp) |
| 185 | { |
| 186 | uint32 headerlen = 0; |
| 187 | uint32 r_size; |
| 188 | |
| 189 | LoadCommonPre(); |
| 190 | |
| 191 | { |
| 192 | if(GET_FSIZE_PTR(fp) & 0x200) // 512 byte header! |
| 193 | headerlen = 512; |
| 194 | } |
| 195 | |
| 196 | r_size = GET_FSIZE_PTR(fp) - headerlen; |
| 197 | if(r_size > 4096 * 1024) r_size = 4096 * 1024; |
| 198 | |
| 199 | for(int x = 0; x < 0x100; x++) |
| 200 | { |
| 201 | PCERead[x] = PCEBusRead; |
| 202 | PCEWrite[x] = PCENullWrite; |
| 203 | } |
| 204 | |
| 205 | uint32 crc = crc32(0, GET_FDATA_PTR(fp) + headerlen, GET_FSIZE_PTR(fp) - headerlen); |
| 206 | |
| 207 | HuCLoad(GET_FDATA_PTR(fp) + headerlen, GET_FSIZE_PTR(fp) - headerlen, crc); |
| 208 | |
| 209 | return(LoadCommon()); |
| 210 | } |
| 211 | |
| 212 | static void LoadCommonPre(void) |
| 213 | { |
| 214 | // FIXME: Make these globals less global! |
| 215 | pce_overclocked = MDFN_GetSettingUI("pce_fast.ocmultiplier"); |
| 216 | PCE_ACEnabled = MDFN_GetSettingB("pce_fast.arcadecard"); |
| 217 | |
| 218 | if(pce_overclocked > 1) |
| 219 | MDFN_printf(_("CPU overclock: %dx\n"), pce_overclocked); |
| 220 | |
| 221 | if(MDFN_GetSettingUI("pce_fast.cdspeed") > 1) |
| 222 | MDFN_printf(_("CD-ROM speed: %ux\n"), (unsigned int)MDFN_GetSettingUI("pce_fast.cdspeed")); |
| 223 | |
| 224 | memset(HuCPUFastMap, 0, sizeof(HuCPUFastMap)); |
| 225 | for(int x = 0; x < 0x100; x++) |
| 226 | { |
| 227 | PCERead[x] = PCEBusRead; |
| 228 | PCEWrite[x] = PCENullWrite; |
| 229 | } |
| 230 | |
| 231 | MDFNMP_Init(1024, (1 << 21) / 1024); |
| 232 | } |
| 233 | |
| 234 | static int LoadCommon(void) |
| 235 | { |
| 236 | VDC_Init(false); |
| 237 | |
| 238 | { |
| 239 | PCERead[0xF8] = BaseRAMRead; |
| 240 | PCERead[0xF9] = PCERead[0xFA] = PCERead[0xFB] = BaseRAMRead_Mirrored; |
| 241 | |
| 242 | PCEWrite[0xF8] = BaseRAMWrite; |
| 243 | PCEWrite[0xF9] = PCEWrite[0xFA] = PCEWrite[0xFB] = BaseRAMWrite_Mirrored; |
| 244 | |
| 245 | for(int x = 0xf8; x < 0xfb; x++) |
| 246 | HuCPUFastMap[x] = BaseRAM - x * 8192; |
| 247 | |
| 248 | PCERead[0xFF] = IORead; |
| 249 | } |
| 250 | |
| 251 | MDFNMP_AddRAM(8192, 0xf8 * 8192, BaseRAM); |
| 252 | |
| 253 | PCEWrite[0xFF] = IOWrite; |
| 254 | |
| 255 | HuC6280_Init(); |
| 256 | |
| 257 | psg = new PCEFast_PSG(&sbuf[0], &sbuf[1]); |
| 258 | |
| 259 | psg->SetVolume(1.0); |
| 260 | |
| 261 | if(PCE_IsCD) |
| 262 | { |
| 263 | unsigned int cdpsgvolume = MDFN_GetSettingUI("pce_fast.cdpsgvolume"); |
| 264 | |
| 265 | if(cdpsgvolume != 100) |
| 266 | { |
| 267 | MDFN_printf(_("CD PSG Volume: %d%%\n"), cdpsgvolume); |
| 268 | } |
| 269 | |
| 270 | psg->SetVolume(0.678 * cdpsgvolume / 100); |
| 271 | |
| 272 | } |
| 273 | |
| 274 | PCEINPUT_Init(); |
| 275 | |
| 276 | PCE_Power(); |
| 277 | |
| 278 | MDFNGameInfo->LayerNames = "Background\0Sprites\0"; |
| 279 | MDFNGameInfo->fps = (uint32)((double)7159090.90909090 / 455 / 263 * 65536 * 256); |
| 280 | |
| 281 | // Clean this up: |
| 282 | if(!MDFN_GetSettingB("pce_fast.correct_aspect")) |
| 283 | MDFNGameInfo->fb_width = 682; |
| 284 | |
| 285 | MDFNGameInfo->nominal_width = MDFN_GetSettingB("pce_fast.correct_aspect") ? 288 : 341; |
| 286 | MDFNGameInfo->nominal_height = MDFN_GetSettingUI("pce_fast.slend") - MDFN_GetSettingUI("pce_fast.slstart") + 1; |
| 287 | |
| 288 | MDFNGameInfo->lcm_width = MDFN_GetSettingB("pce_fast.correct_aspect") ? 1024 : 341; |
| 289 | MDFNGameInfo->lcm_height = MDFNGameInfo->nominal_height; |
| 290 | |
| 291 | return(1); |
| 292 | } |
| 293 | |
| 294 | static bool TestMagicCD(std::vector<CDIF *> *CDInterfaces) |
| 295 | { |
| 296 | static const uint8 magic_test[0x20] = { 0x82, 0xB1, 0x82, 0xCC, 0x83, 0x76, 0x83, 0x8D, 0x83, 0x4F, 0x83, 0x89, 0x83, 0x80, 0x82, 0xCC, |
| 297 | 0x92, 0x98, 0x8D, 0xEC, 0x8C, 0xA0, 0x82, 0xCD, 0x8A, 0x94, 0x8E, 0xAE, 0x89, 0xEF, 0x8E, 0xD0 |
| 298 | }; |
| 299 | uint8 sector_buffer[2048]; |
| 300 | CDIF *cdiface = (*CDInterfaces)[0]; |
| 301 | CDUtility::TOC toc; |
| 302 | bool ret = FALSE; |
| 303 | |
| 304 | memset(sector_buffer, 0, sizeof(sector_buffer)); |
| 305 | |
| 306 | cdiface->ReadTOC(&toc); |
| 307 | |
| 308 | for(int32 track = toc.first_track; track <= toc.last_track; track++) |
| 309 | { |
| 310 | if(toc.tracks[track].control & 0x4) |
| 311 | { |
| 312 | cdiface->ReadSector(sector_buffer, toc.tracks[track].lba, 1); |
| 313 | |
| 314 | if(!memcmp((char*)sector_buffer, (char *)magic_test, 0x20)) |
| 315 | ret = TRUE; |
| 316 | |
| 317 | // PCE CD BIOS apparently only looks at the first data track. |
| 318 | break; |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | |
| 323 | // If it's a PC-FX CD(Battle Heat), return false. |
| 324 | // This is very kludgy. |
| 325 | for(int32 track = toc.first_track; track <= toc.last_track; track++) |
| 326 | { |
| 327 | if(toc.tracks[track].control & 0x4) |
| 328 | { |
| 329 | cdiface->ReadSector(sector_buffer, toc.tracks[track].lba, 1); |
| 330 | if(!strncmp("PC-FX:Hu_CD-ROM", (char*)sector_buffer, strlen("PC-FX:Hu_CD-ROM"))) |
| 331 | { |
| 332 | return(false); |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | |
| 338 | // Now, test for the Games Express CD games. The GE BIOS seems to always look at sector 0x10, but only if the first track is a |
| 339 | // data track. |
| 340 | if(toc.first_track == 1 && (toc.tracks[1].control & 0x4)) |
| 341 | { |
| 342 | if(cdiface->ReadSector(sector_buffer, 0x10, 1)) |
| 343 | { |
| 344 | if(!memcmp((char *)sector_buffer + 0x8, "HACKER CD ROM SYSTEM", 0x14)) |
| 345 | { |
| 346 | ret = TRUE; |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | return(ret); |
| 352 | } |
| 353 | |
| 354 | static int LoadCD(std::vector<CDIF *> *CDInterfaces) |
| 355 | { |
| 356 | std::string bios_path = MDFN_MakeFName(MDFNMKF_FIRMWARE, 0, MDFN_GetSettingS("pce_fast.cdbios").c_str() ); |
| 357 | |
| 358 | LoadCommonPre(); |
| 359 | |
| 360 | if(!HuCLoadCD(bios_path.c_str())) |
| 361 | return(0); |
| 362 | |
| 363 | PCECD_Drive_SetDisc(true, NULL, true); |
| 364 | PCECD_Drive_SetDisc(false, (*CDInterfaces)[0], true); |
| 365 | |
| 366 | return(LoadCommon()); |
| 367 | } |
| 368 | |
| 369 | static void Cleanup_PCE(void) |
| 370 | { |
| 371 | HuC_Close(); |
| 372 | |
| 373 | VDC_Close(); |
| 374 | |
| 375 | if(psg) |
| 376 | delete psg; |
| 377 | psg = NULL; |
| 378 | } |
| 379 | |
| 380 | static void CloseGame(void) |
| 381 | { |
| 382 | Cleanup_PCE(); |
| 383 | } |
| 384 | |
| 385 | static void Emulate(EmulateSpecStruct *espec) |
| 386 | { |
| 387 | INPUT_Frame(); |
| 388 | |
| 389 | MDFNMP_ApplyPeriodicCheats(); |
| 390 | |
| 391 | #if 0 |
| 392 | { |
| 393 | static bool firstcat = true; |
| 394 | MDFN_PixelFormat nf; |
| 395 | |
| 396 | nf.bpp = 16; |
| 397 | nf.colorspace = MDFN_COLORSPACE_RGB; |
| 398 | nf.Rshift = 11; |
| 399 | nf.Gshift = 5; |
| 400 | nf.Bshift = 0; |
| 401 | nf.Ashift = 16; |
| 402 | |
| 403 | nf.Rprec = 5; |
| 404 | nf.Gprec = 6; |
| 405 | nf.Bprec = 5; |
| 406 | nf.Aprec = 8; |
| 407 | |
| 408 | espec->surface->SetFormat(nf, false); |
| 409 | espec->VideoFormatChanged = firstcat; |
| 410 | firstcat = false; |
| 411 | } |
| 412 | #endif |
| 413 | |
| 414 | |
| 415 | if(espec->SoundFormatChanged) |
| 416 | { |
| 417 | for(int y = 0; y < 2; y++) |
| 418 | { |
| 419 | sbuf[y].set_sample_rate(espec->SoundRate ? espec->SoundRate : 44100, 50); |
| 420 | sbuf[y].clock_rate((long)(PCE_MASTER_CLOCK / 3)); |
| 421 | sbuf[y].bass_freq(10); |
| 422 | } |
| 423 | } |
| 424 | VDC_RunFrame(espec, false); |
| 425 | |
| 426 | if(PCE_IsCD) |
| 427 | { |
| 428 | PCECD_Run(HuCPU.timestamp * 3); |
| 429 | } |
| 430 | |
| 431 | psg->EndFrame(HuCPU.timestamp / pce_overclocked); |
| 432 | |
| 433 | if(espec->SoundBuf) |
| 434 | { |
| 435 | for(int y = 0; y < 2; y++) |
| 436 | { |
| 437 | sbuf[y].end_frame(HuCPU.timestamp / pce_overclocked); |
| 438 | espec->SoundBufSize = sbuf[y].read_samples(espec->SoundBuf + y, espec->SoundBufMaxSize, 1); |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | espec->MasterCycles = HuCPU.timestamp * 3; |
| 443 | |
| 444 | INPUT_FixTS(); |
| 445 | |
| 446 | HuC6280_ResetTS(); |
| 447 | |
| 448 | if(PCE_IsCD) |
| 449 | PCECD_ResetTS(); |
| 450 | } |
| 451 | |
| 452 | static int StateAction(StateMem *sm, int load, int data_only) |
| 453 | { |
| 454 | SFORMAT StateRegs[] = |
| 455 | { |
| 456 | SFARRAY(BaseRAM, 8192), |
| 457 | SFVAR(PCEIODataBuffer), |
| 458 | SFEND |
| 459 | }; |
| 460 | |
| 461 | //for(int i = 8192; i < 32768; i++) |
| 462 | // if(BaseRAM[i] != 0xFF) |
| 463 | // printf("%d %02x\n", i, BaseRAM[i]); |
| 464 | |
| 465 | int ret = MDFNSS_StateAction(sm, load, data_only, StateRegs, "MAIN"); |
| 466 | |
| 467 | ret &= HuC6280_StateAction(sm, load, data_only); |
| 468 | ret &= VDC_StateAction(sm, load, data_only); |
| 469 | ret &= psg->StateAction(sm, load, data_only); |
| 470 | ret &= INPUT_StateAction(sm, load, data_only); |
| 471 | ret &= HuC_StateAction(sm, load, data_only); |
| 472 | |
| 473 | if(load) |
| 474 | { |
| 475 | |
| 476 | } |
| 477 | |
| 478 | return(ret); |
| 479 | } |
| 480 | |
| 481 | void PCE_Power(void) |
| 482 | { |
| 483 | memset(BaseRAM, 0x00, sizeof(BaseRAM)); |
| 484 | |
| 485 | for(int i = 8192; i < 32768; i++) |
| 486 | BaseRAM[i] = 0xFF; |
| 487 | |
| 488 | PCEIODataBuffer = 0xFF; |
| 489 | |
| 490 | HuC6280_Power(); |
| 491 | VDC_Power(); |
| 492 | psg->Power(HuCPU.timestamp / pce_overclocked); |
| 493 | HuC_Power(); |
| 494 | |
| 495 | if(PCE_IsCD) |
| 496 | { |
| 497 | PCECD_Power(HuCPU.timestamp * 3); |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | static void DoSimpleCommand(int cmd) |
| 502 | { |
| 503 | switch(cmd) |
| 504 | { |
| 505 | case MDFN_MSC_RESET: PCE_Power(); break; |
| 506 | case MDFN_MSC_POWER: PCE_Power(); break; |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | static MDFNSetting PCESettings[] = |
| 511 | { |
| 512 | { "pce_fast.correct_aspect", MDFNSF_CAT_VIDEO, gettext_noop("Correct the aspect ratio."), NULL, MDFNST_BOOL, "1" }, |
| 513 | { "pce_fast.slstart", MDFNSF_NOFLAGS, gettext_noop("First rendered scanline."), NULL, MDFNST_UINT, "4", "0", "239" }, |
| 514 | { "pce_fast.slend", MDFNSF_NOFLAGS, gettext_noop("Last rendered scanline."), NULL, MDFNST_UINT, "235", "0", "239" }, |
| 515 | { "pce_fast.mouse_sensitivity", MDFNSF_NOFLAGS, gettext_noop("Mouse sensitivity."), NULL, MDFNST_FLOAT, "0.50", NULL, NULL, NULL, PCEINPUT_SettingChanged }, |
| 516 | { "pce_fast.disable_softreset", MDFNSF_NOFLAGS, gettext_noop("If set, when RUN+SEL are pressed simultaneously, disable both buttons temporarily."), NULL, MDFNST_BOOL, "0", NULL, NULL, NULL, PCEINPUT_SettingChanged }, |
| 517 | { "pce_fast.arcadecard", MDFNSF_EMU_STATE | MDFNSF_UNTRUSTED_SAFE, gettext_noop("Enable Arcade Card emulation."), NULL, MDFNST_BOOL, "1" }, |
| 518 | { "pce_fast.ocmultiplier", MDFNSF_EMU_STATE | MDFNSF_UNTRUSTED_SAFE, gettext_noop("CPU overclock multiplier."), NULL, MDFNST_UINT, "1", "1", "100"}, |
| 519 | { "pce_fast.cdspeed", MDFNSF_EMU_STATE | MDFNSF_UNTRUSTED_SAFE, gettext_noop("CD-ROM data transfer speed multiplier."), NULL, MDFNST_UINT, "1", "1", "100" }, |
| 520 | { "pce_fast.nospritelimit", MDFNSF_NOFLAGS, gettext_noop("Remove 16-sprites-per-scanline hardware limit."), NULL, MDFNST_BOOL, "0" }, |
| 521 | |
| 522 | { "pce_fast.cdbios", MDFNSF_EMU_STATE, gettext_noop("Path to the CD BIOS"), NULL, MDFNST_STRING, "syscard3.pce" }, |
| 523 | |
| 524 | { "pce_fast.adpcmlp", MDFNSF_NOFLAGS, gettext_noop("Enable dynamic ADPCM lowpass filter."), NULL, MDFNST_BOOL, "0" }, |
| 525 | { "pce_fast.cdpsgvolume", MDFNSF_NOFLAGS, gettext_noop("PSG volume when playing a CD game."), NULL, MDFNST_UINT, "100", "0", "200" }, |
| 526 | { "pce_fast.cddavolume", MDFNSF_NOFLAGS, gettext_noop("CD-DA volume."), NULL, MDFNST_UINT, "100", "0", "200" }, |
| 527 | { "pce_fast.adpcmvolume", MDFNSF_NOFLAGS, gettext_noop("ADPCM volume."), NULL, MDFNST_UINT, "100", "0", "200" }, |
| 528 | { NULL } |
| 529 | }; |
| 530 | |
| 531 | static uint8 MemRead(uint32 addr) |
| 532 | { |
| 533 | return(PCERead[(addr / 8192) & 0xFF](addr)); |
| 534 | } |
| 535 | |
| 536 | static const FileExtensionSpecStruct KnownExtensions[] = |
| 537 | { |
| 538 | { ".pce", gettext_noop("PC Engine ROM Image") }, |
| 539 | { NULL, NULL } |
| 540 | }; |
| 541 | |
| 542 | static const uint8 BRAM_Init_String[8] = { 'H', 'U', 'B', 'M', 0x00, 0x88, 0x10, 0x80 }; //"HUBM\x00\x88\x10\x80"; |
| 543 | |
| 544 | ArcadeCard *arcade_card = NULL; |
| 545 | |
| 546 | static uint8 *HuCROM = NULL; |
| 547 | |
| 548 | static bool IsPopulous; |
| 549 | bool PCE_IsCD; |
| 550 | |
| 551 | uint8 SaveRAM[2048]; |
| 552 | |
| 553 | static DECLFW(ACPhysWrite) |
| 554 | { |
| 555 | arcade_card->PhysWrite(A, V); |
| 556 | } |
| 557 | |
| 558 | static DECLFR(ACPhysRead) |
| 559 | { |
| 560 | return(arcade_card->PhysRead(A)); |
| 561 | } |
| 562 | |
| 563 | static DECLFR(SaveRAMRead) |
| 564 | { |
| 565 | if((!PCE_IsCD || PCECD_IsBRAMEnabled()) && (A & 8191) < 2048) |
| 566 | return(SaveRAM[A & 2047]); |
| 567 | else |
| 568 | return(0xFF); |
| 569 | } |
| 570 | |
| 571 | static DECLFW(SaveRAMWrite) |
| 572 | { |
| 573 | if((!PCE_IsCD || PCECD_IsBRAMEnabled()) && (A & 8191) < 2048) |
| 574 | SaveRAM[A & 2047] = V; |
| 575 | } |
| 576 | |
| 577 | static DECLFR(HuCRead) |
| 578 | { |
| 579 | return ROMSpace[A]; |
| 580 | } |
| 581 | |
| 582 | static DECLFW(HuCRAMWrite) |
| 583 | { |
| 584 | ROMSpace[A] = V; |
| 585 | } |
| 586 | |
| 587 | static DECLFW(HuCRAMWriteCDSpecial) // Hyper Dyne Special hack |
| 588 | { |
| 589 | BaseRAM[0x2000 | (A & 0x1FFF)] = V; |
| 590 | ROMSpace[A] = V; |
| 591 | } |
| 592 | |
| 593 | static uint8 HuCSF2Latch = 0; |
| 594 | |
| 595 | static DECLFR(HuCSF2Read) |
| 596 | { |
| 597 | return(HuCROM[(A & 0x7FFFF) + 0x80000 + HuCSF2Latch * 0x80000 ]); // | (HuCSF2Latch << 19) ]); |
| 598 | } |
| 599 | |
| 600 | static DECLFW(HuCSF2Write) |
| 601 | { |
| 602 | if((A & 0x1FFC) == 0x1FF0) |
| 603 | { |
| 604 | HuCSF2Latch = (A & 0x3); |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | static void Cleanup(void) |
| 609 | { |
| 610 | if(arcade_card) |
| 611 | delete arcade_card; |
| 612 | arcade_card = NULL; |
| 613 | |
| 614 | if(PCE_IsCD) |
| 615 | PCECD_Close(); |
| 616 | |
| 617 | if(HuCROM) |
| 618 | free(HuCROM); |
| 619 | HuCROM = NULL; |
| 620 | } |
| 621 | |
| 622 | int HuCLoad(const uint8 *data, uint32 len, uint32 crc32) |
| 623 | { |
| 624 | uint32 sf2_threshold = 2048 * 1024; |
| 625 | uint32 sf2_required_size = 2048 * 1024 + 512 * 1024; |
| 626 | uint32 m_len = (len + 8191)&~8191; |
| 627 | bool sf2_mapper = FALSE; |
| 628 | |
| 629 | if(m_len >= sf2_threshold) |
| 630 | { |
| 631 | sf2_mapper = TRUE; |
| 632 | |
| 633 | if(m_len != sf2_required_size) |
| 634 | m_len = sf2_required_size; |
| 635 | } |
| 636 | |
| 637 | IsPopulous = 0; |
| 638 | PCE_IsCD = 0; |
| 639 | |
| 640 | |
| 641 | MDFN_printf(_("ROM: %dKiB\n"), (len + 1023) / 1024); |
| 642 | MDFN_printf(_("ROM CRC32: 0x%04x\n"), crc32); |
| 643 | |
| 644 | if(!(HuCROM = (uint8 *)malloc(m_len))) |
| 645 | { |
| 646 | return(0); |
| 647 | } |
| 648 | |
| 649 | memset(HuCROM, 0xFF, m_len); |
| 650 | memcpy(HuCROM, data, (m_len < len) ? m_len : len); |
| 651 | |
| 652 | memset(ROMSpace, 0xFF, 0x88 * 8192 + 8192); |
| 653 | |
| 654 | if(m_len == 0x60000) |
| 655 | { |
| 656 | memcpy(ROMSpace + 0x00 * 8192, HuCROM, 0x20 * 8192); |
| 657 | memcpy(ROMSpace + 0x20 * 8192, HuCROM, 0x20 * 8192); |
| 658 | memcpy(ROMSpace + 0x40 * 8192, HuCROM + 0x20 * 8192, 0x10 * 8192); |
| 659 | memcpy(ROMSpace + 0x50 * 8192, HuCROM + 0x20 * 8192, 0x10 * 8192); |
| 660 | memcpy(ROMSpace + 0x60 * 8192, HuCROM + 0x20 * 8192, 0x10 * 8192); |
| 661 | memcpy(ROMSpace + 0x70 * 8192, HuCROM + 0x20 * 8192, 0x10 * 8192); |
| 662 | } |
| 663 | else if(m_len == 0x80000) |
| 664 | { |
| 665 | memcpy(ROMSpace + 0x00 * 8192, HuCROM, 0x40 * 8192); |
| 666 | memcpy(ROMSpace + 0x40 * 8192, HuCROM + 0x20 * 8192, 0x20 * 8192); |
| 667 | memcpy(ROMSpace + 0x60 * 8192, HuCROM + 0x20 * 8192, 0x20 * 8192); |
| 668 | } |
| 669 | else |
| 670 | { |
| 671 | memcpy(ROMSpace + 0x00 * 8192, HuCROM, (m_len < 1024 * 1024) ? m_len : 1024 * 1024); |
| 672 | } |
| 673 | |
| 674 | for(int x = 0x00; x < 0x80; x++) |
| 675 | { |
| 676 | HuCPUFastMap[x] = ROMSpace; |
| 677 | PCERead[x] = HuCRead; |
| 678 | } |
| 679 | |
| 680 | if(!memcmp(HuCROM + 0x1F26, "POPULOUS", strlen("POPULOUS"))) |
| 681 | { |
| 682 | uint8 *PopRAM = ROMSpace + 0x40 * 8192; |
| 683 | |
| 684 | memset(PopRAM, 0xFF, 32768); |
| 685 | |
| 686 | IsPopulous = 1; |
| 687 | |
| 688 | MDFN_printf("Populous\n"); |
| 689 | |
| 690 | for(int x = 0x40; x < 0x44; x++) |
| 691 | { |
| 692 | HuCPUFastMap[x] = &PopRAM[(x & 3) * 8192] - x * 8192; |
| 693 | PCERead[x] = HuCRead; |
| 694 | PCEWrite[x] = HuCRAMWrite; |
| 695 | } |
| 696 | MDFNMP_AddRAM(32768, 0x40 * 8192, PopRAM); |
| 697 | } |
| 698 | else |
| 699 | { |
| 700 | memset(SaveRAM, 0x00, 2048); |
| 701 | memcpy(SaveRAM, BRAM_Init_String, 8); // So users don't have to manually intialize the file cabinet |
| 702 | // in the CD BIOS screen. |
| 703 | PCEWrite[0xF7] = SaveRAMWrite; |
| 704 | PCERead[0xF7] = SaveRAMRead; |
| 705 | MDFNMP_AddRAM(2048, 0xF7 * 8192, SaveRAM); |
| 706 | } |
| 707 | |
| 708 | // 0x1A558 |
| 709 | //if(len >= 0x20000 && !memcmp(HuCROM + 0x1A558, "STREET FIGHTER#", strlen("STREET FIGHTER#"))) |
| 710 | if(sf2_mapper) |
| 711 | { |
| 712 | for(int x = 0x40; x < 0x80; x++) |
| 713 | { |
| 714 | // FIXME: PCE_FAST |
| 715 | HuCPUFastMap[x] = NULL; // Make sure our reads go through our read function, and not a table lookup |
| 716 | PCERead[x] = HuCSF2Read; |
| 717 | } |
| 718 | PCEWrite[0] = HuCSF2Write; |
| 719 | MDFN_printf("Street Fighter 2 Mapper\n"); |
| 720 | HuCSF2Latch = 0; |
| 721 | } |
| 722 | |
| 723 | return(1); |
| 724 | } |
| 725 | |
| 726 | bool IsBRAMUsed(void) |
| 727 | { |
| 728 | if(memcmp(SaveRAM, BRAM_Init_String, 8)) // HUBM string is modified/missing |
| 729 | return(1); |
| 730 | |
| 731 | for(int x = 8; x < 2048; x++) |
| 732 | if(SaveRAM[x]) return(1); |
| 733 | |
| 734 | return(0); |
| 735 | } |
| 736 | |
| 737 | int HuCLoadCD(const char *bios_path) |
| 738 | { |
| 739 | static const FileExtensionSpecStruct KnownBIOSExtensions[] = |
| 740 | { |
| 741 | { ".pce", gettext_noop("PC Engine ROM Image") }, |
| 742 | { ".bin", gettext_noop("PC Engine ROM Image") }, |
| 743 | { ".bios", gettext_noop("BIOS Image") }, |
| 744 | { NULL, NULL } |
| 745 | }; |
| 746 | |
| 747 | MDFNFILE fp; |
| 748 | |
| 749 | if(!fp.Open(bios_path, KnownBIOSExtensions, _("CD BIOS"))) |
| 750 | { |
| 751 | return(0); |
| 752 | } |
| 753 | |
| 754 | memset(ROMSpace, 0xFF, 262144); |
| 755 | |
| 756 | memcpy(ROMSpace, GET_FDATA(fp) + (GET_FSIZE(fp) & 512), ((GET_FSIZE(fp) & ~512) > 262144) ? 262144 : (GET_FSIZE(fp) &~ 512) ); |
| 757 | |
| 758 | fp.Close(); |
| 759 | |
| 760 | PCE_IsCD = 1; |
| 761 | PCE_InitCD(); |
| 762 | |
| 763 | MDFN_printf(_("Arcade Card Emulation: %s\n"), PCE_ACEnabled ? _("Enabled") : _("Disabled")); |
| 764 | for(int x = 0; x < 0x40; x++) |
| 765 | { |
| 766 | HuCPUFastMap[x] = ROMSpace; |
| 767 | PCERead[x] = HuCRead; |
| 768 | } |
| 769 | |
| 770 | for(int x = 0x68; x < 0x88; x++) |
| 771 | { |
| 772 | HuCPUFastMap[x] = ROMSpace; |
| 773 | PCERead[x] = HuCRead; |
| 774 | PCEWrite[x] = HuCRAMWrite; |
| 775 | } |
| 776 | PCEWrite[0x80] = HuCRAMWriteCDSpecial; // Hyper Dyne Special hack |
| 777 | MDFNMP_AddRAM(262144, 0x68 * 8192, ROMSpace + 0x68 * 8192); |
| 778 | |
| 779 | if(PCE_ACEnabled) |
| 780 | { |
| 781 | if (!(arcade_card = new ArcadeCard())) |
| 782 | { |
| 783 | MDFN_PrintError(_("Error creating %s object.\n"), "ArcadeCard"); |
| 784 | Cleanup(); |
| 785 | return(0); |
| 786 | } |
| 787 | |
| 788 | for(int x = 0x40; x < 0x44; x++) |
| 789 | { |
| 790 | HuCPUFastMap[x] = NULL; |
| 791 | PCERead[x] = ACPhysRead; |
| 792 | PCEWrite[x] = ACPhysWrite; |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | memset(SaveRAM, 0x00, 2048); |
| 797 | memcpy(SaveRAM, BRAM_Init_String, 8); // So users don't have to manually intialize the file cabinet |
| 798 | // in the CD BIOS screen. |
| 799 | |
| 800 | PCEWrite[0xF7] = SaveRAMWrite; |
| 801 | PCERead[0xF7] = SaveRAMRead; |
| 802 | MDFNMP_AddRAM(2048, 0xF7 * 8192, SaveRAM); |
| 803 | return(1); |
| 804 | } |
| 805 | |
| 806 | int HuC_StateAction(StateMem *sm, int load, int data_only) |
| 807 | { |
| 808 | SFORMAT StateRegs[] = |
| 809 | { |
| 810 | SFARRAY(ROMSpace + 0x40 * 8192, IsPopulous ? 32768 : 0), |
| 811 | SFARRAY(SaveRAM, IsPopulous ? 0 : 2048), |
| 812 | SFARRAY(ROMSpace + 0x68 * 8192, PCE_IsCD ? 262144 : 0), |
| 813 | SFVAR(HuCSF2Latch), |
| 814 | SFEND |
| 815 | }; |
| 816 | int ret = MDFNSS_StateAction(sm, load, data_only, StateRegs, "HuC"); |
| 817 | |
| 818 | if(load) |
| 819 | HuCSF2Latch &= 0x3; |
| 820 | |
| 821 | if(PCE_IsCD) |
| 822 | { |
| 823 | ret &= PCECD_StateAction(sm, load, data_only); |
| 824 | |
| 825 | if(arcade_card) |
| 826 | ret &= arcade_card->StateAction(sm, load, data_only); |
| 827 | } |
| 828 | return(ret); |
| 829 | } |
| 830 | |
| 831 | void HuC_Close(void) |
| 832 | { |
| 833 | Cleanup(); |
| 834 | } |
| 835 | |
| 836 | void HuC_Power(void) |
| 837 | { |
| 838 | if(PCE_IsCD) |
| 839 | memset(ROMSpace + 0x68 * 8192, 0x00, 262144); |
| 840 | |
| 841 | if(arcade_card) |
| 842 | arcade_card->Power(); |
| 843 | } |
| 844 | |
| 845 | MDFNGI EmulatedPCE_Fast = |
| 846 | { |
| 847 | "pce_fast", |
| 848 | "PC Engine (CD)/TurboGrafx 16 (CD)/SuperGrafx", |
| 849 | KnownExtensions, |
| 850 | MODPRIO_INTERNAL_LOW, |
| 851 | NULL, |
| 852 | &PCEInputInfo, |
| 853 | Load, |
| 854 | TestMagic, |
| 855 | LoadCD, |
| 856 | TestMagicCD, |
| 857 | CloseGame, |
| 858 | VDC_SetLayerEnableMask, |
| 859 | NULL, |
| 860 | NULL, |
| 861 | NULL, |
| 862 | NULL, |
| 863 | NULL, |
| 864 | MemRead, |
| 865 | NULL, |
| 866 | false, |
| 867 | StateAction, |
| 868 | Emulate, |
| 869 | PCEINPUT_SetInput, |
| 870 | DoSimpleCommand, |
| 871 | PCESettings, |
| 872 | MDFN_MASTERCLOCK_FIXED(PCE_MASTER_CLOCK), |
| 873 | 0, |
| 874 | |
| 875 | true, // Multires possible? |
| 876 | |
| 877 | 0, // lcm_width |
| 878 | 0, // lcm_height |
| 879 | NULL, // Dummy |
| 880 | |
| 881 | 288, // Nominal width |
| 882 | 232, // Nominal height |
| 883 | |
| 884 | 512, // Framebuffer width |
| 885 | 242, // Framebuffer height |
| 886 | |
| 887 | 2, // Number of output sound channels |
| 888 | }; |
| 889 | |
| 890 | #ifdef NEED_CD |
| 891 | static void ReadM3U(std::vector<std::string> &file_list, std::string path, unsigned depth = 0) |
| 892 | { |
| 893 | std::string dir_path; |
| 894 | char linebuf[2048]; |
| 895 | FILE *fp = fopen(path.c_str(), "rb"); |
| 896 | |
| 897 | if (fp == NULL) |
| 898 | return; |
| 899 | |
| 900 | MDFN_GetFilePathComponents(path, &dir_path); |
| 901 | |
| 902 | while(fgets(linebuf, sizeof(linebuf), fp)) |
| 903 | { |
| 904 | std::string efp; |
| 905 | |
| 906 | if(linebuf[0] == '#') |
| 907 | continue; |
| 908 | string_trim_whitespace_right(linebuf); |
| 909 | if(linebuf[0] == 0) |
| 910 | continue; |
| 911 | |
| 912 | efp = MDFN_EvalFIP(dir_path, std::string(linebuf)); |
| 913 | |
| 914 | if(efp.size() >= 4 && efp.substr(efp.size() - 4) == ".m3u") |
| 915 | { |
| 916 | if(efp == path) |
| 917 | throw(MDFN_Error(0, _("M3U at \"%s\" references self."), efp.c_str())); |
| 918 | |
| 919 | if(depth == 99) |
| 920 | throw(MDFN_Error(0, _("M3U load recursion too deep!"))); |
| 921 | |
| 922 | ReadM3U(file_list, efp, depth++); |
| 923 | } |
| 924 | else |
| 925 | file_list.push_back(efp); |
| 926 | } |
| 927 | |
| 928 | fclose(fp); |
| 929 | } |
| 930 | |
| 931 | #ifdef NEED_CD |
| 932 | static std::vector<CDIF *> CDInterfaces; // FIXME: Cleanup on error out. |
| 933 | #endif |
| 934 | // TODO: LoadCommon() |
| 935 | |
| 936 | MDFNGI *MDFNI_LoadCD(const char *force_module, const char *devicename) |
| 937 | { |
| 938 | MDFN_printf(_("Loading %s...\n\n"), devicename ? devicename : _("PHYSICAL CD")); |
| 939 | |
| 940 | try |
| 941 | { |
| 942 | if(devicename && strlen(devicename) > 4 && !strcasecmp(devicename + strlen(devicename) - 4, ".m3u")) |
| 943 | { |
| 944 | std::vector<std::string> file_list; |
| 945 | |
| 946 | ReadM3U(file_list, devicename); |
| 947 | |
| 948 | for(unsigned i = 0; i < file_list.size(); i++) |
| 949 | { |
| 950 | CDInterfaces.push_back(CDIF_Open(file_list[i].c_str(), false, old_cdimagecache)); |
| 951 | } |
| 952 | } |
| 953 | else |
| 954 | { |
| 955 | CDInterfaces.push_back(CDIF_Open(devicename, false, old_cdimagecache)); |
| 956 | } |
| 957 | } |
| 958 | catch(std::exception &e) |
| 959 | { |
| 960 | MDFND_PrintError(e.what()); |
| 961 | MDFN_PrintError(_("Error opening CD.")); |
| 962 | return(0); |
| 963 | } |
| 964 | |
| 965 | // |
| 966 | // Print out a track list for all discs. |
| 967 | // |
| 968 | MDFN_indent(1); |
| 969 | for(unsigned i = 0; i < CDInterfaces.size(); i++) |
| 970 | { |
| 971 | CDUtility::TOC toc; |
| 972 | |
| 973 | CDInterfaces[i]->ReadTOC(&toc); |
| 974 | |
| 975 | MDFN_printf(_("CD %d Layout:\n"), i + 1); |
| 976 | MDFN_indent(1); |
| 977 | |
| 978 | for(int32 track = toc.first_track; track <= toc.last_track; track++) |
| 979 | { |
| 980 | MDFN_printf(_("Track %2d, LBA: %6d %s\n"), track, toc.tracks[track].lba, (toc.tracks[track].control & 0x4) ? "DATA" : "AUDIO"); |
| 981 | } |
| 982 | |
| 983 | MDFN_printf("Leadout: %6d\n", toc.tracks[100].lba); |
| 984 | MDFN_indent(-1); |
| 985 | MDFN_printf("\n"); |
| 986 | } |
| 987 | MDFN_indent(-1); |
| 988 | |
| 989 | // This if statement will be true if force_module references a system without CDROM support. |
| 990 | if(!MDFNGameInfo->LoadCD) |
| 991 | { |
| 992 | MDFN_PrintError(_("Specified system \"%s\" doesn't support CDs!"), force_module); |
| 993 | return(0); |
| 994 | } |
| 995 | |
| 996 | MDFN_printf(_("Using module: %s(%s)\n\n"), MDFNGameInfo->shortname, MDFNGameInfo->fullname); |
| 997 | |
| 998 | if(!(MDFNGameInfo->LoadCD(&CDInterfaces))) |
| 999 | { |
| 1000 | for(unsigned i = 0; i < CDInterfaces.size(); i++) |
| 1001 | delete CDInterfaces[i]; |
| 1002 | CDInterfaces.clear(); |
| 1003 | |
| 1004 | MDFNGameInfo = NULL; |
| 1005 | return(0); |
| 1006 | } |
| 1007 | |
| 1008 | //MDFNI_SetLayerEnableMask(~0ULL); |
| 1009 | |
| 1010 | MDFN_LoadGameCheats(NULL); |
| 1011 | MDFNMP_InstallReadPatches(); |
| 1012 | |
| 1013 | return(MDFNGameInfo); |
| 1014 | } |
| 1015 | #endif |
| 1016 | |
| 1017 | MDFNGI *MDFNI_LoadGame(const char *force_module, const char *name) |
| 1018 | { |
| 1019 | MDFNFILE GameFile; |
| 1020 | std::vector<FileExtensionSpecStruct> valid_iae; |
| 1021 | MDFNGameInfo = &EmulatedPCE_Fast; |
| 1022 | |
| 1023 | #ifdef NEED_CD |
| 1024 | if(strlen(name) > 4 && (!strcasecmp(name + strlen(name) - 4, ".cue") || !strcasecmp(name + strlen(name) - 4, ".ccd") || !strcasecmp(name + strlen(name) - 4, ".toc") || !strcasecmp(name + strlen(name) - 4, ".m3u"))) |
| 1025 | return(MDFNI_LoadCD(force_module, name)); |
| 1026 | #endif |
| 1027 | |
| 1028 | MDFN_printf(_("Loading %s...\n"),name); |
| 1029 | |
| 1030 | MDFN_indent(1); |
| 1031 | |
| 1032 | // Construct a NULL-delimited list of known file extensions for MDFN_fopen() |
| 1033 | const FileExtensionSpecStruct *curexts = MDFNGameInfo->FileExtensions; |
| 1034 | |
| 1035 | while(curexts->extension && curexts->description) |
| 1036 | { |
| 1037 | valid_iae.push_back(*curexts); |
| 1038 | curexts++; |
| 1039 | } |
| 1040 | |
| 1041 | if(!GameFile.Open(name, &valid_iae[0], _("game"))) |
| 1042 | { |
| 1043 | MDFNGameInfo = NULL; |
| 1044 | return 0; |
| 1045 | } |
| 1046 | |
| 1047 | MDFN_printf(_("Using module: %s(%s)\n\n"), MDFNGameInfo->shortname, MDFNGameInfo->fullname); |
| 1048 | MDFN_indent(1); |
| 1049 | |
| 1050 | // |
| 1051 | // Load per-game settings |
| 1052 | // |
| 1053 | // Maybe we should make a "pgcfg" subdir, and automatically load all files in it? |
| 1054 | // End load per-game settings |
| 1055 | // |
| 1056 | |
| 1057 | if(MDFNGameInfo->Load(name, &GameFile) <= 0) |
| 1058 | { |
| 1059 | GameFile.Close(); |
| 1060 | MDFN_indent(-2); |
| 1061 | MDFNGameInfo = NULL; |
| 1062 | return(0); |
| 1063 | } |
| 1064 | |
| 1065 | MDFN_LoadGameCheats(NULL); |
| 1066 | MDFNMP_InstallReadPatches(); |
| 1067 | |
| 1068 | MDFN_indent(-2); |
| 1069 | |
| 1070 | if(!MDFNGameInfo->name) |
| 1071 | { |
| 1072 | unsigned int x; |
| 1073 | char *tmp; |
| 1074 | |
| 1075 | MDFNGameInfo->name = (UTF8 *)strdup(GetFNComponent(name)); |
| 1076 | |
| 1077 | for(x=0;x<strlen((char *)MDFNGameInfo->name);x++) |
| 1078 | { |
| 1079 | if(MDFNGameInfo->name[x] == '_') |
| 1080 | MDFNGameInfo->name[x] = ' '; |
| 1081 | } |
| 1082 | if((tmp = strrchr((char *)MDFNGameInfo->name, '.'))) |
| 1083 | *tmp = 0; |
| 1084 | } |
| 1085 | |
| 1086 | return(MDFNGameInfo); |
| 1087 | } |
| 1088 | |
| 1089 | static int curindent = 0; |
| 1090 | |
| 1091 | void MDFN_indent(int indent) |
| 1092 | { |
| 1093 | curindent += indent; |
| 1094 | } |
| 1095 | |
| 1096 | static uint8 lastchar = 0; |
| 1097 | |
| 1098 | void MDFN_printf(const char *format, ...) |
| 1099 | { |
| 1100 | char *format_temp; |
| 1101 | char *temp; |
| 1102 | unsigned int x, newlen; |
| 1103 | |
| 1104 | va_list ap; |
| 1105 | va_start(ap,format); |
| 1106 | |
| 1107 | |
| 1108 | // First, determine how large our format_temp buffer needs to be. |
| 1109 | uint8 lastchar_backup = lastchar; // Save lastchar! |
| 1110 | for(newlen=x=0;x<strlen(format);x++) |
| 1111 | { |
| 1112 | if(lastchar == '\n' && format[x] != '\n') |
| 1113 | { |
| 1114 | int y; |
| 1115 | for(y=0;y<curindent;y++) |
| 1116 | newlen++; |
| 1117 | } |
| 1118 | newlen++; |
| 1119 | lastchar = format[x]; |
| 1120 | } |
| 1121 | |
| 1122 | format_temp = (char *)malloc(newlen + 1); // Length + NULL character, duh |
| 1123 | |
| 1124 | // Now, construct our format_temp string |
| 1125 | lastchar = lastchar_backup; // Restore lastchar |
| 1126 | for(newlen=x=0;x<strlen(format);x++) |
| 1127 | { |
| 1128 | if(lastchar == '\n' && format[x] != '\n') |
| 1129 | { |
| 1130 | int y; |
| 1131 | for(y=0;y<curindent;y++) |
| 1132 | format_temp[newlen++] = ' '; |
| 1133 | } |
| 1134 | format_temp[newlen++] = format[x]; |
| 1135 | lastchar = format[x]; |
| 1136 | } |
| 1137 | |
| 1138 | format_temp[newlen] = 0; |
| 1139 | |
| 1140 | temp = new char[4096]; |
| 1141 | vsnprintf(temp, 4096, format_temp, ap); |
| 1142 | free(format_temp); |
| 1143 | |
| 1144 | MDFND_Message(temp); |
| 1145 | free(temp); |
| 1146 | |
| 1147 | va_end(ap); |
| 1148 | } |
| 1149 | |
| 1150 | void MDFN_PrintError(const char *format, ...) |
| 1151 | { |
| 1152 | char *temp; |
| 1153 | |
| 1154 | va_list ap; |
| 1155 | |
| 1156 | va_start(ap, format); |
| 1157 | |
| 1158 | temp = new char[4096]; |
| 1159 | vsnprintf(temp, 4096, format, ap); |
| 1160 | MDFND_PrintError(temp); |
| 1161 | free(temp); |
| 1162 | |
| 1163 | va_end(ap); |
| 1164 | } |
| 1165 | |
| 1166 | void MDFN_DebugPrintReal(const char *file, const int line, const char *format, ...) |
| 1167 | { |
| 1168 | char *temp; |
| 1169 | |
| 1170 | va_list ap; |
| 1171 | |
| 1172 | va_start(ap, format); |
| 1173 | |
| 1174 | temp = new char[4096]; |
| 1175 | vsnprintf(temp, 4096, format, ap); |
| 1176 | fprintf(stderr, "%s:%d %s\n", file, line, temp); |
| 1177 | free(temp); |
| 1178 | |
| 1179 | va_end(ap); |
| 1180 | } |
| 1181 | |
| 1182 | |
| 1183 | static MDFNGI *game; |
| 1184 | |
| 1185 | struct retro_perf_callback perf_cb; |
| 1186 | retro_get_cpu_features_t perf_get_cpu_features_cb = NULL; |
| 1187 | retro_log_printf_t log_cb; |
| 1188 | static retro_video_refresh_t video_cb; |
| 1189 | static retro_audio_sample_t audio_cb; |
| 1190 | static retro_audio_sample_batch_t audio_batch_cb; |
| 1191 | static retro_environment_t environ_cb; |
| 1192 | static retro_input_poll_t input_poll_cb; |
| 1193 | static retro_input_state_t input_state_cb; |
| 1194 | |
| 1195 | static bool overscan; |
| 1196 | static double last_sound_rate; |
| 1197 | |
| 1198 | static MDFN_Surface *surf; |
| 1199 | |
| 1200 | static bool failed_init; |
| 1201 | |
| 1202 | std::string retro_base_directory; |
| 1203 | std::string retro_base_name; |
| 1204 | std::string retro_save_directory; |
| 1205 | |
| 1206 | static void set_basename(const char *path) |
| 1207 | { |
| 1208 | const char *base = strrchr(path, '/'); |
| 1209 | if (!base) |
| 1210 | base = strrchr(path, '\\'); |
| 1211 | |
| 1212 | if (base) |
| 1213 | retro_base_name = base + 1; |
| 1214 | else |
| 1215 | retro_base_name = path; |
| 1216 | |
| 1217 | retro_base_name = retro_base_name.substr(0, retro_base_name.find_last_of('.')); |
| 1218 | } |
| 1219 | |
| 1220 | #include "mednafen/pce_fast/pcecd.h" |
| 1221 | |
| 1222 | #define MEDNAFEN_CORE_NAME_MODULE "pce_fast" |
| 1223 | #define MEDNAFEN_CORE_NAME "Mednafen PCE Fast" |
| 1224 | #define MEDNAFEN_CORE_VERSION "v0.9.38.7" |
| 1225 | #define MEDNAFEN_CORE_EXTENSIONS "pce|cue|ccd" |
| 1226 | #define MEDNAFEN_CORE_TIMING_FPS 59.82 |
| 1227 | #define MEDNAFEN_CORE_GEOMETRY_BASE_W 288 |
| 1228 | #define MEDNAFEN_CORE_GEOMETRY_BASE_H 232 |
| 1229 | #define MEDNAFEN_CORE_GEOMETRY_MAX_W 512 |
| 1230 | #define MEDNAFEN_CORE_GEOMETRY_MAX_H 242 |
| 1231 | #define MEDNAFEN_CORE_GEOMETRY_ASPECT_RATIO (4.0 / 3.0) |
| 1232 | #define FB_WIDTH 512 |
| 1233 | #define FB_HEIGHT 242 |
| 1234 | |
| 1235 | #define FB_MAX_HEIGHT FB_HEIGHT |
| 1236 | |
| 1237 | static void check_system_specs(void) |
| 1238 | { |
| 1239 | unsigned level = 5; |
| 1240 | environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level); |
| 1241 | } |
| 1242 | |
| 1243 | void retro_init(void) |
| 1244 | { |
| 1245 | struct retro_log_callback log; |
| 1246 | if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log)) |
| 1247 | log_cb = log.log; |
| 1248 | else |
| 1249 | log_cb = NULL; |
| 1250 | |
| 1251 | #ifdef NEED_CD |
| 1252 | CDUtility::CDUtility_Init(); |
| 1253 | #endif |
| 1254 | |
| 1255 | const char *dir = NULL; |
| 1256 | |
| 1257 | if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir) |
| 1258 | { |
| 1259 | retro_base_directory = dir; |
| 1260 | // Make sure that we don't have any lingering slashes, etc, as they break Windows. |
| 1261 | size_t last = retro_base_directory.find_last_not_of("/\\"); |
| 1262 | if (last != std::string::npos) |
| 1263 | last++; |
| 1264 | |
| 1265 | retro_base_directory = retro_base_directory.substr(0, last); |
| 1266 | } |
| 1267 | else |
| 1268 | { |
| 1269 | /* TODO: Add proper fallback */ |
| 1270 | if (log_cb) |
| 1271 | log_cb(RETRO_LOG_WARN, "System directory is not defined. Fallback on using same dir as ROM for system directory later ...\n"); |
| 1272 | failed_init = true; |
| 1273 | } |
| 1274 | |
| 1275 | if (environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &dir) && dir) |
| 1276 | { |
| 1277 | // If save directory is defined use it, otherwise use system directory |
| 1278 | retro_save_directory = *dir ? dir : retro_base_directory; |
| 1279 | // Make sure that we don't have any lingering slashes, etc, as they break Windows. |
| 1280 | size_t last = retro_save_directory.find_last_not_of("/\\"); |
| 1281 | if (last != std::string::npos) |
| 1282 | last++; |
| 1283 | |
| 1284 | retro_save_directory = retro_save_directory.substr(0, last); |
| 1285 | } |
| 1286 | else |
| 1287 | { |
| 1288 | /* TODO: Add proper fallback */ |
| 1289 | if (log_cb) |
| 1290 | log_cb(RETRO_LOG_WARN, "Save directory is not defined. Fallback on using SYSTEM directory ...\n"); |
| 1291 | retro_save_directory = retro_base_directory; |
| 1292 | } |
| 1293 | |
| 1294 | enum retro_pixel_format rgb565 = RETRO_PIXEL_FORMAT_RGB565; |
| 1295 | if (environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &rgb565) && log_cb) |
| 1296 | log_cb(RETRO_LOG_INFO, "Frontend supports RGB565 - will use that instead of XRGB1555.\n"); |
| 1297 | |
| 1298 | if (environ_cb(RETRO_ENVIRONMENT_GET_PERF_INTERFACE, &perf_cb)) |
| 1299 | perf_get_cpu_features_cb = perf_cb.get_cpu_features; |
| 1300 | else |
| 1301 | perf_get_cpu_features_cb = NULL; |
| 1302 | |
| 1303 | bool yes = true; |
| 1304 | environ_cb(RETRO_ENVIRONMENT_SET_SUPPORT_ACHIEVEMENTS, &yes); |
| 1305 | |
| 1306 | setting_initial_scanline = 0; |
| 1307 | setting_last_scanline = 242; |
| 1308 | |
| 1309 | check_system_specs(); |
| 1310 | } |
| 1311 | |
| 1312 | void retro_reset(void) |
| 1313 | { |
| 1314 | DoSimpleCommand(MDFN_MSC_RESET); |
| 1315 | } |
| 1316 | |
| 1317 | bool retro_load_game_special(unsigned, const struct retro_game_info *, size_t) |
| 1318 | { |
| 1319 | return false; |
| 1320 | } |
| 1321 | |
| 1322 | static void set_volume (uint32_t *ptr, unsigned number) |
| 1323 | { |
| 1324 | switch(number) |
| 1325 | { |
| 1326 | default: |
| 1327 | *ptr = number; |
| 1328 | break; |
| 1329 | } |
| 1330 | } |
| 1331 | |
| 1332 | |
| 1333 | static void check_variables(void) |
| 1334 | { |
| 1335 | struct retro_variable var = {0}; |
| 1336 | |
| 1337 | var.key = "pce_fast_cdimagecache"; |
| 1338 | |
| 1339 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) |
| 1340 | { |
| 1341 | bool cdimage_cache = true; |
| 1342 | |
| 1343 | if (strcmp(var.value, "enabled") == 0) |
| 1344 | cdimage_cache = true; |
| 1345 | else if (strcmp(var.value, "disabled") == 0) |
| 1346 | cdimage_cache = false; |
| 1347 | |
| 1348 | if (cdimage_cache != old_cdimagecache) |
| 1349 | old_cdimagecache = cdimage_cache; |
| 1350 | } |
| 1351 | |
| 1352 | var.key = "pce_nospritelimit"; |
| 1353 | |
| 1354 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) |
| 1355 | { |
| 1356 | if (strcmp(var.value, "disabled") == 0) |
| 1357 | setting_pce_fast_nospritelimit = 0; |
| 1358 | else if (strcmp(var.value, "enabled") == 0) |
| 1359 | setting_pce_fast_nospritelimit = 1; |
| 1360 | } |
| 1361 | |
| 1362 | var.key = "pce_keepaspect"; |
| 1363 | |
| 1364 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) |
| 1365 | { |
| 1366 | if (strcmp(var.value, "disabled") == 0) |
| 1367 | { |
| 1368 | setting_pce_keepaspect = 0; |
| 1369 | EmulatedPCE_Fast.fb_width = 512; |
| 1370 | EmulatedPCE_Fast.nominal_width = 341; |
| 1371 | EmulatedPCE_Fast.lcm_width = 341; |
| 1372 | } |
| 1373 | else if (strcmp(var.value, "enabled") == 0) |
| 1374 | { |
| 1375 | setting_pce_keepaspect = 1; |
| 1376 | EmulatedPCE_Fast.fb_width = 682; |
| 1377 | EmulatedPCE_Fast.nominal_width = 288; |
| 1378 | EmulatedPCE_Fast.lcm_width = 1024; |
| 1379 | } |
| 1380 | } |
| 1381 | |
| 1382 | var.key = "pce_initial_scanline"; |
| 1383 | |
| 1384 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) |
| 1385 | { |
| 1386 | setting_initial_scanline = atoi(var.value); |
| 1387 | } |
| 1388 | |
| 1389 | var.key = "pce_last_scanline"; |
| 1390 | |
| 1391 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) |
| 1392 | { |
| 1393 | setting_last_scanline = atoi(var.value); |
| 1394 | } |
| 1395 | |
| 1396 | bool do_cdsettings = false; |
| 1397 | var.key = "pce_cddavolume"; |
| 1398 | |
| 1399 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) |
| 1400 | { |
| 1401 | do_cdsettings = true; |
| 1402 | setting_pce_fast_cddavolume = atoi(var.value); |
| 1403 | } |
| 1404 | |
| 1405 | var.key = "pce_adpcmvolume"; |
| 1406 | |
| 1407 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) |
| 1408 | { |
| 1409 | do_cdsettings = true; |
| 1410 | setting_pce_fast_adpcmvolume = atoi(var.value); |
| 1411 | } |
| 1412 | |
| 1413 | var.key = "pce_cdpsgvolume"; |
| 1414 | |
| 1415 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) |
| 1416 | { |
| 1417 | do_cdsettings = true; |
| 1418 | setting_pce_fast_cdpsgvolume = atoi(var.value); |
| 1419 | } |
| 1420 | |
| 1421 | var.key = "pce_cdspeed"; |
| 1422 | |
| 1423 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) |
| 1424 | { |
| 1425 | do_cdsettings = true; |
| 1426 | setting_pce_fast_cdspeed = atoi(var.value); |
| 1427 | } |
| 1428 | |
| 1429 | if (do_cdsettings) |
| 1430 | { |
| 1431 | PCECD_Settings settings = {0}; |
| 1432 | settings.CDDA_Volume = (double)setting_pce_fast_cddavolume / 100; |
| 1433 | settings.CD_Speed = setting_pce_fast_cdspeed; |
| 1434 | settings.ADPCM_Volume = (double)setting_pce_fast_adpcmvolume / 100; |
| 1435 | |
| 1436 | if (PCECD_SetSettings(&settings) && log_cb) |
| 1437 | log_cb(RETRO_LOG_INFO, "PCE CD Audio settings changed.\n"); |
| 1438 | } |
| 1439 | } |
| 1440 | |
| 1441 | #define MAX_PLAYERS 5 |
| 1442 | #define MAX_BUTTONS 13 |
| 1443 | static uint8_t input_buf[MAX_PLAYERS][2] = {0}; |
| 1444 | |
| 1445 | bool retro_load_game(const struct retro_game_info *info) |
| 1446 | { |
| 1447 | if (failed_init) |
| 1448 | return false; |
| 1449 | |
| 1450 | struct retro_input_descriptor desc[] = { |
| 1451 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, |
| 1452 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, |
| 1453 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, |
| 1454 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, |
| 1455 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "II" }, |
| 1456 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "I" }, |
| 1457 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "IV" }, |
| 1458 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "III" }, |
| 1459 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "V" }, |
| 1460 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "VI" }, |
| 1461 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "Mode Switch" }, |
| 1462 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, |
| 1463 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Run" }, |
| 1464 | |
| 1465 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, |
| 1466 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, |
| 1467 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, |
| 1468 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, |
| 1469 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "II" }, |
| 1470 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "I" }, |
| 1471 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "IV" }, |
| 1472 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "III" }, |
| 1473 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "V" }, |
| 1474 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "VI" }, |
| 1475 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "Mode Switch" }, |
| 1476 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, |
| 1477 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Run" }, |
| 1478 | |
| 1479 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, |
| 1480 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, |
| 1481 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, |
| 1482 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, |
| 1483 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "II" }, |
| 1484 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "I" }, |
| 1485 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "IV" }, |
| 1486 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "III" }, |
| 1487 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "V" }, |
| 1488 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "VI" }, |
| 1489 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "Mode Switch" }, |
| 1490 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, |
| 1491 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Run" }, |
| 1492 | |
| 1493 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, |
| 1494 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, |
| 1495 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, |
| 1496 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, |
| 1497 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "II" }, |
| 1498 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "I" }, |
| 1499 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "IV" }, |
| 1500 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "III" }, |
| 1501 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "V" }, |
| 1502 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "VI" }, |
| 1503 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "Mode Switch" }, |
| 1504 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, |
| 1505 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Run" }, |
| 1506 | |
| 1507 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, |
| 1508 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, |
| 1509 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, |
| 1510 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, |
| 1511 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "II" }, |
| 1512 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "I" }, |
| 1513 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "IV" }, |
| 1514 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "III" }, |
| 1515 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "V" }, |
| 1516 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "VI" }, |
| 1517 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "Mode Switch" }, |
| 1518 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, |
| 1519 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Run" }, |
| 1520 | |
| 1521 | { 0 }, |
| 1522 | }; |
| 1523 | |
| 1524 | environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc); |
| 1525 | |
| 1526 | overscan = false; |
| 1527 | environ_cb(RETRO_ENVIRONMENT_GET_OVERSCAN, &overscan); |
| 1528 | |
| 1529 | set_basename(info->path); |
| 1530 | |
| 1531 | check_variables(); |
| 1532 | |
| 1533 | game = MDFNI_LoadGame(MEDNAFEN_CORE_NAME_MODULE, info->path); |
| 1534 | if (!game) |
| 1535 | return false; |
| 1536 | |
| 1537 | surf = (MDFN_Surface*)calloc(1, sizeof(*surf)); |
| 1538 | |
| 1539 | if (!surf) |
| 1540 | return false; |
| 1541 | |
| 1542 | surf->width = FB_WIDTH; |
| 1543 | surf->height = FB_HEIGHT; |
| 1544 | surf->pitch = FB_WIDTH; |
| 1545 | |
| 1546 | surf->pixels = (uint16_t*)calloc(1, FB_WIDTH * FB_HEIGHT * 3); |
| 1547 | |
| 1548 | if (!surf->pixels) |
| 1549 | { |
| 1550 | free(surf); |
| 1551 | return false; |
| 1552 | } |
| 1553 | |
| 1554 | // Possible endian bug ... |
| 1555 | for (unsigned i = 0; i < MAX_PLAYERS; i++) |
| 1556 | PCEINPUT_SetInput(i, "gamepad", &input_buf[i][0]); |
| 1557 | |
| 1558 | VDC_SetPixelFormat(); |
| 1559 | |
| 1560 | return game; |
| 1561 | } |
| 1562 | |
| 1563 | void retro_unload_game(void) |
| 1564 | { |
| 1565 | if(!MDFNGameInfo) |
| 1566 | return; |
| 1567 | |
| 1568 | MDFN_FlushGameCheats(0); |
| 1569 | |
| 1570 | MDFNGameInfo->CloseGame(); |
| 1571 | |
| 1572 | if(MDFNGameInfo->name) |
| 1573 | free(MDFNGameInfo->name); |
| 1574 | MDFNGameInfo->name = NULL; |
| 1575 | |
| 1576 | MDFNMP_Kill(); |
| 1577 | |
| 1578 | MDFNGameInfo = NULL; |
| 1579 | |
| 1580 | #ifdef NEED_CD |
| 1581 | for(unsigned i = 0; i < CDInterfaces.size(); i++) |
| 1582 | delete CDInterfaces[i]; |
| 1583 | CDInterfaces.clear(); |
| 1584 | #endif |
| 1585 | } |
| 1586 | |
| 1587 | static void update_input(void) |
| 1588 | { |
| 1589 | static unsigned map[] = { |
| 1590 | RETRO_DEVICE_ID_JOYPAD_A, |
| 1591 | RETRO_DEVICE_ID_JOYPAD_B, |
| 1592 | RETRO_DEVICE_ID_JOYPAD_SELECT, |
| 1593 | RETRO_DEVICE_ID_JOYPAD_START, |
| 1594 | RETRO_DEVICE_ID_JOYPAD_UP, |
| 1595 | RETRO_DEVICE_ID_JOYPAD_RIGHT, |
| 1596 | RETRO_DEVICE_ID_JOYPAD_DOWN, |
| 1597 | RETRO_DEVICE_ID_JOYPAD_LEFT, |
| 1598 | RETRO_DEVICE_ID_JOYPAD_Y, |
| 1599 | RETRO_DEVICE_ID_JOYPAD_X, |
| 1600 | RETRO_DEVICE_ID_JOYPAD_L, |
| 1601 | RETRO_DEVICE_ID_JOYPAD_R, |
| 1602 | RETRO_DEVICE_ID_JOYPAD_L2 |
| 1603 | }; |
| 1604 | |
| 1605 | for (unsigned j = 0; j < MAX_PLAYERS; j++) |
| 1606 | { |
| 1607 | uint16_t input_state = 0; |
| 1608 | for (unsigned i = 0; i < MAX_BUTTONS; i++) |
| 1609 | input_state |= input_state_cb(j, RETRO_DEVICE_JOYPAD, 0, map[i]) ? (1 << i) : 0; |
| 1610 | |
| 1611 | // Input data must be little endian. |
| 1612 | input_buf[j][0] = (input_state >> 0) & 0xff; |
| 1613 | input_buf[j][1] = (input_state >> 8) & 0xff; |
| 1614 | } |
| 1615 | } |
| 1616 | |
| 1617 | static uint64_t video_frames, audio_frames; |
| 1618 | |
| 1619 | void retro_run(void) |
| 1620 | { |
| 1621 | MDFNGI *curgame = (MDFNGI*)game; |
| 1622 | |
| 1623 | input_poll_cb(); |
| 1624 | |
| 1625 | update_input(); |
| 1626 | |
| 1627 | static int16_t sound_buf[0x10000]; |
| 1628 | static int32_t rects[FB_MAX_HEIGHT]; |
| 1629 | rects[0] = ~0; |
| 1630 | |
| 1631 | EmulateSpecStruct spec = {0}; |
| 1632 | spec.surface = surf; |
| 1633 | spec.SoundRate = 44100; |
| 1634 | spec.SoundBuf = sound_buf; |
| 1635 | spec.LineWidths = rects; |
| 1636 | spec.SoundBufMaxSize = sizeof(sound_buf) / 2; |
| 1637 | spec.SoundVolume = 1.0; |
| 1638 | spec.soundmultiplier = 1.0; |
| 1639 | spec.SoundBufSize = 0; |
| 1640 | spec.VideoFormatChanged = false; |
| 1641 | spec.SoundFormatChanged = false; |
| 1642 | |
| 1643 | if (spec.SoundRate != last_sound_rate) |
| 1644 | { |
| 1645 | spec.SoundFormatChanged = true; |
| 1646 | last_sound_rate = spec.SoundRate; |
| 1647 | } |
| 1648 | |
| 1649 | Emulate(&spec); |
| 1650 | |
| 1651 | int16 *const SoundBuf = spec.SoundBuf + spec.SoundBufSizeALMS * curgame->soundchan; |
| 1652 | int32 SoundBufSize = spec.SoundBufSize - spec.SoundBufSizeALMS; |
| 1653 | const int32 SoundBufMaxSize = spec.SoundBufMaxSize - spec.SoundBufSizeALMS; |
| 1654 | |
| 1655 | spec.SoundBufSize = spec.SoundBufSizeALMS + SoundBufSize; |
| 1656 | |
| 1657 | unsigned width = spec.DisplayRect.w & ~0x1; |
| 1658 | unsigned height = spec.DisplayRect.h; |
| 1659 | |
| 1660 | video_cb(surf->pixels + surf->pitch * spec.DisplayRect.y, width, height, FB_WIDTH << 1); |
| 1661 | |
| 1662 | video_frames++; |
| 1663 | audio_frames += spec.SoundBufSize; |
| 1664 | |
| 1665 | audio_batch_cb(spec.SoundBuf, spec.SoundBufSize); |
| 1666 | |
| 1667 | bool updated = false; |
| 1668 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated) |
| 1669 | check_variables(); |
| 1670 | } |
| 1671 | |
| 1672 | void retro_get_system_info(struct retro_system_info *info) |
| 1673 | { |
| 1674 | memset(info, 0, sizeof(*info)); |
| 1675 | info->library_name = MEDNAFEN_CORE_NAME; |
| 1676 | info->library_version = MEDNAFEN_CORE_VERSION; |
| 1677 | info->need_fullpath = true; |
| 1678 | info->valid_extensions = MEDNAFEN_CORE_EXTENSIONS; |
| 1679 | info->block_extract = false; |
| 1680 | } |
| 1681 | |
| 1682 | void retro_get_system_av_info(struct retro_system_av_info *info) |
| 1683 | { |
| 1684 | memset(info, 0, sizeof(*info)); |
| 1685 | info->timing.fps = MEDNAFEN_CORE_TIMING_FPS; |
| 1686 | info->timing.sample_rate = 44100; |
| 1687 | info->geometry.base_width = MEDNAFEN_CORE_GEOMETRY_BASE_W; |
| 1688 | info->geometry.base_height = MEDNAFEN_CORE_GEOMETRY_BASE_H; |
| 1689 | info->geometry.max_width = MEDNAFEN_CORE_GEOMETRY_MAX_W; |
| 1690 | info->geometry.max_height = MEDNAFEN_CORE_GEOMETRY_MAX_H; |
| 1691 | info->geometry.aspect_ratio = MEDNAFEN_CORE_GEOMETRY_ASPECT_RATIO; |
| 1692 | } |
| 1693 | |
| 1694 | void retro_deinit() |
| 1695 | { |
| 1696 | if (surf) |
| 1697 | free(surf); |
| 1698 | surf = NULL; |
| 1699 | |
| 1700 | if (log_cb) |
| 1701 | { |
| 1702 | log_cb(RETRO_LOG_INFO, "[%s]: Samples / Frame: %.5f\n", |
| 1703 | MEDNAFEN_CORE_NAME, (double)audio_frames / video_frames); |
| 1704 | log_cb(RETRO_LOG_INFO, "[%s]: Estimated FPS: %.5f\n", |
| 1705 | MEDNAFEN_CORE_NAME, (double)video_frames * 44100 / audio_frames); |
| 1706 | } |
| 1707 | } |
| 1708 | |
| 1709 | unsigned retro_get_region(void) |
| 1710 | { |
| 1711 | return RETRO_REGION_NTSC; // FIXME: Regions for other cores. |
| 1712 | } |
| 1713 | |
| 1714 | unsigned retro_api_version(void) |
| 1715 | { |
| 1716 | return RETRO_API_VERSION; |
| 1717 | } |
| 1718 | |
| 1719 | void retro_set_controller_port_device(unsigned in_port, unsigned device) |
| 1720 | { |
| 1721 | MDFNGI *currgame = (MDFNGI*)game; |
| 1722 | |
| 1723 | if (!currgame) |
| 1724 | return; |
| 1725 | |
| 1726 | switch(device) |
| 1727 | { |
| 1728 | case RETRO_DEVICE_JOYPAD: |
| 1729 | PCEINPUT_SetInput(in_port, "gamepad", &input_buf[in_port][0]); |
| 1730 | break; |
| 1731 | case RETRO_DEVICE_MOUSE: |
| 1732 | PCEINPUT_SetInput(in_port, "mouse", &input_buf[in_port][0]); |
| 1733 | break; |
| 1734 | } |
| 1735 | } |
| 1736 | |
| 1737 | void retro_set_environment(retro_environment_t cb) |
| 1738 | { |
| 1739 | environ_cb = cb; |
| 1740 | |
| 1741 | static const struct retro_variable vars[] = { |
| 1742 | { "pce_fast_cdimagecache", "CD Image Cache (Restart); disabled|enabled" }, |
| 1743 | { "pce_nospritelimit", "No Sprite Limit; disabled|enabled" }, |
| 1744 | { "pce_keepaspect", "Keep Aspect; enabled|disabled" }, |
| 1745 | { "pce_initial_scanline", "Initial scanline; 3|4|5|6|7|8|9|10|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|0|1|2" }, |
| 1746 | { "pce_last_scanline", "Last scanline; 241|242|208|209|210|211|212|213|214|215|216|217|218|219|220|221|222|223|224|225|226|227|228|229|230|231|232|233|234|235|236|237|238|239|240" }, |
| 1747 | { "pce_cddavolume", "(CD) CDDA Volume; 100|0|10|20|30|40|50|60|70|80|90" }, |
| 1748 | { "pce_adpcmvolume", "(CD) ADPCM Volume; 100|0|10|20|30|40|50|60|70|80|90" }, |
| 1749 | { "pce_cdpsgvolume", "(CD) CD PSG Volume; 100|0|10|20|30|40|50|60|70|80|90" }, |
| 1750 | { "pce_cdspeed", "(CD) CD Speed; 1|2|4|8" }, |
| 1751 | { NULL, NULL }, |
| 1752 | }; |
| 1753 | |
| 1754 | static const struct retro_controller_description pads[] = { |
| 1755 | { "PCE Joypad", RETRO_DEVICE_JOYPAD }, |
| 1756 | { "Mouse", RETRO_DEVICE_MOUSE }, |
| 1757 | }; |
| 1758 | |
| 1759 | static const struct retro_controller_info ports[] = { |
| 1760 | { pads, 2 }, |
| 1761 | { pads, 2 }, |
| 1762 | { 0 }, |
| 1763 | }; |
| 1764 | |
| 1765 | cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)vars); |
| 1766 | environ_cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports); |
| 1767 | } |
| 1768 | |
| 1769 | void retro_set_audio_sample(retro_audio_sample_t cb) |
| 1770 | { |
| 1771 | audio_cb = cb; |
| 1772 | } |
| 1773 | |
| 1774 | void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) |
| 1775 | { |
| 1776 | audio_batch_cb = cb; |
| 1777 | } |
| 1778 | |
| 1779 | void retro_set_input_poll(retro_input_poll_t cb) |
| 1780 | { |
| 1781 | input_poll_cb = cb; |
| 1782 | } |
| 1783 | |
| 1784 | void retro_set_input_state(retro_input_state_t cb) |
| 1785 | { |
| 1786 | input_state_cb = cb; |
| 1787 | } |
| 1788 | |
| 1789 | void retro_set_video_refresh(retro_video_refresh_t cb) |
| 1790 | { |
| 1791 | video_cb = cb; |
| 1792 | } |
| 1793 | |
| 1794 | static size_t serialize_size; |
| 1795 | |
| 1796 | size_t retro_serialize_size(void) |
| 1797 | { |
| 1798 | StateMem st; |
| 1799 | memset(&st, 0, sizeof(st)); |
| 1800 | |
| 1801 | if (!MDFNSS_SaveSM(&st, 0, 0, NULL, NULL, NULL)) |
| 1802 | return 0; |
| 1803 | |
| 1804 | free(st.data); |
| 1805 | return serialize_size = st.len; |
| 1806 | } |
| 1807 | |
| 1808 | bool retro_serialize(void *data, size_t size) |
| 1809 | { |
| 1810 | StateMem st; |
| 1811 | memset(&st, 0, sizeof(st)); |
| 1812 | st.data = (uint8_t*)data; |
| 1813 | st.malloced = size; |
| 1814 | |
| 1815 | return MDFNSS_SaveSM(&st, 0, 0, NULL, NULL, NULL); |
| 1816 | } |
| 1817 | |
| 1818 | bool retro_unserialize(const void *data, size_t size) |
| 1819 | { |
| 1820 | StateMem st; |
| 1821 | memset(&st, 0, sizeof(st)); |
| 1822 | st.data = (uint8_t*)data; |
| 1823 | st.len = size; |
| 1824 | |
| 1825 | return MDFNSS_LoadSM(&st, 0, 0); |
| 1826 | } |
| 1827 | |
| 1828 | void *retro_get_memory_data(unsigned type) |
| 1829 | { |
| 1830 | switch (type) |
| 1831 | { |
| 1832 | case RETRO_MEMORY_SAVE_RAM: |
| 1833 | if (IsPopulous) |
| 1834 | return (uint8_t*)(ROMSpace + 0x40 * 8192); |
| 1835 | return (uint8_t*)SaveRAM; |
| 1836 | case RETRO_MEMORY_SYSTEM_RAM: |
| 1837 | return BaseRAM; |
| 1838 | default: |
| 1839 | break; |
| 1840 | } |
| 1841 | |
| 1842 | return NULL; |
| 1843 | } |
| 1844 | |
| 1845 | size_t retro_get_memory_size(unsigned type) |
| 1846 | { |
| 1847 | switch (type) |
| 1848 | { |
| 1849 | case RETRO_MEMORY_SAVE_RAM: |
| 1850 | if (IsPopulous) |
| 1851 | return 32768; |
| 1852 | return 2048; |
| 1853 | case RETRO_MEMORY_SYSTEM_RAM: |
| 1854 | return sizeof(BaseRAM) - 8192; |
| 1855 | default: |
| 1856 | break; |
| 1857 | } |
| 1858 | |
| 1859 | return 0; |
| 1860 | } |
| 1861 | |
| 1862 | void retro_cheat_reset(void) |
| 1863 | {} |
| 1864 | |
| 1865 | void retro_cheat_set(unsigned, bool, const char *) |
| 1866 | {} |
| 1867 | |
| 1868 | MDFN_Thread *MDFND_CreateThread(int (*fn)(void *), void *data) |
| 1869 | { |
| 1870 | return (MDFN_Thread*)sthread_create((void (*)(void*))fn, data); |
| 1871 | } |
| 1872 | |
| 1873 | void MDFND_WaitThread(MDFN_Thread *thr, int *val) |
| 1874 | { |
| 1875 | sthread_join((sthread_t*)thr); |
| 1876 | |
| 1877 | if (val) |
| 1878 | { |
| 1879 | *val = 0; |
| 1880 | fprintf(stderr, "WaitThread relies on return value.\n"); |
| 1881 | } |
| 1882 | } |
| 1883 | |
| 1884 | void MDFND_KillThread(MDFN_Thread *) |
| 1885 | { |
| 1886 | fprintf(stderr, "Killing a thread is a BAD IDEA!\n"); |
| 1887 | } |
| 1888 | |
| 1889 | MDFN_Mutex *MDFND_CreateMutex(void) |
| 1890 | { |
| 1891 | return (MDFN_Mutex*)slock_new(); |
| 1892 | } |
| 1893 | |
| 1894 | void MDFND_DestroyMutex(MDFN_Mutex *lock) |
| 1895 | { |
| 1896 | slock_free((slock_t*)lock); |
| 1897 | } |
| 1898 | |
| 1899 | int MDFND_LockMutex(MDFN_Mutex *lock) |
| 1900 | { |
| 1901 | slock_lock((slock_t*)lock); |
| 1902 | return 0; |
| 1903 | } |
| 1904 | |
| 1905 | int MDFND_UnlockMutex(MDFN_Mutex *lock) |
| 1906 | { |
| 1907 | slock_unlock((slock_t*)lock); |
| 1908 | return 0; |
| 1909 | } |
| 1910 | |
| 1911 | MDFN_Cond *MDFND_CreateCond(void) |
| 1912 | { |
| 1913 | return (MDFN_Cond*)scond_new(); |
| 1914 | } |
| 1915 | |
| 1916 | void MDFND_DestroyCond(MDFN_Cond *cond) |
| 1917 | { |
| 1918 | scond_free((scond_t*)cond); |
| 1919 | } |
| 1920 | |
| 1921 | int MDFND_WaitCond(MDFN_Cond *cond, MDFN_Mutex *mutex) |
| 1922 | { |
| 1923 | scond_wait((scond_t*)cond, (slock_t*)mutex); |
| 1924 | return 0; // not sure about this return |
| 1925 | } |
| 1926 | |
| 1927 | int MDFND_SignalCond(MDFN_Cond *cond) |
| 1928 | { |
| 1929 | scond_signal((scond_t*)cond); |
| 1930 | return 0; // not sure about this return |
| 1931 | } |
| 1932 | |
| 1933 | #ifdef _WIN32 |
| 1934 | static void sanitize_path(std::string &path) |
| 1935 | { |
| 1936 | size_t size = path.size(); |
| 1937 | for (size_t i = 0; i < size; i++) |
| 1938 | if (path[i] == '/') |
| 1939 | path[i] = '\\'; |
| 1940 | } |
| 1941 | #endif |
| 1942 | |
| 1943 | // Use a simpler approach to make sure that things go right for libretro. |
| 1944 | std::string MDFN_MakeFName(MakeFName_Type type, int id1, const char *cd1) |
| 1945 | { |
| 1946 | char slash; |
| 1947 | #ifdef _WIN32 |
| 1948 | slash = '\\'; |
| 1949 | #else |
| 1950 | slash = '/'; |
| 1951 | #endif |
| 1952 | std::string ret; |
| 1953 | switch (type) |
| 1954 | { |
| 1955 | case MDFNMKF_SAV: |
| 1956 | ret = retro_save_directory +slash + retro_base_name + |
| 1957 | std::string(".") + std::string(cd1); |
| 1958 | break; |
| 1959 | case MDFNMKF_FIRMWARE: |
| 1960 | ret = retro_base_directory + slash + std::string(cd1); |
| 1961 | #ifdef _WIN32 |
| 1962 | sanitize_path(ret); // Because Windows path handling is mongoloid. |
| 1963 | #endif |
| 1964 | break; |
| 1965 | default: |
| 1966 | break; |
| 1967 | } |
| 1968 | |
| 1969 | if (log_cb) |
| 1970 | log_cb(RETRO_LOG_INFO, "MDFN_MakeFName: %s\n", ret.c_str()); |
| 1971 | return ret; |
| 1972 | } |
| 1973 | |
| 1974 | void MDFND_Message(const char *str) |
| 1975 | { |
| 1976 | if (log_cb) |
| 1977 | log_cb(RETRO_LOG_INFO, "%s\n", str); |
| 1978 | } |
| 1979 | |
| 1980 | void MDFND_MidSync(const EmulateSpecStruct *) |
| 1981 | {} |
| 1982 | |
| 1983 | void MDFN_MidLineUpdate(EmulateSpecStruct *espec, int y) |
| 1984 | { |
| 1985 | //MDFND_MidLineUpdate(espec, y); |
| 1986 | } |
| 1987 | |
| 1988 | void MDFND_PrintError(const char* err) |
| 1989 | { |
| 1990 | if (log_cb) |
| 1991 | log_cb(RETRO_LOG_ERROR, "%s\n", err); |
| 1992 | } |
| 1993 | |
| 1994 | void MDFND_Sleep(unsigned int time) |
| 1995 | { |
| 1996 | retro_sleep(time); |
| 1997 | } |
| 1998 | |
| 1999 | /* forward declarations */ |
| 2000 | extern void MDFND_DispMessage(unsigned char *str); |
| 2001 | |
| 2002 | void MDFND_DispMessage(unsigned char *str) |
| 2003 | { |
| 2004 | const char *strc = (const char*)str; |
| 2005 | struct retro_message msg = |
| 2006 | { |
| 2007 | strc, |
| 2008 | 180 |
| 2009 | }; |
| 2010 | |
| 2011 | environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, &msg); |
| 2012 | } |
| 2013 | |
| 2014 | void MDFN_DispMessage(const char *format, ...) |
| 2015 | { |
| 2016 | struct retro_message msg; |
| 2017 | va_list ap; |
| 2018 | va_start(ap,format); |
| 2019 | char *str = new char[4096]; |
| 2020 | const char *strc = NULL; |
| 2021 | |
| 2022 | vsnprintf(str, 4096, format,ap); |
| 2023 | va_end(ap); |
| 2024 | strc = str; |
| 2025 | |
| 2026 | msg.frames = 180; |
| 2027 | msg.msg = strc; |
| 2028 | |
| 2029 | environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, &msg); |
| 2030 | } |
| 2031 | |
| 2032 | void MDFN_ResetMessages(void) |
| 2033 | { |
| 2034 | } |