Previous 15994 Revisions Next

r9490 Sunday 31st October, 2010 at 20:56:48 UTC by R. Belmont
[MAC] First pass conversion to a fully modern C++ implementation
[src/emu/sound]asc.c asc.h
[src/mess/audio]mac.c
[src/mess/drivers]mac.c
[src/mess/includes]mac.h
[src/mess/machine]mac.c
[src/mess/video]mac.c

src/emu/sound/asc.c
r9489r9490
135135   memset(m_regs, 0, sizeof(m_regs));
136136
137137   m_sync_timer = timer_alloc(this->machine, sync_timer_cb, this);
138
139   state_save_register_device_item(this, 0, m_fifo_a_rdptr);
140   state_save_register_device_item(this, 0, m_fifo_b_rdptr);
141   state_save_register_device_item(this, 0, m_fifo_a_wrptr);
142   state_save_register_device_item(this, 0, m_fifo_b_wrptr);
143   state_save_register_device_item(this, 0, m_fifo_cap_a);
144   state_save_register_device_item(this, 0, m_fifo_cap_b);
145   state_save_register_device_item_array(this, 0, m_fifo_a);
146   state_save_register_device_item_array(this, 0, m_fifo_b);
147   state_save_register_device_item_array(this, 0, m_regs);
148   state_save_register_device_item_array(this, 0, m_phase);
149   state_save_register_device_item_array(this, 0, m_incr);
138150}
139151
140152
r9489r9490
304316//  read - read from the chip's registers and internal RAM
305317//-------------------------------------------------
306318
307UINT8 asc_device::read(UINT16 offset)
319READ8_MEMBER( asc_device::read )
308320{
309321   UINT8 rv;
310322
r9489r9490
440452//  write - write to the chip's registers and internal RAM
441453//-------------------------------------------------
442454
443void asc_device::write(UINT16 offset, UINT8 data)
455WRITE8_MEMBER( asc_device::write )
444456{
445457//   printf("ASC: write %02x to %x\n", data, offset);
446458
src/emu/sound/asc.h
r9489r9490
9696   asc_device(running_machine &_machine, const asc_device_config &config);
9797
9898public:
99   UINT8 read(UINT16 offset);
100   void write(UINT16 offset, UINT8 data);
99   DECLARE_READ8_MEMBER(read);
100   DECLARE_WRITE8_MEMBER(write);
101101
102102   sound_stream *m_stream;
103103
src/mess/audio/mac.c
r9489r9490
66
77****************************************************************************/
88
9#define ADDRESS_MAP_MODERN
10
911#include "emu.h"
12#include "sound/asc.h"
1013#include "includes/mac.h"
1114#include "streams.h"
1215#include "devices/messram.h"
r9489r9490
7073   mac_sound *token = get_token(device);
7174   mac_state *mac = device->machine->driver_data<mac_state>();
7275
73   if ((mac->model == MODEL_MAC_PORTABLE) || (mac->model == MODEL_MAC_PB100))
76   if ((mac->m_model == MODEL_MAC_PORTABLE) || (mac->m_model == MODEL_MAC_PB100))
7477   {
7578      memset(buffer, 0, samples * sizeof(*buffer));
7679      return;
src/mess/machine/mac.c
r9489r9490
7979
8080****************************************************************************/
8181
82#define ADDRESS_MAP_MODERN
83
8284#include <time.h>
8385
8486#include "emu.h"
r9489r9490
8890#include "machine/applefdc.h"
8991#include "devices/sonydriv.h"
9092#include "machine/ncr5380.h"
93#include "sound/asc.h"
9194#include "includes/mac.h"
9295#include "debug/debugcpu.h"
9396#include "devices/messram.h"
9497#include "debugger.h"
9598
96#define ADB_IS_BITBANG   ((mac->model == MODEL_MAC_SE || mac->model == MODEL_MAC_CLASSIC) || (mac->model >= MODEL_MAC_II && mac->model <= MODEL_MAC_IICI) || (mac->model == MODEL_MAC_SE30))
97#define ADB_IS_EGRET   (mac->model >= MODEL_MAC_LC && mac->model <= MODEL_MAC_COLOR_CLASSIC) || ((mac->model >= MODEL_MAC_IISI) && (mac->model <= MODEL_MAC_IIVI))
98#define ADB_IS_PM   (mac->model >= MODEL_MAC_PORTABLE && mac->model <= MODEL_MAC_PB100)
99#define ADB_IS_BITBANG   ((mac->m_model == MODEL_MAC_SE || mac->m_model == MODEL_MAC_CLASSIC) || (mac->m_model >= MODEL_MAC_II && mac->m_model <= MODEL_MAC_IICI) || (mac->m_model == MODEL_MAC_SE30))
100#define ADB_IS_BITBANG_CLASS   ((m_model == MODEL_MAC_SE || m_model == MODEL_MAC_CLASSIC) || (m_model >= MODEL_MAC_II && m_model <= MODEL_MAC_IICI) || (m_model == MODEL_MAC_SE30))
101#define ADB_IS_EGRET   (mac->m_model >= MODEL_MAC_LC && mac->m_model <= MODEL_MAC_COLOR_CLASSIC) || ((mac->m_model >= MODEL_MAC_IISI) && (mac->m_model <= MODEL_MAC_IIVI))
102#define ADB_IS_PM   (mac->m_model >= MODEL_MAC_PORTABLE && mac->m_model <= MODEL_MAC_PB100)
103#define ADB_IS_PM_CLASS   (m_model >= MODEL_MAC_PORTABLE && m_model <= MODEL_MAC_PB100)
99104
100#define AUDIO_IS_CLASSIC (mac->model < MODEL_MAC_II) && (mac->model != MODEL_MAC_PORTABLE) && (mac->model != MODEL_MAC_PB100)
101#define MAC_HAS_VIA2   (mac->model >= MODEL_MAC_II)
105#define AUDIO_IS_CLASSIC (mac->m_model < MODEL_MAC_II) && (mac->m_model != MODEL_MAC_PORTABLE) && (mac->m_model != MODEL_MAC_PB100)
106#define AUDIO_IS_CLASSIC_CLASS (m_model < MODEL_MAC_II) && (m_model != MODEL_MAC_PORTABLE) && (m_model != MODEL_MAC_PB100)
107#define MAC_HAS_VIA2   (m_model >= MODEL_MAC_II)
102108
103#define ASC_INTS_RBV   ((mac->model >= MODEL_MAC_IICI) && (mac->model <= MODEL_MAC_IIVI)) || ((mac->model >= MODEL_MAC_LC) && (mac->model <= MODEL_MAC_COLOR_CLASSIC))
109#define ASC_INTS_RBV   ((mac->m_model >= MODEL_MAC_IICI) && (mac->m_model <= MODEL_MAC_IIVI)) || ((mac->m_model >= MODEL_MAC_LC) && (mac->m_model <= MODEL_MAC_COLOR_CLASSIC))
104110
105111#ifdef MAME_DEBUG
106112#define LOG_VIA         0
r9489r9490
189195};
190196
191197// returns non-zero if this Mac has ADB
192static int has_adb(mac_state *mac)
198int mac_state::has_adb()
193199{
194   return mac->model >= MODEL_MAC_SE;
200   return m_model >= MODEL_MAC_SE;
195201}
196202
197203// handle disk enable lines
198void mac_fdc_set_enable_lines(running_device *device,int enable_mask)
204void mac_fdc_set_enable_lines(running_device *device, int enable_mask)
199205{
200206   mac_state *mac = device->machine->driver_data<mac_state>();
201207
202   if (mac->model != MODEL_MAC_SE)
208   if (mac->m_model != MODEL_MAC_SE)
203209   {
204      sony_set_enable_lines(device,enable_mask);
210      sony_set_enable_lines(device, enable_mask);
205211   }
206212   else
207213   {
208214      if (enable_mask)
209215      {
210         sony_set_enable_lines(device,mac->drive_select ? 1 : 2);
216         sony_set_enable_lines(device, mac->m_drive_select ? 1 : 2);
211217      }
212218      else
213219      {
214         sony_set_enable_lines(device,enable_mask);
220         sony_set_enable_lines(device, enable_mask);
215221      }
216222   }
217223}
r9489r9490
250256    Interrupt handling
251257*/
252258
253static int scc_interrupt, via_interrupt, via2_interrupt, scsi_interrupt, last_taken_interrupt;
254
255static void mac_field_interrupts(running_machine *machine)
259void mac_state::field_interrupts(running_machine *machine)
256260{
257   mac_state *mac = machine->driver_data<mac_state>();
258
259261   int take_interrupt = -1;
260262
261   if (mac->model < MODEL_MAC_II)
263   if (m_model < MODEL_MAC_II)
262264   {
263      if ((scc_interrupt) || (scsi_interrupt))
265      if ((m_scc_interrupt) || (m_scsi_interrupt))
264266      {
265267         take_interrupt = 2;
266268      }
267      else if (via_interrupt)
269      else if (m_via_interrupt)
268270      {
269271         take_interrupt = 1;
270272      }
271273   }
272   else if (mac->model < MODEL_MAC_POWERMAC_6100)
274   else if (m_model < MODEL_MAC_POWERMAC_6100)
273275   {
274      if (scc_interrupt)
276      if (m_scc_interrupt)
275277      {
276278         take_interrupt = 4;
277279      }
278      else if (via2_interrupt)
280      else if (m_via2_interrupt)
279281      {
280282         take_interrupt = 2;
281283      }
282      else if (via_interrupt)
284      else if (m_via_interrupt)
283285      {
284286         take_interrupt = 1;
285287      }
r9489r9490
289291      return;   // no interrupts for PowerPC yet
290292   }
291293
292   if (last_taken_interrupt != -1)
294   if (m_last_taken_interrupt != -1)
293295   {
294      cputag_set_input_line(machine, "maincpu", last_taken_interrupt, CLEAR_LINE);
295      last_taken_interrupt = -1;
296      cputag_set_input_line(machine, "maincpu", m_last_taken_interrupt, CLEAR_LINE);
297      m_last_taken_interrupt = -1;
296298   }
297299
298300   if (take_interrupt != -1)
299301   {
300302      cputag_set_input_line(machine, "maincpu", take_interrupt, ASSERT_LINE);
301      last_taken_interrupt = take_interrupt;
303      m_last_taken_interrupt = take_interrupt;
302304   }
303305}
304306
305static void set_scc_interrupt(running_machine *machine, int value)
307void mac_state::set_scc_interrupt(running_machine *machine, int value)
306308{
307   scc_interrupt = value;
308   mac_field_interrupts(machine);
309   m_scc_interrupt = value;
310   field_interrupts(machine);
309311}
310312
311static void set_via_interrupt(running_machine *machine, int value)
313void mac_state::set_via_interrupt(running_machine *machine, int value)
312314{
313   via_interrupt = value;
314   mac_field_interrupts(machine);
315   m_via_interrupt = value;
316   field_interrupts(machine);
315317}
316318
317319
318void mac_set_via2_interrupt(running_machine *machine, int value)
320void mac_state::set_via2_interrupt(running_machine *machine, int value)
319321{
320   via2_interrupt = value;
321
322   mac_field_interrupts(machine);
322   m_via2_interrupt = value;
323   field_interrupts(machine);
323324}
324325
325326void mac_asc_irq(running_device *device, int state)
r9489r9490
330331   {
331332      if (state)
332333      {
333         mac->rbv_regs[3] |= 0x90;   // any VIA 2 interrupt | sound interrupt
334         mac->m_rbv_regs[3] |= 0x90;   // any VIA 2 interrupt | sound interrupt
334335
335         if (mac->rbv_ier & 0x10)   // ASC on RBV is CB1, bit 4 of IER/IFR
336         if (mac->m_rbv_ier & 0x10)   // ASC on RBV is CB1, bit 4 of IER/IFR
336337         {
337            mac->rbv_ifr |= 0x90;
338            mac_set_via2_interrupt(device->machine, 1);
338            mac->m_rbv_ifr |= 0x90;
339            mac->set_via2_interrupt(device->machine, 1);
339340         }
340341      }
341342      else
342343      {
343         mac->rbv_regs[3] &= ~0x90;
344         mac->rbv_ifr &= ~0x10;
344         mac->m_rbv_regs[3] &= ~0x90;
345         mac->m_rbv_ifr &= ~0x10;
345346      }
346347
347348   }
348   else if (mac->model >= MODEL_MAC_II)
349   else if (mac->m_model >= MODEL_MAC_II)
349350   {
350      via6522_device *via2 = device->machine->device<via6522_device>("via6522_1");
351
352      via2->write_cb1(state^1);
351      mac->m_via2->write_cb1(state^1);
353352   }
354353
355354   // todo: portable/pb100 hook up ASC IRQ differently
356355}
357356
358WRITE16_HANDLER ( mac_autovector_w )
357WRITE16_MEMBER ( mac_state::mac_autovector_w )
359358{
360359   if (LOG_GENERAL)
361360      logerror("mac_autovector_w: offset=0x%08x data=0x%04x\n", offset, data);
r9489r9490
365364   /* Not yet implemented */
366365}
367366
368READ16_HANDLER ( mac_autovector_r )
367READ16_MEMBER ( mac_state::mac_autovector_r )
369368{
370369   if (LOG_GENERAL)
371370      logerror("mac_autovector_r: offset=0x%08x\n", offset);
r9489r9490
384383   /* Not Yet Implemented */
385384}
386385
387void mac_v8_resize(running_machine *machine, mac_state *mac)
386void mac_state::v8_resize(running_machine *machine)
388387{
389388   offs_t memory_size;
390389   UINT8 *memory_data;
391390   int is_rom;
392391
393   is_rom = (mac->overlay) ? 1 : 0;
392   is_rom = (m_overlay) ? 1 : 0;
394393
395394   // get what memory we're going to map
396395   if (is_rom)
r9489r9490
403402   else
404403   {
405404      /* RAM */
406      memory_size = messram_get_size(machine->device("messram"));
407      memory_data = messram_get_ptr(machine->device("messram"));
405      memory_size = messram_get_size(m_ram);
406      memory_data = messram_get_ptr(m_ram);
408407      is_rom = FALSE;
409408   }
410409
411//   printf("mac_v8_resize: memory_size = %x, ctrl bits %02x (overlay %d = %s)\n", memory_size, mac->rbv_regs[1] & 0xe0, mac->overlay, is_rom ? "ROM" : "RAM");
410//   printf("mac_v8_resize: memory_size = %x, ctrl bits %02x (overlay %d = %s)\n", memory_size, mac->m_rbv_regs[1] & 0xe0, mac->m_overlay, is_rom ? "ROM" : "RAM");
412411
413412   if (is_rom)
414413   {
r9489r9490
426425      // LC has 2 MB built-in, all other V8-style machines have 4 MB
427426      // we reserve the first 2 or 4 MB of mess_ram for the onboard,
428427      // RAM above that mark is the SIMM
429      onboard_amt = ((mac->model == MODEL_MAC_LC) || (mac->model == MODEL_MAC_CLASSIC_II)) ? 2*1024*1024 : 4*1024*1024;
430      simm_amt = (mac->rbv_regs[1]>>6) & 3;   // size of SIMM RAM window
428      onboard_amt = ((m_model == MODEL_MAC_LC) || (m_model == MODEL_MAC_CLASSIC_II)) ? 2*1024*1024 : 4*1024*1024;
429      simm_amt = (m_rbv_regs[1]>>6) & 3;   // size of SIMM RAM window
431430      simm_size = memory_size - onboard_amt;   // actual amount of RAM available for SIMMs
432431     
433432      // installing SIMM RAM?
r9489r9490
459458   }
460459}
461460
462void mac_set_memory_overlay(running_machine *machine, int overlay)
461void mac_state::set_memory_overlay(running_machine *machine, int overlay)
463462{
464463   offs_t memory_size;
465464   UINT8 *memory_data;
466465   int is_rom;
467   mac_state *mac = machine->driver_data<mac_state>();
468466
469467   /* normalize overlay */
470468   overlay = overlay ? TRUE : FALSE;
471469
472   if (overlay != mac->overlay)
470   if (overlay != m_overlay)
473471   {
474472      /* set up either main RAM area or ROM mirror at 0x000000-0x3fffff */
475473      if (overlay)
r9489r9490
482480      else
483481      {
484482         /* RAM */
485         memory_size = messram_get_size(machine->device("messram"));
486         memory_data = messram_get_ptr(machine->device("messram"));
483         memory_size = messram_get_size(m_ram);
484         memory_data = messram_get_ptr(m_ram);
487485         is_rom = FALSE;
488486      }
489487
490488      /* install the memory */
491      if (((mac->model >= MODEL_MAC_LC) && (mac->model <= MODEL_MAC_COLOR_CLASSIC) && ((mac->model != MODEL_MAC_LC_III) && (mac->model != MODEL_MAC_LC_III_PLUS))) || (mac->model == MODEL_MAC_CLASSIC_II))
489      if (((m_model >= MODEL_MAC_LC) && (m_model <= MODEL_MAC_COLOR_CLASSIC) && ((m_model != MODEL_MAC_LC_III) && (m_model != MODEL_MAC_LC_III_PLUS))) || (m_model == MODEL_MAC_CLASSIC_II))
492490      {
493         mac->overlay = overlay;
494         mac_v8_resize(machine, mac);
491         m_overlay = overlay;
492         v8_resize(machine);
495493      }
496      else if ((mac->model >= MODEL_MAC_POWERMAC_6100) && (mac->model >= MODEL_MAC_POWERMAC_8100))
494      else if ((m_model >= MODEL_MAC_POWERMAC_6100) && (m_model >= MODEL_MAC_POWERMAC_8100))
497495      {
498496//         mac_install_memory(machine, 0x00000000, memory_size-1, memory_size, memory_data, is_rom, "bank1");
499497      }
500      else if ((mac->model == MODEL_MAC_IICI) || (mac->model == MODEL_MAC_IISI))
498      else if ((m_model == MODEL_MAC_IICI) || (m_model == MODEL_MAC_IISI))
501499      {
502500         // ROM is OK to flood to 3fffffff
503501         if (is_rom)
r9489r9490
509507            mac_install_memory(machine, 0x00000000, 0x03ffffff, memory_size, memory_data, is_rom, "bank1");
510508         }
511509      }
512      else if ((mac->model == MODEL_MAC_PORTABLE) || (mac->model == MODEL_MAC_PB100))
510      else if ((m_model == MODEL_MAC_PORTABLE) || (m_model == MODEL_MAC_PB100))
513511      {
514512         mac_install_memory(machine, 0x000000, 0x8fffff, memory_size, memory_data, is_rom, "bank1");
515513      }
516      else if ((mac->model >= MODEL_MAC_II) && (mac->model <= MODEL_MAC_SE30))
514      else if ((m_model >= MODEL_MAC_II) && (m_model <= MODEL_MAC_SE30))
517515      {
518516         mac_install_memory(machine, 0x00000000, 0x3fffffff, memory_size, memory_data, is_rom, "bank1");
519517      }
520      else if ((mac->model == MODEL_MAC_LC_III) || (mac->model == MODEL_MAC_LC_III_PLUS))   // up to 36 MB
518      else if ((m_model == MODEL_MAC_LC_III) || (m_model == MODEL_MAC_LC_III_PLUS))   // up to 36 MB
521519      {
522520         mac_install_memory(machine, 0x00000000, memory_size-1, memory_size, memory_data, is_rom, "bank1");
523521      }
r9489r9490
526524         mac_install_memory(machine, 0x00000000, 0x003fffff, memory_size, memory_data, is_rom, "bank1");
527525      }
528526
529      mac->overlay = overlay;
527      m_overlay = overlay;
530528
531529      if (LOG_GENERAL)
532530         logerror("mac_set_memory_overlay: overlay=%i\n", overlay);
r9489r9490
572570   static const char *const keynames[] = { "KEY0", "KEY1", "KEY2", "KEY3", "KEY4", "KEY5", "KEY6" };
573571   mac_state *mac = machine->driver_data<mac_state>();
574572
575   if (mac->keycode_buf_index)
573   if (mac->m_keycode_buf_index)
576574   {
577      return mac->keycode_buf[--mac->keycode_buf_index];
575      return mac->m_keycode_buf[--mac->m_keycode_buf_index];
578576   }
579577
580578   for (i=0; i<7; i++)
581579   {
582580      keybuf = input_port_read(machine, keynames[i]);
583581
584      if (keybuf != mac->key_matrix[i])
582      if (keybuf != mac->m_key_matrix[i])
585583      {
586584         /* if state has changed, find first bit which has changed */
587585         if (LOG_KEYBOARD)
r9489r9490
589587
590588         for (j=0; j<16; j++)
591589         {
592            if (((keybuf ^ mac->key_matrix[i]) >> j) & 1)
590            if (((keybuf ^ mac->m_key_matrix[i]) >> j) & 1)
593591            {
594               /* update mac->key_matrix */
595               mac->key_matrix[i] = (mac->key_matrix[i] & ~ (1 << j)) | (keybuf & (1 << j));
592               /* update mac->m_key_matrix */
593               mac->m_key_matrix[i] = (mac->m_key_matrix[i] & ~ (1 << j)) | (keybuf & (1 << j));
596594
597595               if (i < 4)
598596               {
r9489r9490
616614                     if (keybuf & (1 << j))
617615                     {
618616                        /* key down */
619                        if (! (mac->key_matrix[3] & 0x0100))
617                        if (! (mac->m_key_matrix[3] & 0x0100))
620618                        {
621619                           /* shift key is really up */
622                           mac->keycode_buf[0] = keycode;
623                           mac->keycode_buf[1] = 0x79;
624                           mac->keycode_buf_index = 2;
620                           mac->m_keycode_buf[0] = keycode;
621                           mac->m_keycode_buf[1] = 0x79;
622                           mac->m_keycode_buf_index = 2;
625623                           return 0x71;   /* "presses" shift down */
626624                        }
627625                     }
628626                     else
629627                     {   /* key up */
630                        if (! (mac->key_matrix[3] & 0x0100))
628                        if (! (mac->m_key_matrix[3] & 0x0100))
631629                        {
632630                           /* shift key is really up */
633                           mac->keycode_buf[0] = keycode | 0x80;;
634                           mac->keycode_buf[1] = 0x79;
635                           mac->keycode_buf_index = 2;
631                           mac->m_keycode_buf[0] = keycode | 0x80;;
632                           mac->m_keycode_buf[1] = 0x79;
633                           mac->m_keycode_buf_index = 2;
636634                           return 0xF1;   /* "releases" shift */
637635                        }
638636                     }
r9489r9490
643641                     /* key up */
644642                     keycode |= 0x80;
645643                  }
646                  mac->keycode_buf[0] = keycode;
647                  mac->keycode_buf_index = 1;
644                  mac->m_keycode_buf[0] = keycode;
645                  mac->m_keycode_buf_index = 1;
648646                  return 0x79;
649647               }
650648               else /* i == 6 */
r9489r9490
656654                     /* key up */
657655                     keycode |= 0x80;
658656                  }
659                  mac->keycode_buf[0] = keycode;
660                  mac->keycode_buf_index = 1;
657                  mac->m_keycode_buf[0] = keycode;
658                  mac->m_keycode_buf_index = 1;
661659                  return 0x79;
662660               }
663661            }
r9489r9490
676674   int i;
677675
678676   /* init flag */
679   mac->kbd_comm = FALSE;
680   mac->kbd_receive = FALSE;
681   mac->kbd_shift_reg=0;
682   mac->kbd_shift_count=0;
677   mac->m_kbd_comm = FALSE;
678   mac->m_kbd_receive = FALSE;
679   mac->m_kbd_shift_reg=0;
680   mac->m_kbd_shift_count=0;
683681
684682   /* clear key matrix */
685683   for (i=0; i<7; i++)
686684   {
687      mac->key_matrix[i] = 0;
685      mac->m_key_matrix[i] = 0;
688686   }
689687
690688   /* purge transmission buffer */
691   mac->keycode_buf_index = 0;
689   mac->m_keycode_buf_index = 0;
692690}
693691
694692/******************* Keyboard <-> VIA communication ***********************/
r9489r9490
696694static TIMER_CALLBACK(kbd_clock)
697695{
698696   int i;
699   via6522_device *via_0 = machine->device<via6522_device>("via6522_0");
700697   mac_state *mac = machine->driver_data<mac_state>();
701698
702   if (mac->kbd_comm == TRUE)
699   if (mac->m_kbd_comm == TRUE)
703700   {
704701      for (i=0; i<8; i++)
705702      {
706703         /* Put data on CB2 if we are sending*/
707         if (mac->kbd_receive == FALSE)
708            via_0->write_cb2(mac->kbd_shift_reg&0x80?1:0);
709         mac->kbd_shift_reg <<= 1;
710         via_0->write_cb1(0);
711         via_0->write_cb1(1);
704         if (mac->m_kbd_receive == FALSE)
705            mac->m_via1->write_cb2(mac->m_kbd_shift_reg&0x80?1:0);
706         mac->m_kbd_shift_reg <<= 1;
707         mac->m_via1->write_cb1(0);
708         mac->m_via1->write_cb1(1);
712709      }
713      if (mac->kbd_receive == TRUE)
710      if (mac->m_kbd_receive == TRUE)
714711      {
715         mac->kbd_receive = FALSE;
712         mac->m_kbd_receive = FALSE;
716713         /* Process the command received from mac */
717         keyboard_receive(machine, mac->kbd_shift_reg & 0xff);
714         keyboard_receive(machine, mac->m_kbd_shift_reg & 0xff);
718715      }
719716      else
720717      {
721718         /* Communication is over */
722         mac->kbd_comm = FALSE;
719         mac->m_kbd_comm = FALSE;
723720      }
724721   }
725722}
r9489r9490
728725{
729726   mac_state *mac = machine->driver_data<mac_state>();
730727
731   if (mac->kbd_comm == TRUE)
728   if (mac->m_kbd_comm == TRUE)
732729   {
733      mac->kbd_shift_reg = data;
730      mac->m_kbd_shift_reg = data;
734731      timer_set(machine, ATTOTIME_IN_MSEC(1), NULL, 0, kbd_clock);
735732   }
736733}
r9489r9490
739736{
740737   mac_state *mac = device->machine->driver_data<mac_state>();
741738
742   if (mac->kbd_comm == FALSE && data == 0)
739   if (mac->m_kbd_comm == FALSE && data == 0)
743740   {
744741      /* Mac pulls CB2 down to initiate communication */
745      mac->kbd_comm = TRUE;
746      mac->kbd_receive = TRUE;
742      mac->m_kbd_comm = TRUE;
743      mac->m_kbd_receive = TRUE;
747744      timer_set(device->machine, ATTOTIME_IN_USEC(100), NULL, 0, kbd_clock);
748745   }
749   if (mac->kbd_comm == TRUE && mac->kbd_receive == TRUE)
746   if (mac->m_kbd_comm == TRUE && mac->m_kbd_receive == TRUE)
750747   {
751748      /* Shift in what mac is sending */
752      mac->kbd_shift_reg = (mac->kbd_shift_reg & ~1) | data;
749      mac->m_kbd_shift_reg = (mac->m_kbd_shift_reg & ~1) | data;
753750   }
754751}
755752
r9489r9490
777774      if (LOG_KEYBOARD)
778775         logerror("keyboard command : inquiry\n");
779776
780      mac->keyboard_reply = scan_keyboard(machine);
781      if (mac->keyboard_reply == 0x7B)
777      mac->m_keyboard_reply = scan_keyboard(machine);
778      if (mac->m_keyboard_reply == 0x7B)
782779      {
783780         /* if NULL, wait until key pressed or timeout */
784         timer_adjust_oneshot(mac->inquiry_timeout,
781         timer_adjust_oneshot(mac->m_inquiry_timeout,
785782            attotime_make(0, DOUBLE_TO_ATTOSECONDS(0.25)), 0);
786783      }
787784      break;
r9489r9490
805802         /* clear key matrix */
806803         for (i=0; i<7; i++)
807804         {
808            mac->key_matrix[i] = 0;
805            mac->m_key_matrix[i] = 0;
809806         }
810807
811808         /* purge transmission buffer */
812         mac->keycode_buf_index = 0;
809         mac->m_keycode_buf_index = 0;
813810      }
814811
815812      /* format : 1 if another device (-> keypad ?) connected | next device (-> keypad ?) number 1-8
r9489r9490
893890      if (count_x < 0)
894891      {
895892         count_x++;
896         mac->mouse_bit_x = 0;
893         mac->m_mouse_bit_x = 0;
897894      }
898895      else
899896      {
900897         count_x--;
901         mac->mouse_bit_x = 1;
898         mac->m_mouse_bit_x = 1;
902899      }
903900      x_needs_update = 1;
904901   }
r9489r9490
907904      if (count_y < 0)
908905      {
909906         count_y++;
910         mac->mouse_bit_y = 1;
907         mac->m_mouse_bit_y = 1;
911908      }
912909      else
913910      {
914911         count_y--;
915         mac->mouse_bit_y = 0;
912         mac->m_mouse_bit_y = 0;
916913      }
917914      y_needs_update = 1;
918915   }
919916
920917   if (x_needs_update || y_needs_update)
921918      /* assert Port B External Interrupt on the SCC */
922      mac_scc_mouse_irq( machine, x_needs_update, y_needs_update );
919      mac->scc_mouse_irq(machine, x_needs_update, y_needs_update );
923920}
924921
925922/* *************************************************************************
r9489r9490
972969  scsiRd+sRESET       $580070    Reset Parity/Interrupt
973970             */
974971
975READ16_HANDLER ( macplus_scsi_r )
972READ16_MEMBER ( mac_state::macplus_scsi_r )
976973{
977974   int reg = (offset>>3) & 0xf;
978   running_device *ncr = space->machine->device("ncr5380");
975   running_device *ncr = space.machine->device("ncr5380");
979976
980977//  logerror("macplus_scsi_r: offset %x mask %x\n", offset, mem_mask);
981978
r9489r9490
987984   return ncr5380_read_reg(ncr, reg)<<8;
988985}
989986
990READ32_HANDLER (macii_scsi_drq_r)
987READ32_MEMBER (mac_state::macii_scsi_drq_r)
991988{
992   running_device *ncr = space->machine->device("ncr5380");
989   running_device *ncr = space.machine->device("ncr5380");
993990
994991   switch (mem_mask)
995992   {
r9489r9490
10091006   return 0;
10101007}
10111008
1012WRITE32_HANDLER (macii_scsi_drq_w)
1009WRITE32_MEMBER (mac_state::macii_scsi_drq_w)
10131010{
1014   running_device *ncr = space->machine->device("ncr5380");
1011   running_device *ncr = space.machine->device("ncr5380");
10151012
10161013   switch (mem_mask)
10171014   {
r9489r9490
10371034   }
10381035}
10391036
1040WRITE16_HANDLER ( macplus_scsi_w )
1037WRITE16_MEMBER ( mac_state::macplus_scsi_w )
10411038{
10421039   int reg = (offset>>3) & 0xf;
1043   running_device *ncr = space->machine->device("ncr5380");
1040   running_device *ncr = space.machine->device("ncr5380");
10441041
10451042//  logerror("macplus_scsi_w: data %x offset %x mask %x\n", data, offset, mem_mask);
10461043
r9489r9490
10521049   ncr5380_write_reg(ncr, reg, data);
10531050}
10541051
1055WRITE16_HANDLER ( macii_scsi_w )
1052WRITE16_MEMBER ( mac_state::macii_scsi_w )
10561053{
10571054   int reg = (offset>>3) & 0xf;
1058   running_device *ncr = space->machine->device("ncr5380");
1055   running_device *ncr = space.machine->device("ncr5380");
10591056
10601057//  logerror("macplus_scsi_w: data %x offset %x mask %x (PC=%x)\n", data, offset, mem_mask, cpu_get_pc(space->cpu));
10611058
r9489r9490
10711068{
10721069   mac_state *mac = machine->driver_data<mac_state>();
10731070
1074   if ((mac->scsiirq_enable) && ((mac->model == MODEL_MAC_SE) || (mac->model == MODEL_MAC_CLASSIC)))
1071   if ((mac->m_scsiirq_enable) && ((mac->m_model == MODEL_MAC_SE) || (mac->m_model == MODEL_MAC_CLASSIC)))
10751072   {
1076      scsi_interrupt = state;
1077      mac_field_interrupts(machine);
1073      mac->m_scsi_interrupt = state;
1074      mac->field_interrupts(machine);
10781075   }
10791076}
10801077
r9489r9490
10861083
10871084void mac_scc_irq(running_device *device, int status)
10881085{
1089   set_scc_interrupt(device->machine, status);
1086   mac_state *mac = device->machine->driver_data<mac_state>();
1087
1088   mac->set_scc_interrupt(device->machine, status);
10901089}
10911090
10921091
10931092
1094void mac_scc_mouse_irq(running_machine *machine, int x, int y)
1093void mac_state::scc_mouse_irq(running_machine *machine, int x, int y)
10951094{
10961095   running_device *scc = machine->device("scc");
10971096   static int last_was_x = 0;
r9489r9490
11181117
11191118
11201119
1121READ16_HANDLER ( mac_scc_r )
1120READ16_MEMBER ( mac_state::mac_scc_r )
11221121{
1123   running_device *scc = space->machine->device("scc");
1122   running_device *scc = space.machine->device("scc");
11241123   UINT16 result;
11251124
11261125   result = scc8530_r(scc, offset);
r9489r9490
11291128
11301129
11311130
1132WRITE16_HANDLER ( mac_scc_w )
1131WRITE16_MEMBER ( mac_state::mac_scc_w )
11331132{
1134   running_device *scc = space->machine->device("scc");
1133   running_device *scc = space.machine->device("scc");
11351134   scc8530_w(scc, offset, (UINT8) data);
11361135}
11371136
1138WRITE16_HANDLER ( mac_scc_2_w )
1137WRITE16_MEMBER ( mac_state::mac_scc_2_w )
11391138{
1140   running_device *scc = space->machine->device("scc");
1139   running_device *scc = space.machine->device("scc");
11411140   UINT8 wdata = data>>8;
11421141   scc8530_w(scc, offset, wdata);
11431142}
r9489r9490
11501149 * Real Time Clock chip - contains clock information and PRAM.  This chip is
11511150 * accessed through the VIA
11521151 * *************************************************************************/
1153
1154/* a few protos */
1155static void rtc_write_rTCEnb(mac_state *mac, int data);
1156static void rtc_execute_cmd(mac_state *mac, int data);
1157
11581152enum
11591153{
11601154   RTC_STATE_NORMAL,
r9489r9490
11641158};
11651159
11661160/* init the rtc core */
1167static void rtc_init(mac_state *mac)
1161void mac_state::rtc_init()
11681162{
1169   mac->rtc_rTCClk = 0;
1163   m_rtc_rTCClk = 0;
11701164
1171   mac->rtc_write_protect = 0;
1172   mac->rtc_rTCEnb = 0;
1173   rtc_write_rTCEnb(mac, 1);
1174   mac->rtc_state = RTC_STATE_NORMAL;
1165   m_rtc_write_protect = 0;
1166   m_rtc_rTCEnb = 0;
1167   rtc_write_rTCEnb(1);
1168   m_rtc_state = RTC_STATE_NORMAL;
11751169}
11761170
11771171/* write the rTCEnb state */
1178static void rtc_write_rTCEnb(mac_state *mac, int val)
1172void mac_state::rtc_write_rTCEnb(int val)
11791173{
1180   if (val && (! mac->rtc_rTCEnb))
1174   if (val && (! m_rtc_rTCEnb))
11811175   {
11821176      /* rTCEnb goes high (inactive) */
1183      mac->rtc_rTCEnb = 1;
1177      m_rtc_rTCEnb = 1;
11841178      /* abort current transmission */
1185      mac->rtc_data_byte = mac->rtc_bit_count = mac->rtc_data_dir = mac->rtc_data_out = 0;
1186      mac->rtc_state = RTC_STATE_NORMAL;
1179      m_rtc_data_byte = m_rtc_bit_count = m_rtc_data_dir = m_rtc_data_out = 0;
1180      m_rtc_state = RTC_STATE_NORMAL;
11871181   }
1188   else if ((! val) && mac->rtc_rTCEnb)
1182   else if ((! val) && m_rtc_rTCEnb)
11891183   {
11901184      /* rTCEnb goes low (active) */
1191      mac->rtc_rTCEnb = 0;
1185      m_rtc_rTCEnb = 0;
11921186      /* abort current transmission */
1193      mac->rtc_data_byte = mac->rtc_bit_count = mac->rtc_data_dir = mac->rtc_data_out = 0;
1194      mac->rtc_state = RTC_STATE_NORMAL;
1187      m_rtc_data_byte = m_rtc_bit_count = m_rtc_data_dir = m_rtc_data_out = 0;
1188      m_rtc_state = RTC_STATE_NORMAL;
11951189   }
11961190}
11971191
11981192/* shift data (called on rTCClk high-to-low transition (?)) */
1199static void rtc_shift_data(mac_state *mac, int data)
1193void mac_state::rtc_shift_data(int data)
12001194{
1201   if (mac->rtc_rTCEnb)
1195   if (m_rtc_rTCEnb)
12021196      /* if enable line inactive (high), do nothing */
12031197      return;
12041198
1205   if (mac->rtc_data_dir)
1199   if (m_rtc_data_dir)
12061200   {   /* RTC -> VIA transmission */
1207      mac->rtc_data_out = (mac->rtc_data_byte >> --mac->rtc_bit_count) & 0x01;
1201      m_rtc_data_out = (m_rtc_data_byte >> --m_rtc_bit_count) & 0x01;
12081202      if (LOG_RTC)
1209         logerror("RTC shifted new data %d\n", mac->rtc_data_out);
1203         logerror("RTC shifted new data %d\n", m_rtc_data_out);
12101204   }
12111205   else
12121206   {   /* VIA -> RTC transmission */
1213      mac->rtc_data_byte = (mac->rtc_data_byte << 1) | (data ? 1 : 0);
1207      m_rtc_data_byte = (m_rtc_data_byte << 1) | (data ? 1 : 0);
12141208
1215      if (++mac->rtc_bit_count == 8)
1209      if (++m_rtc_bit_count == 8)
12161210      {   /* if one byte received, send to command interpreter */
1217         rtc_execute_cmd(mac, mac->rtc_data_byte);
1211         rtc_execute_cmd(m_rtc_data_byte);
12181212      }
12191213   }
12201214}
12211215
12221216/* called every second, to increment the Clock count */
1223static void rtc_incticks(mac_state *mac)
1217void mac_state::rtc_incticks()
12241218{
12251219   if (LOG_RTC)
12261220      logerror("rtc_incticks called\n");
12271221
1228   if (++mac->rtc_seconds[0] == 0)
1229      if (++mac->rtc_seconds[1] == 0)
1230         if (++mac->rtc_seconds[2] == 0)
1231            ++mac->rtc_seconds[3];
1222   if (++m_rtc_seconds[0] == 0)
1223      if (++m_rtc_seconds[1] == 0)
1224         if (++m_rtc_seconds[2] == 0)
1225            ++m_rtc_seconds[3];
12321226
1233   /*if (++mac->rtc_seconds[4] == 0)
1234        if (++mac->rtc_seconds[5] == 0)
1235            if (++mac->rtc_seconds[6] == 0)
1236                ++mac->rtc_seconds[7];*/
1227   /*if (++m_rtc_seconds[4] == 0)
1228        if (++m_rtc_seconds[5] == 0)
1229            if (++m_rtc_seconds[6] == 0)
1230                ++m_rtc_seconds[7];*/
12371231}
12381232
12391233/* Executes a command.
12401234Called when the first byte after "enable" is received, and when the data byte after a write command
12411235is received. */
1242static void rtc_execute_cmd(mac_state *mac, int data)
1236void mac_state::rtc_execute_cmd(int data)
12431237{
12441238   int i;
12451239
12461240   if (LOG_RTC)
1247      logerror("rtc_execute_cmd: data=%x, state=%x\n", data, mac->rtc_state);
1241      logerror("rtc_execute_cmd: data=%x, state=%x\n", data, m_rtc_state);
12481242
1249   if (mac->rtc_state == RTC_STATE_XPCOMMAND)
1243   if (m_rtc_state == RTC_STATE_XPCOMMAND)
12501244   {
1251      mac->rtc_xpaddr = ((mac->rtc_cmd & 7)<<5) | ((data&0x7c)>>2);
1252      if ((mac->rtc_cmd & 0x80) != 0)
1245      m_rtc_xpaddr = ((m_rtc_cmd & 7)<<5) | ((data&0x7c)>>2);
1246      if ((m_rtc_cmd & 0x80) != 0)
12531247      {
12541248         // read command
12551249         if (LOG_RTC)
1256            logerror("RTC: Reading extended address %x = %x\n", mac->rtc_xpaddr, mac->rtc_ram[mac->rtc_xpaddr]);
1250            logerror("RTC: Reading extended address %x = %x\n", m_rtc_xpaddr, m_rtc_ram[m_rtc_xpaddr]);
12571251
1258         mac->rtc_data_dir = 1;
1259         mac->rtc_data_byte = mac->rtc_ram[mac->rtc_xpaddr];
1260         mac->rtc_state = RTC_STATE_NORMAL;
1252         m_rtc_data_dir = 1;
1253         m_rtc_data_byte = m_rtc_ram[m_rtc_xpaddr];
1254         m_rtc_state = RTC_STATE_NORMAL;
12611255      }
12621256      else
12631257      {
12641258         // write command
1265         mac->rtc_state = RTC_STATE_XPWRITE;
1266         mac->rtc_data_byte = 0;
1267         mac->rtc_bit_count = 0;
1259         m_rtc_state = RTC_STATE_XPWRITE;
1260         m_rtc_data_byte = 0;
1261         m_rtc_bit_count = 0;
12681262      }
12691263   }
1270   else if (mac->rtc_state == RTC_STATE_XPWRITE)
1264   else if (m_rtc_state == RTC_STATE_XPWRITE)
12711265   {
12721266      if (LOG_RTC)
1273         logerror("RTC: writing %x to extended address %x\n", data, mac->rtc_xpaddr);
1274      mac->rtc_ram[mac->rtc_xpaddr] = data;
1275      mac->rtc_state = RTC_STATE_NORMAL;
1267         logerror("RTC: writing %x to extended address %x\n", data, m_rtc_xpaddr);
1268      m_rtc_ram[m_rtc_xpaddr] = data;
1269      m_rtc_state = RTC_STATE_NORMAL;
12761270   }
1277   else if (mac->rtc_state == RTC_STATE_WRITE)
1271   else if (m_rtc_state == RTC_STATE_WRITE)
12781272   {
1279      mac->rtc_state = RTC_STATE_NORMAL;
1273      m_rtc_state = RTC_STATE_NORMAL;
12801274
12811275      /* Writing an RTC register */
1282      i = (mac->rtc_cmd >> 2) & 0x1f;
1283      if (mac->rtc_write_protect && (i != 13))
1276      i = (m_rtc_cmd >> 2) & 0x1f;
1277      if (m_rtc_write_protect && (i != 13))
12841278         /* write-protection : only write-protect can be written again */
12851279         return;
12861280      switch(i)
12871281      {
12881282      case 0: case 1: case 2: case 3:   /* seconds register */
12891283      case 4: case 5: case 6: case 7:   /* ??? (not described in IM III) */
1290         /* after various tries, I assumed mac->rtc_seconds[4+i] is mapped to mac->rtc_seconds[i] */
1284         /* after various tries, I assumed m_rtc_seconds[4+i] is mapped to m_rtc_seconds[i] */
12911285         if (LOG_RTC)
1292            logerror("RTC clock write, address = %X, data = %X\n", i, (int) mac->rtc_data_byte);
1293         mac->rtc_seconds[i & 3] = mac->rtc_data_byte;
1286            logerror("RTC clock write, address = %X, data = %X\n", i, (int) m_rtc_data_byte);
1287         m_rtc_seconds[i & 3] = m_rtc_data_byte;
12941288         break;
12951289
12961290      case 8: case 9: case 10: case 11:   /* RAM address $10-$13 */
12971291         if (LOG_RTC)
1298            logerror("RTC RAM write, address = %X, data = %X\n", (i & 3) + 0x10, (int) mac->rtc_data_byte);
1299         mac->rtc_ram[(i & 3) + 0x10] = mac->rtc_data_byte;
1292            logerror("RTC RAM write, address = %X, data = %X\n", (i & 3) + 0x10, (int) m_rtc_data_byte);
1293         m_rtc_ram[(i & 3) + 0x10] = m_rtc_data_byte;
13001294         break;
13011295
13021296      case 12:
13031297         /* Test register - do nothing */
13041298         if (LOG_RTC)
1305            logerror("RTC write to test register, data = %X\n", (int) mac->rtc_data_byte);
1299            logerror("RTC write to test register, data = %X\n", (int) m_rtc_data_byte);
13061300         break;
13071301
13081302      case 13:
13091303         /* Write-protect register  */
13101304         if (LOG_RTC)
1311            logerror("RTC write to write-protect register, data = %X\n", (int) mac->rtc_data_byte&0x80);
1312         mac->rtc_write_protect = (mac->rtc_data_byte & 0x80) ? TRUE : FALSE;
1305            logerror("RTC write to write-protect register, data = %X\n", (int) m_rtc_data_byte&0x80);
1306         m_rtc_write_protect = (m_rtc_data_byte & 0x80) ? TRUE : FALSE;
13131307         break;
13141308
13151309      case 16: case 17: case 18: case 19:   /* RAM address $00-$0f */
r9489r9490
13171311      case 24: case 25: case 26: case 27:
13181312      case 28: case 29: case 30: case 31:
13191313         if (LOG_RTC)
1320            logerror("RTC RAM write, address = %X, data = %X\n", i & 15, (int) mac->rtc_data_byte);
1321         mac->rtc_ram[i & 15] = mac->rtc_data_byte;
1314            logerror("RTC RAM write, address = %X, data = %X\n", i & 15, (int) m_rtc_data_byte);
1315         m_rtc_ram[i & 15] = m_rtc_data_byte;
13221316         break;
13231317
13241318      default:
1325         printf("Unknown RTC write command : %X, data = %d\n", (int) mac->rtc_cmd, (int) mac->rtc_data_byte);
1319         printf("Unknown RTC write command : %X, data = %d\n", (int) m_rtc_cmd, (int) m_rtc_data_byte);
13261320         break;
13271321      }
13281322   }
13291323   else
13301324   {
1331      // always save this byte to mac->rtc_cmd
1332      mac->rtc_cmd = mac->rtc_data_byte;
1325      // always save this byte to m_rtc_cmd
1326      m_rtc_cmd = m_rtc_data_byte;
13331327
1334      if ((mac->rtc_cmd & 0x78) == 0x38)   // extended command
1328      if ((m_rtc_cmd & 0x78) == 0x38)   // extended command
13351329      {
1336         mac->rtc_state = RTC_STATE_XPCOMMAND;
1337         mac->rtc_data_byte = 0;
1338         mac->rtc_bit_count = 0;
1330         m_rtc_state = RTC_STATE_XPCOMMAND;
1331         m_rtc_data_byte = 0;
1332         m_rtc_bit_count = 0;
13391333      }
13401334      else
13411335      {
1342         if (mac->rtc_cmd & 0x80)
1336         if (m_rtc_cmd & 0x80)
13431337         {
1344            mac->rtc_state = RTC_STATE_NORMAL;
1338            m_rtc_state = RTC_STATE_NORMAL;
13451339
13461340            /* Reading an RTC register */
1347            mac->rtc_data_dir = 1;
1348            i = (mac->rtc_cmd >> 2) & 0x1f;
1341            m_rtc_data_dir = 1;
1342            i = (m_rtc_cmd >> 2) & 0x1f;
13491343            switch(i)
13501344            {
13511345               case 0: case 1: case 2: case 3:
13521346               case 4: case 5: case 6: case 7:
1353                  mac->rtc_data_byte = mac->rtc_seconds[i & 3];
1347                  m_rtc_data_byte = m_rtc_seconds[i & 3];
13541348                  if (LOG_RTC)
1355                     logerror("RTC clock read, address = %X -> data = %X\n", i, mac->rtc_data_byte);
1349                     logerror("RTC clock read, address = %X -> data = %X\n", i, m_rtc_data_byte);
13561350                  break;
13571351
13581352               case 8: case 9: case 10: case 11:
13591353                  if (LOG_RTC)
1360                     logerror("RTC RAM read, address = %X data = %x\n", (i & 3) + 0x10, mac->rtc_ram[(i & 3) + 0x10]);
1361                  mac->rtc_data_byte = mac->rtc_ram[(i & 3) + 0x10];
1354                     logerror("RTC RAM read, address = %X data = %x\n", (i & 3) + 0x10, m_rtc_ram[(i & 3) + 0x10]);
1355                  m_rtc_data_byte = m_rtc_ram[(i & 3) + 0x10];
13621356                  break;
13631357
13641358               case 16: case 17: case 18: case 19:
r9489r9490
13661360               case 24: case 25: case 26: case 27:
13671361               case 28: case 29: case 30: case 31:
13681362                  if (LOG_RTC)
1369                     logerror("RTC RAM read, address = %X data = %x\n", i & 15, mac->rtc_ram[i & 15]);
1370                  mac->rtc_data_byte = mac->rtc_ram[i & 15];
1363                     logerror("RTC RAM read, address = %X data = %x\n", i & 15, m_rtc_ram[i & 15]);
1364                  m_rtc_data_byte = m_rtc_ram[i & 15];
13711365                  break;
13721366
13731367               default:
13741368                  if (LOG_RTC)
1375                     logerror("Unknown RTC read command : %X\n", (int) mac->rtc_cmd);
1376                  mac->rtc_data_byte = 0;
1369                     logerror("Unknown RTC read command : %X\n", (int) m_rtc_cmd);
1370                  m_rtc_data_byte = 0;
13771371                  break;
13781372            }
13791373         }
r9489r9490
13821376            /* Writing an RTC register */
13831377            /* wait for extra data byte */
13841378            if (LOG_RTC)
1385               logerror("RTC write, waiting for data byte : %X\n", (int) mac->rtc_cmd);
1386            mac->rtc_state = RTC_STATE_WRITE;
1387            mac->rtc_data_byte = 0;
1388            mac->rtc_bit_count = 0;
1379               logerror("RTC write, waiting for data byte : %X\n", (int) m_rtc_cmd);
1380            m_rtc_state = RTC_STATE_WRITE;
1381            m_rtc_data_byte = 0;
1382            m_rtc_bit_count = 0;
13891383         }
13901384      }
13911385   }
r9489r9490
14011395   {
14021396      if (LOG_RTC)
14031397         logerror("Writing PRAM to file\n");
1404      mame_fwrite(file, mac->rtc_ram, sizeof(mac->rtc_ram));
1398      mame_fwrite(file, mac->m_rtc_ram, sizeof(mac->m_rtc_ram));
14051399   }
14061400   else
14071401   {
r9489r9490
14091403      {
14101404         if (LOG_RTC)
14111405            logerror("Reading PRAM from file\n");
1412         mame_fread(file, mac->rtc_ram, sizeof(mac->rtc_ram));
1406         mame_fread(file, mac->m_rtc_ram, sizeof(mac->m_rtc_ram));
14131407      }
14141408      else
14151409      {
14161410         if (LOG_RTC)
14171411            logerror("trashing PRAM\n");
14181412
1419         memset(mac->rtc_ram, 0, sizeof(mac->rtc_ram));
1413         memset(mac->m_rtc_ram, 0, sizeof(mac->m_rtc_ram));
14201414
14211415         // some Mac ROMs are buggy in the presence of
14221416         // no NVRAM, so let's initialize it right
1423         mac->rtc_ram[0] = 0xa8;   // valid
1424         mac->rtc_ram[4] = 0xcc;
1425         mac->rtc_ram[5] = 0x0a;
1426         mac->rtc_ram[6] = 0xcc;
1427         mac->rtc_ram[7] = 0x0a;
1428         mac->rtc_ram[0xc] = 0x42;   // XPRAM valid for Plus/SE
1429         mac->rtc_ram[0xd] = 0x75;
1430         mac->rtc_ram[0xe] = 0x67;
1431         mac->rtc_ram[0xf] = 0x73;
1432         mac->rtc_ram[0x10] = 0x18;
1433         mac->rtc_ram[0x11] = 0x88;
1434         mac->rtc_ram[0x12] = 0x01;
1435         mac->rtc_ram[0x13] = 0x4c;
1417         mac->m_rtc_ram[0] = 0xa8;   // valid
1418         mac->m_rtc_ram[4] = 0xcc;
1419         mac->m_rtc_ram[5] = 0x0a;
1420         mac->m_rtc_ram[6] = 0xcc;
1421         mac->m_rtc_ram[7] = 0x0a;
1422         mac->m_rtc_ram[0xc] = 0x42;   // XPRAM valid for Plus/SE
1423         mac->m_rtc_ram[0xd] = 0x75;
1424         mac->m_rtc_ram[0xe] = 0x67;
1425         mac->m_rtc_ram[0xf] = 0x73;
1426         mac->m_rtc_ram[0x10] = 0x18;
1427         mac->m_rtc_ram[0x11] = 0x88;
1428         mac->m_rtc_ram[0x12] = 0x01;
1429         mac->m_rtc_ram[0x13] = 0x4c;
14361430
1437         if (mac->model >= MODEL_MAC_II)
1431         if (mac->m_model >= MODEL_MAC_II)
14381432         {
1439            mac->rtc_ram[0xc] = 0x4e;   // XPRAM valid is different for these
1440            mac->rtc_ram[0xd] = 0x75;
1441            mac->rtc_ram[0xe] = 0x4d;
1442            mac->rtc_ram[0xf] = 0x63;
1443            mac->rtc_ram[0x77] = 0x01;
1444            mac->rtc_ram[0x78] = 0xff;
1445            mac->rtc_ram[0x79] = 0xff;
1446            mac->rtc_ram[0x7a] = 0xff;
1447            mac->rtc_ram[0x7b] = 0xdf;
1433            mac->m_rtc_ram[0xc] = 0x4e;   // XPRAM valid is different for these
1434            mac->m_rtc_ram[0xd] = 0x75;
1435            mac->m_rtc_ram[0xe] = 0x4d;
1436            mac->m_rtc_ram[0xf] = 0x63;
1437            mac->m_rtc_ram[0x77] = 0x01;
1438            mac->m_rtc_ram[0x78] = 0xff;
1439            mac->m_rtc_ram[0x79] = 0xff;
1440            mac->m_rtc_ram[0x7a] = 0xff;
1441            mac->m_rtc_ram[0x7b] = 0xdf;
14481442         }
14491443      }
14501444
r9489r9490
14711465         if (LOG_RTC)
14721466            logerror("second count 0x%lX\n", (unsigned long) seconds);
14731467
1474         mac->rtc_seconds[0] = seconds & 0xff;
1475         mac->rtc_seconds[1] = (seconds >> 8) & 0xff;
1476         mac->rtc_seconds[2] = (seconds >> 16) & 0xff;
1477         mac->rtc_seconds[3] = (seconds >> 24) & 0xff;
1468         mac->m_rtc_seconds[0] = seconds & 0xff;
1469         mac->m_rtc_seconds[1] = (seconds >> 8) & 0xff;
1470         mac->m_rtc_seconds[2] = (seconds >> 16) & 0xff;
1471         mac->m_rtc_seconds[3] = (seconds >> 24) & 0xff;
14781472      }
14791473   }
14801474}
r9489r9490
14831477 * IWM Code specific to the Mac Plus  *
14841478 * ********************************** */
14851479
1486READ16_HANDLER ( mac_iwm_r )
1480READ16_MEMBER ( mac_state::mac_iwm_r )
14871481{
14881482   /* The first time this is called is in a floppy test, which goes from
14891483     * $400104 to $400126.  After that, all access to the floppy goes through
r9489r9490
14941488     */
14951489
14961490   UINT16 result = 0;
1497   running_device *fdc = space->machine->device("fdc");
1491   running_device *fdc = space.machine->device("fdc");
14981492
14991493   if (LOG_MAC_IWM)
1500      logerror("mac_iwm_r: offset=0x%08x mem_mask %04x (PC %x)\n", offset, mem_mask, cpu_get_pc(space->cpu));
1494      logerror("mac_iwm_r: offset=0x%08x mem_mask %04x (PC %x)\n", offset, mem_mask, cpu_get_pc(space.cpu));
15011495
15021496   result = applefdc_r(fdc, (offset >> 8));
15031497   return (result << 8) | result;
15041498}
15051499
1506WRITE16_HANDLER ( mac_iwm_w )
1500WRITE16_MEMBER ( mac_state::mac_iwm_w )
15071501{
1508   running_device *fdc = space->machine->device("fdc");
1502   running_device *fdc = space.machine->device("fdc");
15091503
15101504   if (LOG_MAC_IWM)
1511      logerror("mac_iwm_w: offset=0x%08x data=0x%04x mask %04x (PC=%x)\n", offset, data, mem_mask, cpu_get_pc(space->cpu));
1505      logerror("mac_iwm_w: offset=0x%08x data=0x%04x mask %04x (PC=%x)\n", offset, data, mem_mask, cpu_get_pc(space.cpu));
15121506
15131507   if (ACCESSING_BITS_0_7)
15141508      applefdc_w(fdc, (offset >> 8), data & 0xff);
r9489r9490
15461540      keybuf = input_port_read(machine, keynames[i]);
15471541
15481542      // any changes in this row?
1549      if ((keybuf != mac->key_matrix[i]) && (report < 2))
1543      if ((keybuf != mac->m_key_matrix[i]) && (report < 2))
15501544      {
15511545         // check each column bit
15521546         for (j=0; j<16; j++)
15531547         {
1554            if (((keybuf ^ mac->key_matrix[i]) >> j) & 1)
1548            if (((keybuf ^ mac->m_key_matrix[i]) >> j) & 1)
15551549            {
1556               // update mac->key_matrix
1550               // update mac->m_key_matrix
15571551               if (update)
15581552               {
1559                  mac->key_matrix[i] = (mac->key_matrix[i] & ~ (1 << j)) | (keybuf & (1 << j));
1553                  mac->m_key_matrix[i] = (mac->m_key_matrix[i] & ~ (1 << j)) | (keybuf & (1 << j));
15601554               }
15611555
15621556               codes[report] = (i<<4)|j;
r9489r9490
17321726   int addr, reg;
17331727   mac_state *mac = machine->driver_data<mac_state>();
17341728
1735   addr = (mac->adb_command>>4);
1736   reg = (mac->adb_command & 3);
1729   addr = (mac->m_adb_command>>4);
1730   reg = (mac->m_adb_command & 3);
17371731
1738//  printf("Mac sent %x (cmd %d addr %d reg %d mr %d kr %d)\n", mac->adb_command, (mac->adb_command>>2)&3, addr, reg, adb_mouseaddr, adb_keybaddr);
1732//  printf("Mac sent %x (cmd %d addr %d reg %d mr %d kr %d)\n", mac->m_adb_command, (mac->m_adb_command>>2)&3, addr, reg, adb_mouseaddr, adb_keybaddr);
17391733
1740   if (mac->adb_waiting_cmd)
1734   if (mac->m_adb_waiting_cmd)
17411735   {
1742      switch ((mac->adb_command>>2)&3)
1736      switch ((mac->m_adb_command>>2)&3)
17431737      {
17441738         case 0:
17451739         case 1:
r9489r9490
17491743                  #if LOG_ADB
17501744                  printf("ADB RESET: reg %x address %x\n", reg, addr);
17511745                  #endif
1752                  mac->adb_direction = 0;
1753                  mac->adb_send = 0;
1746                  mac->m_adb_direction = 0;
1747                  mac->m_adb_send = 0;
17541748                  break;
17551749
17561750               case ADB_CMD_FLUSH:
r9489r9490
17581752                  printf("ADB FLUSH: reg %x address %x\n", reg, addr);
17591753                  #endif
17601754
1761                  mac->adb_direction = 0;
1762                  mac->adb_send = 0;
1755                  mac->m_adb_direction = 0;
1756                  mac->m_adb_send = 0;
17631757                  break;
17641758
17651759               default:   // reserved/unused
r9489r9490
17721766            printf("ADB LISTEN: reg %x address %x\n", reg, addr);
17731767            #endif
17741768
1775            mac->adb_direction = 1;   // input from Mac
1776            mac->adb_listenreg = reg;
1777            mac->adb_listenaddr = addr;
1778            mac->adb_command = 0;
1769            mac->m_adb_direction = 1;   // input from Mac
1770            mac->m_adb_listenreg = reg;
1771            mac->m_adb_listenaddr = addr;
1772            mac->m_adb_command = 0;
17791773            break;
17801774
17811775         case 3: // talk
r9489r9490
17841778            #endif
17851779
17861780            // keep track of what device the Mac last TALKed to
1787            mac->adb_last_talk = addr;
1781            mac->m_adb_last_talk = addr;
17881782
1789            mac->adb_direction = 0;    // output to Mac
1783            mac->m_adb_direction = 0;    // output to Mac
17901784            if (addr == adb_mouseaddr)
17911785            {
17921786               UINT8 mouseX, mouseY;
r9489r9490
17991793               {
18001794                  // read mouse
18011795                  case 0:
1802                     if (mac->adb_srq_switch)
1796                     if (mac->m_adb_srq_switch)
18031797                     {
1804                        mac->adb_srq_switch = 0;
1798                        mac->m_adb_srq_switch = 0;
18051799                        mouseX = mouseY = 0;
18061800                     }
18071801                     else
18081802                     {
18091803                        mac_adb_accummouse(machine, &mouseX, &mouseY);
18101804                     }
1811                     mac->adb_buffer[0] = (adb_lastbutton & 0x01) ? 0x00 : 0x80;
1812                     mac->adb_buffer[0] |= mouseX & 0x7f;
1813                     mac->adb_buffer[1] = mouseY & 0x7f;
1814                     mac->adb_datasize = 2;
1805                     mac->m_adb_buffer[0] = (adb_lastbutton & 0x01) ? 0x00 : 0x80;
1806                     mac->m_adb_buffer[0] |= mouseX & 0x7f;
1807                     mac->m_adb_buffer[1] = mouseY & 0x7f;
1808                     mac->m_adb_datasize = 2;
18151809                     break;
18161810
18171811                  // get ID/handler
18181812                  case 3:
1819                     mac->adb_buffer[0] = 0x60 | ((adb_mouseaddr<<8)&0xf);   // SRQ enable, no exceptional event
1820                     mac->adb_buffer[1] = 0x01;   // handler 1
1821                     mac->adb_datasize = 2;
1813                     mac->m_adb_buffer[0] = 0x60 | ((adb_mouseaddr<<8)&0xf);   // SRQ enable, no exceptional event
1814                     mac->m_adb_buffer[1] = 0x01;   // handler 1
1815                     mac->m_adb_datasize = 2;
18221816
18231817                     adb_mouse_initialized = 1;
18241818                     break;
r9489r9490
18371831               {
18381832                  // read keyboard
18391833                  case 0:
1840                     if (mac->adb_srq_switch)
1834                     if (mac->m_adb_srq_switch)
18411835                     {
1842                        mac->adb_srq_switch = 0;
1836                        mac->m_adb_srq_switch = 0;
18431837                     }
18441838                     else
18451839                     {
18461840                        mac_adb_pollkbd(machine, 1);
18471841                     }
18481842//                          printf("keyboard = %02x %02x\n", adb_currentkeys[0], adb_currentkeys[1]);
1849                     mac->adb_buffer[0] = adb_currentkeys[1];
1850                     mac->adb_buffer[1] = adb_currentkeys[0];
1851                     mac->adb_datasize = 2;
1843                     mac->m_adb_buffer[0] = adb_currentkeys[1];
1844                     mac->m_adb_buffer[1] = adb_currentkeys[0];
1845                     mac->m_adb_datasize = 2;
18521846                     break;
18531847
18541848                  // read modifier keys
18551849                  case 2:
18561850                     mac_adb_pollkbd(machine, 1);
1857                     mac->adb_buffer[0] = adb_modifiers;   // nothing pressed
1858                     mac->adb_buffer[1] = 0;
1859                     mac->adb_datasize = 2;
1851                     mac->m_adb_buffer[0] = adb_modifiers;   // nothing pressed
1852                     mac->m_adb_buffer[1] = 0;
1853                     mac->m_adb_datasize = 2;
18601854                     break;
18611855
18621856                  // get ID/handler
18631857                  case 3:
1864                     mac->adb_buffer[0] = 0x60 | ((adb_keybaddr<<8)&0xf);   // SRQ enable, no exceptional event
1865                     mac->adb_buffer[1] = 0x01;   // handler 1
1866                     mac->adb_datasize = 2;
1858                     mac->m_adb_buffer[0] = 0x60 | ((adb_keybaddr<<8)&0xf);   // SRQ enable, no exceptional event
1859                     mac->m_adb_buffer[1] = 0x01;   // handler 1
1860                     mac->m_adb_datasize = 2;
18671861
18681862                     adb_keybinitialized = 1;
18691863                     break;
r9489r9490
18771871               #if LOG_ADB
18781872               printf("ADB: talking to unconnected device\n");
18791873               #endif
1880               mac->adb_buffer[0] = mac->adb_buffer[1] = 0;
1881               mac->adb_datasize = 0;
1874               mac->m_adb_buffer[0] = mac->m_adb_buffer[1] = 0;
1875               mac->m_adb_datasize = 0;
18821876            }
18831877            break;
18841878      }
18851879
1886      mac->adb_waiting_cmd = 0;
1880      mac->m_adb_waiting_cmd = 0;
18871881   }
18881882   else
18891883   {
18901884      #if LOG_ADB
1891      printf("Got LISTEN data %x for device %x reg %x\n", mac->adb_command, mac->adb_listenaddr, mac->adb_listenreg);
1885      printf("Got LISTEN data %x for device %x reg %x\n", mac->m_adb_command, mac->m_adb_listenaddr, mac->m_adb_listenreg);
18921886      #endif
18931887
1894      if (mac->adb_listenaddr == adb_mouseaddr)
1888      if (mac->m_adb_listenaddr == adb_mouseaddr)
18951889      {
1896         if ((mac->adb_listenreg == 3) && (mac->adb_command > 0) && (mac->adb_command < 16))
1890         if ((mac->m_adb_listenreg == 3) && (mac->m_adb_command > 0) && (mac->m_adb_command < 16))
18971891         {
18981892            #if LOG_ADB
1899            printf("MOUSE: moving to address %x\n", mac->adb_command);
1893            printf("MOUSE: moving to address %x\n", mac->m_adb_command);
19001894            #endif
1901            adb_mouseaddr = mac->adb_command&0x0f;
1895            adb_mouseaddr = mac->m_adb_command&0x0f;
19021896         }
19031897      }
1904      else if (mac->adb_listenaddr == adb_keybaddr)
1898      else if (mac->m_adb_listenaddr == adb_keybaddr)
19051899      {
1906         if ((mac->adb_listenreg == 3) && (mac->adb_command > 0) && (mac->adb_command < 16))
1900         if ((mac->m_adb_listenreg == 3) && (mac->m_adb_command > 0) && (mac->m_adb_command < 16))
19071901         {
19081902            #if LOG_ADB
1909            printf("KEYBOARD: moving to address %x\n", mac->adb_command);
1903            printf("KEYBOARD: moving to address %x\n", mac->m_adb_command);
19101904            #endif
1911            adb_keybaddr = mac->adb_command&0x0f;
1905            adb_keybaddr = mac->m_adb_command&0x0f;
19121906         }
19131907      }
19141908   }
r9489r9490
19161910
19171911static TIMER_CALLBACK(mac_adb_tick)
19181912{
1919   via6522_device *via_0 = machine->device<via6522_device>("via6522_0");
19201913   mac_state *mac = machine->driver_data<mac_state>();
19211914
19221915   // do one clock transition on CB1 to advance the VIA shifter
1923   mac->adb_extclock ^= 1;
1924   via_0->write_cb1(mac->adb_extclock);
1925   mac->adb_extclock ^= 1;
1926   via_0->write_cb1(mac->adb_extclock);
1916   mac->m_adb_extclock ^= 1;
1917   mac->m_via1->write_cb1(mac->m_adb_extclock);
1918   mac->m_adb_extclock ^= 1;
1919   mac->m_via1->write_cb1(mac->m_adb_extclock);
19271920
1928   mac->adb_timer_ticks--;
1929   if (!mac->adb_timer_ticks)
1921   mac->m_adb_timer_ticks--;
1922   if (!mac->m_adb_timer_ticks)
19301923   {
19311924      timer_adjust_oneshot(mac_adb_timer, attotime_never, 0);
19321925
1933      if ((mac->adb_direction) && (ADB_IS_BITBANG))
1926      if ((mac->m_adb_direction) && (ADB_IS_BITBANG))
19341927      {
19351928         mac_adb_talk(machine);
19361929      }
19371930      else if (ADB_IS_EGRET)
19381931      {
19391932         // Egret sending a response to the 680x0?
1940         if (mac->adb_state & 1)
1933         if (mac->m_adb_state & 1)
19411934         {
1942            if (mac->adb_datasize > 0)
1935            if (mac->m_adb_datasize > 0)
19431936            {
1944               mac->adb_send = mac->adb_buffer[mac->adb_datasize];
1937               mac->m_adb_send = mac->m_adb_buffer[mac->m_adb_datasize];
19451938               #if LOG_ADB
1946               printf("Egret ADB: sending byte %02x, %d left\n", mac->adb_send, mac->adb_datasize-1);
1939               printf("Egret ADB: sending byte %02x, %d left\n", mac->m_adb_send, mac->m_adb_datasize-1);
19471940               #endif
19481941
1949               mac->adb_datasize--;
1942               mac->m_adb_datasize--;
19501943            }
19511944            else
19521945            {
1953               switch (mac->adb_streaming)
1946               switch (mac->m_adb_streaming)
19541947               {
19551948                  case MCU_STREAMING_PRAMRD:
19561949                     #if LOG_ADB
1957                     printf("Egret ADB: streaming PRAM byte %02x = %02x\n", mac->adb_stream_ptr, mac->rtc_ram[mac->adb_stream_ptr]);
1950                     printf("Egret ADB: streaming PRAM byte %02x = %02x\n", mac->m_adb_stream_ptr, mac->m_rtc_ram[mac->m_adb_stream_ptr]);
19581951                     #endif
1959                     mac->adb_send = mac->rtc_ram[mac->adb_stream_ptr++];
1960                     if (mac->adb_stream_ptr >= 256)
1952                     mac->m_adb_send = mac->m_rtc_ram[mac->m_adb_stream_ptr++];
1953                     if (mac->m_adb_stream_ptr >= 256)
19611954                     {
19621955                        #if LOG_ADB
19631956                        printf("Egret ADB: this is the last PRAM byte, dropping XS\n");
19641957                        #endif
1965                        mac->adb_state &= ~1;
1958                        mac->m_adb_state &= ~1;
19661959                     }
19671960                     break;
19681961
r9489r9490
19701963                     #if LOG_ADB
19711964                     printf("Egret ADB: trying to stream unhandled type\n");
19721965                     #endif
1973                     mac->adb_send = 0;
1966                     mac->m_adb_send = 0;
19741967                     break;
19751968               }
19761969            }
19771970
1978//              mac->adb_timer_ticks = 8;
1971//              mac->m_adb_timer_ticks = 8;
19791972//              timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
19801973
1981            if ((mac->adb_datasize == 0) && (mac->adb_streaming == MCU_STREAMING_NONE))
1974            if ((mac->m_adb_datasize == 0) && (mac->m_adb_streaming == MCU_STREAMING_NONE))
19821975            {
19831976               #if LOG_ADB
19841977               printf("Egret ADB: this is the last byte, dropping XS\n");
19851978               #endif
1986               mac->adb_state &= ~1;
1979               mac->m_adb_state &= ~1;
19871980            }
19881981         }
19891982         else
19901983         {
19911984            // it's not a command byte if SS is low
1992            if (mac->adb_state & 0x02)
1985            if (mac->m_adb_state & 0x02)
19931986            {
19941987               #if LOG_ADB
1995               printf("Egret ADB: got command byte %02x [%02x]\n", mac->adb_command, mac->adb_datasize);
1988               printf("Egret ADB: got command byte %02x [%02x]\n", mac->m_adb_command, mac->m_adb_datasize);
19961989               #endif
1997               mac->adb_buffer[mac->adb_datasize++] = mac->adb_command;
1998               mac->adb_command = 0;
1990               mac->m_adb_buffer[mac->m_adb_datasize++] = mac->m_adb_command;
1991               mac->m_adb_command = 0;
19991992            }
20001993         }
20011994      }
r9489r9490
20112004   UINT8 ret;
20122005   mac_state *mac = device->machine->driver_data<mac_state>();
20132006
2014   ret = (mac->adb_send & 0x80)>>7;
2015   mac->adb_send <<= 1;
2007   ret = (mac->m_adb_send & 0x80)>>7;
2008   mac->m_adb_send <<= 1;
20162009
20172010//  printf("VIA IN CB2 = %x\n", ret);
20182011
r9489r9490
20242017   mac_state *mac = device->machine->driver_data<mac_state>();
20252018
20262019//        printf("VIA OUT CB2 = %x\n", data);
2027   mac->adb_command <<= 1;
2028   mac->adb_command |= data & 1;
2020   mac->m_adb_command <<= 1;
2021   mac->m_adb_command |= data & 1;
20292022}
20302023
20312024static void mac_adb_newaction(mac_state *mac, int state)
20322025{
2033   if (state != mac->adb_state)
2026   if (state != mac->m_adb_state)
20342027   {
20352028      #if LOG_ADB
20362029      printf("New ADB state: %s\n", adb_statenames[state]);
20372030      #endif
20382031
2039      mac->adb_state = state;
2040      mac->adb_timer_ticks = 8;
2032      mac->m_adb_state = state;
2033      mac->m_adb_timer_ticks = 8;
20412034
20422035      switch (state)
20432036      {
20442037         case ADB_STATE_NEW_COMMAND:
2045            mac->adb_command = mac->adb_send = 0;
2046            mac->adb_direction = 1;   // Mac is shifting us a command
2047            mac->adb_waiting_cmd = 1;   // we're going to get a command
2048            mac->adb_irq_pending = 0;
2038            mac->m_adb_command = mac->m_adb_send = 0;
2039            mac->m_adb_direction = 1;   // Mac is shifting us a command
2040            mac->m_adb_waiting_cmd = 1;   // we're going to get a command
2041            mac->m_adb_irq_pending = 0;
20492042            timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
20502043            break;
20512044
20522045         case ADB_STATE_XFER_EVEN:
20532046         case ADB_STATE_XFER_ODD:
2054            if (mac->adb_datasize > 0)
2047            if (mac->m_adb_datasize > 0)
20552048            {
20562049               int i;
20572050
20582051               // is something trying to send to the Mac?
2059               if (mac->adb_direction == 0)
2052               if (mac->m_adb_direction == 0)
20602053               {
20612054                  // set up the byte
2062                  mac->adb_send = mac->adb_buffer[0];
2063                  mac->adb_datasize--;
2055                  mac->m_adb_send = mac->m_adb_buffer[0];
2056                  mac->m_adb_datasize--;
20642057
20652058                  // move down the rest of the buffer, if any
2066                  for (i = 0; i < mac->adb_datasize; i++)
2059                  for (i = 0; i < mac->m_adb_datasize; i++)
20672060                  {
2068                     mac->adb_buffer[i] = mac->adb_buffer[i+1];
2061                     mac->m_adb_buffer[i] = mac->m_adb_buffer[i+1];
20692062                  }
20702063               }
20712064
20722065            }
20732066            else
20742067            {
2075               mac->adb_send = 0;
2076               mac->adb_irq_pending = 1;
2068               mac->m_adb_send = 0;
2069               mac->m_adb_irq_pending = 1;
20772070            }
20782071
20792072            timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
20802073            break;
20812074
20822075         case ADB_STATE_IDLE:
2083            mac->adb_irq_pending = 0;
2076            mac->m_adb_irq_pending = 0;
20842077            break;
20852078      }
20862079   }
r9489r9490
20882081
20892082static void mac_egret_response_std(mac_state *mac, int type, int flag, int cmd)
20902083{
2091   mac->adb_send = 0xaa;
2092   mac->adb_buffer[3] = type;
2093   mac->adb_buffer[2] = flag;
2094   mac->adb_buffer[1] = cmd;
2095   mac->adb_state |= 1;
2096   mac->adb_timer_ticks = 8;
2097   mac->adb_datasize = 3;
2084   mac->m_adb_send = 0xaa;
2085   mac->m_adb_buffer[3] = type;
2086   mac->m_adb_buffer[2] = flag;
2087   mac->m_adb_buffer[1] = cmd;
2088   mac->m_adb_state |= 1;
2089   mac->m_adb_timer_ticks = 8;
2090   mac->m_adb_datasize = 3;
20982091   timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
20992092}
21002093
21012094static void mac_egret_response_read_pram(mac_state *mac, int cmd, int addr)
21022095{
2103   mac->adb_datasize = 4;
2096   mac->m_adb_datasize = 4;
21042097
2105   mac->adb_send = 0xaa;
2106   mac->adb_buffer[4] = 1;   // type
2107   mac->adb_buffer[3] = 0;   // flag
2108   mac->adb_buffer[2] = cmd; // command
2109   mac->adb_buffer[1] = mac->rtc_ram[addr];
2098   mac->m_adb_send = 0xaa;
2099   mac->m_adb_buffer[4] = 1;   // type
2100   mac->m_adb_buffer[3] = 0;   // flag
2101   mac->m_adb_buffer[2] = cmd; // command
2102   mac->m_adb_buffer[1] = mac->m_rtc_ram[addr];
21102103
2111   mac->adb_state |= 1;
2112   mac->adb_timer_ticks = 8;
2104   mac->m_adb_state |= 1;
2105   mac->m_adb_timer_ticks = 8;
21132106   timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
21142107
21152108   // read PRAM is a "streaming" command, don't drop the state line when we're out of data
2116   mac->adb_streaming = MCU_STREAMING_PRAMRD;
2117   mac->adb_stream_ptr = addr+1;
2109   mac->m_adb_streaming = MCU_STREAMING_PRAMRD;
2110   mac->m_adb_stream_ptr = addr+1;
21182111}
21192112
21202113static void mac_egret_response_read_rtc(mac_state *mac)
21212114{
2122   mac->adb_datasize = 7;
2115   mac->m_adb_datasize = 7;
21232116
2124   mac->adb_send = 0xaa;
2125   mac->adb_buffer[7] = 1;   // type
2126   mac->adb_buffer[6] = 0;   // flag
2127   mac->adb_buffer[5] = 7;   // command
2128   mac->adb_buffer[4] = mac->rtc_seconds[3];
2129   mac->adb_buffer[3] = mac->rtc_seconds[2];
2130   mac->adb_buffer[2] = mac->rtc_seconds[1];
2131   mac->adb_buffer[1] = mac->rtc_seconds[0];
2117   mac->m_adb_send = 0xaa;
2118   mac->m_adb_buffer[7] = 1;   // type
2119   mac->m_adb_buffer[6] = 0;   // flag
2120   mac->m_adb_buffer[5] = 7;   // command
2121   mac->m_adb_buffer[4] = mac->m_rtc_seconds[3];
2122   mac->m_adb_buffer[3] = mac->m_rtc_seconds[2];
2123   mac->m_adb_buffer[2] = mac->m_rtc_seconds[1];
2124   mac->m_adb_buffer[1] = mac->m_rtc_seconds[0];
21322125
2133   mac->adb_state |= 1;
2134   mac->adb_timer_ticks = 8;
2126   mac->m_adb_state |= 1;
2127   mac->m_adb_timer_ticks = 8;
21352128   timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
21362129}
21372130
21382131static void mac_egret_mcu_exec(mac_state *mac)
21392132{
2140   mac->adb_streaming = MCU_STREAMING_NONE;
2141   switch (mac->adb_buffer[1])
2133   mac->m_adb_streaming = MCU_STREAMING_NONE;
2134   switch (mac->m_adb_buffer[1])
21422135   {
21432136      case 0x01:   // enable/disable ADB auto-polling
21442137         #if LOG_ADB || LOG_ADB_MCU_CMD
2145         if (mac->adb_buffer[2])
2138         if (mac->m_adb_buffer[2])
21462139         {
21472140            printf("ADB: Egret enable ADB auto-poll\n");
21482141         }
r9489r9490
21572150
21582151      case 0x02: // read 6805 address
21592152         {
2160            int addr = mac->adb_buffer[2]<<8 | mac->adb_buffer[3];
2153            int addr = mac->m_adb_buffer[2]<<8 | mac->m_adb_buffer[3];
21612154
21622155            #if LOG_ADB || LOG_ADB_MCU_CMD
21632156            printf("ADB: Egret read 6805 address %x\n", addr);
r9489r9490
21792172
21802173      case 0x03: // read RTC
21812174         #if LOG_ADB || LOG_ADB_MCU_CMD
2182         printf("ADB: Egret read RTC = %08x\n", mac->rtc_seconds[3]<<24|mac->rtc_seconds[2]<<16|mac->rtc_seconds[1]<<8|mac->rtc_seconds[0]);
2175         printf("ADB: Egret read RTC = %08x\n", mac->m_rtc_seconds[3]<<24|mac->m_rtc_seconds[2]<<16|mac->m_rtc_seconds[1]<<8|mac->m_rtc_seconds[0]);
21832176         #endif
21842177
21852178         mac_egret_response_read_rtc(mac);
r9489r9490
21872180
21882181      case 0x07: // read PRAM
21892182         #if LOG_ADB || LOG_ADB_MCU_CMD
2190         printf("ADB: Egret read PRAM from %x\n", mac->adb_buffer[2]<<8 | mac->adb_buffer[3]);
2183         printf("ADB: Egret read PRAM from %x\n", mac->m_adb_buffer[2]<<8 | mac->m_adb_buffer[3]);
21912184         #endif
21922185
2193         mac_egret_response_read_pram(mac, 7, mac->adb_buffer[2]<<8 | mac->adb_buffer[3]);
2186         mac_egret_response_read_pram(mac, 7, mac->m_adb_buffer[2]<<8 | mac->m_adb_buffer[3]);
21942187         break;
21952188
21962189      case 0x08: // write 6805 address
21972190         {
2198            int addr = mac->adb_buffer[2]<<8 | mac->adb_buffer[3];
2199            int len = mac->adb_datasize - 4;
2191            int addr = mac->m_adb_buffer[2]<<8 | mac->m_adb_buffer[3];
2192            int len = mac->m_adb_datasize - 4;
22002193
22012194            #if LOG_ADB || LOG_ADB_MCU_CMD
22022195            printf("ADB: Egret write %d bytes to address %x\n", len, addr);
r9489r9490
22072200            {
22082201               for (int i = 0; i < len; i++)
22092202               {
2210                  mac->rtc_ram[(addr-0x100)+i] = mac->adb_buffer[4+i];
2203                  mac->m_rtc_ram[(addr-0x100)+i] = mac->m_adb_buffer[4+i];
22112204               }
22122205            }
22132206            #if LOG_ADB || LOG_ADB_MCU_CMD
r9489r9490
22232216
22242217      case 0x0c: // write PRAM
22252218         #if LOG_ADB || LOG_ADB_MCU_CMD
2226         printf("ADB: Egret write %02x to PRAM at %x\n", mac->adb_buffer[4], mac->adb_buffer[2]<<8 | mac->adb_buffer[3]);
2219         printf("ADB: Egret write %02x to PRAM at %x\n", mac->m_adb_buffer[4], mac->m_adb_buffer[2]<<8 | mac->m_adb_buffer[3]);
22272220         #endif
22282221
2229         mac->rtc_ram[mac->adb_buffer[2]<<8 | mac->adb_buffer[3]] = mac->adb_buffer[4];
2222         mac->m_rtc_ram[mac->m_adb_buffer[2]<<8 | mac->m_adb_buffer[3]] = mac->m_adb_buffer[4];
22302223
2231         mac->adb_datasize = 4;
2232         mac->adb_buffer[4] = 1;   // type
2233         mac->adb_buffer[3] = 0;   // flag
2234         mac->adb_buffer[2] = 0x0c;   // command
2235         mac->adb_buffer[1] = 0;   // spare
2236         mac->adb_state |= 1;
2237         mac->adb_timer_ticks = 8;
2224         mac->m_adb_datasize = 4;
2225         mac->m_adb_buffer[4] = 1;   // type
2226         mac->m_adb_buffer[3] = 0;   // flag
2227         mac->m_adb_buffer[2] = 0x0c;   // command
2228         mac->m_adb_buffer[1] = 0;   // spare
2229         mac->m_adb_state |= 1;
2230         mac->m_adb_timer_ticks = 8;
22382231         timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
22392232         break;
22402233
22412234      case 0x0e: // send to DFAC
22422235         #if LOG_ADB || LOG_ADB_MCU_CMD
2243         printf("ADB: Egret send %02x to DFAC\n", mac->adb_buffer[2]);
2236         printf("ADB: Egret send %02x to DFAC\n", mac->m_adb_buffer[2]);
22442237         #endif
22452238
22462239         mac_egret_response_std(mac, 1, 0, 0x0e);
r9489r9490
22482241
22492242      case 0x1b: // set one-second interrupt
22502243         #if LOG_ADB || LOG_ADB_MCU_CMD
2251         if (mac->adb_buffer[2])
2244         if (mac->m_adb_buffer[2])
22522245         {
22532246            printf("ADB: Egret enable one-second IRQ\n");
22542247         }
r9489r9490
22632256
22642257      case 0x1c:   // enable/disable keyboard NMI
22652258         #if LOG_ADB || LOG_ADB_MCU_CMD
2266         if (mac->adb_buffer[2])
2259         if (mac->m_adb_buffer[2])
22672260         {
22682261            printf("ADB: Egret enable keyboard NMI\n");
22692262         }
r9489r9490
22782271
22792272      default:
22802273         #if LOG_ADB || LOG_ADB_MCU_CMD
2281         printf("ADB: Unknown Egret MCU command %02x\n", mac->adb_buffer[1]);
2274         printf("ADB: Unknown Egret MCU command %02x\n", mac->m_adb_buffer[1]);
22822275         #endif
22832276         break;
22842277   }
r9489r9490
22862279
22872280static void mac_egret_newaction(mac_state *mac, int state)
22882281{
2289   if (state != mac->adb_state)
2282   if (state != mac->m_adb_state)
22902283   {
22912284      #if LOG_ADB
2292      printf("ADB: New Egret state: SS %d VF %d XS (68k %d MCU %d)\n", (state>>2)&1, (state>>1)&1, state&1, mac->adb_state&1);
2285      printf("ADB: New Egret state: SS %d VF %d XS (68k %d MCU %d)\n", (state>>2)&1, (state>>1)&1, state&1, mac->m_adb_state&1);
22932286      #endif
22942287
22952288      // if bit 2 is high and stays high, the rising edge of bit 1 indicates the start of sending a byte to the MCU if XS isn't high
2296      if ((state & 0x04) && (mac->adb_state & 0x04) && (state & 0x02) && !(mac->adb_state & 0x02) && !(mac->adb_state & 0x01))
2289      if ((state & 0x04) && (mac->m_adb_state & 0x04) && (state & 0x02) && !(mac->m_adb_state & 0x02) && !(mac->m_adb_state & 0x01))
22972290      {
2298         mac->adb_command = 0;
2299         mac->adb_timer_ticks = 8;
2291         mac->m_adb_command = 0;
2292         mac->m_adb_timer_ticks = 8;
23002293         timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
23012294      }
23022295
23032296      // if bit 2 is high and stays high, the falling edge of bit 1, and we're in send phase, the MCU should clock out a byte
2304      if ((state & 0x04) && (mac->adb_state & 0x04) && !(state & 0x02) && (mac->adb_state & 0x02) && (mac->adb_state & 0x01))
2297      if ((state & 0x04) && (mac->m_adb_state & 0x04) && !(state & 0x02) && (mac->m_adb_state & 0x02) && (mac->m_adb_state & 0x01))
23052298      {
2306         mac->adb_timer_ticks = 8;
2299         mac->m_adb_timer_ticks = 8;
23072300         timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
23082301      }
23092302
23102303      // if bit 2 rises, bit 1 is 0, and MCU XS is high, the MCU should clock out a byte
2311      if ((state & 0x04) && !(mac->adb_state & 0x04) && !(state & 0x02) && (mac->adb_state & 0x01))
2304      if ((state & 0x04) && !(mac->m_adb_state & 0x04) && !(state & 0x02) && (mac->m_adb_state & 0x01))
23122305      {
2313         mac->adb_timer_ticks = 8;
2306         mac->m_adb_timer_ticks = 8;
23142307         timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
23152308      }
23162309
23172310      // if bit 2 drops and bit 1 is 1, terminate the command
2318      if ((state & 0x02) && !(state & 0x04) && (mac->adb_state & 0x04))
2311      if ((state & 0x02) && !(state & 0x04) && (mac->m_adb_state & 0x04))
23192312      {
23202313         #if LOG_ADB
23212314         printf("Egret ADB: SESSION dropped with VF=1, terminating command\n");
23222315         #endif
2323         mac->adb_streaming = MCU_STREAMING_NONE;
2324         mac->adb_state &= ~1;
2325         mac->adb_datasize = 0;
2316         mac->m_adb_streaming = MCU_STREAMING_NONE;
2317         mac->m_adb_state &= ~1;
2318         mac->m_adb_datasize = 0;
23262319      }
23272320
23282321      // if bit 2 drops and bit 1 is zero, execute the command
2329      if (!(state & 0x02) && !(state & 0x04) && (mac->adb_state & 0x04) && (mac->adb_datasize > 0))
2322      if (!(state & 0x02) && !(state & 0x04) && (mac->m_adb_state & 0x04) && (mac->m_adb_datasize > 0))
23302323      {
23312324         #if LOG_ADB || LOG_ADB_MCU_CMD
23322325         int i;
23332326
2334         printf("Egret ADB: exec command with %d bytes: ", mac->adb_datasize);
2327         printf("Egret ADB: exec command with %d bytes: ", mac->m_adb_datasize);
23352328
2336         for (i = 0; i < mac->adb_datasize; i++)
2329         for (i = 0; i < mac->m_adb_datasize; i++)
23372330         {
2338            printf("%02x ", mac->adb_buffer[i]);
2331            printf("%02x ", mac->m_adb_buffer[i]);
23392332         }
23402333
23412334         printf("\n");
23422335         #endif
23432336
23442337         // exec command here
2345         switch (mac->adb_buffer[0])
2338         switch (mac->m_adb_buffer[0])
23462339         {
23472340            case 0:   // ADB command
2348               switch (mac->adb_buffer[1] & 0xf)
2341               switch (mac->m_adb_buffer[1] & 0xf)
23492342               {
23502343                  case 0:      // reset
23512344                     #if LOG_ADB || LOG_ADB_MCU_CMD
r9489r9490
23622355                     break;
23632356
23642357                  default:
2365                     printf("Egret: Unhandled ADB command %x\n", mac->adb_buffer[1]);
2366                     mac->adb_datasize = 0;
2358                     printf("Egret: Unhandled ADB command %x\n", mac->m_adb_buffer[1]);
2359                     mac->m_adb_datasize = 0;
23672360                     break;
23682361
23692362               }
r9489r9490
23742367               break;
23752368
23762369            case 2: // error
2377               mac->adb_datasize = 0;
2370               mac->m_adb_datasize = 0;
23782371               break;
23792372
23802373            case 3: // one-second interrupt
2381               mac->adb_datasize = 0;
2374               mac->m_adb_datasize = 0;
23822375               break;
23832376         }
23842377      }
23852378
2386      mac->adb_state &= ~0x6;
2387      mac->adb_state |= state & 0x6;
2379      mac->m_adb_state &= ~0x6;
2380      mac->m_adb_state |= state & 0x6;
23882381   }
23892382}
23902383
r9489r9490
23952388   #if LOG_ADB
23962389   printf("PM: timer tick, lowering ACK\n");
23972390   #endif
2398   mac->pm_ack &= ~2;   // lower ACK to handshake next step
2391   mac->m_pm_ack &= ~2;   // lower ACK to handshake next step
23992392}
24002393
24012394static void pmu_one_byte_reply(mac_state *mac, UINT8 result)
24022395{
2403   mac->pm_out[0] = 1;   // length
2404   mac->pm_out[1] = result;
2405   mac->pm_slen = 2;
2406   timer_adjust_oneshot(mac->pmu_send_timer, attotime_make(0, ATTOSECONDS_IN_USEC(200)), 0);
2396   mac->m_pm_out[0] = 1;   // length
2397   mac->m_pm_out[1] = result;
2398   mac->m_pm_slen = 2;
2399   timer_adjust_oneshot(mac->m_pmu_send_timer, attotime_make(0, ATTOSECONDS_IN_USEC(200)), 0);
24072400}
24082401
24092402static void pmu_exec(mac_state *mac)
24102403{
2411   mac->pm_sptr = 0;   // clear send pointer
2412   mac->pm_slen = 0;   // and send length
2413   mac->pm_dptr = 0;   // and recieve pointer
2404   mac->m_pm_sptr = 0;   // clear send pointer
2405   mac->m_pm_slen = 0;   // and send length
2406   mac->m_pm_dptr = 0;   // and recieve pointer
24142407
2415   switch (mac->pm_cmd[0])
2408   switch (mac->m_pm_cmd[0])
24162409   {
24172410      case 0x10:   // subsystem power and clock ctrl (no response)
24182411         break;
24192412
24202413      case 0x32:   // write extended PRAM byte(s).  cmd[2] = address, cmd[3] = length, cmd[4...] = data
2421         if ((mac->pm_cmd[2] + mac->pm_cmd[3]) < 0x100)
2414         if ((mac->m_pm_cmd[2] + mac->m_pm_cmd[3]) < 0x100)
24222415         {
24232416            int i;
24242417
2425            for (i = 0; i < mac->pm_cmd[3]; i++)
2418            for (i = 0; i < mac->m_pm_cmd[3]; i++)
24262419            {
2427               mac->rtc_ram[mac->pm_cmd[2] + i] = mac->pm_cmd[4+i];
2420               mac->m_rtc_ram[mac->m_pm_cmd[2] + i] = mac->m_pm_cmd[4+i];
24282421            }
24292422         }
24302423         break;
r9489r9490
24332426         {
24342427            int i;
24352428
2436            mac->pm_out[0] = 20;
2429            mac->m_pm_out[0] = 20;
24372430            for (i = 0; i < 20; i++)
24382431            {
2439               mac->pm_out[1 + i] = mac->rtc_ram[i];
2432               mac->m_pm_out[1 + i] = mac->m_rtc_ram[i];
24402433            }
2441            mac->pm_slen = 21;
2442            timer_adjust_oneshot(mac->pmu_send_timer, attotime_make(0, ATTOSECONDS_IN_USEC(200)), 0);
2434            mac->m_pm_slen = 21;
2435            timer_adjust_oneshot(mac->m_pmu_send_timer, attotime_make(0, ATTOSECONDS_IN_USEC(200)), 0);
24432436         }
24442437         break;
24452438
24462439      case 0x3a:   // read extended PRAM byte(s).  cmd[2] = address, cmd[3] = length
2447         if ((mac->pm_cmd[2] + mac->pm_cmd[3]) < 0x100)
2440         if ((mac->m_pm_cmd[2] + mac->m_pm_cmd[3]) < 0x100)
24482441         {
24492442            int i;
24502443
2451            mac->pm_out[0] = mac->pm_cmd[3];
2452            for (i = 0; i < mac->pm_cmd[3]; i++)
2444            mac->m_pm_out[0] = mac->m_pm_cmd[3];
2445            for (i = 0; i < mac->m_pm_cmd[3]; i++)
24532446            {
2454               mac->pm_out[1 + i] = mac->rtc_ram[mac->pm_cmd[2] + i];
2447               mac->m_pm_out[1 + i] = mac->m_rtc_ram[mac->m_pm_cmd[2] + i];
24552448            }
2456            mac->pm_slen = mac->pm_cmd[3] + 1;
2457            timer_adjust_oneshot(mac->pmu_send_timer, attotime_make(0, ATTOSECONDS_IN_USEC(200)), 0);
2449            mac->m_pm_slen = mac->m_pm_cmd[3] + 1;
2450            timer_adjust_oneshot(mac->m_pmu_send_timer, attotime_make(0, ATTOSECONDS_IN_USEC(200)), 0);
24582451         }
24592452         break;
24602453
r9489r9490
24712464         break;
24722465
24732466      default:
2474         fatalerror("PMU: Unhandled command %02x\n", mac->pm_cmd[0]);
2467         fatalerror("PMU: Unhandled command %02x\n", mac->m_pm_cmd[0]);
24752468         break;
24762469   }
24772470
2478   if (mac->pm_slen > 0)
2471   if (mac->m_pm_slen > 0)
24792472   {
2480      mac->pm_state = 1;
2473      mac->m_pm_state = 1;
24812474   }
24822475}
24832476
2484static void adb_vblank(running_machine *machine)
2477void mac_state::adb_vblank(running_machine *machine)
24852478{
2486   mac_state *mac = machine->driver_data<mac_state>();
2487
2488   if (mac->adb_state == ADB_STATE_IDLE)
2479   if (m_adb_state == ADB_STATE_IDLE)
24892480   {
24902481      if (mac_adb_pollmouse(machine))
24912482      {
24922483         // if the mouse was the last TALK, we can just send the new data
24932484         // otherwise we need to pull SRQ
2494         if (mac->adb_last_talk == adb_mouseaddr)
2485         if (m_adb_last_talk == adb_mouseaddr)
24952486         {
24962487            // repeat last TALK to get updated data
2497            mac->adb_waiting_cmd = 1;
2488            m_adb_waiting_cmd = 1;
24982489            mac_adb_talk(machine);
24992490
2500            mac->adb_timer_ticks = 8;
2491            m_adb_timer_ticks = 8;
25012492            timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
25022493         }
25032494         else
25042495         {
2505            mac->adb_irq_pending = 1;
2506            mac->adb_command = mac->adb_send = 0;
2507            mac->adb_timer_ticks = 1;   // one tick should be sufficient to make it see  the IRQ
2496            m_adb_irq_pending = 1;
2497            m_adb_command = m_adb_send = 0;
2498            m_adb_timer_ticks = 1;   // one tick should be sufficient to make it see  the IRQ
25082499            timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
2509            mac->adb_srq_switch = 1;
2500            m_adb_srq_switch = 1;
25102501         }
25112502      }
25122503      else if (mac_adb_pollkbd(machine, 0))
25132504      {
2514         if (mac->adb_last_talk == adb_keybaddr)
2505         if (m_adb_last_talk == adb_keybaddr)
25152506         {
25162507            // repeat last TALK to get updated data
2517            mac->adb_waiting_cmd = 1;
2508            m_adb_waiting_cmd = 1;
25182509            mac_adb_talk(machine);
25192510
2520            mac->adb_timer_ticks = 8;
2511            m_adb_timer_ticks = 8;
25212512            timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
25222513         }
25232514         else
25242515         {
2525            mac->adb_irq_pending = 1;
2526            mac->adb_command = mac->adb_send = 0;
2527            mac->adb_timer_ticks = 1;   // one tick should be sufficient to make it see  the IRQ
2516            m_adb_irq_pending = 1;
2517            m_adb_command = m_adb_send = 0;
2518            m_adb_timer_ticks = 1;   // one tick should be sufficient to make it see  the IRQ
25282519            timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
2529            mac->adb_srq_switch = 1;
2520            m_adb_srq_switch = 1;
25302521         }
25312522      }
25322523   }
25332524}
25342525
2535static void adb_reset(mac_state *mac)
2526void mac_state::adb_reset(running_machine *machine)
25362527{
25372528   int i;
25382529
2539   mac->adb_srq_switch = 0;
2540   mac->adb_irq_pending = 0;      // no interrupt
2541   mac->adb_timer_ticks = 0;
2542   mac->adb_command = 0;
2543   mac->adb_extclock = 0;
2544   mac->adb_send = 0;
2545   mac->adb_waiting_cmd = 0;
2546   mac->adb_streaming = MCU_STREAMING_NONE;
2547   if (ADB_IS_BITBANG)
2530   m_adb_srq_switch = 0;
2531   m_adb_irq_pending = 0;      // no interrupt
2532   m_adb_timer_ticks = 0;
2533   m_adb_command = 0;
2534   m_adb_extclock = 0;
2535   m_adb_send = 0;
2536   m_adb_waiting_cmd = 0;
2537   m_adb_streaming = MCU_STREAMING_NONE;
2538   m_adb_state = 0;
2539   if (ADB_IS_BITBANG_CLASS)
25482540   {
2549      mac->adb_state = ADB_STATE_NOTINIT;
2541      m_adb_state = ADB_STATE_NOTINIT;
25502542   }
2551   else if (ADB_IS_EGRET)
2552   {
2553      mac->adb_state = 0;
2554   }
2555   mac->adb_direction = 0;
2556   mac->adb_datasize = 0;
2557   mac->adb_last_talk = -1;
2543   m_adb_direction = 0;
2544   m_adb_datasize = 0;
2545   m_adb_last_talk = -1;
25582546
25592547   // mouse
25602548   adb_mouseaddr = 3;
r9489r9490
25682556   adb_modifiers = 0;
25692557   for (i=0; i<7; i++)
25702558   {
2571      mac->key_matrix[i] = 0;
2559      m_key_matrix[i] = 0;
25722560   }
25732561}
25742562
r9489r9490
26142602
26152603//  printf("VIA1 IN_A (PC %x)\n", cpu_get_pc(device->machine->device("maincpu")));
26162604
2617   switch (mac->model)
2605   switch (mac->m_model)
26182606   {
26192607      case MODEL_MAC_PORTABLE:
26202608      case MODEL_MAC_PB100:
26212609         #if LOG_ADB
2622//         printf("Read PM data %x\n", mac->pm_data_recv);
2610//         printf("Read PM data %x\n", mac->m_pm_data_recv);
26232611         #endif
2624         return mac->pm_data_recv;
2612         return mac->m_pm_data_recv;
26252613
26262614      case MODEL_MAC_CLASSIC:
26272615      case MODEL_MAC_II:
r9489r9490
26782666   mac_state *mac = device->machine->driver_data<mac_state>();
26792667
26802668   // portable/PB100 is pretty different
2681   if (mac->model >= MODEL_MAC_PORTABLE && mac->model <= MODEL_MAC_PB100)
2669   if (mac->m_model >= MODEL_MAC_PORTABLE && mac->m_model <= MODEL_MAC_PB100)
26822670   {
2683//      printf("Read VIA B: PM_ACK %x\n", mac->pm_ack);
2684      val = 0x80 | 0x04 | mac->pm_ack;   // SCC wait/request (bit 2 must be set at 900c1a or startup tests always fail)
2671//      printf("Read VIA B: PM_ACK %x\n", mac->m_pm_ack);
2672      val = 0x80 | 0x04 | mac->m_pm_ack;   // SCC wait/request (bit 2 must be set at 900c1a or startup tests always fail)
26852673   }
26862674   else
26872675   {
r9489r9490
26912679
26922680      if (ADB_IS_BITBANG)
26932681      {
2694         val |= mac->adb_state<<4;
2682         val |= mac->m_adb_state<<4;
26952683
2696         if (!mac->adb_irq_pending)
2684         if (!mac->m_adb_irq_pending)
26972685         {
26982686            val |= 0x08;
26992687         }
27002688      }
27012689      else if (ADB_IS_EGRET)
27022690      {
2703         val |= mac->adb_state<<3;
2691         val |= mac->m_adb_state<<3;
27042692         val ^= 0x08;   // maybe it's reversed?
27052693      }
27062694      else
27072695      {
2708         if (mac->mouse_bit_y)   /* Mouse Y2 */
2696         if (mac->m_mouse_bit_y)   /* Mouse Y2 */
27092697            val |= 0x20;
2710         if (mac->mouse_bit_x)   /* Mouse X2 */
2698         if (mac->m_mouse_bit_x)   /* Mouse X2 */
27112699            val |= 0x10;
27122700         if ((input_port_read(device->machine, "MOUSE0") & 0x01) == 0)
27132701            val |= 0x08;
27142702      }
2715      if (mac->rtc_data_out)
2703      if (mac->m_rtc_data_out)
27162704         val |= 1;
27172705   }
27182706
r9489r9490
27292717
27302718//  printf("VIA1 OUT A: %02x (PC %x)\n", data, cpu_get_pc(device->machine->device("maincpu")));
27312719
2732   if (mac->model >= MODEL_MAC_PORTABLE && mac->model <= MODEL_MAC_PB100)
2720   if (mac->m_model >= MODEL_MAC_PORTABLE && mac->m_model <= MODEL_MAC_PB100)
27332721   {
27342722      #if LOG_ADB
27352723//      printf("%02x to PM\n", data);
27362724      #endif
2737      mac->pm_data_send = data;
2725      mac->m_pm_data_send = data;
27382726      return;
27392727   }
27402728
27412729   set_scc_waitrequest((data & 0x80) >> 7);
27422730   mac_set_screen_buffer((data & 0x40) >> 6);
27432731   sony_set_sel_line(fdc,(data & 0x20) >> 5);
2744   if (mac->model == MODEL_MAC_SE)   // on SE this selects which floppy drive (0 = upper, 1 = lower)
2732   if (mac->m_model == MODEL_MAC_SE)   // on SE this selects which floppy drive (0 = upper, 1 = lower)
27452733   {
2746      mac->drive_select = ((data & 0x10) >> 4);
2734      mac->m_drive_select = ((data & 0x10) >> 4);
27472735   }
27482736
2749   if (mac->model < MODEL_MAC_SE)   // SE no longer has dual buffers
2737   if (mac->m_model < MODEL_MAC_SE)   // SE no longer has dual buffers
27502738   {
27512739      mac_set_sound_buffer(sound, (data & 0x08) >> 3);
27522740   }
27532741
2754   if (mac->model < MODEL_MAC_II)
2742   if (mac->m_model < MODEL_MAC_II)
27552743   {
27562744      mac_set_volume(sound, data & 0x07);
27572745   }
r9489r9490
27592747   /* Early Mac models had VIA A4 control overlaying.  In the Mac SE (and
27602748     * possibly later models), overlay was set on reset, but cleared on the
27612749     * first access to the ROM. */
2762   if (mac->model < MODEL_MAC_SE)
2750   if (mac->m_model < MODEL_MAC_SE)
27632751   {
2764      mac_set_memory_overlay(device->machine, (data & 0x10) >> 4);
2752      mac->set_memory_overlay(device->machine, (data & 0x10) >> 4);
27652753   }
27662754}
27672755
r9489r9490
27732761
27742762//  printf("VIA1 OUT B: %02x (PC %x)\n", data, cpu_get_pc(device->machine->device("maincpu")));
27752763
2776   if (mac->model >= MODEL_MAC_PORTABLE && mac->model <= MODEL_MAC_PB100)
2764   if (mac->m_model >= MODEL_MAC_PORTABLE && mac->m_model <= MODEL_MAC_PB100)
27772765   {
27782766      running_device *fdc = device->machine->device("fdc");
27792767
27802768      sony_set_sel_line(fdc,(data & 0x20) >> 5);
2781      mac->drive_select = ((data & 0x10) >> 4);
2769      mac->m_drive_select = ((data & 0x10) >> 4);
27822770
2783      if ((data & 1) && !(mac->pm_req & 1))
2771      if ((data & 1) && !(mac->m_pm_req & 1))
27842772      {
27852773         #if LOG_ADB
27862774         printf("PM: 68k dropping /REQ\n");
27872775         #endif
27882776
2789         if (mac->pm_state == 0)    // do this in receive state only
2777         if (mac->m_pm_state == 0)    // do this in receive state only
27902778         {
2791            mac->pm_data_recv = 0xff;
2792            mac->pm_ack |= 2;
2779            mac->m_pm_data_recv = 0xff;
2780            mac->m_pm_ack |= 2;
27932781
27942782            // check if length byte matches
2795            if ((mac->pm_dptr >= 2) && (mac->pm_cmd[1] == (mac->pm_dptr-2)))
2783            if ((mac->m_pm_dptr >= 2) && (mac->m_pm_cmd[1] == (mac->m_pm_dptr-2)))
27962784            {
27972785               pmu_exec(mac);
27982786               #if LOG_ADB
2799               printf("PMU exec: command %02x length %d\n", mac->pm_cmd[0], mac->pm_cmd[1]);
2787               printf("PMU exec: command %02x length %d\n", mac->m_pm_cmd[0], mac->m_pm_cmd[1]);
28002788               #endif
28012789            }
28022790         }
28032791      }
2804      else if (!(data & 1) && (mac->pm_req & 1))
2792      else if (!(data & 1) && (mac->m_pm_req & 1))
28052793      {
2806         if (mac->pm_state == 0)
2794         if (mac->m_pm_state == 0)
28072795         {
28082796            #if LOG_ADB
2809            printf("PM: 68k asserting /REQ, clocking in byte [%d] = %02x\n", mac->pm_dptr, mac->pm_data_send);
2797            printf("PM: 68k asserting /REQ, clocking in byte [%d] = %02x\n", mac->m_pm_dptr, mac->m_pm_data_send);
28102798            #endif
2811            mac->pm_ack &= ~2;   // clear, we're waiting for more bytes
2812            mac->pm_cmd[mac->pm_dptr++] = mac->pm_data_send;
2799            mac->m_pm_ack &= ~2;   // clear, we're waiting for more bytes
2800            mac->m_pm_cmd[mac->m_pm_dptr++] = mac->m_pm_data_send;
28132801         }
28142802         else   // receiving, so this is different
28152803         {
2816            mac->pm_data_recv = mac->pm_out[mac->pm_sptr++];
2817            mac->pm_slen--;
2818            mac->pm_ack |= 2;   // raise ACK to indicate available byte
2804            mac->m_pm_data_recv = mac->m_pm_out[mac->m_pm_sptr++];
2805            mac->m_pm_slen--;
2806            mac->m_pm_ack |= 2;   // raise ACK to indicate available byte
28192807            #if LOG_ADB
2820            printf("PM: 68k asserted /REQ, sending byte %02x\n", mac->pm_data_recv);
2808            printf("PM: 68k asserted /REQ, sending byte %02x\n", mac->m_pm_data_recv);
28212809            #endif
28222810
28232811            // another byte to send?
2824            if (mac->pm_slen)
2812            if (mac->m_pm_slen)
28252813            {
2826               timer_adjust_oneshot(mac->pmu_send_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
2814               timer_adjust_oneshot(mac->m_pmu_send_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
28272815            }
28282816            else
28292817            {
2830               mac->pm_state = 0;   // back to receive state
2831               timer_adjust_oneshot(mac->pmu_send_timer, attotime_never, 0);
2818               mac->m_pm_state = 0;   // back to receive state
2819               timer_adjust_oneshot(mac->m_pmu_send_timer, attotime_never, 0);
28322820            }
28332821         }
28342822      }
28352823
2836      mac->pm_req = data & 1;
2824      mac->m_pm_req = data & 1;
28372825      return;
28382826   }
28392827
r9489r9490
28432831   }
28442832
28452833   // SE and Classic have SCSI enable/disable here
2846   if ((mac->model == MODEL_MAC_SE) || (mac->model == MODEL_MAC_CLASSIC))
2834   if ((mac->m_model == MODEL_MAC_SE) || (mac->m_model == MODEL_MAC_CLASSIC))
28472835   {
2848      mac->scsiirq_enable = (data & 0x40) ? 0 : 1;
2849//      printf("VIAB & 0x40 = %02x, IRQ enable %d\n", data & 0x40, mac->scsiirq_enable);
2836      mac->m_scsiirq_enable = (data & 0x40) ? 0 : 1;
2837//      printf("VIAB & 0x40 = %02x, IRQ enable %d\n", data & 0x40, mac->m_scsiirq_enable);
28502838   }
28512839
2852   if (mac->model == MODEL_MAC_SE30)
2840   if (mac->m_model == MODEL_MAC_SE30)
28532841   {
28542842      // 0x40 = 0 means enable vblank on SE/30
2855      mac->mac_se30_vbl_enable = (data & 0x40) ? 0 : 1;
2843      mac->m_se30_vbl_enable = (data & 0x40) ? 0 : 1;
28562844
28572845      // clear the interrupt if we disabled it
2858      if (!mac->mac_se30_vbl_enable)
2846      if (!mac->m_se30_vbl_enable)
28592847      {
2860         mac_nubus_slot_interrupt(device->machine, 0xe, 0);
2848         mac->nubus_slot_interrupt(device->machine, 0xe, 0);
28612849      }
28622850   }
28632851
2864   rtc_write_rTCEnb(mac, data & 0x04);
2852   mac->rtc_write_rTCEnb(data & 0x04);
28652853   new_rtc_rTCClk = (data >> 1) & 0x01;
2866   if ((! new_rtc_rTCClk) && (mac->rtc_rTCClk))
2867      rtc_shift_data(mac, data & 0x01);
2868   mac->rtc_rTCClk = new_rtc_rTCClk;
2854   if ((! new_rtc_rTCClk) && (mac->m_rtc_rTCClk))
2855      mac->rtc_shift_data(data & 0x01);
2856   mac->m_rtc_rTCClk = new_rtc_rTCClk;
28692857
28702858   if (ADB_IS_BITBANG)
28712859   {
r9489r9490
28792867
28802868static void mac_via_irq(running_device *device, int state)
28812869{
2870   mac_state *mac = device->machine->driver_data<mac_state>();
2871
28822872   /* interrupt the 68k (level 1) */
2883   set_via_interrupt(device->machine, state);
2873   mac->set_via_interrupt(device->machine, state);
28842874}
28852875
2886READ16_HANDLER ( mac_via_r )
2876READ16_MEMBER ( mac_state::mac_via_r )
28872877{
28882878   UINT16 data;
2889   via6522_device *via_0 = space->machine->device<via6522_device>("via6522_0");;
28902879
28912880   offset >>= 8;
28922881   offset &= 0x0f;
28932882
28942883   if (LOG_VIA)
28952884      logerror("mac_via_r: offset=0x%02x\n", offset);
2896   data = via_0->read(*space, offset);
2885   data = m_via1->read(space, offset);
28972886
28982887   return (data & 0xff) | (data << 8);
28992888}
29002889
2901WRITE16_HANDLER ( mac_via_w )
2890WRITE16_MEMBER ( mac_state::mac_via_w )
29022891{
2903   via6522_device *via_0 = space->machine->device<via6522_device>("via6522_0");;
2904
29052892   offset >>= 8;
29062893   offset &= 0x0f;
29072894
r9489r9490
29092896      logerror("mac_via_w: offset=0x%02x data=0x%08x\n", offset, data);
29102897
29112898   if (ACCESSING_BITS_8_15)
2912      via_0->write(*space, offset, (data >> 8) & 0xff);
2899      m_via1->write(space, offset, (data >> 8) & 0xff);
29132900}
29142901
29152902/* *************************************************************************
r9489r9490
29182905
29192906static void mac_via2_irq(running_device *device, int state)
29202907{
2921   mac_set_via2_interrupt(device->machine, state);
2908   mac_state *mac = device->machine->driver_data<mac_state>();
2909   mac->set_via2_interrupt(device->machine, state);
29222910}
29232911
2924READ16_HANDLER ( mac_via2_r )
2912READ16_MEMBER ( mac_state::mac_via2_r )
29252913{
29262914   int data;
2927   via6522_device *via_1 = space->machine->device<via6522_device>("via6522_1");
29282915
29292916   offset >>= 8;
29302917   offset &= 0x0f;
29312918
2932   data = via_1->read(*space, offset);
2919   data = m_via2->read(space, offset);
29332920
29342921//   if (LOG_VIA)
2935      logerror("mac_via2_r: offset=0x%02x = %02x (PC=%x)\n", offset*2, data, cpu_get_pc(space->machine->device("maincpu")));
2922      logerror("mac_via2_r: offset=0x%02x = %02x (PC=%x)\n", offset*2, data, cpu_get_pc(space.machine->device("maincpu")));
29362923
29372924   return (data & 0xff) | (data << 8);
29382925}
29392926
2940WRITE16_HANDLER ( mac_via2_w )
2927WRITE16_MEMBER ( mac_state::mac_via2_w )
29412928{
2942   via6522_device *via_1 = space->machine->device<via6522_device>("via6522_1");
2943
29442929   offset >>= 8;
29452930   offset &= 0x0f;
29462931
29472932//   if (LOG_VIA)
2948      logerror("mac_via2_w: offset=%x data=0x%08x (PC=%x)\n", offset, data, cpu_get_pc(space->machine->device("maincpu")));
2933      logerror("mac_via2_w: offset=%x data=0x%08x (PC=%x)\n", offset, data, cpu_get_pc(space.machine->device("maincpu")));
29492934
29502935   if (ACCESSING_BITS_8_15)
2951      via_1->write(*space, offset, (data >> 8) & 0xff);
2936      m_via2->write(space, offset, (data >> 8) & 0xff);
29522937}
29532938
29542939
r9489r9490
29572942   UINT8 result = 0xc0;
29582943   mac_state *mac = device->machine->driver_data<mac_state>();
29592944
2960   result |= mac->mac_nubus_irq_state;
2945   result |= mac->m_nubus_irq_state;
29612946
29622947   return result;
29632948}
r9489r9490
29682953
29692954//  logerror("VIA2 IN B (PC %x)\n", cpu_get_pc(device->machine->device("maincpu")));
29702955
2971   if ((mac->model == MODEL_MAC_LC) || (mac->model == MODEL_MAC_LC_II) || (mac->model == MODEL_MAC_CLASSIC_II))
2956   if ((mac->m_model == MODEL_MAC_LC) || (mac->m_model == MODEL_MAC_LC_II) || (mac->m_model == MODEL_MAC_CLASSIC_II))
29722957   {
29732958      return 0x4f;
29742959   }
29752960
2976   if (mac->model == MODEL_MAC_SE30)
2961   if (mac->m_model == MODEL_MAC_SE30)
29772962   {
29782963      return 0x87;   // bits 3 and 6 are tied low on SE/30
29792964   }
r9489r9490
29882973
29892974static WRITE8_DEVICE_HANDLER(mac_via2_out_b)
29902975{
2991   via6522_device *via_0 = device->machine->device<via6522_device>("via6522_0");
2976   mac_state *mac = device->machine->driver_data<mac_state>();
29922977
29932978//  logerror("VIA2 OUT B: %02x (PC %x)\n", data, cpu_get_pc(device->machine->device("maincpu")));
29942979
2995   logerror("VIA2 OUT B: %02x (MMU = %02x)\n", data, data & 0x08);
2980   if (mac->m_model == MODEL_MAC_II)
2981   {
2982      m68k_set_hmmu_enable(mac->m_maincpu, (data & 0x8) ? M68K_HMMU_DISABLE : M68K_HMMU_ENABLE_II);
2983   }
29962984
29972985   // chain 60.15 Hz to VIA1
2998   via_0->write_ca1(data>>7);
2986   mac->m_via1->write_ca1(data>>7);
29992987}
30002988
30012989// This signal is generated internally on RBV, V8, Sonora, VASP, Eagle, etc.
30022990static TIMER_CALLBACK(mac_6015_tick)
30032991{
3004   via6522_device *via_0 = machine->device<via6522_device>("via6522_0");
2992   mac_state *mac = machine->driver_data<mac_state>();
30052993
3006   via_0->write_ca1(0);
3007   via_0->write_ca1(1);
2994   mac->m_via1->write_ca1(0);
2995   mac->m_via1->write_ca1(1);
30082996}
30092997
30102998/* *************************************************************************
30112999 * Main
30123000 * *************************************************************************/
30133001
3014MACHINE_START( mac )
3002void mac_state::machine_start()
30153003{
3016   mac_state *mac = machine->driver_data<mac_state>();
3017   if (has_adb(mac))
3004   if (has_adb())
30183005   {
30193006      mac_adb_timer = timer_alloc(machine, mac_adb_tick, NULL);
30203007      timer_adjust_oneshot(mac_adb_timer, attotime_never, 0);
30213008
30223009      // also allocate PMU timer
3023      if (ADB_IS_PM)
3010      if (ADB_IS_PM_CLASS)
30243011      {
3025         mac->pmu_send_timer = timer_alloc(machine, mac_pmu_tick, NULL);
3012         m_pmu_send_timer = timer_alloc(machine, mac_pmu_tick, NULL);
30263013         timer_adjust_oneshot(mac_adb_timer, attotime_never, 0);
30273014      }
30283015
r9489r9490
30303017   mac_scanline_timer = timer_alloc(machine, mac_scanline_tick, NULL);
30313018   timer_adjust_oneshot(mac_scanline_timer, machine->primary_screen->time_until_pos(0, 0), 0);
30323019
3033   mac->mac6015_timer = timer_alloc(machine, mac_6015_tick, NULL);
3034   timer_adjust_oneshot(mac->mac6015_timer, attotime_never, 0);
3020   m_6015_timer = timer_alloc(machine, mac_6015_tick, NULL);
3021   timer_adjust_oneshot(m_6015_timer, attotime_never, 0);
30353022}
30363023
3037MACHINE_RESET(mac)
3024void mac_state::machine_reset()
30383025{
3039   mac_state *mac = machine->driver_data<mac_state>();
3040
30413026   // stop 60.15 Hz timer
3042   timer_adjust_oneshot(mac->mac6015_timer, attotime_never, 0);
3027   timer_adjust_oneshot(m_6015_timer, attotime_never, 0);
30433028
30443029   // start 60.15 Hz timer for IIci/IIsi (and eventually others)
3045   if ((mac->model == MODEL_MAC_IICI) || (mac->model == MODEL_MAC_IISI))
3030   if ((m_model == MODEL_MAC_IICI) || (m_model == MODEL_MAC_IISI))
30463031   {
3047      timer_adjust_periodic(mac->mac6015_timer, ATTOTIME_IN_HZ(60.15), 0, ATTOTIME_IN_HZ(60.15));
3032      timer_adjust_periodic(m_6015_timer, ATTOTIME_IN_HZ(60.15), 0, ATTOTIME_IN_HZ(60.15));
30483033   }
30493034
30503035   // clear PMU response timer
3051   if (ADB_IS_PM)
3036   if (ADB_IS_PM_CLASS)
30523037   {
30533038      timer_adjust_oneshot(mac_adb_timer, attotime_never, 0);
30543039   }
30553040
3056   last_taken_interrupt = -1;
3041   // default to 32-bit mode on LC
3042   if (m_model == MODEL_MAC_LC)
3043   {
3044      m68k_set_hmmu_enable(m_maincpu, M68K_HMMU_DISABLE);
3045   }
30573046
3047   m_last_taken_interrupt = -1;
3048
30583049   /* initialize real-time clock */
3059   rtc_init(mac);
3050   rtc_init();
30603051
30613052   /* setup the memory overlay */
3062   if (mac->model < MODEL_MAC_POWERMAC_6100)   // no overlay for PowerPC
3053   if (m_model < MODEL_MAC_POWERMAC_6100)   // no overlay for PowerPC
30633054   {
3064      mac->overlay = -1;   // insure no match
3065      mac_set_memory_overlay(machine, 1);
3055      m_overlay = -1;   // insure no match
3056      set_memory_overlay(machine, 1);
30663057   }
30673058
30683059   /* setup videoram */
30693060   mac_set_screen_buffer(1);
30703061
30713062   /* setup sound */
3072   if (AUDIO_IS_CLASSIC)
3063   if (AUDIO_IS_CLASSIC_CLASS)
30733064   {
30743065      mac_set_sound_buffer(machine->device("custom"), 0);
30753066   }
30763067   else if (MAC_HAS_VIA2)   // prime CB1 for ASC and slot interrupts
30773068   {   
3078      via6522_device *via2 = machine->device<via6522_device>("via6522_1");
3079      via2->write_ca1(1);
3080      via2->write_cb1(1);
3069      m_via2->write_ca1(1);
3070      m_via2->write_cb1(1);
30813071   }
30823072
3083   if (has_adb(mac))
3073   if (has_adb())
30843074   {
3085      adb_reset(mac);
3075      adb_reset(machine);
30863076   }
30873077
3088   if ((mac->model == MODEL_MAC_SE) || (mac->model == MODEL_MAC_CLASSIC))
3078   if ((m_model == MODEL_MAC_SE) || (m_model == MODEL_MAC_CLASSIC))
30893079   {
30903080      mac_set_sound_buffer(machine->device("custom"), 1);
30913081
30923082      // classic will fail RAM test and try to boot appletalk if RAM is not all zero
3093      memset(messram_get_ptr(machine->device("messram")), 0, messram_get_size(machine->device("messram")));
3083      memset(messram_get_ptr(m_ram), 0, messram_get_size(m_ram));
30943084   }
30953085
3096   scsi_interrupt = 0;
3086   m_scsi_interrupt = 0;
30973087   if (machine->device<cpu_device>("maincpu")->debug())
30983088   {
30993089      machine->device<cpu_device>("maincpu")->debug()->set_dasm_override(mac_dasm_override);
31003090   }
31013091
3102   mac->drive_select = 0;
3103   mac->scsiirq_enable = 0;
3104   mac->mac_via2_vbl = 0;
3105   mac->mac_se30_vbl_enable = 0;
3106   mac->mac_nubus_irq_state = 0xff;
3107   mac->keyboard_reply = 0;
3108   mac->kbd_comm = 0;
3109   mac->kbd_receive = 0;
3110   mac->kbd_shift_reg = 0;
3111   mac->kbd_shift_count = 0;
3112   mac->mouse_bit_x = mac->mouse_bit_y = 0;
3113   mac->rtc_rTCEnb = 0;
3114   mac->rtc_rTCClk = 0;
3115   mac->rtc_bit_count = 0;
3116   mac->rtc_data_dir = 0;
3117   mac->rtc_data_out = 0;
3118   mac->rtc_cmd = 0;
3119   mac->rtc_write_protect = 0;
3120   mac->rtc_state = 0;
3121   mac->pm_data_send = mac->pm_data_recv = mac->pm_ack = mac->pm_req = mac->pm_dptr = 0;
3122   mac->pm_state = 0;
3092   m_drive_select = 0;
3093   m_scsiirq_enable = 0;
3094   m_via2_vbl = 0;
3095   m_se30_vbl_enable = 0;
3096   m_nubus_irq_state = 0xff;
3097   m_keyboard_reply = 0;
3098   m_kbd_comm = 0;
3099   m_kbd_receive = 0;
3100   m_kbd_shift_reg = 0;
3101   m_kbd_shift_count = 0;
3102   m_mouse_bit_x = m_mouse_bit_y = 0;
3103   m_rtc_rTCEnb = 0;
3104   m_rtc_rTCClk = 0;
3105   m_rtc_bit_count = 0;
3106   m_rtc_data_dir = 0;
3107   m_rtc_data_out = 0;
3108   m_rtc_cmd = 0;
3109   m_rtc_write_protect = 0;
3110   m_rtc_state = 0;
3111   m_pm_data_send = m_pm_data_recv = m_pm_ack = m_pm_req = m_pm_dptr = 0;
3112   m_pm_state = 0;
31233113
3124   memset(mac->egregs, 0xff, sizeof(mac->egregs));
3114   memset(m_egregs, 0xff, sizeof(m_egregs));
31253115}
31263116
31273117
r9489r9490
31313121   int overlay;
31323122   mac_state *mac = machine->driver_data<mac_state>();
31333123
3134   overlay = mac->overlay;
3135   mac->overlay = -1;
3136   mac_set_memory_overlay(machine, overlay);
3124   overlay = mac->m_overlay;
3125   mac->m_overlay = -1;
3126   mac->set_memory_overlay(machine, overlay);
31373127}
31383128
31393129
r9489r9490
31413131{
31423132   mac_state *mac = machine->driver_data<mac_state>();
31433133
3144   if (mac->overlay != -1)
3134   if (mac->m_overlay != -1)
31453135   {
3146      if ((mac->model == MODEL_MAC_PORTABLE) || (mac->model == MODEL_MAC_PB100))
3136      if ((mac->m_model == MODEL_MAC_PORTABLE) || (mac->m_model == MODEL_MAC_PB100))
31473137      {
31483138         if ((address >= 0x900000) && (address <= 0x9fffff))
31493139         {
3150            mac_set_memory_overlay(machine, 0);      // kill the overlay
3140            mac->set_memory_overlay(machine, 0);      // kill the overlay
31513141         }
31523142      }
3153      else if ((mac->model == MODEL_MAC_SE) || (mac->model == MODEL_MAC_CLASSIC))
3143      else if ((mac->m_model == MODEL_MAC_SE) || (mac->m_model == MODEL_MAC_CLASSIC))
31543144      {
31553145         if ((address >= 0x400000) && (address <= 0x4fffff))
31563146         {
3157            mac_set_memory_overlay(machine, 0);      // kill the overlay
3147            mac->set_memory_overlay(machine, 0);      // kill the overlay
31583148         }
31593149      }
3160      else if ((mac->model == MODEL_MAC_LC) || (mac->model == MODEL_MAC_LC_II) || (mac->model == MODEL_MAC_CLASSIC_II))
3150      else if ((mac->m_model == MODEL_MAC_LC) || (mac->m_model == MODEL_MAC_LC_II) || (mac->m_model == MODEL_MAC_CLASSIC_II))
31613151      {
31623152         if ((address >= 0xa00000) && (address <= 0xafffff))
31633153         {
3164            mac_set_memory_overlay(machine, 0);      // kill the overlay
3154            mac->set_memory_overlay(machine, 0);      // kill the overlay
31653155         }
31663156      }
31673157      else
31683158      {
31693159         if ((address >= 0x40000000) && (address <= 0x4fffffff))
31703160         {
3171            mac_set_memory_overlay(machine, 0);      // kill the overlay
3161            mac->set_memory_overlay(machine, 0);      // kill the overlay
31723162         }
31733163      }
31743164   }
r9489r9490
31803170{
31813171   mac_state *mac = machine->driver_data<mac_state>();
31823172
3183   mac->overlay = 1;
3184   scsi_interrupt = 0;
3185   mac->model = model;
3173   mac->m_overlay = 1;
3174   mac->m_scsi_interrupt = 0;
3175   mac->m_model = model;
31863176
3187   if ((mac->model == MODEL_MAC_PORTABLE) || (mac->model == MODEL_MAC_PB100))
3177   if ((mac->m_model == MODEL_MAC_PORTABLE) || (mac->m_model == MODEL_MAC_PB100))
31883178   {
31893179   }
31903180   else if (model < MODEL_MAC_II)
31913181   {
31923182      /* set up RAM mirror at 0x600000-0x6fffff (0x7fffff ???) */
3193      mac_install_memory(machine, 0x600000, 0x6fffff, messram_get_size(machine->device("messram")), messram_get_ptr(machine->device("messram")), FALSE, "bank2");
3183      mac_install_memory(machine, 0x600000, 0x6fffff, messram_get_size(mac->m_ram), messram_get_ptr(mac->m_ram), FALSE, "bank2");
31943184
31953185      /* set up ROM at 0x400000-0x43ffff (-0x5fffff for mac 128k/512k/512ke) */
31963186      mac_install_memory(machine, 0x400000, (model >= MODEL_MAC_PLUS) ? 0x43ffff : 0x5fffff,
31973187         memory_region_length(machine, "bootrom"), memory_region(machine, "bootrom"), TRUE, "bank3");
31983188   }
31993189
3200   mac->overlay = -1;
3201   mac_set_memory_overlay(machine, 1);
3190   mac->m_overlay = -1;
3191   mac->set_memory_overlay(machine, 1);
32023192
3203   memset(messram_get_ptr(machine->device("messram")), 0, messram_get_size(machine->device("messram")));
3193   memset(messram_get_ptr(mac->m_ram), 0, messram_get_size(mac->m_ram));
32043194
32053195   if ((model == MODEL_MAC_SE) || (model == MODEL_MAC_CLASSIC) || (model == MODEL_MAC_CLASSIC_II) || (model == MODEL_MAC_LC) ||
3206       (model == MODEL_MAC_LC_II) || (model == MODEL_MAC_LC_III) || (model == MODEL_MAC_LC_III_PLUS) || ((mac->model >= MODEL_MAC_II) && (mac->model <= MODEL_MAC_SE30)) ||
3196       (model == MODEL_MAC_LC_II) || (model == MODEL_MAC_LC_III) || (model == MODEL_MAC_LC_III_PLUS) || ((mac->m_model >= MODEL_MAC_II) && (mac->m_model <= MODEL_MAC_SE30)) ||
32073197       (model == MODEL_MAC_PORTABLE) || (model == MODEL_MAC_PB100))
32083198   {
32093199      cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM)->set_direct_update_handler(direct_update_delegate_create_static(overlay_opbaseoverride, *machine));
r9489r9490
32123202   /* setup keyboard */
32133203   keyboard_init(mac);
32143204
3215   mac->inquiry_timeout = timer_alloc(machine, inquiry_timeout_func, NULL);
3205   mac->m_inquiry_timeout = timer_alloc(machine, inquiry_timeout_func, NULL);
32163206
32173207   /* save state stuff */
3218   state_save_register_global(machine, mac->overlay);
32193208   state_save_register_postload(machine, mac_state_load, NULL);
32203209}
32213210
r9489r9490
32743263   mac_driver_init(machine, MODEL_MAC_IIX);
32753264}
32763265
3277void mac_nubus_slot_interrupt(running_machine *machine, UINT8 slot, UINT32 state)
3266void mac_state::nubus_slot_interrupt(running_machine *machine, UINT8 slot, UINT32 state)
32783267{
32793268   UINT8 masks[6] = { 0x1, 0x2, 0x4, 0x8, 0x10, 0x20 };
32803269   mac_state *mac = machine->driver_data<mac_state>();
3281   via6522_device *via_1 = machine->device<via6522_device>("via6522_1");
32823270
32833271   slot -= 9;
32843272
32853273   if (state)
32863274   {
3287      mac->mac_nubus_irq_state &= ~masks[slot];
3275      mac->m_nubus_irq_state &= ~masks[slot];
32883276   }
32893277   else
32903278   {
3291      mac->mac_nubus_irq_state |= masks[slot];
3279      mac->m_nubus_irq_state |= masks[slot];
32923280   }
32933281
3294   if ((mac->mac_nubus_irq_state & 0x3f) != 0x3f)
3282   if ((mac->m_nubus_irq_state & 0x3f) != 0x3f)
32953283   {
32963284      // HACK: sometimes we miss an ack (possible misbehavior in the VIA?)
3297      if (via_1->read_ca1() == 0)
3285      if (m_via2->read_ca1() == 0)
32983286      {
3299         via_1->write_ca1(1);
3287         m_via2->write_ca1(1);
33003288      }
33013289
3302      via_1->write_ca1(0);
3290      m_via2->write_ca1(0);
33033291   }
33043292   else
33053293   {
3306      via_1->write_ca1(1);
3294      m_via2->write_ca1(1);
33073295   }
33083296}
33093297
3310static void mac_vblank_irq(running_machine *machine)
3298void mac_state::vblank_irq(running_machine *machine)
33113299{
33123300   static int irq_count = 0, ca1_data = 0, ca2_data = 0;
3313   via6522_device *via_0 = machine->device<via6522_device>("via6522_0");
3314   mac_state *mac = machine->driver_data<mac_state>();
33153301
33163302   /* handle ADB keyboard/mouse */
3317   if (has_adb(mac))
3303   if (has_adb())
33183304   {
33193305      adb_vblank(machine);
33203306   }
33213307
33223308   /* handle keyboard */
3323   if (mac->kbd_comm == TRUE)
3309   if (m_kbd_comm == TRUE)
33243310   {
33253311      int keycode = scan_keyboard(machine);
33263312
r9489r9490
33303316
33313317         logerror("keyboard enquiry successful, keycode %X\n", keycode);
33323318
3333         timer_reset(mac->inquiry_timeout, attotime_never);
3319         timer_reset(m_inquiry_timeout, attotime_never);
33343320         kbd_shift_out(machine, keycode);
33353321      }
33363322   }
33373323
33383324   /* signal VBlank on CA1 input on the VIA */
3339   if (mac->model < MODEL_MAC_II)
3325   if (m_model < MODEL_MAC_II)
33403326   {
33413327      ca1_data ^= 1;
3342      via_0->write_ca1(ca1_data);
3328      m_via1->write_ca1(ca1_data);
33433329   }
33443330
33453331   if (++irq_count == 60)
r9489r9490
33483334
33493335      ca2_data ^= 1;
33503336      /* signal 1 Hz irq on CA2 input on the VIA */
3351      via_0->write_ca2(ca2_data);
3337      m_via1->write_ca2(ca2_data);
33523338
3353      rtc_incticks(mac);
3339      rtc_incticks();
33543340   }
33553341
33563342   // handle SE/30 vblank IRQ
3357   if (mac->model == MODEL_MAC_SE30)
3343   if (m_model == MODEL_MAC_SE30)
33583344   {
3359      if (mac->mac_se30_vbl_enable)
3345      if (m_se30_vbl_enable)
33603346      {
3361         mac->mac_via2_vbl ^= 1;
3362         if (!mac->mac_via2_vbl)
3347         m_via2_vbl ^= 1;
3348         if (!m_via2_vbl)
33633349         {
3364            mac_nubus_slot_interrupt(machine, 0xe, 1);
3350            nubus_slot_interrupt(machine, 0xe, 1);
33653351         }
33663352      }
33673353   }
r9489r9490
33793365
33803366   scanline = machine->primary_screen->vpos();
33813367   if (scanline == MAC_V_VIS)
3382      mac_vblank_irq(machine);
3383
3368      mac->vblank_irq(machine);
3369   
33843370   /* check for mouse changes at 10 irqs per frame */
3385   if (mac->model <= MODEL_MAC_PLUS)
3371   if (mac->m_model <= MODEL_MAC_PLUS)
33863372   {
33873373      if (!(scanline % 10))
33883374         mouse_callback(machine);
src/mess/video/mac.c
r9489r9490
1010
1111***************************************************************************/
1212
13#define ADDRESS_MAP_MODERN
1314
1415#include "emu.h"
16#include "sound/asc.h"
1517#include "includes/mac.h"
1618#include "devices/messram.h"
1719
18UINT32 *mac_se30_vram;
1920static int screen_buffer;
2021
2122PALETTE_INIT( mac )
r9489r9490
7778   UINT16 word;
7879   UINT16 *line;
7980   int y, x, b;
81   mac_state *mac = screen->machine->driver_data<mac_state>();
8082
8183   video_base = screen_buffer ? 0x8000 : 0;
82   video_ram = (const UINT16 *) &mac_se30_vram[video_base/4];
84   video_ram = (const UINT16 *) &mac->m_se30_vram[video_base/4];
8385
8486   for (y = 0; y < MAC_V_VIS; y++)
8587   {
r9489r9490
107109    - 0xfsff603c is VBL disable: write 1 to disable, 0 to enable
108110*/
109111
110UINT32 *mac_cb264_vram;
111static UINT32 cb264_mode, cb264_vbl_disable, cb264_toggle;
112static UINT32 cb264_palette[256], cb264_colors[3], cb264_count, cb264_clutoffs;
113
114112VIDEO_START( mac_cb264 )
115113{
116   cb264_toggle = 0;
117   cb264_count = 0;
118   cb264_clutoffs = 0;
119   cb264_vbl_disable = 1;
120   cb264_mode = 0;
114   mac_state *mac = machine->driver_data<mac_state>();
115
116   mac->m_cb264_toggle = 0;
117   mac->m_cb264_count = 0;
118   mac->m_cb264_clutoffs = 0;
119   mac->m_cb264_vbl_disable = 1;
120   mac->m_cb264_mode = 0;
121121}
122122
123123// we do this here because VIDEO_UPDATE is called constantly when stepping in the debugger,
124124// which makes it hard to get accurate timings (or escape the VIA2 IRQ handler)
125125INTERRUPT_GEN( mac_cb264_vbl )
126126{
127   if (!cb264_vbl_disable)
127   mac_state *mac = device->machine->driver_data<mac_state>();
128
129   if (!mac->m_cb264_vbl_disable)
128130   {
129      mac_nubus_slot_interrupt(device->machine, 0xe, 1);
131      mac->nubus_slot_interrupt(device->machine, 0xe, 1);
130132   }
131133}
132134
r9489r9490
134136{
135137   UINT32 *scanline, *base;
136138   int x, y;
139   mac_state *mac = screen->machine->driver_data<mac_state>();
137140
138   switch (cb264_mode)
141   switch (mac->m_cb264_mode)
139142   {
140143      case 0: // 1 bpp
141144         {
142            UINT8 *vram8 = (UINT8 *)mac_cb264_vram;
145            UINT8 *vram8 = (UINT8 *)mac->m_cb264_vram;
143146            UINT8 pixels;
144147
145148            for (y = 0; y < 480; y++)
r9489r9490
149152               {
150153                  pixels = vram8[(y * 1024) + (BYTE4_XOR_BE(x))];
151154
152                  *scanline++ = cb264_palette[pixels&0x80];
153                  *scanline++ = cb264_palette[(pixels<<1)&0x80];
154                  *scanline++ = cb264_palette[(pixels<<2)&0x80];
155                  *scanline++ = cb264_palette[(pixels<<3)&0x80];
156                  *scanline++ = cb264_palette[(pixels<<4)&0x80];
157                  *scanline++ = cb264_palette[(pixels<<5)&0x80];
158                  *scanline++ = cb264_palette[(pixels<<6)&0x80];
159                  *scanline++ = cb264_palette[(pixels<<7)&0x80];
155                  *scanline++ = mac->m_cb264_palette[pixels&0x80];
156                  *scanline++ = mac->m_cb264_palette[(pixels<<1)&0x80];
157                  *scanline++ = mac->m_cb264_palette[(pixels<<2)&0x80];
158                  *scanline++ = mac->m_cb264_palette[(pixels<<3)&0x80];
159                  *scanline++ = mac->m_cb264_palette[(pixels<<4)&0x80];
160                  *scanline++ = mac->m_cb264_palette[(pixels<<5)&0x80];
161                  *scanline++ = mac->m_cb264_palette[(pixels<<6)&0x80];
162                  *scanline++ = mac->m_cb264_palette[(pixels<<7)&0x80];
160163               }
161164            }
162165         }
r9489r9490
164167
165168      case 1: // 2 bpp (3f/7f/bf/ff)
166169         {
167            UINT8 *vram8 = (UINT8 *)mac_cb264_vram;
170            UINT8 *vram8 = (UINT8 *)mac->m_cb264_vram;
168171            UINT8 pixels;
169172
170173            for (y = 0; y < 480; y++)
r9489r9490
174177               {
175178                  pixels = vram8[(y * 1024) + (BYTE4_XOR_BE(x))];
176179
177                  *scanline++ = cb264_palette[pixels&0xc0];
178                  *scanline++ = cb264_palette[(pixels<<2)&0xc0];
179                  *scanline++ = cb264_palette[(pixels<<4)&0xc0];
180                  *scanline++ = cb264_palette[(pixels<<6)&0xc0];
180                  *scanline++ = mac->m_cb264_palette[pixels&0xc0];
181                  *scanline++ = mac->m_cb264_palette[(pixels<<2)&0xc0];
182                  *scanline++ = mac->m_cb264_palette[(pixels<<4)&0xc0];
183                  *scanline++ = mac->m_cb264_palette[(pixels<<6)&0xc0];
181184               }
182185            }
183186         }
r9489r9490
185188
186189      case 2: // 4 bpp
187190         {
188            UINT8 *vram8 = (UINT8 *)mac_cb264_vram;
191            UINT8 *vram8 = (UINT8 *)mac->m_cb264_vram;
189192            UINT8 pixels;
190193
191194            for (y = 0; y < 480; y++)
r9489r9490
196199               {
197200                  pixels = vram8[(y * 1024) + (BYTE4_XOR_BE(x))];
198201
199                  *scanline++ = cb264_palette[pixels&0xf0];
200                  *scanline++ = cb264_palette[(pixels<<4)&0xf0];
202                  *scanline++ = mac->m_cb264_palette[pixels&0xf0];
203                  *scanline++ = mac->m_cb264_palette[(pixels<<4)&0xf0];
201204               }
202205            }         
203206         }
r9489r9490
205208
206209      case 3: // 8 bpp
207210         {
208            UINT8 *vram8 = (UINT8 *)mac_cb264_vram;
211            UINT8 *vram8 = (UINT8 *)mac->m_cb264_vram;
209212            UINT8 pixels;
210213
211214            for (y = 0; y < 480; y++)
r9489r9490
215218               for (x = 0; x < 640; x++)
216219               {
217220                  pixels = vram8[(y * 1024) + (BYTE4_XOR_BE(x))];
218                  *scanline++ = cb264_palette[pixels];
221                  *scanline++ = mac->m_cb264_palette[pixels];
219222               }
220223            }
221224         }
r9489r9490
226229         for (y = 0; y < 480; y++)
227230         {
228231            scanline = BITMAP_ADDR32(bitmap, y, 0);
229            base = &mac_cb264_vram[y * 1024];
232            base = &mac->m_cb264_vram[y * 1024];
230233            for (x = 0; x < 640; x++)
231234            {
232235               *scanline++ = *base++;
r9489r9490
235238         break;
236239
237240      default:
238         fatalerror("cb264: unknown video mode %d", cb264_mode);
241         fatalerror("cb264: unknown video mode %d", mac->m_cb264_mode);
239242         break;
240243
241244   }
r9489r9490
243246   return 0;
244247}
245248
246READ32_HANDLER( mac_cb264_r )
249READ32_MEMBER( mac_state::mac_cb264_r )
247250{
248251   switch (offset)
249252   {
r9489r9490
252255         break;
253256
254257      case 0x34/4:
255         cb264_toggle ^= 1;
256         return cb264_toggle;   // bit 0 is vblank?
258         m_cb264_toggle ^= 1;
259         return m_cb264_toggle;   // bit 0 is vblank?
257260
258261      default:
259         logerror("cb264_r: reg %x (mask %x PC %x)\n", offset*4, mem_mask, cpu_get_pc(space->cpu));
262         logerror("cb264_r: reg %x (mask %x PC %x)\n", offset*4, mem_mask, cpu_get_pc(space.cpu));
260263         break;
261264   }
262265
263266   return 0;
264267}
265268
266WRITE32_HANDLER( mac_cb264_w )
269WRITE32_MEMBER( mac_state::mac_cb264_w )
267270{
268271   switch (offset)
269272   {
270273      case 0x4/4:   // 0 = 1 bpp, 1 = 2bpp, 2 = 4bpp, 3 = 8bpp, 4 = 24bpp
271         cb264_mode = data;
274         m_cb264_mode = data;
272275         break;
273276
274277      case 0x14/4:   // VBL ack
275         mac_nubus_slot_interrupt(space->machine, 0xe, 0);
278         {
279            mac_state *mac = space.machine->driver_data<mac_state>();
280            mac->nubus_slot_interrupt(space.machine, 0xe, 0);
281         }
276282         break;
277283
278284      case 0x3c/4:   // VBL disable
279         cb264_vbl_disable = data;
285         m_cb264_vbl_disable = data;
280286         break;
281287
282288      default:
r9489r9490
285291   }
286292}
287293
288WRITE32_HANDLER( mac_cb264_ramdac_w )
294WRITE32_MEMBER( mac_state::mac_cb264_ramdac_w )
289295{
290296   switch (offset)
291297   {
292298      case 0:
293         cb264_clutoffs = data>>24;
294         cb264_count = 0;
299         m_cb264_clutoffs = data>>24;
300         m_cb264_count = 0;
295301         break;
296302
297303      case 1:
298         cb264_colors[cb264_count++] = data>>24;
304         m_cb264_colors[m_cb264_count++] = data>>24;
299305
300         if (cb264_count == 3)
306         if (m_cb264_count == 3)
301307         {
302            palette_set_color(space->machine, cb264_clutoffs, MAKE_RGB(cb264_colors[0], cb264_colors[1], cb264_colors[2]));
303            cb264_palette[cb264_clutoffs] = MAKE_RGB(cb264_colors[0], cb264_colors[1], cb264_colors[2]);
304            cb264_clutoffs++;
305            cb264_count = 0;
308            palette_set_color(space.machine, m_cb264_clutoffs, MAKE_RGB(m_cb264_colors[0], m_cb264_colors[1], m_cb264_colors[2]));
309            m_cb264_palette[m_cb264_clutoffs] = MAKE_RGB(m_cb264_colors[0], m_cb264_colors[1], m_cb264_colors[2]);
310            m_cb264_clutoffs++;
311            m_cb264_count = 0;
306312         }
307313         break;
308314
r9489r9490
325331   int htotal, vtotal;
326332   double framerate;
327333
328   memset(mac->rbv_regs, 0, sizeof(mac->rbv_regs));
334   memset(mac->m_rbv_regs, 0, sizeof(mac->m_rbv_regs));
329335
330   mac->rbv_count = 0;
331   mac->rbv_clutoffs = 0;
332   mac->rbv_immed10wr = 0;
336   mac->m_rbv_count = 0;
337   mac->m_rbv_clutoffs = 0;
338   mac->m_rbv_immed10wr = 0;
333339
334   mac->rbv_regs[2] = 0xff;
340   mac->m_rbv_regs[2] = 0xff;
335341
336   mac->rbv_type = RBV_TYPE_RBV;
342   mac->m_rbv_type = RBV_TYPE_RBV;
337343
338344   visarea.min_x = 0;
339345   visarea.min_y = 0;
340346
341   if (mac->model == MODEL_MAC_CLASSIC_II)
347   if (mac->m_model == MODEL_MAC_CLASSIC_II)
342348   {
343      mac->rbv_montype = 32;
349      mac->m_rbv_montype = 32;
344350      visarea.max_x = MAC_H_VIS-1;
345351      visarea.max_y = MAC_V_VIS-1;
346352           htotal = MAC_H_TOTAL;
r9489r9490
349355   }
350356   else
351357   {
352      mac->rbv_montype = input_port_read_safe(machine, "MONTYPE", 2);
353      switch (mac->rbv_montype)
358      mac->m_rbv_montype = input_port_read_safe(machine, "MONTYPE", 2);
359      switch (mac->m_rbv_montype)
354360      {
355361         case 1:   // 15" portrait display
356362            visarea.max_x = 640-1;
r9489r9490
387393{
388394   mac_state *mac = machine->driver_data<mac_state>();
389395
390   memset(mac->rbv_regs, 0, sizeof(mac->rbv_regs));
396   memset(mac->m_rbv_regs, 0, sizeof(mac->m_rbv_regs));
391397
392   mac->rbv_count = 0;
393   mac->rbv_clutoffs = 0;
394   mac->rbv_immed10wr = 0;
398   mac->m_rbv_count = 0;
399   mac->m_rbv_clutoffs = 0;
400   mac->m_rbv_immed10wr = 0;
395401
396   mac->rbv_regs[2] = 0xff;
397   mac->rbv_regs[4] = 0x6;
398   mac->rbv_regs[5] = 0x3;
402   mac->m_rbv_regs[2] = 0xff;
403   mac->m_rbv_regs[4] = 0x6;
404   mac->m_rbv_regs[5] = 0x3;
399405
400   mac->sonora_vctl[0] = 0x9f;
401   mac->sonora_vctl[1] = 0;
402   mac->sonora_vctl[2] = 0;
406   mac->m_sonora_vctl[0] = 0x9f;
407   mac->m_sonora_vctl[1] = 0;
408   mac->m_sonora_vctl[2] = 0;
403409
404   mac->rbv_type = RBV_TYPE_SONORA;
410   mac->m_rbv_type = RBV_TYPE_SONORA;
405411}
406412
407413VIDEO_START( macv8 )
408414{
409415   mac_state *mac = machine->driver_data<mac_state>();
410416
411   memset(mac->rbv_regs, 0, sizeof(mac->rbv_regs));
417   memset(mac->m_rbv_regs, 0, sizeof(mac->m_rbv_regs));
412418
413   mac->rbv_count = 0;
414   mac->rbv_clutoffs = 0;
415   mac->rbv_immed10wr = 0;
419   mac->m_rbv_count = 0;
420   mac->m_rbv_clutoffs = 0;
421   mac->m_rbv_immed10wr = 0;
416422
417   mac->rbv_regs[0] = 0x4f;
418   mac->rbv_regs[1] = 0x06;
419   mac->rbv_regs[2] = 0xff;
423   mac->m_rbv_regs[0] = 0x4f;
424   mac->m_rbv_regs[1] = 0x06;
425   mac->m_rbv_regs[2] = 0xff;
420426
421   mac->rbv_type = RBV_TYPE_V8;
427   mac->m_rbv_type = RBV_TYPE_V8;
422428}
423429
424430VIDEO_UPDATE( macrbv )
r9489r9490
427433   int x, y, hres, vres;
428434   mac_state *mac = screen->machine->driver_data<mac_state>();
429435
430   switch (mac->rbv_montype)
436   switch (mac->m_rbv_montype)
431437   {
432438      case 32: // classic II built-in display
433439         hres = MAC_H_VIS;
r9489r9490
451457         break;
452458   }
453459
454   switch (mac->rbv_regs[0x10] & 7)
460   switch (mac->m_rbv_regs[0x10] & 7)
455461   {
456462      case 0:   // 1bpp
457463      {
r9489r9490
465471            {
466472               pixels = vram8[(y * (hres/8)) + ((x/8)^3)];
467473
468               *scanline++ = mac->rbv_palette[0xfe|(pixels>>7)];
469               *scanline++ = mac->rbv_palette[0xfe|((pixels>>6)&1)];
470               *scanline++ = mac->rbv_palette[0xfe|((pixels>>5)&1)];
471               *scanline++ = mac->rbv_palette[0xfe|((pixels>>4)&1)];
472               *scanline++ = mac->rbv_palette[0xfe|((pixels>>3)&1)];
473               *scanline++ = mac->rbv_palette[0xfe|((pixels>>2)&1)];
474               *scanline++ = mac->rbv_palette[0xfe|((pixels>>1)&1)];
475               *scanline++ = mac->rbv_palette[0xfe|(pixels&1)];
474               *scanline++ = mac->m_rbv_palette[0xfe|(pixels>>7)];
475               *scanline++ = mac->m_rbv_palette[0xfe|((pixels>>6)&1)];
476               *scanline++ = mac->m_rbv_palette[0xfe|((pixels>>5)&1)];
477               *scanline++ = mac->m_rbv_palette[0xfe|((pixels>>4)&1)];
478               *scanline++ = mac->m_rbv_palette[0xfe|((pixels>>3)&1)];
479               *scanline++ = mac->m_rbv_palette[0xfe|((pixels>>2)&1)];
480               *scanline++ = mac->m_rbv_palette[0xfe|((pixels>>1)&1)];
481               *scanline++ = mac->m_rbv_palette[0xfe|(pixels&1)];
476482            }
477483         }
478484      }
r9489r9490
490496            {
491497               pixels = vram8[(y * (hres/4)) + (BYTE4_XOR_BE(x))];
492498
493               *scanline++ = mac->rbv_palette[0xfc|((pixels>>6)&3)];
494               *scanline++ = mac->rbv_palette[0xfc|((pixels>>4)&3)];
495               *scanline++ = mac->rbv_palette[0xfc|((pixels>>2)&3)];
496               *scanline++ = mac->rbv_palette[0xfc|(pixels&3)];
499               *scanline++ = mac->m_rbv_palette[0xfc|((pixels>>6)&3)];
500               *scanline++ = mac->m_rbv_palette[0xfc|((pixels>>4)&3)];
501               *scanline++ = mac->m_rbv_palette[0xfc|((pixels>>2)&3)];
502               *scanline++ = mac->m_rbv_palette[0xfc|(pixels&3)];
497503            }
498504         }
499505      }
r9489r9490
512518            {
513519               pixels = vram8[(y * (hres/2)) + (BYTE4_XOR_BE(x))];
514520
515               *scanline++ = mac->rbv_palette[0xf0|(pixels>>4)];
516               *scanline++ = mac->rbv_palette[0xf0|(pixels&0xf)];
521               *scanline++ = mac->m_rbv_palette[0xf0|(pixels>>4)];
522               *scanline++ = mac->m_rbv_palette[0xf0|(pixels&0xf)];
517523            }
518524         }
519525      }
r9489r9490
531537            for (x = 0; x < hres; x++)
532538            {
533539               pixels = vram8[(y * hres) + (BYTE4_XOR_BE(x))];
534               *scanline++ = mac->rbv_palette[pixels];
540               *scanline++ = mac->m_rbv_palette[pixels];
535541            }
536542         }
537543      }
r9489r9490
547553   mac_state *mac = screen->machine->driver_data<mac_state>();
548554   UINT8 mode = 0;
549555
550   switch (mac->rbv_type)
556   switch (mac->m_rbv_type)
551557   {
552558      case RBV_TYPE_RBV:
553559      case RBV_TYPE_V8:
554         mode = mac->rbv_regs[0x10] & 7;
560         mode = mac->m_rbv_regs[0x10] & 7;
555561         break;
556562
557563      case RBV_TYPE_SONORA:
558         mode = mac->sonora_vctl[1] & 7;
564         mode = mac->m_sonora_vctl[1] & 7;
559565
560566         // forced blank?
561         if (mac->sonora_vctl[0] & 0x80)
567         if (mac->m_sonora_vctl[0] & 0x80)
562568         {
563569            return 0;
564570         }
r9489r9490
569575   {
570576      case 0:   // 1bpp
571577      {
572         UINT8 *vram8 = (UINT8 *)mac->rbv_vram;
578         UINT8 *vram8 = (UINT8 *)mac->m_rbv_vram;
573579         UINT8 pixels;
574580
575581         for (y = 0; y < 480; y++)
r9489r9490
579585            {
580586               pixels = vram8[(y * 80) + ((x/8)^3)];
581587
582               *scanline++ = mac->rbv_palette[0xfe|(pixels>>7)];
583               *scanline++ = mac->rbv_palette[0xfe|((pixels>>6)&1)];
584               *scanline++ = mac->rbv_palette[0xfe|((pixels>>5)&1)];
585               *scanline++ = mac->rbv_palette[0xfe|((pixels>>4)&1)];
586               *scanline++ = mac->rbv_palette[0xfe|((pixels>>3)&1)];
587               *scanline++ = mac->rbv_palette[0xfe|((pixels>>2)&1)];
588               *scanline++ = mac->rbv_palette[0xfe|((pixels>>1)&1)];
589               *scanline++ = mac->rbv_palette[0xfe|(pixels&1)];
588               *scanline++ = mac->m_rbv_palette[0xfe|(pixels>>7)];
589               *scanline++ = mac->m_rbv_palette[0xfe|((pixels>>6)&1)];
590               *scanline++ = mac->m_rbv_palette[0xfe|((pixels>>5)&1)];
591               *scanline++ = mac->m_rbv_palette[0xfe|((pixels>>4)&1)];
592               *scanline++ = mac->m_rbv_palette[0xfe|((pixels>>3)&1)];
593               *scanline++ = mac->m_rbv_palette[0xfe|((pixels>>2)&1)];
594               *scanline++ = mac->m_rbv_palette[0xfe|((pixels>>1)&1)];
595               *scanline++ = mac->m_rbv_palette[0xfe|(pixels&1)];
590596            }
591597         }
592598      }
r9489r9490
594600
595601      case 1:   // 2bpp
596602      {
597         UINT8 *vram8 = (UINT8 *)mac->rbv_vram;
603         UINT8 *vram8 = (UINT8 *)mac->m_rbv_vram;
598604         UINT8 pixels;
599605
600606         for (y = 0; y < 480; y++)
r9489r9490
604610            {
605611               pixels = vram8[(y * 160) + (BYTE4_XOR_BE(x))];
606612
607               *scanline++ = mac->rbv_palette[0xfc|((pixels>>6)&3)];
608               *scanline++ = mac->rbv_palette[0xfc|((pixels>>4)&3)];
609               *scanline++ = mac->rbv_palette[0xfc|((pixels>>2)&3)];
610               *scanline++ = mac->rbv_palette[0xfc|(pixels&3)];
613               *scanline++ = mac->m_rbv_palette[0xfc|((pixels>>6)&3)];
614               *scanline++ = mac->m_rbv_palette[0xfc|((pixels>>4)&3)];
615               *scanline++ = mac->m_rbv_palette[0xfc|((pixels>>2)&3)];
616               *scanline++ = mac->m_rbv_palette[0xfc|(pixels&3)];
611617            }
612618         }
613619      }
r9489r9490
615621
616622      case 2: // 4bpp
617623      {
618         UINT8 *vram8 = (UINT8 *)mac->rbv_vram;
624         UINT8 *vram8 = (UINT8 *)mac->m_rbv_vram;
619625         UINT8 pixels;
620626
621627         for (y = 0; y < 480; y++)
r9489r9490
626632            {
627633               pixels = vram8[(y * 320) + (BYTE4_XOR_BE(x))];
628634
629               *scanline++ = mac->rbv_palette[0xf0|(pixels>>4)];
630               *scanline++ = mac->rbv_palette[0xf0|(pixels&0xf)];
635               *scanline++ = mac->m_rbv_palette[0xf0|(pixels>>4)];
636               *scanline++ = mac->m_rbv_palette[0xf0|(pixels&0xf)];
631637            }
632638         }
633639      }
r9489r9490
635641
636642      case 3: // 8bpp
637643      {
638         UINT8 *vram8 = (UINT8 *)mac->rbv_vram;
644         UINT8 *vram8 = (UINT8 *)mac->m_rbv_vram;
639645         UINT8 pixels;
640646         
641647         for (y = 0; y < 480; y++)
r9489r9490
645651            for (x = 0; x < 640; x++)
646652            {
647653               pixels = vram8[(y * 640) + (BYTE4_XOR_BE(x))];
648               *scanline++ = mac->rbv_palette[pixels];
654               *scanline++ = mac->m_rbv_palette[pixels];
649655            }
650656         }
651657      }
src/mess/includes/mac.h
r9489r9490
110110extern const via6522_interface mac_via6522_2_intf;
111111extern const via6522_interface mac_via6522_adb_intf;
112112
113void mac_scc_irq(running_device *device, int status);
114void mac_scsi_irq(running_machine *machine, int state);
115void mac_asc_irq(running_device *device, int state);
116void mac_fdc_set_enable_lines(running_device *device, int enable_mask);
117
113118MACHINE_START( macscsi );
114119MACHINE_START( mac );
115120MACHINE_RESET( mac );
r9489r9490
135140DRIVER_INIT(macprtb);
136141DRIVER_INIT(macpb100);
137142
138READ16_HANDLER ( mac_via_r );
139WRITE16_HANDLER ( mac_via_w );
140READ16_HANDLER ( mac_via2_r );
141WRITE16_HANDLER ( mac_via2_w );
142READ16_HANDLER ( mac_autovector_r );
143WRITE16_HANDLER ( mac_autovector_w );
144READ16_HANDLER ( mac_iwm_r );
145WRITE16_HANDLER ( mac_iwm_w );
146READ16_HANDLER ( mac_scc_r );
147WRITE16_HANDLER ( mac_scc_w );
148WRITE16_HANDLER ( mac_scc_2_w );
149READ16_HANDLER ( macplus_scsi_r );
150WRITE16_HANDLER ( macplus_scsi_w );
151WRITE16_HANDLER ( macii_scsi_w );
152READ32_HANDLER (macii_scsi_drq_r);
153WRITE32_HANDLER (macii_scsi_drq_w);
154143NVRAM_HANDLER( mac );
155void mac_scc_irq(running_device *device, int status);
156void mac_scc_mouse_irq( running_machine *machine, int x, int y );
157void mac_fdc_set_enable_lines(running_device *device, int enable_mask);
158144
159void mac_nubus_slot_interrupt(running_machine *machine, UINT8 slot, UINT32 state);
160
161void mac_scsi_irq(running_machine *machine, int state);
162
163void mac_asc_irq(running_device *device, int state);
164
165void mac_set_via2_interrupt(running_machine *machine, int value);
166
167145/*----------- defined in video/mac.c -----------*/
168146
169extern UINT32 *mac_se30_vram;
170
171147VIDEO_START( mac );
172148VIDEO_UPDATE( mac );
173149VIDEO_UPDATE( macse30 );
r9489r9490
182158
183159void mac_set_screen_buffer( int buffer );
184160
185extern UINT32 *mac_cb264_vram;
186161VIDEO_START( mac_cb264 );
187162VIDEO_UPDATE( mac_cb264 );
188READ32_HANDLER( mac_cb264_r );
189WRITE32_HANDLER( mac_cb264_w );
190WRITE32_HANDLER( mac_cb264_ramdac_w );
191163INTERRUPT_GEN( mac_cb264_vbl );
192164
193165/*----------- defined in audio/mac.c -----------*/
r9489r9490
206178{
207179public:
208180   mac_state(running_machine &machine, const driver_device_config_base &config)
209      : driver_device(machine, config) { }
181      : driver_device(machine, config),
182      m_maincpu(*this, "maincpu"),
183      m_via1(*this, "via6522_0"),
184      m_via2(*this, "via6522_1"),
185      m_asc(*this, "asc"),
186      m_ram(*this, "messram")
187    { }
210188
211   model_t model;
189   required_device<cpu_device> m_maincpu;
190   required_device<via6522_device> m_via1;
191   optional_device<via6522_device> m_via2;
192   optional_device<asc_device> m_asc;
193   required_device<running_device> m_ram;
212194
213   UINT32 overlay;
214   int drive_select;
215   int scsiirq_enable;
195   virtual void machine_start();
196   virtual void machine_reset();
216197
217   UINT32 mac_via2_vbl;
218   UINT32 mac_se30_vbl_enable;
219   UINT8 mac_nubus_irq_state;
198   model_t m_model;
220199
200   UINT32 m_overlay;
201   int m_drive_select;
202   int m_scsiirq_enable;
203
204   UINT32 m_via2_vbl;
205   UINT32 m_se30_vbl_enable;
206   UINT8 m_nubus_irq_state;
207
221208   /* used to store the reply to most keyboard commands */
222   int keyboard_reply;
209   int m_keyboard_reply;
223210
224211   /* Keyboard communication in progress? */
225   int kbd_comm;
226   int kbd_receive;
212   int m_kbd_comm;
213   int m_kbd_receive;
227214   /* timer which is used to time out inquiry */
228   emu_timer *inquiry_timeout;
215   emu_timer *m_inquiry_timeout;
229216
230   int kbd_shift_reg;
231   int kbd_shift_count;
217   int m_kbd_shift_reg;
218   int m_kbd_shift_count;
232219
233220   /* keyboard matrix to detect transition */
234   int key_matrix[7];
221   int m_key_matrix[7];
235222
236223   /* keycode buffer (used for keypad/arrow key transition) */
237   int keycode_buf[2];
238   int keycode_buf_index;
224   int m_keycode_buf[2];
225   int m_keycode_buf_index;
239226
240   int mouse_bit_x;
241   int mouse_bit_y;
227   int m_mouse_bit_x;
228   int m_mouse_bit_y;
242229
243230
244231   /* state of rTCEnb and rTCClk lines */
245   UINT8 rtc_rTCEnb;
246   UINT8 rtc_rTCClk;
232   UINT8 m_rtc_rTCEnb;
233   UINT8 m_rtc_rTCClk;
247234
248235   /* serial transmit/receive register : bits are shifted in/out of this byte */
249   UINT8 rtc_data_byte;
236   UINT8 m_rtc_data_byte;
250237   /* serial transmitted/received bit count */
251   UINT8 rtc_bit_count;
238   UINT8 m_rtc_bit_count;
252239   /* direction of the current transfer (0 : VIA->RTC, 1 : RTC->VIA) */
253   UINT8 rtc_data_dir;
240   UINT8 m_rtc_data_dir;
254241   /* when rtc_data_dir == 1, state of rTCData as set by RTC (-> data bit seen by VIA) */
255   UINT8 rtc_data_out;
242   UINT8 m_rtc_data_out;
256243
257244   /* set to 1 when command in progress */
258   UINT8 rtc_cmd;
245   UINT8 m_rtc_cmd;
259246
260247   /* write protect flag */
261   UINT8 rtc_write_protect;
248   UINT8 m_rtc_write_protect;
262249
263250   /* internal seconds register */
264   UINT8 rtc_seconds[/*8*/4];
251   UINT8 m_rtc_seconds[/*8*/4];
265252   /* 20-byte long PRAM, or 256-byte long XPRAM */
266   UINT8 rtc_ram[256];
253   UINT8 m_rtc_ram[256];
267254   /* current extended address and RTC state */
268   UINT8 rtc_xpaddr;
269   UINT8 rtc_state;
255   UINT8 m_rtc_xpaddr;
256   UINT8 m_rtc_state;
270257
271258   // Mac ADB state
272   INT32 adb_irq_pending, adb_waiting_cmd, adb_datasize, adb_buffer[257];
273   INT32 adb_state, adb_command, adb_send, adb_timer_ticks, adb_extclock, adb_direction;
274   INT32 adb_listenreg, adb_listenaddr, adb_last_talk, adb_srq_switch;
275   INT32 adb_streaming, adb_stream_ptr;
259   INT32 m_adb_irq_pending, m_adb_waiting_cmd, m_adb_datasize, m_adb_buffer[257];
260   INT32 m_adb_state, m_adb_command, m_adb_send, m_adb_timer_ticks, m_adb_extclock, m_adb_direction;
261   INT32 m_adb_listenreg, m_adb_listenaddr, m_adb_last_talk, m_adb_srq_switch;
262   INT32 m_adb_streaming, m_adb_stream_ptr;
276263
277264   // Portable/PB100 Power Manager IC comms (chapter 4, "Guide to the Macintosh Family Hardware", second edition)
278   UINT8 pm_data_send, pm_data_recv, pm_ack, pm_req, pm_cmd[32], pm_out[32], pm_dptr, pm_sptr, pm_slen, pm_state;
279   emu_timer *pmu_send_timer;
265   UINT8 m_pm_data_send, m_pm_data_recv, m_pm_ack, m_pm_req, m_pm_cmd[32], m_pm_out[32], m_pm_dptr, m_pm_sptr, m_pm_slen, m_pm_state;
266   emu_timer *m_pmu_send_timer;
280267
281268   // 60.15 Hz timer for RBV/V8/Sonora/Eagle/VASP/etc.
282   emu_timer *mac6015_timer;
269   emu_timer *m_6015_timer;
283270
284271   // RBV and friends (V8, etc)
285   UINT8 rbv_regs[256], rbv_ier, rbv_ifr, rbv_type, rbv_montype;
286   UINT32 rbv_colors[3], rbv_count, rbv_clutoffs, rbv_immed10wr;
287   UINT32 rbv_palette[256];
288   UINT32 *rbv_vram;
289   UINT8 sonora_vctl[4];
272   UINT8 m_rbv_regs[256], m_rbv_ier, m_rbv_ifr, m_rbv_type, m_rbv_montype;
273   UINT32 m_rbv_colors[3], m_rbv_count, m_rbv_clutoffs, m_rbv_immed10wr;
274   UINT32 m_rbv_palette[256];
275   UINT32 *m_rbv_vram;
276   UINT8 m_sonora_vctl[4];
290277
278   UINT32 *m_se30_vram, *m_cb264_vram;
279
280   UINT32 m_cb264_mode, m_cb264_vbl_disable, m_cb264_toggle;
281   UINT32 m_cb264_palette[256], m_cb264_colors[3], m_cb264_count, m_cb264_clutoffs;
282
291283   // Egret/Caboose/Cuda stuff
292   UINT8 egregs[0x20];
284   UINT8 m_egregs[0x20];
285
286   // interrupts
287   int m_scc_interrupt, m_via_interrupt, m_via2_interrupt, m_scsi_interrupt, m_last_taken_interrupt;
288
289   // defined in machine/mac.c
290   void v8_resize(running_machine *machine);
291   void set_memory_overlay(running_machine *machine, int overlay);
292   void scc_mouse_irq( running_machine *machine, int x, int y );
293   void nubus_slot_interrupt(running_machine *machine, UINT8 slot, UINT32 state);
294   void set_scc_interrupt(running_machine *machine, int value);
295   void set_via_interrupt(running_machine *machine, int value);
296   void set_via2_interrupt(running_machine *machine, int value);
297   void field_interrupts(running_machine *machine);
298   void rtc_write_rTCEnb(int data);
299   void rtc_shift_data(int data);
300   void vblank_irq(running_machine *machine);
301   void rtc_incticks();
302
303   DECLARE_READ16_MEMBER ( mac_via_r );
304   DECLARE_WRITE16_MEMBER ( mac_via_w );
305   DECLARE_READ16_MEMBER ( mac_via2_r );
306   DECLARE_WRITE16_MEMBER ( mac_via2_w );
307   DECLARE_READ16_MEMBER ( mac_autovector_r );
308   DECLARE_WRITE16_MEMBER ( mac_autovector_w );
309   DECLARE_READ16_MEMBER ( mac_iwm_r );
310   DECLARE_WRITE16_MEMBER ( mac_iwm_w );
311   DECLARE_READ16_MEMBER ( mac_scc_r );
312   DECLARE_WRITE16_MEMBER ( mac_scc_w );
313   DECLARE_WRITE16_MEMBER ( mac_scc_2_w );
314   DECLARE_READ16_MEMBER ( macplus_scsi_r );
315   DECLARE_WRITE16_MEMBER ( macplus_scsi_w );
316   DECLARE_WRITE16_MEMBER ( macii_scsi_w );
317   DECLARE_READ32_MEMBER (macii_scsi_drq_r);
318   DECLARE_WRITE32_MEMBER (macii_scsi_drq_w);
319
320   DECLARE_READ32_MEMBER( rbv_ramdac_r );
321   DECLARE_WRITE32_MEMBER( rbv_ramdac_w );
322   DECLARE_READ8_MEMBER( mac_sonora_vctl_r );
323   DECLARE_WRITE8_MEMBER( mac_sonora_vctl_w );
324   DECLARE_READ8_MEMBER ( mac_rbv_r );
325   DECLARE_WRITE8_MEMBER ( mac_rbv_w );
326
327   DECLARE_READ32_MEMBER(mac_read_id);
328
329   DECLARE_READ16_MEMBER(mac_config_r);
330
331   DECLARE_READ32_MEMBER( mac_cb264_r );
332   DECLARE_WRITE32_MEMBER( mac_cb264_w );
333   DECLARE_WRITE32_MEMBER( mac_cb264_ramdac_w );
334
335private:
336   int has_adb();
337   void rtc_init();
338   void rtc_execute_cmd(int data);
339   void adb_reset(running_machine *machine);
340   void adb_vblank(running_machine *machine);
293341};
294342
295// defined in machine/mac.c
296void mac_v8_resize(running_machine *machine, mac_state *mac);
297void mac_set_memory_overlay(running_machine *machine, int overlay);
298
299343#endif /* MAC_H_ */
300344
301345
src/mess/drivers/mac.c
r9489r9490
3636
3737****************************************************************************/
3838
39#define ADDRESS_MAP_MODERN
40
3941#include "emu.h"
4042#include "cpu/m68000/m68000.h"
4143#include "cpu/powerpc/ppc.h"
4244#include "cpu/m6805/m6805.h"
43#include "includes/mac.h"
4445#include "machine/6522via.h"
4546#include "machine/ncr5380.h"
4647#include "machine/applefdc.h"
r9489r9490
5152#include "devices/chd_cd.h"
5253#include "sound/asc.h"
5354#include "sound/cdda.h"
55#include "includes/mac.h"
5456
5557#define C7M   (7833600)
5658#define C15M   (C7M*2)
5759#define C32M   (C15M*2)
5860
59// ASC trampolines
60static READ8_HANDLER(mac_asc_r)
61{
62   return space->machine->device<asc_device>("asc")->read(offset);
63}
64
65static WRITE8_HANDLER(mac_asc_w)
66{
67   space->machine->device<asc_device>("asc")->write(offset, data);
68}
69
7061// do this here - VIDEO_UPDATE is called each scanline when stepping in the
7162// debugger, which means you can't escape the VIA2 IRQ handler
7263//
r9489r9490
8071{
8172   mac_state *mac = device->machine->driver_data<mac_state>();
8273
83   mac->rbv_regs[2] &= ~0x40;   // set vblank signal
74   mac->m_rbv_regs[2] &= ~0x40;   // set vblank signal
8475
85   if ((mac->rbv_regs[0x12] & 0x40) && (mac->rbv_ier & 0x2))   
76   if ((mac->m_rbv_regs[0x12] & 0x40) && (mac->m_rbv_ier & 0x2))   
8677   {
87      mac->rbv_ifr |= 0x82;
88      mac_set_via2_interrupt(device->machine, 1);
78      mac->m_rbv_ifr |= 0x82;
79      mac->set_via2_interrupt(device->machine, 1);
8980   }
9081}
9182
92static READ32_HANDLER( rbv_ramdac_r )
83READ32_MEMBER( mac_state::rbv_ramdac_r )
9384{
9485   return 0;
9586}
9687
97static WRITE32_HANDLER( rbv_ramdac_w )
88WRITE32_MEMBER( mac_state::rbv_ramdac_w )
9889{
99   mac_state *mac = space->machine->driver_data<mac_state>();
100
10190   if (!offset)
10291   {
103      mac->rbv_clutoffs = data>>24;
104      mac->rbv_count = 0;
92      m_rbv_clutoffs = data>>24;
93      m_rbv_count = 0;
10594   }
10695   else
10796   {
108      mac->rbv_colors[mac->rbv_count++] = data>>24;
97      m_rbv_colors[m_rbv_count++] = data>>24;
10998
110      if (mac->rbv_count == 3)
99      if (m_rbv_count == 3)
111100      {
112101         // for portrait display, force monochrome by using the blue channel
113         if (mac->model != MODEL_MAC_CLASSIC_II)
102         if (m_model != MODEL_MAC_CLASSIC_II)
114103         {
115104            // Color Classic has no MONTYPE so the safe read gets us 512x384, which is right
116            if (input_port_read_safe(space->machine, "MONTYPE", 2) == 1)
105            if (input_port_read_safe(space.machine, "MONTYPE", 2) == 1)
117106            {
118               palette_set_color(space->machine, mac->rbv_clutoffs, MAKE_RGB(mac->rbv_colors[2], mac->rbv_colors[2], mac->rbv_colors[2]));
119               mac->rbv_palette[mac->rbv_clutoffs] = MAKE_RGB(mac->rbv_colors[2], mac->rbv_colors[2], mac->rbv_colors[2]);
120               mac->rbv_clutoffs++;
121               mac->rbv_count = 0;
107               palette_set_color(space.machine, m_rbv_clutoffs, MAKE_RGB(m_rbv_colors[2], m_rbv_colors[2], m_rbv_colors[2]));
108               m_rbv_palette[m_rbv_clutoffs] = MAKE_RGB(m_rbv_colors[2], m_rbv_colors[2], m_rbv_colors[2]);
109               m_rbv_clutoffs++;
110               m_rbv_count = 0;
122111            }
123112            else
124113            {
125               palette_set_color(space->machine, mac->rbv_clutoffs, MAKE_RGB(mac->rbv_colors[0], mac->rbv_colors[1], mac->rbv_colors[2]));
126               mac->rbv_palette[mac->rbv_clutoffs] = MAKE_RGB(mac->rbv_colors[0], mac->rbv_colors[1], mac->rbv_colors[2]);
127               mac->rbv_clutoffs++;
128               mac->rbv_count = 0;
114               palette_set_color(space.machine, m_rbv_clutoffs, MAKE_RGB(m_rbv_colors[0], m_rbv_colors[1], m_rbv_colors[2]));
115               m_rbv_palette[m_rbv_clutoffs] = MAKE_RGB(m_rbv_colors[0], m_rbv_colors[1], m_rbv_colors[2]);
116               m_rbv_clutoffs++;
117               m_rbv_count = 0;
129118            }
130119         }
131120      }
132121   }
133122}
134123
135static READ8_HANDLER( mac_sonora_vctl_r )
124READ8_MEMBER( mac_state::mac_sonora_vctl_r )
136125{
137   mac_state *mac = space->machine->driver_data<mac_state>();
138
139126   if (offset == 2)
140127   {
141128      return (6 << 4);   // 640x480 RGB monitor
142129   }
143130
144   return mac->sonora_vctl[offset];
131   return m_sonora_vctl[offset];
145132}
146133
147static WRITE8_HANDLER( mac_sonora_vctl_w )
134WRITE8_MEMBER( mac_state::mac_sonora_vctl_w )
148135{
149   mac_state *mac = space->machine->driver_data<mac_state>();
150
151   mac->sonora_vctl[offset] = data;   
136   m_sonora_vctl[offset] = data;   
152137}
153138
154static READ8_HANDLER ( mac_rbv_r )
139READ8_MEMBER ( mac_state::mac_rbv_r )
155140{
156141   int data = 0;
157   mac_state *mac = space->machine->driver_data<mac_state>();
158142   
159143   if (offset < 0x100)
160144   {   
161      data = mac->rbv_regs[offset];
145      data = m_rbv_regs[offset];
162146
163147      if (offset == 0x02)
164148      {
165         if (!space->machine->primary_screen->vblank())
149         if (!space.machine->primary_screen->vblank())
166150         {
167151            data |= 0x40;
168152         }
r9489r9490
170154
171155      if (offset == 0x10)
172156      {
173         if (!mac->rbv_immed10wr)
157         if (!m_rbv_immed10wr)
174158         {
175159            data &= ~0x38;
176            data |= (input_port_read_safe(space->machine, "MONTYPE", 2)<<3);
160            data |= (input_port_read_safe(space.machine, "MONTYPE", 2)<<3);
177161         }
178162         else
179163         {
180            mac->rbv_immed10wr = 0;
164            m_rbv_immed10wr = 0;
181165         }
182166      }
183167
r9489r9490
194178      switch (offset)
195179      {
196180         case 13:   // IFR
197//            printf("Read IER = %02x (PC=%x)\n", mac->rbv_ier, cpu_get_pc(space->cpu));
198            return mac->rbv_ifr;
181//            printf("Read IER = %02x (PC=%x)\n", m_rbv_ier, cpu_get_pc(space.cpu));
182            return m_rbv_ifr;
199183            break;
200184
201185         case 14:   // IER
202//            printf("Read IFR = %02x (PC=%x)\n", mac->rbv_ifr, cpu_get_pc(space->cpu));
203            return mac->rbv_ier;
186//            printf("Read IFR = %02x (PC=%x)\n", m_rbv_ifr, cpu_get_pc(space.cpu));
187            return m_rbv_ier;
204188            break;
205189
206190         default:
r9489r9490
209193      }
210194   }
211195
212//   if (offset != 2) printf("rbv_r: %x = %02x (PC=%x)\n", offset, data, cpu_get_pc(space->cpu));
196//   if (offset != 2) printf("rbv_r: %x = %02x (PC=%x)\n", offset, data, cpu_get_pc(space.cpu));
213197
214198   return data;
215199}
216200
217static WRITE8_HANDLER ( mac_rbv_w )
201WRITE8_MEMBER ( mac_state::mac_rbv_w )
218202{
219   mac_state *mac = space->machine->driver_data<mac_state>();
220
221203   if (offset < 0x100)
222204   {
223205//      if (offset == 0x10)
224//      printf("rbv_w: %02x to offset %x (PC=%x)\n", data, offset, cpu_get_pc(space->cpu));
206//      printf("rbv_w: %02x to offset %x (PC=%x)\n", data, offset, cpu_get_pc(space.cpu));
225207      switch (offset)
226208      {
227209         case 0x00:
228            if (mac->model == MODEL_MAC_LC)
210            if (m_model == MODEL_MAC_LC)
229211            {
230               running_device *cpu = space->machine->device("maincpu");
231               
232               m68k_set_hmmu_enable(cpu, (data & 0x8) ? M68K_HMMU_DISABLE : M68K_HMMU_ENABLE_LC);   
212               m68k_set_hmmu_enable(m_maincpu, (data & 0x8) ? M68K_HMMU_DISABLE : M68K_HMMU_ENABLE_LC);
233213            }
234214            break;
235215
236216         case 0x01:
237            if (((data & 0xc0) != (mac->rbv_regs[1] & 0xc0)) && (mac->rbv_type == RBV_TYPE_V8))
217            if (((data & 0xc0) != (m_rbv_regs[1] & 0xc0)) && (m_rbv_type == RBV_TYPE_V8))
238218            {
239               mac->rbv_regs[1] = data;
240               mac_v8_resize(space->machine, mac);
219               m_rbv_regs[1] = data;
220               v8_resize(space.machine);
241221            }
242222            break;
243223
244224         case 0x02:
245            if ((data & 0x40) && (mac->rbv_type == RBV_TYPE_SONORA))
225            if ((data & 0x40) && (m_rbv_type == RBV_TYPE_SONORA))
246226            {
247               mac->rbv_regs[offset] &= ~0x40;
227               m_rbv_regs[offset] &= ~0x40;
248228            }
249229            else
250230            {
251               mac->rbv_regs[offset] = data;
231               m_rbv_regs[offset] = data;
252232            }
253233            break;
254234
255235         case 0x03:
256            mac_set_via2_interrupt(space->machine, 0);
257            mac->rbv_regs[offset] = data;
236            set_via2_interrupt(space.machine, 0);
237            m_rbv_regs[offset] = data;
258238            break;
259239
260240         case 0x10:
261241            if (data != 0)
262242            {
263               mac->rbv_immed10wr = 1;
243               m_rbv_immed10wr = 1;
264244            }
265            mac->rbv_regs[offset] = data;
245            m_rbv_regs[offset] = data;
266246            break;
267247
268248         case 0x12:
269249            if (data & 0x80)   // 1 bits write 1s
270250            {
271               mac->rbv_regs[offset] |= data & 0x7f;
251               m_rbv_regs[offset] |= data & 0x7f;
272252            }
273253            else         // 1 bits write 0s
274254            {
275               mac->rbv_regs[offset] &= ~(data & 0x7f);
255               m_rbv_regs[offset] &= ~(data & 0x7f);
276256            }
277257            break;
278258
279259         case 0x13:
280260            if (data & 0x80)   // 1 bits write 1s
281261            {
282               mac->rbv_regs[offset] |= data & 0x7f;
262               m_rbv_regs[offset] |= data & 0x7f;
283263
284               if (data == 0xff) mac->rbv_regs[offset] = 0x1f;   // I don't know why this is special, but the IIci ROM's POST demands it
264               if (data == 0xff) m_rbv_regs[offset] = 0x1f;   // I don't know why this is special, but the IIci ROM's POST demands it
285265            }
286266            else         // 1 bits write 0s
287267            {
288               mac->rbv_regs[offset] &= ~(data & 0x7f);
268               m_rbv_regs[offset] &= ~(data & 0x7f);
289269            }
290//            printf("RBV: 0x13 (%02x) = %02x (PC %x)\n", data, mac->rbv_regs[offset], cpu_get_pc(space->cpu));
270//            printf("RBV: 0x13 (%02x) = %02x (PC %x)\n", data, m_rbv_regs[offset], cpu_get_pc(space.cpu));
291271            break;
292272
293273         default:
294            mac->rbv_regs[offset] = data;
274            m_rbv_regs[offset] = data;
295275            break;
296276      }
297277   }
r9489r9490
303283      {
304284         case 13:   // IFR
305285//            printf("rbv_w: %02x to IFR\n", data);
306            mac->rbv_ifr = data;
307            mac_set_via2_interrupt(space->machine, 0);
286            m_rbv_ifr = data;
287            set_via2_interrupt(space.machine, 0);
308288            break;
309289
310290         case 14:   // IER
311291            if (data & 0x80)   // 1 bits write 1s
312292            {
313               mac->rbv_ier |= data & 0x7f;
293               m_rbv_ier |= data & 0x7f;
314294            }
315295            else       // 1 bits write 0s
316296            {
317               mac->rbv_ier &= ~(data & 0x7f);
297               m_rbv_ier &= ~(data & 0x7f);
318298            }
319299
320//            printf("rbv_w: %02x to IER => %02x\n", data, mac->rbv_ier);
300//            printf("rbv_w: %02x to IER => %02x\n", data, m_rbv_ier);
321301            break;
322302
323303         default:
r9489r9490
327307   }
328308}
329309
330static READ32_HANDLER(mac_read_id)
310READ32_MEMBER(mac_state::mac_read_id)
331311{
332   mac_state *mac = space->machine->driver_data<mac_state>();
312   logerror("Mac read ID reg @ PC=%x\n", cpu_get_pc(space.cpu));
333313
334   logerror("Mac read ID reg @ PC=%x\n", cpu_get_pc(space->cpu));
335
336   switch (mac->model)
314   switch (m_model)
337315   {
338316      case MODEL_MAC_LC_III:
339317         return 0xa55a0001;   // 25 MHz LC III
r9489r9490
374352   return 0;
375353}
376354
377static READ16_HANDLER(mac_config_r)
355READ16_MEMBER(mac_state::mac_config_r)
378356{
379357   return 0xffff;   // not sure what this does
380358}
r9489r9490
383361    ADDRESS MAPS
384362***************************************************************************/
385363
386static ADDRESS_MAP_START(mac512ke_map, ADDRESS_SPACE_PROGRAM, 16)
364static ADDRESS_MAP_START(mac512ke_map, ADDRESS_SPACE_PROGRAM, 16, mac_state )
387365   AM_RANGE(0x800000, 0x9fffff) AM_READ(mac_scc_r)
388366   AM_RANGE(0xa00000, 0xbfffff) AM_WRITE(mac_scc_w)
389367   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(mac_iwm_r, mac_iwm_w)
r9489r9490
391369   AM_RANGE(0xfffff0, 0xffffff) AM_READWRITE(mac_autovector_r, mac_autovector_w)
392370ADDRESS_MAP_END
393371                 
394static ADDRESS_MAP_START(macplus_map, ADDRESS_SPACE_PROGRAM, 16)
372static ADDRESS_MAP_START(macplus_map, ADDRESS_SPACE_PROGRAM, 16, mac_state )
395373   AM_RANGE(0x580000, 0x5fffff) AM_READWRITE(macplus_scsi_r, macplus_scsi_w)
396374   AM_RANGE(0x800000, 0x9fffff) AM_READ(mac_scc_r)
397375   AM_RANGE(0xa00000, 0xbfffff) AM_WRITE(mac_scc_w)
r9489r9490
400378   AM_RANGE(0xfffff0, 0xffffff) AM_READWRITE(mac_autovector_r, mac_autovector_w)
401379ADDRESS_MAP_END
402380
403static ADDRESS_MAP_START(macprtb_map, ADDRESS_SPACE_PROGRAM, 16)
381static ADDRESS_MAP_START(macprtb_map, ADDRESS_SPACE_PROGRAM, 16, mac_state )
404382   AM_RANGE(0x900000, 0x93ffff) AM_ROM AM_REGION("bootrom", 0) AM_MIRROR(0x0c0000)
405383   AM_RANGE(0xf60000, 0xf6ffff) AM_READWRITE(mac_iwm_r, mac_iwm_w)
406384   AM_RANGE(0xf70000, 0xf7ffff) AM_READWRITE(mac_via_r, mac_via_w)
407385   AM_RANGE(0xf90000, 0xf9ffff) AM_READWRITE(macplus_scsi_r, macplus_scsi_w)
408386   AM_RANGE(0xfa8000, 0xfaffff) AM_RAM   // VRAM
409   AM_RANGE(0xfb0000, 0xfbffff) AM_READWRITE8(mac_asc_r, mac_asc_w, 0xffff)
387   AM_RANGE(0xfb0000, 0xfbffff) AM_DEVREADWRITE8("asc", asc_device, read, write, 0xffff)
410388   AM_RANGE(0xfc0000, 0xfcffff) AM_READ(mac_config_r)
411389   AM_RANGE(0xfd0000, 0xfdffff) AM_READWRITE(mac_scc_r, mac_scc_2_w)
412390   AM_RANGE(0xfffff0, 0xffffff) AM_READWRITE(mac_autovector_r, mac_autovector_w)
413391ADDRESS_MAP_END
414392
415static ADDRESS_MAP_START(maclc_map, ADDRESS_SPACE_PROGRAM, 32)
416   AM_RANGE(0x00a00000, 0x00a7ffff) AM_ROM AM_REGION("bootrom", 0)   // ROM (in 32-bit mode)
393static ADDRESS_MAP_START(maclc_map, ADDRESS_SPACE_PROGRAM, 32, mac_state )
394   ADDRESS_MAP_GLOBAL_MASK(0x80ffffff)   // V8 uses bit 31 and 23-0 for address decoding only
417395
418   AM_RANGE(0xf00000, 0xf01fff) AM_READWRITE16(mac_via_r, mac_via_w, 0xffffffff)
419   AM_RANGE(0xf04000, 0xf05fff) AM_READWRITE16(mac_scc_r, mac_scc_2_w, 0xffffffff)
420   AM_RANGE(0xf06000, 0xf06003) AM_WRITE(macii_scsi_drq_w) AM_MIRROR(0x00f00000)
421   AM_RANGE(0xf10000, 0xf11fff) AM_READWRITE16(macplus_scsi_r, macii_scsi_w, 0xffffffff) AM_MIRROR(0x00f00000)
422   AM_RANGE(0xf12060, 0xf12063) AM_READ(macii_scsi_drq_r) AM_MIRROR(0x00f00000)
423   AM_RANGE(0xf14000, 0xf15fff) AM_READ8(mac_asc_r, 0xffffffff) AM_WRITE8(mac_asc_w, 0xffffffff)
424   AM_RANGE(0xf16000, 0xf17fff) AM_READWRITE16(mac_iwm_r, mac_iwm_w, 0xffffffff) AM_MIRROR(0x00f00000)
425   AM_RANGE(0xf24000, 0xf24003) AM_READWRITE(rbv_ramdac_r, rbv_ramdac_w)
426   AM_RANGE(0xf26000, 0xf27fff) AM_READWRITE8(mac_rbv_r, mac_rbv_w, 0xffffffff)   // VIA2 (V8)
396   AM_RANGE(0xa00000, 0xa7ffff) AM_ROM AM_REGION("bootrom", 0)   // ROM (in 32-bit mode)
427397
428   AM_RANGE(0x50f00000, 0x50f01fff) AM_READWRITE16(mac_via_r, mac_via_w, 0xffffffff)
429   AM_RANGE(0x50f04000, 0x50f05fff) AM_READWRITE16(mac_scc_r, mac_scc_2_w, 0xffffffff)
430   AM_RANGE(0x50f06000, 0x50f06003) AM_WRITE(macii_scsi_drq_w) AM_MIRROR(0x00f00000)
431   AM_RANGE(0x50f10000, 0x50f11fff) AM_READWRITE16(macplus_scsi_r, macii_scsi_w, 0xffffffff) AM_MIRROR(0x00f00000)
432   AM_RANGE(0x50f12060, 0x50f12063) AM_READ(macii_scsi_drq_r) AM_MIRROR(0x00f00000)
433   AM_RANGE(0x50f14000, 0x50f15fff) AM_READ8(mac_asc_r, 0xffffffff) AM_WRITE8(mac_asc_w, 0xffffffff)
434   AM_RANGE(0x50f16000, 0x50f17fff) AM_READWRITE16(mac_iwm_r, mac_iwm_w, 0xffffffff) AM_MIRROR(0x00f00000)
435   AM_RANGE(0x50f24000, 0x50f24003) AM_READWRITE(rbv_ramdac_r,rbv_ramdac_w)
436   AM_RANGE(0x50f26000, 0x50f27fff) AM_READWRITE8(mac_rbv_r, mac_rbv_w, 0xffffffff)   // VIA2 (V8)
437   AM_RANGE(0x50f40000, 0x50fbffff) AM_RAM AM_BASE_MEMBER(mac_state, rbv_vram)
438ADDRESS_MAP_END
439/*
440static ADDRESS_MAP_START(macclrclassic_map, ADDRESS_SPACE_PROGRAM, 32)
441   AM_RANGE(0x00a00000, 0x00afffff) AM_ROM AM_REGION("bootrom", 0)
442   AM_RANGE(0x40a00000, 0x40afffff) AM_ROM AM_REGION("bootrom", 0)
443
444398   AM_RANGE(0xf00000, 0xf01fff) AM_READWRITE16(mac_via_r, mac_via_w, 0xffffffff)
445399   AM_RANGE(0xf04000, 0xf05fff) AM_READWRITE16(mac_scc_r, mac_scc_2_w, 0xffffffff)
446400   AM_RANGE(0xf06000, 0xf06003) AM_WRITE(macii_scsi_drq_w) AM_MIRROR(0x00f00000)
447401   AM_RANGE(0xf10000, 0xf11fff) AM_READWRITE16(macplus_scsi_r, macii_scsi_w, 0xffffffff) AM_MIRROR(0x00f00000)
448402   AM_RANGE(0xf12060, 0xf12063) AM_READ(macii_scsi_drq_r) AM_MIRROR(0x00f00000)
449   AM_RANGE(0xf14000, 0xf15fff) AM_READ8(mac_asc_r, 0xffffffff) AM_WRITE8(mac_asc_w, 0xffffffff)
403   AM_RANGE(0xf14000, 0xf15fff) AM_DEVREADWRITE8("asc", asc_device, read, write, 0xffffffff) AM_MIRROR(0x00f00000)
450404   AM_RANGE(0xf16000, 0xf17fff) AM_READWRITE16(mac_iwm_r, mac_iwm_w, 0xffffffff) AM_MIRROR(0x00f00000)
451405   AM_RANGE(0xf24000, 0xf24003) AM_READWRITE(rbv_ramdac_r, rbv_ramdac_w)
452406   AM_RANGE(0xf26000, 0xf27fff) AM_READWRITE8(mac_rbv_r, mac_rbv_w, 0xffffffff)   // VIA2 (V8)
453
454   AM_RANGE(0x50f00000, 0x50f01fff) AM_READWRITE16(mac_via_r, mac_via_w, 0xffffffff)
455   AM_RANGE(0x50f04000, 0x50f05fff) AM_READWRITE16(mac_scc_r, mac_scc_2_w, 0xffffffff)
456   AM_RANGE(0x50f06000, 0x50f06003) AM_WRITE(macii_scsi_drq_w) AM_MIRROR(0x00f00000)
457   AM_RANGE(0x50f10000, 0x50f11fff) AM_READWRITE16(macplus_scsi_r, macii_scsi_w, 0xffffffff) AM_MIRROR(0x00f00000)
458   AM_RANGE(0x50f12060, 0x50f12063) AM_READ(macii_scsi_drq_r) AM_MIRROR(0x00f00000)
459   AM_RANGE(0x50f14000, 0x50f15fff) AM_READ8(mac_asc_r, 0xffffffff) AM_WRITE8(mac_asc_w, 0xffffffff)
460   AM_RANGE(0x50f16000, 0x50f17fff) AM_READWRITE16(mac_iwm_r, mac_iwm_w, 0xffffffff) AM_MIRROR(0x00f00000)
461   AM_RANGE(0x50f24000, 0x50f24003) AM_READWRITE(rbv_ramdac_r,rbv_ramdac_w)
462   AM_RANGE(0x50f26000, 0x50f27fff) AM_READWRITE8(mac_rbv_r, mac_rbv_w, 0xffffffff)   // VIA2 (V8)
463   AM_RANGE(0x50f40000, 0x50fbffff) AM_RAM AM_BASE_MEMBER(mac_state, rbv_vram)
407   AM_RANGE(0xf40000, 0xfbffff) AM_RAM AM_BASE(m_rbv_vram)
464408ADDRESS_MAP_END
465*/
466static ADDRESS_MAP_START(maclc3_map, ADDRESS_SPACE_PROGRAM, 32)         
409
410static ADDRESS_MAP_START(maclc3_map, ADDRESS_SPACE_PROGRAM, 32, mac_state )
467411   AM_RANGE(0x40000000, 0x400fffff) AM_ROM AM_REGION("bootrom", 0) AM_MIRROR(0x0ff00000)
468412
469413   AM_RANGE(0x50000000, 0x50001fff) AM_READWRITE16(mac_via_r, mac_via_w, 0xffffffff) AM_MIRROR(0x00f00000)
470414   AM_RANGE(0x50004000, 0x50005fff) AM_READWRITE16(mac_scc_r, mac_scc_2_w, 0xffffffff) AM_MIRROR(0x00f00000)
471   AM_RANGE(0x50014000, 0x50015fff) AM_READ8(mac_asc_r, 0xffffffff) AM_WRITE8(mac_asc_w, 0xffffffff) AM_MIRROR(0x00f00000)
415   AM_RANGE(0x50014000, 0x50015fff) AM_DEVREADWRITE8("asc", asc_device, read, write, 0xffffffff) AM_MIRROR(0x00f00000)
472416   AM_RANGE(0x50016000, 0x50017fff) AM_READWRITE16(mac_iwm_r, mac_iwm_w, 0xffffffff) AM_MIRROR(0x00f00000)
473417   AM_RANGE(0x50024000, 0x50024007) AM_WRITE( rbv_ramdac_w ) AM_MIRROR(0x00f00000)
474   AM_RANGE(0x50026000, 0x50027fff) AM_READWRITE16(mac_rbv_r, mac_rbv_w, 0xffffffff) AM_MIRROR(0x00f00000)
418   AM_RANGE(0x50026000, 0x50027fff) AM_READWRITE8(mac_rbv_r, mac_rbv_w, 0xffffffff) AM_MIRROR(0x00f00000)
475419   AM_RANGE(0x50028000, 0x50028003) AM_READWRITE8(mac_sonora_vctl_r, mac_sonora_vctl_w, 0xffffffff) AM_MIRROR(0x00f00000)
476420
477421   AM_RANGE(0x5ffffffc, 0x5fffffff) AM_READ(mac_read_id)
478422
479   AM_RANGE(0x60000000, 0x600fffff) AM_RAM AM_MIRROR(0x0ff00000) AM_BASE_MEMBER(mac_state, rbv_vram)
423   AM_RANGE(0x60000000, 0x600fffff) AM_RAM AM_MIRROR(0x0ff00000) AM_BASE(m_rbv_vram)
480424ADDRESS_MAP_END
481425
482static ADDRESS_MAP_START(macii_map, ADDRESS_SPACE_PROGRAM, 32)
426static ADDRESS_MAP_START(macii_map, ADDRESS_SPACE_PROGRAM, 32, mac_state )
483427   AM_RANGE(0x40000000, 0x4003ffff) AM_ROM AM_REGION("bootrom", 0) AM_MIRROR(0x0ffc0000)
484428
485429   // MMU remaps I/O without the F
r9489r9490
490434   AM_RANGE(0x50006060, 0x50006063) AM_READ(macii_scsi_drq_r) AM_MIRROR(0x00f00000)
491435   AM_RANGE(0x50010000, 0x50011fff) AM_READWRITE16(macplus_scsi_r, macii_scsi_w, 0xffffffff) AM_MIRROR(0x00f00000)
492436   AM_RANGE(0x50012060, 0x50012063) AM_READ(macii_scsi_drq_r) AM_MIRROR(0x00f00000)
493   AM_RANGE(0x50014000, 0x50015fff) AM_READ8(mac_asc_r, 0xffffffff) AM_WRITE8(mac_asc_w, 0xffffffff) AM_MIRROR(0x00f00000)
437   AM_RANGE(0x50014000, 0x50015fff) AM_DEVREADWRITE8("asc", asc_device, read, write, 0xffffffff) AM_MIRROR(0x00f00000)
494438   AM_RANGE(0x50016000, 0x50017fff) AM_READWRITE16(mac_iwm_r, mac_iwm_w, 0xffffffff) AM_MIRROR(0x00f00000)
495439   AM_RANGE(0x50040000, 0x50041fff) AM_READWRITE16(mac_via_r, mac_via_w, 0xffffffff) AM_MIRROR(0x00f00000)
496440
497441   // RasterOps 264 640x480 fixed-res color video card (8, 16, or 24 bit)
498   AM_RANGE(0xfe000000, 0xfe1fffff) AM_RAM   AM_BASE(&mac_cb264_vram) // supposed to be 1.5 megs of VRAM, but every other word?
442   AM_RANGE(0xfe000000, 0xfe1fffff) AM_RAM   AM_BASE(m_cb264_vram) // supposed to be 1.5 megs of VRAM, but every other word?
499443   AM_RANGE(0xfeff6000, 0xfeff60ff) AM_READWRITE( mac_cb264_r, mac_cb264_w )
500444   AM_RANGE(0xfeff7000, 0xfeff7fff) AM_WRITE( mac_cb264_ramdac_w )
501445   AM_RANGE(0xfeff8000, 0xfeffffff) AM_ROM AM_REGION("rops264", 0)
502446ADDRESS_MAP_END
503447
504static ADDRESS_MAP_START(maciici_map, ADDRESS_SPACE_PROGRAM, 32)
448static ADDRESS_MAP_START(maciici_map, ADDRESS_SPACE_PROGRAM, 32, mac_state )
505449   AM_RANGE(0x40000000, 0x4007ffff) AM_ROM AM_REGION("bootrom", 0) AM_MIRROR(0x0ff80000)
506450
507451   AM_RANGE(0x50000000, 0x50001fff) AM_READWRITE16(mac_via_r, mac_via_w, 0xffffffff) AM_MIRROR(0x00f00000)
r9489r9490
510454   AM_RANGE(0x50006060, 0x50006063) AM_READ(macii_scsi_drq_r) AM_MIRROR(0x00f00000)
511455   AM_RANGE(0x50010000, 0x50011fff) AM_READWRITE16(macplus_scsi_r, macii_scsi_w, 0xffffffff) AM_MIRROR(0x00f00000)
512456   AM_RANGE(0x50012060, 0x50012063) AM_READ(macii_scsi_drq_r) AM_MIRROR(0x00f00000)
513   AM_RANGE(0x50014000, 0x50015fff) AM_READ8(mac_asc_r, 0xffffffff) AM_WRITE8(mac_asc_w, 0xffffffff) AM_MIRROR(0x00f00000)
457   AM_RANGE(0x50014000, 0x50015fff) AM_DEVREADWRITE8("asc", asc_device, read, write, 0xffffffff) AM_MIRROR(0x00f00000)
514458   AM_RANGE(0x50016000, 0x50017fff) AM_READWRITE16(mac_iwm_r, mac_iwm_w, 0xffffffff) AM_MIRROR(0x00f00000)
515459   AM_RANGE(0x50024000, 0x50024007) AM_WRITE( rbv_ramdac_w ) AM_MIRROR(0x00f00000)
516   AM_RANGE(0x50026000, 0x50027fff) AM_READWRITE16(mac_rbv_r, mac_rbv_w, 0xffffffff) AM_MIRROR(0x00f00000)
460   AM_RANGE(0x50026000, 0x50027fff) AM_READWRITE8(mac_rbv_r, mac_rbv_w, 0xffffffff) AM_MIRROR(0x00f00000)
517461   AM_RANGE(0x50040000, 0x50041fff) AM_READWRITE16(mac_via_r, mac_via_w, 0xffffffff) AM_MIRROR(0x00f00000)
518462ADDRESS_MAP_END
519463
520static ADDRESS_MAP_START(macse30_map, ADDRESS_SPACE_PROGRAM, 32)
464static ADDRESS_MAP_START(macse30_map, ADDRESS_SPACE_PROGRAM, 32, mac_state )
521465   AM_RANGE(0x40000000, 0x4003ffff) AM_ROM AM_REGION("bootrom", 0) AM_MIRROR(0x0ffc0000)
522466
523467   AM_RANGE(0x50000000, 0x50001fff) AM_READWRITE16(mac_via_r, mac_via_w, 0xffffffff) AM_MIRROR(0x00f00000)
r9489r9490
527471   AM_RANGE(0x50006060, 0x50006063) AM_READ(macii_scsi_drq_r) AM_MIRROR(0x00f00000)
528472   AM_RANGE(0x50010000, 0x50011fff) AM_READWRITE16(macplus_scsi_r, macii_scsi_w, 0xffffffff) AM_MIRROR(0x00f00000)
529473   AM_RANGE(0x50012060, 0x50012063) AM_READ(macii_scsi_drq_r) AM_MIRROR(0x00f00000)
530   AM_RANGE(0x50014000, 0x50015fff) AM_READ8(mac_asc_r, 0xffffffff) AM_WRITE8(mac_asc_w, 0xffffffff) AM_MIRROR(0x00f00000)
474   AM_RANGE(0x50014000, 0x50015fff) AM_DEVREADWRITE8("asc", asc_device, read, write, 0xffffffff) AM_MIRROR(0x00f00000)
531475   AM_RANGE(0x50016000, 0x50017fff) AM_READWRITE16(mac_iwm_r, mac_iwm_w, 0xffffffff) AM_MIRROR(0x00f00000)
532476   AM_RANGE(0x50040000, 0x50041fff) AM_READWRITE16(mac_via_r, mac_via_w, 0xffffffff) AM_MIRROR(0x00f00000)   // mirror
533477
534   AM_RANGE(0xfe000000, 0xfe00ffff) AM_RAM   AM_BASE(&mac_se30_vram)
478   AM_RANGE(0xfe000000, 0xfe00ffff) AM_RAM   AM_BASE(m_se30_vram)
535479   AM_RANGE(0xfeffe000, 0xfeffffff) AM_ROM AM_REGION("se30vrom", 0x0)
536480ADDRESS_MAP_END
537481
538static ADDRESS_MAP_START(pwrmac_map, ADDRESS_SPACE_PROGRAM, 64)
482static ADDRESS_MAP_START(pwrmac_map, ADDRESS_SPACE_PROGRAM, 64, mac_state )
539483   AM_RANGE(0x00000000, 0x007fffff) AM_RAM   // 8 MB standard
540484
541485   AM_RANGE(0x40000000, 0x403fffff) AM_ROM AM_REGION("bootrom", 0) AM_MIRROR(0x0fc00000)
r9489r9490
621565   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(1260))
622566   MDRV_QUANTUM_TIME(HZ(60))
623567
624   MDRV_MACHINE_START( mac )
625   MDRV_MACHINE_RESET( mac )
626
627568    /* video hardware */
628569   MDRV_VIDEO_ATTRIBUTES(VIDEO_UPDATE_BEFORE_VBLANK)
629570   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
r9489r9490
701642   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(1260))
702643   MDRV_QUANTUM_TIME(HZ(60))
703644
704   MDRV_MACHINE_START( mac )
705   MDRV_MACHINE_RESET( mac )
706
707645    /* video hardware */
708646   MDRV_VIDEO_ATTRIBUTES(VIDEO_UPDATE_BEFORE_VBLANK)
709647   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
r9489r9490
747685static MACHINE_CONFIG_START( macii, mac_state )
748686
749687   /* basic machine hardware */
750   MDRV_CPU_ADD("maincpu", M68020PMMU, 7833600*2)
688   MDRV_CPU_ADD("maincpu", M68020HMMU, 7833600*2)
751689   MDRV_CPU_PROGRAM_MAP(macii_map)
752690   MDRV_CPU_VBLANK_INT("screen", mac_cb264_vbl)
753691
r9489r9490
755693   // dot clock, htotal, hstart, hend, vtotal, vstart, vend
756694   MDRV_SCREEN_RAW_PARAMS(25175000, 800, 0, 640, 525, 0, 480)
757695
758   MDRV_MACHINE_START( mac )
759   MDRV_MACHINE_RESET( mac )
760
761696        /* video hardware */
762697   MDRV_VIDEO_ATTRIBUTES(VIDEO_UPDATE_BEFORE_VBLANK)
763698   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
r9489r9490
800735
801736static MACHINE_CONFIG_DERIVED( maclc, macii )
802737
803   MDRV_CPU_REPLACE("maincpu", M68020, 7833600*2)
738   MDRV_CPU_REPLACE("maincpu", M68020HMMU, 7833600*2)
804739   MDRV_CPU_PROGRAM_MAP(maclc_map)
805740   MDRV_CPU_VBLANK_INT("screen", mac_rbv_vbl)
806741
r9489r9490
828763   MDRV_RAM_DEFAULT_SIZE("4M")
829764   MDRV_RAM_EXTRA_OPTIONS("6M,8M,10M")
830765MACHINE_CONFIG_END
831/*
832static MACHINE_CONFIG_DERIVED( maccclas, maclc2 )
833766
834   MDRV_CPU_REPLACE("maincpu", M68030, 7833600*2)
835   MDRV_CPU_PROGRAM_MAP(macclrclassic_map)
836   MDRV_CPU_VBLANK_INT("screen", mac_rbv_vbl)
837
838   MDRV_RAM_MODIFY("messram")
839   MDRV_RAM_DEFAULT_SIZE("4M")
840   MDRV_RAM_EXTRA_OPTIONS("6M,8M,10M")
841MACHINE_CONFIG_END
842*/
843767static MACHINE_CONFIG_DERIVED( maclc3, maclc )
844768
845769   MDRV_CPU_REPLACE("maincpu", M68030, 25000000)
r9489r9490
879803   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(1260))
880804   MDRV_QUANTUM_TIME(HZ(60))
881805
882   MDRV_MACHINE_START( mac )
883   MDRV_MACHINE_RESET( mac )
884
885806        /* video hardware */
886807   MDRV_VIDEO_ATTRIBUTES(VIDEO_UPDATE_BEFORE_VBLANK)
887808   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
r9489r9490
996917   // dot clock, htotal, hstart, hend, vtotal, vstart, vend
997918   MDRV_SCREEN_RAW_PARAMS(25175000, 800, 0, 640, 525, 0, 480)
998919
999   MDRV_MACHINE_START( mac )
1000   MDRV_MACHINE_RESET( mac )
1001
1002920        /* video hardware */
1003921   MDRV_VIDEO_ATTRIBUTES(VIDEO_UPDATE_BEFORE_VBLANK)
1004922   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
r9489r9490
14501368   ROM_REGION16_BE(0x40000, "bootrom", 0)
14511369        ROM_LOAD16_WORD( "96645f9c.rom", 0x000000, 0x040000, CRC(29ac7ee9) SHA1(7f3acf40b1f63612de2314a2e9fcfeafca0711fc) )
14521370ROM_END
1453/*
1371
14541372ROM_START( maccclas )
14551373   ROM_REGION32_BE(0x100000, "bootrom", 0)
14561374        ROM_LOAD( "ecd99dc0.rom", 0x000000, 0x100000, CRC(c84c3aa5) SHA1(fd9e852e2d77fe17287ba678709b9334d4d74f1e) )
r9489r9490
14581376   ROM_REGION(0x1100, "egret", 0)
14591377   ROM_LOAD( "341s0851.bin", 0x000000, 0x001100, CRC(ea9ea6e4) SHA1(8b0dae3ec66cdddbf71567365d2c462688aeb571) )
14601378ROM_END
1461*/
1379
14621380/*    YEAR  NAME      PARENT    COMPAT  MACHINE   INPUT     INIT     COMPANY          FULLNAME */
14631381COMP( 1984, mac128k,  0,   0,   mac128k,  macplus,  mac128k512k,      "Apple Computer", "Macintosh 128k",  GAME_NOT_WORKING )
14641382COMP( 1984, mac512k,  mac128k,  0,   mac512ke, macplus,  mac128k512k,  "Apple Computer", "Macintosh 512k",  GAME_NOT_WORKING )
r9489r9490
14791397COMP( 1991, macpb100, 0,        0,      macprtb,  macadb,   macprtb,  "Apple Computer", "Macintosh PowerBook 100", GAME_NOT_WORKING )
14801398COMP( 1991, macclas2, 0,   0,   macclas2, macadb,   macclassic2,      "Apple Computer", "Macintosh Classic II",  GAME_NOT_WORKING )
14811399COMP( 1991, maclc2,   0,   0,   maclc2,   maciici,  maclc2,             "Apple Computer", "Macintosh LC II",  GAME_NOT_WORKING )
1482//COMP( 1993, maccclas, 0,        0,      maccclas, macadb,   maclrcclassic,        "Apple Computer", "Macintosh Color Classic", GAME_NOT_WORKING )
1400COMP( 1993, maccclas, 0,        0,      maclc2,  macadb,   maclrcclassic,        "Apple Computer", "Macintosh Color Classic", GAME_NOT_WORKING )
14831401COMP( 1993, maclc3,   0,   0,   maclc3,   maciici,  maclc3,             "Apple Computer", "Macintosh LC III",  GAME_NOT_WORKING )
14841402COMP( 1994, pmac6100, 0,   0,   pwrmac,   macadb,   macpm6100,         "Apple Computer", "Power Macintosh 6100",  GAME_NOT_WORKING | GAME_NO_SOUND )
14851403

Previous 15994 Revisions Next


© 1998-2018 The MESS Team