Previous 199869 Revisions Next

r19779 Monday 24th December, 2012 at 21:11:07 UTC by Nathan Woods
Better devicification of the Apple II FDC/IWM/SWIM
[src/mess]mess.mak
[src/mess/drivers]mac.c
[src/mess/machine]a2diskii.c apple2gs.c apple3.c applefdc.c applefdc.h lisa.c mac.c oric.c swim.c* swim.h*

trunk/src/mess/machine/apple3.c
r19778r19779
104104READ8_MEMBER(apple3_state::apple3_c0xx_r)
105105{
106106   acia6551_device *acia = machine().device<acia6551_device>("acia");
107   device_t *fdc = machine().device("fdc");
107   applefdc_base_device *fdc = machine().device<applefdc_base_device>("fdc");
108108   UINT8 result = 0xFF;
109109
110110   switch(offset)
r19778r19779
171171      case 0xE4: case 0xE5: case 0xE6: case 0xE7:
172172      case 0xE8: case 0xE9: case 0xEA: case 0xEB:
173173      case 0xEC: case 0xED: case 0xEE: case 0xEF:
174         result = applefdc_r(fdc, space, offset);
174         result = fdc->read(offset);
175175         break;
176176
177177      case 0xF0:
r19778r19779
189189WRITE8_MEMBER(apple3_state::apple3_c0xx_w)
190190{
191191   acia6551_device *acia = machine().device<acia6551_device>("acia");
192   device_t *fdc = machine().device("fdc");
192   applefdc_base_device *fdc = machine().device<applefdc_base_device>("fdc");
193
193194   switch(offset)
194195   {
195196      case 0x10: case 0x11: case 0x12: case 0x13:
r19778r19779
234235      case 0xE4: case 0xE5: case 0xE6: case 0xE7:
235236      case 0xE8: case 0xE9: case 0xEA: case 0xEB:
236237      case 0xEC: case 0xED: case 0xEE: case 0xEF:
237         applefdc_w(fdc, space, offset, data);
238         fdc->write(offset, data);
238239         break;
239240
240241      case 0xF0:
trunk/src/mess/machine/apple2gs.c
r19778r19779
10491049        case 0xe8: case 0xe9: case 0xea: case 0xeb: case 0xec: case 0xed: case 0xee: case 0xef:
10501050         if ((m_sltromsel & (1 << 6)) == 0)
10511051         {
1052                result = applefdc_r(m_fdc, space, offset);
1052                result = m_fdc->read(offset);
10531053            }
10541054            else
10551055            {
r19778r19779
12051205        case 0xe8: case 0xe9: case 0xea: case 0xeb: case 0xec: case 0xed: case 0xee: case 0xef:
12061206            if ((m_sltromsel & (1 << 6)) == 0)
12071207            {
1208                applefdc_w(m_fdc, space, offset, data);
1208                m_fdc->write(offset, data);
12091209            }
12101210            else
12111211            {
trunk/src/mess/machine/swim.c
r0r19779
1/*********************************************************************
2
3    swim.c
4
5    Implementation of the Apple SWIM FDC controller; used on (less)
6   early Macs
7
8*********************************************************************/
9
10#include "machine/swim.h"
11
12
13/***************************************************************************
14    CONSTANTS
15***************************************************************************/
16
17#define LOG_SWIM   0
18
19enum
20{
21   SWIM_MODE_IWM,
22   SWIM_MODE_SWIM,
23   SWIM_MODE_SWIM2,
24   SWIM_MODE_SWIM3
25};
26
27
28/***************************************************************************
29    DEVICE
30***************************************************************************/
31
32const device_type SWIM = &device_creator<swim_device>;
33
34//-------------------------------------------------
35//  ctor
36//-------------------------------------------------
37
38swim_device::swim_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
39   : applefdc_base_device(APPLEFDC_SWIM, mconfig, SWIM, "Apple SWIM (Steve Woz Integrated Machine)", tag, owner, clock)
40{
41}
42
43
44
45//-------------------------------------------------
46//  device_start - device-specific start
47//-------------------------------------------------
48
49void swim_device::device_start()
50{
51   // call inherited version
52   applefdc_base_device::device_start();
53
54   m_swim_mode         = SWIM_MODE_IWM;
55   m_swim_magic_state   = 0x00;
56   m_parm_offset      = 0x00;
57   memset(m_ism_regs, 0, sizeof(m_ism_regs));
58   memset(m_parms, 0, sizeof(m_parms));
59}
60
61
62
63//-------------------------------------------------
64//  device_reset - device-specific reset
65//-------------------------------------------------
66
67void swim_device::device_reset()
68{
69   // call inherited version
70   applefdc_base_device::device_reset();
71
72   static UINT8 swim_default_parms[16] =
73   {
74      0x38, 0x18, 0x41, 0x2e, 0x2e, 0x18, 0x18, 0x1b,
75      0x1b, 0x2f, 0x2f, 0x19, 0x19, 0x97, 0x1b, 0x57
76   };
77
78   for (int i = 0; i < 16; i++)
79   {
80      m_parms[i] = swim_default_parms[i];
81   }
82
83   m_swim_magic_state = 0;
84   m_swim_mode = SWIM_MODE_IWM;
85   m_parm_offset = 0;
86}
87
88
89
90//-------------------------------------------------
91//  read - reads a byte from the FDC
92//-------------------------------------------------
93
94UINT8 swim_device::read(UINT8 offset)
95{
96   UINT8 result = 0;
97
98   if (m_swim_mode == SWIM_MODE_IWM)
99   {
100      // IWM mode
101      result = applefdc_base_device::read(offset);
102   }
103   else if (m_swim_mode >= SWIM_MODE_SWIM)
104   {
105      // reading parameter RAM?
106      if ((offset & 7) == 3)
107      {
108         result = m_parms[m_parm_offset++];
109         m_parm_offset &= 0xf;
110      }
111      else
112      {
113         result = m_ism_regs[offset&7];
114      }
115
116      if (LOG_SWIM)
117         logerror("SWIM: read %02x from offset %x\n", result, offset & 7);
118   }
119   return result;
120}
121
122
123
124//-------------------------------------------------
125//  write - write a byte to the FDC
126//-------------------------------------------------
127
128void swim_device::write(UINT8 offset, UINT8 data)
129{
130   if (m_swim_mode == SWIM_MODE_IWM)
131   {
132      // IWM mode
133      applefdc_base_device::write(offset, data);
134   }
135   else if (m_swim_mode >= SWIM_MODE_SWIM)
136   {
137      if (LOG_SWIM)
138         logerror("SWIM: write %02x to offset %x\n", data, offset & 7);
139
140      switch (offset & 7)
141      {
142         case 2: // write CRC
143            break;
144
145         case 3: // write parameter
146            m_parms[m_parm_offset++] = data;
147            m_parm_offset &= 0xf;
148            break;
149
150         case 6: // write zeros to status (also zeroes parameter RAM pointer)
151            m_ism_regs[6] &= ~data;
152            m_parm_offset = 0;
153
154            if (data == 0xf8)   // magic "revert to IWM" value
155            {
156               if (LOG_SWIM)
157                  logerror("SWIM: reverting to IWM\n");
158               m_swim_mode = SWIM_MODE_IWM;
159            }
160            break;
161
162         case 7: // write ones to status
163            m_ism_regs[6] |= data;
164            break;
165
166         default:
167            m_ism_regs[offset & 7] = data;
168            break;
169
170      }
171   }
172}
173
174
175
176//-------------------------------------------------
177//  iwm_modereg_w - changes the mode register
178//-------------------------------------------------
179
180void swim_device::iwm_modereg_w(UINT8 data)
181{
182   // SWIM mode is unlocked by writing 1/0/1/1 in a row to bit 6 (which is unused on IWM)
183   // when SWIM mode engages, the IWM is disconnected from both the 68k and the drives,
184   // and the ISM is substituted.
185
186   switch (m_swim_magic_state)
187   {
188      case 0:
189      case 2:
190      case 3:
191         if (data & 0x40)
192         {
193            m_swim_magic_state++;
194         }
195         else
196         {
197            m_swim_magic_state = 0;
198         }
199         break;
200      case 1:
201         if (!(data & 0x40))
202         {
203            m_swim_magic_state++;
204         }
205         else
206         {
207            m_swim_magic_state = 0;
208         }
209         break;
210   }
211
212   if (m_swim_magic_state == 4)
213   {
214      m_swim_magic_state = 0;
215      m_swim_mode = SWIM_MODE_SWIM;
216   }
217
218   // call inherited version
219   applefdc_base_device::iwm_modereg_w(data);
220}
trunk/src/mess/machine/swim.h
r0r19779
1/*********************************************************************
2
3    swim.h
4
5    Implementation of the Apple SWIM FDC controller; used on (less)
6   early Macs
7
8*********************************************************************/
9
10#ifndef __SWIM_H__
11#define __SWIM_H__
12
13#include "machine/applefdc.h"
14
15
16/***************************************************************************
17    DEVICE
18***************************************************************************/
19
20extern const device_type SWIM;
21
22class swim_device : public applefdc_base_device
23{
24public:
25   swim_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
26
27   // read/write
28   virtual UINT8 read(UINT8 offset);
29   virtual void write(UINT8 offset, UINT8 data);
30
31protected:
32   // device-level overrides
33   virtual void device_start();
34   virtual void device_reset();
35
36   // other overrides
37   virtual void iwm_modereg_w(UINT8 data);
38
39private:
40   UINT8      m_swim_mode;
41   UINT8      m_swim_magic_state;
42   UINT8      m_parm_offset;
43   UINT8      m_ism_regs[8];
44   UINT8      m_parms[16];
45};
46
47
48
49/***************************************************************************
50    DEVICE CONFIGURATION MACROS
51***************************************************************************/
52
53#define MCFG_SWIM_ADD(_tag, _intrf) \
54   MCFG_DEVICE_ADD(_tag, SWIM, 0) \
55   MCFG_DEVICE_CONFIG(_intrf)
56
57#define MCFG_SWIM_MODIFY(_tag, _intrf) \
58  MCFG_DEVICE_MODIFY(_tag)         \
59  MCFG_DEVICE_CONFIG(_intrf)
60
61#endif // __SWIM_H__
trunk/src/mess/machine/oric.c
r19778r19779
417417static void oric_install_apple2_interface(running_machine &machine)
418418{
419419   oric_state *state = machine.driver_data<oric_state>();
420   device_t *fdc = machine.device("fdc");
420   applefdc_base_device *fdc = machine.device<applefdc_base_device>("fdc");
421421   address_space &space = machine.device("maincpu")->memory().space(AS_PROGRAM);
422422
423423   if (state->m_is_telestrat)
424424      return;
425425
426   space.install_read_handler(0x0300, 0x030f, read8_delegate(FUNC(oric_state::oric_IO_r),state));
427   space.install_legacy_read_handler(*fdc, 0x0310, 0x031f, FUNC(applefdc_r));
426   space.install_read_handler(0x0300, 0x030f, read8_delegate(FUNC(oric_state::oric_IO_r), state));
427   space.install_read_handler(0x0310, 0x031f, read8_delegate(FUNC(applefdc_base_device::read), fdc));
428428   space.install_read_bank(0x0320, 0x03ff, "bank4");
429429
430   space.install_write_handler(0x0300, 0x030f, write8_delegate(FUNC(oric_state::oric_IO_w),state));
431   space.install_legacy_write_handler(*fdc, 0x0310, 0x031f, FUNC(applefdc_w));
430   space.install_write_handler(0x0300, 0x030f, write8_delegate(FUNC(oric_state::oric_IO_w), state));
431   space.install_write_handler(0x0310, 0x031f, write8_delegate(FUNC(applefdc_base_device::write), fdc));
432432   state->membank("bank4")->set_base(   state->memregion("maincpu")->base() + 0x014000 + 0x020);
433433}
434434
r19778r19779
541541static void oric_install_apple2_v2_interface(running_machine &machine)
542542{
543543   oric_state *state = machine.driver_data<oric_state>();
544   device_t *fdc = machine.device("fdc");
544   applefdc_base_device *fdc = machine.device<applefdc_base_device>("fdc");
545545   address_space &space = machine.device("maincpu")->memory().space(AS_PROGRAM);
546546
547   space.install_read_handler(0x0300, 0x030f, read8_delegate(FUNC(oric_state::oric_IO_r),state));
548   space.install_legacy_read_handler(*fdc, 0x0310, 0x031f, FUNC(applefdc_r));
547   space.install_read_handler(0x0300, 0x030f, read8_delegate(FUNC(oric_state::oric_IO_r), state));
548   space.install_read_handler(0x0310, 0x031f, read8_delegate(FUNC(applefdc_base_device::read), fdc));
549549   space.install_read_bank(0x0320, 0x03ff, "bank4");
550550
551   space.install_write_handler(0x0300, 0x030f, write8_delegate(FUNC(oric_state::oric_IO_w),state));
552   space.install_legacy_write_handler(*fdc, 0x0310, 0x031f, FUNC(applefdc_w));
551   space.install_write_handler(0x0300, 0x030f, write8_delegate(FUNC(oric_state::oric_IO_w), state));
552   space.install_write_handler(0x0310, 0x031f, write8_delegate(FUNC(applefdc_base_device::write), fdc));
553553   space.install_write_handler(0x0380, 0x0383, write8_delegate(FUNC(oric_state::apple2_v2_interface_w),state));
554554
555555   state->apple2_v2_interface_w(space, 0, 0);
trunk/src/mess/machine/a2diskii.c
r19778r19779
138138
139139UINT8 a2bus_floppy_device::read_c0nx(address_space &space, UINT8 offset)
140140{
141   return applefdc_r(m_fdc, space, offset);
141   return m_fdc->read(offset);
142142}
143143
144144
r19778r19779
148148
149149void a2bus_floppy_device::write_c0nx(address_space &space, UINT8 offset, UINT8 data)
150150{
151    applefdc_w(m_fdc, space, offset, data);
151   m_fdc->write(offset, data);
152152}
153153
154154/*-------------------------------------------------
trunk/src/mess/machine/mac.c
r19778r19779
11401140     */
11411141
11421142   UINT16 result = 0;
1143   device_t *fdc = space.machine().device("fdc");
1143   applefdc_base_device *fdc = space.machine().device<applefdc_base_device>("fdc");
11441144
1145   result = applefdc_r(fdc, space, (offset >> 8));
1145   result = fdc->read(offset >> 8);
11461146
11471147   if (LOG_MAC_IWM)
11481148      printf("mac_iwm_r: offset=0x%08x mem_mask %04x = %02x (PC %x)\n", offset, mem_mask, result, m_maincpu->pc());
r19778r19779
11521152
11531153WRITE16_MEMBER ( mac_state::mac_iwm_w )
11541154{
1155   device_t *fdc = space.machine().device("fdc");
1155   applefdc_base_device *fdc = space.machine().device<applefdc_base_device>("fdc");
11561156
11571157   if (LOG_MAC_IWM)
11581158      printf("mac_iwm_w: offset=0x%08x data=0x%04x mask %04x (PC=%x)\n", offset, data, mem_mask, m_maincpu->pc());
11591159
11601160   if (ACCESSING_BITS_0_7)
1161      applefdc_w(fdc, space, (offset >> 8), data & 0xff);
1161      fdc->write((offset >> 8), data & 0xff);
11621162   else
1163      applefdc_w(fdc, space, (offset >> 8), data>>8);
1163      fdc->write((offset >> 8), data>>8);
11641164}
11651165
11661166READ8_MEMBER(mac_state::mac_adb_via_in_cb2)
trunk/src/mess/machine/applefdc.c
r19778r19779
3939
4040
4141/***************************************************************************
42    PARAMETERS
42    CONSTANTS
4343***************************************************************************/
4444
45/* logging */
45// logging
4646#define LOG_APPLEFDC      0
4747#define LOG_APPLEFDC_EXTRA   0
4848
49// mask for FDC lines
50#define IWM_MOTOR         0x10
51#define IWM_DRIVE         0x20
52#define IWM_Q6            0x40
53#define IWM_Q7            0x80
4954
55const device_timer_id TIMER_MOTOR_ONOFF = 1;
5056
51/***************************************************************************
52    CONSTANTS
53***************************************************************************/
5457
55/* mask for FDC lines */
56#define IWM_MOTOR   0x10
57#define IWM_DRIVE   0x20
58#define IWM_Q6      0x40
59#define IWM_Q7      0x80
6058
61enum applefdc_t
62{
63   APPLEFDC_APPLE2,   /* classic Apple II disk controller (pre-IWM) */
64   APPLEFDC_IWM,      /* Integrated Woz Machine */
65   APPLEFDC_SWIM      /* Sander/Woz Integrated Machine */
66};
6759
6860
69static UINT8 swim_default_parms[16] =
70{
71   0x38, 0x18, 0x41, 0x2e, 0x2e, 0x18, 0x18, 0x1b,
72   0x1b, 0x2f, 0x2f, 0x19, 0x19, 0x97, 0x1b, 0x57
73};
74
7561/***************************************************************************
7662    IWM MODE
7763
r19778r19779
10793   IWM_MODE_LATCHMODE         = 0x01
10894};
10995
110enum
111{
112   SWIM_MODE_IWM,
113   SWIM_MODE_SWIM,
114   SWIM_MODE_SWIM2,
115   SWIM_MODE_SWIM3
116};
11796
118/***************************************************************************
119    TYPE DEFINITIONS
120***************************************************************************/
12197
122struct applefdc_token
123{
124   /* data that is constant for the lifetime of the emulation */
125   emu_timer *motor_timer;
126   applefdc_t type;
127
128   /* data that changes at emulation time */
129   UINT8 write_byte;
130   UINT8 lines;               /* flags from IWM_MOTOR - IWM_Q7 */
131   UINT8 mode;                  /* 0-31; see above */
132   UINT8 handshake_hack;         /* not sure what this is for */
133
134   /* SWIM extentions */
135   UINT8 swim_mode;
136   UINT8 swim_magic_state;
137   UINT8 ism_regs[8];
138   UINT8 parm_offset;
139   UINT8 parms[16];
140};
141
142
143
14498/***************************************************************************
145    PROTOTYPES
99    BASE DEVICE
146100***************************************************************************/
147101
148static TIMER_CALLBACK(iwm_turnmotor_onoff);
102//-------------------------------------------------
103//  ctor
104//-------------------------------------------------
149105
150
151
152/***************************************************************************
153    INLINE FUNCTIONS
154***************************************************************************/
155
156INLINE void assert_is_applefdc(device_t *device)
106applefdc_base_device::applefdc_base_device(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)
107   : device_t(mconfig, type, name, tag, owner, clock)
157108{
158   assert(device != NULL);
159   assert((device->type() == APPLEFDC) || (device->type() == IWM) || (device->type() == SWIM));
109   m_type = fdc_type;
160110}
161111
162112
163113
164INLINE applefdc_token *get_token(device_t *device)
114//-------------------------------------------------
115//  device_start - device-specific startup
116//-------------------------------------------------
117
118void applefdc_base_device::device_start()
165119{
166   assert_is_applefdc(device);
167   return (applefdc_token *) downcast<applefdc_base_device *>(device)->token();
120   // timer
121   m_motor_timer = timer_alloc(TIMER_MOTOR_ONOFF);
122
123   // state
124   m_write_byte      = 0x00;
125   m_lines            = 0x00;   
126   m_mode            = 0x1F;   // default value needed by Lisa 2 - no, I don't know if it is true
127   m_handshake_hack   = 0x00;
128
129   // register save states
130   save_item(NAME(m_write_byte));
131   save_item(NAME(m_lines));
132   save_item(NAME(m_mode));
133   save_item(NAME(m_handshake_hack));
168134}
169135
170136
171137
172INLINE const applefdc_interface *get_interface(device_t *device)
173{
174   static const applefdc_interface dummy_interface = {0, };
138//-------------------------------------------------
139//  device_reset - device-specific reset
140//-------------------------------------------------
175141
176   assert_is_applefdc(device);
177   return (device->static_config() != NULL)
178      ? (const applefdc_interface *) device->static_config()
179      : &dummy_interface;
142void applefdc_base_device::device_reset(void)
143{
144   m_handshake_hack = 0x00;
145   m_write_byte = 0x00;
146   m_lines = 0x00;
147   m_mode = 0x1F;   /* default value needed by Lisa 2 - no, I don't know if it is true */
148   m_motor_timer->reset();
180149}
181150
182151
183152
184/***************************************************************************
185    CORE IMPLEMENTATION
186***************************************************************************/
153//-------------------------------------------------
154//  device_timer - device-specific timer callbacks
155//-------------------------------------------------
187156
188/*-------------------------------------------------
189    applefdc_start - starts up an FDC
190-------------------------------------------------*/
191
192static void applefdc_start(device_t *device, applefdc_t type)
157void applefdc_base_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
193158{
194   applefdc_token *fdc = get_token(device);
195
196   memset(fdc, 0, sizeof(*fdc));
197   fdc->type = type;
198   fdc->motor_timer = device->machine().scheduler().timer_alloc(FUNC(iwm_turnmotor_onoff), (void *) device);
199   fdc->lines = 0x00;
200   fdc->mode = 0x1F;   /* default value needed by Lisa 2 - no, I don't know if it is true */
201   fdc->swim_mode = SWIM_MODE_IWM;
202
203   /* register save states */
204   state_save_register_item(device->machine(), "applefdc", NULL, 0, fdc->write_byte);
205   state_save_register_item(device->machine(), "applefdc", NULL, 0, fdc->lines);
206   state_save_register_item(device->machine(), "applefdc", NULL, 0, fdc->mode);
207   state_save_register_item(device->machine(), "applefdc", NULL, 0, fdc->handshake_hack);
159   switch(id)
160   {
161      case TIMER_MOTOR_ONOFF:
162         turn_motor_onoff(param != 0);
163         break;
164   }
208165}
209166
210167
211168
212/*-------------------------------------------------
213    DEVICE_RESET(applefdc) - resets an FDC
214-------------------------------------------------*/
169//-------------------------------------------------
170//  get_interface - gets the interface
171//-------------------------------------------------
215172
216static DEVICE_RESET(applefdc)
173const applefdc_interface *applefdc_base_device::get_interface()
217174{
218   applefdc_token *fdc = get_token(device);
175   static const applefdc_interface dummy_interface = {0, };
219176
220   fdc->handshake_hack = 0x00;
221   fdc->write_byte = 0x00;
222   fdc->lines = 0x00;
223   fdc->mode = 0x1F;   /* default value needed by Lisa 2 - no, I don't know if it is true */
224   fdc->swim_magic_state = 0;
225   fdc->swim_mode = SWIM_MODE_IWM;
226   fdc->parm_offset = 0;
227
228   // setup SWIM default parms if it's a SWIM
229   if (fdc->type == APPLEFDC_SWIM)
230   {
231      for (int i = 0; i < 16; i++)
232      {
233         fdc->parms[i] = swim_default_parms[i];
234      }
235   }
236
237   fdc->motor_timer->reset();
177   return (static_config() != NULL)
178      ? (const applefdc_interface *) static_config()
179      : &dummy_interface;
238180}
239181
240182
241183
242/*-------------------------------------------------
243    iwm_enable2 - hackish function
244-------------------------------------------------*/
184//-------------------------------------------------
185//  iwm_enable2 - hackish function
186//-------------------------------------------------
245187
246static int iwm_enable2(device_t *device)
188int applefdc_base_device::iwm_enable2()
247189{
248   applefdc_token *fdc = get_token(device);
249
250190   /* R. Nabet : This function looks more like a hack than a real feature of the IWM; */
251191   /* it is not called from the Mac Plus driver */
252   return (fdc->lines & APPLEFDC_PH1) && (fdc->lines & APPLEFDC_PH3);
192   return (m_lines & APPLEFDC_PH1) && (m_lines & APPLEFDC_PH3);
253193}
254194
255195
256196
257/*-------------------------------------------------
258    iwm_readenable2handshake - hackish function
259-------------------------------------------------*/
197//-------------------------------------------------
198//  iwm_readenable2handshake - hackish function
199//-------------------------------------------------
260200
261static UINT8 iwm_readenable2handshake(device_t *device)
201UINT8 applefdc_base_device::iwm_readenable2handshake()
262202{
263   applefdc_token *fdc = get_token(device);
264
265203   /* R. Nabet : This function looks more like a hack than a real feature of the IWM; */
266204   /* it is not called from the Mac Plus driver */
267   fdc->handshake_hack++;
268   fdc->handshake_hack %= 4;
269   return (fdc->handshake_hack != 0) ? 0xc0 : 0x80;
205   m_handshake_hack++;
206   m_handshake_hack %= 4;
207   return (m_handshake_hack != 0) ? 0xc0 : 0x80;
270208}
271209
272210
273211
274/*-------------------------------------------------
275    applefdc_statusreg_r - reads the status register
276-------------------------------------------------*/
212//-------------------------------------------------
213//  statusreg_r - reads the status register
214//-------------------------------------------------
277215
278static UINT8 applefdc_statusreg_r(device_t *device)
216UINT8 applefdc_base_device::statusreg_r()
279217{
280218   UINT8 result;
281219   int status;
282   applefdc_token *fdc = get_token(device);
283   const applefdc_interface *intf = get_interface(device);
220   const applefdc_interface *intf = get_interface();
284221
285222   /* IWM status:
286223     *
r19778r19779
290227     * Bits 4-0 Same as IWM mode bits 4-0
291228     */
292229
293   status = iwm_enable2(device) ? 1 : (intf->read_status ? intf->read_status(device) : 0);
230   status = iwm_enable2() ? 1 : (intf->read_status ? intf->read_status(this) : 0);
294231
295232   result = (status ? 0x80 : 0x00);
296233
297   if (fdc->type != APPLEFDC_APPLE2)
298       result |= (((fdc->lines & IWM_MOTOR) ? 1 : 0) << 5) | fdc->mode;
234   if (m_type != APPLEFDC_APPLE2)
235       result |= (((m_lines & IWM_MOTOR) ? 1 : 0) << 5) | m_mode;
299236   return result;
300237}
301238
302239
303240
304/*-------------------------------------------------
305    iwm_modereg_w - changes the mode register
306-------------------------------------------------*/
241//-------------------------------------------------
242//  iwm_modereg_w - changes the mode register
243//-------------------------------------------------
307244
308static void iwm_modereg_w(device_t *device, UINT8 data)
245void applefdc_base_device::iwm_modereg_w(UINT8 data)
309246{
310   applefdc_token *fdc = get_token(device);
247   m_mode = data & 0x1f;   /* write mode register */
311248
312   fdc->mode = data & 0x1f;   /* write mode register */
313
314   // SWIM mode is unlocked by writing 1/0/1/1 in a row to bit 6 (which is unused on IWM)
315   // when SWIM mode engages, the IWM is disconnected from both the 68k and the drives,
316   // and the ISM is substituted.
317   if (fdc->type == APPLEFDC_SWIM)
318   {
319      switch (fdc->swim_magic_state)
320      {
321         case 0:
322         case 2:
323         case 3:
324            if (data & 0x40)
325            {
326               fdc->swim_magic_state++;
327            }
328            else
329            {
330               fdc->swim_magic_state = 0;
331            }
332            break;
333         case 1:
334            if (!(data & 0x40))
335            {
336               fdc->swim_magic_state++;
337            }
338            else
339            {
340               fdc->swim_magic_state = 0;
341            }
342            break;
343      }
344
345      if (fdc->swim_magic_state == 4)
346      {
347         fdc->swim_magic_state = 0;
348//          printf("IWM: switching to SWIM mode\n");
349         fdc->swim_mode = SWIM_MODE_SWIM;
350      }
351   }
352
353249   if (LOG_APPLEFDC_EXTRA)
354      logerror("iwm_modereg_w: iwm_mode=0x%02x\n", (unsigned) fdc->mode);
250      logerror("iwm_modereg_w: iwm_mode=0x%02x\n", (unsigned) m_mode);
355251}
356252
357253
358254
359/*-------------------------------------------------
360    applefdc_read_reg - reads a register
361-------------------------------------------------*/
255//-------------------------------------------------
256//  read_reg - reads a register
257//-------------------------------------------------
362258
363static UINT8 applefdc_read_reg(device_t *device, int lines)
259UINT8 applefdc_base_device::read_reg(int lines)
364260{
365   applefdc_token *fdc = get_token(device);
366   const applefdc_interface *intf = get_interface(device);
261   const applefdc_interface *intf = get_interface();
367262   UINT8 result = 0;
368263
369264   switch(lines)
370265   {
371266      case 0:
372         /* Read data register */
373         if ((fdc->type != APPLEFDC_APPLE2) && (iwm_enable2(device) || !(fdc->lines & IWM_MOTOR)))
267         // read data register
268         if ((m_type != APPLEFDC_APPLE2) && (iwm_enable2() || !(m_lines & IWM_MOTOR)))
374269         {
375270            result = 0xFF;
376271         }
377272         else
378273         {
379            /*
380                         * Right now, this function assumes latch mode; which is always used for
381                         * 3.5 inch drives.  Eventually we should check to see if latch mode is
382                         * off
383                         */
274            // Right now, this function assumes latch mode; which is always used for
275            // 3.5 inch drives.  Eventually we should check to see if latch mode is
276            // off
384277            if (LOG_APPLEFDC)
385278            {
386               if ((fdc->mode & IWM_MODE_LATCHMODE) == 0x00)
279               if ((m_mode & IWM_MODE_LATCHMODE) == 0x00)
387280                  logerror("applefdc_read_reg(): latch mode off not implemented\n");
388281            }
389282
390            result = (intf->read_data ? intf->read_data(device) : 0x00);
283            result = (intf->read_data ? intf->read_data(this) : 0x00);
391284         }
392285         break;
393286
394287      case IWM_Q6:
395         /* Read status register */
396         result = applefdc_statusreg_r(device);
288         // read status register
289         result = statusreg_r();
397290         break;
398291
399292      case IWM_Q7:
400         /* Classic Apple II: Read status register
401             * IWM: Read handshake register
402             */
403         if (fdc->type == APPLEFDC_APPLE2)
404            result = applefdc_statusreg_r(device);
293         // Classic Apple II: Read status register
294            // IWM: Read handshake register
295         if (m_type == APPLEFDC_APPLE2)
296            result = statusreg_r();
405297         else
406            result = iwm_enable2(device) ? iwm_readenable2handshake(device) : 0x80;
298            result = iwm_enable2() ? iwm_readenable2handshake() : 0x80;
407299         break;
408300   }
409301   return result;
r19778r19779
411303
412304
413305
414/*-------------------------------------------------
415    applefdc_write_reg - writes a register
416-------------------------------------------------*/
306//-------------------------------------------------
307//  write_reg - writes a register
308//-------------------------------------------------
417309
418static void applefdc_write_reg(device_t *device, UINT8 data)
310void applefdc_base_device::write_reg(UINT8 data)
419311{
420   applefdc_token *fdc = get_token(device);
421   const applefdc_interface *intf = get_interface(device);
312   const applefdc_interface *intf = get_interface();
422313
423   switch(fdc->lines & (IWM_Q6 | IWM_Q7))
314   switch(m_lines & (IWM_Q6 | IWM_Q7))
424315   {
425316      case IWM_Q6 | IWM_Q7:
426         if (!(fdc->lines & IWM_MOTOR))
317         if (!(m_lines & IWM_MOTOR))
427318         {
428            iwm_modereg_w(device, data);
319            iwm_modereg_w(data);
429320         }
430         else if (!iwm_enable2(device))
321         else if (!iwm_enable2())
431322         {
432            /*
433                         * Right now, this function assumes latch mode; which is always used for
434                         * 3.5 inch drives.  Eventually we should check to see if latch mode is
435                         * off
436                         */
323            // Right now, this function assumes latch mode; which is always used for
324            // 3.5 inch drives.  Eventually we should check to see if latch mode is
325            // off
437326            if (LOG_APPLEFDC)
438327            {
439               if ((fdc->mode & IWM_MODE_LATCHMODE) == 0)
328               if ((m_mode & IWM_MODE_LATCHMODE) == 0)
440329                  logerror("applefdc_write_reg(): latch mode off not implemented\n");
441330            }
442331
443332            if (intf->write_data != NULL)
444               intf->write_data(device,data);
333               intf->write_data(this, data);
445334         }
446335         break;
447336   }
r19778r19779
449338
450339
451340
452/*-------------------------------------------------
453    TIMER_CALLBACK(iwm_turnmotor_onoff) - timer
454    callback for turning motor on or off
455-------------------------------------------------*/
341//-------------------------------------------------
342//  turn_motor_onoff - timer callback for turning
343//   motor on or off
344//-------------------------------------------------
456345
457static TIMER_CALLBACK(iwm_turnmotor_onoff)
346void applefdc_base_device::turn_motor_onoff(bool status)
458347{
459   device_t *device = (device_t *) ptr;
460   applefdc_token *fdc = get_token(device);
461   const applefdc_interface *intf = get_interface(device);
462   int status = param;
348   const applefdc_interface *intf = get_interface();
463349   int enable_lines;
464350
465   if (status != 0)
351   if (status)
466352   {
467      fdc->lines |= IWM_MOTOR;
468      enable_lines = (fdc->lines & IWM_DRIVE) ? 2 : 1;
353      m_lines |= IWM_MOTOR;
354      enable_lines = (m_lines & IWM_DRIVE) ? 2 : 1;
469355   }
470356   else
471357   {
472      fdc->lines &= ~IWM_MOTOR;
358      m_lines &= ~IWM_MOTOR;
473359
474      if (fdc->type == APPLEFDC_APPLE2)
475         enable_lines = (fdc->lines & IWM_DRIVE) ? 2 : 1;
360      if (m_type == APPLEFDC_APPLE2)
361         enable_lines = (m_lines & IWM_DRIVE) ? 2 : 1;
476362      else
477363         enable_lines = 0;
478364   }
479365
480366   /* invoke callback, if present */
481367   if (intf->set_enable_lines != NULL)
482      intf->set_enable_lines(device,enable_lines);
368      intf->set_enable_lines(this, enable_lines);
483369
484370   if (LOG_APPLEFDC_EXTRA)
485371      logerror("iwm_turnmotor_onoff(): Turning motor %s\n", status ? "on" : "off");
r19778r19779
487373
488374
489375
490/*-------------------------------------------------
491    iwm_access
492-------------------------------------------------*/
376//-------------------------------------------------
377//  iwm_access
378//-------------------------------------------------
493379
494static void iwm_access(device_t *device, int offset)
380void applefdc_base_device::iwm_access(int offset)
495381{
496382   static const char *const lines[] =
497383   {
r19778r19779
505391      "Q7"
506392   };
507393
508   applefdc_token *fdc = get_token(device);
509   const applefdc_interface *intf = get_interface(device);
394   const applefdc_interface *intf = get_interface();
510395
511396   if (offset & 1)
512      fdc->lines |= (1 << (offset >> 1));
397      m_lines |= (1 << (offset >> 1));
513398   else
514      fdc->lines &= ~(1 << (offset >> 1));
399      m_lines &= ~(1 << (offset >> 1));
515400
516401   if (LOG_APPLEFDC_EXTRA)
517402   {
518403      logerror("iwm_access(): %s line %s => %02x\n",
519         (offset & 1) ? "setting" : "clearing", lines[offset >> 1], fdc->lines);
404         (offset & 1) ? "setting" : "clearing", lines[offset >> 1], m_lines);
520405   }
521406
522407   if ((offset < 0x08) && (intf->set_lines != NULL))
523      intf->set_lines(device,fdc->lines & 0x0f);
408      intf->set_lines(this, m_lines & 0x0f);
524409
525410   switch(offset)
526411   {
527412      case 0x08:
528413         /* turn off motor */
529         fdc->motor_timer->adjust(
530            (fdc->mode & IWM_MODE_MOTOROFFDELAY) ? attotime::zero : attotime::from_seconds(1), 0);
414         m_motor_timer->adjust(
415            (m_mode & IWM_MODE_MOTOROFFDELAY) ? attotime::zero : attotime::from_seconds(1), 0);
531416         break;
532417
533418      case 0x09:
534419         /* turn on motor */
535         fdc->motor_timer->adjust(attotime::zero, 1);
420         m_motor_timer->adjust(attotime::zero, 1);
536421         break;
537422
538423      case 0x0A:
539424         /* turn off IWM_DRIVE */
540         if ((fdc->lines & IWM_MOTOR) && (intf->set_enable_lines != NULL))
541            intf->set_enable_lines(device,1);
425         if ((m_lines & IWM_MOTOR) && (intf->set_enable_lines != NULL))
426            intf->set_enable_lines(this, 1);
542427         break;
543428
544429      case 0x0B:
545430         /* turn on IWM_DRIVE */
546         if ((fdc->lines & IWM_MOTOR) && (intf->set_enable_lines != NULL))
547            intf->set_enable_lines(device,2);
431         if ((m_lines & IWM_MOTOR) && (intf->set_enable_lines != NULL))
432            intf->set_enable_lines(this, 2);
548433         break;
549434   }
550435}
551436
552437
553438
554/*-------------------------------------------------
555    applefdc_r - reads a byte from the FDC
556-------------------------------------------------*/
439//-------------------------------------------------
440//  read - reads a byte from the FDC
441//-------------------------------------------------
557442
558READ8_DEVICE_HANDLER( applefdc_r )
443UINT8 applefdc_base_device::read(UINT8 offset)
559444{
560   applefdc_token *fdc = get_token(device);
561   const applefdc_interface *intf = get_interface(device);
445   const applefdc_interface *intf = get_interface();
562446   UINT8 result = 0;
563447
564   /* normalize offset */
448   // normalize offset
565449   offset &= 0xf;
566450
567451   if (LOG_APPLEFDC_EXTRA)
568452      logerror("applefdc_r: offset=%i\n", offset);
569453
570   if ((fdc->type < APPLEFDC_SWIM) || (fdc->swim_mode == SWIM_MODE_IWM))
454   iwm_access(offset);
455
456   switch(m_type)
571457   {
572      iwm_access(device, offset);
458      case APPLEFDC_APPLE2:
459         switch(offset)
460         {
461            case 0x0C:
462               if (m_lines & IWM_Q7)
463               {
464                  if (intf->write_data != NULL)
465                     intf->write_data(this, m_write_byte);
466                  result = 0;
467               }
468               else
469                  result = read_reg(0);
470               break;
573471
574      switch(fdc->type)
575      {
576         case APPLEFDC_APPLE2:
577            switch(offset)
578            {
579               case 0x0C:
580                  if (fdc->lines & IWM_Q7)
581                  {
582                     if (intf->write_data != NULL)
583                        intf->write_data(device,fdc->write_byte);
584                     result = 0;
585                  }
586                  else
587                     result = applefdc_read_reg(device, 0);
472            case 0x0D:
473               result = read_reg(IWM_Q6);
474               break;
588475
589                  break;
590               case 0x0D:
591                  result = applefdc_read_reg(device, IWM_Q6);
592                  break;
593               case 0x0E:
594                  result = applefdc_read_reg(device, IWM_Q7);
595                  break;
596               case 0x0F:
597                  result = applefdc_read_reg(device, IWM_Q7 | IWM_Q6);
598                  break;
599            }
600            break;
476            case 0x0E:
477               result = read_reg(IWM_Q7);
478               break;
601479
602         case APPLEFDC_IWM:
603            if ((offset & 1) == 0)
604               result = applefdc_read_reg(device, fdc->lines & (IWM_Q6 | IWM_Q7));
605            break;
480            case 0x0F:
481               result = read_reg(IWM_Q7 | IWM_Q6);
482               break;
483         }
484         break;
606485
607         case APPLEFDC_SWIM:
608            if ((offset & 1) == 0)
609               result = applefdc_read_reg(device, fdc->lines & (IWM_Q6 | IWM_Q7));
610            break;
611      }
486      case APPLEFDC_IWM:
487         if ((offset & 1) == 0)
488            result = read_reg(m_lines & (IWM_Q6 | IWM_Q7));
489         break;
490
491      case APPLEFDC_SWIM:
492         if ((offset & 1) == 0)
493            result = read_reg(m_lines & (IWM_Q6 | IWM_Q7));
494         break;
612495   }
613   else if (fdc->swim_mode >= SWIM_MODE_SWIM)
614   {
615      // reading parameter RAM?
616      if ((offset & 7) == 3)
617      {
618         result = fdc->parms[fdc->parm_offset++];
619         fdc->parm_offset &= 0xf;
620      }
621      else
622      {
623         result = fdc->ism_regs[offset&7];
624      }
625      printf("SWIM: read %02x from offset %x\n", result, offset & 7);
626   }
627496
628497   return result;
629498}
630499
631500
632501
633/*-------------------------------------------------
634    applefdc_w - writes a byte to the FDC
635-------------------------------------------------*/
502//-------------------------------------------------
503//  write - writes a byte to the FDC
504//-------------------------------------------------
636505
637WRITE8_DEVICE_HANDLER( applefdc_w )
506void applefdc_base_device::write(UINT8 offset, UINT8 data)
638507{
639   applefdc_token *fdc = get_token(device);
640   const applefdc_interface *intf = get_interface(device);
508   const applefdc_interface *intf = get_interface();
641509
642510   /* normalize offset */
643511   offset &= 15;
r19778r19779
645513   if (LOG_APPLEFDC_EXTRA)
646514      logerror("applefdc_w: offset=%i data=0x%02x\n", offset, data);
647515
648   if ((fdc->type < APPLEFDC_SWIM) || (fdc->swim_mode == SWIM_MODE_IWM))
649   {
650      iwm_access(device, offset);
516   iwm_access(offset);
651517
652      switch(fdc->type)
653      {
654         case APPLEFDC_APPLE2:
655            switch(offset)
656            {
657               case 0x0C:
658                  if (fdc->lines & IWM_Q7)
659                  {
660                     if (intf->write_data != NULL)
661                        intf->write_data(device,fdc->write_byte);
662                  }
663                  break;
664
665               case 0x0D:
666                  fdc->write_byte = data;
667                  break;
668            }
669            break;
670
671         case APPLEFDC_IWM:
672            if (offset & 1)
673               applefdc_write_reg(device, data);
674            break;
675
676         case APPLEFDC_SWIM:
677            if (offset & 1)
678               applefdc_write_reg(device, data);
679            break;
680      }
681   }
682   else if (fdc->swim_mode >= SWIM_MODE_SWIM)
518   switch(m_type)
683519   {
684      printf("SWIM: write %02x to offset %x\n", data, offset & 7);
685      switch (offset & 7)
686      {
687         case 2: // write CRC
688            break;
520      case APPLEFDC_APPLE2:
521         switch(offset)
522         {
523            case 0x0C:
524               if (m_lines & IWM_Q7)
525               {
526                  if (intf->write_data != NULL)
527                     intf->write_data(this, m_write_byte);
528               }
529               break;
689530
690         case 3: // write parameter
691            fdc->parms[fdc->parm_offset++] = data;
692            fdc->parm_offset &= 0xf;
693            break;
531            case 0x0D:
532               m_write_byte = data;
533               break;
534         }
535         break;
694536
695         case 6: // write zeros to status (also zeroes parameter RAM pointer)
696            fdc->ism_regs[6] &= ~data;
697            fdc->parm_offset = 0;
537      case APPLEFDC_IWM:
538         if (offset & 1)
539            write_reg(data);
540         break;
698541
699            if (data == 0xf8)   // magic "revert to IWM" value
700            {
701               printf("SWIM: reverting to IWM\n");
702               fdc->swim_mode = SWIM_MODE_IWM;
703            }
704            break;
705
706         case 7: // write ones to status
707            fdc->ism_regs[6] |= data;
708            break;
709
710         default:
711            fdc->ism_regs[offset & 7] = data;
712            break;
713
714      }
542      case APPLEFDC_SWIM:
543         if (offset & 1)
544            write_reg(data);
545         break;
715546   }
716547}
717548
718549
719550
720/*-------------------------------------------------
721    applefdc_w - writes a byte to the FDC
722-------------------------------------------------*/
551//-------------------------------------------------
552//  get_lines - accessor
553//-------------------------------------------------
723554
724UINT8 applefdc_get_lines(device_t *device)
555UINT8 applefdc_base_device::get_lines()
725556{
726   applefdc_token *fdc = get_token(device);
727   return fdc->lines & 0x0f;
557   return m_lines & 0x0f;
728558}
729559
730560
731561
732562/***************************************************************************
733    INTERFACE
563    APPLE FDC - Used on Apple II
734564***************************************************************************/
735565
736/*-------------------------------------------------
737    DEVICE_START(oldfdc) - device start
738    callback
739-------------------------------------------------*/
740
741static DEVICE_START(oldfdc)
742{
743   applefdc_start(device, APPLEFDC_APPLE2);
744}
745
746
747
748/*-------------------------------------------------
749    DEVICE_START(iwm) - device start
750    callback
751-------------------------------------------------*/
752
753static DEVICE_START(iwm)
754{
755   applefdc_start(device, APPLEFDC_IWM);
756}
757
758
759/*-------------------------------------------------
760    DEVICE_START(iwm) - device start
761    callback
762-------------------------------------------------*/
763
764static DEVICE_START(swim)
765{
766   applefdc_start(device, APPLEFDC_SWIM);
767}
768
769
770applefdc_base_device::applefdc_base_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock)
771   : device_t(mconfig, type, name, tag, owner, clock)
772{
773   m_token = global_alloc_clear(applefdc_token);
774}
775
776//-------------------------------------------------
777//  device_config_complete - perform any
778//  operations now that the configuration is
779//  complete
780//-------------------------------------------------
781
782void applefdc_base_device::device_config_complete()
783{
784}
785
786//-------------------------------------------------
787//  device_reset - device-specific reset
788//-------------------------------------------------
789
790void applefdc_base_device::device_reset()
791{
792   DEVICE_RESET_NAME( applefdc )(this);
793}
794
795
796566const device_type APPLEFDC = &device_creator<applefdc_device>;
797567
798568applefdc_device::applefdc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
799   : applefdc_base_device(mconfig, APPLEFDC, "Apple FDC", tag, owner, clock)
569   : applefdc_base_device(APPLEFDC_APPLE2, mconfig, APPLEFDC, "Apple FDC", tag, owner, clock)
800570{
801571}
802572
803//-------------------------------------------------
804//  device_start - device-specific startup
805//-------------------------------------------------
806573
807void applefdc_device::device_start()
808{
809   DEVICE_START_NAME( oldfdc )(this);
810}
811574
575/***************************************************************************
576    IWM - Used on early Macs
577***************************************************************************/
812578
813579const device_type IWM = &device_creator<iwm_device>;
814580
815581iwm_device::iwm_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
816   : applefdc_base_device(mconfig, IWM, "Apple IWM (Integrated Woz Machine)", tag, owner, clock)
582   : applefdc_base_device(APPLEFDC_IWM, mconfig, IWM, "Apple IWM (Integrated Woz Machine)", tag, owner, clock)
817583{
818584}
819
820//-------------------------------------------------
821//  device_start - device-specific startup
822//-------------------------------------------------
823
824void iwm_device::device_start()
825{
826   DEVICE_START_NAME( iwm )(this);
827}
828
829
830const device_type SWIM = &device_creator<swim_device>;
831
832swim_device::swim_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
833   : applefdc_base_device(mconfig, SWIM, "Apple SWIM (Steve Woz Integrated Machine)", tag, owner, clock)
834{
835}
836
837//-------------------------------------------------
838//  device_start - device-specific startup
839//-------------------------------------------------
840
841void swim_device::device_start()
842{
843   DEVICE_START_NAME( swim )(this);
844}
845
846
trunk/src/mess/machine/applefdc.h
r19778r19779
2828#define APPLEFDC_PH2   0x04
2929#define APPLEFDC_PH3   0x08
3030
31class applefdc_base_device : public device_t
31extern const device_type APPLEFDC;
32extern const device_type IWM;
33extern const device_type SWIM;
34
35
36
37/***************************************************************************
38    INTERFACE
39***************************************************************************/
40
41struct applefdc_interface
3242{
33public:
34   applefdc_base_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock);
35   ~applefdc_base_device() { global_free(m_token); }
43   void (*set_lines)(device_t *device, UINT8 lines);
44   void (*set_enable_lines)(device_t *device, int enable_mask);
3645
37   // access to legacy token
38   void *token() const { assert(m_token != NULL); return m_token; }
39protected:
40   // device-level overrides
41   virtual void device_config_complete();
42   virtual void device_start() { }
43   virtual void device_reset();
44private:
45   // internal state
46   void *m_token;
46   UINT8 (*read_data)(device_t *device);
47   void (*write_data)(device_t *device, UINT8 data);
48   int (*read_status)(device_t *device);
4749};
4850
49class applefdc_device : public applefdc_base_device
51
52
53/***************************************************************************
54    BASE DEVICE
55***************************************************************************/
56
57class applefdc_base_device : public device_t
5058{
5159public:
52   applefdc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
53protected:
54   // device-level overrides
55   virtual void device_start();
56};
60   // read/write handlers
61   virtual UINT8 read(UINT8 offset);
62   virtual void write(UINT8 offset, UINT8 data);
5763
58extern const device_type APPLEFDC;
64   // read/write handlers overloads
65   UINT8 read(offs_t offset)            { return read((UINT8) offset); }
66   void write(offs_t offset, UINT8 data)   { write((UINT8) offset, data); }
67   DECLARE_READ8_MEMBER( read )         { return read((UINT8) offset); }
68   DECLARE_WRITE8_MEMBER( write )         { write((UINT8) offset, data); }
5969
60class iwm_device : public applefdc_base_device
61{
62public:
63   iwm_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
70   // accessor
71   UINT8 get_lines();
72
6473protected:
65   // device-level overrides
66   virtual void device_start();
67};
74   enum applefdc_t
75   {
76      APPLEFDC_APPLE2,   /* classic Apple II disk controller (pre-IWM) */
77      APPLEFDC_IWM,      /* Integrated Woz Machine */
78      APPLEFDC_SWIM      /* Sander/Woz Integrated Machine */
79   };
6880
69extern const device_type IWM;
81   // constructor
82   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);
7083
71class swim_device : public applefdc_base_device
72{
73public:
74   swim_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
75protected:
7684   // device-level overrides
7785   virtual void device_start();
78};
86   virtual void device_reset();
87   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
7988
80extern const device_type SWIM;
89   // other protecteds
90   virtual void iwm_modereg_w(UINT8 data);
8191
92private:
93   // data that is constant for the lifetime of the emulation
94   emu_timer *   m_motor_timer;
95   applefdc_t   m_type;
8296
97   // data that changes at emulation time
98   UINT8      m_write_byte;
99   UINT8      m_lines;               /* flags from IWM_MOTOR - IWM_Q7 */
100   UINT8      m_mode;                  /* 0-31; see above */
101   UINT8      m_handshake_hack;         /* not sure what this is for */
83102
103   // functions
104   const applefdc_interface *get_interface();
105   int iwm_enable2();
106   UINT8 iwm_readenable2handshake();
107   UINT8 statusreg_r();
108   UINT8 read_reg(int lines);
109   void write_reg(UINT8 data);
110   void turn_motor_onoff(bool status);
111   void iwm_access(int offset);
112};
84113
114
115
85116/***************************************************************************
86    TYPE DEFINITIONS
117    APPLE FDC - Used on Apple II
87118***************************************************************************/
88119
89struct applefdc_interface
120class applefdc_device : public applefdc_base_device
90121{
91   void (*set_lines)(device_t *device, UINT8 lines);
92   void (*set_enable_lines)(device_t *device, int enable_mask);
93
94   UINT8 (*read_data)(device_t *device);
95   void (*write_data)(device_t *device, UINT8 data);
96   int (*read_status)(device_t *device);
122public:
123   applefdc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
97124};
98125
99126
100127
101128/***************************************************************************
102    PROTOTYPES
129    IWM - Used on early Macs
103130***************************************************************************/
104/* read/write handlers */
105DECLARE_READ8_DEVICE_HANDLER(applefdc_r);
106DECLARE_WRITE8_DEVICE_HANDLER(applefdc_w);
107131
108/* accessor */
109UINT8 applefdc_get_lines(device_t *device);
132class iwm_device : public applefdc_base_device
133{
134public:
135   iwm_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
136};
110137
138
139
111140/***************************************************************************
112141    DEVICE CONFIGURATION MACROS
113142***************************************************************************/
r19778r19779
128157  MCFG_DEVICE_MODIFY(_tag)         \
129158  MCFG_DEVICE_CONFIG(_intrf)
130159
131#define MCFG_SWIM_ADD(_tag, _intrf) \
132   MCFG_DEVICE_ADD(_tag, SWIM, 0) \
133   MCFG_DEVICE_CONFIG(_intrf)
134160
135#define MCFG_SWIM_MODIFY(_tag, _intrf) \
136  MCFG_DEVICE_MODIFY(_tag)         \
137  MCFG_DEVICE_CONFIG(_intrf)
138
139
140161#endif /* __APPLEFDC_H__ */
trunk/src/mess/machine/lisa.c
r19778r19779
11961196         state->m_MT1 = offset & 1;
11971197         if (state->m_MT1 && ! oldMT1)
11981198         {
1199            device_t *fdc = machine.device("fdc");
1199            applefdc_base_device *fdc = machine.device<applefdc_base_device>("fdc");
12001200
12011201            state->m_PWM_floppy_motor_speed = (state->m_PWM_floppy_motor_speed << 1) & 0xff;
1202            if (applefdc_get_lines(fdc) & APPLEFDC_PH0)
1202            if (fdc->get_lines() & APPLEFDC_PH0)
12031203               state->m_PWM_floppy_motor_speed |= 1;
12041204            sony_set_speed(((256-state->m_PWM_floppy_motor_speed) * 1.3) + 237);
12051205         }
r19778r19779
12331233READ8_MEMBER(lisa_state::lisa_fdc_io_r)
12341234{
12351235   int answer=0;
1236   device_t *fdc = machine().device("fdc");
1236   applefdc_base_device *fdc = machine().device<applefdc_base_device>("fdc");
12371237
12381238   switch ((offset & 0x0030) >> 4)
12391239   {
12401240   case 0:   /* IWM */
1241      answer = applefdc_r(fdc, space, offset);
1241      answer = fdc->read(offset);
12421242      break;
12431243
12441244   case 1:   /* TTL glue */
r19778r19779
12601260
12611261WRITE8_MEMBER(lisa_state::lisa_fdc_io_w)
12621262{
1263   device_t *fdc = machine().device("fdc");
1263   applefdc_base_device *fdc = machine().device<applefdc_base_device>("fdc");
12641264
12651265   switch ((offset & 0x0030) >> 4)
12661266   {
12671267   case 0:   /* IWM */
1268      applefdc_w(fdc, space, offset, data);
1268      fdc->write(offset, data);
12691269      break;
12701270
12711271   case 1:   /* TTL glue */
trunk/src/mess/drivers/mac.c
r19778r19779
5050#include "machine/6522via.h"
5151#include "machine/ncr5380.h"
5252#include "machine/applefdc.h"
53#include "machine/swim.h"
5354#include "devices/sonydriv.h"
5455#include "formats/ap_dsk35.h"
5556#include "machine/ram.h"
trunk/src/mess/mess.mak
r19778r19779
710710   $(MESS_MACHINE)/egret.o     \
711711   $(MESS_MACHINE)/cuda.o      \
712712   $(MESS_MACHINE)/mackbd.o    \
713   $(MESS_MACHINE)/swim.o      \
713714   $(MESS_VIDEO)/nubus_48gc.o   \
714715   $(MESS_VIDEO)/nubus_cb264.o \
715716   $(MESS_VIDEO)/nubus_vikbw.o \

Previous 199869 Revisions Next


© 1997-2024 The MAME Team