Previous 15994 Revisions Next

r9346 Saturday 9th October, 2010 at 22:09:43 UTC by R. Belmont
[MAC] Some reorganization of the code
[src/mess/drivers]mac.c
[src/mess/includes]mac.h
[src/mess/machine]mac.c
[src/mess/video]mac.c

src/mess/machine/mac.c
r9345r9346
8585#define AUDIO_IS_CLASSIC (mac->mac_model < MODEL_MAC_II) && (mac->mac_model != MODEL_MAC_PORTABLE) && (mac->mac_model != MODEL_MAC_PB100)
8686#define MAC_HAS_VIA2   (mac->mac_model >= MODEL_MAC_II)
8787
88#define ASC_INTS_RBV   ((mac->mac_model == MODEL_MAC_IICI) || (mac->mac_model == MODEL_MAC_IISI) || (mac->mac_model >= MODEL_MAC_LC && mac->mac_model <= MODEL_MAC_COLOR_CLASSIC))
89
8890#ifdef MAME_DEBUG
8991#define LOG_VIA         0
9092#define LOG_RTC         0
r9345r9346
102104#endif
103105
104106#define LOG_ADB         0
107#define LOG_ADB_MCU_CMD      0
105108
106109// ADB states
107110#define ADB_STATE_NEW_COMMAND   (0)
r9345r9346
308311{
309312   mac_state *mac = device->machine->driver_data<mac_state>();
310313
311   if (mac->mac_model >= MODEL_MAC_II)
314   if (ASC_INTS_RBV)
312315   {
316      mac->rbv_regs[3] |= 0x90;   // any VIA 2 interrupt | sound interrupt
317
318      // (need to figure out what gets triggered here)
319   }
320   else if (mac->mac_model >= MODEL_MAC_II)
321   {
313322      via6522_device *via2 = device->machine->device<via6522_device>("via6522_1");
314323
315324      via2->write_cb1(state^1);
r9345r9346
20982107   switch (mac->adb_buffer[1])
20992108   {
21002109      case 0x01:   // enable/disable ADB auto-polling
2101         #if LOG_ADB
2110         #if LOG_ADB || LOG_ADB_MCU_CMD
21022111         if (mac->adb_buffer[2])
21032112         {
21042113            printf("ADB: Egret enable ADB auto-poll\n");
r9345r9346
21162125         {
21172126            int addr = mac->adb_buffer[2]<<8 | mac->adb_buffer[3];
21182127
2119            #if LOG_ADB
2128            #if LOG_ADB || LOG_ADB_MCU_CMD
21202129            printf("ADB: Egret read 6805 address %x\n", addr);
21212130            #endif
21222131
r9345r9346
21352144         break;
21362145
21372146      case 0x03: // read RTC
2138         #if LOG_ADB
2147         #if LOG_ADB || LOG_ADB_MCU_CMD
21392148         printf("ADB: Egret read RTC = %08x\n", mac->rtc_seconds[3]<<24|mac->rtc_seconds[2]<<16|mac->rtc_seconds[1]<<8|mac->rtc_seconds[0]);
21402149         #endif
21412150
r9345r9346
21432152         break;
21442153
21452154      case 0x07: // read PRAM
2146         #if LOG_ADB
2155         #if LOG_ADB || LOG_ADB_MCU_CMD
21472156         printf("ADB: Egret read PRAM from %x\n", mac->adb_buffer[2]<<8 | mac->adb_buffer[3]);
21482157         #endif
21492158
r9345r9346
21552164            int addr = mac->adb_buffer[2]<<8 | mac->adb_buffer[3];
21562165            int len = mac->adb_datasize - 4;
21572166
2158            #if LOG_ADB
2167            #if LOG_ADB || LOG_ADB_MCU_CMD
21592168            printf("ADB: Egret write %d bytes to address %x\n", len, addr);
21602169            #endif
21612170
r9345r9346
21672176                  mac->rtc_ram[(addr-0x100)+i] = mac->adb_buffer[4+i];
21682177               }
21692178            }
2170            #if LOG_ADB
2179            #if LOG_ADB || LOG_ADB_MCU_CMD
21712180            else
21722181            {
21732182               printf("ADB: Egret unhandled direct write @ %x\n", addr);
r9345r9346
21792188         break;
21802189
21812190      case 0x0c: // write PRAM
2182         #if LOG_ADB
2191         #if LOG_ADB || LOG_ADB_MCU_CMD
21832192         printf("ADB: Egret write %02x to PRAM at %x\n", mac->adb_buffer[4], mac->adb_buffer[2]<<8 | mac->adb_buffer[3]);
21842193         #endif
21852194
r9345r9346
21962205         break;
21972206
21982207      case 0x0e: // send to DFAC
2199         #if LOG_ADB
2208         #if LOG_ADB || LOG_ADB_MCU_CMD
22002209         printf("ADB: Egret send %02x to DFAC\n", mac->adb_buffer[2]);
22012210         #endif
22022211
r9345r9346
22042213         break;
22052214
22062215      case 0x1b: // set one-second interrupt
2207         #if LOG_ADB
2216         #if LOG_ADB || LOG_ADB_MCU_CMD
22082217         if (mac->adb_buffer[2])
22092218         {
22102219            printf("ADB: Egret enable one-second IRQ\n");
r9345r9346
22192228         break;
22202229
22212230      case 0x1c:   // enable/disable keyboard NMI
2222         #if LOG_ADB
2231         #if LOG_ADB || LOG_ADB_MCU_CMD
22232232         if (mac->adb_buffer[2])
22242233         {
22252234            printf("ADB: Egret enable keyboard NMI\n");
r9345r9346
22342243         break;
22352244
22362245      default:
2237         #if LOG_ADB
2246         #if LOG_ADB || LOG_ADB_MCU_CMD
22382247         printf("ADB: Unknown Egret MCU command %02x\n", mac->adb_buffer[1]);
22392248         #endif
22402249         break;
r9345r9346
22852294      // if bit 2 drops and bit 1 is zero, execute the command
22862295      if (!(state & 0x02) && !(state & 0x04) && (mac->adb_state & 0x04) && (mac->adb_datasize > 0))
22872296      {
2288         #if LOG_ADB
2297         #if LOG_ADB || LOG_ADB_MCU_CMD
22892298         int i;
22902299
22912300         printf("Egret ADB: exec command with %d bytes: ", mac->adb_datasize);
r9345r9346
23022311         switch (mac->adb_buffer[0])
23032312         {
23042313            case 0:   // ADB command
2305               mac->adb_datasize = 0;
2314               switch (mac->adb_buffer[1] & 0xf)
2315               {
2316                  case 0:      // reset
2317                     #if LOG_ADB || LOG_ADB_MCU_CMD
2318                     printf("Egret: ADB Reset\n");
2319                     #endif
2320                     mac_egret_response_std(mac, 0, 0, 0);
2321                     break;
2322
2323                  case 1:      // flush
2324                     #if LOG_ADB || LOG_ADB_MCU_CMD
2325                     printf("Egret: ADB Reset\n");
2326                     #endif
2327                     mac_egret_response_std(mac, 1, 0, 0);
2328                     break;
2329
2330                  default:
2331                     printf("Egret: Unhandled ADB command %x\n", mac->adb_buffer[1]);
2332                     mac->adb_datasize = 0;
2333                     break;
2334
2335               }
23062336               break;
23072337
23082338            case 1: // general Egret MCU command
src/mess/video/mac.c
r9345r9346
199199                  *scanline++ = cb264_palette[pixels&0xf0];
200200                  *scanline++ = cb264_palette[(pixels<<4)&0xf0];
201201               }
202            }
202            }         
203203         }
204204         break;
205205
r9345r9346
312312   }
313313}
314314
315// IIci/IIsi RAM-Based Video (RBV)
316
317VIDEO_START( macrbv )
318{
319   mac_state *mac = machine->driver_data<mac_state>();
320
321   memset(mac->rbv_regs, 0, sizeof(mac->rbv_regs));
322
323   mac->rbv_count = 0;
324   mac->rbv_clutoffs = 0;
325   mac->rbv_immed10wr = 0;
326
327   mac->rbv_regs[2] = 0xff;
328}
329
330VIDEO_UPDATE( macrbv )
331{
332   UINT32 *scanline;
333   int x, y;
334   mac_state *mac = screen->machine->driver_data<mac_state>();
335
336   switch (mac->rbv_regs[0x10] & 7)
337   {
338      case 0:   // 1bpp
339      {
340         UINT8 *vram8 = (UINT8 *)messram_get_ptr(screen->machine->device("messram"));
341         UINT8 pixels;
342
343         for (y = 0; y < 480; y++)
344         {
345            scanline = BITMAP_ADDR32(bitmap, y, 0);
346            for (x = 0; x < 640; x+=8)
347            {
348               pixels = vram8[(y * 80) + ((x/8)^3)];
349
350               *scanline++ = mac->rbv_palette[0xfe|(pixels>>7)];
351               *scanline++ = mac->rbv_palette[0xfe|((pixels>>6)&1)];
352               *scanline++ = mac->rbv_palette[0xfe|((pixels>>5)&1)];
353               *scanline++ = mac->rbv_palette[0xfe|((pixels>>4)&1)];
354               *scanline++ = mac->rbv_palette[0xfe|((pixels>>3)&1)];
355               *scanline++ = mac->rbv_palette[0xfe|((pixels>>2)&1)];
356               *scanline++ = mac->rbv_palette[0xfe|((pixels>>1)&1)];
357               *scanline++ = mac->rbv_palette[0xfe|(pixels&1)];
358            }
359         }
360      }
361      break;
362
363      case 1:   // 2bpp
364      {
365         UINT8 *vram8 = (UINT8 *)messram_get_ptr(screen->machine->device("messram"));
366         UINT8 pixels;
367
368         for (y = 0; y < 480; y++)
369         {
370            scanline = BITMAP_ADDR32(bitmap, y, 0);
371            for (x = 0; x < 640/4; x++)
372            {
373               pixels = vram8[(y * 160) + (BYTE4_XOR_BE(x))];
374
375               *scanline++ = mac->rbv_palette[0xfc|((pixels>>6)&3)];
376               *scanline++ = mac->rbv_palette[0xfc|((pixels>>4)&3)];
377               *scanline++ = mac->rbv_palette[0xfc|((pixels>>2)&3)];
378               *scanline++ = mac->rbv_palette[0xfc|(pixels&3)];
379            }
380         }
381      }
382      break;
383
384      case 2: // 4bpp
385      {
386         UINT8 *vram8 = (UINT8 *)messram_get_ptr(screen->machine->device("messram"));
387         UINT8 pixels;
388
389         for (y = 0; y < 480; y++)
390         {
391            scanline = BITMAP_ADDR32(bitmap, y, 0);
392
393            for (x = 0; x < 640/2; x++)
394            {
395               pixels = vram8[(y * 320) + (BYTE4_XOR_BE(x))];
396
397               *scanline++ = mac->rbv_palette[0xf0|(pixels>>4)];
398               *scanline++ = mac->rbv_palette[0xf0|(pixels&0xf)];
399            }
400         }
401      }
402      break;
403
404      case 3: // 8bpp
405      {
406         UINT8 *vram8 = (UINT8 *)messram_get_ptr(screen->machine->device("messram"));
407         UINT8 pixels;
408         
409         for (y = 0; y < 480; y++)
410         {
411            scanline = BITMAP_ADDR32(bitmap, y, 0);
412
413            for (x = 0; x < 640; x++)
414            {
415               pixels = vram8[(y * 640) + (BYTE4_XOR_BE(x))];
416               *scanline++ = mac->rbv_palette[pixels];
417            }
418         }
419      }
420   }
421
422   return 0;
423}
424
src/mess/includes/mac.h
r9345r9346
161161VIDEO_UPDATE( macse30 );
162162PALETTE_INIT( mac );
163163
164VIDEO_START( macrbv );
165VIDEO_UPDATE( macrbv );
166
164167void mac_set_screen_buffer( int buffer );
165168
166169extern UINT32 *mac_cb264_vram;
r9345r9346
261264
262265   // 60.15 Hz timer for RBV/V8/Sonora/Eagle/VASP/etc.
263266   emu_timer *mac6015_timer;
267
268   // RBV and friends (V8, etc)
269   UINT8 rbv_regs[256], rbv_ier, rbv_ifr;
270   UINT32 rbv_colors[3], rbv_count, rbv_clutoffs, rbv_immed10wr;
271   UINT32 rbv_palette[256];
264272};
265273
266274#endif /* MAC_H_ */
src/mess/drivers/mac.c
r9345r9346
6969   return 0x17171717;
7070}
7171
72// IIci/IIsi RAM-Based Video (RBV)
73
74static UINT8 rbv_regs[256], rbv_ier, rbv_ifr;
75static UINT32 rbv_colors[3], rbv_count, rbv_clutoffs, rbv_immed10wr;
76static UINT32 rbv_palette[256];
77
78static VIDEO_START( macrbv )
79{
80   memset(rbv_regs, 0, sizeof(rbv_regs));
81
82   rbv_count = 0;
83   rbv_clutoffs = 0;
84   rbv_immed10wr = 0;
85
86   rbv_regs[2] = 0xff;
87}
88
8972// do this here - VIDEO_UPDATE is called each scanline when stepping in the
9073// debugger, which means you can't escape the VIA2 IRQ handler
91static INTERRUPT_GEN( mac_rbv_vbl )
74INTERRUPT_GEN( mac_rbv_vbl )
9275{
93   rbv_regs[2] &= ~0x40;   // set vblank signal
76   mac_state *mac = device->machine->driver_data<mac_state>();
9477
95   if ((rbv_regs[0x12] & 0x40) && (rbv_ier & 0x2))
78   mac->rbv_regs[2] &= ~0x40;   // set vblank signal
79
80   if ((mac->rbv_regs[0x12] & 0x40) && (mac->rbv_ier & 0x2))
9681   {
97      rbv_ifr |= 0x82;
82      mac->rbv_ifr |= 0x82;
9883      mac_set_via2_interrupt(device->machine, 1);
9984   }
10085}
10186
102static VIDEO_UPDATE( macrbv )
103{
104   UINT32 *scanline;
105   int x, y;
106
107   switch (rbv_regs[0x10] & 7)
108   {
109      case 0:   // 1bpp
110      {
111         UINT8 *vram8 = (UINT8 *)messram_get_ptr(screen->machine->device("messram"));
112         UINT8 pixels;
113
114         for (y = 0; y < 480; y++)
115         {
116            scanline = BITMAP_ADDR32(bitmap, y, 0);
117            for (x = 0; x < 640; x+=8)
118            {
119               pixels = vram8[(y * 80) + ((x/8)^3)];
120
121               *scanline++ = rbv_palette[0xfe|(pixels>>7)];
122               *scanline++ = rbv_palette[0xfe|((pixels>>6)&1)];
123               *scanline++ = rbv_palette[0xfe|((pixels>>5)&1)];
124               *scanline++ = rbv_palette[0xfe|((pixels>>4)&1)];
125               *scanline++ = rbv_palette[0xfe|((pixels>>3)&1)];
126               *scanline++ = rbv_palette[0xfe|((pixels>>2)&1)];
127               *scanline++ = rbv_palette[0xfe|((pixels>>1)&1)];
128               *scanline++ = rbv_palette[0xfe|(pixels&1)];
129            }
130         }
131      }
132      break;
133
134      case 1:   // 2bpp
135      {
136         UINT8 *vram8 = (UINT8 *)messram_get_ptr(screen->machine->device("messram"));
137         UINT8 pixels;
138
139         for (y = 0; y < 480; y++)
140         {
141            scanline = BITMAP_ADDR32(bitmap, y, 0);
142            for (x = 0; x < 640/4; x++)
143            {
144               pixels = vram8[(y * 160) + (BYTE4_XOR_BE(x))];
145
146               *scanline++ = rbv_palette[0xfc|((pixels>>6)&3)];
147               *scanline++ = rbv_palette[0xfc|((pixels>>4)&3)];
148               *scanline++ = rbv_palette[0xfc|((pixels>>2)&3)];
149               *scanline++ = rbv_palette[0xfc|(pixels&3)];
150            }
151         }
152      }
153      break;
154
155      case 2: // 4bpp
156      {
157         UINT8 *vram8 = (UINT8 *)messram_get_ptr(screen->machine->device("messram"));
158         UINT8 pixels;
159
160         for (y = 0; y < 480; y++)
161         {
162            scanline = BITMAP_ADDR32(bitmap, y, 0);
163
164            for (x = 0; x < 640/2; x++)
165            {
166               pixels = vram8[(y * 320) + (BYTE4_XOR_BE(x))];
167
168               *scanline++ = rbv_palette[0xf0|(pixels>>4)];
169               *scanline++ = rbv_palette[0xf0|(pixels&0xf)];
170            }
171         }
172      }
173      break;
174
175      case 3: // 8bpp
176      {
177         UINT8 *vram8 = (UINT8 *)messram_get_ptr(screen->machine->device("messram"));
178         UINT8 pixels;
179         
180         for (y = 0; y < 480; y++)
181         {
182            scanline = BITMAP_ADDR32(bitmap, y, 0);
183
184            for (x = 0; x < 640; x++)
185            {
186               pixels = vram8[(y * 640) + (BYTE4_XOR_BE(x))];
187               *scanline++ = rbv_palette[pixels];
188            }
189         }
190      }
191   }
192
193   return 0;
194}
195
19687static WRITE32_HANDLER( rbv_ramdac_w )
19788{
89   mac_state *mac = space->machine->driver_data<mac_state>();
90
19891   if (!offset)
19992   {
200      rbv_clutoffs = data>>24;
201      rbv_count = 0;
93      mac->rbv_clutoffs = data>>24;
94      mac->rbv_count = 0;
20295   }
20396   else
20497   {
205      rbv_colors[rbv_count++] = data>>24;
98      mac->rbv_colors[mac->rbv_count++] = data>>24;
20699
207      if (rbv_count == 3)
100      if (mac->rbv_count == 3)
208101      {
209         palette_set_color(space->machine, rbv_clutoffs, MAKE_RGB(rbv_colors[0], rbv_colors[1], rbv_colors[2]));
210         rbv_palette[rbv_clutoffs] = MAKE_RGB(rbv_colors[0], rbv_colors[1], rbv_colors[2]);
211         rbv_clutoffs++;
212         rbv_count = 0;
102         palette_set_color(space->machine, mac->rbv_clutoffs, MAKE_RGB(mac->rbv_colors[0], mac->rbv_colors[1], mac->rbv_colors[2]));
103         mac->rbv_palette[mac->rbv_clutoffs] = MAKE_RGB(mac->rbv_colors[0], mac->rbv_colors[1], mac->rbv_colors[2]);
104         mac->rbv_clutoffs++;
105         mac->rbv_count = 0;
213106      }
214107   }
215108}
r9345r9346
217110static READ8_HANDLER ( mac_rbv_r )
218111{
219112   int data = 0;
113   mac_state *mac = space->machine->driver_data<mac_state>();
220114   
221115   if (offset < 0x100)
222116   {   
223      data = rbv_regs[offset];
117      data = mac->rbv_regs[offset];
224118
225119      if (offset == 0x02)
226120      {
r9345r9346
232126
233127      if (offset == 0x10)
234128      {
235         if (!rbv_immed10wr)
129         if (!mac->rbv_immed10wr)
236130         {
237131            data &= ~0x38;
238132            data |= (6<<3);   // 13" RGB monitor at 640x480
239133         }
240134         else
241135         {
242            rbv_immed10wr = 0;
136            mac->rbv_immed10wr = 0;
243137         }
244138      }
245139
r9345r9346
256150      switch (offset)
257151      {
258152         case 13:   // IFR
259            return rbv_ifr;
153            return mac->rbv_ifr;
260154            break;
261155
262156         case 14:   // IER
263            return rbv_ier;
157            return mac->rbv_ier;
264158            break;
265159
266160         default:
r9345r9346
276170
277171static WRITE8_HANDLER ( mac_rbv_w )
278172{
173   mac_state *mac = space->machine->driver_data<mac_state>();
174
279175   if (offset < 0x100)
280176   {
281177//      if (offset == 0x10) printf("rbv_w: %02x to offset %x (PC=%x)\n", data, offset, cpu_get_pc(space->cpu));
r9345r9346
283179      {
284180         case 0x03:
285181            mac_set_via2_interrupt(space->machine, 0);
286            rbv_regs[offset] = data;
182            mac->rbv_regs[offset] = data;
287183            break;
288184
289185         case 0x10:
290186            if (data != 0)
291187            {
292               rbv_immed10wr = 1;
188               mac->rbv_immed10wr = 1;
293189            }
294            rbv_regs[offset] = data;
190            mac->rbv_regs[offset] = data;
295191            break;
296192
297193         case 0x12:
298194            if (data & 0x80)   // 1 bits write 1s
299195            {
300               rbv_regs[offset] |= data & 0x7f;
196               mac->rbv_regs[offset] |= data & 0x7f;
301197            }
302198            else         // 1 bits write 0s
303199            {
304               rbv_regs[offset] &= ~(data & 0x7f);
200               mac->rbv_regs[offset] &= ~(data & 0x7f);
305201            }
306202            break;
307203
308204         case 0x13:
309205            if (data & 0x80)   // 1 bits write 1s
310206            {
311               rbv_regs[offset] |= data & 0x7f;
207               mac->rbv_regs[offset] |= data & 0x7f;
312208
313               if (data == 0xff) rbv_regs[offset] = 0x1f;   // I don't know why this is special, but the IIci ROM's POST demands it
209               if (data == 0xff) mac->rbv_regs[offset] = 0x1f;   // I don't know why this is special, but the IIci ROM's POST demands it
314210            }
315211            else         // 1 bits write 0s
316212            {
317               rbv_regs[offset] &= ~(data & 0x7f);
213               mac->rbv_regs[offset] &= ~(data & 0x7f);
318214            }
215//            printf("RBV: 0x13 (%02x) = %02x (PC %x)\n", data, mac->rbv_regs[offset], cpu_get_pc(space->cpu));
319216            break;
320217
321218         default:
322            rbv_regs[offset] = data;
219            mac->rbv_regs[offset] = data;
323220            break;
324221      }
325222   }
r9345r9346
331228      {
332229         case 13:   // IFR
333230//            printf("rbv_w: %02x to IFR\n", data);
334            rbv_ifr = data;
231            mac->rbv_ifr = data;
335232            mac_set_via2_interrupt(space->machine, 0);
336233            break;
337234
338235         case 14:   // IER
339236            if (data & 0x80)   // 1 bits write 1s
340237            {
341               rbv_ier |= data & 0x7f;
238               mac->rbv_ier |= data & 0x7f;
342239            }
343240            else       // 1 bits write 0s
344241            {
345               rbv_ier &= ~(data & 0x7f);
242               mac->rbv_ier &= ~(data & 0x7f);
346243            }
347244
348//            printf("rbv_w: %02x to IER => %02x\n", data, rbv_ier);
245//            printf("rbv_w: %02x to IER => %02x\n", data, mac->rbv_ier);
349246            break;
350247
351248         default:

Previous 15994 Revisions Next


© 1998-2018 The MESS Team