summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author angelosa <lordkale4@gmail.com>2021-09-08 22:30:22 +0200
committer angelosa <lordkale4@gmail.com>2021-09-08 22:30:22 +0200
commitcd9a371dab06e6ed44bf3b297d74bb04f31b4ccc (patch)
treecf296dcb077924a48da4d1fdad9e2a563ba19398
parentd9a4f53711e7b19add79e981ecf758d15a158336 (diff)
k054000.cpp: convert access to address map
-rw-r--r--src/mame/video/k054000.cpp97
-rw-r--r--src/mame/video/k054000.h14
2 files changed, 98 insertions, 13 deletions
diff --git a/src/mame/video/k054000.cpp b/src/mame/video/k054000.cpp
index ad279083ae8..e4e47c2a0e7 100644
--- a/src/mame/video/k054000.cpp
+++ b/src/mame/video/k054000.cpp
@@ -66,7 +66,18 @@ k054000_device::k054000_device(const machine_config &mconfig, const char *tag, d
void k054000_device::device_start()
{
- save_item(NAME(m_regs));
+ save_item(NAME(m_Acx));
+ save_item(NAME(m_Acy));
+ save_item(NAME(m_Aax));
+ save_item(NAME(m_Aay));
+ save_item(NAME(m_Bcx));
+ save_item(NAME(m_Bcy));
+ save_item(NAME(m_Bax));
+ save_item(NAME(m_Bay));
+ save_pointer(NAME(m_raw_Acx), 4);
+ save_pointer(NAME(m_raw_Acy), 4);
+ save_pointer(NAME(m_raw_Bcx), 4);
+ save_pointer(NAME(m_raw_Bcy), 4);
}
//-------------------------------------------------
@@ -75,22 +86,87 @@ void k054000_device::device_start()
void k054000_device::device_reset()
{
- int i;
-
- for (i = 0; i < 0x20; i++)
- m_regs[i] = 0;
+ // TODO: initial state (very unlikely to be all zeroes)
+ // ...
}
/*****************************************************************************
DEVICE HANDLERS
*****************************************************************************/
-void k054000_device::write(offs_t offset, u8 data)
+void k054000_device::map(address_map &map)
+{
+ map.unmap_value_low();
+ map(0x01, 0x04).w(FUNC(k054000_device::acx_w));
+ map(0x06, 0x06).lw8(NAME([this] (u8 data) { m_Aax = data + 1; }));
+ map(0x07, 0x07).lw8(NAME([this] (u8 data) { m_Aay = data + 1; }));
+ map(0x09, 0x0c).w(FUNC(k054000_device::acy_w));
+
+ map(0x0e, 0x0e).lw8(NAME([this] (u8 data) { m_Bax = data + 1; }));
+ map(0x0f, 0x0f).lw8(NAME([this] (u8 data) { m_Bay = data + 1; }));
+ map(0x11, 0x13).w(FUNC(k054000_device::bcy_w));
+ map(0x15, 0x17).w(FUNC(k054000_device::bcx_w));
+
+ map(0x18, 0x18).r(FUNC(k054000_device::status_r));
+}
+
+inline int k054000_device::convert_raw_to_result(u8 *buf)
+{
+ int res = (buf[0] << 16) | (buf[1] << 8) | buf[2];
+ // last value in the buffer is used as OTG correction in Vendetta
+ if (buf[3] & 0x80)
+ res -= (0x100 - buf[3]);
+ else
+ res += buf[3];
+ return res;
+}
+
+void k054000_device::acx_w(offs_t offset, u8 data)
+{
+ m_raw_Acx[offset] = data;
+ m_Acx = convert_raw_to_result(m_raw_Acx);
+}
+
+void k054000_device::acy_w(offs_t offset, u8 data)
+{
+ m_raw_Acy[offset] = data;
+ m_Acy = convert_raw_to_result(m_raw_Acy);
+}
+
+void k054000_device::bcx_w(offs_t offset, u8 data)
+{
+ m_raw_Bcx[offset] = data;
+ m_Bcx = convert_raw_to_result(m_raw_Bcx);
+}
+
+void k054000_device::bcy_w(offs_t offset, u8 data)
+{
+ m_raw_Bcy[offset] = data;
+ m_Bcy = convert_raw_to_result(m_raw_Bcy);
+}
+
+u8 k054000_device::status_r()
{
- //logerror("%s: write %02x to 054000 address %02x\n",m_maincpu->pc(),data,offset);
- m_regs[offset] = data;
+ u8 res = 0;
+
+ if (m_Acx + m_Aax < m_Bcx - m_Bax)
+ res |= 1;
+
+ if (m_Bcx + m_Bax < m_Acx - m_Aax)
+ res |= 1;
+
+ if (m_Acy + m_Aay < m_Bcy - m_Bay)
+ res |= 1;
+
+ if (m_Bcy + m_Bay < m_Acy - m_Aay)
+ res |= 1;
+
+ printf("%d %d %d %d (%d|%d)|%d %d %d %d == %d\n", m_Acx, m_Acy, m_Aax, m_Aay, m_raw_Acx[3], m_raw_Acy[3], m_Bcx, m_Bcy, m_Bax, m_Bay, res);
+
+ return res;
}
+#ifdef UNUSED_FUNCTION
u8 k054000_device::read(offs_t offset)
{
int Acx, Acy, Aax, Aay;
@@ -128,8 +204,8 @@ u8 k054000_device::read(offs_t offset)
Bax = m_regs[0x0e] + 1;
Bay = m_regs[0x0f] + 1;
- if (m_regs[0x04] || m_regs[0x0c])
- printf("%d %d %d %d (%d|%d)|%d %d %d %d\n", Acx, Acy, Aax, Aay, m_regs[0x04], m_regs[0x0c], Bcx, Bcy, Bax, Bay);
+ //if (m_regs[0x04] || m_regs[0x0c])
+ printf("%d %d %d %d (%d|%d)|%d %d %d %d\n", Acx, Acy, Aax, Aay, m_regs[0x04], m_regs[0x0c], Bcx, Bcy, Bax, Bay);
if (Acx + Aax < Bcx - Bax)
return 1;
@@ -145,3 +221,4 @@ u8 k054000_device::read(offs_t offset)
return 0;
}
+#endif
diff --git a/src/mame/video/k054000.h b/src/mame/video/k054000.h
index cf12a580422..41815c9f7ac 100644
--- a/src/mame/video/k054000.h
+++ b/src/mame/video/k054000.h
@@ -12,8 +12,7 @@ public:
k054000_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
~k054000_device() {}
- void write(offs_t offset, u8 data);
- u8 read(offs_t offset);
+ void map(address_map &map);
protected:
// device-level overrides
@@ -22,7 +21,16 @@ protected:
private:
// internal state
- uint8_t m_regs[0x20];
+ void acx_w(offs_t offset, u8 data);
+ void acy_w(offs_t offset, u8 data);
+ void bcx_w(offs_t offset, u8 data);
+ void bcy_w(offs_t offset, u8 data);
+ int convert_raw_to_result(u8 *buf);
+ u8 status_r();
+
+ u8 m_raw_Acx[4], m_raw_Acy[4], m_raw_Bcx[4], m_raw_Bcy[4];
+ int m_Acx, m_Acy, m_Bcx, m_Bcy;
+ int m_Aax, m_Aay, m_Bax, m_Bay;
};
DECLARE_DEVICE_TYPE(K054000, k054000_device)