Previous 199869 Revisions Next

r26915 Friday 3rd January, 2014 at 16:19:16 UTC by Osso
Modernized mos6530 device.(nw)
[src/emu/bus/ieee488]c2040.c
[src/emu/machine]mos6530.c mos6530.h
[src/mess/drivers]kim1.c mk2.c

trunk/src/emu/bus/ieee488/c2040.c
r26914r26915
297297   ADDRESS_MAP_GLOBAL_MASK(0x1fff)
298298   AM_RANGE(0x0000, 0x003f) AM_MIRROR(0x0300) AM_RAM // 6530
299299   AM_RANGE(0x0040, 0x004f) AM_MIRROR(0x0330) AM_DEVREADWRITE(M6522_TAG, via6522_device, read, write)
300   AM_RANGE(0x0080, 0x008f) AM_MIRROR(0x0330) AM_DEVREADWRITE_LEGACY(M6530_TAG, mos6530_r, mos6530_w)
300   AM_RANGE(0x0080, 0x008f) AM_MIRROR(0x0330) AM_DEVREADWRITE(M6530_TAG, mos6530_device, read, write)
301301   AM_RANGE(0x0400, 0x07ff) AM_RAM AM_SHARE("share1")
302302   AM_RANGE(0x0800, 0x0bff) AM_RAM AM_SHARE("share2")
303303   AM_RANGE(0x0c00, 0x0fff) AM_RAM AM_SHARE("share3")
r26914r26915
331331   ADDRESS_MAP_GLOBAL_MASK(0x1fff)
332332   AM_RANGE(0x0000, 0x003f) AM_MIRROR(0x0300) AM_RAM // 6530
333333   AM_RANGE(0x0040, 0x004f) AM_MIRROR(0x0330) AM_DEVREADWRITE(M6522_TAG, via6522_device, read, write)
334   AM_RANGE(0x0080, 0x008f) AM_MIRROR(0x0330) AM_DEVREADWRITE_LEGACY(M6530_TAG, mos6530_r, mos6530_w)
334   AM_RANGE(0x0080, 0x008f) AM_MIRROR(0x0330) AM_DEVREADWRITE(M6530_TAG, mos6530_device, read, write)
335335   AM_RANGE(0x0400, 0x07ff) AM_RAM AM_SHARE("share1")
336336   AM_RANGE(0x0800, 0x0bff) AM_RAM AM_SHARE("share2")
337337   AM_RANGE(0x0c00, 0x0fff) AM_RAM AM_SHARE("share3")
r26914r26915
348348   ADDRESS_MAP_GLOBAL_MASK(0x1fff)
349349   AM_RANGE(0x0000, 0x003f) AM_MIRROR(0x0300) AM_RAM // 6530
350350   AM_RANGE(0x0040, 0x004f) AM_MIRROR(0x0330) AM_DEVREADWRITE(M6522_TAG, via6522_device, read, write)
351   AM_RANGE(0x0080, 0x008f) AM_MIRROR(0x0330) AM_DEVREADWRITE_LEGACY(M6530_TAG, mos6530_r, mos6530_w)
351   AM_RANGE(0x0080, 0x008f) AM_MIRROR(0x0330) AM_DEVREADWRITE(M6530_TAG, mos6530_device, read, write)
352352   AM_RANGE(0x0400, 0x07ff) AM_RAM AM_SHARE("share1")
353353   AM_RANGE(0x0800, 0x0bff) AM_RAM AM_SHARE("share2")
354354   AM_RANGE(0x0c00, 0x0fff) AM_RAM AM_SHARE("share3")
r26914r26915
365365   ADDRESS_MAP_GLOBAL_MASK(0x1fff)
366366   AM_RANGE(0x0000, 0x003f) AM_MIRROR(0x0300) AM_RAM // 6530
367367   AM_RANGE(0x0040, 0x004f) AM_MIRROR(0x0330) AM_DEVREADWRITE(M6522_TAG, via6522_device, read, write)
368   AM_RANGE(0x0080, 0x008f) AM_MIRROR(0x0330) AM_DEVREADWRITE_LEGACY(M6530_TAG, mos6530_r, mos6530_w)
368   AM_RANGE(0x0080, 0x008f) AM_MIRROR(0x0330) AM_DEVREADWRITE(M6530_TAG, mos6530_device, read, write)
369369   AM_RANGE(0x0400, 0x07ff) AM_RAM AM_SHARE("share1")
370370   AM_RANGE(0x0800, 0x0bff) AM_RAM AM_SHARE("share2")
371371   AM_RANGE(0x0c00, 0x0fff) AM_RAM AM_SHARE("share3")
trunk/src/emu/machine/mos6530.c
r26914r26915
1717
1818#include "emu.h"
1919#include "mos6530.h"
20#include "devlegcy.h"
2120
2221
2322/***************************************************************************
r26914r26915
3332
3433#define TIMER_FLAG      0x80
3534
36
37
3835/***************************************************************************
39    TYPE DEFINITIONS
36    DEVICE INTERFACE
4037***************************************************************************/
4138
42struct mos6530_port
39const device_type MOS6530 = &device_creator<mos6530_device>;
40
41mos6530_device::mos6530_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
42   : device_t(mconfig, MOS6530, "MOS6530", tag, owner, clock, "mos6530", __FILE__)
4343{
44   devcb_resolved_read8        in_port_func;
45   devcb_resolved_write8       out_port_func;
44}
4645
47   UINT8               in;
48   UINT8               out;
49   UINT8               ddr;
50};
46//-------------------------------------------------
47//  device_config_complete - perform any
48//  operations now that the configuration is
49//  complete
50//-------------------------------------------------
5151
52
53struct mos6530_state
52void mos6530_device::device_config_complete()
5453{
55   devcb_resolved_write_line   out_irq_func;
54   // inherit a copy of the static data
55   const mos6530_interface *intf = reinterpret_cast<const mos6530_interface *>(static_config());
56   if (intf != NULL)
57         *static_cast<mos6530_interface *>(this) = *intf;
5658
57   mos6530_port    port[2];
59   // or initialize to defaults if none provided
60   else
61   {
62      memset(&m_in_pa_cb, 0, sizeof(m_in_pa_cb));
63      memset(&m_out_pa_cb, 0, sizeof(m_out_pa_cb));
64      memset(&m_in_pb_cb, 0, sizeof(m_in_pb_cb));
65      memset(&m_out_pb_cb, 0, sizeof(m_out_pb_cb));
66   }
67}
5868
59   UINT8           irqstate;
60   UINT8           irqenable;
69//-------------------------------------------------
70//  device_start - device-specific startup
71//-------------------------------------------------
6172
62   UINT8           timershift;
63   UINT8           timerstate;
64   emu_timer *     timer;
73void mos6530_device::device_start()
74{
75   /* set static values */
76   m_clock = clock();
6577
66   UINT32          clock;
67};
78   /* resolve callbacks */
79   m_port[0].in_port_func.resolve(m_in_pa_cb, *this);
80   m_port[1].in_port_func.resolve(m_in_pb_cb, *this);
81   m_port[0].out_port_func.resolve(m_out_pa_cb, *this);
82   m_port[1].out_port_func.resolve(m_out_pb_cb, *this);
6883
84   /* allocate timers */
85   m_timer = timer_alloc(TIMER_END_CALLBACK);
6986
87   /* register for save states */
88   save_item(NAME(m_port[0].in));
89   save_item(NAME(m_port[0].out));
90   save_item(NAME(m_port[0].ddr));
91   save_item(NAME(m_port[1].in));
92   save_item(NAME(m_port[1].out));
93   save_item(NAME(m_port[1].ddr));
7094
71/***************************************************************************
72    INLINE FUNCTIONS
73***************************************************************************/
95   save_item(NAME(m_irqstate));
96   save_item(NAME(m_irqenable));
7497
75/*-------------------------------------------------
76    get_safe_token - convert a device's token
77    into a mos6530_state
78-------------------------------------------------*/
98   save_item(NAME(m_timershift));
99   save_item(NAME(m_timerstate));
100}
79101
80INLINE mos6530_state *get_safe_token(device_t *device)
102//-------------------------------------------------
103//  device_reset - device-specific reset
104//-------------------------------------------------
105
106void mos6530_device::device_reset()
81107{
82   assert(device != NULL);
83   assert(device->type() == MOS6530);
84   return (mos6530_state *)downcast<mos6530_device *>(device)->token();
108   /* reset I/O states */
109   m_port[0].out = 0;
110   m_port[0].ddr = 0;
111   m_port[1].out = 0;
112   m_port[1].ddr = 0;
113
114   /* reset IRQ states */
115   m_irqenable = 0;
116   m_irqstate = TIMER_FLAG;
117   update_irqstate();
118
119   /* reset timer states */
120   m_timershift = 0;
121   m_timerstate = TIMER_IDLE;
122   m_timer->adjust(attotime::never);
85123}
86124
87125
126/***************************************************************************
127    TYPE DEFINITIONS
128***************************************************************************/
129
130
88131/*-------------------------------------------------
89132    update_irqstate - update the IRQ state
90133    based on interrupt enables
91134-------------------------------------------------*/
92135
93INLINE void update_irqstate(device_t *device)
136void mos6530_device::update_irqstate()
94137{
95   mos6530_state *miot = get_safe_token(device);
96   UINT8 out = miot->port[1].out;
138   UINT8 out = m_port[1].out;
97139
98   if ( miot->irqenable )
99      out = ( ( miot->irqstate & TIMER_FLAG ) ? 0x00 : 0x80 ) | ( out & 0x7F );
140   if ( m_irqenable )
141      out = ( ( m_irqstate & TIMER_FLAG ) ? 0x00 : 0x80 ) | ( out & 0x7F );
100142
101   if (!miot->port[1].out_port_func.isnull())
102      miot->port[1].out_port_func(0, out);
143   if (!m_port[1].out_port_func.isnull())
144      m_port[1].out_port_func(0, out);
103145   else
104      logerror("6530MIOT chip %s: Port B is being written to but has no handler.\n", device->tag());
146      logerror("6530MIOT chip %s: Port B is being written to but has no handler.\n", tag());
105147}
106148
107149
r26914r26915
109151    get_timer - return the current timer value
110152-------------------------------------------------*/
111153
112INLINE UINT8 get_timer(mos6530_state *miot)
154UINT8 mos6530_device::get_timer()
113155{
114156   /* if idle, return 0 */
115   if (miot->timerstate == TIMER_IDLE)
157   if (m_timerstate == TIMER_IDLE)
116158      return 0;
117159
118160   /* if counting, return the number of ticks remaining */
119   else if (miot->timerstate == TIMER_COUNTING)
120      return miot->timer->remaining().as_ticks(miot->clock) >> miot->timershift;
161   else if (m_timerstate == TIMER_COUNTING)
162      return m_timer->remaining().as_ticks(m_clock) >> m_timershift;
121163
122164   /* if finishing, return the number of ticks without the shift */
123165   else
124      return miot->timer->remaining().as_ticks(miot->clock);
166      return m_timer->remaining().as_ticks(m_clock);
125167}
126168
127169
r26914r26915
134176    timer
135177-------------------------------------------------*/
136178
137static TIMER_CALLBACK( timer_end_callback )
179void mos6530_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
138180{
139   device_t *device = (device_t *)ptr;
140   mos6530_state *miot = get_safe_token(device);
181   switch (id)
182   {
183      // deferred reset
184      case TIMER_END_CALLBACK:
185         assert(m_timerstate != TIMER_IDLE);
141186
142   assert(miot->timerstate != TIMER_IDLE);
187         /* if we finished counting, switch to the finishing state */
188         if (m_timerstate == TIMER_COUNTING)
189         {
190            m_timerstate = TIMER_FINISHING;
191            m_timer->adjust(attotime::from_ticks(256, m_clock));
143192
144   /* if we finished counting, switch to the finishing state */
145   if (miot->timerstate == TIMER_COUNTING)
146   {
147      miot->timerstate = TIMER_FINISHING;
148      miot->timer->adjust(attotime::from_ticks(256, miot->clock));
193            /* signal timer IRQ as well */
194            m_irqstate |= TIMER_FLAG;
195            update_irqstate();
196         }
149197
150      /* signal timer IRQ as well */
151      miot->irqstate |= TIMER_FLAG;
152      update_irqstate(device);
198         /* if we finished finishing, switch to the idle state */
199         else if (m_timerstate == TIMER_FINISHING)
200         {
201            m_timerstate = TIMER_IDLE;
202            m_timer->adjust(attotime::never);
203         }
204         break;
153205   }
154
155   /* if we finished finishing, switch to the idle state */
156   else if (miot->timerstate == TIMER_FINISHING)
157   {
158      miot->timerstate = TIMER_IDLE;
159      miot->timer->adjust(attotime::never);
160   }
161206}
162207
163
164
165208/***************************************************************************
166209    I/O ACCESS
167210***************************************************************************/
r26914r26915
170213    mos6530_w - master I/O write access
171214-------------------------------------------------*/
172215
173WRITE8_DEVICE_HANDLER( mos6530_w )
216WRITE8_MEMBER( mos6530_device::write )
174217{
175   mos6530_state *miot = get_safe_token(device);
176
177218   /* if A2 == 1, we are writing to the timer */
178219   if (offset & 0x04)
179220   {
r26914r26915
182223      INT64 target;
183224
184225      /* A0-A1 contain the timer divisor */
185      miot->timershift = timershift[offset & 3];
226      m_timershift = timershift[offset & 3];
186227
187228      /* A3 contains the timer IRQ enable */
188229      if (offset & 8)
189         miot->irqenable |= TIMER_FLAG;
230         m_irqenable |= TIMER_FLAG;
190231      else
191         miot->irqenable &= ~TIMER_FLAG;
232         m_irqenable &= ~TIMER_FLAG;
192233
193234      /* writes here clear the timer flag */
194      if (miot->timerstate != TIMER_FINISHING || get_timer(miot) != 0xff)
195         miot->irqstate &= ~TIMER_FLAG;
196      update_irqstate(device);
235      if (m_timerstate != TIMER_FINISHING || get_timer() != 0xff)
236         m_irqstate &= ~TIMER_FLAG;
237      update_irqstate();
197238
198239      /* update the timer */
199      miot->timerstate = TIMER_COUNTING;
200      target = curtime.as_ticks(miot->clock) + 1 + (data << miot->timershift);
201      miot->timer->adjust(attotime::from_ticks(target, miot->clock) - curtime);
240      m_timerstate = TIMER_COUNTING;
241      target = curtime.as_ticks(m_clock) + 1 + (data << m_timershift);
242      m_timer->adjust(attotime::from_ticks(target, m_clock) - curtime);
202243   }
203244
204245   /* if A2 == 0, we are writing to the I/O section */
205246   else
206247   {
207248      /* A1 selects the port */
208      mos6530_port *port = &miot->port[(offset >> 1) & 1];
249      mos6530_port *port = &m_port[(offset >> 1) & 1];
209250
210251      /* if A0 == 1, we are writing to the port's DDR */
211252      if (offset & 1)
r26914r26915
217258         UINT8 olddata = port->out;
218259         port->out = data;
219260
220         if ( ( offset & 2 ) && miot->irqenable )
261         if ( ( offset & 2 ) && m_irqenable )
221262         {
222            olddata = ( ( miot->irqstate & TIMER_FLAG ) ? 0x00 : 0x80 ) | ( olddata & 0x7F );
223            data = ( ( miot->irqstate & TIMER_FLAG ) ? 0x00 : 0x80 ) | ( data & 0x7F );
263            olddata = ( ( m_irqstate & TIMER_FLAG ) ? 0x00 : 0x80 ) | ( olddata & 0x7F );
264            data = ( ( m_irqstate & TIMER_FLAG ) ? 0x00 : 0x80 ) | ( data & 0x7F );
224265         }
225266
226267         if (!port->out_port_func.isnull())
227268            port->out_port_func(0, data);
228269         else
229            logerror("6530MIOT chip %s: Port %c is being written to but has no handler.  PC: %08X - %02X\n", device->tag(), 'A' + (offset & 1), space.machine().firstcpu->pc(), data);
270            logerror("6530MIOT chip %s: Port %c is being written to but has no handler.  PC: %08X - %02X\n", tag(), 'A' + (offset & 1), space.machine().firstcpu->pc(), data);
230271      }
231272   }
232273}
r26914r26915
236277    mos6530_r - master I/O read access
237278-------------------------------------------------*/
238279
239READ8_DEVICE_HANDLER( mos6530_r )
280READ8_MEMBER( mos6530_device::read )
240281{
241   mos6530_state *miot = get_safe_token(device);
242282   UINT8 val = 0;
243283
244284   /* if A2 == 1 and A0 == 1, we are reading interrupt flags */
245285   if ((offset & 0x05) == 0x05)
246286   {
247      val = miot->irqstate;
287      val = m_irqstate;
248288   }
249289
250290   /* if A2 == 1 and A0 == 0, we are reading the timer */
251291   else if ((offset & 0x05) == 0x04)
252292   {
253      val = get_timer(miot);
293      val = get_timer();
254294
255295      /* A3 contains the timer IRQ enable */
256296      if (offset & 8)
257         miot->irqenable |= TIMER_FLAG;
297         m_irqenable |= TIMER_FLAG;
258298      else
259         miot->irqenable &= ~TIMER_FLAG;
299         m_irqenable &= ~TIMER_FLAG;
260300
261301      /* implicitly clears the timer flag */
262      if (miot->timerstate != TIMER_FINISHING || val != 0xff)
263         miot->irqstate &= ~TIMER_FLAG;
264      update_irqstate(device);
302      if (m_timerstate != TIMER_FINISHING || val != 0xff)
303         m_irqstate &= ~TIMER_FLAG;
304      update_irqstate();
265305   }
266306
267307   /* if A2 == 0 and A0 == anything, we are reading from ports */
268308   else
269309   {
270310      /* A1 selects the port */
271      mos6530_port *port = &miot->port[(offset >> 1) & 1];
311      mos6530_port *port = &m_port[(offset >> 1) & 1];
272312
273313      /* if A0 == 1, we are reading the port's DDR */
274314      if (offset & 1)
r26914r26915
279319      {
280320         UINT8   out = port->out;
281321
282         if ( ( offset & 2 ) && miot->irqenable )
283            out = ( ( miot->irqstate & TIMER_FLAG ) ? 0x00 : 0x80 ) | ( out & 0x7F );
322         if ( ( offset & 2 ) && m_irqenable )
323            out = ( ( m_irqstate & TIMER_FLAG ) ? 0x00 : 0x80 ) | ( out & 0x7F );
284324
285325         /* call the input callback if it exists */
286326         if (!port->in_port_func.isnull())
r26914r26915
288328            port->in = port->in_port_func(0);
289329         }
290330         else
291            logerror("6530MIOT chip %s: Port %c is being read but has no handler.  PC: %08X\n", device->tag(), 'A' + (offset & 1), space.machine().firstcpu->pc());
331            logerror("6530MIOT chip %s: Port %c is being read but has no handler.  PC: %08X\n", tag(), 'A' + (offset & 1), space.machine().firstcpu->pc());
292332
293333         /* apply the DDR to the result */
294334         val = (out & port->ddr) | (port->in & ~port->ddr);
r26914r26915
303343    value
304344-------------------------------------------------*/
305345
306void mos6530_porta_in_set(device_t *device, UINT8 data, UINT8 mask)
346void mos6530_device::porta_in_set(UINT8 data, UINT8 mask)
307347{
308   mos6530_state *miot = get_safe_token(device);
309   miot->port[0].in = (miot->port[0].in & ~mask) | (data & mask);
348   m_port[0].in = (m_port[0].in & ~mask) | (data & mask);
310349}
311350
312351
r26914r26915
315354    value
316355-------------------------------------------------*/
317356
318void mos6530_portb_in_set(device_t *device, UINT8 data, UINT8 mask)
357void mos6530_device::portb_in_set(UINT8 data, UINT8 mask)
319358{
320   mos6530_state *miot = get_safe_token(device);
321   miot->port[1].in = (miot->port[1].in & ~mask) | (data & mask);
359   m_port[1].in = (m_port[1].in & ~mask) | (data & mask);
322360}
323361
324362
r26914r26915
327365    value
328366-------------------------------------------------*/
329367
330UINT8 mos6530_porta_in_get(device_t *device)
368UINT8 mos6530_device::porta_in_get()
331369{
332   mos6530_state *miot = get_safe_token(device);
333   return miot->port[0].in;
370   return m_port[0].in;
334371}
335372
336373
r26914r26915
339376    value
340377-------------------------------------------------*/
341378
342UINT8 mos6530_portb_in_get(device_t *device)
379UINT8 mos6530_device::portb_in_get()
343380{
344   mos6530_state *miot = get_safe_token(device);
345   return miot->port[1].in;
381   return m_port[1].in;
346382}
347383
348384
r26914r26915
351387    value
352388-------------------------------------------------*/
353389
354UINT8 mos6530_porta_out_get(device_t *device)
390UINT8 mos6530_device::porta_out_get()
355391{
356   mos6530_state *miot = get_safe_token(device);
357   return miot->port[0].out;
392   return m_port[0].out;
358393}
359394
360395
r26914r26915
363398    value
364399-------------------------------------------------*/
365400
366UINT8 mos6530_portb_out_get(device_t *device)
401UINT8 mos6530_device::portb_out_get()
367402{
368   mos6530_state *miot = get_safe_token(device);
369   return miot->port[1].out;
403   return m_port[1].out;
370404}
371
372
373/***************************************************************************
374    DEVICE INTERFACE
375***************************************************************************/
376
377static DEVICE_START( mos6530 )
378{
379   mos6530_state *miot = get_safe_token(device);
380   const mos6530_interface *intf = (const mos6530_interface*)device->static_config();
381
382   /* validate arguments */
383   assert(device != NULL);
384   assert(device->tag() != NULL);
385
386   /* set static values */
387   miot->clock = device->clock();
388
389   /* resolve callbacks */
390   miot->port[0].in_port_func.resolve(intf->in_pa_func, *device);
391   miot->port[1].in_port_func.resolve(intf->in_pb_func, *device);
392   miot->port[0].out_port_func.resolve(intf->out_pa_func, *device);
393   miot->port[1].out_port_func.resolve(intf->out_pb_func, *device);
394
395   /* allocate timers */
396   miot->timer = device->machine().scheduler().timer_alloc(FUNC(timer_end_callback), (void *)device);
397
398   /* register for save states */
399   device->save_item(NAME(miot->port[0].in));
400   device->save_item(NAME(miot->port[0].out));
401   device->save_item(NAME(miot->port[0].ddr));
402   device->save_item(NAME(miot->port[1].in));
403   device->save_item(NAME(miot->port[1].out));
404   device->save_item(NAME(miot->port[1].ddr));
405
406   device->save_item(NAME(miot->irqstate));
407   device->save_item(NAME(miot->irqenable));
408
409   device->save_item(NAME(miot->timershift));
410   device->save_item(NAME(miot->timerstate));
411}
412
413
414static DEVICE_RESET( mos6530 )
415{
416   mos6530_state *miot = get_safe_token(device);
417
418   /* reset I/O states */
419   miot->port[0].out = 0;
420   miot->port[0].ddr = 0;
421   miot->port[1].out = 0;
422   miot->port[1].ddr = 0;
423
424   /* reset IRQ states */
425   miot->irqenable = 0;
426   miot->irqstate = TIMER_FLAG;
427   update_irqstate(device);
428
429   /* reset timer states */
430   miot->timershift = 0;
431   miot->timerstate = TIMER_IDLE;
432   miot->timer->adjust(attotime::never);
433}
434
435
436const device_type MOS6530 = &device_creator<mos6530_device>;
437
438mos6530_device::mos6530_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
439   : device_t(mconfig, MOS6530, "MOS6530", tag, owner, clock, "mos6530", __FILE__)
440{
441   m_token = global_alloc_clear(mos6530_state);
442}
443
444//-------------------------------------------------
445//  device_config_complete - perform any
446//  operations now that the configuration is
447//  complete
448//-------------------------------------------------
449
450void mos6530_device::device_config_complete()
451{
452}
453
454//-------------------------------------------------
455//  device_start - device-specific startup
456//-------------------------------------------------
457
458void mos6530_device::device_start()
459{
460   DEVICE_START_NAME( mos6530 )(this);
461}
462
463//-------------------------------------------------
464//  device_reset - device-specific reset
465//-------------------------------------------------
466
467void mos6530_device::device_reset()
468{
469   DEVICE_RESET_NAME( mos6530 )(this);
470}
trunk/src/emu/machine/mos6530.h
r26914r26915
3333#ifndef __MIOT6530_H__
3434#define __MIOT6530_H__
3535
36
3637/***************************************************************************
38    TYPE DEFINITIONS
39***************************************************************************/
40
41struct mos6530_interface
42{
43   devcb_read8             m_in_pa_cb;
44   devcb_write8            m_out_pa_cb;
45
46   devcb_read8             m_in_pb_cb;
47   devcb_write8            m_out_pb_cb;
48};
49
50struct mos6530_port
51{
52   devcb_resolved_read8        in_port_func;
53   devcb_resolved_write8       out_port_func;
54
55   UINT8               in;
56   UINT8               out;
57   UINT8               ddr;
58};
59
60/***************************************************************************
3761    MACROS / CONSTANTS
3862***************************************************************************/
3963
40class mos6530_device : public device_t
64class mos6530_device : public device_t,
65                        mos6530_interface
4166{
4267public:
4368   mos6530_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
44   ~mos6530_device() { global_free(m_token); }
69   ~mos6530_device() {}
4570
46   // access to legacy token
47   void *token() const { assert(m_token != NULL); return m_token; }
71   DECLARE_READ8_MEMBER( read );
72   DECLARE_WRITE8_MEMBER( write );
73   
74   UINT8 porta_in_get();
75   UINT8 portb_in_get();
76
77   UINT8 porta_out_get();
78   UINT8 portb_out_get();
79   
4880protected:
4981   // device-level overrides
5082   virtual void device_config_complete();
5183   virtual void device_start();
5284   virtual void device_reset();
85   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
86   
5387private:
5488   // internal state
55   void *m_token;
89
90   //devcb_resolved_write_line   out_irq_func;
91
92   mos6530_port    m_port[2];
93
94   UINT8           m_irqstate;
95   UINT8           m_irqenable;
96
97   UINT8           m_timershift;
98   UINT8           m_timerstate;
99   emu_timer *     m_timer;
100
101   UINT32          m_clock;
102   
103   void update_irqstate();   
104   UINT8 get_timer();
105   
106   void porta_in_set(UINT8 data, UINT8 mask);
107   void portb_in_set(UINT8 data, UINT8 mask);
108   
109   enum
110   {
111      TIMER_END_CALLBACK
112   };
56113};
57114
58115extern const device_type MOS6530;
r26914r26915
65122#define MOS6530_INTERFACE(name) \
66123   const mos6530_interface (name) =
67124
68/***************************************************************************
69    TYPE DEFINITIONS
70***************************************************************************/
71
72struct mos6530_interface
73{
74   devcb_read8             in_pa_func;
75   devcb_write8            out_pa_func;
76
77   devcb_read8             in_pb_func;
78   devcb_write8            out_pb_func;
79};
80
81/***************************************************************************
82    PROTOTYPES
83***************************************************************************/
84
85DECLARE_READ8_DEVICE_HANDLER( mos6530_r );
86DECLARE_WRITE8_DEVICE_HANDLER( mos6530_w );
87
88void mos6530_porta_in_set(device_t *device, UINT8 data, UINT8 mask);
89void mos6530_portb_in_set(device_t *device, UINT8 data, UINT8 mask);
90
91UINT8 mos6530_porta_in_get(device_t *device);
92UINT8 mos6530_portb_in_get(device_t *device);
93
94UINT8 mos6530_porta_out_get(device_t *device);
95UINT8 mos6530_portb_out_get(device_t *device);
96
97125#endif
trunk/src/mess/drivers/mk2.c
r26914r26915
8181static ADDRESS_MAP_START(mk2_mem , AS_PROGRAM, 8, mk2_state)
8282   ADDRESS_MAP_GLOBAL_MASK(0x1FFF) // m6504
8383   AM_RANGE( 0x0000, 0x01ff) AM_RAM // 2 2111, should be mirrored
84   AM_RANGE( 0x0b00, 0x0b0f) AM_DEVREADWRITE_LEGACY("miot", mos6530_r, mos6530_w)
84   AM_RANGE( 0x0b00, 0x0b0f) AM_DEVREADWRITE("miot", mos6530_device, read, write)
8585   AM_RANGE( 0x0b80, 0x0bbf) AM_RAM // rriot ram
8686   AM_RANGE( 0x0c00, 0x0fff) AM_ROM // rriot rom
8787   AM_RANGE( 0x1000, 0x1fff) AM_ROM
r26914r26915
137137   int data=0xff;
138138   int help=ioport("BLACK")->read() | ioport("WHITE")->read(); // looks like white and black keys are the same!
139139
140   switch (mos6530_portb_out_get(m_miot)&0x7)
140   switch (m_miot->portb_out_get()&0x7)
141141   {
142142   case 4:
143143      if (BIT(help, 5)) data&=~0x1; //F
r26914r26915
159159
160160WRITE8_MEMBER( mk2_state::mk2_write_a )
161161{
162   UINT8 temp = mos6530_portb_out_get(m_miot);
162   UINT8 temp = m_miot->portb_out_get();
163163
164164   m_led[temp & 3] |= data;
165165}
trunk/src/mess/drivers/kim1.c
r26914r26915
145145
146146static ADDRESS_MAP_START(kim1_map, AS_PROGRAM, 8, kim1_state)
147147   AM_RANGE(0x0000, 0x03ff) AM_MIRROR(0xe000) AM_RAM
148   AM_RANGE(0x1700, 0x173f) AM_MIRROR(0xe000) AM_DEVREADWRITE_LEGACY("miot_u3", mos6530_r, mos6530_w )
149   AM_RANGE(0x1740, 0x177f) AM_MIRROR(0xe000) AM_DEVREADWRITE_LEGACY("miot_u2", mos6530_r, mos6530_w )
148   AM_RANGE(0x1700, 0x173f) AM_MIRROR(0xe000) AM_DEVREADWRITE("miot_u3", mos6530_device, read, write )
149   AM_RANGE(0x1740, 0x177f) AM_MIRROR(0xe000) AM_DEVREADWRITE("miot_u2", mos6530_device, read, write )
150150   AM_RANGE(0x1780, 0x17bf) AM_MIRROR(0xe000) AM_RAM
151151   AM_RANGE(0x17c0, 0x17ff) AM_MIRROR(0xe000) AM_RAM
152152   AM_RANGE(0x1800, 0x1bff) AM_MIRROR(0xe000) AM_ROM
r26914r26915
242242
243243READ8_MEMBER( kim1_state::kim1_u2_read_b )
244244{
245   if ( mos6530_portb_out_get(m_riot2) & 0x20 )
245   if ( m_riot2->portb_out_get() & 0x20 )
246246      return 0xFF;
247247
248248   return 0x7F | ( m_311_output ^ 0x80 );

Previous 199869 Revisions Next


© 1997-2024 The MAME Team