summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/spi_sdcard.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/machine/spi_sdcard.h')
-rw-r--r--src/devices/machine/spi_sdcard.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/devices/machine/spi_sdcard.h b/src/devices/machine/spi_sdcard.h
new file mode 100644
index 00000000000..4bd79e5aa30
--- /dev/null
+++ b/src/devices/machine/spi_sdcard.h
@@ -0,0 +1,55 @@
+// license:BSD-3-Clause
+// copyright-holders:R. Belmont
+#ifndef MAME_MACHINE_SPI_SDCARD_H
+#define MAME_MACHINE_SPI_SDCARD_H
+
+#pragma once
+
+#include "imagedev/harddriv.h"
+
+class spi_sdcard_device : public device_t
+{
+public:
+ spi_sdcard_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
+
+ // SPI 4-wire interface
+ auto spi_miso_callback() { return write_miso.bind(); }
+ void spi_clock_w(int state);
+ void spi_ss_w(int state) { m_ss = state; }
+ void spi_mosi_w(int state) { m_in_bit = state; }
+
+ bool get_card_present() { return !(m_harddisk == nullptr); }
+
+ devcb_write_line write_miso;
+
+protected:
+ spi_sdcard_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);
+
+ virtual void device_start() override;
+ virtual void device_reset() override;
+ virtual void device_add_mconfig(machine_config &config) override;
+
+ required_device<harddisk_image_device> m_image;
+
+private:
+ enum
+ {
+ SD_STATE_IDLE = 0,
+ SD_STATE_WRITE_WAITFE,
+ SD_STATE_WRITE_DATA
+ };
+
+ void send_data(int count);
+ void do_command();
+
+ u8 m_data[520], m_cmd[6];
+ hard_disk_file *m_harddisk;
+
+ u8 m_in_latch, m_out_latch;
+ int m_cmd_ptr, m_state, m_out_ptr, m_out_count, m_ss, m_in_bit, m_cur_bit, m_write_ptr;
+ bool m_bACMD;
+};
+
+DECLARE_DEVICE_TYPE(SPI_SDCARD, spi_sdcard_device)
+
+#endif // MAME_MACHINE_SPI_SDCARD_H