From f7445714fcec7bdb8a5c0c9bb1444841ad54c4d7 Mon Sep 17 00:00:00 2001
From: Jason Flatt <jflatt@cox.net>
Date: Wed, 8 Mar 2023 18:01:16 -0800
Subject: [PATCH] Add irobot patch

---
 irobot.patch          | 37 +++++++++++++++++++++++++++++++++++++
 org.mamedev.MAME.yaml |  2 ++
 2 files changed, 39 insertions(+)
 create mode 100644 irobot.patch

diff --git a/irobot.patch b/irobot.patch
new file mode 100644
index 0000000..1abd26e
--- /dev/null
+++ b/irobot.patch
@@ -0,0 +1,37 @@
+diff --git a/src/mame/atari/irobot_m.cpp b/src/mame/atari/irobot_m.cpp
+index dfb5987e7e8..f6d24db5a9a 100644
+--- a/src/mame/atari/irobot_m.cpp
++++ b/src/mame/atari/irobot_m.cpp
+@@ -315,12 +315,11 @@ void irobot_state::irmb_dout(const irmb_ops *curop, uint32_t d)
+ void irobot_state::load_oproms()
+ {
+ 	uint8_t *MB = memregion("proms")->base() + 0x20;
+-	int i;
+ 
+ 	/* allocate RAM */
+ 	m_mbops = std::make_unique<irmb_ops[]>(1024);
+ 
+-	for (i = 0; i < 1024; i++)
++	for (int i = 0; i < 1024; i++)
+ 	{
+ 		int nxtadd, func, ramsel, diradd, latchmask, dirmask, time;
+ 
+@@ -387,12 +386,14 @@ void irobot_state::load_oproms()
+ void irobot_state::init_irobot()
+ {
+ 	for (int i = 0; i < 16; i++)
+-	{
+-		m_irmb_stack[i] = &m_mbops[0];
+ 		m_irmb_regs[i] = 0;
+-	}
+-	m_irmb_latch = 0;
++
+ 	load_oproms();
++
++	for (int i = 0; i < 16; i++)
++		m_irmb_stack[i] = &m_mbops[0];
++
++	m_irmb_latch = 0;
+ }
+ 
+ TIMER_DEVICE_CALLBACK_MEMBER(irobot_state::irobot_irmb_done_callback)
diff --git a/org.mamedev.MAME.yaml b/org.mamedev.MAME.yaml
index d37a4b7..902db35 100644
--- a/org.mamedev.MAME.yaml
+++ b/org.mamedev.MAME.yaml
@@ -85,3 +85,5 @@ modules:
         path: sound.patch
       - type: patch
         path: ym3802.patch
+      - type: patch
+        path: irobot.patch