summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices
diff options
context:
space:
mode:
author Tomasz Slanina <tomasz.slanina@alan-systems.com>2018-08-22 10:19:16 +0200
committer Tomasz Slanina <tomasz.slanina@alan-systems.com>2018-08-22 10:19:16 +0200
commit403196c318fa275fccbb08ac21c9a83371d3123c (patch)
tree40937f2c2eb7701b6825c40f258b4e187ded11fb /src/devices
parentfbfab1d7a57d66c89273f31f02bf19f3781ae36a (diff)
New Working Game
------------------------------- Nightmare [Tomasz Slanina, Roberto Fresca, Jordi Beltran, Paco Ortiz, Recreativas.org]
Diffstat (limited to 'src/devices')
-rwxr-xr-xsrc/devices/machine/sda2006.cpp191
-rwxr-xr-xsrc/devices/machine/sda2006.h60
2 files changed, 251 insertions, 0 deletions
diff --git a/src/devices/machine/sda2006.cpp b/src/devices/machine/sda2006.cpp
new file mode 100755
index 00000000000..cfa31d9591d
--- /dev/null
+++ b/src/devices/machine/sda2006.cpp
@@ -0,0 +1,191 @@
+// license:BSD-3-Clause
+// copyright-holders:Tomasz Slanina
+
+#include "emu.h"
+#include "machine/sda2006.h"
+
+//-------------------------------------------------
+//
+// Siemens SDA2006 512-bit (32x16) NV EEPROM
+//
+// TODO:
+// - 8/12 bit controll word selection (currently emulates only 8 bt one)
+// - INV pin
+// - better( and correct) state flow
+// - read mode, with reversed data stream
+//
+//-------------------------------------------------
+
+enum {
+ CMD_WRITE,
+ CMD_READ_REVERSED,
+ CMD_READ,
+ CMD_UNKNOWN
+};
+
+#define EEPROM_CAPACITY 0x40
+#define EEPROM_ADDRESS_MASK 0x1f
+
+// device type definition
+DEFINE_DEVICE_TYPE(SDA2006, sda2006_device, "sda2006", "SDA2006 EEPROM")
+
+//-------------------------------------------------
+// sda2006_device - constructor
+//-------------------------------------------------
+
+sda2006_device::sda2006_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
+ : device_t(mconfig, SDA2006, tag, owner, clock)
+ , device_nvram_interface(mconfig, *this)
+ , m_latch(0), m_current_address(0), m_eeprom_state(),m_read_stream_pos(0),m_is_end_o_stream(false), m_write_stream_length(0), m_write_stream(0), m_write_state(0), m_clock_state (0)
+{
+}
+
+//-------------------------------------------------
+// device_validity_check - perform validity checks
+// on this device
+//-------------------------------------------------
+
+void sda2006_device::device_validity_check(validity_checker &valid) const
+{
+}
+
+//-------------------------------------------------
+// device_start - device-specific startup
+//-------------------------------------------------
+
+void sda2006_device::device_start()
+{
+ save_item(NAME(m_latch));
+ save_item(NAME(m_current_address));
+ save_item(NAME(m_eeprom_state));
+ save_item(NAME(m_read_stream_pos));
+ save_item(NAME(m_is_end_o_stream));
+ save_item(NAME(m_write_stream_length));
+ save_item(NAME(m_write_stream));
+ save_item(NAME(m_write_state));
+ save_item(NAME(m_clock_state));
+}
+
+//-------------------------------------------------
+// device_reset - device-specific reset
+//-------------------------------------------------
+
+void sda2006_device::device_reset()
+{
+ m_current_address = 0;
+ m_is_end_o_stream = false;
+ m_write_stream_length = 0;
+ m_write_stream = 0;
+ m_write_state = 0;
+ m_read_stream_pos = 0;
+ m_eeprom_state = EEPROM_WRITE;
+ m_clock_state = 0;
+
+}
+
+//-------------------------------------------------
+// nvram_default - called to initialize NVRAM to
+// its default state
+//-------------------------------------------------
+
+void sda2006_device::nvram_default()
+{
+ for (auto & elem : m_eeprom_data)
+ elem = 0xffff;
+}
+
+//-------------------------------------------------
+// nvram_read - called to read NVRAM from the
+// .nv file
+//-------------------------------------------------
+
+void sda2006_device::nvram_read(emu_file &file)
+{
+ file.read(m_eeprom_data, EEPROM_CAPACITY);
+}
+
+//-------------------------------------------------
+// nvram_write - called to write NVRAM to the
+// .nv file
+//-------------------------------------------------
+
+void sda2006_device::nvram_write(emu_file &file)
+{
+ file.write(m_eeprom_data, EEPROM_CAPACITY);
+}
+
+READ_LINE_MEMBER( sda2006_device::read_data )
+{
+ return m_latch^1;
+}
+
+WRITE_LINE_MEMBER( sda2006_device::write_data )
+{
+ m_latch = state;
+}
+
+WRITE_LINE_MEMBER( sda2006_device::write_enable )
+{
+ if( (m_write_state ^ state) && (!state)){ //falling edge
+ m_is_end_o_stream = true;
+ }
+
+ m_write_state = state;
+}
+
+WRITE_LINE_MEMBER( sda2006_device::write_clock )
+{
+ if( (m_clock_state ^ state) && (!state)) { // falling edge
+
+
+ if( m_eeprom_state == EEPROM_READ){
+ m_latch = (m_eeprom_data[m_current_address]>>(m_read_stream_pos))&1;
+ ++m_read_stream_pos;
+ if ( m_read_stream_pos == 16) {
+ // end of read
+ m_eeprom_state = EEPROM_WRITE;
+ m_write_stream_length = 0;
+ m_write_stream = 0;
+ }
+ } else {
+ if( m_is_end_o_stream ){
+ // stream data = AAAAACCC (read) or DDDDDDDDDDDDDDDDAAAAACCC (write)
+
+ uint32_t reversed_stream = 0;
+ uint32_t mask = 1;
+ uint32_t counter = m_write_stream_length;
+ m_is_end_o_stream = false;
+ m_write_stream_length = 0;
+ while(counter>0){
+ reversed_stream<<=1;
+
+ if (m_write_stream & mask) {
+ reversed_stream |= 1;
+ }
+ mask <<= 1;
+ --counter;
+ }
+
+ uint32_t command = bitswap<8>(m_write_stream, 7,6,5,4,3,0,1,2);
+
+ switch (command&3){
+ case CMD_WRITE: m_eeprom_data[(reversed_stream>>16) & EEPROM_ADDRESS_MASK] = reversed_stream & 0xffff; break;
+ case CMD_READ:
+ m_current_address = reversed_stream & EEPROM_ADDRESS_MASK;
+ m_read_stream_pos = 0;
+ m_eeprom_state = EEPROM_READ;
+ break;
+ case CMD_READ_REVERSED:
+ case CMD_UNKNOWN: break;
+ }
+ } else {
+
+ if( m_write_state ) {
+ m_write_stream = ( m_write_stream << 1 ) | m_latch;
+ ++m_write_stream_length;
+ }
+ }
+ }
+ }
+ m_clock_state = state;
+}
diff --git a/src/devices/machine/sda2006.h b/src/devices/machine/sda2006.h
new file mode 100755
index 00000000000..51fb91446d2
--- /dev/null
+++ b/src/devices/machine/sda2006.h
@@ -0,0 +1,60 @@
+// license:BSD-3-Clause
+// copyright-holders:Tomasz Slanina
+#ifndef MAME_MACHINE_SDA2006_H
+#define MAME_MACHINE_SDA2006_H
+
+#pragma once
+
+
+
+// sda2006_device
+
+class sda2006_device : public device_t,
+ public device_nvram_interface
+{
+public:
+ // construction/destruction
+ sda2006_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock = 0);
+
+ // I/O operations
+ DECLARE_READ_LINE_MEMBER( read_data );
+ DECLARE_WRITE_LINE_MEMBER( write_data );
+ DECLARE_WRITE_LINE_MEMBER( write_clock );
+ DECLARE_WRITE_LINE_MEMBER( write_enable );
+
+protected:
+ // device-level overrides
+ virtual void device_validity_check(validity_checker &valid) const override;
+ virtual void device_start() override;
+ virtual void device_reset() override;
+
+ virtual void nvram_default() override;
+ virtual void nvram_read(emu_file &file) override;
+ virtual void nvram_write(emu_file &file) override;
+
+private:
+ enum {
+ EEPROM_READ = 0,
+ EEPROM_WRITE
+ };
+
+ uint8_t m_latch;
+ uint8_t m_current_address;
+ uint32_t m_eeprom_state;
+ uint8_t m_read_stream_pos;
+ bool m_is_end_o_stream;
+ uint8_t m_write_stream_length;
+ uint32_t m_write_stream;
+ uint8_t m_write_state;
+ uint8_t m_clock_state;
+
+
+
+ uint16_t m_eeprom_data[0x20];
+};
+
+
+// device type definition
+DECLARE_DEVICE_TYPE(SDA2006, sda2006_device)
+
+#endif // MAME_MACHINE_SDA2006_H