summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/machine/nes_event.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_event.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_event.c')
-rw-r--r--src/mess/machine/nes_event.c239
1 files changed, 239 insertions, 0 deletions
diff --git a/src/mess/machine/nes_event.c b/src/mess/machine/nes_event.c
new file mode 100644
index 00000000000..d59fbf626f7
--- /dev/null
+++ b/src/mess/machine/nes_event.c
@@ -0,0 +1,239 @@
+/***********************************************************************************************************
+
+
+ NES/Famicom cartridge emulation for Nintendo NES-EVENT PCB
+
+ Copyright MESS Team.
+ Visit http://mamedev.org for licensing and usage restrictions.
+
+
+ Here we emulate the following PCBs
+
+ * Nintendo NES-EVENT [mapper 105]
+
+ ***********************************************************************************************************/
+
+
+#include "emu.h"
+#include "machine/nes_event.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_EVENT = &device_creator<nes_event_device>;
+
+
+nes_event_device::nes_event_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
+ : nes_sxrom_device(mconfig, NES_EVENT, "NES Cart Event PCB", tag, owner, clock, "nes_event", __FILE__),
+ m_dsw(*this, "DIPSW")
+{
+}
+
+
+void nes_event_device::device_start()
+{
+ common_start();
+ event_timer = timer_alloc(TIMER_EVENT);
+ event_timer->adjust(attotime::never);
+
+ save_item(NAME(m_latch));
+ save_item(NAME(m_count));
+ save_item(NAME(m_reg));
+ save_item(NAME(m_reg_write_enable));
+ save_item(NAME(m_nwc_init));
+
+ save_item(NAME(m_timer_count));
+ save_item(NAME(m_timer_on));
+ save_item(NAME(m_timer_enabled));
+}
+
+void nes_event_device::pcb_reset()
+{
+ m_latch = 0;
+ m_count = 0;
+ m_reg[0] = 0x0f;
+ m_reg[1] = m_reg[2] = m_reg[3] = 0;
+ m_reg_write_enable = 1;
+ m_nwc_init = 2;
+
+ set_nt_mirroring(PPU_MIRROR_HORZ);
+ chr8(0, CHRRAM);
+ prg32(0);
+ m_timer_count = 0;
+ m_timer_enabled = 0;
+ m_timer_on = 0;
+}
+
+
+
+/*-------------------------------------------------
+ mapper specific handlers
+ -------------------------------------------------*/
+
+/*-------------------------------------------------
+
+ Event PCB
+
+ Games: Nintento World Championships
+
+ MMC-1 variant with repurposed register at $a000 and a
+ lot of discrete components
+
+ iNES: mapper 105
+
+ In MESS: Supported.
+
+ -------------------------------------------------*/
+
+void nes_event_device::set_chr()
+{
+ // no CHR switching, there are only 8KB VRAM from the cart
+}
+
+void nes_event_device::set_prg()
+{
+// printf("enter with %d and reg1 0x%x - reg3 0x%x\n", m_nwc_init, m_reg[1], m_reg[3]);
+ // reg[1] is different from base MMC-1!
+ // bit 0 is ignored, bit1/bit3 are used for PRG switch, bit4 is used for the timer
+ UINT8 temp = (m_reg[1] >> 1) & 7;
+
+ // initially PRG is fixed, until bit4 of reg1 is set to 1 and then to 0
+ switch (m_nwc_init)
+ {
+ case 2:
+ if (m_reg[1] & 0x10) m_nwc_init--;
+ return;
+ case 1:
+ if (~m_reg[1] & 0x10) m_nwc_init--;
+ return;
+ }
+
+ if (temp < 4)
+ prg32(temp);
+ else
+ {
+ // else PRG works similarly to base MMC-1, but only acts on the higher 128KB (2nd PRG ROM)
+ switch (m_reg[0] & 0x0c)
+ {
+ case 0x00:
+ case 0x04:
+ prg32(0x04 | ((m_reg[3] >> 1) & 0x03));
+ break;
+ case 0x08:
+ prg16_89ab(0x08 | 0x00);
+ prg16_cdef(0x08 | (m_reg[3] & 0x07));
+ break;
+ case 0x0c:
+ prg16_89ab(0x08 | (m_reg[3] & 0x07));
+ prg16_cdef(0x08 | 0x07);
+ break;
+ }
+ }
+
+ // after the init procedure above, bit4 of m_reg[1] is used to init IRQ, by setting and then clearing the bit
+ // however, there are (bankswitch related?) writes with bit4 cleared before the one 'enabling' the timer, so
+ // we need the additional m_timer_enabled variable, to avoid starting the timer before its time...
+ if (m_reg[1] & 0x10)
+ {
+ m_timer_enabled = 1;
+ machine().device("maincpu")->execute().set_input_line(M6502_IRQ_LINE, CLEAR_LINE);
+ }
+ else
+ {
+ if (!m_timer_on && m_timer_enabled)
+ {
+ m_timer_count = 0x20000000 | ((m_dsw->read() & 0x0f) << 25);
+ event_timer->adjust(attotime::zero, 0, machine().device<cpu_device>("maincpu")->cycles_to_attotime(1));
+ m_timer_on = 1;
+ }
+ }
+}
+
+void nes_event_device::update_regs(int reg)
+{
+ switch (reg)
+ {
+ case 0:
+ switch (m_reg[0] & 0x03)
+ {
+ case 0: set_nt_mirroring(PPU_MIRROR_LOW); break;
+ case 1: set_nt_mirroring(PPU_MIRROR_HIGH); break;
+ case 2: set_nt_mirroring(PPU_MIRROR_VERT); break;
+ case 3: set_nt_mirroring(PPU_MIRROR_HORZ); break;
+ }
+ set_prg();
+ break;
+ case 1:
+ set_prg();
+ break;
+ case 2:
+ set_chr();
+ break;
+ case 3:
+ set_prg();
+ break;
+ }
+}
+
+//-------------------------------------------------
+// Dipswicth
+//-------------------------------------------------
+
+static INPUT_PORTS_START( nwc_dsw )
+ PORT_START("DIPSW")
+ PORT_DIPNAME( 0x0f, 0x04, "Timer" ) PORT_DIPLOCATION("SW:!1,!2,!3,!4")
+ PORT_DIPSETTING( 0x00, "5:00.4" )
+ PORT_DIPSETTING( 0x01, "5:19.2" )
+ PORT_DIPSETTING( 0x02, "5:38.0" )
+ PORT_DIPSETTING( 0x03, "5:56.7" )
+ PORT_DIPSETTING( 0x04, "6:15.5" )
+ PORT_DIPSETTING( 0x05, "6:34.3" )
+ PORT_DIPSETTING( 0x06, "6:53.1" )
+ PORT_DIPSETTING( 0x07, "7:11.9" )
+ PORT_DIPSETTING( 0x08, "7:30.6" )
+ PORT_DIPSETTING( 0x09, "7:49.4" )
+ PORT_DIPSETTING( 0x0a, "8:08.2" )
+ PORT_DIPSETTING( 0x0b, "8:27.0" )
+ PORT_DIPSETTING( 0x0c, "8:45.8" )
+ PORT_DIPSETTING( 0x0d, "9:04.5" )
+ PORT_DIPSETTING( 0x0e, "9:23.3" )
+ PORT_DIPSETTING( 0x0f, "9:42.1" )
+INPUT_PORTS_END
+
+
+
+ioport_constructor nes_event_device::device_input_ports() const
+{
+ return INPUT_PORTS_NAME( nwc_dsw );
+}
+
+
+//-------------------------------------------------
+// device_timer - handler timer events
+//-------------------------------------------------
+
+void nes_event_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
+{
+ if (id == TIMER_EVENT)
+ {
+ m_timer_count--;
+ if (!m_timer_count)
+ {
+ machine().device("maincpu")->execute().set_input_line(M6502_IRQ_LINE, HOLD_LINE);
+ event_timer->reset();
+ }
+ }
+}