Previous 15994 Revisions Next

r8332 Sunday 27th June, 2010 at 18:18:23 UTC by R. Belmont
[MAC] Fixed u2 regressions, greatly improved Egret MCU simulation. maclc2 almost boots.
[src/mess/drivers]mac.c
[src/mess/includes]mac.h
[src/mess/machine]mac.c

src/mess/machine/mac.c
r8331r8332
7878#include "devices/messram.h"
7979
8080#define ADB_IS_BITBANG   (mac->mac_model >= MODEL_MAC_SE && mac->mac_model <= MODEL_MAC_CLASSIC) || (mac->mac_model >= MODEL_MAC_II && mac->mac_model <= MODEL_MAC_IICX) || (mac->mac_model == MODEL_MAC_SE30)
81#define ADB_IS_EGRET   (mac->mac_model >= MODEL_MAC_LC && mac->mac_model <= MODEL_MAC_COLOR_CLASSIC) || (mac->mac_model == MODEL_MAC_IICI) || (mac->mac_model == MODEL_MAC_IISI)
81#define ADB_IS_EGRET   (mac->mac_model >= MODEL_MAC_LC && mac->mac_model <= MODEL_MAC_COLOR_CLASSIC) || (mac->mac_model == MODEL_MAC_IISI)
8282#define ADB_IS_PM   (mac->mac_model >= MODEL_MAC_PORTABLE && mac->mac_model <= MODEL_MAC_PB100)
8383
8484#ifdef MAME_DEBUG
r8331r8332
997997{
998998   running_device *scc = devtag_get_device(space->machine, "scc");
999999   UINT8 wdata = data>>8;
1000
10011000   scc8530_w(scc, offset, wdata);
10021001}
10031002
r8331r8332
17981797         // Egret sending a response to the 680x0?
17991798         if (mac->adb_state & 1)
18001799         {
1801            mac->adb_send = mac->adb_buffer[mac->adb_datasize];
1802            #if LOG_ADB
1803            printf("Egret ADB: done sending byte %02x, %d left\n", mac->adb_send, mac->adb_datasize);
1804            #endif
1800            if (mac->adb_datasize > 0)
1801            {
1802               mac->adb_send = mac->adb_buffer[mac->adb_datasize];
1803               #if LOG_ADB
1804               printf("Egret ADB: sending byte %02x, %d left\n", mac->adb_send, mac->adb_datasize-1);
1805               #endif
18051806
1806            mac->adb_datasize--;
1807            mac->adb_timer_ticks = 8;
1808            timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
1807               mac->adb_datasize--;
1808            }
1809            else
1810            {
1811               switch (mac->adb_streaming)
1812               {
1813                  case MCU_STREAMING_PRAMRD:
1814                     #if LOG_ADB
1815                     printf("Egret ADB: streaming PRAM byte %02x = %02x\n", mac->adb_stream_ptr, mac->rtc_ram[mac->adb_stream_ptr]);
1816                     #endif
1817                     mac->adb_send = mac->rtc_ram[mac->adb_stream_ptr++];
1818                     if (mac->adb_stream_ptr >= 256)
1819                     {
1820                        #if LOG_ADB
1821                        printf("Egret ADB: this is the last PRAM byte, dropping XS\n");
1822                        #endif
1823                        mac->adb_state &= ~1;
1824                     }
1825                     break;
18091826
1810            if (mac->adb_datasize == 0)
1827                  default:
1828                     #if LOG_ADB
1829                     printf("Egret ADB: trying to stream unhandled type\n");
1830                     #endif
1831                     mac->adb_send = 0;
1832                     break;
1833               }
1834            }
1835
1836//            mac->adb_timer_ticks = 8;
1837//            timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
1838
1839            if ((mac->adb_datasize == 0) && (mac->adb_streaming == MCU_STREAMING_NONE))
18111840            {
18121841               #if LOG_ADB
18131842               printf("Egret ADB: this is the last byte, dropping XS\n");
r8331r8332
18171846         }
18181847         else
18191848         {
1820            #if LOG_ADB
1821            printf("Egret ADB: got command byte %02x\n", mac->adb_command);
1822            #endif
1823            mac->adb_buffer[mac->adb_datasize++] = mac->adb_command;
1824            mac->adb_command = 0;
1849            // it's not a command byte if SS is low
1850            if (mac->adb_state & 0x02)
1851            {
1852               #if LOG_ADB
1853               printf("Egret ADB: got command byte %02x [%02x]\n", mac->adb_command, mac->adb_datasize);
1854               #endif
1855               mac->adb_buffer[mac->adb_datasize++] = mac->adb_command;
1856               mac->adb_command = 0;
1857            }
18251858         }
18261859      }
18271860   }
r8331r8332
18391872   ret = (mac->adb_send & 0x80)>>7;
18401873   mac->adb_send <<= 1;
18411874
1842//  printf("IN CB2 = %x\n", ret);
1875//   printf("VIA IN CB2 = %x\n", ret);
18431876
18441877   return ret;
18451878}
r8331r8332
18481881{
18491882   mac_state *mac = (mac_state *)device->machine->driver_data;
18501883
1851//      printf("OUT CB2 = %x\n", data);
1884//        printf("VIA OUT CB2 = %x\n", data);
18521885   mac->adb_command <<= 1;
18531886   mac->adb_command |= data & 1;
18541887}
r8331r8332
19251958
19261959static void mac_egret_response_read_pram(mac_state *mac, int addr)
19271960{
1928   int count = 0x100 - addr;
1961   mac->adb_datasize = 4;
19291962
1930   mac->adb_datasize = count+3;
1963   mac->adb_send = 0xaa;
1964   mac->adb_buffer[4] = 1;   // type
1965   mac->adb_buffer[3] = 0;   // flag
1966   mac->adb_buffer[2] = 7;   // command
1967   mac->adb_buffer[1] = mac->rtc_ram[addr];
19311968
1932   mac->adb_buffer[count+3] = 1;
1933   mac->adb_buffer[count+2] = 0;
1934   mac->adb_buffer[count+1] = 7;
1935   while (count)
1936   {
1937      mac->adb_buffer[count] = mac->rtc_ram[addr];
1938      addr++;
1939      count--;
1940   }
1941
1942   mac->adb_send = 0xaa;
19431969   mac->adb_state |= 1;
19441970   mac->adb_timer_ticks = 8;
19451971   timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
1972
1973   // read PRAM is a "streaming" command, don't drop the state line when we're out of data
1974   mac->adb_streaming = MCU_STREAMING_PRAMRD;
1975   mac->adb_stream_ptr = addr+1;
19461976}
19471977
19481978static void mac_egret_mcu_exec(mac_state *mac)
19491979{
1980   mac->adb_streaming = MCU_STREAMING_NONE;
19501981   switch (mac->adb_buffer[1])
19511982   {
19521983      case 0x01:   // enable/disable ADB auto-polling
r8331r8332
19722003         mac_egret_response_read_pram(mac, mac->adb_buffer[2]<<8 | mac->adb_buffer[3]);
19732004         break;
19742005
2006      case 0x08: // write 6805 address
2007         {
2008            int addr = mac->adb_buffer[2]<<8 | mac->adb_buffer[3];
2009            int len = mac->adb_datasize - 4;
2010
2011            #if LOG_ADB
2012            printf("ADB: Egret write %d bytes to address %x\n", len, addr);
2013            #endif
2014
2015            // check if this is a sneaky PRAM write (PRAM is at 6805 address 0x100)
2016            if ((addr >= 0x100) && (addr <= 0x200))
2017            {
2018               for (int i = 0; i < len; i++)
2019               {
2020                  mac->rtc_ram[(addr-0x100)+i] = mac->adb_buffer[4+i];
2021               }
2022            }
2023            #if LOG_ADB
2024            else
2025            {
2026               printf("ADB: Egret unhandled direct write\n");
2027            }
2028            #endif
2029
2030            mac_egret_response_std(mac, 1, 0, 0x08);
2031         }
2032         break;
2033
2034      case 0x0c: // write PRAM
2035         #if LOG_ADB
2036         printf("ADB: Egret write %02x to PRAM at %x\n", mac->adb_buffer[4], mac->adb_buffer[2]<<8 | mac->adb_buffer[3]);
2037         #endif
2038
2039         mac->rtc_ram[mac->adb_buffer[2]<<8 | mac->adb_buffer[3]] = mac->adb_buffer[4];
2040
2041         mac->adb_datasize = 4;
2042         mac->adb_buffer[4] = 1;   // type
2043         mac->adb_buffer[3] = 0;   // flag
2044         mac->adb_buffer[2] = 0x0c;   // command
2045         mac->adb_buffer[1] = 0;   // spare
2046         mac->adb_state |= 1;
2047         mac->adb_timer_ticks = 8;
2048         timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
2049         break;
2050
19752051      case 0x0e: // send to DFAC
19762052         #if LOG_ADB
19772053         printf("ADB: Egret send %02x to DFAC\n", mac->adb_buffer[2]);
r8331r8332
20232099   if (state != mac->adb_state)
20242100   {
20252101      #if LOG_ADB
2026      printf("ADB: New Egret state: SS %d VF %d XS %d\n", (state>>2)&1, (state>>1)&1, mac->adb_state&1);
2102      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);
20272103      #endif
20282104
2029      // if bit 2 is high and stays high, the rising edge of bit 1 indicates the start of sending a command
2030      if ((state & 0x04) && (mac->adb_state & 0x04) && (state & 0x02) && !(mac->adb_state & 0x02))
2105      // 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
2106      if ((state & 0x04) && (mac->adb_state & 0x04) && (state & 0x02) && !(mac->adb_state & 0x02) && !(mac->adb_state & 0x01))
20312107      {
2032         mac->adb_command = mac->adb_send = 0;
2108         mac->adb_command = 0;
20332109         mac->adb_timer_ticks = 8;
20342110         timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
20352111      }
20362112
2113      // 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
2114      if ((state & 0x04) && (mac->adb_state & 0x04) && !(state & 0x02) && (mac->adb_state & 0x02) && (mac->adb_state & 0x01))
2115      {
2116         mac->adb_timer_ticks = 8;
2117         timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
2118      }
2119
2120      // if bit 2 rises, bit 1 is 0, and MCU XS is high, the MCU should clock out a byte
2121      if ((state & 0x04) && !(mac->adb_state & 0x04) && !(state & 0x02) && (mac->adb_state & 0x01))
2122      {
2123         mac->adb_timer_ticks = 8;
2124         timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0);
2125      }
2126
2127      // if bit 2 drops and bit 1 is 1, terminate the command
2128      if ((state & 0x02) && !(state & 0x04) && (mac->adb_state & 0x04))
2129      {
2130         #if LOG_ADB
2131         printf("Egret ADB: SESSION dropped with VF=1, terminating command\n");
2132         #endif
2133         mac->adb_streaming = MCU_STREAMING_NONE;
2134         mac->adb_state &= ~1;
2135         mac->adb_datasize = 0;
2136      }
2137
20372138      // if bit 2 drops and bit 1 is zero, execute the command
2038      if (!(state & 0x02) && !(state & 0x04) && (mac->adb_state & 0x04) && (mac->adb_datasize))
2139      if (!(state & 0x02) && !(state & 0x04) && (mac->adb_state & 0x04) && (mac->adb_datasize > 0))
20392140      {
20402141         #if LOG_ADB
20412142         int i;
20422143
2043         printf("ADB: Egret exec command with %d bytes: ", mac->adb_datasize);
2144         printf("Egret ADB: exec command with %d bytes: ", mac->adb_datasize);
20442145
20452146         for (i = 0; i < mac->adb_datasize; i++)
20462147         {
r8331r8332
21382239   mac->adb_extclock = 0;
21392240   mac->adb_send = 0;
21402241   mac->adb_waiting_cmd = 0;
2242   mac->adb_streaming = MCU_STREAMING_NONE;
21412243   if (ADB_IS_BITBANG)
21422244   {
21432245      mac->adb_state = ADB_STATE_NOTINIT;
src/mess/includes/mac.h
r8331r8332
1212#include "machine/8530scc.h"
1313#include "machine/6522via.h"
1414
15/* for Egret and CUDA streaming MCU commands, command types */
16typedef enum
17{
18   MCU_STREAMING_NONE = 0,
19   MCU_STREAMING_PRAMRD,
20   MCU_STREAMING_PRAMWR,
21   MCU_STREAMING_WRAMRD,
22   MCU_STREAMING_WRAMWR
23} mac_streaming_t;
24
1525/* tells which model is being emulated (set by macxxx_init) */
1626typedef enum
1727{
r8331r8332
239249   INT32 adb_irq_pending, adb_waiting_cmd, adb_datasize, adb_buffer[257];
240250   INT32 adb_state, adb_command, adb_send, adb_timer_ticks, adb_extclock, adb_direction;
241251   INT32 adb_listenreg, adb_listenaddr, adb_last_talk, adb_srq_switch;
252   INT32 adb_streaming, adb_stream_ptr;
242253
243254   // Portable/PB100 Power Manager IC comms (chapter 4, "Guide to the Macintosh Family Hardware", second edition)
244255   UINT8 pm_data_send, pm_data_recv, pm_ack, pm_req;
src/mess/drivers/mac.c
r8331r8332
55
66    Nate Woods, Raphael Nabet, R. Belmont
77
8
98        0x000000 - 0x3fffff     RAM/ROM (switches based on overlay)
109        0x400000 - 0x4fffff     ROM
1110        0x580000 - 0x5fffff     5380 NCR/Symbios SCSI peripherals chip (Mac Plus only)
r8331r8332
8584{
8685   mac_state *mac = (mac_state *)space->machine->driver_data;
8786
88//  logerror("ASC: Read @ %x (PC %x)\n", offset, cpu_get_pc(devtag_get_device(space->machine, "maincpu")));
87   logerror("ASC: Read @ %x (PC %x)\n", offset, cpu_get_pc(devtag_get_device(space->machine, "maincpu")));
8988
9089   switch (offset)
9190   {
92      case 0:   // VERSION
91      case 0x800:   // VERSION
92         // LC/LCII return 0xe8 (V8 ASIC ASC emulation)
93         if ((mac->mac_model == MODEL_MAC_LC) || (mac->mac_model == MODEL_MAC_LC_II))
94               {
95            return 0xe8;
96         }
97
98         // LCIII returns 0xbc (Sonora ASIC ASC emulation)
99         if (mac->mac_model == MODEL_MAC_LC_III)
100         {
101            return 0xbc;
102         }
103
93104         return 0;   // original ASC
94105
106      case 0x804:
107         if ((mac->mac_model == MODEL_MAC_LC) || (mac->mac_model == MODEL_MAC_LC_II))
108               {
109            return 3;
110         }
111         break;
112
95113      default:
96114         break;
97115   }
r8331r8332
105123   INT32 i;
106124   mac_state *mac = (mac_state *)space->machine->driver_data;
107125
108//  logerror("ASC: %02x to %x (PC %x)\n", data, offset, cpu_get_pc(devtag_get_device(space->machine, "maincpu")));
126   logerror("ASC: %02x to %x (PC %x)\n", data, offset, cpu_get_pc(devtag_get_device(space->machine, "maincpu")));
109127
110128   mac->mac_asc_regs[offset] = data;
111129
r8331r8332
874892
875893   MDRV_CPU_REPLACE("maincpu", M68030, 7833600*2)
876894   MDRV_CPU_PROGRAM_MAP(macii_map)
895   MDRV_CPU_VBLANK_INT("screen", mac_cb264_vbl)
877896
878897   MDRV_RAM_MODIFY("messram")
879898   MDRV_RAM_DEFAULT_SIZE("2M")

Previous 15994 Revisions Next


© 1998-2018 The MESS Team