Better devicification of the Apple II FDC/IWM/SWIM

This commit is contained in:
Nathan Woods 2012-12-24 21:11:07 +00:00
parent 4e3e4bec10
commit e9352ef19a
13 changed files with 647 additions and 602 deletions

2
.gitattributes vendored
View File

@ -7293,6 +7293,8 @@ src/mess/machine/strata.c svneol=native#text/plain
src/mess/machine/strata.h svneol=native#text/plain
src/mess/machine/super80.c svneol=native#text/plain
src/mess/machine/svi318.c svneol=native#text/plain
src/mess/machine/swim.c svneol=native#text/plain
src/mess/machine/swim.h svneol=native#text/plain
src/mess/machine/sym1.c svneol=native#text/plain
src/mess/machine/tandy1t.c svneol=native#text/plain
src/mess/machine/tandy2kb.c svneol=native#text/plain

View File

@ -50,6 +50,7 @@
#include "machine/6522via.h"
#include "machine/ncr5380.h"
#include "machine/applefdc.h"
#include "machine/swim.h"
#include "devices/sonydriv.h"
#include "formats/ap_dsk35.h"
#include "machine/ram.h"

View File

@ -138,7 +138,7 @@ void a2bus_floppy_device::device_reset()
UINT8 a2bus_floppy_device::read_c0nx(address_space &space, UINT8 offset)
{
return applefdc_r(m_fdc, space, offset);
return m_fdc->read(offset);
}
@ -148,7 +148,7 @@ UINT8 a2bus_floppy_device::read_c0nx(address_space &space, UINT8 offset)
void a2bus_floppy_device::write_c0nx(address_space &space, UINT8 offset, UINT8 data)
{
applefdc_w(m_fdc, space, offset, data);
m_fdc->write(offset, data);
}
/*-------------------------------------------------

View File

@ -1049,7 +1049,7 @@ READ8_MEMBER( apple2gs_state::apple2gs_c0xx_r )
case 0xe8: case 0xe9: case 0xea: case 0xeb: case 0xec: case 0xed: case 0xee: case 0xef:
if ((m_sltromsel & (1 << 6)) == 0)
{
result = applefdc_r(m_fdc, space, offset);
result = m_fdc->read(offset);
}
else
{
@ -1205,7 +1205,7 @@ WRITE8_MEMBER( apple2gs_state::apple2gs_c0xx_w )
case 0xe8: case 0xe9: case 0xea: case 0xeb: case 0xec: case 0xed: case 0xee: case 0xef:
if ((m_sltromsel & (1 << 6)) == 0)
{
applefdc_w(m_fdc, space, offset, data);
m_fdc->write(offset, data);
}
else
{

View File

@ -104,7 +104,7 @@ void apple3_state::apple3_profile_w(offs_t offset, UINT8 data)
READ8_MEMBER(apple3_state::apple3_c0xx_r)
{
acia6551_device *acia = machine().device<acia6551_device>("acia");
device_t *fdc = machine().device("fdc");
applefdc_base_device *fdc = machine().device<applefdc_base_device>("fdc");
UINT8 result = 0xFF;
switch(offset)
@ -171,7 +171,7 @@ READ8_MEMBER(apple3_state::apple3_c0xx_r)
case 0xE4: case 0xE5: case 0xE6: case 0xE7:
case 0xE8: case 0xE9: case 0xEA: case 0xEB:
case 0xEC: case 0xED: case 0xEE: case 0xEF:
result = applefdc_r(fdc, space, offset);
result = fdc->read(offset);
break;
case 0xF0:
@ -189,7 +189,8 @@ READ8_MEMBER(apple3_state::apple3_c0xx_r)
WRITE8_MEMBER(apple3_state::apple3_c0xx_w)
{
acia6551_device *acia = machine().device<acia6551_device>("acia");
device_t *fdc = machine().device("fdc");
applefdc_base_device *fdc = machine().device<applefdc_base_device>("fdc");
switch(offset)
{
case 0x10: case 0x11: case 0x12: case 0x13:
@ -234,7 +235,7 @@ WRITE8_MEMBER(apple3_state::apple3_c0xx_w)
case 0xE4: case 0xE5: case 0xE6: case 0xE7:
case 0xE8: case 0xE9: case 0xEA: case 0xEB:
case 0xEC: case 0xED: case 0xEE: case 0xEF:
applefdc_w(fdc, space, offset, data);
fdc->write(offset, data);
break;
case 0xF0:

File diff suppressed because it is too large Load Diff

View File

@ -28,62 +28,14 @@
#define APPLEFDC_PH2 0x04
#define APPLEFDC_PH3 0x08
class applefdc_base_device : public device_t
{
public:
applefdc_base_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock);
~applefdc_base_device() { global_free(m_token); }
// access to legacy token
void *token() const { assert(m_token != NULL); return m_token; }
protected:
// device-level overrides
virtual void device_config_complete();
virtual void device_start() { }
virtual void device_reset();
private:
// internal state
void *m_token;
};
class applefdc_device : public applefdc_base_device
{
public:
applefdc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
protected:
// device-level overrides
virtual void device_start();
};
extern const device_type APPLEFDC;
class iwm_device : public applefdc_base_device
{
public:
iwm_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
protected:
// device-level overrides
virtual void device_start();
};
extern const device_type IWM;
class swim_device : public applefdc_base_device
{
public:
swim_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
protected:
// device-level overrides
virtual void device_start();
};
extern const device_type SWIM;
/***************************************************************************
TYPE DEFINITIONS
INTERFACE
***************************************************************************/
struct applefdc_interface
@ -99,14 +51,91 @@ struct applefdc_interface
/***************************************************************************
PROTOTYPES
BASE DEVICE
***************************************************************************/
/* read/write handlers */
DECLARE_READ8_DEVICE_HANDLER(applefdc_r);
DECLARE_WRITE8_DEVICE_HANDLER(applefdc_w);
/* accessor */
UINT8 applefdc_get_lines(device_t *device);
class applefdc_base_device : public device_t
{
public:
// read/write handlers
virtual UINT8 read(UINT8 offset);
virtual void write(UINT8 offset, UINT8 data);
// read/write handlers overloads
UINT8 read(offs_t offset) { return read((UINT8) offset); }
void write(offs_t offset, UINT8 data) { write((UINT8) offset, data); }
DECLARE_READ8_MEMBER( read ) { return read((UINT8) offset); }
DECLARE_WRITE8_MEMBER( write ) { write((UINT8) offset, data); }
// accessor
UINT8 get_lines();
protected:
enum applefdc_t
{
APPLEFDC_APPLE2, /* classic Apple II disk controller (pre-IWM) */
APPLEFDC_IWM, /* Integrated Woz Machine */
APPLEFDC_SWIM /* Sander/Woz Integrated Machine */
};
// constructor
applefdc_base_device(applefdc_t fdc_type, const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock);
// device-level overrides
virtual void device_start();
virtual void device_reset();
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
// other protecteds
virtual void iwm_modereg_w(UINT8 data);
private:
// data that is constant for the lifetime of the emulation
emu_timer * m_motor_timer;
applefdc_t m_type;
// data that changes at emulation time
UINT8 m_write_byte;
UINT8 m_lines; /* flags from IWM_MOTOR - IWM_Q7 */
UINT8 m_mode; /* 0-31; see above */
UINT8 m_handshake_hack; /* not sure what this is for */
// functions
const applefdc_interface *get_interface();
int iwm_enable2();
UINT8 iwm_readenable2handshake();
UINT8 statusreg_r();
UINT8 read_reg(int lines);
void write_reg(UINT8 data);
void turn_motor_onoff(bool status);
void iwm_access(int offset);
};
/***************************************************************************
APPLE FDC - Used on Apple II
***************************************************************************/
class applefdc_device : public applefdc_base_device
{
public:
applefdc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
};
/***************************************************************************
IWM - Used on early Macs
***************************************************************************/
class iwm_device : public applefdc_base_device
{
public:
iwm_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
};
/***************************************************************************
DEVICE CONFIGURATION MACROS
@ -128,13 +157,5 @@ UINT8 applefdc_get_lines(device_t *device);
MCFG_DEVICE_MODIFY(_tag) \
MCFG_DEVICE_CONFIG(_intrf)
#define MCFG_SWIM_ADD(_tag, _intrf) \
MCFG_DEVICE_ADD(_tag, SWIM, 0) \
MCFG_DEVICE_CONFIG(_intrf)
#define MCFG_SWIM_MODIFY(_tag, _intrf) \
MCFG_DEVICE_MODIFY(_tag) \
MCFG_DEVICE_CONFIG(_intrf)
#endif /* __APPLEFDC_H__ */

View File

@ -1196,10 +1196,10 @@ INLINE void lisa_fdc_ttl_glue_access(running_machine &machine, offs_t offset)
state->m_MT1 = offset & 1;
if (state->m_MT1 && ! oldMT1)
{
device_t *fdc = machine.device("fdc");
applefdc_base_device *fdc = machine.device<applefdc_base_device>("fdc");
state->m_PWM_floppy_motor_speed = (state->m_PWM_floppy_motor_speed << 1) & 0xff;
if (applefdc_get_lines(fdc) & APPLEFDC_PH0)
if (fdc->get_lines() & APPLEFDC_PH0)
state->m_PWM_floppy_motor_speed |= 1;
sony_set_speed(((256-state->m_PWM_floppy_motor_speed) * 1.3) + 237);
}
@ -1233,12 +1233,12 @@ INLINE void lisa_fdc_ttl_glue_access(running_machine &machine, offs_t offset)
READ8_MEMBER(lisa_state::lisa_fdc_io_r)
{
int answer=0;
device_t *fdc = machine().device("fdc");
applefdc_base_device *fdc = machine().device<applefdc_base_device>("fdc");
switch ((offset & 0x0030) >> 4)
{
case 0: /* IWM */
answer = applefdc_r(fdc, space, offset);
answer = fdc->read(offset);
break;
case 1: /* TTL glue */
@ -1260,12 +1260,12 @@ READ8_MEMBER(lisa_state::lisa_fdc_io_r)
WRITE8_MEMBER(lisa_state::lisa_fdc_io_w)
{
device_t *fdc = machine().device("fdc");
applefdc_base_device *fdc = machine().device<applefdc_base_device>("fdc");
switch ((offset & 0x0030) >> 4)
{
case 0: /* IWM */
applefdc_w(fdc, space, offset, data);
fdc->write(offset, data);
break;
case 1: /* TTL glue */

View File

@ -1140,9 +1140,9 @@ READ16_MEMBER ( mac_state::mac_iwm_r )
*/
UINT16 result = 0;
device_t *fdc = space.machine().device("fdc");
applefdc_base_device *fdc = space.machine().device<applefdc_base_device>("fdc");
result = applefdc_r(fdc, space, (offset >> 8));
result = fdc->read(offset >> 8);
if (LOG_MAC_IWM)
printf("mac_iwm_r: offset=0x%08x mem_mask %04x = %02x (PC %x)\n", offset, mem_mask, result, m_maincpu->pc());
@ -1152,15 +1152,15 @@ READ16_MEMBER ( mac_state::mac_iwm_r )
WRITE16_MEMBER ( mac_state::mac_iwm_w )
{
device_t *fdc = space.machine().device("fdc");
applefdc_base_device *fdc = space.machine().device<applefdc_base_device>("fdc");
if (LOG_MAC_IWM)
printf("mac_iwm_w: offset=0x%08x data=0x%04x mask %04x (PC=%x)\n", offset, data, mem_mask, m_maincpu->pc());
if (ACCESSING_BITS_0_7)
applefdc_w(fdc, space, (offset >> 8), data & 0xff);
fdc->write((offset >> 8), data & 0xff);
else
applefdc_w(fdc, space, (offset >> 8), data>>8);
fdc->write((offset >> 8), data>>8);
}
READ8_MEMBER(mac_state::mac_adb_via_in_cb2)

View File

@ -417,18 +417,18 @@ CALL &320 to start, or use BOBY rom.
static void oric_install_apple2_interface(running_machine &machine)
{
oric_state *state = machine.driver_data<oric_state>();
device_t *fdc = machine.device("fdc");
applefdc_base_device *fdc = machine.device<applefdc_base_device>("fdc");
address_space &space = machine.device("maincpu")->memory().space(AS_PROGRAM);
if (state->m_is_telestrat)
return;
space.install_read_handler(0x0300, 0x030f, read8_delegate(FUNC(oric_state::oric_IO_r),state));
space.install_legacy_read_handler(*fdc, 0x0310, 0x031f, FUNC(applefdc_r));
space.install_read_handler(0x0300, 0x030f, read8_delegate(FUNC(oric_state::oric_IO_r), state));
space.install_read_handler(0x0310, 0x031f, read8_delegate(FUNC(applefdc_base_device::read), fdc));
space.install_read_bank(0x0320, 0x03ff, "bank4");
space.install_write_handler(0x0300, 0x030f, write8_delegate(FUNC(oric_state::oric_IO_w),state));
space.install_legacy_write_handler(*fdc, 0x0310, 0x031f, FUNC(applefdc_w));
space.install_write_handler(0x0300, 0x030f, write8_delegate(FUNC(oric_state::oric_IO_w), state));
space.install_write_handler(0x0310, 0x031f, write8_delegate(FUNC(applefdc_base_device::write), fdc));
state->membank("bank4")->set_base( state->memregion("maincpu")->base() + 0x014000 + 0x020);
}
@ -541,15 +541,15 @@ WRITE8_MEMBER(oric_state::apple2_v2_interface_w)
static void oric_install_apple2_v2_interface(running_machine &machine)
{
oric_state *state = machine.driver_data<oric_state>();
device_t *fdc = machine.device("fdc");
applefdc_base_device *fdc = machine.device<applefdc_base_device>("fdc");
address_space &space = machine.device("maincpu")->memory().space(AS_PROGRAM);
space.install_read_handler(0x0300, 0x030f, read8_delegate(FUNC(oric_state::oric_IO_r),state));
space.install_legacy_read_handler(*fdc, 0x0310, 0x031f, FUNC(applefdc_r));
space.install_read_handler(0x0300, 0x030f, read8_delegate(FUNC(oric_state::oric_IO_r), state));
space.install_read_handler(0x0310, 0x031f, read8_delegate(FUNC(applefdc_base_device::read), fdc));
space.install_read_bank(0x0320, 0x03ff, "bank4");
space.install_write_handler(0x0300, 0x030f, write8_delegate(FUNC(oric_state::oric_IO_w),state));
space.install_legacy_write_handler(*fdc, 0x0310, 0x031f, FUNC(applefdc_w));
space.install_write_handler(0x0300, 0x030f, write8_delegate(FUNC(oric_state::oric_IO_w), state));
space.install_write_handler(0x0310, 0x031f, write8_delegate(FUNC(applefdc_base_device::write), fdc));
space.install_write_handler(0x0380, 0x0383, write8_delegate(FUNC(oric_state::apple2_v2_interface_w),state));
state->apple2_v2_interface_w(space, 0, 0);

220
src/mess/machine/swim.c Normal file
View File

@ -0,0 +1,220 @@
/*********************************************************************
swim.c
Implementation of the Apple SWIM FDC controller; used on (less)
early Macs
*********************************************************************/
#include "machine/swim.h"
/***************************************************************************
CONSTANTS
***************************************************************************/
#define LOG_SWIM 0
enum
{
SWIM_MODE_IWM,
SWIM_MODE_SWIM,
SWIM_MODE_SWIM2,
SWIM_MODE_SWIM3
};
/***************************************************************************
DEVICE
***************************************************************************/
const device_type SWIM = &device_creator<swim_device>;
//-------------------------------------------------
// ctor
//-------------------------------------------------
swim_device::swim_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: applefdc_base_device(APPLEFDC_SWIM, mconfig, SWIM, "Apple SWIM (Steve Woz Integrated Machine)", tag, owner, clock)
{
}
//-------------------------------------------------
// device_start - device-specific start
//-------------------------------------------------
void swim_device::device_start()
{
// call inherited version
applefdc_base_device::device_start();
m_swim_mode = SWIM_MODE_IWM;
m_swim_magic_state = 0x00;
m_parm_offset = 0x00;
memset(m_ism_regs, 0, sizeof(m_ism_regs));
memset(m_parms, 0, sizeof(m_parms));
}
//-------------------------------------------------
// device_reset - device-specific reset
//-------------------------------------------------
void swim_device::device_reset()
{
// call inherited version
applefdc_base_device::device_reset();
static UINT8 swim_default_parms[16] =
{
0x38, 0x18, 0x41, 0x2e, 0x2e, 0x18, 0x18, 0x1b,
0x1b, 0x2f, 0x2f, 0x19, 0x19, 0x97, 0x1b, 0x57
};
for (int i = 0; i < 16; i++)
{
m_parms[i] = swim_default_parms[i];
}
m_swim_magic_state = 0;
m_swim_mode = SWIM_MODE_IWM;
m_parm_offset = 0;
}
//-------------------------------------------------
// read - reads a byte from the FDC
//-------------------------------------------------
UINT8 swim_device::read(UINT8 offset)
{
UINT8 result = 0;
if (m_swim_mode == SWIM_MODE_IWM)
{
// IWM mode
result = applefdc_base_device::read(offset);
}
else if (m_swim_mode >= SWIM_MODE_SWIM)
{
// reading parameter RAM?
if ((offset & 7) == 3)
{
result = m_parms[m_parm_offset++];
m_parm_offset &= 0xf;
}
else
{
result = m_ism_regs[offset&7];
}
if (LOG_SWIM)
logerror("SWIM: read %02x from offset %x\n", result, offset & 7);
}
return result;
}
//-------------------------------------------------
// write - write a byte to the FDC
//-------------------------------------------------
void swim_device::write(UINT8 offset, UINT8 data)
{
if (m_swim_mode == SWIM_MODE_IWM)
{
// IWM mode
applefdc_base_device::write(offset, data);
}
else if (m_swim_mode >= SWIM_MODE_SWIM)
{
if (LOG_SWIM)
logerror("SWIM: write %02x to offset %x\n", data, offset & 7);
switch (offset & 7)
{
case 2: // write CRC
break;
case 3: // write parameter
m_parms[m_parm_offset++] = data;
m_parm_offset &= 0xf;
break;
case 6: // write zeros to status (also zeroes parameter RAM pointer)
m_ism_regs[6] &= ~data;
m_parm_offset = 0;
if (data == 0xf8) // magic "revert to IWM" value
{
if (LOG_SWIM)
logerror("SWIM: reverting to IWM\n");
m_swim_mode = SWIM_MODE_IWM;
}
break;
case 7: // write ones to status
m_ism_regs[6] |= data;
break;
default:
m_ism_regs[offset & 7] = data;
break;
}
}
}
//-------------------------------------------------
// iwm_modereg_w - changes the mode register
//-------------------------------------------------
void swim_device::iwm_modereg_w(UINT8 data)
{
// SWIM mode is unlocked by writing 1/0/1/1 in a row to bit 6 (which is unused on IWM)
// when SWIM mode engages, the IWM is disconnected from both the 68k and the drives,
// and the ISM is substituted.
switch (m_swim_magic_state)
{
case 0:
case 2:
case 3:
if (data & 0x40)
{
m_swim_magic_state++;
}
else
{
m_swim_magic_state = 0;
}
break;
case 1:
if (!(data & 0x40))
{
m_swim_magic_state++;
}
else
{
m_swim_magic_state = 0;
}
break;
}
if (m_swim_magic_state == 4)
{
m_swim_magic_state = 0;
m_swim_mode = SWIM_MODE_SWIM;
}
// call inherited version
applefdc_base_device::iwm_modereg_w(data);
}

61
src/mess/machine/swim.h Normal file
View File

@ -0,0 +1,61 @@
/*********************************************************************
swim.h
Implementation of the Apple SWIM FDC controller; used on (less)
early Macs
*********************************************************************/
#ifndef __SWIM_H__
#define __SWIM_H__
#include "machine/applefdc.h"
/***************************************************************************
DEVICE
***************************************************************************/
extern const device_type SWIM;
class swim_device : public applefdc_base_device
{
public:
swim_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
// read/write
virtual UINT8 read(UINT8 offset);
virtual void write(UINT8 offset, UINT8 data);
protected:
// device-level overrides
virtual void device_start();
virtual void device_reset();
// other overrides
virtual void iwm_modereg_w(UINT8 data);
private:
UINT8 m_swim_mode;
UINT8 m_swim_magic_state;
UINT8 m_parm_offset;
UINT8 m_ism_regs[8];
UINT8 m_parms[16];
};
/***************************************************************************
DEVICE CONFIGURATION MACROS
***************************************************************************/
#define MCFG_SWIM_ADD(_tag, _intrf) \
MCFG_DEVICE_ADD(_tag, SWIM, 0) \
MCFG_DEVICE_CONFIG(_intrf)
#define MCFG_SWIM_MODIFY(_tag, _intrf) \
MCFG_DEVICE_MODIFY(_tag) \
MCFG_DEVICE_CONFIG(_intrf)
#endif // __SWIM_H__

View File

@ -710,6 +710,7 @@ $(MESSOBJ)/apple.a: \
$(MESS_MACHINE)/egret.o \
$(MESS_MACHINE)/cuda.o \
$(MESS_MACHINE)/mackbd.o \
$(MESS_MACHINE)/swim.o \
$(MESS_VIDEO)/nubus_48gc.o \
$(MESS_VIDEO)/nubus_cb264.o \
$(MESS_VIDEO)/nubus_vikbw.o \