Previous 199869 Revisions Next

r20509 Saturday 26th January, 2013 at 20:23:50 UTC by Ryan Holtz
[CDI] Modernized CD-i and removed tag lookups [MooglyGuy]
[src/mame/drivers]cdi.c
[src/mame/includes]cdi.h
[src/mame/machine]cdi070.c cdi070.h cdicdic.c cdicdic.h cdislave.c cdislave.h
[src/mame/video]mcd212.c

trunk/src/mame/machine/cdislave.c
r20508r20509
5050//  MEMBER FUNCTIONS
5151//**************************************************************************
5252
53TIMER_CALLBACK( cdislave_device::trigger_readback_int )
53TIMER_CALLBACK_MEMBER( cdislave_device::trigger_readback_int )
5454{
55   cdislave_device *slave = static_cast<cdislave_device *>(machine.device("slave"));
56   slave->readback_trigger();
57}
55   cdi_state *state = machine().driver_data<cdi_state>();
5856
59void cdislave_device::readback_trigger()
60{
6157   verboselog(machine(), 0, "Asserting IRQ2\n" );
62   machine().device("maincpu")->execute().set_input_line_vector(M68K_IRQ_2, 26);
63   machine().device("maincpu")->execute().set_input_line(M68K_IRQ_2, ASSERT_LINE);
58   state->m_maincpu->set_input_line_vector(M68K_IRQ_2, 26);
59   state->m_maincpu->set_input_line(M68K_IRQ_2, ASSERT_LINE);
6460   m_interrupt_timer->adjust(attotime::never);
6561}
6662
r20508r20509
7975
8076void cdislave_device::perform_mouse_update()
8177{
82   UINT16 x = machine().root_device().ioport("MOUSEX")->read();
83   UINT16 y = machine().root_device().ioport("MOUSEY")->read();
84   UINT8 buttons = machine().root_device().ioport("MOUSEBTN")->read();
78   cdi_state *state = machine().driver_data<cdi_state>();
8579
80   UINT16 x = state->m_mousex->read();
81   UINT16 y = state->m_mousey->read();
82   UINT8 buttons = state->m_mousebtn->read();
83
8684   UINT16 old_mouse_x = m_real_mouse_x;
8785   UINT16 old_mouse_y = m_real_mouse_y;
8886
r20508r20509
122120   perform_mouse_update();
123121}
124122
125READ16_DEVICE_HANDLER( slave_r )
123READ16_MEMBER( cdislave_device::slave_r )
126124{
127   return downcast<cdislave_device *>(device)->register_read(offset, mem_mask);
128}
125   cdi_state *state = machine().driver_data<cdi_state>();
129126
130UINT16 cdislave_device::register_read(const UINT32 offset, const UINT16 mem_mask)
131{
132127   if(m_channel[offset].m_out_count)
133128   {
134129      UINT8 ret = m_channel[offset].m_out_buf[m_channel[offset].m_out_index];
r20508r20509
144139            case 0xf4:
145140            case 0xf7:
146141               verboselog(machine(), 0, "slave_r: De-asserting IRQ2\n" );
147               machine().device("maincpu")->execute().set_input_line(M68K_IRQ_2, CLEAR_LINE);
142               state->m_maincpu->set_input_line(M68K_IRQ_2, CLEAR_LINE);
148143               break;
149144         }
150145      }
r20508r20509
180175   }
181176}
182177
183WRITE16_DEVICE_HANDLER( slave_w )
178WRITE16_MEMBER( cdislave_device::slave_w )
184179{
185   downcast<cdislave_device *>(device)->register_write(offset, data, mem_mask);
186}
187
188void cdislave_device::register_write(const UINT32 offset, const UINT16 data, const UINT16 mem_mask)
189{
190180   cdi_state *state = machine().driver_data<cdi_state>();
191181
192182   switch(offset)
r20508r20509
429419cdislave_device::cdislave_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
430420   : device_t(mconfig, MACHINE_CDISLAVE, "CDISLAVE", tag, owner, clock)
431421{
432   init();
433422}
434423
435424//-------------------------------------------------
r20508r20509
438427
439428void cdislave_device::device_start()
440429{
441   register_globals();
442
443   m_interrupt_timer = machine().scheduler().timer_alloc(FUNC(trigger_readback_int));
444   m_interrupt_timer->adjust(attotime::never);
445}
446
447//-------------------------------------------------
448//  device_reset - device-specific reset
449//-------------------------------------------------
450
451void cdislave_device::device_reset()
452{
453   init();
454}
455
456void cdislave_device::init()
457{
458   for(INT32 index = 0; index < 4; index++)
459   {
460      m_channel[index].m_out_buf[0] = 0;
461      m_channel[index].m_out_buf[1] = 0;
462      m_channel[index].m_out_buf[2] = 0;
463      m_channel[index].m_out_buf[3] = 0;
464      m_channel[index].m_out_index = 0;
465      m_channel[index].m_out_count = 0;
466      m_channel[index].m_out_cmd = 0;
467   }
468
469   memset(m_in_buf, 0, 17);
470   m_in_index = 0;
471   m_in_count = 0;
472
473   m_polling_active = 0;
474
475   m_xbus_interrupt_enable = 0;
476
477   memset(m_lcd_state, 0, 16);
478
479   m_real_mouse_x = 0xffff;
480   m_real_mouse_y = 0xffff;
481
482   m_fake_mouse_x = 0;
483   m_fake_mouse_y = 0;
484}
485
486void cdislave_device::register_globals()
487{
488430   save_item(NAME(m_channel[0].m_out_buf[0]));
489431   save_item(NAME(m_channel[0].m_out_buf[1]));
490432   save_item(NAME(m_channel[0].m_out_buf[2]));
r20508r20509
529471
530472   save_item(NAME(m_fake_mouse_x));
531473   save_item(NAME(m_fake_mouse_y));
474
475   m_interrupt_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(cdislave_device::trigger_readback_int), this));
476   m_interrupt_timer->adjust(attotime::never);
532477}
478
479//-------------------------------------------------
480//  device_reset - device-specific reset
481//-------------------------------------------------
482
483void cdislave_device::device_reset()
484{
485   for(INT32 index = 0; index < 4; index++)
486   {
487      m_channel[index].m_out_buf[0] = 0;
488      m_channel[index].m_out_buf[1] = 0;
489      m_channel[index].m_out_buf[2] = 0;
490      m_channel[index].m_out_buf[3] = 0;
491      m_channel[index].m_out_index = 0;
492      m_channel[index].m_out_count = 0;
493      m_channel[index].m_out_cmd = 0;
494   }
495
496   memset(m_in_buf, 0, 17);
497   m_in_index = 0;
498   m_in_count = 0;
499
500   m_polling_active = 0;
501
502   m_xbus_interrupt_enable = 0;
503
504   memset(m_lcd_state, 0, 16);
505
506   m_real_mouse_x = 0xffff;
507   m_real_mouse_y = 0xffff;
508
509   m_fake_mouse_x = 0;
510   m_fake_mouse_y = 0;
511}
trunk/src/mame/machine/cdislave.h
r20508r20509
5151
5252   UINT8* get_lcd_state() { return m_lcd_state; }
5353   void readback_trigger();
54   void register_write(const UINT32 offset, const UINT16 data, const UINT16 mem_mask);
55   UINT16 register_read(const UINT32 offset, const UINT16 mem_mask);
5654
55   DECLARE_READ16_MEMBER( slave_r );
56   DECLARE_WRITE16_MEMBER( slave_w );
57
5758protected:
5859   // device-level overrides
5960   virtual void device_start();
r20508r20509
6263   virtual void device_clock_changed() { }
6364
6465   // internal callbacks
65   static TIMER_CALLBACK( trigger_readback_int );
66   TIMER_CALLBACK_MEMBER( trigger_readback_int );
6667
6768private:
6869   // internal state
r20508r20509
9697   UINT16 m_fake_mouse_x;
9798   UINT16 m_fake_mouse_y;
9899
99   void register_globals();
100   void init();
101
102100   // static internal members
103101
104102   // non-static internal members
r20508r20509
111109// device type definition
112110extern const device_type MACHINE_CDISLAVE;
113111
114
115
116//**************************************************************************
117//  READ/WRITE HANDLERS
118//**************************************************************************
119
120DECLARE_READ16_DEVICE_HANDLER( slave_r );
121DECLARE_WRITE16_DEVICE_HANDLER( slave_w );
122
123
124112#endif // __CDISLAVE_H__
trunk/src/mame/machine/cdicdic.c
r20508r20509
530530}
531531
532532// After an appropriate delay for decoding to take place...
533TIMER_CALLBACK( cdicdic_device::audio_sample_trigger )
533TIMER_CALLBACK_MEMBER( cdicdic_device::audio_sample_trigger )
534534{
535   cdicdic_device *cdic = static_cast<cdicdic_device *>(machine.device("cdic"));
536   cdic->sample_trigger();
535   sample_trigger();
537536}
538537
539538void cdicdic_device::sample_trigger()
540539{
540   cdi_state *state = machine().driver_data<cdi_state>();
541
541542   if(m_decode_addr == 0xffff)
542543   {
543544      verboselog(machine(), 0, "Decode stop requested, stopping playback\n" );
r20508r20509
553554
554555      // Set the CDIC interrupt line
555556      verboselog(machine(), 0, "Setting CDIC interrupt line for soundmap decode\n" );
556      machine().device("maincpu")->execute().set_input_line_vector(M68K_IRQ_4, 128);
557      machine().device("maincpu")->execute().set_input_line(M68K_IRQ_4, ASSERT_LINE);
557      state->m_maincpu->set_input_line_vector(M68K_IRQ_4, 128);
558      state->m_maincpu->set_input_line(M68K_IRQ_4, ASSERT_LINE);
558559   }
559560   else
560561   {
r20508r20509
590591   }
591592}
592593
593TIMER_CALLBACK( cdicdic_device::trigger_readback_int )
594TIMER_CALLBACK_MEMBER( cdicdic_device::trigger_readback_int )
594595{
595   cdicdic_device *cdic = static_cast<cdicdic_device *>(machine.device("cdic"));
596   cdic->process_delayed_command();
596   process_delayed_command();
597597}
598598
599599void cdicdic_device::process_delayed_command()
600600{
601   cdi_state *state = machine().driver_data<cdi_state>();
602
601603   switch(m_command)
602604   {
603605      case 0x23: // Reset Mode 1
r20508r20509
707709
708710               //printf( "Setting CDIC interrupt line\n" );
709711               verboselog(machine(), 0, "Setting CDIC interrupt line for audio sector\n" );
710               machine().device("maincpu")->execute().set_input_line_vector(M68K_IRQ_4, 128);
711               machine().device("maincpu")->execute().set_input_line(M68K_IRQ_4, ASSERT_LINE);
712               state->m_maincpu->set_input_line_vector(M68K_IRQ_4, 128);
713               state->m_maincpu->set_input_line(M68K_IRQ_4, ASSERT_LINE);
712714            }
713715            else if((buffer[CDIC_SECTOR_SUBMODE2] & (CDIC_SUBMODE_DATA | CDIC_SUBMODE_AUDIO | CDIC_SUBMODE_VIDEO)) == 0x00)
714716            {
r20508r20509
726728               {
727729                  //printf( "Setting CDIC interrupt line\n" );
728730                  verboselog(machine(), 0, "Setting CDIC interrupt line for message sector\n" );
729                  machine().device("maincpu")->execute().set_input_line_vector(M68K_IRQ_4, 128);
730                  machine().device("maincpu")->execute().set_input_line(M68K_IRQ_4, ASSERT_LINE);
731                  state->m_maincpu->set_input_line_vector(M68K_IRQ_4, 128);
732                  state->m_maincpu->set_input_line(M68K_IRQ_4, ASSERT_LINE);
731733               }
732734               else
733735               {
r20508r20509
746748
747749               //printf( "Setting CDIC interrupt line\n" );
748750               verboselog(machine(), 0, "Setting CDIC interrupt line for data sector\n" );
749               machine().device("maincpu")->execute().set_input_line_vector(M68K_IRQ_4, 128);
750               machine().device("maincpu")->execute().set_input_line(M68K_IRQ_4, ASSERT_LINE);
751               state->m_maincpu->set_input_line_vector(M68K_IRQ_4, 128);
752               state->m_maincpu->set_input_line(M68K_IRQ_4, ASSERT_LINE);
751753            }
752754
753755            if((buffer[CDIC_SECTOR_SUBMODE2] & CDIC_SUBMODE_EOF) == 0 && m_command != 0x23)
r20508r20509
803805
804806         if(!cdrom_read_data(m_cd, lba, buffer, CD_TRACK_RAW_DONTCARE))
805807         {
806            printf( "liajfoaijsdofiaodf\n");
808            mame_printf_verbose("Unable to read CD-ROM data.\n");
807809         }
808810
809811         if(!(msf & 0x0000ff))
r20508r20509
811813//              next_lba = next_nybbles[0] + next_nybbles[1]*10 + ((next_nybbles[2] + next_nybbles[3]*10)*75) + ((next_nybbles[4] + next_nybbles[5]*10)*75*60);
812814            verboselog(machine(), 0, "Playing CDDA sector from MSF location %06x\n", m_time | 2 );
813815
814            cdda_start_audio(machine().device("cdda"), lba, rounded_next_msf);
816            cdda_start_audio(state->m_cdda, lba, rounded_next_msf);
815817         }
816818
817819         m_ram[(m_data_buffer & 5) * (0xa00/2) + 0x924/2] = 0x0001;                      //  CTRL
r20508r20509
841843         }
842844
843845         verboselog(machine(), 0, "Setting CDIC interrupt line for CDDA sector\n" );
844         machine().device("maincpu")->execute().set_input_line_vector(M68K_IRQ_4, 128);
845         machine().device("maincpu")->execute().set_input_line(M68K_IRQ_4, ASSERT_LINE);
846         state->m_maincpu->set_input_line_vector(M68K_IRQ_4, 128);
847         state->m_maincpu->set_input_line(M68K_IRQ_4, ASSERT_LINE);
846848         break;
847849      }
848850      case 0x2c: // Seek
r20508r20509
892894         m_time = next_msf << 8;
893895
894896         verboselog(machine(), 0, "Setting CDIC interrupt line for Seek sector\n" );
895         machine().device("maincpu")->execute().set_input_line_vector(M68K_IRQ_4, 128);
896         machine().device("maincpu")->execute().set_input_line(M68K_IRQ_4, ASSERT_LINE);
897         state->m_maincpu->set_input_line_vector(M68K_IRQ_4, 128);
898         state->m_maincpu->set_input_line(M68K_IRQ_4, ASSERT_LINE);
897899         break;
898900      }
899901   }
900902}
901903
902READ16_DEVICE_HANDLER( cdic_r )
904READ16_MEMBER( cdicdic_device::regs_r )
903905{
904   return downcast<cdicdic_device *>(device)->register_read(offset, mem_mask);
905}
906
907UINT16 cdicdic_device::register_read(const UINT32 offset, const UINT16 mem_mask)
908{
906   cdi_state *state = machine().driver_data<cdi_state>();
909907   UINT32 addr = offset + 0x3c00/2;
910908
911909   switch(addr)
r20508r20509
944942         m_audio_buffer &= 0x7fff;
945943         if(!((m_audio_buffer | m_x_buffer) & 0x8000))
946944         {
947            machine().device("maincpu")->execute().set_input_line(M68K_IRQ_4, CLEAR_LINE);
945            state->m_maincpu->set_input_line(M68K_IRQ_4, CLEAR_LINE);
948946            verboselog(machine(), 0, "Clearing CDIC interrupt line\n" );
949947            ////printf("Clearing CDIC interrupt line\n" );
950948         }
r20508r20509
958956         m_x_buffer &= 0x7fff;
959957         if(!((m_audio_buffer | m_x_buffer) & 0x8000))
960958         {
961            machine().device("maincpu")->execute().set_input_line(M68K_IRQ_4, CLEAR_LINE);
959            state->m_maincpu->set_input_line(M68K_IRQ_4, CLEAR_LINE);
962960            verboselog(machine(), 0, "Clearing CDIC interrupt line\n" );
963961            ////printf("Clearing CDIC interrupt line\n" );
964962         }
r20508r20509
987985   }
988986}
989987
990WRITE16_DEVICE_HANDLER( cdic_w )
988WRITE16_MEMBER( cdicdic_device::regs_w )
991989{
992   downcast<cdicdic_device *>(device)->register_write(offset, data, mem_mask);
993}
994
995void cdicdic_device::register_write(const UINT32 offset, const UINT16 data, const UINT16 mem_mask)
996{
997990   cdi_state *state = machine().driver_data<cdi_state>();
998991
999992   UINT32 addr = offset + 0x3c00/2;
r20508r20509
10511044
10521045      case 0x3ff8/2:
10531046      {
1054         scc68070_regs_t *scc68070 = &state->m_scc68070_regs;
1055         UINT32 start = scc68070->dma.channel[0].memory_address_counter;
1056         UINT32 count = scc68070->dma.channel[0].transfer_counter;
1047         UINT32 start = state->m_scc->dma().channel[0].memory_address_counter;
1048         UINT32 count = state->m_scc->dma().channel[0].transfer_counter;
10571049         UINT32 index = 0;
10581050         UINT32 device_index = (data & 0x3fff) >> 1;
10591051         UINT16 *memory = state->m_planea;
r20508r20509
10681060         }
10691061         for(index = start / 2; index < (start / 2 + count); index++)
10701062         {
1071            if(scc68070->dma.channel[0].operation_control & OCR_D)
1063            if(state->m_scc->dma().channel[0].operation_control & OCR_D)
10721064            {
10731065               memory[index] = m_ram[device_index++];
10741066            }
r20508r20509
10771069               m_ram[device_index++] = memory[index];
10781070            }
10791071         }
1080         scc68070->dma.channel[0].memory_address_counter += scc68070->dma.channel[0].transfer_counter * 2;
1072         state->m_scc->dma().channel[0].memory_address_counter += state->m_scc->dma().channel[0].transfer_counter * 2;
10811073         break;
10821074      }
10831075
r20508r20509
11231115                  break;
11241116               }
11251117               case 0x2b: // Stop CDDA
1126                  cdda_stop_audio(machine().device("cdda"));
1118                  cdda_stop_audio(state->m_cdda);
11271119                  m_interrupt_timer->adjust(attotime::never);
11281120                  break;
11291121               case 0x23: // Reset Mode 1
r20508r20509
11711163cdicdic_device::cdicdic_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
11721164   : device_t(mconfig, MACHINE_CDICDIC, "CDICDIC", tag, owner, clock)
11731165{
1174   init();
11751166}
11761167
11771168//-------------------------------------------------
r20508r20509
11801171
11811172void cdicdic_device::device_start()
11821173{
1183   register_globals();
1174   save_item(NAME(m_command));
1175   save_item(NAME(m_time));
1176   save_item(NAME(m_file));
1177   save_item(NAME(m_channel));
1178   save_item(NAME(m_audio_channel));
1179   save_item(NAME(m_audio_buffer));
1180   save_item(NAME(m_x_buffer));
1181   save_item(NAME(m_dma_control));
1182   save_item(NAME(m_z_buffer));
1183   save_item(NAME(m_interrupt_vector));
1184   save_item(NAME(m_data_buffer));
11841185
1185   m_interrupt_timer = machine().scheduler().timer_alloc(FUNC(trigger_readback_int));
1186   save_item(NAME(m_audio_sample_freq));
1187   save_item(NAME(m_audio_sample_size));
1188
1189   m_interrupt_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(cdicdic_device::trigger_readback_int), this));
11861190   m_interrupt_timer->adjust(attotime::never);
11871191
1188   m_audio_sample_timer = machine().scheduler().timer_alloc(FUNC(audio_sample_trigger));
1192   m_audio_sample_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(cdicdic_device::audio_sample_trigger), this));
11891193   m_audio_sample_timer->adjust(attotime::never);
11901194
11911195   m_ram = auto_alloc_array(machine(), UINT16, 0x3c00/2);
r20508r20509
11971201
11981202void cdicdic_device::device_reset()
11991203{
1200   init();
1204   cdi_state *state = machine().driver_data<cdi_state>();
12011205
1202   cdrom_image_device *cdrom_dev = machine().device<cdrom_image_device>("cdrom");
1203   if( cdrom_dev )
1204   {
1205      // MESS case (has CDROM device)
1206      m_cd = cdrom_dev->get_cdrom_file();
1207      cdda_set_cdrom(machine().device("cdda"), m_cd);
1208   }
1209   else
1210   {
1211      // MAME case
1212      m_cd = cdrom_open(get_disk_handle(machine(), ":cdrom"));
1213      cdda_set_cdrom(machine().device("cdda"), m_cd);
1214   }
1215}
1216
1217void cdicdic_device::init()
1218{
12191206   m_command = 0;
12201207   m_time = 0;
12211208   m_file = 0;
r20508r20509
12331220
12341221   m_decode_addr = 0;
12351222   m_decode_delay = 0;
1236}
12371223
1238void cdicdic_device::register_globals()
1239{
1240   save_item(NAME(m_command));
1241   save_item(NAME(m_time));
1242   save_item(NAME(m_file));
1243   save_item(NAME(m_channel));
1244   save_item(NAME(m_audio_channel));
1245   save_item(NAME(m_audio_buffer));
1246   save_item(NAME(m_x_buffer));
1247   save_item(NAME(m_dma_control));
1248   save_item(NAME(m_z_buffer));
1249   save_item(NAME(m_interrupt_vector));
1250   save_item(NAME(m_data_buffer));
1251
1252   save_item(NAME(m_audio_sample_freq));
1253   save_item(NAME(m_audio_sample_size));
1224   cdrom_image_device *cdrom_dev = machine().device<cdrom_image_device>("cdrom");
1225   if( cdrom_dev )
1226   {
1227      // MESS case (has CDROM device)
1228      m_cd = cdrom_dev->get_cdrom_file();
1229      cdda_set_cdrom(state->m_cdda, m_cd);
1230   }
1231   else
1232   {
1233      // MAME case
1234      m_cd = cdrom_open(get_disk_handle(machine(), ":cdrom"));
1235      cdda_set_cdrom(state->m_cdda, m_cd);
1236   }
12541237}
12551238
1256WRITE16_DEVICE_HANDLER( cdic_ram_w )
1239WRITE16_MEMBER( cdicdic_device::ram_w )
12571240{
1258   downcast<cdicdic_device *>(device)->ram_write(offset, data, mem_mask);
1259}
1260
1261void cdicdic_device::ram_write(const UINT32 offset, const UINT16 data, const UINT16 mem_mask)
1262{
1263   verboselog(machine(), 5, "cdic_ram_w: %08x = %04x & %04x\n", 0x00300000 + offset*2, data, mem_mask);
12641241   COMBINE_DATA(&m_ram[offset]);
12651242}
12661243
1267READ16_DEVICE_HANDLER( cdic_ram_r )
1244READ16_MEMBER( cdicdic_device::ram_r )
12681245{
1269   return downcast<cdicdic_device *>(device)->ram_read(offset, mem_mask);
1270}
1271
1272UINT16 cdicdic_device::ram_read(const UINT32 offset, const UINT16 mem_mask)
1273{
1274   verboselog(machine(), 5, "cdic_ram_r: %08x = %04x & %04x\n", 0x00300000 + offset * 2, m_ram[offset], mem_mask);
12751246   return m_ram[offset];
12761247}
trunk/src/mame/machine/cdi070.c
r20508r20509
11/******************************************************************************
22
33
4    CD-i-specific SCC68070 SoC peripheral emulation
4    CD-i-specific cdi68070 SoC peripheral emulation
55    -------------------
66
77    MESS implementation by Harmony
r20508r20509
2424#include "machine/cdi070.h"
2525#include "includes/cdi.h"
2626
27// device type definition
28const device_type MACHINE_CDI68070 = &device_creator<cdi68070_device>;
29
2730#if ENABLE_VERBOSE_LOG
2831INLINE void verboselog(running_machine &machine, int n_level, const char *s_fmt, ...)
2932{
r20508r20509
4144#define verboselog(x,y,z,...)
4245#endif
4346
44static UINT16 mcu_value = 0;
45static UINT8 mcu_ack = 0;
47//**************************************************************************
48//  LIVE DEVICE
49//**************************************************************************
4650
47static void scc68070_set_timer_callback(scc68070_regs_t *scc68070, int channel)
51//-------------------------------------------------
52//  cdi68070_device - constructor
53//-------------------------------------------------
54
55cdi68070_device::cdi68070_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
56   : device_t(mconfig, MACHINE_CDI68070, "CDI68070", tag, owner, clock)
4857{
49   UINT32 compare = 0;
50   attotime period;
58}
59
60//-------------------------------------------------
61//  device_start - device-specific startup
62//-------------------------------------------------
63
64void cdi68070_device::device_start()
65{
66   save_item(NAME(m_lir));
67
68   save_item(NAME(m_picr1));
69   save_item(NAME(m_picr2));
70
71   save_item(NAME(m_i2c.data_register));
72   save_item(NAME(m_i2c.address_register));
73   save_item(NAME(m_i2c.status_register));
74   save_item(NAME(m_i2c.control_register));
75   save_item(NAME(m_i2c.clock_control_register));
76
77   save_item(NAME(m_uart.mode_register));
78   save_item(NAME(m_uart.status_register));
79   save_item(NAME(m_uart.clock_select));
80   save_item(NAME(m_uart.command_register));
81   save_item(NAME(m_uart.transmit_holding_register));
82   save_item(NAME(m_uart.receive_holding_register));
83
84   save_item(NAME(m_timers.timer_status_register));
85   save_item(NAME(m_timers.timer_control_register));
86   save_item(NAME(m_timers.reload_register));
87   save_item(NAME(m_timers.timer0));
88   save_item(NAME(m_timers.timer1));
89   save_item(NAME(m_timers.timer2));
90
91   save_item(NAME(m_dma.channel[0].channel_status));
92   save_item(NAME(m_dma.channel[0].channel_error));
93   save_item(NAME(m_dma.channel[0].device_control));
94   save_item(NAME(m_dma.channel[0].operation_control));
95   save_item(NAME(m_dma.channel[0].sequence_control));
96   save_item(NAME(m_dma.channel[0].channel_control));
97   save_item(NAME(m_dma.channel[0].transfer_counter));
98   save_item(NAME(m_dma.channel[0].memory_address_counter));
99   save_item(NAME(m_dma.channel[0].device_address_counter));
100   save_item(NAME(m_dma.channel[1].channel_status));
101   save_item(NAME(m_dma.channel[1].channel_error));
102   save_item(NAME(m_dma.channel[1].device_control));
103   save_item(NAME(m_dma.channel[1].operation_control));
104   save_item(NAME(m_dma.channel[1].sequence_control));
105   save_item(NAME(m_dma.channel[1].channel_control));
106   save_item(NAME(m_dma.channel[1].transfer_counter));
107   save_item(NAME(m_dma.channel[1].memory_address_counter));
108   save_item(NAME(m_dma.channel[1].device_address_counter));
109
110   save_item(NAME(m_mmu.status));
111   save_item(NAME(m_mmu.control));
112   save_item(NAME(m_mmu.desc[0].attr));
113   save_item(NAME(m_mmu.desc[0].length));
114   save_item(NAME(m_mmu.desc[0].segment));
115   save_item(NAME(m_mmu.desc[0].base));
116   save_item(NAME(m_mmu.desc[1].attr));
117   save_item(NAME(m_mmu.desc[1].length));
118   save_item(NAME(m_mmu.desc[1].segment));
119   save_item(NAME(m_mmu.desc[1].base));
120   save_item(NAME(m_mmu.desc[2].attr));
121   save_item(NAME(m_mmu.desc[2].length));
122   save_item(NAME(m_mmu.desc[2].segment));
123   save_item(NAME(m_mmu.desc[2].base));
124   save_item(NAME(m_mmu.desc[3].attr));
125   save_item(NAME(m_mmu.desc[3].length));
126   save_item(NAME(m_mmu.desc[3].segment));
127   save_item(NAME(m_mmu.desc[3].base));
128   save_item(NAME(m_mmu.desc[4].attr));
129   save_item(NAME(m_mmu.desc[4].length));
130   save_item(NAME(m_mmu.desc[4].segment));
131   save_item(NAME(m_mmu.desc[4].base));
132   save_item(NAME(m_mmu.desc[5].attr));
133   save_item(NAME(m_mmu.desc[5].length));
134   save_item(NAME(m_mmu.desc[5].segment));
135   save_item(NAME(m_mmu.desc[5].base));
136   save_item(NAME(m_mmu.desc[6].attr));
137   save_item(NAME(m_mmu.desc[6].length));
138   save_item(NAME(m_mmu.desc[6].segment));
139   save_item(NAME(m_mmu.desc[6].base));
140   save_item(NAME(m_mmu.desc[7].attr));
141   save_item(NAME(m_mmu.desc[7].length));
142   save_item(NAME(m_mmu.desc[7].segment));
143   save_item(NAME(m_mmu.desc[7].base));
144
145   m_timers.timer0_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(cdi68070_device::timer0_callback), this));
146   m_timers.timer0_timer->adjust(attotime::never);
147
148   m_uart.rx_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(cdi68070_device::rx_callback), this));
149   m_uart.rx_timer->adjust(attotime::never);
150
151   m_uart.tx_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(cdi68070_device::tx_callback), this));
152   m_uart.tx_timer->adjust(attotime::never);
153}
154
155//-------------------------------------------------
156//  device_reset - device-specific reset
157//-------------------------------------------------
158
159void cdi68070_device::device_reset()
160{
161   m_lir = 0;
162
163   m_picr1 = 0;
164   m_picr2 = 0;
165
166   m_i2c.data_register = 0;
167   m_i2c.address_register = 0;
168   m_i2c.status_register = 0;
169   m_i2c.control_register = 0;
170   m_i2c.clock_control_register = 0;
171
172   m_uart.mode_register = 0;
173   m_uart.status_register = USR_TXRDY;
174   m_uart.clock_select = 0;
175   m_uart.command_register = 0;
176   m_uart.transmit_holding_register = 0;
177   m_uart.receive_holding_register = 0;
178   m_uart.receive_pointer = -1;
179   m_uart.transmit_pointer = -1;
180
181   m_timers.timer_status_register = 0;
182   m_timers.timer_control_register = 0;
183   m_timers.reload_register = 0;
184   m_timers.timer0 = 0;
185   m_timers.timer1 = 0;
186   m_timers.timer2 = 0;
187
188   for(int index = 0; index < 2; index++)
189   {
190      m_dma.channel[index].channel_status = 0;
191      m_dma.channel[index].channel_error = 0;
192      m_dma.channel[index].device_control = 0;
193      m_dma.channel[index].operation_control = 0;
194      m_dma.channel[index].sequence_control = 0;
195      m_dma.channel[index].channel_control = 0;
196      m_dma.channel[index].transfer_counter = 0;
197      m_dma.channel[index].memory_address_counter = 0;
198      m_dma.channel[index].device_address_counter = 0;
199   }
200
201   m_mmu.status = 0;
202   m_mmu.control = 0;
203   for(int index = 0; index < 8; index++)
204   {
205      m_mmu.desc[index].attr = 0;
206      m_mmu.desc[index].length = 0;
207      m_mmu.desc[index].segment = 0;
208      m_mmu.desc[index].base = 0;
209   }
210
211   memset(m_seeds, 0, 10 * sizeof(UINT16));
212   memset(m_state, 0, 8 * sizeof(UINT8));
213   m_mcu_value = 0;
214   m_mcu_ack = 0;
215}
216
217void cdi68070_device::set_timer_callback(int channel)
218{
51219   switch(channel)
52220   {
53221      case 0:
54         compare = 0x10000 - scc68070->timers.timer0;
55         period = attotime::from_hz(CLOCK_A/192) * compare;
56         scc68070->timers.timer0_timer->adjust(period);
222      {
223         UINT32 compare = 0x10000 - m_timers.timer0;
224         attotime period = attotime::from_hz(CLOCK_A/192) * compare;
225         m_timers.timer0_timer->adjust(period);
57226         break;
227      }
58228      default:
59         fatalerror( "Unsupported timer channel to scc68070_set_timer_callback!\n" );
229      {
230         fatalerror( "Unsupported timer channel to set_timer_callback!\n" );
231      }
60232   }
61233}
62234
63void scc68070_set_quizard_mcu_ack(running_machine &machine, UINT8 ack)
235void cdi68070_device::set_quizard_mcu_ack(UINT8 ack)
64236{
65   mcu_ack = ack;
237   m_mcu_ack = ack;
66238}
67239
68void scc68070_set_quizard_mcu_value(running_machine &machine, UINT16 value)
240void cdi68070_device::set_quizard_mcu_value(UINT16 value)
69241{
70   mcu_value = value;
242   m_mcu_value = value;
71243}
72244
73TIMER_CALLBACK( scc68070_timer0_callback )
245TIMER_CALLBACK_MEMBER( cdi68070_device::timer0_callback )
74246{
75   cdi_state *state = machine.driver_data<cdi_state>();
76   scc68070_regs_t *scc68070 = &state->m_scc68070_regs;
247   cdi_state *state = machine().driver_data<cdi_state>();
77248
78   scc68070->timers.timer0 = scc68070->timers.reload_register;
79   scc68070->timers.timer_status_register |= TSR_OV0;
80   if(scc68070->picr1 & 7)
249   m_timers.timer0 = m_timers.reload_register;
250   m_timers.timer_status_register |= TSR_OV0;
251   if(m_picr1 & 7)
81252   {
82      UINT8 interrupt = scc68070->picr1 & 7;
83      scc68070->timers.timer_status_register |= TSR_OV0;
253      UINT8 interrupt = m_picr1 & 7;
254      m_timers.timer_status_register |= TSR_OV0;
84255      if(interrupt)
85256      {
86         machine.device("maincpu")->execute().set_input_line_vector(M68K_IRQ_1 + (interrupt - 1), 56 + interrupt);
87         machine.device("maincpu")->execute().set_input_line(M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE);
257         state->m_maincpu->set_input_line_vector(M68K_IRQ_1 + (interrupt - 1), 56 + interrupt);
258         state->m_maincpu->set_input_line(M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE);
88259      }
89260   }
90261
91   scc68070_set_timer_callback(&state->m_scc68070_regs, 0);
262   set_timer_callback(0);
92263}
93264
94static void scc68070_uart_rx_check(running_machine &machine, scc68070_regs_t *scc68070)
265void cdi68070_device::uart_rx_check()
95266{
96   if((scc68070->uart.command_register & 3) == 1)
267   if((m_uart.command_register & 3) == 1)
97268   {
98      UINT32 div = 0x10000 >> ((scc68070->uart.clock_select >> 4) & 7);
99      scc68070->uart.rx_timer->adjust(attotime::from_hz((49152000 / div) / 8));
269      UINT32 div = 0x10000 >> ((m_uart.clock_select >> 4) & 7);
270      m_uart.rx_timer->adjust(attotime::from_hz((49152000 / div) / 8));
100271   }
101272   else
102273   {
103      scc68070->uart.status_register &= ~USR_RXRDY;
104      scc68070->uart.rx_timer->adjust(attotime::never);
274      m_uart.status_register &= ~USR_RXRDY;
275      m_uart.rx_timer->adjust(attotime::never);
105276   }
106277}
107278
108static void scc68070_uart_tx_check(running_machine &machine, scc68070_regs_t *scc68070)
279void cdi68070_device::uart_tx_check()
109280{
110   if(((scc68070->uart.command_register >> 2) & 3) == 1)
281   if(((m_uart.command_register >> 2) & 3) == 1)
111282   {
112      if(scc68070->uart.transmit_pointer >= 0)
283      if(m_uart.transmit_pointer >= 0)
113284      {
114         scc68070->uart.status_register &= ~USR_TXRDY;
285         m_uart.status_register &= ~USR_TXRDY;
115286      }
116287      else
117288      {
118         scc68070->uart.status_register |= USR_TXRDY;
289         m_uart.status_register |= USR_TXRDY;
119290      }
120291
121      if(scc68070->uart.tx_timer->remaining() == attotime::never)
292      if(m_uart.tx_timer->remaining() == attotime::never)
122293      {
123         UINT32 div = 0x10000 >> (scc68070->uart.clock_select & 7);
124         scc68070->uart.tx_timer->adjust(attotime::from_hz((49152000 / div) / 8));
294         UINT32 div = 0x10000 >> (m_uart.clock_select & 7);
295         m_uart.tx_timer->adjust(attotime::from_hz((49152000 / div) / 8));
125296      }
126297   }
127298   else
128299   {
129      scc68070->uart.tx_timer->adjust(attotime::never);
300      m_uart.tx_timer->adjust(attotime::never);
130301   }
131302}
132303
133void scc68070_uart_rx(running_machine &machine, scc68070_regs_t *scc68070, UINT8 data)
304void cdi68070_device::uart_rx(UINT8 data)
134305{
135   //printf("%d: %02x\n", scc68070->uart.receive_pointer + 1, data);
136   scc68070->uart.receive_pointer++;
137   scc68070->uart.receive_buffer[scc68070->uart.receive_pointer] = data;
138   scc68070_uart_rx_check(machine, scc68070);
306   m_uart.receive_pointer++;
307   m_uart.receive_buffer[m_uart.receive_pointer] = data;
308   uart_rx_check();
139309}
140310
141void scc68070_uart_tx(running_machine &machine, scc68070_regs_t *scc68070, UINT8 data)
311void cdi68070_device::uart_tx(UINT8 data)
142312{
143   scc68070->uart.transmit_pointer++;
144   scc68070->uart.transmit_buffer[scc68070->uart.transmit_pointer] = data;
145   scc68070_uart_tx_check(machine, scc68070);
313   m_uart.transmit_pointer++;
314   m_uart.transmit_buffer[m_uart.transmit_pointer] = data;
315   uart_tx_check();
146316}
147317
148TIMER_CALLBACK( scc68070_rx_callback )
318TIMER_CALLBACK_MEMBER( cdi68070_device::rx_callback )
149319{
150   cdi_state *state = machine.driver_data<cdi_state>();
151   scc68070_regs_t *scc68070 = &state->m_scc68070_regs;
320   cdi_state *state = machine().driver_data<cdi_state>();
152321
153   if((scc68070->uart.command_register & 3) == 1)
322   if((m_uart.command_register & 3) == 1)
154323   {
155      if(scc68070->uart.receive_pointer >= 0)
324      if(m_uart.receive_pointer >= 0)
156325      {
157         scc68070->uart.status_register |= USR_RXRDY;
326         m_uart.status_register |= USR_RXRDY;
158327      }
159328      else
160329      {
161         scc68070->uart.status_register &= ~USR_RXRDY;
330         m_uart.status_register &= ~USR_RXRDY;
162331      }
163332
164      scc68070->uart.receive_holding_register = scc68070->uart.receive_buffer[0];
333      m_uart.receive_holding_register = m_uart.receive_buffer[0];
165334
166      if(scc68070->uart.receive_pointer > -1)
335      if(m_uart.receive_pointer > -1)
167336      {
168         verboselog(machine, 2, "scc68070_rx_callback: Receiving %02x\n", scc68070->uart.receive_holding_register);
337         verboselog(machine(), 2, "scc68070_rx_callback: Receiving %02x\n", m_uart.receive_holding_register);
169338
170         UINT8 interrupt = (scc68070->picr2 >> 4) & 7;
339         UINT8 interrupt = (m_picr2 >> 4) & 7;
171340         if(interrupt)
172341         {
173            machine.device("maincpu")->execute().set_input_line_vector(M68K_IRQ_1 + (interrupt - 1), 56 + interrupt);
174            machine.device("maincpu")->execute().set_input_line(M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE);
342            state->m_maincpu->set_input_line_vector(M68K_IRQ_1 + (interrupt - 1), 56 + interrupt);
343            state->m_maincpu->set_input_line(M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE);
175344         }
176345
177         scc68070->uart.status_register |= USR_RXRDY;
178         UINT32 div = 0x10000 >> ((scc68070->uart.clock_select >> 4) & 7);
179         scc68070->uart.rx_timer->adjust(attotime::from_hz((49152000 / div) / 8));
346         m_uart.status_register |= USR_RXRDY;
347         UINT32 div = 0x10000 >> ((m_uart.clock_select >> 4) & 7);
348         m_uart.rx_timer->adjust(attotime::from_hz((49152000 / div) / 8));
180349      }
181350      else
182351      {
183         scc68070->uart.status_register &= ~USR_RXRDY;
352         m_uart.status_register &= ~USR_RXRDY;
184353      }
185354   }
186355   else
187356   {
188      scc68070->uart.status_register &= ~USR_RXRDY;
357      m_uart.status_register &= ~USR_RXRDY;
189358   }
190359
191   scc68070_uart_rx_check(machine, scc68070);
360   uart_rx_check();
192361}
193362
194static UINT16 seeds[10] = { 0 };
195static UINT8 g_state[8] = { 0 };
196
197void scc68070_quizard_rx(running_machine &machine, scc68070_regs_t *scc68070, UINT8 data)
363void cdi68070_device::quizard_rx(UINT8 data)
198364{
199   scc68070_uart_rx(machine, scc68070, 0x5a);
200   scc68070_uart_rx(machine, scc68070, data);
365   uart_rx(0x5a);
366   uart_rx(data);
201367}
202368
203static void quizard_set_seeds(UINT8 *rx)
369void cdi68070_device::quizard_set_seeds(UINT8 *rx)
204370{
205   seeds[0] = (rx[1] << 8) | rx[0];
206   seeds[1] = (rx[3] << 8) | rx[2];
207   seeds[2] = (rx[5] << 8) | rx[4];
208   seeds[3] = (rx[7] << 8) | rx[6];
209   seeds[4] = (rx[9] << 8) | rx[8];
210   seeds[5] = (rx[11] << 8) | rx[10];
211   seeds[6] = (rx[13] << 8) | rx[12];
212   seeds[7] = (rx[15] << 8) | rx[14];
213   seeds[8] = (rx[17] << 8) | rx[16];
214   seeds[9] = (rx[19] << 8) | rx[18];
371   m_seeds[0] = (rx[1] << 8) | rx[0];
372   m_seeds[1] = (rx[3] << 8) | rx[2];
373   m_seeds[2] = (rx[5] << 8) | rx[4];
374   m_seeds[3] = (rx[7] << 8) | rx[6];
375   m_seeds[4] = (rx[9] << 8) | rx[8];
376   m_seeds[5] = (rx[11] << 8) | rx[10];
377   m_seeds[6] = (rx[13] << 8) | rx[12];
378   m_seeds[7] = (rx[15] << 8) | rx[14];
379   m_seeds[8] = (rx[17] << 8) | rx[16];
380   m_seeds[9] = (rx[19] << 8) | rx[18];
215381}
216382
217static void quizard_calculate_state(running_machine &machine, scc68070_regs_t *scc68070)
383void cdi68070_device::quizard_calculate_state()
218384{
219385   //const UINT16 desired_bitfield = mcu_value;
220386   const UINT16 field0 = 0x00ff;
221   const UINT16 field1 = mcu_value ^ 0x00ff;
387   const UINT16 field1 = m_mcu_value ^ 0x00ff;
222388
223389   UINT16 total0 = 0;
224390   UINT16 total1 = 0;
r20508r20509
227393   {
228394      if(field0 & (1 << index))
229395      {
230         total0 += seeds[index];
396         total0 += m_seeds[index];
231397      }
232398      if(field1 & (1 << index))
233399      {
234         total1 += seeds[index];
400         total1 += m_seeds[index];
235401      }
236402   }
237403
238404   UINT16 hi0 = (total0 >> 8) + 0x40;
239   g_state[2] = hi0 / 2;
240   g_state[3] = hi0 - g_state[2];
405   m_state[2] = hi0 / 2;
406   m_state[3] = hi0 - m_state[2];
241407
242408   UINT16 lo0 = (total0 & 0x00ff) + 0x40;
243   g_state[0] = lo0 / 2;
244   g_state[1] = lo0 - g_state[0];
409   m_state[0] = lo0 / 2;
410   m_state[1] = lo0 - m_state[0];
245411
246412   UINT16 hi1 = (total1 >> 8) + 0x40;
247   g_state[6] = hi1 / 2;
248   g_state[7] = hi1 - g_state[6];
413   m_state[6] = hi1 / 2;
414   m_state[7] = hi1 - m_state[6];
249415
250416   UINT16 lo1 = (total1 & 0x00ff) + 0x40;
251   g_state[4] = lo1 / 2;
252   g_state[5] = lo1 - g_state[4];
417   m_state[4] = lo1 / 2;
418   m_state[5] = lo1 - m_state[4];
253419}
254420
255INTERRUPT_GEN( scc68070_mcu_frame )
421void cdi68070_device::mcu_frame()
256422{
257   cdi_state *state = device->machine().driver_data<cdi_state>();
258   scc68070_regs_t *scc68070 = &state->m_scc68070_regs;
259
260423   if(0)//mcu_active)
261424   {
262      quizard_calculate_state(device->machine(), scc68070);
263      scc68070_uart_rx(device->machine(), scc68070, 0x5a);
425      quizard_calculate_state();
426      uart_rx(0x5a);
264427      for(int index = 0; index < 8; index++)
265428      {
266         scc68070_uart_rx(device->machine(), scc68070, g_state[index]);
429         uart_rx(m_state[index]);
267430      }
268431   }
269432}
270433
271static void quizard_handle_byte_tx(running_machine &machine, scc68070_regs_t *scc68070)
434void cdi68070_device::quizard_handle_byte_tx()
272435{
273436   static int state = 0;
274437   static UINT8 rx[0x100];
275438   static UINT8 rx_ptr = 0xff;
276   UINT8 tx = scc68070->uart.transmit_holding_register;
439   UINT8 tx = m_uart.transmit_holding_register;
277440
278   //printf("%02x ", tx );
279   if((tx >= 0x20 && tx < 0x7f) || tx == 0x0d || tx == 0x0a)
280   {
281      //printf("%c ", tx);
282   }
283   //printf("\n");
284
285441   switch(state)
286442   {
287443      case 0: // Waiting for a leadoff byte
288         if(tx == mcu_ack) // Sequence end
444         if(tx == m_mcu_ack) // Sequence end
289445         {
290446            //scc68070_uart_rx(machine, scc68070, 0x5a);
291447            //scc68070_uart_rx(machine, scc68070, 0x42);
r20508r20509
319475         {
320476            //printf("Calculating seeds\n");
321477            quizard_set_seeds(rx);
322            quizard_calculate_state(machine, scc68070);
478            quizard_calculate_state();
323479            state = 2;
324480         }
325481         break;
326482
327483      case 2: // Receiving the seed acknowledge
328484      case 4:
329         if(tx == mcu_ack)
485         if(tx == m_mcu_ack)
330486         {
331487            if(state == 2)
332488            {
r20508r20509
337493               state = 0;
338494            }
339495            //printf("Sending seed ack\n");
340            scc68070_uart_rx(machine, scc68070, 0x5a);
341            scc68070_uart_rx(machine, scc68070, g_state[0]);
342            scc68070_uart_rx(machine, scc68070, g_state[1]);
343            scc68070_uart_rx(machine, scc68070, g_state[2]);
344            scc68070_uart_rx(machine, scc68070, g_state[3]);
345            scc68070_uart_rx(machine, scc68070, g_state[4]);
346            scc68070_uart_rx(machine, scc68070, g_state[5]);
347            scc68070_uart_rx(machine, scc68070, g_state[6]);
348            scc68070_uart_rx(machine, scc68070, g_state[7]);
496            uart_rx(0x5a);
497            uart_rx(m_state[0]);
498            uart_rx(m_state[1]);
499            uart_rx(m_state[2]);
500            uart_rx(m_state[3]);
501            uart_rx(m_state[4]);
502            uart_rx(m_state[5]);
503            uart_rx(m_state[6]);
504            uart_rx(m_state[7]);
349505         }
350506         break;
351507
r20508r20509
371527   }
372528}
373529
374TIMER_CALLBACK( scc68070_tx_callback )
530TIMER_CALLBACK_MEMBER( cdi68070_device::tx_callback )
375531{
376   cdi_state *state = machine.driver_data<cdi_state>();
377   scc68070_regs_t *scc68070 = &state->m_scc68070_regs;
532   cdi_state *state = machine().driver_data<cdi_state>();
378533
379   if(((scc68070->uart.command_register >> 2) & 3) == 1)
534   if(((m_uart.command_register >> 2) & 3) == 1)
380535   {
381      UINT8 interrupt = scc68070->picr2 & 7;
536      UINT8 interrupt = m_picr2 & 7;
382537      if(interrupt)
383538      {
384         machine.device("maincpu")->execute().set_input_line_vector(M68K_IRQ_1 + (interrupt - 1), 56 + interrupt);
385         machine.device("maincpu")->execute().set_input_line(M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE);
539         state->m_maincpu->set_input_line_vector(M68K_IRQ_1 + (interrupt - 1), 56 + interrupt);
540         state->m_maincpu->set_input_line(M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE);
386541      }
387542
388      if(scc68070->uart.transmit_pointer > -1)
543      if(m_uart.transmit_pointer > -1)
389544      {
390         scc68070->uart.transmit_holding_register = scc68070->uart.transmit_buffer[0];
391         quizard_handle_byte_tx(machine, scc68070);
545         m_uart.transmit_holding_register = m_uart.transmit_buffer[0];
546         quizard_handle_byte_tx();
392547
393         verboselog(machine, 2, "scc68070_tx_callback: Transmitting %02x\n", scc68070->uart.transmit_holding_register);
394         for(int index = 0; index < scc68070->uart.transmit_pointer; index++)
548         verboselog(machine(), 2, "cdi68070_tx_callback: Transmitting %02x\n", m_uart.transmit_holding_register);
549         for(int index = 0; index < m_uart.transmit_pointer; index++)
395550         {
396            scc68070->uart.transmit_buffer[index] = scc68070->uart.transmit_buffer[index+1];
551            m_uart.transmit_buffer[index] = m_uart.transmit_buffer[index+1];
397552         }
398         scc68070->uart.transmit_pointer--;
553         m_uart.transmit_pointer--;
399554
400         UINT32 div = 0x10000 >> (scc68070->uart.clock_select & 7);
401         scc68070->uart.tx_timer->adjust(attotime::from_hz((49152000 / div) / 8));
555         UINT32 div = 0x10000 >> (m_uart.clock_select & 7);
556         m_uart.tx_timer->adjust(attotime::from_hz((49152000 / div) / 8));
402557      }
403558      else
404559      {
405         scc68070->uart.tx_timer->adjust(attotime::never);
560         m_uart.tx_timer->adjust(attotime::never);
406561      }
407562   }
408563   else
409564   {
410      scc68070->uart.tx_timer->adjust(attotime::never);
565      m_uart.tx_timer->adjust(attotime::never);
411566   }
412567
413   scc68070_uart_tx_check(machine, scc68070);
568   uart_tx_check();
414569}
415570
416READ16_HANDLER( scc68070_periphs_r )
571READ16_MEMBER( cdi68070_device::periphs_r )
417572{
418   cdi_state *state = space.machine().driver_data<cdi_state>();
419   scc68070_regs_t *scc68070 = &state->m_scc68070_regs;
573   cdi_state *state = machine().driver_data<cdi_state>();
420574
421575   switch(offset)
422576   {
423577      // Interrupts: 80001001
424578      case 0x1000/2: // LIR priority level
425         return scc68070->lir;
579         return m_lir;
426580
427581      // I2C interface: 80002001 to 80002009
428582      case 0x2000/2:
429583         if(ACCESSING_BITS_0_7)
430584         {
431            verboselog(space.machine(), 2, "scc68070_periphs_w: I2C Data Register: %04x & %04x\n", scc68070->i2c.data_register, mem_mask);
585            verboselog(machine(), 2, "cdi68070_periphs_w: I2C Data Register: %04x & %04x\n", m_i2c.data_register, mem_mask);
432586         }
433         return scc68070->i2c.data_register;
587         return m_i2c.data_register;
434588      case 0x2002/2:
435589         if(ACCESSING_BITS_0_7)
436590         {
437            verboselog(space.machine(), 2, "scc68070_periphs_w: I2C Address Register: %04x & %04x\n", scc68070->i2c.address_register, mem_mask);
591            verboselog(machine(), 2, "cdi68070_periphs_w: I2C Address Register: %04x & %04x\n", m_i2c.address_register, mem_mask);
438592         }
439         return scc68070->i2c.address_register;
593         return m_i2c.address_register;
440594      case 0x2004/2:
441595         if(ACCESSING_BITS_0_7)
442596         {
443            verboselog(space.machine(), 2, "scc68070_periphs_w: I2C Status Register: %04x & %04x\n", scc68070->i2c.status_register, mem_mask);
597            verboselog(machine(), 2, "cdi68070_periphs_w: I2C Status Register: %04x & %04x\n", m_i2c.status_register, mem_mask);
444598         }
445         return scc68070->i2c.status_register;
599         return m_i2c.status_register;
446600      case 0x2006/2:
447601         if(ACCESSING_BITS_0_7)
448602         {
449            verboselog(space.machine(), 2, "scc68070_periphs_w: I2C Control Register: %04x & %04x\n", scc68070->i2c.control_register, mem_mask);
603            verboselog(machine(), 2, "cdi68070_periphs_w: I2C Control Register: %04x & %04x\n", m_i2c.control_register, mem_mask);
450604         }
451         return scc68070->i2c.control_register;
605         return m_i2c.control_register;
452606      case 0x2008/2:
453607         if(ACCESSING_BITS_0_7)
454608         {
455            verboselog(space.machine(), 2, "scc68070_periphs_w: I2C Clock Control Register: %04x & %04x\n", scc68070->i2c.clock_control_register, mem_mask);
609            verboselog(machine(), 2, "cdi68070_periphs_w: I2C Clock Control Register: %04x & %04x\n", m_i2c.clock_control_register, mem_mask);
456610         }
457         return scc68070->i2c.clock_control_register;
611         return m_i2c.clock_control_register;
458612
459613      // UART interface: 80002011 to 8000201b
460614      case 0x2010/2:
461615         if(ACCESSING_BITS_0_7)
462616         {
463            verboselog(space.machine(), 2, "scc68070_periphs_r: UART Mode Register: %04x & %04x\n", scc68070->uart.mode_register, mem_mask);
617            verboselog(machine(), 2, "cdi68070_periphs_r: UART Mode Register: %04x & %04x\n", m_uart.mode_register, mem_mask);
464618         }
465619         else
466620         {
467            verboselog(space.machine(), 0, "scc68070_periphs_r: Unknown address: %04x & %04x\n", offset * 2, mem_mask);
621            verboselog(machine(), 0, "cdi68070_periphs_r: Unknown address: %04x & %04x\n", offset * 2, mem_mask);
468622         }
469         return scc68070->uart.mode_register | 0x20;
623         return m_uart.mode_register | 0x20;
470624      case 0x2012/2:
471         scc68070->uart.status_register |= (1 << 1);
625         m_uart.status_register |= (1 << 1);
472626         if(ACCESSING_BITS_0_7)
473627         {
474            verboselog(space.machine(), 2, "scc68070_periphs_r: UART Status Register: %04x & %04x\n", scc68070->uart.status_register, mem_mask);
628            verboselog(machine(), 2, "cdi68070_periphs_r: UART Status Register: %04x & %04x\n", m_uart.status_register, mem_mask);
475629         }
476630         else
477631         {
478            verboselog(space.machine(), 0, "scc68070_periphs_r: Unknown address: %04x & %04x\n", offset * 2, mem_mask);
632            verboselog(space.machine(), 0, "cdi68070_periphs_r: Unknown address: %04x & %04x\n", offset * 2, mem_mask);
479633         }
480634
481         if((scc68070->picr2 >> 4) & 7)
635         if((m_picr2 >> 4) & 7)
482636         {
483            space.machine().device("maincpu")->execute().set_input_line(M68K_IRQ_1 + (((scc68070->picr2 >> 4) & 7) - 1), ASSERT_LINE);
637            state->m_maincpu->set_input_line(M68K_IRQ_1 + (((m_picr2 >> 4) & 7) - 1), ASSERT_LINE);
484638         }
485639
486         if(scc68070->picr2 & 7)
640         if(m_picr2 & 7)
487641         {
488            space.machine().device("maincpu")->execute().set_input_line(M68K_IRQ_1 + ((scc68070->picr2 & 7) - 1), ASSERT_LINE);
642            state->m_maincpu->set_input_line(M68K_IRQ_1 + ((m_picr2 & 7) - 1), ASSERT_LINE);
489643         }
490644
491         return scc68070->uart.status_register;
645         return m_uart.status_register;
492646
493647      case 0x2014/2:
494648         if(ACCESSING_BITS_0_7)
495649         {
496            verboselog(space.machine(), 2, "scc68070_periphs_r: UART Clock Select: %04x & %04x\n", scc68070->uart.clock_select, mem_mask);
650            verboselog(machine(), 2, "cdi68070_periphs_r: UART Clock Select: %04x & %04x\n", m_uart.clock_select, mem_mask);
497651         }
498652         else
499653         {
500            verboselog(space.machine(), 0, "scc68070_periphs_r: Unknown address: %04x & %04x\n", offset * 2, mem_mask);
654            verboselog(machine(), 0, "cdi68070_periphs_r: Unknown address: %04x & %04x\n", offset * 2, mem_mask);
501655         }
502         return scc68070->uart.clock_select | 0x08;
656         return m_uart.clock_select | 0x08;
503657      case 0x2016/2:
504658         if(ACCESSING_BITS_0_7)
505659         {
506            verboselog(space.machine(), 2, "scc68070_periphs_r: UART Command Register: %02x & %04x\n", scc68070->uart.command_register, mem_mask);
660            verboselog(machine(), 2, "cdi68070_periphs_r: UART Command Register: %02x & %04x\n", m_uart.command_register, mem_mask);
507661         }
508662         else
509663         {
510            verboselog(space.machine(), 0, "scc68070_periphs_r: Unknown address: %04x & %04x\n", offset * 2, mem_mask);
664            verboselog(machine(), 0, "cdi68070_periphs_r: Unknown address: %04x & %04x\n", offset * 2, mem_mask);
511665         }
512         return scc68070->uart.command_register | 0x80;
666         return m_uart.command_register | 0x80;
513667      case 0x2018/2:
514668         if(ACCESSING_BITS_0_7)
515669         {
516            verboselog(space.machine(), 2, "scc68070_periphs_r: UART Transmit Holding Register: %02x & %04x\n", scc68070->uart.transmit_holding_register, mem_mask);
670            verboselog(machine(), 2, "cdi68070_periphs_r: UART Transmit Holding Register: %02x & %04x\n", m_uart.transmit_holding_register, mem_mask);
517671         }
518672         else
519673         {
520            verboselog(space.machine(), 0, "scc68070_periphs_r: Unknown address: %04x & %04x\n", offset * 2, mem_mask);
674            verboselog(machine(), 0, "cdi68070_periphs_r: Unknown address: %04x & %04x\n", offset * 2, mem_mask);
521675         }
522         return scc68070->uart.transmit_holding_register;
676         return m_uart.transmit_holding_register;
523677      case 0x201a/2:
524678         if(ACCESSING_BITS_0_7)
525679         {
526            verboselog(space.machine(), 2, "scc68070_periphs_r: UART Receive Holding Register: %02x & %04x\n", scc68070->uart.receive_holding_register, mem_mask);
680            verboselog(machine(), 2, "cdi68070_periphs_r: UART Receive Holding Register: %02x & %04x\n", m_uart.receive_holding_register, mem_mask);
527681         }
528682         else
529683         {
530            verboselog(space.machine(), 0, "scc68070_periphs_r: Unknown address: %04x & %04x\n", offset * 2, mem_mask);
684            verboselog(machine(), 0, "cdi68070_periphs_r: Unknown address: %04x & %04x\n", offset * 2, mem_mask);
531685         }
532         if((scc68070->picr2 >> 4) & 7)
686         if((m_picr2 >> 4) & 7)
533687         {
534            space.machine().device("maincpu")->execute().set_input_line(M68K_IRQ_1 + (((scc68070->picr2 >> 4) & 7) - 1), CLEAR_LINE);
688            state->m_maincpu->set_input_line(M68K_IRQ_1 + (((m_picr2 >> 4) & 7) - 1), CLEAR_LINE);
535689         }
536690
537         scc68070->uart.receive_holding_register = scc68070->uart.receive_buffer[0];
538         if(scc68070->uart.receive_pointer >= 0)
691         m_uart.receive_holding_register = m_uart.receive_buffer[0];
692         if(m_uart.receive_pointer >= 0)
539693         {
540            for(int index = 0; index < scc68070->uart.receive_pointer; index++)
694            for(int index = 0; index < m_uart.receive_pointer; index++)
541695            {
542               scc68070->uart.receive_buffer[index] = scc68070->uart.receive_buffer[index + 1];
696               m_uart.receive_buffer[index] = m_uart.receive_buffer[index + 1];
543697            }
544            scc68070->uart.receive_pointer--;
698            m_uart.receive_pointer--;
545699         }
546         //printf("R: %02x\n", scc68070->uart.receive_holding_register);
547         return scc68070->uart.receive_holding_register;
700         //printf("R: %02x\n", m_uart.receive_holding_register);
701         return m_uart.receive_holding_register;
548702
549703      // Timers: 80002020 to 80002029
550704      case 0x2020/2:
551705         if(ACCESSING_BITS_0_7)
552706         {
553            verboselog(space.machine(), 2, "scc68070_periphs_r: Timer Control Register: %02x & %04x\n", scc68070->timers.timer_control_register, mem_mask);
707            verboselog(machine(), 2, "cdi68070_periphs_r: Timer Control Register: %02x & %04x\n", m_timers.timer_control_register, mem_mask);
554708         }
555709         if(ACCESSING_BITS_8_15)
556710         {
557            verboselog(space.machine(), 12, "scc68070_periphs_r: Timer Status Register: %02x & %04x\n", scc68070->timers.timer_status_register, mem_mask);
711            verboselog(machine(), 12, "cdi68070_periphs_r: Timer Status Register: %02x & %04x\n", m_timers.timer_status_register, mem_mask);
558712         }
559         return (scc68070->timers.timer_status_register << 8) | scc68070->timers.timer_control_register;
713         return (m_timers.timer_status_register << 8) | m_timers.timer_control_register;
560714      case 0x2022/2:
561         verboselog(space.machine(), 2, "scc68070_periphs_r: Timer Reload Register: %04x & %04x\n", scc68070->timers.reload_register, mem_mask);
562         return scc68070->timers.reload_register;
715         verboselog(machine(), 2, "cdi68070_periphs_r: Timer Reload Register: %04x & %04x\n", m_timers.reload_register, mem_mask);
716         return m_timers.reload_register;
563717      case 0x2024/2:
564         verboselog(space.machine(), 2, "scc68070_periphs_r: Timer 0: %04x & %04x\n", scc68070->timers.timer0, mem_mask);
565         return scc68070->timers.timer0;
718         verboselog(machine(), 2, "cdi68070_periphs_r: Timer 0: %04x & %04x\n", m_timers.timer0, mem_mask);
719         return m_timers.timer0;
566720      case 0x2026/2:
567         verboselog(space.machine(), 2, "scc68070_periphs_r: Timer 1: %04x & %04x\n", scc68070->timers.timer1, mem_mask);
568         return scc68070->timers.timer1;
721         verboselog(machine(), 2, "cdi68070_periphs_r: Timer 1: %04x & %04x\n", m_timers.timer1, mem_mask);
722         return m_timers.timer1;
569723      case 0x2028/2:
570         verboselog(space.machine(), 2, "scc68070_periphs_r: Timer 2: %04x & %04x\n", scc68070->timers.timer2, mem_mask);
571         return scc68070->timers.timer2;
724         verboselog(machine(), 2, "cdi68070_periphs_r: Timer 2: %04x & %04x\n", m_timers.timer2, mem_mask);
725         return m_timers.timer2;
572726
573727      // PICR1: 80002045
574728      case 0x2044/2:
575729         if(ACCESSING_BITS_0_7)
576730         {
577            verboselog(space.machine(), 2, "scc68070_periphs_r: Peripheral Interrupt Control Register 1: %02x & %04x\n", scc68070->picr1, mem_mask);
731            verboselog(machine(), 2, "cdi68070_periphs_r: Peripheral Interrupt Control Register 1: %02x & %04x\n", m_picr1, mem_mask);
578732         }
579         return scc68070->picr1;
733         return m_picr1;
580734
581735      // PICR2: 80002047
582736      case 0x2046/2:
583737         if(ACCESSING_BITS_0_7)
584738         {
585            verboselog(space.machine(), 2, "scc68070_periphs_r: Peripheral Interrupt Control Register 2: %02x & %04x\n", scc68070->picr2, mem_mask);
739            verboselog(machine(), 2, "cdi68070_periphs_r: Peripheral Interrupt Control Register 2: %02x & %04x\n", m_picr2, mem_mask);
586740         }
587         return scc68070->picr2 & 0x77;
741         return m_picr2 & 0x77;
588742
589743      // DMA controller: 80004000 to 8000406d
590744      case 0x4000/2:
591745      case 0x4040/2:
592746         if(ACCESSING_BITS_0_7)
593747         {
594            verboselog(space.machine(), 2, "scc68070_periphs_r: DMA(%d) Error Register: %04x & %04x\n", (offset - 0x2000) / 32, scc68070->dma.channel[(offset - 0x2000) / 32].channel_error, mem_mask);
748            verboselog(machine(), 2, "cdi68070_periphs_r: DMA(%d) Error Register: %04x & %04x\n", (offset - 0x2000) / 32, m_dma.channel[(offset - 0x2000) / 32].channel_error, mem_mask);
595749         }
596750         if(ACCESSING_BITS_8_15)
597751         {
598            verboselog(space.machine(), 2, "scc68070_periphs_r: DMA(%d) Status Register: %04x & %04x\n", (offset - 0x2000) / 32, scc68070->dma.channel[(offset - 0x2000) / 32].channel_status, mem_mask);
752            verboselog(machine(), 2, "cdi68070_periphs_r: DMA(%d) Status Register: %04x & %04x\n", (offset - 0x2000) / 32, m_dma.channel[(offset - 0x2000) / 32].channel_status, mem_mask);
599753         }
600         return (scc68070->dma.channel[(offset - 0x2000) / 32].channel_status << 8) | scc68070->dma.channel[(offset - 0x2000) / 32].channel_error;
754         return (m_dma.channel[(offset - 0x2000) / 32].channel_status << 8) | m_dma.channel[(offset - 0x2000) / 32].channel_error;
601755      case 0x4004/2:
602756      case 0x4044/2:
603757         if(ACCESSING_BITS_0_7)
604758         {
605            verboselog(space.machine(), 2, "scc68070_periphs_r: DMA(%d) Operation Control Register: %02x & %04x\n", (offset - 0x2000) / 32, scc68070->dma.channel[(offset - 0x2000) / 32].operation_control, mem_mask);
759            verboselog(machine(), 2, "cdi68070_periphs_r: DMA(%d) Operation Control Register: %02x & %04x\n", (offset - 0x2000) / 32, m_dma.channel[(offset - 0x2000) / 32].operation_control, mem_mask);
606760         }
607761         if(ACCESSING_BITS_8_15)
608762         {
609            verboselog(space.machine(), 2, "scc68070_periphs_r: DMA(%d) Device Control Register: %02x & %04x\n", (offset - 0x2000) / 32, scc68070->dma.channel[(offset - 0x2000) / 32].device_control, mem_mask);
763            verboselog(machine(), 2, "cdi68070_periphs_r: DMA(%d) Device Control Register: %02x & %04x\n", (offset - 0x2000) / 32, m_dma.channel[(offset - 0x2000) / 32].device_control, mem_mask);
610764         }
611         return (scc68070->dma.channel[(offset - 0x2000) / 32].device_control << 8) | scc68070->dma.channel[(offset - 0x2000) / 32].operation_control;
765         return (m_dma.channel[(offset - 0x2000) / 32].device_control << 8) | m_dma.channel[(offset - 0x2000) / 32].operation_control;
612766      case 0x4006/2:
613767      case 0x4046/2:
614768         if(ACCESSING_BITS_0_7)
615769         {
616            verboselog(space.machine(), 2, "scc68070_periphs_r: DMA(%d) Channel Control Register: %02x & %04x\n", (offset - 0x2000) / 32, scc68070->dma.channel[(offset - 0x2000) / 32].channel_control, mem_mask);
770            verboselog(machine(), 2, "cdi68070_periphs_r: DMA(%d) Channel Control Register: %02x & %04x\n", (offset - 0x2000) / 32, m_dma.channel[(offset - 0x2000) / 32].channel_control, mem_mask);
617771         }
618772         if(ACCESSING_BITS_8_15)
619773         {
620            verboselog(space.machine(), 2, "scc68070_periphs_r: DMA(%d) Sequence Control Register: %02x & %04x\n", (offset - 0x2000) / 32, scc68070->dma.channel[(offset - 0x2000) / 32].sequence_control, mem_mask);
774            verboselog(machine(), 2, "cdi68070_periphs_r: DMA(%d) Sequence Control Register: %02x & %04x\n", (offset - 0x2000) / 32, m_dma.channel[(offset - 0x2000) / 32].sequence_control, mem_mask);
621775         }
622         return (scc68070->dma.channel[(offset - 0x2000) / 32].sequence_control << 8) | scc68070->dma.channel[(offset - 0x2000) / 32].channel_control;
776         return (m_dma.channel[(offset - 0x2000) / 32].sequence_control << 8) | m_dma.channel[(offset - 0x2000) / 32].channel_control;
623777      case 0x400a/2:
624         verboselog(space.machine(), 2, "scc68070_periphs_r: DMA(%d) Memory Transfer Counter: %04x & %04x\n", (offset - 0x2000) / 32, scc68070->dma.channel[(offset - 0x2000) / 32].transfer_counter, mem_mask);
625         return scc68070->dma.channel[(offset - 0x2000) / 32].transfer_counter;
778         verboselog(machine(), 2, "cdi68070_periphs_r: DMA(%d) Memory Transfer Counter: %04x & %04x\n", (offset - 0x2000) / 32, m_dma.channel[(offset - 0x2000) / 32].transfer_counter, mem_mask);
779         return m_dma.channel[(offset - 0x2000) / 32].transfer_counter;
626780      case 0x400c/2:
627781      case 0x404c/2:
628         verboselog(space.machine(), 2, "scc68070_periphs_r: DMA(%d) Memory Address Counter (High Word): %04x & %04x\n", (offset - 0x2000) / 32, (scc68070->dma.channel[(offset - 0x2000) / 32].memory_address_counter >> 16), mem_mask);
629         return (scc68070->dma.channel[(offset - 0x2000) / 32].memory_address_counter >> 16);
782         verboselog(machine(), 2, "cdi68070_periphs_r: DMA(%d) Memory Address Counter (High Word): %04x & %04x\n", (offset - 0x2000) / 32, (m_dma.channel[(offset - 0x2000) / 32].memory_address_counter >> 16), mem_mask);
783         return (m_dma.channel[(offset - 0x2000) / 32].memory_address_counter >> 16);
630784      case 0x400e/2:
631785      case 0x404e/2:
632         verboselog(space.machine(), 2, "scc68070_periphs_r: DMA(%d) Memory Address Counter (Low Word): %04x & %04x\n", (offset - 0x2000) / 32, scc68070->dma.channel[(offset - 0x2000) / 32].memory_address_counter, mem_mask);
633         return scc68070->dma.channel[(offset - 0x2000) / 32].memory_address_counter;
786         verboselog(machine(), 2, "cdi68070_periphs_r: DMA(%d) Memory Address Counter (Low Word): %04x & %04x\n", (offset - 0x2000) / 32, m_dma.channel[(offset - 0x2000) / 32].memory_address_counter, mem_mask);
787         return m_dma.channel[(offset - 0x2000) / 32].memory_address_counter;
634788      case 0x4014/2:
635789      case 0x4054/2:
636         verboselog(space.machine(), 2, "scc68070_periphs_r: DMA(%d) Device Address Counter (High Word): %04x & %04x\n", (offset - 0x2000) / 32, (scc68070->dma.channel[(offset - 0x2000) / 32].device_address_counter >> 16), mem_mask);
637         return (scc68070->dma.channel[(offset - 0x2000) / 32].device_address_counter >> 16);
790         verboselog(machine(), 2, "cdi68070_periphs_r: DMA(%d) Device Address Counter (High Word): %04x & %04x\n", (offset - 0x2000) / 32, (m_dma.channel[(offset - 0x2000) / 32].device_address_counter >> 16), mem_mask);
791         return (m_dma.channel[(offset - 0x2000) / 32].device_address_counter >> 16);
638792      case 0x4016/2:
639793      case 0x4056/2:
640         verboselog(space.machine(), 2, "scc68070_periphs_r: DMA(%d) Device Address Counter (Low Word): %04x & %04x\n", (offset - 0x2000) / 32, scc68070->dma.channel[(offset - 0x2000) / 32].device_address_counter, mem_mask);
641         return scc68070->dma.channel[(offset - 0x2000) / 32].device_address_counter;
794         verboselog(machine(), 2, "cdi68070_periphs_r: DMA(%d) Device Address Counter (Low Word): %04x & %04x\n", (offset - 0x2000) / 32, m_dma.channel[(offset - 0x2000) / 32].device_address_counter, mem_mask);
795         return m_dma.channel[(offset - 0x2000) / 32].device_address_counter;
642796
643797      // MMU: 80008000 to 8000807f
644798      case 0x8000/2:  // Status / Control register
645799         if(ACCESSING_BITS_0_7)
646800         {   // Control
647            verboselog(space.machine(), 2, "scc68070_periphs_r: MMU Control: %02x & %04x\n", scc68070->mmu.control, mem_mask);
648            return scc68070->mmu.control;
801            verboselog(machine(), 2, "cdi68070_periphs_r: MMU Control: %02x & %04x\n", m_mmu.control, mem_mask);
802            return m_mmu.control;
649803         }   // Status
650804         else
651805         {
652            verboselog(space.machine(), 2, "scc68070_periphs_r: MMU Status: %02x & %04x\n", scc68070->mmu.status, mem_mask);
653            return scc68070->mmu.status;
806            verboselog(machine(), 2, "cdi68070_periphs_r: MMU Status: %02x & %04x\n", m_mmu.status, mem_mask);
807            return m_mmu.status;
654808         }
655809         break;
656810      case 0x8040/2:
r20508r20509
661815      case 0x8068/2:
662816      case 0x8070/2:
663817      case 0x8078/2:  // Attributes (SD0-7)
664         verboselog(space.machine(), 2, "scc68070_periphs_r: MMU descriptor %d attributes: %04x & %04x\n", (offset - 0x4020) / 4, scc68070->mmu.desc[(offset - 0x4020) / 4].attr, mem_mask);
665         return scc68070->mmu.desc[(offset - 0x4020) / 4].attr;
818         verboselog(machine(), 2, "cdi68070_periphs_r: MMU descriptor %d attributes: %04x & %04x\n", (offset - 0x4020) / 4, m_mmu.desc[(offset - 0x4020) / 4].attr, mem_mask);
819         return m_mmu.desc[(offset - 0x4020) / 4].attr;
666820      case 0x8042/2:
667821      case 0x804a/2:
668822      case 0x8052/2:
r20508r20509
671825      case 0x806a/2:
672826      case 0x8072/2:
673827      case 0x807a/2:  // Segment Length (SD0-7)
674         verboselog(space.machine(), 2, "scc68070_periphs_r: MMU descriptor %d length: %04x & %04x\n", (offset - 0x4020) / 4, scc68070->mmu.desc[(offset - 0x4020) / 4].length, mem_mask);
675         return scc68070->mmu.desc[(offset - 0x4020) / 4].length;
828         verboselog(machine(), 2, "cdi68070_periphs_r: MMU descriptor %d length: %04x & %04x\n", (offset - 0x4020) / 4, m_mmu.desc[(offset - 0x4020) / 4].length, mem_mask);
829         return m_mmu.desc[(offset - 0x4020) / 4].length;
676830      case 0x8044/2:
677831      case 0x804c/2:
678832      case 0x8054/2:
r20508r20509
683837      case 0x807c/2:  // Segment Number (SD0-7, A0=1 only)
684838         if(ACCESSING_BITS_0_7)
685839         {
686            verboselog(space.machine(), 2, "scc68070_periphs_r: MMU descriptor %d segment: %02x & %04x\n", (offset - 0x4020) / 4, scc68070->mmu.desc[(offset - 0x4020) / 4].segment, mem_mask);
687            return scc68070->mmu.desc[(offset - 0x4020) / 4].segment;
840            verboselog(machine(), 2, "cdi68070_periphs_r: MMU descriptor %d segment: %02x & %04x\n", (offset - 0x4020) / 4, m_mmu.desc[(offset - 0x4020) / 4].segment, mem_mask);
841            return m_mmu.desc[(offset - 0x4020) / 4].segment;
688842         }
689843         break;
690844      case 0x8046/2:
r20508r20509
695849      case 0x806e/2:
696850      case 0x8076/2:
697851      case 0x807e/2:  // Base Address (SD0-7)
698         verboselog(space.machine(), 2, "scc68070_periphs_r: MMU descriptor %d base: %04x & %04x\n", (offset - 0x4020) / 4, scc68070->mmu.desc[(offset - 0x4020) / 4].base, mem_mask);
699         return scc68070->mmu.desc[(offset - 0x4020) / 4].base;
852         verboselog(machine(), 2, "cdi68070_periphs_r: MMU descriptor %d base: %04x & %04x\n", (offset - 0x4020) / 4, m_mmu.desc[(offset - 0x4020) / 4].base, mem_mask);
853         return m_mmu.desc[(offset - 0x4020) / 4].base;
700854      default:
701         verboselog(space.machine(), 0, "scc68070_periphs_r: Unknown address: %04x & %04x\n", offset * 2, mem_mask);
855         verboselog(space.machine(), 0, "cdi68070_periphs_r: Unknown address: %04x & %04x\n", offset * 2, mem_mask);
702856         break;
703857   }
704858
705859   return 0;
706860}
707861
708WRITE16_HANDLER( scc68070_periphs_w )
862WRITE16_MEMBER( cdi68070_device::periphs_w )
709863{
710   cdi_state *state = space.machine().driver_data<cdi_state>();
711   scc68070_regs_t *scc68070 = &state->m_scc68070_regs;
864   cdi_state *state = machine().driver_data<cdi_state>();
712865
713866   switch(offset)
714867   {
715868      // Interrupts: 80001001
716869      case 0x1000/2: // LIR priority level
717         verboselog(space.machine(), 2, "scc68070_periphs_w: LIR: %04x & %04x\n", data, mem_mask);
718         COMBINE_DATA(&scc68070->lir);
870         verboselog(machine(), 2, "cdi68070_periphs_w: LIR: %04x & %04x\n", data, mem_mask);
871         COMBINE_DATA(&m_lir);
719872         break;
720873
721874      // I2C interface: 80002001 to 80002009
722875      case 0x2000/2:
723876         if(ACCESSING_BITS_0_7)
724877         {
725            verboselog(space.machine(), 2, "scc68070_periphs_w: I2C Data Register: %04x & %04x\n", data, mem_mask);
726            scc68070->i2c.data_register = data & 0x00ff;
878            verboselog(machine(), 2, "cdi68070_periphs_w: I2C Data Register: %04x & %04x\n", data, mem_mask);
879            m_i2c.data_register = data & 0x00ff;
727880         }
728881         break;
729882      case 0x2002/2:
730883         if(ACCESSING_BITS_0_7)
731884         {
732            verboselog(space.machine(), 2, "scc68070_periphs_w: I2C Address Register: %04x & %04x\n", data, mem_mask);
733            scc68070->i2c.address_register = data & 0x00ff;
885            verboselog(machine(), 2, "cdi68070_periphs_w: I2C Address Register: %04x & %04x\n", data, mem_mask);
886            m_i2c.address_register = data & 0x00ff;
734887         }
735888         break;
736889      case 0x2004/2:
737890         if(ACCESSING_BITS_0_7)
738891         {
739            verboselog(space.machine(), 2, "scc68070_periphs_w: I2C Status Register: %04x & %04x\n", data, mem_mask);
740            scc68070->i2c.status_register = data & 0x00ff;
892            verboselog(machine(), 2, "cdi68070_periphs_w: I2C Status Register: %04x & %04x\n", data, mem_mask);
893            m_i2c.status_register = data & 0x00ff;
741894         }
742895         break;
743896      case 0x2006/2:
744897         if(ACCESSING_BITS_0_7)
745898         {
746            verboselog(space.machine(), 2, "scc68070_periphs_w: I2C Control Register: %04x & %04x\n", data, mem_mask);
747            scc68070->i2c.control_register = data & 0x00ff;
899            verboselog(machine(), 2, "cdi68070_periphs_w: I2C Control Register: %04x & %04x\n", data, mem_mask);
900            m_i2c.control_register = data & 0x00ff;
748901         }
749902         break;
750903      case 0x2008/2:
751904         if(ACCESSING_BITS_0_7)
752905         {
753            verboselog(space.machine(), 2, "scc68070_periphs_w: I2C Clock Control Register: %04x & %04x\n", data, mem_mask);
754            scc68070->i2c.clock_control_register = data & 0x00ff;
906            verboselog(machine(), 2, "cdi68070_periphs_w: I2C Clock Control Register: %04x & %04x\n", data, mem_mask);
907            m_i2c.clock_control_register = data & 0x00ff;
755908         }
756909         break;
757910
r20508r20509
759912      case 0x2010/2:
760913         if(ACCESSING_BITS_0_7)
761914         {
762            verboselog(space.machine(), 2, "scc68070_periphs_w: UART Mode Register: %04x & %04x\n", data, mem_mask);
763            scc68070->uart.mode_register = data & 0x00ff;
915            verboselog(machine(), 2, "cdi68070_periphs_w: UART Mode Register: %04x & %04x\n", data, mem_mask);
916            m_uart.mode_register = data & 0x00ff;
764917         }
765918         else
766919         {
767            verboselog(space.machine(), 0, "scc68070_periphs_w: Unknown address: %04x = %04x & %04x\n", offset * 2, data, mem_mask);
920            verboselog(machine(), 0, "cdi68070_periphs_w: Unknown address: %04x = %04x & %04x\n", offset * 2, data, mem_mask);
768921         }
769922         break;
770923      case 0x2012/2:
771924         if(ACCESSING_BITS_0_7)
772925         {
773            verboselog(space.machine(), 2, "scc68070_periphs_w: UART Status Register: %04x & %04x\n", data, mem_mask);
774            scc68070->uart.status_register = data & 0x00ff;
926            verboselog(machine(), 2, "cdi68070_periphs_w: UART Status Register: %04x & %04x\n", data, mem_mask);
927            m_uart.status_register = data & 0x00ff;
775928         }
776929         else
777930         {
778            verboselog(space.machine(), 0, "scc68070_periphs_w: Unknown address: %04x = %04x & %04x\n", offset * 2, data, mem_mask);
931            verboselog(machine(), 0, "cdi68070_periphs_w: Unknown address: %04x = %04x & %04x\n", offset * 2, data, mem_mask);
779932         }
780933         break;
781934      case 0x2014/2:
782935         if(ACCESSING_BITS_0_7)
783936         {
784            verboselog(space.machine(), 2, "scc68070_periphs_w: UART Clock Select: %04x & %04x\n", data, mem_mask);
785            scc68070->uart.clock_select = data & 0x00ff;
937            verboselog(machine(), 2, "cdi68070_periphs_w: UART Clock Select: %04x & %04x\n", data, mem_mask);
938            m_uart.clock_select = data & 0x00ff;
786939         }
787940         else
788941         {
789            verboselog(space.machine(), 0, "scc68070_periphs_w: Unknown address: %04x = %04x & %04x\n", offset * 2, data, mem_mask);
942            verboselog(machine(), 0, "cdi68070_periphs_w: Unknown address: %04x = %04x & %04x\n", offset * 2, data, mem_mask);
790943         }
791944         break;
792945      case 0x2016/2:
793946         if(ACCESSING_BITS_0_7)
794947         {
795            verboselog(space.machine(), 2, "scc68070_periphs_w: UART Command Register: %04x & %04x\n", data, mem_mask);
796            scc68070->uart.command_register = data & 0x00ff;
797            scc68070_uart_rx_check(space.machine(), scc68070);
798            scc68070_uart_tx_check(space.machine(), scc68070);
948            verboselog(machine(), 2, "cdi68070_periphs_w: UART Command Register: %04x & %04x\n", data, mem_mask);
949            m_uart.command_register = data & 0x00ff;
950            uart_rx_check();
951            uart_tx_check();
799952         }
800953         else
801954         {
802            verboselog(space.machine(), 0, "scc68070_periphs_w: Unknown address: %04x = %04x & %04x\n", offset * 2, data, mem_mask);
955            verboselog(machine(), 0, "cdi68070_periphs_w: Unknown address: %04x = %04x & %04x\n", offset * 2, data, mem_mask);
803956         }
804957         break;
805958      case 0x2018/2:
806959         if(ACCESSING_BITS_0_7)
807960         {
808            verboselog(space.machine(), 2, "scc68070_periphs_w: UART Transmit Holding Register: %04x & %04x: %c\n", data, mem_mask, (data >= 0x20 && data < 0x7f) ? (data & 0x00ff) : ' ');
809            scc68070_uart_tx(space.machine(), scc68070, data & 0x00ff);
810            scc68070->uart.transmit_holding_register = data & 0x00ff;
961            verboselog(machine(), 2, "cdi68070_periphs_w: UART Transmit Holding Register: %04x & %04x: %c\n", data, mem_mask, (data >= 0x20 && data < 0x7f) ? (data & 0x00ff) : ' ');
962            uart_tx(data & 0x00ff);
963            m_uart.transmit_holding_register = data & 0x00ff;
811964         }
812965         else
813966         {
814            verboselog(space.machine(), 0, "scc68070_periphs_w: Unknown address: %04x = %04x & %04x\n", offset * 2, data, mem_mask);
967            verboselog(machine(), 0, "cdi68070_periphs_w: Unknown address: %04x = %04x & %04x\n", offset * 2, data, mem_mask);
815968         }
816969         break;
817970      case 0x201a/2:
818971         if(ACCESSING_BITS_0_7)
819972         {
820            verboselog(space.machine(), 2, "scc68070_periphs_w: UART Receive Holding Register: %04x & %04x\n", data, mem_mask);
821            scc68070->uart.receive_holding_register = data & 0x00ff;
973            verboselog(machine(), 2, "cdi68070_periphs_w: UART Receive Holding Register: %04x & %04x\n", data, mem_mask);
974            m_uart.receive_holding_register = data & 0x00ff;
822975         }
823976         else
824977         {
825            verboselog(space.machine(), 0, "scc68070_periphs_w: Unknown address: %04x = %04x & %04x\n", offset * 2, data, mem_mask);
978            verboselog(machine(), 0, "cdi68070_periphs_w: Unknown address: %04x = %04x & %04x\n", offset * 2, data, mem_mask);
826979         }
827980         break;
828981
r20508r20509
830983      case 0x2020/2:
831984         if(ACCESSING_BITS_0_7)
832985         {
833            verboselog(space.machine(), 2, "scc68070_periphs_w: Timer Control Register: %04x & %04x\n", data, mem_mask);
834            scc68070->timers.timer_control_register = data & 0x00ff;
986            verboselog(machine(), 2, "cdi68070_periphs_w: Timer Control Register: %04x & %04x\n", data, mem_mask);
987            m_timers.timer_control_register = data & 0x00ff;
835988         }
836989         if(ACCESSING_BITS_8_15)
837990         {
838            verboselog(space.machine(), 12, "scc68070_periphs_w: Timer Status Register: %04x & %04x\n", data, mem_mask);
839            scc68070->timers.timer_status_register &= ~(data >> 8);
840            if(!scc68070->timers.timer_status_register)
991            verboselog(machine(), 12, "cdi68070_periphs_w: Timer Status Register: %04x & %04x\n", data, mem_mask);
992            m_timers.timer_status_register &= ~(data >> 8);
993            if(!m_timers.timer_status_register)
841994            {
842               UINT8 interrupt = scc68070->picr1 & 7;
843               space.machine().device("maincpu")->execute().set_input_line(M68K_IRQ_1 + (interrupt - 1), CLEAR_LINE);
995               UINT8 interrupt = m_picr1 & 7;
996               state->m_maincpu->set_input_line(M68K_IRQ_1 + (interrupt - 1), CLEAR_LINE);
844997            }
845998         }
846999         break;
8471000      case 0x2022/2:
848         verboselog(space.machine(), 2, "scc68070_periphs_w: Timer Reload Register: %04x & %04x\n", data, mem_mask);
849         COMBINE_DATA(&scc68070->timers.reload_register);
1001         verboselog(machine(), 2, "cdi68070_periphs_w: Timer Reload Register: %04x & %04x\n", data, mem_mask);
1002         COMBINE_DATA(&m_timers.reload_register);
8501003         break;
8511004      case 0x2024/2:
852         verboselog(space.machine(), 2, "scc68070_periphs_w: Timer 0: %04x & %04x\n", data, mem_mask);
853         COMBINE_DATA(&scc68070->timers.timer0);
854         scc68070_set_timer_callback(&state->m_scc68070_regs, 0);
1005         verboselog(machine(), 2, "cdi68070_periphs_w: Timer 0: %04x & %04x\n", data, mem_mask);
1006         COMBINE_DATA(&m_timers.timer0);
1007         set_timer_callback(0);
8551008         break;
8561009      case 0x2026/2:
857         verboselog(space.machine(), 2, "scc68070_periphs_w: Timer 1: %04x & %04x\n", data, mem_mask);
858         COMBINE_DATA(&scc68070->timers.timer1);
1010         verboselog(machine(), 2, "cdi68070_periphs_w: Timer 1: %04x & %04x\n", data, mem_mask);
1011         COMBINE_DATA(&m_timers.timer1);
8591012         break;
8601013      case 0x2028/2:
861         verboselog(space.machine(), 2, "scc68070_periphs_w: Timer 2: %04x & %04x\n", data, mem_mask);
862         COMBINE_DATA(&scc68070->timers.timer2);
1014         verboselog(machine(), 2, "cdi68070_periphs_w: Timer 2: %04x & %04x\n", data, mem_mask);
1015         COMBINE_DATA(&m_timers.timer2);
8631016         break;
8641017
8651018      // PICR1: 80002045
8661019      case 0x2044/2:
8671020         if(ACCESSING_BITS_0_7)
8681021         {
869            verboselog(space.machine(), 2, "scc68070_periphs_w: Peripheral Interrupt Control Register 1: %04x & %04x\n", data, mem_mask);
870            scc68070->picr1 = data & 0x00ff;
1022            verboselog(machine(), 2, "cdi68070_periphs_w: Peripheral Interrupt Control Register 1: %04x & %04x\n", data, mem_mask);
1023            m_picr1 = data & 0x00ff;
8711024         }
8721025         break;
8731026
r20508r20509
8751028      case 0x2046/2:
8761029         if(ACCESSING_BITS_0_7)
8771030         {
878            verboselog(space.machine(), 2, "scc68070_periphs_w: Peripheral Interrupt Control Register 2: %04x & %04x\n", data, mem_mask);
879            scc68070->picr2 = data & 0x00ff;
1031            verboselog(machine(), 2, "cdi68070_periphs_w: Peripheral Interrupt Control Register 2: %04x & %04x\n", data, mem_mask);
1032            m_picr2 = data & 0x00ff;
8801033         }
8811034         break;
8821035
r20508r20509
8851038      case 0x4040/2:
8861039         if(ACCESSING_BITS_0_7)
8871040         {
888            verboselog(space.machine(), 2, "scc68070_periphs_w: DMA(%d) Error (invalid): %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask);
1041            verboselog(machine(), 2, "cdi68070_periphs_w: DMA(%d) Error (invalid): %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask);
8891042         }
8901043         if(ACCESSING_BITS_8_15)
8911044         {
892            verboselog(space.machine(), 2, "scc68070_periphs_w: DMA(%d) Status: %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask);
893            scc68070->dma.channel[(offset - 0x2000) / 32].channel_status &= ~(data & 0xb0);
1045            verboselog(machine(), 2, "cdi68070_periphs_w: DMA(%d) Status: %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask);
1046            m_dma.channel[(offset - 0x2000) / 32].channel_status &= ~(data & 0xb0);
8941047         }
8951048         break;
8961049      case 0x4004/2:
8971050      case 0x4044/2:
8981051         if(ACCESSING_BITS_0_7)
8991052         {
900            verboselog(space.machine(), 2, "scc68070_periphs_w: DMA(%d) Operation Control Register: %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask);
901            scc68070->dma.channel[(offset - 0x2000) / 32].operation_control = data & 0x00ff;
1053            verboselog(machine(), 2, "cdi68070_periphs_w: DMA(%d) Operation Control Register: %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask);
1054            m_dma.channel[(offset - 0x2000) / 32].operation_control = data & 0x00ff;
9021055         }
9031056         if(ACCESSING_BITS_8_15)
9041057         {
905            verboselog(space.machine(), 2, "scc68070_periphs_w: DMA(%d) Device Control Register: %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask);
906            scc68070->dma.channel[(offset - 0x2000) / 32].device_control = data >> 8;
1058            verboselog(machine(), 2, "cdi68070_periphs_w: DMA(%d) Device Control Register: %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask);
1059            m_dma.channel[(offset - 0x2000) / 32].device_control = data >> 8;
9071060         }
9081061         break;
9091062      case 0x4006/2:
9101063      case 0x4046/2:
9111064         if(ACCESSING_BITS_0_7)
9121065         {
913            verboselog(space.machine(), 2, "scc68070_periphs_w: DMA(%d) Channel Control Register: %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask);
914            scc68070->dma.channel[(offset - 0x2000) / 32].channel_control = data & 0x007f;
1066            verboselog(machine(), 2, "cdi68070_periphs_w: DMA(%d) Channel Control Register: %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask);
1067            m_dma.channel[(offset - 0x2000) / 32].channel_control = data & 0x007f;
9151068            if(data & CCR_SO)
9161069            {
917               scc68070->dma.channel[(offset - 0x2000) / 32].channel_status |= CSR_COC;
1070               m_dma.channel[(offset - 0x2000) / 32].channel_status |= CSR_COC;
9181071            }
9191072         }
9201073         if(ACCESSING_BITS_8_15)
9211074         {
922            verboselog(space.machine(), 2, "scc68070_periphs_w: DMA(%d) Sequence Control Register: %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask);
923            scc68070->dma.channel[(offset - 0x2000) / 32].sequence_control = data >> 8;
1075            verboselog(machine(), 2, "cdi68070_periphs_w: DMA(%d) Sequence Control Register: %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask);
1076            m_dma.channel[(offset - 0x2000) / 32].sequence_control = data >> 8;
9241077         }
9251078         break;
9261079      case 0x400a/2:
927         verboselog(space.machine(), 2, "scc68070_periphs_w: DMA(%d) Memory Transfer Counter: %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask);
928         COMBINE_DATA(&scc68070->dma.channel[(offset - 0x2000) / 32].transfer_counter);
1080         verboselog(machine(), 2, "cdi68070_periphs_w: DMA(%d) Memory Transfer Counter: %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask);
1081         COMBINE_DATA(&m_dma.channel[(offset - 0x2000) / 32].transfer_counter);
9291082         break;
9301083      case 0x400c/2:
9311084      case 0x404c/2:
932         verboselog(space.machine(), 2, "scc68070_periphs_w: DMA(%d) Memory Address Counter (High Word): %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask);
933         scc68070->dma.channel[(offset - 0x2000) / 32].memory_address_counter &= ~(mem_mask << 16);
934         scc68070->dma.channel[(offset - 0x2000) / 32].memory_address_counter |= data << 16;
1085         verboselog(machine(), 2, "cdi68070_periphs_w: DMA(%d) Memory Address Counter (High Word): %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask);
1086         m_dma.channel[(offset - 0x2000) / 32].memory_address_counter &= ~(mem_mask << 16);
1087         m_dma.channel[(offset - 0x2000) / 32].memory_address_counter |= data << 16;
9351088         break;
9361089      case 0x400e/2:
9371090      case 0x404e/2:
938         verboselog(space.machine(), 2, "scc68070_periphs_w: DMA(%d) Memory Address Counter (Low Word): %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask);
939         scc68070->dma.channel[(offset - 0x2000) / 32].memory_address_counter &= ~mem_mask;
940         scc68070->dma.channel[(offset - 0x2000) / 32].memory_address_counter |= data;
1091         verboselog(machine(), 2, "cdi68070_periphs_w: DMA(%d) Memory Address Counter (Low Word): %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask);
1092         m_dma.channel[(offset - 0x2000) / 32].memory_address_counter &= ~mem_mask;
1093         m_dma.channel[(offset - 0x2000) / 32].memory_address_counter |= data;
9411094         break;
9421095      case 0x4014/2:
9431096      case 0x4054/2:
944         verboselog(space.machine(), 2, "scc68070_periphs_w: DMA(%d) Device Address Counter (High Word): %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask);
945         scc68070->dma.channel[(offset - 0x2000) / 32].device_address_counter &= ~(mem_mask << 16);
946         scc68070->dma.channel[(offset - 0x2000) / 32].device_address_counter |= data << 16;
1097         verboselog(machine(), 2, "cdi68070_periphs_w: DMA(%d) Device Address Counter (High Word): %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask);
1098         m_dma.channel[(offset - 0x2000) / 32].device_address_counter &= ~(mem_mask << 16);
1099         m_dma.channel[(offset - 0x2000) / 32].device_address_counter |= data << 16;
9471100         break;
9481101      case 0x4016/2:
9491102      case 0x4056/2:
950         verboselog(space.machine(), 2, "scc68070_periphs_w: DMA(%d) Device Address Counter (Low Word): %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask);
951         scc68070->dma.channel[(offset - 0x2000) / 32].device_address_counter &= ~mem_mask;
952         scc68070->dma.channel[(offset - 0x2000) / 32].device_address_counter |= data;
1103         verboselog(machine(), 2, "cdi68070_periphs_w: DMA(%d) Device Address Counter (Low Word): %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask);
1104         m_dma.channel[(offset - 0x2000) / 32].device_address_counter &= ~mem_mask;
1105         m_dma.channel[(offset - 0x2000) / 32].device_address_counter |= data;
9531106         break;
9541107
9551108      // MMU: 80008000 to 8000807f
9561109      case 0x8000/2:  // Status / Control register
9571110         if(ACCESSING_BITS_0_7)
9581111         {   // Control
959            verboselog(space.machine(), 2, "scc68070_periphs_w: MMU Control: %04x & %04x\n", data, mem_mask);
960            scc68070->mmu.control = data & 0x00ff;
1112            verboselog(machine(), 2, "cdi68070_periphs_w: MMU Control: %04x & %04x\n", data, mem_mask);
1113            m_mmu.control = data & 0x00ff;
9611114         }   // Status
9621115         else
9631116         {
964            verboselog(space.machine(), 0, "scc68070_periphs_w: MMU Status (invalid): %04x & %04x\n", data, mem_mask);
1117            verboselog(machine(), 0, "cdi68070_periphs_w: MMU Status (invalid): %04x & %04x\n", data, mem_mask);
9651118         }
9661119         break;
9671120      case 0x8040/2:
r20508r20509
9721125      case 0x8068/2:
9731126      case 0x8070/2:
9741127      case 0x8078/2:  // Attributes (SD0-7)
975         verboselog(space.machine(), 2, "scc68070_periphs_w: MMU descriptor %d attributes: %04x & %04x\n", (offset - 0x4020) / 4, data, mem_mask);
976         COMBINE_DATA(&scc68070->mmu.desc[(offset - 0x4020) / 4].attr);
1128         verboselog(machine(), 2, "cdi68070_periphs_w: MMU descriptor %d attributes: %04x & %04x\n", (offset - 0x4020) / 4, data, mem_mask);
1129         COMBINE_DATA(&m_mmu.desc[(offset - 0x4020) / 4].attr);
9771130         break;
9781131      case 0x8042/2:
9791132      case 0x804a/2:
r20508r20509
9831136      case 0x806a/2:
9841137      case 0x8072/2:
9851138      case 0x807a/2:  // Segment Length (SD0-7)
986         verboselog(space.machine(), 2, "scc68070_periphs_w: MMU descriptor %d length: %04x & %04x\n", (offset - 0x4020) / 4, data, mem_mask);
987         COMBINE_DATA(&scc68070->mmu.desc[(offset - 0x4020) / 4].length);
1139         verboselog(machine(), 2, "cdi68070_periphs_w: MMU descriptor %d length: %04x & %04x\n", (offset - 0x4020) / 4, data, mem_mask);
1140         COMBINE_DATA(&m_mmu.desc[(offset - 0x4020) / 4].length);
9881141         break;
9891142      case 0x8044/2:
9901143      case 0x804c/2:
r20508r20509
9961149      case 0x807c/2:  // Segment Number (SD0-7, A0=1 only)
9971150         if(ACCESSING_BITS_0_7)
9981151         {
999            verboselog(space.machine(), 2, "scc68070_periphs_w: MMU descriptor %d segment: %04x & %04x\n", (offset - 0x4020) / 4, data, mem_mask);
1000            scc68070->mmu.desc[(offset - 0x4020) / 4].segment = data & 0x00ff;
1152            verboselog(machine(), 2, "cdi68070_periphs_w: MMU descriptor %d segment: %04x & %04x\n", (offset - 0x4020) / 4, data, mem_mask);
1153            m_mmu.desc[(offset - 0x4020) / 4].segment = data & 0x00ff;
10011154         }
10021155         break;
10031156      case 0x8046/2:
r20508r20509
10081161      case 0x806e/2:
10091162      case 0x8076/2:
10101163      case 0x807e/2:  // Base Address (SD0-7)
1011         verboselog(space.machine(), 2, "scc68070_periphs_w: MMU descriptor %d base: %04x & %04x\n", (offset - 0x4020) / 4, data, mem_mask);
1012         COMBINE_DATA(&scc68070->mmu.desc[(offset - 0x4020) / 4].base);
1164         verboselog(machine(), 2, "cdi68070_periphs_w: MMU descriptor %d base: %04x & %04x\n", (offset - 0x4020) / 4, data, mem_mask);
1165         COMBINE_DATA(&m_mmu.desc[(offset - 0x4020) / 4].base);
10131166         break;
10141167      default:
1015         verboselog(space.machine(), 0, "scc68070_periphs_w: Unknown address: %04x = %04x & %04x\n", offset * 2, data, mem_mask);
1168         verboselog(machine(), 0, "cdi68070_periphs_w: Unknown address: %04x = %04x & %04x\n", offset * 2, data, mem_mask);
10161169         break;
10171170   }
10181171}
10191172
1020void scc68070_init(running_machine &machine, scc68070_regs_t *scc68070)
1021{
1022   int index = 0;
1023   scc68070->lir = 0;
1024
1025   scc68070->picr1 = 0;
1026   scc68070->picr2 = 0;
1027
1028   scc68070->i2c.data_register = 0;
1029   scc68070->i2c.address_register = 0;
1030   scc68070->i2c.status_register = 0;
1031   scc68070->i2c.control_register = 0;
1032   scc68070->i2c.clock_control_register = 0;
1033
1034   scc68070->uart.mode_register = 0;
1035   scc68070->uart.status_register = USR_TXRDY;
1036   scc68070->uart.clock_select = 0;
1037   scc68070->uart.command_register = 0;
1038   scc68070->uart.transmit_holding_register = 0;
1039   scc68070->uart.receive_holding_register = 0;
1040   scc68070->uart.receive_pointer = -1;
1041   scc68070->uart.transmit_pointer = -1;
1042
1043   scc68070->timers.timer_status_register = 0;
1044   scc68070->timers.timer_control_register = 0;
1045   scc68070->timers.reload_register = 0;
1046   scc68070->timers.timer0 = 0;
1047   scc68070->timers.timer1 = 0;
1048   scc68070->timers.timer2 = 0;
1049
1050   for(index = 0; index < 2; index++)
1051   {
1052      scc68070->dma.channel[index].channel_status = 0;
1053      scc68070->dma.channel[index].channel_error = 0;
1054      scc68070->dma.channel[index].device_control = 0;
1055      scc68070->dma.channel[index].operation_control = 0;
1056      scc68070->dma.channel[index].sequence_control = 0;
1057      scc68070->dma.channel[index].channel_control = 0;
1058      scc68070->dma.channel[index].transfer_counter = 0;
1059      scc68070->dma.channel[index].memory_address_counter = 0;
1060      scc68070->dma.channel[index].device_address_counter = 0;
1061   }
1062
1063   scc68070->mmu.status = 0;
1064   scc68070->mmu.control = 0;
1065   for(index = 0; index < 8; index++)
1066   {
1067      scc68070->mmu.desc[index].attr = 0;
1068      scc68070->mmu.desc[index].length = 0;
1069      scc68070->mmu.desc[index].segment = 0;
1070      scc68070->mmu.desc[index].base = 0;
1071   }
1072}
1073
1074void scc68070_register_globals(running_machine &machine, scc68070_regs_t *scc68070)
1075{
1076   state_save_register_global(machine, scc68070->lir);
1077
1078   state_save_register_global(machine, scc68070->picr1);
1079   state_save_register_global(machine, scc68070->picr2);
1080
1081   state_save_register_global(machine, scc68070->i2c.data_register);
1082   state_save_register_global(machine, scc68070->i2c.address_register);
1083   state_save_register_global(machine, scc68070->i2c.status_register);
1084   state_save_register_global(machine, scc68070->i2c.control_register);
1085   state_save_register_global(machine, scc68070->i2c.clock_control_register);
1086
1087   state_save_register_global(machine, scc68070->uart.mode_register);
1088   state_save_register_global(machine, scc68070->uart.status_register);
1089   state_save_register_global(machine, scc68070->uart.clock_select);
1090   state_save_register_global(machine, scc68070->uart.command_register);
1091   state_save_register_global(machine, scc68070->uart.transmit_holding_register);
1092   state_save_register_global(machine, scc68070->uart.receive_holding_register);
1093
1094   state_save_register_global(machine, scc68070->timers.timer_status_register);
1095   state_save_register_global(machine, scc68070->timers.timer_control_register);
1096   state_save_register_global(machine, scc68070->timers.reload_register);
1097   state_save_register_global(machine, scc68070->timers.timer0);
1098   state_save_register_global(machine, scc68070->timers.timer1);
1099   state_save_register_global(machine, scc68070->timers.timer2);
1100
1101   state_save_register_global(machine, scc68070->dma.channel[0].channel_status);
1102   state_save_register_global(machine, scc68070->dma.channel[0].channel_error);
1103   state_save_register_global(machine, scc68070->dma.channel[0].device_control);
1104   state_save_register_global(machine, scc68070->dma.channel[0].operation_control);
1105   state_save_register_global(machine, scc68070->dma.channel[0].sequence_control);
1106   state_save_register_global(machine, scc68070->dma.channel[0].channel_control);
1107   state_save_register_global(machine, scc68070->dma.channel[0].transfer_counter);
1108   state_save_register_global(machine, scc68070->dma.channel[0].memory_address_counter);
1109   state_save_register_global(machine, scc68070->dma.channel[0].device_address_counter);
1110   state_save_register_global(machine, scc68070->dma.channel[1].channel_status);
1111   state_save_register_global(machine, scc68070->dma.channel[1].channel_error);
1112   state_save_register_global(machine, scc68070->dma.channel[1].device_control);
1113   state_save_register_global(machine, scc68070->dma.channel[1].operation_control);
1114   state_save_register_global(machine, scc68070->dma.channel[1].sequence_control);
1115   state_save_register_global(machine, scc68070->dma.channel[1].channel_control);
1116   state_save_register_global(machine, scc68070->dma.channel[1].transfer_counter);
1117   state_save_register_global(machine, scc68070->dma.channel[1].memory_address_counter);
1118   state_save_register_global(machine, scc68070->dma.channel[1].device_address_counter);
1119
1120   state_save_register_global(machine, scc68070->mmu.status);
1121   state_save_register_global(machine, scc68070->mmu.control);
1122   state_save_register_global(machine, scc68070->mmu.desc[0].attr);
1123   state_save_register_global(machine, scc68070->mmu.desc[0].length);
1124   state_save_register_global(machine, scc68070->mmu.desc[0].segment);
1125   state_save_register_global(machine, scc68070->mmu.desc[0].base);
1126   state_save_register_global(machine, scc68070->mmu.desc[1].attr);
1127   state_save_register_global(machine, scc68070->mmu.desc[1].length);
1128   state_save_register_global(machine, scc68070->mmu.desc[1].segment);
1129   state_save_register_global(machine, scc68070->mmu.desc[1].base);
1130   state_save_register_global(machine, scc68070->mmu.desc[2].attr);
1131   state_save_register_global(machine, scc68070->mmu.desc[2].length);
1132   state_save_register_global(machine, scc68070->mmu.desc[2].segment);
1133   state_save_register_global(machine, scc68070->mmu.desc[2].base);
1134   state_save_register_global(machine, scc68070->mmu.desc[3].attr);
1135   state_save_register_global(machine, scc68070->mmu.desc[3].length);
1136   state_save_register_global(machine, scc68070->mmu.desc[3].segment);
1137   state_save_register_global(machine, scc68070->mmu.desc[3].base);
1138   state_save_register_global(machine, scc68070->mmu.desc[4].attr);
1139   state_save_register_global(machine, scc68070->mmu.desc[4].length);
1140   state_save_register_global(machine, scc68070->mmu.desc[4].segment);
1141   state_save_register_global(machine, scc68070->mmu.desc[4].base);
1142   state_save_register_global(machine, scc68070->mmu.desc[5].attr);
1143   state_save_register_global(machine, scc68070->mmu.desc[5].length);
1144   state_save_register_global(machine, scc68070->mmu.desc[5].segment);
1145   state_save_register_global(machine, scc68070->mmu.desc[5].base);
1146   state_save_register_global(machine, scc68070->mmu.desc[6].attr);
1147   state_save_register_global(machine, scc68070->mmu.desc[6].length);
1148   state_save_register_global(machine, scc68070->mmu.desc[6].segment);
1149   state_save_register_global(machine, scc68070->mmu.desc[6].base);
1150   state_save_register_global(machine, scc68070->mmu.desc[7].attr);
1151   state_save_register_global(machine, scc68070->mmu.desc[7].length);
1152   state_save_register_global(machine, scc68070->mmu.desc[7].segment);
1153   state_save_register_global(machine, scc68070->mmu.desc[7].base);
1154
1155   scc68070->timers.timer0_timer = machine.scheduler().timer_alloc(FUNC(scc68070_timer0_callback));
1156   scc68070->timers.timer0_timer->adjust(attotime::never);
1157
1158   scc68070->uart.rx_timer = machine.scheduler().timer_alloc(FUNC(scc68070_rx_callback));
1159   scc68070->uart.rx_timer->adjust(attotime::never);
1160
1161   scc68070->uart.tx_timer = machine.scheduler().timer_alloc(FUNC(scc68070_tx_callback));
1162   scc68070->uart.tx_timer->adjust(attotime::never);
1163}
1164
11651173#if ENABLE_UART_PRINTING
11661174READ16_HANDLER( uart_loopback_enable )
11671175{
trunk/src/mame/machine/cdicdic.h
r20508r20509
2626
2727#include "emu.h"
2828#include "cdrom.h"
29#include "sound/cdda.h"
2930
3031
31
3232//**************************************************************************
3333//  INTERFACE CONFIGURATION MACROS
3434//**************************************************************************
r20508r20509
5959   void register_write(const UINT32 offset, const UINT16 data, const UINT16 mem_mask);
6060   UINT16 register_read(const UINT32 offset, const UINT16 mem_mask);
6161
62   DECLARE_READ16_MEMBER( regs_r );
63   DECLARE_WRITE16_MEMBER( regs_w );
64   DECLARE_READ16_MEMBER( ram_r );
65   DECLARE_WRITE16_MEMBER( ram_w );
66
67
6268protected:
6369   // device-level overrides
6470   virtual void device_start();
r20508r20509
6773   virtual void device_clock_changed() { }
6874
6975   // internal callbacks
70   static TIMER_CALLBACK( audio_sample_trigger );
71   static TIMER_CALLBACK( trigger_readback_int );
76   TIMER_CALLBACK_MEMBER( audio_sample_trigger );
77   TIMER_CALLBACK_MEMBER( trigger_readback_int );
7278
7379private:
7480   // internal state
r20508r20509
99105   int m_xa_last[4];
100106   UINT16 *m_ram;
101107
102   void register_globals();
103   void init();
104
105108   // static internal members
106109   static void decode_xa_mono(INT32 *cdic_xa_last, const UINT8 *xa, INT16 *dp);
107110   static void decode_xa_mono8(INT32 *cdic_xa_last, const UINT8 *xa, INT16 *dp);
r20508r20509
120123// device type definition
121124extern const device_type MACHINE_CDICDIC;
122125
123
124
125//**************************************************************************
126//  READ/WRITE HANDLERS
127//**************************************************************************
128
129DECLARE_READ16_DEVICE_HANDLER( cdic_r );
130DECLARE_WRITE16_DEVICE_HANDLER( cdic_w );
131DECLARE_READ16_DEVICE_HANDLER( cdic_ram_r );
132DECLARE_WRITE16_DEVICE_HANDLER( cdic_ram_w );
133
134
135126#endif // __CDICDIC_H__
trunk/src/mame/machine/cdi070.h
r20508r20509
1919
2020*******************************************************************************/
2121
22#ifndef _MACHINE_CDI070_H_
23#define _MACHINE_CDI070_H_
22#ifndef _MACHINE_CDI68070_H_
23#define _MACHINE_CDI68070_H_
2424
2525#include "emu.h"
2626
27struct scc68070_i2c_regs_t
28{
29   UINT8 reserved0;
30   UINT8 data_register;
31   UINT8 reserved1;
32   UINT8 address_register;
33   UINT8 reserved2;
34   UINT8 status_register;
35   UINT8 reserved3;
36   UINT8 control_register;
37   UINT8 reserved;
38   UINT8 clock_control_register;
39};
40
4127#define ISR_MST     0x80    // Master
4228#define ISR_TRX     0x40    // Transmitter
4329#define ISR_BB      0x20    // Busy
r20508r20509
4733#define ISR_AD0     0x02    // Address Zero
4834#define ISR_LRB     0x01    // Last Received Bit
4935
50struct scc68070_uart_regs_t
51{
52   UINT8 reserved0;
53   UINT8 mode_register;
54   UINT8 reserved1;
55   UINT8 status_register;
56   UINT8 reserved2;
57   UINT8 clock_select;
58   UINT8 reserved3;
59   UINT8 command_register;
60   UINT8 reserved4;
61   UINT8 transmit_holding_register;
62   UINT8 reserved5;
63   UINT8 receive_holding_register;
64
65   INT16 receive_pointer;
66   UINT8 receive_buffer[32768];
67   emu_timer* rx_timer;
68
69   INT16 transmit_pointer;
70   UINT8 transmit_buffer[32768];
71   emu_timer* tx_timer;
72};
73
7436#define UMR_OM          0xc0
7537#define UMR_OM_NORMAL   0x00
7638#define UMR_OM_ECHO     0x40
r20508r20509
9052#define USR_TXRDY       0x04
9153#define USR_RXRDY       0x01
9254
93struct scc68070_timer_regs_t
94{
95   UINT8 timer_status_register;
96   UINT8 timer_control_register;
97   UINT16 reload_register;
98   UINT16 timer0;
99   UINT16 timer1;
100   UINT16 timer2;
101   emu_timer* timer0_timer;
102};
103
10455#define TSR_OV0         0x80
10556#define TSR_MA1         0x40
10657#define TSR_CAP1        0x20
r20508r20509
13081#define TCR_M2_CAPTURE  0x02
13182#define TCR_M2_COUNT    0x03
13283
133struct scc68070_dma_channel_t
134{
135   UINT8 channel_status;
136   UINT8 channel_error;
137
138   UINT8 reserved0[2];
139
140   UINT8 device_control;
141   UINT8 operation_control;
142   UINT8 sequence_control;
143   UINT8 channel_control;
144
145   UINT8 reserved1[3];
146
147   UINT16 transfer_counter;
148
149   UINT32 memory_address_counter;
150
151   UINT8 reserved2[4];
152
153   UINT32 device_address_counter;
154
155   UINT8 reserved3[40];
156};
157
15884#define CSR_COC         0x80
15985#define CSR_NDT         0x20
16086#define CSR_ERR         0x10
r20508r20509
193119#define CCR_INE         0x08
194120#define CCR_IPL         0x07
195121
196struct scc68070_dma_regs_t
197{
198   scc68070_dma_channel_t channel[2];
199};
122//**************************************************************************
123//  INTERFACE CONFIGURATION MACROS
124//**************************************************************************
200125
201struct scc68070_mmu_desc_t
202{
203   UINT16 attr;
204   UINT16 length;
205   UINT8  undefined;
206   UINT8  segment;
207   UINT16 base;
208};
126#define MCFG_CDI68070_ADD(_tag) \
127   MCFG_DEVICE_ADD(_tag, MACHINE_CDI68070, 0)
128#define MCFG_CDI68070_REPLACE(_tag) \
129   MCFG_DEVICE_REPLACE(_tag, MACHINE_CDI68070, 0)
209130
210struct scc68070_mmu_regs_t
131//**************************************************************************
132//  TYPE DEFINITIONS
133//**************************************************************************
134
135// ======================> cdi68070_device
136
137class cdi68070_device : public device_t
211138{
212   UINT8 status;
213   UINT8 control;
139public:
140   // construction/destruction
141   cdi68070_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
214142
215   UINT8 reserved[0x3e];
143   // external callbacks
144   void init();
145   void uart_rx(UINT8 data);
146   void uart_tx(UINT8 data);
216147
217   scc68070_mmu_desc_t desc[8];
218};
148   // UART Access for Quizard
149   void set_quizard_mcu_value(UINT16 value);
150   void set_quizard_mcu_ack(UINT8 ack);
151   void quizard_rx(UINT8 data);
219152
220struct scc68070_regs_t
221{
222   UINT16 lir;
223   UINT8 picr1;
224   UINT8 picr2;
153   void mcu_frame();
225154
226   scc68070_i2c_regs_t i2c;
227   scc68070_uart_regs_t uart;
228   scc68070_timer_regs_t timers;
229   scc68070_dma_regs_t dma;
230   scc68070_mmu_regs_t mmu;
231};
155   DECLARE_READ16_MEMBER(periphs_r);
156   DECLARE_WRITE16_MEMBER(periphs_w);
232157
233// Member functions
234TIMER_CALLBACK( scc68070_timer0_callback );
235TIMER_CALLBACK( scc68070_rx_callback );
236TIMER_CALLBACK( scc68070_tx_callback );
237DECLARE_READ16_HANDLER( scc68070_periphs_r );
238DECLARE_WRITE16_HANDLER( scc68070_periphs_w );
239//DECLARE_READ16_HANDLER( uart_loopback_enable );
158   TIMER_CALLBACK_MEMBER( timer0_callback );
159   TIMER_CALLBACK_MEMBER( rx_callback );
160   TIMER_CALLBACK_MEMBER( tx_callback );
240161
241void scc68070_init(running_machine &machine, scc68070_regs_t *scc68070);
242void scc68070_uart_rx(running_machine &machine, scc68070_regs_t *scc68070, UINT8 data);
243void scc68070_uart_tx(running_machine &machine, scc68070_regs_t *scc68070, UINT8 data);
244void scc68070_register_globals(running_machine &machine, scc68070_regs_t *scc68070);
162   // register structures
163   struct i2c_regs_t
164   {
165      UINT8 reserved0;
166      UINT8 data_register;
167      UINT8 reserved1;
168      UINT8 address_register;
169      UINT8 reserved2;
170      UINT8 status_register;
171      UINT8 reserved3;
172      UINT8 control_register;
173      UINT8 reserved;
174      UINT8 clock_control_register;
175   };
245176
246// UART Access for Quizard
247void scc68070_set_quizard_mcu_value(running_machine &machine, UINT16 value);
248void scc68070_set_quizard_mcu_ack(running_machine &machine, UINT8 ack);
249void scc68070_quizard_rx(running_machine &machine, scc68070_regs_t *scc68070, UINT8 data);
177   struct uart_regs_t
178   {
179      UINT8 reserved0;
180      UINT8 mode_register;
181      UINT8 reserved1;
182      UINT8 status_register;
183      UINT8 reserved2;
184      UINT8 clock_select;
185      UINT8 reserved3;
186      UINT8 command_register;
187      UINT8 reserved4;
188      UINT8 transmit_holding_register;
189      UINT8 reserved5;
190      UINT8 receive_holding_register;
250191
251INTERRUPT_GEN( scc68070_mcu_frame );
192      INT16 receive_pointer;
193      UINT8 receive_buffer[32768];
194      emu_timer* rx_timer;
252195
253#endif // _MACHINE_CDI070_H_
196      INT16 transmit_pointer;
197      UINT8 transmit_buffer[32768];
198      emu_timer* tx_timer;
199   };
200
201   struct timer_regs_t
202   {
203      UINT8 timer_status_register;
204      UINT8 timer_control_register;
205      UINT16 reload_register;
206      UINT16 timer0;
207      UINT16 timer1;
208      UINT16 timer2;
209      emu_timer* timer0_timer;
210   };
211
212   struct dma_channel_t
213   {
214      UINT8 channel_status;
215      UINT8 channel_error;
216
217      UINT8 reserved0[2];
218
219      UINT8 device_control;
220      UINT8 operation_control;
221      UINT8 sequence_control;
222      UINT8 channel_control;
223
224      UINT8 reserved1[3];
225
226      UINT16 transfer_counter;
227
228      UINT32 memory_address_counter;
229
230      UINT8 reserved2[4];
231
232      UINT32 device_address_counter;
233
234      UINT8 reserved3[40];
235   };
236
237   struct dma_regs_t
238   {
239      dma_channel_t channel[2];
240   };
241
242   struct mmu_desc_t
243   {
244      UINT16 attr;
245      UINT16 length;
246      UINT8  undefined;
247      UINT8  segment;
248      UINT16 base;
249   };
250
251   struct mmu_regs_t
252   {
253      UINT8 status;
254      UINT8 control;
255
256      UINT8 reserved[0x3e];
257
258      mmu_desc_t desc[8];
259   };
260
261   dma_regs_t& dma() { return m_dma; }
262
263   UINT16 get_lir() { return m_lir; }
264
265protected:
266   // device-level overrides
267   virtual void device_start();
268   virtual void device_reset();
269
270private:
271
272   void uart_rx_check();
273   void uart_tx_check();
274   void set_timer_callback(int channel);
275
276   // internal state
277   emu_timer *m_interrupt_timer;
278
279   UINT16 m_seeds[10];
280   UINT8 m_state[8];
281
282   UINT16 m_mcu_value;
283   UINT8 m_mcu_ack;
284
285   UINT16 m_lir;
286   UINT8 m_picr1;
287   UINT8 m_picr2;
288
289   i2c_regs_t m_i2c;
290   uart_regs_t m_uart;
291   timer_regs_t m_timers;
292   dma_regs_t m_dma;
293   mmu_regs_t m_mmu;
294
295   // non-static internal members
296   void quizard_calculate_state();
297   void quizard_set_seeds(UINT8 *rx);
298   void quizard_handle_byte_tx();
299};
300
301// device type definition
302extern const device_type MACHINE_CDI68070;
303
304#endif // _MACHINE_CDI68070_H_
trunk/src/mame/video/mcd212.c
r20508r20509
620620            mcd212->channel[1].csrr |= 1 << (2 - channel);
621621            if(mcd212->channel[1].csrr & (MCD212_CSR2R_IT1 | MCD212_CSR2R_IT2))
622622            {
623               UINT8 interrupt = (state->m_scc68070_regs.lir >> 4) & 7;
623               UINT8 interrupt = (state->m_scc->get_lir() >> 4) & 7;
624624               if(interrupt)
625625               {
626                  machine.device("maincpu")->execute().set_input_line_vector(M68K_IRQ_1 + (interrupt - 1), 56 + interrupt);
627                  machine.device("maincpu")->execute().set_input_line(M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE);
626                  state->m_maincpu->set_input_line_vector(M68K_IRQ_1 + (interrupt - 1), 56 + interrupt);
627                  state->m_maincpu->set_input_line(M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE);
628628               }
629629            }
630630#if 0
r20508r20509
633633               UINT8 interrupt = state->m_scc68070_regs.lir & 7;
634634               if(interrupt)
635635               {
636                  machine.device("maincpu")->execute().set_input_line_vector(M68K_IRQ_1 + (interrupt - 1), 24 + interrupt);
637                  machine.device("maincpu")->execute().set_input_line(M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE);
636                  state->m_maincpu->set_input_line_vector(M68K_IRQ_1 + (interrupt - 1), 24 + interrupt);
637                  state->m_maincpu->set_input_line(M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE);
638638               }
639639            }
640640#endif
r20508r20509
711711            mcd212->channel[1].csrr |= 1 << (2 - channel);
712712            if(mcd212->channel[1].csrr & (MCD212_CSR2R_IT1 | MCD212_CSR2R_IT2))
713713            {
714               UINT8 interrupt = (state->m_scc68070_regs.lir >> 4) & 7;
714               UINT8 interrupt = (state->m_scc->get_lir() >> 4) & 7;
715715               if(interrupt)
716716               {
717                  machine.device("maincpu")->execute().set_input_line_vector(M68K_IRQ_1 + (interrupt - 1), 56 + interrupt);
718                  machine.device("maincpu")->execute().set_input_line(M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE);
717                  state->m_maincpu->set_input_line_vector(M68K_IRQ_1 + (interrupt - 1), 56 + interrupt);
718                  state->m_maincpu->set_input_line(M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE);
719719               }
720720            }
721721#if 0
r20508r20509
724724               UINT8 interrupt = state->m_scc68070_regs.lir & 7;
725725               if(interrupt)
726726               {
727                  machine.device("maincpu")->execute().set_input_line_vector(M68K_IRQ_1 + (interrupt - 1), 24 + interrupt);
728                  machine.device("maincpu")->execute().set_input_line(M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE);
727                  state->m_maincpu->set_input_line_vector(M68K_IRQ_1 + (interrupt - 1), 24 + interrupt);
728                  state->m_maincpu->set_input_line(M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE);
729729               }
730730            }
731731#endif
r20508r20509
13711371            else
13721372            {
13731373               UINT8 old_csr = mcd212->channel[1].csrr;
1374               UINT8 interrupt1 = (state->m_scc68070_regs.lir >> 4) & 7;
1374               UINT8 interrupt1 = (state->m_scc->get_lir() >> 4) & 7;
13751375               //UINT8 interrupt2 = state->m_scc68070_regs.lir & 7;
13761376               mcd212->channel[1].csrr &= ~(MCD212_CSR2R_IT1 | MCD212_CSR2R_IT2);
13771377               if(interrupt1)
13781378               {
1379                  space.machine().device("maincpu")->execute().set_input_line(M68K_IRQ_1 + (interrupt1 - 1), CLEAR_LINE);
1379                  state->m_maincpu->set_input_line(M68K_IRQ_1 + (interrupt1 - 1), CLEAR_LINE);
13801380               }
13811381               //if(interrupt2)
13821382               //{
1383               //  space.machine().device("maincpu")->execute().set_input_line(M68K_IRQ_1 + (interrupt2 - 1), CLEAR_LINE);
1383               //  state->m_maincpu->set_input_line(M68K_IRQ_1 + (interrupt2 - 1), CLEAR_LINE);
13841384               //}
13851385               return old_csr;
13861386            }
trunk/src/mame/includes/cdi.h
r20508r20509
1616{
1717public:
1818   cdi_state(const machine_config &mconfig, device_type type, const char *tag)
19      : driver_device(mconfig, type, tag) ,
19      : driver_device(mconfig, type, tag),
20      m_maincpu(*this, "maincpu"),
2021      m_planea(*this, "planea"),
21      m_planeb(*this, "planeb"){ }
22      m_planeb(*this, "planeb"),
23      m_input1(*this, "INPUT1"),
24      m_input2(*this, "INPUT2"),
25      m_mousex(*this, "MOUSEX"),
26      m_mousey(*this, "MOUSEY"),
27      m_mousebtn(*this, "MOUSEBTN"),
28      m_slave(*this, "slave"),
29      m_scc(*this, "scc68070"),
30      m_cdic(*this, "cdic"),
31      m_cdda(*this, "cdda"){ }
2232
33   required_device<cpu_device> m_maincpu;
2334   required_shared_ptr<UINT16> m_planea;
2435   required_shared_ptr<UINT16> m_planeb;
36   optional_device<ioport_port> m_input1;
37   optional_device<ioport_port> m_input2;
38   required_ioport m_mousex;
39   required_ioport m_mousey;
40   required_ioport m_mousebtn;
41   required_device<cdislave_device> m_slave;
42   required_device<cdi68070_device> m_scc;
43   required_device<cdicdic_device> m_cdic;
44   required_device<cdda_device> m_cdda;
2545
2646   dmadac_sound_device *m_dmadac[2];
2747
48   INTERRUPT_GEN_MEMBER( mcu_frame );
49
2850   UINT8 m_timer_set;
2951   emu_timer *m_test_timer;
3052   bitmap_rgb32 m_lcdbitmap;
31   scc68070_regs_t m_scc68070_regs;
3253   mcd212_regs_t m_mcd212_regs;
3354   mcd212_ab_t m_mcd212_ab;
3455   DECLARE_INPUT_CHANGED_MEMBER(mcu_input);
trunk/src/mame/drivers/cdi.c
r20508r20509
6161#if ENABLE_UART_PRINTING
6262   AM_RANGE(0x00301400, 0x00301403) AM_READ_LEGACY(uart_loopback_enable)
6363#endif
64   AM_RANGE(0x00300000, 0x00303bff) AM_DEVREADWRITE_LEGACY("cdic", cdic_ram_r, cdic_ram_w)
65   //AM_RANGE(0x00300000, 0x00303bff) AM_RAM AM_SHARE("cdic_regs.ram")
66   AM_RANGE(0x00303c00, 0x00303fff) AM_DEVREADWRITE_LEGACY("cdic", cdic_r, cdic_w)
67   AM_RANGE(0x00310000, 0x00317fff) AM_DEVREADWRITE_LEGACY("slave", slave_r, slave_w)
64   AM_RANGE(0x00300000, 0x00303bff) AM_DEVREADWRITE("cdic", cdicdic_device, ram_r, ram_w)
65   AM_RANGE(0x00303c00, 0x00303fff) AM_DEVREADWRITE("cdic", cdicdic_device, regs_r, regs_w)
66   AM_RANGE(0x00310000, 0x00317fff) AM_DEVREADWRITE("slave", cdislave_device, slave_r, slave_w)
6867   //AM_RANGE(0x00318000, 0x0031ffff) AM_NOP
6968   AM_RANGE(0x00320000, 0x00323fff) AM_DEVREADWRITE8_LEGACY("mk48t08", timekeeper_r, timekeeper_w, 0xff00)    /* nvram (only low bytes used) */
7069   AM_RANGE(0x00400000, 0x0047ffff) AM_ROM AM_REGION("maincpu", 0)
r20508r20509
7271   //AM_RANGE(0x00500000, 0x0057ffff) AM_RAM
7372   AM_RANGE(0x00500000, 0x00ffffff) AM_NOP
7473   //AM_RANGE(0x00e00000, 0x00efffff) AM_RAM // DVC
75   AM_RANGE(0x80000000, 0x8000807f) AM_READWRITE_LEGACY(scc68070_periphs_r, scc68070_periphs_w)
74   AM_RANGE(0x80000000, 0x8000807f) AM_DEVREADWRITE("scc68070", cdi68070_device, periphs_r, periphs_w)
7675ADDRESS_MAP_END
7776
7877/*************************
r20508r20509
8180
8281INPUT_CHANGED_MEMBER(cdi_state::mcu_input)
8382{
84   scc68070_regs_t *scc68070 = &m_scc68070_regs;
8583   bool send = false;
8684
8785   switch((FPTR)param)
8886   {
8987      case 0x39:
90         if(ioport("INPUT1")->read() & 0x01) send = true;
88         if(m_input1->read() & 0x01) send = true;
9189         break;
9290      case 0x37:
93         if(ioport("INPUT1")->read() & 0x02) send = true;
91         if(m_input1->read() & 0x02) send = true;
9492         break;
9593      case 0x31:
96         if(ioport("INPUT1")->read() & 0x04) send = true;
94         if(m_input1->read() & 0x04) send = true;
9795         break;
9896      case 0x32:
99         if(ioport("INPUT1")->read() & 0x08) send = true;
97         if(m_input1->read() & 0x08) send = true;
10098         break;
10199      case 0x33:
102         if(ioport("INPUT1")->read() & 0x10) send = true;
100         if(m_input1->read() & 0x10) send = true;
103101         break;
104102
105103      case 0x30:
106         if(ioport("INPUT2")->read() & 0x01) send = true;
104         if(m_input2->read() & 0x01) send = true;
107105         break;
108106      case 0x38:
109         if(ioport("INPUT2")->read() & 0x02) send = true;
107         if(m_input2->read() & 0x02) send = true;
110108         break;
111109      case 0x34:
112         if(ioport("INPUT2")->read() & 0x04) send = true;
110         if(m_input2->read() & 0x04) send = true;
113111         break;
114112      case 0x35:
115         if(ioport("INPUT2")->read() & 0x08) send = true;
113         if(m_input2->read() & 0x08) send = true;
116114         break;
117115      case 0x36:
118         if(ioport("INPUT2")->read() & 0x10) send = true;
116         if(m_input2->read() & 0x10) send = true;
119117         break;
120118   }
121119
122120   if(send)
123121   {
124122      UINT8 data = (UINT8)((FPTR)param & 0x000000ff);
125      scc68070_quizard_rx(machine(), scc68070, data);
123      m_scc->quizard_rx(data);
126124   }
127125}
128126
r20508r20509
191189
192190void cdi_state::machine_start()
193191{
194   scc68070_register_globals(machine(), &m_scc68070_regs);
195192}
196193
194INTERRUPT_GEN_MEMBER( cdi_state::mcu_frame )
195{
196   m_scc->mcu_frame();
197}
198
197199MACHINE_RESET_MEMBER(cdi_state,cdi)
198200{
199201   UINT16 *src   = (UINT16*)memregion("maincpu")->base();
r20508r20509
201203   //device_t *cdrom_dev = machine().device("cdrom");
202204   memcpy(dst, src, 0x8);
203205
204   scc68070_init(machine(), &m_scc68070_regs);
206   m_maincpu->reset();
205207
206   machine().device("maincpu")->reset();
207
208208   m_dmadac[0] = machine().device<dmadac_sound_device>("dac1");
209209   m_dmadac[1] = machine().device<dmadac_sound_device>("dac2");
210210}
r20508r20509
213213{
214214   MACHINE_RESET_CALL_MEMBER( cdi );
215215
216   scc68070_set_quizard_mcu_value(machine(), 0x021f);
217   scc68070_set_quizard_mcu_ack(machine(), 0x5a);
216   m_scc->set_quizard_mcu_value(0x021f);
217   m_scc->set_quizard_mcu_ack(0x5a);
218218}
219219
220220MACHINE_RESET_MEMBER(cdi_state,quizrd17)
221221{
222222   MACHINE_RESET_CALL_MEMBER( cdi );
223223
224   scc68070_set_quizard_mcu_value(machine(), 0x021f);
225   scc68070_set_quizard_mcu_ack(machine(), 0x5a);
224   m_scc->set_quizard_mcu_value(0x021f);
225   m_scc->set_quizard_mcu_ack(0x5a);
226226}
227227
228228/* Untested - copied from quizrd17 */
r20508r20509
230230{
231231   MACHINE_RESET_CALL_MEMBER( cdi );
232232
233   scc68070_set_quizard_mcu_value(machine(), 0x021f);
234   scc68070_set_quizard_mcu_ack(machine(), 0x5a);
233   m_scc->set_quizard_mcu_value(0x021f);
234   m_scc->set_quizard_mcu_ack(0x5a);
235235}
236236
237237MACHINE_RESET_MEMBER(cdi_state,quizrd22)
r20508r20509
242242   // 0x001: French
243243   // 0x188: German
244244
245   scc68070_set_quizard_mcu_value(machine(), 0x188);
246   scc68070_set_quizard_mcu_ack(machine(), 0x59);
245   m_scc->set_quizard_mcu_value(0x188);
246   m_scc->set_quizard_mcu_ack(0x59);
247247}
248248
249249/* Untested - copied from quizrd22 */
r20508r20509
255255   // 0x001: French
256256   // 0x188: German
257257
258   scc68070_set_quizard_mcu_value(machine(), 0x188);
259   scc68070_set_quizard_mcu_ack(machine(), 0x59);
258   m_scc->set_quizard_mcu_value(0x188);
259   m_scc->set_quizard_mcu_ack(0x59);
260260}
261261
262262MACHINE_RESET_MEMBER(cdi_state,quizrd32)
263263{
264264   MACHINE_RESET_CALL_MEMBER( cdi );
265265
266   scc68070_set_quizard_mcu_value(machine(), 0x00ae);
267   scc68070_set_quizard_mcu_ack(machine(), 0x58);
266   m_scc->set_quizard_mcu_value(0x00ae);
267   m_scc->set_quizard_mcu_ack(0x58);
268268}
269269
270270/* Untested - copied from quizrd32 */
r20508r20509
272272{
273273   MACHINE_RESET_CALL_MEMBER( cdi );
274274
275   scc68070_set_quizard_mcu_value(machine(), 0x00ae);
276   scc68070_set_quizard_mcu_ack(machine(), 0x58);
275   m_scc->set_quizard_mcu_value(0x00ae);
276   m_scc->set_quizard_mcu_ack(0x58);
277277}
278278
279279/* Untested - copied from quizrr41 */
r20508r20509
281281{
282282   MACHINE_RESET_CALL_MEMBER( cdi );
283283
284   //scc68070_set_quizard_mcu_value(machine(), 0x0139);
285   scc68070_set_quizard_mcu_value(machine(), 0x011f);
286   scc68070_set_quizard_mcu_ack(machine(), 0x57);
284   //m_scc->set_quizard_mcu_value(0x0139);
285   m_scc->set_quizard_mcu_value(0x011f);
286   m_scc->set_quizard_mcu_ack(0x57);
287287}
288288
289289MACHINE_RESET_MEMBER(cdi_state,quizrr41)
290290{
291291   MACHINE_RESET_CALL_MEMBER( cdi );
292292
293   //scc68070_set_quizard_mcu_value(machine(), 0x0139);
294   scc68070_set_quizard_mcu_value(machine(), 0x011f);
295   scc68070_set_quizard_mcu_ack(machine(), 0x57);
293   //m_scc->set_quizard_mcu_value(0x0139);
294   m_scc->set_quizard_mcu_value(0x011f);
295   m_scc->set_quizard_mcu_ack(0x57);
296296}
297297
298298MACHINE_RESET_MEMBER(cdi_state,quizrr42)
299299{
300300   MACHINE_RESET_CALL_MEMBER( cdi );
301301
302   scc68070_set_quizard_mcu_value(machine(), 0x01ae);
303   scc68070_set_quizard_mcu_ack(machine(), 0x57);
302   m_scc->set_quizard_mcu_value(0x01ae);
303   m_scc->set_quizard_mcu_ack(0x57);
304304}
305305
306306static DEVICE_IMAGE_DISPLAY_INFO(cdi_cdinfo)
r20508r20509
343343
344344   MCFG_DEFAULT_LAYOUT(layout_cdi)
345345
346   MCFG_CDI68070_ADD("scc68070")
347   MCFG_CDICDIC_ADD("cdic")
348   MCFG_CDISLAVE_ADD("slave")
346349
347
348   MCFG_CDICDIC_ADD( "cdic" )
349   MCFG_CDISLAVE_ADD( "slave" )
350
351350   /* sound hardware */
352351   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
353352
r20508r20509
384383static MACHINE_CONFIG_DERIVED( quizard, cdi_base )
385384   MCFG_CPU_MODIFY("maincpu")
386385   MCFG_CPU_PROGRAM_MAP(cdimono1_mem)
387   MCFG_CPU_VBLANK_INT("screen", scc68070_mcu_frame)
386   MCFG_CPU_VBLANK_INT_DRIVER("screen", cdi_state, mcu_frame)
388387MACHINE_CONFIG_END
389388
390389static MACHINE_CONFIG_DERIVED( quizrd12, quizard )

Previous 199869 Revisions Next


© 1997-2024 The MAME Team