Debian Codegraph @

libretro.cpp

raw symbols SCIP
1 #include "mednafen/mednafen.h"
2 #include "mednafen/mempatcher.h"
3 #include "mednafen/git.h"
4 #include "mednafen/general.h"
5 #include "libretro.h"
6
7 static MDFNGI *game;
8
9 struct retro_perf_callback perf_cb;
10 retro_get_cpu_features_t perf_get_cpu_features_cb = NULL;
11 retro_log_printf_t log_cb;
12 static retro_video_refresh_t video_cb;
13 static retro_audio_sample_t audio_cb;
14 static retro_audio_sample_batch_t audio_batch_cb;
15 static retro_environment_t environ_cb;
16 static retro_input_poll_t input_poll_cb;
17 static retro_input_state_t input_state_cb;
18
19 static bool overscan;
20 static double last_sound_rate;
21 static MDFN_PixelFormat last_pixel_format;
22
23 static MDFN_Surface *surf;
24
25 /* Mednafen - Multi-system Emulator
26 *
27 * This program is free software; you can redistribute it and/or modify
28 * it under the terms of the GNU General Public License as published by
29 * the Free Software Foundation; either version 2 of the License, or
30 * (at your option) any later version.
31 *
32 * This program is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
36 *
37 * You should have received a copy of the GNU General Public License
38 * along with this program; if not, write to the Free Software
39 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
40 */
41
42 #include "mednafen/vb/vb.h"
43 #include "mednafen/vb/timer.h"
44 #include "mednafen/vb/vsu.h"
45 #include "mednafen/vb/vip.h"
46 #ifdef WANT_DEBUGGER
47 #include "mednafen/vb/debug.h"
48 #endif
49 #include "mednafen/vb/input.h"
50 #include "mednafen/general.h"
51 #include "mednafen/mempatcher.h"
52 #if 0
53 #include <iconv.h>
54 #endif
55
56 enum
57 {
58 ANAGLYPH_PRESET_DISABLED = 0,
59 ANAGLYPH_PRESET_RED_BLUE,
60 ANAGLYPH_PRESET_RED_CYAN,
61 ANAGLYPH_PRESET_RED_ELECTRICCYAN,
62 ANAGLYPH_PRESET_RED_GREEN,
63 ANAGLYPH_PRESET_GREEN_MAGENTA,
64 ANAGLYPH_PRESET_YELLOW_BLUE,
65 };
66
67 static const uint32 AnaglyphPreset_Colors[][2] =
68 {
69 { 0, 0 },
70 { 0xFF0000, 0x0000FF },
71 { 0xFF0000, 0x00B7EB },
72 { 0xFF0000, 0x00FFFF },
73 { 0xFF0000, 0x00FF00 },
74 { 0x00FF00, 0xFF00FF },
75 { 0xFFFF00, 0x0000FF },
76 };
77
78
79 int32 VB_InDebugPeek;
80
81 static uint32 VB3DMode;
82
83 static Blip_Buffer sbuf[2];
84
85 static uint8 *WRAM = NULL;
86
87 static uint8 *GPRAM = NULL;
88 static uint32 GPRAM_Mask;
89
90 static uint8 *GPROM = NULL;
91 static uint32 GPROM_Mask;
92
93 V810 *VB_V810 = NULL;
94
95 VSU *VB_VSU = NULL;
96 static uint32 VSU_CycleFix;
97
98 static uint8 WCR;
99
100 static int32 next_vip_ts, next_timer_ts, next_input_ts;
101
102
103 static uint32 IRQ_Asserted;
104
105 static INLINE void RecalcIntLevel(void)
106 {
107 int ilevel = -1;
108
109 for(int i = 4; i >= 0; i--)
110 {
111 if(IRQ_Asserted & (1 << i))
112 {
113 ilevel = i;
114 break;
115 }
116 }
117
118 VB_V810->SetInt(ilevel);
119 }
120
121 void VBIRQ_Assert(int source, bool assert)
122 {
123 assert(source >= 0 && source <= 4);
124
125 IRQ_Asserted &= ~(1 << source);
126
127 if(assert)
128 IRQ_Asserted |= 1 << source;
129
130 RecalcIntLevel();
131 }
132
133
134
135 static uint8 HWCTRL_Read(v810_timestamp_t &timestamp, uint32 A)
136 {
137 uint8 ret = 0;
138
139 if(A & 0x3)
140 {
141 puts("HWCtrl Bogus Read?");
142 return(ret);
143 }
144
145 switch(A & 0xFF)
146 {
147 default: printf("Unknown HWCTRL Read: %08x\n", A);
148 break;
149
150 case 0x18:
151 case 0x1C:
152 case 0x20: ret = TIMER_Read(timestamp, A);
153 break;
154
155 case 0x24: ret = WCR | 0xFC;
156 break;
157
158 case 0x10:
159 case 0x14:
160 case 0x28: ret = VBINPUT_Read(timestamp, A);
161 break;
162
163 }
164
165 return(ret);
166 }
167
168 static void HWCTRL_Write(v810_timestamp_t &timestamp, uint32 A, uint8 V)
169 {
170 if(A & 0x3)
171 {
172 puts("HWCtrl Bogus Write?");
173 return;
174 }
175
176 switch(A & 0xFF)
177 {
178 default: printf("Unknown HWCTRL Write: %08x %02x\n", A, V);
179 break;
180
181 case 0x18:
182 case 0x1C:
183 case 0x20: TIMER_Write(timestamp, A, V);
184 break;
185
186 case 0x24: WCR = V & 0x3;
187 break;
188
189 case 0x10:
190 case 0x14:
191 case 0x28: VBINPUT_Write(timestamp, A, V);
192 break;
193 }
194 }
195
196 uint8 MDFN_FASTCALL MemRead8(v810_timestamp_t &timestamp, uint32 A)
197 {
198 uint8 ret = 0;
199 A &= (1 << 27) - 1;
200
201 //if((A >> 24) <= 2)
202 // printf("Read8: %d %08x\n", timestamp, A);
203
204 switch(A >> 24)
205 {
206 case 0: ret = VIP_Read8(timestamp, A);
207 break;
208
209 case 1: break;
210
211 case 2: ret = HWCTRL_Read(timestamp, A);
212 break;
213
214 case 3: break;
215 case 4: break;
216
217 case 5: ret = WRAM[A & 0xFFFF];
218 break;
219
220 case 6: if(GPRAM)
221 ret = GPRAM[A & GPRAM_Mask];
222 else
223 printf("GPRAM(Unmapped) Read: %08x\n", A);
224 break;
225
226 case 7: ret = GPROM[A & GPROM_Mask];
227 break;
228 }
229 return(ret);
230 }
231
232 uint16 MDFN_FASTCALL MemRead16(v810_timestamp_t &timestamp, uint32 A)
233 {
234 uint16 ret = 0;
235
236 A &= (1 << 27) - 1;
237
238 //if((A >> 24) <= 2)
239 // printf("Read16: %d %08x\n", timestamp, A);
240
241
242 switch(A >> 24)
243 {
244 case 0: ret = VIP_Read16(timestamp, A);
245 break;
246
247 case 1: break;
248
249 case 2: ret = HWCTRL_Read(timestamp, A);
250 break;
251
252 case 3: break;
253
254 case 4: break;
255
256 case 5: ret = LoadU16_LE((uint16 *)&WRAM[A & 0xFFFF]);
257 break;
258
259 case 6: if(GPRAM)
260 ret = LoadU16_LE((uint16 *)&GPRAM[A & GPRAM_Mask]);
261 else printf("GPRAM(Unmapped) Read: %08x\n", A);
262 break;
263
264 case 7: ret = LoadU16_LE((uint16 *)&GPROM[A & GPROM_Mask]);
265 break;
266 }
267 return(ret);
268 }
269
270 void MDFN_FASTCALL MemWrite8(v810_timestamp_t &timestamp, uint32 A, uint8 V)
271 {
272 A &= (1 << 27) - 1;
273
274 //if((A >> 24) <= 2)
275 // printf("Write8: %d %08x %02x\n", timestamp, A, V);
276
277 switch(A >> 24)
278 {
279 case 0: VIP_Write8(timestamp, A, V);
280 break;
281
282 case 1: VB_VSU->Write((timestamp + VSU_CycleFix) >> 2, A, V);
283 break;
284
285 case 2: HWCTRL_Write(timestamp, A, V);
286 break;
287
288 case 3: break;
289
290 case 4: break;
291
292 case 5: WRAM[A & 0xFFFF] = V;
293 break;
294
295 case 6: if(GPRAM)
296 GPRAM[A & GPRAM_Mask] = V;
297 break;
298
299 case 7: // ROM, no writing allowed!
300 break;
301 }
302 }
303
304 void MDFN_FASTCALL MemWrite16(v810_timestamp_t &timestamp, uint32 A, uint16 V)
305 {
306 A &= (1 << 27) - 1;
307
308 //if((A >> 24) <= 2)
309 // printf("Write16: %d %08x %04x\n", timestamp, A, V);
310
311 switch(A >> 24)
312 {
313 case 0: VIP_Write16(timestamp, A, V);
314 break;
315
316 case 1: VB_VSU->Write((timestamp + VSU_CycleFix) >> 2, A, V);
317 break;
318
319 case 2: HWCTRL_Write(timestamp, A, V);
320 break;
321
322 case 3: break;
323
324 case 4: break;
325
326 case 5: StoreU16_LE((uint16 *)&WRAM[A & 0xFFFF], V);
327 break;
328
329 case 6: if(GPRAM)
330 StoreU16_LE((uint16 *)&GPRAM[A & GPRAM_Mask], V);
331 break;
332
333 case 7: // ROM, no writing allowed!
334 break;
335 }
336 }
337
338 static void FixNonEvents(void)
339 {
340 if(next_vip_ts & 0x40000000)
341 next_vip_ts = VB_EVENT_NONONO;
342
343 if(next_timer_ts & 0x40000000)
344 next_timer_ts = VB_EVENT_NONONO;
345
346 if(next_input_ts & 0x40000000)
347 next_input_ts = VB_EVENT_NONONO;
348 }
349
350 static void EventReset(void)
351 {
352 next_vip_ts = VB_EVENT_NONONO;
353 next_timer_ts = VB_EVENT_NONONO;
354 next_input_ts = VB_EVENT_NONONO;
355 }
356
357 static INLINE int32 CalcNextTS(void)
358 {
359 int32 next_timestamp = next_vip_ts;
360
361 if(next_timestamp > next_timer_ts)
362 next_timestamp = next_timer_ts;
363
364 if(next_timestamp > next_input_ts)
365 next_timestamp = next_input_ts;
366
367 return(next_timestamp);
368 }
369
370 static void RebaseTS(const v810_timestamp_t timestamp)
371 {
372 //printf("Rebase: %08x %08x %08x\n", timestamp, next_vip_ts, next_timer_ts);
373
374 assert(next_vip_ts > timestamp);
375 assert(next_timer_ts > timestamp);
376 assert(next_input_ts > timestamp);
377
378 next_vip_ts -= timestamp;
379 next_timer_ts -= timestamp;
380 next_input_ts -= timestamp;
381 }
382
383 void VB_SetEvent(const int type, const v810_timestamp_t next_timestamp)
384 {
385 //assert(next_timestamp > VB_V810->v810_timestamp);
386
387 if(type == VB_EVENT_VIP)
388 next_vip_ts = next_timestamp;
389 else if(type == VB_EVENT_TIMER)
390 next_timer_ts = next_timestamp;
391 else if(type == VB_EVENT_INPUT)
392 next_input_ts = next_timestamp;
393
394 if(next_timestamp < VB_V810->GetEventNT())
395 VB_V810->SetEventNT(next_timestamp);
396 }
397
398
399 static int32 MDFN_FASTCALL EventHandler(const v810_timestamp_t timestamp)
400 {
401 if(timestamp >= next_vip_ts)
402 next_vip_ts = VIP_Update(timestamp);
403
404 if(timestamp >= next_timer_ts)
405 next_timer_ts = TIMER_Update(timestamp);
406
407 if(timestamp >= next_input_ts)
408 next_input_ts = VBINPUT_Update(timestamp);
409
410 return(CalcNextTS());
411 }
412
413 // Called externally from debug.cpp in some cases.
414 void ForceEventUpdates(const v810_timestamp_t timestamp)
415 {
416 next_vip_ts = VIP_Update(timestamp);
417 next_timer_ts = TIMER_Update(timestamp);
418 next_input_ts = VBINPUT_Update(timestamp);
419
420 VB_V810->SetEventNT(CalcNextTS());
421 //printf("FEU: %d %d %d\n", next_vip_ts, next_timer_ts, next_input_ts);
422 }
423
424 static void VB_Power(void)
425 {
426 memset(WRAM, 0, 65536);
427
428 VIP_Power();
429 VB_VSU->Power();
430 TIMER_Power();
431 VBINPUT_Power();
432
433 EventReset();
434 IRQ_Asserted = 0;
435 RecalcIntLevel();
436 VB_V810->Reset();
437
438 VSU_CycleFix = 0;
439 WCR = 0;
440
441
442 ForceEventUpdates(0); //VB_V810->v810_timestamp);
443 }
444
445 static void SettingChanged(const char *name)
446 {
447 if(!strcasecmp(name, "vb.3dmode"))
448 {
449 // FIXME, TODO (complicated)
450 //VB3DMode = MDFN_GetSettingUI("vb.3dmode");
451 //VIP_Set3DMode(VB3DMode);
452 }
453 else if(!strcasecmp(name, "vb.disable_parallax"))
454 {
455 VIP_SetParallaxDisable(MDFN_GetSettingB("vb.disable_parallax"));
456 }
457 else if(!strcasecmp(name, "vb.anaglyph.lcolor") || !strcasecmp(name, "vb.anaglyph.rcolor") ||
458 !strcasecmp(name, "vb.anaglyph.preset") || !strcasecmp(name, "vb.default_color"))
459
460 {
461 uint32 lcolor = MDFN_GetSettingUI("vb.anaglyph.lcolor"), rcolor = MDFN_GetSettingUI("vb.anaglyph.rcolor");
462 int preset = MDFN_GetSettingI("vb.anaglyph.preset");
463
464 if(preset != ANAGLYPH_PRESET_DISABLED)
465 {
466 lcolor = AnaglyphPreset_Colors[preset][0];
467 rcolor = AnaglyphPreset_Colors[preset][1];
468 }
469 VIP_SetAnaglyphColors(lcolor, rcolor);
470 VIP_SetDefaultColor(MDFN_GetSettingUI("vb.default_color"));
471 }
472 else if(!strcasecmp(name, "vb.input.instant_read_hack"))
473 {
474 VBINPUT_SetInstantReadHack(MDFN_GetSettingB("vb.input.instant_read_hack"));
475 }
476 else if(!strcasecmp(name, "vb.instant_display_hack"))
477 VIP_SetInstantDisplayHack(MDFN_GetSettingB("vb.instant_display_hack"));
478 else if(!strcasecmp(name, "vb.allow_draw_skip"))
479 VIP_SetAllowDrawSkip(MDFN_GetSettingB("vb.allow_draw_skip"));
480 else
481 abort();
482
483
484 }
485
486 struct VB_HeaderInfo
487 {
488 char game_title[256];
489 uint32 game_code;
490 uint16 manf_code;
491 uint8 version;
492 };
493
494 static void ReadHeader(MDFNFILE *fp, VB_HeaderInfo *hi)
495 {
496 #if 0
497 iconv_t sjis_ict = iconv_open("UTF-8", "shift_jis");
498
499 if(sjis_ict != (iconv_t)-1)
500 {
501 char *in_ptr, *out_ptr;
502 size_t ibl, obl;
503
504 ibl = 20;
505 obl = sizeof(hi->game_title) - 1;
506
507 in_ptr = (char*)GET_FDATA_PTR(fp) + (0xFFFFFDE0 & (GET_FSIZE_PTR(fp) - 1));
508 out_ptr = hi->game_title;
509
510 iconv(sjis_ict, (ICONV_CONST char **)&in_ptr, &ibl, &out_ptr, &obl);
511 iconv_close(sjis_ict);
512
513 *out_ptr = 0;
514
515 MDFN_RemoveControlChars(hi->game_title);
516 MDFN_trim(hi->game_title);
517 }
518 else
519 hi->game_title[0] = 0;
520
521 hi->game_code = MDFN_de32lsb(fp->data + (0xFFFFFDFB & (fp->size - 1)));
522 hi->manf_code = MDFN_de16lsb(fp->data + (0xFFFFFDF9 & (fp->size - 1)));
523 hi->version = fp->data[0xFFFFFDFF & (fp->size - 1)];
524 #endif
525 }
526
527 static bool TestMagic(const char *name, MDFNFILE *fp)
528 {
529 if(!strcasecmp(GET_FEXTS_PTR(fp), "vb") || !strcasecmp(GET_FEXTS_PTR(fp), "vboy"))
530 return(true);
531
532 return(false);
533 }
534
535 struct VBGameEntry
536 {
537 uint32 checksums[16];
538 const char *title;
539 uint32 patch_address[512];
540 };
541
542 static const struct VBGameEntry VBGames[] =
543 {
544 { { 0xbb71b522 } , "3D Tetris (US)", { 0xFFF1E740,
545 0xfff1e75a,
546 0xfff5c958,
547 0xfff5c9a4,
548 0xfff5c9b6,
549 0xfff677a6,
550 0xfff677f0,
551 0xfff6c72a,
552 0xfffeffc2,
553 0xfff6df22,
554 0xfff6e01a,
555 0xfff6e20a,
556 0xfff6e302,
557 0xfff6e5e4,
558 0xfff6eb34,
559 0xfff6eb8a,
560 0xfff00cd0,
561 0xfffd9508,
562 0xfffdad90,
563 0xfffd9f1c,
564 0xfffca7a2,
565 0xfffca986,
566 0xfffcaad4,
567 0xfffcacb0,
568 0xfff3dbc6,
569 0xfff3dc58,
570 0xfff3ca1a,
571 0xfff3effe,
572 0xfff3f06c,
573 0xfff3f122,
574 0xfff3f2da,
575 0xfff3c9d8,
576 0xfff01892,
577 0xfff017f4,
578 0xfff016c8,
579 0xfff4677c,
580 0xfff4620a,
581 0xfff3503e,
582 0xfff3f97a,
583 0xfff3fae0,
584 0xfff01270,
585 0xfff473c8,
586 0xfff472dc,
587 0xfff0160a,
588 0xfff6e112,
589 0xfff6e7d2,
590 0xfffc1730,
591 0xfff3f1e6,
592 0xfffc22da,
593 0xfffc20a2,
594 0xfffc2378,
595 0xfff36152,
596 0xfff37120,
597 0xfff378b4,
598 0xfffc1b44,
599 0xfffc1b8e,
600 0xfff3f258,
601 0xfff3655c,
602 0xfffd9902,
603 0xfff49b60,
604 0xfff86ef0,
605 0xfff3cf08,
606 0xfff5894c,
607 0xfff3cec2,
608 0xfff5a73e,
609 0xfff400ce,
610 0xfff3c2ec,
611 0xfff5b5c2,
612 0xfff5b64a,
613 0xfffd2968,
614 0xfffd2ca0,
615 0xfffd2be0,
616 0xfffd2b40,
617 0xfffd2d10,
618 0xfffd2d26,
619 0xfff5a6a0,
620 0xfff5a564,
621 0xfffd9800,
622 0xfffd9a04,
623 0xfffd9b30,
624 0xfffcd8d0,
625 0xfffcd830,
626 0xfffc15a4,
627 0xfff4b5f2,
628 0xfff3f346,
629 0xfff374ae,
630 0xfff3fa42,
631 0xfff3720c,
632 0xfff38298,
633 0xfff38370,
634 0xfff2b8a2,
635 0xfff2bf52,
636 0xfff0199a,
637 0xfff01dc0,
638 0xfffd169e,
639 0xfffd19d6,
640 0xfffd1876,
641 0xfffd1a46,
642 0xfffd1a5c,
643 0xfff676b6,
644 0xfff675fc,
645 0xfff37b48,
646 0xfffc246e,
647 0xfffc24b8,
648 0xfff365e8,
649 0xfff2dfa0,
650 0xfff36674,
651 0xfff36700,
652 0xfff598f4,
653 0xfff59992,
654 0xfff59c2a,
655 0xfff59c74,
656 0xfff4709a,
657 0xfff46eec,
658 0xfff4714c,
659 0xfff4b808,
660 0xfff3f3b2,
661 0xfffdaeda,
662 0xfffdb044,
663 0xfffdae36,
664 0xfff4b698,
665 0xfff4b73c,
666 0xfff49c06,
667 0xfffdb322,
668 0xfffdb18c,
669 0xfff4ba68,
670 0xfff4b8d2,
671 0xfff474aa,
672 0xfffd1916,
673 0xfff3d0ac,
674 0xfff477ac,
675 0xfff3d2ca,
676 0xfff476c0,
677 0xfff5a41e,
678 0xfff5a04c,
679 0xfff4788e,
680 0xfffc1392,
681 0xfffc14f8,
682 } },
683
684 { { 0xe81a3703 }, "Bound High!", { 0x0703181A , 0x070229BE, 0x07002CA6,
685 0x07024f20,
686 0x070317ae,
687 0x07030986,
688 0x070309ca,
689 0x07031968,
690 0x07030ad2,
691 0x07030b16,
692 0x070319be,
693 0x07031a20,
694 0x070296b4,
695 0x0702984e,
696 0x07029888,
697 0x070298d0,
698 0x07029910,
699 0x070299ce,
700 0x07030c3a,
701 0x07030dfc,
702 0x07030e52,
703 0x07030eb4,
704 0x070250fa,
705 0x07025148,
706 0x07025776,
707 0x070257c6,
708 0x07025828,
709 0x07021dc0,
710 0x07021e50,
711 0x070008e6,
712 0x0700155c,
713 0x070005f4,
714 0x07022a08,
715 0x07031e2e,
716 0x07032308,
717 0x0703234a,
718 0x070323ac,
719 0x0703a27a,
720 0x0703a754,
721 0x0703a77c,
722 0x0703a7b4,
723 0x0703a816,
724 0x07002104,
725 0x070028e2,
726 0x0700299e,
727 0x070029d8,
728 0x07001782,
729 0x07001912,
730 0x070024da,
731 0x070347e6,
732 0x07035ec4,
733 0x07035f16,
734 0x07035f78,
735 0x0702d152,
736 0x0702d19a,
737 0x0702d548,
738 0x0702d5cc,
739 0x07001c30,
740 0x0702e97e,
741 0x0702e9bc,
742 0x070009b2,
743 0x07030422,
744 0x070305fc,
745 0x0703064c,
746 0x070306ae,
747 0x07026c80,
748 0x07027618,
749 0x07027656,
750 0x07001a92,
751 0x0702eff8,
752 0x0702f4e6,
753 0x0702f54e,
754 0x0702f5b0,
755 0x07025df6,
756 0x07025fb2,
757 0x07026036,
758 0x0702e01a,
759 0x0702e090,
760 0x0702e114,
761 0x0702e8ea,
762 0x07001440,
763 0x0702c46e,
764 0x0702c4b6,
765 0x0702c9e4,
766 0x0702ca6e,
767 0x0702a532,
768 0x0702a5bc,
769 0x0702aba0,
770 0x0702b4ce,
771 0x0702b536,
772 } },
773
774 { { 0xc9710a36} , "Galactic Pinball", { 0xFFF4018A,
775 0xfff40114,
776 0xfff51886,
777 0xfff51abe,
778 0xfff4b704,
779 0xfff4ec7a,
780 0xfff53708,
781 0xfff53a3c,
782 }},
783
784 { { 0x2199af41 }, "Golf (US)", { 0xFFE0141A, 0xFFE097C4, 0xFFE1F47A, 0xFFE0027E, 0xFFE05CA0, 0xFFE014A0,
785 0xffe00286,
786 0xffe013d0,
787 0xffe013f0,
788 0xffe01482,
789 0xffe01004,
790 0xffe01024,
791 0xffe00d30,
792 0xffe00d50,
793 0xffe00db4,
794 0xffe00dd4,
795 0xffe13efe,
796 0xffe13f62,
797 0xffe13fd2,
798 0xffe01744,
799 0xffe01764,
800 0xffe05c90,
801 0xffe017b2,
802 0xffe017d2,
803 0xffe01930,
804 0xffe01950,
805 0xffe01c4a,
806 0xffe01c6a,
807 0xffe01cb8,
808 0xffe01cd8,
809 0xffe01dce,
810 0xffe01de8,
811 0xffe01e5a,
812 0xffe01e7a,
813 0xffe1409e,
814 0xffe02450,
815 0xffe02470,
816 0xffe024b0,
817 0xffe024d0,
818 0xffe02530,
819 0xffe02550,
820 0xffe0257e,
821 0xffe0259e,
822 0xffe1429c,
823 0xffe027c4,
824 0xffe027e4,
825 0xffe13f2a,
826 0xffe097a4,
827 0xffe181bc,
828 0xffe1ce40,
829 0xffe1ce60,
830 0xffe07e80,
831 0xffe07ea0,
832 0xffe07ec0,
833 0xffe07ee0,
834 0xffe0810e,
835 0xffe08158,
836 0xffe1e468,
837 0xffe1e488,
838 0xffe2198c,
839 0xffe09a96,
840 0xffe09ab6,
841 0xffe1f7be,
842 0xffe1f7de,
843 0xffe1f8ae,
844 0xffe1f9d6,
845 0xffe1fa18,
846 0xffe1fa38,
847 0xffe05c68,
848 0xffe05c78,
849 0xffe14344,
850 0xffe09e06,
851 0xffe16d8a,
852 0xffe16daa,
853 0xffe21712,
854 0xffe1f37a,
855 0xffe1f39a,
856 0xffe1f624,
857 0xffe1f666,
858 0xffe1f686,
859 0xffe141f8,
860 0xffe151d2,
861 0xffe17622,
862 } },
863
864 { { 0xefd0ac36 }, "Innsmouth House (Japan)", { 0x070082F4,
865 0x07017546,
866 0x07016f9a,
867 0x07017558,
868 0x07016fac,
869 0x07017692,
870 0x070176a4,
871 }},
872
873 { { 0xa44de03c, 0x81af4d6d /*[b1]*/, 0xb15d706e /*(Enable Cheats Hack)*/, 0x79a99f3c /*[T+Ger1.0_KR155E]*/ }, "Jack Bros (US)", { 0x070001A6 }},
874 { { 0xcab61e8b }, "Jack Bros (Japan)", {
875 0x07000192,
876 } },
877
878 // Is 0xbf0d0ab0 the bad dump?
879 { { 0xa47de78c, 0xbf0d0ab0 }, "Mario Clash", { 0xFFFF5BB4, 0xFFFE6FF0, 0xFFFE039E,
880 0xfffdd786,
881 0xfffdd76c,
882 0xffff5bc6,
883 0xffff73a4,
884 0xffff73b6,
885 0xfffdd836,
886 0xfffdd848,
887 0xffff916c,
888 0xffff917e,
889 0xfffe7002,
890 0xfffe7c36,
891 0xfffe7c48,
892 0xffff44f4,
893 0xffff4506,
894 0xfffe03b0,
895 0xffff2514,
896 0xffff2526,
897 0xffff9be2,
898 0xffff9bf4,
899 } },
900
901 { { 0x7ce7460d }, "Mario's Tennis", { 0xFFF8017C, 0xFFF90FEA, 0xFFF86DFA, 0xFFF873D6, 0xFFF9301C,
902 0xfff801a2,
903 0xfff90f98,
904 0xfff90fae,
905 0xfff90fc8,
906 0xfff914c4,
907 0xfff9150e,
908 0xfff82a00,
909 0xfff82a1a,
910 0xfff82a38,
911 0xfff86b98,
912 0xfff86e66,
913 0xfff871a2,
914 0xfff8d9b6,
915 0xfff8da5a,
916 0xfff8dcf8,
917 0xfff87aa8,
918 0xfff93c86,
919 0xfff93ca8,
920 0xfff93ce0,
921 0xfff94338,
922 0xfff93158,
923 } },
924
925 { { 0xdf4d56b4 }, "Nester's Funky Bowling (US)", { 0xFFE00B78, 0xFFE00D82, 0xFFE0105A, 0xFFE00FCE,
926 0xffe00f6a,
927 0xffe00f72,
928 0xffe00ddc,
929 0xffe0089e,
930 0xffe00fba,
931 0xffe03702,
932 0xffe01064,
933 0xffe0c024,
934 0xffe00bba,
935 0xffe0d86c,
936 0xffe0d51c,
937 } },
938
939 { { 0x19bb2dfb, 0x25fb89bb /*[b1]*/, 0x21d224af /*[h1]*/, 0xc767fe4b /*[h2]*/ }, "Panic Bomber (US)", { 0x07001FE8,
940 0x07001f34,
941 0x07001fc6,
942 } },
943
944 // Japan and US versions probably use the same code.
945 { { 0xaa10a7b4, 0x7e85c45d }, "Red Alarm", { 0x202CE, 0x070202B4,
946 0x070202e2,
947 0x07020642,
948 0x0702074c,
949 0x07001f50,
950 0x0703ca0a,
951 0x07045c9e,
952 0x0703326a,
953 0x07031aae,
954 0x070328a4,
955 0x07032e5e,
956 0x0703748e,
957 0x07035868,
958 0x07035948,
959 0x07031c88,
960 0x0703786a,
961 0x0703628e,
962 0x07035b20,
963 0x07035bc0,
964 0x07033856,
965 0x07037370,
966 0x07031a2e,
967 0x070373c4,
968 0x0703cfd8,
969 0x0703d03c,
970 0x0703d0a4,
971 0x0702eae2,
972 0x0703ce00,
973 0x07044f02,
974 0x07041922,
975 0x07041df0,
976 0x0701ba38,
977 0x07045176,
978 0x07044f8c,
979 0x0703c926,
980 0x0703c940,
981 0x0703c712,
982 0x0703c73c,
983 0x07023158,
984 0x070231d6,
985 0x0702320c,
986 0x07020a60,
987 0x0700489c,
988 0x07032174,
989 0x070324ca,
990 0x0702ef56,
991 0x070414b0,
992 0x0702052e,
993 0x070321a6,
994 0x070321fe,
995 0x07032224,
996 0x07021866,
997 0x07021aa4,
998 0x07021b36,
999 0x07021b5e,
1000 0x07021b88,
1001 0x0703c6ba,
1002 0x0703cb3c,
1003 0x0703c67a,
1004 0x070412d2,
1005 0x0704132a,
1006 0x07041428,
1007 0x07020d2e,
1008 0x07020d48,
1009 0x0703755a,
1010 0x070375ac,
1011 0x070375da,
1012 0x07020aaa,
1013 0x0701ba8a,
1014 0x07041b0c,
1015 0x070355d8,
1016 0x07051ce0,
1017 0x070049e0,
1018 0x070049fa,
1019 0x07004a94,
1020 0x07020fb8,
1021 0x07021046,
1022 0x070210dc,
1023 0x07004bc2,
1024 0x07004ac0,
1025 0x07041640,
1026 0x07041698,
1027 0x07041744,
1028 0x07020eb0,
1029 0x070208bc,
1030 0x07020db6,
1031 0x07020e40,
1032 0x07004b28,
1033 0x070417c0,
1034 0x07041d3c,
1035 0x07035f18,
1036
1037 0x07022bd2,
1038 0x07020504,
1039 0x070419a4,
1040 0x07041a78,
1041 } },
1042
1043 { { 0x44788197 }, "SD Gundam Dimension War (Japan)", {
1044 0xfff296de,
1045 0xfff2970a,
1046 0xfff29730,
1047 0xfff298b0,
1048 0xfff298fa,
1049 0xfff29aac,
1050 0xfff29af2,
1051 0xfff29b1a,
1052 0xfff065ba,
1053 0xfff29b56,
1054 0xfff29cd6,
1055 0xfff4b7aa,
1056 0xfff4b8e4,
1057 0xfff4b9e2,
1058 0xfff4ba2e,
1059 0xfff4bbba,
1060 0xfff2824c,
1061 0xfff2835a,
1062 0xfff2848e,
1063 0xfff28aa4,
1064 0xfff28b20,
1065 0xfff28d66,
1066 0xfff28e5c,
1067 0xfff28e76,
1068 0xfff065e6,
1069 0xfff29504,
1070 0xfff5869e,
1071 0xfff58134,
1072 0xfff563e4,
1073 0xfff5687e,
1074 0xfff19686,
1075 0xfff196e6,
1076 0xfff19726,
1077 0xfff1974e,
1078 0xfff1a3a2,
1079 0xfff1083e,
1080 0xfff140b2,
1081 0xfff1372c,
1082 0xfff13c0e,
1083 0xfff13c70,
1084 0xfff166f2,
1085 0xfff18010,
1086 0xfff18070,
1087 0xfff18604,
1088 0xfff10654,
1089 0xfff44a7a,
1090 0xfff44a90,
1091 0xfff44ab4,
1092 0xfff44af8,
1093 0xfff4bd2e,
1094 0xfff4517a,
1095 0xfff439e6,
1096 0xfff43e92,
1097 0xfff43ea8,
1098 0xfff43ecc,
1099 0xfff43ef8,
1100 0xfff442ee,
1101 0xfff444c8,
1102 0xfff1995c,
1103 0xfff191ce,
1104 0xfff264d4,
1105 0xfff267ae,
1106 0xfff489aa,
1107 0xfff489ee,
1108 0xfff48a32,
1109 0xfff48a76,
1110 0xfff48aba,
1111 0xfff48ccc,
1112 0xfff48dae,
1113 0xfff493f2,
1114 0xfff49422,
1115 0xfff494c0,
1116 0xfff49620,
1117 0xfff4a822,
1118 0xfff4a940,
1119 0xfff4aa46,
1120 0xfff4ab2a,
1121 0xfff1b3b6,
1122 0xfff1b3fc,
1123 0xfff1b456,
1124 0xfff1b496,
1125 0xfff1b4d6,
1126 0xfff1b516,
1127 0xfff1b556,
1128 0xfff1bc6e,
1129 0xfff1bc94,
1130 0xfff1bcaa,
1131 0xfff1bcce,
1132 0xfff1bcf6,
1133 0xfff1bd0c,
1134 0xfff1bd48,
1135 0xfff1bdca,
1136 0xfff1be2a,
1137 0xfff1bed6,
1138 0xfff26c88,
1139 0xfff4ac00,
1140 0xfff4ad68,
1141 0xfff4b0f8,
1142 0xfff26a70,
1143 0xfff26b18,
1144 0xfff1bf5e,
1145 0xfff26dbe,
1146 0xfff26e54,
1147 0xfff441c4,
1148 0xfff2d548,
1149 0xfff2d630,
1150 0xfff2d67c,
1151 0xfff2d6c0,
1152 0xfff2d750,
1153 0xfff2d7de,
1154 0xfff2d872,
1155 0xfff2d90e,
1156 0xfff2d9bc,
1157 0xfff2da64,
1158 0xfff2daec,
1159 0xfff2db74,
1160 0xfff2dc1c,
1161 0xfff2dc94,
1162 0xfff2dd32,
1163 0xfff2ddf4,
1164 0xfff2df4c,
1165 0xfff3017a,
1166 0xfff3091c,
1167 0xfff271f2,
1168 0xfff272a0,
1169 0xfff4be52,
1170 0xfff4bf06,
1171 0xfff4bf36,
1172 0xfff4bf5e,
1173 0xfff4c4fe,
1174 0xfff19852,
1175 0xfff44b38,
1176 0xfff44e4a,
1177 0xfff44f4c,
1178 0xfff0edc0,
1179 0xfff0f142,
1180 } },
1181
1182 { { 0xfa44402d }, "Space Invaders VC (Japan)", {
1183 0xfff80154,
1184 0xfff87e04,
1185 0xfff87e18,
1186 } },
1187
1188 // Is 0xc2211fcc a bad dump?
1189 { {0x60895693, 0xc2211fcc, 0x7cb69b3a /*[T+Eng]*/ }, "Space Squash (Japan)", {
1190 0x0701a97e,
1191 } },
1192
1193 { { 0x6ba07915, 0x41fb63bf /*[b1]*/ }, "T&E Virtual Golf (Japan)", {
1194 0x0700027e,
1195 0x07000286,
1196 0x070013d0,
1197 0x070013f0,
1198 0x0700141a,
1199 0x07001004,
1200 0x07001024,
1201 0x07000d30,
1202 0x07000d50,
1203 0x07000db4,
1204 0x07000dd4,
1205 0x07013c4e,
1206 0x07013cb2,
1207 0x07013d22,
1208 0x07001718,
1209 0x07001738,
1210 0x07001a32,
1211 0x07001a52,
1212 0x07005988,
1213 0x07005998,
1214 0x07001aa0,
1215 0x07001ac0,
1216 0x07001bb6,
1217 0x07001bd0,
1218 0x07001c36,
1219 0x07001c56,
1220 0x07013dee,
1221 0x0700223c,
1222 0x0700225c,
1223 0x0700229c,
1224 0x070022bc,
1225 0x07013fec,
1226 0x070024ee,
1227 0x0700250e,
1228 0x07013c7a,
1229 0x0700947c,
1230 0x0700949c,
1231 0x07009ade,
1232 0x0702162c,
1233 0x07017e2c,
1234 0x0701cae0,
1235 0x0701cb00,
1236 0x07007b70,
1237 0x07007b90,
1238 0x07007bb0,
1239 0x07007bd0,
1240 0x07007dfe,
1241 0x07007e48,
1242 0x0701e108,
1243 0x0701e128,
1244 0x07017280,
1245 0x0700976e,
1246 0x0700978e,
1247 0x0701f45e,
1248 0x0701f47e,
1249 0x0701f54e,
1250 0x0701f676,
1251 0x0701f6b8,
1252 0x0701f6d8,
1253 0x07005960,
1254 0x07005970,
1255 0x07014094,
1256 0x070169e6,
1257 0x07016a06,
1258 0x07013f48,
1259 0x0701f01a,
1260 0x0701f03a,
1261 0x0701f11a,
1262 0x0701f2c4,
1263 0x0701f306,
1264 0x0701f326,
1265 0x07014f22,
1266 0x07007982,
1267 0x070079a2,
1268 } },
1269
1270 { { 0x36103000, 0xa6e0d6db /*[T+Ger.4b_KR155E]*/, 0x126123ad /*[T+Ger1.0_KR155E]*/ }, "Teleroboxer", {
1271 0xfff2c408,
1272 0xfff2c3f2,
1273 0xfff2b626,
1274 0xfff2c2ee,
1275 0xfff2c2ae,
1276 0xfff2b71c,
1277 0xfff2b736,
1278 0xfff2c1da,
1279 0xfff2c21a,
1280 0xfff2c36c,
1281 0xfff2b876,
1282 0xfff2b996,
1283 0xfff2b9b0,
1284 0xfff2b970,
1285 0xfff2baf4,
1286 0xfff2bb50,
1287 0xfff2bc7e,
1288 0xfff2bc9c,
1289 0xfff6c2a2,
1290 0xfff6c386,
1291 0xfff6c39c,
1292 0xfff6ad22,
1293 0xfff0304c,
1294 0xfff03b8e,
1295 0xfff042ce,
1296 0xfff04782,
1297 0xfff04c5c,
1298 0xfff04d90,
1299 0xfff11242,
1300 0xfff12f4a,
1301 0xfff141b8,
1302 0xfff04192,
1303 0xfff0414c,
1304 0xfff0616c,
1305 0xfff069d0,
1306 0xfff07912,
1307 0xfff1a980,
1308 0xfff1dc7e,
1309 0xfff1f060,
1310 0xfff22c92,
1311 0xfff2ae50,
1312 0xfff2af42,
1313 0xfff2af60,
1314 0xfff2e08c,
1315 0xfff32112,
1316 0xfff3213a,
1317 0xfff2e9aa,
1318
1319 0xfff2e66c,
1320 0xfff2eb50,
1321 0xfff2eb6e,
1322 0xfff29f8c,
1323 0xfff2a1e4,
1324 0xfff2a36e,
1325 0xfff2a38c,
1326 0xfff339b0,
1327 0xfff339c6,
1328 0xfff25802,
1329 0xfff25a1e,
1330 0xfff2637c,
1331 0xfff2745c,
1332 0xfff27a74,
1333 0xfff29010,
1334 0xfff04014,
1335
1336 0xfff32368,
1337 0xfff32382,
1338 0xfff32398,
1339 0xfff325ea,
1340 0xfff325a4,
1341 0xfff32668,
1342 0xfff326c0,
1343 0xfff326fc,
1344 0xfff32730,
1345 0xfff32764,
1346 0xfff32798,
1347 0xfff327c2,
1348 0xfff327f0,
1349 0xfff0811c,
1350 0xfff083ac,
1351 0xfff098e4,
1352
1353 0xfff0ed12,
1354 0xfff0f114,
1355 0xfff0f7aa,
1356 0xfff101f0,
1357 0xfff102ae,
1358 0xfff108be,
1359 0xfff0a568,
1360 0xfff0aa78,
1361 0xfff0be3c,
1362 0xfff043a4,
1363 0xfff0435e,
1364 0xfff0dcf8,
1365 0xfff0dcb2,
1366
1367 0xfff054a4,
1368 0xfff05706,
1369 0xfff05934,
1370 0xfff23ad2,
1371 0xfff23b76,
1372 0xfff2420e,
1373
1374 0xfff5d454,
1375 0xfff5d51a,
1376 0xfff5d550,
1377 0xfff30eac,
1378 } },
1379
1380 { { 0x40498f5e }, "Tobidase! Panibomb (Japan)", {
1381 0x07001fe4,
1382 0x07001f30,
1383 0x07001fc2,
1384 } },
1385
1386 { { 0x133e9372 }, "VB Wario Land", { 0x1c232e, 0x1BFB98, 0x1C215C, 0x1C27C6,
1387 0xfffc2814,
1388 0xfffbf49a,
1389 0xfffbf48c,
1390 0xfffc45bc,
1391 0xfffc2956,
1392 } },
1393
1394 // Good grief(probably not even all of them!):
1395 { { 0x3ccb67ae }, "V-Tetris (Japan)", { 0xFFFA2ED4, 0xFFFA9FDC, 0xFFFA776A, 0xFFFA341C, 0xFFFABAB2, 0xFFFACCAE, 0xFFF8B38A, 0xFFFA9C14, 0xFFF8F086, 0xFFF925FE,
1396 0xfffa2e58,
1397 0xfffa2e78,
1398 0xfffa2e98,
1399 0xfffa2f02,
1400 0xfffa2f32,
1401 0xfffa2fb6,
1402 0xfffa2fd4,
1403 0xfff965e4,
1404 0xfffa9f6c,
1405 0xfffa9f8c,
1406 0xfffa9fac,
1407 0xfffaa026,
1408 0xfffaa044,
1409 0xfffa76c6,
1410 0xfffa7704,
1411 0xfffa7724,
1412 0xfffa7a2a,
1413 0xfffa7aba,
1414 0xfffa30d4,
1415 0xfffa30f2,
1416 0xfffa3142,
1417 0xfffa3158,
1418 0xfffa3268,
1419 0xfffa33c0,
1420 0xfffa33f4,
1421 0xfffa34b6,
1422 0xfffa35dc,
1423 0xfffa35f2,
1424 0xfffa3684,
1425 0xfffa369a,
1426 0xfffa376e,
1427 0xfffa3784,
1428 0xfffa3918,
1429 0xfffa3930,
1430 0xfffa3946,
1431 0xfffa39e4,
1432 0xfffa3a4e,
1433 0xfffa3ba6,
1434 0xfffa3bea,
1435 0xfffa3c00,
1436 0xfffa3cde,
1437 0xfffa3db4,
1438 0xfffa3de0,
1439 0xfffa3dfe,
1440 0xfffaba16,
1441 0xfffaba44,
1442 0xfffaba76,
1443 0xfffabc48,
1444 0xfffabf3e,
1445 0xfffac0f6,
1446 0xfffac45e,
1447 0xfffac59e,
1448 0xfffac904,
1449 0xfffaca44,
1450 0xfffaca94,
1451 0xfffacbc0,
1452 0xfffacbf0,
1453 0xfffacc2c,
1454 0xfffad262,
1455 0xfffacfe6,
1456 0xfffad01c,
1457 0xfffad296,
1458 0xfffad2f0,
1459 0xfff8b012,
1460 0xfff8b2de,
1461 0xfff8b2f2,
1462 0xfff8b31e,
1463 0xfff8b33e,
1464 0xfff8bf62,
1465 0xfff8c20e,
1466 0xfff8b98e,
1467 0xfff8bc4e,
1468 0xfff8c554,
1469 0xfff8c800,
1470 0xfff8c824,
1471 0xfff8c842,
1472 0xfff8d15e,
1473 0xfff8d188,
1474 0xfff8d1c0,
1475 0xfff8d1f6,
1476 0xfff8d5da,
1477 0xfff8d25e,
1478 0xfff8d27c,
1479 0xfffa9b98,
1480 0xfffa9bb8,
1481 0xfffa9bd8,
1482 0xfffa9f22,
1483 0xfffa9f40,
1484 0xfff9233c,
1485 0xfff923d0,
1486 0xfff923e4,
1487 0xfff9244a,
1488 0xfff92492,
1489 0xfff924b2,
1490 0xfff8f056,
1491 0xfff8f46a,
1492 0xfff9250e,
1493 0xfff925ba,
1494 0xfff925e0,
1495 0xfff94036,
1496 0xfff92f56,
1497 0xfff93d72,
1498 0xfff9409c,
1499 0xfff94270,
1500 0xfff928c0,
1501 0xfff92920,
1502 0xfff92940,
1503 0xfff9296e,
1504 0xfff929c8,
1505 0xfff92a74,
1506 0xfff92a9c,
1507 0xfff92aba,
1508 0xfff9265c,
1509 0xfff92688,
1510 0xfff926ba,
1511 0xfff926e6,
1512 0xfff92712,
1513 0xfff8f7b0,
1514 0xfff8f886,
1515 0xfff8f8a8,
1516 0xfff8f96a,
1517 0xfff8f998,
1518 0xfff8fae0,
1519 0xfff8faf6,
1520 0xfff8fb14,
1521 0xfff8fba4,
1522 0xfff8fcd0,
1523 0xfff8fd0c,
1524 0xfff8fd9c,
1525 0xfff8fe4c,
1526 0xfff8ff7a,
1527 0xfff8ffc8,
1528 0xfff90058,
1529 0xfff90108,
1530 0xfff90236,
1531 0xfff90284,
1532 0xfff90314,
1533 0xfff903c4,
1534 0xfff904f2,
1535 0xfff90540,
1536 0xfff905d0,
1537 0xfff90680,
1538 0xfff907ae,
1539 0xfff907fc,
1540 0xfff9088c,
1541 0xfff908ae,
1542 0xfff908de,
1543 0xfff909cc,
1544 0xfff8f4c6,
1545 0xfff8f586,
1546 0xfff8f59a,
1547 0xfff8f5bc,
1548 0xfff8f5ec,
1549 0xfff8f642,
1550 0xfff8f714,
1551 0xfff8f740,
1552 0xfff8f77c,
1553 0xfff940f4,
1554 0xfff9411a,
1555 0xfff94134,
1556 0xfffad91e,
1557 0xfff94152,
1558 0xfffad98a,
1559 0xfffad9f8,
1560 0xfffada66,
1561 0xfffadad8,
1562 0xfffadb4a,
1563 0xfffadbbc,
1564 0xfffadc2e,
1565 0xfffadc7e,
1566 0xfffb72e2,
1567 0xfff94172,
1568 0xfff941a6,
1569 0xfffa79b0,
1570 0xfffa7924,
1571 0xfffabd9e,
1572 0xfffabe32,
1573 0xfffabe54,
1574 0xfffabee8,
1575 0xfffabf18,
1576 0xfffac11a,
1577 0xfffac2c2,
1578 0xfffac41a,
1579 0xfffac5c0,
1580 0xfffac5d6,
1581 0xfffac768,
1582 0xfffac8c0,
1583 0xfffaca66,
1584 0xfffacc78,
1585 0xfffaddb2,
1586 0xfffade64,
1587 0xfffadf18,
1588 0xfffadfcc,
1589 0xfffae084,
1590 0xfffae13c,
1591 0xfffae1f4,
1592 0xfffae2ac,
1593 0xfffae2d8,
1594 0xfffa6dda,
1595 0xfffa6dfa,
1596 0xfffa6e24,
1597 0xfffa6e62,
1598 0xfffa6e82,
1599 0xfff9c9e2,
1600 0xfff9ca02,
1601 0xfff9ca2e,
1602 0xfff9cbd4,
1603 0xfff9cc14,
1604 0xfff9ccba,
1605 0xfff9cce6,
1606 0xfff9cd8c,
1607 0xfff9cdea,
1608 0xfff9ce86,
1609 0xfff9cea4,
1610 0xfffa6f46,
1611 0xfffa6f70,
1612 0xfffa6fae,
1613 0xfffa6fce,
1614 0xfff944fe,
1615 0xfff9453a,
1616 0xfff945bc,
1617 0xfff94604,
1618 0xfff946b0,
1619 0xfff946d6,
1620 0xfff946f4,
1621 0xfff9616a,
1622 0xfff95e7e,
1623 0xfff950be,
1624 0xfff961d0,
1625 0xfff964f8,
1626 0xfff948ca,
1627 0xfff948ea,
1628 0xfff94918,
1629 0xfff94972,
1630 0xfff94a1e,
1631 0xfff94a46,
1632 0xfff94a64,
1633 0xfff962d2,
1634 0xfff962f8,
1635 0xfff96312,
1636 0xfff96330,
1637 0xfffb7226,
1638 0xfff96350,
1639 0xfff96384,
1640 0xfff9652a,
1641 0xfff96554,
1642 0xfffa706a,
1643 0xffface1a,
1644 0xffface50,
1645 0xffface70,
1646 0xfff8c238,
1647 0xfff8c3a4,
1648 0xfff8c3ce,
1649 0xfff8c536,
1650 0xfff8de2a,
1651 0xfff8de54,
1652 0xfff8de8e,
1653 0xfff8dec6,
1654 0xfff8e284,
1655 0xfff8df1e,
1656 0xfff8df3c,
1657 0xfffa9dce,
1658 0xfffa9e56,
1659 0xfff943a2,
1660 0xfff94454,
1661 0xfff944e8,
1662 0xfff9486a,
1663 0xfff8cc76,
1664 0xfff8cca0,
1665 0xfff8ccda,
1666 0xfff8cd12,
1667 0xfff8d0d0,
1668 0xfff8cd6a,
1669 0xfff8cd88,
1670 0xfff8dda4,
1671 0xfff8d8bc,
1672 0xfff8ddc8,
1673 0xfff8ddf0,
1674 0xfff8c8de,
1675 0xfff8cbaa,
1676 0xfff8cbbe,
1677 0xfff8cbe8,
1678 0xfff8cc10,
1679 0xfff8d0f4,
1680 0xfff8d11c,
1681 0xfff8e2a8,
1682 0xfff8e2d0,
1683 0xfff8bc6c,
1684 0xfff8bf2c,
1685 0xfff8bf44,
1686 0xfff8f680,
1687 0xfff8e4f8,
1688 0xfff8e518,
1689 0xfff8e5ce,
1690 0xfff8e606,
1691 0xfff8ed2e,
1692 0xfff8eb30,
1693 0xfff8efa6,
1694 0xfff8efd0,
1695 0xfff8f012,
1696 0xfff9cdb2,
1697 0xfffa146a,
1698 0xfffa169c,
1699 0xfffa16ca,
1700 0xfffa16fa,
1701 0xfffa1766,
1702 0xfffa179e,
1703 0xfffa21d8,
1704 0xfffa2272,
1705 0xfffa2290,
1706 0xfffa22a6,
1707 0xfffa24d4,
1708 0xfff8df6e,
1709 0xfff8df98,
1710 0xfff8dfc6,
1711 0xfff8cdba,
1712 0xfff8cde4,
1713 0xfff8ce12,
1714 0xfff8d2ae,
1715 0xfff8d2d8,
1716 0xfff8d30e,
1717 } },
1718
1719 { { 0x4c32ba5e, 0xdc8c0bf4 /*[h1]*/ }, "Vertical Force (US)", { 0x7000BF4 } },
1720
1721 // Is 0x05d06377 a bad dump?
1722 { { 0x9e9b8b92, 0x05d06377 }, "Vertical Force (Japan)", { 0x7000BF4 } },
1723
1724 { { 0x20688279, 0xddf9abe0 /*(Debug Menu Hack)*/ }, "Virtual Bowling (Japan)", {
1725 0xfff24eda,
1726 0xfff28bea,
1727 0xfff28c00,
1728 0xfff1fb9a,
1729 0xfff1c284,
1730 0xfff1ddc4,
1731 0xfff0b93e,
1732 0xfff249ac,
1733 0xfff0b9a4,
1734 0xfff258fc,
1735 0xfff172aa,
1736 0xfff2606e,
1737 0xfff1a0e6,
1738 0xfff1a0fc,
1739 0xfff17222,
1740 0xfff26058,
1741 0xfff0b984,
1742 0xfff21080,
1743 0xfff21096,
1744 0xfff1ddae,
1745 0xfff13288,
1746 0xfff132d8,
1747 0xfff13ec8,
1748 0xfff0b920,
1749 0xfff284e8,
1750 0xfff284fe,
1751 0xfff154ac,
1752 0xfff155f8,
1753 0xfff15706,
1754 0xfff2f51e,
1755 0xfff1fb84,
1756 0xfff27310,
1757 0xfff0c480,
1758 0xfff2d618,
1759 0xfff2d62e,
1760 } },
1761
1762 { { 0x526cc969, 0x45471e40 /*[b1]*/ }, "Virtual Fishing (Japan)", {
1763 0x07000388,
1764 0x07000368,
1765 } },
1766
1767
1768 { { 0x8989fe0a }, "Virtual Lab (Japan)", {
1769 0x070000ae,
1770 0x0700395a,
1771 0x070051ac,
1772 0x070039cc,
1773 0x07003a96,
1774 0x07003b1c,
1775 0x07003bce,
1776 0x07003c4e,
1777 0x07003d42,
1778 0x07003e42,
1779 0x07003e9c,
1780 0x07003f30,
1781 0x07004098,
1782 0x070041ee,
1783 0x07003180,
1784 0x070050f4,
1785 0x07002fc4,
1786 0x07000960,
1787 0x070009a6,
1788 0x07000b60,
1789 0x07000bb4,
1790 0x07001764,
1791 0x070020ec,
1792 0x070075cc,
1793 0x07003112,
1794 0x070001b2,
1795 0x07001074,
1796 0x070010e4,
1797 0x070011d0,
1798 0x07001262,
1799 0x070012f6,
1800 0x070013f4,
1801 0x070014bc,
1802 0x070015a2,
1803 0x0700162e,
1804 0x070023b8,
1805 0x07002790,
1806 0x070033ca,
1807 0x070034c8,
1808 0x07003254,
1809 0x070035d0,
1810 0x0700369e,
1811 0x0700370a,
1812 0x07003796,
1813 0x070037fc,
1814 0x070032f6,
1815 } },
1816
1817 // Is 0xcc62ab38 a bad dump?
1818 { { 0x736b40d6, 0xcc62ab38 }, "Virtual League Baseball (US)", {
1819 0x07000bbc,
1820 0x070011a4,
1821 0x07000cc4,
1822 0x07000c1c,
1823 0x07000c6a,
1824 0x07000be0,
1825 0x07000c40,
1826 } },
1827
1828 { { 0x9ba8bb5e }, "Virtual Pro Yakyuu '95", {
1829 0x07000bbc,
1830 0x070011a4,
1831 0x07000cc4,
1832 0x07000c1c,
1833 0x07000c6a,
1834 0x07000be0,
1835 0x07000c40,
1836 } },
1837
1838 { { 0x82a95e51, 0x742298d1 /*[b1]*/ }, "Waterworld (US)", { // Apparently has complex wait loop.
1839 0x070008fc,
1840 0x0700090e,
1841 0x0700209e,
1842 0x070020b4,
1843 0x070009da,
1844 0x0700222a,
1845 0x07002312,
1846 0x070023f8,
1847 0x07002680,
1848 0x07002c68,
1849 0x0700303c,
1850 0x07003052,
1851 0x0700397e,
1852 0x07003994,
1853 0x07000bb4,
1854 0x07000ac8,
1855 } },
1856
1857 { { 0x44C2B723 } , "Space Pinball (Prototype)", {
1858 0x0702EA7A
1859 }},
1860 };
1861
1862 static int Load(const char *name, MDFNFILE *fp)
1863 {
1864 V810_Emu_Mode cpu_mode;
1865
1866 VB_InDebugPeek = 0;
1867
1868 cpu_mode = (V810_Emu_Mode)MDFN_GetSettingI("vb.cpu_emulation");
1869
1870 if(GET_FSIZE_PTR(fp) != round_up_pow2(GET_FSIZE_PTR(fp)))
1871 {
1872 puts("VB ROM image size is not a power of 2???");
1873 return(0);
1874 }
1875
1876 if(GET_FSIZE_PTR(fp) < 256)
1877 {
1878 puts("VB ROM image size is too small??");
1879 return(0);
1880 }
1881
1882 if(GET_FSIZE_PTR(fp) > (1 << 24))
1883 {
1884 puts("VB ROM image size is too large??");
1885 return(0);
1886 }
1887
1888 VB_HeaderInfo hinfo;
1889
1890 ReadHeader(fp, &hinfo);
1891
1892 MDFN_printf(_("Title: %s\n"), hinfo.game_title);
1893 MDFN_printf(_("Game ID Code: %u\n"), hinfo.game_code);
1894 MDFN_printf(_("Manufacturer Code: %d\n"), hinfo.manf_code);
1895 MDFN_printf(_("Version: %u\n"), hinfo.version);
1896
1897 MDFN_printf(_("ROM: %dKiB\n"), (int)(GET_FSIZE_PTR(fp) / 1024));
1898
1899 MDFN_printf("\n");
1900
1901 MDFN_printf(_("V810 Emulation Mode: %s\n"), (cpu_mode == V810_EMU_MODE_ACCURATE) ? _("Accurate") : _("Fast"));
1902
1903 VB_V810 = new V810();
1904 VB_V810->Init(cpu_mode, true);
1905
1906 VB_V810->SetMemReadHandlers(MemRead8, MemRead16, NULL);
1907 VB_V810->SetMemWriteHandlers(MemWrite8, MemWrite16, NULL);
1908
1909 VB_V810->SetIOReadHandlers(MemRead8, MemRead16, NULL);
1910 VB_V810->SetIOWriteHandlers(MemWrite8, MemWrite16, NULL);
1911
1912 for(int i = 0; i < 256; i++)
1913 {
1914 VB_V810->SetMemReadBus32(i, false);
1915 VB_V810->SetMemWriteBus32(i, false);
1916 }
1917
1918 std::vector<uint32> Map_Addresses;
1919
1920 for(uint64 A = 0; A < 1ULL << 32; A += (1 << 27))
1921 {
1922 for(uint64 sub_A = 5 << 24; sub_A < (6 << 24); sub_A += 65536)
1923 {
1924 Map_Addresses.push_back(A + sub_A);
1925 }
1926 }
1927
1928 WRAM = VB_V810->SetFastMap(&Map_Addresses[0], 65536, Map_Addresses.size(), "WRAM");
1929 Map_Addresses.clear();
1930
1931
1932 // Round up the ROM size to 65536(we mirror it a little later)
1933 GPROM_Mask = (GET_FSIZE_PTR(fp) < 65536) ? (65536 - 1) : (GET_FSIZE_PTR(fp) - 1);
1934
1935 for(uint64 A = 0; A < 1ULL << 32; A += (1 << 27))
1936 {
1937 for(uint64 sub_A = 7 << 24; sub_A < (8 << 24); sub_A += GPROM_Mask + 1)
1938 {
1939 Map_Addresses.push_back(A + sub_A);
1940 //printf("%08x\n", (uint32)(A + sub_A));
1941 }
1942 }
1943
1944
1945 GPROM = VB_V810->SetFastMap(&Map_Addresses[0], GPROM_Mask + 1, Map_Addresses.size(), "Cart ROM");
1946 Map_Addresses.clear();
1947
1948 // Mirror ROM images < 64KiB to 64KiB
1949 for(uint64 i = 0; i < 65536; i += GET_FSIZE_PTR(fp))
1950 {
1951 memcpy(GPROM + i, GET_FDATA_PTR(fp), GET_FSIZE_PTR(fp));
1952 }
1953
1954 GPRAM_Mask = 0xFFFF;
1955
1956 for(uint64 A = 0; A < 1ULL << 32; A += (1 << 27))
1957 {
1958 for(uint64 sub_A = 6 << 24; sub_A < (7 << 24); sub_A += GPRAM_Mask + 1)
1959 {
1960 //printf("GPRAM: %08x\n", A + sub_A);
1961 Map_Addresses.push_back(A + sub_A);
1962 }
1963 }
1964
1965
1966 GPRAM = VB_V810->SetFastMap(&Map_Addresses[0], GPRAM_Mask + 1, Map_Addresses.size(), "Cart RAM");
1967 Map_Addresses.clear();
1968
1969 memset(GPRAM, 0, GPRAM_Mask + 1);
1970
1971 {
1972 FILE *gp = gzopen(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav").c_str(), "rb");
1973
1974 if(gp)
1975 {
1976 if(gzread(gp, GPRAM, 65536) != 65536)
1977 puts("Error reading GPRAM");
1978 gzclose(gp);
1979 }
1980 }
1981
1982 VIP_Init();
1983 VB_VSU = new VSU(&sbuf[0], &sbuf[1]);
1984 VBINPUT_Init();
1985
1986 VB3DMode = MDFN_GetSettingUI("vb.3dmode");
1987 uint32 prescale = MDFN_GetSettingUI("vb.liprescale");
1988 uint32 sbs_separation = MDFN_GetSettingUI("vb.sidebyside.separation");
1989
1990 VIP_Set3DMode(VB3DMode, MDFN_GetSettingUI("vb.3dreverse"), prescale, sbs_separation);
1991
1992
1993 //SettingChanged("vb.3dmode");
1994 SettingChanged("vb.disable_parallax");
1995 SettingChanged("vb.anaglyph.lcolor");
1996 SettingChanged("vb.anaglyph.rcolor");
1997 SettingChanged("vb.anaglyph.preset");
1998 SettingChanged("vb.default_color");
1999
2000 SettingChanged("vb.instant_display_hack");
2001 SettingChanged("vb.allow_draw_skip");
2002
2003 SettingChanged("vb.input.instant_read_hack");
2004
2005 MDFNGameInfo->fps = (int64)20000000 * 65536 * 256 / (259 * 384 * 4);
2006
2007
2008 VB_Power();
2009
2010
2011 #ifdef WANT_DEBUGGER
2012 VBDBG_Init();
2013 #endif
2014
2015
2016 MDFNGameInfo->nominal_width = 384;
2017 MDFNGameInfo->nominal_height = 224;
2018 MDFNGameInfo->fb_width = 384;
2019 MDFNGameInfo->fb_height = 224;
2020
2021 switch(VB3DMode)
2022 {
2023 default: break;
2024
2025 case VB3DMODE_VLI:
2026 MDFNGameInfo->nominal_width = 768 * prescale;
2027 MDFNGameInfo->nominal_height = 224;
2028 MDFNGameInfo->fb_width = 768 * prescale;
2029 MDFNGameInfo->fb_height = 224;
2030 break;
2031
2032 case VB3DMODE_HLI:
2033 MDFNGameInfo->nominal_width = 384;
2034 MDFNGameInfo->nominal_height = 448 * prescale;
2035 MDFNGameInfo->fb_width = 384;
2036 MDFNGameInfo->fb_height = 448 * prescale;
2037 break;
2038
2039 case VB3DMODE_CSCOPE:
2040 MDFNGameInfo->nominal_width = 512;
2041 MDFNGameInfo->nominal_height = 384;
2042 MDFNGameInfo->fb_width = 512;
2043 MDFNGameInfo->fb_height = 384;
2044 break;
2045
2046 case VB3DMODE_SIDEBYSIDE:
2047 MDFNGameInfo->nominal_width = 384 * 2 + sbs_separation;
2048 MDFNGameInfo->nominal_height = 224;
2049 MDFNGameInfo->fb_width = 384 * 2 + sbs_separation;
2050 MDFNGameInfo->fb_height = 224;
2051 break;
2052 }
2053 MDFNGameInfo->lcm_width = MDFNGameInfo->fb_width;
2054 MDFNGameInfo->lcm_height = MDFNGameInfo->fb_height;
2055
2056
2057 MDFNMP_Init(32768, ((uint64)1 << 27) / 32768);
2058 MDFNMP_AddRAM(65536, 5 << 24, WRAM);
2059 if((GPRAM_Mask + 1) >= 32768)
2060 MDFNMP_AddRAM(GPRAM_Mask + 1, 6 << 24, GPRAM);
2061 return(1);
2062 }
2063
2064 static void CloseGame(void)
2065 {
2066 // Only save cart RAM if it has been modified.
2067 for(unsigned int i = 0; i < GPRAM_Mask + 1; i++)
2068 {
2069 if(GPRAM[i])
2070 {
2071 if(!MDFN_DumpToFile(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav").c_str(), 6, GPRAM, 65536))
2072 {
2073
2074 }
2075 break;
2076 }
2077 }
2078 //VIP_Kill();
2079
2080 if(VB_VSU)
2081 {
2082 delete VB_VSU;
2083 VB_VSU = NULL;
2084 }
2085
2086 /*
2087 if(GPRAM)
2088 {
2089 MDFN_free(GPRAM);
2090 GPRAM = NULL;
2091 }
2092
2093 if(GPROM)
2094 {
2095 MDFN_free(GPROM);
2096 GPROM = NULL;
2097 }
2098 */
2099
2100 if(VB_V810)
2101 {
2102 VB_V810->Kill();
2103 delete VB_V810;
2104 VB_V810 = NULL;
2105 }
2106 }
2107
2108 void VB_ExitLoop(void)
2109 {
2110 VB_V810->Exit();
2111 }
2112
2113 static void Emulate(EmulateSpecStruct *espec)
2114 {
2115 v810_timestamp_t v810_timestamp;
2116
2117 MDFNMP_ApplyPeriodicCheats();
2118
2119 VBINPUT_Frame();
2120
2121 if(espec->SoundFormatChanged)
2122 {
2123 for(int y = 0; y < 2; y++)
2124 {
2125 sbuf[y].set_sample_rate(espec->SoundRate ? espec->SoundRate : 44100, 50);
2126 sbuf[y].clock_rate((long)(VB_MASTER_CLOCK / 4));
2127 sbuf[y].bass_freq(20);
2128 }
2129 }
2130
2131 VIP_StartFrame(espec);
2132
2133 v810_timestamp = VB_V810->Run(EventHandler);
2134
2135 FixNonEvents();
2136 ForceEventUpdates(v810_timestamp);
2137
2138 VB_VSU->EndFrame((v810_timestamp + VSU_CycleFix) >> 2);
2139
2140 if(espec->SoundBuf)
2141 {
2142 for(int y = 0; y < 2; y++)
2143 {
2144 sbuf[y].end_frame((v810_timestamp + VSU_CycleFix) >> 2);
2145 espec->SoundBufSize = sbuf[y].read_samples(espec->SoundBuf + y, espec->SoundBufMaxSize, 1);
2146 }
2147 }
2148
2149 VSU_CycleFix = (v810_timestamp + VSU_CycleFix) & 3;
2150
2151 espec->MasterCycles = v810_timestamp;
2152
2153 TIMER_ResetTS();
2154 VBINPUT_ResetTS();
2155 VIP_ResetTS();
2156
2157 RebaseTS(v810_timestamp);
2158
2159 VB_V810->ResetTS(0);
2160 }
2161
2162 #ifdef WANT_DEBUGGER
2163 static DebuggerInfoStruct DBGInfo =
2164 {
2165 "shift_jis",
2166 4,
2167 2, // Instruction alignment(bytes)
2168 32,
2169 32,
2170 0x00000000,
2171 ~0U,
2172
2173 VBDBG_MemPeek,
2174 VBDBG_Disassemble,
2175 NULL,
2176 NULL, //ForceIRQ,
2177 NULL,
2178 VBDBG_FlushBreakPoints,
2179 VBDBG_AddBreakPoint,
2180 VBDBG_SetCPUCallback,
2181 VBDBG_EnableBranchTrace,
2182 VBDBG_GetBranchTrace,
2183 NULL, //KING_SetGraphicsDecode,
2184 VBDBG_SetLogFunc,
2185 };
2186 #endif
2187
2188
2189 static int StateAction(StateMem *sm, int load, int data_only)
2190 {
2191 const v810_timestamp_t timestamp = VB_V810->v810_timestamp;
2192 int ret = 1;
2193
2194 SFORMAT StateRegs[] =
2195 {
2196 SFARRAY(WRAM, 65536),
2197 SFARRAY(GPRAM, GPRAM_Mask ? (GPRAM_Mask + 1) : 0),
2198 SFVAR(WCR),
2199 SFVAR(IRQ_Asserted),
2200 SFVAR(VSU_CycleFix),
2201 SFEND
2202 };
2203
2204 ret &= MDFNSS_StateAction(sm, load, data_only, StateRegs, "MAIN");
2205
2206 ret &= VB_V810->StateAction(sm, load, data_only);
2207
2208 ret &= VB_VSU->StateAction(sm, load, data_only);
2209 ret &= TIMER_StateAction(sm, load, data_only);
2210 ret &= VBINPUT_StateAction(sm, load, data_only);
2211 ret &= VIP_StateAction(sm, load, data_only);
2212
2213 if(load)
2214 {
2215 // Needed to recalculate next_*_ts since we don't bother storing their deltas in save states.
2216 ForceEventUpdates(timestamp);
2217 }
2218 return(ret);
2219 }
2220
2221 static void SetLayerEnableMask(uint64 mask)
2222 {
2223
2224 }
2225
2226 static void DoSimpleCommand(int cmd)
2227 {
2228 switch(cmd)
2229 {
2230 case MDFN_MSC_POWER:
2231 case MDFN_MSC_RESET: VB_Power(); break;
2232 }
2233 }
2234
2235 static const MDFNSetting_EnumList V810Mode_List[] =
2236 {
2237 { "fast", (int)V810_EMU_MODE_FAST, gettext_noop("Fast Mode"), gettext_noop("Fast mode trades timing accuracy, cache emulation, and executing from hardware registers and RAM not intended for code use for performance.")},
2238 { "accurate", (int)V810_EMU_MODE_ACCURATE, gettext_noop("Accurate Mode"), gettext_noop("Increased timing accuracy, though not perfect, along with cache emulation, at the cost of decreased performance. Additionally, even the pipeline isn't correctly and fully emulated in this mode.") },
2239 { NULL, 0 },
2240 };
2241
2242 static const MDFNSetting_EnumList VB3DMode_List[] =
2243 {
2244 { "anaglyph", VB3DMODE_ANAGLYPH, gettext_noop("Anaglyph"), gettext_noop("Used in conjunction with classic dual-lens-color glasses.") },
2245 { "cscope", VB3DMODE_CSCOPE, gettext_noop("CyberScope"), gettext_noop("Intended for use with the CyberScope 3D device.") },
2246 { "sidebyside", VB3DMODE_SIDEBYSIDE, gettext_noop("Side-by-Side"), gettext_noop("The left-eye image is displayed on the left, and the right-eye image is displayed on the right.") },
2247 // { "overunder", VB3DMODE_OVERUNDER },
2248 { "vli", VB3DMODE_VLI, gettext_noop("Vertical Line Interlaced"), gettext_noop("Vertical lines alternate between left view and right view.") },
2249 { "hli", VB3DMODE_HLI, gettext_noop("Horizontal Line Interlaced"), gettext_noop("Horizontal lines alternate between left view and right view.") },
2250 { NULL, 0 },
2251 };
2252
2253 static const MDFNSetting_EnumList AnaglyphPreset_List[] =
2254 {
2255 { "disabled", ANAGLYPH_PRESET_DISABLED, gettext_noop("Disabled"), gettext_noop("Forces usage of custom anaglyph colors.") },
2256 { "0", ANAGLYPH_PRESET_DISABLED },
2257
2258 { "red_blue", ANAGLYPH_PRESET_RED_BLUE, gettext_noop("Red/Blue"), gettext_noop("Classic red/blue anaglyph.") },
2259 { "red_cyan", ANAGLYPH_PRESET_RED_CYAN, gettext_noop("Red/Cyan"), gettext_noop("Improved quality red/cyan anaglyph.") },
2260 { "red_electriccyan", ANAGLYPH_PRESET_RED_ELECTRICCYAN, gettext_noop("Red/Electric Cyan"), gettext_noop("Alternate version of red/cyan") },
2261 { "red_green", ANAGLYPH_PRESET_RED_GREEN, gettext_noop("Red/Green") },
2262 { "green_magenta", ANAGLYPH_PRESET_GREEN_MAGENTA, gettext_noop("Green/Magenta") },
2263 { "yellow_blue", ANAGLYPH_PRESET_YELLOW_BLUE, gettext_noop("Yellow/Blue") },
2264
2265 { NULL, 0 },
2266 };
2267
2268 static MDFNSetting VBSettings[] =
2269 {
2270 { "vb.cpu_emulation", MDFNSF_EMU_STATE | MDFNSF_UNTRUSTED_SAFE, gettext_noop("CPU emulation mode."), NULL, MDFNST_ENUM, "fast", NULL, NULL, NULL, NULL, V810Mode_List },
2271 { "vb.input.instant_read_hack", MDFNSF_EMU_STATE | MDFNSF_UNTRUSTED_SAFE, gettext_noop("Input latency reduction hack."), gettext_noop("Reduces latency in some games by 20ms by returning the current pad state, rather than latched state, on serial port data reads. This hack may cause some homebrew software to malfunction, but it should be relatively safe for commercial official games."), MDFNST_BOOL, "1", NULL, NULL, NULL, SettingChanged },
2272
2273 { "vb.instant_display_hack", MDFNSF_NOFLAGS, gettext_noop("Display latency reduction hack."), gettext_noop("Reduces latency in games by displaying the framebuffer 20ms earlier. This hack has some potential of causing graphical glitches, so it is disabled by default."), MDFNST_BOOL, "0", NULL, NULL, NULL, SettingChanged },
2274 { "vb.allow_draw_skip", MDFNSF_EMU_STATE | MDFNSF_UNTRUSTED_SAFE, gettext_noop("Allow draw skipping."), gettext_noop("If vb.instant_display_hack is set to \"1\", and this setting is set to \"1\", then frame-skipping the drawing to the emulated framebuffer will be allowed. THIS WILL CAUSE GRAPHICAL GLITCHES, AND THEORETICALLY(but unlikely) GAME CRASHES, ESPECIALLY WITH DIRECT FRAMEBUFFER DRAWING GAMES."), MDFNST_BOOL, "0", NULL, NULL, NULL, SettingChanged },
2275
2276 // FIXME: We're going to have to set up some kind of video mode change notification for changing vb.3dmode while the game is running to work properly.
2277 { "vb.3dmode", MDFNSF_NOFLAGS, gettext_noop("3D mode."), NULL, MDFNST_ENUM, "anaglyph", NULL, NULL, NULL, /*SettingChanged*/NULL, VB3DMode_List },
2278 { "vb.liprescale", MDFNSF_NOFLAGS, gettext_noop("Line Interlaced prescale."), NULL, MDFNST_UINT, "2", "1", "10", NULL, NULL },
2279
2280 { "vb.disable_parallax", MDFNSF_EMU_STATE | MDFNSF_UNTRUSTED_SAFE, gettext_noop("Disable parallax for BG and OBJ rendering."), NULL, MDFNST_BOOL, "0", NULL, NULL, NULL, SettingChanged },
2281 { "vb.default_color", MDFNSF_NOFLAGS, gettext_noop("Default maximum-brightness color to use in non-anaglyph 3D modes."), NULL, MDFNST_UINT, "0xF0F0F0", "0x000000", "0xFFFFFF", NULL, SettingChanged },
2282
2283 { "vb.anaglyph.preset", MDFNSF_NOFLAGS, gettext_noop("Anaglyph preset colors."), NULL, MDFNST_ENUM, "red_blue", NULL, NULL, NULL, SettingChanged, AnaglyphPreset_List },
2284 { "vb.anaglyph.lcolor", MDFNSF_NOFLAGS, gettext_noop("Anaglyph maximum-brightness color for left view."), NULL, MDFNST_UINT, "0xffba00", "0x000000", "0xFFFFFF", NULL, SettingChanged },
2285 { "vb.anaglyph.rcolor", MDFNSF_NOFLAGS, gettext_noop("Anaglyph maximum-brightness color for right view."), NULL, MDFNST_UINT, "0x00baff", "0x000000", "0xFFFFFF", NULL, SettingChanged },
2286
2287 { "vb.sidebyside.separation", MDFNSF_NOFLAGS, gettext_noop("Number of pixels to separate L/R views by."), gettext_noop("This setting refers to pixels before vb.xscale(fs) scaling is taken into consideration. For example, a value of \"100\" here will result in a separation of 300 screen pixels if vb.xscale(fs) is set to \"3\"."), MDFNST_UINT, /*"96"*/"0", "0", "1024", NULL, NULL },
2288
2289 { "vb.3dreverse", MDFNSF_NOFLAGS, gettext_noop("Reverse left/right 3D views."), NULL, MDFNST_BOOL, "0", NULL, NULL, NULL, SettingChanged },
2290 { NULL }
2291 };
2292
2293
2294 static const InputDeviceInputInfoStruct IDII[] =
2295 {
2296 { "a", "A", 7, IDIT_BUTTON_CAN_RAPID, NULL },
2297 { "b", "B", 6, IDIT_BUTTON_CAN_RAPID, NULL },
2298 { "rt", "Right-Back", 13, IDIT_BUTTON, NULL },
2299 { "lt", "Left-Back", 12, IDIT_BUTTON, NULL },
2300
2301 { "up-r", "UP ↑ (Right D-Pad)", 8, IDIT_BUTTON, "down-r" },
2302 { "right-r", "RIGHT → (Right D-Pad)", 11, IDIT_BUTTON, "left-r" },
2303
2304 { "right-l", "RIGHT → (Left D-Pad)", 3, IDIT_BUTTON, "left-l" },
2305 { "left-l", "LEFT ← (Left D-Pad)", 2, IDIT_BUTTON, "right-l" },
2306 { "down-l", "DOWN ↓ (Left D-Pad)", 1, IDIT_BUTTON, "up-l" },
2307 { "up-l", "UP ↑ (Left D-Pad)", 0, IDIT_BUTTON, "down-l" },
2308
2309 { "start", "Start", 5, IDIT_BUTTON, NULL },
2310 { "select", "Select", 4, IDIT_BUTTON, NULL },
2311
2312 { "left-r", "LEFT ← (Right D-Pad)", 10, IDIT_BUTTON, "right-r" },
2313 { "down-r", "DOWN ↓ (Right D-Pad)", 9, IDIT_BUTTON, "up-r" },
2314 };
2315
2316 static InputDeviceInfoStruct InputDeviceInfo[] =
2317 {
2318 {
2319 "gamepad",
2320 "Gamepad",
2321 NULL,
2322 NULL,
2323 sizeof(IDII) / sizeof(InputDeviceInputInfoStruct),
2324 IDII,
2325 }
2326 };
2327
2328 static const InputPortInfoStruct PortInfo[] =
2329 {
2330 { "builtin", "Built-In", sizeof(InputDeviceInfo) / sizeof(InputDeviceInfoStruct), InputDeviceInfo, "gamepad" }
2331 };
2332
2333 static InputInfoStruct InputInfo =
2334 {
2335 sizeof(PortInfo) / sizeof(InputPortInfoStruct),
2336 PortInfo
2337 };
2338
2339
2340 static const FileExtensionSpecStruct KnownExtensions[] =
2341 {
2342 { ".vb", gettext_noop("Nintendo Virtual Boy") },
2343 { ".vboy", gettext_noop("Nintendo Virtual Boy") },
2344 { NULL, NULL }
2345 };
2346
2347 MDFNGI EmulatedVB =
2348 {
2349 "vb",
2350 "Virtual Boy",
2351 KnownExtensions,
2352 MODPRIO_INTERNAL_HIGH,
2353 #ifdef WANT_DEBUGGER
2354 &DBGInfo,
2355 #else
2356 NULL, // Debug info
2357 #endif
2358 &InputInfo, //
2359 Load,
2360 TestMagic,
2361 NULL,
2362 NULL,
2363 CloseGame,
2364 SetLayerEnableMask,
2365 NULL, // Layer names, null-delimited
2366 NULL,
2367 NULL,
2368 NULL,
2369 NULL,
2370 NULL,
2371 NULL,
2372 false,
2373 StateAction,
2374 Emulate,
2375 VBINPUT_SetInput,
2376 DoSimpleCommand,
2377 VBSettings,
2378 MDFN_MASTERCLOCK_FIXED(VB_MASTER_CLOCK),
2379 0,
2380 false, // Multires possible?
2381
2382 0, // lcm_width
2383 0, // lcm_height
2384 NULL, // Dummy
2385
2386 384, // Nominal width
2387 224, // Nominal height
2388
2389 384, // Framebuffer width
2390 256, // Framebuffer height
2391
2392 2, // Number of output sound channels
2393 };
2394
2395 static bool failed_init;
2396
2397 static void hookup_ports(bool force);
2398
2399 static bool initial_ports_hookup = false;
2400
2401 std::string retro_base_directory;
2402 std::string retro_base_name;
2403 std::string retro_save_directory;
2404
2405 static void set_basename(const char *path)
2406 {
2407 const char *base = strrchr(path, '/');
2408 if (!base)
2409 base = strrchr(path, '\\');
2410
2411 if (base)
2412 retro_base_name = base + 1;
2413 else
2414 retro_base_name = path;
2415
2416 retro_base_name = retro_base_name.substr(0, retro_base_name.find_last_of('.'));
2417 }
2418
2419 #define MEDNAFEN_CORE_NAME_MODULE "vb"
2420 #define MEDNAFEN_CORE_NAME "Mednafen VB"
2421 #define MEDNAFEN_CORE_VERSION "v0.9.36.1"
2422 #define MEDNAFEN_CORE_EXTENSIONS "vb|vboy|bin"
2423 #define MEDNAFEN_CORE_TIMING_FPS 50.27
2424 #define MEDNAFEN_CORE_GEOMETRY_BASE_W (game->nominal_width)
2425 #define MEDNAFEN_CORE_GEOMETRY_BASE_H (game->nominal_height)
2426 #define MEDNAFEN_CORE_GEOMETRY_MAX_W 384
2427 #define MEDNAFEN_CORE_GEOMETRY_MAX_H 224
2428 #define MEDNAFEN_CORE_GEOMETRY_ASPECT_RATIO (4.0 / 3.0)
2429 #define FB_WIDTH 384
2430 #define FB_HEIGHT 224
2431
2432
2433 #define FB_MAX_HEIGHT FB_HEIGHT
2434
2435 const char *mednafen_core_str = MEDNAFEN_CORE_NAME;
2436
2437 static void check_system_specs(void)
2438 {
2439 unsigned level = 0;
2440 environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level);
2441 }
2442
2443 void retro_init(void)
2444 {
2445 struct retro_log_callback log;
2446 if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log))
2447 log_cb = log.log;
2448 else
2449 log_cb = NULL;
2450
2451 MDFNI_InitializeModule();
2452
2453 const char *dir = NULL;
2454
2455 if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir)
2456 {
2457 retro_base_directory = dir;
2458 // Make sure that we don't have any lingering slashes, etc, as they break Windows.
2459 size_t last = retro_base_directory.find_last_not_of("/\\");
2460 if (last != std::string::npos)
2461 last++;
2462
2463 retro_base_directory = retro_base_directory.substr(0, last);
2464
2465 MDFNI_Initialize(retro_base_directory.c_str());
2466 }
2467 else
2468 {
2469 /* TODO: Add proper fallback */
2470 if (log_cb)
2471 log_cb(RETRO_LOG_WARN, "System directory is not defined. Fallback on using same dir as ROM for system directory later ...\n");
2472 failed_init = true;
2473 }
2474
2475 if (environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &dir) && dir)
2476 {
2477 // If save directory is defined use it, otherwise use system directory
2478 retro_save_directory = *dir ? dir : retro_base_directory;
2479 // Make sure that we don't have any lingering slashes, etc, as they break Windows.
2480 size_t last = retro_save_directory.find_last_not_of("/\\");
2481 if (last != std::string::npos)
2482 last++;
2483
2484 retro_save_directory = retro_save_directory.substr(0, last);
2485 }
2486 else
2487 {
2488 /* TODO: Add proper fallback */
2489 if (log_cb)
2490 log_cb(RETRO_LOG_WARN, "Save directory is not defined. Fallback on using SYSTEM directory ...\n");
2491 retro_save_directory = retro_base_directory;
2492 }
2493
2494 #if defined(WANT_16BPP) && defined(FRONTEND_SUPPORTS_RGB565)
2495 enum retro_pixel_format rgb565 = RETRO_PIXEL_FORMAT_RGB565;
2496 if (environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &rgb565) && log_cb)
2497 log_cb(RETRO_LOG_INFO, "Frontend supports RGB565 - will use that instead of XRGB1555.\n");
2498 #endif
2499
2500 if (environ_cb(RETRO_ENVIRONMENT_GET_PERF_INTERFACE, &perf_cb))
2501 perf_get_cpu_features_cb = perf_cb.get_cpu_features;
2502 else
2503 perf_get_cpu_features_cb = NULL;
2504
2505 check_system_specs();
2506 }
2507
2508 void retro_reset(void)
2509 {
2510 game->DoSimpleCommand(MDFN_MSC_RESET);
2511 }
2512
2513 bool retro_load_game_special(unsigned, const struct retro_game_info *, size_t)
2514 {
2515 return false;
2516 }
2517
2518 static void set_volume (uint32_t *ptr, unsigned number)
2519 {
2520 switch(number)
2521 {
2522 default:
2523 *ptr = number;
2524 break;
2525 }
2526 }
2527
2528 static void check_variables(void)
2529 {
2530 struct retro_variable var = {0};
2531
2532 var.key = "vb_color_mode";
2533
2534 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
2535 {
2536 if (strcmp(var.value, "black & red") == 0)
2537 {
2538 setting_vb_lcolor = 0xFF0000;
2539 setting_vb_rcolor = 0x000000;
2540 }
2541 else if (strcmp(var.value, "black & white") == 0)
2542 {
2543 setting_vb_lcolor = 0xFFFFFF;
2544 setting_vb_rcolor = 0x000000;
2545 }
2546 log_cb(RETRO_LOG_INFO, "[%s]: Palette changed: %s .\n", mednafen_core_str, var.value);
2547 }
2548
2549 var.key = "vb_anaglyph_preset";
2550
2551 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
2552 {
2553
2554
2555 if (strcmp(var.value, "disabled") == 0)
2556 setting_vb_anaglyph_preset = 0;
2557 else if (strcmp(var.value, "red & blue") == 0)
2558 setting_vb_anaglyph_preset = 1;
2559 else if (strcmp(var.value, "red & cyan") == 0)
2560 setting_vb_anaglyph_preset = 2;
2561 else if (strcmp(var.value, "red & electric cyan") == 0)
2562 setting_vb_anaglyph_preset = 3;
2563 else if (strcmp(var.value, "red & green") == 0)
2564 setting_vb_anaglyph_preset = 4;
2565 else if (strcmp(var.value, "green & magenta") == 0)
2566 setting_vb_anaglyph_preset = 5;
2567 else if (strcmp(var.value, "yellow & blue") == 0)
2568 setting_vb_anaglyph_preset = 6;
2569
2570 log_cb(RETRO_LOG_INFO, "[%s]: Palette changed: %s .\n", mednafen_core_str, var.value);
2571 }
2572 }
2573
2574 #define MAX_PLAYERS 1
2575 #define MAX_BUTTONS 14
2576 static uint16_t input_buf[MAX_PLAYERS];
2577
2578 static void hookup_ports(bool force)
2579 {
2580 MDFNGI *currgame = game;
2581
2582 if (initial_ports_hookup && !force)
2583 return;
2584
2585 // Possible endian bug ...
2586 currgame->SetInput(0, "gamepad", &input_buf[0]);
2587
2588 initial_ports_hookup = true;
2589 }
2590
2591 bool retro_load_game(const struct retro_game_info *info)
2592 {
2593 if (failed_init)
2594 return false;
2595
2596 struct retro_input_descriptor desc[] = {
2597 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "Left D-Pad Left" },
2598 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "Left D-Pad Up" },
2599 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "Left D-Pad Down" },
2600 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "Left D-Pad Right" },
2601 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" },
2602 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "A" },
2603 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L" },
2604 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R" },
2605 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "Right D-Pad Left" },
2606 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "Right D-Pad Up" },
2607 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "Right D-Pad Down" },
2608 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "Right D-Pad Right" },
2609 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
2610 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
2611
2612 { 0 },
2613 };
2614
2615 environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc);
2616
2617 #ifdef WANT_32BPP
2618 enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_XRGB8888;
2619 if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt))
2620 {
2621 if (log_cb)
2622 log_cb(RETRO_LOG_ERROR, "Pixel format XRGB8888 not supported by platform, cannot use %s.\n", MEDNAFEN_CORE_NAME);
2623 return false;
2624 }
2625 #endif
2626
2627 overscan = false;
2628 environ_cb(RETRO_ENVIRONMENT_GET_OVERSCAN, &overscan);
2629
2630 set_basename(info->path);
2631
2632 check_variables();
2633
2634 game = MDFNI_LoadGame(MEDNAFEN_CORE_NAME_MODULE, info->path);
2635 if (!game)
2636 return false;
2637
2638 MDFN_PixelFormat pix_fmt(MDFN_COLORSPACE_RGB, 16, 8, 0, 24);
2639 memset(&last_pixel_format, 0, sizeof(MDFN_PixelFormat));
2640
2641 surf = new MDFN_Surface(NULL, FB_WIDTH, FB_HEIGHT, FB_WIDTH, pix_fmt);
2642
2643 hookup_ports(true);
2644
2645 check_variables();
2646
2647 return game;
2648 }
2649
2650 void retro_unload_game()
2651 {
2652 if (!game)
2653 return;
2654
2655 MDFNI_CloseGame();
2656 }
2657
2658
2659
2660 static void update_input(void)
2661 {
2662 input_buf[0] = 0;
2663 static unsigned map[] = {
2664 RETRO_DEVICE_ID_JOYPAD_A,
2665 RETRO_DEVICE_ID_JOYPAD_B,
2666 RETRO_DEVICE_ID_JOYPAD_R,
2667 RETRO_DEVICE_ID_JOYPAD_L,
2668 RETRO_DEVICE_ID_JOYPAD_L2, //right d-pad UP
2669 RETRO_DEVICE_ID_JOYPAD_R3, //right d-pad RIGHT
2670 RETRO_DEVICE_ID_JOYPAD_RIGHT, //left d-pad
2671 RETRO_DEVICE_ID_JOYPAD_LEFT, //left d-pad
2672 RETRO_DEVICE_ID_JOYPAD_DOWN, //left d-pad
2673 RETRO_DEVICE_ID_JOYPAD_UP, //left d-pad
2674 RETRO_DEVICE_ID_JOYPAD_START,
2675 RETRO_DEVICE_ID_JOYPAD_SELECT,
2676 RETRO_DEVICE_ID_JOYPAD_R2, //right d-pad LEFT
2677 RETRO_DEVICE_ID_JOYPAD_L3, //right d-pad DOWN
2678 };
2679
2680 for (unsigned j = 0; j < MAX_PLAYERS; j++)
2681 {
2682 for (unsigned i = 0; i < MAX_BUTTONS; i++)
2683 input_buf[j] |= map[i] != -1u &&
2684 input_state_cb(j, RETRO_DEVICE_JOYPAD, 0, map[i]) ? (1 << i) : 0;
2685
2686 #ifdef MSB_FIRST
2687 union {
2688 uint8_t b[2];
2689 uint16_t s;
2690 } u;
2691 u.s = input_buf[j];
2692 input_buf[j] = u.b[0] | u.b[1] << 8;
2693 #endif
2694 }
2695
2696 }
2697
2698 static uint64_t video_frames, audio_frames;
2699
2700
2701 void retro_run()
2702 {
2703 MDFNGI *curgame = game;
2704
2705 input_poll_cb();
2706
2707 update_input();
2708
2709 static int16_t sound_buf[0x10000];
2710 static MDFN_Rect rects[FB_MAX_HEIGHT];
2711 rects[0].w = ~0;
2712
2713 EmulateSpecStruct spec = {0};
2714 spec.surface = surf;
2715 spec.SoundRate = 44100;
2716 spec.SoundBuf = sound_buf;
2717 spec.LineWidths = rects;
2718 spec.SoundBufMaxSize = sizeof(sound_buf) / 2;
2719 spec.SoundVolume = 1.0;
2720 spec.soundmultiplier = 1.0;
2721 spec.SoundBufSize = 0;
2722 spec.VideoFormatChanged = false;
2723 spec.SoundFormatChanged = false;
2724
2725 if (memcmp(&last_pixel_format, &spec.surface->format, sizeof(MDFN_PixelFormat)))
2726 {
2727 spec.VideoFormatChanged = true;
2728
2729 last_pixel_format = spec.surface->format;
2730 }
2731
2732 if (spec.SoundRate != last_sound_rate)
2733 {
2734 spec.SoundFormatChanged = true;
2735 last_sound_rate = spec.SoundRate;
2736 }
2737
2738 curgame->Emulate(&spec);
2739
2740 int16 *const SoundBuf = spec.SoundBuf + spec.SoundBufSizeALMS * curgame->soundchan;
2741 int32 SoundBufSize = spec.SoundBufSize - spec.SoundBufSizeALMS;
2742 const int32 SoundBufMaxSize = spec.SoundBufMaxSize - spec.SoundBufSizeALMS;
2743
2744 spec.SoundBufSize = spec.SoundBufSizeALMS + SoundBufSize;
2745
2746 unsigned width = spec.DisplayRect.w;
2747 unsigned height = spec.DisplayRect.h;
2748
2749 #if defined(WANT_32BPP)
2750 const uint32_t *pix = surf->pixels;
2751 video_cb(pix, width, height, FB_WIDTH << 2);
2752 #elif defined(WANT_16BPP)
2753 const uint16_t *pix = surf->pixels16;
2754 video_cb(pix, width, height, FB_WIDTH << 1);
2755 #endif
2756
2757 video_frames++;
2758 audio_frames += spec.SoundBufSize;
2759
2760 audio_batch_cb(spec.SoundBuf, spec.SoundBufSize);
2761
2762 bool updated = false;
2763 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
2764 check_variables();
2765 }
2766
2767 void retro_get_system_info(struct retro_system_info *info)
2768 {
2769 memset(info, 0, sizeof(*info));
2770 info->library_name = MEDNAFEN_CORE_NAME;
2771 info->library_version = MEDNAFEN_CORE_VERSION;
2772 info->need_fullpath = true;
2773 info->valid_extensions = MEDNAFEN_CORE_EXTENSIONS;
2774 info->block_extract = false;
2775 }
2776
2777 void retro_get_system_av_info(struct retro_system_av_info *info)
2778 {
2779 memset(info, 0, sizeof(*info));
2780 info->timing.fps = MEDNAFEN_CORE_TIMING_FPS;
2781 info->timing.sample_rate = 44100;
2782 info->geometry.base_width = MEDNAFEN_CORE_GEOMETRY_BASE_W;
2783 info->geometry.base_height = MEDNAFEN_CORE_GEOMETRY_BASE_H;
2784 info->geometry.max_width = MEDNAFEN_CORE_GEOMETRY_MAX_W;
2785 info->geometry.max_height = MEDNAFEN_CORE_GEOMETRY_MAX_H;
2786 info->geometry.aspect_ratio = MEDNAFEN_CORE_GEOMETRY_ASPECT_RATIO;
2787 }
2788
2789 void retro_deinit()
2790 {
2791 delete surf;
2792 surf = NULL;
2793
2794 if (log_cb)
2795 {
2796 log_cb(RETRO_LOG_INFO, "[%s]: Samples / Frame: %.5f\n",
2797 mednafen_core_str, (double)audio_frames / video_frames);
2798 log_cb(RETRO_LOG_INFO, "[%s]: Estimated FPS: %.5f\n",
2799 mednafen_core_str, (double)video_frames * 44100 / audio_frames);
2800 }
2801 }
2802
2803 unsigned retro_get_region(void)
2804 {
2805 return RETRO_REGION_NTSC; // FIXME: Regions for other cores.
2806 }
2807
2808 unsigned retro_api_version(void)
2809 {
2810 return RETRO_API_VERSION;
2811 }
2812
2813 void retro_set_controller_port_device(unsigned in_port, unsigned device)
2814 {
2815 MDFNGI *currgame = (MDFNGI*)game;
2816
2817 if (!currgame)
2818 return;
2819 }
2820
2821 void retro_set_environment(retro_environment_t cb)
2822 {
2823 environ_cb = cb;
2824
2825 static const struct retro_variable vars[] = {
2826 { "vb_anaglyph_preset", "Anaglyph preset (restart); disabled|red & blue|red & cyan|red & electric cyan|red & green|green & magenta|yellow & blue" },
2827 { "vb_color_mode", "Palette (restart); black & red|black & white" },
2828 { NULL, NULL },
2829 };
2830 cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)vars);
2831 }
2832
2833 void retro_set_audio_sample(retro_audio_sample_t cb)
2834 {
2835 audio_cb = cb;
2836 }
2837
2838 void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb)
2839 {
2840 audio_batch_cb = cb;
2841 }
2842
2843 void retro_set_input_poll(retro_input_poll_t cb)
2844 {
2845 input_poll_cb = cb;
2846 }
2847
2848 void retro_set_input_state(retro_input_state_t cb)
2849 {
2850 input_state_cb = cb;
2851 }
2852
2853 void retro_set_video_refresh(retro_video_refresh_t cb)
2854 {
2855 video_cb = cb;
2856 }
2857
2858 static size_t serialize_size;
2859
2860 size_t retro_serialize_size(void)
2861 {
2862 MDFNGI *curgame = (MDFNGI*)game;
2863 //if (serialize_size)
2864 // return serialize_size;
2865
2866 if (!curgame->StateAction)
2867 {
2868 if (log_cb)
2869 log_cb(RETRO_LOG_WARN, "[mednafen]: Module %s doesn't support save states.\n", curgame->shortname);
2870 return 0;
2871 }
2872
2873 StateMem st;
2874 memset(&st, 0, sizeof(st));
2875
2876 if (!MDFNSS_SaveSM(&st, 0, 0, NULL, NULL, NULL))
2877 {
2878 if (log_cb)
2879 log_cb(RETRO_LOG_WARN, "[mednafen]: Module %s doesn't support save states.\n", curgame->shortname);
2880 return 0;
2881 }
2882
2883 free(st.data);
2884 return serialize_size = st.len;
2885 }
2886
2887 bool retro_serialize(void *data, size_t size)
2888 {
2889 StateMem st;
2890 memset(&st, 0, sizeof(st));
2891 st.data = (uint8_t*)data;
2892 st.malloced = size;
2893
2894 return MDFNSS_SaveSM(&st, 0, 0, NULL, NULL, NULL);
2895 }
2896
2897 bool retro_unserialize(const void *data, size_t size)
2898 {
2899 StateMem st;
2900 memset(&st, 0, sizeof(st));
2901 st.data = (uint8_t*)data;
2902 st.len = size;
2903
2904 return MDFNSS_LoadSM(&st, 0, 0);
2905 }
2906
2907 void *retro_get_memory_data(unsigned)
2908 {
2909 return NULL;
2910 }
2911
2912 size_t retro_get_memory_size(unsigned)
2913 {
2914 return 0;
2915 }
2916
2917 void retro_cheat_reset(void)
2918 {}
2919
2920 void retro_cheat_set(unsigned, bool, const char *)
2921 {}
2922
2923 #ifdef _WIN32
2924 static void sanitize_path(std::string &path)
2925 {
2926 size_t size = path.size();
2927 for (size_t i = 0; i < size; i++)
2928 if (path[i] == '/')
2929 path[i] = '\\';
2930 }
2931 #endif
2932
2933 // Use a simpler approach to make sure that things go right for libretro.
2934 std::string MDFN_MakeFName(MakeFName_Type type, int id1, const char *cd1)
2935 {
2936 char slash;
2937 #ifdef _WIN32
2938 slash = '\\';
2939 #else
2940 slash = '/';
2941 #endif
2942 std::string ret;
2943 switch (type)
2944 {
2945 case MDFNMKF_SAV:
2946 ret = retro_save_directory +slash + retro_base_name +
2947 std::string(".") +
2948 std::string(cd1);
2949 break;
2950 case MDFNMKF_FIRMWARE:
2951 ret = retro_base_directory + slash + std::string(cd1);
2952 #ifdef _WIN32
2953 sanitize_path(ret); // Because Windows path handling is mongoloid.
2954 #endif
2955 break;
2956 default:
2957 break;
2958 }
2959
2960 if (log_cb)
2961 log_cb(RETRO_LOG_INFO, "MDFN_MakeFName: %s\n", ret.c_str());
2962 return ret;
2963 }
2964
2965 void MDFND_DispMessage(unsigned char *str)
2966 {
2967 if (log_cb)
2968 log_cb(RETRO_LOG_INFO, "%s\n", str);
2969 }
2970
2971 void MDFND_Message(const char *str)
2972 {
2973 if (log_cb)
2974 log_cb(RETRO_LOG_INFO, "%s\n", str);
2975 }
2976
2977 void MDFND_MidSync(const EmulateSpecStruct *)
2978 {}
2979
2980 void MDFN_MidLineUpdate(EmulateSpecStruct *espec, int y)
2981 {
2982 //MDFND_MidLineUpdate(espec, y);
2983 }
2984
2985 void MDFND_PrintError(const char* err)
2986 {
2987 if (log_cb)
2988 log_cb(RETRO_LOG_ERROR, "%s\n", err);
2989 }