Previous 15994 Revisions Next

r13162 Wednesday 2nd November, 2011 at 01:40:54 UTC by R. Belmont
mac: Further improvements to Quadra 700; System 7.5.0 (and probably 7.1) will boot, but system remains NOT_WORKING due to many known flaws. Fixed slot interrupts on IIci so 4-head operation is possible. Various cleanups. [R. Belmont]
[src/emu]emu.mak
[src/emu/machine]ncr539x.c* ncr539x.h*
[src/mess/drivers]mac.c
[src/mess/includes]mac.h
[src/mess/machine]mac.c
[src/mess/video]mac.c

src/emu/emu.mak
r13161r13162
215215   $(EMUMACHINE)/msm5832.o   \
216216   $(EMUMACHINE)/msm58321.o   \
217217   $(EMUMACHINE)/msm6242.o      \
218    $(EMUMACHINE)/ncr539x.o     \
218219   $(EMUMACHINE)/nmc9306.o      \
219220   $(EMUMACHINE)/nvram.o      \
220221   $(EMUMACHINE)/pc16552d.o   \
src/emu/machine/ncr539x.c
r0r13162
1/*
2 * ncr539x.c
3 *
4 * NCR 53(CF)94/53(CF)96 SCSI controller
5 * Includes enhanced features of the AMD 53CF94/96 and compatibles
6 *
7 * All new emulation in 2011 by R. Belmont.
8 *
9 */
10
11#include "emu.h"
12#include "ncr539x.h"
13
14#define VERBOSE         (0)
15#define VERBOSE_READS   (0)
16
17enum
18{
19   TIMER_539X_COMMAND,
20
21   TIMER_539X_END
22};
23
24#define MAIN_STATUS_INTERRUPT      0x80
25#define MAIN_STATUS_ILLEGAL_OPER   0x40
26#define MAIN_STATUS_PARITY_ERROR   0x20
27#define MAIN_STATUS_COUNT_TO_ZERO   0x10
28#define MAIN_STATUS_GROUP_VALID      0x08
29#define MAIN_STATUS_MESSAGE         0x04
30#define MAIN_STATUS_CMD_DATA      0x02
31#define MAIN_STATUS_IO            0x01
32
33#define IRQ_STATUS_RESET         0x80
34#define IRQ_STATUS_INVALID_COMMAND   0x40
35#define IRQ_STATUS_DISCONNECTED      0x20
36#define IRQ_STATUS_SERVICE_REQUEST   0x10
37#define IRQ_STATUS_SUCCESS         0x08
38#define IRQ_STATUS_RESELECTED      0x04         // we were reselected as a target
39#define IRQ_STATUS_SELECTED_WITH_ATN   0x02      // we were selected as a target with ATN steps
40#define IRQ_STATUS_SELECTED         0x01         // we were selected as a target
41
42#define CR2_ALIGN_ENABLE         0x80
43#define CR2_FEATURES_ENABLE         0x40
44#define CR2_BYTE_ORDER            0x20
45#define CR2_TRISTATE_DMA         0x10
46#define CR2_SCSI2_ENABLE         0x08
47#define CR2_ABORT_ON_PARITY_ERROR   0x04
48#define CR2_GENERATE_REGISTER_PARITY   0x02
49#define CR2_GENERATE_DATA_PARITY   0x01
50
51#if VERBOSE
52#if VERBOSE_READS
53static const char *rdregs[16] = {
54   "Transfer count LSB",   // 0
55   "Transfer count MSB",   // 1
56   "FIFO",             // 2
57   "Command",           // 3
58   "Status",            // 4
59   "Interrupt Status",    // 5
60   "Internal State",
61   "Current FIFO/Internal State",
62   "Control Register 1",
63   "0x9",
64   "0xA",
65   "Control Register 2",
66   "Control Register 3",
67   "Control Register 4",
68   "Transfer count HSB/Chip ID",
69   "0xF"
70};
71#endif
72
73static const char *wrregs[16] = {
74   "Start Transfer count LSB",
75   "Start Transfer count MSB",
76   "FIFO",
77   "Command",
78   "SCSI Destination ID",
79   "SCSI Timeout",
80   "Synchronous Transfer Period",
81   "Synchronous Offset",
82   "Control Register 1",
83   "Clock Factor",
84   "Forced Test Mode",
85   "Control Register 2",
86   "Control Register 3",
87   "Control Register 4",
88   "Start Transfer count HSB",
89   "Data Alignment"
90};
91#endif
92
93// get the length of a SCSI command based on its command byte type
94static int get_cmd_len(int cbyte)
95{
96   int group;
97
98   group = (cbyte>>5) & 7;
99
100   if (group == 0) return 6;
101   if (group == 1 || group == 2) return 10;
102   if (group == 5) return 12;
103
104   return 6;
105}
106
107//-------------------------------------------------
108//  device_config_complete - perform any
109//  operations now that the configuration is
110//  complete
111//-------------------------------------------------
112
113void ncr539x_device::device_config_complete()
114{
115   // inherit a copy of the static data
116   const NCR539Xinterface *intf = reinterpret_cast<const NCR539Xinterface *>(static_config());
117   if (intf != NULL)
118   {
119      *static_cast<NCR539Xinterface *>(this) = *intf;
120   }
121
122   // or initialize to defaults if none provided
123   else
124   {
125      scsidevs = NULL;
126      memset(&m_out_irq_cb, 0, sizeof(m_out_irq_cb));
127      memset(&m_out_drq_cb, 0, sizeof(m_out_drq_cb));
128   }
129}
130
131//**************************************************************************
132//  LIVE DEVICE
133//**************************************************************************
134
135const device_type NCR539X = &device_creator<ncr539x_device>;
136
137//-------------------------------------------------
138//  ncr539x_device - constructor/destructor
139//-------------------------------------------------
140
141ncr539x_device::ncr539x_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
142    : device_t(mconfig, NCR539X, "539x SCSI", tag, owner, clock)
143{
144}
145
146//-------------------------------------------------
147//  device_start - device-specific startup
148//-------------------------------------------------
149
150void ncr539x_device::device_start()
151{
152   int i;
153
154   memset(m_scsi_devices, 0, sizeof(m_scsi_devices));
155
156   // resolve line callbacks
157   m_out_irq_func.resolve(m_out_irq_cb, *this);
158   m_out_drq_func.resolve(m_out_drq_cb, *this);
159
160   // try to open the devices
161   for (i = 0; i < scsidevs->devs_present; i++)
162   {
163      SCSIAllocInstance( machine(),
164            scsidevs->devices[i].scsiClass,
165            &m_scsi_devices[scsidevs->devices[i].scsiID],
166            scsidevs->devices[i].diskregion );
167   }
168
169   m_operation_timer = timer_alloc(0, NULL);
170}
171
172//-------------------------------------------------
173//  device_reset - device-specific reset
174//-------------------------------------------------
175
176void ncr539x_device::device_reset()
177{
178   memset(m_scsi_devices, 0, sizeof(m_scsi_devices));
179
180   m_fifo_ptr = 0;
181   m_irq_status = 0;
182   m_status = SCSI_PHASE_STATUS;
183   m_internal_state = 0;
184   m_buffer_offset = 512;
185   m_buffer_remaining = 0;
186   m_dma_size = 0;
187   m_xfer_count = 0;
188   m_total_data = 0;
189   m_selected = false;
190   m_control1 = m_control2 = m_control3 = m_control4 = 0;
191   m_chipid_available = false;
192   m_chipid_lock = false;
193
194   m_out_irq_func(CLEAR_LINE);
195   m_out_drq_func(CLEAR_LINE);
196
197   scan_devices();
198}
199
200//-------------------------------------------------
201//  device_stop - device-specific stop/shutdown
202//-------------------------------------------------
203void ncr539x_device::device_stop()
204{
205   int i;
206
207   // clean up the devices
208   for (i = 0; i < scsidevs->devs_present; i++)
209   {
210      SCSIDeleteInstance( m_scsi_devices[scsidevs->devices[i].scsiID] );
211   }
212}
213
214void ncr539x_device::dma_read_data(int bytes, UINT8 *pData)
215{
216   if (m_scsi_devices[m_last_id])
217   {
218      if (VERBOSE)
219         logerror("NCR539x: issuing read for %d bytes\n", bytes);
220      SCSIReadData(m_scsi_devices[m_last_id], pData, bytes);
221   }
222   else
223   {
224      logerror("ncr539x: read unknown device SCSI ID %d\n", m_last_id);
225   }
226}
227
228
229void ncr539x_device::dma_write_data(int bytes, UINT8 *pData)
230{
231   if (bytes)
232   {
233      if (m_scsi_devices[m_last_id])
234      {
235         SCSIWriteData(m_scsi_devices[m_last_id], pData, bytes);
236      }
237      else
238      {
239         logerror("ncr539x: write to unknown device SCSI ID %d\n", m_last_id);
240      }
241   }
242}
243
244void ncr539x_device::scan_devices()
245{
246   int i;
247
248   // try to open the devices
249   for (i = 0; i < scsidevs->devs_present; i++)
250   {
251      // if a device wasn't already allocated
252      if (!m_scsi_devices[scsidevs->devices[i].scsiID])
253      {
254         SCSIAllocInstance( machine(),
255               scsidevs->devices[i].scsiClass,
256               &m_scsi_devices[scsidevs->devices[i].scsiID],
257               scsidevs->devices[i].diskregion );
258      }
259   }
260}
261
262void ncr539x_device::device_timer(emu_timer &timer, device_timer_id tid, int param, void *ptr)
263{
264   //printf("539X: device_timer expired, param = %d, m_command = %02x\n", param, m_command);
265
266   switch (param)
267   {
268      case TIMER_539X_COMMAND:
269         // if this is a DMA command, raise DRQ now
270         if (m_command & 0x80)
271         {
272            m_out_drq_func(ASSERT_LINE);
273         }
274
275         switch (m_command & 0x7f)
276         {
277            case 0x41:   // select without ATN steps
278               if (m_scsi_devices[m_last_id])
279               {
280                  m_irq_status |= IRQ_STATUS_SERVICE_REQUEST | IRQ_STATUS_SUCCESS;
281                  // we should now be in the command phase
282                  m_status &= ~7;   // clear bus phases
283                  m_status |= MAIN_STATUS_INTERRUPT | SCSI_PHASE_COMMAND;
284                  m_fifo_ptr = 0;
285                  m_selected = true;
286
287                  #if VERBOSE
288                  printf("Selecting w/o ATN, irq_status = %02x, status = %02x!\n", m_irq_status, m_status);
289                  #endif
290
291                  // if DMA is not enabled, there should already be a command loaded into the FIFO
292                  if (!(m_command & 0x80))
293                  {
294                     exec_fifo();
295                  }
296                  update_fifo_internal_state(0);
297               }
298               else
299               {
300                  #if VERBOSE
301                  printf("Select failed, no device @ ID %d!\n", m_last_id);
302                  #endif
303                  m_status |= MAIN_STATUS_INTERRUPT;
304                  m_irq_status |= IRQ_STATUS_DISCONNECTED;
305               }
306               m_out_irq_func(ASSERT_LINE);
307               break;
308
309            case 0x42:   // Select with ATN steps
310               if (m_scsi_devices[m_last_id])
311               {
312                  m_irq_status |= IRQ_STATUS_SERVICE_REQUEST | IRQ_STATUS_SUCCESS;
313                  // we should now be in the command phase
314                  m_status &= ~7;   // clear bus phases
315                  m_status |= MAIN_STATUS_INTERRUPT | SCSI_PHASE_COMMAND;
316                  m_fifo_ptr = 0;
317                  m_selected = true;
318                  #if VERBOSE
319                  printf("Selecting with ATN, irq_status = %02x, status = %02x!\n", m_irq_status, m_status);
320                  #endif
321
322                  // if DMA is not enabled, there should already be a command loaded into the FIFO
323                  if (!(m_command & 0x80))
324                  {
325                     exec_fifo();
326                  }
327                  update_fifo_internal_state(0);
328               }
329               else
330               {
331                  #if VERBOSE
332                  printf("Select failed, no device @ ID %d!\n", m_last_id);
333                  #endif
334                  m_status |= MAIN_STATUS_INTERRUPT;
335                  m_irq_status |= IRQ_STATUS_DISCONNECTED;
336               }
337               m_out_irq_func(ASSERT_LINE);
338               break;
339
340            case 0x11:   // initiator command complete
341               #if VERBOSE
342               printf("Initiator command complete\n");
343               #endif
344               m_irq_status = IRQ_STATUS_SERVICE_REQUEST;
345               m_status &= ~7;   // clear phase bits
346               m_status |= MAIN_STATUS_INTERRUPT | SCSI_PHASE_DATAIN;   // go to data in phase (?)
347               m_out_irq_func(ASSERT_LINE);
348
349               // this puts status and message bytes into the FIFO (todo: what are these?)
350               m_fifo_ptr = 0;
351               m_xfer_count = 2;
352               m_buffer_remaining = m_total_data = 0;
353               m_fifo[0] = 0;   // status byte
354               m_fifo[1] = 0;   // message byte
355               m_selected = false;
356               update_fifo_internal_state(2);
357               break;
358
359            case 0x12:   // message accepted
360               #if VERBOSE
361               printf("Message accepted\n");
362               #endif
363               m_irq_status = IRQ_STATUS_SERVICE_REQUEST;
364               m_status |= MAIN_STATUS_INTERRUPT;
365               m_out_irq_func(ASSERT_LINE);
366               break;
367
368            default:
369               fatalerror("539x: Unhandled command %02x\n", m_command);
370               break;
371         }
372         break;
373
374      default:
375         break;
376   }
377}
378
379READ8_MEMBER( ncr539x_device::read )
380{
381   UINT8 rv = 0;
382
383   #if VERBOSE
384   #if VERBOSE_READS
385   printf("539x: Read @ %s (%02x) (PC=%x) (status %02x irq_status %02x)\n", rdregs[offset], offset, cpu_get_pc(&space.device()), m_status, m_irq_status);
386   #endif
387   #endif
388
389   switch (offset)
390   {
391      case 0:
392         rv = m_xfer_count & 0xff;
393         break;
394
395      case 1:
396         rv = (m_xfer_count>>8) & 0xff;
397         break;
398
399      case 2: // FIFO
400         {
401            UINT8 fifo_bytes = m_fifo_internal_state & 0x1f;
402
403            if (!fifo_bytes)
404            {
405               rv = 0;
406            }
407            else
408            {
409               rv = m_fifo[m_fifo_ptr++];
410
411               fifo_bytes--;
412               m_xfer_count--;
413               update_fifo_internal_state(fifo_bytes);
414
415               #if VERBOSE
416               printf("Read %02x from FIFO[%d], FIFO now contains %d bytes (PC=%x, m_buffer_remaining %x)\n", rv, m_fifo_ptr-1, fifo_bytes, cpu_get_pc(&space.device()), m_buffer_remaining);
417               #endif
418
419               if (fifo_bytes == 0)
420               {
421                  // the last transfer command has more data for us
422                  if (m_xfer_count > 0)
423                  {
424                     int fifo_fill_size = m_fifo_size;
425                     if (m_xfer_count < fifo_fill_size)
426                     {
427                        fifo_fill_size = m_xfer_count;
428                     }
429                     memcpy(m_fifo, &m_buffer[m_buffer_offset], fifo_fill_size);
430                     m_buffer_offset += fifo_fill_size;
431                     m_buffer_remaining -= fifo_fill_size;
432                     m_fifo_ptr = 0;
433                     update_fifo_internal_state(fifo_fill_size);
434                     #if VERBOSE
435                     printf("Refreshing FIFO (%x remaining from transfer, %x in buffer, %x in total)\n", m_xfer_count, m_buffer_remaining, m_total_data);
436                     #endif
437                  }
438                  else
439                  {
440                     #if VERBOSE
441                     printf("FIFO empty, asserting service request (buffer_remaining %x)\n", m_buffer_remaining);
442                     #endif
443                     m_irq_status = IRQ_STATUS_SERVICE_REQUEST;
444                     m_status &= 0x7;   // clear everything but the phase bits
445                     m_status |= MAIN_STATUS_INTERRUPT | MAIN_STATUS_COUNT_TO_ZERO;
446                     m_out_irq_func(ASSERT_LINE);
447
448                     // if no data at all, drop the phase
449                     if ((m_buffer_remaining + m_total_data) == 0)
450                     {
451                        #if VERBOSE
452                        printf("Out of data, setting phase STATUS\n");
453                        #endif
454                        m_status &= ~0x7;
455                        m_status |= SCSI_PHASE_STATUS;
456                     }
457                  }
458               }
459            }
460         }
461         break;
462
463      case 3:
464         rv = m_command;
465         break;
466
467      case 4:
468         rv = m_status;
469         break;
470
471      case 5:
472         rv = m_irq_status;
473         // clear the interrupt state
474         m_status &= ~MAIN_STATUS_INTERRUPT;
475         m_out_irq_func(CLEAR_LINE);
476         break;
477
478      case 6:
479         rv = m_internal_state;
480         break;
481
482      case 7:
483         rv = m_fifo_internal_state;
484         break;
485
486      case 8:
487         rv = m_control1;
488         break;
489
490      case 0xb:
491         rv = m_control2;
492         break;
493
494      case 0xc:
495         rv = m_control3;
496         break;
497
498      case 0xd:
499         rv = m_control4;
500         break;
501
502      case 0xe:
503         if (m_control2 & CR2_FEATURES_ENABLE)
504         {
505            if (m_chipid_available)
506            {
507               rv = 0xa2;   // 0x12 for CF94, 0xa2 for CF96
508            }
509            else
510            {
511               rv = (m_xfer_count>>16) & 0xff;
512            }
513         }
514         break;
515
516   }
517   return rv;
518}
519
520WRITE8_MEMBER( ncr539x_device::write )
521{
522   #if VERBOSE
523   if (offset != 2) printf("539x: Write %02x @ %s (%02x) (PC=%x)\n", data, wrregs[offset], offset, cpu_get_pc(&space.device()));
524   #endif
525
526   switch (offset)
527   {
528      case 0:
529         m_dma_size &= 0xff00;
530         m_dma_size |= data;
531         break;
532
533      case 1:
534         m_dma_size &= 0x00ff;
535         m_dma_size |= (data<<8);
536         break;
537
538      case 2: // FIFO
539         fifo_write(data);
540         break;
541
542      case 3:
543         m_command = data;
544
545         // clear status bits (OK to do here?)
546         m_status &= ~MAIN_STATUS_INTERRUPT;
547         m_irq_status = 0;
548
549         switch (data & 0x7f)
550         {
551            case 0x00:   // NOP
552               m_irq_status = IRQ_STATUS_SUCCESS;
553               m_status |= MAIN_STATUS_INTERRUPT;
554               m_out_irq_func(ASSERT_LINE);
555
556               // DMA NOP?  allow chip ID
557               if ((m_command == 0x80) && (!m_chipid_lock))
558               {
559                  m_chipid_available = true;
560               }
561               break;
562
563            case 0x01:   // Clear FIFO (must not change buffer state)
564               m_fifo_ptr = 0;
565               update_fifo_internal_state(0);
566               m_irq_status = IRQ_STATUS_SUCCESS;
567               m_status |= MAIN_STATUS_INTERRUPT;
568               m_out_irq_func(ASSERT_LINE);
569               break;
570
571            case 0x02:   // Reset device
572               device_reset();
573
574               m_irq_status = IRQ_STATUS_SUCCESS;
575               m_status |= MAIN_STATUS_INTERRUPT;
576               m_out_irq_func(ASSERT_LINE);
577               break;
578
579            case 0x03:   // Reset SCSI bus
580               m_status = 0;
581               m_irq_status = IRQ_STATUS_SUCCESS;
582               m_status |= MAIN_STATUS_INTERRUPT;
583               m_out_irq_func(ASSERT_LINE);
584               break;
585
586            case 0x10:   // information transfer (must happen immediately)
587               m_status &= 0x7;   // clear everything but the phase bits
588               m_status |= MAIN_STATUS_INTERRUPT;
589               m_irq_status = IRQ_STATUS_SUCCESS;
590
591               int phase;
592               SCSIGetPhase( m_scsi_devices[m_last_id], &phase );
593
594               #if VERBOSE
595               printf("Information transfer: phase %d buffer remaining %x\n", phase, m_buffer_remaining);
596               #endif
597
598               if (phase == SCSI_PHASE_DATAIN)   // target -> initiator transfer
599               {
600                  int amtToGet = m_buffer_size;
601
602                  // fill the internal sector buffer
603                  if (m_buffer_remaining <= 0)
604                  {
605                     if (m_total_data < m_buffer_size)
606                     {
607                        amtToGet = m_total_data;
608                     }
609
610                     #if VERBOSE
611                     printf("amtToGet = %x\n", amtToGet);
612                     #endif
613
614                     if (amtToGet > 0)
615                     {
616                        SCSIReadData(m_scsi_devices[m_last_id], m_buffer, amtToGet);
617
618                        m_total_data -= amtToGet;
619                        m_buffer_offset = 0;
620                        m_buffer_remaining = amtToGet;
621                     }
622                  }
623
624                  // copy the requested amount into the FIFO
625                  if (amtToGet > 0)
626                  {
627                     if (m_buffer_remaining < m_dma_size)
628                     {
629                        m_dma_size = m_buffer_remaining;
630                     }
631
632                     int fifo_fill_size = m_fifo_size;
633
634                     if (m_dma_size < fifo_fill_size)
635                     {
636                        fifo_fill_size = m_dma_size;
637                     }
638
639                     #if VERBOSE
640                     printf("filling FIFO from buffer[%x] for %x bytes\n", m_buffer_offset, fifo_fill_size);
641                     #endif
642
643                     memcpy(m_fifo, &m_buffer[m_buffer_offset], fifo_fill_size);
644                     m_buffer_offset += fifo_fill_size;
645                     m_buffer_remaining -= fifo_fill_size;
646
647                     m_xfer_count = m_dma_size;
648                     m_fifo_ptr = 0;
649                     update_fifo_internal_state(fifo_fill_size);
650                     m_out_drq_func(ASSERT_LINE);
651                  }
652
653                  m_status |= MAIN_STATUS_COUNT_TO_ZERO;
654
655                  #if VERBOSE
656                  printf("Information transfer: put %02x bytes into FIFO (dma size %x) (buffer remaining %x)\n", m_fifo_internal_state & 0x1f, m_dma_size, m_buffer_remaining);
657                  #endif
658               }
659               else if (phase == SCSI_PHASE_DATAOUT)
660               {
661                  m_xfer_count = m_dma_size;
662                  if (m_xfer_count == 0)
663                  {
664                     m_xfer_count = 0x10000;
665                  }
666                  #if VERBOSE
667                  printf("dma_size %x, xfer_count %x\n", m_dma_size, m_xfer_count);
668                  #endif
669                  m_status &= ~MAIN_STATUS_COUNT_TO_ZERO;
670                  m_fifo_ptr = 0;
671                  m_buffer_offset = 0;
672                  m_buffer_remaining = 0;
673               }
674               m_out_irq_func(ASSERT_LINE);
675               break;
676
677            case 0x24:   // Terminate steps
678               #if VERBOSE
679               printf("Terminate steps\n");
680               #endif
681               m_irq_status = IRQ_STATUS_SUCCESS | IRQ_STATUS_DISCONNECTED;
682               m_status |= MAIN_STATUS_INTERRUPT;
683               m_out_irq_func(ASSERT_LINE);
684               m_fifo_ptr = 0;
685               update_fifo_internal_state(0);
686               break;
687
688            case 0x27:   // Disconnect
689               #if VERBOSE
690               printf("Disconnect\n");
691               #endif
692               m_irq_status = IRQ_STATUS_SUCCESS;
693               m_status |= MAIN_STATUS_INTERRUPT;
694               m_out_irq_func(ASSERT_LINE);
695               break;
696
697            case 0x44:   // Enable selection/reselection
698               #if VERBOSE
699               printf("Enable selection/reselection\n");
700               #endif
701               m_irq_status = IRQ_STATUS_SUCCESS;
702               m_status |= MAIN_STATUS_INTERRUPT;
703               m_out_irq_func(ASSERT_LINE);
704               break;
705
706            case 0x47:   // Reselect with ATN3 steps
707               if (m_scsi_devices[m_last_id])
708               {
709                  m_irq_status |= IRQ_STATUS_SERVICE_REQUEST | IRQ_STATUS_SUCCESS;
710                  // we should now be in the command phase
711                  m_status &= ~7;   // clear bus phases
712                  m_status |= MAIN_STATUS_INTERRUPT | SCSI_PHASE_COMMAND;
713                  m_fifo_ptr = 0;
714                  m_selected = true;
715                  #if VERBOSE
716                  printf("Reselecting with ATN3, irq_status = %02x, status = %02x!\n", m_irq_status, m_status);
717                  #endif
718
719                  // if DMA is not enabled, there should already be a command loaded into the FIFO
720                  if (!(m_command & 0x80))
721                  {
722                     exec_fifo();
723                  }
724                  update_fifo_internal_state(0);
725               }
726               else
727               {
728                  #if VERBOSE
729                  printf("Reselect with ATN3 failed, no device @ ID %d!\n", m_last_id);
730                  #endif
731                  m_status |= MAIN_STATUS_INTERRUPT;
732                  m_irq_status |= IRQ_STATUS_DISCONNECTED;
733               }
734               m_out_irq_func(ASSERT_LINE);
735               break;
736
737            default:   // other commands are not instantaneous
738               #if VERBOSE
739               printf("Setting timer for command %02x\n", data);
740               #endif
741               // 1x commands happen much faster
742               if ((m_command & 0x70) == 0x10)
743               {
744                  m_operation_timer->adjust(attotime::from_hz(65536), TIMER_539X_COMMAND);
745               }
746               else
747               {
748                  m_operation_timer->adjust(attotime::from_hz(16384), TIMER_539X_COMMAND);
749               }
750               break;
751         }
752         break;
753
754      case 4:
755         m_last_id = data;
756         break;
757
758      case 5:
759         m_timeout = data;
760         break;
761
762      case 6:
763         m_sync_xfer_period = data;
764         break;
765
766      case 7:
767         m_sync_offset = data;
768         break;
769
770      case 8:
771         m_control1 = data;
772         break;
773
774      case 9:
775         m_clock_factor = data;
776         break;
777
778      case 0xa:
779         m_forced_test = data;
780         break;
781
782      case 0xb:
783         m_control2 = data;
784         break;
785
786      case 0xc:
787         m_control3 = data;
788         break;
789
790      case 0xd:
791         m_control4 = data;
792         break;
793
794      case 0xe:
795         if (m_control2 & CR2_FEATURES_ENABLE)
796         {
797            m_dma_size &= 0xffff;
798            m_dma_size |= (data<<16);
799            m_chipid_available = false;
800            m_chipid_lock = true;
801         }
802         break;
803
804      case 0xf:
805         m_data_alignment = data;
806         break;
807   }
808}
809
810void ncr539x_device::exec_fifo()
811{
812   int length, phase;
813
814   SCSISetCommand(m_scsi_devices[m_last_id], &m_fifo[0], 12);
815   SCSIExecCommand(m_scsi_devices[m_last_id], &length);
816   SCSIGetPhase(m_scsi_devices[m_last_id], &phase);
817
818   #if VERBOSE
819   printf("Command executed (id %d), new phase %d, length %x\n", m_last_id, phase, length);
820   #endif
821
822   m_buffer_offset = m_buffer_size;
823   m_buffer_remaining = 0;
824   m_total_data = length;
825
826   m_status &= ~7;   // clear bus phases
827   m_status |= (phase & 7);   // set the phase reported by the device
828}
829
830void ncr539x_device::check_fifo_executable()
831{
832   if (get_cmd_len(m_fifo[0]) == m_fifo_ptr)
833   {
834      exec_fifo();
835   }
836}
837
838void ncr539x_device::fifo_write(UINT8 data)
839{
840   int phase = (m_status & 7);
841
842   if (phase != SCSI_PHASE_DATAOUT)
843   {
844      #if VERBOSE
845      printf("539x: Write %02x @ FIFO[%x]\n", data, m_fifo_ptr);
846      #endif
847      m_fifo[m_fifo_ptr++] = data;
848
849      if (m_selected)
850      {
851         check_fifo_executable();
852      }
853   }
854   else   // phase is DATAOUT
855   {
856      m_buffer[m_buffer_offset++] = data;
857      m_xfer_count--;
858      m_total_data--;
859      #if VERBOSE
860      printf("539x: Write %02x @ buffer[%x], xfer_count %x, total %x\n", data, m_buffer_offset-1, m_xfer_count, m_total_data);
861      #endif
862
863      // default to flushing our entire buffer
864      int flush_size = m_buffer_size;
865
866      // if the actual size is less than the buffer size, flush that instead
867      if (m_dma_size < m_buffer_size)
868      {
869         flush_size = m_dma_size;
870      }
871
872      if ((m_buffer_offset == flush_size) || (m_xfer_count == 0))
873      {
874         #if VERBOSE
875         printf("Flushing buffer to device, %x bytes left in buffer (%x total)\n", m_xfer_count, m_total_data);
876         #endif
877         SCSIWriteData(m_scsi_devices[m_last_id], m_buffer, flush_size);
878         m_buffer_offset = 0;
879
880         // need a service request here too
881         m_irq_status = IRQ_STATUS_SERVICE_REQUEST;
882         m_status &= 7;
883         m_status |= MAIN_STATUS_INTERRUPT;
884         m_out_irq_func(ASSERT_LINE);
885      }
886
887      if ((m_xfer_count == 0) && (m_total_data == 0))
888      {
889         #if VERBOSE
890         printf("End of write, asserting service request\n");
891         #endif
892
893         m_buffer_offset = 0;
894         m_irq_status = IRQ_STATUS_SERVICE_REQUEST;
895         m_status = MAIN_STATUS_INTERRUPT | SCSI_PHASE_STATUS;
896         m_out_irq_func(ASSERT_LINE);
897      }
898   }
899}
900
901void ncr539x_device::update_fifo_internal_state(int bytes)
902{
903   if (bytes >= 0x1f)
904   {
905      m_fifo_internal_state |= 0x1f;
906   }
907   else
908   {
909      m_fifo_internal_state &= ~0x1f;
910      m_fifo_internal_state |= (bytes & 0x1f);
911   }
912}
src/emu/machine/ncr539x.h
r0r13162
1/*
2 * ncr5394/5396.h SCSI controller
3 *
4 */
5
6#ifndef _NCR539x_H_
7#define _NCR539x_H_
8
9#include "machine/scsidev.h"
10
11struct NCR539Xinterface
12{
13   const SCSIConfigTable *scsidevs;      /* SCSI devices */
14    devcb_write_line m_out_irq_cb;          /* IRQ line */
15    devcb_write_line m_out_drq_cb;          /* DRQ line */
16};
17
18// 539x registers
19enum
20{
21};
22
23// device stuff
24#define MCFG_NCR539X_ADD(_tag, _clock, _intrf) \
25    MCFG_DEVICE_ADD(_tag, NCR539X, _clock) \
26    MCFG_DEVICE_CONFIG(_intrf)
27
28class ncr539x_device : public device_t,
29                  public NCR539Xinterface
30{
31public:
32   // construction/destruction
33   ncr539x_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
34
35   // our API
36    DECLARE_READ8_MEMBER(read);
37    DECLARE_WRITE8_MEMBER(write);
38
39   void dma_read_data(int bytes, UINT8 *pData);
40   void dma_write_data(int bytes, UINT8 *pData);
41
42   void *get_scsi_device(int id);
43
44   void scan_devices();
45protected:
46   // device-level overrides
47   virtual void device_start();
48   virtual void device_reset();
49   virtual void device_stop();
50   virtual void device_config_complete();
51    virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
52
53private:
54    void fifo_write(UINT8 data);
55    void check_fifo_executable();
56    void exec_fifo();
57    void update_fifo_internal_state(int bytes);
58
59   SCSIInstance *m_scsi_devices[8];
60
61    UINT32 m_xfer_count;
62    UINT32 m_dma_size;
63    UINT8 m_command;
64   UINT8 m_last_id;
65    UINT8 m_timeout;
66    UINT8 m_sync_xfer_period;
67    UINT8 m_sync_offset;
68    UINT8 m_control1, m_control2, m_control3, m_control4;
69    UINT8 m_clock_factor;
70    UINT8 m_forced_test;
71    UINT8 m_data_alignment;
72                   
73    bool m_selected;
74    bool m_chipid_available, m_chipid_lock;
75                       
76    static const int m_fifo_size = 16;
77    UINT8 m_fifo_ptr, m_fifo[m_fifo_size];
78
79    int m_xfer_remaining;   // amount in the FIFO when we're in data in phase
80
81    // read-only registers
82    UINT8 m_status, m_irq_status, m_internal_state, m_fifo_internal_state;
83
84    static const int m_buffer_size = 2048;
85
86    UINT8 m_buffer[m_buffer_size];
87    int m_buffer_offset, m_buffer_remaining, m_total_data;
88
89    emu_timer *m_operation_timer;
90
91   devcb_resolved_write_line   m_out_irq_func;
92   devcb_resolved_write_line   m_out_drq_func;
93};
94
95// device type definition
96extern const device_type NCR539X;
97#endif
src/mess/machine/mac.c
r13161r13162
2121         - PowerBook 100        68k (16 MHz)    SWIM    ADB-PMU    PMU      640x400 B&W
2222         - Mac II               020             IWM     MacII ADB  ext      NuBus card
2323         - Mac IIx              030             SWIM    MacII ADB  ext      NuBus card
24         - Mac IIfx             030             SWIM    ADB-IOP    ext      NuBus card
24         - Mac IIfx             030             SWIM    IOP ADB    ext      NuBus card
2525         - Mac SE/30            030             SWIM    MacII ADB  ext      Internal fake NuBus card
2626         - Mac IIcx             030             SWIM    MacII ADB  ext      NuBus card
27         - Mac IIci             030             SWIM    Egret ADB  ext      Internal "RBV" type
27         - Mac IIci             030             SWIM    MacII ADB  ext      Internal "RBV" type
2828         - Mac IIsi             030             SWIM    Egret ADB  n/a      Internal "RBV" type
2929         - PowerBook 140/145(B) 030 (16/25 MHz) SWIM    ADB-PMU    PMU      640x400 B&W (passive matrix)
3030         - PowerBook 170        030 (25 MHz)    SWIM    ADB-PMU    PMU      640x400 B&W (active matrix)
r13161r13162
3232         - Mac LC               020             SWIM    Egret ADB  n/a      Internal "V8" type
3333         - Mac LC II            030             SWIM    Egret ADB  n/a      Internal "V8" type
3434         - Mac LC III           030             SWIM    Egret ADB  n/a      Internal "Sonora" type
35         - Mac Classic II       030             SWIM    Egret ADB  n/a      Internal "Eagle" type
36
35         - Mac Classic II       030             SWIM    Egret ADB  n/a      Internal "Eagle" type (V8 clone)
36         - Mac Color Classic    030             SWIM    Cuda ADB   n/a      Internal "Spice" type (V8 clone)
37        - Mac Quadra 700      040 (25 MHz)   SWIM II   MacII ADB  ext     Internal "DAFB" type
38        - Mac Quadra 900      040 (33 MHz)   SWIM II   IOP ADB    ext     Internal "DAFB" type
39 
3740    Notes:
3841        - The Mac Plus boot code seems to check to see the extent of ROM
3942          mirroring to determine if SCSI is available.  If the ROM is mirrored,
r13161r13162
4750        - There are 5 known kinds of host-side ADB hardware:
4851          * "Mac II ADB" used in the SE, II, IIx, IIcx, SE/30, IIci, Quadra 610, Quadra 650, Quadra 700,
4952             Quadra 800, Centris 610 and Centris 650.  This is a bit-banger using the VIA and a simple PIC.
50          * "ADB-PMU" used in the Mac Portable and all 680x0-based PowerBooks.
51          * "ADB-EGRET" used in the IIsi, IIvi, IIvx, Classic II, LC, LC II, LC III, Performa 460,
53          * "PMU ADB" used in the Mac Portable and all 680x0-based PowerBooks.
54          * "Egret ADB" used in the IIsi, IIvi, IIvx, Classic II, LC, LC II, LC III, Performa 460,
5255             and Performa 600.  This is a 68HC05 with a different internal ROM than CUDA.
53          * "ADB-IOP" (ADB driven by a 6502 coprocessor, similar to Lisa) used in the IIfx,
56          * "IOP ADB" (ADB driven by a 6502 coprocessor, similar to Lisa) used in the IIfx,
5457            Quadra 900, and Quadra 950.
55          * "ADB-CUDA" (Apple's CUDA chip, which is a 68HC05 MCU) used in the Color Classic, LC 520,
58          * "Cuda ADB" (Apple's CUDA chip, which is a 68HC05 MCU) used in the Color Classic, LC 520,
5659            LC 55x, LC 57x, LC 58x, Quadra 630, Quadra 660AV, Quadra 840AV, PowerMac 6100/7100/8100,
5760            IIci, and PowerMac 5200.
5861
r13161r13162
8891#include "machine/applefdc.h"
8992#include "devices/sonydriv.h"
9093#include "machine/ncr5380.h"
91#include "machine/am53cf96.h"
9294#include "sound/asc.h"
9395#include "includes/mac.h"
9496#include "debug/debugcpu.h"
r13161r13162
537539      {
538540         mac_install_memory(machine(), 0x00000000, memory_size-1, memory_size, memory_data, is_rom, "bank1");
539541      }
542      else if (m_model == MODEL_MAC_QUADRA_700)
543      {
544         mac_install_memory(machine(), 0x00000000, memory_size-1, memory_size, memory_data, is_rom, "bank1");
545      }
540546      else
541547      {
542548         mac_install_memory(machine(), 0x00000000, 0x003fffff, memory_size, memory_data, is_rom, "bank1");
r13161r13162
10911097    }*/
10921098}
10931099
1100WRITE_LINE_MEMBER(mac_state::irq_539x_1_w)
1101{
1102   if (state)   // make sure a CB1 transition occurs
1103   {
1104      m_via2->write_cb2(0);
1105      m_via2->write_cb2(1);
1106   }
1107}
1108
1109WRITE_LINE_MEMBER(mac_state::drq_539x_1_w)
1110{
1111   m_dafb_scsi1_drq = state;
1112}
1113
10941114/* *************************************************************************
10951115 * SCC
10961116 *
r13161r13162
33333353MAC_DRIVER_INIT(maciivx, MODEL_MAC_IIVX)
33343354MAC_DRIVER_INIT(maciifx, MODEL_MAC_IIFX)
33353355MAC_DRIVER_INIT(macpbduo210, MODEL_MAC_PBDUO_210)
3356MAC_DRIVER_INIT(macquadra700, MODEL_MAC_QUADRA_700)
33363357
3337static void scsi96_irq(running_machine &machine)
3338{
3339}
3340
3341static const SCSIConfigTable dev_table =
3342{
3343   2,                                      /* 2 SCSI devices */
3344   {
3345    { SCSI_ID_6, "harddisk1", SCSI_DEVICE_HARDDISK },  /* SCSI ID 6, using disk1, and it's a harddisk */
3346    { SCSI_ID_5, "harddisk2", SCSI_DEVICE_HARDDISK }   /* SCSI ID 5, using disk2, and it's a harddisk */
3347   }
3348};
3349
3350static const struct AM53CF96interface scsi_intf =
3351{
3352   &dev_table,      /* SCSI device table */
3353   &scsi96_irq,   /* command completion IRQ */
3354};
3355
3356DRIVER_INIT(macquadra700)
3357{
3358   mac_driver_init(machine, MODEL_MAC_QUADRA_700);
3359   am53cf96_init(machine, &scsi_intf);
3360}
3361
33623358// make the appletalk init fail instead of hanging on the II FDHD/IIx/IIcx/SE30 ROM
33633359static void patch_appletalk_iix(running_machine &machine)
33643360{
r13161r13162
34103406      mac->m_nubus_irq_state |= masks[slot];
34113407   }
34123408
3413   if (mac->m_model != MODEL_MAC_IIFX)
3409   if ((mac->m_model != MODEL_MAC_IIFX) && (mac->m_model != MODEL_MAC_IICI) && (mac->m_model != MODEL_MAC_IISI))
34143410   {
34153411      if ((mac->m_nubus_irq_state & mask) != mask)
34163412      {
r13161r13162
34263422         m_via2->write_ca1(1);
34273423      }
34283424   }
3425
3426   if ((mac->m_model == MODEL_MAC_IICI) || (mac->m_model == MODEL_MAC_IISI) || (mac->m_model == MODEL_MAC_IIVX) || (mac->m_model == MODEL_MAC_IIVI))
3427   {
3428      mac->m_rbv_regs[2] &= ~0x38;
3429      mac->m_rbv_regs[2] |= (mac->m_nubus_irq_state & 0x38);
3430      mac->rbv_recalc_irqs();
3431   }
34293432}
34303433
34313434void mac_state::vblank_irq()
src/mess/video/mac.c
r13161r13162
77    Emulates the video hardware for compact Macintosh series (original
88    Macintosh (128k, 512k, 512ke), Macintosh Plus, Macintosh SE, Macintosh
99    Classic)
10 
11    Also emulates on-board video for systems with the
12    RBV, V8, Sonora, and DAFB chips.
13 
14    ----------------------------------------------------------------------
15    Monitor sense codes
16 
17    Apple assigns 3 pins for monitor IDs.  These allow 8 possible codes:
18 
19    000 - color 2-Page Display (21")
20    001 - monochrome Full Page display (15")
21    010 - color 512x384 (12")
22    011 - monochrome 2 Page display (21")
23    100 - NTSC
24    101 - color Full Page display (15")
25    110 - High-Resolution Color (13" 640x480) or use "type 6" extended codes
26    111 - No monitor connected or use "type 7" extended codes
27 
28    For extended codes, you drive one of the 3 pins at a time and read the 2
29    undriven pins.  See http://support.apple.com/kb/TA21618?viewlocale=en_US
30    for details.
31 
32Extended codes:
33 
34               Sense 2 Low  Sense 1 Low   Sense 0 Low
35               1 & 0        2 & 0         2 & 1     
1036
37Multiple Scan 14"    00         00         11
38Multiple Scan 16"    00         10         11
39Multiple Scan 21"    10         00         11
40PAL Encoder        00         00         00
41NTSC Encoder       01         01         00
42VGA/Super VGA       01         01         11
43RGB 16"           10         11         01
44PAL Monitor        11         00         00
45RGB 19"           11         10         10
46Radius color TPD    11           00           01   (TPD = Two Page Display)
47Radius mono TPD      11           01           00
48Apple TPD            11           01           01
49Apple color FPD      01           11           10   (FPD = Full Page Display)
50 
1151***************************************************************************/
1252
1353#define ADDRESS_MAP_MODERN
r13161r13162
474514            return 0;
475515         }
476516         break;
477
478      case RBV_TYPE_DAFB:
479         mode = 0;
480         break;
481517   }
482518
483519   switch (mode)
r13161r13162
507543               }
508544            }
509545         }
510         else if (mac->m_rbv_type == RBV_TYPE_DAFB)
511         {
512            vram8 += 0x1000;
513
514            for (y = 0; y < 480; y++)
515            {
516               scanline = BITMAP_ADDR32(bitmap, y, 0);
517               for (x = 0; x < 640; x+=8)
518               {
519                  pixels = vram8[(y * 256 * 4) + ((x/8)^3)];
520
521                  *scanline++ = mac->m_rbv_palette[(pixels>>7)&1];
522                  *scanline++ = mac->m_rbv_palette[(pixels>>6)&1];
523                  *scanline++ = mac->m_rbv_palette[(pixels>>5)&1];
524                  *scanline++ = mac->m_rbv_palette[(pixels>>4)&1];
525                  *scanline++ = mac->m_rbv_palette[(pixels>>3)&1];
526                  *scanline++ = mac->m_rbv_palette[(pixels>>2)&1];
527                  *scanline++ = mac->m_rbv_palette[(pixels>>1)&1];
528                  *scanline++ = mac->m_rbv_palette[(pixels&1)];
529               }
530            }
531         }
532546         else
533547         {
534548            for (y = 0; y < 480; y++)
r13161r13162
685699   mac->m_rbv_vbltime = 0;
686700   mac->m_dafb_int_status = 0;
687701   mac->m_rbv_type = RBV_TYPE_DAFB;
702   mac->m_dafb_mode = 0;
703   mac->m_dafb_base = 0x1000;
704   mac->m_dafb_stride = 256*4;
688705
689706   memset(mac->m_rbv_palette, 0, sizeof(mac->m_rbv_palette));
690707}
r13161r13162
695712
696713   switch (offset<<2)
697714   {
698      case 0x1c:   // monitor sense
699         return 1;   // 640x480
715      case 0x1c:   // inverse of monitor sense
716         return 7;   // 21" color 2-page
700717         break;
701718
719      case 0x24: // SCSI 539x #1 status
720         return m_dafb_scsi1_drq<<9;
721         break;
722
723      case 0x28: // SCSI 539x #2 status
724         return m_dafb_scsi2_drq<<9;
725         break;
726
702727      case 0x108:   // IRQ/VBL status
703728         return m_dafb_int_status;
704729         break;
r13161r13162
718743
719744WRITE32_MEMBER(mac_state::dafb_w)
720745{
721// printf("DAFB: Write %08x @ %x (mask %x PC=%x)\n", data, offset*4, mem_mask, cpu_get_pc(m_maincpu));
746//   if (offset != 0x10c/4) printf("DAFB: Write %08x @ %x (mask %x PC=%x)\n", data, offset*4, mem_mask, cpu_get_pc(m_maincpu));
722747
723748   switch (offset<<2)
724749   {
750      case 0:   // bits 20-9 of base
751         m_dafb_base &= 0x1ff;
752         m_dafb_base |= (data & 0xffff) << 9;
753//         printf("DAFB baseH: %x\n", m_dafb_base);
754         break;
755
756      case 4:   // bits 8-5 of base
757         m_dafb_base &= ~0x1ff;
758         m_dafb_base |= (data & 0xf) << 5;
759//         printf("DAFB baseL: %x\n", m_dafb_base);
760         break;
761
762      case 8:
763         m_dafb_stride = data<<2;   // stride in DWORDs
764//         printf("DAFB stride: %x %x\n", m_dafb_stride, data);
765         break;
766
725767      case 0x104:
726768         if (data & 1)   // VBL enable
727769         {
r13161r13162
772814
773815WRITE32_MEMBER(mac_state::dafb_dac_w)
774816{
775// printf("DAFB: Write %08x to DAC @ %x (mask %x PC=%x)\n", data, offset*4, mem_mask, cpu_get_pc(m_maincpu));
817//   if ((offset > 0) && (offset != 0x10/4)) printf("DAFB: Write %08x to DAC @ %x (mask %x PC=%x)\n", data, offset*4, mem_mask, cpu_get_pc(m_maincpu));
776818
777819   switch (offset<<2)
778820   {
r13161r13162
792834            m_rbv_count = 0;
793835         }
794836         break;
837
838      case 0x20:
839         printf("%x to DAFB mode\n", data);
840         switch (data & 0x9f)
841         {
842            case 0x80:
843               m_dafb_mode = 0;   // 1bpp
844               break;
845
846            case 0x88:
847               m_dafb_mode = 1;   // 2bpp
848               break;
849
850            case 0x90:
851               m_dafb_mode = 2;   // 4bpp
852               break;
853
854            case 0x98:
855               m_dafb_mode = 3;   // 8bpp
856               break;
857
858            case 0x9c:
859               m_dafb_mode = 4;   // 24bpp
860               break;
861         }
862         break;
795863   }
796864}
797865
866SCREEN_UPDATE( macdafb )
867{
868   UINT32 *scanline;
869   int x, y;
870   mac_state *mac = screen->machine().driver_data<mac_state>();
871
872   switch (mac->m_dafb_mode)
873   {
874      case 0:   // 1bpp
875      {
876         UINT8 *vram8 = (UINT8 *)mac->m_vram;
877         UINT8 pixels;
878         vram8 += mac->m_dafb_base;
879
880         for (y = 0; y < 870; y++)
881         {
882            scanline = BITMAP_ADDR32(bitmap, y, 0);
883            for (x = 0; x < 1152; x+=8)
884            {
885               pixels = vram8[(y * mac->m_dafb_stride) + ((x/8)^3)];
886
887               *scanline++ = mac->m_rbv_palette[(pixels>>7)&1];
888               *scanline++ = mac->m_rbv_palette[(pixels>>6)&1];
889               *scanline++ = mac->m_rbv_palette[(pixels>>5)&1];
890               *scanline++ = mac->m_rbv_palette[(pixels>>4)&1];
891               *scanline++ = mac->m_rbv_palette[(pixels>>3)&1];
892               *scanline++ = mac->m_rbv_palette[(pixels>>2)&1];
893               *scanline++ = mac->m_rbv_palette[(pixels>>1)&1];
894               *scanline++ = mac->m_rbv_palette[(pixels&1)];
895            }
896         }
897      }
898      break;
899
900      case 1:   // 2bpp
901      {
902         UINT8 *vram8 = (UINT8 *)mac->m_vram;
903         UINT8 pixels;
904         vram8 += mac->m_dafb_base;
905
906         for (y = 0; y < 870; y++)
907         {
908            scanline = BITMAP_ADDR32(bitmap, y, 0);
909            for (x = 0; x < 1152/4; x++)
910            {
911               pixels = vram8[(y * mac->m_dafb_stride) + (BYTE4_XOR_BE(x))];
912
913               *scanline++ = mac->m_rbv_palette[((pixels>>6)&3)];
914               *scanline++ = mac->m_rbv_palette[((pixels>>4)&3)];
915               *scanline++ = mac->m_rbv_palette[((pixels>>2)&3)];
916               *scanline++ = mac->m_rbv_palette[(pixels&3)];
917            }
918         }
919      }
920      break;
921
922      case 2: // 4bpp
923      {
924         UINT8 *vram8 = (UINT8 *)mac->m_vram;
925         UINT8 pixels;
926         vram8 += mac->m_dafb_base;
927
928         for (y = 0; y < 870; y++)
929         {
930            scanline = BITMAP_ADDR32(bitmap, y, 0);
931
932            for (x = 0; x < 1152/2; x++)
933            {
934               pixels = vram8[(y * mac->m_dafb_stride) + (BYTE4_XOR_BE(x))];
935
936               *scanline++ = mac->m_rbv_palette[(pixels>>4)];
937               *scanline++ = mac->m_rbv_palette[(pixels&0xf)];
938            }
939         }
940      }
941      break;
942
943      case 3: // 8bpp
944      {
945         UINT8 *vram8 = (UINT8 *)mac->m_vram;
946         UINT8 pixels;
947         vram8 += mac->m_dafb_base;
948
949         for (y = 0; y < 870; y++)
950         {
951            scanline = BITMAP_ADDR32(bitmap, y, 0);
952
953            for (x = 0; x < 1152; x++)
954            {
955               pixels = vram8[(y * mac->m_dafb_stride) + (BYTE4_XOR_BE(x))];
956               *scanline++ = mac->m_rbv_palette[pixels];
957            }
958         }
959      }
960      break;
961
962      case 4: // 24 bpp
963         for (y = 0; y < 480; y++)
964         {
965            UINT32 *base;
966
967            scanline = BITMAP_ADDR32(bitmap, y, 0);
968            base = (UINT32 *)&mac->m_vram[(y * (mac->m_dafb_stride/4)) + (mac->m_dafb_base/4)];
969            for (x = 0; x < 640; x++)
970            {
971               *scanline++ = *base++;
972            }
973         }
974         break;
975   }
976
977   return 0;
978}
979
src/mess/includes/mac.h
r13161r13162
1414#include "machine/ram.h"
1515#include "machine/egret.h"
1616#include "machine/nubus.h"
17#include "machine/ncr539x.h"
1718#include "sound/awacs.h"
1819
1920#define MAC_SCREEN_NAME "screen"
21#define MAC_539X_1_TAG "539x_1"
22#define MAC_539X_2_TAG "539x_2"
2023
2124/* for Egret and CUDA streaming MCU commands, command types */
2225typedef enum
r13161r13162
155158/*----------- defined in video/mac.c -----------*/
156159
157160VIDEO_START( mac );
158SCREEN_UPDATE( mac );
159SCREEN_UPDATE( macse30 );
160SCREEN_UPDATE( macprtb );
161SCREEN_UPDATE( macpb140 );
162SCREEN_UPDATE( macpb160 );
163PALETTE_INIT( mac );
164PALETTE_INIT( macgsc );
165
166161VIDEO_START( macrbv );
167162VIDEO_START( macv8 );
168163VIDEO_START( macsonora );
169164VIDEO_START( macdafb );
170SCREEN_UPDATE( macrbv );
171SCREEN_UPDATE( macrbvvram );
165
172166VIDEO_RESET(macrbv);
173167VIDEO_RESET(macdafb);
174168VIDEO_RESET(maceagle);
175169VIDEO_RESET(macsonora);
176170
171SCREEN_UPDATE( mac );
172SCREEN_UPDATE( macse30 );
173SCREEN_UPDATE( macprtb );
174SCREEN_UPDATE( macpb140 );
175SCREEN_UPDATE( macpb160 );
176SCREEN_UPDATE( macrbv );
177SCREEN_UPDATE( macrbvvram );
178SCREEN_UPDATE( macdafb );
179
180PALETTE_INIT( mac );
181PALETTE_INIT( macgsc );
182
177183/*----------- defined in audio/mac.c -----------*/
178184
179185DECLARE_LEGACY_SOUND_DEVICE(MAC_SOUND, mac_sound);
r13161r13162
198204        m_awacs(*this, "awacs"),
199205        m_egret(*this, "egret"),
200206      m_ram(*this, RAM_TAG),
201        m_screen(*this, MAC_SCREEN_NAME)
207        m_screen(*this, MAC_SCREEN_NAME),
208        m_539x_1(*this, MAC_539X_1_TAG),
209        m_539x_2(*this, MAC_539X_2_TAG)
202210    { }
203211
204212   required_device<cpu_device> m_maincpu;
r13161r13162
209217    optional_device<egret_device> m_egret;
210218   required_device<device_t> m_ram;
211219    optional_device<screen_device> m_screen;
220    optional_device<ncr539x_device> m_539x_1;
221    optional_device<ncr539x_device> m_539x_2;
212222
213223   virtual void machine_start();
214224   virtual void machine_reset();
r13161r13162
300310    emu_timer *m_vbl_timer, *m_cursor_timer;
301311    UINT16 m_cursor_line;
302312    UINT16 m_dafb_int_status;
303
313    int m_dafb_scsi1_drq, m_dafb_scsi2_drq;
314    UINT8 m_dafb_mode;
315    UINT32 m_dafb_base, m_dafb_stride;
316             
304317    // this is shared among all video setups with vram
305318   UINT32 *m_vram;
306319
r13161r13162
390403    DECLARE_WRITE_LINE_MEMBER(nubus_irq_d_w);
391404    DECLARE_WRITE_LINE_MEMBER(nubus_irq_e_w);
392405
406    DECLARE_WRITE_LINE_MEMBER(irq_539x_1_w);
407    DECLARE_WRITE_LINE_MEMBER(drq_539x_1_w);
408
393409private:
394410   int has_adb();
395411   void rtc_init();
src/mess/drivers/mac.c
r13161r13162
4444#include "cpu/m6805/m6805.h"
4545#include "machine/6522via.h"
4646#include "machine/ncr5380.h"
47#include "machine/am53cf96.h"
4847#include "machine/applefdc.h"
4948#include "devices/sonydriv.h"
5049#include "imagedev/harddriv.h"
r13161r13162
201200   UINT8 slot_irqs = (~m_rbv_regs[2]) & 0x78;
202201   slot_irqs &= (m_rbv_regs[0x12] & 0x78);
203202
204//  printf("slot_irqs = %02x\n", slot_irqs);
205203   if (slot_irqs)
206204   {
207205      m_rbv_regs[3] |= 2;   // any slot
r13161r13162
556554
557555READ8_MEMBER(mac_state::mac_5396_r)
558556{
557   if (offset < 0x100)
558   {
559      return m_539x_1->read(space, offset>>4);
560   }
561   else   // pseudo-DMA: read from the FIFO
562   {
563      return m_539x_1->read(space, 2);
564   }
565
559566   return 0;
560567}
561568
562569WRITE8_MEMBER(mac_state::mac_5396_w)
563570{
564//  printf("%02x to 5396 @ %x\n", data, offset);
571   if (offset < 0x100)
572   {
573      m_539x_1->write(space, offset>>4, data);
574   }
575   else   // pseudo-DMA: write to the FIFO
576   {
577      m_539x_1->write(space, 2, data);                                                                                             
578   }
565579}
566580
567581/***************************************************************************
r13161r13162
754768static ADDRESS_MAP_START(quadra700_map, AS_PROGRAM, 32, mac_state )
755769   AM_RANGE(0x40000000, 0x400fffff) AM_ROM AM_REGION("bootrom", 0) AM_MIRROR(0x0ff00000)
756770
757   AM_RANGE(0x50000000, 0x50001fff) AM_READWRITE16(mac_via_r, mac_via_w, 0xffffffff) AM_MIRROR(0x00f00000)
758   AM_RANGE(0x50002000, 0x50003fff) AM_READWRITE16(mac_via2_r, mac_via2_w, 0xffffffff) AM_MIRROR(0x00f00000)
771   AM_RANGE(0x50000000, 0x50001fff) AM_READWRITE16(mac_via_r, mac_via_w, 0xffffffff) AM_MIRROR(0x00fc0000)
772   AM_RANGE(0x50002000, 0x50003fff) AM_READWRITE16(mac_via2_r, mac_via2_w, 0xffffffff) AM_MIRROR(0x00fc0000)
759773// 50008000 = Ethernet MAC ID PROM
760774// 5000a000 = Sonic (DP83932) ethernet
761775// 5000f000 = SCSI cf96, 5000f402 = SCSI #2 cf96
762   AM_RANGE(0x5000f000, 0x5000f3ff) AM_READWRITE8(mac_5396_r, mac_5396_w, 0xffffffff) AM_MIRROR(0x00f00000)
763   AM_RANGE(0x5000c000, 0x5000dfff) AM_READWRITE16(mac_scc_r, mac_scc_2_w, 0xffffffff) AM_MIRROR(0x00f00000)
764   AM_RANGE(0x50014000, 0x50015fff) AM_DEVREADWRITE8("asc", asc_device, read, write, 0xffffffff) AM_MIRROR(0x00f00000)
765   AM_RANGE(0x5001e000, 0x5001ffff) AM_READWRITE16(mac_iwm_r, mac_iwm_w, 0xffffffff) AM_MIRROR(0x00f00000)
776   AM_RANGE(0x5000f000, 0x5000f3ff) AM_READWRITE8(mac_5396_r, mac_5396_w, 0xffffffff) AM_MIRROR(0x00fc0000)
777   AM_RANGE(0x5000c000, 0x5000dfff) AM_READWRITE16(mac_scc_r, mac_scc_2_w, 0xffffffff) AM_MIRROR(0x00fc0000)
778   AM_RANGE(0x50014000, 0x50015fff) AM_DEVREADWRITE8("asc", asc_device, read, write, 0xffffffff) AM_MIRROR(0x00fc0000)
779   AM_RANGE(0x5001e000, 0x5001ffff) AM_READWRITE16(mac_iwm_r, mac_iwm_w, 0xffffffff) AM_MIRROR(0x00fc0000)
766780
767   AM_RANGE(0x50040000, 0x50041fff) AM_READWRITE16(mac_via_r, mac_via_w, 0xffffffff) AM_MIRROR(0x00f00000)
781   AM_RANGE(0x50040000, 0x50041fff) AM_READWRITE16(mac_via_r, mac_via_w, 0xffffffff) AM_MIRROR(0x00fc0000)
768782   // f9800000 = VDAC / DAFB
769783   AM_RANGE(0xf9000000, 0xf91fffff) AM_RAM   AM_BASE(m_vram)
770784   AM_RANGE(0xf9800000, 0xf98001ff) AM_READWRITE(dafb_r, dafb_w)
r13161r13162
826840   mac_scsi_irq   // IRQ (unconnected on the Mac Plus)
827841};
828842
843static const struct NCR539Xinterface mac_539x_intf =
844{
845   &dev_table,   // SCSI device table
846   DEVCB_DRIVER_LINE_MEMBER(mac_state, irq_539x_1_w),
847   DEVCB_DRIVER_LINE_MEMBER(mac_state, drq_539x_1_w)
848};
849
829850static const struct nbbus_interface nubus_intf =
830851{
831852   // interrupt lines
r13161r13162
854875/***************************************************************************
855876    MACHINE DRIVERS
856877***************************************************************************/
857static const floppy_interface mac128512_floppy_interface = //SONY_FLOPPY_ALLOW400K
858{
859   DEVCB_NULL,
860   DEVCB_NULL,
861   DEVCB_NULL,
862   DEVCB_NULL,
863   DEVCB_NULL,
864   FLOPPY_STANDARD_3_5_DSHD,
865   LEGACY_FLOPPY_OPTIONS_NAME(apple35_mac),
866   NULL,
867   NULL
868};
869878
870
871879static const floppy_interface mac_floppy_interface =
872880{
873881   DEVCB_NULL,
r13161r13162
913921
914922   /* devices */
915923   MCFG_IWM_ADD("fdc", mac_iwm_interface)
916   MCFG_LEGACY_FLOPPY_SONY_2_DRIVES_ADD(mac128512_floppy_interface)
924   MCFG_LEGACY_FLOPPY_SONY_2_DRIVES_ADD(mac_floppy_interface)
917925
918926   MCFG_SCC8530_ADD("scc", C7M)
919927   MCFG_SCC8530_IRQ(mac_scc_irq)
r13161r13162
9941002   MCFG_NCR5380_ADD("ncr5380", C7M, macplus_5380intf)
9951003
9961004   MCFG_IWM_ADD("fdc", mac_iwm_interface)
997   MCFG_LEGACY_FLOPPY_SONY_2_DRIVES_ADD(mac128512_floppy_interface)
1005   MCFG_LEGACY_FLOPPY_SONY_2_DRIVES_ADD(mac_floppy_interface)
9981006
9991007   MCFG_SCC8530_ADD("scc", C7M)
10001008   MCFG_SCC8530_IRQ(mac_scc_irq)
r13161r13162
15641572
15651573   MCFG_SCREEN_ADD(MAC_SCREEN_NAME, RASTER)
15661574   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
1567   MCFG_SCREEN_RAW_PARAMS(25175000, 800, 0, 640, 525, 0, 480)
1568   MCFG_SCREEN_VISIBLE_AREA(0, 640-1, 0, 480-1)
1569   MCFG_SCREEN_UPDATE(macrbvvram)
1575   MCFG_SCREEN_REFRESH_RATE(75.08)
1576   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(1260))
1577   MCFG_SCREEN_SIZE(1152, 870)
1578   MCFG_SCREEN_VISIBLE_AREA(0, 1152-1, 0, 870-1)
1579   MCFG_SCREEN_UPDATE(macdafb)
15701580
15711581   MCFG_VIDEO_START(macdafb)
15721582   MCFG_VIDEO_RESET(macdafb)
r13161r13162
15961606   MCFG_VIA6522_ADD("via6522_0", C7M/10, mac_via6522_adb_intf)
15971607   MCFG_VIA6522_ADD("via6522_1", C7M/10, mac_via6522_2_intf)
15981608
1609   MCFG_NCR539X_ADD(MAC_539X_1_TAG, C7M, mac_539x_intf)
1610
15991611   MCFG_HARDDISK_ADD( "harddisk1" )
16001612   MCFG_HARDDISK_ADD( "harddisk2" )
16011613
16021614   /* internal ram */
16031615   MCFG_RAM_ADD(RAM_TAG)
16041616   MCFG_RAM_DEFAULT_SIZE("4M")
1605   MCFG_RAM_EXTRA_OPTIONS("8M,20M,36M,68M")   // QD700 has 4M on board and can take 4M, 8M, 16M, or 32M SIMMs
1617   MCFG_RAM_EXTRA_OPTIONS("8M,16M,32M,64M,68M,72M,80M,96M,128M")
16061618MACHINE_CONFIG_END
16071619
16081620static INPUT_PORTS_START( macplus )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team