Previous 15994 Revisions Next

r5896 Sunday 27th September, 2009 at 08:34:12 UTC by MooglyGuy
Harmony diff: Improved interrupt generation and MCD212 emulation, CD-i BIOSes 0 and 1 now get to the initial menu, then hang.
[src/mess/drivers]cdi.c

src/mess/drivers/cdi.c
r5895r5896
5757
5858static UINT16 *planea;
5959static UINT16 *planeb;
60static UINT16 *cdic_ram;
6061
61#define ENABLE_UART_PRINTING (1)
62#define ENABLE_UART_PRINTING (0)
6263
63#define VERBOSE_LEVEL   (5)
64#define VERBOSE_LEVEL   (6)
6465
6566INLINE void verboselog(running_machine *machine, int n_level, const char *s_fmt, ...)
6667{
r5895r5896
7677}
7778
7879/*************************
79*     Video Hardware     *
80* Helpful test functions *
8081*************************/
8182
82typedef struct
83{
84   UINT8 csrr;
85   UINT16 csrw;
86   UINT16 dcr;
87   UINT16 vsr;
88   UINT16 ddr;
89   UINT16 dcp;
90   UINT8 clut[256];
91   UINT8 image_coding_method;
92   UINT8 transparency_control;
93   UINT8 plane_order;
94   UINT8 clut_bank;
95   UINT8 transparent_color_a;
96   UINT8 reserved0;
97   UINT8 transparent_color_b;
98   UINT8 mask_color_a;
99   UINT8 reserved1;
100   UINT8 mask_color_b;
101   UINT8 dyuv_abs_start_a;
102   UINT8 dyuv_abs_start_b;
103   UINT8 reserved2;
104   UINT8 cursor_position;
105   UINT8 cursor_control;
106   UINT8 cursor_pattern[16];
107   UINT8 region_control[8];
108   UINT8 backdrop_color;
109   UINT8 mosaic_hold_a;
110   UINT8 mosaic_hold_b;
111   UINT8 weight_factor_a;
112   UINT8 weight_factor_b;
113} mcd212_channel_t;
83emu_timer *test_timer;
11484
115typedef struct
85TIMER_CALLBACK( test_timer_callback )
11686{
117   mcd212_channel_t channel[2];
118   emu_timer *scan_timer;
119} mcd212_t;
120
121mcd212_t mcd212;
122
123#define MCD212_DCR_DE         0x8000   // Display Enable
124#define MCD212_DCR_CF         0x4000   // Crystal Frequency
125#define MCD212_DCR_FD         0x2000   // Frame Duration
126#define MCD212_DCR_SM         0x1000   // Scan Mode
127#define MCD212_DCR_CM         0x0800   // Color Mode Ch.1/2
128#define MCD212_DCR_ICA         0x0200   // ICA Enable Ch.1/2
129#define MCD212_DCR_DCA         0x0100   // DCA Enable Ch.1/2
130
131#define MCD212_DDR_FT         0x0300   // Display File Type
132#define MCD212_DDR_FT_BMP      0x0000   // Bitmap
133#define MCD212_DDR_FT_BMP2      0x0100   // Bitmap (alt.)
134#define MCD212_DDR_FT_RLE      0x0200   // Run-Length Encoded
135#define MCD212_DDR_FT_MOSAIC   0x0300   // Mosaic
136
137static READ16_HANDLER(mcd212_r)
138{
139   switch(offset)
87   // This function manually triggers the SLAVE interrupt request.  Currently, it is the only input trigger that will do anything more than
88   // what the driver does otherwise.
89   static UINT8 stage = 0;
90   if(stage == 0)
14091   {
141      case 0x00/2:
142      case 0x10/2:
143         if(ACCESSING_BITS_0_7)
144         {
145            verboselog(space->machine, 2, "mcd212_r: Status Register %d: %02x & %04x\n", (1 - (offset / 8)) + 1, mcd212.channel[1 - (offset / 8)].csrr, mem_mask);
146            mcd212.channel[1 - (offset / 8)].csrr ^= 0x80; // Simulate drawing / not drawing
147            return mcd212.channel[1 - (offset / 8)].csrr;
148         }
149         break;
150      case 0x02/2:
151      case 0x12/2:
152         verboselog(space->machine, 2, "mcd212_r: Display Command Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, mcd212.channel[1 - (offset / 8)].dcr, mem_mask);
153         return mcd212.channel[1 - (offset / 8)].dcr;
154         break;
155      case 0x04/2:
156      case 0x14/2:
157         verboselog(space->machine, 2, "mcd212_r: Video Start Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, mcd212.channel[1 - (offset / 8)].vsr, mem_mask);
158         return mcd212.channel[1 - (offset / 8)].vsr;
159         break;
160      case 0x08/2:
161      case 0x18/2:
162         verboselog(space->machine, 2, "mcd212_r: Display Decoder Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, mcd212.channel[1 - (offset / 8)].ddr, mem_mask);
163         return mcd212.channel[1 - (offset / 8)].ddr;
164         break;
165      case 0x0a/2:
166      case 0x1a/2:
167         verboselog(space->machine, 2, "mcd212_r: DCA Pointer Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, mcd212.channel[1 - (offset / 8)].dcp, mem_mask);
168         return mcd212.channel[1 - (offset / 8)].dcp;
169         break;
170      default:
171         verboselog(space->machine, 2, "mcd212_r: Unknown Register %d & %04x\n", (1 - (offset / 8)) + 1, mem_mask);
172         break;
92      stage++;
93      //cpu_set_input_line_vector(cputag_get_cpu(machine, "maincpu"), M68K_IRQ_4, 60);
94      cputag_set_input_line(machine, "maincpu", M68K_IRQ_2, ASSERT_LINE);
95      timer_adjust_oneshot(test_timer, ATTOTIME_IN_HZ(10000), 0);
17396   }
174
175   return 0;
176}
177
178static WRITE16_HANDLER(mcd212_w)
179{
180   switch(offset)
97   else
18198   {
182      case 0x00/2:
183      case 0x10/2:
184         verboselog(space->machine, 2, "mcd212_w: Status Register %d: %02x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
185         COMBINE_DATA(&mcd212.channel[1 - (offset / 8)].csrw);
186         break;
187      case 0x02/2:
188      case 0x12/2:
189         verboselog(space->machine, 2, "mcd212_w: Display Command Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
190         COMBINE_DATA(&mcd212.channel[1 - (offset / 8)].dcr);
191         break;
192      case 0x04/2:
193      case 0x14/2:
194         verboselog(space->machine, 2, "mcd212_w: Video Start Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
195         COMBINE_DATA(&mcd212.channel[1 - (offset / 8)].vsr);
196         break;
197      case 0x08/2:
198      case 0x18/2:
199         verboselog(space->machine, 2, "mcd212_w: Display Decoder Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
200         COMBINE_DATA(&mcd212.channel[1 - (offset / 8)].ddr);
201         break;
202      case 0x0a/2:
203      case 0x1a/2:
204         verboselog(space->machine, 2, "mcd212_w: DCA Pointer Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
205         COMBINE_DATA(&mcd212.channel[1 - (offset / 8)].dcp);
206         break;
207      default:
208         verboselog(space->machine, 2, "mcd212_w: Unknown Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
209         break;
99      cputag_set_input_line(machine, "maincpu", M68K_IRQ_2, CLEAR_LINE);
100      stage = 0;
210101   }
211102}
212103
213INLINE void mcd212_set_register(running_machine *machine, int channel, UINT8 reg, UINT32 value)
214{
215   switch(reg)
216   {
217      case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: // CLUT 0 - 63
218      case 0x88: case 0x89: case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e: case 0x8f:
219      case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97:
220      case 0x98: case 0x99: case 0x9a: case 0x9b: case 0x9c: case 0x9d: case 0x9e: case 0x9f:
221      case 0xa0: case 0xa1: case 0xa2: case 0xa3: case 0xa4: case 0xa5: case 0xa6: case 0xa7:
222      case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf:
223      case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7:
224      case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf:
225         verboselog(machine, 6, "          %04xxxxx: CLUT[%d] = %08x\n", channel * 0x20, mcd212.channel[channel].clut_bank * 0x40 + (reg - 0x80), value );
226         mcd212.channel[channel].clut[mcd212.channel[channel].clut_bank * 0x40 + (reg - 0x80)] = value;
227         break;
228      case 0xc0: // Image Coding Method
229         if(channel == 0)
230         {
231            verboselog(machine, 6, "          %04xxxxx: Image Coding Method = %08x\n", channel * 0x20, value );
232            mcd212.channel[channel].image_coding_method = value;
233         }
234         break;
235      case 0xc1: // Transparency Control
236         if(channel == 0)
237         {
238            verboselog(machine, 6, "          %04xxxxx: Transparency Control = %08x\n", channel * 0x20, value );
239            mcd212.channel[channel].transparency_control = value;
240         }
241         break;
242      case 0xc2: // Plane Order
243         if(channel == 0)
244         {
245            verboselog(machine, 6, "          %04xxxxx: Plane Order = %08x\n", channel * 0x20, value & 7);
246            mcd212.channel[channel].plane_order = value & 0x00000007;
247         }
248         break;
249      case 0xc3: // CLUT Bank Register
250         verboselog(machine, 6, "          %04xxxxx: CLUT Bank Register = %08x\n", channel * 0x20, value & 3);
251         mcd212.channel[channel].clut_bank = value & 0x00000003;
252         break;
253      case 0xc4: // Transparent Color A
254         if(channel == 0)
255         {
256            verboselog(machine, 6, "          %04xxxxx: Transparent Color A = %08x\n", channel * 0x20, value );
257            mcd212.channel[channel].transparent_color_a = value;
258         }
259         break;
260      case 0xc6: // Transparent Color B
261         if(channel == 1)
262         {
263            verboselog(machine, 6, "          %04xxxxx: Transparent Color B = %08x\n", channel * 0x20, value );
264            mcd212.channel[channel].transparent_color_b = value;
265         }
266         break;
267      case 0xc7: // Mask Color A
268         if(channel == 0)
269         {
270            verboselog(machine, 6, "          %04xxxxx: Mask Color A = %08x\n", channel * 0x20, value );
271            mcd212.channel[channel].mask_color_a = value;
272         }
273         break;
274      case 0xc9: // Mask Color B
275         if(channel == 1)
276         {
277            verboselog(machine, 6, "          %04xxxxx: Mask Color B = %08x\n", channel * 0x20, value );
278            mcd212.channel[channel].mask_color_b = value;
279         }
280         break;
281      case 0xca: // Delta YUV Absolute Start Value A
282         if(channel == 0)
283         {
284            verboselog(machine, 6, "          %04xxxxx: Delta YUV Absolute Start Value A = %08x\n", channel * 0x20, value );
285            mcd212.channel[channel].dyuv_abs_start_a = value;
286         }
287         break;
288      case 0xcb: // Delta YUV Absolute Start Value B
289         if(channel == 1)
290         {
291            verboselog(machine, 6, "          %04xxxxx: Delta YUV Absolute Start Value B = %08x\n", channel * 0x20, value );
292            mcd212.channel[channel].dyuv_abs_start_b = value;
293         }
294         break;
295      case 0xcd: // Cursor Position
296         if(channel == 0)
297         {
298            verboselog(machine, 6, "          %04xxxxx: Cursor Position = %08x\n", channel * 0x20, value );
299            mcd212.channel[channel].cursor_position = value;
300         }
301         break;
302      case 0xce: // Cursor Control
303         if(channel == 0)
304         {
305            verboselog(machine, 6, "          %04xxxxx: Cursor Control = %08x\n", channel * 0x20, value );
306            mcd212.channel[channel].cursor_control = value;
307         }
308         break;
309      case 0xcf: // Cursor Pattern
310         if(channel == 0)
311         {
312            verboselog(machine, 6, "          %04xxxxx: Cursor Pattern[%d] = %04x\n", channel * 0x20, (value >> 16) & 0x000f, value & 0x0000ffff);
313            mcd212.channel[channel].cursor_pattern[(value >> 16) & 0x000f] = value & 0x0000ffff;
314         }
315         break;
316      case 0xd0: // Region Control 0-7
317      case 0xd1:
318      case 0xd2:
319      case 0xd3:
320      case 0xd4:
321      case 0xd5:
322      case 0xd6:
323      case 0xd7:
324         verboselog(machine, 6, "          %04xxxxx: Region Control %d = %08x\n", channel * 0x20, reg & 7, value );
325         mcd212.channel[channel].region_control[reg & 7] = value;
326         break;
327      case 0xd8: // Backdrop Color
328         if(channel == 0)
329         {
330            verboselog(machine, 6, "          %04xxxxx: Backdrop Color = %08x\n", channel * 0x20, value );
331            mcd212.channel[channel].backdrop_color = value;
332         }
333         break;
334      case 0xd9: // Mosaic Pixel Hold Factor A
335         if(channel == 0)
336         {
337            verboselog(machine, 6, "          %04xxxxx: Mosaic Pixel Hold Factor A = %08x\n", channel * 0x20, value );
338            mcd212.channel[channel].mosaic_hold_a = value;
339         }
340         break;
341      case 0xda: // Mosaic Pixel Hold Factor B
342         if(channel == 1)
343         {
344            verboselog(machine, 6, "          %04xxxxx: Mosaic Pixel Hold Factor B = %08x\n", channel * 0x20, value );
345            mcd212.channel[channel].mosaic_hold_b = value;
346         }
347         break;
348      case 0xdb: // Weight Factor A
349         if(channel == 0)
350         {
351            verboselog(machine, 6, "          %04xxxxx: Weight Factor A = %08x\n", channel * 0x20, value );
352            mcd212.channel[channel].weight_factor_a = value;
353         }
354         break;
355      case 0xdc: // Weight Factor B
356         if(channel == 1)
357         {
358            verboselog(machine, 6, "          %04xxxxx: Weight Factor B = %08x\n", channel * 0x20, value );
359            mcd212.channel[channel].weight_factor_b = value;
360         }
361         break;
362   }
363}
104/***********************
105* On-board peripherals *
106***********************/
364107
365INLINE void mcd212_set_vsr(int channel, UINT32 value)
366{
367   mcd212.channel[channel].vsr = value & 0x0000ffff;
368   mcd212.channel[channel].dcr &= 0xffc0;
369   mcd212.channel[channel].dcr |= (value >> 16) & 0x003f;
370}
371
372INLINE UINT32 mcd212_get_vsr(int channel)
373{
374   return ((mcd212.channel[channel].dcr & 0x3f) << 16) | mcd212.channel[channel].vsr;
375}
376
377INLINE void mcd212_set_dcp(int channel, UINT32 value)
378{
379   mcd212.channel[channel].dcp = value & 0x0000ffff;
380   mcd212.channel[channel].ddr &= 0xffc0;
381   mcd212.channel[channel].ddr |= (value >> 16) & 0x003f;
382}
383
384INLINE UINT32 mcd212_get_dcp(int channel)
385{
386   return ((mcd212.channel[channel].ddr & 0x3f) << 16) | mcd212.channel[channel].dcp;
387}
388
389INLINE void mcd212_set_display_parameters(int channel, UINT8 value)
390{
391   mcd212.channel[channel].ddr &= 0xf0ff;
392   mcd212.channel[channel].ddr |= (value & 0x0f) << 8;
393   mcd212.channel[channel].dcr &= 0xf7ff;
394   mcd212.channel[channel].dcr |= (value & 0x10) << 7;
395}
396
397static void mcd212_process_ica(running_machine *machine, int channel)
398{
399   UINT16 *ica = channel ? planeb : planea;
400   UINT32 addr = 0x000400/2;
401   UINT32 cmd = 0;
402   while(1)
403   {
404      UINT8 stop = 0;
405      cmd = ica[addr++] << 16;
406      cmd |= ica[addr++];
407      switch((cmd & 0xff000000) >> 24)
408      {
409         case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07:   // STOP
410         case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: case 0x0e: case 0x0f:
411            verboselog(machine, 6, "%08x: %08x: ICA: STOP\n", addr * 2 + channel * 0x200000, cmd );
412            stop = 1;
413            break;
414         case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17: // NOP
415         case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f:
416            verboselog(machine, 6, "%08x: %08x: ICA: NOP\n", addr * 2 + channel * 0x200000, cmd );
417            break;
418         case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27: // RELOAD DCP
419         case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f:
420            verboselog(machine, 6, "%08x: %08x: ICA: RELOAD DCP\n", addr * 2 + channel * 0x200000, cmd );
421            mcd212_set_dcp(channel, cmd & 0x001fffff);
422            break;
423         case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37: // RELOAD DCP and STOP
424         case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3c: case 0x3d: case 0x3e: case 0x3f:
425            verboselog(machine, 6, "%08x: %08x: ICA: RELOAD DCP and STOP\n", addr * 2 + channel * 0x200000, cmd );
426            mcd212_set_dcp(channel, cmd & 0x001fffff);
427            stop = 1;
428            break;
429         case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46: case 0x47: // RELOAD ICA
430         case 0x48: case 0x49: case 0x4a: case 0x4b: case 0x4c: case 0x4d: case 0x4e: case 0x4f:
431            verboselog(machine, 6, "%08x: %08x: ICA: RELOAD ICA\n", addr * 2 + channel * 0x200000, cmd );
432            addr = (cmd & 0x001fffff) / 2;
433            break;
434         case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57: // RELOAD VSR and STOP
435         case 0x58: case 0x59: case 0x5a: case 0x5b: case 0x5c: case 0x5d: case 0x5e: case 0x5f:
436            verboselog(machine, 6, "%08x: %08x: ICA: RELOAD VSR and STOP\n", addr * 2 + channel * 0x200000, cmd );
437            mcd212_set_vsr(channel, cmd & 0x001fffff);
438            stop = 1;
439            break;
440         case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67: // INTERRUPT
441         case 0x68: case 0x69: case 0x6a: case 0x6b: case 0x6c: case 0x6d: case 0x6e: case 0x6f:
442            verboselog(machine, 5, "%08x: %08x: ICA: INTERRUPT\n", addr * 2 + channel * 0x200000, cmd );
443            mcd212.channel[1].csrr |= 1 << (2 - channel);
444            // TODO
445            // mcd212_check_interrupts
446            break;
447         case 0x70: case 0x71: case 0x72: case 0x73: case 0x74: case 0x75: case 0x76: case 0x77: // RELOAD DISPLAY PARAMETERS
448         case 0x78: case 0x79: case 0x7a: case 0x7b: case 0x7c: case 0x7d: case 0x7e: case 0x7f:
449            verboselog(machine, 6, "%08x: %08x: ICA: RELOAD DISPLAY PARAMETERS\n", addr * 2 + channel * 0x200000, cmd );
450            mcd212_set_display_parameters(channel, cmd & 0x1f);
451            break;
452         default:
453            mcd212_set_register(machine, channel, cmd >> 24, cmd & 0x00ffffff);
454            break;
455      }
456      if(stop)
457      {
458         break;
459      }
460   }
461}
462
463static void mcd212_process_dca(running_machine *machine, int channel)
464{
465   UINT16 *dca = channel ? planeb : planea;
466   UINT32 addr = mcd212_get_dcp(channel) / 2;
467   UINT32 cmd = 0;
468   while(1)
469   {
470      UINT8 stop = 0;
471      cmd = dca[addr++] << 16;
472      cmd |= dca[addr++];
473      switch((cmd & 0xff000000) >> 24)
474      {
475         case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07:   // STOP
476         case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: case 0x0e: case 0x0f:
477            verboselog(machine, 6, "%08x: %08x: DCA: STOP\n", addr * 2 + channel * 0x200000, cmd );
478            stop = 1;
479            break;
480         case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17: // NOP
481         case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f:
482            verboselog(machine, 6, "%08x: %08x: DCA: NOP\n", addr * 2 + channel * 0x200000, cmd );
483            break;
484         case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27: // RELOAD DCP
485         case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f:
486            verboselog(machine, 6, "%08x: %08x: DCA: RELOAD DCP (NOP)\n", addr * 2 + channel * 0x200000, cmd );
487            break;
488         case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37: // RELOAD DCP and STOP
489         case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3c: case 0x3d: case 0x3e: case 0x3f:
490            verboselog(machine, 6, "%08x: %08x: DCA: RELOAD DCP and STOP\n", addr * 2 + channel * 0x200000, cmd );
491            mcd212_set_dcp(channel, cmd & 0x001fffff);
492            stop = 1;
493            break;
494         case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46: case 0x47: // RELOAD VSR
495         case 0x48: case 0x49: case 0x4a: case 0x4b: case 0x4c: case 0x4d: case 0x4e: case 0x4f:
496            verboselog(machine, 6, "%08x: %08x: DCA: RELOAD VSR\n", addr * 2 + channel * 0x200000, cmd );
497            mcd212_set_vsr(channel, cmd & 0x001fffff);
498            break;
499         case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57: // RELOAD VSR and STOP
500         case 0x58: case 0x59: case 0x5a: case 0x5b: case 0x5c: case 0x5d: case 0x5e: case 0x5f:
501            verboselog(machine, 6, "%08x: %08x: DCA: RELOAD VSR and STOP\n", addr * 2 + channel * 0x200000, cmd );
502            mcd212_set_vsr(channel, cmd & 0x001fffff);
503            stop = 1;
504            break;
505         case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67: // INTERRUPT
506         case 0x68: case 0x69: case 0x6a: case 0x6b: case 0x6c: case 0x6d: case 0x6e: case 0x6f:
507            verboselog(machine, 5, "%08x: %08x: DCA: INTERRUPT\n", addr * 2 + channel * 0x200000, cmd );
508            mcd212.channel[1].csrr |= 1 << (2 - channel);
509            // TODO
510            // mcd212_check_interrupts
511            break;
512         case 0x70: case 0x71: case 0x72: case 0x73: case 0x74: case 0x75: case 0x76: case 0x77: // RELOAD DISPLAY PARAMETERS
513         case 0x78: case 0x79: case 0x7a: case 0x7b: case 0x7c: case 0x7d: case 0x7e: case 0x7f:
514            verboselog(machine, 6, "%08x: %08x: DCA: RELOAD DISPLAY PARAMETERS\n", addr * 2 + channel * 0x200000, cmd );
515            mcd212_set_display_parameters(channel, cmd & 0x1f);
516            break;
517         default:
518            mcd212_set_register(machine, channel, cmd >> 24, cmd & 0x00ffffff);
519            break;
520      }
521      if(stop)
522      {
523         break;
524      }
525   }
526}
527
528static void mcd212_process_vsr(running_machine *machine, int channel, UINT32 *pixels)
529{
530   UINT8 *data = channel ? (UINT8*)planeb : (UINT8*)planea;
531   UINT32 vsr = mcd212_get_vsr(channel);
532   UINT8 done = 0;
533   int x = 0;
534
535   while(!done)
536   {
537      UINT8 byte = data[vsr++ ^ 3];
538      switch(mcd212.channel[channel].ddr & MCD212_DDR_FT)
539      {
540         case MCD212_DDR_FT_BMP:
541         case MCD212_DDR_FT_BMP2:
542            verboselog(machine, 0, "Unsupported display mode: Bitmap\n" );
543            done = 1;
544            break;
545         case MCD212_DDR_FT_RLE:
546            if(mcd212.channel[channel].dcr & MCD212_DCR_CM)
547            {
548               // 4-bit RLE
549               verboselog(machine, 0, "Unsupported display mode: 4-bit RLE\n" );
550               done = 1;
551            }
552            else
553            {
554               // 8-bit RLE
555               if(byte & 0x80)
556               {
557                  // Run length
558                  UINT8 length = data[vsr++ ^ 3];
559                  if(!length)
560                  {
561                     // Go to the end of the line
562                     for(; x < 640; x++)
563                     {
564                        fflush(stdout);
565                        pixels[x] = mcd212.channel[0].clut[byte & 0x7f];
566                     }
567                     done = 1;
568                  }
569                  else
570                  {
571                     int end = x + length;
572                     for(; x < end; x++)
573                     {
574                        fflush(stdout);
575                        pixels[x] = mcd212.channel[0].clut[byte & 0x7f];
576                     }
577                  }
578               }
579               else
580               {
581                  fflush(stdout);
582                  // Single pixel
583                  pixels[x++] = mcd212.channel[0].clut[byte & 0x7f];
584               }
585            }
586            break;
587         case MCD212_DDR_FT_MOSAIC:
588            verboselog(machine, 0, "Unsupported display mode: Mosaic\n" );
589            done = 1;
590            break;
591      }
592   }
593}
594
595static void mcd212_draw_scanline(running_machine *machine, int y)
596{
597   bitmap_t *bitmap = tmpbitmap;
598   UINT32 plane_a[768];
599   //UINT32 plane_b[768];
600   UINT32 *scanline = BITMAP_ADDR32(bitmap, y, 0);
601   int x;
602   mcd212_process_vsr(machine, 0, plane_a);
603   //mcd212_process_vsr(machine, 1, plane_b);
604   for(x = 0; x < 768; x++)
605   {
606      scanline[x] = plane_a[x];
607   }
608}
609
610TIMER_CALLBACK( mcd212_perform_scan )
611{
612   int scanline = video_screen_get_vpos(machine->primary_screen);
613   if(mcd212.channel[0].dcr & MCD212_DCR_DE)
614   {
615      if(scanline == 0)
616      {
617         // Process ICA
618         int index = 0;
619         for(index = 0; index < 2; index++)
620         {
621            if(mcd212.channel[index].dcr & MCD212_DCR_ICA)
622            {
623               mcd212_process_ica(machine, index);
624            }
625         }
626      }
627      else if(scanline >= 22)
628      {
629         int index = 0;
630         // Process VSR
631         mcd212_draw_scanline(machine, scanline);
632         // Process DCA
633         for(index = 0; index < 2; index++)
634         {
635            if(mcd212.channel[index].dcr & MCD212_DCR_DCA)
636            {
637               mcd212_process_dca(machine, index);
638            }
639         }
640      }
641   }
642   timer_adjust_oneshot(mcd212.scan_timer, video_screen_get_time_until_pos(machine->primary_screen, ( scanline + 1 ) % 262, 0), 0);
643}
644
645static VIDEO_START(cdi)
646{
647   VIDEO_START_CALL(generic_bitmapped);
648   mcd212.channel[0].csrr = 0x00;
649   mcd212.channel[1].csrr = 0x00;
650   mcd212.channel[0].clut_bank = 0;
651   mcd212.channel[1].clut_bank = 0;
652   mcd212.scan_timer = timer_alloc(machine, mcd212_perform_scan, 0);
653   timer_adjust_oneshot(mcd212.scan_timer, video_screen_get_time_until_pos(machine->primary_screen, 0, 0), 0);
654}
655
656/*************************
657* Memory map information *
658*************************/
659
660108typedef struct
661109{
662110   UINT8 reserved0;
r5895r5896
864312   {
865313      case 0:
866314         compare = 0x10000 - scc68070_regs.timers.timer0;
867         period = attotime_mul(ATTOTIME_IN_HZ(1000000), compare);
315         period = attotime_mul(ATTOTIME_IN_HZ(CLOCK_A/3), compare);
868316            timer_adjust_oneshot(scc68070_regs.timers.timer0_timer, period, 0);
869317         break;
870318      default:
r5895r5896
875323TIMER_CALLBACK( scc68070_timer0_callback )
876324{
877325   scc68070_regs.timers.timer0 = scc68070_regs.timers.reload_register;
326   scc68070_regs.timers.timer_status_register |= TSR_OV0;
878327   if(scc68070_regs.picr1 & 7)
879328   {
329      UINT8 interrupt = scc68070_regs.picr1 & 7;
880330      scc68070_regs.timers.timer_status_register |= TSR_OV0;
881      //printf( "Pulling line %d\n", 1 + ((scc68070_regs.picr1 & 7) - 1) );
882      cputag_set_input_line(machine, "maincpu", M68K_IRQ_1 + ((scc68070_regs.picr1 & 7) - 1), ASSERT_LINE);
331      cpu_set_input_line_vector(cputag_get_cpu(machine, "maincpu"), M68K_IRQ_1 + (interrupt - 1), 56 + interrupt);
332      cputag_set_input_line(machine, "maincpu", M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE);
883333   }
884334   scc68070_set_timer_callback(0);
885335}
r5895r5896
934384      case 0x2012/2:
935385         if(ACCESSING_BITS_0_7)
936386         {
937//            verboselog(space->machine, 2, "scc68070_periphs_r: UART Status Register: %04x & %04x\n", scc68070_regs.uart.status_register, mem_mask);
387            verboselog(space->machine, 2, "scc68070_periphs_r: UART Status Register: %04x & %04x\n", scc68070_regs.uart.status_register, mem_mask);
938388         }
939389         return scc68070_regs.uart.status_register | USR_TXRDY | USR_RXRDY;
940390      case 0x2014/2:
r5895r5896
946396      case 0x2016/2:
947397         if(ACCESSING_BITS_0_7)
948398         {
949//            verboselog(space->machine, 2, "scc68070_periphs_r: UART Command Register: %02x & %04x\n", scc68070_regs.uart.command_register, mem_mask);
399            verboselog(space->machine, 2, "scc68070_periphs_r: UART Command Register: %02x & %04x\n", scc68070_regs.uart.command_register, mem_mask);
950400         }
951401         return scc68070_regs.uart.command_register;
952402      case 0x2018/2:
r5895r5896
958408      case 0x201a/2:
959409         if(ACCESSING_BITS_0_7)
960410         {
961//            verboselog(space->machine, 2, "scc68070_periphs_r: UART Receive Holding Register: %02x & %04x\n", scc68070_regs.uart.receive_holding_register, mem_mask);
411            verboselog(space->machine, 2, "scc68070_periphs_r: UART Receive Holding Register: %02x & %04x\n", scc68070_regs.uart.receive_holding_register, mem_mask);
962412         }
963413         return scc68070_regs.uart.receive_holding_register;
964414
r5895r5896
966416      case 0x2020/2:
967417         if(ACCESSING_BITS_0_7)
968418         {
969            verboselog(space->machine, 2, "scc68070_periphs_r: Timer Status Register: %02x & %04x\n", scc68070_regs.timers.timer_status_register, mem_mask);
419            verboselog(space->machine, 2, "scc68070_periphs_r: Timer Control Register: %02x & %04x\n", scc68070_regs.timers.timer_control_register, mem_mask);
970420         }
971421         if(ACCESSING_BITS_8_15)
972422         {
973            verboselog(space->machine, 2, "scc68070_periphs_r: Timer Control Register: %02x & %04x\n", scc68070_regs.timers.timer_control_register, mem_mask);
423            verboselog(space->machine, 11, "scc68070_periphs_r: Timer Status Register: %02x & %04x\n", scc68070_regs.timers.timer_status_register, mem_mask);
974424         }
975         return (scc68070_regs.timers.timer_control_register << 8) | scc68070_regs.timers.timer_status_register;
425         return (scc68070_regs.timers.timer_status_register << 8) | scc68070_regs.timers.timer_control_register;
976426         break;
977427      case 0x2022/2:
978428         verboselog(space->machine, 2, "scc68070_periphs_r: Timer Reload Register: %04x & %04x\n", scc68070_regs.timers.reload_register, mem_mask);
r5895r5896
1136586   {
1137587      // Interupts: 80001001
1138588      case 0x1000/2: // LIR priority level
589         verboselog(space->machine, 2, "scc68070_periphs_w: LIR: %04x & %04x\n", data, mem_mask);
1139590         COMBINE_DATA(&scc68070_regs.lir);
1140591         break;
1141592
r5895r5896
1201652      case 0x2016/2:
1202653         if(ACCESSING_BITS_0_7)
1203654         {
1204//            verboselog(space->machine, 2, "scc68070_periphs_w: UART Command Register: %04x & %04x\n", data, mem_mask);
655            verboselog(space->machine, 2, "scc68070_periphs_w: UART Command Register: %04x & %04x\n", data, mem_mask);
1205656            scc68070_regs.uart.command_register = data & 0x00ff;
1206657         }
1207658         break;
1208659      case 0x2018/2:
1209660         if(ACCESSING_BITS_0_7)
1210661         {
1211            //verboselog(space->machine, 2, "scc68070_periphs_w: UART Transmit Holding Register: %04x & %04x\n", data, mem_mask);
662            verboselog(space->machine, 2, "scc68070_periphs_w: UART Transmit Holding Register: %04x & %04x\n", data, mem_mask);
1212663            if(data >= 0x20 && data < 0x7f)
1213664            {
1214665               printf( "%c", data & 0x00ff );
r5895r5896
1228679      case 0x2020/2:
1229680         if(ACCESSING_BITS_0_7)
1230681         {
1231            verboselog(space->machine, 2, "scc68070_periphs_w: Timer Status Register: %04x & %04x\n", data, mem_mask);
1232            scc68070_regs.timers.timer_status_register &= ~(data & 0x00ff);
1233            if(scc68070_regs.picr1 & 7)
1234            {
1235               cputag_set_input_line(space->machine, "maincpu", M68K_IRQ_1 + ((scc68070_regs.picr1 & 7) - 1), CLEAR_LINE);
1236            }
682            verboselog(space->machine, 2, "scc68070_periphs_w: Timer Control Register: %04x & %04x\n", data, mem_mask);
683            scc68070_regs.timers.timer_control_register = data & 0x00ff;
1237684         }
1238685         if(ACCESSING_BITS_8_15)
1239686         {
1240            verboselog(space->machine, 2, "scc68070_periphs_w: Timer Control Register: %04x & %04x\n", data, mem_mask);
1241            scc68070_regs.timers.timer_control_register = data >> 8;
687            verboselog(space->machine, 11, "scc68070_periphs_w: Timer Status Register: %04x & %04x\n", data, mem_mask);
688            scc68070_regs.timers.timer_status_register &= ~(data >> 8);
689            if(!scc68070_regs.timers.timer_status_register)
690            {
691               UINT8 interrupt = scc68070_regs.picr1 & 7;
692               cputag_set_input_line(space->machine, "maincpu", M68K_IRQ_1 + (interrupt - 1), CLEAR_LINE);
693            }
1242694         }
1243695         break;
1244696      case 0x2022/2:
r5895r5896
1420872static READ16_HANDLER( cdic_r )
1421873{
1422874   verboselog(space->machine, 0, "cdic_r: UNIMPLEMENTED: Unknown address: %04x & %04x\n", offset*2, mem_mask);
1423   return 0;
875   if(offset == 0x1400/2 || offset == 0x1402/2)
876   {
877   #if ENABLE_UART_PRINTING
878      return 0x1234;
879   #endif
880   }
881   if(offset == 0x3ff6/2)
882   {
883      //return 0x8000;
884   }
885   if(offset == 0x3ffe/2)
886   {
887      //return 0x8000;
888   }
889   return cdic_ram[offset];
1424890}
1425891
1426892static WRITE16_HANDLER( cdic_w )
1427893{
1428894   verboselog(space->machine, 0, "cdic_w: UNIMPLEMENTED: Unknown address: %04x = %04x & %04x\n", offset*2, data, mem_mask);
895   //COMBINE_DATA(&cdic_ram[offset]);
1429896}
1430897
1431static READ16_HANDLER( uart_debug_r )
1432{
1433#if ENABLE_UART_PRINTING
1434   return 0x1234;
1435#else
1436   return 0;
1437#endif
1438}
1439
1440898UINT8 slave_register;
1441899UINT8 slave_read_index;
1442900
1443901static READ16_HANDLER( slave_r )
1444902{
903   static UINT32 read_count = 0;
904   static UINT32 return_count = 0;
1445905   verboselog(space->machine, 0, "slave_r: UNIMPLEMENTED: Unknown address: %04x & %04x\n", offset*2, mem_mask);
906   if(offset == 0x00)
907   {
908      switch(slave_register)
909      {
910         case 0xf7:
911            switch(read_count)
912            {
913               case 0:
914                  switch(return_count)
915                  {
916                     case 0:
917                     case 1:
918                     case 2:
919                     case 3:
920                        return_count++;
921                        if(return_count == 4)
922                        {
923                           read_count++;
924                           return_count = 0;
925                        }
926                        return 0;
927                  }
928                  break;
929               case 1:
930                  switch(return_count)
931                  {
932                     case 0:
933                        return_count++;
934                        return 0x35;
935                     case 1:
936                        return_count++;
937                        return 0x0d;
938                     case 2:
939                        return_count++;
940                        return 0x03;
941                     case 3:
942                        return_count = 0;
943                        read_count = 0;
944                        return 0x70;
945                  }
946                  break;
947               default:
948                  return 0;
949                  break;
950            }
951            break;
952         default:
953            break;
954      }
955      return 0x0000;
956   }
1446957   if(offset == 0x02)
1447958   {
1448959      if(slave_read_index == 0)
r5895r5896
1474985      {
1475986         slave_register = data & 0x00ff;
1476987         slave_read_index = 0;
988         if(slave_register == 0xf7)
989         {
990            timer_adjust_oneshot(test_timer, ATTOTIME_IN_HZ(10000), 0);
991         }
1477992      }
1478993   }
1479994}
r5895r5896
14881003
14891004static READ16_HANDLER( m48t08_r )
14901005{
1491   verboselog(space->machine, 0, "m48t08_r: %04x = %02x & %04x\n", offset, m48t08.nvram[offset], mem_mask );
1006   verboselog(space->machine, 4, "m48t08_r: %04x = %02x & %04x\n", offset, m48t08.nvram[offset], mem_mask );
14921007   return m48t08.nvram[offset] << 8;
14931008}
14941009
14951010static WRITE16_HANDLER( m48t08_w )
14961011{
1497   verboselog(space->machine, 0, "m48t08_w: %04x = %02x\n", offset, data >> 8);
1012   verboselog(space->machine, 4, "m48t08_w: %04x = %02x\n", offset, data >> 8);
14981013   switch(offset)
14991014   {
15001015      case 0x1ff9:
r5895r5896
15451060   }
15461061}
15471062
1063/*************************
1064*     Video Hardware     *
1065*************************/
1066
1067typedef struct
1068{
1069   UINT8 csrr;
1070   UINT16 csrw;
1071   UINT16 dcr;
1072   UINT16 vsr;
1073   UINT16 ddr;
1074   UINT16 dcp;
1075   UINT32 clut[256];
1076   UINT8 image_coding_method;
1077   UINT8 transparency_control;
1078   UINT8 plane_order;
1079   UINT8 clut_bank;
1080   UINT8 transparent_color_a;
1081   UINT8 reserved0;
1082   UINT8 transparent_color_b;
1083   UINT8 mask_color_a;
1084   UINT8 reserved1;
1085   UINT8 mask_color_b;
1086   UINT8 dyuv_abs_start_a;
1087   UINT8 dyuv_abs_start_b;
1088   UINT8 reserved2;
1089   UINT8 cursor_position;
1090   UINT8 cursor_control;
1091   UINT8 cursor_pattern[16];
1092   UINT8 region_control[8];
1093   UINT8 backdrop_color;
1094   UINT8 mosaic_hold_a;
1095   UINT8 mosaic_hold_b;
1096   UINT8 weight_factor_a;
1097   UINT8 weight_factor_b;
1098} mcd212_channel_t;
1099
1100typedef struct
1101{
1102   mcd212_channel_t channel[2];
1103   emu_timer *scan_timer;
1104} mcd212_t;
1105
1106mcd212_t mcd212;
1107
1108#define MCD212_CSR2R_IT1      0x0004   // Interrupt 1
1109#define MCD212_CSR2R_IT2      0x0002   // Interrupt 2
1110#define MCD212_CSR2R_BE         0x0001   // Bus Error
1111
1112#define MCD212_DCR_DE         0x8000   // Display Enable
1113#define MCD212_DCR_CF         0x4000   // Crystal Frequency
1114#define MCD212_DCR_FD         0x2000   // Frame Duration
1115#define MCD212_DCR_SM         0x1000   // Scan Mode
1116#define MCD212_DCR_CM         0x0800   // Color Mode Ch.1/2
1117#define MCD212_DCR_ICA         0x0200   // ICA Enable Ch.1/2
1118#define MCD212_DCR_DCA         0x0100   // DCA Enable Ch.1/2
1119
1120#define MCD212_DDR_FT         0x0300   // Display File Type
1121#define MCD212_DDR_FT_BMP      0x0000   // Bitmap
1122#define MCD212_DDR_FT_BMP2      0x0100   // Bitmap (alt.)
1123#define MCD212_DDR_FT_RLE      0x0200   // Run-Length Encoded
1124#define MCD212_DDR_FT_MOSAIC   0x0300   // Mosaic
1125
1126static READ16_HANDLER(mcd212_r)
1127{
1128   UINT8 channel = 1 - (offset / 8);
1129   switch(offset)
1130   {
1131      case 0x00/2:
1132      case 0x10/2:
1133         if(ACCESSING_BITS_0_7)
1134         {
1135            verboselog(space->machine, 2, "mcd212_r: Status Register %d: %02x & %04x\n", channel + 1, mcd212.channel[1 - (offset / 8)].csrr, mem_mask);
1136            if(channel == 0)
1137            {
1138               return mcd212.channel[0].csrr | 0x20;
1139            }
1140            else
1141            {
1142               UINT8 old_csr = mcd212.channel[1].csrr;
1143               UINT8 interrupt1 = (scc68070_regs.lir >> 4) & 7;
1144               UINT8 interrupt2 = scc68070_regs.lir & 7;
1145               mcd212.channel[1].csrr &= ~(MCD212_CSR2R_IT1 | MCD212_CSR2R_IT2);
1146               if(interrupt1)
1147               {
1148                  cputag_set_input_line(space->machine, "maincpu", M68K_IRQ_1 + (interrupt1 - 1), CLEAR_LINE);
1149               }
1150               if(interrupt2)
1151               {
1152                  cputag_set_input_line(space->machine, "maincpu", M68K_IRQ_1 + (interrupt2 - 1), CLEAR_LINE);
1153               }
1154               return old_csr;
1155            }
1156         }
1157         else
1158         {
1159            verboselog(space->machine, 2, "mcd212_r: Unknown Register %d: %04x\n", channel + 1, mem_mask);
1160         }
1161         break;
1162      case 0x02/2:
1163      case 0x12/2:
1164         verboselog(space->machine, 2, "mcd212_r: Display Command Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, mcd212.channel[1 - (offset / 8)].dcr, mem_mask);
1165         return mcd212.channel[1 - (offset / 8)].dcr;
1166         break;
1167      case 0x04/2:
1168      case 0x14/2:
1169         verboselog(space->machine, 2, "mcd212_r: Video Start Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, mcd212.channel[1 - (offset / 8)].vsr, mem_mask);
1170         return mcd212.channel[1 - (offset / 8)].vsr;
1171         break;
1172      case 0x08/2:
1173      case 0x18/2:
1174         verboselog(space->machine, 2, "mcd212_r: Display Decoder Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, mcd212.channel[1 - (offset / 8)].ddr, mem_mask);
1175         return mcd212.channel[1 - (offset / 8)].ddr;
1176         break;
1177      case 0x0a/2:
1178      case 0x1a/2:
1179         verboselog(space->machine, 2, "mcd212_r: DCA Pointer Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, mcd212.channel[1 - (offset / 8)].dcp, mem_mask);
1180         return mcd212.channel[1 - (offset / 8)].dcp;
1181         break;
1182      default:
1183         verboselog(space->machine, 2, "mcd212_r: Unknown Register %d & %04x\n", (1 - (offset / 8)) + 1, mem_mask);
1184         break;
1185   }
1186
1187   return 0;
1188}
1189
1190static WRITE16_HANDLER(mcd212_w)
1191{
1192   switch(offset)
1193   {
1194      case 0x00/2:
1195      case 0x10/2:
1196         verboselog(space->machine, 2, "mcd212_w: Status Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
1197         COMBINE_DATA(&mcd212.channel[1 - (offset / 8)].csrw);
1198         break;
1199      case 0x02/2:
1200      case 0x12/2:
1201         verboselog(space->machine, 2, "mcd212_w: Display Command Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
1202         COMBINE_DATA(&mcd212.channel[1 - (offset / 8)].dcr);
1203         break;
1204      case 0x04/2:
1205      case 0x14/2:
1206         verboselog(space->machine, 2, "mcd212_w: Video Start Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
1207         COMBINE_DATA(&mcd212.channel[1 - (offset / 8)].vsr);
1208         break;
1209      case 0x08/2:
1210      case 0x18/2:
1211         verboselog(space->machine, 2, "mcd212_w: Display Decoder Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
1212         COMBINE_DATA(&mcd212.channel[1 - (offset / 8)].ddr);
1213         break;
1214      case 0x0a/2:
1215      case 0x1a/2:
1216         verboselog(space->machine, 2, "mcd212_w: DCA Pointer Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
1217         COMBINE_DATA(&mcd212.channel[1 - (offset / 8)].dcp);
1218         break;
1219      default:
1220         verboselog(space->machine, 2, "mcd212_w: Unknown Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask);
1221         break;
1222   }
1223}
1224
1225INLINE void mcd212_set_register(running_machine *machine, int channel, UINT8 reg, UINT32 value)
1226{
1227   switch(reg)
1228   {
1229      case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: // CLUT 0 - 63
1230      case 0x88: case 0x89: case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e: case 0x8f:
1231      case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97:
1232      case 0x98: case 0x99: case 0x9a: case 0x9b: case 0x9c: case 0x9d: case 0x9e: case 0x9f:
1233      case 0xa0: case 0xa1: case 0xa2: case 0xa3: case 0xa4: case 0xa5: case 0xa6: case 0xa7:
1234      case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf:
1235      case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7:
1236      case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf:
1237         verboselog(machine, 11, "          %04xxxxx: %d: CLUT[%d] = %08x\n", channel * 0x20, channel, mcd212.channel[channel].clut_bank * 0x40 + (reg - 0x80), value );
1238         mcd212.channel[channel].clut[mcd212.channel[channel].clut_bank * 0x40 + (reg - 0x80)] = value;
1239         break;
1240      case 0xc0: // Image Coding Method
1241         if(channel == 0)
1242         {
1243            verboselog(machine, 11, "          %04xxxxx: %d: Image Coding Method = %08x\n", channel * 0x20, channel, value );
1244            mcd212.channel[channel].image_coding_method = value;
1245         }
1246         break;
1247      case 0xc1: // Transparency Control
1248         if(channel == 0)
1249         {
1250            verboselog(machine, 11, "          %04xxxxx: %d: Transparency Control = %08x\n", channel * 0x20, channel, value );
1251            mcd212.channel[channel].transparency_control = value;
1252         }
1253         break;
1254      case 0xc2: // Plane Order
1255         if(channel == 0)
1256         {
1257            verboselog(machine, 11, "          %04xxxxx: %d: Plane Order = %08x\n", channel * 0x20, channel, value & 7);
1258            mcd212.channel[channel].plane_order = value & 0x00000007;
1259         }
1260         break;
1261      case 0xc3: // CLUT Bank Register
1262         verboselog(machine, 11, "          %04xxxxx: %d: CLUT Bank Register = %08x\n", channel * 0x20, channel, value & 3);
1263         mcd212.channel[channel].clut_bank = value & 0x00000003;
1264         break;
1265      case 0xc4: // Transparent Color A
1266         if(channel == 0)
1267         {
1268            verboselog(machine, 11, "          %04xxxxx: %d: Transparent Color A = %08x\n", channel * 0x20, channel, value );
1269            mcd212.channel[channel].transparent_color_a = value;
1270         }
1271         break;
1272      case 0xc6: // Transparent Color B
1273         if(channel == 1)
1274         {
1275            verboselog(machine, 11, "          %04xxxxx: %d: Transparent Color B = %08x\n", channel * 0x20, channel, value );
1276            mcd212.channel[channel].transparent_color_b = value;
1277         }
1278         break;
1279      case 0xc7: // Mask Color A
1280         if(channel == 0)
1281         {
1282            verboselog(machine, 11, "          %04xxxxx: %d: Mask Color A = %08x\n", channel * 0x20, channel, value );
1283            mcd212.channel[channel].mask_color_a = value;
1284         }
1285         break;
1286      case 0xc9: // Mask Color B
1287         if(channel == 1)
1288         {
1289            verboselog(machine, 11, "          %04xxxxx: %d: Mask Color B = %08x\n", channel * 0x20, channel, value );
1290            mcd212.channel[channel].mask_color_b = value;
1291         }
1292         break;
1293      case 0xca: // Delta YUV Absolute Start Value A
1294         if(channel == 0)
1295         {
1296            verboselog(machine, 11, "          %04xxxxx: %d: Delta YUV Absolute Start Value A = %08x\n", channel * 0x20, channel, value );
1297            mcd212.channel[channel].dyuv_abs_start_a = value;
1298         }
1299         break;
1300      case 0xcb: // Delta YUV Absolute Start Value B
1301         if(channel == 1)
1302         {
1303            verboselog(machine, 11, "          %04xxxxx: %d: Delta YUV Absolute Start Value B = %08x\n", channel * 0x20, channel, value );
1304            mcd212.channel[channel].dyuv_abs_start_b = value;
1305         }
1306         break;
1307      case 0xcd: // Cursor Position
1308         if(channel == 0)
1309         {
1310            verboselog(machine, 11, "          %04xxxxx: %d: Cursor Position = %08x\n", channel * 0x20, channel, value );
1311            mcd212.channel[channel].cursor_position = value;
1312         }
1313         break;
1314      case 0xce: // Cursor Control
1315         if(channel == 0)
1316         {
1317            verboselog(machine, 11, "          %04xxxxx: %d: Cursor Control = %08x\n", channel * 0x20, channel, value );
1318            mcd212.channel[channel].cursor_control = value;
1319         }
1320         break;
1321      case 0xcf: // Cursor Pattern
1322         if(channel == 0)
1323         {
1324            verboselog(machine, 11, "          %04xxxxx: %d: Cursor Pattern[%d] = %04x\n", channel * 0x20, channel, (value >> 16) & 0x000f, value & 0x0000ffff);
1325            mcd212.channel[channel].cursor_pattern[(value >> 16) & 0x000f] = value & 0x0000ffff;
1326         }
1327         break;
1328      case 0xd0: // Region Control 0-7
1329      case 0xd1:
1330      case 0xd2:
1331      case 0xd3:
1332      case 0xd4:
1333      case 0xd5:
1334      case 0xd6:
1335      case 0xd7:
1336         verboselog(machine, 11, "          %04xxxxx: %d: Region Control %d = %08x\n", channel * 0x20, channel, reg & 7, value );
1337         mcd212.channel[channel].region_control[reg & 7] = value;
1338         break;
1339      case 0xd8: // Backdrop Color
1340         if(channel == 0)
1341         {
1342            verboselog(machine, 11, "          %04xxxxx: %d: Backdrop Color = %08x\n", channel * 0x20, channel, value );
1343            mcd212.channel[channel].backdrop_color = value;
1344         }
1345         break;
1346      case 0xd9: // Mosaic Pixel Hold Factor A
1347         if(channel == 0)
1348         {
1349            verboselog(machine, 11, "          %04xxxxx: %d: Mosaic Pixel Hold Factor A = %08x\n", channel * 0x20, channel, value );
1350            mcd212.channel[channel].mosaic_hold_a = value;
1351         }
1352         break;
1353      case 0xda: // Mosaic Pixel Hold Factor B
1354         if(channel == 1)
1355         {
1356            verboselog(machine, 11, "          %04xxxxx: %d: Mosaic Pixel Hold Factor B = %08x\n", channel * 0x20, channel, value );
1357            mcd212.channel[channel].mosaic_hold_b = value;
1358         }
1359         break;
1360      case 0xdb: // Weight Factor A
1361         if(channel == 0)
1362         {
1363            verboselog(machine, 11, "          %04xxxxx: %d: Weight Factor A = %08x\n", channel * 0x20, channel, value );
1364            mcd212.channel[channel].weight_factor_a = value;
1365         }
1366         break;
1367      case 0xdc: // Weight Factor B
1368         if(channel == 1)
1369         {
1370            verboselog(machine, 11, "          %04xxxxx: %d: Weight Factor B = %08x\n", channel * 0x20, channel, value );
1371            mcd212.channel[channel].weight_factor_b = value;
1372         }
1373         break;
1374   }
1375}
1376
1377INLINE void mcd212_set_vsr(int channel, UINT32 value)
1378{
1379   mcd212.channel[channel].vsr = value & 0x0000ffff;
1380   mcd212.channel[channel].dcr &= 0xffc0;
1381   mcd212.channel[channel].dcr |= (value >> 16) & 0x003f;
1382}
1383
1384INLINE UINT32 mcd212_get_vsr(int channel)
1385{
1386   return ((mcd212.channel[channel].dcr & 0x3f) << 16) | mcd212.channel[channel].vsr;
1387}
1388
1389INLINE void mcd212_set_dcp(int channel, UINT32 value)
1390{
1391   mcd212.channel[channel].dcp = value & 0x0000ffff;
1392   mcd212.channel[channel].ddr &= 0xffc0;
1393   mcd212.channel[channel].ddr |= (value >> 16) & 0x003f;
1394}
1395
1396INLINE UINT32 mcd212_get_dcp(int channel)
1397{
1398   return ((mcd212.channel[channel].ddr & 0x3f) << 16) | mcd212.channel[channel].dcp;
1399}
1400
1401INLINE void mcd212_set_display_parameters(int channel, UINT8 value)
1402{
1403   mcd212.channel[channel].ddr &= 0xf0ff;
1404   mcd212.channel[channel].ddr |= (value & 0x0f) << 8;
1405   mcd212.channel[channel].dcr &= 0xf7ff;
1406   mcd212.channel[channel].dcr |= (value & 0x10) << 7;
1407}
1408
1409static void mcd212_process_ica(running_machine *machine, int channel)
1410{
1411   UINT16 *ica = channel ? planeb : planea;
1412   UINT32 addr = 0x000400/2;
1413   UINT32 cmd = 0;
1414   while(1)
1415   {
1416      UINT8 stop = 0;
1417      cmd = ica[addr++] << 16;
1418      cmd |= ica[addr++];
1419      switch((cmd & 0xff000000) >> 24)
1420      {
1421         case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07:   // STOP
1422         case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: case 0x0e: case 0x0f:
1423            verboselog(machine, 11, "%08x: %08x: ICA %d: STOP\n", addr * 2 + channel * 0x200000, cmd, channel );
1424            stop = 1;
1425            break;
1426         case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17: // NOP
1427         case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f:
1428            verboselog(machine, 11, "%08x: %08x: ICA %d: NOP\n", addr * 2 + channel * 0x200000, cmd, channel );
1429            break;
1430         case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27: // RELOAD DCP
1431         case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f:
1432            verboselog(machine, 11, "%08x: %08x: ICA %d: RELOAD DCP\n", addr * 2 + channel * 0x200000, cmd, channel );
1433            mcd212_set_dcp(channel, cmd & 0x001fffff);
1434            break;
1435         case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37: // RELOAD DCP and STOP
1436         case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3c: case 0x3d: case 0x3e: case 0x3f:
1437            verboselog(machine, 11, "%08x: %08x: ICA %d: RELOAD DCP and STOP\n", addr * 2 + channel * 0x200000, cmd, channel );
1438            mcd212_set_dcp(channel, cmd & 0x001fffff);
1439            stop = 1;
1440            break;
1441         case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46: case 0x47: // RELOAD ICA
1442         case 0x48: case 0x49: case 0x4a: case 0x4b: case 0x4c: case 0x4d: case 0x4e: case 0x4f:
1443            verboselog(machine, 11, "%08x: %08x: ICA %d: RELOAD ICA\n", addr * 2 + channel * 0x200000, cmd, channel );
1444            addr = (cmd & 0x001fffff) / 2;
1445            break;
1446         case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57: // RELOAD VSR and STOP
1447         case 0x58: case 0x59: case 0x5a: case 0x5b: case 0x5c: case 0x5d: case 0x5e: case 0x5f:
1448            verboselog(machine, 11, "%08x: %08x: ICA %d: RELOAD VSR and STOP\n", addr * 2 + channel * 0x200000, cmd, channel );
1449            mcd212_set_vsr(channel, cmd & 0x001fffff);
1450            stop = 1;
1451            break;
1452         case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67: // INTERRUPT
1453         case 0x68: case 0x69: case 0x6a: case 0x6b: case 0x6c: case 0x6d: case 0x6e: case 0x6f:
1454            verboselog(machine, 11, "%08x: %08x: ICA %d: INTERRUPT\n", addr * 2 + channel * 0x200000, cmd, channel );
1455            mcd212.channel[1].csrr |= 1 << (2 - channel);
1456            if(mcd212.channel[1].csrr & MCD212_CSR2R_IT1)
1457            {
1458               UINT8 interrupt = (scc68070_regs.lir >> 4) & 7;
1459               if(interrupt)
1460               {
1461                  verboselog(machine, 4, "Flagging interrupt 1, line %d\n", interrupt );
1462                  cpu_set_input_line_vector(cputag_get_cpu(machine, "maincpu"), M68K_IRQ_1 + (interrupt - 1), 56 + interrupt);
1463                  cputag_set_input_line(machine, "maincpu", M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE);
1464               }
1465            }
1466            if(mcd212.channel[1].csrr & MCD212_CSR2R_IT2)
1467            {
1468               UINT8 interrupt = scc68070_regs.lir & 7;
1469               if(interrupt)
1470               {
1471                  verboselog(machine, 4, "Flagging interrupt 2, line %d\n", interrupt );
1472                  cpu_set_input_line_vector(cputag_get_cpu(machine, "maincpu"), M68K_IRQ_1 + (interrupt - 1), 24 + interrupt);
1473                  cputag_set_input_line(machine, "maincpu", M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE);
1474               }
1475            }
1476            break;
1477         case 0x78: case 0x79: case 0x7a: case 0x7b: case 0x7c: case 0x7d: case 0x7e: case 0x7f: // RELOAD DISPLAY PARAMETERS
1478            verboselog(machine, 11, "%08x: %08x: ICA %d: RELOAD DISPLAY PARAMETERS\n", addr * 2 + channel * 0x200000, cmd, channel );
1479            mcd212_set_display_parameters(channel, cmd & 0x1f);
1480            break;
1481         default:
1482            mcd212_set_register(machine, channel, cmd >> 24, cmd & 0x00ffffff);
1483            break;
1484      }
1485      if(stop)
1486      {
1487         break;
1488      }
1489   }
1490}
1491
1492static void mcd212_process_dca(running_machine *machine, int channel)
1493{
1494   UINT16 *dca = channel ? planeb : planea;
1495   UINT32 addr = mcd212_get_dcp(channel) / 2;
1496   UINT32 cmd = 0;
1497   UINT32 count = 0;
1498   UINT32 max = (mcd212.channel[channel].dcr & MCD212_DCR_CM) ? 64 : 32;
1499   while(1)
1500   {
1501      UINT8 stop = 0;
1502      cmd = dca[addr++] << 16;
1503      cmd |= dca[addr++];
1504      count += 4;
1505      switch((cmd & 0xff000000) >> 24)
1506      {
1507         case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07:   // STOP
1508         case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: case 0x0e: case 0x0f:
1509            verboselog(machine, 11, "%08x: %08x: DCA %d: STOP\n", addr * 2 + channel * 0x200000, cmd, channel );
1510            stop = 1;
1511            break;
1512         case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17: // NOP
1513         case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f:
1514            verboselog(machine, 11, "%08x: %08x: DCA %d: NOP\n", addr * 2 + channel * 0x200000, cmd, channel );
1515            break;
1516         case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27: // RELOAD DCP
1517         case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f:
1518            verboselog(machine, 11, "%08x: %08x: DCA %d: RELOAD DCP (NOP)\n", addr * 2 + channel * 0x200000, cmd, channel );
1519            break;
1520         case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37: // RELOAD DCP and STOP
1521         case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3c: case 0x3d: case 0x3e: case 0x3f:
1522            verboselog(machine, 11, "%08x: %08x: DCA %d: RELOAD DCP and STOP\n", addr * 2 + channel * 0x200000, cmd, channel );
1523            mcd212_set_dcp(channel, cmd & 0x001fffff);
1524            stop = 1;
1525            break;
1526         case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46: case 0x47: // RELOAD VSR
1527         case 0x48: case 0x49: case 0x4a: case 0x4b: case 0x4c: case 0x4d: case 0x4e: case 0x4f:
1528            verboselog(machine, 11, "%08x: %08x: DCA %d: RELOAD VSR\n", addr * 2 + channel * 0x200000, cmd, channel );
1529            mcd212_set_vsr(channel, cmd & 0x001fffff);
1530            break;
1531         case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57: // RELOAD VSR and STOP
1532         case 0x58: case 0x59: case 0x5a: case 0x5b: case 0x5c: case 0x5d: case 0x5e: case 0x5f:
1533            verboselog(machine, 11, "%08x: %08x: DCA %d: RELOAD VSR and STOP\n", addr * 2 + channel * 0x200000, cmd, channel );
1534            mcd212_set_vsr(channel, cmd & 0x001fffff);
1535            stop = 1;
1536            break;
1537         case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67: // INTERRUPT
1538         case 0x68: case 0x69: case 0x6a: case 0x6b: case 0x6c: case 0x6d: case 0x6e: case 0x6f:
1539            verboselog(machine, 11, "%08x: %08x: DCA %d: INTERRUPT\n", addr * 2 + channel * 0x200000, cmd, channel );
1540            mcd212.channel[1].csrr |= 1 << (2 - channel);
1541            if(mcd212.channel[1].csrr & MCD212_CSR2R_IT1)
1542            {
1543               UINT8 interrupt = (scc68070_regs.lir >> 4) & 7;
1544               if(interrupt)
1545               {
1546                  cpu_set_input_line_vector(cputag_get_cpu(machine, "maincpu"), M68K_IRQ_1 + (interrupt - 1), 24 + interrupt);
1547                  cputag_set_input_line(machine, "maincpu", M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE);
1548               }
1549            }
1550            if(mcd212.channel[1].csrr & MCD212_CSR2R_IT2)
1551            {
1552               UINT8 interrupt = scc68070_regs.lir & 7;
1553               if(interrupt)
1554               {
1555                  cpu_set_input_line_vector(cputag_get_cpu(machine, "maincpu"), M68K_IRQ_1 + (interrupt - 1), 24 + interrupt);
1556                  cputag_set_input_line(machine, "maincpu", M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE);
1557               }
1558            }
1559            break;
1560         case 0x78: case 0x79: case 0x7a: case 0x7b: case 0x7c: case 0x7d: case 0x7e: case 0x7f: // RELOAD DISPLAY PARAMETERS
1561            verboselog(machine, 11, "%08x: %08x: DCA %d: RELOAD DISPLAY PARAMETERS\n", addr * 2 + channel * 0x200000, cmd, channel );
1562            mcd212_set_display_parameters(channel, cmd & 0x1f);
1563            break;
1564         default:
1565            mcd212_set_register(machine, channel, cmd >> 24, cmd & 0x00ffffff);
1566            break;
1567      }
1568      if(stop != 0 || count == max)
1569      {
1570         break;
1571      }
1572   }
1573}
1574
1575static void mcd212_process_vsr(running_machine *machine, int channel, UINT32 *pixels)
1576{
1577   UINT8 *data = channel ? (UINT8*)planeb : (UINT8*)planea;
1578   UINT32 vsr = mcd212_get_vsr(channel) & 0x0007ffff;
1579   UINT8 done = 0;
1580   int x = 0;
1581
1582   //printf( "vsr before: %08x: ", vsr );
1583   //fflush(stdout);
1584
1585   /*
1586   switch(mcd212.channel[channel].ddr & MCD212_DDR_FT)
1587   {
1588      case MCD212_DDR_FT_BMP:
1589      case MCD212_DDR_FT_BMP2:
1590         if(mcd212.channel[channel].dcr & MCD212_DCR_CM)
1591         {
1592            printf( "4-bit Bitmap: " );
1593         }
1594         else
1595         {
1596            static UINT8 fuck = 0;
1597            printf( "8-bit Bitmap: " );
1598            if(!fuck)
1599            {
1600               FILE* out = fopen("planea.bin","wb");
1601               int i = 0;
1602               for(i = 0; i < 0x80000; i += 2)
1603               {
1604                  UINT8 temp1, temp2;
1605                  temp1 = planea[i/2] >> 8;
1606                  temp2 = planea[i/2] & 0x00ff;
1607                  fwrite(&temp1, 1, 1, out);
1608                  fwrite(&temp2, 1, 1, out);
1609               }
1610               fflush(out);
1611               fclose(out);
1612               out = fopen("planeb.bin","wb");
1613               for(i = 0; i < 0x80000; i += 2)
1614               {
1615                  UINT8 temp1, temp2;
1616                  temp1 = planeb[i/2] >> 8;
1617                  temp2 = planeb[i/2] & 0x00ff;
1618                  fwrite(&temp1, 1, 1, out);
1619                  fwrite(&temp2, 1, 1, out);
1620               }
1621               fflush(out);
1622               fclose(out);
1623               fuck++;
1624
1625            }
1626         }
1627         break;
1628      case MCD212_DDR_FT_RLE:
1629         if(mcd212.channel[channel].dcr & MCD212_DCR_CM)
1630         {
1631            printf( "4-bit RLE: " );
1632         }
1633         else
1634         {
1635            printf( "8-bit RLE: " );
1636         }
1637         break;
1638      case MCD212_DDR_FT_MOSAIC:
1639         if(mcd212.channel[channel].dcr & MCD212_DCR_CM)
1640         {
1641            printf( "4-bit Mosaic: " );
1642         }
1643         else
1644         {
1645            printf( "8-bit Mosaic: " );
1646         }
1647         break;
1648   }
1649   */
1650
1651   while(!done)
1652   {
1653      UINT8 byte = data[vsr++ ^ 1];
1654      //printf( "%02x ", byte );
1655      //fflush(stdout);
1656      switch(mcd212.channel[channel].ddr & MCD212_DDR_FT)
1657      {
1658         case MCD212_DDR_FT_BMP:
1659         case MCD212_DDR_FT_BMP2:
1660            if(mcd212.channel[channel].dcr & MCD212_DCR_CM)
1661            {
1662               // 4-bit Bitmap
1663               verboselog(machine, 0, "Unsupported display mode: 4-bit Bitmap\n" );
1664            }
1665            else
1666            {
1667               // 8-bit Bitmap
1668               for(; x < 768; x++)
1669               {
1670                  pixels[x++] = mcd212.channel[channel].clut[byte];
1671                  pixels[x] = mcd212.channel[channel].clut[byte];
1672                  byte = data[vsr++ ^ 1];
1673               }
1674            }
1675            done = 1;
1676            break;
1677         case MCD212_DDR_FT_RLE:
1678            if(mcd212.channel[channel].dcr & MCD212_DCR_CM)
1679            {
1680               // 4-bit RLE
1681               verboselog(machine, 0, "Unsupported display mode: 4-bit RLE\n" );
1682               done = 1;
1683            }
1684            else
1685            {
1686               // 8-bit RLE
1687               fflush(stdout);
1688               if(byte & 0x80)
1689               {
1690                  // Run length
1691                  UINT8 length = data[vsr++ ^ 1];
1692                  //printf( "%02x ", length );
1693                  //fflush(stdout);
1694                  if(!length)
1695                  {
1696                     // Go to the end of the line
1697                     for(; x < 768; x++)
1698                     {
1699                        pixels[x++] = mcd212.channel[channel].clut[byte & 0x7f];
1700                        pixels[x] = mcd212.channel[channel].clut[byte & 0x7f];
1701                     }
1702                     done = 1;
1703                     mcd212_set_vsr(channel, vsr);
1704                  }
1705                  else
1706                  {
1707                     int end = x + (length * 2);
1708                     //printf( "x = %d length = %d end = %d\n", x, length * 2, end);
1709                     //fflush(stdout);
1710                     for(; x < end && x < 768; x++)
1711                     {
1712                        pixels[x++] = mcd212.channel[channel].clut[byte & 0x7f];
1713                        pixels[x] = mcd212.channel[channel].clut[byte & 0x7f];
1714                     }
1715                     if(x >= 768)
1716                     {
1717                        done = 1;
1718                        mcd212_set_vsr(channel, vsr);
1719                     }
1720                  }
1721               }
1722               else
1723               {
1724                  // Single pixel
1725                  pixels[x++] = mcd212.channel[channel].clut[byte & 0x7f];
1726                  pixels[x++] = mcd212.channel[channel].clut[byte & 0x7f];
1727                  if(x >= 768)
1728                  {
1729                     done = 1;
1730                     mcd212_set_vsr(channel, vsr);
1731                  }
1732               }
1733            }
1734            break;
1735         case MCD212_DDR_FT_MOSAIC:
1736            verboselog(machine, 0, "Unsupported display mode: Mosaic\n" );
1737            done = 1;
1738            break;
1739      }
1740   }
1741
1742   //printf( ": vsr after: %08x\n", vsr);
1743   //mcd212_set_vsr(channel, vsr);
1744}
1745
1746static void mcd212_draw_scanline(running_machine *machine, int y)
1747{
1748   bitmap_t *bitmap = tmpbitmap;
1749   UINT32 plane_a[768];
1750   UINT32 plane_b[768];
1751   UINT32 *scanline = BITMAP_ADDR32(bitmap, y, 0);
1752   int x;
1753   //prinf( "y=%d, m
1754   mcd212_process_vsr(machine, 0, plane_a);
1755   mcd212_process_vsr(machine, 1, plane_b);
1756   for(x = 0; x < 768; x++)
1757   {
1758      scanline[x] = plane_a[x];
1759   }
1760}
1761
1762TIMER_CALLBACK( mcd212_perform_scan )
1763{
1764   int scanline = video_screen_get_vpos(machine->primary_screen);
1765   if(/*mcd212.channel[0].dcr & MCD212_DCR_DE*/1)
1766   {
1767      if(scanline == 0)
1768      {
1769         // Process ICA
1770         int index = 0;
1771         mcd212.channel[0].csrr &= 0x7f;
1772         for(index = 0; index < 2; index++)
1773         {
1774            if(mcd212.channel[index].dcr & MCD212_DCR_ICA)
1775            {
1776               mcd212_process_ica(machine, index);
1777            }
1778         }
1779      }
1780      else if(scanline >= 22)
1781      {
1782         int index = 0;
1783         mcd212.channel[0].csrr |= 0x80;
1784         // Process VSR
1785         mcd212_draw_scanline(machine, scanline);
1786         // Process DCA
1787         for(index = 0; index < 2; index++)
1788         {
1789            if(mcd212.channel[index].dcr & MCD212_DCR_DCA)
1790            {
1791               mcd212_process_dca(machine, index);
1792            }
1793         }
1794      }
1795   }
1796   timer_adjust_oneshot(mcd212.scan_timer, video_screen_get_time_until_pos(machine->primary_screen, ( scanline + 1 ) % 262, 0), 0);
1797}
1798
1799static VIDEO_START(cdi)
1800{
1801   VIDEO_START_CALL(generic_bitmapped);
1802   mcd212.channel[0].csrr = 0x00;
1803   mcd212.channel[1].csrr = 0x00;
1804   mcd212.channel[0].clut_bank = 0;
1805   mcd212.channel[1].clut_bank = 0;
1806   mcd212.scan_timer = timer_alloc(machine, mcd212_perform_scan, 0);
1807   timer_adjust_oneshot(mcd212.scan_timer, video_screen_get_time_until_pos(machine->primary_screen, 0, 0), 0);
1808}
1809
1810/*************************
1811*      Memory maps       *
1812*************************/
1813
15481814static ADDRESS_MAP_START( cdi_mem, ADDRESS_SPACE_PROGRAM, 16 )
15491815   AM_RANGE(0x00000000, 0x0007ffff) AM_RAM AM_BASE(&planea)
15501816   AM_RANGE(0x00200000, 0x0027ffff) AM_RAM AM_BASE(&planeb)
1551   AM_RANGE(0x00300000, 0x003013ff) AM_READWRITE(cdic_r, cdic_w)
1552   AM_RANGE(0x00301400, 0x00301403) AM_READ(uart_debug_r)
1817   AM_RANGE(0x00300000, 0x00303fff) AM_READWRITE(cdic_r, cdic_w) AM_BASE(&cdic_ram)
15531818   AM_RANGE(0x00310000, 0x00317fff) AM_READWRITE(slave_r, slave_w)
15541819   //AM_RANGE(0x00318000, 0x0031ffff) AM_NOP
15551820   AM_RANGE(0x00320000, 0x00323fff) AM_READWRITE(m48t08_r, m48t08_w)
r5895r5896
15601825   AM_RANGE(0x80000000, 0x8000807f) AM_READWRITE(scc68070_periphs_r, scc68070_periphs_w)
15611826ADDRESS_MAP_END
15621827
1563
15641828/*************************
15651829*      Input ports       *
15661830*************************/
r5895r5896
15681832static INPUT_PORTS_START( cdi )
15691833INPUT_PORTS_END
15701834
1571
15721835static MACHINE_RESET( cdi )
15731836{
15741837   UINT16 *src   = (UINT16*)memory_region( machine, "maincpu" );
r5895r5896
15771840   memcpy(dst, src, 0x8);
15781841
15791842   //memcpy(m48t08.nvram, srcnv, 0x2000);
1580   m48t08.nvram[0x1ff9] = 0x80;
1843   //m48t08.nvram[0x1ff9] = 0x80;
15811844
15821845   scc68070_regs.timers.timer0_timer = timer_alloc(machine, scc68070_timer0_callback, 0);
1846   timer_adjust_oneshot(scc68070_regs.timers.timer0_timer, attotime_never, 0);
15831847
1848   test_timer = timer_alloc(machine, test_timer_callback, 0);
1849   timer_adjust_oneshot(test_timer, attotime_never, 0);
1850
15841851   device_reset(cputag_get_cpu(machine, "maincpu"));
15851852}
15861853
r5895r5896
15881855*    Machine Drivers     *
15891856*************************/
15901857
1591//static INTERRUPT_GEN( cdi_irq )
1592//{
1593//  if(input_code_pressed(KEYCODE_Z))
1594//      cpu_set_input_line(device->machine->firstcpu, 1, HOLD_LINE);
1595//  ram[0x2004/2]^=0xffff;
1596//}
1597
15981858static MACHINE_DRIVER_START( cdi )
15991859   MDRV_CPU_ADD("maincpu", SCC68070, CLOCK_A/2)   /* SCC-68070 CCA84 datasheet */
16001860   MDRV_CPU_PROGRAM_MAP(cdi_mem)
1601    //MDRV_CPU_VBLANK_INT("screen", cdi_irq) /* no interrupts? (it erases the vectors..) */
16021861
16031862   MDRV_SCREEN_ADD("screen", RASTER)
16041863   MDRV_SCREEN_REFRESH_RATE(60)
16051864   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0))
16061865   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
16071866   MDRV_SCREEN_SIZE(768, 262)
1608   MDRV_SCREEN_VISIBLE_AREA(0, 639-1, 22, 262-1) //dynamic resolution,TODO
1867   MDRV_SCREEN_VISIBLE_AREA(0, 768-1, 22, 262-1) //dynamic resolution,TODO
16091868
16101869   MDRV_PALETTE_LENGTH(0x100)
16111870

Previous 15994 Revisions Next


© 1998-2018 The MESS Team