summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/swim1.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/machine/swim1.cpp')
-rw-r--r--src/devices/machine/swim1.cpp109
1 files changed, 77 insertions, 32 deletions
diff --git a/src/devices/machine/swim1.cpp b/src/devices/machine/swim1.cpp
index 75c3b12b186..2a54d1d613e 100644
--- a/src/devices/machine/swim1.cpp
+++ b/src/devices/machine/swim1.cpp
@@ -9,12 +9,15 @@
#include "emu.h"
#include "swim1.h"
-#include "cpu/m68000/m68000.h"
+#define VERBOSE 0
+#include "logmacro.h"
DEFINE_DEVICE_TYPE(SWIM1, swim1_device, "swim1", "Apple SWIM1 (Sander/Wozniak Integrated Machine) version 1 floppy controller")
swim1_device::swim1_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
- applefdintf_device(mconfig, SWIM1, tag, owner, clock)
+ applefdintf_device(mconfig, SWIM1, tag, owner, clock),
+ m_floppy(nullptr),
+ m_timer(nullptr)
{
}
@@ -22,6 +25,7 @@ void swim1_device::device_start()
{
applefdintf_device::device_start();
+ m_timer = timer_alloc(FUNC(swim1_device::update), this);
save_item(NAME(m_last_sync));
save_item(NAME(m_flux_write_start));
save_item(NAME(m_flux_write));
@@ -100,6 +104,7 @@ void swim1_device::device_reset()
m_devsel_cb(0);
m_sel35_cb(true);
m_hdsel_cb(false);
+ m_dat1byte_cb(0);
}
void swim1_device::set_floppy(floppy_image_device *floppy)
@@ -110,7 +115,7 @@ void swim1_device::set_floppy(floppy_image_device *floppy)
sync();
flush_write();
- logerror("floppy %s\n", floppy ? floppy->tag() : "-");
+ LOG("floppy %s\n", floppy ? floppy->tag() : "-");
m_floppy = floppy;
update_phases();
@@ -125,7 +130,7 @@ floppy_image_device *swim1_device::get_floppy() const
void swim1_device::ism_show_mode() const
{
- logerror("ism mode%s %s hdsel=%c %c%s %c%c%s\n",
+ LOG("ism mode%s %s hdsel=%c %c%s %c%c%s\n",
m_ism_mode & 0x80 ? " motoron" : "",
m_ism_mode & 0x40 ? "ism" : "iwm",
m_ism_mode & 0x20 ? '1' : '0',
@@ -142,7 +147,19 @@ u8 swim1_device::read(offs_t offset)
if(m_ism_mode & 0x40)
return ism_read(offset);
else
- return iwm_control(offset, 0x00);
+ {
+ if(!machine().side_effects_disabled())
+ iwm_control(offset, 0x00);
+
+ switch(m_iwm_control & 0xc0) {
+ case 0x00: return m_iwm_active ? m_iwm_data : 0xff;
+ case 0x40: return (m_iwm_status & 0x7f) | ((!m_floppy || m_floppy->wpt_r()) ? 0x80 : 0x00);
+ case 0x80: return m_iwm_whd;
+ case 0xc0: return 0xff;
+ }
+
+ abort();
+ }
}
void swim1_device::write(offs_t offset, u8 data)
@@ -161,7 +178,7 @@ u8 swim1_device::ism_read(offs_t offset)
// "data", "mark", "crc", "param", "phases", "setup", "status", "handshake"
// };
- // logerror("read ism %s\n", names[offset & 7]);
+ // LOG("read ism %s\n", names[offset & 7]);
switch(offset & 7) {
case 0x0: { // data
u16 r = ism_fifo_pop();
@@ -268,14 +285,14 @@ void swim1_device::ism_write(offs_t offset, u8 data)
"minct", "mult", "ssl", "sss", "sll", "sls", "rpt", "csls",
"lsl", "lss", "lll", "lls", "late", "time0", "early", "time1"
};
- logerror("param[%s] = %02x\n", pname[m_ism_param_idx], data);
+ LOG("param[%s] = %02x\n", pname[m_ism_param_idx], data);
m_ism_param[m_ism_param_idx] = data;
m_ism_param_idx = (m_ism_param_idx + 1) & 15;
break;
}
case 0x4: {
- logerror("ism phases %02x\n", data);
+ LOG("ism phases %02x\n", data);
m_phases = data;
update_phases();
break;
@@ -283,7 +300,7 @@ void swim1_device::ism_write(offs_t offset, u8 data)
case 0x5:
m_ism_setup = data;
- logerror("setup timer=%s tsm=%s %s ecm=%s %s %s 3.5=%s %s\n",
+ LOG("setup timer=%s tsm=%s %s ecm=%s %s %s 3.5=%s %s\n",
m_ism_setup & 0x80 ? "on" : "off",
m_ism_setup & 0x40 ? "off" : "on",
m_ism_setup & 0x20 ? "ibm" : "apple",
@@ -298,13 +315,21 @@ void swim1_device::ism_write(offs_t offset, u8 data)
m_ism_mode &= ~data;
m_ism_param_idx = 0;
ism_show_mode();
- if(!(m_ism_mode & 0x40))
- logerror("switch to iwm\n");
+ if(data & 0x10)
+ m_dat1byte_cb((m_ism_fifo_pos != 0) ? 1 : 0);
+ if(!(m_ism_mode & 0x40)) {
+ LOG("switch to iwm\n");
+ u8 ism_devsel = m_ism_mode & 0x80 ? (m_ism_mode >> 1) & 3 : 0;
+ if(ism_devsel != m_iwm_devsel)
+ m_devsel_cb(m_iwm_devsel);
+ }
break;
case 0x7:
m_ism_mode |= data;
ism_show_mode();
+ if(data & 0x10)
+ m_dat1byte_cb((m_ism_fifo_pos != 2) ? 1 : 0);
break;
default:
@@ -315,7 +340,7 @@ void swim1_device::ism_write(offs_t offset, u8 data)
if(m_ism_mode & 0x01)
ism_fifo_clear();
- if((m_ism_mode ^ prev_mode) & 0x06)
+ if((m_ism_mode ^ prev_mode) & 0x86)
m_devsel_cb(m_ism_mode & 0x80 ? (m_ism_mode >> 1) & 3 : 0);
if((m_ism_mode ^ prev_mode) & 0x20)
m_hdsel_cb((m_ism_mode >> 5) & 1);
@@ -323,7 +348,7 @@ void swim1_device::ism_write(offs_t offset, u8 data)
if((m_ism_mode & 0x18) == 0x18 && ((prev_mode & 0x18) != 0x18)) {
// Entering write mode
m_ism_current_bit = 0;
- logerror("%s write start %s %s floppy=%p\n", machine().time().to_string(), m_ism_setup & 0x40 ? "gcr" : "mfm", m_ism_setup & 0x08 ? "fclk/2" : "fclk", m_floppy);
+ LOG("%s write start %s %s floppy=%p\n", machine().time().to_string(), m_ism_setup & 0x40 ? "gcr" : "mfm", m_ism_setup & 0x08 ? "fclk/2" : "fclk", m_floppy);
m_flux_write_start = m_last_sync;
m_flux_write_count = 0;
@@ -333,7 +358,7 @@ void swim1_device::ism_write(offs_t offset, u8 data)
m_flux_write_start = 0;
m_ism_current_bit = 0xff;
m_ism_half_cycles_before_change = 0;
- logerror("%s write end\n", machine().time().to_string());
+ LOG("%s write end\n", machine().time().to_string());
}
if((m_ism_mode & 0x18) == 0x08 && ((prev_mode & 0x18) != 0x08)) {
@@ -348,18 +373,18 @@ void swim1_device::ism_write(offs_t offset, u8 data)
m_ism_csm_pair_side = 0;
m_ism_csm_min_count = 0;
- logerror("%s read start %s %s floppy=%p\n", machine().time().to_string(), m_ism_setup & 0x04 ? "gcr" : "mfm", m_ism_setup & 0x08 ? "fclk/2" : "fclk", m_floppy);
+ LOG("%s read start %s %s floppy=%p\n", machine().time().to_string(), m_ism_setup & 0x04 ? "gcr" : "mfm", m_ism_setup & 0x08 ? "fclk/2" : "fclk", m_floppy);
} else if((prev_mode & 0x18) == 0x08 && (m_ism_mode & 0x18) != 0x08) {
// Exiting read mode
flush_write();
m_ism_current_bit = 0xff;
m_ism_half_cycles_before_change = 0;
- logerror("%s read end\n", machine().time().to_string());
+ LOG("%s read end\n", machine().time().to_string());
}
}
-void swim1_device::device_timer(emu_timer &, device_timer_id, int, void *)
+TIMER_CALLBACK_MEMBER(swim1_device::update)
{
if(m_iwm_active == MODE_DELAY) {
flush_write();
@@ -405,7 +430,7 @@ void swim1_device::flush_write(u64 when)
m_flux_write_count = 0;
}
-u8 swim1_device::iwm_control(int offset, u8 data)
+void swim1_device::iwm_control(int offset, u8 data)
{
iwm_sync();
@@ -500,7 +525,7 @@ u8 swim1_device::iwm_control(int offset, u8 data)
if(s == 0xc0 && m_iwm_active)
slot = "write load / write data";
- logerror("%s control %c%c %c%c %c%c%c%c (%s) [%s, %s] whd=%02x data=%02x\n",
+ LOG("%s control %c%c %c%c %c%c%c%c (%s) [%s, %s] whd=%02x data=%02x\n",
machine().time().to_string(),
m_iwm_control & 0x80 ? '1' : '0',
m_iwm_control & 0x40 ? '1' : '0',
@@ -532,7 +557,10 @@ u8 swim1_device::iwm_control(int offset, u8 data)
case 3:
if(data & 0x40) {
m_ism_mode |= 0x40;
- logerror("switch to ism\n");
+ LOG("switch to ism\n");
+ u8 ism_devsel = m_ism_mode & 0x80 ? (m_ism_mode >> 1) & 3 : 0;
+ if(ism_devsel != m_iwm_devsel)
+ m_devsel_cb(ism_devsel);
}
break;
}
@@ -540,16 +568,15 @@ u8 swim1_device::iwm_control(int offset, u8 data)
if(m_iwm_to_ism_counter != prev_iwm_to_ism_counter+1)
m_iwm_to_ism_counter = 0;
else
- logerror("iwm counter = %d\n", m_iwm_to_ism_counter);
+ LOG("iwm counter = %d\n", m_iwm_to_ism_counter);
- switch(m_iwm_control & 0xc0) {
- case 0x00: return m_iwm_active ? m_iwm_data : 0xff;
- case 0x40: return (m_iwm_status & 0x7f) | ((!m_floppy || m_floppy->wpt_r()) ? 0x80 : 0x00);
- case 0x80: return m_iwm_whd;
- case 0xc0: if(offset & 1) { if(m_iwm_active) iwm_data_w(data); else iwm_mode_w(data); } return 0xff;
+ if((m_iwm_control & 0xc0) == 0xc0 && (offset & 1))
+ {
+ if(m_iwm_active)
+ iwm_data_w(data);
+ else
+ iwm_mode_w(data);
}
-
- abort();
}
void swim1_device::ism_crc_clear()
@@ -580,6 +607,7 @@ attotime swim1_device::cycles_to_time(u64 cycles) const
void swim1_device::ism_fifo_clear()
{
m_ism_fifo_pos = 0;
+ m_dat1byte_cb((m_ism_mode & 0x10) ? 1 : 0);
ism_crc_clear();
}
@@ -588,6 +616,15 @@ bool swim1_device::ism_fifo_push(u16 data)
if(m_ism_fifo_pos == 2)
return true;
m_ism_fifo[m_ism_fifo_pos ++] = data;
+ if(m_ism_mode & 0x10) {
+ // write
+ if(m_ism_fifo_pos == 2)
+ m_dat1byte_cb(0);
+ } else {
+ // read
+ if(m_ism_fifo_pos == 1)
+ m_dat1byte_cb(1);
+ }
return false;
}
@@ -598,6 +635,15 @@ u16 swim1_device::ism_fifo_pop()
u16 r = m_ism_fifo[0];
m_ism_fifo[0] = m_ism_fifo[1];
m_ism_fifo_pos --;
+ if(m_ism_mode & 0x10) {
+ // write
+ if(m_ism_fifo_pos == 1)
+ m_dat1byte_cb(1);
+ } else {
+ // read
+ if(m_ism_fifo_pos == 0)
+ m_dat1byte_cb(0);
+ }
return r;
}
@@ -605,7 +651,7 @@ void swim1_device::iwm_mode_w(u8 data)
{
m_iwm_mode = data;
m_iwm_status = (m_iwm_status & 0xe0) | (data & 0x1f);
- logerror("mode %02x%s%s%s%s%s%s%s\n", m_iwm_mode,
+ LOG("mode %02x%s%s%s%s%s%s%s\n", m_iwm_mode,
m_iwm_mode & 0x80 ? " b7" : "",
m_iwm_mode & 0x40 ? " mz-reset" : "",
m_iwm_mode & 0x20 ? " test" : " normal",
@@ -763,7 +809,7 @@ void swim1_device::iwm_sync()
case SW_WINDOW_LOAD:
if(m_iwm_whd & 0x80) {
- logerror("underrun\n");
+ LOG("underrun\n");
flush_write();
m_flux_write_start = 0;
m_iwm_whd &= ~0x40;
@@ -873,7 +919,7 @@ void swim1_device::ism_sync()
m_ism_current_bit = 0xff;
m_ism_half_cycles_before_change = 0;
m_ism_mode &= ~8;
- logerror("write end on underrun\n");
+ LOG("write end on underrun\n");
break;
}
if(r & M_CRC)
@@ -1134,7 +1180,6 @@ void swim1_device::ism_sync()
val |= M_CRC0;
if(ism_fifo_push(val) && !m_ism_error)
m_ism_error |= 0x01;
- machine().debug_break();
m_ism_tsm_bits = 0;
}
}