Previous 15994 Revisions Next

r6328 Sunday 8th November, 2009 at 00:08:40 UTC by R. Belmont
[MAC] Improved ADB and improved LC-series support (still doens't boot).
[src/mess/drivers]mac.c
[src/mess/machine]mac.c

src/mess/machine/mac.c
r6327r6328
4242          but A/UX can run 32.
4343        - There are 5 known kinds of host-side ADB hardware:
4444          * "Mac II ADB" used in the SE, II, IIx, IIcx, SE/30, IIci, Quadra 610, Quadra 650, Quadra 700,
45             Quadra 800, Centris 610 and Centris 650.  This is a dumb state machine using the VIA.
45             Quadra 800, Centris 610 and Centris 650.  This is a bit-banger using the VIA and a simple PIC.
4646          * "ADB-PMU" used in the Mac Portable and all 680x0-based PowerBooks.
4747          * "ADB-EGRET" used in the IIsi, IIvi, IIvx, Classic II, LC, LC II, LC III, Performa 460,
4848             and Performa 600.  This is a 68HC05 with a different internal ROM than CUDA.
r6327r6328
5050            Quadra 900, and Quadra 950.
5151          * "ADB-CUDA" (Apple's CUDA chip, which is a 68HC05 MCU) used in the Color Classic, LC 520,
5252            LC 55x, LC 57x, LC 58x, Quadra 630, Quadra 660AV, Quadra 840AV, PowerMac 6100/7100/8100,
53            IIcx, IIci, and PowerMac 5200.
53            IIci, and PowerMac 5200.
5454
5555`    TODO:
5656        - Mac Portable and PowerBook 100 are similar to this hardware, but we need ROMs!
r6327r6328
7676#include "debug/debugcpu.h"
7777#include "devices/messram.h"
7878
79#define ADB_IS_BITBANG   (mac_model >= MODEL_MAC_SE && mac_model <= MODEL_MAC_CLASSIC) || (mac_model >= MODEL_MAC_II && mac_model <= MODEL_MAC_IICX) || (mac_model == MODEL_MAC_SE30)
80#define ADB_IS_EGRET   (mac_model >= MODEL_MAC_LC && mac_model <= MODEL_MAC_COLOR_CLASSIC) || (mac_model == MODEL_MAC_IICI) || (mac_model == MODEL_MAC_IISI)
81
7982#ifdef MAME_DEBUG
8083#define LOG_VIA         0
8184#define LOG_RTC         0
r6327r6328
99102#define ADB_STATE_XFER_EVEN   (1)
100103#define ADB_STATE_XFER_ODD   (2)
101104#define ADB_STATE_IDLE      (3)
105#define ADB_STATE_NOTINIT   (4)
102106
103107// ADB commands
104108#define ADB_CMD_RESET      (0)
r6327r6328
229233
230234   memory_set_bankptr(machine,bank, memory_data);
231235
232   if (LOG_MEMORY)
236   if (1) //LOG_MEMORY)
233237   {
234238      logerror("mac_install_memory(): bank=%d range=[0x%06x...0x%06x] mask=0x%06x ptr=0x%p\n",
235239         bank, memory_begin, memory_end, memory_mask, memory_data);
r6327r6328
369373      /* install the memory */
370374      if (((mac_model >= MODEL_MAC_LC) && (mac_model <= MODEL_MAC_COLOR_CLASSIC))|| (mac_model == MODEL_MAC_LC_II))
371375      {
372         mac_install_memory(machine, 0x00000000, 0x009fffff, memory_size, memory_data, is_rom, 1);
376         mac_install_memory(machine, 0x00000000, memory_size-1, memory_size, memory_data, is_rom, 1);
373377      }
374378      else if ((mac_model == MODEL_MAC_IICI) || (mac_model == MODEL_MAC_IISI))
375379      {
r6327r6328
13121316      {
13131317         if (LOG_RTC)
13141318            logerror("trashing PRAM\n");
1319
1320         memset(rtc_ram, 0, sizeof(rtc_ram));
1321
1322         // some Mac ROMs are buggy in the presence of
1323         // no NVRAM, so let's initialize it right
1324         rtc_ram[0] = 0xa8;   // valid
1325         rtc_ram[4] = 0xcc;
1326         rtc_ram[5] = 0x0a;
1327         rtc_ram[6] = 0xcc;
1328         rtc_ram[7] = 0x0a;
1329         rtc_ram[0xc] = 0x42;    // XPRAM valid for Plus/SE
1330         rtc_ram[0xd] = 0x75;
1331         rtc_ram[0xe] = 0x67;
1332         rtc_ram[0xf] = 0x73;
1333         rtc_ram[0x10] = 0x18;
1334         rtc_ram[0x11] = 0x88;
1335         rtc_ram[0x12] = 0x01;
1336         rtc_ram[0x13] = 0x4c;
1337
1338         if (mac_model >= MODEL_MAC_II)
1339         {
1340            rtc_ram[0xc] = 0x4e;    // XPRAM valid is different for these
1341            rtc_ram[0xd] = 0x75;
1342            rtc_ram[0xe] = 0x4d;
1343            rtc_ram[0xf] = 0x63;
1344            rtc_ram[0x77] = 0x01;
1345            rtc_ram[0x78] = 0xff;
1346            rtc_ram[0x79] = 0xff;
1347            rtc_ram[0x7a] = 0xff;
1348            rtc_ram[0x7b] = 0xdf;
1349         }
13151350      }
13161351
13171352      {
r6327r6328
13871422 * *************************************************************************/
13881423
13891424// Mac ADB state
1390static int adb_irq_pending, adb_waiting_cmd, adb_datasize, adb_buffer[8];
1425static int adb_irq_pending, adb_waiting_cmd, adb_datasize, adb_buffer[16];
13911426static int adb_state, adb_command, adb_send, adb_timer_ticks, adb_extclock, adb_direction;
1392static int adb_listenreg, adb_listenaddr;
1427static int adb_listenreg, adb_listenaddr, adb_last_talk;
13931428
13941429// ADB mouse state
13951430static int adb_mouseaddr = 3;
r6327r6328
14071442{
14081443   int NewX, NewY, NewButton;
14091444
1445   if (!adb_mouse_initialized)
1446   {
1447      return;
1448   }
1449
14101450   NewButton = input_port_read(machine, "MOUSE0") & 0x01;
14111451   NewX = input_port_read(machine, "MOUSE2");
14121452   NewY = input_port_read(machine, "MOUSE1");
r6327r6328
14951535
14961536                  adb_direction = 0;
14971537                  adb_send = 0;
1498
1499                  #if 0
1500                  adb_buffer[0] = 0xff;
1501                  adb_datasize = 1;
1502
1503                  // it's not documented how to respond, but yanking SRQ seems to work
1504                  adb_extclock ^= 1;
1505                  via_cb1_w(via_0, 0, adb_extclock);
1506                  adb_extclock ^= 1;
1507                  via_cb1_w(via_0, 0, adb_extclock);
1508                  #endif
15091538                  break;
15101539
15111540               default:   // reserved/unused
r6327r6328
15211550            adb_direction = 1;   // input from Mac
15221551            adb_listenreg = reg;
15231552            adb_listenaddr = addr;
1553            adb_command = 0;
15241554            break;
15251555
15261556         case 3: // talk
r6327r6328
15281558            printf("ADB TALK: reg %x address %x\n", reg, addr);
15291559            #endif
15301560
1561            // keep track of what device the Mac last TALKed to
1562            adb_last_talk = addr;
1563
15311564            adb_direction = 0;       // output to Mac
15321565            if (addr == adb_mouseaddr)
15331566            {
r6327r6328
16001633               #if LOG_ADB
16011634               printf("ADB: talking to unconnected device\n");
16021635               #endif
1603               adb_buffer[0] = adb_buffer[1] = 0xff;
1636               adb_buffer[0] = adb_buffer[1] = 0;
16041637               adb_datasize = 0;
16051638            }
16061639            break;
r6327r6328
16101643   }
16111644   else
16121645   {
1613      printf("Got LISTEN data %x for device %x reg %x\n", adb_command, adb_listenreg, adb_listenaddr);
1646      #if LOG_ADB
1647      printf("Got LISTEN data %x for device %x reg %x\n", adb_command, adb_listenaddr, adb_listenreg);
1648      #endif
1649#if 0
1650      if (adb_listenaddr == adb_mouseaddr)
1651      {
1652         if ((adb_listenreg == 3) && (adb_command > 0) && (adb_command < 16))
1653         {
1654            #if LOG_ADB
1655             printf("MOUSE: moving to address %x\n", adb_command);
1656            #endif
1657            adb_mouseaddr = adb_command&0x0f;
1658         }
1659      }
1660      else if (adb_listenaddr == adb_keybaddr)
1661      {
1662         if ((adb_listenreg == 3) && (adb_command > 0) && (adb_command < 16))
1663         {
1664            #if LOG_ADB
1665             printf("KEYBOARD: moving to address %x\n", adb_command);
1666            #endif
1667            adb_keybaddr = adb_command&0x0f;
1668         }
1669      }
1670#endif
16141671   }
16151672}
16161673
r6327r6328
16291686   {
16301687      timer_adjust_oneshot(mac_adb_timer, attotime_never, 0);
16311688
1632      if (adb_direction)
1689      if ((adb_direction) && (ADB_IS_BITBANG))
16331690      {
16341691         mac_adb_talk(machine);
16351692      }
1693      else if (ADB_IS_EGRET)
1694      {
1695         #if LOG_ADB
1696         printf("Egret ADB: got command byte %02x\n", adb_command);
1697         #endif
1698      }
16361699   }
16371700   else
16381701   {
r6327r6328
16541717
16551718static WRITE8_DEVICE_HANDLER(mac_adb_via_out_cb2)
16561719{
1657//  printf("OUT CB2 = %x\n", data);
1720//      printf("OUT CB2 = %x\n", data);
16581721   adb_command <<= 1;
16591722   adb_command |= data & 1;
16601723}
r6327r6328
16761739            adb_command = adb_send = 0;
16771740            adb_direction = 1;   // Mac is shifting us a command
16781741            adb_waiting_cmd = 1;   // we're going to get a command
1742            adb_irq_pending = 0;
16791743            timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
16801744            break;
16811745
r6327r6328
16981762                     adb_buffer[i] = adb_buffer[i+1];
16991763                  }
17001764               }
1765
17011766            }
17021767            else
17031768            {
17041769               adb_send = 0;
1770               adb_irq_pending = 1;
17051771            }
17061772
17071773            timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
17081774            break;
17091775
17101776         case ADB_STATE_IDLE:
1777            adb_irq_pending = 0;
1778            timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
17111779            break;
17121780      }
17131781   }
17141782}
17151783
1784static void mac_egret_newaction(int state)
1785{
1786   if (state != adb_state)
1787   {
1788      #if LOG_ADB
1789      printf("ADB: New Egret state: SS %d VF %d XS %d\n", (state>>2)&1, (state>>1)&1, state&1);
1790      #endif
1791     
1792      // rising edge of VIA bit 5 (bit 2 here) seems to mean the 68k wants to send something
1793      if ((state & 0x04) && !(adb_state & 0x4))
1794      {
1795         adb_command = adb_send = 0;
1796         adb_timer_ticks = 8;
1797         timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
1798      }
1799
1800      adb_state = state;
1801   }
1802}
1803
17161804static void adb_vblank(running_machine *machine)
17171805{
17181806   // if any device has a service request, show it on the VIA
17191807   // (no need to actually generate an IRQ, the Mac will see it)
17201808   if ((adb_mouse_wanted_srq) || (adb_keyb_wanted_srq))
17211809   {
1722//      printf("ADB IRQ: kb %d ms %d\n", adb_keyb_wanted_srq, adb_mouse_wanted_srq);
1810//      printf("ADB IRQ: kb %d ms %d (last talk %d)\n", adb_keyb_wanted_srq, adb_mouse_wanted_srq, adb_last_talk);
17231811      adb_irq_pending = 1;
17241812   }
17251813   else
r6327r6328
17291817
17301818      if ((adb_state == ADB_STATE_IDLE) && (adb_mouse_wanted_srq))
17311819      {
1732         // repeat last TALK to get updated data
1733         adb_waiting_cmd = 1;
1734         mac_adb_talk(machine);
1820         // if the mouse was the last TALK, we can just send the new data
1821         // otherwise we need to pull SRQ
1822         if (adb_last_talk == adb_mouseaddr)
1823         {
1824            // repeat last TALK to get updated data
1825            adb_waiting_cmd = 1;
1826            mac_adb_talk(machine);
17351827
1736         adb_timer_ticks = 8;
1737         timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
1738         adb_mouse_wanted_srq = 0;
1828            adb_timer_ticks = 8;
1829            timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
1830            adb_mouse_wanted_srq = 0;
1831         }
1832         #if 0
1833         else
1834         {
1835            printf("IDLE, mouse moved, mouse not last TALK, pulling SRQ\n");
1836            adb_irq_pending = 1;
1837
1838            adb_command = adb_send = 0;
1839            adb_timer_ticks = 8;
1840            timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
1841         }
1842         #endif
17391843      }
17401844   }
17411845}
r6327r6328
17481852   adb_extclock = 0;
17491853   adb_send = 0;
17501854   adb_waiting_cmd = 0;
1751   adb_state = ADB_STATE_IDLE;
1855   adb_state = ADB_STATE_NOTINIT;
17521856   adb_direction = 0;
17531857   adb_datasize = 0;
1754
1858   adb_last_talk = -1;
1859   
17551860   // mouse
17561861   adb_mouseaddr = 3;
17571862   adb_lastmousex = adb_lastmousey = adb_lastbutton = 0;
r6327r6328
17591864   adb_mouse_initialized = 0;
17601865
17611866   // keyboard
1762   adb_keybaddr = 2;
1867   adb_keybaddr = 2;             
17631868   adb_keyb_wanted_srq = 0;
17641869   adb_keybinitialized = 0;
17651870}
r6327r6328
18051910//   printf("VIA1 IN_A (PC %x)\n", cpu_get_pc(cputag_get_cpu(device->machine, "maincpu")));
18061911
18071912   if ((mac_model == MODEL_MAC_CLASSIC) ||
1808       (mac_model == MODEL_MAC_LC_II) || (mac_model == MODEL_MAC_II) ||
1809       (mac_model == MODEL_MAC_II_FDHD) || (mac_model == MODEL_MAC_IIX))
1913       (mac_model == MODEL_MAC_II) || (mac_model == MODEL_MAC_II_FDHD) ||
1914       (mac_model == MODEL_MAC_IIX))
18101915   {
18111916      return 0x81;      // bit 0 must be set to avoid attempting to boot from AppleTalk
18121917   }
r6327r6328
18161921      return 0x81 | PA6;
18171922   }
18181923
1819   if (mac_model == MODEL_MAC_LC)
1924   if ((mac_model == MODEL_MAC_LC) || (mac_model == MODEL_MAC_LC_II))   // these both use the V8 ASIC and should in theory ID the same
18201925   {
18211926      return 0x81 | PA6 | PA4 | PA2;
18221927   }
r6327r6328
18481953{
18491954   int val = 0;
18501955
1851//   printf("VIA1 IN_B (PC %x)\n", cpu_get_pc(cputag_get_cpu(device->machine, "maincpu")));
1852
18531956   /* video beam in display (! VBLANK && ! HBLANK basically) */
18541957   if (video_screen_get_vpos(device->machine->primary_screen) >= MAC_V_VIS)
18551958      val |= 0x40;
18561959
1857   if (has_adb())
1960   if ((ADB_IS_BITBANG) || (ADB_IS_EGRET))
18581961   {
18591962      val |= adb_state<<4;
18601963
r6327r6328
18751978   if (rtc_data_out)
18761979      val |= 1;
18771980
1981//   printf("VIA1 IN_B = %02x (PC %x)\n", val, cpu_get_pc(cputag_get_cpu(device->machine, "maincpu")));
1982
18781983   return val;
18791984}
18801985
r6327r6328
19472052      rtc_shift_data(data & 0x01);
19482053   rtc_rTCClk = new_rtc_rTCClk;
19492054
1950   if (has_adb())
2055   if (ADB_IS_BITBANG)
19512056   {
19522057      mac_adb_newaction((data & 0x30) >> 4);
19532058   }
2059   else if (ADB_IS_EGRET)
2060   {
2061      mac_egret_newaction((data & 0x38) >> 3);
2062   }
19542063}
19552064
19562065static void mac_via_irq(const device_config *device, int state)
r6327r6328
20062115   offset &= 0x0f;
20072116
20082117   if (LOG_VIA)
2009      logerror("mac_via2_r: offset=0x%02x\n", offset);
2118      logerror("mac_via2_r: offset=0x%02x\n", offset*2);
20102119   data = via_r(via_1, offset);
20112120
20122121   return (data & 0xff) | (data << 8);
r6327r6328
20202129   offset &= 0x0f;   
20212130
20222131   if (LOG_VIA)
2023      logerror("mac_via2_w: offset=0x%02x data=0x%08x\n", offset, data);
2132      logerror("mac_via2_w: offset=%x data=0x%08x\n", offset, data);
20242133
20252134   if (ACCESSING_BITS_8_15)
20262135      via_w(via_1, offset, (data >> 8) & 0xff);
r6327r6328
20432152{
20442153//   logerror("VIA2 IN B (PC %x)\n", cpu_get_pc(cputag_get_cpu(device->machine, "maincpu")));
20452154
2155   if ((mac_model == MODEL_MAC_LC) || (mac_model == MODEL_MAC_LC_II))
2156   {
2157      return 0x4f;
2158   }
2159
20462160   if (mac_model == MODEL_MAC_SE30)
20472161   {
20482162      return 0x87;   // bits 3 and 6 are tied low on SE/30
r6327r6328
20622176
20632177//   logerror("VIA2 OUT B: %02x (PC %x)\n", data, cpu_get_pc(cputag_get_cpu(device->machine, "maincpu")));
20642178
2179//   printf("VIA2 OUT B: %02x (MMU = %02x)\n", data, data & 0x08);
2180
20652181   // chain 60.15 Hz to VIA1
20662182   via_ca1_w(via_0, 0, data>>7);
20672183}
r6327r6328
21752291   }
21762292   else if ((model == MODEL_MAC_LC) || (model == MODEL_MAC_LC_II))
21772293   {
2178      mac_install_memory(machine, 0x000000, 0x9fffff, messram_get_size(devtag_get_device(machine, "messram")), messram_get_ptr(devtag_get_device(machine, "messram")), FALSE, 2);
2294      mac_install_memory(machine, 0x000000, messram_get_size(devtag_get_device(machine, "messram"))-1, messram_get_size(devtag_get_device(machine, "messram")), messram_get_ptr(devtag_get_device(machine, "messram")), FALSE, 2);
21792295   }
21802296   else if ((mac_model == MODEL_MAC_CLASSIC_II) || ((mac_model >= MODEL_MAC_II) && (mac_model <= MODEL_MAC_SE30)))
21812297   {
src/mess/drivers/mac.c
r6327r6328
3535           PB_EXT  from mouse Y circuitry
3636           PA_EXT  from mouse X circuitry
3737
38RBV @ 43f80, alt 48000
38LC ram sizer: a46576, stores size at 7ffc
3939
4040****************************************************************************/
4141
r6327r6328
192192      if (rbv_count == 3)
193193      {
194194         rbv_count = 0;
195         rbv_clutoffs++;
196195         palette_set_color(space->machine, rbv_clutoffs, MAKE_RGB(rbv_colors[0], rbv_colors[1], rbv_colors[2]));
197196         rbv_palette[rbv_clutoffs] = MAKE_RGB(rbv_colors[0], rbv_colors[1], rbv_colors[2]);
197         rbv_clutoffs++;
198198      }
199199   }
200200}
r6327r6328
244244      via_w(via_1, offset, (data >> 8) & 0xff);
245245}
246246
247// LC/LC II "V8" video and friends
248
249static UINT8 v8_regs[256];
250static UINT32 v8_colors[3], v8_count, v8_clutoffs;
251static UINT32 v8_palette[256];
252
253static READ16_HANDLER ( mac_v8_r )
254{
255   int data, viaoffs;
256   const device_config *via_1 = devtag_get_device(space->machine, "via6522_1");
257
258   printf("v8_r: %x, mask %x (PC %x)\n", offset*2, mem_mask, cpu_get_pc(space->cpu));
259
260   viaoffs = (offset >> 8) & 0x0f;
261
262   switch (offset)
263   {
264      case 0:
265         data = via_r(via_1, viaoffs);
266         return (data<<8) | v8_regs[0];
267
268      default:
269         data = via_r(via_1, viaoffs);
270         return (data<<8)|data;
271   }
272
273}
274
275static WRITE16_HANDLER ( mac_v8_w )
276{
277   const device_config *via_1 = devtag_get_device(space->machine, "via6522_1");
278   int viaoffs;
279
280   printf("v8_w: %x to offset %x, mask %x (PC %x)\n", data, offset*2, mem_mask, cpu_get_pc(space->cpu));
281
282   viaoffs = (offset >> 8) & 0x0f;
283
284   switch (offset)
285   {
286      case 0:
287         if (ACCESSING_BITS_8_15)
288         {
289            via_w(via_1, viaoffs, (data >> 8) & 0xff);
290         }
291         else
292         {
293            v8_regs[0] = data&0xe7;
294         }
295         break;
296
297      default:
298         if (ACCESSING_BITS_8_15)
299         {
300            via_w(via_1, viaoffs, (data >> 8) & 0xff);
301         }
302         break;
303   }
304}
305
306static WRITE32_HANDLER( mac_v8_ramdac_w )
307{
308   if (mem_mask == 0xff000000)
309   {
310      v8_clutoffs = data>>24;
311      v8_count = 0;
312   }
313   else if (mem_mask == 0x00ff0000)
314   {
315      v8_colors[v8_count++] = data>>16;
316
317      if (v8_count == 3)
318      {
319         v8_count = 0;
320         palette_set_color(space->machine, v8_clutoffs, MAKE_RGB(v8_colors[0], v8_colors[1], v8_colors[2]));
321         v8_palette[v8_clutoffs] = MAKE_RGB(v8_colors[0], v8_colors[1], v8_colors[2]);
322         v8_clutoffs++;
323      }
324   }
325}
326
327static VIDEO_START( maclc )
328{
329   memset(v8_regs, 0, sizeof(v8_regs));
330
331   v8_regs[1] = 0x6;   // set init value
332}
333
334static VIDEO_UPDATE( maclc )
335{
336   return 0;
337}
338
247339/***************************************************************************
248340    ADDRESS MAPS
249341***************************************************************************/
r6327r6328
279371   // 50f18000-9fff = PWMs
280372
281373   // 50f24000-5fff = VDAC (palette)
282   AM_RANGE(0x50f24000, 0x50f25fff) AM_RAM
283   AM_RANGE(0x50f26000, 0x50f27fff) AM_READWRITE16(mac_via2_r, mac_via2_w, 0xffffffff)   // VIA2 (RBV)
374   AM_RANGE(0x50f24000, 0x50f24003) AM_WRITE(mac_v8_ramdac_w)
375   AM_RANGE(0x50f26000, 0x50f27fff) AM_READWRITE16(mac_v8_r, mac_v8_w, 0xffffffff)   // VIA2 (V8)
284376
285377   AM_RANGE(0xfeff8000, 0xfeffffff) AM_ROM AM_REGION("user1", 0x78000)
286378ADDRESS_MAP_END
r6327r6328
398490   AM_RANGE(0xfeff8000, 0xfeffffff) AM_ROM AM_REGION("user1", 0x78000)
399491ADDRESS_MAP_END
400492
401static VIDEO_START( maclc )
402{
403}
404
405static VIDEO_UPDATE( maclc )
406{
407   return 0;
408}
409
410
411493/***************************************************************************
412494    DEVICE CONFIG
413495***************************************************************************/

Previous 15994 Revisions Next


© 1998-2018 The MESS Team