Previous 199869 Revisions Next

r18286 Thursday 4th October, 2012 at 16:42:19 UTC by Curt Coder
mos6526: Implemented a nearly cycle-exact "old" CIA, which passes most of the Lorenz/VICE CIA tests. Refactored the c64/c128/vic10/cbm2 drivers and the 1571/1581 floppy drives to use the new implementation. [Curt Coder]
[src/emu]emu.mak
[src/emu/machine]6526cia.c 6526cia.h mos6526.c* mos6526.h*
[src/mame/drivers]alg.c arcadia.c cd32.c mquake.c upscope.c
[src/mess/drivers]ami1200.c amiga.c c128.c c64.c c65.c cbm2.c sbc6510.c vic10.c
[src/mess/includes]c128.h c64.h c65.h cbm2.h vic10.h
[src/mess/machine]c128.c c1571.c c1571.h c1581.c c1581.h c65.c

trunk/src/emu/emu.mak
r18285r18286
219219   $(EMUMACHINE)/mccs1850.o   \
220220   $(EMUMACHINE)/mm74c922.o   \
221221   $(EMUMACHINE)/microtch.o   \
222   $(EMUMACHINE)/mos6526.o      \
222223   $(EMUMACHINE)/mos6529.o      \
223224   $(EMUMACHINE)/msm5832.o      \
224225   $(EMUMACHINE)/msm58321.o   \
trunk/src/emu/machine/mos6526.c
r0r18286
1/**********************************************************************
2
3    MOS 6526/8520 Complex Interface Adapter emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10/*
11
12   TODO:
13
14   - pass Lorenz test suite 2.15
15      - ICR01
16      - IMR
17      - CIA1TA/TB
18      - CIA2TA/TB
19   - pass VICE cia tests
20   - 8520 read/write
21   - 5710 read/write
22   - optimize
23
24*/
25
26#include "mos6526.h"
27
28
29
30//**************************************************************************
31//  MACROS / CONSTANTS
32//**************************************************************************
33
34// registers
35enum
36{
37   PRA = 0,
38   PRB,
39   DDRA,
40   DDRB,
41   TA_LO,
42   TA_HI,
43   TB_LO,
44   TB_HI,
45   TOD_10THS,
46   TOD_SEC,
47   TOD_MIN,
48   TOD_HR,
49   SDR,
50   ICR, IMR = ICR,
51   CRA,
52   CRB   
53};
54
55
56// interrupt control register
57#define ICR_TA      0x01
58#define ICR_TB      0x02
59#define ICR_ALARM   0x04
60#define ICR_SP      0x08
61#define ICR_FLAG   0x10
62
63
64// interrupt mask register
65#define IMR_TA      BIT(m_imr, 0)
66#define IMR_TB      BIT(m_imr, 1)
67#define IMR_ALARM   BIT(m_imr, 2)
68#define IMR_SP      BIT(m_imr, 3)
69#define IMR_FLAG   BIT(m_imr, 4)
70#define IMR_SET      BIT(data, 7)
71
72
73// control register A
74enum
75{
76   CRA_INMODE_PHI2 = 0,
77   CRA_INMODE_CNT
78};
79
80#define CRA_START      0x01
81#define CRA_STARTED      BIT(m_cra, 0)
82#define CRA_PBON       BIT(m_cra, 1)
83#define CRA_OUTMODE    BIT(m_cra, 2)
84#define CRA_RUNMODE    BIT(m_cra, 3)
85#define CRA_LOAD      BIT(m_cra, 4)
86#define CRA_INMODE       BIT(m_cra, 5)
87#define CRA_SPMODE       BIT(m_cra, 6)
88#define CRA_TODIN       BIT(m_cra, 7)
89
90
91// control register B
92enum
93{
94   CRB_INMODE_PHI2 = 0,
95   CRB_INMODE_CNT,
96   CRB_INMODE_TA,
97   CRB_INMODE_CNT_TA
98};
99
100#define CRB_START      0x01
101#define CRB_STARTED      BIT(m_crb, 0)
102#define CRB_PBON       BIT(m_crb, 1)
103#define CRB_OUTMODE    BIT(m_crb, 2)
104#define CRB_RUNMODE    BIT(m_crb, 3)
105#define CRB_LOAD       BIT(m_crb, 4)
106#define CRB_INMODE       ((m_crb & 0x60) >> 5)
107#define CRB_ALARM       BIT(m_crb, 7)
108
109
110
111//**************************************************************************
112//  DEVICE TYPE DEFINITIONS
113//**************************************************************************
114
115const device_type MOS6526 = &device_creator<mos6526_device>;
116const device_type MOS6526A = &device_creator<mos6526a_device>;
117const device_type MOS8520 = &device_creator<mos8520_device>;
118const device_type MOS5710 = &device_creator<mos5710_device>;
119
120
121//-------------------------------------------------
122//  static_set_tod_clock -
123//-------------------------------------------------
124
125void mos6526_device::static_set_tod_clock(device_t &device, int tod_clock)
126{
127   mos6526_device &cia = dynamic_cast<mos6526_device &>(device);
128
129   cia.m_tod_clock = tod_clock;
130}
131
132
133//-------------------------------------------------
134//  device_config_complete - perform any
135//  operations now that the configuration is
136//  complete
137//-------------------------------------------------
138
139void mos6526_device::device_config_complete()
140{
141   // inherit a copy of the static data
142   const mos6526_interface *intf = reinterpret_cast<const mos6526_interface *>(static_config());
143   if (intf != NULL)
144      *static_cast<mos6526_interface *>(this) = *intf;
145
146   // or initialize to defaults if none provided
147   else
148   {
149       memset(&m_out_irq_cb, 0, sizeof(m_out_irq_cb));
150       memset(&m_out_pc_cb, 0, sizeof(m_out_pc_cb));
151       memset(&m_out_cnt_cb, 0, sizeof(m_out_cnt_cb));
152       memset(&m_out_sp_cb, 0, sizeof(m_out_sp_cb));
153       memset(&m_in_pa_cb, 0, sizeof(m_in_pa_cb));
154       memset(&m_out_pa_cb, 0, sizeof(m_out_pa_cb));
155       memset(&m_in_pb_cb, 0, sizeof(m_in_pb_cb));
156       memset(&m_out_pb_cb, 0, sizeof(m_out_pb_cb));
157   }
158}
159
160
161
162//**************************************************************************
163//  INLINE HELPERS
164//**************************************************************************
165
166//-------------------------------------------------
167//  update_pa - update port A
168//-------------------------------------------------
169
170inline void mos6526_device::update_pa()
171{
172   UINT8 pa = m_pra | ~m_ddra;
173
174   if (m_pa != pa)
175   {
176      m_pa = pa;
177      m_out_pa_func(0, pa);
178   }
179}
180
181
182//-------------------------------------------------
183//  update_pb - update port B
184//-------------------------------------------------
185
186inline void mos6526_device::update_pb()
187{
188   UINT8 pb = m_prb | ~m_ddrb;
189
190   if (CRA_PBON)
191   {
192      int pb6 = CRA_OUTMODE ? m_ta_pb6 : m_ta_out;
193
194      pb &= ~0x40;
195      pb |= pb6 << 6;
196   }
197
198   if (CRB_PBON)
199   {
200      int pb7 = CRB_OUTMODE ? m_tb_pb7 : m_tb_out;
201
202      pb &= ~0x80;
203      pb |= pb7 << 7;
204   }
205
206   if (m_pb != pb)
207   {
208      m_out_pb_func(0, pb);
209      m_pb = pb;
210   }
211}
212
213
214//-------------------------------------------------
215//  set_cra - control register A write
216//-------------------------------------------------
217
218inline void mos6526_device::set_cra(UINT8 data)
219{
220   if (!CRA_STARTED && (data & CRA_START))
221   {
222      m_ta_pb6 = 1;
223   }
224
225   m_cra = data;
226   update_pb();
227}
228
229
230//-------------------------------------------------
231//  set_crb - control register B write
232//-------------------------------------------------
233
234inline void mos6526_device::set_crb(UINT8 data)
235{
236   if (!CRB_STARTED && (data & CRB_START))
237   {
238      m_tb_pb7 = 1;
239   }
240
241   m_crb = data;
242   update_pb();
243}
244
245
246//-------------------------------------------------
247//  bcd_increment -
248//-------------------------------------------------
249
250inline UINT8 mos6526_device::bcd_increment(UINT8 value)
251{
252   value++;
253
254   if ((value & 0x0f) >= 0x0a)
255      value += 0x10 - 0x0a;
256   
257   return value;
258}
259
260
261//-------------------------------------------------
262//  clock_tod - time-of-day clock pulse
263//-------------------------------------------------
264
265inline void mos6526_device::clock_tod()
266{
267   UINT8 subsecond   = (UINT8) (m_tod >>  0);
268   UINT8 second   = (UINT8) (m_tod >>  8);
269   UINT8 minute   = (UINT8) (m_tod >> 16);
270   UINT8 hour      = (UINT8) (m_tod >> 24);
271
272   m_tod_count++;
273   
274   if (m_tod_count == (CRA_TODIN ? 5 : 6))
275   {
276      m_tod_count = 0;
277
278      subsecond = bcd_increment(subsecond);
279
280      if (subsecond >= 0x10)
281      {
282         subsecond = 0x00;
283         second = bcd_increment(second);
284
285         if (second >= 60)
286         {
287            second = 0x00;
288            minute = bcd_increment(minute);
289
290            if (minute >= 0x60)
291            {
292               minute = 0x00;
293
294               int pm = hour & 0x80;
295               hour &= 0x1f;
296
297               if (hour == 11) pm ^= 0x80;
298               if (hour == 12) hour = 0;
299
300               hour = bcd_increment(hour);
301
302               hour |= pm;
303            }
304         }
305      }
306   }
307
308   m_tod = (((UINT32) subsecond)   <<  0)
309        | (((UINT32) second)      <<  8)
310        | (((UINT32) minute)      << 16)
311        | (((UINT32) hour)      << 24);
312}
313
314
315//-------------------------------------------------
316//  clock_tod - time-of-day clock pulse
317//-------------------------------------------------
318
319inline void mos8520_device::clock_tod()
320{
321   m_tod++;
322   m_tod &= 0xffffff;
323}
324
325
326//-------------------------------------------------
327//  read_tod - time-of-day read
328//-------------------------------------------------
329
330inline UINT8 mos6526_device::read_tod(int offset)
331{
332   int shift = 8 * offset;
333
334   if (m_tod_latched)
335   {
336      return m_tod_latch >> shift;
337   }
338   else
339   {
340      return m_tod >> shift;
341   }
342}
343
344
345//-------------------------------------------------
346//  write_tod - time-of-day write
347//-------------------------------------------------
348
349inline void mos6526_device::write_tod(int offset, UINT8 data)
350{
351   int shift = 8 * offset;
352
353   if (CRB_ALARM)
354   {
355      m_alarm = (m_alarm & ~(0xff << shift)) | (data << shift);
356   }
357   else
358   {
359      m_tod = (m_tod & ~(0xff << shift)) | (data << shift);
360   }
361}
362
363
364//-------------------------------------------------
365//  serial_input -
366//-------------------------------------------------
367
368inline void mos6526_device::serial_input()
369{
370   if (m_count_a0 && !CRA_SPMODE)
371   {
372      m_shift <<= 1;
373      m_bits++;
374
375      m_shift |= m_sp;
376
377      if (m_bits == 8)
378      {
379         m_sdr = m_shift;
380         m_bits = 0;
381
382         m_icr |= ICR_SP;
383      }
384   }
385}
386
387
388//-------------------------------------------------
389//  clock_ta - clock timer A
390//-------------------------------------------------
391
392inline void mos6526_device::clock_ta()
393{
394   if (m_count_a3)
395   {
396      m_ta--;
397   }
398
399   m_ta_out = (m_count_a2 && !m_ta);
400
401   if (m_ta_out)
402   {
403      m_ta_pb6 = !m_ta_pb6;
404
405      if (CRA_RUNMODE || m_oneshot_a0)
406      {
407         m_cra &= ~CRA_START;
408         m_count_a0 = m_count_a1 = m_count_a2 = 0;
409      }
410
411      m_load_a1 = 1;
412   }
413
414   if (m_load_a1)
415   {
416      m_count_a2 = 0;
417      m_ta = m_ta_latch;
418   }
419}
420
421
422//-------------------------------------------------
423//  serial_output -
424//-------------------------------------------------
425
426inline void mos6526_device::serial_output()
427{
428   if (m_ta_out && CRA_SPMODE)
429   {
430      if (!m_sdr_empty || m_bits)
431      {
432         if (m_cnt)
433         {
434            if (m_bits == 0)
435            {
436               m_sdr_empty = true;
437               m_shift = m_sdr;
438            }
439
440            m_sp = BIT(m_shift, 7);
441            m_out_sp_func(m_sp);
442
443            m_shift <<= 1;
444            m_bits++;
445
446            if (m_bits == 8)
447            {
448               m_icr |= ICR_SP;
449            }
450         }
451         else
452         {
453            if (m_bits == 8)
454            {
455               m_bits = 0;
456            }
457         }
458
459         m_cnt = !m_cnt;
460         m_out_cnt_func(m_cnt);
461      }
462   }
463}
464
465
466//-------------------------------------------------
467//  clock_tb - clock timer B
468//-------------------------------------------------
469
470inline void mos6526_device::clock_tb()
471{
472   if (m_count_b3)
473   {
474      m_tb--;
475   }
476
477   m_tb_out = (m_count_b2 && !m_tb);
478
479   if (m_tb_out)
480   {
481      m_tb_pb7 = !m_tb_pb7;
482
483      if (CRB_RUNMODE || m_oneshot_b0)
484      {
485         m_crb &= ~CRB_START;
486         m_count_b0 = m_count_b1 = m_count_b2 = 0;
487      }
488
489      m_load_b1 = 1;
490   }
491
492   if (m_load_b1)
493   {
494      m_count_b2 = 0;
495      m_tb = m_tb_latch;
496   }
497}
498
499
500//-------------------------------------------------
501//  update_interrupt -
502//-------------------------------------------------
503
504inline void mos6526_device::update_interrupt()
505{
506   if (!m_irq && m_ir1)
507   {
508      m_out_irq_func(ASSERT_LINE);
509      m_irq = true;
510   }
511
512   if (m_ta_out)
513   {
514      m_icr |= ICR_TA;
515   }
516
517   if (m_tb_out && !m_icr_read)
518   {
519      m_icr |= ICR_TB;
520   }
521
522   m_icr_read = false;
523}
524
525
526//-------------------------------------------------
527//  clock_pipeline - clock pipeline
528//-------------------------------------------------
529
530inline void mos6526_device::clock_pipeline()
531{
532   // timer A pipeline
533   m_count_a3 = m_count_a2;
534   
535   switch (CRA_INMODE)
536   {
537   case CRA_INMODE_PHI2:
538      m_count_a2 = 1;
539      break;
540
541   case CRA_INMODE_CNT:
542      m_count_a2 = m_count_a1;
543      break;
544   }
545
546   m_count_a2 &= CRA_STARTED;
547   m_count_a1 = m_count_a0;
548   m_count_a0 = 0;
549
550   m_load_a2 = m_load_a1;
551   m_load_a1 = m_load_a0;
552   m_load_a0 = CRA_LOAD;
553   m_cra &= ~0x10;
554
555   m_oneshot_a0 = CRA_RUNMODE;
556
557   // timer B pipeline
558   m_count_b3 = m_count_b2;
559
560   switch (CRB_INMODE)
561   {
562   case CRB_INMODE_PHI2:
563      m_count_b2 = 1;
564      break;
565
566   case CRB_INMODE_CNT:
567      m_count_b2 = m_count_b1;
568      break;
569     
570   case CRB_INMODE_TA:
571      m_count_b2 = m_ta_out;
572      break;
573     
574   case CRB_INMODE_CNT_TA:
575      m_count_b2 = m_ta_out && m_cnt;
576      break;
577   }
578
579   m_count_b2 &= CRB_STARTED;
580   m_count_b1 = m_count_b0;
581   m_count_b0 = 0;
582
583   m_load_b2 = m_load_b1;
584   m_load_b1 = m_load_b0;
585   m_load_b0 = CRB_LOAD;
586   m_crb &= ~0x10;
587
588   m_oneshot_b0 = CRB_RUNMODE;
589
590   // interrupt pipeline
591   if (m_ir0) m_ir1 = 1;
592   m_ir0 = (m_icr & m_imr) ? 1 : 0;
593}
594
595
596//-------------------------------------------------
597//  synchronize -
598//-------------------------------------------------
599
600inline void mos6526_device::synchronize()
601{
602   if (!m_pc)
603   {
604      m_pc = 1;
605      m_out_pc_func(m_pc);
606   }
607
608   serial_input();
609
610   clock_ta();
611
612   serial_output();
613
614   clock_tb();
615
616   update_pb();
617
618   update_interrupt();
619
620   clock_pipeline();
621}
622
623
624
625//**************************************************************************
626//  LIVE DEVICE
627//**************************************************************************
628
629//-------------------------------------------------
630//  mos6526_device - constructor
631//-------------------------------------------------
632
633mos6526_device::mos6526_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, UINT32 variant)
634    : device_t(mconfig, type, name, tag, owner, clock),
635     device_execute_interface(mconfig, *this),
636     m_icount(0),
637     m_variant(variant)
638{
639}
640
641mos6526_device::mos6526_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
642    : device_t(mconfig, MOS6526, "MOS6526", tag, owner, clock),
643     device_execute_interface(mconfig, *this),
644     m_icount(0),
645     m_variant(TYPE_6526)
646{ }
647
648mos6526a_device::mos6526a_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
649    : mos6526_device(mconfig, MOS6526A, "MOS6526A", tag, owner, clock, TYPE_6526A) { }
650
651mos8520_device::mos8520_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
652    : mos6526_device(mconfig, MOS8520, "MOS8520", tag, owner, clock, TYPE_8520) { }
653
654mos5710_device::mos5710_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
655    : mos6526_device(mconfig, MOS5710, "MOS5710", tag, owner, clock, TYPE_5710) { }
656
657
658//-------------------------------------------------
659//  device_start - device-specific startup
660//-------------------------------------------------
661
662void mos6526_device::device_start()
663{
664   // set our instruction counter
665   m_icountptr = &m_icount;
666
667   // resolve callbacks
668   m_out_irq_func.resolve(m_out_irq_cb, *this);
669   m_out_pc_func.resolve(m_out_pc_cb, *this);
670   m_out_cnt_func.resolve(m_out_cnt_cb, *this);
671   m_out_sp_func.resolve(m_out_sp_cb, *this);
672   m_in_pa_func.resolve(m_in_pa_cb, *this);
673   m_out_pa_func.resolve(m_out_pa_cb, *this);
674   m_in_pb_func.resolve(m_in_pb_cb, *this);
675   m_out_pb_func.resolve(m_out_pb_cb, *this);
676
677   // allocate timer
678   if (m_tod_clock > 0)
679   {
680      m_tod_timer = timer_alloc();
681      m_tod_timer->adjust(attotime::from_hz(m_tod_clock), 0, attotime::from_hz(m_tod_clock));
682   }
683
684   // state saving
685   save_item(NAME(m_ir0));
686   save_item(NAME(m_ir1));
687   save_item(NAME(m_icr));
688   save_item(NAME(m_imr));
689   save_item(NAME(m_pc));
690   save_item(NAME(m_flag));
691   save_item(NAME(m_pra));
692   save_item(NAME(m_prb));
693   save_item(NAME(m_ddra));
694   save_item(NAME(m_ddrb));
695   save_item(NAME(m_sp));
696   save_item(NAME(m_cnt));
697   save_item(NAME(m_sdr));
698   save_item(NAME(m_shift));
699   save_item(NAME(m_sdr_empty));
700   save_item(NAME(m_bits));
701
702   save_item(NAME(m_ta_out));
703   save_item(NAME(m_tb_out));
704   save_item(NAME(m_ta_pb6));
705   save_item(NAME(m_tb_pb7));
706   save_item(NAME(m_ta));
707   save_item(NAME(m_tb));
708   save_item(NAME(m_ta_latch));
709   save_item(NAME(m_tb_latch));
710   save_item(NAME(m_cra));
711   save_item(NAME(m_crb));
712   
713   save_item(NAME(m_tod_count));
714   save_item(NAME(m_tod));
715   save_item(NAME(m_tod_latch));
716   save_item(NAME(m_alarm));
717   save_item(NAME(m_tod_stopped));
718   save_item(NAME(m_tod_latched));
719}
720
721
722//-------------------------------------------------
723//  device_reset - device-specific reset
724//-------------------------------------------------
725
726void mos6526_device::device_reset()
727{
728   m_irq = false;
729   m_ir0 = 0;
730   m_ir1 = 0;
731   m_icr = 0;
732   m_imr = 0;
733   m_icr_read = false;
734
735   m_pc = 1;
736   m_flag = 1;
737   m_pra = 0;
738   m_prb = 0;
739   m_ddra = 0;
740   m_ddrb = 0;
741   m_pa = 0xff;
742   m_pb = 0xff;
743
744   m_sp = 1;
745   m_cnt = 1;
746   m_sdr = 0;
747   m_shift = 0;
748   m_sdr_empty = true;
749   m_bits = 0;
750
751   m_ta_out = 0;
752   m_tb_out = 0;
753   m_ta_pb6 = 0;
754   m_tb_pb7 = 0;
755   m_count_a0 = 0;
756   m_count_a1 = 0;
757   m_count_a2 = 0;
758   m_count_a3 = 0;
759   m_load_a0 = 0;
760   m_load_a1 = 0;
761   m_load_a2 = 0;
762   m_oneshot_a0 = 0;
763   m_count_b0 = 0;
764   m_count_b1 = 0;
765   m_count_b2 = 0;
766   m_count_b3 = 0;
767   m_load_b0 = 0;
768   m_load_b1 = 0;
769   m_load_b2 = 0;
770   m_oneshot_b0 = 0;
771   m_ta = 0;
772   m_tb = 0;
773   m_ta_latch = 0xffff;
774   m_tb_latch = 0xffff;
775   m_cra = 0;
776   m_crb = 0;
777
778   m_tod_count = 0;
779   m_tod = 0x01000000L;
780   m_tod_latch = 0;
781   m_alarm = 0;
782   m_tod_stopped = true;
783   m_tod_latched = false;
784
785   m_out_irq_func(CLEAR_LINE);
786   m_out_pc_func(m_pc);
787   m_out_sp_func(m_sp);
788   m_out_cnt_func(m_cnt);
789}
790
791
792//-------------------------------------------------
793//  device_timer - handler timer events
794//-------------------------------------------------
795
796void mos6526_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
797{
798   if (!m_tod_stopped)
799   {
800      clock_tod();
801
802      if (m_tod == m_alarm)
803      {
804         m_icr |= ICR_ALARM;
805      }
806   }
807}
808
809
810//-------------------------------------------------
811//  execute_run -
812//-------------------------------------------------
813
814void mos6526_device::execute_run()
815{
816   do
817   {
818      synchronize();
819
820      m_icount--;
821   } while (m_icount > 0);
822}
823
824
825//-------------------------------------------------
826//  read -
827//-------------------------------------------------
828
829READ8_MEMBER( mos6526_device::read )
830{
831   UINT8 data = 0;
832
833   switch (offset)
834   {
835   case PRA:
836      data = (m_in_pa_func(0) & ~m_ddra) | (m_pra & m_ddra);
837      break;
838
839   case PRB:
840      data = (m_in_pb_func(0) & ~m_ddrb) | (m_prb & m_ddrb);
841     
842      if (CRA_PBON)
843      {
844         int pb6 = CRA_OUTMODE ? m_ta_pb6 : m_ta_out;
845
846         data &= ~0x40;
847         data |= pb6 << 6;
848      }
849
850      if (CRB_PBON)
851      {
852         int pb7 = CRB_OUTMODE ? m_tb_pb7 : m_tb_out;
853
854         data &= ~0x80;
855         data |= pb7 << 7;
856      }
857     
858      m_pc = 0;
859      m_out_pc_func(m_pc);
860      break;
861     
862   case DDRA:
863      data = m_ddra;
864      break;
865     
866   case DDRB:
867      data = m_ddrb;
868      break;
869     
870   case TA_LO:
871      data = m_ta & 0xff;
872      break;
873     
874   case TA_HI:
875      data = m_ta >> 8;
876      break;
877     
878   case TB_LO:
879      data = m_tb & 0xff;
880      break;
881     
882   case TB_HI:
883      data = m_tb >> 8;
884      break;
885     
886   case TOD_10THS:
887      data = read_tod(0);
888
889      m_tod_latched = false;
890      break;
891     
892   case TOD_SEC:
893      data = read_tod(1);
894      break;
895     
896   case TOD_MIN:
897      data = read_tod(2);
898      break;
899     
900   case TOD_HR:
901      if (!m_tod_latched)
902      {
903         m_tod_latched = true;
904         m_tod_latch = m_tod;
905      }
906
907      data = read_tod(3);
908      break;
909     
910   case SDR:
911      data = m_sdr;
912      break;
913     
914   case ICR:
915      data = (m_ir1 << 7) | m_icr;
916
917      m_icr_read = true;
918
919      m_ir0 = 0;
920      m_ir1 = 0;
921      m_icr = 0;
922      m_irq = false;
923      m_out_irq_func(CLEAR_LINE);
924      break;
925     
926   case CRA:
927      data = m_cra;
928      break;
929     
930   case CRB:
931      data = m_crb;
932      break;
933   }
934
935   return data;
936}
937
938
939//-------------------------------------------------
940//  write -
941//-------------------------------------------------
942
943WRITE8_MEMBER( mos6526_device::write )
944{
945   switch (offset)
946   {
947   case PRA:
948      m_pra = data;
949      update_pa();
950      break;
951
952   case PRB:
953      m_prb = data;
954      update_pb();
955     
956      m_pc = 0;
957      m_out_pc_func(m_pc);
958      break;
959     
960   case DDRA:
961      m_ddra = data;
962      update_pa();
963      break;
964     
965   case DDRB:
966      m_ddrb = data;
967      update_pb();
968      break;
969     
970   case TA_LO:
971      m_ta_latch = (m_ta_latch & 0xff00) | data;
972
973      if (m_load_a2)
974      {
975         m_ta = (m_ta & 0xff00) | data;
976      }
977      break;
978     
979   case TA_HI:
980      m_ta_latch = (data << 8) | (m_ta_latch & 0xff);
981
982      if (!CRA_STARTED)
983      {
984         m_load_a0 = 1;
985      }
986
987      if (m_load_a2)
988      {
989         m_ta = (data << 8) | (m_ta & 0xff);
990      }
991      break;
992     
993   case TB_LO:
994      m_tb_latch = (m_tb_latch & 0xff00) | data;
995
996      if (m_load_b2)
997      {
998         m_tb = (m_tb & 0xff00) | data;
999      }
1000      break;
1001     
1002   case TB_HI:
1003      m_tb_latch = (data << 8) | (m_tb_latch & 0xff);
1004
1005      if (!CRB_STARTED)
1006      {
1007         m_load_b0 = 1;
1008      }
1009
1010      if (m_load_b2)
1011      {
1012         m_tb = (data << 8) | (m_tb & 0xff);
1013      }
1014      break;
1015     
1016   case TOD_10THS:
1017      write_tod(0, data);
1018
1019      m_tod_stopped = false;
1020      break;
1021     
1022   case TOD_SEC:
1023      write_tod(1, data);
1024      break;
1025     
1026   case TOD_MIN:
1027      write_tod(2, data);
1028      break;
1029     
1030   case TOD_HR:
1031      m_tod_stopped = true;
1032
1033      if (((data & 0x1f) == 0x12) && !CRB_ALARM)
1034      {
1035         // toggle AM/PM flag
1036         data ^= 0x80;
1037      }
1038
1039      write_tod(3, data);
1040      break;
1041     
1042   case SDR:
1043      m_sdr = data;
1044      m_sdr_empty = false;
1045      break;
1046     
1047   case IMR:
1048      if (IMR_SET)
1049      {
1050         m_imr |= (data & 0x1f);
1051      }
1052      else
1053      {
1054         m_imr &= ~(data & 0x1f);
1055      }
1056
1057      if (!m_irq && (m_icr & m_imr))
1058      {
1059         m_ir0 = 1;
1060      }
1061      break;
1062     
1063   case CRA:
1064      set_cra(data);
1065      break;
1066     
1067   case CRB:
1068      set_crb(data);
1069      break;
1070   }
1071}
1072
1073
1074//-------------------------------------------------
1075//  pa_r - port A read
1076//-------------------------------------------------
1077
1078UINT8 mos6526_device::pa_r()
1079{
1080   return m_pa;
1081}
1082
1083
1084//-------------------------------------------------
1085//  pb_r - port B read
1086//-------------------------------------------------
1087
1088UINT8 mos6526_device::pb_r()
1089{
1090   return m_pb;
1091}
1092
1093
1094//-------------------------------------------------
1095//  sp_r - serial port read
1096//-------------------------------------------------
1097
1098READ_LINE_MEMBER( mos6526_device::sp_r )
1099{
1100   return m_sp;
1101}
1102
1103
1104//-------------------------------------------------
1105//  sp_w - serial port write
1106//-------------------------------------------------
1107
1108WRITE_LINE_MEMBER( mos6526_device::sp_w )
1109{
1110   m_sp = state;
1111}
1112
1113
1114//-------------------------------------------------
1115//  cnt_r - serial counter read
1116//-------------------------------------------------
1117
1118READ_LINE_MEMBER( mos6526_device::cnt_r )
1119{
1120   return m_cnt;
1121}
1122
1123
1124//-------------------------------------------------
1125//  cnt_w - serial counter write
1126//-------------------------------------------------
1127
1128WRITE_LINE_MEMBER( mos6526_device::cnt_w )
1129{
1130   if (CRA_SPMODE) return;
1131
1132   if (!m_cnt && state)
1133   {
1134      m_count_a0 = 1;
1135      m_count_b0 = 1;
1136   }
1137   
1138   m_cnt = state;
1139}
1140
1141
1142//-------------------------------------------------
1143//  flag_w - flag write
1144//-------------------------------------------------
1145
1146WRITE_LINE_MEMBER( mos6526_device::flag_w )
1147{
1148   if (m_flag && !state)
1149   {
1150      m_icr |= ICR_FLAG;
1151   }
1152
1153   m_flag = state;
1154}
trunk/src/emu/machine/mos6526.h
r0r18286
1/**********************************************************************
2
3    MOS 6526/8520 Complex Interface Adapter emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************
9                            _____   _____
10                   Vss   1 |*    \_/     | 40  CNT
11                   PA0   2 |             | 39  SP
12                   PA1   3 |             | 38  RS0
13                   PA2   4 |             | 37  RS1
14                   PA3   5 |             | 36  RS2
15                   PA4   6 |             | 35  RS3
16                   PA5   7 |             | 34  _RES
17                   PA6   8 |             | 33  DB0
18                   PA7   9 |             | 32  DB1
19                   PB0  10 |   MOS6526   | 31  DB2
20                   PB1  11 |   MOS8520   | 30  DB3
21                   PB2  12 |             | 29  DB4
22                   PB3  13 |             | 28  DB5
23                   PB4  14 |             | 27  DB6
24                   PB5  15 |             | 26  DB7
25                   PB6  16 |             | 25  phi2
26                   PB7  17 |             | 24  _FLAG
27                   _PC  18 |             | 23  _CS
28                   TOD  19 |             | 22  R/W
29                   Vcc  20 |_____________| 21  _IRQ
30
31**********************************************************************/
32
33#pragma once
34
35#ifndef __MOS6526__
36#define __MOS6526__
37
38#include "emu.h"
39
40
41
42//**************************************************************************
43//  INTERFACE CONFIGURATION MACROS
44//**************************************************************************
45
46#define MCFG_MOS6526_ADD(_tag, _clock, _tod_clock, _config) \
47   MCFG_DEVICE_ADD(_tag, MOS6526, _clock) \
48   MCFG_DEVICE_CONFIG(_config) \
49   mos6526_device::static_set_tod_clock(*device, _tod_clock);
50
51#define MCFG_MOS6526A_ADD(_tag, _clock, _tod_clock, _config) \
52   MCFG_DEVICE_ADD(_tag, MOS6526A, _clock) \
53   MCFG_DEVICE_CONFIG(_config) \
54   mos6526_device::static_set_tod_clock(*device, _tod_clock);
55
56#define MCFG_MOS8520_ADD(_tag, _clock, _tod_clock, _config) \
57   MCFG_DEVICE_ADD(_tag, MOS8520, _clock) \
58   MCFG_DEVICE_CONFIG(_config) \
59   mos6526_device::static_set_tod_clock(*device, _tod_clock);
60
61#define MCFG_MOS5710_ADD(_tag, _clock, _tod_clock, _config) \
62   MCFG_DEVICE_ADD(_tag, MOS5710, _clock) \
63   MCFG_DEVICE_CONFIG(_config) \
64   mos6526_device::static_set_tod_clock(*device, _tod_clock);
65
66
67#define MOS6526_INTERFACE(name) \
68   const mos6526_interface (name)=
69
70#define MOS8520_INTERFACE(name) \
71   const mos6526_interface (name)=
72
73
74
75//**************************************************************************
76//  TYPE DEFINITIONS
77//**************************************************************************
78
79// ======================> mos6526_interface
80
81struct mos6526_interface
82{
83   devcb_write_line    m_out_irq_cb;
84   devcb_write_line    m_out_pc_cb;
85   devcb_write_line    m_out_cnt_cb;
86   devcb_write_line    m_out_sp_cb;
87
88   devcb_read8         m_in_pa_cb;
89   devcb_write8        m_out_pa_cb;
90
91   devcb_read8         m_in_pb_cb;
92   devcb_write8        m_out_pb_cb;
93};
94
95
96// ======================> mos6526_device
97
98class mos6526_device :  public device_t,
99                  public device_execute_interface,
100                  public mos6526_interface
101{
102public:
103   // construction/destruction
104   mos6526_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, UINT32 variant);
105   mos6526_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
106
107   // inline configuration
108   static void static_set_tod_clock(device_t &device, int tod_clock);
109
110   DECLARE_READ8_MEMBER( read );
111   DECLARE_WRITE8_MEMBER( write );
112
113   UINT8 pa_r();
114   UINT8 pb_r();
115
116   DECLARE_READ_LINE_MEMBER( sp_r );
117   DECLARE_WRITE_LINE_MEMBER( sp_w );
118   DECLARE_READ_LINE_MEMBER( cnt_r );
119   DECLARE_WRITE_LINE_MEMBER( cnt_w );
120   DECLARE_WRITE_LINE_MEMBER( flag_w );
121
122protected:
123   enum
124   {
125      TYPE_6526,
126      TYPE_6526A,
127      TYPE_8520,
128      TYPE_5710
129   };
130
131   // device-level overrides
132   virtual void device_config_complete();
133   virtual void device_start();
134   virtual void device_reset();
135   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
136   virtual void execute_run();
137
138    int m_icount;
139   int m_variant;
140   int m_tod_clock;
141
142   inline void update_interrupt();
143   inline void update_pa();
144   inline void update_pb();
145   inline void set_cra(UINT8 data);
146   inline void set_crb(UINT8 data);
147   inline void serial_input();
148   inline void serial_output();
149   inline void clock_ta();
150   inline void clock_tb();
151   inline void clock_pipeline();
152   inline UINT8 bcd_increment(UINT8 value);
153   inline void clock_tod();
154   inline UINT8 read_tod(int offset);
155   inline void write_tod(int offset, UINT8 data);
156   inline void synchronize();
157
158   devcb_resolved_write_line   m_out_irq_func;
159   devcb_resolved_write_line   m_out_pc_func;
160   devcb_resolved_write_line   m_out_cnt_func;
161   devcb_resolved_write_line   m_out_sp_func;
162   devcb_resolved_read8        m_in_pa_func;
163   devcb_resolved_write8       m_out_pa_func;
164   devcb_resolved_read8        m_in_pb_func;
165   devcb_resolved_write8       m_out_pb_func;
166
167   // interrupts
168   bool m_irq;
169   int m_ir0;
170   int m_ir1;
171   UINT8 m_icr;
172   UINT8 m_imr;
173   bool m_icr_read;
174
175   // peripheral ports
176   int m_pc;
177   int m_flag;
178   UINT8 m_pra;
179   UINT8 m_prb;
180   UINT8 m_ddra;
181   UINT8 m_ddrb;
182   UINT8 m_pa;
183   UINT8 m_pb;
184
185   // serial
186   int m_sp;
187   int m_cnt;
188   UINT8 m_sdr;
189   UINT8 m_shift;
190   bool m_sdr_empty;
191   int m_bits;
192
193   // timers
194   int m_ta_out;
195   int m_tb_out;
196   int m_ta_pb6;
197   int m_tb_pb7;
198   int m_count_a0;
199   int m_count_a1;
200   int m_count_a2;
201   int m_count_a3;
202   int m_load_a0;
203   int m_load_a1;
204   int m_load_a2;
205   int m_oneshot_a0;
206   int m_count_b0;
207   int m_count_b1;
208   int m_count_b2;
209   int m_count_b3;
210   int m_load_b0;
211   int m_load_b1;
212   int m_load_b2;
213   int m_oneshot_b0;
214   UINT16 m_ta;
215   UINT16 m_tb;
216   UINT16 m_ta_latch;
217   UINT16 m_tb_latch;
218   UINT8 m_cra;
219   UINT8 m_crb;
220
221   // time-of-day
222   int m_tod_count;
223   UINT32 m_tod;
224   UINT32 m_tod_latch;
225   UINT32 m_alarm;
226   bool m_tod_stopped;
227   bool m_tod_latched;
228   emu_timer *m_tod_timer;
229};
230
231
232// ======================> mos6526a_device
233
234class mos6526a_device : public mos6526_device
235{
236public:
237   mos6526a_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
238};
239
240
241// ======================> mos8520_device
242
243class mos8520_device : public mos6526_device
244{
245public:
246   mos8520_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
247
248   //DECLARE_READ8_MEMBER( read );
249   //DECLARE_WRITE8_MEMBER( write );
250
251protected:
252   inline void clock_tod();
253};
254
255
256// ======================> mos5710_device
257
258class mos5710_device : public mos6526_device
259{
260public:
261   mos5710_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
262
263   //DECLARE_READ8_MEMBER( read );
264   //DECLARE_WRITE8_MEMBER( write );
265};
266
267
268// device type definition
269extern const device_type MOS6526;
270extern const device_type MOS6526A;
271extern const device_type MOS8520;
272extern const device_type MOS5710;
273
274
275
276#endif
trunk/src/emu/machine/6526cia.c
r18285r18286
5050//**************************************************************************
5151
5252// device type definition
53const device_type MOS6526R1 = &device_creator<mos6526r1_device>;
54const device_type MOS6526R2 = &device_creator<mos6526r2_device>;
55const device_type MOS8520 = &device_creator<mos8520_device>;
56const device_type MOS5710 = &device_creator<mos5710_device>;
53const device_type LEGACY_MOS6526R1 = &device_creator<legacy_mos6526r1_device>;
54const device_type LEGACY_MOS6526R2 = &device_creator<legacy_mos6526r2_device>;
55const device_type LEGACY_MOS8520 = &device_creator<legacy_mos8520_device>;
56const device_type LEGACY_MOS5710 = &device_creator<legacy_mos5710_device>;
5757
5858
5959
r18285r18286
6161//  INLINE HELPERS
6262//**************************************************************************
6363
64inline attotime mos6526_device::cycles_to_time(int c)
64inline attotime legacy_mos6526_device::cycles_to_time(int c)
6565{
6666   return attotime::from_hz(clock()) * c;
6767}
r18285r18286
7373//**************************************************************************
7474
7575//-------------------------------------------------
76//  mos6526_device - constructor
76//  legacy_mos6526_device - constructor
7777//-------------------------------------------------
7878
79mos6526_device::mos6526_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock)
79legacy_mos6526_device::legacy_mos6526_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock)
8080    : device_t(mconfig, type, name, tag, owner, clock)
8181{
8282}
8383
84mos6526r1_device::mos6526r1_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
85    : mos6526_device(mconfig, MOS6526R1, "MOS6526r1", tag, owner, clock) { }
84legacy_mos6526r1_device::legacy_mos6526r1_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
85    : legacy_mos6526_device(mconfig, LEGACY_MOS6526R1, "MOS6526r1", tag, owner, clock) { }
8686
87mos6526r2_device::mos6526r2_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
88    : mos6526_device(mconfig, MOS6526R2, "MOS6526r2", tag, owner, clock) { }
87legacy_mos6526r2_device::legacy_mos6526r2_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
88    : legacy_mos6526_device(mconfig, LEGACY_MOS6526R2, "MOS6526r2", tag, owner, clock) { }
8989
90mos8520_device::mos8520_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
91    : mos6526_device(mconfig, MOS8520, "MOS8520", tag, owner, clock) { }
90legacy_mos8520_device::legacy_mos8520_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
91    : legacy_mos6526_device(mconfig, LEGACY_MOS8520, "LEGACY_MOS8520", tag, owner, clock) { }
9292
93mos5710_device::mos5710_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
94    : mos6526_device(mconfig, MOS5710, "MOS5710", tag, owner, clock) { }
93legacy_mos5710_device::legacy_mos5710_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
94    : legacy_mos6526_device(mconfig, LEGACY_MOS5710, "LEGACY_MOS5710", tag, owner, clock) { }
9595
9696
97void mos6526_device::static_set_tod_clock(device_t &device, int tod_clock)
97void legacy_mos6526_device::static_set_tod_clock(device_t &device, int tod_clock)
9898{
99   mos6526_device &cia = dynamic_cast<mos6526_device &>(device);
99   legacy_mos6526_device &cia = dynamic_cast<legacy_mos6526_device &>(device);
100100
101101   cia.m_tod_clock = tod_clock;
102102}
r18285r18286
106106//  device_reset - device-specific reset
107107//-------------------------------------------------
108108
109void mos6526_device::device_reset()
109void legacy_mos6526_device::device_reset()
110110{
111111   /* clear things out */
112112   m_port[0].m_latch = 0x00;
r18285r18286
154154//  complete
155155//-------------------------------------------------
156156
157void mos6526_device::device_config_complete()
157void legacy_mos6526_device::device_config_complete()
158158{
159159   // inherit a copy of the static data
160   const mos6526_interface *intf = reinterpret_cast<const mos6526_interface *>(static_config());
160   const legacy_mos6526_interface *intf = reinterpret_cast<const legacy_mos6526_interface *>(static_config());
161161   if (intf != NULL)
162      *static_cast<mos6526_interface *>(this) = *intf;
162      *static_cast<legacy_mos6526_interface *>(this) = *intf;
163163
164164   // or initialize to defaults if none provided
165165   else
r18285r18286
180180//  device_start - device-specific startup
181181//-------------------------------------------------
182182
183void mos6526_device::device_start()
183void legacy_mos6526_device::device_start()
184184{
185185   /* clear out CIA structure, and copy the interface */
186186   m_out_irq_func.resolve(m_out_irq_cb, *this);
r18285r18286
258258//  device_timer - handler timer events
259259//-------------------------------------------------
260260
261void mos6526_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
261void legacy_mos6526_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
262262{
263263   switch (id)
264264   {
r18285r18286
277277    set_port_mask_value
278278-------------------------------------------------*/
279279
280void mos6526_device::set_port_mask_value(int port, int data)
280void legacy_mos6526_device::set_port_mask_value(int port, int data)
281281{
282282   m_port[port].m_mask_value = data;
283283}
r18285r18286
286286    update_pc - pulse /pc output
287287-------------------------------------------------*/
288288
289void mos6526_device::update_pc()
289void legacy_mos6526_device::update_pc()
290290{
291291   m_out_pc_func(0);
292292
r18285r18286
297297    update_interrupts
298298-------------------------------------------------*/
299299
300void mos6526_device::update_interrupts()
300void legacy_mos6526_device::update_interrupts()
301301{
302302   UINT8 new_irq;
303303
r18285r18286
325325    timer_bump
326326-------------------------------------------------*/
327327
328void mos6526_device::timer_bump(int timer)
328void legacy_mos6526_device::timer_bump(int timer)
329329{
330330   m_timer[timer].update(timer, -1);
331331
r18285r18286
343343    cia_timer_underflow
344344-------------------------------------------------*/
345345
346void mos6526_device::timer_underflow(int timer)
346void legacy_mos6526_device::timer_underflow(int timer)
347347{
348348   assert((timer == 0) || (timer == 1));
349349
r18285r18286
426426    TIMER_CALLBACK( cia_timer_proc )
427427-------------------------------------------------*/
428428
429TIMER_CALLBACK( mos6526_device::timer_proc )
429TIMER_CALLBACK( legacy_mos6526_device::timer_proc )
430430{
431    mos6526_device *cia = reinterpret_cast<mos6526_device *>(ptr);
431    legacy_mos6526_device *cia = reinterpret_cast<legacy_mos6526_device *>(ptr);
432432
433433   cia->timer_underflow(param);
434434}
r18285r18286
449449    cia6526_increment
450450-------------------------------------------------*/
451451
452void mos6526_device::increment()
452void legacy_mos6526_device::increment()
453453{
454454   /* break down TOD value into components */
455455   UINT8 subsecond   = (UINT8) (m_tod >>  0);
r18285r18286
494494    cia_clock_tod - Update TOD on CIA A
495495-------------------------------------------------*/
496496
497void mos6526_device::clock_tod()
497void legacy_mos6526_device::clock_tod()
498498{
499499   if (m_tod_running)
500500   {
501      if ((type() == MOS6526R1) || (type() == MOS6526R2))
501      if ((type() == LEGACY_MOS6526R1) || (type() == LEGACY_MOS6526R2))
502502      {
503503         /* The 6526 split the value into hours, minutes, seconds and
504504             * subseconds */
505505         increment();
506506      }
507      else if (type() == MOS8520)
507      else if (type() == LEGACY_MOS8520)
508508      {
509509         /* the 8520 has a straight 24-bit counter */
510510         m_tod++;
r18285r18286
524524    cnt_w
525525-------------------------------------------------*/
526526
527void mos6526_device::cnt_w(UINT8 state)
527void legacy_mos6526_device::cnt_w(UINT8 state)
528528{
529529   /* is this a rising edge? */
530530   if (!m_cnt && state)
r18285r18286
569569   m_cnt = state;
570570}
571571
572void mos6526_device::flag_w(UINT8 state)
572void legacy_mos6526_device::flag_w(UINT8 state)
573573{
574574   /* falling edge */
575575   if (m_flag && !state)
r18285r18286
581581   m_flag = state;
582582}
583583
584READ8_MEMBER( mos6526_device::read )
584READ8_MEMBER( legacy_mos6526_device::read )
585585{
586586   return reg_r(offset);
587587}
588588
589WRITE8_MEMBER( mos6526_device::write )
589WRITE8_MEMBER( legacy_mos6526_device::write )
590590{
591591   reg_w(offset, data);
592592}
r18285r18286
595595    reg_r
596596-------------------------------------------------*/
597597
598UINT8 mos6526_device::reg_r(UINT8 offset)
598UINT8 legacy_mos6526_device::reg_r(UINT8 offset)
599599{
600600   cia_timer *timer;
601601   cia_port *port;
r18285r18286
675675      case CIA_TOD1:
676676      case CIA_TOD2:
677677      case CIA_TOD3:
678         if (type() == MOS8520)
678         if (type() == LEGACY_MOS8520)
679679         {
680680            if (offset == CIA_TOD2)
681681            {
r18285r18286
733733    reg_w
734734-------------------------------------------------*/
735735
736void mos6526_device::reg_w(UINT8 offset, UINT8 data)
736void legacy_mos6526_device::reg_w(UINT8 offset, UINT8 data)
737737{
738738   cia_timer *timer;
739739   cia_port *port;
r18285r18286
813813            m_tod = (m_tod & ~(0xff << shift)) | (data << shift);
814814         }
815815
816         if (type() == MOS8520)
816         if (type() == LEGACY_MOS8520)
817817         {
818818            if (offset == CIA_TOD2)
819819            {
r18285r18286
889889    a given CIA timer
890890-------------------------------------------------*/
891891
892void mos6526_device::cia_timer::update(int which, INT32 new_count)
892void legacy_mos6526_device::cia_timer::update(int which, INT32 new_count)
893893{
894894   /* sanity check arguments */
895895   assert((new_count >= -1) && (new_count <= 0xffff));
r18285r18286
926926    timer
927927-------------------------------------------------*/
928928
929UINT16 mos6526_device::cia_timer::get_count()
929UINT16 legacy_mos6526_device::cia_timer::get_count()
930930{
931931   UINT16 count;
932932
r18285r18286
947947    TRAMPOLINES
948948***************************************************************************/
949949
950void cia_set_port_mask_value(device_t *device, int port, int data) { downcast<mos6526_device *>(device)->set_port_mask_value(port, data); }
950void cia_set_port_mask_value(device_t *device, int port, int data) { downcast<legacy_mos6526_device *>(device)->set_port_mask_value(port, data); }
951951
952READ8_DEVICE_HANDLER( mos6526_r ) { return downcast<mos6526_device *>(device)->reg_r(offset); }
953WRITE8_DEVICE_HANDLER( mos6526_w ) { downcast<mos6526_device *>(device)->reg_w(offset, data); }
952READ8_DEVICE_HANDLER( mos6526_r ) { return downcast<legacy_mos6526_device *>(device)->reg_r(offset); }
953WRITE8_DEVICE_HANDLER( mos6526_w ) { downcast<legacy_mos6526_device *>(device)->reg_w(offset, data); }
954954
955READ8_DEVICE_HANDLER( mos6526_pa_r ) { return downcast<mos6526_device *>(device)->pa_r(offset); }
956READ8_DEVICE_HANDLER( mos6526_pb_r ) { return downcast<mos6526_device *>(device)->pb_r(offset); }
955READ8_DEVICE_HANDLER( mos6526_pa_r ) { return downcast<legacy_mos6526_device *>(device)->pa_r(offset); }
956READ8_DEVICE_HANDLER( mos6526_pb_r ) { return downcast<legacy_mos6526_device *>(device)->pb_r(offset); }
957957
958READ_LINE_DEVICE_HANDLER( mos6526_irq_r ) { return downcast<mos6526_device *>(device)->irq_r(); }
958READ_LINE_DEVICE_HANDLER( mos6526_irq_r ) { return downcast<legacy_mos6526_device *>(device)->irq_r(); }
959959
960WRITE_LINE_DEVICE_HANDLER( mos6526_tod_w ) { downcast<mos6526_device *>(device)->tod_w(state); }
960WRITE_LINE_DEVICE_HANDLER( mos6526_tod_w ) { downcast<legacy_mos6526_device *>(device)->tod_w(state); }
961961
962READ_LINE_DEVICE_HANDLER( mos6526_cnt_r ) { return downcast<mos6526_device *>(device)->cnt_r(); }
963WRITE_LINE_DEVICE_HANDLER( mos6526_cnt_w ) { downcast<mos6526_device *>(device)->cnt_w(state); }
962READ_LINE_DEVICE_HANDLER( mos6526_cnt_r ) { return downcast<legacy_mos6526_device *>(device)->cnt_r(); }
963WRITE_LINE_DEVICE_HANDLER( mos6526_cnt_w ) { downcast<legacy_mos6526_device *>(device)->cnt_w(state); }
964964
965READ_LINE_DEVICE_HANDLER( mos6526_sp_r ) { return downcast<mos6526_device *>(device)->sp_r(); }
966WRITE_LINE_DEVICE_HANDLER( mos6526_sp_w ) { downcast<mos6526_device *>(device)->sp_w(state); }
965READ_LINE_DEVICE_HANDLER( mos6526_sp_r ) { return downcast<legacy_mos6526_device *>(device)->sp_r(); }
966WRITE_LINE_DEVICE_HANDLER( mos6526_sp_w ) { downcast<legacy_mos6526_device *>(device)->sp_w(state); }
967967
968WRITE_LINE_DEVICE_HANDLER( mos6526_flag_w ) { downcast<mos6526_device *>(device)->flag_w(state); }
968WRITE_LINE_DEVICE_HANDLER( mos6526_flag_w ) { downcast<legacy_mos6526_device *>(device)->flag_w(state); }
trunk/src/emu/machine/6526cia.h
r18285r18286
4343//  INTERFACE CONFIGURATION MACROS
4444//**************************************************************************
4545
46#define MCFG_MOS6526R1_ADD(_tag, _clock, _tod_clock, _config) \
47   MCFG_DEVICE_ADD(_tag, MOS6526R1, _clock) \
46#define MCFG_LEGACY_MOS6526R1_ADD(_tag, _clock, _tod_clock, _config) \
47   MCFG_DEVICE_ADD(_tag, LEGACY_MOS6526R1, _clock) \
4848   MCFG_DEVICE_CONFIG(_config) \
49   mos6526_device::static_set_tod_clock(*device, _tod_clock);
49   legacy_mos6526_device::static_set_tod_clock(*device, _tod_clock);
5050
51#define MCFG_MOS6526R2_ADD(_tag, _clock, _tod_clock, _config) \
52   MCFG_DEVICE_ADD(_tag, MOS6526R2, _clock) \
51#define MCFG_LEGACY_MOS6526R2_ADD(_tag, _clock, _tod_clock, _config) \
52   MCFG_DEVICE_ADD(_tag, LEGACY_MOS6526R2, _clock) \
5353   MCFG_DEVICE_CONFIG(_config) \
54   mos6526_device::static_set_tod_clock(*device, _tod_clock);
54   legacy_mos6526_device::static_set_tod_clock(*device, _tod_clock);
5555
56#define MCFG_MOS8520_ADD(_tag, _clock, _tod_clock, _config) \
57   MCFG_DEVICE_ADD(_tag, MOS8520, _clock) \
56#define MCFG_LEGACY_MOS8520_ADD(_tag, _clock, _tod_clock, _config) \
57   MCFG_DEVICE_ADD(_tag, LEGACY_MOS8520, _clock) \
5858   MCFG_DEVICE_CONFIG(_config) \
59   mos6526_device::static_set_tod_clock(*device, _tod_clock);
59   legacy_mos6526_device::static_set_tod_clock(*device, _tod_clock);
6060
61#define MCFG_MOS5710_ADD(_tag, _clock, _tod_clock, _config) \
62   MCFG_DEVICE_ADD(_tag, MOS5710, _clock) \
61#define MCFG_LEGACY_MOS5710_ADD(_tag, _clock, _tod_clock, _config) \
62   MCFG_DEVICE_ADD(_tag, LEGACY_MOS5710, _clock) \
6363   MCFG_DEVICE_CONFIG(_config) \
64   mos6526_device::static_set_tod_clock(*device, _tod_clock);
64   legacy_mos6526_device::static_set_tod_clock(*device, _tod_clock);
6565
6666
67#define MOS6526_INTERFACE(name) \
68   const mos6526_interface (name)=
67#define LEGACY_MOS6526_INTERFACE(name) \
68   const legacy_mos6526_interface (name)=
6969
70#define MOS8520_INTERFACE(name) \
71   const mos6526_interface (name)=
70#define LEGACY_MOS8520_INTERFACE(name) \
71   const legacy_mos6526_interface (name)=
7272
73#define MOS5710_INTERFACE(name) \
74   const mos6526_interface (name)=
7573
7674
77
7875/***************************************************************************
7976    TYPE DEFINITIONS
8077***************************************************************************/
8178
8279
83// ======================> mos6526_interface
80// ======================> legacy_mos6526_interface
8481
85struct mos6526_interface
82struct legacy_mos6526_interface
8683{
8784   devcb_write_line   m_out_irq_cb;
8885   devcb_write_line   m_out_pc_cb;
r18285r18286
9895
9996
10097
101// ======================> mos6526_device
98// ======================> legacy_mos6526_device
10299
103class mos6526_device :  public device_t,
104                        public mos6526_interface
100class legacy_mos6526_device :  public device_t,
101                        public legacy_mos6526_interface
105102{
106103protected:
107104    // construction/destruction
108    mos6526_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock);
105    legacy_mos6526_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock);
109106
110107public:
111108   // inline configuration
r18285r18286
182179      UINT8         m_mode;
183180      UINT8         m_irq;
184181      emu_timer*      m_timer;
185      mos6526_device*   m_cia;
182      legacy_mos6526_device*   m_cia;
186183   };
187184
188185   struct cia_port
r18285r18286
230227   emu_timer *m_tod_timer;
231228};
232229
233class mos6526r1_device : public mos6526_device
230class legacy_mos6526r1_device : public legacy_mos6526_device
234231{
235232public:
236   mos6526r1_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
233   legacy_mos6526r1_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
237234};
238235
239class mos6526r2_device : public mos6526_device
236class legacy_mos6526r2_device : public legacy_mos6526_device
240237{
241238public:
242   mos6526r2_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
239   legacy_mos6526r2_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
243240};
244241
245class mos8520_device : public mos6526_device
242class legacy_mos8520_device : public legacy_mos6526_device
246243{
247244public:
248   mos8520_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
245   legacy_mos8520_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
249246};
250247
251class mos5710_device : public mos6526_device
248class legacy_mos5710_device : public legacy_mos6526_device
252249{
253250public:
254   mos5710_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
251   legacy_mos5710_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
255252};
256253
257254
258255// device type definition
259extern const device_type MOS6526R1;
260extern const device_type MOS6526R2;
261extern const device_type MOS8520;
262extern const device_type MOS5710;
256extern const device_type LEGACY_MOS6526R1;
257extern const device_type LEGACY_MOS6526R2;
258extern const device_type LEGACY_MOS8520;
259extern const device_type LEGACY_MOS5710;
263260
264261
265262
trunk/src/mess/machine/c65.c
r18285r18286
129129#endif
130130}
131131
132const mos6526_interface c65_cia0 =
132const legacy_mos6526_interface c65_cia0 =
133133{
134134   DEVCB_LINE(c65_cia0_interrupt),
135135   DEVCB_NULL,   /* pc_func */
r18285r18286
193193   c65_nmi(machine());
194194}
195195
196const mos6526_interface c65_cia1 =
196const legacy_mos6526_interface c65_cia1 =
197197{
198198   DEVCB_DRIVER_LINE_MEMBER(c65_state,c65_cia1_interrupt),
199199   DEVCB_NULL,   /* pc_func */
trunk/src/mess/machine/c128.c
r18285r18286
9090
9191void c128_state::nmi()
9292{
93   int cia1irq = mos6526_irq_r(m_cia2);
94
95   if (m_nmilevel != (ioport("SPECIAL")->read() & 0x80) || cia1irq)   /* KEY_RESTORE */
93   if (m_nmilevel != (ioport("SPECIAL")->read() & 0x80) || m_cia1_irq)   /* KEY_RESTORE */
9694   {
9795      if (1) // this was never valid, there is no active CPU during a timer firing!  cpu_getactivecpu() == 0)
9896      {
9997         /* z80 */
100         m_maincpu->set_input_line(INPUT_LINE_NMI, (ioport("SPECIAL")->read() & 0x80) || cia1irq);
98         m_maincpu->set_input_line(INPUT_LINE_NMI, (ioport("SPECIAL")->read() & 0x80) || m_cia1_irq);
10199      }
102100      else
103101      {
104         m_subcpu->set_input_line(INPUT_LINE_NMI, (ioport("SPECIAL")->read() & 0x80) || cia1irq);
102         m_subcpu->set_input_line(INPUT_LINE_NMI, (ioport("SPECIAL")->read() & 0x80) || m_cia1_irq);
105103      }
106104
107      m_nmilevel = (ioport("SPECIAL")->read() & 0x80) || cia1irq;
105      m_nmilevel = (ioport("SPECIAL")->read() & 0x80) || m_cia1_irq;
108106   }
109107}
110108
r18285r18286
126124
127125READ8_MEMBER( c128_state::cia1_pa_r )
128126{
129   UINT8 cia0portb = mos6526_pb_r(m_cia1, space, 0);
127   UINT8 cia0portb = m_cia1->pb_r();
130128
131129   return cbm_common_cia0_port_a_r(m_cia1, cia0portb);
132130}
r18285r18286
134132READ8_MEMBER( c128_state::cia1_pb_r )
135133{
136134   UINT8 value = 0xff;
137   UINT8 cia0porta = mos6526_pa_r(m_cia1, space, 0);
135   UINT8 cia0porta = m_cia1->pa_r();
138136   //vic2e_device_interface *intf = dynamic_cast<vic2e_device_interface*>(&m_vic);
139137
140138   value &= cbm_common_cia0_port_b_r(m_cia1, cia0porta);
r18285r18286
175173
176174WRITE_LINE_MEMBER( c128_state::cia1_irq_w )
177175{
176   m_cia1_irq = state;
177
178178   irq(state || m_vicirq);
179179}
180180
r18285r18286
182182{
183183   if (state  != m_vicirq)
184184   {
185      irq(state || mos6526_irq_r(m_cia1));
185      irq(state || m_cia1_irq);
186186      m_vicirq = state;
187187   }
188188}
r18285r18286
237237
238238WRITE_LINE_MEMBER( c128_state::iec_srq_w )
239239{
240   mos6526_cnt_w(m_cia1, MMU_FSDIR || state);
240   m_cia1->cnt_w(MMU_FSDIR || state);
241241}
242242
243243WRITE_LINE_MEMBER( c128_state::iec_data_w )
244244{
245   mos6526_sp_w(m_cia1, MMU_FSDIR || state);
245   m_cia1->sp_w(MMU_FSDIR || state);
246246}
247247
248248/*
r18285r18286
370370            m_colorram[(offset & 0x3ff)|((c64_port6510&3)<<10)] = data | 0xf0; // maybe all 8 bit connected!
371371          break;
372372      case 0xc:
373         mos6526_w(m_cia1, space, offset, data);
373         m_cia1->write(space, offset & 0x0f, data);
374374         break;
375375      case 0xd:
376         mos6526_w(m_cia2, space, offset, data);
376         m_cia2->write(space, offset & 0x0f, data);
377377         break;
378378      case 0xf:
379379         dma8726_port_w(space, offset&0xff,data);
r18285r18286
404404      return m_colorram[offset & 0x3ff];
405405   else if (offset == 0xc00)
406406      {
407         cia_set_port_mask_value(m_cia1, 0, ioport("CTRLSEL")->read() & 0x80 ? c64_keyline[8] : c64_keyline[9] );
408         return mos6526_r(m_cia1, space, offset);
407         //cia_set_port_mask_value(m_cia1, 0, ioport("CTRLSEL")->read() & 0x80 ? c64_keyline[8] : c64_keyline[9] );
408         return m_cia1->read(space, offset & 0x0f);
409409      }
410410   else if (offset == 0xc01)
411411      {
412         cia_set_port_mask_value(m_cia1, 1, ioport("CTRLSEL")->read() & 0x80 ? c64_keyline[9] : c64_keyline[8] );
413         return mos6526_r(m_cia1, space, offset);
412         //cia_set_port_mask_value(m_cia1, 1, ioport("CTRLSEL")->read() & 0x80 ? c64_keyline[9] : c64_keyline[8] );
413         return m_cia1->read(space, offset & 0x0f);
414414      }
415415   else if (offset < 0xd00)
416      return mos6526_r(m_cia1, space, offset);
416      return m_cia1->read(space, offset & 0x0f);
417417   else if (offset < 0xe00)
418      return mos6526_r(m_cia2, space, offset);
418      return m_cia2->read(space, offset & 0x0f);
419419   else if ((offset >= 0xf00) & (offset <= 0xfff))
420420      return dma8726_port_r(space, offset&0xff);
421421   DBG_LOG(machine(), 1, "io read", ("%.3x\n", offset));
r18285r18286
799799      bankswitch(0);
800800      iec_srq_out_w();
801801      iec_data_out_w();
802      mos6526_cnt_w(m_cia1, MMU_FSDIR || m_iec->srq_r());
803      mos6526_sp_w(m_cia1, MMU_FSDIR || m_iec->data_r());
802      m_cia1->cnt_w(MMU_FSDIR || m_iec->srq_r());
803      m_cia1->sp_w(MMU_FSDIR || m_iec->data_r());
804804      break;
805805   case 0:
806806   case 6:
trunk/src/mess/machine/c1571.c
r18285r18286
166166   AM_RANGE(0x1800, 0x180f) AM_MIRROR(0x03f0) AM_DEVREADWRITE(M6522_0_TAG, via6522_device, read, write)
167167   AM_RANGE(0x1c00, 0x1c0f) AM_MIRROR(0x03f0) AM_DEVREADWRITE(M6522_1_TAG, via6522_device, read, write)
168168   AM_RANGE(0x2000, 0x2003) AM_MIRROR(0x1ffc) AM_DEVREADWRITE_LEGACY(WD1770_TAG, wd17xx_r, wd17xx_w)
169   AM_RANGE(0x4000, 0x400f) AM_MIRROR(0x3ff0) AM_DEVREADWRITE_LEGACY(M6526_TAG, mos6526_r, mos6526_w)
169   AM_RANGE(0x4000, 0x400f) AM_MIRROR(0x3ff0) AM_DEVREADWRITE(M6526_TAG, mos6526_device, read, write)
170170   AM_RANGE(0x8000, 0xffff) AM_ROM AM_REGION(M6502_TAG, 0)
171171ADDRESS_MAP_END
172172
r18285r18286
445445
446446
447447//-------------------------------------------------
448//  mos6526_interface cia_intf
448//  MOS6526_INTERFACE( cia_intf )
449449//-------------------------------------------------
450450
451451WRITE_LINE_MEMBER( base_c1571_device::cia_irq_w )
r18285r18286
603603
604604   MCFG_VIA6522_ADD(M6522_0_TAG, XTAL_16MHz/16, via0_intf)
605605   MCFG_VIA6522_ADD(M6522_1_TAG, XTAL_16MHz/16, via1_intf)
606   MCFG_MOS6526R1_ADD(M6526_TAG, XTAL_16MHz/16, 0, cia_intf)
606   MCFG_MOS6526_ADD(M6526_TAG, XTAL_16MHz/16, 0, cia_intf)
607607   MCFG_WD1770_ADD(WD1770_TAG, /* XTAL_16MHz/2, */ fdc_intf)
608608
609609   MCFG_LEGACY_FLOPPY_DRIVE_ADD(FLOPPY_0, c1571_floppy_interface)
r18285r18286
622622
623623   MCFG_VIA6522_ADD(M6522_0_TAG, XTAL_16MHz/16, via0_intf)
624624   MCFG_VIA6522_ADD(M6522_1_TAG, XTAL_16MHz/16, via1_intf)
625   MCFG_MOS6526R1_ADD(M6526_TAG, XTAL_16MHz/16, 0, cia_intf)
625   MCFG_MOS6526_ADD(M6526_TAG, XTAL_16MHz/16, 0, cia_intf)
626626   MCFG_WD1770_ADD(WD1770_TAG, /* XTAL_16MHz/2, */ fdc_intf)
627627
628628   MCFG_LEGACY_FLOPPY_DRIVE_ADD(FLOPPY_0, c1570_floppy_interface)
trunk/src/mess/machine/c1571.h
r18285r18286
2020#include "formats/g64_dsk.h"
2121#include "machine/64h156.h"
2222#include "machine/6522via.h"
23#include "machine/6526cia.h"
2423#include "machine/c64_bn1541.h"
2524#include "machine/cbmiec.h"
25#include "machine/mos6526.h"
2626#include "machine/wd17xx.h"
2727
2828
trunk/src/mess/machine/c1581.c
r18285r18286
110110
111111static ADDRESS_MAP_START( c1581_mem, AS_PROGRAM, 8, base_c1581_device )
112112   AM_RANGE(0x0000, 0x1fff) AM_MIRROR(0x2000) AM_RAM
113   AM_RANGE(0x4000, 0x400f) AM_MIRROR(0x1ff0) AM_DEVREADWRITE_LEGACY(M8520_TAG, mos6526_r, mos6526_w)
113   AM_RANGE(0x4000, 0x400f) AM_MIRROR(0x1ff0) AM_DEVREADWRITE(M8520_TAG, mos8520_device, read, write)
114114   AM_RANGE(0x6000, 0x6003) AM_MIRROR(0x1ffc) AM_DEVREADWRITE_LEGACY(WD1770_TAG, wd17xx_r, wd17xx_w)
115115   AM_RANGE(0x8000, 0xffff) AM_ROM AM_REGION(M6502_TAG, 0)
116116ADDRESS_MAP_END
trunk/src/mess/machine/c1581.h
r18285r18286
1717#include "cpu/m6502/m6502.h"
1818#include "imagedev/flopdrv.h"
1919#include "formats/d81_dsk.h"
20#include "machine/6526cia.h"
2120#include "machine/cbmiec.h"
21#include "machine/mos6526.h"
2222#include "machine/wd17xx.h"
2323
2424
trunk/src/mess/includes/cbm2.h
r18285r18286
88#include "formats/cbm_snqk.h"
99#include "includes/cbm.h"
1010#include "machine/6525tpi.h"
11#include "machine/6526cia.h"
1211#include "machine/6551acia.h"
1312#include "machine/cbm2exp.h"
1413#include "machine/cbmipt.h"
1514#include "machine/ds75160a.h"
1615#include "machine/ds75161a.h"
1716#include "machine/ieee488.h"
17#include "machine/mos6526.h"
1818#include "machine/petcass.h"
1919#include "machine/pla.h"
2020#include "machine/ram.h"
trunk/src/mess/includes/c64.h
r18285r18286
77#include "emu.h"
88#include "formats/cbm_snqk.h"
99#include "includes/cbm.h"
10#include "machine/6526cia.h"
1110#include "machine/c64exp.h"
1211#include "machine/c64user.h"
1312#include "machine/cbmiec.h"
1413#include "machine/cbmipt.h"
14#include "machine/mos6526.h"
1515#include "machine/petcass.h"
1616#include "machine/pla.h"
1717#include "machine/ram.h"
trunk/src/mess/includes/c128.h
r18285r18286
1717#include "emu.h"
1818#include "formats/cbm_snqk.h"
1919#include "includes/cbm.h"
20#include "machine/6526cia.h"
2120#include "machine/c64exp.h"
2221#include "machine/c64user.h"
2322#include "machine/cbmiec.h"
2423#include "machine/cbmipt.h"
24#include "machine/mos6526.h"
2525#include "machine/mos8722.h"
2626#include "machine/petcass.h"
2727#include "machine/pla.h"
r18285r18286
213213   int m_va1617;
214214   int m_nmilevel;
215215   int m_z80en;
216   int m_cia1_irq;
216217   DECLARE_DRIVER_INIT(c128pal);
217218   DECLARE_DRIVER_INIT(c128dcrp);
218219   DECLARE_DRIVER_INIT(c128dcr);
trunk/src/mess/includes/c65.h
r18285r18286
9393void c65_vic_interrupt(running_machine &machine, int level);
9494void c65_bankswitch_interface(running_machine &machine, int value);
9595
96extern const mos6526_interface c65_cia0;
97extern const mos6526_interface c65_cia1;
96extern const legacy_mos6526_interface c65_cia0;
97extern const legacy_mos6526_interface c65_cia1;
9898
9999#endif /* C65_H_ */
trunk/src/mess/includes/vic10.h
r18285r18286
66
77#include "emu.h"
88#include "includes/cbm.h"
9#include "machine/6526cia.h"
109#include "machine/cbmipt.h"
10#include "machine/mos6526.h"
1111#include "machine/petcass.h"
1212#include "machine/ram.h"
13#include "machine/vcsctrl.h"
1314#include "sound/dac.h"
1415#include "sound/sid6581.h"
1516#include "video/mos6566.h"
r18285r18286
2021#define MOS6526_TAG      "u9"
2122#define SCREEN_TAG      "screen"
2223#define TIMER_C1531_TAG   "c1531"
24#define CONTROL1_TAG   "joy1"
25#define CONTROL2_TAG   "joy2"
2326
2427class vic10_state : public driver_device
2528{
r18285r18286
3033        m_vic(*this, MOS6566_TAG),
3134        m_sid(*this, MOS6581_TAG),
3235        m_cia(*this, MOS6526_TAG),
36        m_joy1(*this, CONTROL1_TAG),
37        m_joy2(*this, CONTROL2_TAG),
3338        m_exp(*this, VIC10_EXPANSION_SLOT_TAG),
3439        m_ram(*this, RAM_TAG),
3540        m_cassette(*this, PET_DATASSETTE_PORT_TAG),
r18285r18286
4247   required_device<mos6566_device> m_vic;
4348   required_device<sid6581_device> m_sid;
4449   required_device<mos6526_device> m_cia;
50   required_device<vcs_control_port_device> m_joy1;
51   required_device<vcs_control_port_device> m_joy2;
4552   required_device<vic10_expansion_slot_device> m_exp;
4653   required_device<ram_device> m_ram;
4754   optional_device<pet_datassette_port_device> m_cassette;
trunk/src/mess/drivers/amiga.c
r18285r18286
287287   MACHINE_RESET_CALL_LEGACY( amigacd );
288288}
289289
290static const mos6526_interface cia_0_ntsc_intf =
290static const legacy_mos6526_interface cia_0_ntsc_intf =
291291{
292292   DEVCB_DEVICE_LINE("cia_0", amiga_cia_0_irq),                     /* irq_func */
293293   DEVCB_DEVICE_LINE_MEMBER("centronics", centronics_device, strobe_w),   /* pc_func */
r18285r18286
299299   DEVCB_DEVICE_MEMBER("centronics", centronics_device, write)   /* port B */
300300};
301301
302static const mos6526_interface cia_0_pal_intf =
302static const legacy_mos6526_interface cia_0_pal_intf =
303303{
304304   DEVCB_DEVICE_LINE("cia_0", amiga_cia_0_irq),                     /* irq_func */
305305   DEVCB_DEVICE_LINE_MEMBER("centronics", centronics_device, strobe_w),   /* pc_func */
r18285r18286
311311   DEVCB_DEVICE_MEMBER("centronics", centronics_device, write)   /* port B */
312312};
313313
314static const mos6526_interface cia_1_intf =
314static const legacy_mos6526_interface cia_1_intf =
315315{
316316   DEVCB_DEVICE_LINE("cia_1", amiga_cia_1_irq),                     /* irq_func */
317317   DEVCB_NULL,                                    /* pc_func */
r18285r18286
323323   DEVCB_DEVICE_MEMBER("fdc", amiga_fdc, ciaaprb_w)      /* port B */
324324};
325325
326static const mos6526_interface cia_0_cdtv_intf =
326static const legacy_mos6526_interface cia_0_cdtv_intf =
327327{
328328   DEVCB_DEVICE_LINE("cia_0", amiga_cia_0_irq),                     /* irq_func */
329329   DEVCB_DEVICE_LINE_MEMBER("centronics", centronics_device, strobe_w),   /* pc_func */
r18285r18286
335335   DEVCB_DEVICE_MEMBER("centronics", centronics_device, write)   /* port B */
336336};
337337
338static const mos6526_interface cia_1_cdtv_intf =
338static const legacy_mos6526_interface cia_1_cdtv_intf =
339339{
340340   DEVCB_DEVICE_LINE("cia_1", amiga_cia_1_irq),                     /* irq_func */
341341   DEVCB_NULL,   /* pc_func */
r18285r18286
415415   MCFG_SOUND_ROUTE(3, "lspeaker", 0.50)
416416
417417   /* cia */
418   MCFG_MOS8520_ADD("cia_0", AMIGA_68000_NTSC_CLOCK / 10, 60, cia_0_ntsc_intf)
419   MCFG_MOS8520_ADD("cia_1", AMIGA_68000_NTSC_CLOCK, 0, cia_1_intf)
418   MCFG_LEGACY_MOS8520_ADD("cia_0", AMIGA_68000_NTSC_CLOCK / 10, 60, cia_0_ntsc_intf)
419   MCFG_LEGACY_MOS8520_ADD("cia_1", AMIGA_68000_NTSC_CLOCK, 0, cia_1_intf)
420420
421421   /* fdc */
422422   MCFG_AMIGA_FDC_ADD("fdc", AMIGA_68000_NTSC_CLOCK)
r18285r18286
474474   /* cia */
475475   MCFG_DEVICE_REMOVE("cia_0")
476476   MCFG_DEVICE_REMOVE("cia_1")
477   MCFG_MOS8520_ADD("cia_0", CDTV_CLOCK_X1 / 40, 0, cia_0_cdtv_intf)
478   MCFG_MOS8520_ADD("cia_1", CDTV_CLOCK_X1 / 4, 0, cia_1_cdtv_intf)
477   MCFG_LEGACY_MOS8520_ADD("cia_0", CDTV_CLOCK_X1 / 40, 0, cia_0_cdtv_intf)
478   MCFG_LEGACY_MOS8520_ADD("cia_1", CDTV_CLOCK_X1 / 4, 0, cia_1_cdtv_intf)
479479
480480   /* fdc */
481481   MCFG_DEVICE_MODIFY("fdc")
r18285r18286
498498
499499   /* cia */
500500   MCFG_DEVICE_REMOVE("cia_0")
501   MCFG_MOS8520_ADD("cia_0", AMIGA_68000_PAL_CLOCK / 10, 50, cia_0_pal_intf)
501   MCFG_LEGACY_MOS8520_ADD("cia_0", AMIGA_68000_PAL_CLOCK / 10, 50, cia_0_pal_intf)
502502
503503   /* fdc */
504504   MCFG_DEVICE_MODIFY("fdc")
trunk/src/mess/drivers/sbc6510.c
r18285r18286
248248   m_key_row = data;
249249}
250250
251const mos6526_interface cia_intf =
251const legacy_mos6526_interface cia_intf =
252252{
253253   DEVCB_CPU_INPUT_LINE("maincpu", M6502_IRQ_LINE), // irq
254254   DEVCB_NULL,   // pc (timer related) not connected
r18285r18286
276276   MCFG_SOUND_CONFIG(sbc6510_ay_interface)
277277   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
278278
279   MCFG_MOS6526R1_ADD("cia6526", XTAL_1MHz, 50, cia_intf)
279   MCFG_LEGACY_MOS6526R1_ADD("cia6526", XTAL_1MHz, 50, cia_intf)
280280MACHINE_CONFIG_END
281281
282282/* ROM definition */
trunk/src/mess/drivers/c64.c
r18285r18286
5252   m_maincpu->set_input_line(INPUT_LINE_IRQ0, m_cia1_irq || m_vic_irq || m_exp_irq);
5353   m_maincpu->set_input_line(INPUT_LINE_NMI, m_cia2_irq || restore || m_exp_nmi);
5454
55   mos6526_flag_w(m_cia1, m_cass_rd && m_iec_srq);
55   m_cia1->flag_w(m_cass_rd && m_iec_srq);
5656}
5757
5858
r18285r18286
135135         switch ((offset >> 8) & 0x03)
136136         {
137137         case 0: // CIA1
138            if (offset & 1)
139               cia_set_port_mask_value(m_cia1, 1, ioport("CTRLSEL")->read() & 0x80 ? c64_keyline[9] : c64_keyline[8] );
140            else
141               cia_set_port_mask_value(m_cia1, 0, ioport("CTRLSEL")->read() & 0x80 ? c64_keyline[8] : c64_keyline[9] );
142
143138            data = m_cia1->read(space, offset & 0x0f);
144139            break;
145140
r18285r18286
426421
427422READ8_MEMBER( c64_state::sid_potx_r )
428423{
429   UINT8 cia1_pa = mos6526_pa_r(m_cia1, space, 0);
424   UINT8 cia1_pa = m_cia1->pa_r();
430425   
431426   int sela = BIT(cia1_pa, 6);
432427   int selb = BIT(cia1_pa, 7);
r18285r18286
441436
442437READ8_MEMBER( c64_state::sid_poty_r )
443438{
444   UINT8 cia1_pa = mos6526_pa_r(m_cia1, space, 0);
439   UINT8 cia1_pa = m_cia1->pa_r();
445440   
446441   int sela = BIT(cia1_pa, 6);
447442   int selb = BIT(cia1_pa, 7);
r18285r18286
462457
463458
464459//-------------------------------------------------
465//  mos6526_interface cia1_intf
460//  legacy_mos6526_interface cia1_intf
466461//-------------------------------------------------
467462
468463WRITE_LINE_MEMBER( c64_state::cia1_irq_w )
r18285r18286
489484
490485    */
491486
492   UINT8 cia0portb = mos6526_pb_r(m_cia1, space, 0);
487   UINT8 cia0portb = m_cia1->pb_r();
493488
494489   return cbm_common_cia0_port_a_r(m_cia1, cia0portb);
495490}
r18285r18286
511506
512507    */
513508
514   UINT8 cia0porta = mos6526_pa_r(m_cia1, space, 0);
509   UINT8 cia0porta = m_cia1->pa_r();
515510
516511   return cbm_common_cia0_port_b_r(m_cia1, cia0porta);
517512}
r18285r18286
536531   m_vic->lp_w(BIT(data, 4));
537532}
538533
539static const mos6526_interface cia1_intf =
534static MOS6526_INTERFACE( cia1_intf )
540535{
541536   DEVCB_DRIVER_LINE_MEMBER(c64_state, cia1_irq_w),
542537   DEVCB_NULL,
r18285r18286
550545
551546
552547//-------------------------------------------------
553//  mos6526_interface cia2_intf
548//  legacy_mos6526_interface cia2_intf
554549//-------------------------------------------------
555550
556551WRITE_LINE_MEMBER( c64_state::cia2_irq_w )
r18285r18286
619614   m_iec->data_w(!BIT(data, 5));
620615}
621616
622static const mos6526_interface cia2_intf =
617static MOS6526_INTERFACE( cia2_intf )
623618{
624619   DEVCB_DRIVER_LINE_MEMBER(c64_state, cia2_irq_w),
625620   DEVCB_DEVICE_LINE_MEMBER(C64_USER_PORT_TAG, c64_user_port_device, pc2_w),
r18285r18286
895890
896891static C64_USER_PORT_INTERFACE( user_intf )
897892{
898   DEVCB_DEVICE_LINE(MOS6526_1_TAG, mos6526_sp_w),
899   DEVCB_DEVICE_LINE(MOS6526_1_TAG, mos6526_cnt_w),
900   DEVCB_DEVICE_LINE(MOS6526_2_TAG, mos6526_sp_w),
901   DEVCB_DEVICE_LINE(MOS6526_2_TAG, mos6526_cnt_w),
902   DEVCB_DEVICE_LINE(MOS6526_2_TAG, mos6526_flag_w),
893   DEVCB_DEVICE_LINE_MEMBER(MOS6526_1_TAG, mos6526_device, sp_w),
894   DEVCB_DEVICE_LINE_MEMBER(MOS6526_1_TAG, mos6526_device, cnt_w),
895   DEVCB_DEVICE_LINE_MEMBER(MOS6526_2_TAG, mos6526_device, sp_w),
896   DEVCB_DEVICE_LINE_MEMBER(MOS6526_2_TAG, mos6526_device, cnt_w),
897   DEVCB_DEVICE_LINE_MEMBER(MOS6526_2_TAG, mos6526_device, flag_w),
903898   DEVCB_DRIVER_LINE_MEMBER(c64_state, exp_reset_w)
904899};
905900
r18285r18286
10061001
10071002   // devices
10081003   MCFG_PLS100_ADD(PLA_TAG)
1009   MCFG_MOS6526R1_ADD(MOS6526_1_TAG, VIC6567_CLOCK, 60, cia1_intf)
1010   MCFG_MOS6526R1_ADD(MOS6526_2_TAG, VIC6567_CLOCK, 60, cia2_intf)
1004   MCFG_MOS6526_ADD(MOS6526_1_TAG, VIC6567_CLOCK, 60, cia1_intf)
1005   MCFG_MOS6526_ADD(MOS6526_2_TAG, VIC6567_CLOCK, 60, cia2_intf)
10111006   MCFG_QUICKLOAD_ADD("quickload", cbm_c64, "p00,prg,t64", CBM_QUICKLOAD_DELAY_SECONDS)
10121007   MCFG_PET_DATASSETTE_PORT_ADD(PET_DATASSETTE_PORT_TAG, datassette_intf, cbm_datassette_devices, "c1530", NULL)
10131008   MCFG_CBM_IEC_ADD(iec_intf, "c1541")
r18285r18286
11051100
11061101   // devices
11071102   MCFG_PLS100_ADD(PLA_TAG)
1108   MCFG_MOS6526R1_ADD(MOS6526_1_TAG, VIC6569_CLOCK, 50, cia1_intf)
1109   MCFG_MOS6526R1_ADD(MOS6526_2_TAG, VIC6569_CLOCK, 50, cia2_intf)
1103   MCFG_MOS6526_ADD(MOS6526_1_TAG, VIC6569_CLOCK, 50, cia1_intf)
1104   MCFG_MOS6526_ADD(MOS6526_2_TAG, VIC6569_CLOCK, 50, cia2_intf)
11101105   MCFG_QUICKLOAD_ADD("quickload", cbm_c64, "p00,prg,t64", CBM_QUICKLOAD_DELAY_SECONDS)
11111106   MCFG_PET_DATASSETTE_PORT_ADD(PET_DATASSETTE_PORT_TAG, datassette_intf, cbm_datassette_devices, "c1530", NULL)
11121107   MCFG_CBM_IEC_ADD(iec_intf, "c1541")
r18285r18286
11821177
11831178   // devices
11841179   MCFG_PLS100_ADD(PLA_TAG)
1185   MCFG_MOS6526R1_ADD(MOS6526_1_TAG, VIC6569_CLOCK, 50, cia1_intf)
1186   MCFG_MOS6526R1_ADD(MOS6526_2_TAG, VIC6569_CLOCK, 50, cia2_intf)
1180   MCFG_MOS6526_ADD(MOS6526_1_TAG, VIC6569_CLOCK, 50, cia1_intf)
1181   MCFG_MOS6526_ADD(MOS6526_2_TAG, VIC6569_CLOCK, 50, cia2_intf)
11871182   MCFG_CBM_IEC_BUS_ADD(iec_intf)
11881183   MCFG_VCS_CONTROL_PORT_ADD(CONTROL1_TAG, vcs_control_port_devices, NULL, NULL)
11891184   MCFG_VCS_CONTROL_PORT_ADD(CONTROL2_TAG, vcs_control_port_devices, NULL, NULL)
trunk/src/mess/drivers/c65.c
r18285r18286
337337   MCFG_QUICKLOAD_ADD("quickload", cbm_c65, "p00,prg", CBM_QUICKLOAD_DELAY_SECONDS)
338338
339339   /* cia */
340   MCFG_MOS6526R1_ADD("cia_0", 3500000, 60, c65_cia0)
341   MCFG_MOS6526R1_ADD("cia_1", 3500000, 60, c65_cia1)
340   MCFG_LEGACY_MOS6526R1_ADD("cia_0", 3500000, 60, c65_cia0)
341   MCFG_LEGACY_MOS6526R1_ADD("cia_1", 3500000, 60, c65_cia1)
342342
343343   /* floppy from serial bus */
344344   MCFG_CBM_IEC_ADD(cbm_iec_intf, NULL)
r18285r18286
371371   /* cia */
372372   MCFG_DEVICE_REMOVE("cia_0")
373373   MCFG_DEVICE_REMOVE("cia_1")
374   MCFG_MOS6526R1_ADD("cia_0", 3500000, 50, c65_cia0)
375   MCFG_MOS6526R1_ADD("cia_1", 3500000, 50, c65_cia1)
374   MCFG_LEGACY_MOS6526R1_ADD("cia_0", 3500000, 50, c65_cia0)
375   MCFG_LEGACY_MOS6526R1_ADD("cia_1", 3500000, 50, c65_cia1)
376376MACHINE_CONFIG_END
377377
378378
trunk/src/mess/drivers/cbm2.c
r18285r18286
14311431
14321432
14331433//-------------------------------------------------
1434//  mos6526_interface cia_intf
1434//  MOS6526_INTERFACE( cia_intf )
14351435//-------------------------------------------------
14361436
14371437READ8_MEMBER( cbm2_state::cia_pa_r )
r18285r18286
15421542   //m_user->data2_w(data);
15431543}
15441544
1545static const mos6526_interface cia_intf =
1545static MOS6526_INTERFACE( cia_intf )
15461546{
15471547   DEVCB_DEVICE_LINE_MEMBER(MOS6525_1_TAG, tpi6525_device, i2_w),
15481548   DEVCB_NULL,//DEVCB_DEVICE_LINE_MEMBER(CBM2_USER_PORT_TAG, cbm2_user_port_device, pc_w),
r18285r18286
15631563{
15641564   m_cass_rd = state;
15651565
1566   mos6526_flag_w(m_cia, m_cass_rd && m_user_flag);
1566   m_cia->flag_w(m_cass_rd && m_user_flag);
15671567}
15681568
15691569static PET_DATASSETTE_PORT_INTERFACE( datassette_intf )
r18285r18286
18371837   MCFG_TPI6525_ADD(MOS6525_1_TAG, p500_tpi1_intf)
18381838   MCFG_TPI6525_ADD(MOS6525_2_TAG, p500_tpi2_intf)
18391839   MCFG_ACIA6551_ADD(MOS6551A_TAG)
1840   MCFG_MOS6526R1_ADD(MOS6526_TAG, VIC6567_CLOCK, 60, cia_intf)
1840   MCFG_MOS6526_ADD(MOS6526_TAG, VIC6567_CLOCK, 60, cia_intf)
18411841   MCFG_DS75160A_ADD(DS75160A_TAG, ds75160a_intf)
18421842   MCFG_DS75161A_ADD(DS75161A_TAG, ds75161a_intf)
18431843   MCFG_CBM_IEEE488_ADD(ieee488_intf, "c8050")
r18285r18286
18871887   MCFG_TPI6525_ADD(MOS6525_1_TAG, p500_tpi1_intf)
18881888   MCFG_TPI6525_ADD(MOS6525_2_TAG, p500_tpi2_intf)
18891889   MCFG_ACIA6551_ADD(MOS6551A_TAG)
1890   MCFG_MOS6526R1_ADD(MOS6526_TAG, VIC6569_CLOCK, 50, cia_intf)
1890   MCFG_MOS6526_ADD(MOS6526_TAG, VIC6569_CLOCK, 50, cia_intf)
18911891   MCFG_DS75160A_ADD(DS75160A_TAG, ds75160a_intf)
18921892   MCFG_DS75161A_ADD(DS75161A_TAG, ds75161a_intf)
18931893   MCFG_CBM_IEEE488_ADD(ieee488_intf, "c8050")
r18285r18286
19441944   MCFG_TPI6525_ADD(MOS6525_1_TAG, tpi1_intf)
19451945   MCFG_TPI6525_ADD(MOS6525_2_TAG, tpi2_intf)
19461946   MCFG_ACIA6551_ADD(MOS6551A_TAG)
1947   MCFG_MOS6526R1_ADD(MOS6526_TAG, XTAL_18MHz/9, 60, cia_intf)
1947   MCFG_MOS6526_ADD(MOS6526_TAG, XTAL_18MHz/9, 60, cia_intf)
19481948   MCFG_DS75160A_ADD(DS75160A_TAG, ds75160a_intf)
19491949   MCFG_DS75161A_ADD(DS75161A_TAG, ds75161a_intf)
19501950   MCFG_CBM_IEEE488_ADD(ieee488_intf, "c8050")
r18285r18286
19911991   MCFG_MACHINE_START_OVERRIDE(cbm2_state, cbm2_pal)
19921992
19931993   MCFG_DEVICE_REMOVE(MOS6526_TAG)
1994   MCFG_MOS6526R1_ADD(MOS6526_TAG, XTAL_18MHz/9, 50, cia_intf)
1994   MCFG_MOS6526_ADD(MOS6526_TAG, XTAL_18MHz/9, 50, cia_intf)
19951995MACHINE_CONFIG_END
19961996
19971997
r18285r18286
20772077   MCFG_TPI6525_ADD(MOS6525_2_TAG, hp_tpi2_intf)
20782078
20792079   MCFG_DEVICE_REMOVE(MOS6526_TAG)
2080   MCFG_MOS6526R1_ADD(MOS6526_TAG, XTAL_18MHz/9, 50, cia_intf)
2080   MCFG_MOS6526_ADD(MOS6526_TAG, XTAL_18MHz/9, 50, cia_intf)
20812081MACHINE_CONFIG_END
20822082
20832083
trunk/src/mess/drivers/ami1200.c
r18285r18286
256256}
257257
258258
259static const mos6526_interface a1200_cia_0_intf =
259static const legacy_mos6526_interface a1200_cia_0_intf =
260260{
261261   DEVCB_DEVICE_LINE("cia_0", amiga_cia_0_irq),                           /* irq_func */
262262   DEVCB_NULL,   /* pc_func */
r18285r18286
268268   DEVCB_DRIVER_MEMBER(ami1200_state,ami1200_cia_0_portb_w)      /* port B */
269269};
270270
271static const mos6526_interface a1200_cia_1_intf =
271static const legacy_mos6526_interface a1200_cia_1_intf =
272272{
273273   DEVCB_DEVICE_LINE("cia_1", amiga_cia_1_irq),                           /* irq_func */
274274   DEVCB_NULL,   /* pc_func */
r18285r18286
317317   MCFG_SOUND_ROUTE(3, "lspeaker", 0.25)
318318
319319   /* cia */
320   MCFG_MOS8520_ADD("cia_0", AMIGA_68EC020_NTSC_CLOCK / 10, 0, a1200_cia_0_intf)
321   MCFG_MOS8520_ADD("cia_1", AMIGA_68EC020_NTSC_CLOCK / 10, 0, a1200_cia_1_intf)
320   MCFG_LEGACY_MOS8520_ADD("cia_0", AMIGA_68EC020_NTSC_CLOCK / 10, 0, a1200_cia_0_intf)
321   MCFG_LEGACY_MOS8520_ADD("cia_1", AMIGA_68EC020_NTSC_CLOCK / 10, 0, a1200_cia_1_intf)
322322
323323   /* fdc */
324324   MCFG_AMIGA_FDC_ADD("fdc", AMIGA_68EC020_NTSC_CLOCK/2)
trunk/src/mess/drivers/vic10.c
r18285r18286
6868   }
6969   else if (offset >= 0xdc00 && offset < 0xe000)
7070   {
71      data = mos6526_r(m_cia, space, offset & 0x0f);
71      data = m_cia->read(space, offset & 0x0f);
7272   }
7373   else if (offset >= 0xe000)
7474   {
r18285r18286
111111   }
112112   else if (offset >= 0xdc00 && offset < 0xe000)
113113   {
114      mos6526_w(m_cia, space, offset & 0x0f, data);
114      m_cia->write(space, offset & 0x0f, data);
115115   }
116116
117117   m_exp->cd_w(space, offset, data, lorom, uprom, exram);
r18285r18286
251251//  sid6581_interface sid_intf
252252//-------------------------------------------------
253253
254UINT8 vic10_state::paddle_read(address_space &space, int which)
254READ8_MEMBER( vic10_state::sid_potx_r )
255255{
256   int pot1 = 0xff, pot2 = 0xff, pot3 = 0xff, pot4 = 0xff, temp;
257   UINT8 cia0porta = mos6526_pa_r(m_cia, space, 0);
258   int controller1 = ioport("CTRLSEL")->read() & 0x07;
259   int controller2 = ioport("CTRLSEL")->read() & 0x70;
260   // Notice that only a single input is defined for Mouse & Lightpen in both ports
261   switch (controller1)
262   {
263      case 0x01:
264         if (which)
265            pot2 = ioport("PADDLE2")->read();
266         else
267            pot1 = ioport("PADDLE1")->read();
268         break;
256   UINT8 cia_pa = m_cia->pa_r();
257   
258   int sela = BIT(cia_pa, 6);
259   int selb = BIT(cia_pa, 7);
269260
270      case 0x02:
271         if (which)
272            pot2 = ioport("TRACKY")->read();
273         else
274            pot1 = ioport("TRACKX")->read();
275         break;
261   UINT8 data = 0;
276262
277      case 0x03:
278         if (which && (ioport("JOY1_2B")->read() & 0x20))   // Joy1 Button 2
279            pot1 = 0x00;
280         break;
263   if (sela) data = m_joy1->pot_x_r();
264   if (selb) data = m_joy2->pot_x_r();
281265
282      case 0x04:
283         if (which)
284            pot2 = ioport("LIGHTY")->read();
285         else
286            pot1 = ioport("LIGHTX")->read();
287         break;
266   return data;
267}
288268
289      case 0x06:
290         if (which && (ioport("OTHER")->read() & 0x04))   // Lightpen Signal
291            pot2 = 0x00;
292         break;
269READ8_MEMBER( vic10_state::sid_poty_r )
270{
271   UINT8 cia_pa = m_cia->pa_r();
272   
273   int sela = BIT(cia_pa, 6);
274   int selb = BIT(cia_pa, 7);
293275
294      case 0x00:
295      case 0x07:
296         break;
276   UINT8 data = 0;
297277
298      default:
299         logerror("Invalid Controller Setting %d\n", controller1);
300         break;
301   }
278   if (sela) data = m_joy1->pot_y_r();
279   if (selb) data = m_joy2->pot_y_r();
302280
303   switch (controller2)
304   {
305      case 0x10:
306         if (which)
307            pot4 = ioport("PADDLE4")->read();
308         else
309            pot3 = ioport("PADDLE3")->read();
310         break;
311
312      case 0x20:
313         if (which)
314            pot4 = ioport("TRACKY")->read();
315         else
316            pot3 = ioport("TRACKX")->read();
317         break;
318
319      case 0x30:
320         if (which && (ioport("JOY2_2B")->read() & 0x20))   // Joy2 Button 2
321            pot4 = 0x00;
322         break;
323
324      case 0x40:
325         if (which)
326            pot4 = ioport("LIGHTY")->read();
327         else
328            pot3 = ioport("LIGHTX")->read();
329         break;
330
331      case 0x60:
332         if (which && (ioport("OTHER")->read() & 0x04))   // Lightpen Signal
333            pot4 = 0x00;
334         break;
335
336      case 0x00:
337      case 0x70:
338         break;
339
340      default:
341         logerror("Invalid Controller Setting %d\n", controller1);
342         break;
343   }
344
345   if (ioport("CTRLSEL")->read() & 0x80)      // Swap
346   {
347      temp = pot1; pot1 = pot3; pot3 = temp;
348      temp = pot2; pot2 = pot4; pot4 = temp;
349   }
350
351   switch (cia0porta & 0xc0)
352   {
353      case 0x40:
354         return which ? pot2 : pot1;
355
356      case 0x80:
357         return which ? pot4 : pot3;
358
359      case 0xc0:
360         return which ? pot2 : pot1;
361
362      default:
363         return 0;
364   }
281   return data;
365282}
366283
367READ8_MEMBER( vic10_state::sid_potx_r )
368{
369   return paddle_read(space, 0);
370}
371
372READ8_MEMBER( vic10_state::sid_poty_r )
373{
374   return paddle_read(space, 1);
375}
376
377284static MOS6581_INTERFACE( sid_intf )
378285{
379286   DEVCB_DRIVER_MEMBER(vic10_state, sid_potx_r),
r18285r18286
382289
383290
384291//-------------------------------------------------
385//  mos6526_interface cia_intf
292//  MOS6526_INTERFACE( cia_intf )
386293//-------------------------------------------------
387294
388295WRITE_LINE_MEMBER( vic10_state::cia_irq_w )
r18285r18286
409316
410317    */
411318
412   UINT8 cia0portb = mos6526_pb_r(m_cia, space, 0);
319   UINT8 cia0portb = m_cia->pb_r();
413320
414321   return cbm_common_cia0_port_a_r(m_cia, cia0portb);
415322}
r18285r18286
431338
432339    */
433340
434   UINT8 cia0porta = mos6526_pa_r(m_cia, space, 0);
341   UINT8 cia0porta = m_cia->pa_r();
435342
436343   return cbm_common_cia0_port_b_r(m_cia, cia0porta);
437344}
r18285r18286
456363   m_vic->lp_w(BIT(data, 4));
457364}
458365
459static const mos6526_interface cia_intf =
366static MOS6526_INTERFACE( cia_intf )
460367{
461368   DEVCB_DRIVER_LINE_MEMBER(vic10_state, cia_irq_w),
462369   DEVCB_NULL,
r18285r18286
543450
544451static PET_DATASSETTE_PORT_INTERFACE( datassette_intf )
545452{
546   DEVCB_DEVICE_LINE(MOS6526_TAG, mos6526_flag_w)
453   DEVCB_DEVICE_LINE_MEMBER(MOS6526_TAG, mos6526_device, flag_w)
547454};
548455
549456
r18285r18286
561468static VIC10_EXPANSION_INTERFACE( expansion_intf )
562469{
563470   DEVCB_DRIVER_LINE_MEMBER(vic10_state, exp_irq_w),
564   DEVCB_DEVICE_LINE(MOS6526_TAG, mos6526_sp_w),
565   DEVCB_DEVICE_LINE(MOS6526_TAG, mos6526_cnt_w),
471   DEVCB_DEVICE_LINE_MEMBER(MOS6526_TAG, mos6526_device, sp_w),
472   DEVCB_DEVICE_LINE_MEMBER(MOS6526_TAG, mos6526_device, cnt_w),
566473   DEVCB_CPU_INPUT_LINE(M6510_TAG, INPUT_LINE_RESET)
567474};
568475
r18285r18286
629536   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
630537
631538   // devices
632   MCFG_MOS6526R1_ADD(MOS6526_TAG, VIC6566_CLOCK, 60, cia_intf)
539   MCFG_MOS6526_ADD(MOS6526_TAG, VIC6566_CLOCK, 60, cia_intf)
633540   MCFG_PET_DATASSETTE_PORT_ADD(PET_DATASSETTE_PORT_TAG, datassette_intf, cbm_datassette_devices, NULL, NULL)
541   MCFG_VCS_CONTROL_PORT_ADD(CONTROL1_TAG, vcs_control_port_devices, NULL, NULL)
542   MCFG_VCS_CONTROL_PORT_ADD(CONTROL2_TAG, vcs_control_port_devices, NULL, NULL)
634543   MCFG_VIC10_EXPANSION_SLOT_ADD(VIC10_EXPANSION_SLOT_TAG, VIC6566_CLOCK, expansion_intf, vic10_expansion_cards, NULL, NULL)
635544
636545   // software list
trunk/src/mess/drivers/c128.c
r18285r18286
555555   AM_RANGE(0xd500, 0xd5ff) AM_READWRITE(mmu8722_port_r, mmu8722_port_w)
556556   AM_RANGE(0xd600, 0xd600) AM_MIRROR(0x1fe) AM_DEVREADWRITE(MOS8563_TAG, mos8563_device, status_r, address_w)
557557   AM_RANGE(0xd601, 0xd601) AM_MIRROR(0x1fe) AM_DEVREADWRITE(MOS8563_TAG, mos8563_device, register_r, register_w)
558   AM_RANGE(0xdc00, 0xdcff) AM_DEVREADWRITE_LEGACY(MOS6526_1_TAG, mos6526_r, mos6526_w)
559   AM_RANGE(0xdd00, 0xddff) AM_DEVREADWRITE_LEGACY(MOS6526_2_TAG, mos6526_r, mos6526_w)
558   AM_RANGE(0xdc00, 0xdc0f) AM_MIRROR(0xf0) AM_DEVREADWRITE(MOS6526_1_TAG, mos6526_device, read, write)
559   AM_RANGE(0xdd00, 0xdd0f) AM_MIRROR(0xf0) AM_DEVREADWRITE(MOS6526_2_TAG, mos6526_device, read, write)
560560/*  AM_RANGE(0xdf00, 0xdfff) AM_READWRITE_LEGACY(dma_port_r, dma_port_w) */
561561ADDRESS_MAP_END
562562
r18285r18286
968968
969969READ8_MEMBER( c128_state::sid_potx_r )
970970{
971   UINT8 cia1_pa = mos6526_pa_r(m_cia1, space, 0);
971   UINT8 cia1_pa = m_cia1->pa_r();
972972   
973973   int sela = BIT(cia1_pa, 6);
974974   int selb = BIT(cia1_pa, 7);
r18285r18286
983983
984984READ8_MEMBER( c128_state::sid_poty_r )
985985{
986   UINT8 cia1_pa = mos6526_pa_r(m_cia1, space, 0);
986   UINT8 cia1_pa = m_cia1->pa_r();
987987   
988988   int sela = BIT(cia1_pa, 6);
989989   int selb = BIT(cia1_pa, 7);
r18285r18286
10381038
10391039static PET_DATASSETTE_PORT_INTERFACE( datassette_intf )
10401040{
1041   DEVCB_DEVICE_LINE(MOS6526_1_TAG, mos6526_flag_w)
1041   DEVCB_DEVICE_LINE_MEMBER(MOS6526_1_TAG, mos6526_device, flag_w)
10421042};
10431043
10441044
r18285r18286
11091109   // devices
11101110   MCFG_MOS8722_ADD(MOS8722_TAG, mmu_intf)
11111111   MCFG_MOS8721_ADD(MOS8721_TAG)
1112   MCFG_MOS6526R1_ADD(MOS6526_1_TAG, VIC6567_CLOCK, 60, c128_cia1_intf)
1113   MCFG_MOS6526R1_ADD(MOS6526_2_TAG, VIC6567_CLOCK, 60, c128_cia2_intf)
1112   MCFG_MOS6526_ADD(MOS6526_1_TAG, VIC6567_CLOCK, 60, c128_cia1_intf)
1113   MCFG_MOS6526_ADD(MOS6526_2_TAG, VIC6567_CLOCK, 60, c128_cia2_intf)
11141114   MCFG_QUICKLOAD_ADD("quickload", cbm_c64, "p00,prg", CBM_QUICKLOAD_DELAY_SECONDS)
11151115   MCFG_PET_DATASSETTE_PORT_ADD(PET_DATASSETTE_PORT_TAG, datassette_intf, cbm_datassette_devices, "c1530", NULL)
11161116   MCFG_VCS_CONTROL_PORT_ADD(CONTROL1_TAG, vcs_control_port_devices, NULL, NULL)
r18285r18286
12161216   // devices
12171217   MCFG_MOS8722_ADD(MOS8722_TAG, mmu_intf)
12181218   MCFG_MOS8721_ADD(MOS8721_TAG)
1219   MCFG_MOS6526R1_ADD(MOS6526_1_TAG, VIC6569_CLOCK, 50, c128_cia1_intf)
1220   MCFG_MOS6526R1_ADD(MOS6526_2_TAG, VIC6569_CLOCK, 50, c128_cia2_intf)
1219   MCFG_MOS6526_ADD(MOS6526_1_TAG, VIC6569_CLOCK, 50, c128_cia1_intf)
1220   MCFG_MOS6526_ADD(MOS6526_2_TAG, VIC6569_CLOCK, 50, c128_cia2_intf)
12211221   MCFG_QUICKLOAD_ADD("quickload", cbm_c64, "p00,prg", CBM_QUICKLOAD_DELAY_SECONDS)
12221222   MCFG_PET_DATASSETTE_PORT_ADD(PET_DATASSETTE_PORT_TAG, datassette_intf, cbm_datassette_devices, "c1530", NULL)
12231223   MCFG_VCS_CONTROL_PORT_ADD(CONTROL1_TAG, vcs_control_port_devices, NULL, NULL)
trunk/src/mame/drivers/upscope.c
r18285r18286
283283 *
284284 *************************************/
285285
286static const mos6526_interface cia_0_intf =
286static const legacy_mos6526_interface cia_0_intf =
287287{
288288   DEVCB_LINE(amiga_cia_0_irq),                              /* irq_func */
289289   DEVCB_NULL,   /* pc_func */
r18285r18286
295295   DEVCB_DRIVER_MEMBER(upscope_state,upscope_cia_0_portb_w)   /* port B */
296296};
297297
298static const mos6526_interface cia_1_intf =
298static const legacy_mos6526_interface cia_1_intf =
299299{
300300   DEVCB_LINE(amiga_cia_1_irq),                              /* irq_func */
301301   DEVCB_NULL,   /* pc_func */
r18285r18286
341341   MCFG_SOUND_ROUTE(3, "rspeaker", 0.50)
342342
343343   /* cia */
344   MCFG_MOS8520_ADD("cia_0", AMIGA_68000_NTSC_CLOCK / 10, 0, cia_0_intf)
345   MCFG_MOS8520_ADD("cia_1", AMIGA_68000_NTSC_CLOCK / 10, 0, cia_1_intf)
344   MCFG_LEGACY_MOS8520_ADD("cia_0", AMIGA_68000_NTSC_CLOCK / 10, 0, cia_0_intf)
345   MCFG_LEGACY_MOS8520_ADD("cia_1", AMIGA_68000_NTSC_CLOCK / 10, 0, cia_1_intf)
346346
347347   /* fdc */
348348   MCFG_AMIGA_FDC_ADD("fdc", AMIGA_68000_NTSC_CLOCK)
trunk/src/mame/drivers/cd32.c
r18285r18286
725725 *
726726 *************************************/
727727
728static const mos6526_interface cia_0_intf =
728static const legacy_mos6526_interface cia_0_intf =
729729{
730730   DEVCB_LINE(amiga_cia_0_irq),                           /* irq_func */
731731   DEVCB_NULL,   /* pc_func */
r18285r18286
737737   DEVCB_DRIVER_MEMBER(cd32_state,cd32_cia_0_portb_w)      /* port B */
738738};
739739
740static const mos6526_interface cia_1_intf =
740static const legacy_mos6526_interface cia_1_intf =
741741{
742742   DEVCB_LINE(amiga_cia_1_irq),                           /* irq_func */
743743   DEVCB_NULL,   /* pc_func */
r18285r18286
800800   MCFG_SOUND_ROUTE( 1, "rspeaker", 0.50 )
801801
802802   /* cia */
803   MCFG_MOS8520_ADD("cia_0", AMIGA_68EC020_PAL_CLOCK / 10, 0, cia_0_intf)
804   MCFG_MOS8520_ADD("cia_1", AMIGA_68EC020_PAL_CLOCK / 10, 0, cia_1_intf)
803   MCFG_LEGACY_MOS8520_ADD("cia_0", AMIGA_68EC020_PAL_CLOCK / 10, 0, cia_0_intf)
804   MCFG_LEGACY_MOS8520_ADD("cia_1", AMIGA_68EC020_PAL_CLOCK / 10, 0, cia_1_intf)
805805
806806   MCFG_MICROTOUCH_ADD( "microtouch", cd32_microtouch_config )
807807
trunk/src/mame/drivers/arcadia.c
r18285r18286
284284 *
285285 *************************************/
286286
287static const mos6526_interface cia_0_intf =
287static const legacy_mos6526_interface cia_0_intf =
288288{
289289   DEVCB_LINE(amiga_cia_0_irq),                              /* irq_func */
290290   DEVCB_NULL,   /* pc_func */
r18285r18286
296296   DEVCB_DRIVER_MEMBER(arcadia_amiga_state,arcadia_cia_0_portb_w)   /* port B */
297297};
298298
299static const mos6526_interface cia_1_intf =
299static const legacy_mos6526_interface cia_1_intf =
300300{
301301   DEVCB_LINE(amiga_cia_1_irq),                              /* irq_func */
302302   DEVCB_NULL,   /* pc_func */
r18285r18286
342342   MCFG_SOUND_ROUTE(3, "lspeaker", 0.50)
343343
344344   /* cia */
345   MCFG_MOS8520_ADD("cia_0", AMIGA_68000_NTSC_CLOCK / 10, 0, cia_0_intf)
346   MCFG_MOS8520_ADD("cia_1", AMIGA_68000_NTSC_CLOCK / 10, 0, cia_1_intf)
345   MCFG_LEGACY_MOS8520_ADD("cia_0", AMIGA_68000_NTSC_CLOCK / 10, 0, cia_0_intf)
346   MCFG_LEGACY_MOS8520_ADD("cia_1", AMIGA_68000_NTSC_CLOCK / 10, 0, cia_1_intf)
347347
348348   /* fdc */
349349   MCFG_AMIGA_FDC_ADD("fdc", AMIGA_68000_NTSC_CLOCK)
trunk/src/mame/drivers/alg.c
r18285r18286
412412 *
413413 *************************************/
414414
415static const mos6526_interface cia_0_intf =
415static const legacy_mos6526_interface cia_0_intf =
416416{
417417   DEVCB_LINE(amiga_cia_0_irq),                        /* irq_func */
418418   DEVCB_NULL,   /* pc_func */
r18285r18286
424424   DEVCB_DRIVER_MEMBER(alg_state,alg_cia_0_portb_w)   /* port B */
425425};
426426
427static const mos6526_interface cia_1_intf =
427static const legacy_mos6526_interface cia_1_intf =
428428{
429429   DEVCB_LINE(amiga_cia_1_irq),                        /* irq_func */
430430   DEVCB_NULL,   /* pc_func */
r18285r18286
475475   MCFG_SOUND_ROUTE(1, "rspeaker", 1.0)
476476
477477   /* cia */
478   MCFG_MOS8520_ADD("cia_0", AMIGA_68000_NTSC_CLOCK / 10, 0, cia_0_intf)
479   MCFG_MOS8520_ADD("cia_1", AMIGA_68000_NTSC_CLOCK / 10, 0, cia_1_intf)
478   MCFG_LEGACY_MOS8520_ADD("cia_0", AMIGA_68000_NTSC_CLOCK / 10, 0, cia_0_intf)
479   MCFG_LEGACY_MOS8520_ADD("cia_1", AMIGA_68000_NTSC_CLOCK / 10, 0, cia_1_intf)
480480
481481   /* fdc */
482482   MCFG_AMIGA_FDC_ADD("fdc", AMIGA_68000_NTSC_CLOCK)
trunk/src/mame/drivers/mquake.c
r18285r18286
313313 *
314314 *************************************/
315315
316static const mos6526_interface cia_0_intf =
316static const legacy_mos6526_interface cia_0_intf =
317317{
318318   DEVCB_LINE(amiga_cia_0_irq),                           /* irq_func */
319319   DEVCB_NULL,   /* pc_func */
r18285r18286
325325   DEVCB_HANDLER(mquake_cia_0_portb_w)   /* port B */
326326};
327327
328static const mos6526_interface cia_1_intf =
328static const legacy_mos6526_interface cia_1_intf =
329329{
330330   DEVCB_LINE(amiga_cia_1_irq),                           /* irq_func */
331331   DEVCB_NULL,   /* pc_func */
r18285r18286
378378   MCFG_SOUND_ROUTE(1, "rspeaker", 0.50)
379379
380380   /* cia */
381   MCFG_MOS8520_ADD("cia_0", AMIGA_68000_NTSC_CLOCK / 10, 0, cia_0_intf)
382   MCFG_MOS8520_ADD("cia_1", AMIGA_68000_NTSC_CLOCK / 10, 0, cia_1_intf)
381   MCFG_LEGACY_MOS8520_ADD("cia_0", AMIGA_68000_NTSC_CLOCK / 10, 0, cia_0_intf)
382   MCFG_LEGACY_MOS8520_ADD("cia_1", AMIGA_68000_NTSC_CLOCK / 10, 0, cia_1_intf)
383383
384384   /* fdc */
385385   MCFG_AMIGA_FDC_ADD("fdc", AMIGA_68000_NTSC_CLOCK)

Previous 199869 Revisions Next


© 1997-2024 The MAME Team