summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/machine/nes_irem.c
diff options
context:
space:
mode:
author Fabio Priuli <etabeta78@users.noreply.github.com>2013-04-21 19:27:29 +0000
committer Fabio Priuli <etabeta78@users.noreply.github.com>2013-04-21 19:27:29 +0000
commitc1540080a1f2262a86b0cce00d734ac49bafbc92 (patch)
tree6cfbab2077f5eaebb01bea115746b9470752db49 /src/mess/machine/nes_irem.c
parent335b6f828a3821a0dc84f86d55e6415a20f4160d (diff)
(MESS) nes.c: major refactoring and improvements of NES/FC cart emulation: [Fabio Priuli]
- converted carts, mappers and pcbs to use slot devices - fixed starting of Famicom, Famicom Twin and Dr. PCJr - fixed handling of "no disk" in FDS so that the system displays Mario and Luigi jumping around as expected - added AY8910 sound to Sunsoft-5B (Gimmick JPN sfx) - added YM2413 to VRC-7 (Lagrange Point OST) - added support for recorded samples to Jaleco sport titles and to Bandai Family Trainer Aerobics Studio, thanks to notes by hap and egoh, and recordings by Pongbashi (samples are needed because these games use a currently undumpable speech chip) - added support for NES-EVENT pcb used by Nintendo World Championship 1990, including dipswitches - added support for Galoob Game Genie real usage (in addition to the codes which Puggsy added to his cheat collections): when you load ggenie, a second cartslot becomes available to load another game attached to the cheat device (e.g. with "mess.exe nes -cart ggenie -cart2 smb") and you can enter the cheat codes as in a real NES - added support for Nantettatte!! Baseball lock-on mechanism, based on the tests performed by naruko on his carts: when you load nantbb, a second cartslot becomes available to load one of the two update minicarts (91 Hen or OB Hen) - improved emulation of Namcot 163, 175 and 340 boards, based on the tests performed by naruko, lidnariq and bootgod on the real hardware - moved Nantettatte!! Baseball minicarts to a separate list (nes_ntbrom.xml) because they cannot be loaded in the NES directly, but only through the nantbb subslot - emulated bus conflict (CPU/PRG) in PCBs documented as having it - partial emulation of open bus, enough to make working the games using it as a sort of protection - fixed crash when loading files using FFE mappers - fixed mirroring in some boards (Sunsoft DCS and UNL-CC-21) and in some games (e.g. Paris Dakar Rally Special and Escape from Atlantis) - fixed a few bugs in Tengen 800032 emulation (mapper 64), promoting Klax, Xybots and Road Runner to work state - fixed Tengen 800037 emulation (mapper 158), promoting US Alien Syndrome to work state - added working emulation of many bootleg pcbs used for pirate conversions from FDS (Ai Senshi Nicol, Doki Doki Panic, Fuuun Shaolin Kyo, Green Beret, Monty no Doki Doki Daidassou, Tobidase Daisakusen, Super Mario Bros Malee 2 / Genius Merio Bros...) - improved emulation of many pirate pcb (BMC-GOLDENCARD-6IN1, KS7013B, KS7012, BMC-GHOSTBUSTERS63IN1, UNL-MALISB, MAXI15 and more...) - improved RacerMate Challenge II emulation, but the game is still not working due to unemulated bicycle controller - added CPU-based IRQ mode in Tengen 800032 emulation (mapper 64), fixing Skulls & Crossbones gfx (but the game is still not working) - fixed many small inaccuracies in the old code, spot during the conversion - added support for most other known pcbs, even if in most cases emulation is only sketchy - reduced the need of fake alt pbcs for boards which only differed by mirroring handling (these are now recognized through the "mirroring" feature) - removed fake wram which was added to a lot of partially documented pcbs and re-added it only where actually present, so to more accurately document what was really in the carts Out of whatsnew: There's still a lot to do (e.g. to clean up the implementation of the pirate pcbs) but I hope that submitting this now I can get some wider testing help so to catch and fix regressions before next release :)
Diffstat (limited to 'src/mess/machine/nes_irem.c')
-rw-r--r--src/mess/machine/nes_irem.c333
1 files changed, 333 insertions, 0 deletions
diff --git a/src/mess/machine/nes_irem.c b/src/mess/machine/nes_irem.c
new file mode 100644
index 00000000000..35bef9b856a
--- /dev/null
+++ b/src/mess/machine/nes_irem.c
@@ -0,0 +1,333 @@
+/***********************************************************************************************************
+
+
+ NES/Famicom cartridge emulation for IREM PCBs
+
+ Copyright MESS Team.
+ Visit http://mamedev.org for licensing and usage restrictions.
+
+
+ Here we emulate the following PCBs
+
+ * IREM LROG017 [mapper 77]
+ * IREM Holy Diver [mapper 78]
+ * IREM TAM-S1 [mapper 97]
+ * IREM G101 [mapper 32]
+ * IREM H3001 [mapper 65]
+
+ ***********************************************************************************************************/
+
+
+#include "emu.h"
+#include "machine/nes_irem.h"
+
+#include "cpu/m6502/m6502.h"
+
+#ifdef NES_PCB_DEBUG
+#define VERBOSE 1
+#else
+#define VERBOSE 0
+#endif
+
+#define LOG_MMC(x) do { if (VERBOSE) logerror x; } while (0)
+
+
+//-------------------------------------------------
+// constructor
+//-------------------------------------------------
+
+const device_type NES_LROG017 = &device_creator<nes_lrog017_device>;
+const device_type NES_HOLYDIVR = &device_creator<nes_holydivr_device>;
+const device_type NES_TAM_S1 = &device_creator<nes_tam_s1_device>;
+const device_type NES_G101 = &device_creator<nes_g101_device>;
+const device_type NES_H3001 = &device_creator<nes_h3001_device>;
+
+
+nes_lrog017_device::nes_lrog017_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
+ : nes_nrom_device(mconfig, NES_LROG017, "NES Cart Irem Discrete 74*161/161/21/138 PCB", tag, owner, clock, "nes_lrog017", __FILE__)
+{
+}
+
+nes_holydivr_device::nes_holydivr_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
+ : nes_nrom_device(mconfig, NES_HOLYDIVR, "NES Cart Irem Holy Diver PCB", tag, owner, clock, "nes_holydivr", __FILE__)
+{
+}
+
+nes_tam_s1_device::nes_tam_s1_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
+ : nes_nrom_device(mconfig, NES_TAM_S1, "NES Cart Irem TAM-S1 PCB", tag, owner, clock, "nes_tam_s1", __FILE__)
+{
+}
+
+nes_g101_device::nes_g101_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
+ : nes_nrom_device(mconfig, NES_G101, "NES Cart Irem G-101 PCB", tag, owner, clock, "nes_g101", __FILE__)
+{
+}
+
+nes_h3001_device::nes_h3001_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
+ : nes_nrom_device(mconfig, NES_H3001, "NES Cart Irem H-3001 PCB", tag, owner, clock, "nes_h3001", __FILE__)
+{
+}
+
+
+
+
+void nes_lrog017_device::device_start()
+{
+ common_start();
+}
+
+void nes_lrog017_device::pcb_reset()
+{
+ m_chr_source = m_vrom_chunks ? CHRROM : CHRRAM;
+ prg32(0);
+ chr2_0(0, CHRROM);
+ chr2_2(0, CHRROM);
+ chr2_4(1, CHRROM);
+ chr2_6(2, CHRROM);
+}
+
+void nes_holydivr_device::device_start()
+{
+ common_start();
+}
+
+void nes_holydivr_device::pcb_reset()
+{
+ m_chr_source = m_vrom_chunks ? CHRROM : CHRRAM;
+ prg16_89ab(0);
+ prg16_cdef(m_prg_chunks - 1);
+ chr8(0, m_chr_source);
+}
+
+void nes_tam_s1_device::device_start()
+{
+ common_start();
+}
+
+void nes_tam_s1_device::pcb_reset()
+{
+ m_chr_source = m_vrom_chunks ? CHRROM : CHRRAM;
+ prg16_89ab(m_prg_chunks - 1);
+ prg16_cdef(0);
+ chr8(0, m_chr_source);
+}
+
+void nes_g101_device::device_start()
+{
+ common_start();
+ save_item(NAME(m_latch));
+}
+
+void nes_g101_device::pcb_reset()
+{
+ m_chr_source = m_vrom_chunks ? CHRROM : CHRRAM;
+ prg16_89ab(0);
+ prg16_cdef(m_prg_chunks - 1);
+ chr8(0, m_chr_source);
+
+ m_latch = 0;
+}
+
+void nes_h3001_device::device_start()
+{
+ common_start();
+ save_item(NAME(m_irq_enable));
+ save_item(NAME(m_irq_count));
+ save_item(NAME(m_irq_count_latch));
+}
+
+void nes_h3001_device::pcb_reset()
+{
+ m_chr_source = m_vrom_chunks ? CHRROM : CHRRAM;
+ prg16_89ab(0);
+ prg16_cdef(m_prg_chunks - 1);
+ chr8(0, m_chr_source);
+
+ m_irq_enable = 0;
+ m_irq_count = 0;
+ m_irq_count_latch = 0;
+}
+
+
+/*-------------------------------------------------
+ mapper specific handlers
+ -------------------------------------------------*/
+
+/*-------------------------------------------------
+
+ Irem LROG017 - Discrete board emulation (74*161/161/21/138)
+
+ Games: Napoleon Senki
+
+ iNES: mapper 77
+
+ -------------------------------------------------*/
+
+WRITE8_MEMBER(nes_lrog017_device::write_h)
+{
+ LOG_MMC(("lrog017 write_h, offset: %04x, data: %02x\n", offset, data));
+
+ // this pcb is subject to bus conflict
+ data = account_bus_conflict(offset, data);
+
+ prg32(data);
+ chr2_0((data >> 4), CHRROM);
+}
+
+/*-------------------------------------------------
+
+ Irem Holy Diver board emulation
+
+ iNES: mapper 78 (shared with JF-16)
+
+ -------------------------------------------------*/
+
+WRITE8_MEMBER(nes_holydivr_device::write_h)
+{
+ LOG_MMC(("holy diver write_h, offset: %04x, data: %02x\n", offset, data));
+
+ // this pcb is subject to bus conflict
+ data = account_bus_conflict(offset, data);
+
+ set_nt_mirroring(BIT(data, 3) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
+ chr8(data >> 4, CHRROM);
+ prg16_89ab(data);
+}
+
+/*-------------------------------------------------
+
+ Irem TAM-S1 board emulation
+
+ Games: Kaiketsu Yanchamaru
+
+ iNES: mapper 97
+
+ In MESS: Supported.
+
+ -------------------------------------------------*/
+
+WRITE8_MEMBER(nes_tam_s1_device::write_h)
+{
+ LOG_MMC(("tam s1 write_h, offset: %04x, data: %02x\n", offset, data));
+
+ if (offset < 0x4000)
+ {
+ // this pcb is subject to bus conflict
+ data = account_bus_conflict(offset, data);
+
+ set_nt_mirroring(BIT(data, 7) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ);
+ prg16_cdef(data);
+ }
+}
+
+/*-------------------------------------------------
+
+ Irem G-101 board emulation
+
+ Major League uses hardwired mirroring
+
+ iNES: mapper 32
+
+ -------------------------------------------------*/
+
+WRITE8_MEMBER(nes_g101_device::write_h)
+{
+ LOG_MMC(("g101 write_h, offset: %04x, data: %02x\n", offset, data));
+
+ switch (offset & 0x7000)
+ {
+ case 0x0000:
+ // NEStopia here differs a little bit
+ m_latch ? prg8_cd(data) : prg8_89(data);
+ break;
+ case 0x1000:
+ m_latch = BIT(data, 1);
+ if (m_pcb_ctrl_mirror)
+ set_nt_mirroring(BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
+ break;
+ case 0x2000:
+ prg8_ab(data);
+ break;
+ case 0x3000:
+ chr1_x(offset & 0x07, data, CHRROM);
+ break;
+ }
+}
+
+/*-------------------------------------------------
+
+ Irem H-3001 board emulation
+
+ Games: Daiku no Gen San 2 - Akage no Dan no Gyakushuu,
+ Kaiketsu Yanchamaru 3, Spartan X 2
+
+ iNES: mapper 65
+
+ In MESS: Supported.
+
+ -------------------------------------------------*/
+
+/* Here, IRQ counter decrements every CPU cycle. Since we update it every scanline,
+ we need to decrement it by 114 (Each scanline consists of 341 dots and, on NTSC,
+ there are 3 dots to every 1 CPU cycle, hence 114 is the number of cycles per scanline ) */
+void nes_h3001_device::hblank_irq(int scanline, int vblank, int blanked)
+{
+ if (m_irq_enable)
+ {
+ m_irq_count -= 114;
+
+ if (m_irq_count <= 114)
+ {
+ m_irq_enable = 0;
+ machine().device("maincpu")->execute().set_input_line(M6502_IRQ_LINE, HOLD_LINE);
+ }
+ }
+}
+
+WRITE8_MEMBER(nes_h3001_device::write_h)
+{
+ LOG_MMC(("h3001 write_h, offset %04x, data: %02x\n", offset, data));
+
+ switch (offset & 0x7fff)
+ {
+ case 0x0000:
+ prg8_89(data);
+ break;
+
+ case 0x1001:
+ set_nt_mirroring(BIT(data, 7) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
+ break;
+
+ case 0x1003:
+ m_irq_enable = data & 0x80;
+ break;
+
+ case 0x1004:
+ m_irq_count = m_irq_count_latch;
+ break;
+
+ case 0x1005:
+ m_irq_count_latch = (m_irq_count_latch & 0x00ff) | (data << 8);
+ break;
+
+ case 0x1006:
+ m_irq_count_latch = (m_irq_count_latch & 0xff00) | data;
+ break;
+
+ case 0x2000:
+ prg8_ab(data);
+ break;
+
+ case 0x3000: case 0x3001: case 0x3002: case 0x3003:
+ case 0x3004: case 0x3005: case 0x3006: case 0x3007:
+ chr1_x(offset & 0x07, data, CHRROM);
+ break;
+
+ case 0x4000:
+ prg8_cd(data);
+ break;
+
+ default:
+ break;
+ }
+}