From 188a28c9ff09ab95beb0427c8ea1b37dd512e6c1 Mon Sep 17 00:00:00 2001 From: cracyc Date: Tue, 22 Jun 2021 17:10:30 -0500 Subject: vis: add memory card device --- scripts/src/machine.lua | 12 ++++ scripts/target/mame/mess.lua | 1 + src/devices/machine/ds6417.cpp | 158 +++++++++++++++++++++++++++++++++++++++++ src/devices/machine/ds6417.h | 64 +++++++++++++++++ src/mame/drivers/vis.cpp | 21 ++++-- 5 files changed, 252 insertions(+), 4 deletions(-) create mode 100644 src/devices/machine/ds6417.cpp create mode 100644 src/devices/machine/ds6417.h diff --git a/scripts/src/machine.lua b/scripts/src/machine.lua index 1df555aa05f..456b21e836d 100644 --- a/scripts/src/machine.lua +++ b/scripts/src/machine.lua @@ -1197,6 +1197,18 @@ if (MACHINES["DS2404"]~=null) then } end +--------------------------------------------------- +-- +--@src/devices/machine/ds2404.h,MACHINES["DS6417"] = true +--------------------------------------------------- + +if (MACHINES["DS6417"]~=null) then + files { + MAME_DIR .. "src/devices/machine/ds6417.cpp", + MAME_DIR .. "src/devices/machine/ds6417.h", + } +end + --------------------------------------------------- -- --@src/devices/machine/ds75160a.h,MACHINES["DS75160A"] = true diff --git a/scripts/target/mame/mess.lua b/scripts/target/mame/mess.lua index 0b1f1ecb0e1..15e31fd7400 100644 --- a/scripts/target/mame/mess.lua +++ b/scripts/target/mame/mess.lua @@ -516,6 +516,7 @@ MACHINES["DS1386"] = true MACHINES["DS17X85"] = true MACHINES["DS2401"] = true MACHINES["DS2404"] = true +MACHINES["DS6417"] = true MACHINES["DS75160A"] = true MACHINES["DS75161A"] = true MACHINES["DS8874"] = true diff --git a/src/devices/machine/ds6417.cpp b/src/devices/machine/ds6417.cpp new file mode 100644 index 00000000000..bc696d6b10b --- /dev/null +++ b/src/devices/machine/ds6417.cpp @@ -0,0 +1,158 @@ +// license:BSD-3-Clause +// copyright-holders:Carl + + +#include "emu.h" +#include "ds6417.h" + + +DEFINE_DEVICE_TYPE(DS6417, ds6417_device, "ds6417", "Dallas DS6417 Memory Card") + +ds6417_device::ds6417_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) + : device_t(mconfig, DS6417, tag, owner, clock) + , device_image_interface(mconfig, *this) +{ +} + +void ds6417_device::device_start() +{ + save_item(NAME(m_read)); + save_item(NAME(m_clk)); + save_item(NAME(m_reset)); + save_item(NAME(m_start)); + save_item(NAME(m_data)); + save_item(NAME(m_command)); + save_item(NAME(m_addr)); + save_item(NAME(m_crc)); + save_item(NAME(m_select)); + save_item(NAME(m_shiftreg)); +} + +void ds6417_device::device_reset() +{ + m_read = false; + m_start = false; + m_count = 0; + m_command = 0; +} + +image_init_result ds6417_device::call_load() +{ + if(length() != 32768) + return image_init_result::FAIL; + return image_init_result::PASS; +} + +image_init_result ds6417_device::call_create(int format_type, util::option_resolution *format_options) +{ + u8 buffer[32768] = {0}; + if(fwrite(buffer, 32768) != 32768) + return image_init_result::FAIL; + return image_init_result::PASS; +} + +WRITE_LINE_MEMBER( ds6417_device::clock_w ) +{ + if(!m_reset) + return; + + if(m_clock != (state != 0)) + return; + + m_clock = state; + + if(m_read && m_clock && m_start) + { + if(!(m_count & 7)) + { + switch(m_command) + { + case CMD_READ: + case CMD_READMASK: + fread(&m_shiftreg, 1); + break; + case CMD_READPROT: + m_shiftreg = m_selectval; + break; + case CMD_READCRC: + m_shiftreg = m_crc; + break; + } + } + + m_data = m_shiftreg & 1; + m_shiftreg >>= 1; + m_count++; + } + else if(!m_clock) + { + m_shiftreg = (m_shiftreg >> 1) | (m_data ? 0x80 : 0); + m_count++; + + if(m_start) + { + if(!(m_count & 7)) + { + switch(m_command) + { + case CMD_WRITE: + fwrite(&m_shiftreg, 1); + break; + case CMD_WRITEPROT: + m_selectval = m_shiftreg; + break; + } + } + } + else + { + switch(m_count) + { + case 8: + if((m_shiftreg != 0xe8) || (m_shiftreg != 0x17)) + reset(); + break; + case 16: + m_addr = m_shiftreg; + break; + case 24: + m_addr |= m_shiftreg << 8; + break; + case 32: + m_addr |= (m_shiftreg & 7) << 16; + m_command = m_shiftreg >> 3; + break; + case 40: + m_select = m_shiftreg; + break; + case 48: + m_select |= m_shiftreg << 8; + break; + case 56: + if((m_command & CMD_READMASK) == CMD_READMASK) + { + m_selbits = m_command & 7; + m_command &= 0x18; + } + switch(m_command) + { + case CMD_READ: + case CMD_READPROT: + case CMD_READMASK: + case CMD_READCRC: + m_read = true; + break; + case CMD_WRITE: + case CMD_WRITEPROT: + break; + default: + reset(); + return; + } + m_start = true; + fseek(m_addr & 0x7fff, SEEK_SET); + break; + } + } + } +} diff --git a/src/devices/machine/ds6417.h b/src/devices/machine/ds6417.h new file mode 100644 index 00000000000..6c2de94c6de --- /dev/null +++ b/src/devices/machine/ds6417.h @@ -0,0 +1,64 @@ +// license:BSD-3-Clause +// copyright-holders:Carl + +// Only known to be used by the Tandy VIS + +#ifndef MAME_MACHINE_DS6417_H_ +#define MAME_MACHINE_DS6417_H_ + + +class ds6417_device : public device_t, + public device_image_interface +{ +public: + // construction/destruction + ds6417_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); + + virtual iodevice_t image_type() const noexcept override { return IO_MEMCARD; } + + virtual bool is_readable() const noexcept override { return true; } + virtual bool is_writeable() const noexcept override { return true; } + virtual bool is_creatable() const noexcept override { return true; } + virtual bool must_be_loaded() const noexcept override { return false; } + virtual bool is_reset_on_load() const noexcept override { return false; } + virtual const char *file_extensions() const noexcept override { return "bin"; } + + virtual image_init_result call_load() override; + virtual image_init_result call_create(int format_type, util::option_resolution *format_options) override; + + DECLARE_WRITE_LINE_MEMBER(data_w) { if(m_read) m_data = state; } + DECLARE_WRITE_LINE_MEMBER(clock_w); + DECLARE_WRITE_LINE_MEMBER(reset_w) { m_reset = state; if(!state) reset(); } + DECLARE_READ_LINE_MEMBER(data_r) { return m_data; } + +protected: + virtual void device_start() override; + virtual void device_reset() override; + +private: + enum { + CMD_READ = 0x06, + CMD_WRITE = 0x11, + CMD_READPROT = 0x05, + CMD_WRITEPROT = 0x0e, + CMD_READMASK = 0x18, + CMD_READCRC = 0x03 + }; + bool m_reset; + bool m_clk; + bool m_data; + bool m_read; + bool m_start; + u8 m_count; + u8 m_shiftreg; + u8 m_command; + u8 m_crc; + u8 m_selbits; + u32 m_addr; + u16 m_select; + u16 m_selectval; +}; + +DECLARE_DEVICE_TYPE(DS6417, ds6417_device) + +#endif /* MAME_MACHINE_DS6417_H_ */ diff --git a/src/mame/drivers/vis.cpp b/src/mame/drivers/vis.cpp index 48cad1e3307..470b22be7fc 100644 --- a/src/mame/drivers/vis.cpp +++ b/src/mame/drivers/vis.cpp @@ -6,6 +6,7 @@ #include "cpu/i86/i286.h" #include "machine/8042kbdc.h" #include "machine/at.h" +#include "machine/ds6417.h" #include "sound/dac.h" #include "sound/ymopl.h" #include "video/pc_vga.h" @@ -703,6 +704,7 @@ public: m_maincpu(*this, "maincpu"), m_pic1(*this, "mb:pic8259_master"), m_pic2(*this, "mb:pic8259_slave"), + m_card(*this, "card"), m_pad(*this, "PAD") { } @@ -714,6 +716,7 @@ private: required_device m_maincpu; required_device m_pic1; required_device m_pic2; + required_device m_card; required_ioport m_pad; uint8_t sysctl_r(); @@ -721,7 +724,8 @@ private: uint8_t unk_r(offs_t offset); void unk_w(offs_t offset, uint8_t data); uint8_t unk2_r(); - uint8_t unk3_r(); + uint8_t memcard_r(); + void memcard_w(offs_t offset, uint8_t data); uint16_t pad_r(offs_t offset); void pad_w(offs_t offset, uint16_t data); uint8_t unk1_r(offs_t offset); @@ -772,9 +776,16 @@ uint8_t vis_state::unk2_r() } //memory card reader? -uint8_t vis_state::unk3_r() +uint8_t vis_state::memcard_r() { - return 0x00; + return m_card->data_r() ? 0x20 : 0; +} + +void vis_state::memcard_w(offs_t offset, uint8_t data) +{ + m_card->clock_w(BIT(data, 0)); + m_card->data_w(BIT(data, 1)); + m_card->reset_w(BIT(data, 2)); } uint16_t vis_state::pad_r(offs_t offset) @@ -867,7 +878,7 @@ void vis_state::io_map(address_map &map) map(0x00e0, 0x00e1).noprw(); map(0x023c, 0x023f).rw(FUNC(vis_state::unk1_r), FUNC(vis_state::unk1_w)); map(0x0268, 0x026f).rw(FUNC(vis_state::pad_r), FUNC(vis_state::pad_w)); - map(0x031a, 0x031a).r(FUNC(vis_state::unk3_r)); + map(0x031a, 0x031a).rw(FUNC(vis_state::memcard_r), FUNC(vis_state::memcard_w)).umask16(0x00ff); } static void vis_cards(device_slot_interface &device) @@ -920,6 +931,8 @@ void vis_state::vis(machine_config &config) ISA16_SLOT(config, "mcd", 0, "mb:isabus", pc_isa16_cards, "mcd", true); ISA16_SLOT(config, "visaudio", 0, "mb:isabus", vis_cards, "visaudio", true); ISA16_SLOT(config, "visvga", 0, "mb:isabus", vis_cards, "visvga", true); + + DS6417(config, m_card, 0); } ROM_START(vis) -- cgit v1.2.3