vis: fix card comms and crc

This commit is contained in:
cracyc 2021-06-23 16:41:27 -05:00
parent 4c92baf896
commit 3f5cec732b
4 changed files with 63 additions and 20 deletions

View File

@ -1199,7 +1199,7 @@ end
---------------------------------------------------
--
--@src/devices/machine/ds2404.h,MACHINES["DS6417"] = true
--@src/devices/machine/ds6417.h,MACHINES["DS6417"] = true
---------------------------------------------------
if (MACHINES["DS6417"]~=null) then

View File

@ -6,7 +6,7 @@
#include "ds6417.h"
DEFINE_DEVICE_TYPE(DS6417, ds6417_device, "ds6417", "Dallas DS6417 Memory Card")
DEFINE_DEVICE_TYPE(DS6417, ds6417_device, "ds6417", "Dallas DS6417 CyberCard")
ds6417_device::ds6417_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: device_t(mconfig, DS6417, tag, owner, clock)
@ -26,6 +26,7 @@ void ds6417_device::device_start()
save_item(NAME(m_crc));
save_item(NAME(m_select));
save_item(NAME(m_shiftreg));
save_item(NAME(m_count));
}
void ds6417_device::device_reset()
@ -51,17 +52,26 @@ image_init_result ds6417_device::call_create(int format_type, util::option_resol
return image_init_result::PASS;
}
uint8_t ds6417_device::calccrc(uint8_t bit, uint8_t crc) const
{
bit = (crc ^ bit) & 1;
if(bit)
return ((crc >> 1) | (bit << 7)) ^ 0x66;
else
return crc >> 1;
}
WRITE_LINE_MEMBER( ds6417_device::clock_w )
{
if(!m_reset)
if(!m_reset || !exists())
return;
if(m_clock != (state != 0))
if(m_clk == (state != 0))
return;
m_clock = state;
m_clk = state;
if(m_read && m_clock && m_start)
if(m_read && !m_clk && m_start)
{
if(!(m_count & 7))
{
@ -83,14 +93,16 @@ WRITE_LINE_MEMBER( ds6417_device::clock_w )
m_data = m_shiftreg & 1;
m_shiftreg >>= 1;
m_count++;
m_crc = calccrc(m_data, m_crc);
}
else if(!m_clock)
else if(m_clk && !m_read)
{
m_shiftreg = (m_shiftreg >> 1) | (m_data ? 0x80 : 0);
m_count++;
if(m_start)
{
m_crc = calccrc(m_data, m_crc);
if(!(m_count & 7))
{
switch(m_command)
@ -109,7 +121,7 @@ WRITE_LINE_MEMBER( ds6417_device::clock_w )
switch(m_count)
{
case 8:
if((m_shiftreg != 0xe8) || (m_shiftreg != 0x17))
if((m_shiftreg != 0xe8) && (m_shiftreg != 0x17))
reset();
break;
case 16:
@ -129,6 +141,7 @@ WRITE_LINE_MEMBER( ds6417_device::clock_w )
m_select |= m_shiftreg << 8;
break;
case 56:
// command crc
if((m_command & CMD_READMASK) == CMD_READMASK)
{
m_selbits = m_command & 7;
@ -137,17 +150,20 @@ WRITE_LINE_MEMBER( ds6417_device::clock_w )
switch(m_command)
{
case CMD_READ:
case CMD_READPROT:
case CMD_READMASK:
m_crc = 0; [[fallthrough]];
case CMD_READPROT:
case CMD_READCRC:
m_read = true;
break;
case CMD_WRITE:
m_crc = 0; [[fallthrough]];
case CMD_WRITEPROT:
break;
default:
reset();
return;
}
m_start = true;
fseek(m_addr & 0x7fff, SEEK_SET);

View File

@ -26,16 +26,17 @@ public:
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(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; }
DECLARE_WRITE_LINE_MEMBER(reset_w) { if(!state && m_reset) reset(); m_reset = state; }
DECLARE_READ_LINE_MEMBER(data_r) { return m_read ? m_data : 0; }
protected:
virtual void device_start() override;
virtual void device_reset() override;
private:
uint8_t calccrc(uint8_t bit, uint8_t crc) const;
enum {
CMD_READ = 0x06,
CMD_WRITE = 0x11,

View File

@ -724,7 +724,7 @@ private:
uint8_t unk_r(offs_t offset);
void unk_w(offs_t offset, uint8_t data);
uint8_t unk2_r();
uint8_t memcard_r();
uint8_t memcard_r(offs_t offset);
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);
@ -739,6 +739,7 @@ private:
uint8_t m_unkidx;
uint8_t m_unk[16];
uint8_t m_unk1[4];
uint8_t m_cardreg, m_cardval, m_cardcnt;
uint16_t m_padctl, m_padstat;
};
@ -775,17 +776,42 @@ uint8_t vis_state::unk2_r()
return 0x40;
}
//memory card reader?
uint8_t vis_state::memcard_r()
uint8_t vis_state::memcard_r(offs_t offset)
{
return m_card->data_r() ? 0x20 : 0;
if(offset)
{
if((m_cardreg & 0x18) == 0x18)
{
if(m_cardcnt == 8)
return 0;
m_card->clock_w(1);
m_card->clock_w(0);
m_cardval = (m_cardval >> 1) | (m_card->data_r() ? 0x80 : 0);
m_cardcnt++;
return 0x80;
}
}
else
{
m_cardcnt = 0;
return m_cardval;
}
return 0;
}
void vis_state::memcard_w(offs_t offset, uint8_t data)
{
m_card->clock_w(BIT(data, 0));
if(offset)
{
if((data & 0x18) != 0x18)
{
m_card->data_w(BIT(data, 1));
m_card->reset_w(BIT(data, 2));
m_card->clock_w(BIT(data, 0));
m_card->reset_w(!BIT(data, 2));
}
m_cardreg = data;
m_cardcnt = 0;
}
}
uint16_t vis_state::pad_r(offs_t offset)
@ -878,7 +904,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).rw(FUNC(vis_state::memcard_r), FUNC(vis_state::memcard_w)).umask16(0x00ff);
map(0x0318, 0x031a).rw(FUNC(vis_state::memcard_r), FUNC(vis_state::memcard_w)).umask16(0x00ff);
}
static void vis_cards(device_slot_interface &device)