diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4a2d16d9..a093236c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -438,6 +438,7 @@ set(SRC_CORE
${CMAKE_CURRENT_SOURCE_DIR}/boards/33.cpp
${CMAKE_CURRENT_SOURCE_DIR}/boards/34.cpp
${CMAKE_CURRENT_SOURCE_DIR}/boards/354.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/boards/413.cpp
${CMAKE_CURRENT_SOURCE_DIR}/boards/36.cpp
${CMAKE_CURRENT_SOURCE_DIR}/boards/3d-block.cpp
${CMAKE_CURRENT_SOURCE_DIR}/boards/40.cpp
diff --git a/src/boards/413.cpp b/src/boards/413.cpp
new file mode 100644
index 00000000..3eb25cfa
--- /dev/null
+++ b/src/boards/413.cpp
@@ -0,0 +1,147 @@
+/* FCEUmm - NES/Famicom Emulator
+ *
+ * Copyright notice for this file:
+ * Copyright (C) 2024
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "mapinc.h"
+#include "../ines.h"
+
+static uint8 reg[4];
+static uint8 IRQCount;
+static uint8 IRQReload;
+static uint8 IRQa;
+static uint8 serialControl;
+static uint32 serialAddress;
+
+static SFORMAT StateRegs[] = {
+ { reg, 4, "REGS" },
+ { &IRQCount, 1, "IRQC" },
+ { &IRQReload, 1, "IRQR" },
+ { &IRQa, 1, "IRQA" },
+ { &serialAddress, 4, "ADDR" },
+ { &serialControl, 1, "CTRL" },
+ { 0 }
+};
+
+static void Sync(void) {
+ setprg4(0x5000, 0x01);
+ setprg8(0x6000, reg[0]);
+
+ setprg8(0x8000, reg[1]);
+ setprg8(0xA000, reg[2]);
+ setprg4(0xD000, 0x07);
+ setprg8(0xE000, 0x04);
+
+ setchr4(0x0000, reg[3]);
+ setchr4(0x1000, ~0x02);
+}
+
+static uint64 lreset;
+static uint32 laddr;
+static DECLFR(M413ReadPCM) {
+ uint8 ret = X.DB;
+ if ((A == laddr) && ((timestampbase + timestamp) < (lreset + 4))) {
+ return ret;
+ }
+ if (serialControl & 0x02) {
+ ret = MiscROM[serialAddress++ & (MiscROM_size - 1)];
+ } else {
+ ret = MiscROM[serialAddress & (MiscROM_size - 1)];
+ }
+ laddr = A;
+ lreset = timestampbase + timestamp;
+ return ret;
+}
+
+static DECLFW(M413Write) {
+ switch (A & 0xF000) {
+ case 0x8000:
+ IRQReload = V;
+ break;
+ case 0x9000:
+ IRQCount = 0;
+ break;
+ case 0xA000:
+ case 0xB000:
+ IRQa = (A & 0x1000) != 0;
+ if (!IRQa) {
+ X6502_IRQEnd(FCEU_IQEXT);
+ }
+ break;
+ case 0xC000:
+ serialAddress = (serialAddress << 1) | (V >> 7);
+ break;
+ case 0xD000:
+ serialControl = V;
+ break;
+ case 0xE000:
+ case 0xF000:
+ reg[V >> 6] = V & 0x3F;
+ Sync();
+ break;
+ }
+}
+
+static void M413Power(void) {
+ serialAddress = 0;
+ serialControl = 0;
+
+ IRQCount = 0;
+ IRQReload = 0;
+ IRQa = 0;
+
+ reg[0] = 0;
+ reg[1] = 0;
+ reg[2] = 0;
+ reg[3] = 0;
+
+ laddr = 0;
+ lreset = 0;
+
+ Sync();
+
+ SetReadHandler(0x4800, 0x4FFF, M413ReadPCM);
+ SetReadHandler(0x5000, 0x7FFF, CartBR);
+ SetReadHandler(0x8000, 0xBFFF, CartBR);
+ SetReadHandler(0xC000, 0xCFFF, M413ReadPCM);
+ SetReadHandler(0xD000, 0xFFFF, CartBR);
+
+ SetWriteHandler(0x8000, 0xFFFF, M413Write);
+}
+
+static void M413IRQHook(void) {
+ if (IRQCount == 0) {
+ IRQCount = IRQReload;
+ } else {
+ IRQCount--;
+ }
+ if ((IRQCount == 0) && IRQa) {
+ X6502_IRQBegin(FCEU_IQEXT);
+ }
+}
+
+static void StateRestore(int version) {
+ Sync();
+}
+
+void Mapper413_Init(CartInfo *info) {
+ info->Power = M413Power;
+ GameHBIRQHook = M413IRQHook;
+ GameStateRestore = StateRestore;
+ AddExState(&StateRegs, ~0, 0, 0);
+}
diff --git a/src/ines.cpp b/src/ines.cpp
index a09189de..5d4427df 100644
--- a/src/ines.cpp
+++ b/src/ines.cpp
@@ -49,6 +49,7 @@ extern SFORMAT FCEUVSUNI_STATEINFO[];
uint8 *trainerpoo = NULL;
uint8 *ROM = NULL;
uint8 *VROM = NULL;
+uint8 *MiscROM = NULL;
uint8 *ExtraNTARAM = NULL;
iNES_HEADER head;
@@ -58,6 +59,7 @@ uint8 Mirroring = 0;
uint8 MirroringAs2bits = 0;
uint32 ROM_size = 0;
uint32 VROM_size = 0;
+uint32 MiscROM_size = 0;
char LoadedRomFName[4096]; //mbg merge 7/17/06 added
char LoadedRomFNamePatchToUse[4096];
@@ -794,6 +796,7 @@ BMAPPINGLocal bmap[] = {
{"FAM250/81-01-39-C/SCHI-24", 354, Mapper354_Init },
{"Impact Soft MMC3 Flash Board", 406, Mapper406_Init },
+ {"Super Russian Roulette", 413, Mapper413_Init },
{"INX_007T_V01", 470, INX_007T_Init },
{"KONAMI QTAi Board", 547, QTAi_Init },
@@ -806,10 +809,13 @@ int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) {
struct md5_context md5;
uint64 partialmd5 = 0;
const char* mappername = "Not Listed";
+ size_t filesize = FCEU_fgetsize(fp);
if (FCEU_fread(&head, 1, 16, fp) != 16 || memcmp(&head, "NES\x1A", 4))
return LOADER_INVALID_FORMAT;
-
+ // Remove header size from filesize
+ filesize -= 16;
+
head.cleanup();
iNESCart.clear();
@@ -946,6 +952,7 @@ int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) {
if (head.ROM_type & 4) { /* Trainer */
trainerpoo = (uint8*)FCEU_gmalloc(512);
FCEU_fread(trainerpoo, 512, 1, fp);
+ filesize -= 512;
}
ResetCartMapping();
@@ -957,6 +964,15 @@ int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) {
if (vrom_size_bytes)
FCEU_fread(VROM, 1, vrom_size_bytes, fp);
+
+ // Misc ROMS
+ if ((head.misc_roms & 0x03) && !(head.ROM_type & 4)) {
+ MiscROM_size = filesize - rom_size_bytes - vrom_size_bytes;
+ MiscROM = (uint8 *)FCEU_malloc(MiscROM_size);
+ memset(MiscROM, 0xFF, MiscROM_size);
+ FCEU_fread(MiscROM, 1, MiscROM_size, fp);
+ FCEU_printf(" Misc ROM size : %d\n", MiscROM_size);
+ }
md5_starts(&md5);
md5_update(&md5, ROM, rom_size_bytes);
@@ -1008,6 +1024,7 @@ int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) {
FCEU_printf(" WRAM backed by battery: %d KiB\n", iNESCart.battery_wram_size / 1024);
FCEU_printf(" VRAM backed by battery: %d KiB\n", iNESCart.battery_vram_size / 1024);
}
+ if (head.misc_roms & 0x03) FCEU_printf(" Misc ROM: %d KiB\n", MiscROM_size / 1024);
}
SetInput();
diff --git a/src/ines.h b/src/ines.h
index 6c95863a..407a5b97 100644
--- a/src/ines.h
+++ b/src/ines.h
@@ -42,8 +42,10 @@ public:
//mbg merge 6/29/06
extern uint8 *ROM;
extern uint8 *VROM;
+extern uint8 *MiscROM;
extern uint32 VROM_size;
extern uint32 ROM_size;
+extern uint32 MiscROM_size;
extern uint8 *ExtraNTARAM;
extern uint8 **VPageR;
extern int iNesSave(void); //bbit Edited: line added
@@ -278,6 +280,7 @@ void Mapper254_Init(CartInfo *);
void Mapper255_Init(CartInfo *);
void Mapper354_Init(CartInfo *);
void Mapper406_Init(CartInfo *);
+void Mapper413_Init(CartInfo *);
void INX_007T_Init(CartInfo* info);
void GN45_Init(CartInfo *info); /* previously mapper 205 */
diff --git a/vc/vc14_fceux.vcxproj b/vc/vc14_fceux.vcxproj
index 43e5dc9d..c8191b90 100644
--- a/vc/vc14_fceux.vcxproj
+++ b/vc/vc14_fceux.vcxproj
@@ -437,6 +437,7 @@ xcopy /y /d "$(ProjectDir)\..\src\drivers\win\7z_64.dll" "$(OutDir)"
+
diff --git a/vc/vc14_fceux.vcxproj.filters b/vc/vc14_fceux.vcxproj.filters
index 9392e42e..1b57adff 100644
--- a/vc/vc14_fceux.vcxproj.filters
+++ b/vc/vc14_fceux.vcxproj.filters
@@ -1120,6 +1120,9 @@
boards
+
+ boards
+